vue.global.js 625 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081
  1. var Vue = (function (exports) {
  2. 'use strict';
  3. /**
  4. * Make a map and return a function for checking if a key
  5. * is in that map.
  6. * IMPORTANT: all calls of this function must be prefixed with
  7. * \/\*#\_\_PURE\_\_\*\/
  8. * So that rollup can tree-shake them if necessary.
  9. */
  10. function makeMap(str, expectsLowerCase) {
  11. const map = Object.create(null);
  12. const list = str.split(',');
  13. for (let i = 0; i < list.length; i++) {
  14. map[list[i]] = true;
  15. }
  16. return expectsLowerCase ? val => !!map[val.toLowerCase()] : val => !!map[val];
  17. }
  18. /**
  19. * dev only flag -> name mapping
  20. */
  21. const PatchFlagNames = {
  22. [1 /* PatchFlags.TEXT */]: `TEXT`,
  23. [2 /* PatchFlags.CLASS */]: `CLASS`,
  24. [4 /* PatchFlags.STYLE */]: `STYLE`,
  25. [8 /* PatchFlags.PROPS */]: `PROPS`,
  26. [16 /* PatchFlags.FULL_PROPS */]: `FULL_PROPS`,
  27. [32 /* PatchFlags.HYDRATE_EVENTS */]: `HYDRATE_EVENTS`,
  28. [64 /* PatchFlags.STABLE_FRAGMENT */]: `STABLE_FRAGMENT`,
  29. [128 /* PatchFlags.KEYED_FRAGMENT */]: `KEYED_FRAGMENT`,
  30. [256 /* PatchFlags.UNKEYED_FRAGMENT */]: `UNKEYED_FRAGMENT`,
  31. [512 /* PatchFlags.NEED_PATCH */]: `NEED_PATCH`,
  32. [1024 /* PatchFlags.DYNAMIC_SLOTS */]: `DYNAMIC_SLOTS`,
  33. [2048 /* PatchFlags.DEV_ROOT_FRAGMENT */]: `DEV_ROOT_FRAGMENT`,
  34. [-1 /* PatchFlags.HOISTED */]: `HOISTED`,
  35. [-2 /* PatchFlags.BAIL */]: `BAIL`
  36. };
  37. /**
  38. * Dev only
  39. */
  40. const slotFlagsText = {
  41. [1 /* SlotFlags.STABLE */]: 'STABLE',
  42. [2 /* SlotFlags.DYNAMIC */]: 'DYNAMIC',
  43. [3 /* SlotFlags.FORWARDED */]: 'FORWARDED'
  44. };
  45. const GLOBALS_WHITE_LISTED = 'Infinity,undefined,NaN,isFinite,isNaN,parseFloat,parseInt,decodeURI,' +
  46. 'decodeURIComponent,encodeURI,encodeURIComponent,Math,Number,Date,Array,' +
  47. 'Object,Boolean,String,RegExp,Map,Set,JSON,Intl,BigInt';
  48. const isGloballyWhitelisted = /*#__PURE__*/ makeMap(GLOBALS_WHITE_LISTED);
  49. const range = 2;
  50. function generateCodeFrame(source, start = 0, end = source.length) {
  51. // Split the content into individual lines but capture the newline sequence
  52. // that separated each line. This is important because the actual sequence is
  53. // needed to properly take into account the full line length for offset
  54. // comparison
  55. let lines = source.split(/(\r?\n)/);
  56. // Separate the lines and newline sequences into separate arrays for easier referencing
  57. const newlineSequences = lines.filter((_, idx) => idx % 2 === 1);
  58. lines = lines.filter((_, idx) => idx % 2 === 0);
  59. let count = 0;
  60. const res = [];
  61. for (let i = 0; i < lines.length; i++) {
  62. count +=
  63. lines[i].length +
  64. ((newlineSequences[i] && newlineSequences[i].length) || 0);
  65. if (count >= start) {
  66. for (let j = i - range; j <= i + range || end > count; j++) {
  67. if (j < 0 || j >= lines.length)
  68. continue;
  69. const line = j + 1;
  70. res.push(`${line}${' '.repeat(Math.max(3 - String(line).length, 0))}| ${lines[j]}`);
  71. const lineLength = lines[j].length;
  72. const newLineSeqLength = (newlineSequences[j] && newlineSequences[j].length) || 0;
  73. if (j === i) {
  74. // push underline
  75. const pad = start - (count - (lineLength + newLineSeqLength));
  76. const length = Math.max(1, end > count ? lineLength - pad : end - start);
  77. res.push(` | ` + ' '.repeat(pad) + '^'.repeat(length));
  78. }
  79. else if (j > i) {
  80. if (end > count) {
  81. const length = Math.max(Math.min(end - count, lineLength), 1);
  82. res.push(` | ` + '^'.repeat(length));
  83. }
  84. count += lineLength + newLineSeqLength;
  85. }
  86. }
  87. break;
  88. }
  89. }
  90. return res.join('\n');
  91. }
  92. function normalizeStyle(value) {
  93. if (isArray(value)) {
  94. const res = {};
  95. for (let i = 0; i < value.length; i++) {
  96. const item = value[i];
  97. const normalized = isString(item)
  98. ? parseStringStyle(item)
  99. : normalizeStyle(item);
  100. if (normalized) {
  101. for (const key in normalized) {
  102. res[key] = normalized[key];
  103. }
  104. }
  105. }
  106. return res;
  107. }
  108. else if (isString(value)) {
  109. return value;
  110. }
  111. else if (isObject(value)) {
  112. return value;
  113. }
  114. }
  115. const listDelimiterRE = /;(?![^(]*\))/g;
  116. const propertyDelimiterRE = /:([^]+)/;
  117. const styleCommentRE = /\/\*.*?\*\//gs;
  118. function parseStringStyle(cssText) {
  119. const ret = {};
  120. cssText
  121. .replace(styleCommentRE, '')
  122. .split(listDelimiterRE)
  123. .forEach(item => {
  124. if (item) {
  125. const tmp = item.split(propertyDelimiterRE);
  126. tmp.length > 1 && (ret[tmp[0].trim()] = tmp[1].trim());
  127. }
  128. });
  129. return ret;
  130. }
  131. function normalizeClass(value) {
  132. let res = '';
  133. if (isString(value)) {
  134. res = value;
  135. }
  136. else if (isArray(value)) {
  137. for (let i = 0; i < value.length; i++) {
  138. const normalized = normalizeClass(value[i]);
  139. if (normalized) {
  140. res += normalized + ' ';
  141. }
  142. }
  143. }
  144. else if (isObject(value)) {
  145. for (const name in value) {
  146. if (value[name]) {
  147. res += name + ' ';
  148. }
  149. }
  150. }
  151. return res.trim();
  152. }
  153. function normalizeProps(props) {
  154. if (!props)
  155. return null;
  156. let { class: klass, style } = props;
  157. if (klass && !isString(klass)) {
  158. props.class = normalizeClass(klass);
  159. }
  160. if (style) {
  161. props.style = normalizeStyle(style);
  162. }
  163. return props;
  164. }
  165. // These tag configs are shared between compiler-dom and runtime-dom, so they
  166. // https://developer.mozilla.org/en-US/docs/Web/HTML/Element
  167. const HTML_TAGS = 'html,body,base,head,link,meta,style,title,address,article,aside,footer,' +
  168. 'header,h1,h2,h3,h4,h5,h6,nav,section,div,dd,dl,dt,figcaption,' +
  169. 'figure,picture,hr,img,li,main,ol,p,pre,ul,a,b,abbr,bdi,bdo,br,cite,code,' +
  170. 'data,dfn,em,i,kbd,mark,q,rp,rt,ruby,s,samp,small,span,strong,sub,sup,' +
  171. 'time,u,var,wbr,area,audio,map,track,video,embed,object,param,source,' +
  172. 'canvas,script,noscript,del,ins,caption,col,colgroup,table,thead,tbody,td,' +
  173. 'th,tr,button,datalist,fieldset,form,input,label,legend,meter,optgroup,' +
  174. 'option,output,progress,select,textarea,details,dialog,menu,' +
  175. 'summary,template,blockquote,iframe,tfoot';
  176. // https://developer.mozilla.org/en-US/docs/Web/SVG/Element
  177. const SVG_TAGS = 'svg,animate,animateMotion,animateTransform,circle,clipPath,color-profile,' +
  178. 'defs,desc,discard,ellipse,feBlend,feColorMatrix,feComponentTransfer,' +
  179. 'feComposite,feConvolveMatrix,feDiffuseLighting,feDisplacementMap,' +
  180. 'feDistanceLight,feDropShadow,feFlood,feFuncA,feFuncB,feFuncG,feFuncR,' +
  181. 'feGaussianBlur,feImage,feMerge,feMergeNode,feMorphology,feOffset,' +
  182. 'fePointLight,feSpecularLighting,feSpotLight,feTile,feTurbulence,filter,' +
  183. 'foreignObject,g,hatch,hatchpath,image,line,linearGradient,marker,mask,' +
  184. 'mesh,meshgradient,meshpatch,meshrow,metadata,mpath,path,pattern,' +
  185. 'polygon,polyline,radialGradient,rect,set,solidcolor,stop,switch,symbol,' +
  186. 'text,textPath,title,tspan,unknown,use,view';
  187. const VOID_TAGS = 'area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr';
  188. /**
  189. * Compiler only.
  190. * Do NOT use in runtime code paths unless behind `true` flag.
  191. */
  192. const isHTMLTag = /*#__PURE__*/ makeMap(HTML_TAGS);
  193. /**
  194. * Compiler only.
  195. * Do NOT use in runtime code paths unless behind `true` flag.
  196. */
  197. const isSVGTag = /*#__PURE__*/ makeMap(SVG_TAGS);
  198. /**
  199. * Compiler only.
  200. * Do NOT use in runtime code paths unless behind `true` flag.
  201. */
  202. const isVoidTag = /*#__PURE__*/ makeMap(VOID_TAGS);
  203. /**
  204. * On the client we only need to offer special cases for boolean attributes that
  205. * have different names from their corresponding dom properties:
  206. * - itemscope -> N/A
  207. * - allowfullscreen -> allowFullscreen
  208. * - formnovalidate -> formNoValidate
  209. * - ismap -> isMap
  210. * - nomodule -> noModule
  211. * - novalidate -> noValidate
  212. * - readonly -> readOnly
  213. */
  214. const specialBooleanAttrs = `itemscope,allowfullscreen,formnovalidate,ismap,nomodule,novalidate,readonly`;
  215. const isSpecialBooleanAttr = /*#__PURE__*/ makeMap(specialBooleanAttrs);
  216. /**
  217. * Boolean attributes should be included if the value is truthy or ''.
  218. * e.g. `<select multiple>` compiles to `{ multiple: '' }`
  219. */
  220. function includeBooleanAttr(value) {
  221. return !!value || value === '';
  222. }
  223. function looseCompareArrays(a, b) {
  224. if (a.length !== b.length)
  225. return false;
  226. let equal = true;
  227. for (let i = 0; equal && i < a.length; i++) {
  228. equal = looseEqual(a[i], b[i]);
  229. }
  230. return equal;
  231. }
  232. function looseEqual(a, b) {
  233. if (a === b)
  234. return true;
  235. let aValidType = isDate(a);
  236. let bValidType = isDate(b);
  237. if (aValidType || bValidType) {
  238. return aValidType && bValidType ? a.getTime() === b.getTime() : false;
  239. }
  240. aValidType = isSymbol(a);
  241. bValidType = isSymbol(b);
  242. if (aValidType || bValidType) {
  243. return a === b;
  244. }
  245. aValidType = isArray(a);
  246. bValidType = isArray(b);
  247. if (aValidType || bValidType) {
  248. return aValidType && bValidType ? looseCompareArrays(a, b) : false;
  249. }
  250. aValidType = isObject(a);
  251. bValidType = isObject(b);
  252. if (aValidType || bValidType) {
  253. /* istanbul ignore if: this if will probably never be called */
  254. if (!aValidType || !bValidType) {
  255. return false;
  256. }
  257. const aKeysCount = Object.keys(a).length;
  258. const bKeysCount = Object.keys(b).length;
  259. if (aKeysCount !== bKeysCount) {
  260. return false;
  261. }
  262. for (const key in a) {
  263. const aHasKey = a.hasOwnProperty(key);
  264. const bHasKey = b.hasOwnProperty(key);
  265. if ((aHasKey && !bHasKey) ||
  266. (!aHasKey && bHasKey) ||
  267. !looseEqual(a[key], b[key])) {
  268. return false;
  269. }
  270. }
  271. }
  272. return String(a) === String(b);
  273. }
  274. function looseIndexOf(arr, val) {
  275. return arr.findIndex(item => looseEqual(item, val));
  276. }
  277. /**
  278. * For converting {{ interpolation }} values to displayed strings.
  279. * @private
  280. */
  281. const toDisplayString = (val) => {
  282. return isString(val)
  283. ? val
  284. : val == null
  285. ? ''
  286. : isArray(val) ||
  287. (isObject(val) &&
  288. (val.toString === objectToString || !isFunction(val.toString)))
  289. ? JSON.stringify(val, replacer, 2)
  290. : String(val);
  291. };
  292. const replacer = (_key, val) => {
  293. // can't use isRef here since @vue/shared has no deps
  294. if (val && val.__v_isRef) {
  295. return replacer(_key, val.value);
  296. }
  297. else if (isMap(val)) {
  298. return {
  299. [`Map(${val.size})`]: [...val.entries()].reduce((entries, [key, val]) => {
  300. entries[`${key} =>`] = val;
  301. return entries;
  302. }, {})
  303. };
  304. }
  305. else if (isSet(val)) {
  306. return {
  307. [`Set(${val.size})`]: [...val.values()]
  308. };
  309. }
  310. else if (isObject(val) && !isArray(val) && !isPlainObject(val)) {
  311. return String(val);
  312. }
  313. return val;
  314. };
  315. const EMPTY_OBJ = Object.freeze({})
  316. ;
  317. const EMPTY_ARR = Object.freeze([]) ;
  318. const NOOP = () => { };
  319. /**
  320. * Always return false.
  321. */
  322. const NO = () => false;
  323. const onRE = /^on[^a-z]/;
  324. const isOn = (key) => onRE.test(key);
  325. const isModelListener = (key) => key.startsWith('onUpdate:');
  326. const extend = Object.assign;
  327. const remove = (arr, el) => {
  328. const i = arr.indexOf(el);
  329. if (i > -1) {
  330. arr.splice(i, 1);
  331. }
  332. };
  333. const hasOwnProperty = Object.prototype.hasOwnProperty;
  334. const hasOwn = (val, key) => hasOwnProperty.call(val, key);
  335. const isArray = Array.isArray;
  336. const isMap = (val) => toTypeString(val) === '[object Map]';
  337. const isSet = (val) => toTypeString(val) === '[object Set]';
  338. const isDate = (val) => toTypeString(val) === '[object Date]';
  339. const isFunction = (val) => typeof val === 'function';
  340. const isString = (val) => typeof val === 'string';
  341. const isSymbol = (val) => typeof val === 'symbol';
  342. const isObject = (val) => val !== null && typeof val === 'object';
  343. const isPromise = (val) => {
  344. return isObject(val) && isFunction(val.then) && isFunction(val.catch);
  345. };
  346. const objectToString = Object.prototype.toString;
  347. const toTypeString = (value) => objectToString.call(value);
  348. const toRawType = (value) => {
  349. // extract "RawType" from strings like "[object RawType]"
  350. return toTypeString(value).slice(8, -1);
  351. };
  352. const isPlainObject = (val) => toTypeString(val) === '[object Object]';
  353. const isIntegerKey = (key) => isString(key) &&
  354. key !== 'NaN' &&
  355. key[0] !== '-' &&
  356. '' + parseInt(key, 10) === key;
  357. const isReservedProp = /*#__PURE__*/ makeMap(
  358. // the leading comma is intentional so empty string "" is also included
  359. ',key,ref,ref_for,ref_key,' +
  360. 'onVnodeBeforeMount,onVnodeMounted,' +
  361. 'onVnodeBeforeUpdate,onVnodeUpdated,' +
  362. 'onVnodeBeforeUnmount,onVnodeUnmounted');
  363. const isBuiltInDirective = /*#__PURE__*/ makeMap('bind,cloak,else-if,else,for,html,if,model,on,once,pre,show,slot,text,memo');
  364. const cacheStringFunction = (fn) => {
  365. const cache = Object.create(null);
  366. return ((str) => {
  367. const hit = cache[str];
  368. return hit || (cache[str] = fn(str));
  369. });
  370. };
  371. const camelizeRE = /-(\w)/g;
  372. /**
  373. * @private
  374. */
  375. const camelize = cacheStringFunction((str) => {
  376. return str.replace(camelizeRE, (_, c) => (c ? c.toUpperCase() : ''));
  377. });
  378. const hyphenateRE = /\B([A-Z])/g;
  379. /**
  380. * @private
  381. */
  382. const hyphenate = cacheStringFunction((str) => str.replace(hyphenateRE, '-$1').toLowerCase());
  383. /**
  384. * @private
  385. */
  386. const capitalize = cacheStringFunction((str) => str.charAt(0).toUpperCase() + str.slice(1));
  387. /**
  388. * @private
  389. */
  390. const toHandlerKey = cacheStringFunction((str) => str ? `on${capitalize(str)}` : ``);
  391. // compare whether a value has changed, accounting for NaN.
  392. const hasChanged = (value, oldValue) => !Object.is(value, oldValue);
  393. const invokeArrayFns = (fns, arg) => {
  394. for (let i = 0; i < fns.length; i++) {
  395. fns[i](arg);
  396. }
  397. };
  398. const def = (obj, key, value) => {
  399. Object.defineProperty(obj, key, {
  400. configurable: true,
  401. enumerable: false,
  402. value
  403. });
  404. };
  405. const toNumber = (val) => {
  406. const n = parseFloat(val);
  407. return isNaN(n) ? val : n;
  408. };
  409. let _globalThis;
  410. const getGlobalThis = () => {
  411. return (_globalThis ||
  412. (_globalThis =
  413. typeof globalThis !== 'undefined'
  414. ? globalThis
  415. : typeof self !== 'undefined'
  416. ? self
  417. : typeof window !== 'undefined'
  418. ? window
  419. : typeof global !== 'undefined'
  420. ? global
  421. : {}));
  422. };
  423. function warn(msg, ...args) {
  424. console.warn(`[Vue warn] ${msg}`, ...args);
  425. }
  426. let activeEffectScope;
  427. class EffectScope {
  428. constructor(detached = false) {
  429. this.detached = detached;
  430. /**
  431. * @internal
  432. */
  433. this.active = true;
  434. /**
  435. * @internal
  436. */
  437. this.effects = [];
  438. /**
  439. * @internal
  440. */
  441. this.cleanups = [];
  442. this.parent = activeEffectScope;
  443. if (!detached && activeEffectScope) {
  444. this.index =
  445. (activeEffectScope.scopes || (activeEffectScope.scopes = [])).push(this) - 1;
  446. }
  447. }
  448. run(fn) {
  449. if (this.active) {
  450. const currentEffectScope = activeEffectScope;
  451. try {
  452. activeEffectScope = this;
  453. return fn();
  454. }
  455. finally {
  456. activeEffectScope = currentEffectScope;
  457. }
  458. }
  459. else {
  460. warn(`cannot run an inactive effect scope.`);
  461. }
  462. }
  463. /**
  464. * This should only be called on non-detached scopes
  465. * @internal
  466. */
  467. on() {
  468. activeEffectScope = this;
  469. }
  470. /**
  471. * This should only be called on non-detached scopes
  472. * @internal
  473. */
  474. off() {
  475. activeEffectScope = this.parent;
  476. }
  477. stop(fromParent) {
  478. if (this.active) {
  479. let i, l;
  480. for (i = 0, l = this.effects.length; i < l; i++) {
  481. this.effects[i].stop();
  482. }
  483. for (i = 0, l = this.cleanups.length; i < l; i++) {
  484. this.cleanups[i]();
  485. }
  486. if (this.scopes) {
  487. for (i = 0, l = this.scopes.length; i < l; i++) {
  488. this.scopes[i].stop(true);
  489. }
  490. }
  491. // nested scope, dereference from parent to avoid memory leaks
  492. if (!this.detached && this.parent && !fromParent) {
  493. // optimized O(1) removal
  494. const last = this.parent.scopes.pop();
  495. if (last && last !== this) {
  496. this.parent.scopes[this.index] = last;
  497. last.index = this.index;
  498. }
  499. }
  500. this.parent = undefined;
  501. this.active = false;
  502. }
  503. }
  504. }
  505. function effectScope(detached) {
  506. return new EffectScope(detached);
  507. }
  508. function recordEffectScope(effect, scope = activeEffectScope) {
  509. if (scope && scope.active) {
  510. scope.effects.push(effect);
  511. }
  512. }
  513. function getCurrentScope() {
  514. return activeEffectScope;
  515. }
  516. function onScopeDispose(fn) {
  517. if (activeEffectScope) {
  518. activeEffectScope.cleanups.push(fn);
  519. }
  520. else {
  521. warn(`onScopeDispose() is called when there is no active effect scope` +
  522. ` to be associated with.`);
  523. }
  524. }
  525. const createDep = (effects) => {
  526. const dep = new Set(effects);
  527. dep.w = 0;
  528. dep.n = 0;
  529. return dep;
  530. };
  531. const wasTracked = (dep) => (dep.w & trackOpBit) > 0;
  532. const newTracked = (dep) => (dep.n & trackOpBit) > 0;
  533. const initDepMarkers = ({ deps }) => {
  534. if (deps.length) {
  535. for (let i = 0; i < deps.length; i++) {
  536. deps[i].w |= trackOpBit; // set was tracked
  537. }
  538. }
  539. };
  540. const finalizeDepMarkers = (effect) => {
  541. const { deps } = effect;
  542. if (deps.length) {
  543. let ptr = 0;
  544. for (let i = 0; i < deps.length; i++) {
  545. const dep = deps[i];
  546. if (wasTracked(dep) && !newTracked(dep)) {
  547. dep.delete(effect);
  548. }
  549. else {
  550. deps[ptr++] = dep;
  551. }
  552. // clear bits
  553. dep.w &= ~trackOpBit;
  554. dep.n &= ~trackOpBit;
  555. }
  556. deps.length = ptr;
  557. }
  558. };
  559. const targetMap = new WeakMap();
  560. // The number of effects currently being tracked recursively.
  561. let effectTrackDepth = 0;
  562. let trackOpBit = 1;
  563. /**
  564. * The bitwise track markers support at most 30 levels of recursion.
  565. * This value is chosen to enable modern JS engines to use a SMI on all platforms.
  566. * When recursion depth is greater, fall back to using a full cleanup.
  567. */
  568. const maxMarkerBits = 30;
  569. let activeEffect;
  570. const ITERATE_KEY = Symbol('iterate' );
  571. const MAP_KEY_ITERATE_KEY = Symbol('Map key iterate' );
  572. class ReactiveEffect {
  573. constructor(fn, scheduler = null, scope) {
  574. this.fn = fn;
  575. this.scheduler = scheduler;
  576. this.active = true;
  577. this.deps = [];
  578. this.parent = undefined;
  579. recordEffectScope(this, scope);
  580. }
  581. run() {
  582. if (!this.active) {
  583. return this.fn();
  584. }
  585. let parent = activeEffect;
  586. let lastShouldTrack = shouldTrack;
  587. while (parent) {
  588. if (parent === this) {
  589. return;
  590. }
  591. parent = parent.parent;
  592. }
  593. try {
  594. this.parent = activeEffect;
  595. activeEffect = this;
  596. shouldTrack = true;
  597. trackOpBit = 1 << ++effectTrackDepth;
  598. if (effectTrackDepth <= maxMarkerBits) {
  599. initDepMarkers(this);
  600. }
  601. else {
  602. cleanupEffect(this);
  603. }
  604. return this.fn();
  605. }
  606. finally {
  607. if (effectTrackDepth <= maxMarkerBits) {
  608. finalizeDepMarkers(this);
  609. }
  610. trackOpBit = 1 << --effectTrackDepth;
  611. activeEffect = this.parent;
  612. shouldTrack = lastShouldTrack;
  613. this.parent = undefined;
  614. if (this.deferStop) {
  615. this.stop();
  616. }
  617. }
  618. }
  619. stop() {
  620. // stopped while running itself - defer the cleanup
  621. if (activeEffect === this) {
  622. this.deferStop = true;
  623. }
  624. else if (this.active) {
  625. cleanupEffect(this);
  626. if (this.onStop) {
  627. this.onStop();
  628. }
  629. this.active = false;
  630. }
  631. }
  632. }
  633. function cleanupEffect(effect) {
  634. const { deps } = effect;
  635. if (deps.length) {
  636. for (let i = 0; i < deps.length; i++) {
  637. deps[i].delete(effect);
  638. }
  639. deps.length = 0;
  640. }
  641. }
  642. function effect(fn, options) {
  643. if (fn.effect) {
  644. fn = fn.effect.fn;
  645. }
  646. const _effect = new ReactiveEffect(fn);
  647. if (options) {
  648. extend(_effect, options);
  649. if (options.scope)
  650. recordEffectScope(_effect, options.scope);
  651. }
  652. if (!options || !options.lazy) {
  653. _effect.run();
  654. }
  655. const runner = _effect.run.bind(_effect);
  656. runner.effect = _effect;
  657. return runner;
  658. }
  659. function stop(runner) {
  660. runner.effect.stop();
  661. }
  662. let shouldTrack = true;
  663. const trackStack = [];
  664. function pauseTracking() {
  665. trackStack.push(shouldTrack);
  666. shouldTrack = false;
  667. }
  668. function resetTracking() {
  669. const last = trackStack.pop();
  670. shouldTrack = last === undefined ? true : last;
  671. }
  672. function track(target, type, key) {
  673. if (shouldTrack && activeEffect) {
  674. let depsMap = targetMap.get(target);
  675. if (!depsMap) {
  676. targetMap.set(target, (depsMap = new Map()));
  677. }
  678. let dep = depsMap.get(key);
  679. if (!dep) {
  680. depsMap.set(key, (dep = createDep()));
  681. }
  682. const eventInfo = { effect: activeEffect, target, type, key }
  683. ;
  684. trackEffects(dep, eventInfo);
  685. }
  686. }
  687. function trackEffects(dep, debuggerEventExtraInfo) {
  688. let shouldTrack = false;
  689. if (effectTrackDepth <= maxMarkerBits) {
  690. if (!newTracked(dep)) {
  691. dep.n |= trackOpBit; // set newly tracked
  692. shouldTrack = !wasTracked(dep);
  693. }
  694. }
  695. else {
  696. // Full cleanup mode.
  697. shouldTrack = !dep.has(activeEffect);
  698. }
  699. if (shouldTrack) {
  700. dep.add(activeEffect);
  701. activeEffect.deps.push(dep);
  702. if (activeEffect.onTrack) {
  703. activeEffect.onTrack(Object.assign({ effect: activeEffect }, debuggerEventExtraInfo));
  704. }
  705. }
  706. }
  707. function trigger(target, type, key, newValue, oldValue, oldTarget) {
  708. const depsMap = targetMap.get(target);
  709. if (!depsMap) {
  710. // never been tracked
  711. return;
  712. }
  713. let deps = [];
  714. if (type === "clear" /* TriggerOpTypes.CLEAR */) {
  715. // collection being cleared
  716. // trigger all effects for target
  717. deps = [...depsMap.values()];
  718. }
  719. else if (key === 'length' && isArray(target)) {
  720. const newLength = toNumber(newValue);
  721. depsMap.forEach((dep, key) => {
  722. if (key === 'length' || key >= newLength) {
  723. deps.push(dep);
  724. }
  725. });
  726. }
  727. else {
  728. // schedule runs for SET | ADD | DELETE
  729. if (key !== void 0) {
  730. deps.push(depsMap.get(key));
  731. }
  732. // also run for iteration key on ADD | DELETE | Map.SET
  733. switch (type) {
  734. case "add" /* TriggerOpTypes.ADD */:
  735. if (!isArray(target)) {
  736. deps.push(depsMap.get(ITERATE_KEY));
  737. if (isMap(target)) {
  738. deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
  739. }
  740. }
  741. else if (isIntegerKey(key)) {
  742. // new index added to array -> length changes
  743. deps.push(depsMap.get('length'));
  744. }
  745. break;
  746. case "delete" /* TriggerOpTypes.DELETE */:
  747. if (!isArray(target)) {
  748. deps.push(depsMap.get(ITERATE_KEY));
  749. if (isMap(target)) {
  750. deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
  751. }
  752. }
  753. break;
  754. case "set" /* TriggerOpTypes.SET */:
  755. if (isMap(target)) {
  756. deps.push(depsMap.get(ITERATE_KEY));
  757. }
  758. break;
  759. }
  760. }
  761. const eventInfo = { target, type, key, newValue, oldValue, oldTarget }
  762. ;
  763. if (deps.length === 1) {
  764. if (deps[0]) {
  765. {
  766. triggerEffects(deps[0], eventInfo);
  767. }
  768. }
  769. }
  770. else {
  771. const effects = [];
  772. for (const dep of deps) {
  773. if (dep) {
  774. effects.push(...dep);
  775. }
  776. }
  777. {
  778. triggerEffects(createDep(effects), eventInfo);
  779. }
  780. }
  781. }
  782. function triggerEffects(dep, debuggerEventExtraInfo) {
  783. // spread into array for stabilization
  784. const effects = isArray(dep) ? dep : [...dep];
  785. for (const effect of effects) {
  786. if (effect.computed) {
  787. triggerEffect(effect, debuggerEventExtraInfo);
  788. }
  789. }
  790. for (const effect of effects) {
  791. if (!effect.computed) {
  792. triggerEffect(effect, debuggerEventExtraInfo);
  793. }
  794. }
  795. }
  796. function triggerEffect(effect, debuggerEventExtraInfo) {
  797. if (effect !== activeEffect || effect.allowRecurse) {
  798. if (effect.onTrigger) {
  799. effect.onTrigger(extend({ effect }, debuggerEventExtraInfo));
  800. }
  801. if (effect.scheduler) {
  802. effect.scheduler();
  803. }
  804. else {
  805. effect.run();
  806. }
  807. }
  808. }
  809. const isNonTrackableKeys = /*#__PURE__*/ makeMap(`__proto__,__v_isRef,__isVue`);
  810. const builtInSymbols = new Set(
  811. /*#__PURE__*/
  812. Object.getOwnPropertyNames(Symbol)
  813. // ios10.x Object.getOwnPropertyNames(Symbol) can enumerate 'arguments' and 'caller'
  814. // but accessing them on Symbol leads to TypeError because Symbol is a strict mode
  815. // function
  816. .filter(key => key !== 'arguments' && key !== 'caller')
  817. .map(key => Symbol[key])
  818. .filter(isSymbol));
  819. const get = /*#__PURE__*/ createGetter();
  820. const shallowGet = /*#__PURE__*/ createGetter(false, true);
  821. const readonlyGet = /*#__PURE__*/ createGetter(true);
  822. const shallowReadonlyGet = /*#__PURE__*/ createGetter(true, true);
  823. const arrayInstrumentations = /*#__PURE__*/ createArrayInstrumentations();
  824. function createArrayInstrumentations() {
  825. const instrumentations = {};
  826. ['includes', 'indexOf', 'lastIndexOf'].forEach(key => {
  827. instrumentations[key] = function (...args) {
  828. const arr = toRaw(this);
  829. for (let i = 0, l = this.length; i < l; i++) {
  830. track(arr, "get" /* TrackOpTypes.GET */, i + '');
  831. }
  832. // we run the method using the original args first (which may be reactive)
  833. const res = arr[key](...args);
  834. if (res === -1 || res === false) {
  835. // if that didn't work, run it again using raw values.
  836. return arr[key](...args.map(toRaw));
  837. }
  838. else {
  839. return res;
  840. }
  841. };
  842. });
  843. ['push', 'pop', 'shift', 'unshift', 'splice'].forEach(key => {
  844. instrumentations[key] = function (...args) {
  845. pauseTracking();
  846. const res = toRaw(this)[key].apply(this, args);
  847. resetTracking();
  848. return res;
  849. };
  850. });
  851. return instrumentations;
  852. }
  853. function createGetter(isReadonly = false, shallow = false) {
  854. return function get(target, key, receiver) {
  855. if (key === "__v_isReactive" /* ReactiveFlags.IS_REACTIVE */) {
  856. return !isReadonly;
  857. }
  858. else if (key === "__v_isReadonly" /* ReactiveFlags.IS_READONLY */) {
  859. return isReadonly;
  860. }
  861. else if (key === "__v_isShallow" /* ReactiveFlags.IS_SHALLOW */) {
  862. return shallow;
  863. }
  864. else if (key === "__v_raw" /* ReactiveFlags.RAW */ &&
  865. receiver ===
  866. (isReadonly
  867. ? shallow
  868. ? shallowReadonlyMap
  869. : readonlyMap
  870. : shallow
  871. ? shallowReactiveMap
  872. : reactiveMap).get(target)) {
  873. return target;
  874. }
  875. const targetIsArray = isArray(target);
  876. if (!isReadonly && targetIsArray && hasOwn(arrayInstrumentations, key)) {
  877. return Reflect.get(arrayInstrumentations, key, receiver);
  878. }
  879. const res = Reflect.get(target, key, receiver);
  880. if (isSymbol(key) ? builtInSymbols.has(key) : isNonTrackableKeys(key)) {
  881. return res;
  882. }
  883. if (!isReadonly) {
  884. track(target, "get" /* TrackOpTypes.GET */, key);
  885. }
  886. if (shallow) {
  887. return res;
  888. }
  889. if (isRef(res)) {
  890. // ref unwrapping - skip unwrap for Array + integer key.
  891. return targetIsArray && isIntegerKey(key) ? res : res.value;
  892. }
  893. if (isObject(res)) {
  894. // Convert returned value into a proxy as well. we do the isObject check
  895. // here to avoid invalid value warning. Also need to lazy access readonly
  896. // and reactive here to avoid circular dependency.
  897. return isReadonly ? readonly(res) : reactive(res);
  898. }
  899. return res;
  900. };
  901. }
  902. const set = /*#__PURE__*/ createSetter();
  903. const shallowSet = /*#__PURE__*/ createSetter(true);
  904. function createSetter(shallow = false) {
  905. return function set(target, key, value, receiver) {
  906. let oldValue = target[key];
  907. if (isReadonly(oldValue) && isRef(oldValue) && !isRef(value)) {
  908. return false;
  909. }
  910. if (!shallow) {
  911. if (!isShallow(value) && !isReadonly(value)) {
  912. oldValue = toRaw(oldValue);
  913. value = toRaw(value);
  914. }
  915. if (!isArray(target) && isRef(oldValue) && !isRef(value)) {
  916. oldValue.value = value;
  917. return true;
  918. }
  919. }
  920. const hadKey = isArray(target) && isIntegerKey(key)
  921. ? Number(key) < target.length
  922. : hasOwn(target, key);
  923. const result = Reflect.set(target, key, value, receiver);
  924. // don't trigger if target is something up in the prototype chain of original
  925. if (target === toRaw(receiver)) {
  926. if (!hadKey) {
  927. trigger(target, "add" /* TriggerOpTypes.ADD */, key, value);
  928. }
  929. else if (hasChanged(value, oldValue)) {
  930. trigger(target, "set" /* TriggerOpTypes.SET */, key, value, oldValue);
  931. }
  932. }
  933. return result;
  934. };
  935. }
  936. function deleteProperty(target, key) {
  937. const hadKey = hasOwn(target, key);
  938. const oldValue = target[key];
  939. const result = Reflect.deleteProperty(target, key);
  940. if (result && hadKey) {
  941. trigger(target, "delete" /* TriggerOpTypes.DELETE */, key, undefined, oldValue);
  942. }
  943. return result;
  944. }
  945. function has(target, key) {
  946. const result = Reflect.has(target, key);
  947. if (!isSymbol(key) || !builtInSymbols.has(key)) {
  948. track(target, "has" /* TrackOpTypes.HAS */, key);
  949. }
  950. return result;
  951. }
  952. function ownKeys(target) {
  953. track(target, "iterate" /* TrackOpTypes.ITERATE */, isArray(target) ? 'length' : ITERATE_KEY);
  954. return Reflect.ownKeys(target);
  955. }
  956. const mutableHandlers = {
  957. get,
  958. set,
  959. deleteProperty,
  960. has,
  961. ownKeys
  962. };
  963. const readonlyHandlers = {
  964. get: readonlyGet,
  965. set(target, key) {
  966. {
  967. warn(`Set operation on key "${String(key)}" failed: target is readonly.`, target);
  968. }
  969. return true;
  970. },
  971. deleteProperty(target, key) {
  972. {
  973. warn(`Delete operation on key "${String(key)}" failed: target is readonly.`, target);
  974. }
  975. return true;
  976. }
  977. };
  978. const shallowReactiveHandlers = /*#__PURE__*/ extend({}, mutableHandlers, {
  979. get: shallowGet,
  980. set: shallowSet
  981. });
  982. // Props handlers are special in the sense that it should not unwrap top-level
  983. // refs (in order to allow refs to be explicitly passed down), but should
  984. // retain the reactivity of the normal readonly object.
  985. const shallowReadonlyHandlers = /*#__PURE__*/ extend({}, readonlyHandlers, {
  986. get: shallowReadonlyGet
  987. });
  988. const toShallow = (value) => value;
  989. const getProto = (v) => Reflect.getPrototypeOf(v);
  990. function get$1(target, key, isReadonly = false, isShallow = false) {
  991. // #1772: readonly(reactive(Map)) should return readonly + reactive version
  992. // of the value
  993. target = target["__v_raw" /* ReactiveFlags.RAW */];
  994. const rawTarget = toRaw(target);
  995. const rawKey = toRaw(key);
  996. if (!isReadonly) {
  997. if (key !== rawKey) {
  998. track(rawTarget, "get" /* TrackOpTypes.GET */, key);
  999. }
  1000. track(rawTarget, "get" /* TrackOpTypes.GET */, rawKey);
  1001. }
  1002. const { has } = getProto(rawTarget);
  1003. const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
  1004. if (has.call(rawTarget, key)) {
  1005. return wrap(target.get(key));
  1006. }
  1007. else if (has.call(rawTarget, rawKey)) {
  1008. return wrap(target.get(rawKey));
  1009. }
  1010. else if (target !== rawTarget) {
  1011. // #3602 readonly(reactive(Map))
  1012. // ensure that the nested reactive `Map` can do tracking for itself
  1013. target.get(key);
  1014. }
  1015. }
  1016. function has$1(key, isReadonly = false) {
  1017. const target = this["__v_raw" /* ReactiveFlags.RAW */];
  1018. const rawTarget = toRaw(target);
  1019. const rawKey = toRaw(key);
  1020. if (!isReadonly) {
  1021. if (key !== rawKey) {
  1022. track(rawTarget, "has" /* TrackOpTypes.HAS */, key);
  1023. }
  1024. track(rawTarget, "has" /* TrackOpTypes.HAS */, rawKey);
  1025. }
  1026. return key === rawKey
  1027. ? target.has(key)
  1028. : target.has(key) || target.has(rawKey);
  1029. }
  1030. function size(target, isReadonly = false) {
  1031. target = target["__v_raw" /* ReactiveFlags.RAW */];
  1032. !isReadonly && track(toRaw(target), "iterate" /* TrackOpTypes.ITERATE */, ITERATE_KEY);
  1033. return Reflect.get(target, 'size', target);
  1034. }
  1035. function add(value) {
  1036. value = toRaw(value);
  1037. const target = toRaw(this);
  1038. const proto = getProto(target);
  1039. const hadKey = proto.has.call(target, value);
  1040. if (!hadKey) {
  1041. target.add(value);
  1042. trigger(target, "add" /* TriggerOpTypes.ADD */, value, value);
  1043. }
  1044. return this;
  1045. }
  1046. function set$1(key, value) {
  1047. value = toRaw(value);
  1048. const target = toRaw(this);
  1049. const { has, get } = getProto(target);
  1050. let hadKey = has.call(target, key);
  1051. if (!hadKey) {
  1052. key = toRaw(key);
  1053. hadKey = has.call(target, key);
  1054. }
  1055. else {
  1056. checkIdentityKeys(target, has, key);
  1057. }
  1058. const oldValue = get.call(target, key);
  1059. target.set(key, value);
  1060. if (!hadKey) {
  1061. trigger(target, "add" /* TriggerOpTypes.ADD */, key, value);
  1062. }
  1063. else if (hasChanged(value, oldValue)) {
  1064. trigger(target, "set" /* TriggerOpTypes.SET */, key, value, oldValue);
  1065. }
  1066. return this;
  1067. }
  1068. function deleteEntry(key) {
  1069. const target = toRaw(this);
  1070. const { has, get } = getProto(target);
  1071. let hadKey = has.call(target, key);
  1072. if (!hadKey) {
  1073. key = toRaw(key);
  1074. hadKey = has.call(target, key);
  1075. }
  1076. else {
  1077. checkIdentityKeys(target, has, key);
  1078. }
  1079. const oldValue = get ? get.call(target, key) : undefined;
  1080. // forward the operation before queueing reactions
  1081. const result = target.delete(key);
  1082. if (hadKey) {
  1083. trigger(target, "delete" /* TriggerOpTypes.DELETE */, key, undefined, oldValue);
  1084. }
  1085. return result;
  1086. }
  1087. function clear() {
  1088. const target = toRaw(this);
  1089. const hadItems = target.size !== 0;
  1090. const oldTarget = isMap(target)
  1091. ? new Map(target)
  1092. : new Set(target)
  1093. ;
  1094. // forward the operation before queueing reactions
  1095. const result = target.clear();
  1096. if (hadItems) {
  1097. trigger(target, "clear" /* TriggerOpTypes.CLEAR */, undefined, undefined, oldTarget);
  1098. }
  1099. return result;
  1100. }
  1101. function createForEach(isReadonly, isShallow) {
  1102. return function forEach(callback, thisArg) {
  1103. const observed = this;
  1104. const target = observed["__v_raw" /* ReactiveFlags.RAW */];
  1105. const rawTarget = toRaw(target);
  1106. const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
  1107. !isReadonly && track(rawTarget, "iterate" /* TrackOpTypes.ITERATE */, ITERATE_KEY);
  1108. return target.forEach((value, key) => {
  1109. // important: make sure the callback is
  1110. // 1. invoked with the reactive map as `this` and 3rd arg
  1111. // 2. the value received should be a corresponding reactive/readonly.
  1112. return callback.call(thisArg, wrap(value), wrap(key), observed);
  1113. });
  1114. };
  1115. }
  1116. function createIterableMethod(method, isReadonly, isShallow) {
  1117. return function (...args) {
  1118. const target = this["__v_raw" /* ReactiveFlags.RAW */];
  1119. const rawTarget = toRaw(target);
  1120. const targetIsMap = isMap(rawTarget);
  1121. const isPair = method === 'entries' || (method === Symbol.iterator && targetIsMap);
  1122. const isKeyOnly = method === 'keys' && targetIsMap;
  1123. const innerIterator = target[method](...args);
  1124. const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
  1125. !isReadonly &&
  1126. track(rawTarget, "iterate" /* TrackOpTypes.ITERATE */, isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY);
  1127. // return a wrapped iterator which returns observed versions of the
  1128. // values emitted from the real iterator
  1129. return {
  1130. // iterator protocol
  1131. next() {
  1132. const { value, done } = innerIterator.next();
  1133. return done
  1134. ? { value, done }
  1135. : {
  1136. value: isPair ? [wrap(value[0]), wrap(value[1])] : wrap(value),
  1137. done
  1138. };
  1139. },
  1140. // iterable protocol
  1141. [Symbol.iterator]() {
  1142. return this;
  1143. }
  1144. };
  1145. };
  1146. }
  1147. function createReadonlyMethod(type) {
  1148. return function (...args) {
  1149. {
  1150. const key = args[0] ? `on key "${args[0]}" ` : ``;
  1151. console.warn(`${capitalize(type)} operation ${key}failed: target is readonly.`, toRaw(this));
  1152. }
  1153. return type === "delete" /* TriggerOpTypes.DELETE */ ? false : this;
  1154. };
  1155. }
  1156. function createInstrumentations() {
  1157. const mutableInstrumentations = {
  1158. get(key) {
  1159. return get$1(this, key);
  1160. },
  1161. get size() {
  1162. return size(this);
  1163. },
  1164. has: has$1,
  1165. add,
  1166. set: set$1,
  1167. delete: deleteEntry,
  1168. clear,
  1169. forEach: createForEach(false, false)
  1170. };
  1171. const shallowInstrumentations = {
  1172. get(key) {
  1173. return get$1(this, key, false, true);
  1174. },
  1175. get size() {
  1176. return size(this);
  1177. },
  1178. has: has$1,
  1179. add,
  1180. set: set$1,
  1181. delete: deleteEntry,
  1182. clear,
  1183. forEach: createForEach(false, true)
  1184. };
  1185. const readonlyInstrumentations = {
  1186. get(key) {
  1187. return get$1(this, key, true);
  1188. },
  1189. get size() {
  1190. return size(this, true);
  1191. },
  1192. has(key) {
  1193. return has$1.call(this, key, true);
  1194. },
  1195. add: createReadonlyMethod("add" /* TriggerOpTypes.ADD */),
  1196. set: createReadonlyMethod("set" /* TriggerOpTypes.SET */),
  1197. delete: createReadonlyMethod("delete" /* TriggerOpTypes.DELETE */),
  1198. clear: createReadonlyMethod("clear" /* TriggerOpTypes.CLEAR */),
  1199. forEach: createForEach(true, false)
  1200. };
  1201. const shallowReadonlyInstrumentations = {
  1202. get(key) {
  1203. return get$1(this, key, true, true);
  1204. },
  1205. get size() {
  1206. return size(this, true);
  1207. },
  1208. has(key) {
  1209. return has$1.call(this, key, true);
  1210. },
  1211. add: createReadonlyMethod("add" /* TriggerOpTypes.ADD */),
  1212. set: createReadonlyMethod("set" /* TriggerOpTypes.SET */),
  1213. delete: createReadonlyMethod("delete" /* TriggerOpTypes.DELETE */),
  1214. clear: createReadonlyMethod("clear" /* TriggerOpTypes.CLEAR */),
  1215. forEach: createForEach(true, true)
  1216. };
  1217. const iteratorMethods = ['keys', 'values', 'entries', Symbol.iterator];
  1218. iteratorMethods.forEach(method => {
  1219. mutableInstrumentations[method] = createIterableMethod(method, false, false);
  1220. readonlyInstrumentations[method] = createIterableMethod(method, true, false);
  1221. shallowInstrumentations[method] = createIterableMethod(method, false, true);
  1222. shallowReadonlyInstrumentations[method] = createIterableMethod(method, true, true);
  1223. });
  1224. return [
  1225. mutableInstrumentations,
  1226. readonlyInstrumentations,
  1227. shallowInstrumentations,
  1228. shallowReadonlyInstrumentations
  1229. ];
  1230. }
  1231. const [mutableInstrumentations, readonlyInstrumentations, shallowInstrumentations, shallowReadonlyInstrumentations] = /* #__PURE__*/ createInstrumentations();
  1232. function createInstrumentationGetter(isReadonly, shallow) {
  1233. const instrumentations = shallow
  1234. ? isReadonly
  1235. ? shallowReadonlyInstrumentations
  1236. : shallowInstrumentations
  1237. : isReadonly
  1238. ? readonlyInstrumentations
  1239. : mutableInstrumentations;
  1240. return (target, key, receiver) => {
  1241. if (key === "__v_isReactive" /* ReactiveFlags.IS_REACTIVE */) {
  1242. return !isReadonly;
  1243. }
  1244. else if (key === "__v_isReadonly" /* ReactiveFlags.IS_READONLY */) {
  1245. return isReadonly;
  1246. }
  1247. else if (key === "__v_raw" /* ReactiveFlags.RAW */) {
  1248. return target;
  1249. }
  1250. return Reflect.get(hasOwn(instrumentations, key) && key in target
  1251. ? instrumentations
  1252. : target, key, receiver);
  1253. };
  1254. }
  1255. const mutableCollectionHandlers = {
  1256. get: /*#__PURE__*/ createInstrumentationGetter(false, false)
  1257. };
  1258. const shallowCollectionHandlers = {
  1259. get: /*#__PURE__*/ createInstrumentationGetter(false, true)
  1260. };
  1261. const readonlyCollectionHandlers = {
  1262. get: /*#__PURE__*/ createInstrumentationGetter(true, false)
  1263. };
  1264. const shallowReadonlyCollectionHandlers = {
  1265. get: /*#__PURE__*/ createInstrumentationGetter(true, true)
  1266. };
  1267. function checkIdentityKeys(target, has, key) {
  1268. const rawKey = toRaw(key);
  1269. if (rawKey !== key && has.call(target, rawKey)) {
  1270. const type = toRawType(target);
  1271. console.warn(`Reactive ${type} contains both the raw and reactive ` +
  1272. `versions of the same object${type === `Map` ? ` as keys` : ``}, ` +
  1273. `which can lead to inconsistencies. ` +
  1274. `Avoid differentiating between the raw and reactive versions ` +
  1275. `of an object and only use the reactive version if possible.`);
  1276. }
  1277. }
  1278. const reactiveMap = new WeakMap();
  1279. const shallowReactiveMap = new WeakMap();
  1280. const readonlyMap = new WeakMap();
  1281. const shallowReadonlyMap = new WeakMap();
  1282. function targetTypeMap(rawType) {
  1283. switch (rawType) {
  1284. case 'Object':
  1285. case 'Array':
  1286. return 1 /* TargetType.COMMON */;
  1287. case 'Map':
  1288. case 'Set':
  1289. case 'WeakMap':
  1290. case 'WeakSet':
  1291. return 2 /* TargetType.COLLECTION */;
  1292. default:
  1293. return 0 /* TargetType.INVALID */;
  1294. }
  1295. }
  1296. function getTargetType(value) {
  1297. return value["__v_skip" /* ReactiveFlags.SKIP */] || !Object.isExtensible(value)
  1298. ? 0 /* TargetType.INVALID */
  1299. : targetTypeMap(toRawType(value));
  1300. }
  1301. function reactive(target) {
  1302. // if trying to observe a readonly proxy, return the readonly version.
  1303. if (isReadonly(target)) {
  1304. return target;
  1305. }
  1306. return createReactiveObject(target, false, mutableHandlers, mutableCollectionHandlers, reactiveMap);
  1307. }
  1308. /**
  1309. * Return a shallowly-reactive copy of the original object, where only the root
  1310. * level properties are reactive. It also does not auto-unwrap refs (even at the
  1311. * root level).
  1312. */
  1313. function shallowReactive(target) {
  1314. return createReactiveObject(target, false, shallowReactiveHandlers, shallowCollectionHandlers, shallowReactiveMap);
  1315. }
  1316. /**
  1317. * Creates a readonly copy of the original object. Note the returned copy is not
  1318. * made reactive, but `readonly` can be called on an already reactive object.
  1319. */
  1320. function readonly(target) {
  1321. return createReactiveObject(target, true, readonlyHandlers, readonlyCollectionHandlers, readonlyMap);
  1322. }
  1323. /**
  1324. * Returns a reactive-copy of the original object, where only the root level
  1325. * properties are readonly, and does NOT unwrap refs nor recursively convert
  1326. * returned properties.
  1327. * This is used for creating the props proxy object for stateful components.
  1328. */
  1329. function shallowReadonly(target) {
  1330. return createReactiveObject(target, true, shallowReadonlyHandlers, shallowReadonlyCollectionHandlers, shallowReadonlyMap);
  1331. }
  1332. function createReactiveObject(target, isReadonly, baseHandlers, collectionHandlers, proxyMap) {
  1333. if (!isObject(target)) {
  1334. {
  1335. console.warn(`value cannot be made reactive: ${String(target)}`);
  1336. }
  1337. return target;
  1338. }
  1339. // target is already a Proxy, return it.
  1340. // exception: calling readonly() on a reactive object
  1341. if (target["__v_raw" /* ReactiveFlags.RAW */] &&
  1342. !(isReadonly && target["__v_isReactive" /* ReactiveFlags.IS_REACTIVE */])) {
  1343. return target;
  1344. }
  1345. // target already has corresponding Proxy
  1346. const existingProxy = proxyMap.get(target);
  1347. if (existingProxy) {
  1348. return existingProxy;
  1349. }
  1350. // only specific value types can be observed.
  1351. const targetType = getTargetType(target);
  1352. if (targetType === 0 /* TargetType.INVALID */) {
  1353. return target;
  1354. }
  1355. const proxy = new Proxy(target, targetType === 2 /* TargetType.COLLECTION */ ? collectionHandlers : baseHandlers);
  1356. proxyMap.set(target, proxy);
  1357. return proxy;
  1358. }
  1359. function isReactive(value) {
  1360. if (isReadonly(value)) {
  1361. return isReactive(value["__v_raw" /* ReactiveFlags.RAW */]);
  1362. }
  1363. return !!(value && value["__v_isReactive" /* ReactiveFlags.IS_REACTIVE */]);
  1364. }
  1365. function isReadonly(value) {
  1366. return !!(value && value["__v_isReadonly" /* ReactiveFlags.IS_READONLY */]);
  1367. }
  1368. function isShallow(value) {
  1369. return !!(value && value["__v_isShallow" /* ReactiveFlags.IS_SHALLOW */]);
  1370. }
  1371. function isProxy(value) {
  1372. return isReactive(value) || isReadonly(value);
  1373. }
  1374. function toRaw(observed) {
  1375. const raw = observed && observed["__v_raw" /* ReactiveFlags.RAW */];
  1376. return raw ? toRaw(raw) : observed;
  1377. }
  1378. function markRaw(value) {
  1379. def(value, "__v_skip" /* ReactiveFlags.SKIP */, true);
  1380. return value;
  1381. }
  1382. const toReactive = (value) => isObject(value) ? reactive(value) : value;
  1383. const toReadonly = (value) => isObject(value) ? readonly(value) : value;
  1384. function trackRefValue(ref) {
  1385. if (shouldTrack && activeEffect) {
  1386. ref = toRaw(ref);
  1387. {
  1388. trackEffects(ref.dep || (ref.dep = createDep()), {
  1389. target: ref,
  1390. type: "get" /* TrackOpTypes.GET */,
  1391. key: 'value'
  1392. });
  1393. }
  1394. }
  1395. }
  1396. function triggerRefValue(ref, newVal) {
  1397. ref = toRaw(ref);
  1398. if (ref.dep) {
  1399. {
  1400. triggerEffects(ref.dep, {
  1401. target: ref,
  1402. type: "set" /* TriggerOpTypes.SET */,
  1403. key: 'value',
  1404. newValue: newVal
  1405. });
  1406. }
  1407. }
  1408. }
  1409. function isRef(r) {
  1410. return !!(r && r.__v_isRef === true);
  1411. }
  1412. function ref(value) {
  1413. return createRef(value, false);
  1414. }
  1415. function shallowRef(value) {
  1416. return createRef(value, true);
  1417. }
  1418. function createRef(rawValue, shallow) {
  1419. if (isRef(rawValue)) {
  1420. return rawValue;
  1421. }
  1422. return new RefImpl(rawValue, shallow);
  1423. }
  1424. class RefImpl {
  1425. constructor(value, __v_isShallow) {
  1426. this.__v_isShallow = __v_isShallow;
  1427. this.dep = undefined;
  1428. this.__v_isRef = true;
  1429. this._rawValue = __v_isShallow ? value : toRaw(value);
  1430. this._value = __v_isShallow ? value : toReactive(value);
  1431. }
  1432. get value() {
  1433. trackRefValue(this);
  1434. return this._value;
  1435. }
  1436. set value(newVal) {
  1437. const useDirectValue = this.__v_isShallow || isShallow(newVal) || isReadonly(newVal);
  1438. newVal = useDirectValue ? newVal : toRaw(newVal);
  1439. if (hasChanged(newVal, this._rawValue)) {
  1440. this._rawValue = newVal;
  1441. this._value = useDirectValue ? newVal : toReactive(newVal);
  1442. triggerRefValue(this, newVal);
  1443. }
  1444. }
  1445. }
  1446. function triggerRef(ref) {
  1447. triggerRefValue(ref, ref.value );
  1448. }
  1449. function unref(ref) {
  1450. return isRef(ref) ? ref.value : ref;
  1451. }
  1452. const shallowUnwrapHandlers = {
  1453. get: (target, key, receiver) => unref(Reflect.get(target, key, receiver)),
  1454. set: (target, key, value, receiver) => {
  1455. const oldValue = target[key];
  1456. if (isRef(oldValue) && !isRef(value)) {
  1457. oldValue.value = value;
  1458. return true;
  1459. }
  1460. else {
  1461. return Reflect.set(target, key, value, receiver);
  1462. }
  1463. }
  1464. };
  1465. function proxyRefs(objectWithRefs) {
  1466. return isReactive(objectWithRefs)
  1467. ? objectWithRefs
  1468. : new Proxy(objectWithRefs, shallowUnwrapHandlers);
  1469. }
  1470. class CustomRefImpl {
  1471. constructor(factory) {
  1472. this.dep = undefined;
  1473. this.__v_isRef = true;
  1474. const { get, set } = factory(() => trackRefValue(this), () => triggerRefValue(this));
  1475. this._get = get;
  1476. this._set = set;
  1477. }
  1478. get value() {
  1479. return this._get();
  1480. }
  1481. set value(newVal) {
  1482. this._set(newVal);
  1483. }
  1484. }
  1485. function customRef(factory) {
  1486. return new CustomRefImpl(factory);
  1487. }
  1488. function toRefs(object) {
  1489. if (!isProxy(object)) {
  1490. console.warn(`toRefs() expects a reactive object but received a plain one.`);
  1491. }
  1492. const ret = isArray(object) ? new Array(object.length) : {};
  1493. for (const key in object) {
  1494. ret[key] = toRef(object, key);
  1495. }
  1496. return ret;
  1497. }
  1498. class ObjectRefImpl {
  1499. constructor(_object, _key, _defaultValue) {
  1500. this._object = _object;
  1501. this._key = _key;
  1502. this._defaultValue = _defaultValue;
  1503. this.__v_isRef = true;
  1504. }
  1505. get value() {
  1506. const val = this._object[this._key];
  1507. return val === undefined ? this._defaultValue : val;
  1508. }
  1509. set value(newVal) {
  1510. this._object[this._key] = newVal;
  1511. }
  1512. }
  1513. function toRef(object, key, defaultValue) {
  1514. const val = object[key];
  1515. return isRef(val)
  1516. ? val
  1517. : new ObjectRefImpl(object, key, defaultValue);
  1518. }
  1519. var _a;
  1520. class ComputedRefImpl {
  1521. constructor(getter, _setter, isReadonly, isSSR) {
  1522. this._setter = _setter;
  1523. this.dep = undefined;
  1524. this.__v_isRef = true;
  1525. this[_a] = false;
  1526. this._dirty = true;
  1527. this.effect = new ReactiveEffect(getter, () => {
  1528. if (!this._dirty) {
  1529. this._dirty = true;
  1530. triggerRefValue(this);
  1531. }
  1532. });
  1533. this.effect.computed = this;
  1534. this.effect.active = this._cacheable = !isSSR;
  1535. this["__v_isReadonly" /* ReactiveFlags.IS_READONLY */] = isReadonly;
  1536. }
  1537. get value() {
  1538. // the computed ref may get wrapped by other proxies e.g. readonly() #3376
  1539. const self = toRaw(this);
  1540. trackRefValue(self);
  1541. if (self._dirty || !self._cacheable) {
  1542. self._dirty = false;
  1543. self._value = self.effect.run();
  1544. }
  1545. return self._value;
  1546. }
  1547. set value(newValue) {
  1548. this._setter(newValue);
  1549. }
  1550. }
  1551. _a = "__v_isReadonly" /* ReactiveFlags.IS_READONLY */;
  1552. function computed(getterOrOptions, debugOptions, isSSR = false) {
  1553. let getter;
  1554. let setter;
  1555. const onlyGetter = isFunction(getterOrOptions);
  1556. if (onlyGetter) {
  1557. getter = getterOrOptions;
  1558. setter = () => {
  1559. console.warn('Write operation failed: computed value is readonly');
  1560. }
  1561. ;
  1562. }
  1563. else {
  1564. getter = getterOrOptions.get;
  1565. setter = getterOrOptions.set;
  1566. }
  1567. const cRef = new ComputedRefImpl(getter, setter, onlyGetter || !setter, isSSR);
  1568. if (debugOptions && !isSSR) {
  1569. cRef.effect.onTrack = debugOptions.onTrack;
  1570. cRef.effect.onTrigger = debugOptions.onTrigger;
  1571. }
  1572. return cRef;
  1573. }
  1574. const stack = [];
  1575. function pushWarningContext(vnode) {
  1576. stack.push(vnode);
  1577. }
  1578. function popWarningContext() {
  1579. stack.pop();
  1580. }
  1581. function warn$1(msg, ...args) {
  1582. // avoid props formatting or warn handler tracking deps that might be mutated
  1583. // during patch, leading to infinite recursion.
  1584. pauseTracking();
  1585. const instance = stack.length ? stack[stack.length - 1].component : null;
  1586. const appWarnHandler = instance && instance.appContext.config.warnHandler;
  1587. const trace = getComponentTrace();
  1588. if (appWarnHandler) {
  1589. callWithErrorHandling(appWarnHandler, instance, 11 /* ErrorCodes.APP_WARN_HANDLER */, [
  1590. msg + args.join(''),
  1591. instance && instance.proxy,
  1592. trace
  1593. .map(({ vnode }) => `at <${formatComponentName(instance, vnode.type)}>`)
  1594. .join('\n'),
  1595. trace
  1596. ]);
  1597. }
  1598. else {
  1599. const warnArgs = [`[Vue warn]: ${msg}`, ...args];
  1600. /* istanbul ignore if */
  1601. if (trace.length &&
  1602. // avoid spamming console during tests
  1603. !false) {
  1604. warnArgs.push(`\n`, ...formatTrace(trace));
  1605. }
  1606. console.warn(...warnArgs);
  1607. }
  1608. resetTracking();
  1609. }
  1610. function getComponentTrace() {
  1611. let currentVNode = stack[stack.length - 1];
  1612. if (!currentVNode) {
  1613. return [];
  1614. }
  1615. // we can't just use the stack because it will be incomplete during updates
  1616. // that did not start from the root. Re-construct the parent chain using
  1617. // instance parent pointers.
  1618. const normalizedStack = [];
  1619. while (currentVNode) {
  1620. const last = normalizedStack[0];
  1621. if (last && last.vnode === currentVNode) {
  1622. last.recurseCount++;
  1623. }
  1624. else {
  1625. normalizedStack.push({
  1626. vnode: currentVNode,
  1627. recurseCount: 0
  1628. });
  1629. }
  1630. const parentInstance = currentVNode.component && currentVNode.component.parent;
  1631. currentVNode = parentInstance && parentInstance.vnode;
  1632. }
  1633. return normalizedStack;
  1634. }
  1635. /* istanbul ignore next */
  1636. function formatTrace(trace) {
  1637. const logs = [];
  1638. trace.forEach((entry, i) => {
  1639. logs.push(...(i === 0 ? [] : [`\n`]), ...formatTraceEntry(entry));
  1640. });
  1641. return logs;
  1642. }
  1643. function formatTraceEntry({ vnode, recurseCount }) {
  1644. const postfix = recurseCount > 0 ? `... (${recurseCount} recursive calls)` : ``;
  1645. const isRoot = vnode.component ? vnode.component.parent == null : false;
  1646. const open = ` at <${formatComponentName(vnode.component, vnode.type, isRoot)}`;
  1647. const close = `>` + postfix;
  1648. return vnode.props
  1649. ? [open, ...formatProps(vnode.props), close]
  1650. : [open + close];
  1651. }
  1652. /* istanbul ignore next */
  1653. function formatProps(props) {
  1654. const res = [];
  1655. const keys = Object.keys(props);
  1656. keys.slice(0, 3).forEach(key => {
  1657. res.push(...formatProp(key, props[key]));
  1658. });
  1659. if (keys.length > 3) {
  1660. res.push(` ...`);
  1661. }
  1662. return res;
  1663. }
  1664. /* istanbul ignore next */
  1665. function formatProp(key, value, raw) {
  1666. if (isString(value)) {
  1667. value = JSON.stringify(value);
  1668. return raw ? value : [`${key}=${value}`];
  1669. }
  1670. else if (typeof value === 'number' ||
  1671. typeof value === 'boolean' ||
  1672. value == null) {
  1673. return raw ? value : [`${key}=${value}`];
  1674. }
  1675. else if (isRef(value)) {
  1676. value = formatProp(key, toRaw(value.value), true);
  1677. return raw ? value : [`${key}=Ref<`, value, `>`];
  1678. }
  1679. else if (isFunction(value)) {
  1680. return [`${key}=fn${value.name ? `<${value.name}>` : ``}`];
  1681. }
  1682. else {
  1683. value = toRaw(value);
  1684. return raw ? value : [`${key}=`, value];
  1685. }
  1686. }
  1687. const ErrorTypeStrings = {
  1688. ["sp" /* LifecycleHooks.SERVER_PREFETCH */]: 'serverPrefetch hook',
  1689. ["bc" /* LifecycleHooks.BEFORE_CREATE */]: 'beforeCreate hook',
  1690. ["c" /* LifecycleHooks.CREATED */]: 'created hook',
  1691. ["bm" /* LifecycleHooks.BEFORE_MOUNT */]: 'beforeMount hook',
  1692. ["m" /* LifecycleHooks.MOUNTED */]: 'mounted hook',
  1693. ["bu" /* LifecycleHooks.BEFORE_UPDATE */]: 'beforeUpdate hook',
  1694. ["u" /* LifecycleHooks.UPDATED */]: 'updated',
  1695. ["bum" /* LifecycleHooks.BEFORE_UNMOUNT */]: 'beforeUnmount hook',
  1696. ["um" /* LifecycleHooks.UNMOUNTED */]: 'unmounted hook',
  1697. ["a" /* LifecycleHooks.ACTIVATED */]: 'activated hook',
  1698. ["da" /* LifecycleHooks.DEACTIVATED */]: 'deactivated hook',
  1699. ["ec" /* LifecycleHooks.ERROR_CAPTURED */]: 'errorCaptured hook',
  1700. ["rtc" /* LifecycleHooks.RENDER_TRACKED */]: 'renderTracked hook',
  1701. ["rtg" /* LifecycleHooks.RENDER_TRIGGERED */]: 'renderTriggered hook',
  1702. [0 /* ErrorCodes.SETUP_FUNCTION */]: 'setup function',
  1703. [1 /* ErrorCodes.RENDER_FUNCTION */]: 'render function',
  1704. [2 /* ErrorCodes.WATCH_GETTER */]: 'watcher getter',
  1705. [3 /* ErrorCodes.WATCH_CALLBACK */]: 'watcher callback',
  1706. [4 /* ErrorCodes.WATCH_CLEANUP */]: 'watcher cleanup function',
  1707. [5 /* ErrorCodes.NATIVE_EVENT_HANDLER */]: 'native event handler',
  1708. [6 /* ErrorCodes.COMPONENT_EVENT_HANDLER */]: 'component event handler',
  1709. [7 /* ErrorCodes.VNODE_HOOK */]: 'vnode hook',
  1710. [8 /* ErrorCodes.DIRECTIVE_HOOK */]: 'directive hook',
  1711. [9 /* ErrorCodes.TRANSITION_HOOK */]: 'transition hook',
  1712. [10 /* ErrorCodes.APP_ERROR_HANDLER */]: 'app errorHandler',
  1713. [11 /* ErrorCodes.APP_WARN_HANDLER */]: 'app warnHandler',
  1714. [12 /* ErrorCodes.FUNCTION_REF */]: 'ref function',
  1715. [13 /* ErrorCodes.ASYNC_COMPONENT_LOADER */]: 'async component loader',
  1716. [14 /* ErrorCodes.SCHEDULER */]: 'scheduler flush. This is likely a Vue internals bug. ' +
  1717. 'Please open an issue at https://new-issue.vuejs.org/?repo=vuejs/core'
  1718. };
  1719. function callWithErrorHandling(fn, instance, type, args) {
  1720. let res;
  1721. try {
  1722. res = args ? fn(...args) : fn();
  1723. }
  1724. catch (err) {
  1725. handleError(err, instance, type);
  1726. }
  1727. return res;
  1728. }
  1729. function callWithAsyncErrorHandling(fn, instance, type, args) {
  1730. if (isFunction(fn)) {
  1731. const res = callWithErrorHandling(fn, instance, type, args);
  1732. if (res && isPromise(res)) {
  1733. res.catch(err => {
  1734. handleError(err, instance, type);
  1735. });
  1736. }
  1737. return res;
  1738. }
  1739. const values = [];
  1740. for (let i = 0; i < fn.length; i++) {
  1741. values.push(callWithAsyncErrorHandling(fn[i], instance, type, args));
  1742. }
  1743. return values;
  1744. }
  1745. function handleError(err, instance, type, throwInDev = true) {
  1746. const contextVNode = instance ? instance.vnode : null;
  1747. if (instance) {
  1748. let cur = instance.parent;
  1749. // the exposed instance is the render proxy to keep it consistent with 2.x
  1750. const exposedInstance = instance.proxy;
  1751. // in production the hook receives only the error code
  1752. const errorInfo = ErrorTypeStrings[type] ;
  1753. while (cur) {
  1754. const errorCapturedHooks = cur.ec;
  1755. if (errorCapturedHooks) {
  1756. for (let i = 0; i < errorCapturedHooks.length; i++) {
  1757. if (errorCapturedHooks[i](err, exposedInstance, errorInfo) === false) {
  1758. return;
  1759. }
  1760. }
  1761. }
  1762. cur = cur.parent;
  1763. }
  1764. // app-level handling
  1765. const appErrorHandler = instance.appContext.config.errorHandler;
  1766. if (appErrorHandler) {
  1767. callWithErrorHandling(appErrorHandler, null, 10 /* ErrorCodes.APP_ERROR_HANDLER */, [err, exposedInstance, errorInfo]);
  1768. return;
  1769. }
  1770. }
  1771. logError(err, type, contextVNode, throwInDev);
  1772. }
  1773. function logError(err, type, contextVNode, throwInDev = true) {
  1774. {
  1775. const info = ErrorTypeStrings[type];
  1776. if (contextVNode) {
  1777. pushWarningContext(contextVNode);
  1778. }
  1779. warn$1(`Unhandled error${info ? ` during execution of ${info}` : ``}`);
  1780. if (contextVNode) {
  1781. popWarningContext();
  1782. }
  1783. // crash in dev by default so it's more noticeable
  1784. if (throwInDev) {
  1785. throw err;
  1786. }
  1787. else {
  1788. console.error(err);
  1789. }
  1790. }
  1791. }
  1792. let isFlushing = false;
  1793. let isFlushPending = false;
  1794. const queue = [];
  1795. let flushIndex = 0;
  1796. const pendingPostFlushCbs = [];
  1797. let activePostFlushCbs = null;
  1798. let postFlushIndex = 0;
  1799. const resolvedPromise = /*#__PURE__*/ Promise.resolve();
  1800. let currentFlushPromise = null;
  1801. const RECURSION_LIMIT = 100;
  1802. function nextTick(fn) {
  1803. const p = currentFlushPromise || resolvedPromise;
  1804. return fn ? p.then(this ? fn.bind(this) : fn) : p;
  1805. }
  1806. // #2768
  1807. // Use binary-search to find a suitable position in the queue,
  1808. // so that the queue maintains the increasing order of job's id,
  1809. // which can prevent the job from being skipped and also can avoid repeated patching.
  1810. function findInsertionIndex(id) {
  1811. // the start index should be `flushIndex + 1`
  1812. let start = flushIndex + 1;
  1813. let end = queue.length;
  1814. while (start < end) {
  1815. const middle = (start + end) >>> 1;
  1816. const middleJobId = getId(queue[middle]);
  1817. middleJobId < id ? (start = middle + 1) : (end = middle);
  1818. }
  1819. return start;
  1820. }
  1821. function queueJob(job) {
  1822. // the dedupe search uses the startIndex argument of Array.includes()
  1823. // by default the search index includes the current job that is being run
  1824. // so it cannot recursively trigger itself again.
  1825. // if the job is a watch() callback, the search will start with a +1 index to
  1826. // allow it recursively trigger itself - it is the user's responsibility to
  1827. // ensure it doesn't end up in an infinite loop.
  1828. if (!queue.length ||
  1829. !queue.includes(job, isFlushing && job.allowRecurse ? flushIndex + 1 : flushIndex)) {
  1830. if (job.id == null) {
  1831. queue.push(job);
  1832. }
  1833. else {
  1834. queue.splice(findInsertionIndex(job.id), 0, job);
  1835. }
  1836. queueFlush();
  1837. }
  1838. }
  1839. function queueFlush() {
  1840. if (!isFlushing && !isFlushPending) {
  1841. isFlushPending = true;
  1842. currentFlushPromise = resolvedPromise.then(flushJobs);
  1843. }
  1844. }
  1845. function invalidateJob(job) {
  1846. const i = queue.indexOf(job);
  1847. if (i > flushIndex) {
  1848. queue.splice(i, 1);
  1849. }
  1850. }
  1851. function queuePostFlushCb(cb) {
  1852. if (!isArray(cb)) {
  1853. if (!activePostFlushCbs ||
  1854. !activePostFlushCbs.includes(cb, cb.allowRecurse ? postFlushIndex + 1 : postFlushIndex)) {
  1855. pendingPostFlushCbs.push(cb);
  1856. }
  1857. }
  1858. else {
  1859. // if cb is an array, it is a component lifecycle hook which can only be
  1860. // triggered by a job, which is already deduped in the main queue, so
  1861. // we can skip duplicate check here to improve perf
  1862. pendingPostFlushCbs.push(...cb);
  1863. }
  1864. queueFlush();
  1865. }
  1866. function flushPreFlushCbs(seen,
  1867. // if currently flushing, skip the current job itself
  1868. i = isFlushing ? flushIndex + 1 : 0) {
  1869. {
  1870. seen = seen || new Map();
  1871. }
  1872. for (; i < queue.length; i++) {
  1873. const cb = queue[i];
  1874. if (cb && cb.pre) {
  1875. if (checkRecursiveUpdates(seen, cb)) {
  1876. continue;
  1877. }
  1878. queue.splice(i, 1);
  1879. i--;
  1880. cb();
  1881. }
  1882. }
  1883. }
  1884. function flushPostFlushCbs(seen) {
  1885. if (pendingPostFlushCbs.length) {
  1886. const deduped = [...new Set(pendingPostFlushCbs)];
  1887. pendingPostFlushCbs.length = 0;
  1888. // #1947 already has active queue, nested flushPostFlushCbs call
  1889. if (activePostFlushCbs) {
  1890. activePostFlushCbs.push(...deduped);
  1891. return;
  1892. }
  1893. activePostFlushCbs = deduped;
  1894. {
  1895. seen = seen || new Map();
  1896. }
  1897. activePostFlushCbs.sort((a, b) => getId(a) - getId(b));
  1898. for (postFlushIndex = 0; postFlushIndex < activePostFlushCbs.length; postFlushIndex++) {
  1899. if (checkRecursiveUpdates(seen, activePostFlushCbs[postFlushIndex])) {
  1900. continue;
  1901. }
  1902. activePostFlushCbs[postFlushIndex]();
  1903. }
  1904. activePostFlushCbs = null;
  1905. postFlushIndex = 0;
  1906. }
  1907. }
  1908. const getId = (job) => job.id == null ? Infinity : job.id;
  1909. const comparator = (a, b) => {
  1910. const diff = getId(a) - getId(b);
  1911. if (diff === 0) {
  1912. if (a.pre && !b.pre)
  1913. return -1;
  1914. if (b.pre && !a.pre)
  1915. return 1;
  1916. }
  1917. return diff;
  1918. };
  1919. function flushJobs(seen) {
  1920. isFlushPending = false;
  1921. isFlushing = true;
  1922. {
  1923. seen = seen || new Map();
  1924. }
  1925. // Sort queue before flush.
  1926. // This ensures that:
  1927. // 1. Components are updated from parent to child. (because parent is always
  1928. // created before the child so its render effect will have smaller
  1929. // priority number)
  1930. // 2. If a component is unmounted during a parent component's update,
  1931. // its update can be skipped.
  1932. queue.sort(comparator);
  1933. // conditional usage of checkRecursiveUpdate must be determined out of
  1934. // try ... catch block since Rollup by default de-optimizes treeshaking
  1935. // inside try-catch. This can leave all warning code unshaked. Although
  1936. // they would get eventually shaken by a minifier like terser, some minifiers
  1937. // would fail to do that (e.g. https://github.com/evanw/esbuild/issues/1610)
  1938. const check = (job) => checkRecursiveUpdates(seen, job)
  1939. ;
  1940. try {
  1941. for (flushIndex = 0; flushIndex < queue.length; flushIndex++) {
  1942. const job = queue[flushIndex];
  1943. if (job && job.active !== false) {
  1944. if (true && check(job)) {
  1945. continue;
  1946. }
  1947. // console.log(`running:`, job.id)
  1948. callWithErrorHandling(job, null, 14 /* ErrorCodes.SCHEDULER */);
  1949. }
  1950. }
  1951. }
  1952. finally {
  1953. flushIndex = 0;
  1954. queue.length = 0;
  1955. flushPostFlushCbs(seen);
  1956. isFlushing = false;
  1957. currentFlushPromise = null;
  1958. // some postFlushCb queued jobs!
  1959. // keep flushing until it drains.
  1960. if (queue.length || pendingPostFlushCbs.length) {
  1961. flushJobs(seen);
  1962. }
  1963. }
  1964. }
  1965. function checkRecursiveUpdates(seen, fn) {
  1966. if (!seen.has(fn)) {
  1967. seen.set(fn, 1);
  1968. }
  1969. else {
  1970. const count = seen.get(fn);
  1971. if (count > RECURSION_LIMIT) {
  1972. const instance = fn.ownerInstance;
  1973. const componentName = instance && getComponentName(instance.type);
  1974. warn$1(`Maximum recursive updates exceeded${componentName ? ` in component <${componentName}>` : ``}. ` +
  1975. `This means you have a reactive effect that is mutating its own ` +
  1976. `dependencies and thus recursively triggering itself. Possible sources ` +
  1977. `include component template, render function, updated hook or ` +
  1978. `watcher source function.`);
  1979. return true;
  1980. }
  1981. else {
  1982. seen.set(fn, count + 1);
  1983. }
  1984. }
  1985. }
  1986. /* eslint-disable no-restricted-globals */
  1987. let isHmrUpdating = false;
  1988. const hmrDirtyComponents = new Set();
  1989. // Expose the HMR runtime on the global object
  1990. // This makes it entirely tree-shakable without polluting the exports and makes
  1991. // it easier to be used in toolings like vue-loader
  1992. // Note: for a component to be eligible for HMR it also needs the __hmrId option
  1993. // to be set so that its instances can be registered / removed.
  1994. {
  1995. getGlobalThis().__VUE_HMR_RUNTIME__ = {
  1996. createRecord: tryWrap(createRecord),
  1997. rerender: tryWrap(rerender),
  1998. reload: tryWrap(reload)
  1999. };
  2000. }
  2001. const map = new Map();
  2002. function registerHMR(instance) {
  2003. const id = instance.type.__hmrId;
  2004. let record = map.get(id);
  2005. if (!record) {
  2006. createRecord(id, instance.type);
  2007. record = map.get(id);
  2008. }
  2009. record.instances.add(instance);
  2010. }
  2011. function unregisterHMR(instance) {
  2012. map.get(instance.type.__hmrId).instances.delete(instance);
  2013. }
  2014. function createRecord(id, initialDef) {
  2015. if (map.has(id)) {
  2016. return false;
  2017. }
  2018. map.set(id, {
  2019. initialDef: normalizeClassComponent(initialDef),
  2020. instances: new Set()
  2021. });
  2022. return true;
  2023. }
  2024. function normalizeClassComponent(component) {
  2025. return isClassComponent(component) ? component.__vccOpts : component;
  2026. }
  2027. function rerender(id, newRender) {
  2028. const record = map.get(id);
  2029. if (!record) {
  2030. return;
  2031. }
  2032. // update initial record (for not-yet-rendered component)
  2033. record.initialDef.render = newRender;
  2034. [...record.instances].forEach(instance => {
  2035. if (newRender) {
  2036. instance.render = newRender;
  2037. normalizeClassComponent(instance.type).render = newRender;
  2038. }
  2039. instance.renderCache = [];
  2040. // this flag forces child components with slot content to update
  2041. isHmrUpdating = true;
  2042. instance.update();
  2043. isHmrUpdating = false;
  2044. });
  2045. }
  2046. function reload(id, newComp) {
  2047. const record = map.get(id);
  2048. if (!record)
  2049. return;
  2050. newComp = normalizeClassComponent(newComp);
  2051. // update initial def (for not-yet-rendered components)
  2052. updateComponentDef(record.initialDef, newComp);
  2053. // create a snapshot which avoids the set being mutated during updates
  2054. const instances = [...record.instances];
  2055. for (const instance of instances) {
  2056. const oldComp = normalizeClassComponent(instance.type);
  2057. if (!hmrDirtyComponents.has(oldComp)) {
  2058. // 1. Update existing comp definition to match new one
  2059. if (oldComp !== record.initialDef) {
  2060. updateComponentDef(oldComp, newComp);
  2061. }
  2062. // 2. mark definition dirty. This forces the renderer to replace the
  2063. // component on patch.
  2064. hmrDirtyComponents.add(oldComp);
  2065. }
  2066. // 3. invalidate options resolution cache
  2067. instance.appContext.optionsCache.delete(instance.type);
  2068. // 4. actually update
  2069. if (instance.ceReload) {
  2070. // custom element
  2071. hmrDirtyComponents.add(oldComp);
  2072. instance.ceReload(newComp.styles);
  2073. hmrDirtyComponents.delete(oldComp);
  2074. }
  2075. else if (instance.parent) {
  2076. // 4. Force the parent instance to re-render. This will cause all updated
  2077. // components to be unmounted and re-mounted. Queue the update so that we
  2078. // don't end up forcing the same parent to re-render multiple times.
  2079. queueJob(instance.parent.update);
  2080. }
  2081. else if (instance.appContext.reload) {
  2082. // root instance mounted via createApp() has a reload method
  2083. instance.appContext.reload();
  2084. }
  2085. else if (typeof window !== 'undefined') {
  2086. // root instance inside tree created via raw render(). Force reload.
  2087. window.location.reload();
  2088. }
  2089. else {
  2090. console.warn('[HMR] Root or manually mounted instance modified. Full reload required.');
  2091. }
  2092. }
  2093. // 5. make sure to cleanup dirty hmr components after update
  2094. queuePostFlushCb(() => {
  2095. for (const instance of instances) {
  2096. hmrDirtyComponents.delete(normalizeClassComponent(instance.type));
  2097. }
  2098. });
  2099. }
  2100. function updateComponentDef(oldComp, newComp) {
  2101. extend(oldComp, newComp);
  2102. for (const key in oldComp) {
  2103. if (key !== '__file' && !(key in newComp)) {
  2104. delete oldComp[key];
  2105. }
  2106. }
  2107. }
  2108. function tryWrap(fn) {
  2109. return (id, arg) => {
  2110. try {
  2111. return fn(id, arg);
  2112. }
  2113. catch (e) {
  2114. console.error(e);
  2115. console.warn(`[HMR] Something went wrong during Vue component hot-reload. ` +
  2116. `Full reload required.`);
  2117. }
  2118. };
  2119. }
  2120. let buffer = [];
  2121. let devtoolsNotInstalled = false;
  2122. function emit(event, ...args) {
  2123. if (exports.devtools) {
  2124. exports.devtools.emit(event, ...args);
  2125. }
  2126. else if (!devtoolsNotInstalled) {
  2127. buffer.push({ event, args });
  2128. }
  2129. }
  2130. function setDevtoolsHook(hook, target) {
  2131. var _a, _b;
  2132. exports.devtools = hook;
  2133. if (exports.devtools) {
  2134. exports.devtools.enabled = true;
  2135. buffer.forEach(({ event, args }) => exports.devtools.emit(event, ...args));
  2136. buffer = [];
  2137. }
  2138. else if (
  2139. // handle late devtools injection - only do this if we are in an actual
  2140. // browser environment to avoid the timer handle stalling test runner exit
  2141. // (#4815)
  2142. typeof window !== 'undefined' &&
  2143. // some envs mock window but not fully
  2144. window.HTMLElement &&
  2145. // also exclude jsdom
  2146. !((_b = (_a = window.navigator) === null || _a === void 0 ? void 0 : _a.userAgent) === null || _b === void 0 ? void 0 : _b.includes('jsdom'))) {
  2147. const replay = (target.__VUE_DEVTOOLS_HOOK_REPLAY__ =
  2148. target.__VUE_DEVTOOLS_HOOK_REPLAY__ || []);
  2149. replay.push((newHook) => {
  2150. setDevtoolsHook(newHook, target);
  2151. });
  2152. // clear buffer after 3s - the user probably doesn't have devtools installed
  2153. // at all, and keeping the buffer will cause memory leaks (#4738)
  2154. setTimeout(() => {
  2155. if (!exports.devtools) {
  2156. target.__VUE_DEVTOOLS_HOOK_REPLAY__ = null;
  2157. devtoolsNotInstalled = true;
  2158. buffer = [];
  2159. }
  2160. }, 3000);
  2161. }
  2162. else {
  2163. // non-browser env, assume not installed
  2164. devtoolsNotInstalled = true;
  2165. buffer = [];
  2166. }
  2167. }
  2168. function devtoolsInitApp(app, version) {
  2169. emit("app:init" /* DevtoolsHooks.APP_INIT */, app, version, {
  2170. Fragment,
  2171. Text,
  2172. Comment,
  2173. Static
  2174. });
  2175. }
  2176. function devtoolsUnmountApp(app) {
  2177. emit("app:unmount" /* DevtoolsHooks.APP_UNMOUNT */, app);
  2178. }
  2179. const devtoolsComponentAdded = /*#__PURE__*/ createDevtoolsComponentHook("component:added" /* DevtoolsHooks.COMPONENT_ADDED */);
  2180. const devtoolsComponentUpdated =
  2181. /*#__PURE__*/ createDevtoolsComponentHook("component:updated" /* DevtoolsHooks.COMPONENT_UPDATED */);
  2182. const _devtoolsComponentRemoved = /*#__PURE__*/ createDevtoolsComponentHook("component:removed" /* DevtoolsHooks.COMPONENT_REMOVED */);
  2183. const devtoolsComponentRemoved = (component) => {
  2184. if (exports.devtools &&
  2185. typeof exports.devtools.cleanupBuffer === 'function' &&
  2186. // remove the component if it wasn't buffered
  2187. !exports.devtools.cleanupBuffer(component)) {
  2188. _devtoolsComponentRemoved(component);
  2189. }
  2190. };
  2191. function createDevtoolsComponentHook(hook) {
  2192. return (component) => {
  2193. emit(hook, component.appContext.app, component.uid, component.parent ? component.parent.uid : undefined, component);
  2194. };
  2195. }
  2196. const devtoolsPerfStart = /*#__PURE__*/ createDevtoolsPerformanceHook("perf:start" /* DevtoolsHooks.PERFORMANCE_START */);
  2197. const devtoolsPerfEnd = /*#__PURE__*/ createDevtoolsPerformanceHook("perf:end" /* DevtoolsHooks.PERFORMANCE_END */);
  2198. function createDevtoolsPerformanceHook(hook) {
  2199. return (component, type, time) => {
  2200. emit(hook, component.appContext.app, component.uid, component, type, time);
  2201. };
  2202. }
  2203. function devtoolsComponentEmit(component, event, params) {
  2204. emit("component:emit" /* DevtoolsHooks.COMPONENT_EMIT */, component.appContext.app, component, event, params);
  2205. }
  2206. function emit$1(instance, event, ...rawArgs) {
  2207. if (instance.isUnmounted)
  2208. return;
  2209. const props = instance.vnode.props || EMPTY_OBJ;
  2210. {
  2211. const { emitsOptions, propsOptions: [propsOptions] } = instance;
  2212. if (emitsOptions) {
  2213. if (!(event in emitsOptions) &&
  2214. !(false )) {
  2215. if (!propsOptions || !(toHandlerKey(event) in propsOptions)) {
  2216. warn$1(`Component emitted event "${event}" but it is neither declared in ` +
  2217. `the emits option nor as an "${toHandlerKey(event)}" prop.`);
  2218. }
  2219. }
  2220. else {
  2221. const validator = emitsOptions[event];
  2222. if (isFunction(validator)) {
  2223. const isValid = validator(...rawArgs);
  2224. if (!isValid) {
  2225. warn$1(`Invalid event arguments: event validation failed for event "${event}".`);
  2226. }
  2227. }
  2228. }
  2229. }
  2230. }
  2231. let args = rawArgs;
  2232. const isModelListener = event.startsWith('update:');
  2233. // for v-model update:xxx events, apply modifiers on args
  2234. const modelArg = isModelListener && event.slice(7);
  2235. if (modelArg && modelArg in props) {
  2236. const modifiersKey = `${modelArg === 'modelValue' ? 'model' : modelArg}Modifiers`;
  2237. const { number, trim } = props[modifiersKey] || EMPTY_OBJ;
  2238. if (trim) {
  2239. args = rawArgs.map(a => (isString(a) ? a.trim() : a));
  2240. }
  2241. if (number) {
  2242. args = rawArgs.map(toNumber);
  2243. }
  2244. }
  2245. {
  2246. devtoolsComponentEmit(instance, event, args);
  2247. }
  2248. {
  2249. const lowerCaseEvent = event.toLowerCase();
  2250. if (lowerCaseEvent !== event && props[toHandlerKey(lowerCaseEvent)]) {
  2251. warn$1(`Event "${lowerCaseEvent}" is emitted in component ` +
  2252. `${formatComponentName(instance, instance.type)} but the handler is registered for "${event}". ` +
  2253. `Note that HTML attributes are case-insensitive and you cannot use ` +
  2254. `v-on to listen to camelCase events when using in-DOM templates. ` +
  2255. `You should probably use "${hyphenate(event)}" instead of "${event}".`);
  2256. }
  2257. }
  2258. let handlerName;
  2259. let handler = props[(handlerName = toHandlerKey(event))] ||
  2260. // also try camelCase event handler (#2249)
  2261. props[(handlerName = toHandlerKey(camelize(event)))];
  2262. // for v-model update:xxx events, also trigger kebab-case equivalent
  2263. // for props passed via kebab-case
  2264. if (!handler && isModelListener) {
  2265. handler = props[(handlerName = toHandlerKey(hyphenate(event)))];
  2266. }
  2267. if (handler) {
  2268. callWithAsyncErrorHandling(handler, instance, 6 /* ErrorCodes.COMPONENT_EVENT_HANDLER */, args);
  2269. }
  2270. const onceHandler = props[handlerName + `Once`];
  2271. if (onceHandler) {
  2272. if (!instance.emitted) {
  2273. instance.emitted = {};
  2274. }
  2275. else if (instance.emitted[handlerName]) {
  2276. return;
  2277. }
  2278. instance.emitted[handlerName] = true;
  2279. callWithAsyncErrorHandling(onceHandler, instance, 6 /* ErrorCodes.COMPONENT_EVENT_HANDLER */, args);
  2280. }
  2281. }
  2282. function normalizeEmitsOptions(comp, appContext, asMixin = false) {
  2283. const cache = appContext.emitsCache;
  2284. const cached = cache.get(comp);
  2285. if (cached !== undefined) {
  2286. return cached;
  2287. }
  2288. const raw = comp.emits;
  2289. let normalized = {};
  2290. // apply mixin/extends props
  2291. let hasExtends = false;
  2292. if (!isFunction(comp)) {
  2293. const extendEmits = (raw) => {
  2294. const normalizedFromExtend = normalizeEmitsOptions(raw, appContext, true);
  2295. if (normalizedFromExtend) {
  2296. hasExtends = true;
  2297. extend(normalized, normalizedFromExtend);
  2298. }
  2299. };
  2300. if (!asMixin && appContext.mixins.length) {
  2301. appContext.mixins.forEach(extendEmits);
  2302. }
  2303. if (comp.extends) {
  2304. extendEmits(comp.extends);
  2305. }
  2306. if (comp.mixins) {
  2307. comp.mixins.forEach(extendEmits);
  2308. }
  2309. }
  2310. if (!raw && !hasExtends) {
  2311. if (isObject(comp)) {
  2312. cache.set(comp, null);
  2313. }
  2314. return null;
  2315. }
  2316. if (isArray(raw)) {
  2317. raw.forEach(key => (normalized[key] = null));
  2318. }
  2319. else {
  2320. extend(normalized, raw);
  2321. }
  2322. if (isObject(comp)) {
  2323. cache.set(comp, normalized);
  2324. }
  2325. return normalized;
  2326. }
  2327. // Check if an incoming prop key is a declared emit event listener.
  2328. // e.g. With `emits: { click: null }`, props named `onClick` and `onclick` are
  2329. // both considered matched listeners.
  2330. function isEmitListener(options, key) {
  2331. if (!options || !isOn(key)) {
  2332. return false;
  2333. }
  2334. key = key.slice(2).replace(/Once$/, '');
  2335. return (hasOwn(options, key[0].toLowerCase() + key.slice(1)) ||
  2336. hasOwn(options, hyphenate(key)) ||
  2337. hasOwn(options, key));
  2338. }
  2339. /**
  2340. * mark the current rendering instance for asset resolution (e.g.
  2341. * resolveComponent, resolveDirective) during render
  2342. */
  2343. let currentRenderingInstance = null;
  2344. let currentScopeId = null;
  2345. /**
  2346. * Note: rendering calls maybe nested. The function returns the parent rendering
  2347. * instance if present, which should be restored after the render is done:
  2348. *
  2349. * ```js
  2350. * const prev = setCurrentRenderingInstance(i)
  2351. * // ...render
  2352. * setCurrentRenderingInstance(prev)
  2353. * ```
  2354. */
  2355. function setCurrentRenderingInstance(instance) {
  2356. const prev = currentRenderingInstance;
  2357. currentRenderingInstance = instance;
  2358. currentScopeId = (instance && instance.type.__scopeId) || null;
  2359. return prev;
  2360. }
  2361. /**
  2362. * Set scope id when creating hoisted vnodes.
  2363. * @private compiler helper
  2364. */
  2365. function pushScopeId(id) {
  2366. currentScopeId = id;
  2367. }
  2368. /**
  2369. * Technically we no longer need this after 3.0.8 but we need to keep the same
  2370. * API for backwards compat w/ code generated by compilers.
  2371. * @private
  2372. */
  2373. function popScopeId() {
  2374. currentScopeId = null;
  2375. }
  2376. /**
  2377. * Only for backwards compat
  2378. * @private
  2379. */
  2380. const withScopeId = (_id) => withCtx;
  2381. /**
  2382. * Wrap a slot function to memoize current rendering instance
  2383. * @private compiler helper
  2384. */
  2385. function withCtx(fn, ctx = currentRenderingInstance, isNonScopedSlot // false only
  2386. ) {
  2387. if (!ctx)
  2388. return fn;
  2389. // already normalized
  2390. if (fn._n) {
  2391. return fn;
  2392. }
  2393. const renderFnWithContext = (...args) => {
  2394. // If a user calls a compiled slot inside a template expression (#1745), it
  2395. // can mess up block tracking, so by default we disable block tracking and
  2396. // force bail out when invoking a compiled slot (indicated by the ._d flag).
  2397. // This isn't necessary if rendering a compiled `<slot>`, so we flip the
  2398. // ._d flag off when invoking the wrapped fn inside `renderSlot`.
  2399. if (renderFnWithContext._d) {
  2400. setBlockTracking(-1);
  2401. }
  2402. const prevInstance = setCurrentRenderingInstance(ctx);
  2403. let res;
  2404. try {
  2405. res = fn(...args);
  2406. }
  2407. finally {
  2408. setCurrentRenderingInstance(prevInstance);
  2409. if (renderFnWithContext._d) {
  2410. setBlockTracking(1);
  2411. }
  2412. }
  2413. {
  2414. devtoolsComponentUpdated(ctx);
  2415. }
  2416. return res;
  2417. };
  2418. // mark normalized to avoid duplicated wrapping
  2419. renderFnWithContext._n = true;
  2420. // mark this as compiled by default
  2421. // this is used in vnode.ts -> normalizeChildren() to set the slot
  2422. // rendering flag.
  2423. renderFnWithContext._c = true;
  2424. // disable block tracking by default
  2425. renderFnWithContext._d = true;
  2426. return renderFnWithContext;
  2427. }
  2428. /**
  2429. * dev only flag to track whether $attrs was used during render.
  2430. * If $attrs was used during render then the warning for failed attrs
  2431. * fallthrough can be suppressed.
  2432. */
  2433. let accessedAttrs = false;
  2434. function markAttrsAccessed() {
  2435. accessedAttrs = true;
  2436. }
  2437. function renderComponentRoot(instance) {
  2438. const { type: Component, vnode, proxy, withProxy, props, propsOptions: [propsOptions], slots, attrs, emit, render, renderCache, data, setupState, ctx, inheritAttrs } = instance;
  2439. let result;
  2440. let fallthroughAttrs;
  2441. const prev = setCurrentRenderingInstance(instance);
  2442. {
  2443. accessedAttrs = false;
  2444. }
  2445. try {
  2446. if (vnode.shapeFlag & 4 /* ShapeFlags.STATEFUL_COMPONENT */) {
  2447. // withProxy is a proxy with a different `has` trap only for
  2448. // runtime-compiled render functions using `with` block.
  2449. const proxyToUse = withProxy || proxy;
  2450. result = normalizeVNode(render.call(proxyToUse, proxyToUse, renderCache, props, setupState, data, ctx));
  2451. fallthroughAttrs = attrs;
  2452. }
  2453. else {
  2454. // functional
  2455. const render = Component;
  2456. // in dev, mark attrs accessed if optional props (attrs === props)
  2457. if (true && attrs === props) {
  2458. markAttrsAccessed();
  2459. }
  2460. result = normalizeVNode(render.length > 1
  2461. ? render(props, true
  2462. ? {
  2463. get attrs() {
  2464. markAttrsAccessed();
  2465. return attrs;
  2466. },
  2467. slots,
  2468. emit
  2469. }
  2470. : { attrs, slots, emit })
  2471. : render(props, null /* we know it doesn't need it */));
  2472. fallthroughAttrs = Component.props
  2473. ? attrs
  2474. : getFunctionalFallthrough(attrs);
  2475. }
  2476. }
  2477. catch (err) {
  2478. blockStack.length = 0;
  2479. handleError(err, instance, 1 /* ErrorCodes.RENDER_FUNCTION */);
  2480. result = createVNode(Comment);
  2481. }
  2482. // attr merging
  2483. // in dev mode, comments are preserved, and it's possible for a template
  2484. // to have comments along side the root element which makes it a fragment
  2485. let root = result;
  2486. let setRoot = undefined;
  2487. if (result.patchFlag > 0 &&
  2488. result.patchFlag & 2048 /* PatchFlags.DEV_ROOT_FRAGMENT */) {
  2489. [root, setRoot] = getChildRoot(result);
  2490. }
  2491. if (fallthroughAttrs && inheritAttrs !== false) {
  2492. const keys = Object.keys(fallthroughAttrs);
  2493. const { shapeFlag } = root;
  2494. if (keys.length) {
  2495. if (shapeFlag & (1 /* ShapeFlags.ELEMENT */ | 6 /* ShapeFlags.COMPONENT */)) {
  2496. if (propsOptions && keys.some(isModelListener)) {
  2497. // If a v-model listener (onUpdate:xxx) has a corresponding declared
  2498. // prop, it indicates this component expects to handle v-model and
  2499. // it should not fallthrough.
  2500. // related: #1543, #1643, #1989
  2501. fallthroughAttrs = filterModelListeners(fallthroughAttrs, propsOptions);
  2502. }
  2503. root = cloneVNode(root, fallthroughAttrs);
  2504. }
  2505. else if (!accessedAttrs && root.type !== Comment) {
  2506. const allAttrs = Object.keys(attrs);
  2507. const eventAttrs = [];
  2508. const extraAttrs = [];
  2509. for (let i = 0, l = allAttrs.length; i < l; i++) {
  2510. const key = allAttrs[i];
  2511. if (isOn(key)) {
  2512. // ignore v-model handlers when they fail to fallthrough
  2513. if (!isModelListener(key)) {
  2514. // remove `on`, lowercase first letter to reflect event casing
  2515. // accurately
  2516. eventAttrs.push(key[2].toLowerCase() + key.slice(3));
  2517. }
  2518. }
  2519. else {
  2520. extraAttrs.push(key);
  2521. }
  2522. }
  2523. if (extraAttrs.length) {
  2524. warn$1(`Extraneous non-props attributes (` +
  2525. `${extraAttrs.join(', ')}) ` +
  2526. `were passed to component but could not be automatically inherited ` +
  2527. `because component renders fragment or text root nodes.`);
  2528. }
  2529. if (eventAttrs.length) {
  2530. warn$1(`Extraneous non-emits event listeners (` +
  2531. `${eventAttrs.join(', ')}) ` +
  2532. `were passed to component but could not be automatically inherited ` +
  2533. `because component renders fragment or text root nodes. ` +
  2534. `If the listener is intended to be a component custom event listener only, ` +
  2535. `declare it using the "emits" option.`);
  2536. }
  2537. }
  2538. }
  2539. }
  2540. // inherit directives
  2541. if (vnode.dirs) {
  2542. if (!isElementRoot(root)) {
  2543. warn$1(`Runtime directive used on component with non-element root node. ` +
  2544. `The directives will not function as intended.`);
  2545. }
  2546. // clone before mutating since the root may be a hoisted vnode
  2547. root = cloneVNode(root);
  2548. root.dirs = root.dirs ? root.dirs.concat(vnode.dirs) : vnode.dirs;
  2549. }
  2550. // inherit transition data
  2551. if (vnode.transition) {
  2552. if (!isElementRoot(root)) {
  2553. warn$1(`Component inside <Transition> renders non-element root node ` +
  2554. `that cannot be animated.`);
  2555. }
  2556. root.transition = vnode.transition;
  2557. }
  2558. if (setRoot) {
  2559. setRoot(root);
  2560. }
  2561. else {
  2562. result = root;
  2563. }
  2564. setCurrentRenderingInstance(prev);
  2565. return result;
  2566. }
  2567. /**
  2568. * dev only
  2569. * In dev mode, template root level comments are rendered, which turns the
  2570. * template into a fragment root, but we need to locate the single element
  2571. * root for attrs and scope id processing.
  2572. */
  2573. const getChildRoot = (vnode) => {
  2574. const rawChildren = vnode.children;
  2575. const dynamicChildren = vnode.dynamicChildren;
  2576. const childRoot = filterSingleRoot(rawChildren);
  2577. if (!childRoot) {
  2578. return [vnode, undefined];
  2579. }
  2580. const index = rawChildren.indexOf(childRoot);
  2581. const dynamicIndex = dynamicChildren ? dynamicChildren.indexOf(childRoot) : -1;
  2582. const setRoot = (updatedRoot) => {
  2583. rawChildren[index] = updatedRoot;
  2584. if (dynamicChildren) {
  2585. if (dynamicIndex > -1) {
  2586. dynamicChildren[dynamicIndex] = updatedRoot;
  2587. }
  2588. else if (updatedRoot.patchFlag > 0) {
  2589. vnode.dynamicChildren = [...dynamicChildren, updatedRoot];
  2590. }
  2591. }
  2592. };
  2593. return [normalizeVNode(childRoot), setRoot];
  2594. };
  2595. function filterSingleRoot(children) {
  2596. let singleRoot;
  2597. for (let i = 0; i < children.length; i++) {
  2598. const child = children[i];
  2599. if (isVNode(child)) {
  2600. // ignore user comment
  2601. if (child.type !== Comment || child.children === 'v-if') {
  2602. if (singleRoot) {
  2603. // has more than 1 non-comment child, return now
  2604. return;
  2605. }
  2606. else {
  2607. singleRoot = child;
  2608. }
  2609. }
  2610. }
  2611. else {
  2612. return;
  2613. }
  2614. }
  2615. return singleRoot;
  2616. }
  2617. const getFunctionalFallthrough = (attrs) => {
  2618. let res;
  2619. for (const key in attrs) {
  2620. if (key === 'class' || key === 'style' || isOn(key)) {
  2621. (res || (res = {}))[key] = attrs[key];
  2622. }
  2623. }
  2624. return res;
  2625. };
  2626. const filterModelListeners = (attrs, props) => {
  2627. const res = {};
  2628. for (const key in attrs) {
  2629. if (!isModelListener(key) || !(key.slice(9) in props)) {
  2630. res[key] = attrs[key];
  2631. }
  2632. }
  2633. return res;
  2634. };
  2635. const isElementRoot = (vnode) => {
  2636. return (vnode.shapeFlag & (6 /* ShapeFlags.COMPONENT */ | 1 /* ShapeFlags.ELEMENT */) ||
  2637. vnode.type === Comment // potential v-if branch switch
  2638. );
  2639. };
  2640. function shouldUpdateComponent(prevVNode, nextVNode, optimized) {
  2641. const { props: prevProps, children: prevChildren, component } = prevVNode;
  2642. const { props: nextProps, children: nextChildren, patchFlag } = nextVNode;
  2643. const emits = component.emitsOptions;
  2644. // Parent component's render function was hot-updated. Since this may have
  2645. // caused the child component's slots content to have changed, we need to
  2646. // force the child to update as well.
  2647. if ((prevChildren || nextChildren) && isHmrUpdating) {
  2648. return true;
  2649. }
  2650. // force child update for runtime directive or transition on component vnode.
  2651. if (nextVNode.dirs || nextVNode.transition) {
  2652. return true;
  2653. }
  2654. if (optimized && patchFlag >= 0) {
  2655. if (patchFlag & 1024 /* PatchFlags.DYNAMIC_SLOTS */) {
  2656. // slot content that references values that might have changed,
  2657. // e.g. in a v-for
  2658. return true;
  2659. }
  2660. if (patchFlag & 16 /* PatchFlags.FULL_PROPS */) {
  2661. if (!prevProps) {
  2662. return !!nextProps;
  2663. }
  2664. // presence of this flag indicates props are always non-null
  2665. return hasPropsChanged(prevProps, nextProps, emits);
  2666. }
  2667. else if (patchFlag & 8 /* PatchFlags.PROPS */) {
  2668. const dynamicProps = nextVNode.dynamicProps;
  2669. for (let i = 0; i < dynamicProps.length; i++) {
  2670. const key = dynamicProps[i];
  2671. if (nextProps[key] !== prevProps[key] &&
  2672. !isEmitListener(emits, key)) {
  2673. return true;
  2674. }
  2675. }
  2676. }
  2677. }
  2678. else {
  2679. // this path is only taken by manually written render functions
  2680. // so presence of any children leads to a forced update
  2681. if (prevChildren || nextChildren) {
  2682. if (!nextChildren || !nextChildren.$stable) {
  2683. return true;
  2684. }
  2685. }
  2686. if (prevProps === nextProps) {
  2687. return false;
  2688. }
  2689. if (!prevProps) {
  2690. return !!nextProps;
  2691. }
  2692. if (!nextProps) {
  2693. return true;
  2694. }
  2695. return hasPropsChanged(prevProps, nextProps, emits);
  2696. }
  2697. return false;
  2698. }
  2699. function hasPropsChanged(prevProps, nextProps, emitsOptions) {
  2700. const nextKeys = Object.keys(nextProps);
  2701. if (nextKeys.length !== Object.keys(prevProps).length) {
  2702. return true;
  2703. }
  2704. for (let i = 0; i < nextKeys.length; i++) {
  2705. const key = nextKeys[i];
  2706. if (nextProps[key] !== prevProps[key] &&
  2707. !isEmitListener(emitsOptions, key)) {
  2708. return true;
  2709. }
  2710. }
  2711. return false;
  2712. }
  2713. function updateHOCHostEl({ vnode, parent }, el // HostNode
  2714. ) {
  2715. while (parent && parent.subTree === vnode) {
  2716. (vnode = parent.vnode).el = el;
  2717. parent = parent.parent;
  2718. }
  2719. }
  2720. const isSuspense = (type) => type.__isSuspense;
  2721. // Suspense exposes a component-like API, and is treated like a component
  2722. // in the compiler, but internally it's a special built-in type that hooks
  2723. // directly into the renderer.
  2724. const SuspenseImpl = {
  2725. name: 'Suspense',
  2726. // In order to make Suspense tree-shakable, we need to avoid importing it
  2727. // directly in the renderer. The renderer checks for the __isSuspense flag
  2728. // on a vnode's type and calls the `process` method, passing in renderer
  2729. // internals.
  2730. __isSuspense: true,
  2731. process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized,
  2732. // platform-specific impl passed from renderer
  2733. rendererInternals) {
  2734. if (n1 == null) {
  2735. mountSuspense(n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, rendererInternals);
  2736. }
  2737. else {
  2738. patchSuspense(n1, n2, container, anchor, parentComponent, isSVG, slotScopeIds, optimized, rendererInternals);
  2739. }
  2740. },
  2741. hydrate: hydrateSuspense,
  2742. create: createSuspenseBoundary,
  2743. normalize: normalizeSuspenseChildren
  2744. };
  2745. // Force-casted public typing for h and TSX props inference
  2746. const Suspense = (SuspenseImpl
  2747. );
  2748. function triggerEvent(vnode, name) {
  2749. const eventListener = vnode.props && vnode.props[name];
  2750. if (isFunction(eventListener)) {
  2751. eventListener();
  2752. }
  2753. }
  2754. function mountSuspense(vnode, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, rendererInternals) {
  2755. const { p: patch, o: { createElement } } = rendererInternals;
  2756. const hiddenContainer = createElement('div');
  2757. const suspense = (vnode.suspense = createSuspenseBoundary(vnode, parentSuspense, parentComponent, container, hiddenContainer, anchor, isSVG, slotScopeIds, optimized, rendererInternals));
  2758. // start mounting the content subtree in an off-dom container
  2759. patch(null, (suspense.pendingBranch = vnode.ssContent), hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds);
  2760. // now check if we have encountered any async deps
  2761. if (suspense.deps > 0) {
  2762. // has async
  2763. // invoke @fallback event
  2764. triggerEvent(vnode, 'onPending');
  2765. triggerEvent(vnode, 'onFallback');
  2766. // mount the fallback tree
  2767. patch(null, vnode.ssFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2768. isSVG, slotScopeIds);
  2769. setActiveBranch(suspense, vnode.ssFallback);
  2770. }
  2771. else {
  2772. // Suspense has no async deps. Just resolve.
  2773. suspense.resolve();
  2774. }
  2775. }
  2776. function patchSuspense(n1, n2, container, anchor, parentComponent, isSVG, slotScopeIds, optimized, { p: patch, um: unmount, o: { createElement } }) {
  2777. const suspense = (n2.suspense = n1.suspense);
  2778. suspense.vnode = n2;
  2779. n2.el = n1.el;
  2780. const newBranch = n2.ssContent;
  2781. const newFallback = n2.ssFallback;
  2782. const { activeBranch, pendingBranch, isInFallback, isHydrating } = suspense;
  2783. if (pendingBranch) {
  2784. suspense.pendingBranch = newBranch;
  2785. if (isSameVNodeType(newBranch, pendingBranch)) {
  2786. // same root type but content may have changed.
  2787. patch(pendingBranch, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2788. if (suspense.deps <= 0) {
  2789. suspense.resolve();
  2790. }
  2791. else if (isInFallback) {
  2792. patch(activeBranch, newFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2793. isSVG, slotScopeIds, optimized);
  2794. setActiveBranch(suspense, newFallback);
  2795. }
  2796. }
  2797. else {
  2798. // toggled before pending tree is resolved
  2799. suspense.pendingId++;
  2800. if (isHydrating) {
  2801. // if toggled before hydration is finished, the current DOM tree is
  2802. // no longer valid. set it as the active branch so it will be unmounted
  2803. // when resolved
  2804. suspense.isHydrating = false;
  2805. suspense.activeBranch = pendingBranch;
  2806. }
  2807. else {
  2808. unmount(pendingBranch, parentComponent, suspense);
  2809. }
  2810. // increment pending ID. this is used to invalidate async callbacks
  2811. // reset suspense state
  2812. suspense.deps = 0;
  2813. // discard effects from pending branch
  2814. suspense.effects.length = 0;
  2815. // discard previous container
  2816. suspense.hiddenContainer = createElement('div');
  2817. if (isInFallback) {
  2818. // already in fallback state
  2819. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2820. if (suspense.deps <= 0) {
  2821. suspense.resolve();
  2822. }
  2823. else {
  2824. patch(activeBranch, newFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2825. isSVG, slotScopeIds, optimized);
  2826. setActiveBranch(suspense, newFallback);
  2827. }
  2828. }
  2829. else if (activeBranch && isSameVNodeType(newBranch, activeBranch)) {
  2830. // toggled "back" to current active branch
  2831. patch(activeBranch, newBranch, container, anchor, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2832. // force resolve
  2833. suspense.resolve(true);
  2834. }
  2835. else {
  2836. // switched to a 3rd branch
  2837. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2838. if (suspense.deps <= 0) {
  2839. suspense.resolve();
  2840. }
  2841. }
  2842. }
  2843. }
  2844. else {
  2845. if (activeBranch && isSameVNodeType(newBranch, activeBranch)) {
  2846. // root did not change, just normal patch
  2847. patch(activeBranch, newBranch, container, anchor, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2848. setActiveBranch(suspense, newBranch);
  2849. }
  2850. else {
  2851. // root node toggled
  2852. // invoke @pending event
  2853. triggerEvent(n2, 'onPending');
  2854. // mount pending branch in off-dom container
  2855. suspense.pendingBranch = newBranch;
  2856. suspense.pendingId++;
  2857. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2858. if (suspense.deps <= 0) {
  2859. // incoming branch has no async deps, resolve now.
  2860. suspense.resolve();
  2861. }
  2862. else {
  2863. const { timeout, pendingId } = suspense;
  2864. if (timeout > 0) {
  2865. setTimeout(() => {
  2866. if (suspense.pendingId === pendingId) {
  2867. suspense.fallback(newFallback);
  2868. }
  2869. }, timeout);
  2870. }
  2871. else if (timeout === 0) {
  2872. suspense.fallback(newFallback);
  2873. }
  2874. }
  2875. }
  2876. }
  2877. }
  2878. let hasWarned = false;
  2879. function createSuspenseBoundary(vnode, parent, parentComponent, container, hiddenContainer, anchor, isSVG, slotScopeIds, optimized, rendererInternals, isHydrating = false) {
  2880. /* istanbul ignore if */
  2881. if (!hasWarned) {
  2882. hasWarned = true;
  2883. // @ts-ignore `console.info` cannot be null error
  2884. console[console.info ? 'info' : 'log'](`<Suspense> is an experimental feature and its API will likely change.`);
  2885. }
  2886. const { p: patch, m: move, um: unmount, n: next, o: { parentNode, remove } } = rendererInternals;
  2887. const timeout = toNumber(vnode.props && vnode.props.timeout);
  2888. const suspense = {
  2889. vnode,
  2890. parent,
  2891. parentComponent,
  2892. isSVG,
  2893. container,
  2894. hiddenContainer,
  2895. anchor,
  2896. deps: 0,
  2897. pendingId: 0,
  2898. timeout: typeof timeout === 'number' ? timeout : -1,
  2899. activeBranch: null,
  2900. pendingBranch: null,
  2901. isInFallback: true,
  2902. isHydrating,
  2903. isUnmounted: false,
  2904. effects: [],
  2905. resolve(resume = false) {
  2906. {
  2907. if (!resume && !suspense.pendingBranch) {
  2908. throw new Error(`suspense.resolve() is called without a pending branch.`);
  2909. }
  2910. if (suspense.isUnmounted) {
  2911. throw new Error(`suspense.resolve() is called on an already unmounted suspense boundary.`);
  2912. }
  2913. }
  2914. const { vnode, activeBranch, pendingBranch, pendingId, effects, parentComponent, container } = suspense;
  2915. if (suspense.isHydrating) {
  2916. suspense.isHydrating = false;
  2917. }
  2918. else if (!resume) {
  2919. const delayEnter = activeBranch &&
  2920. pendingBranch.transition &&
  2921. pendingBranch.transition.mode === 'out-in';
  2922. if (delayEnter) {
  2923. activeBranch.transition.afterLeave = () => {
  2924. if (pendingId === suspense.pendingId) {
  2925. move(pendingBranch, container, anchor, 0 /* MoveType.ENTER */);
  2926. }
  2927. };
  2928. }
  2929. // this is initial anchor on mount
  2930. let { anchor } = suspense;
  2931. // unmount current active tree
  2932. if (activeBranch) {
  2933. // if the fallback tree was mounted, it may have been moved
  2934. // as part of a parent suspense. get the latest anchor for insertion
  2935. anchor = next(activeBranch);
  2936. unmount(activeBranch, parentComponent, suspense, true);
  2937. }
  2938. if (!delayEnter) {
  2939. // move content from off-dom container to actual container
  2940. move(pendingBranch, container, anchor, 0 /* MoveType.ENTER */);
  2941. }
  2942. }
  2943. setActiveBranch(suspense, pendingBranch);
  2944. suspense.pendingBranch = null;
  2945. suspense.isInFallback = false;
  2946. // flush buffered effects
  2947. // check if there is a pending parent suspense
  2948. let parent = suspense.parent;
  2949. let hasUnresolvedAncestor = false;
  2950. while (parent) {
  2951. if (parent.pendingBranch) {
  2952. // found a pending parent suspense, merge buffered post jobs
  2953. // into that parent
  2954. parent.effects.push(...effects);
  2955. hasUnresolvedAncestor = true;
  2956. break;
  2957. }
  2958. parent = parent.parent;
  2959. }
  2960. // no pending parent suspense, flush all jobs
  2961. if (!hasUnresolvedAncestor) {
  2962. queuePostFlushCb(effects);
  2963. }
  2964. suspense.effects = [];
  2965. // invoke @resolve event
  2966. triggerEvent(vnode, 'onResolve');
  2967. },
  2968. fallback(fallbackVNode) {
  2969. if (!suspense.pendingBranch) {
  2970. return;
  2971. }
  2972. const { vnode, activeBranch, parentComponent, container, isSVG } = suspense;
  2973. // invoke @fallback event
  2974. triggerEvent(vnode, 'onFallback');
  2975. const anchor = next(activeBranch);
  2976. const mountFallback = () => {
  2977. if (!suspense.isInFallback) {
  2978. return;
  2979. }
  2980. // mount the fallback tree
  2981. patch(null, fallbackVNode, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2982. isSVG, slotScopeIds, optimized);
  2983. setActiveBranch(suspense, fallbackVNode);
  2984. };
  2985. const delayEnter = fallbackVNode.transition && fallbackVNode.transition.mode === 'out-in';
  2986. if (delayEnter) {
  2987. activeBranch.transition.afterLeave = mountFallback;
  2988. }
  2989. suspense.isInFallback = true;
  2990. // unmount current active branch
  2991. unmount(activeBranch, parentComponent, null, // no suspense so unmount hooks fire now
  2992. true // shouldRemove
  2993. );
  2994. if (!delayEnter) {
  2995. mountFallback();
  2996. }
  2997. },
  2998. move(container, anchor, type) {
  2999. suspense.activeBranch &&
  3000. move(suspense.activeBranch, container, anchor, type);
  3001. suspense.container = container;
  3002. },
  3003. next() {
  3004. return suspense.activeBranch && next(suspense.activeBranch);
  3005. },
  3006. registerDep(instance, setupRenderEffect) {
  3007. const isInPendingSuspense = !!suspense.pendingBranch;
  3008. if (isInPendingSuspense) {
  3009. suspense.deps++;
  3010. }
  3011. const hydratedEl = instance.vnode.el;
  3012. instance
  3013. .asyncDep.catch(err => {
  3014. handleError(err, instance, 0 /* ErrorCodes.SETUP_FUNCTION */);
  3015. })
  3016. .then(asyncSetupResult => {
  3017. // retry when the setup() promise resolves.
  3018. // component may have been unmounted before resolve.
  3019. if (instance.isUnmounted ||
  3020. suspense.isUnmounted ||
  3021. suspense.pendingId !== instance.suspenseId) {
  3022. return;
  3023. }
  3024. // retry from this component
  3025. instance.asyncResolved = true;
  3026. const { vnode } = instance;
  3027. {
  3028. pushWarningContext(vnode);
  3029. }
  3030. handleSetupResult(instance, asyncSetupResult, false);
  3031. if (hydratedEl) {
  3032. // vnode may have been replaced if an update happened before the
  3033. // async dep is resolved.
  3034. vnode.el = hydratedEl;
  3035. }
  3036. const placeholder = !hydratedEl && instance.subTree.el;
  3037. setupRenderEffect(instance, vnode,
  3038. // component may have been moved before resolve.
  3039. // if this is not a hydration, instance.subTree will be the comment
  3040. // placeholder.
  3041. parentNode(hydratedEl || instance.subTree.el),
  3042. // anchor will not be used if this is hydration, so only need to
  3043. // consider the comment placeholder case.
  3044. hydratedEl ? null : next(instance.subTree), suspense, isSVG, optimized);
  3045. if (placeholder) {
  3046. remove(placeholder);
  3047. }
  3048. updateHOCHostEl(instance, vnode.el);
  3049. {
  3050. popWarningContext();
  3051. }
  3052. // only decrease deps count if suspense is not already resolved
  3053. if (isInPendingSuspense && --suspense.deps === 0) {
  3054. suspense.resolve();
  3055. }
  3056. });
  3057. },
  3058. unmount(parentSuspense, doRemove) {
  3059. suspense.isUnmounted = true;
  3060. if (suspense.activeBranch) {
  3061. unmount(suspense.activeBranch, parentComponent, parentSuspense, doRemove);
  3062. }
  3063. if (suspense.pendingBranch) {
  3064. unmount(suspense.pendingBranch, parentComponent, parentSuspense, doRemove);
  3065. }
  3066. }
  3067. };
  3068. return suspense;
  3069. }
  3070. function hydrateSuspense(node, vnode, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, rendererInternals, hydrateNode) {
  3071. /* eslint-disable no-restricted-globals */
  3072. const suspense = (vnode.suspense = createSuspenseBoundary(vnode, parentSuspense, parentComponent, node.parentNode, document.createElement('div'), null, isSVG, slotScopeIds, optimized, rendererInternals, true /* hydrating */));
  3073. // there are two possible scenarios for server-rendered suspense:
  3074. // - success: ssr content should be fully resolved
  3075. // - failure: ssr content should be the fallback branch.
  3076. // however, on the client we don't really know if it has failed or not
  3077. // attempt to hydrate the DOM assuming it has succeeded, but we still
  3078. // need to construct a suspense boundary first
  3079. const result = hydrateNode(node, (suspense.pendingBranch = vnode.ssContent), parentComponent, suspense, slotScopeIds, optimized);
  3080. if (suspense.deps === 0) {
  3081. suspense.resolve();
  3082. }
  3083. return result;
  3084. /* eslint-enable no-restricted-globals */
  3085. }
  3086. function normalizeSuspenseChildren(vnode) {
  3087. const { shapeFlag, children } = vnode;
  3088. const isSlotChildren = shapeFlag & 32 /* ShapeFlags.SLOTS_CHILDREN */;
  3089. vnode.ssContent = normalizeSuspenseSlot(isSlotChildren ? children.default : children);
  3090. vnode.ssFallback = isSlotChildren
  3091. ? normalizeSuspenseSlot(children.fallback)
  3092. : createVNode(Comment);
  3093. }
  3094. function normalizeSuspenseSlot(s) {
  3095. let block;
  3096. if (isFunction(s)) {
  3097. const trackBlock = isBlockTreeEnabled && s._c;
  3098. if (trackBlock) {
  3099. // disableTracking: false
  3100. // allow block tracking for compiled slots
  3101. // (see ./componentRenderContext.ts)
  3102. s._d = false;
  3103. openBlock();
  3104. }
  3105. s = s();
  3106. if (trackBlock) {
  3107. s._d = true;
  3108. block = currentBlock;
  3109. closeBlock();
  3110. }
  3111. }
  3112. if (isArray(s)) {
  3113. const singleChild = filterSingleRoot(s);
  3114. if (!singleChild) {
  3115. warn$1(`<Suspense> slots expect a single root node.`);
  3116. }
  3117. s = singleChild;
  3118. }
  3119. s = normalizeVNode(s);
  3120. if (block && !s.dynamicChildren) {
  3121. s.dynamicChildren = block.filter(c => c !== s);
  3122. }
  3123. return s;
  3124. }
  3125. function queueEffectWithSuspense(fn, suspense) {
  3126. if (suspense && suspense.pendingBranch) {
  3127. if (isArray(fn)) {
  3128. suspense.effects.push(...fn);
  3129. }
  3130. else {
  3131. suspense.effects.push(fn);
  3132. }
  3133. }
  3134. else {
  3135. queuePostFlushCb(fn);
  3136. }
  3137. }
  3138. function setActiveBranch(suspense, branch) {
  3139. suspense.activeBranch = branch;
  3140. const { vnode, parentComponent } = suspense;
  3141. const el = (vnode.el = branch.el);
  3142. // in case suspense is the root node of a component,
  3143. // recursively update the HOC el
  3144. if (parentComponent && parentComponent.subTree === vnode) {
  3145. parentComponent.vnode.el = el;
  3146. updateHOCHostEl(parentComponent, el);
  3147. }
  3148. }
  3149. function provide(key, value) {
  3150. if (!currentInstance) {
  3151. {
  3152. warn$1(`provide() can only be used inside setup().`);
  3153. }
  3154. }
  3155. else {
  3156. let provides = currentInstance.provides;
  3157. // by default an instance inherits its parent's provides object
  3158. // but when it needs to provide values of its own, it creates its
  3159. // own provides object using parent provides object as prototype.
  3160. // this way in `inject` we can simply look up injections from direct
  3161. // parent and let the prototype chain do the work.
  3162. const parentProvides = currentInstance.parent && currentInstance.parent.provides;
  3163. if (parentProvides === provides) {
  3164. provides = currentInstance.provides = Object.create(parentProvides);
  3165. }
  3166. // TS doesn't allow symbol as index type
  3167. provides[key] = value;
  3168. }
  3169. }
  3170. function inject(key, defaultValue, treatDefaultAsFactory = false) {
  3171. // fallback to `currentRenderingInstance` so that this can be called in
  3172. // a functional component
  3173. const instance = currentInstance || currentRenderingInstance;
  3174. if (instance) {
  3175. // #2400
  3176. // to support `app.use` plugins,
  3177. // fallback to appContext's `provides` if the instance is at root
  3178. const provides = instance.parent == null
  3179. ? instance.vnode.appContext && instance.vnode.appContext.provides
  3180. : instance.parent.provides;
  3181. if (provides && key in provides) {
  3182. // TS doesn't allow symbol as index type
  3183. return provides[key];
  3184. }
  3185. else if (arguments.length > 1) {
  3186. return treatDefaultAsFactory && isFunction(defaultValue)
  3187. ? defaultValue.call(instance.proxy)
  3188. : defaultValue;
  3189. }
  3190. else {
  3191. warn$1(`injection "${String(key)}" not found.`);
  3192. }
  3193. }
  3194. else {
  3195. warn$1(`inject() can only be used inside setup() or functional components.`);
  3196. }
  3197. }
  3198. // Simple effect.
  3199. function watchEffect(effect, options) {
  3200. return doWatch(effect, null, options);
  3201. }
  3202. function watchPostEffect(effect, options) {
  3203. return doWatch(effect, null, (Object.assign(Object.assign({}, options), { flush: 'post' }) ));
  3204. }
  3205. function watchSyncEffect(effect, options) {
  3206. return doWatch(effect, null, (Object.assign(Object.assign({}, options), { flush: 'sync' }) ));
  3207. }
  3208. // initial value for watchers to trigger on undefined initial values
  3209. const INITIAL_WATCHER_VALUE = {};
  3210. // implementation
  3211. function watch(source, cb, options) {
  3212. if (!isFunction(cb)) {
  3213. warn$1(`\`watch(fn, options?)\` signature has been moved to a separate API. ` +
  3214. `Use \`watchEffect(fn, options?)\` instead. \`watch\` now only ` +
  3215. `supports \`watch(source, cb, options?) signature.`);
  3216. }
  3217. return doWatch(source, cb, options);
  3218. }
  3219. function doWatch(source, cb, { immediate, deep, flush, onTrack, onTrigger } = EMPTY_OBJ) {
  3220. if (!cb) {
  3221. if (immediate !== undefined) {
  3222. warn$1(`watch() "immediate" option is only respected when using the ` +
  3223. `watch(source, callback, options?) signature.`);
  3224. }
  3225. if (deep !== undefined) {
  3226. warn$1(`watch() "deep" option is only respected when using the ` +
  3227. `watch(source, callback, options?) signature.`);
  3228. }
  3229. }
  3230. const warnInvalidSource = (s) => {
  3231. warn$1(`Invalid watch source: `, s, `A watch source can only be a getter/effect function, a ref, ` +
  3232. `a reactive object, or an array of these types.`);
  3233. };
  3234. const instance = currentInstance;
  3235. let getter;
  3236. let forceTrigger = false;
  3237. let isMultiSource = false;
  3238. if (isRef(source)) {
  3239. getter = () => source.value;
  3240. forceTrigger = isShallow(source);
  3241. }
  3242. else if (isReactive(source)) {
  3243. getter = () => source;
  3244. deep = true;
  3245. }
  3246. else if (isArray(source)) {
  3247. isMultiSource = true;
  3248. forceTrigger = source.some(s => isReactive(s) || isShallow(s));
  3249. getter = () => source.map(s => {
  3250. if (isRef(s)) {
  3251. return s.value;
  3252. }
  3253. else if (isReactive(s)) {
  3254. return traverse(s);
  3255. }
  3256. else if (isFunction(s)) {
  3257. return callWithErrorHandling(s, instance, 2 /* ErrorCodes.WATCH_GETTER */);
  3258. }
  3259. else {
  3260. warnInvalidSource(s);
  3261. }
  3262. });
  3263. }
  3264. else if (isFunction(source)) {
  3265. if (cb) {
  3266. // getter with cb
  3267. getter = () => callWithErrorHandling(source, instance, 2 /* ErrorCodes.WATCH_GETTER */);
  3268. }
  3269. else {
  3270. // no cb -> simple effect
  3271. getter = () => {
  3272. if (instance && instance.isUnmounted) {
  3273. return;
  3274. }
  3275. if (cleanup) {
  3276. cleanup();
  3277. }
  3278. return callWithAsyncErrorHandling(source, instance, 3 /* ErrorCodes.WATCH_CALLBACK */, [onCleanup]);
  3279. };
  3280. }
  3281. }
  3282. else {
  3283. getter = NOOP;
  3284. warnInvalidSource(source);
  3285. }
  3286. if (cb && deep) {
  3287. const baseGetter = getter;
  3288. getter = () => traverse(baseGetter());
  3289. }
  3290. let cleanup;
  3291. let onCleanup = (fn) => {
  3292. cleanup = effect.onStop = () => {
  3293. callWithErrorHandling(fn, instance, 4 /* ErrorCodes.WATCH_CLEANUP */);
  3294. };
  3295. };
  3296. let oldValue = isMultiSource
  3297. ? new Array(source.length).fill(INITIAL_WATCHER_VALUE)
  3298. : INITIAL_WATCHER_VALUE;
  3299. const job = () => {
  3300. if (!effect.active) {
  3301. return;
  3302. }
  3303. if (cb) {
  3304. // watch(source, cb)
  3305. const newValue = effect.run();
  3306. if (deep ||
  3307. forceTrigger ||
  3308. (isMultiSource
  3309. ? newValue.some((v, i) => hasChanged(v, oldValue[i]))
  3310. : hasChanged(newValue, oldValue)) ||
  3311. (false )) {
  3312. // cleanup before running cb again
  3313. if (cleanup) {
  3314. cleanup();
  3315. }
  3316. callWithAsyncErrorHandling(cb, instance, 3 /* ErrorCodes.WATCH_CALLBACK */, [
  3317. newValue,
  3318. // pass undefined as the old value when it's changed for the first time
  3319. oldValue === INITIAL_WATCHER_VALUE
  3320. ? undefined
  3321. : (isMultiSource && oldValue[0] === INITIAL_WATCHER_VALUE)
  3322. ? []
  3323. : oldValue,
  3324. onCleanup
  3325. ]);
  3326. oldValue = newValue;
  3327. }
  3328. }
  3329. else {
  3330. // watchEffect
  3331. effect.run();
  3332. }
  3333. };
  3334. // important: mark the job as a watcher callback so that scheduler knows
  3335. // it is allowed to self-trigger (#1727)
  3336. job.allowRecurse = !!cb;
  3337. let scheduler;
  3338. if (flush === 'sync') {
  3339. scheduler = job; // the scheduler function gets called directly
  3340. }
  3341. else if (flush === 'post') {
  3342. scheduler = () => queuePostRenderEffect(job, instance && instance.suspense);
  3343. }
  3344. else {
  3345. // default: 'pre'
  3346. job.pre = true;
  3347. if (instance)
  3348. job.id = instance.uid;
  3349. scheduler = () => queueJob(job);
  3350. }
  3351. const effect = new ReactiveEffect(getter, scheduler);
  3352. {
  3353. effect.onTrack = onTrack;
  3354. effect.onTrigger = onTrigger;
  3355. }
  3356. // initial run
  3357. if (cb) {
  3358. if (immediate) {
  3359. job();
  3360. }
  3361. else {
  3362. oldValue = effect.run();
  3363. }
  3364. }
  3365. else if (flush === 'post') {
  3366. queuePostRenderEffect(effect.run.bind(effect), instance && instance.suspense);
  3367. }
  3368. else {
  3369. effect.run();
  3370. }
  3371. const unwatch = () => {
  3372. effect.stop();
  3373. if (instance && instance.scope) {
  3374. remove(instance.scope.effects, effect);
  3375. }
  3376. };
  3377. return unwatch;
  3378. }
  3379. // this.$watch
  3380. function instanceWatch(source, value, options) {
  3381. const publicThis = this.proxy;
  3382. const getter = isString(source)
  3383. ? source.includes('.')
  3384. ? createPathGetter(publicThis, source)
  3385. : () => publicThis[source]
  3386. : source.bind(publicThis, publicThis);
  3387. let cb;
  3388. if (isFunction(value)) {
  3389. cb = value;
  3390. }
  3391. else {
  3392. cb = value.handler;
  3393. options = value;
  3394. }
  3395. const cur = currentInstance;
  3396. setCurrentInstance(this);
  3397. const res = doWatch(getter, cb.bind(publicThis), options);
  3398. if (cur) {
  3399. setCurrentInstance(cur);
  3400. }
  3401. else {
  3402. unsetCurrentInstance();
  3403. }
  3404. return res;
  3405. }
  3406. function createPathGetter(ctx, path) {
  3407. const segments = path.split('.');
  3408. return () => {
  3409. let cur = ctx;
  3410. for (let i = 0; i < segments.length && cur; i++) {
  3411. cur = cur[segments[i]];
  3412. }
  3413. return cur;
  3414. };
  3415. }
  3416. function traverse(value, seen) {
  3417. if (!isObject(value) || value["__v_skip" /* ReactiveFlags.SKIP */]) {
  3418. return value;
  3419. }
  3420. seen = seen || new Set();
  3421. if (seen.has(value)) {
  3422. return value;
  3423. }
  3424. seen.add(value);
  3425. if (isRef(value)) {
  3426. traverse(value.value, seen);
  3427. }
  3428. else if (isArray(value)) {
  3429. for (let i = 0; i < value.length; i++) {
  3430. traverse(value[i], seen);
  3431. }
  3432. }
  3433. else if (isSet(value) || isMap(value)) {
  3434. value.forEach((v) => {
  3435. traverse(v, seen);
  3436. });
  3437. }
  3438. else if (isPlainObject(value)) {
  3439. for (const key in value) {
  3440. traverse(value[key], seen);
  3441. }
  3442. }
  3443. return value;
  3444. }
  3445. function useTransitionState() {
  3446. const state = {
  3447. isMounted: false,
  3448. isLeaving: false,
  3449. isUnmounting: false,
  3450. leavingVNodes: new Map()
  3451. };
  3452. onMounted(() => {
  3453. state.isMounted = true;
  3454. });
  3455. onBeforeUnmount(() => {
  3456. state.isUnmounting = true;
  3457. });
  3458. return state;
  3459. }
  3460. const TransitionHookValidator = [Function, Array];
  3461. const BaseTransitionImpl = {
  3462. name: `BaseTransition`,
  3463. props: {
  3464. mode: String,
  3465. appear: Boolean,
  3466. persisted: Boolean,
  3467. // enter
  3468. onBeforeEnter: TransitionHookValidator,
  3469. onEnter: TransitionHookValidator,
  3470. onAfterEnter: TransitionHookValidator,
  3471. onEnterCancelled: TransitionHookValidator,
  3472. // leave
  3473. onBeforeLeave: TransitionHookValidator,
  3474. onLeave: TransitionHookValidator,
  3475. onAfterLeave: TransitionHookValidator,
  3476. onLeaveCancelled: TransitionHookValidator,
  3477. // appear
  3478. onBeforeAppear: TransitionHookValidator,
  3479. onAppear: TransitionHookValidator,
  3480. onAfterAppear: TransitionHookValidator,
  3481. onAppearCancelled: TransitionHookValidator
  3482. },
  3483. setup(props, { slots }) {
  3484. const instance = getCurrentInstance();
  3485. const state = useTransitionState();
  3486. let prevTransitionKey;
  3487. return () => {
  3488. const children = slots.default && getTransitionRawChildren(slots.default(), true);
  3489. if (!children || !children.length) {
  3490. return;
  3491. }
  3492. let child = children[0];
  3493. if (children.length > 1) {
  3494. let hasFound = false;
  3495. // locate first non-comment child
  3496. for (const c of children) {
  3497. if (c.type !== Comment) {
  3498. if (hasFound) {
  3499. // warn more than one non-comment child
  3500. warn$1('<transition> can only be used on a single element or component. ' +
  3501. 'Use <transition-group> for lists.');
  3502. break;
  3503. }
  3504. child = c;
  3505. hasFound = true;
  3506. }
  3507. }
  3508. }
  3509. // there's no need to track reactivity for these props so use the raw
  3510. // props for a bit better perf
  3511. const rawProps = toRaw(props);
  3512. const { mode } = rawProps;
  3513. // check mode
  3514. if (mode &&
  3515. mode !== 'in-out' &&
  3516. mode !== 'out-in' &&
  3517. mode !== 'default') {
  3518. warn$1(`invalid <transition> mode: ${mode}`);
  3519. }
  3520. if (state.isLeaving) {
  3521. return emptyPlaceholder(child);
  3522. }
  3523. // in the case of <transition><keep-alive/></transition>, we need to
  3524. // compare the type of the kept-alive children.
  3525. const innerChild = getKeepAliveChild(child);
  3526. if (!innerChild) {
  3527. return emptyPlaceholder(child);
  3528. }
  3529. const enterHooks = resolveTransitionHooks(innerChild, rawProps, state, instance);
  3530. setTransitionHooks(innerChild, enterHooks);
  3531. const oldChild = instance.subTree;
  3532. const oldInnerChild = oldChild && getKeepAliveChild(oldChild);
  3533. let transitionKeyChanged = false;
  3534. const { getTransitionKey } = innerChild.type;
  3535. if (getTransitionKey) {
  3536. const key = getTransitionKey();
  3537. if (prevTransitionKey === undefined) {
  3538. prevTransitionKey = key;
  3539. }
  3540. else if (key !== prevTransitionKey) {
  3541. prevTransitionKey = key;
  3542. transitionKeyChanged = true;
  3543. }
  3544. }
  3545. // handle mode
  3546. if (oldInnerChild &&
  3547. oldInnerChild.type !== Comment &&
  3548. (!isSameVNodeType(innerChild, oldInnerChild) || transitionKeyChanged)) {
  3549. const leavingHooks = resolveTransitionHooks(oldInnerChild, rawProps, state, instance);
  3550. // update old tree's hooks in case of dynamic transition
  3551. setTransitionHooks(oldInnerChild, leavingHooks);
  3552. // switching between different views
  3553. if (mode === 'out-in') {
  3554. state.isLeaving = true;
  3555. // return placeholder node and queue update when leave finishes
  3556. leavingHooks.afterLeave = () => {
  3557. state.isLeaving = false;
  3558. // #6835
  3559. // it also needs to be updated when active is undefined
  3560. if (instance.update.active !== false) {
  3561. instance.update();
  3562. }
  3563. };
  3564. return emptyPlaceholder(child);
  3565. }
  3566. else if (mode === 'in-out' && innerChild.type !== Comment) {
  3567. leavingHooks.delayLeave = (el, earlyRemove, delayedLeave) => {
  3568. const leavingVNodesCache = getLeavingNodesForType(state, oldInnerChild);
  3569. leavingVNodesCache[String(oldInnerChild.key)] = oldInnerChild;
  3570. // early removal callback
  3571. el._leaveCb = () => {
  3572. earlyRemove();
  3573. el._leaveCb = undefined;
  3574. delete enterHooks.delayedLeave;
  3575. };
  3576. enterHooks.delayedLeave = delayedLeave;
  3577. };
  3578. }
  3579. }
  3580. return child;
  3581. };
  3582. }
  3583. };
  3584. // export the public type for h/tsx inference
  3585. // also to avoid inline import() in generated d.ts files
  3586. const BaseTransition = BaseTransitionImpl;
  3587. function getLeavingNodesForType(state, vnode) {
  3588. const { leavingVNodes } = state;
  3589. let leavingVNodesCache = leavingVNodes.get(vnode.type);
  3590. if (!leavingVNodesCache) {
  3591. leavingVNodesCache = Object.create(null);
  3592. leavingVNodes.set(vnode.type, leavingVNodesCache);
  3593. }
  3594. return leavingVNodesCache;
  3595. }
  3596. // The transition hooks are attached to the vnode as vnode.transition
  3597. // and will be called at appropriate timing in the renderer.
  3598. function resolveTransitionHooks(vnode, props, state, instance) {
  3599. const { appear, mode, persisted = false, onBeforeEnter, onEnter, onAfterEnter, onEnterCancelled, onBeforeLeave, onLeave, onAfterLeave, onLeaveCancelled, onBeforeAppear, onAppear, onAfterAppear, onAppearCancelled } = props;
  3600. const key = String(vnode.key);
  3601. const leavingVNodesCache = getLeavingNodesForType(state, vnode);
  3602. const callHook = (hook, args) => {
  3603. hook &&
  3604. callWithAsyncErrorHandling(hook, instance, 9 /* ErrorCodes.TRANSITION_HOOK */, args);
  3605. };
  3606. const callAsyncHook = (hook, args) => {
  3607. const done = args[1];
  3608. callHook(hook, args);
  3609. if (isArray(hook)) {
  3610. if (hook.every(hook => hook.length <= 1))
  3611. done();
  3612. }
  3613. else if (hook.length <= 1) {
  3614. done();
  3615. }
  3616. };
  3617. const hooks = {
  3618. mode,
  3619. persisted,
  3620. beforeEnter(el) {
  3621. let hook = onBeforeEnter;
  3622. if (!state.isMounted) {
  3623. if (appear) {
  3624. hook = onBeforeAppear || onBeforeEnter;
  3625. }
  3626. else {
  3627. return;
  3628. }
  3629. }
  3630. // for same element (v-show)
  3631. if (el._leaveCb) {
  3632. el._leaveCb(true /* cancelled */);
  3633. }
  3634. // for toggled element with same key (v-if)
  3635. const leavingVNode = leavingVNodesCache[key];
  3636. if (leavingVNode &&
  3637. isSameVNodeType(vnode, leavingVNode) &&
  3638. leavingVNode.el._leaveCb) {
  3639. // force early removal (not cancelled)
  3640. leavingVNode.el._leaveCb();
  3641. }
  3642. callHook(hook, [el]);
  3643. },
  3644. enter(el) {
  3645. let hook = onEnter;
  3646. let afterHook = onAfterEnter;
  3647. let cancelHook = onEnterCancelled;
  3648. if (!state.isMounted) {
  3649. if (appear) {
  3650. hook = onAppear || onEnter;
  3651. afterHook = onAfterAppear || onAfterEnter;
  3652. cancelHook = onAppearCancelled || onEnterCancelled;
  3653. }
  3654. else {
  3655. return;
  3656. }
  3657. }
  3658. let called = false;
  3659. const done = (el._enterCb = (cancelled) => {
  3660. if (called)
  3661. return;
  3662. called = true;
  3663. if (cancelled) {
  3664. callHook(cancelHook, [el]);
  3665. }
  3666. else {
  3667. callHook(afterHook, [el]);
  3668. }
  3669. if (hooks.delayedLeave) {
  3670. hooks.delayedLeave();
  3671. }
  3672. el._enterCb = undefined;
  3673. });
  3674. if (hook) {
  3675. callAsyncHook(hook, [el, done]);
  3676. }
  3677. else {
  3678. done();
  3679. }
  3680. },
  3681. leave(el, remove) {
  3682. const key = String(vnode.key);
  3683. if (el._enterCb) {
  3684. el._enterCb(true /* cancelled */);
  3685. }
  3686. if (state.isUnmounting) {
  3687. return remove();
  3688. }
  3689. callHook(onBeforeLeave, [el]);
  3690. let called = false;
  3691. const done = (el._leaveCb = (cancelled) => {
  3692. if (called)
  3693. return;
  3694. called = true;
  3695. remove();
  3696. if (cancelled) {
  3697. callHook(onLeaveCancelled, [el]);
  3698. }
  3699. else {
  3700. callHook(onAfterLeave, [el]);
  3701. }
  3702. el._leaveCb = undefined;
  3703. if (leavingVNodesCache[key] === vnode) {
  3704. delete leavingVNodesCache[key];
  3705. }
  3706. });
  3707. leavingVNodesCache[key] = vnode;
  3708. if (onLeave) {
  3709. callAsyncHook(onLeave, [el, done]);
  3710. }
  3711. else {
  3712. done();
  3713. }
  3714. },
  3715. clone(vnode) {
  3716. return resolveTransitionHooks(vnode, props, state, instance);
  3717. }
  3718. };
  3719. return hooks;
  3720. }
  3721. // the placeholder really only handles one special case: KeepAlive
  3722. // in the case of a KeepAlive in a leave phase we need to return a KeepAlive
  3723. // placeholder with empty content to avoid the KeepAlive instance from being
  3724. // unmounted.
  3725. function emptyPlaceholder(vnode) {
  3726. if (isKeepAlive(vnode)) {
  3727. vnode = cloneVNode(vnode);
  3728. vnode.children = null;
  3729. return vnode;
  3730. }
  3731. }
  3732. function getKeepAliveChild(vnode) {
  3733. return isKeepAlive(vnode)
  3734. ? vnode.children
  3735. ? vnode.children[0]
  3736. : undefined
  3737. : vnode;
  3738. }
  3739. function setTransitionHooks(vnode, hooks) {
  3740. if (vnode.shapeFlag & 6 /* ShapeFlags.COMPONENT */ && vnode.component) {
  3741. setTransitionHooks(vnode.component.subTree, hooks);
  3742. }
  3743. else if (vnode.shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
  3744. vnode.ssContent.transition = hooks.clone(vnode.ssContent);
  3745. vnode.ssFallback.transition = hooks.clone(vnode.ssFallback);
  3746. }
  3747. else {
  3748. vnode.transition = hooks;
  3749. }
  3750. }
  3751. function getTransitionRawChildren(children, keepComment = false, parentKey) {
  3752. let ret = [];
  3753. let keyedFragmentCount = 0;
  3754. for (let i = 0; i < children.length; i++) {
  3755. let child = children[i];
  3756. // #5360 inherit parent key in case of <template v-for>
  3757. const key = parentKey == null
  3758. ? child.key
  3759. : String(parentKey) + String(child.key != null ? child.key : i);
  3760. // handle fragment children case, e.g. v-for
  3761. if (child.type === Fragment) {
  3762. if (child.patchFlag & 128 /* PatchFlags.KEYED_FRAGMENT */)
  3763. keyedFragmentCount++;
  3764. ret = ret.concat(getTransitionRawChildren(child.children, keepComment, key));
  3765. }
  3766. // comment placeholders should be skipped, e.g. v-if
  3767. else if (keepComment || child.type !== Comment) {
  3768. ret.push(key != null ? cloneVNode(child, { key }) : child);
  3769. }
  3770. }
  3771. // #1126 if a transition children list contains multiple sub fragments, these
  3772. // fragments will be merged into a flat children array. Since each v-for
  3773. // fragment may contain different static bindings inside, we need to de-op
  3774. // these children to force full diffs to ensure correct behavior.
  3775. if (keyedFragmentCount > 1) {
  3776. for (let i = 0; i < ret.length; i++) {
  3777. ret[i].patchFlag = -2 /* PatchFlags.BAIL */;
  3778. }
  3779. }
  3780. return ret;
  3781. }
  3782. // implementation, close to no-op
  3783. function defineComponent(options) {
  3784. return isFunction(options) ? { setup: options, name: options.name } : options;
  3785. }
  3786. const isAsyncWrapper = (i) => !!i.type.__asyncLoader;
  3787. function defineAsyncComponent(source) {
  3788. if (isFunction(source)) {
  3789. source = { loader: source };
  3790. }
  3791. const { loader, loadingComponent, errorComponent, delay = 200, timeout, // undefined = never times out
  3792. suspensible = true, onError: userOnError } = source;
  3793. let pendingRequest = null;
  3794. let resolvedComp;
  3795. let retries = 0;
  3796. const retry = () => {
  3797. retries++;
  3798. pendingRequest = null;
  3799. return load();
  3800. };
  3801. const load = () => {
  3802. let thisRequest;
  3803. return (pendingRequest ||
  3804. (thisRequest = pendingRequest =
  3805. loader()
  3806. .catch(err => {
  3807. err = err instanceof Error ? err : new Error(String(err));
  3808. if (userOnError) {
  3809. return new Promise((resolve, reject) => {
  3810. const userRetry = () => resolve(retry());
  3811. const userFail = () => reject(err);
  3812. userOnError(err, userRetry, userFail, retries + 1);
  3813. });
  3814. }
  3815. else {
  3816. throw err;
  3817. }
  3818. })
  3819. .then((comp) => {
  3820. if (thisRequest !== pendingRequest && pendingRequest) {
  3821. return pendingRequest;
  3822. }
  3823. if (!comp) {
  3824. warn$1(`Async component loader resolved to undefined. ` +
  3825. `If you are using retry(), make sure to return its return value.`);
  3826. }
  3827. // interop module default
  3828. if (comp &&
  3829. (comp.__esModule || comp[Symbol.toStringTag] === 'Module')) {
  3830. comp = comp.default;
  3831. }
  3832. if (comp && !isObject(comp) && !isFunction(comp)) {
  3833. throw new Error(`Invalid async component load result: ${comp}`);
  3834. }
  3835. resolvedComp = comp;
  3836. return comp;
  3837. })));
  3838. };
  3839. return defineComponent({
  3840. name: 'AsyncComponentWrapper',
  3841. __asyncLoader: load,
  3842. get __asyncResolved() {
  3843. return resolvedComp;
  3844. },
  3845. setup() {
  3846. const instance = currentInstance;
  3847. // already resolved
  3848. if (resolvedComp) {
  3849. return () => createInnerComp(resolvedComp, instance);
  3850. }
  3851. const onError = (err) => {
  3852. pendingRequest = null;
  3853. handleError(err, instance, 13 /* ErrorCodes.ASYNC_COMPONENT_LOADER */, !errorComponent /* do not throw in dev if user provided error component */);
  3854. };
  3855. // suspense-controlled or SSR.
  3856. if ((suspensible && instance.suspense) ||
  3857. (false )) {
  3858. return load()
  3859. .then(comp => {
  3860. return () => createInnerComp(comp, instance);
  3861. })
  3862. .catch(err => {
  3863. onError(err);
  3864. return () => errorComponent
  3865. ? createVNode(errorComponent, {
  3866. error: err
  3867. })
  3868. : null;
  3869. });
  3870. }
  3871. const loaded = ref(false);
  3872. const error = ref();
  3873. const delayed = ref(!!delay);
  3874. if (delay) {
  3875. setTimeout(() => {
  3876. delayed.value = false;
  3877. }, delay);
  3878. }
  3879. if (timeout != null) {
  3880. setTimeout(() => {
  3881. if (!loaded.value && !error.value) {
  3882. const err = new Error(`Async component timed out after ${timeout}ms.`);
  3883. onError(err);
  3884. error.value = err;
  3885. }
  3886. }, timeout);
  3887. }
  3888. load()
  3889. .then(() => {
  3890. loaded.value = true;
  3891. if (instance.parent && isKeepAlive(instance.parent.vnode)) {
  3892. // parent is keep-alive, force update so the loaded component's
  3893. // name is taken into account
  3894. queueJob(instance.parent.update);
  3895. }
  3896. })
  3897. .catch(err => {
  3898. onError(err);
  3899. error.value = err;
  3900. });
  3901. return () => {
  3902. if (loaded.value && resolvedComp) {
  3903. return createInnerComp(resolvedComp, instance);
  3904. }
  3905. else if (error.value && errorComponent) {
  3906. return createVNode(errorComponent, {
  3907. error: error.value
  3908. });
  3909. }
  3910. else if (loadingComponent && !delayed.value) {
  3911. return createVNode(loadingComponent);
  3912. }
  3913. };
  3914. }
  3915. });
  3916. }
  3917. function createInnerComp(comp, parent) {
  3918. const { ref, props, children, ce } = parent.vnode;
  3919. const vnode = createVNode(comp, props, children);
  3920. // ensure inner component inherits the async wrapper's ref owner
  3921. vnode.ref = ref;
  3922. // pass the custom element callback on to the inner comp
  3923. // and remove it from the async wrapper
  3924. vnode.ce = ce;
  3925. delete parent.vnode.ce;
  3926. return vnode;
  3927. }
  3928. const isKeepAlive = (vnode) => vnode.type.__isKeepAlive;
  3929. const KeepAliveImpl = {
  3930. name: `KeepAlive`,
  3931. // Marker for special handling inside the renderer. We are not using a ===
  3932. // check directly on KeepAlive in the renderer, because importing it directly
  3933. // would prevent it from being tree-shaken.
  3934. __isKeepAlive: true,
  3935. props: {
  3936. include: [String, RegExp, Array],
  3937. exclude: [String, RegExp, Array],
  3938. max: [String, Number]
  3939. },
  3940. setup(props, { slots }) {
  3941. const instance = getCurrentInstance();
  3942. // KeepAlive communicates with the instantiated renderer via the
  3943. // ctx where the renderer passes in its internals,
  3944. // and the KeepAlive instance exposes activate/deactivate implementations.
  3945. // The whole point of this is to avoid importing KeepAlive directly in the
  3946. // renderer to facilitate tree-shaking.
  3947. const sharedContext = instance.ctx;
  3948. const cache = new Map();
  3949. const keys = new Set();
  3950. let current = null;
  3951. {
  3952. instance.__v_cache = cache;
  3953. }
  3954. const parentSuspense = instance.suspense;
  3955. const { renderer: { p: patch, m: move, um: _unmount, o: { createElement } } } = sharedContext;
  3956. const storageContainer = createElement('div');
  3957. sharedContext.activate = (vnode, container, anchor, isSVG, optimized) => {
  3958. const instance = vnode.component;
  3959. move(vnode, container, anchor, 0 /* MoveType.ENTER */, parentSuspense);
  3960. // in case props have changed
  3961. patch(instance.vnode, vnode, container, anchor, instance, parentSuspense, isSVG, vnode.slotScopeIds, optimized);
  3962. queuePostRenderEffect(() => {
  3963. instance.isDeactivated = false;
  3964. if (instance.a) {
  3965. invokeArrayFns(instance.a);
  3966. }
  3967. const vnodeHook = vnode.props && vnode.props.onVnodeMounted;
  3968. if (vnodeHook) {
  3969. invokeVNodeHook(vnodeHook, instance.parent, vnode);
  3970. }
  3971. }, parentSuspense);
  3972. {
  3973. // Update components tree
  3974. devtoolsComponentAdded(instance);
  3975. }
  3976. };
  3977. sharedContext.deactivate = (vnode) => {
  3978. const instance = vnode.component;
  3979. move(vnode, storageContainer, null, 1 /* MoveType.LEAVE */, parentSuspense);
  3980. queuePostRenderEffect(() => {
  3981. if (instance.da) {
  3982. invokeArrayFns(instance.da);
  3983. }
  3984. const vnodeHook = vnode.props && vnode.props.onVnodeUnmounted;
  3985. if (vnodeHook) {
  3986. invokeVNodeHook(vnodeHook, instance.parent, vnode);
  3987. }
  3988. instance.isDeactivated = true;
  3989. }, parentSuspense);
  3990. {
  3991. // Update components tree
  3992. devtoolsComponentAdded(instance);
  3993. }
  3994. };
  3995. function unmount(vnode) {
  3996. // reset the shapeFlag so it can be properly unmounted
  3997. resetShapeFlag(vnode);
  3998. _unmount(vnode, instance, parentSuspense, true);
  3999. }
  4000. function pruneCache(filter) {
  4001. cache.forEach((vnode, key) => {
  4002. const name = getComponentName(vnode.type);
  4003. if (name && (!filter || !filter(name))) {
  4004. pruneCacheEntry(key);
  4005. }
  4006. });
  4007. }
  4008. function pruneCacheEntry(key) {
  4009. const cached = cache.get(key);
  4010. if (!current || cached.type !== current.type) {
  4011. unmount(cached);
  4012. }
  4013. else if (current) {
  4014. // current active instance should no longer be kept-alive.
  4015. // we can't unmount it now but it might be later, so reset its flag now.
  4016. resetShapeFlag(current);
  4017. }
  4018. cache.delete(key);
  4019. keys.delete(key);
  4020. }
  4021. // prune cache on include/exclude prop change
  4022. watch(() => [props.include, props.exclude], ([include, exclude]) => {
  4023. include && pruneCache(name => matches(include, name));
  4024. exclude && pruneCache(name => !matches(exclude, name));
  4025. },
  4026. // prune post-render after `current` has been updated
  4027. { flush: 'post', deep: true });
  4028. // cache sub tree after render
  4029. let pendingCacheKey = null;
  4030. const cacheSubtree = () => {
  4031. // fix #1621, the pendingCacheKey could be 0
  4032. if (pendingCacheKey != null) {
  4033. cache.set(pendingCacheKey, getInnerChild(instance.subTree));
  4034. }
  4035. };
  4036. onMounted(cacheSubtree);
  4037. onUpdated(cacheSubtree);
  4038. onBeforeUnmount(() => {
  4039. cache.forEach(cached => {
  4040. const { subTree, suspense } = instance;
  4041. const vnode = getInnerChild(subTree);
  4042. if (cached.type === vnode.type) {
  4043. // current instance will be unmounted as part of keep-alive's unmount
  4044. resetShapeFlag(vnode);
  4045. // but invoke its deactivated hook here
  4046. const da = vnode.component.da;
  4047. da && queuePostRenderEffect(da, suspense);
  4048. return;
  4049. }
  4050. unmount(cached);
  4051. });
  4052. });
  4053. return () => {
  4054. pendingCacheKey = null;
  4055. if (!slots.default) {
  4056. return null;
  4057. }
  4058. const children = slots.default();
  4059. const rawVNode = children[0];
  4060. if (children.length > 1) {
  4061. {
  4062. warn$1(`KeepAlive should contain exactly one component child.`);
  4063. }
  4064. current = null;
  4065. return children;
  4066. }
  4067. else if (!isVNode(rawVNode) ||
  4068. (!(rawVNode.shapeFlag & 4 /* ShapeFlags.STATEFUL_COMPONENT */) &&
  4069. !(rawVNode.shapeFlag & 128 /* ShapeFlags.SUSPENSE */))) {
  4070. current = null;
  4071. return rawVNode;
  4072. }
  4073. let vnode = getInnerChild(rawVNode);
  4074. const comp = vnode.type;
  4075. // for async components, name check should be based in its loaded
  4076. // inner component if available
  4077. const name = getComponentName(isAsyncWrapper(vnode)
  4078. ? vnode.type.__asyncResolved || {}
  4079. : comp);
  4080. const { include, exclude, max } = props;
  4081. if ((include && (!name || !matches(include, name))) ||
  4082. (exclude && name && matches(exclude, name))) {
  4083. current = vnode;
  4084. return rawVNode;
  4085. }
  4086. const key = vnode.key == null ? comp : vnode.key;
  4087. const cachedVNode = cache.get(key);
  4088. // clone vnode if it's reused because we are going to mutate it
  4089. if (vnode.el) {
  4090. vnode = cloneVNode(vnode);
  4091. if (rawVNode.shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
  4092. rawVNode.ssContent = vnode;
  4093. }
  4094. }
  4095. // #1513 it's possible for the returned vnode to be cloned due to attr
  4096. // fallthrough or scopeId, so the vnode here may not be the final vnode
  4097. // that is mounted. Instead of caching it directly, we store the pending
  4098. // key and cache `instance.subTree` (the normalized vnode) in
  4099. // beforeMount/beforeUpdate hooks.
  4100. pendingCacheKey = key;
  4101. if (cachedVNode) {
  4102. // copy over mounted state
  4103. vnode.el = cachedVNode.el;
  4104. vnode.component = cachedVNode.component;
  4105. if (vnode.transition) {
  4106. // recursively update transition hooks on subTree
  4107. setTransitionHooks(vnode, vnode.transition);
  4108. }
  4109. // avoid vnode being mounted as fresh
  4110. vnode.shapeFlag |= 512 /* ShapeFlags.COMPONENT_KEPT_ALIVE */;
  4111. // make this key the freshest
  4112. keys.delete(key);
  4113. keys.add(key);
  4114. }
  4115. else {
  4116. keys.add(key);
  4117. // prune oldest entry
  4118. if (max && keys.size > parseInt(max, 10)) {
  4119. pruneCacheEntry(keys.values().next().value);
  4120. }
  4121. }
  4122. // avoid vnode being unmounted
  4123. vnode.shapeFlag |= 256 /* ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE */;
  4124. current = vnode;
  4125. return isSuspense(rawVNode.type) ? rawVNode : vnode;
  4126. };
  4127. }
  4128. };
  4129. // export the public type for h/tsx inference
  4130. // also to avoid inline import() in generated d.ts files
  4131. const KeepAlive = KeepAliveImpl;
  4132. function matches(pattern, name) {
  4133. if (isArray(pattern)) {
  4134. return pattern.some((p) => matches(p, name));
  4135. }
  4136. else if (isString(pattern)) {
  4137. return pattern.split(',').includes(name);
  4138. }
  4139. else if (pattern.test) {
  4140. return pattern.test(name);
  4141. }
  4142. /* istanbul ignore next */
  4143. return false;
  4144. }
  4145. function onActivated(hook, target) {
  4146. registerKeepAliveHook(hook, "a" /* LifecycleHooks.ACTIVATED */, target);
  4147. }
  4148. function onDeactivated(hook, target) {
  4149. registerKeepAliveHook(hook, "da" /* LifecycleHooks.DEACTIVATED */, target);
  4150. }
  4151. function registerKeepAliveHook(hook, type, target = currentInstance) {
  4152. // cache the deactivate branch check wrapper for injected hooks so the same
  4153. // hook can be properly deduped by the scheduler. "__wdc" stands for "with
  4154. // deactivation check".
  4155. const wrappedHook = hook.__wdc ||
  4156. (hook.__wdc = () => {
  4157. // only fire the hook if the target instance is NOT in a deactivated branch.
  4158. let current = target;
  4159. while (current) {
  4160. if (current.isDeactivated) {
  4161. return;
  4162. }
  4163. current = current.parent;
  4164. }
  4165. return hook();
  4166. });
  4167. injectHook(type, wrappedHook, target);
  4168. // In addition to registering it on the target instance, we walk up the parent
  4169. // chain and register it on all ancestor instances that are keep-alive roots.
  4170. // This avoids the need to walk the entire component tree when invoking these
  4171. // hooks, and more importantly, avoids the need to track child components in
  4172. // arrays.
  4173. if (target) {
  4174. let current = target.parent;
  4175. while (current && current.parent) {
  4176. if (isKeepAlive(current.parent.vnode)) {
  4177. injectToKeepAliveRoot(wrappedHook, type, target, current);
  4178. }
  4179. current = current.parent;
  4180. }
  4181. }
  4182. }
  4183. function injectToKeepAliveRoot(hook, type, target, keepAliveRoot) {
  4184. // injectHook wraps the original for error handling, so make sure to remove
  4185. // the wrapped version.
  4186. const injected = injectHook(type, hook, keepAliveRoot, true /* prepend */);
  4187. onUnmounted(() => {
  4188. remove(keepAliveRoot[type], injected);
  4189. }, target);
  4190. }
  4191. function resetShapeFlag(vnode) {
  4192. // bitwise operations to remove keep alive flags
  4193. vnode.shapeFlag &= ~256 /* ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE */;
  4194. vnode.shapeFlag &= ~512 /* ShapeFlags.COMPONENT_KEPT_ALIVE */;
  4195. }
  4196. function getInnerChild(vnode) {
  4197. return vnode.shapeFlag & 128 /* ShapeFlags.SUSPENSE */ ? vnode.ssContent : vnode;
  4198. }
  4199. function injectHook(type, hook, target = currentInstance, prepend = false) {
  4200. if (target) {
  4201. const hooks = target[type] || (target[type] = []);
  4202. // cache the error handling wrapper for injected hooks so the same hook
  4203. // can be properly deduped by the scheduler. "__weh" stands for "with error
  4204. // handling".
  4205. const wrappedHook = hook.__weh ||
  4206. (hook.__weh = (...args) => {
  4207. if (target.isUnmounted) {
  4208. return;
  4209. }
  4210. // disable tracking inside all lifecycle hooks
  4211. // since they can potentially be called inside effects.
  4212. pauseTracking();
  4213. // Set currentInstance during hook invocation.
  4214. // This assumes the hook does not synchronously trigger other hooks, which
  4215. // can only be false when the user does something really funky.
  4216. setCurrentInstance(target);
  4217. const res = callWithAsyncErrorHandling(hook, target, type, args);
  4218. unsetCurrentInstance();
  4219. resetTracking();
  4220. return res;
  4221. });
  4222. if (prepend) {
  4223. hooks.unshift(wrappedHook);
  4224. }
  4225. else {
  4226. hooks.push(wrappedHook);
  4227. }
  4228. return wrappedHook;
  4229. }
  4230. else {
  4231. const apiName = toHandlerKey(ErrorTypeStrings[type].replace(/ hook$/, ''));
  4232. warn$1(`${apiName} is called when there is no active component instance to be ` +
  4233. `associated with. ` +
  4234. `Lifecycle injection APIs can only be used during execution of setup().` +
  4235. (` If you are using async setup(), make sure to register lifecycle ` +
  4236. `hooks before the first await statement.`
  4237. ));
  4238. }
  4239. }
  4240. const createHook = (lifecycle) => (hook, target = currentInstance) =>
  4241. // post-create lifecycle registrations are noops during SSR (except for serverPrefetch)
  4242. (!isInSSRComponentSetup || lifecycle === "sp" /* LifecycleHooks.SERVER_PREFETCH */) &&
  4243. injectHook(lifecycle, (...args) => hook(...args), target);
  4244. const onBeforeMount = createHook("bm" /* LifecycleHooks.BEFORE_MOUNT */);
  4245. const onMounted = createHook("m" /* LifecycleHooks.MOUNTED */);
  4246. const onBeforeUpdate = createHook("bu" /* LifecycleHooks.BEFORE_UPDATE */);
  4247. const onUpdated = createHook("u" /* LifecycleHooks.UPDATED */);
  4248. const onBeforeUnmount = createHook("bum" /* LifecycleHooks.BEFORE_UNMOUNT */);
  4249. const onUnmounted = createHook("um" /* LifecycleHooks.UNMOUNTED */);
  4250. const onServerPrefetch = createHook("sp" /* LifecycleHooks.SERVER_PREFETCH */);
  4251. const onRenderTriggered = createHook("rtg" /* LifecycleHooks.RENDER_TRIGGERED */);
  4252. const onRenderTracked = createHook("rtc" /* LifecycleHooks.RENDER_TRACKED */);
  4253. function onErrorCaptured(hook, target = currentInstance) {
  4254. injectHook("ec" /* LifecycleHooks.ERROR_CAPTURED */, hook, target);
  4255. }
  4256. /**
  4257. Runtime helper for applying directives to a vnode. Example usage:
  4258. const comp = resolveComponent('comp')
  4259. const foo = resolveDirective('foo')
  4260. const bar = resolveDirective('bar')
  4261. return withDirectives(h(comp), [
  4262. [foo, this.x],
  4263. [bar, this.y]
  4264. ])
  4265. */
  4266. function validateDirectiveName(name) {
  4267. if (isBuiltInDirective(name)) {
  4268. warn$1('Do not use built-in directive ids as custom directive id: ' + name);
  4269. }
  4270. }
  4271. /**
  4272. * Adds directives to a VNode.
  4273. */
  4274. function withDirectives(vnode, directives) {
  4275. const internalInstance = currentRenderingInstance;
  4276. if (internalInstance === null) {
  4277. warn$1(`withDirectives can only be used inside render functions.`);
  4278. return vnode;
  4279. }
  4280. const instance = getExposeProxy(internalInstance) ||
  4281. internalInstance.proxy;
  4282. const bindings = vnode.dirs || (vnode.dirs = []);
  4283. for (let i = 0; i < directives.length; i++) {
  4284. let [dir, value, arg, modifiers = EMPTY_OBJ] = directives[i];
  4285. if (dir) {
  4286. if (isFunction(dir)) {
  4287. dir = {
  4288. mounted: dir,
  4289. updated: dir
  4290. };
  4291. }
  4292. if (dir.deep) {
  4293. traverse(value);
  4294. }
  4295. bindings.push({
  4296. dir,
  4297. instance,
  4298. value,
  4299. oldValue: void 0,
  4300. arg,
  4301. modifiers
  4302. });
  4303. }
  4304. }
  4305. return vnode;
  4306. }
  4307. function invokeDirectiveHook(vnode, prevVNode, instance, name) {
  4308. const bindings = vnode.dirs;
  4309. const oldBindings = prevVNode && prevVNode.dirs;
  4310. for (let i = 0; i < bindings.length; i++) {
  4311. const binding = bindings[i];
  4312. if (oldBindings) {
  4313. binding.oldValue = oldBindings[i].value;
  4314. }
  4315. let hook = binding.dir[name];
  4316. if (hook) {
  4317. // disable tracking inside all lifecycle hooks
  4318. // since they can potentially be called inside effects.
  4319. pauseTracking();
  4320. callWithAsyncErrorHandling(hook, instance, 8 /* ErrorCodes.DIRECTIVE_HOOK */, [
  4321. vnode.el,
  4322. binding,
  4323. vnode,
  4324. prevVNode
  4325. ]);
  4326. resetTracking();
  4327. }
  4328. }
  4329. }
  4330. const COMPONENTS = 'components';
  4331. const DIRECTIVES = 'directives';
  4332. /**
  4333. * @private
  4334. */
  4335. function resolveComponent(name, maybeSelfReference) {
  4336. return resolveAsset(COMPONENTS, name, true, maybeSelfReference) || name;
  4337. }
  4338. const NULL_DYNAMIC_COMPONENT = Symbol();
  4339. /**
  4340. * @private
  4341. */
  4342. function resolveDynamicComponent(component) {
  4343. if (isString(component)) {
  4344. return resolveAsset(COMPONENTS, component, false) || component;
  4345. }
  4346. else {
  4347. // invalid types will fallthrough to createVNode and raise warning
  4348. return (component || NULL_DYNAMIC_COMPONENT);
  4349. }
  4350. }
  4351. /**
  4352. * @private
  4353. */
  4354. function resolveDirective(name) {
  4355. return resolveAsset(DIRECTIVES, name);
  4356. }
  4357. // implementation
  4358. function resolveAsset(type, name, warnMissing = true, maybeSelfReference = false) {
  4359. const instance = currentRenderingInstance || currentInstance;
  4360. if (instance) {
  4361. const Component = instance.type;
  4362. // explicit self name has highest priority
  4363. if (type === COMPONENTS) {
  4364. const selfName = getComponentName(Component, false /* do not include inferred name to avoid breaking existing code */);
  4365. if (selfName &&
  4366. (selfName === name ||
  4367. selfName === camelize(name) ||
  4368. selfName === capitalize(camelize(name)))) {
  4369. return Component;
  4370. }
  4371. }
  4372. const res =
  4373. // local registration
  4374. // check instance[type] first which is resolved for options API
  4375. resolve(instance[type] || Component[type], name) ||
  4376. // global registration
  4377. resolve(instance.appContext[type], name);
  4378. if (!res && maybeSelfReference) {
  4379. // fallback to implicit self-reference
  4380. return Component;
  4381. }
  4382. if (warnMissing && !res) {
  4383. const extra = type === COMPONENTS
  4384. ? `\nIf this is a native custom element, make sure to exclude it from ` +
  4385. `component resolution via compilerOptions.isCustomElement.`
  4386. : ``;
  4387. warn$1(`Failed to resolve ${type.slice(0, -1)}: ${name}${extra}`);
  4388. }
  4389. return res;
  4390. }
  4391. else {
  4392. warn$1(`resolve${capitalize(type.slice(0, -1))} ` +
  4393. `can only be used in render() or setup().`);
  4394. }
  4395. }
  4396. function resolve(registry, name) {
  4397. return (registry &&
  4398. (registry[name] ||
  4399. registry[camelize(name)] ||
  4400. registry[capitalize(camelize(name))]));
  4401. }
  4402. /**
  4403. * Actual implementation
  4404. */
  4405. function renderList(source, renderItem, cache, index) {
  4406. let ret;
  4407. const cached = (cache && cache[index]);
  4408. if (isArray(source) || isString(source)) {
  4409. ret = new Array(source.length);
  4410. for (let i = 0, l = source.length; i < l; i++) {
  4411. ret[i] = renderItem(source[i], i, undefined, cached && cached[i]);
  4412. }
  4413. }
  4414. else if (typeof source === 'number') {
  4415. if (!Number.isInteger(source)) {
  4416. warn$1(`The v-for range expect an integer value but got ${source}.`);
  4417. }
  4418. ret = new Array(source);
  4419. for (let i = 0; i < source; i++) {
  4420. ret[i] = renderItem(i + 1, i, undefined, cached && cached[i]);
  4421. }
  4422. }
  4423. else if (isObject(source)) {
  4424. if (source[Symbol.iterator]) {
  4425. ret = Array.from(source, (item, i) => renderItem(item, i, undefined, cached && cached[i]));
  4426. }
  4427. else {
  4428. const keys = Object.keys(source);
  4429. ret = new Array(keys.length);
  4430. for (let i = 0, l = keys.length; i < l; i++) {
  4431. const key = keys[i];
  4432. ret[i] = renderItem(source[key], key, i, cached && cached[i]);
  4433. }
  4434. }
  4435. }
  4436. else {
  4437. ret = [];
  4438. }
  4439. if (cache) {
  4440. cache[index] = ret;
  4441. }
  4442. return ret;
  4443. }
  4444. /**
  4445. * Compiler runtime helper for creating dynamic slots object
  4446. * @private
  4447. */
  4448. function createSlots(slots, dynamicSlots) {
  4449. for (let i = 0; i < dynamicSlots.length; i++) {
  4450. const slot = dynamicSlots[i];
  4451. // array of dynamic slot generated by <template v-for="..." #[...]>
  4452. if (isArray(slot)) {
  4453. for (let j = 0; j < slot.length; j++) {
  4454. slots[slot[j].name] = slot[j].fn;
  4455. }
  4456. }
  4457. else if (slot) {
  4458. // conditional single slot generated by <template v-if="..." #foo>
  4459. slots[slot.name] = slot.key
  4460. ? (...args) => {
  4461. const res = slot.fn(...args);
  4462. // attach branch key so each conditional branch is considered a
  4463. // different fragment
  4464. if (res)
  4465. res.key = slot.key;
  4466. return res;
  4467. }
  4468. : slot.fn;
  4469. }
  4470. }
  4471. return slots;
  4472. }
  4473. /**
  4474. * Compiler runtime helper for rendering `<slot/>`
  4475. * @private
  4476. */
  4477. function renderSlot(slots, name, props = {},
  4478. // this is not a user-facing function, so the fallback is always generated by
  4479. // the compiler and guaranteed to be a function returning an array
  4480. fallback, noSlotted) {
  4481. if (currentRenderingInstance.isCE ||
  4482. (currentRenderingInstance.parent &&
  4483. isAsyncWrapper(currentRenderingInstance.parent) &&
  4484. currentRenderingInstance.parent.isCE)) {
  4485. if (name !== 'default')
  4486. props.name = name;
  4487. return createVNode('slot', props, fallback && fallback());
  4488. }
  4489. let slot = slots[name];
  4490. if (slot && slot.length > 1) {
  4491. warn$1(`SSR-optimized slot function detected in a non-SSR-optimized render ` +
  4492. `function. You need to mark this component with $dynamic-slots in the ` +
  4493. `parent template.`);
  4494. slot = () => [];
  4495. }
  4496. // a compiled slot disables block tracking by default to avoid manual
  4497. // invocation interfering with template-based block tracking, but in
  4498. // `renderSlot` we can be sure that it's template-based so we can force
  4499. // enable it.
  4500. if (slot && slot._c) {
  4501. slot._d = false;
  4502. }
  4503. openBlock();
  4504. const validSlotContent = slot && ensureValidVNode(slot(props));
  4505. const rendered = createBlock(Fragment, {
  4506. key: props.key ||
  4507. // slot content array of a dynamic conditional slot may have a branch
  4508. // key attached in the `createSlots` helper, respect that
  4509. (validSlotContent && validSlotContent.key) ||
  4510. `_${name}`
  4511. }, validSlotContent || (fallback ? fallback() : []), validSlotContent && slots._ === 1 /* SlotFlags.STABLE */
  4512. ? 64 /* PatchFlags.STABLE_FRAGMENT */
  4513. : -2 /* PatchFlags.BAIL */);
  4514. if (!noSlotted && rendered.scopeId) {
  4515. rendered.slotScopeIds = [rendered.scopeId + '-s'];
  4516. }
  4517. if (slot && slot._c) {
  4518. slot._d = true;
  4519. }
  4520. return rendered;
  4521. }
  4522. function ensureValidVNode(vnodes) {
  4523. return vnodes.some(child => {
  4524. if (!isVNode(child))
  4525. return true;
  4526. if (child.type === Comment)
  4527. return false;
  4528. if (child.type === Fragment &&
  4529. !ensureValidVNode(child.children))
  4530. return false;
  4531. return true;
  4532. })
  4533. ? vnodes
  4534. : null;
  4535. }
  4536. /**
  4537. * For prefixing keys in v-on="obj" with "on"
  4538. * @private
  4539. */
  4540. function toHandlers(obj, preserveCaseIfNecessary) {
  4541. const ret = {};
  4542. if (!isObject(obj)) {
  4543. warn$1(`v-on with no argument expects an object value.`);
  4544. return ret;
  4545. }
  4546. for (const key in obj) {
  4547. ret[preserveCaseIfNecessary && /[A-Z]/.test(key)
  4548. ? `on:${key}`
  4549. : toHandlerKey(key)] = obj[key];
  4550. }
  4551. return ret;
  4552. }
  4553. /**
  4554. * #2437 In Vue 3, functional components do not have a public instance proxy but
  4555. * they exist in the internal parent chain. For code that relies on traversing
  4556. * public $parent chains, skip functional ones and go to the parent instead.
  4557. */
  4558. const getPublicInstance = (i) => {
  4559. if (!i)
  4560. return null;
  4561. if (isStatefulComponent(i))
  4562. return getExposeProxy(i) || i.proxy;
  4563. return getPublicInstance(i.parent);
  4564. };
  4565. const publicPropertiesMap =
  4566. // Move PURE marker to new line to workaround compiler discarding it
  4567. // due to type annotation
  4568. /*#__PURE__*/ extend(Object.create(null), {
  4569. $: i => i,
  4570. $el: i => i.vnode.el,
  4571. $data: i => i.data,
  4572. $props: i => (shallowReadonly(i.props) ),
  4573. $attrs: i => (shallowReadonly(i.attrs) ),
  4574. $slots: i => (shallowReadonly(i.slots) ),
  4575. $refs: i => (shallowReadonly(i.refs) ),
  4576. $parent: i => getPublicInstance(i.parent),
  4577. $root: i => getPublicInstance(i.root),
  4578. $emit: i => i.emit,
  4579. $options: i => (resolveMergedOptions(i) ),
  4580. $forceUpdate: i => i.f || (i.f = () => queueJob(i.update)),
  4581. $nextTick: i => i.n || (i.n = nextTick.bind(i.proxy)),
  4582. $watch: i => (instanceWatch.bind(i) )
  4583. });
  4584. const isReservedPrefix = (key) => key === '_' || key === '$';
  4585. const hasSetupBinding = (state, key) => state !== EMPTY_OBJ && !state.__isScriptSetup && hasOwn(state, key);
  4586. const PublicInstanceProxyHandlers = {
  4587. get({ _: instance }, key) {
  4588. const { ctx, setupState, data, props, accessCache, type, appContext } = instance;
  4589. // for internal formatters to know that this is a Vue instance
  4590. if (key === '__isVue') {
  4591. return true;
  4592. }
  4593. // data / props / ctx
  4594. // This getter gets called for every property access on the render context
  4595. // during render and is a major hotspot. The most expensive part of this
  4596. // is the multiple hasOwn() calls. It's much faster to do a simple property
  4597. // access on a plain object, so we use an accessCache object (with null
  4598. // prototype) to memoize what access type a key corresponds to.
  4599. let normalizedProps;
  4600. if (key[0] !== '$') {
  4601. const n = accessCache[key];
  4602. if (n !== undefined) {
  4603. switch (n) {
  4604. case 1 /* AccessTypes.SETUP */:
  4605. return setupState[key];
  4606. case 2 /* AccessTypes.DATA */:
  4607. return data[key];
  4608. case 4 /* AccessTypes.CONTEXT */:
  4609. return ctx[key];
  4610. case 3 /* AccessTypes.PROPS */:
  4611. return props[key];
  4612. // default: just fallthrough
  4613. }
  4614. }
  4615. else if (hasSetupBinding(setupState, key)) {
  4616. accessCache[key] = 1 /* AccessTypes.SETUP */;
  4617. return setupState[key];
  4618. }
  4619. else if (data !== EMPTY_OBJ && hasOwn(data, key)) {
  4620. accessCache[key] = 2 /* AccessTypes.DATA */;
  4621. return data[key];
  4622. }
  4623. else if (
  4624. // only cache other properties when instance has declared (thus stable)
  4625. // props
  4626. (normalizedProps = instance.propsOptions[0]) &&
  4627. hasOwn(normalizedProps, key)) {
  4628. accessCache[key] = 3 /* AccessTypes.PROPS */;
  4629. return props[key];
  4630. }
  4631. else if (ctx !== EMPTY_OBJ && hasOwn(ctx, key)) {
  4632. accessCache[key] = 4 /* AccessTypes.CONTEXT */;
  4633. return ctx[key];
  4634. }
  4635. else if (shouldCacheAccess) {
  4636. accessCache[key] = 0 /* AccessTypes.OTHER */;
  4637. }
  4638. }
  4639. const publicGetter = publicPropertiesMap[key];
  4640. let cssModule, globalProperties;
  4641. // public $xxx properties
  4642. if (publicGetter) {
  4643. if (key === '$attrs') {
  4644. track(instance, "get" /* TrackOpTypes.GET */, key);
  4645. markAttrsAccessed();
  4646. }
  4647. return publicGetter(instance);
  4648. }
  4649. else if (
  4650. // css module (injected by vue-loader)
  4651. (cssModule = type.__cssModules) &&
  4652. (cssModule = cssModule[key])) {
  4653. return cssModule;
  4654. }
  4655. else if (ctx !== EMPTY_OBJ && hasOwn(ctx, key)) {
  4656. // user may set custom properties to `this` that start with `$`
  4657. accessCache[key] = 4 /* AccessTypes.CONTEXT */;
  4658. return ctx[key];
  4659. }
  4660. else if (
  4661. // global properties
  4662. ((globalProperties = appContext.config.globalProperties),
  4663. hasOwn(globalProperties, key))) {
  4664. {
  4665. return globalProperties[key];
  4666. }
  4667. }
  4668. else if (currentRenderingInstance &&
  4669. (!isString(key) ||
  4670. // #1091 avoid internal isRef/isVNode checks on component instance leading
  4671. // to infinite warning loop
  4672. key.indexOf('__v') !== 0)) {
  4673. if (data !== EMPTY_OBJ && isReservedPrefix(key[0]) && hasOwn(data, key)) {
  4674. warn$1(`Property ${JSON.stringify(key)} must be accessed via $data because it starts with a reserved ` +
  4675. `character ("$" or "_") and is not proxied on the render context.`);
  4676. }
  4677. else if (instance === currentRenderingInstance) {
  4678. warn$1(`Property ${JSON.stringify(key)} was accessed during render ` +
  4679. `but is not defined on instance.`);
  4680. }
  4681. }
  4682. },
  4683. set({ _: instance }, key, value) {
  4684. const { data, setupState, ctx } = instance;
  4685. if (hasSetupBinding(setupState, key)) {
  4686. setupState[key] = value;
  4687. return true;
  4688. }
  4689. else if (setupState.__isScriptSetup &&
  4690. hasOwn(setupState, key)) {
  4691. warn$1(`Cannot mutate <script setup> binding "${key}" from Options API.`);
  4692. return false;
  4693. }
  4694. else if (data !== EMPTY_OBJ && hasOwn(data, key)) {
  4695. data[key] = value;
  4696. return true;
  4697. }
  4698. else if (hasOwn(instance.props, key)) {
  4699. warn$1(`Attempting to mutate prop "${key}". Props are readonly.`);
  4700. return false;
  4701. }
  4702. if (key[0] === '$' && key.slice(1) in instance) {
  4703. warn$1(`Attempting to mutate public property "${key}". ` +
  4704. `Properties starting with $ are reserved and readonly.`);
  4705. return false;
  4706. }
  4707. else {
  4708. if (key in instance.appContext.config.globalProperties) {
  4709. Object.defineProperty(ctx, key, {
  4710. enumerable: true,
  4711. configurable: true,
  4712. value
  4713. });
  4714. }
  4715. else {
  4716. ctx[key] = value;
  4717. }
  4718. }
  4719. return true;
  4720. },
  4721. has({ _: { data, setupState, accessCache, ctx, appContext, propsOptions } }, key) {
  4722. let normalizedProps;
  4723. return (!!accessCache[key] ||
  4724. (data !== EMPTY_OBJ && hasOwn(data, key)) ||
  4725. hasSetupBinding(setupState, key) ||
  4726. ((normalizedProps = propsOptions[0]) && hasOwn(normalizedProps, key)) ||
  4727. hasOwn(ctx, key) ||
  4728. hasOwn(publicPropertiesMap, key) ||
  4729. hasOwn(appContext.config.globalProperties, key));
  4730. },
  4731. defineProperty(target, key, descriptor) {
  4732. if (descriptor.get != null) {
  4733. // invalidate key cache of a getter based property #5417
  4734. target._.accessCache[key] = 0;
  4735. }
  4736. else if (hasOwn(descriptor, 'value')) {
  4737. this.set(target, key, descriptor.value, null);
  4738. }
  4739. return Reflect.defineProperty(target, key, descriptor);
  4740. }
  4741. };
  4742. {
  4743. PublicInstanceProxyHandlers.ownKeys = (target) => {
  4744. warn$1(`Avoid app logic that relies on enumerating keys on a component instance. ` +
  4745. `The keys will be empty in production mode to avoid performance overhead.`);
  4746. return Reflect.ownKeys(target);
  4747. };
  4748. }
  4749. const RuntimeCompiledPublicInstanceProxyHandlers = /*#__PURE__*/ extend({}, PublicInstanceProxyHandlers, {
  4750. get(target, key) {
  4751. // fast path for unscopables when using `with` block
  4752. if (key === Symbol.unscopables) {
  4753. return;
  4754. }
  4755. return PublicInstanceProxyHandlers.get(target, key, target);
  4756. },
  4757. has(_, key) {
  4758. const has = key[0] !== '_' && !isGloballyWhitelisted(key);
  4759. if (!has && PublicInstanceProxyHandlers.has(_, key)) {
  4760. warn$1(`Property ${JSON.stringify(key)} should not start with _ which is a reserved prefix for Vue internals.`);
  4761. }
  4762. return has;
  4763. }
  4764. });
  4765. // dev only
  4766. // In dev mode, the proxy target exposes the same properties as seen on `this`
  4767. // for easier console inspection. In prod mode it will be an empty object so
  4768. // these properties definitions can be skipped.
  4769. function createDevRenderContext(instance) {
  4770. const target = {};
  4771. // expose internal instance for proxy handlers
  4772. Object.defineProperty(target, `_`, {
  4773. configurable: true,
  4774. enumerable: false,
  4775. get: () => instance
  4776. });
  4777. // expose public properties
  4778. Object.keys(publicPropertiesMap).forEach(key => {
  4779. Object.defineProperty(target, key, {
  4780. configurable: true,
  4781. enumerable: false,
  4782. get: () => publicPropertiesMap[key](instance),
  4783. // intercepted by the proxy so no need for implementation,
  4784. // but needed to prevent set errors
  4785. set: NOOP
  4786. });
  4787. });
  4788. return target;
  4789. }
  4790. // dev only
  4791. function exposePropsOnRenderContext(instance) {
  4792. const { ctx, propsOptions: [propsOptions] } = instance;
  4793. if (propsOptions) {
  4794. Object.keys(propsOptions).forEach(key => {
  4795. Object.defineProperty(ctx, key, {
  4796. enumerable: true,
  4797. configurable: true,
  4798. get: () => instance.props[key],
  4799. set: NOOP
  4800. });
  4801. });
  4802. }
  4803. }
  4804. // dev only
  4805. function exposeSetupStateOnRenderContext(instance) {
  4806. const { ctx, setupState } = instance;
  4807. Object.keys(toRaw(setupState)).forEach(key => {
  4808. if (!setupState.__isScriptSetup) {
  4809. if (isReservedPrefix(key[0])) {
  4810. warn$1(`setup() return property ${JSON.stringify(key)} should not start with "$" or "_" ` +
  4811. `which are reserved prefixes for Vue internals.`);
  4812. return;
  4813. }
  4814. Object.defineProperty(ctx, key, {
  4815. enumerable: true,
  4816. configurable: true,
  4817. get: () => setupState[key],
  4818. set: NOOP
  4819. });
  4820. }
  4821. });
  4822. }
  4823. function createDuplicateChecker() {
  4824. const cache = Object.create(null);
  4825. return (type, key) => {
  4826. if (cache[key]) {
  4827. warn$1(`${type} property "${key}" is already defined in ${cache[key]}.`);
  4828. }
  4829. else {
  4830. cache[key] = type;
  4831. }
  4832. };
  4833. }
  4834. let shouldCacheAccess = true;
  4835. function applyOptions(instance) {
  4836. const options = resolveMergedOptions(instance);
  4837. const publicThis = instance.proxy;
  4838. const ctx = instance.ctx;
  4839. // do not cache property access on public proxy during state initialization
  4840. shouldCacheAccess = false;
  4841. // call beforeCreate first before accessing other options since
  4842. // the hook may mutate resolved options (#2791)
  4843. if (options.beforeCreate) {
  4844. callHook(options.beforeCreate, instance, "bc" /* LifecycleHooks.BEFORE_CREATE */);
  4845. }
  4846. const {
  4847. // state
  4848. data: dataOptions, computed: computedOptions, methods, watch: watchOptions, provide: provideOptions, inject: injectOptions,
  4849. // lifecycle
  4850. created, beforeMount, mounted, beforeUpdate, updated, activated, deactivated, beforeDestroy, beforeUnmount, destroyed, unmounted, render, renderTracked, renderTriggered, errorCaptured, serverPrefetch,
  4851. // public API
  4852. expose, inheritAttrs,
  4853. // assets
  4854. components, directives, filters } = options;
  4855. const checkDuplicateProperties = createDuplicateChecker() ;
  4856. {
  4857. const [propsOptions] = instance.propsOptions;
  4858. if (propsOptions) {
  4859. for (const key in propsOptions) {
  4860. checkDuplicateProperties("Props" /* OptionTypes.PROPS */, key);
  4861. }
  4862. }
  4863. }
  4864. // options initialization order (to be consistent with Vue 2):
  4865. // - props (already done outside of this function)
  4866. // - inject
  4867. // - methods
  4868. // - data (deferred since it relies on `this` access)
  4869. // - computed
  4870. // - watch (deferred since it relies on `this` access)
  4871. if (injectOptions) {
  4872. resolveInjections(injectOptions, ctx, checkDuplicateProperties, instance.appContext.config.unwrapInjectedRef);
  4873. }
  4874. if (methods) {
  4875. for (const key in methods) {
  4876. const methodHandler = methods[key];
  4877. if (isFunction(methodHandler)) {
  4878. // In dev mode, we use the `createRenderContext` function to define
  4879. // methods to the proxy target, and those are read-only but
  4880. // reconfigurable, so it needs to be redefined here
  4881. {
  4882. Object.defineProperty(ctx, key, {
  4883. value: methodHandler.bind(publicThis),
  4884. configurable: true,
  4885. enumerable: true,
  4886. writable: true
  4887. });
  4888. }
  4889. {
  4890. checkDuplicateProperties("Methods" /* OptionTypes.METHODS */, key);
  4891. }
  4892. }
  4893. else {
  4894. warn$1(`Method "${key}" has type "${typeof methodHandler}" in the component definition. ` +
  4895. `Did you reference the function correctly?`);
  4896. }
  4897. }
  4898. }
  4899. if (dataOptions) {
  4900. if (!isFunction(dataOptions)) {
  4901. warn$1(`The data option must be a function. ` +
  4902. `Plain object usage is no longer supported.`);
  4903. }
  4904. const data = dataOptions.call(publicThis, publicThis);
  4905. if (isPromise(data)) {
  4906. warn$1(`data() returned a Promise - note data() cannot be async; If you ` +
  4907. `intend to perform data fetching before component renders, use ` +
  4908. `async setup() + <Suspense>.`);
  4909. }
  4910. if (!isObject(data)) {
  4911. warn$1(`data() should return an object.`);
  4912. }
  4913. else {
  4914. instance.data = reactive(data);
  4915. {
  4916. for (const key in data) {
  4917. checkDuplicateProperties("Data" /* OptionTypes.DATA */, key);
  4918. // expose data on ctx during dev
  4919. if (!isReservedPrefix(key[0])) {
  4920. Object.defineProperty(ctx, key, {
  4921. configurable: true,
  4922. enumerable: true,
  4923. get: () => data[key],
  4924. set: NOOP
  4925. });
  4926. }
  4927. }
  4928. }
  4929. }
  4930. }
  4931. // state initialization complete at this point - start caching access
  4932. shouldCacheAccess = true;
  4933. if (computedOptions) {
  4934. for (const key in computedOptions) {
  4935. const opt = computedOptions[key];
  4936. const get = isFunction(opt)
  4937. ? opt.bind(publicThis, publicThis)
  4938. : isFunction(opt.get)
  4939. ? opt.get.bind(publicThis, publicThis)
  4940. : NOOP;
  4941. if (get === NOOP) {
  4942. warn$1(`Computed property "${key}" has no getter.`);
  4943. }
  4944. const set = !isFunction(opt) && isFunction(opt.set)
  4945. ? opt.set.bind(publicThis)
  4946. : () => {
  4947. warn$1(`Write operation failed: computed property "${key}" is readonly.`);
  4948. }
  4949. ;
  4950. const c = computed$1({
  4951. get,
  4952. set
  4953. });
  4954. Object.defineProperty(ctx, key, {
  4955. enumerable: true,
  4956. configurable: true,
  4957. get: () => c.value,
  4958. set: v => (c.value = v)
  4959. });
  4960. {
  4961. checkDuplicateProperties("Computed" /* OptionTypes.COMPUTED */, key);
  4962. }
  4963. }
  4964. }
  4965. if (watchOptions) {
  4966. for (const key in watchOptions) {
  4967. createWatcher(watchOptions[key], ctx, publicThis, key);
  4968. }
  4969. }
  4970. if (provideOptions) {
  4971. const provides = isFunction(provideOptions)
  4972. ? provideOptions.call(publicThis)
  4973. : provideOptions;
  4974. Reflect.ownKeys(provides).forEach(key => {
  4975. provide(key, provides[key]);
  4976. });
  4977. }
  4978. if (created) {
  4979. callHook(created, instance, "c" /* LifecycleHooks.CREATED */);
  4980. }
  4981. function registerLifecycleHook(register, hook) {
  4982. if (isArray(hook)) {
  4983. hook.forEach(_hook => register(_hook.bind(publicThis)));
  4984. }
  4985. else if (hook) {
  4986. register(hook.bind(publicThis));
  4987. }
  4988. }
  4989. registerLifecycleHook(onBeforeMount, beforeMount);
  4990. registerLifecycleHook(onMounted, mounted);
  4991. registerLifecycleHook(onBeforeUpdate, beforeUpdate);
  4992. registerLifecycleHook(onUpdated, updated);
  4993. registerLifecycleHook(onActivated, activated);
  4994. registerLifecycleHook(onDeactivated, deactivated);
  4995. registerLifecycleHook(onErrorCaptured, errorCaptured);
  4996. registerLifecycleHook(onRenderTracked, renderTracked);
  4997. registerLifecycleHook(onRenderTriggered, renderTriggered);
  4998. registerLifecycleHook(onBeforeUnmount, beforeUnmount);
  4999. registerLifecycleHook(onUnmounted, unmounted);
  5000. registerLifecycleHook(onServerPrefetch, serverPrefetch);
  5001. if (isArray(expose)) {
  5002. if (expose.length) {
  5003. const exposed = instance.exposed || (instance.exposed = {});
  5004. expose.forEach(key => {
  5005. Object.defineProperty(exposed, key, {
  5006. get: () => publicThis[key],
  5007. set: val => (publicThis[key] = val)
  5008. });
  5009. });
  5010. }
  5011. else if (!instance.exposed) {
  5012. instance.exposed = {};
  5013. }
  5014. }
  5015. // options that are handled when creating the instance but also need to be
  5016. // applied from mixins
  5017. if (render && instance.render === NOOP) {
  5018. instance.render = render;
  5019. }
  5020. if (inheritAttrs != null) {
  5021. instance.inheritAttrs = inheritAttrs;
  5022. }
  5023. // asset options.
  5024. if (components)
  5025. instance.components = components;
  5026. if (directives)
  5027. instance.directives = directives;
  5028. }
  5029. function resolveInjections(injectOptions, ctx, checkDuplicateProperties = NOOP, unwrapRef = false) {
  5030. if (isArray(injectOptions)) {
  5031. injectOptions = normalizeInject(injectOptions);
  5032. }
  5033. for (const key in injectOptions) {
  5034. const opt = injectOptions[key];
  5035. let injected;
  5036. if (isObject(opt)) {
  5037. if ('default' in opt) {
  5038. injected = inject(opt.from || key, opt.default, true /* treat default function as factory */);
  5039. }
  5040. else {
  5041. injected = inject(opt.from || key);
  5042. }
  5043. }
  5044. else {
  5045. injected = inject(opt);
  5046. }
  5047. if (isRef(injected)) {
  5048. // TODO remove the check in 3.3
  5049. if (unwrapRef) {
  5050. Object.defineProperty(ctx, key, {
  5051. enumerable: true,
  5052. configurable: true,
  5053. get: () => injected.value,
  5054. set: v => (injected.value = v)
  5055. });
  5056. }
  5057. else {
  5058. {
  5059. warn$1(`injected property "${key}" is a ref and will be auto-unwrapped ` +
  5060. `and no longer needs \`.value\` in the next minor release. ` +
  5061. `To opt-in to the new behavior now, ` +
  5062. `set \`app.config.unwrapInjectedRef = true\` (this config is ` +
  5063. `temporary and will not be needed in the future.)`);
  5064. }
  5065. ctx[key] = injected;
  5066. }
  5067. }
  5068. else {
  5069. ctx[key] = injected;
  5070. }
  5071. {
  5072. checkDuplicateProperties("Inject" /* OptionTypes.INJECT */, key);
  5073. }
  5074. }
  5075. }
  5076. function callHook(hook, instance, type) {
  5077. callWithAsyncErrorHandling(isArray(hook)
  5078. ? hook.map(h => h.bind(instance.proxy))
  5079. : hook.bind(instance.proxy), instance, type);
  5080. }
  5081. function createWatcher(raw, ctx, publicThis, key) {
  5082. const getter = key.includes('.')
  5083. ? createPathGetter(publicThis, key)
  5084. : () => publicThis[key];
  5085. if (isString(raw)) {
  5086. const handler = ctx[raw];
  5087. if (isFunction(handler)) {
  5088. watch(getter, handler);
  5089. }
  5090. else {
  5091. warn$1(`Invalid watch handler specified by key "${raw}"`, handler);
  5092. }
  5093. }
  5094. else if (isFunction(raw)) {
  5095. watch(getter, raw.bind(publicThis));
  5096. }
  5097. else if (isObject(raw)) {
  5098. if (isArray(raw)) {
  5099. raw.forEach(r => createWatcher(r, ctx, publicThis, key));
  5100. }
  5101. else {
  5102. const handler = isFunction(raw.handler)
  5103. ? raw.handler.bind(publicThis)
  5104. : ctx[raw.handler];
  5105. if (isFunction(handler)) {
  5106. watch(getter, handler, raw);
  5107. }
  5108. else {
  5109. warn$1(`Invalid watch handler specified by key "${raw.handler}"`, handler);
  5110. }
  5111. }
  5112. }
  5113. else {
  5114. warn$1(`Invalid watch option: "${key}"`, raw);
  5115. }
  5116. }
  5117. /**
  5118. * Resolve merged options and cache it on the component.
  5119. * This is done only once per-component since the merging does not involve
  5120. * instances.
  5121. */
  5122. function resolveMergedOptions(instance) {
  5123. const base = instance.type;
  5124. const { mixins, extends: extendsOptions } = base;
  5125. const { mixins: globalMixins, optionsCache: cache, config: { optionMergeStrategies } } = instance.appContext;
  5126. const cached = cache.get(base);
  5127. let resolved;
  5128. if (cached) {
  5129. resolved = cached;
  5130. }
  5131. else if (!globalMixins.length && !mixins && !extendsOptions) {
  5132. {
  5133. resolved = base;
  5134. }
  5135. }
  5136. else {
  5137. resolved = {};
  5138. if (globalMixins.length) {
  5139. globalMixins.forEach(m => mergeOptions(resolved, m, optionMergeStrategies, true));
  5140. }
  5141. mergeOptions(resolved, base, optionMergeStrategies);
  5142. }
  5143. if (isObject(base)) {
  5144. cache.set(base, resolved);
  5145. }
  5146. return resolved;
  5147. }
  5148. function mergeOptions(to, from, strats, asMixin = false) {
  5149. const { mixins, extends: extendsOptions } = from;
  5150. if (extendsOptions) {
  5151. mergeOptions(to, extendsOptions, strats, true);
  5152. }
  5153. if (mixins) {
  5154. mixins.forEach((m) => mergeOptions(to, m, strats, true));
  5155. }
  5156. for (const key in from) {
  5157. if (asMixin && key === 'expose') {
  5158. warn$1(`"expose" option is ignored when declared in mixins or extends. ` +
  5159. `It should only be declared in the base component itself.`);
  5160. }
  5161. else {
  5162. const strat = internalOptionMergeStrats[key] || (strats && strats[key]);
  5163. to[key] = strat ? strat(to[key], from[key]) : from[key];
  5164. }
  5165. }
  5166. return to;
  5167. }
  5168. const internalOptionMergeStrats = {
  5169. data: mergeDataFn,
  5170. props: mergeObjectOptions,
  5171. emits: mergeObjectOptions,
  5172. // objects
  5173. methods: mergeObjectOptions,
  5174. computed: mergeObjectOptions,
  5175. // lifecycle
  5176. beforeCreate: mergeAsArray,
  5177. created: mergeAsArray,
  5178. beforeMount: mergeAsArray,
  5179. mounted: mergeAsArray,
  5180. beforeUpdate: mergeAsArray,
  5181. updated: mergeAsArray,
  5182. beforeDestroy: mergeAsArray,
  5183. beforeUnmount: mergeAsArray,
  5184. destroyed: mergeAsArray,
  5185. unmounted: mergeAsArray,
  5186. activated: mergeAsArray,
  5187. deactivated: mergeAsArray,
  5188. errorCaptured: mergeAsArray,
  5189. serverPrefetch: mergeAsArray,
  5190. // assets
  5191. components: mergeObjectOptions,
  5192. directives: mergeObjectOptions,
  5193. // watch
  5194. watch: mergeWatchOptions,
  5195. // provide / inject
  5196. provide: mergeDataFn,
  5197. inject: mergeInject
  5198. };
  5199. function mergeDataFn(to, from) {
  5200. if (!from) {
  5201. return to;
  5202. }
  5203. if (!to) {
  5204. return from;
  5205. }
  5206. return function mergedDataFn() {
  5207. return (extend)(isFunction(to) ? to.call(this, this) : to, isFunction(from) ? from.call(this, this) : from);
  5208. };
  5209. }
  5210. function mergeInject(to, from) {
  5211. return mergeObjectOptions(normalizeInject(to), normalizeInject(from));
  5212. }
  5213. function normalizeInject(raw) {
  5214. if (isArray(raw)) {
  5215. const res = {};
  5216. for (let i = 0; i < raw.length; i++) {
  5217. res[raw[i]] = raw[i];
  5218. }
  5219. return res;
  5220. }
  5221. return raw;
  5222. }
  5223. function mergeAsArray(to, from) {
  5224. return to ? [...new Set([].concat(to, from))] : from;
  5225. }
  5226. function mergeObjectOptions(to, from) {
  5227. return to ? extend(extend(Object.create(null), to), from) : from;
  5228. }
  5229. function mergeWatchOptions(to, from) {
  5230. if (!to)
  5231. return from;
  5232. if (!from)
  5233. return to;
  5234. const merged = extend(Object.create(null), to);
  5235. for (const key in from) {
  5236. merged[key] = mergeAsArray(to[key], from[key]);
  5237. }
  5238. return merged;
  5239. }
  5240. function initProps(instance, rawProps, isStateful, // result of bitwise flag comparison
  5241. isSSR = false) {
  5242. const props = {};
  5243. const attrs = {};
  5244. def(attrs, InternalObjectKey, 1);
  5245. instance.propsDefaults = Object.create(null);
  5246. setFullProps(instance, rawProps, props, attrs);
  5247. // ensure all declared prop keys are present
  5248. for (const key in instance.propsOptions[0]) {
  5249. if (!(key in props)) {
  5250. props[key] = undefined;
  5251. }
  5252. }
  5253. // validation
  5254. {
  5255. validateProps(rawProps || {}, props, instance);
  5256. }
  5257. if (isStateful) {
  5258. // stateful
  5259. instance.props = isSSR ? props : shallowReactive(props);
  5260. }
  5261. else {
  5262. if (!instance.type.props) {
  5263. // functional w/ optional props, props === attrs
  5264. instance.props = attrs;
  5265. }
  5266. else {
  5267. // functional w/ declared props
  5268. instance.props = props;
  5269. }
  5270. }
  5271. instance.attrs = attrs;
  5272. }
  5273. function isInHmrContext(instance) {
  5274. while (instance) {
  5275. if (instance.type.__hmrId)
  5276. return true;
  5277. instance = instance.parent;
  5278. }
  5279. }
  5280. function updateProps(instance, rawProps, rawPrevProps, optimized) {
  5281. const { props, attrs, vnode: { patchFlag } } = instance;
  5282. const rawCurrentProps = toRaw(props);
  5283. const [options] = instance.propsOptions;
  5284. let hasAttrsChanged = false;
  5285. if (
  5286. // always force full diff in dev
  5287. // - #1942 if hmr is enabled with sfc component
  5288. // - vite#872 non-sfc component used by sfc component
  5289. !(isInHmrContext(instance)) &&
  5290. (optimized || patchFlag > 0) &&
  5291. !(patchFlag & 16 /* PatchFlags.FULL_PROPS */)) {
  5292. if (patchFlag & 8 /* PatchFlags.PROPS */) {
  5293. // Compiler-generated props & no keys change, just set the updated
  5294. // the props.
  5295. const propsToUpdate = instance.vnode.dynamicProps;
  5296. for (let i = 0; i < propsToUpdate.length; i++) {
  5297. let key = propsToUpdate[i];
  5298. // skip if the prop key is a declared emit event listener
  5299. if (isEmitListener(instance.emitsOptions, key)) {
  5300. continue;
  5301. }
  5302. // PROPS flag guarantees rawProps to be non-null
  5303. const value = rawProps[key];
  5304. if (options) {
  5305. // attr / props separation was done on init and will be consistent
  5306. // in this code path, so just check if attrs have it.
  5307. if (hasOwn(attrs, key)) {
  5308. if (value !== attrs[key]) {
  5309. attrs[key] = value;
  5310. hasAttrsChanged = true;
  5311. }
  5312. }
  5313. else {
  5314. const camelizedKey = camelize(key);
  5315. props[camelizedKey] = resolvePropValue(options, rawCurrentProps, camelizedKey, value, instance, false /* isAbsent */);
  5316. }
  5317. }
  5318. else {
  5319. if (value !== attrs[key]) {
  5320. attrs[key] = value;
  5321. hasAttrsChanged = true;
  5322. }
  5323. }
  5324. }
  5325. }
  5326. }
  5327. else {
  5328. // full props update.
  5329. if (setFullProps(instance, rawProps, props, attrs)) {
  5330. hasAttrsChanged = true;
  5331. }
  5332. // in case of dynamic props, check if we need to delete keys from
  5333. // the props object
  5334. let kebabKey;
  5335. for (const key in rawCurrentProps) {
  5336. if (!rawProps ||
  5337. // for camelCase
  5338. (!hasOwn(rawProps, key) &&
  5339. // it's possible the original props was passed in as kebab-case
  5340. // and converted to camelCase (#955)
  5341. ((kebabKey = hyphenate(key)) === key || !hasOwn(rawProps, kebabKey)))) {
  5342. if (options) {
  5343. if (rawPrevProps &&
  5344. // for camelCase
  5345. (rawPrevProps[key] !== undefined ||
  5346. // for kebab-case
  5347. rawPrevProps[kebabKey] !== undefined)) {
  5348. props[key] = resolvePropValue(options, rawCurrentProps, key, undefined, instance, true /* isAbsent */);
  5349. }
  5350. }
  5351. else {
  5352. delete props[key];
  5353. }
  5354. }
  5355. }
  5356. // in the case of functional component w/o props declaration, props and
  5357. // attrs point to the same object so it should already have been updated.
  5358. if (attrs !== rawCurrentProps) {
  5359. for (const key in attrs) {
  5360. if (!rawProps ||
  5361. (!hasOwn(rawProps, key) &&
  5362. (!false ))) {
  5363. delete attrs[key];
  5364. hasAttrsChanged = true;
  5365. }
  5366. }
  5367. }
  5368. }
  5369. // trigger updates for $attrs in case it's used in component slots
  5370. if (hasAttrsChanged) {
  5371. trigger(instance, "set" /* TriggerOpTypes.SET */, '$attrs');
  5372. }
  5373. {
  5374. validateProps(rawProps || {}, props, instance);
  5375. }
  5376. }
  5377. function setFullProps(instance, rawProps, props, attrs) {
  5378. const [options, needCastKeys] = instance.propsOptions;
  5379. let hasAttrsChanged = false;
  5380. let rawCastValues;
  5381. if (rawProps) {
  5382. for (let key in rawProps) {
  5383. // key, ref are reserved and never passed down
  5384. if (isReservedProp(key)) {
  5385. continue;
  5386. }
  5387. const value = rawProps[key];
  5388. // prop option names are camelized during normalization, so to support
  5389. // kebab -> camel conversion here we need to camelize the key.
  5390. let camelKey;
  5391. if (options && hasOwn(options, (camelKey = camelize(key)))) {
  5392. if (!needCastKeys || !needCastKeys.includes(camelKey)) {
  5393. props[camelKey] = value;
  5394. }
  5395. else {
  5396. (rawCastValues || (rawCastValues = {}))[camelKey] = value;
  5397. }
  5398. }
  5399. else if (!isEmitListener(instance.emitsOptions, key)) {
  5400. if (!(key in attrs) || value !== attrs[key]) {
  5401. attrs[key] = value;
  5402. hasAttrsChanged = true;
  5403. }
  5404. }
  5405. }
  5406. }
  5407. if (needCastKeys) {
  5408. const rawCurrentProps = toRaw(props);
  5409. const castValues = rawCastValues || EMPTY_OBJ;
  5410. for (let i = 0; i < needCastKeys.length; i++) {
  5411. const key = needCastKeys[i];
  5412. props[key] = resolvePropValue(options, rawCurrentProps, key, castValues[key], instance, !hasOwn(castValues, key));
  5413. }
  5414. }
  5415. return hasAttrsChanged;
  5416. }
  5417. function resolvePropValue(options, props, key, value, instance, isAbsent) {
  5418. const opt = options[key];
  5419. if (opt != null) {
  5420. const hasDefault = hasOwn(opt, 'default');
  5421. // default values
  5422. if (hasDefault && value === undefined) {
  5423. const defaultValue = opt.default;
  5424. if (opt.type !== Function && isFunction(defaultValue)) {
  5425. const { propsDefaults } = instance;
  5426. if (key in propsDefaults) {
  5427. value = propsDefaults[key];
  5428. }
  5429. else {
  5430. setCurrentInstance(instance);
  5431. value = propsDefaults[key] = defaultValue.call(null, props);
  5432. unsetCurrentInstance();
  5433. }
  5434. }
  5435. else {
  5436. value = defaultValue;
  5437. }
  5438. }
  5439. // boolean casting
  5440. if (opt[0 /* BooleanFlags.shouldCast */]) {
  5441. if (isAbsent && !hasDefault) {
  5442. value = false;
  5443. }
  5444. else if (opt[1 /* BooleanFlags.shouldCastTrue */] &&
  5445. (value === '' || value === hyphenate(key))) {
  5446. value = true;
  5447. }
  5448. }
  5449. }
  5450. return value;
  5451. }
  5452. function normalizePropsOptions(comp, appContext, asMixin = false) {
  5453. const cache = appContext.propsCache;
  5454. const cached = cache.get(comp);
  5455. if (cached) {
  5456. return cached;
  5457. }
  5458. const raw = comp.props;
  5459. const normalized = {};
  5460. const needCastKeys = [];
  5461. // apply mixin/extends props
  5462. let hasExtends = false;
  5463. if (!isFunction(comp)) {
  5464. const extendProps = (raw) => {
  5465. hasExtends = true;
  5466. const [props, keys] = normalizePropsOptions(raw, appContext, true);
  5467. extend(normalized, props);
  5468. if (keys)
  5469. needCastKeys.push(...keys);
  5470. };
  5471. if (!asMixin && appContext.mixins.length) {
  5472. appContext.mixins.forEach(extendProps);
  5473. }
  5474. if (comp.extends) {
  5475. extendProps(comp.extends);
  5476. }
  5477. if (comp.mixins) {
  5478. comp.mixins.forEach(extendProps);
  5479. }
  5480. }
  5481. if (!raw && !hasExtends) {
  5482. if (isObject(comp)) {
  5483. cache.set(comp, EMPTY_ARR);
  5484. }
  5485. return EMPTY_ARR;
  5486. }
  5487. if (isArray(raw)) {
  5488. for (let i = 0; i < raw.length; i++) {
  5489. if (!isString(raw[i])) {
  5490. warn$1(`props must be strings when using array syntax.`, raw[i]);
  5491. }
  5492. const normalizedKey = camelize(raw[i]);
  5493. if (validatePropName(normalizedKey)) {
  5494. normalized[normalizedKey] = EMPTY_OBJ;
  5495. }
  5496. }
  5497. }
  5498. else if (raw) {
  5499. if (!isObject(raw)) {
  5500. warn$1(`invalid props options`, raw);
  5501. }
  5502. for (const key in raw) {
  5503. const normalizedKey = camelize(key);
  5504. if (validatePropName(normalizedKey)) {
  5505. const opt = raw[key];
  5506. const prop = (normalized[normalizedKey] =
  5507. isArray(opt) || isFunction(opt) ? { type: opt } : Object.assign({}, opt));
  5508. if (prop) {
  5509. const booleanIndex = getTypeIndex(Boolean, prop.type);
  5510. const stringIndex = getTypeIndex(String, prop.type);
  5511. prop[0 /* BooleanFlags.shouldCast */] = booleanIndex > -1;
  5512. prop[1 /* BooleanFlags.shouldCastTrue */] =
  5513. stringIndex < 0 || booleanIndex < stringIndex;
  5514. // if the prop needs boolean casting or default value
  5515. if (booleanIndex > -1 || hasOwn(prop, 'default')) {
  5516. needCastKeys.push(normalizedKey);
  5517. }
  5518. }
  5519. }
  5520. }
  5521. }
  5522. const res = [normalized, needCastKeys];
  5523. if (isObject(comp)) {
  5524. cache.set(comp, res);
  5525. }
  5526. return res;
  5527. }
  5528. function validatePropName(key) {
  5529. if (key[0] !== '$') {
  5530. return true;
  5531. }
  5532. else {
  5533. warn$1(`Invalid prop name: "${key}" is a reserved property.`);
  5534. }
  5535. return false;
  5536. }
  5537. // use function string name to check type constructors
  5538. // so that it works across vms / iframes.
  5539. function getType(ctor) {
  5540. const match = ctor && ctor.toString().match(/^\s*function (\w+)/);
  5541. return match ? match[1] : ctor === null ? 'null' : '';
  5542. }
  5543. function isSameType(a, b) {
  5544. return getType(a) === getType(b);
  5545. }
  5546. function getTypeIndex(type, expectedTypes) {
  5547. if (isArray(expectedTypes)) {
  5548. return expectedTypes.findIndex(t => isSameType(t, type));
  5549. }
  5550. else if (isFunction(expectedTypes)) {
  5551. return isSameType(expectedTypes, type) ? 0 : -1;
  5552. }
  5553. return -1;
  5554. }
  5555. /**
  5556. * dev only
  5557. */
  5558. function validateProps(rawProps, props, instance) {
  5559. const resolvedValues = toRaw(props);
  5560. const options = instance.propsOptions[0];
  5561. for (const key in options) {
  5562. let opt = options[key];
  5563. if (opt == null)
  5564. continue;
  5565. validateProp(key, resolvedValues[key], opt, !hasOwn(rawProps, key) && !hasOwn(rawProps, hyphenate(key)));
  5566. }
  5567. }
  5568. /**
  5569. * dev only
  5570. */
  5571. function validateProp(name, value, prop, isAbsent) {
  5572. const { type, required, validator } = prop;
  5573. // required!
  5574. if (required && isAbsent) {
  5575. warn$1('Missing required prop: "' + name + '"');
  5576. return;
  5577. }
  5578. // missing but optional
  5579. if (value == null && !prop.required) {
  5580. return;
  5581. }
  5582. // type check
  5583. if (type != null && type !== true) {
  5584. let isValid = false;
  5585. const types = isArray(type) ? type : [type];
  5586. const expectedTypes = [];
  5587. // value is valid as long as one of the specified types match
  5588. for (let i = 0; i < types.length && !isValid; i++) {
  5589. const { valid, expectedType } = assertType(value, types[i]);
  5590. expectedTypes.push(expectedType || '');
  5591. isValid = valid;
  5592. }
  5593. if (!isValid) {
  5594. warn$1(getInvalidTypeMessage(name, value, expectedTypes));
  5595. return;
  5596. }
  5597. }
  5598. // custom validator
  5599. if (validator && !validator(value)) {
  5600. warn$1('Invalid prop: custom validator check failed for prop "' + name + '".');
  5601. }
  5602. }
  5603. const isSimpleType = /*#__PURE__*/ makeMap('String,Number,Boolean,Function,Symbol,BigInt');
  5604. /**
  5605. * dev only
  5606. */
  5607. function assertType(value, type) {
  5608. let valid;
  5609. const expectedType = getType(type);
  5610. if (isSimpleType(expectedType)) {
  5611. const t = typeof value;
  5612. valid = t === expectedType.toLowerCase();
  5613. // for primitive wrapper objects
  5614. if (!valid && t === 'object') {
  5615. valid = value instanceof type;
  5616. }
  5617. }
  5618. else if (expectedType === 'Object') {
  5619. valid = isObject(value);
  5620. }
  5621. else if (expectedType === 'Array') {
  5622. valid = isArray(value);
  5623. }
  5624. else if (expectedType === 'null') {
  5625. valid = value === null;
  5626. }
  5627. else {
  5628. valid = value instanceof type;
  5629. }
  5630. return {
  5631. valid,
  5632. expectedType
  5633. };
  5634. }
  5635. /**
  5636. * dev only
  5637. */
  5638. function getInvalidTypeMessage(name, value, expectedTypes) {
  5639. let message = `Invalid prop: type check failed for prop "${name}".` +
  5640. ` Expected ${expectedTypes.map(capitalize).join(' | ')}`;
  5641. const expectedType = expectedTypes[0];
  5642. const receivedType = toRawType(value);
  5643. const expectedValue = styleValue(value, expectedType);
  5644. const receivedValue = styleValue(value, receivedType);
  5645. // check if we need to specify expected value
  5646. if (expectedTypes.length === 1 &&
  5647. isExplicable(expectedType) &&
  5648. !isBoolean(expectedType, receivedType)) {
  5649. message += ` with value ${expectedValue}`;
  5650. }
  5651. message += `, got ${receivedType} `;
  5652. // check if we need to specify received value
  5653. if (isExplicable(receivedType)) {
  5654. message += `with value ${receivedValue}.`;
  5655. }
  5656. return message;
  5657. }
  5658. /**
  5659. * dev only
  5660. */
  5661. function styleValue(value, type) {
  5662. if (type === 'String') {
  5663. return `"${value}"`;
  5664. }
  5665. else if (type === 'Number') {
  5666. return `${Number(value)}`;
  5667. }
  5668. else {
  5669. return `${value}`;
  5670. }
  5671. }
  5672. /**
  5673. * dev only
  5674. */
  5675. function isExplicable(type) {
  5676. const explicitTypes = ['string', 'number', 'boolean'];
  5677. return explicitTypes.some(elem => type.toLowerCase() === elem);
  5678. }
  5679. /**
  5680. * dev only
  5681. */
  5682. function isBoolean(...args) {
  5683. return args.some(elem => elem.toLowerCase() === 'boolean');
  5684. }
  5685. const isInternalKey = (key) => key[0] === '_' || key === '$stable';
  5686. const normalizeSlotValue = (value) => isArray(value)
  5687. ? value.map(normalizeVNode)
  5688. : [normalizeVNode(value)];
  5689. const normalizeSlot = (key, rawSlot, ctx) => {
  5690. if (rawSlot._n) {
  5691. // already normalized - #5353
  5692. return rawSlot;
  5693. }
  5694. const normalized = withCtx((...args) => {
  5695. if (true && currentInstance) {
  5696. warn$1(`Slot "${key}" invoked outside of the render function: ` +
  5697. `this will not track dependencies used in the slot. ` +
  5698. `Invoke the slot function inside the render function instead.`);
  5699. }
  5700. return normalizeSlotValue(rawSlot(...args));
  5701. }, ctx);
  5702. normalized._c = false;
  5703. return normalized;
  5704. };
  5705. const normalizeObjectSlots = (rawSlots, slots, instance) => {
  5706. const ctx = rawSlots._ctx;
  5707. for (const key in rawSlots) {
  5708. if (isInternalKey(key))
  5709. continue;
  5710. const value = rawSlots[key];
  5711. if (isFunction(value)) {
  5712. slots[key] = normalizeSlot(key, value, ctx);
  5713. }
  5714. else if (value != null) {
  5715. {
  5716. warn$1(`Non-function value encountered for slot "${key}". ` +
  5717. `Prefer function slots for better performance.`);
  5718. }
  5719. const normalized = normalizeSlotValue(value);
  5720. slots[key] = () => normalized;
  5721. }
  5722. }
  5723. };
  5724. const normalizeVNodeSlots = (instance, children) => {
  5725. if (!isKeepAlive(instance.vnode) &&
  5726. !(false )) {
  5727. warn$1(`Non-function value encountered for default slot. ` +
  5728. `Prefer function slots for better performance.`);
  5729. }
  5730. const normalized = normalizeSlotValue(children);
  5731. instance.slots.default = () => normalized;
  5732. };
  5733. const initSlots = (instance, children) => {
  5734. if (instance.vnode.shapeFlag & 32 /* ShapeFlags.SLOTS_CHILDREN */) {
  5735. const type = children._;
  5736. if (type) {
  5737. // users can get the shallow readonly version of the slots object through `this.$slots`,
  5738. // we should avoid the proxy object polluting the slots of the internal instance
  5739. instance.slots = toRaw(children);
  5740. // make compiler marker non-enumerable
  5741. def(children, '_', type);
  5742. }
  5743. else {
  5744. normalizeObjectSlots(children, (instance.slots = {}));
  5745. }
  5746. }
  5747. else {
  5748. instance.slots = {};
  5749. if (children) {
  5750. normalizeVNodeSlots(instance, children);
  5751. }
  5752. }
  5753. def(instance.slots, InternalObjectKey, 1);
  5754. };
  5755. const updateSlots = (instance, children, optimized) => {
  5756. const { vnode, slots } = instance;
  5757. let needDeletionCheck = true;
  5758. let deletionComparisonTarget = EMPTY_OBJ;
  5759. if (vnode.shapeFlag & 32 /* ShapeFlags.SLOTS_CHILDREN */) {
  5760. const type = children._;
  5761. if (type) {
  5762. // compiled slots.
  5763. if (isHmrUpdating) {
  5764. // Parent was HMR updated so slot content may have changed.
  5765. // force update slots and mark instance for hmr as well
  5766. extend(slots, children);
  5767. }
  5768. else if (optimized && type === 1 /* SlotFlags.STABLE */) {
  5769. // compiled AND stable.
  5770. // no need to update, and skip stale slots removal.
  5771. needDeletionCheck = false;
  5772. }
  5773. else {
  5774. // compiled but dynamic (v-if/v-for on slots) - update slots, but skip
  5775. // normalization.
  5776. extend(slots, children);
  5777. // #2893
  5778. // when rendering the optimized slots by manually written render function,
  5779. // we need to delete the `slots._` flag if necessary to make subsequent updates reliable,
  5780. // i.e. let the `renderSlot` create the bailed Fragment
  5781. if (!optimized && type === 1 /* SlotFlags.STABLE */) {
  5782. delete slots._;
  5783. }
  5784. }
  5785. }
  5786. else {
  5787. needDeletionCheck = !children.$stable;
  5788. normalizeObjectSlots(children, slots);
  5789. }
  5790. deletionComparisonTarget = children;
  5791. }
  5792. else if (children) {
  5793. // non slot object children (direct value) passed to a component
  5794. normalizeVNodeSlots(instance, children);
  5795. deletionComparisonTarget = { default: 1 };
  5796. }
  5797. // delete stale slots
  5798. if (needDeletionCheck) {
  5799. for (const key in slots) {
  5800. if (!isInternalKey(key) && !(key in deletionComparisonTarget)) {
  5801. delete slots[key];
  5802. }
  5803. }
  5804. }
  5805. };
  5806. function createAppContext() {
  5807. return {
  5808. app: null,
  5809. config: {
  5810. isNativeTag: NO,
  5811. performance: false,
  5812. globalProperties: {},
  5813. optionMergeStrategies: {},
  5814. errorHandler: undefined,
  5815. warnHandler: undefined,
  5816. compilerOptions: {}
  5817. },
  5818. mixins: [],
  5819. components: {},
  5820. directives: {},
  5821. provides: Object.create(null),
  5822. optionsCache: new WeakMap(),
  5823. propsCache: new WeakMap(),
  5824. emitsCache: new WeakMap()
  5825. };
  5826. }
  5827. let uid = 0;
  5828. function createAppAPI(render, hydrate) {
  5829. return function createApp(rootComponent, rootProps = null) {
  5830. if (!isFunction(rootComponent)) {
  5831. rootComponent = Object.assign({}, rootComponent);
  5832. }
  5833. if (rootProps != null && !isObject(rootProps)) {
  5834. warn$1(`root props passed to app.mount() must be an object.`);
  5835. rootProps = null;
  5836. }
  5837. const context = createAppContext();
  5838. const installedPlugins = new Set();
  5839. let isMounted = false;
  5840. const app = (context.app = {
  5841. _uid: uid++,
  5842. _component: rootComponent,
  5843. _props: rootProps,
  5844. _container: null,
  5845. _context: context,
  5846. _instance: null,
  5847. version,
  5848. get config() {
  5849. return context.config;
  5850. },
  5851. set config(v) {
  5852. {
  5853. warn$1(`app.config cannot be replaced. Modify individual options instead.`);
  5854. }
  5855. },
  5856. use(plugin, ...options) {
  5857. if (installedPlugins.has(plugin)) {
  5858. warn$1(`Plugin has already been applied to target app.`);
  5859. }
  5860. else if (plugin && isFunction(plugin.install)) {
  5861. installedPlugins.add(plugin);
  5862. plugin.install(app, ...options);
  5863. }
  5864. else if (isFunction(plugin)) {
  5865. installedPlugins.add(plugin);
  5866. plugin(app, ...options);
  5867. }
  5868. else {
  5869. warn$1(`A plugin must either be a function or an object with an "install" ` +
  5870. `function.`);
  5871. }
  5872. return app;
  5873. },
  5874. mixin(mixin) {
  5875. {
  5876. if (!context.mixins.includes(mixin)) {
  5877. context.mixins.push(mixin);
  5878. }
  5879. else {
  5880. warn$1('Mixin has already been applied to target app' +
  5881. (mixin.name ? `: ${mixin.name}` : ''));
  5882. }
  5883. }
  5884. return app;
  5885. },
  5886. component(name, component) {
  5887. {
  5888. validateComponentName(name, context.config);
  5889. }
  5890. if (!component) {
  5891. return context.components[name];
  5892. }
  5893. if (context.components[name]) {
  5894. warn$1(`Component "${name}" has already been registered in target app.`);
  5895. }
  5896. context.components[name] = component;
  5897. return app;
  5898. },
  5899. directive(name, directive) {
  5900. {
  5901. validateDirectiveName(name);
  5902. }
  5903. if (!directive) {
  5904. return context.directives[name];
  5905. }
  5906. if (context.directives[name]) {
  5907. warn$1(`Directive "${name}" has already been registered in target app.`);
  5908. }
  5909. context.directives[name] = directive;
  5910. return app;
  5911. },
  5912. mount(rootContainer, isHydrate, isSVG) {
  5913. if (!isMounted) {
  5914. // #5571
  5915. if (rootContainer.__vue_app__) {
  5916. warn$1(`There is already an app instance mounted on the host container.\n` +
  5917. ` If you want to mount another app on the same host container,` +
  5918. ` you need to unmount the previous app by calling \`app.unmount()\` first.`);
  5919. }
  5920. const vnode = createVNode(rootComponent, rootProps);
  5921. // store app context on the root VNode.
  5922. // this will be set on the root instance on initial mount.
  5923. vnode.appContext = context;
  5924. // HMR root reload
  5925. {
  5926. context.reload = () => {
  5927. render(cloneVNode(vnode), rootContainer, isSVG);
  5928. };
  5929. }
  5930. if (isHydrate && hydrate) {
  5931. hydrate(vnode, rootContainer);
  5932. }
  5933. else {
  5934. render(vnode, rootContainer, isSVG);
  5935. }
  5936. isMounted = true;
  5937. app._container = rootContainer;
  5938. rootContainer.__vue_app__ = app;
  5939. {
  5940. app._instance = vnode.component;
  5941. devtoolsInitApp(app, version);
  5942. }
  5943. return getExposeProxy(vnode.component) || vnode.component.proxy;
  5944. }
  5945. else {
  5946. warn$1(`App has already been mounted.\n` +
  5947. `If you want to remount the same app, move your app creation logic ` +
  5948. `into a factory function and create fresh app instances for each ` +
  5949. `mount - e.g. \`const createMyApp = () => createApp(App)\``);
  5950. }
  5951. },
  5952. unmount() {
  5953. if (isMounted) {
  5954. render(null, app._container);
  5955. {
  5956. app._instance = null;
  5957. devtoolsUnmountApp(app);
  5958. }
  5959. delete app._container.__vue_app__;
  5960. }
  5961. else {
  5962. warn$1(`Cannot unmount an app that is not mounted.`);
  5963. }
  5964. },
  5965. provide(key, value) {
  5966. if (key in context.provides) {
  5967. warn$1(`App already provides property with key "${String(key)}". ` +
  5968. `It will be overwritten with the new value.`);
  5969. }
  5970. context.provides[key] = value;
  5971. return app;
  5972. }
  5973. });
  5974. return app;
  5975. };
  5976. }
  5977. /**
  5978. * Function for handling a template ref
  5979. */
  5980. function setRef(rawRef, oldRawRef, parentSuspense, vnode, isUnmount = false) {
  5981. if (isArray(rawRef)) {
  5982. rawRef.forEach((r, i) => setRef(r, oldRawRef && (isArray(oldRawRef) ? oldRawRef[i] : oldRawRef), parentSuspense, vnode, isUnmount));
  5983. return;
  5984. }
  5985. if (isAsyncWrapper(vnode) && !isUnmount) {
  5986. // when mounting async components, nothing needs to be done,
  5987. // because the template ref is forwarded to inner component
  5988. return;
  5989. }
  5990. const refValue = vnode.shapeFlag & 4 /* ShapeFlags.STATEFUL_COMPONENT */
  5991. ? getExposeProxy(vnode.component) || vnode.component.proxy
  5992. : vnode.el;
  5993. const value = isUnmount ? null : refValue;
  5994. const { i: owner, r: ref } = rawRef;
  5995. if (!owner) {
  5996. warn$1(`Missing ref owner context. ref cannot be used on hoisted vnodes. ` +
  5997. `A vnode with ref must be created inside the render function.`);
  5998. return;
  5999. }
  6000. const oldRef = oldRawRef && oldRawRef.r;
  6001. const refs = owner.refs === EMPTY_OBJ ? (owner.refs = {}) : owner.refs;
  6002. const setupState = owner.setupState;
  6003. // dynamic ref changed. unset old ref
  6004. if (oldRef != null && oldRef !== ref) {
  6005. if (isString(oldRef)) {
  6006. refs[oldRef] = null;
  6007. if (hasOwn(setupState, oldRef)) {
  6008. setupState[oldRef] = null;
  6009. }
  6010. }
  6011. else if (isRef(oldRef)) {
  6012. oldRef.value = null;
  6013. }
  6014. }
  6015. if (isFunction(ref)) {
  6016. callWithErrorHandling(ref, owner, 12 /* ErrorCodes.FUNCTION_REF */, [value, refs]);
  6017. }
  6018. else {
  6019. const _isString = isString(ref);
  6020. const _isRef = isRef(ref);
  6021. if (_isString || _isRef) {
  6022. const doSet = () => {
  6023. if (rawRef.f) {
  6024. const existing = _isString
  6025. ? hasOwn(setupState, ref)
  6026. ? setupState[ref]
  6027. : refs[ref]
  6028. : ref.value;
  6029. if (isUnmount) {
  6030. isArray(existing) && remove(existing, refValue);
  6031. }
  6032. else {
  6033. if (!isArray(existing)) {
  6034. if (_isString) {
  6035. refs[ref] = [refValue];
  6036. if (hasOwn(setupState, ref)) {
  6037. setupState[ref] = refs[ref];
  6038. }
  6039. }
  6040. else {
  6041. ref.value = [refValue];
  6042. if (rawRef.k)
  6043. refs[rawRef.k] = ref.value;
  6044. }
  6045. }
  6046. else if (!existing.includes(refValue)) {
  6047. existing.push(refValue);
  6048. }
  6049. }
  6050. }
  6051. else if (_isString) {
  6052. refs[ref] = value;
  6053. if (hasOwn(setupState, ref)) {
  6054. setupState[ref] = value;
  6055. }
  6056. }
  6057. else if (_isRef) {
  6058. ref.value = value;
  6059. if (rawRef.k)
  6060. refs[rawRef.k] = value;
  6061. }
  6062. else {
  6063. warn$1('Invalid template ref type:', ref, `(${typeof ref})`);
  6064. }
  6065. };
  6066. if (value) {
  6067. doSet.id = -1;
  6068. queuePostRenderEffect(doSet, parentSuspense);
  6069. }
  6070. else {
  6071. doSet();
  6072. }
  6073. }
  6074. else {
  6075. warn$1('Invalid template ref type:', ref, `(${typeof ref})`);
  6076. }
  6077. }
  6078. }
  6079. let hasMismatch = false;
  6080. const isSVGContainer = (container) => /svg/.test(container.namespaceURI) && container.tagName !== 'foreignObject';
  6081. const isComment = (node) => node.nodeType === 8 /* DOMNodeTypes.COMMENT */;
  6082. // Note: hydration is DOM-specific
  6083. // But we have to place it in core due to tight coupling with core - splitting
  6084. // it out creates a ton of unnecessary complexity.
  6085. // Hydration also depends on some renderer internal logic which needs to be
  6086. // passed in via arguments.
  6087. function createHydrationFunctions(rendererInternals) {
  6088. const { mt: mountComponent, p: patch, o: { patchProp, createText, nextSibling, parentNode, remove, insert, createComment } } = rendererInternals;
  6089. const hydrate = (vnode, container) => {
  6090. if (!container.hasChildNodes()) {
  6091. warn$1(`Attempting to hydrate existing markup but container is empty. ` +
  6092. `Performing full mount instead.`);
  6093. patch(null, vnode, container);
  6094. flushPostFlushCbs();
  6095. container._vnode = vnode;
  6096. return;
  6097. }
  6098. hasMismatch = false;
  6099. hydrateNode(container.firstChild, vnode, null, null, null);
  6100. flushPostFlushCbs();
  6101. container._vnode = vnode;
  6102. if (hasMismatch && !false) {
  6103. // this error should show up in production
  6104. console.error(`Hydration completed but contains mismatches.`);
  6105. }
  6106. };
  6107. const hydrateNode = (node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized = false) => {
  6108. const isFragmentStart = isComment(node) && node.data === '[';
  6109. const onMismatch = () => handleMismatch(node, vnode, parentComponent, parentSuspense, slotScopeIds, isFragmentStart);
  6110. const { type, ref, shapeFlag, patchFlag } = vnode;
  6111. let domType = node.nodeType;
  6112. vnode.el = node;
  6113. if (patchFlag === -2 /* PatchFlags.BAIL */) {
  6114. optimized = false;
  6115. vnode.dynamicChildren = null;
  6116. }
  6117. let nextNode = null;
  6118. switch (type) {
  6119. case Text:
  6120. if (domType !== 3 /* DOMNodeTypes.TEXT */) {
  6121. // #5728 empty text node inside a slot can cause hydration failure
  6122. // because the server rendered HTML won't contain a text node
  6123. if (vnode.children === '') {
  6124. insert((vnode.el = createText('')), parentNode(node), node);
  6125. nextNode = node;
  6126. }
  6127. else {
  6128. nextNode = onMismatch();
  6129. }
  6130. }
  6131. else {
  6132. if (node.data !== vnode.children) {
  6133. hasMismatch = true;
  6134. warn$1(`Hydration text mismatch:` +
  6135. `\n- Client: ${JSON.stringify(node.data)}` +
  6136. `\n- Server: ${JSON.stringify(vnode.children)}`);
  6137. node.data = vnode.children;
  6138. }
  6139. nextNode = nextSibling(node);
  6140. }
  6141. break;
  6142. case Comment:
  6143. if (domType !== 8 /* DOMNodeTypes.COMMENT */ || isFragmentStart) {
  6144. nextNode = onMismatch();
  6145. }
  6146. else {
  6147. nextNode = nextSibling(node);
  6148. }
  6149. break;
  6150. case Static:
  6151. if (isFragmentStart) {
  6152. // entire template is static but SSRed as a fragment
  6153. node = nextSibling(node);
  6154. domType = node.nodeType;
  6155. }
  6156. if (domType === 1 /* DOMNodeTypes.ELEMENT */ || domType === 3 /* DOMNodeTypes.TEXT */) {
  6157. // determine anchor, adopt content
  6158. nextNode = node;
  6159. // if the static vnode has its content stripped during build,
  6160. // adopt it from the server-rendered HTML.
  6161. const needToAdoptContent = !vnode.children.length;
  6162. for (let i = 0; i < vnode.staticCount; i++) {
  6163. if (needToAdoptContent)
  6164. vnode.children +=
  6165. nextNode.nodeType === 1 /* DOMNodeTypes.ELEMENT */
  6166. ? nextNode.outerHTML
  6167. : nextNode.data;
  6168. if (i === vnode.staticCount - 1) {
  6169. vnode.anchor = nextNode;
  6170. }
  6171. nextNode = nextSibling(nextNode);
  6172. }
  6173. return isFragmentStart ? nextSibling(nextNode) : nextNode;
  6174. }
  6175. else {
  6176. onMismatch();
  6177. }
  6178. break;
  6179. case Fragment:
  6180. if (!isFragmentStart) {
  6181. nextNode = onMismatch();
  6182. }
  6183. else {
  6184. nextNode = hydrateFragment(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized);
  6185. }
  6186. break;
  6187. default:
  6188. if (shapeFlag & 1 /* ShapeFlags.ELEMENT */) {
  6189. if (domType !== 1 /* DOMNodeTypes.ELEMENT */ ||
  6190. vnode.type.toLowerCase() !==
  6191. node.tagName.toLowerCase()) {
  6192. nextNode = onMismatch();
  6193. }
  6194. else {
  6195. nextNode = hydrateElement(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized);
  6196. }
  6197. }
  6198. else if (shapeFlag & 6 /* ShapeFlags.COMPONENT */) {
  6199. // when setting up the render effect, if the initial vnode already
  6200. // has .el set, the component will perform hydration instead of mount
  6201. // on its sub-tree.
  6202. vnode.slotScopeIds = slotScopeIds;
  6203. const container = parentNode(node);
  6204. mountComponent(vnode, container, null, parentComponent, parentSuspense, isSVGContainer(container), optimized);
  6205. // component may be async, so in the case of fragments we cannot rely
  6206. // on component's rendered output to determine the end of the fragment
  6207. // instead, we do a lookahead to find the end anchor node.
  6208. nextNode = isFragmentStart
  6209. ? locateClosingAsyncAnchor(node)
  6210. : nextSibling(node);
  6211. // #4293 teleport as component root
  6212. if (nextNode &&
  6213. isComment(nextNode) &&
  6214. nextNode.data === 'teleport end') {
  6215. nextNode = nextSibling(nextNode);
  6216. }
  6217. // #3787
  6218. // if component is async, it may get moved / unmounted before its
  6219. // inner component is loaded, so we need to give it a placeholder
  6220. // vnode that matches its adopted DOM.
  6221. if (isAsyncWrapper(vnode)) {
  6222. let subTree;
  6223. if (isFragmentStart) {
  6224. subTree = createVNode(Fragment);
  6225. subTree.anchor = nextNode
  6226. ? nextNode.previousSibling
  6227. : container.lastChild;
  6228. }
  6229. else {
  6230. subTree =
  6231. node.nodeType === 3 ? createTextVNode('') : createVNode('div');
  6232. }
  6233. subTree.el = node;
  6234. vnode.component.subTree = subTree;
  6235. }
  6236. }
  6237. else if (shapeFlag & 64 /* ShapeFlags.TELEPORT */) {
  6238. if (domType !== 8 /* DOMNodeTypes.COMMENT */) {
  6239. nextNode = onMismatch();
  6240. }
  6241. else {
  6242. nextNode = vnode.type.hydrate(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized, rendererInternals, hydrateChildren);
  6243. }
  6244. }
  6245. else if (shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
  6246. nextNode = vnode.type.hydrate(node, vnode, parentComponent, parentSuspense, isSVGContainer(parentNode(node)), slotScopeIds, optimized, rendererInternals, hydrateNode);
  6247. }
  6248. else {
  6249. warn$1('Invalid HostVNode type:', type, `(${typeof type})`);
  6250. }
  6251. }
  6252. if (ref != null) {
  6253. setRef(ref, null, parentSuspense, vnode);
  6254. }
  6255. return nextNode;
  6256. };
  6257. const hydrateElement = (el, vnode, parentComponent, parentSuspense, slotScopeIds, optimized) => {
  6258. optimized = optimized || !!vnode.dynamicChildren;
  6259. const { type, props, patchFlag, shapeFlag, dirs } = vnode;
  6260. // #4006 for form elements with non-string v-model value bindings
  6261. // e.g. <option :value="obj">, <input type="checkbox" :true-value="1">
  6262. const forcePatchValue = (type === 'input' && dirs) || type === 'option';
  6263. // skip props & children if this is hoisted static nodes
  6264. // #5405 in dev, always hydrate children for HMR
  6265. {
  6266. if (dirs) {
  6267. invokeDirectiveHook(vnode, null, parentComponent, 'created');
  6268. }
  6269. // props
  6270. if (props) {
  6271. if (forcePatchValue ||
  6272. !optimized ||
  6273. patchFlag & (16 /* PatchFlags.FULL_PROPS */ | 32 /* PatchFlags.HYDRATE_EVENTS */)) {
  6274. for (const key in props) {
  6275. if ((forcePatchValue && key.endsWith('value')) ||
  6276. (isOn(key) && !isReservedProp(key))) {
  6277. patchProp(el, key, null, props[key], false, undefined, parentComponent);
  6278. }
  6279. }
  6280. }
  6281. else if (props.onClick) {
  6282. // Fast path for click listeners (which is most often) to avoid
  6283. // iterating through props.
  6284. patchProp(el, 'onClick', null, props.onClick, false, undefined, parentComponent);
  6285. }
  6286. }
  6287. // vnode / directive hooks
  6288. let vnodeHooks;
  6289. if ((vnodeHooks = props && props.onVnodeBeforeMount)) {
  6290. invokeVNodeHook(vnodeHooks, parentComponent, vnode);
  6291. }
  6292. if (dirs) {
  6293. invokeDirectiveHook(vnode, null, parentComponent, 'beforeMount');
  6294. }
  6295. if ((vnodeHooks = props && props.onVnodeMounted) || dirs) {
  6296. queueEffectWithSuspense(() => {
  6297. vnodeHooks && invokeVNodeHook(vnodeHooks, parentComponent, vnode);
  6298. dirs && invokeDirectiveHook(vnode, null, parentComponent, 'mounted');
  6299. }, parentSuspense);
  6300. }
  6301. // children
  6302. if (shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */ &&
  6303. // skip if element has innerHTML / textContent
  6304. !(props && (props.innerHTML || props.textContent))) {
  6305. let next = hydrateChildren(el.firstChild, vnode, el, parentComponent, parentSuspense, slotScopeIds, optimized);
  6306. let hasWarned = false;
  6307. while (next) {
  6308. hasMismatch = true;
  6309. if (!hasWarned) {
  6310. warn$1(`Hydration children mismatch in <${vnode.type}>: ` +
  6311. `server rendered element contains more child nodes than client vdom.`);
  6312. hasWarned = true;
  6313. }
  6314. // The SSRed DOM contains more nodes than it should. Remove them.
  6315. const cur = next;
  6316. next = next.nextSibling;
  6317. remove(cur);
  6318. }
  6319. }
  6320. else if (shapeFlag & 8 /* ShapeFlags.TEXT_CHILDREN */) {
  6321. if (el.textContent !== vnode.children) {
  6322. hasMismatch = true;
  6323. warn$1(`Hydration text content mismatch in <${vnode.type}>:\n` +
  6324. `- Client: ${el.textContent}\n` +
  6325. `- Server: ${vnode.children}`);
  6326. el.textContent = vnode.children;
  6327. }
  6328. }
  6329. }
  6330. return el.nextSibling;
  6331. };
  6332. const hydrateChildren = (node, parentVNode, container, parentComponent, parentSuspense, slotScopeIds, optimized) => {
  6333. optimized = optimized || !!parentVNode.dynamicChildren;
  6334. const children = parentVNode.children;
  6335. const l = children.length;
  6336. let hasWarned = false;
  6337. for (let i = 0; i < l; i++) {
  6338. const vnode = optimized
  6339. ? children[i]
  6340. : (children[i] = normalizeVNode(children[i]));
  6341. if (node) {
  6342. node = hydrateNode(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized);
  6343. }
  6344. else if (vnode.type === Text && !vnode.children) {
  6345. continue;
  6346. }
  6347. else {
  6348. hasMismatch = true;
  6349. if (!hasWarned) {
  6350. warn$1(`Hydration children mismatch in <${container.tagName.toLowerCase()}>: ` +
  6351. `server rendered element contains fewer child nodes than client vdom.`);
  6352. hasWarned = true;
  6353. }
  6354. // the SSRed DOM didn't contain enough nodes. Mount the missing ones.
  6355. patch(null, vnode, container, null, parentComponent, parentSuspense, isSVGContainer(container), slotScopeIds);
  6356. }
  6357. }
  6358. return node;
  6359. };
  6360. const hydrateFragment = (node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized) => {
  6361. const { slotScopeIds: fragmentSlotScopeIds } = vnode;
  6362. if (fragmentSlotScopeIds) {
  6363. slotScopeIds = slotScopeIds
  6364. ? slotScopeIds.concat(fragmentSlotScopeIds)
  6365. : fragmentSlotScopeIds;
  6366. }
  6367. const container = parentNode(node);
  6368. const next = hydrateChildren(nextSibling(node), vnode, container, parentComponent, parentSuspense, slotScopeIds, optimized);
  6369. if (next && isComment(next) && next.data === ']') {
  6370. return nextSibling((vnode.anchor = next));
  6371. }
  6372. else {
  6373. // fragment didn't hydrate successfully, since we didn't get a end anchor
  6374. // back. This should have led to node/children mismatch warnings.
  6375. hasMismatch = true;
  6376. // since the anchor is missing, we need to create one and insert it
  6377. insert((vnode.anchor = createComment(`]`)), container, next);
  6378. return next;
  6379. }
  6380. };
  6381. const handleMismatch = (node, vnode, parentComponent, parentSuspense, slotScopeIds, isFragment) => {
  6382. hasMismatch = true;
  6383. warn$1(`Hydration node mismatch:\n- Client vnode:`, vnode.type, `\n- Server rendered DOM:`, node, node.nodeType === 3 /* DOMNodeTypes.TEXT */
  6384. ? `(text)`
  6385. : isComment(node) && node.data === '['
  6386. ? `(start of fragment)`
  6387. : ``);
  6388. vnode.el = null;
  6389. if (isFragment) {
  6390. // remove excessive fragment nodes
  6391. const end = locateClosingAsyncAnchor(node);
  6392. while (true) {
  6393. const next = nextSibling(node);
  6394. if (next && next !== end) {
  6395. remove(next);
  6396. }
  6397. else {
  6398. break;
  6399. }
  6400. }
  6401. }
  6402. const next = nextSibling(node);
  6403. const container = parentNode(node);
  6404. remove(node);
  6405. patch(null, vnode, container, next, parentComponent, parentSuspense, isSVGContainer(container), slotScopeIds);
  6406. return next;
  6407. };
  6408. const locateClosingAsyncAnchor = (node) => {
  6409. let match = 0;
  6410. while (node) {
  6411. node = nextSibling(node);
  6412. if (node && isComment(node)) {
  6413. if (node.data === '[')
  6414. match++;
  6415. if (node.data === ']') {
  6416. if (match === 0) {
  6417. return nextSibling(node);
  6418. }
  6419. else {
  6420. match--;
  6421. }
  6422. }
  6423. }
  6424. }
  6425. return node;
  6426. };
  6427. return [hydrate, hydrateNode];
  6428. }
  6429. /* eslint-disable no-restricted-globals */
  6430. let supported;
  6431. let perf;
  6432. function startMeasure(instance, type) {
  6433. if (instance.appContext.config.performance && isSupported()) {
  6434. perf.mark(`vue-${type}-${instance.uid}`);
  6435. }
  6436. {
  6437. devtoolsPerfStart(instance, type, isSupported() ? perf.now() : Date.now());
  6438. }
  6439. }
  6440. function endMeasure(instance, type) {
  6441. if (instance.appContext.config.performance && isSupported()) {
  6442. const startTag = `vue-${type}-${instance.uid}`;
  6443. const endTag = startTag + `:end`;
  6444. perf.mark(endTag);
  6445. perf.measure(`<${formatComponentName(instance, instance.type)}> ${type}`, startTag, endTag);
  6446. perf.clearMarks(startTag);
  6447. perf.clearMarks(endTag);
  6448. }
  6449. {
  6450. devtoolsPerfEnd(instance, type, isSupported() ? perf.now() : Date.now());
  6451. }
  6452. }
  6453. function isSupported() {
  6454. if (supported !== undefined) {
  6455. return supported;
  6456. }
  6457. if (typeof window !== 'undefined' && window.performance) {
  6458. supported = true;
  6459. perf = window.performance;
  6460. }
  6461. else {
  6462. supported = false;
  6463. }
  6464. return supported;
  6465. }
  6466. const queuePostRenderEffect = queueEffectWithSuspense
  6467. ;
  6468. /**
  6469. * The createRenderer function accepts two generic arguments:
  6470. * HostNode and HostElement, corresponding to Node and Element types in the
  6471. * host environment. For example, for runtime-dom, HostNode would be the DOM
  6472. * `Node` interface and HostElement would be the DOM `Element` interface.
  6473. *
  6474. * Custom renderers can pass in the platform specific types like this:
  6475. *
  6476. * ``` js
  6477. * const { render, createApp } = createRenderer<Node, Element>({
  6478. * patchProp,
  6479. * ...nodeOps
  6480. * })
  6481. * ```
  6482. */
  6483. function createRenderer(options) {
  6484. return baseCreateRenderer(options);
  6485. }
  6486. // Separate API for creating hydration-enabled renderer.
  6487. // Hydration logic is only used when calling this function, making it
  6488. // tree-shakable.
  6489. function createHydrationRenderer(options) {
  6490. return baseCreateRenderer(options, createHydrationFunctions);
  6491. }
  6492. // implementation
  6493. function baseCreateRenderer(options, createHydrationFns) {
  6494. const target = getGlobalThis();
  6495. target.__VUE__ = true;
  6496. {
  6497. setDevtoolsHook(target.__VUE_DEVTOOLS_GLOBAL_HOOK__, target);
  6498. }
  6499. const { insert: hostInsert, remove: hostRemove, patchProp: hostPatchProp, createElement: hostCreateElement, createText: hostCreateText, createComment: hostCreateComment, setText: hostSetText, setElementText: hostSetElementText, parentNode: hostParentNode, nextSibling: hostNextSibling, setScopeId: hostSetScopeId = NOOP, insertStaticContent: hostInsertStaticContent } = options;
  6500. // Note: functions inside this closure should use `const xxx = () => {}`
  6501. // style in order to prevent being inlined by minifiers.
  6502. const patch = (n1, n2, container, anchor = null, parentComponent = null, parentSuspense = null, isSVG = false, slotScopeIds = null, optimized = isHmrUpdating ? false : !!n2.dynamicChildren) => {
  6503. if (n1 === n2) {
  6504. return;
  6505. }
  6506. // patching & not same type, unmount old tree
  6507. if (n1 && !isSameVNodeType(n1, n2)) {
  6508. anchor = getNextHostNode(n1);
  6509. unmount(n1, parentComponent, parentSuspense, true);
  6510. n1 = null;
  6511. }
  6512. if (n2.patchFlag === -2 /* PatchFlags.BAIL */) {
  6513. optimized = false;
  6514. n2.dynamicChildren = null;
  6515. }
  6516. const { type, ref, shapeFlag } = n2;
  6517. switch (type) {
  6518. case Text:
  6519. processText(n1, n2, container, anchor);
  6520. break;
  6521. case Comment:
  6522. processCommentNode(n1, n2, container, anchor);
  6523. break;
  6524. case Static:
  6525. if (n1 == null) {
  6526. mountStaticNode(n2, container, anchor, isSVG);
  6527. }
  6528. else {
  6529. patchStaticNode(n1, n2, container, isSVG);
  6530. }
  6531. break;
  6532. case Fragment:
  6533. processFragment(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6534. break;
  6535. default:
  6536. if (shapeFlag & 1 /* ShapeFlags.ELEMENT */) {
  6537. processElement(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6538. }
  6539. else if (shapeFlag & 6 /* ShapeFlags.COMPONENT */) {
  6540. processComponent(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6541. }
  6542. else if (shapeFlag & 64 /* ShapeFlags.TELEPORT */) {
  6543. type.process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, internals);
  6544. }
  6545. else if (shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
  6546. type.process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, internals);
  6547. }
  6548. else {
  6549. warn$1('Invalid VNode type:', type, `(${typeof type})`);
  6550. }
  6551. }
  6552. // set ref
  6553. if (ref != null && parentComponent) {
  6554. setRef(ref, n1 && n1.ref, parentSuspense, n2 || n1, !n2);
  6555. }
  6556. };
  6557. const processText = (n1, n2, container, anchor) => {
  6558. if (n1 == null) {
  6559. hostInsert((n2.el = hostCreateText(n2.children)), container, anchor);
  6560. }
  6561. else {
  6562. const el = (n2.el = n1.el);
  6563. if (n2.children !== n1.children) {
  6564. hostSetText(el, n2.children);
  6565. }
  6566. }
  6567. };
  6568. const processCommentNode = (n1, n2, container, anchor) => {
  6569. if (n1 == null) {
  6570. hostInsert((n2.el = hostCreateComment(n2.children || '')), container, anchor);
  6571. }
  6572. else {
  6573. // there's no support for dynamic comments
  6574. n2.el = n1.el;
  6575. }
  6576. };
  6577. const mountStaticNode = (n2, container, anchor, isSVG) => {
  6578. [n2.el, n2.anchor] = hostInsertStaticContent(n2.children, container, anchor, isSVG, n2.el, n2.anchor);
  6579. };
  6580. /**
  6581. * Dev / HMR only
  6582. */
  6583. const patchStaticNode = (n1, n2, container, isSVG) => {
  6584. // static nodes are only patched during dev for HMR
  6585. if (n2.children !== n1.children) {
  6586. const anchor = hostNextSibling(n1.anchor);
  6587. // remove existing
  6588. removeStaticNode(n1);
  6589. [n2.el, n2.anchor] = hostInsertStaticContent(n2.children, container, anchor, isSVG);
  6590. }
  6591. else {
  6592. n2.el = n1.el;
  6593. n2.anchor = n1.anchor;
  6594. }
  6595. };
  6596. const moveStaticNode = ({ el, anchor }, container, nextSibling) => {
  6597. let next;
  6598. while (el && el !== anchor) {
  6599. next = hostNextSibling(el);
  6600. hostInsert(el, container, nextSibling);
  6601. el = next;
  6602. }
  6603. hostInsert(anchor, container, nextSibling);
  6604. };
  6605. const removeStaticNode = ({ el, anchor }) => {
  6606. let next;
  6607. while (el && el !== anchor) {
  6608. next = hostNextSibling(el);
  6609. hostRemove(el);
  6610. el = next;
  6611. }
  6612. hostRemove(anchor);
  6613. };
  6614. const processElement = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6615. isSVG = isSVG || n2.type === 'svg';
  6616. if (n1 == null) {
  6617. mountElement(n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6618. }
  6619. else {
  6620. patchElement(n1, n2, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6621. }
  6622. };
  6623. const mountElement = (vnode, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6624. let el;
  6625. let vnodeHook;
  6626. const { type, props, shapeFlag, transition, dirs } = vnode;
  6627. el = vnode.el = hostCreateElement(vnode.type, isSVG, props && props.is, props);
  6628. // mount children first, since some props may rely on child content
  6629. // being already rendered, e.g. `<select value>`
  6630. if (shapeFlag & 8 /* ShapeFlags.TEXT_CHILDREN */) {
  6631. hostSetElementText(el, vnode.children);
  6632. }
  6633. else if (shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  6634. mountChildren(vnode.children, el, null, parentComponent, parentSuspense, isSVG && type !== 'foreignObject', slotScopeIds, optimized);
  6635. }
  6636. if (dirs) {
  6637. invokeDirectiveHook(vnode, null, parentComponent, 'created');
  6638. }
  6639. // props
  6640. if (props) {
  6641. for (const key in props) {
  6642. if (key !== 'value' && !isReservedProp(key)) {
  6643. hostPatchProp(el, key, null, props[key], isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  6644. }
  6645. }
  6646. /**
  6647. * Special case for setting value on DOM elements:
  6648. * - it can be order-sensitive (e.g. should be set *after* min/max, #2325, #4024)
  6649. * - it needs to be forced (#1471)
  6650. * #2353 proposes adding another renderer option to configure this, but
  6651. * the properties affects are so finite it is worth special casing it
  6652. * here to reduce the complexity. (Special casing it also should not
  6653. * affect non-DOM renderers)
  6654. */
  6655. if ('value' in props) {
  6656. hostPatchProp(el, 'value', null, props.value);
  6657. }
  6658. if ((vnodeHook = props.onVnodeBeforeMount)) {
  6659. invokeVNodeHook(vnodeHook, parentComponent, vnode);
  6660. }
  6661. }
  6662. // scopeId
  6663. setScopeId(el, vnode, vnode.scopeId, slotScopeIds, parentComponent);
  6664. {
  6665. Object.defineProperty(el, '__vnode', {
  6666. value: vnode,
  6667. enumerable: false
  6668. });
  6669. Object.defineProperty(el, '__vueParentComponent', {
  6670. value: parentComponent,
  6671. enumerable: false
  6672. });
  6673. }
  6674. if (dirs) {
  6675. invokeDirectiveHook(vnode, null, parentComponent, 'beforeMount');
  6676. }
  6677. // #1583 For inside suspense + suspense not resolved case, enter hook should call when suspense resolved
  6678. // #1689 For inside suspense + suspense resolved case, just call it
  6679. const needCallTransitionHooks = (!parentSuspense || (parentSuspense && !parentSuspense.pendingBranch)) &&
  6680. transition &&
  6681. !transition.persisted;
  6682. if (needCallTransitionHooks) {
  6683. transition.beforeEnter(el);
  6684. }
  6685. hostInsert(el, container, anchor);
  6686. if ((vnodeHook = props && props.onVnodeMounted) ||
  6687. needCallTransitionHooks ||
  6688. dirs) {
  6689. queuePostRenderEffect(() => {
  6690. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, vnode);
  6691. needCallTransitionHooks && transition.enter(el);
  6692. dirs && invokeDirectiveHook(vnode, null, parentComponent, 'mounted');
  6693. }, parentSuspense);
  6694. }
  6695. };
  6696. const setScopeId = (el, vnode, scopeId, slotScopeIds, parentComponent) => {
  6697. if (scopeId) {
  6698. hostSetScopeId(el, scopeId);
  6699. }
  6700. if (slotScopeIds) {
  6701. for (let i = 0; i < slotScopeIds.length; i++) {
  6702. hostSetScopeId(el, slotScopeIds[i]);
  6703. }
  6704. }
  6705. if (parentComponent) {
  6706. let subTree = parentComponent.subTree;
  6707. if (subTree.patchFlag > 0 &&
  6708. subTree.patchFlag & 2048 /* PatchFlags.DEV_ROOT_FRAGMENT */) {
  6709. subTree =
  6710. filterSingleRoot(subTree.children) || subTree;
  6711. }
  6712. if (vnode === subTree) {
  6713. const parentVNode = parentComponent.vnode;
  6714. setScopeId(el, parentVNode, parentVNode.scopeId, parentVNode.slotScopeIds, parentComponent.parent);
  6715. }
  6716. }
  6717. };
  6718. const mountChildren = (children, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, start = 0) => {
  6719. for (let i = start; i < children.length; i++) {
  6720. const child = (children[i] = optimized
  6721. ? cloneIfMounted(children[i])
  6722. : normalizeVNode(children[i]));
  6723. patch(null, child, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6724. }
  6725. };
  6726. const patchElement = (n1, n2, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6727. const el = (n2.el = n1.el);
  6728. let { patchFlag, dynamicChildren, dirs } = n2;
  6729. // #1426 take the old vnode's patch flag into account since user may clone a
  6730. // compiler-generated vnode, which de-opts to FULL_PROPS
  6731. patchFlag |= n1.patchFlag & 16 /* PatchFlags.FULL_PROPS */;
  6732. const oldProps = n1.props || EMPTY_OBJ;
  6733. const newProps = n2.props || EMPTY_OBJ;
  6734. let vnodeHook;
  6735. // disable recurse in beforeUpdate hooks
  6736. parentComponent && toggleRecurse(parentComponent, false);
  6737. if ((vnodeHook = newProps.onVnodeBeforeUpdate)) {
  6738. invokeVNodeHook(vnodeHook, parentComponent, n2, n1);
  6739. }
  6740. if (dirs) {
  6741. invokeDirectiveHook(n2, n1, parentComponent, 'beforeUpdate');
  6742. }
  6743. parentComponent && toggleRecurse(parentComponent, true);
  6744. if (isHmrUpdating) {
  6745. // HMR updated, force full diff
  6746. patchFlag = 0;
  6747. optimized = false;
  6748. dynamicChildren = null;
  6749. }
  6750. const areChildrenSVG = isSVG && n2.type !== 'foreignObject';
  6751. if (dynamicChildren) {
  6752. patchBlockChildren(n1.dynamicChildren, dynamicChildren, el, parentComponent, parentSuspense, areChildrenSVG, slotScopeIds);
  6753. if (parentComponent && parentComponent.type.__hmrId) {
  6754. traverseStaticChildren(n1, n2);
  6755. }
  6756. }
  6757. else if (!optimized) {
  6758. // full diff
  6759. patchChildren(n1, n2, el, null, parentComponent, parentSuspense, areChildrenSVG, slotScopeIds, false);
  6760. }
  6761. if (patchFlag > 0) {
  6762. // the presence of a patchFlag means this element's render code was
  6763. // generated by the compiler and can take the fast path.
  6764. // in this path old node and new node are guaranteed to have the same shape
  6765. // (i.e. at the exact same position in the source template)
  6766. if (patchFlag & 16 /* PatchFlags.FULL_PROPS */) {
  6767. // element props contain dynamic keys, full diff needed
  6768. patchProps(el, n2, oldProps, newProps, parentComponent, parentSuspense, isSVG);
  6769. }
  6770. else {
  6771. // class
  6772. // this flag is matched when the element has dynamic class bindings.
  6773. if (patchFlag & 2 /* PatchFlags.CLASS */) {
  6774. if (oldProps.class !== newProps.class) {
  6775. hostPatchProp(el, 'class', null, newProps.class, isSVG);
  6776. }
  6777. }
  6778. // style
  6779. // this flag is matched when the element has dynamic style bindings
  6780. if (patchFlag & 4 /* PatchFlags.STYLE */) {
  6781. hostPatchProp(el, 'style', oldProps.style, newProps.style, isSVG);
  6782. }
  6783. // props
  6784. // This flag is matched when the element has dynamic prop/attr bindings
  6785. // other than class and style. The keys of dynamic prop/attrs are saved for
  6786. // faster iteration.
  6787. // Note dynamic keys like :[foo]="bar" will cause this optimization to
  6788. // bail out and go through a full diff because we need to unset the old key
  6789. if (patchFlag & 8 /* PatchFlags.PROPS */) {
  6790. // if the flag is present then dynamicProps must be non-null
  6791. const propsToUpdate = n2.dynamicProps;
  6792. for (let i = 0; i < propsToUpdate.length; i++) {
  6793. const key = propsToUpdate[i];
  6794. const prev = oldProps[key];
  6795. const next = newProps[key];
  6796. // #1471 force patch value
  6797. if (next !== prev || key === 'value') {
  6798. hostPatchProp(el, key, prev, next, isSVG, n1.children, parentComponent, parentSuspense, unmountChildren);
  6799. }
  6800. }
  6801. }
  6802. }
  6803. // text
  6804. // This flag is matched when the element has only dynamic text children.
  6805. if (patchFlag & 1 /* PatchFlags.TEXT */) {
  6806. if (n1.children !== n2.children) {
  6807. hostSetElementText(el, n2.children);
  6808. }
  6809. }
  6810. }
  6811. else if (!optimized && dynamicChildren == null) {
  6812. // unoptimized, full diff
  6813. patchProps(el, n2, oldProps, newProps, parentComponent, parentSuspense, isSVG);
  6814. }
  6815. if ((vnodeHook = newProps.onVnodeUpdated) || dirs) {
  6816. queuePostRenderEffect(() => {
  6817. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, n2, n1);
  6818. dirs && invokeDirectiveHook(n2, n1, parentComponent, 'updated');
  6819. }, parentSuspense);
  6820. }
  6821. };
  6822. // The fast path for blocks.
  6823. const patchBlockChildren = (oldChildren, newChildren, fallbackContainer, parentComponent, parentSuspense, isSVG, slotScopeIds) => {
  6824. for (let i = 0; i < newChildren.length; i++) {
  6825. const oldVNode = oldChildren[i];
  6826. const newVNode = newChildren[i];
  6827. // Determine the container (parent element) for the patch.
  6828. const container =
  6829. // oldVNode may be an errored async setup() component inside Suspense
  6830. // which will not have a mounted element
  6831. oldVNode.el &&
  6832. // - In the case of a Fragment, we need to provide the actual parent
  6833. // of the Fragment itself so it can move its children.
  6834. (oldVNode.type === Fragment ||
  6835. // - In the case of different nodes, there is going to be a replacement
  6836. // which also requires the correct parent container
  6837. !isSameVNodeType(oldVNode, newVNode) ||
  6838. // - In the case of a component, it could contain anything.
  6839. oldVNode.shapeFlag & (6 /* ShapeFlags.COMPONENT */ | 64 /* ShapeFlags.TELEPORT */))
  6840. ? hostParentNode(oldVNode.el)
  6841. : // In other cases, the parent container is not actually used so we
  6842. // just pass the block element here to avoid a DOM parentNode call.
  6843. fallbackContainer;
  6844. patch(oldVNode, newVNode, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, true);
  6845. }
  6846. };
  6847. const patchProps = (el, vnode, oldProps, newProps, parentComponent, parentSuspense, isSVG) => {
  6848. if (oldProps !== newProps) {
  6849. if (oldProps !== EMPTY_OBJ) {
  6850. for (const key in oldProps) {
  6851. if (!isReservedProp(key) && !(key in newProps)) {
  6852. hostPatchProp(el, key, oldProps[key], null, isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  6853. }
  6854. }
  6855. }
  6856. for (const key in newProps) {
  6857. // empty string is not valid prop
  6858. if (isReservedProp(key))
  6859. continue;
  6860. const next = newProps[key];
  6861. const prev = oldProps[key];
  6862. // defer patching value
  6863. if (next !== prev && key !== 'value') {
  6864. hostPatchProp(el, key, prev, next, isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  6865. }
  6866. }
  6867. if ('value' in newProps) {
  6868. hostPatchProp(el, 'value', oldProps.value, newProps.value);
  6869. }
  6870. }
  6871. };
  6872. const processFragment = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6873. const fragmentStartAnchor = (n2.el = n1 ? n1.el : hostCreateText(''));
  6874. const fragmentEndAnchor = (n2.anchor = n1 ? n1.anchor : hostCreateText(''));
  6875. let { patchFlag, dynamicChildren, slotScopeIds: fragmentSlotScopeIds } = n2;
  6876. if (// #5523 dev root fragment may inherit directives
  6877. (isHmrUpdating || patchFlag & 2048 /* PatchFlags.DEV_ROOT_FRAGMENT */)) {
  6878. // HMR updated / Dev root fragment (w/ comments), force full diff
  6879. patchFlag = 0;
  6880. optimized = false;
  6881. dynamicChildren = null;
  6882. }
  6883. // check if this is a slot fragment with :slotted scope ids
  6884. if (fragmentSlotScopeIds) {
  6885. slotScopeIds = slotScopeIds
  6886. ? slotScopeIds.concat(fragmentSlotScopeIds)
  6887. : fragmentSlotScopeIds;
  6888. }
  6889. if (n1 == null) {
  6890. hostInsert(fragmentStartAnchor, container, anchor);
  6891. hostInsert(fragmentEndAnchor, container, anchor);
  6892. // a fragment can only have array children
  6893. // since they are either generated by the compiler, or implicitly created
  6894. // from arrays.
  6895. mountChildren(n2.children, container, fragmentEndAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6896. }
  6897. else {
  6898. if (patchFlag > 0 &&
  6899. patchFlag & 64 /* PatchFlags.STABLE_FRAGMENT */ &&
  6900. dynamicChildren &&
  6901. // #2715 the previous fragment could've been a BAILed one as a result
  6902. // of renderSlot() with no valid children
  6903. n1.dynamicChildren) {
  6904. // a stable fragment (template root or <template v-for>) doesn't need to
  6905. // patch children order, but it may contain dynamicChildren.
  6906. patchBlockChildren(n1.dynamicChildren, dynamicChildren, container, parentComponent, parentSuspense, isSVG, slotScopeIds);
  6907. if (parentComponent && parentComponent.type.__hmrId) {
  6908. traverseStaticChildren(n1, n2);
  6909. }
  6910. else if (
  6911. // #2080 if the stable fragment has a key, it's a <template v-for> that may
  6912. // get moved around. Make sure all root level vnodes inherit el.
  6913. // #2134 or if it's a component root, it may also get moved around
  6914. // as the component is being moved.
  6915. n2.key != null ||
  6916. (parentComponent && n2 === parentComponent.subTree)) {
  6917. traverseStaticChildren(n1, n2, true /* shallow */);
  6918. }
  6919. }
  6920. else {
  6921. // keyed / unkeyed, or manual fragments.
  6922. // for keyed & unkeyed, since they are compiler generated from v-for,
  6923. // each child is guaranteed to be a block so the fragment will never
  6924. // have dynamicChildren.
  6925. patchChildren(n1, n2, container, fragmentEndAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6926. }
  6927. }
  6928. };
  6929. const processComponent = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6930. n2.slotScopeIds = slotScopeIds;
  6931. if (n1 == null) {
  6932. if (n2.shapeFlag & 512 /* ShapeFlags.COMPONENT_KEPT_ALIVE */) {
  6933. parentComponent.ctx.activate(n2, container, anchor, isSVG, optimized);
  6934. }
  6935. else {
  6936. mountComponent(n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  6937. }
  6938. }
  6939. else {
  6940. updateComponent(n1, n2, optimized);
  6941. }
  6942. };
  6943. const mountComponent = (initialVNode, container, anchor, parentComponent, parentSuspense, isSVG, optimized) => {
  6944. const instance = (initialVNode.component = createComponentInstance(initialVNode, parentComponent, parentSuspense));
  6945. if (instance.type.__hmrId) {
  6946. registerHMR(instance);
  6947. }
  6948. {
  6949. pushWarningContext(initialVNode);
  6950. startMeasure(instance, `mount`);
  6951. }
  6952. // inject renderer internals for keepAlive
  6953. if (isKeepAlive(initialVNode)) {
  6954. instance.ctx.renderer = internals;
  6955. }
  6956. // resolve props and slots for setup context
  6957. {
  6958. {
  6959. startMeasure(instance, `init`);
  6960. }
  6961. setupComponent(instance);
  6962. {
  6963. endMeasure(instance, `init`);
  6964. }
  6965. }
  6966. // setup() is async. This component relies on async logic to be resolved
  6967. // before proceeding
  6968. if (instance.asyncDep) {
  6969. parentSuspense && parentSuspense.registerDep(instance, setupRenderEffect);
  6970. // Give it a placeholder if this is not hydration
  6971. // TODO handle self-defined fallback
  6972. if (!initialVNode.el) {
  6973. const placeholder = (instance.subTree = createVNode(Comment));
  6974. processCommentNode(null, placeholder, container, anchor);
  6975. }
  6976. return;
  6977. }
  6978. setupRenderEffect(instance, initialVNode, container, anchor, parentSuspense, isSVG, optimized);
  6979. {
  6980. popWarningContext();
  6981. endMeasure(instance, `mount`);
  6982. }
  6983. };
  6984. const updateComponent = (n1, n2, optimized) => {
  6985. const instance = (n2.component = n1.component);
  6986. if (shouldUpdateComponent(n1, n2, optimized)) {
  6987. if (instance.asyncDep &&
  6988. !instance.asyncResolved) {
  6989. // async & still pending - just update props and slots
  6990. // since the component's reactive effect for render isn't set-up yet
  6991. {
  6992. pushWarningContext(n2);
  6993. }
  6994. updateComponentPreRender(instance, n2, optimized);
  6995. {
  6996. popWarningContext();
  6997. }
  6998. return;
  6999. }
  7000. else {
  7001. // normal update
  7002. instance.next = n2;
  7003. // in case the child component is also queued, remove it to avoid
  7004. // double updating the same child component in the same flush.
  7005. invalidateJob(instance.update);
  7006. // instance.update is the reactive effect.
  7007. instance.update();
  7008. }
  7009. }
  7010. else {
  7011. // no update needed. just copy over properties
  7012. n2.el = n1.el;
  7013. instance.vnode = n2;
  7014. }
  7015. };
  7016. const setupRenderEffect = (instance, initialVNode, container, anchor, parentSuspense, isSVG, optimized) => {
  7017. const componentUpdateFn = () => {
  7018. if (!instance.isMounted) {
  7019. let vnodeHook;
  7020. const { el, props } = initialVNode;
  7021. const { bm, m, parent } = instance;
  7022. const isAsyncWrapperVNode = isAsyncWrapper(initialVNode);
  7023. toggleRecurse(instance, false);
  7024. // beforeMount hook
  7025. if (bm) {
  7026. invokeArrayFns(bm);
  7027. }
  7028. // onVnodeBeforeMount
  7029. if (!isAsyncWrapperVNode &&
  7030. (vnodeHook = props && props.onVnodeBeforeMount)) {
  7031. invokeVNodeHook(vnodeHook, parent, initialVNode);
  7032. }
  7033. toggleRecurse(instance, true);
  7034. if (el && hydrateNode) {
  7035. // vnode has adopted host node - perform hydration instead of mount.
  7036. const hydrateSubTree = () => {
  7037. {
  7038. startMeasure(instance, `render`);
  7039. }
  7040. instance.subTree = renderComponentRoot(instance);
  7041. {
  7042. endMeasure(instance, `render`);
  7043. }
  7044. {
  7045. startMeasure(instance, `hydrate`);
  7046. }
  7047. hydrateNode(el, instance.subTree, instance, parentSuspense, null);
  7048. {
  7049. endMeasure(instance, `hydrate`);
  7050. }
  7051. };
  7052. if (isAsyncWrapperVNode) {
  7053. initialVNode.type.__asyncLoader().then(
  7054. // note: we are moving the render call into an async callback,
  7055. // which means it won't track dependencies - but it's ok because
  7056. // a server-rendered async wrapper is already in resolved state
  7057. // and it will never need to change.
  7058. () => !instance.isUnmounted && hydrateSubTree());
  7059. }
  7060. else {
  7061. hydrateSubTree();
  7062. }
  7063. }
  7064. else {
  7065. {
  7066. startMeasure(instance, `render`);
  7067. }
  7068. const subTree = (instance.subTree = renderComponentRoot(instance));
  7069. {
  7070. endMeasure(instance, `render`);
  7071. }
  7072. {
  7073. startMeasure(instance, `patch`);
  7074. }
  7075. patch(null, subTree, container, anchor, instance, parentSuspense, isSVG);
  7076. {
  7077. endMeasure(instance, `patch`);
  7078. }
  7079. initialVNode.el = subTree.el;
  7080. }
  7081. // mounted hook
  7082. if (m) {
  7083. queuePostRenderEffect(m, parentSuspense);
  7084. }
  7085. // onVnodeMounted
  7086. if (!isAsyncWrapperVNode &&
  7087. (vnodeHook = props && props.onVnodeMounted)) {
  7088. const scopedInitialVNode = initialVNode;
  7089. queuePostRenderEffect(() => invokeVNodeHook(vnodeHook, parent, scopedInitialVNode), parentSuspense);
  7090. }
  7091. // activated hook for keep-alive roots.
  7092. // #1742 activated hook must be accessed after first render
  7093. // since the hook may be injected by a child keep-alive
  7094. if (initialVNode.shapeFlag & 256 /* ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE */ ||
  7095. (parent &&
  7096. isAsyncWrapper(parent.vnode) &&
  7097. parent.vnode.shapeFlag & 256 /* ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE */)) {
  7098. instance.a && queuePostRenderEffect(instance.a, parentSuspense);
  7099. }
  7100. instance.isMounted = true;
  7101. {
  7102. devtoolsComponentAdded(instance);
  7103. }
  7104. // #2458: deference mount-only object parameters to prevent memleaks
  7105. initialVNode = container = anchor = null;
  7106. }
  7107. else {
  7108. // updateComponent
  7109. // This is triggered by mutation of component's own state (next: null)
  7110. // OR parent calling processComponent (next: VNode)
  7111. let { next, bu, u, parent, vnode } = instance;
  7112. let originNext = next;
  7113. let vnodeHook;
  7114. {
  7115. pushWarningContext(next || instance.vnode);
  7116. }
  7117. // Disallow component effect recursion during pre-lifecycle hooks.
  7118. toggleRecurse(instance, false);
  7119. if (next) {
  7120. next.el = vnode.el;
  7121. updateComponentPreRender(instance, next, optimized);
  7122. }
  7123. else {
  7124. next = vnode;
  7125. }
  7126. // beforeUpdate hook
  7127. if (bu) {
  7128. invokeArrayFns(bu);
  7129. }
  7130. // onVnodeBeforeUpdate
  7131. if ((vnodeHook = next.props && next.props.onVnodeBeforeUpdate)) {
  7132. invokeVNodeHook(vnodeHook, parent, next, vnode);
  7133. }
  7134. toggleRecurse(instance, true);
  7135. // render
  7136. {
  7137. startMeasure(instance, `render`);
  7138. }
  7139. const nextTree = renderComponentRoot(instance);
  7140. {
  7141. endMeasure(instance, `render`);
  7142. }
  7143. const prevTree = instance.subTree;
  7144. instance.subTree = nextTree;
  7145. {
  7146. startMeasure(instance, `patch`);
  7147. }
  7148. patch(prevTree, nextTree,
  7149. // parent may have changed if it's in a teleport
  7150. hostParentNode(prevTree.el),
  7151. // anchor may have changed if it's in a fragment
  7152. getNextHostNode(prevTree), instance, parentSuspense, isSVG);
  7153. {
  7154. endMeasure(instance, `patch`);
  7155. }
  7156. next.el = nextTree.el;
  7157. if (originNext === null) {
  7158. // self-triggered update. In case of HOC, update parent component
  7159. // vnode el. HOC is indicated by parent instance's subTree pointing
  7160. // to child component's vnode
  7161. updateHOCHostEl(instance, nextTree.el);
  7162. }
  7163. // updated hook
  7164. if (u) {
  7165. queuePostRenderEffect(u, parentSuspense);
  7166. }
  7167. // onVnodeUpdated
  7168. if ((vnodeHook = next.props && next.props.onVnodeUpdated)) {
  7169. queuePostRenderEffect(() => invokeVNodeHook(vnodeHook, parent, next, vnode), parentSuspense);
  7170. }
  7171. {
  7172. devtoolsComponentUpdated(instance);
  7173. }
  7174. {
  7175. popWarningContext();
  7176. }
  7177. }
  7178. };
  7179. // create reactive effect for rendering
  7180. const effect = (instance.effect = new ReactiveEffect(componentUpdateFn, () => queueJob(update), instance.scope // track it in component's effect scope
  7181. ));
  7182. const update = (instance.update = () => effect.run());
  7183. update.id = instance.uid;
  7184. // allowRecurse
  7185. // #1801, #2043 component render effects should allow recursive updates
  7186. toggleRecurse(instance, true);
  7187. {
  7188. effect.onTrack = instance.rtc
  7189. ? e => invokeArrayFns(instance.rtc, e)
  7190. : void 0;
  7191. effect.onTrigger = instance.rtg
  7192. ? e => invokeArrayFns(instance.rtg, e)
  7193. : void 0;
  7194. update.ownerInstance = instance;
  7195. }
  7196. update();
  7197. };
  7198. const updateComponentPreRender = (instance, nextVNode, optimized) => {
  7199. nextVNode.component = instance;
  7200. const prevProps = instance.vnode.props;
  7201. instance.vnode = nextVNode;
  7202. instance.next = null;
  7203. updateProps(instance, nextVNode.props, prevProps, optimized);
  7204. updateSlots(instance, nextVNode.children, optimized);
  7205. pauseTracking();
  7206. // props update may have triggered pre-flush watchers.
  7207. // flush them before the render update.
  7208. flushPreFlushCbs();
  7209. resetTracking();
  7210. };
  7211. const patchChildren = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized = false) => {
  7212. const c1 = n1 && n1.children;
  7213. const prevShapeFlag = n1 ? n1.shapeFlag : 0;
  7214. const c2 = n2.children;
  7215. const { patchFlag, shapeFlag } = n2;
  7216. // fast path
  7217. if (patchFlag > 0) {
  7218. if (patchFlag & 128 /* PatchFlags.KEYED_FRAGMENT */) {
  7219. // this could be either fully-keyed or mixed (some keyed some not)
  7220. // presence of patchFlag means children are guaranteed to be arrays
  7221. patchKeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7222. return;
  7223. }
  7224. else if (patchFlag & 256 /* PatchFlags.UNKEYED_FRAGMENT */) {
  7225. // unkeyed
  7226. patchUnkeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7227. return;
  7228. }
  7229. }
  7230. // children has 3 possibilities: text, array or no children.
  7231. if (shapeFlag & 8 /* ShapeFlags.TEXT_CHILDREN */) {
  7232. // text children fast path
  7233. if (prevShapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  7234. unmountChildren(c1, parentComponent, parentSuspense);
  7235. }
  7236. if (c2 !== c1) {
  7237. hostSetElementText(container, c2);
  7238. }
  7239. }
  7240. else {
  7241. if (prevShapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  7242. // prev children was array
  7243. if (shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  7244. // two arrays, cannot assume anything, do full diff
  7245. patchKeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7246. }
  7247. else {
  7248. // no new children, just unmount old
  7249. unmountChildren(c1, parentComponent, parentSuspense, true);
  7250. }
  7251. }
  7252. else {
  7253. // prev children was text OR null
  7254. // new children is array OR null
  7255. if (prevShapeFlag & 8 /* ShapeFlags.TEXT_CHILDREN */) {
  7256. hostSetElementText(container, '');
  7257. }
  7258. // mount new if array
  7259. if (shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  7260. mountChildren(c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7261. }
  7262. }
  7263. }
  7264. };
  7265. const patchUnkeyedChildren = (c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  7266. c1 = c1 || EMPTY_ARR;
  7267. c2 = c2 || EMPTY_ARR;
  7268. const oldLength = c1.length;
  7269. const newLength = c2.length;
  7270. const commonLength = Math.min(oldLength, newLength);
  7271. let i;
  7272. for (i = 0; i < commonLength; i++) {
  7273. const nextChild = (c2[i] = optimized
  7274. ? cloneIfMounted(c2[i])
  7275. : normalizeVNode(c2[i]));
  7276. patch(c1[i], nextChild, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7277. }
  7278. if (oldLength > newLength) {
  7279. // remove old
  7280. unmountChildren(c1, parentComponent, parentSuspense, true, false, commonLength);
  7281. }
  7282. else {
  7283. // mount new
  7284. mountChildren(c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, commonLength);
  7285. }
  7286. };
  7287. // can be all-keyed or mixed
  7288. const patchKeyedChildren = (c1, c2, container, parentAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  7289. let i = 0;
  7290. const l2 = c2.length;
  7291. let e1 = c1.length - 1; // prev ending index
  7292. let e2 = l2 - 1; // next ending index
  7293. // 1. sync from start
  7294. // (a b) c
  7295. // (a b) d e
  7296. while (i <= e1 && i <= e2) {
  7297. const n1 = c1[i];
  7298. const n2 = (c2[i] = optimized
  7299. ? cloneIfMounted(c2[i])
  7300. : normalizeVNode(c2[i]));
  7301. if (isSameVNodeType(n1, n2)) {
  7302. patch(n1, n2, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7303. }
  7304. else {
  7305. break;
  7306. }
  7307. i++;
  7308. }
  7309. // 2. sync from end
  7310. // a (b c)
  7311. // d e (b c)
  7312. while (i <= e1 && i <= e2) {
  7313. const n1 = c1[e1];
  7314. const n2 = (c2[e2] = optimized
  7315. ? cloneIfMounted(c2[e2])
  7316. : normalizeVNode(c2[e2]));
  7317. if (isSameVNodeType(n1, n2)) {
  7318. patch(n1, n2, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7319. }
  7320. else {
  7321. break;
  7322. }
  7323. e1--;
  7324. e2--;
  7325. }
  7326. // 3. common sequence + mount
  7327. // (a b)
  7328. // (a b) c
  7329. // i = 2, e1 = 1, e2 = 2
  7330. // (a b)
  7331. // c (a b)
  7332. // i = 0, e1 = -1, e2 = 0
  7333. if (i > e1) {
  7334. if (i <= e2) {
  7335. const nextPos = e2 + 1;
  7336. const anchor = nextPos < l2 ? c2[nextPos].el : parentAnchor;
  7337. while (i <= e2) {
  7338. patch(null, (c2[i] = optimized
  7339. ? cloneIfMounted(c2[i])
  7340. : normalizeVNode(c2[i])), container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7341. i++;
  7342. }
  7343. }
  7344. }
  7345. // 4. common sequence + unmount
  7346. // (a b) c
  7347. // (a b)
  7348. // i = 2, e1 = 2, e2 = 1
  7349. // a (b c)
  7350. // (b c)
  7351. // i = 0, e1 = 0, e2 = -1
  7352. else if (i > e2) {
  7353. while (i <= e1) {
  7354. unmount(c1[i], parentComponent, parentSuspense, true);
  7355. i++;
  7356. }
  7357. }
  7358. // 5. unknown sequence
  7359. // [i ... e1 + 1]: a b [c d e] f g
  7360. // [i ... e2 + 1]: a b [e d c h] f g
  7361. // i = 2, e1 = 4, e2 = 5
  7362. else {
  7363. const s1 = i; // prev starting index
  7364. const s2 = i; // next starting index
  7365. // 5.1 build key:index map for newChildren
  7366. const keyToNewIndexMap = new Map();
  7367. for (i = s2; i <= e2; i++) {
  7368. const nextChild = (c2[i] = optimized
  7369. ? cloneIfMounted(c2[i])
  7370. : normalizeVNode(c2[i]));
  7371. if (nextChild.key != null) {
  7372. if (keyToNewIndexMap.has(nextChild.key)) {
  7373. warn$1(`Duplicate keys found during update:`, JSON.stringify(nextChild.key), `Make sure keys are unique.`);
  7374. }
  7375. keyToNewIndexMap.set(nextChild.key, i);
  7376. }
  7377. }
  7378. // 5.2 loop through old children left to be patched and try to patch
  7379. // matching nodes & remove nodes that are no longer present
  7380. let j;
  7381. let patched = 0;
  7382. const toBePatched = e2 - s2 + 1;
  7383. let moved = false;
  7384. // used to track whether any node has moved
  7385. let maxNewIndexSoFar = 0;
  7386. // works as Map<newIndex, oldIndex>
  7387. // Note that oldIndex is offset by +1
  7388. // and oldIndex = 0 is a special value indicating the new node has
  7389. // no corresponding old node.
  7390. // used for determining longest stable subsequence
  7391. const newIndexToOldIndexMap = new Array(toBePatched);
  7392. for (i = 0; i < toBePatched; i++)
  7393. newIndexToOldIndexMap[i] = 0;
  7394. for (i = s1; i <= e1; i++) {
  7395. const prevChild = c1[i];
  7396. if (patched >= toBePatched) {
  7397. // all new children have been patched so this can only be a removal
  7398. unmount(prevChild, parentComponent, parentSuspense, true);
  7399. continue;
  7400. }
  7401. let newIndex;
  7402. if (prevChild.key != null) {
  7403. newIndex = keyToNewIndexMap.get(prevChild.key);
  7404. }
  7405. else {
  7406. // key-less node, try to locate a key-less node of the same type
  7407. for (j = s2; j <= e2; j++) {
  7408. if (newIndexToOldIndexMap[j - s2] === 0 &&
  7409. isSameVNodeType(prevChild, c2[j])) {
  7410. newIndex = j;
  7411. break;
  7412. }
  7413. }
  7414. }
  7415. if (newIndex === undefined) {
  7416. unmount(prevChild, parentComponent, parentSuspense, true);
  7417. }
  7418. else {
  7419. newIndexToOldIndexMap[newIndex - s2] = i + 1;
  7420. if (newIndex >= maxNewIndexSoFar) {
  7421. maxNewIndexSoFar = newIndex;
  7422. }
  7423. else {
  7424. moved = true;
  7425. }
  7426. patch(prevChild, c2[newIndex], container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7427. patched++;
  7428. }
  7429. }
  7430. // 5.3 move and mount
  7431. // generate longest stable subsequence only when nodes have moved
  7432. const increasingNewIndexSequence = moved
  7433. ? getSequence(newIndexToOldIndexMap)
  7434. : EMPTY_ARR;
  7435. j = increasingNewIndexSequence.length - 1;
  7436. // looping backwards so that we can use last patched node as anchor
  7437. for (i = toBePatched - 1; i >= 0; i--) {
  7438. const nextIndex = s2 + i;
  7439. const nextChild = c2[nextIndex];
  7440. const anchor = nextIndex + 1 < l2 ? c2[nextIndex + 1].el : parentAnchor;
  7441. if (newIndexToOldIndexMap[i] === 0) {
  7442. // mount new
  7443. patch(null, nextChild, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7444. }
  7445. else if (moved) {
  7446. // move if:
  7447. // There is no stable subsequence (e.g. a reverse)
  7448. // OR current node is not among the stable sequence
  7449. if (j < 0 || i !== increasingNewIndexSequence[j]) {
  7450. move(nextChild, container, anchor, 2 /* MoveType.REORDER */);
  7451. }
  7452. else {
  7453. j--;
  7454. }
  7455. }
  7456. }
  7457. }
  7458. };
  7459. const move = (vnode, container, anchor, moveType, parentSuspense = null) => {
  7460. const { el, type, transition, children, shapeFlag } = vnode;
  7461. if (shapeFlag & 6 /* ShapeFlags.COMPONENT */) {
  7462. move(vnode.component.subTree, container, anchor, moveType);
  7463. return;
  7464. }
  7465. if (shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
  7466. vnode.suspense.move(container, anchor, moveType);
  7467. return;
  7468. }
  7469. if (shapeFlag & 64 /* ShapeFlags.TELEPORT */) {
  7470. type.move(vnode, container, anchor, internals);
  7471. return;
  7472. }
  7473. if (type === Fragment) {
  7474. hostInsert(el, container, anchor);
  7475. for (let i = 0; i < children.length; i++) {
  7476. move(children[i], container, anchor, moveType);
  7477. }
  7478. hostInsert(vnode.anchor, container, anchor);
  7479. return;
  7480. }
  7481. if (type === Static) {
  7482. moveStaticNode(vnode, container, anchor);
  7483. return;
  7484. }
  7485. // single nodes
  7486. const needTransition = moveType !== 2 /* MoveType.REORDER */ &&
  7487. shapeFlag & 1 /* ShapeFlags.ELEMENT */ &&
  7488. transition;
  7489. if (needTransition) {
  7490. if (moveType === 0 /* MoveType.ENTER */) {
  7491. transition.beforeEnter(el);
  7492. hostInsert(el, container, anchor);
  7493. queuePostRenderEffect(() => transition.enter(el), parentSuspense);
  7494. }
  7495. else {
  7496. const { leave, delayLeave, afterLeave } = transition;
  7497. const remove = () => hostInsert(el, container, anchor);
  7498. const performLeave = () => {
  7499. leave(el, () => {
  7500. remove();
  7501. afterLeave && afterLeave();
  7502. });
  7503. };
  7504. if (delayLeave) {
  7505. delayLeave(el, remove, performLeave);
  7506. }
  7507. else {
  7508. performLeave();
  7509. }
  7510. }
  7511. }
  7512. else {
  7513. hostInsert(el, container, anchor);
  7514. }
  7515. };
  7516. const unmount = (vnode, parentComponent, parentSuspense, doRemove = false, optimized = false) => {
  7517. const { type, props, ref, children, dynamicChildren, shapeFlag, patchFlag, dirs } = vnode;
  7518. // unset ref
  7519. if (ref != null) {
  7520. setRef(ref, null, parentSuspense, vnode, true);
  7521. }
  7522. if (shapeFlag & 256 /* ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE */) {
  7523. parentComponent.ctx.deactivate(vnode);
  7524. return;
  7525. }
  7526. const shouldInvokeDirs = shapeFlag & 1 /* ShapeFlags.ELEMENT */ && dirs;
  7527. const shouldInvokeVnodeHook = !isAsyncWrapper(vnode);
  7528. let vnodeHook;
  7529. if (shouldInvokeVnodeHook &&
  7530. (vnodeHook = props && props.onVnodeBeforeUnmount)) {
  7531. invokeVNodeHook(vnodeHook, parentComponent, vnode);
  7532. }
  7533. if (shapeFlag & 6 /* ShapeFlags.COMPONENT */) {
  7534. unmountComponent(vnode.component, parentSuspense, doRemove);
  7535. }
  7536. else {
  7537. if (shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
  7538. vnode.suspense.unmount(parentSuspense, doRemove);
  7539. return;
  7540. }
  7541. if (shouldInvokeDirs) {
  7542. invokeDirectiveHook(vnode, null, parentComponent, 'beforeUnmount');
  7543. }
  7544. if (shapeFlag & 64 /* ShapeFlags.TELEPORT */) {
  7545. vnode.type.remove(vnode, parentComponent, parentSuspense, optimized, internals, doRemove);
  7546. }
  7547. else if (dynamicChildren &&
  7548. // #1153: fast path should not be taken for non-stable (v-for) fragments
  7549. (type !== Fragment ||
  7550. (patchFlag > 0 && patchFlag & 64 /* PatchFlags.STABLE_FRAGMENT */))) {
  7551. // fast path for block nodes: only need to unmount dynamic children.
  7552. unmountChildren(dynamicChildren, parentComponent, parentSuspense, false, true);
  7553. }
  7554. else if ((type === Fragment &&
  7555. patchFlag &
  7556. (128 /* PatchFlags.KEYED_FRAGMENT */ | 256 /* PatchFlags.UNKEYED_FRAGMENT */)) ||
  7557. (!optimized && shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */)) {
  7558. unmountChildren(children, parentComponent, parentSuspense);
  7559. }
  7560. if (doRemove) {
  7561. remove(vnode);
  7562. }
  7563. }
  7564. if ((shouldInvokeVnodeHook &&
  7565. (vnodeHook = props && props.onVnodeUnmounted)) ||
  7566. shouldInvokeDirs) {
  7567. queuePostRenderEffect(() => {
  7568. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, vnode);
  7569. shouldInvokeDirs &&
  7570. invokeDirectiveHook(vnode, null, parentComponent, 'unmounted');
  7571. }, parentSuspense);
  7572. }
  7573. };
  7574. const remove = vnode => {
  7575. const { type, el, anchor, transition } = vnode;
  7576. if (type === Fragment) {
  7577. if (vnode.patchFlag > 0 &&
  7578. vnode.patchFlag & 2048 /* PatchFlags.DEV_ROOT_FRAGMENT */ &&
  7579. transition &&
  7580. !transition.persisted) {
  7581. vnode.children.forEach(child => {
  7582. if (child.type === Comment) {
  7583. hostRemove(child.el);
  7584. }
  7585. else {
  7586. remove(child);
  7587. }
  7588. });
  7589. }
  7590. else {
  7591. removeFragment(el, anchor);
  7592. }
  7593. return;
  7594. }
  7595. if (type === Static) {
  7596. removeStaticNode(vnode);
  7597. return;
  7598. }
  7599. const performRemove = () => {
  7600. hostRemove(el);
  7601. if (transition && !transition.persisted && transition.afterLeave) {
  7602. transition.afterLeave();
  7603. }
  7604. };
  7605. if (vnode.shapeFlag & 1 /* ShapeFlags.ELEMENT */ &&
  7606. transition &&
  7607. !transition.persisted) {
  7608. const { leave, delayLeave } = transition;
  7609. const performLeave = () => leave(el, performRemove);
  7610. if (delayLeave) {
  7611. delayLeave(vnode.el, performRemove, performLeave);
  7612. }
  7613. else {
  7614. performLeave();
  7615. }
  7616. }
  7617. else {
  7618. performRemove();
  7619. }
  7620. };
  7621. const removeFragment = (cur, end) => {
  7622. // For fragments, directly remove all contained DOM nodes.
  7623. // (fragment child nodes cannot have transition)
  7624. let next;
  7625. while (cur !== end) {
  7626. next = hostNextSibling(cur);
  7627. hostRemove(cur);
  7628. cur = next;
  7629. }
  7630. hostRemove(end);
  7631. };
  7632. const unmountComponent = (instance, parentSuspense, doRemove) => {
  7633. if (instance.type.__hmrId) {
  7634. unregisterHMR(instance);
  7635. }
  7636. const { bum, scope, update, subTree, um } = instance;
  7637. // beforeUnmount hook
  7638. if (bum) {
  7639. invokeArrayFns(bum);
  7640. }
  7641. // stop effects in component scope
  7642. scope.stop();
  7643. // update may be null if a component is unmounted before its async
  7644. // setup has resolved.
  7645. if (update) {
  7646. // so that scheduler will no longer invoke it
  7647. update.active = false;
  7648. unmount(subTree, instance, parentSuspense, doRemove);
  7649. }
  7650. // unmounted hook
  7651. if (um) {
  7652. queuePostRenderEffect(um, parentSuspense);
  7653. }
  7654. queuePostRenderEffect(() => {
  7655. instance.isUnmounted = true;
  7656. }, parentSuspense);
  7657. // A component with async dep inside a pending suspense is unmounted before
  7658. // its async dep resolves. This should remove the dep from the suspense, and
  7659. // cause the suspense to resolve immediately if that was the last dep.
  7660. if (parentSuspense &&
  7661. parentSuspense.pendingBranch &&
  7662. !parentSuspense.isUnmounted &&
  7663. instance.asyncDep &&
  7664. !instance.asyncResolved &&
  7665. instance.suspenseId === parentSuspense.pendingId) {
  7666. parentSuspense.deps--;
  7667. if (parentSuspense.deps === 0) {
  7668. parentSuspense.resolve();
  7669. }
  7670. }
  7671. {
  7672. devtoolsComponentRemoved(instance);
  7673. }
  7674. };
  7675. const unmountChildren = (children, parentComponent, parentSuspense, doRemove = false, optimized = false, start = 0) => {
  7676. for (let i = start; i < children.length; i++) {
  7677. unmount(children[i], parentComponent, parentSuspense, doRemove, optimized);
  7678. }
  7679. };
  7680. const getNextHostNode = vnode => {
  7681. if (vnode.shapeFlag & 6 /* ShapeFlags.COMPONENT */) {
  7682. return getNextHostNode(vnode.component.subTree);
  7683. }
  7684. if (vnode.shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
  7685. return vnode.suspense.next();
  7686. }
  7687. return hostNextSibling((vnode.anchor || vnode.el));
  7688. };
  7689. const render = (vnode, container, isSVG) => {
  7690. if (vnode == null) {
  7691. if (container._vnode) {
  7692. unmount(container._vnode, null, null, true);
  7693. }
  7694. }
  7695. else {
  7696. patch(container._vnode || null, vnode, container, null, null, null, isSVG);
  7697. }
  7698. flushPreFlushCbs();
  7699. flushPostFlushCbs();
  7700. container._vnode = vnode;
  7701. };
  7702. const internals = {
  7703. p: patch,
  7704. um: unmount,
  7705. m: move,
  7706. r: remove,
  7707. mt: mountComponent,
  7708. mc: mountChildren,
  7709. pc: patchChildren,
  7710. pbc: patchBlockChildren,
  7711. n: getNextHostNode,
  7712. o: options
  7713. };
  7714. let hydrate;
  7715. let hydrateNode;
  7716. if (createHydrationFns) {
  7717. [hydrate, hydrateNode] = createHydrationFns(internals);
  7718. }
  7719. return {
  7720. render,
  7721. hydrate,
  7722. createApp: createAppAPI(render, hydrate)
  7723. };
  7724. }
  7725. function toggleRecurse({ effect, update }, allowed) {
  7726. effect.allowRecurse = update.allowRecurse = allowed;
  7727. }
  7728. /**
  7729. * #1156
  7730. * When a component is HMR-enabled, we need to make sure that all static nodes
  7731. * inside a block also inherit the DOM element from the previous tree so that
  7732. * HMR updates (which are full updates) can retrieve the element for patching.
  7733. *
  7734. * #2080
  7735. * Inside keyed `template` fragment static children, if a fragment is moved,
  7736. * the children will always be moved. Therefore, in order to ensure correct move
  7737. * position, el should be inherited from previous nodes.
  7738. */
  7739. function traverseStaticChildren(n1, n2, shallow = false) {
  7740. const ch1 = n1.children;
  7741. const ch2 = n2.children;
  7742. if (isArray(ch1) && isArray(ch2)) {
  7743. for (let i = 0; i < ch1.length; i++) {
  7744. // this is only called in the optimized path so array children are
  7745. // guaranteed to be vnodes
  7746. const c1 = ch1[i];
  7747. let c2 = ch2[i];
  7748. if (c2.shapeFlag & 1 /* ShapeFlags.ELEMENT */ && !c2.dynamicChildren) {
  7749. if (c2.patchFlag <= 0 || c2.patchFlag === 32 /* PatchFlags.HYDRATE_EVENTS */) {
  7750. c2 = ch2[i] = cloneIfMounted(ch2[i]);
  7751. c2.el = c1.el;
  7752. }
  7753. if (!shallow)
  7754. traverseStaticChildren(c1, c2);
  7755. }
  7756. // #6852 also inherit for text nodes
  7757. if (c2.type === Text) {
  7758. c2.el = c1.el;
  7759. }
  7760. // also inherit for comment nodes, but not placeholders (e.g. v-if which
  7761. // would have received .el during block patch)
  7762. if (c2.type === Comment && !c2.el) {
  7763. c2.el = c1.el;
  7764. }
  7765. }
  7766. }
  7767. }
  7768. // https://en.wikipedia.org/wiki/Longest_increasing_subsequence
  7769. function getSequence(arr) {
  7770. const p = arr.slice();
  7771. const result = [0];
  7772. let i, j, u, v, c;
  7773. const len = arr.length;
  7774. for (i = 0; i < len; i++) {
  7775. const arrI = arr[i];
  7776. if (arrI !== 0) {
  7777. j = result[result.length - 1];
  7778. if (arr[j] < arrI) {
  7779. p[i] = j;
  7780. result.push(i);
  7781. continue;
  7782. }
  7783. u = 0;
  7784. v = result.length - 1;
  7785. while (u < v) {
  7786. c = (u + v) >> 1;
  7787. if (arr[result[c]] < arrI) {
  7788. u = c + 1;
  7789. }
  7790. else {
  7791. v = c;
  7792. }
  7793. }
  7794. if (arrI < arr[result[u]]) {
  7795. if (u > 0) {
  7796. p[i] = result[u - 1];
  7797. }
  7798. result[u] = i;
  7799. }
  7800. }
  7801. }
  7802. u = result.length;
  7803. v = result[u - 1];
  7804. while (u-- > 0) {
  7805. result[u] = v;
  7806. v = p[v];
  7807. }
  7808. return result;
  7809. }
  7810. const isTeleport = (type) => type.__isTeleport;
  7811. const isTeleportDisabled = (props) => props && (props.disabled || props.disabled === '');
  7812. const isTargetSVG = (target) => typeof SVGElement !== 'undefined' && target instanceof SVGElement;
  7813. const resolveTarget = (props, select) => {
  7814. const targetSelector = props && props.to;
  7815. if (isString(targetSelector)) {
  7816. if (!select) {
  7817. warn$1(`Current renderer does not support string target for Teleports. ` +
  7818. `(missing querySelector renderer option)`);
  7819. return null;
  7820. }
  7821. else {
  7822. const target = select(targetSelector);
  7823. if (!target) {
  7824. warn$1(`Failed to locate Teleport target with selector "${targetSelector}". ` +
  7825. `Note the target element must exist before the component is mounted - ` +
  7826. `i.e. the target cannot be rendered by the component itself, and ` +
  7827. `ideally should be outside of the entire Vue component tree.`);
  7828. }
  7829. return target;
  7830. }
  7831. }
  7832. else {
  7833. if (!targetSelector && !isTeleportDisabled(props)) {
  7834. warn$1(`Invalid Teleport target: ${targetSelector}`);
  7835. }
  7836. return targetSelector;
  7837. }
  7838. };
  7839. const TeleportImpl = {
  7840. __isTeleport: true,
  7841. process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, internals) {
  7842. const { mc: mountChildren, pc: patchChildren, pbc: patchBlockChildren, o: { insert, querySelector, createText, createComment } } = internals;
  7843. const disabled = isTeleportDisabled(n2.props);
  7844. let { shapeFlag, children, dynamicChildren } = n2;
  7845. // #3302
  7846. // HMR updated, force full diff
  7847. if (isHmrUpdating) {
  7848. optimized = false;
  7849. dynamicChildren = null;
  7850. }
  7851. if (n1 == null) {
  7852. // insert anchors in the main view
  7853. const placeholder = (n2.el = createComment('teleport start')
  7854. );
  7855. const mainAnchor = (n2.anchor = createComment('teleport end')
  7856. );
  7857. insert(placeholder, container, anchor);
  7858. insert(mainAnchor, container, anchor);
  7859. const target = (n2.target = resolveTarget(n2.props, querySelector));
  7860. const targetAnchor = (n2.targetAnchor = createText(''));
  7861. if (target) {
  7862. insert(targetAnchor, target);
  7863. // #2652 we could be teleporting from a non-SVG tree into an SVG tree
  7864. isSVG = isSVG || isTargetSVG(target);
  7865. }
  7866. else if (!disabled) {
  7867. warn$1('Invalid Teleport target on mount:', target, `(${typeof target})`);
  7868. }
  7869. const mount = (container, anchor) => {
  7870. // Teleport *always* has Array children. This is enforced in both the
  7871. // compiler and vnode children normalization.
  7872. if (shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  7873. mountChildren(children, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7874. }
  7875. };
  7876. if (disabled) {
  7877. mount(container, mainAnchor);
  7878. }
  7879. else if (target) {
  7880. mount(target, targetAnchor);
  7881. }
  7882. }
  7883. else {
  7884. // update content
  7885. n2.el = n1.el;
  7886. const mainAnchor = (n2.anchor = n1.anchor);
  7887. const target = (n2.target = n1.target);
  7888. const targetAnchor = (n2.targetAnchor = n1.targetAnchor);
  7889. const wasDisabled = isTeleportDisabled(n1.props);
  7890. const currentContainer = wasDisabled ? container : target;
  7891. const currentAnchor = wasDisabled ? mainAnchor : targetAnchor;
  7892. isSVG = isSVG || isTargetSVG(target);
  7893. if (dynamicChildren) {
  7894. // fast path when the teleport happens to be a block root
  7895. patchBlockChildren(n1.dynamicChildren, dynamicChildren, currentContainer, parentComponent, parentSuspense, isSVG, slotScopeIds);
  7896. // even in block tree mode we need to make sure all root-level nodes
  7897. // in the teleport inherit previous DOM references so that they can
  7898. // be moved in future patches.
  7899. traverseStaticChildren(n1, n2, true);
  7900. }
  7901. else if (!optimized) {
  7902. patchChildren(n1, n2, currentContainer, currentAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, false);
  7903. }
  7904. if (disabled) {
  7905. if (!wasDisabled) {
  7906. // enabled -> disabled
  7907. // move into main container
  7908. moveTeleport(n2, container, mainAnchor, internals, 1 /* TeleportMoveTypes.TOGGLE */);
  7909. }
  7910. }
  7911. else {
  7912. // target changed
  7913. if ((n2.props && n2.props.to) !== (n1.props && n1.props.to)) {
  7914. const nextTarget = (n2.target = resolveTarget(n2.props, querySelector));
  7915. if (nextTarget) {
  7916. moveTeleport(n2, nextTarget, null, internals, 0 /* TeleportMoveTypes.TARGET_CHANGE */);
  7917. }
  7918. else {
  7919. warn$1('Invalid Teleport target on update:', target, `(${typeof target})`);
  7920. }
  7921. }
  7922. else if (wasDisabled) {
  7923. // disabled -> enabled
  7924. // move into teleport target
  7925. moveTeleport(n2, target, targetAnchor, internals, 1 /* TeleportMoveTypes.TOGGLE */);
  7926. }
  7927. }
  7928. }
  7929. updateCssVars(n2);
  7930. },
  7931. remove(vnode, parentComponent, parentSuspense, optimized, { um: unmount, o: { remove: hostRemove } }, doRemove) {
  7932. const { shapeFlag, children, anchor, targetAnchor, target, props } = vnode;
  7933. if (target) {
  7934. hostRemove(targetAnchor);
  7935. }
  7936. // an unmounted teleport should always remove its children if not disabled
  7937. if (doRemove || !isTeleportDisabled(props)) {
  7938. hostRemove(anchor);
  7939. if (shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  7940. for (let i = 0; i < children.length; i++) {
  7941. const child = children[i];
  7942. unmount(child, parentComponent, parentSuspense, true, !!child.dynamicChildren);
  7943. }
  7944. }
  7945. }
  7946. },
  7947. move: moveTeleport,
  7948. hydrate: hydrateTeleport
  7949. };
  7950. function moveTeleport(vnode, container, parentAnchor, { o: { insert }, m: move }, moveType = 2 /* TeleportMoveTypes.REORDER */) {
  7951. // move target anchor if this is a target change.
  7952. if (moveType === 0 /* TeleportMoveTypes.TARGET_CHANGE */) {
  7953. insert(vnode.targetAnchor, container, parentAnchor);
  7954. }
  7955. const { el, anchor, shapeFlag, children, props } = vnode;
  7956. const isReorder = moveType === 2 /* TeleportMoveTypes.REORDER */;
  7957. // move main view anchor if this is a re-order.
  7958. if (isReorder) {
  7959. insert(el, container, parentAnchor);
  7960. }
  7961. // if this is a re-order and teleport is enabled (content is in target)
  7962. // do not move children. So the opposite is: only move children if this
  7963. // is not a reorder, or the teleport is disabled
  7964. if (!isReorder || isTeleportDisabled(props)) {
  7965. // Teleport has either Array children or no children.
  7966. if (shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  7967. for (let i = 0; i < children.length; i++) {
  7968. move(children[i], container, parentAnchor, 2 /* MoveType.REORDER */);
  7969. }
  7970. }
  7971. }
  7972. // move main view anchor if this is a re-order.
  7973. if (isReorder) {
  7974. insert(anchor, container, parentAnchor);
  7975. }
  7976. }
  7977. function hydrateTeleport(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized, { o: { nextSibling, parentNode, querySelector } }, hydrateChildren) {
  7978. const target = (vnode.target = resolveTarget(vnode.props, querySelector));
  7979. if (target) {
  7980. // if multiple teleports rendered to the same target element, we need to
  7981. // pick up from where the last teleport finished instead of the first node
  7982. const targetNode = target._lpa || target.firstChild;
  7983. if (vnode.shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  7984. if (isTeleportDisabled(vnode.props)) {
  7985. vnode.anchor = hydrateChildren(nextSibling(node), vnode, parentNode(node), parentComponent, parentSuspense, slotScopeIds, optimized);
  7986. vnode.targetAnchor = targetNode;
  7987. }
  7988. else {
  7989. vnode.anchor = nextSibling(node);
  7990. // lookahead until we find the target anchor
  7991. // we cannot rely on return value of hydrateChildren() because there
  7992. // could be nested teleports
  7993. let targetAnchor = targetNode;
  7994. while (targetAnchor) {
  7995. targetAnchor = nextSibling(targetAnchor);
  7996. if (targetAnchor &&
  7997. targetAnchor.nodeType === 8 &&
  7998. targetAnchor.data === 'teleport anchor') {
  7999. vnode.targetAnchor = targetAnchor;
  8000. target._lpa =
  8001. vnode.targetAnchor && nextSibling(vnode.targetAnchor);
  8002. break;
  8003. }
  8004. }
  8005. hydrateChildren(targetNode, vnode, target, parentComponent, parentSuspense, slotScopeIds, optimized);
  8006. }
  8007. }
  8008. updateCssVars(vnode);
  8009. }
  8010. return vnode.anchor && nextSibling(vnode.anchor);
  8011. }
  8012. // Force-casted public typing for h and TSX props inference
  8013. const Teleport = TeleportImpl;
  8014. function updateCssVars(vnode) {
  8015. // presence of .ut method indicates owner component uses css vars.
  8016. // code path here can assume browser environment.
  8017. const ctx = vnode.ctx;
  8018. if (ctx && ctx.ut) {
  8019. let node = vnode.children[0].el;
  8020. while (node !== vnode.targetAnchor) {
  8021. if (node.nodeType === 1)
  8022. node.setAttribute('data-v-owner', ctx.uid);
  8023. node = node.nextSibling;
  8024. }
  8025. ctx.ut();
  8026. }
  8027. }
  8028. const Fragment = Symbol('Fragment' );
  8029. const Text = Symbol('Text' );
  8030. const Comment = Symbol('Comment' );
  8031. const Static = Symbol('Static' );
  8032. // Since v-if and v-for are the two possible ways node structure can dynamically
  8033. // change, once we consider v-if branches and each v-for fragment a block, we
  8034. // can divide a template into nested blocks, and within each block the node
  8035. // structure would be stable. This allows us to skip most children diffing
  8036. // and only worry about the dynamic nodes (indicated by patch flags).
  8037. const blockStack = [];
  8038. let currentBlock = null;
  8039. /**
  8040. * Open a block.
  8041. * This must be called before `createBlock`. It cannot be part of `createBlock`
  8042. * because the children of the block are evaluated before `createBlock` itself
  8043. * is called. The generated code typically looks like this:
  8044. *
  8045. * ```js
  8046. * function render() {
  8047. * return (openBlock(),createBlock('div', null, [...]))
  8048. * }
  8049. * ```
  8050. * disableTracking is true when creating a v-for fragment block, since a v-for
  8051. * fragment always diffs its children.
  8052. *
  8053. * @private
  8054. */
  8055. function openBlock(disableTracking = false) {
  8056. blockStack.push((currentBlock = disableTracking ? null : []));
  8057. }
  8058. function closeBlock() {
  8059. blockStack.pop();
  8060. currentBlock = blockStack[blockStack.length - 1] || null;
  8061. }
  8062. // Whether we should be tracking dynamic child nodes inside a block.
  8063. // Only tracks when this value is > 0
  8064. // We are not using a simple boolean because this value may need to be
  8065. // incremented/decremented by nested usage of v-once (see below)
  8066. let isBlockTreeEnabled = 1;
  8067. /**
  8068. * Block tracking sometimes needs to be disabled, for example during the
  8069. * creation of a tree that needs to be cached by v-once. The compiler generates
  8070. * code like this:
  8071. *
  8072. * ``` js
  8073. * _cache[1] || (
  8074. * setBlockTracking(-1),
  8075. * _cache[1] = createVNode(...),
  8076. * setBlockTracking(1),
  8077. * _cache[1]
  8078. * )
  8079. * ```
  8080. *
  8081. * @private
  8082. */
  8083. function setBlockTracking(value) {
  8084. isBlockTreeEnabled += value;
  8085. }
  8086. function setupBlock(vnode) {
  8087. // save current block children on the block vnode
  8088. vnode.dynamicChildren =
  8089. isBlockTreeEnabled > 0 ? currentBlock || EMPTY_ARR : null;
  8090. // close block
  8091. closeBlock();
  8092. // a block is always going to be patched, so track it as a child of its
  8093. // parent block
  8094. if (isBlockTreeEnabled > 0 && currentBlock) {
  8095. currentBlock.push(vnode);
  8096. }
  8097. return vnode;
  8098. }
  8099. /**
  8100. * @private
  8101. */
  8102. function createElementBlock(type, props, children, patchFlag, dynamicProps, shapeFlag) {
  8103. return setupBlock(createBaseVNode(type, props, children, patchFlag, dynamicProps, shapeFlag, true /* isBlock */));
  8104. }
  8105. /**
  8106. * Create a block root vnode. Takes the same exact arguments as `createVNode`.
  8107. * A block root keeps track of dynamic nodes within the block in the
  8108. * `dynamicChildren` array.
  8109. *
  8110. * @private
  8111. */
  8112. function createBlock(type, props, children, patchFlag, dynamicProps) {
  8113. return setupBlock(createVNode(type, props, children, patchFlag, dynamicProps, true /* isBlock: prevent a block from tracking itself */));
  8114. }
  8115. function isVNode(value) {
  8116. return value ? value.__v_isVNode === true : false;
  8117. }
  8118. function isSameVNodeType(n1, n2) {
  8119. if (n2.shapeFlag & 6 /* ShapeFlags.COMPONENT */ &&
  8120. hmrDirtyComponents.has(n2.type)) {
  8121. // #7042, ensure the vnode being unmounted during HMR
  8122. // bitwise operations to remove keep alive flags
  8123. n1.shapeFlag &= ~256 /* ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE */;
  8124. n2.shapeFlag &= ~512 /* ShapeFlags.COMPONENT_KEPT_ALIVE */;
  8125. // HMR only: if the component has been hot-updated, force a reload.
  8126. return false;
  8127. }
  8128. return n1.type === n2.type && n1.key === n2.key;
  8129. }
  8130. let vnodeArgsTransformer;
  8131. /**
  8132. * Internal API for registering an arguments transform for createVNode
  8133. * used for creating stubs in the test-utils
  8134. * It is *internal* but needs to be exposed for test-utils to pick up proper
  8135. * typings
  8136. */
  8137. function transformVNodeArgs(transformer) {
  8138. vnodeArgsTransformer = transformer;
  8139. }
  8140. const createVNodeWithArgsTransform = (...args) => {
  8141. return _createVNode(...(vnodeArgsTransformer
  8142. ? vnodeArgsTransformer(args, currentRenderingInstance)
  8143. : args));
  8144. };
  8145. const InternalObjectKey = `__vInternal`;
  8146. const normalizeKey = ({ key }) => key != null ? key : null;
  8147. const normalizeRef = ({ ref, ref_key, ref_for }) => {
  8148. return (ref != null
  8149. ? isString(ref) || isRef(ref) || isFunction(ref)
  8150. ? { i: currentRenderingInstance, r: ref, k: ref_key, f: !!ref_for }
  8151. : ref
  8152. : null);
  8153. };
  8154. function createBaseVNode(type, props = null, children = null, patchFlag = 0, dynamicProps = null, shapeFlag = type === Fragment ? 0 : 1 /* ShapeFlags.ELEMENT */, isBlockNode = false, needFullChildrenNormalization = false) {
  8155. const vnode = {
  8156. __v_isVNode: true,
  8157. __v_skip: true,
  8158. type,
  8159. props,
  8160. key: props && normalizeKey(props),
  8161. ref: props && normalizeRef(props),
  8162. scopeId: currentScopeId,
  8163. slotScopeIds: null,
  8164. children,
  8165. component: null,
  8166. suspense: null,
  8167. ssContent: null,
  8168. ssFallback: null,
  8169. dirs: null,
  8170. transition: null,
  8171. el: null,
  8172. anchor: null,
  8173. target: null,
  8174. targetAnchor: null,
  8175. staticCount: 0,
  8176. shapeFlag,
  8177. patchFlag,
  8178. dynamicProps,
  8179. dynamicChildren: null,
  8180. appContext: null,
  8181. ctx: currentRenderingInstance
  8182. };
  8183. if (needFullChildrenNormalization) {
  8184. normalizeChildren(vnode, children);
  8185. // normalize suspense children
  8186. if (shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
  8187. type.normalize(vnode);
  8188. }
  8189. }
  8190. else if (children) {
  8191. // compiled element vnode - if children is passed, only possible types are
  8192. // string or Array.
  8193. vnode.shapeFlag |= isString(children)
  8194. ? 8 /* ShapeFlags.TEXT_CHILDREN */
  8195. : 16 /* ShapeFlags.ARRAY_CHILDREN */;
  8196. }
  8197. // validate key
  8198. if (vnode.key !== vnode.key) {
  8199. warn$1(`VNode created with invalid key (NaN). VNode type:`, vnode.type);
  8200. }
  8201. // track vnode for block tree
  8202. if (isBlockTreeEnabled > 0 &&
  8203. // avoid a block node from tracking itself
  8204. !isBlockNode &&
  8205. // has current parent block
  8206. currentBlock &&
  8207. // presence of a patch flag indicates this node needs patching on updates.
  8208. // component nodes also should always be patched, because even if the
  8209. // component doesn't need to update, it needs to persist the instance on to
  8210. // the next vnode so that it can be properly unmounted later.
  8211. (vnode.patchFlag > 0 || shapeFlag & 6 /* ShapeFlags.COMPONENT */) &&
  8212. // the EVENTS flag is only for hydration and if it is the only flag, the
  8213. // vnode should not be considered dynamic due to handler caching.
  8214. vnode.patchFlag !== 32 /* PatchFlags.HYDRATE_EVENTS */) {
  8215. currentBlock.push(vnode);
  8216. }
  8217. return vnode;
  8218. }
  8219. const createVNode = (createVNodeWithArgsTransform );
  8220. function _createVNode(type, props = null, children = null, patchFlag = 0, dynamicProps = null, isBlockNode = false) {
  8221. if (!type || type === NULL_DYNAMIC_COMPONENT) {
  8222. if (!type) {
  8223. warn$1(`Invalid vnode type when creating vnode: ${type}.`);
  8224. }
  8225. type = Comment;
  8226. }
  8227. if (isVNode(type)) {
  8228. // createVNode receiving an existing vnode. This happens in cases like
  8229. // <component :is="vnode"/>
  8230. // #2078 make sure to merge refs during the clone instead of overwriting it
  8231. const cloned = cloneVNode(type, props, true /* mergeRef: true */);
  8232. if (children) {
  8233. normalizeChildren(cloned, children);
  8234. }
  8235. if (isBlockTreeEnabled > 0 && !isBlockNode && currentBlock) {
  8236. if (cloned.shapeFlag & 6 /* ShapeFlags.COMPONENT */) {
  8237. currentBlock[currentBlock.indexOf(type)] = cloned;
  8238. }
  8239. else {
  8240. currentBlock.push(cloned);
  8241. }
  8242. }
  8243. cloned.patchFlag |= -2 /* PatchFlags.BAIL */;
  8244. return cloned;
  8245. }
  8246. // class component normalization.
  8247. if (isClassComponent(type)) {
  8248. type = type.__vccOpts;
  8249. }
  8250. // class & style normalization.
  8251. if (props) {
  8252. // for reactive or proxy objects, we need to clone it to enable mutation.
  8253. props = guardReactiveProps(props);
  8254. let { class: klass, style } = props;
  8255. if (klass && !isString(klass)) {
  8256. props.class = normalizeClass(klass);
  8257. }
  8258. if (isObject(style)) {
  8259. // reactive state objects need to be cloned since they are likely to be
  8260. // mutated
  8261. if (isProxy(style) && !isArray(style)) {
  8262. style = extend({}, style);
  8263. }
  8264. props.style = normalizeStyle(style);
  8265. }
  8266. }
  8267. // encode the vnode type information into a bitmap
  8268. const shapeFlag = isString(type)
  8269. ? 1 /* ShapeFlags.ELEMENT */
  8270. : isSuspense(type)
  8271. ? 128 /* ShapeFlags.SUSPENSE */
  8272. : isTeleport(type)
  8273. ? 64 /* ShapeFlags.TELEPORT */
  8274. : isObject(type)
  8275. ? 4 /* ShapeFlags.STATEFUL_COMPONENT */
  8276. : isFunction(type)
  8277. ? 2 /* ShapeFlags.FUNCTIONAL_COMPONENT */
  8278. : 0;
  8279. if (shapeFlag & 4 /* ShapeFlags.STATEFUL_COMPONENT */ && isProxy(type)) {
  8280. type = toRaw(type);
  8281. warn$1(`Vue received a Component which was made a reactive object. This can ` +
  8282. `lead to unnecessary performance overhead, and should be avoided by ` +
  8283. `marking the component with \`markRaw\` or using \`shallowRef\` ` +
  8284. `instead of \`ref\`.`, `\nComponent that was made reactive: `, type);
  8285. }
  8286. return createBaseVNode(type, props, children, patchFlag, dynamicProps, shapeFlag, isBlockNode, true);
  8287. }
  8288. function guardReactiveProps(props) {
  8289. if (!props)
  8290. return null;
  8291. return isProxy(props) || InternalObjectKey in props
  8292. ? extend({}, props)
  8293. : props;
  8294. }
  8295. function cloneVNode(vnode, extraProps, mergeRef = false) {
  8296. // This is intentionally NOT using spread or extend to avoid the runtime
  8297. // key enumeration cost.
  8298. const { props, ref, patchFlag, children } = vnode;
  8299. const mergedProps = extraProps ? mergeProps(props || {}, extraProps) : props;
  8300. const cloned = {
  8301. __v_isVNode: true,
  8302. __v_skip: true,
  8303. type: vnode.type,
  8304. props: mergedProps,
  8305. key: mergedProps && normalizeKey(mergedProps),
  8306. ref: extraProps && extraProps.ref
  8307. ? // #2078 in the case of <component :is="vnode" ref="extra"/>
  8308. // if the vnode itself already has a ref, cloneVNode will need to merge
  8309. // the refs so the single vnode can be set on multiple refs
  8310. mergeRef && ref
  8311. ? isArray(ref)
  8312. ? ref.concat(normalizeRef(extraProps))
  8313. : [ref, normalizeRef(extraProps)]
  8314. : normalizeRef(extraProps)
  8315. : ref,
  8316. scopeId: vnode.scopeId,
  8317. slotScopeIds: vnode.slotScopeIds,
  8318. children: patchFlag === -1 /* PatchFlags.HOISTED */ && isArray(children)
  8319. ? children.map(deepCloneVNode)
  8320. : children,
  8321. target: vnode.target,
  8322. targetAnchor: vnode.targetAnchor,
  8323. staticCount: vnode.staticCount,
  8324. shapeFlag: vnode.shapeFlag,
  8325. // if the vnode is cloned with extra props, we can no longer assume its
  8326. // existing patch flag to be reliable and need to add the FULL_PROPS flag.
  8327. // note: preserve flag for fragments since they use the flag for children
  8328. // fast paths only.
  8329. patchFlag: extraProps && vnode.type !== Fragment
  8330. ? patchFlag === -1 // hoisted node
  8331. ? 16 /* PatchFlags.FULL_PROPS */
  8332. : patchFlag | 16 /* PatchFlags.FULL_PROPS */
  8333. : patchFlag,
  8334. dynamicProps: vnode.dynamicProps,
  8335. dynamicChildren: vnode.dynamicChildren,
  8336. appContext: vnode.appContext,
  8337. dirs: vnode.dirs,
  8338. transition: vnode.transition,
  8339. // These should technically only be non-null on mounted VNodes. However,
  8340. // they *should* be copied for kept-alive vnodes. So we just always copy
  8341. // them since them being non-null during a mount doesn't affect the logic as
  8342. // they will simply be overwritten.
  8343. component: vnode.component,
  8344. suspense: vnode.suspense,
  8345. ssContent: vnode.ssContent && cloneVNode(vnode.ssContent),
  8346. ssFallback: vnode.ssFallback && cloneVNode(vnode.ssFallback),
  8347. el: vnode.el,
  8348. anchor: vnode.anchor,
  8349. ctx: vnode.ctx
  8350. };
  8351. return cloned;
  8352. }
  8353. /**
  8354. * Dev only, for HMR of hoisted vnodes reused in v-for
  8355. * https://github.com/vitejs/vite/issues/2022
  8356. */
  8357. function deepCloneVNode(vnode) {
  8358. const cloned = cloneVNode(vnode);
  8359. if (isArray(vnode.children)) {
  8360. cloned.children = vnode.children.map(deepCloneVNode);
  8361. }
  8362. return cloned;
  8363. }
  8364. /**
  8365. * @private
  8366. */
  8367. function createTextVNode(text = ' ', flag = 0) {
  8368. return createVNode(Text, null, text, flag);
  8369. }
  8370. /**
  8371. * @private
  8372. */
  8373. function createStaticVNode(content, numberOfNodes) {
  8374. // A static vnode can contain multiple stringified elements, and the number
  8375. // of elements is necessary for hydration.
  8376. const vnode = createVNode(Static, null, content);
  8377. vnode.staticCount = numberOfNodes;
  8378. return vnode;
  8379. }
  8380. /**
  8381. * @private
  8382. */
  8383. function createCommentVNode(text = '',
  8384. // when used as the v-else branch, the comment node must be created as a
  8385. // block to ensure correct updates.
  8386. asBlock = false) {
  8387. return asBlock
  8388. ? (openBlock(), createBlock(Comment, null, text))
  8389. : createVNode(Comment, null, text);
  8390. }
  8391. function normalizeVNode(child) {
  8392. if (child == null || typeof child === 'boolean') {
  8393. // empty placeholder
  8394. return createVNode(Comment);
  8395. }
  8396. else if (isArray(child)) {
  8397. // fragment
  8398. return createVNode(Fragment, null,
  8399. // #3666, avoid reference pollution when reusing vnode
  8400. child.slice());
  8401. }
  8402. else if (typeof child === 'object') {
  8403. // already vnode, this should be the most common since compiled templates
  8404. // always produce all-vnode children arrays
  8405. return cloneIfMounted(child);
  8406. }
  8407. else {
  8408. // strings and numbers
  8409. return createVNode(Text, null, String(child));
  8410. }
  8411. }
  8412. // optimized normalization for template-compiled render fns
  8413. function cloneIfMounted(child) {
  8414. return (child.el === null && child.patchFlag !== -1 /* PatchFlags.HOISTED */) ||
  8415. child.memo
  8416. ? child
  8417. : cloneVNode(child);
  8418. }
  8419. function normalizeChildren(vnode, children) {
  8420. let type = 0;
  8421. const { shapeFlag } = vnode;
  8422. if (children == null) {
  8423. children = null;
  8424. }
  8425. else if (isArray(children)) {
  8426. type = 16 /* ShapeFlags.ARRAY_CHILDREN */;
  8427. }
  8428. else if (typeof children === 'object') {
  8429. if (shapeFlag & (1 /* ShapeFlags.ELEMENT */ | 64 /* ShapeFlags.TELEPORT */)) {
  8430. // Normalize slot to plain children for plain element and Teleport
  8431. const slot = children.default;
  8432. if (slot) {
  8433. // _c marker is added by withCtx() indicating this is a compiled slot
  8434. slot._c && (slot._d = false);
  8435. normalizeChildren(vnode, slot());
  8436. slot._c && (slot._d = true);
  8437. }
  8438. return;
  8439. }
  8440. else {
  8441. type = 32 /* ShapeFlags.SLOTS_CHILDREN */;
  8442. const slotFlag = children._;
  8443. if (!slotFlag && !(InternalObjectKey in children)) {
  8444. children._ctx = currentRenderingInstance;
  8445. }
  8446. else if (slotFlag === 3 /* SlotFlags.FORWARDED */ && currentRenderingInstance) {
  8447. // a child component receives forwarded slots from the parent.
  8448. // its slot type is determined by its parent's slot type.
  8449. if (currentRenderingInstance.slots._ === 1 /* SlotFlags.STABLE */) {
  8450. children._ = 1 /* SlotFlags.STABLE */;
  8451. }
  8452. else {
  8453. children._ = 2 /* SlotFlags.DYNAMIC */;
  8454. vnode.patchFlag |= 1024 /* PatchFlags.DYNAMIC_SLOTS */;
  8455. }
  8456. }
  8457. }
  8458. }
  8459. else if (isFunction(children)) {
  8460. children = { default: children, _ctx: currentRenderingInstance };
  8461. type = 32 /* ShapeFlags.SLOTS_CHILDREN */;
  8462. }
  8463. else {
  8464. children = String(children);
  8465. // force teleport children to array so it can be moved around
  8466. if (shapeFlag & 64 /* ShapeFlags.TELEPORT */) {
  8467. type = 16 /* ShapeFlags.ARRAY_CHILDREN */;
  8468. children = [createTextVNode(children)];
  8469. }
  8470. else {
  8471. type = 8 /* ShapeFlags.TEXT_CHILDREN */;
  8472. }
  8473. }
  8474. vnode.children = children;
  8475. vnode.shapeFlag |= type;
  8476. }
  8477. function mergeProps(...args) {
  8478. const ret = {};
  8479. for (let i = 0; i < args.length; i++) {
  8480. const toMerge = args[i];
  8481. for (const key in toMerge) {
  8482. if (key === 'class') {
  8483. if (ret.class !== toMerge.class) {
  8484. ret.class = normalizeClass([ret.class, toMerge.class]);
  8485. }
  8486. }
  8487. else if (key === 'style') {
  8488. ret.style = normalizeStyle([ret.style, toMerge.style]);
  8489. }
  8490. else if (isOn(key)) {
  8491. const existing = ret[key];
  8492. const incoming = toMerge[key];
  8493. if (incoming &&
  8494. existing !== incoming &&
  8495. !(isArray(existing) && existing.includes(incoming))) {
  8496. ret[key] = existing
  8497. ? [].concat(existing, incoming)
  8498. : incoming;
  8499. }
  8500. }
  8501. else if (key !== '') {
  8502. ret[key] = toMerge[key];
  8503. }
  8504. }
  8505. }
  8506. return ret;
  8507. }
  8508. function invokeVNodeHook(hook, instance, vnode, prevVNode = null) {
  8509. callWithAsyncErrorHandling(hook, instance, 7 /* ErrorCodes.VNODE_HOOK */, [
  8510. vnode,
  8511. prevVNode
  8512. ]);
  8513. }
  8514. const emptyAppContext = createAppContext();
  8515. let uid$1 = 0;
  8516. function createComponentInstance(vnode, parent, suspense) {
  8517. const type = vnode.type;
  8518. // inherit parent app context - or - if root, adopt from root vnode
  8519. const appContext = (parent ? parent.appContext : vnode.appContext) || emptyAppContext;
  8520. const instance = {
  8521. uid: uid$1++,
  8522. vnode,
  8523. type,
  8524. parent,
  8525. appContext,
  8526. root: null,
  8527. next: null,
  8528. subTree: null,
  8529. effect: null,
  8530. update: null,
  8531. scope: new EffectScope(true /* detached */),
  8532. render: null,
  8533. proxy: null,
  8534. exposed: null,
  8535. exposeProxy: null,
  8536. withProxy: null,
  8537. provides: parent ? parent.provides : Object.create(appContext.provides),
  8538. accessCache: null,
  8539. renderCache: [],
  8540. // local resolved assets
  8541. components: null,
  8542. directives: null,
  8543. // resolved props and emits options
  8544. propsOptions: normalizePropsOptions(type, appContext),
  8545. emitsOptions: normalizeEmitsOptions(type, appContext),
  8546. // emit
  8547. emit: null,
  8548. emitted: null,
  8549. // props default value
  8550. propsDefaults: EMPTY_OBJ,
  8551. // inheritAttrs
  8552. inheritAttrs: type.inheritAttrs,
  8553. // state
  8554. ctx: EMPTY_OBJ,
  8555. data: EMPTY_OBJ,
  8556. props: EMPTY_OBJ,
  8557. attrs: EMPTY_OBJ,
  8558. slots: EMPTY_OBJ,
  8559. refs: EMPTY_OBJ,
  8560. setupState: EMPTY_OBJ,
  8561. setupContext: null,
  8562. // suspense related
  8563. suspense,
  8564. suspenseId: suspense ? suspense.pendingId : 0,
  8565. asyncDep: null,
  8566. asyncResolved: false,
  8567. // lifecycle hooks
  8568. // not using enums here because it results in computed properties
  8569. isMounted: false,
  8570. isUnmounted: false,
  8571. isDeactivated: false,
  8572. bc: null,
  8573. c: null,
  8574. bm: null,
  8575. m: null,
  8576. bu: null,
  8577. u: null,
  8578. um: null,
  8579. bum: null,
  8580. da: null,
  8581. a: null,
  8582. rtg: null,
  8583. rtc: null,
  8584. ec: null,
  8585. sp: null
  8586. };
  8587. {
  8588. instance.ctx = createDevRenderContext(instance);
  8589. }
  8590. instance.root = parent ? parent.root : instance;
  8591. instance.emit = emit$1.bind(null, instance);
  8592. // apply custom element special handling
  8593. if (vnode.ce) {
  8594. vnode.ce(instance);
  8595. }
  8596. return instance;
  8597. }
  8598. let currentInstance = null;
  8599. const getCurrentInstance = () => currentInstance || currentRenderingInstance;
  8600. const setCurrentInstance = (instance) => {
  8601. currentInstance = instance;
  8602. instance.scope.on();
  8603. };
  8604. const unsetCurrentInstance = () => {
  8605. currentInstance && currentInstance.scope.off();
  8606. currentInstance = null;
  8607. };
  8608. const isBuiltInTag = /*#__PURE__*/ makeMap('slot,component');
  8609. function validateComponentName(name, config) {
  8610. const appIsNativeTag = config.isNativeTag || NO;
  8611. if (isBuiltInTag(name) || appIsNativeTag(name)) {
  8612. warn$1('Do not use built-in or reserved HTML elements as component id: ' + name);
  8613. }
  8614. }
  8615. function isStatefulComponent(instance) {
  8616. return instance.vnode.shapeFlag & 4 /* ShapeFlags.STATEFUL_COMPONENT */;
  8617. }
  8618. let isInSSRComponentSetup = false;
  8619. function setupComponent(instance, isSSR = false) {
  8620. isInSSRComponentSetup = isSSR;
  8621. const { props, children } = instance.vnode;
  8622. const isStateful = isStatefulComponent(instance);
  8623. initProps(instance, props, isStateful, isSSR);
  8624. initSlots(instance, children);
  8625. const setupResult = isStateful
  8626. ? setupStatefulComponent(instance, isSSR)
  8627. : undefined;
  8628. isInSSRComponentSetup = false;
  8629. return setupResult;
  8630. }
  8631. function setupStatefulComponent(instance, isSSR) {
  8632. var _a;
  8633. const Component = instance.type;
  8634. {
  8635. if (Component.name) {
  8636. validateComponentName(Component.name, instance.appContext.config);
  8637. }
  8638. if (Component.components) {
  8639. const names = Object.keys(Component.components);
  8640. for (let i = 0; i < names.length; i++) {
  8641. validateComponentName(names[i], instance.appContext.config);
  8642. }
  8643. }
  8644. if (Component.directives) {
  8645. const names = Object.keys(Component.directives);
  8646. for (let i = 0; i < names.length; i++) {
  8647. validateDirectiveName(names[i]);
  8648. }
  8649. }
  8650. if (Component.compilerOptions && isRuntimeOnly()) {
  8651. warn$1(`"compilerOptions" is only supported when using a build of Vue that ` +
  8652. `includes the runtime compiler. Since you are using a runtime-only ` +
  8653. `build, the options should be passed via your build tool config instead.`);
  8654. }
  8655. }
  8656. // 0. create render proxy property access cache
  8657. instance.accessCache = Object.create(null);
  8658. // 1. create public instance / render proxy
  8659. // also mark it raw so it's never observed
  8660. instance.proxy = markRaw(new Proxy(instance.ctx, PublicInstanceProxyHandlers));
  8661. {
  8662. exposePropsOnRenderContext(instance);
  8663. }
  8664. // 2. call setup()
  8665. const { setup } = Component;
  8666. if (setup) {
  8667. const setupContext = (instance.setupContext =
  8668. setup.length > 1 ? createSetupContext(instance) : null);
  8669. setCurrentInstance(instance);
  8670. pauseTracking();
  8671. const setupResult = callWithErrorHandling(setup, instance, 0 /* ErrorCodes.SETUP_FUNCTION */, [shallowReadonly(instance.props) , setupContext]);
  8672. resetTracking();
  8673. unsetCurrentInstance();
  8674. if (isPromise(setupResult)) {
  8675. setupResult.then(unsetCurrentInstance, unsetCurrentInstance);
  8676. if (isSSR) {
  8677. // return the promise so server-renderer can wait on it
  8678. return setupResult
  8679. .then((resolvedResult) => {
  8680. handleSetupResult(instance, resolvedResult, isSSR);
  8681. })
  8682. .catch(e => {
  8683. handleError(e, instance, 0 /* ErrorCodes.SETUP_FUNCTION */);
  8684. });
  8685. }
  8686. else {
  8687. // async setup returned Promise.
  8688. // bail here and wait for re-entry.
  8689. instance.asyncDep = setupResult;
  8690. if (!instance.suspense) {
  8691. const name = (_a = Component.name) !== null && _a !== void 0 ? _a : 'Anonymous';
  8692. warn$1(`Component <${name}>: setup function returned a promise, but no ` +
  8693. `<Suspense> boundary was found in the parent component tree. ` +
  8694. `A component with async setup() must be nested in a <Suspense> ` +
  8695. `in order to be rendered.`);
  8696. }
  8697. }
  8698. }
  8699. else {
  8700. handleSetupResult(instance, setupResult, isSSR);
  8701. }
  8702. }
  8703. else {
  8704. finishComponentSetup(instance, isSSR);
  8705. }
  8706. }
  8707. function handleSetupResult(instance, setupResult, isSSR) {
  8708. if (isFunction(setupResult)) {
  8709. // setup returned an inline render function
  8710. {
  8711. instance.render = setupResult;
  8712. }
  8713. }
  8714. else if (isObject(setupResult)) {
  8715. if (isVNode(setupResult)) {
  8716. warn$1(`setup() should not return VNodes directly - ` +
  8717. `return a render function instead.`);
  8718. }
  8719. // setup returned bindings.
  8720. // assuming a render function compiled from template is present.
  8721. {
  8722. instance.devtoolsRawSetupState = setupResult;
  8723. }
  8724. instance.setupState = proxyRefs(setupResult);
  8725. {
  8726. exposeSetupStateOnRenderContext(instance);
  8727. }
  8728. }
  8729. else if (setupResult !== undefined) {
  8730. warn$1(`setup() should return an object. Received: ${setupResult === null ? 'null' : typeof setupResult}`);
  8731. }
  8732. finishComponentSetup(instance, isSSR);
  8733. }
  8734. let compile;
  8735. let installWithProxy;
  8736. /**
  8737. * For runtime-dom to register the compiler.
  8738. * Note the exported method uses any to avoid d.ts relying on the compiler types.
  8739. */
  8740. function registerRuntimeCompiler(_compile) {
  8741. compile = _compile;
  8742. installWithProxy = i => {
  8743. if (i.render._rc) {
  8744. i.withProxy = new Proxy(i.ctx, RuntimeCompiledPublicInstanceProxyHandlers);
  8745. }
  8746. };
  8747. }
  8748. // dev only
  8749. const isRuntimeOnly = () => !compile;
  8750. function finishComponentSetup(instance, isSSR, skipOptions) {
  8751. const Component = instance.type;
  8752. // template / render function normalization
  8753. // could be already set when returned from setup()
  8754. if (!instance.render) {
  8755. // only do on-the-fly compile if not in SSR - SSR on-the-fly compilation
  8756. // is done by server-renderer
  8757. if (!isSSR && compile && !Component.render) {
  8758. const template = Component.template ||
  8759. resolveMergedOptions(instance).template;
  8760. if (template) {
  8761. {
  8762. startMeasure(instance, `compile`);
  8763. }
  8764. const { isCustomElement, compilerOptions } = instance.appContext.config;
  8765. const { delimiters, compilerOptions: componentCompilerOptions } = Component;
  8766. const finalCompilerOptions = extend(extend({
  8767. isCustomElement,
  8768. delimiters
  8769. }, compilerOptions), componentCompilerOptions);
  8770. Component.render = compile(template, finalCompilerOptions);
  8771. {
  8772. endMeasure(instance, `compile`);
  8773. }
  8774. }
  8775. }
  8776. instance.render = (Component.render || NOOP);
  8777. // for runtime-compiled render functions using `with` blocks, the render
  8778. // proxy used needs a different `has` handler which is more performant and
  8779. // also only allows a whitelist of globals to fallthrough.
  8780. if (installWithProxy) {
  8781. installWithProxy(instance);
  8782. }
  8783. }
  8784. // support for 2.x options
  8785. {
  8786. setCurrentInstance(instance);
  8787. pauseTracking();
  8788. applyOptions(instance);
  8789. resetTracking();
  8790. unsetCurrentInstance();
  8791. }
  8792. // warn missing template/render
  8793. // the runtime compilation of template in SSR is done by server-render
  8794. if (!Component.render && instance.render === NOOP && !isSSR) {
  8795. /* istanbul ignore if */
  8796. if (!compile && Component.template) {
  8797. warn$1(`Component provided template option but ` +
  8798. `runtime compilation is not supported in this build of Vue.` +
  8799. (` Use "vue.global.js" instead.`
  8800. ) /* should not happen */);
  8801. }
  8802. else {
  8803. warn$1(`Component is missing template or render function.`);
  8804. }
  8805. }
  8806. }
  8807. function createAttrsProxy(instance) {
  8808. return new Proxy(instance.attrs, {
  8809. get(target, key) {
  8810. markAttrsAccessed();
  8811. track(instance, "get" /* TrackOpTypes.GET */, '$attrs');
  8812. return target[key];
  8813. },
  8814. set() {
  8815. warn$1(`setupContext.attrs is readonly.`);
  8816. return false;
  8817. },
  8818. deleteProperty() {
  8819. warn$1(`setupContext.attrs is readonly.`);
  8820. return false;
  8821. }
  8822. }
  8823. );
  8824. }
  8825. function createSetupContext(instance) {
  8826. const expose = exposed => {
  8827. if (instance.exposed) {
  8828. warn$1(`expose() should be called only once per setup().`);
  8829. }
  8830. instance.exposed = exposed || {};
  8831. };
  8832. let attrs;
  8833. {
  8834. // We use getters in dev in case libs like test-utils overwrite instance
  8835. // properties (overwrites should not be done in prod)
  8836. return Object.freeze({
  8837. get attrs() {
  8838. return attrs || (attrs = createAttrsProxy(instance));
  8839. },
  8840. get slots() {
  8841. return shallowReadonly(instance.slots);
  8842. },
  8843. get emit() {
  8844. return (event, ...args) => instance.emit(event, ...args);
  8845. },
  8846. expose
  8847. });
  8848. }
  8849. }
  8850. function getExposeProxy(instance) {
  8851. if (instance.exposed) {
  8852. return (instance.exposeProxy ||
  8853. (instance.exposeProxy = new Proxy(proxyRefs(markRaw(instance.exposed)), {
  8854. get(target, key) {
  8855. if (key in target) {
  8856. return target[key];
  8857. }
  8858. else if (key in publicPropertiesMap) {
  8859. return publicPropertiesMap[key](instance);
  8860. }
  8861. },
  8862. has(target, key) {
  8863. return key in target || key in publicPropertiesMap;
  8864. }
  8865. })));
  8866. }
  8867. }
  8868. const classifyRE = /(?:^|[-_])(\w)/g;
  8869. const classify = (str) => str.replace(classifyRE, c => c.toUpperCase()).replace(/[-_]/g, '');
  8870. function getComponentName(Component, includeInferred = true) {
  8871. return isFunction(Component)
  8872. ? Component.displayName || Component.name
  8873. : Component.name || (includeInferred && Component.__name);
  8874. }
  8875. /* istanbul ignore next */
  8876. function formatComponentName(instance, Component, isRoot = false) {
  8877. let name = getComponentName(Component);
  8878. if (!name && Component.__file) {
  8879. const match = Component.__file.match(/([^/\\]+)\.\w+$/);
  8880. if (match) {
  8881. name = match[1];
  8882. }
  8883. }
  8884. if (!name && instance && instance.parent) {
  8885. // try to infer the name based on reverse resolution
  8886. const inferFromRegistry = (registry) => {
  8887. for (const key in registry) {
  8888. if (registry[key] === Component) {
  8889. return key;
  8890. }
  8891. }
  8892. };
  8893. name =
  8894. inferFromRegistry(instance.components ||
  8895. instance.parent.type.components) || inferFromRegistry(instance.appContext.components);
  8896. }
  8897. return name ? classify(name) : isRoot ? `App` : `Anonymous`;
  8898. }
  8899. function isClassComponent(value) {
  8900. return isFunction(value) && '__vccOpts' in value;
  8901. }
  8902. const computed$1 = ((getterOrOptions, debugOptions) => {
  8903. // @ts-ignore
  8904. return computed(getterOrOptions, debugOptions, isInSSRComponentSetup);
  8905. });
  8906. // dev only
  8907. const warnRuntimeUsage = (method) => warn$1(`${method}() is a compiler-hint helper that is only usable inside ` +
  8908. `<script setup> of a single file component. Its arguments should be ` +
  8909. `compiled away and passing it at runtime has no effect.`);
  8910. // implementation
  8911. function defineProps() {
  8912. {
  8913. warnRuntimeUsage(`defineProps`);
  8914. }
  8915. return null;
  8916. }
  8917. // implementation
  8918. function defineEmits() {
  8919. {
  8920. warnRuntimeUsage(`defineEmits`);
  8921. }
  8922. return null;
  8923. }
  8924. /**
  8925. * Vue `<script setup>` compiler macro for declaring a component's exposed
  8926. * instance properties when it is accessed by a parent component via template
  8927. * refs.
  8928. *
  8929. * `<script setup>` components are closed by default - i.e. variables inside
  8930. * the `<script setup>` scope is not exposed to parent unless explicitly exposed
  8931. * via `defineExpose`.
  8932. *
  8933. * This is only usable inside `<script setup>`, is compiled away in the
  8934. * output and should **not** be actually called at runtime.
  8935. */
  8936. function defineExpose(exposed) {
  8937. {
  8938. warnRuntimeUsage(`defineExpose`);
  8939. }
  8940. }
  8941. /**
  8942. * Vue `<script setup>` compiler macro for providing props default values when
  8943. * using type-based `defineProps` declaration.
  8944. *
  8945. * Example usage:
  8946. * ```ts
  8947. * withDefaults(defineProps<{
  8948. * size?: number
  8949. * labels?: string[]
  8950. * }>(), {
  8951. * size: 3,
  8952. * labels: () => ['default label']
  8953. * })
  8954. * ```
  8955. *
  8956. * This is only usable inside `<script setup>`, is compiled away in the output
  8957. * and should **not** be actually called at runtime.
  8958. */
  8959. function withDefaults(props, defaults) {
  8960. {
  8961. warnRuntimeUsage(`withDefaults`);
  8962. }
  8963. return null;
  8964. }
  8965. function useSlots() {
  8966. return getContext().slots;
  8967. }
  8968. function useAttrs() {
  8969. return getContext().attrs;
  8970. }
  8971. function getContext() {
  8972. const i = getCurrentInstance();
  8973. if (!i) {
  8974. warn$1(`useContext() called without active instance.`);
  8975. }
  8976. return i.setupContext || (i.setupContext = createSetupContext(i));
  8977. }
  8978. /**
  8979. * Runtime helper for merging default declarations. Imported by compiled code
  8980. * only.
  8981. * @internal
  8982. */
  8983. function mergeDefaults(raw, defaults) {
  8984. const props = isArray(raw)
  8985. ? raw.reduce((normalized, p) => ((normalized[p] = {}), normalized), {})
  8986. : raw;
  8987. for (const key in defaults) {
  8988. const opt = props[key];
  8989. if (opt) {
  8990. if (isArray(opt) || isFunction(opt)) {
  8991. props[key] = { type: opt, default: defaults[key] };
  8992. }
  8993. else {
  8994. opt.default = defaults[key];
  8995. }
  8996. }
  8997. else if (opt === null) {
  8998. props[key] = { default: defaults[key] };
  8999. }
  9000. else {
  9001. warn$1(`props default key "${key}" has no corresponding declaration.`);
  9002. }
  9003. }
  9004. return props;
  9005. }
  9006. /**
  9007. * Used to create a proxy for the rest element when destructuring props with
  9008. * defineProps().
  9009. * @internal
  9010. */
  9011. function createPropsRestProxy(props, excludedKeys) {
  9012. const ret = {};
  9013. for (const key in props) {
  9014. if (!excludedKeys.includes(key)) {
  9015. Object.defineProperty(ret, key, {
  9016. enumerable: true,
  9017. get: () => props[key]
  9018. });
  9019. }
  9020. }
  9021. return ret;
  9022. }
  9023. /**
  9024. * `<script setup>` helper for persisting the current instance context over
  9025. * async/await flows.
  9026. *
  9027. * `@vue/compiler-sfc` converts the following:
  9028. *
  9029. * ```ts
  9030. * const x = await foo()
  9031. * ```
  9032. *
  9033. * into:
  9034. *
  9035. * ```ts
  9036. * let __temp, __restore
  9037. * const x = (([__temp, __restore] = withAsyncContext(() => foo())),__temp=await __temp,__restore(),__temp)
  9038. * ```
  9039. * @internal
  9040. */
  9041. function withAsyncContext(getAwaitable) {
  9042. const ctx = getCurrentInstance();
  9043. if (!ctx) {
  9044. warn$1(`withAsyncContext called without active current instance. ` +
  9045. `This is likely a bug.`);
  9046. }
  9047. let awaitable = getAwaitable();
  9048. unsetCurrentInstance();
  9049. if (isPromise(awaitable)) {
  9050. awaitable = awaitable.catch(e => {
  9051. setCurrentInstance(ctx);
  9052. throw e;
  9053. });
  9054. }
  9055. return [awaitable, () => setCurrentInstance(ctx)];
  9056. }
  9057. // Actual implementation
  9058. function h(type, propsOrChildren, children) {
  9059. const l = arguments.length;
  9060. if (l === 2) {
  9061. if (isObject(propsOrChildren) && !isArray(propsOrChildren)) {
  9062. // single vnode without props
  9063. if (isVNode(propsOrChildren)) {
  9064. return createVNode(type, null, [propsOrChildren]);
  9065. }
  9066. // props without children
  9067. return createVNode(type, propsOrChildren);
  9068. }
  9069. else {
  9070. // omit props
  9071. return createVNode(type, null, propsOrChildren);
  9072. }
  9073. }
  9074. else {
  9075. if (l > 3) {
  9076. children = Array.prototype.slice.call(arguments, 2);
  9077. }
  9078. else if (l === 3 && isVNode(children)) {
  9079. children = [children];
  9080. }
  9081. return createVNode(type, propsOrChildren, children);
  9082. }
  9083. }
  9084. const ssrContextKey = Symbol(`ssrContext` );
  9085. const useSSRContext = () => {
  9086. {
  9087. warn$1(`useSSRContext() is not supported in the global build.`);
  9088. }
  9089. };
  9090. function initCustomFormatter() {
  9091. /* eslint-disable no-restricted-globals */
  9092. if (typeof window === 'undefined') {
  9093. return;
  9094. }
  9095. const vueStyle = { style: 'color:#3ba776' };
  9096. const numberStyle = { style: 'color:#0b1bc9' };
  9097. const stringStyle = { style: 'color:#b62e24' };
  9098. const keywordStyle = { style: 'color:#9d288c' };
  9099. // custom formatter for Chrome
  9100. // https://www.mattzeunert.com/2016/02/19/custom-chrome-devtools-object-formatters.html
  9101. const formatter = {
  9102. header(obj) {
  9103. // TODO also format ComponentPublicInstance & ctx.slots/attrs in setup
  9104. if (!isObject(obj)) {
  9105. return null;
  9106. }
  9107. if (obj.__isVue) {
  9108. return ['div', vueStyle, `VueInstance`];
  9109. }
  9110. else if (isRef(obj)) {
  9111. return [
  9112. 'div',
  9113. {},
  9114. ['span', vueStyle, genRefFlag(obj)],
  9115. '<',
  9116. formatValue(obj.value),
  9117. `>`
  9118. ];
  9119. }
  9120. else if (isReactive(obj)) {
  9121. return [
  9122. 'div',
  9123. {},
  9124. ['span', vueStyle, isShallow(obj) ? 'ShallowReactive' : 'Reactive'],
  9125. '<',
  9126. formatValue(obj),
  9127. `>${isReadonly(obj) ? ` (readonly)` : ``}`
  9128. ];
  9129. }
  9130. else if (isReadonly(obj)) {
  9131. return [
  9132. 'div',
  9133. {},
  9134. ['span', vueStyle, isShallow(obj) ? 'ShallowReadonly' : 'Readonly'],
  9135. '<',
  9136. formatValue(obj),
  9137. '>'
  9138. ];
  9139. }
  9140. return null;
  9141. },
  9142. hasBody(obj) {
  9143. return obj && obj.__isVue;
  9144. },
  9145. body(obj) {
  9146. if (obj && obj.__isVue) {
  9147. return [
  9148. 'div',
  9149. {},
  9150. ...formatInstance(obj.$)
  9151. ];
  9152. }
  9153. }
  9154. };
  9155. function formatInstance(instance) {
  9156. const blocks = [];
  9157. if (instance.type.props && instance.props) {
  9158. blocks.push(createInstanceBlock('props', toRaw(instance.props)));
  9159. }
  9160. if (instance.setupState !== EMPTY_OBJ) {
  9161. blocks.push(createInstanceBlock('setup', instance.setupState));
  9162. }
  9163. if (instance.data !== EMPTY_OBJ) {
  9164. blocks.push(createInstanceBlock('data', toRaw(instance.data)));
  9165. }
  9166. const computed = extractKeys(instance, 'computed');
  9167. if (computed) {
  9168. blocks.push(createInstanceBlock('computed', computed));
  9169. }
  9170. const injected = extractKeys(instance, 'inject');
  9171. if (injected) {
  9172. blocks.push(createInstanceBlock('injected', injected));
  9173. }
  9174. blocks.push([
  9175. 'div',
  9176. {},
  9177. [
  9178. 'span',
  9179. {
  9180. style: keywordStyle.style + ';opacity:0.66'
  9181. },
  9182. '$ (internal): '
  9183. ],
  9184. ['object', { object: instance }]
  9185. ]);
  9186. return blocks;
  9187. }
  9188. function createInstanceBlock(type, target) {
  9189. target = extend({}, target);
  9190. if (!Object.keys(target).length) {
  9191. return ['span', {}];
  9192. }
  9193. return [
  9194. 'div',
  9195. { style: 'line-height:1.25em;margin-bottom:0.6em' },
  9196. [
  9197. 'div',
  9198. {
  9199. style: 'color:#476582'
  9200. },
  9201. type
  9202. ],
  9203. [
  9204. 'div',
  9205. {
  9206. style: 'padding-left:1.25em'
  9207. },
  9208. ...Object.keys(target).map(key => {
  9209. return [
  9210. 'div',
  9211. {},
  9212. ['span', keywordStyle, key + ': '],
  9213. formatValue(target[key], false)
  9214. ];
  9215. })
  9216. ]
  9217. ];
  9218. }
  9219. function formatValue(v, asRaw = true) {
  9220. if (typeof v === 'number') {
  9221. return ['span', numberStyle, v];
  9222. }
  9223. else if (typeof v === 'string') {
  9224. return ['span', stringStyle, JSON.stringify(v)];
  9225. }
  9226. else if (typeof v === 'boolean') {
  9227. return ['span', keywordStyle, v];
  9228. }
  9229. else if (isObject(v)) {
  9230. return ['object', { object: asRaw ? toRaw(v) : v }];
  9231. }
  9232. else {
  9233. return ['span', stringStyle, String(v)];
  9234. }
  9235. }
  9236. function extractKeys(instance, type) {
  9237. const Comp = instance.type;
  9238. if (isFunction(Comp)) {
  9239. return;
  9240. }
  9241. const extracted = {};
  9242. for (const key in instance.ctx) {
  9243. if (isKeyOfType(Comp, key, type)) {
  9244. extracted[key] = instance.ctx[key];
  9245. }
  9246. }
  9247. return extracted;
  9248. }
  9249. function isKeyOfType(Comp, key, type) {
  9250. const opts = Comp[type];
  9251. if ((isArray(opts) && opts.includes(key)) ||
  9252. (isObject(opts) && key in opts)) {
  9253. return true;
  9254. }
  9255. if (Comp.extends && isKeyOfType(Comp.extends, key, type)) {
  9256. return true;
  9257. }
  9258. if (Comp.mixins && Comp.mixins.some(m => isKeyOfType(m, key, type))) {
  9259. return true;
  9260. }
  9261. }
  9262. function genRefFlag(v) {
  9263. if (isShallow(v)) {
  9264. return `ShallowRef`;
  9265. }
  9266. if (v.effect) {
  9267. return `ComputedRef`;
  9268. }
  9269. return `Ref`;
  9270. }
  9271. if (window.devtoolsFormatters) {
  9272. window.devtoolsFormatters.push(formatter);
  9273. }
  9274. else {
  9275. window.devtoolsFormatters = [formatter];
  9276. }
  9277. }
  9278. function withMemo(memo, render, cache, index) {
  9279. const cached = cache[index];
  9280. if (cached && isMemoSame(cached, memo)) {
  9281. return cached;
  9282. }
  9283. const ret = render();
  9284. // shallow clone
  9285. ret.memo = memo.slice();
  9286. return (cache[index] = ret);
  9287. }
  9288. function isMemoSame(cached, memo) {
  9289. const prev = cached.memo;
  9290. if (prev.length != memo.length) {
  9291. return false;
  9292. }
  9293. for (let i = 0; i < prev.length; i++) {
  9294. if (hasChanged(prev[i], memo[i])) {
  9295. return false;
  9296. }
  9297. }
  9298. // make sure to let parent block track it when returning cached
  9299. if (isBlockTreeEnabled > 0 && currentBlock) {
  9300. currentBlock.push(cached);
  9301. }
  9302. return true;
  9303. }
  9304. // Core API ------------------------------------------------------------------
  9305. const version = "3.2.45";
  9306. /**
  9307. * SSR utils for \@vue/server-renderer. Only exposed in ssr-possible builds.
  9308. * @internal
  9309. */
  9310. const ssrUtils = (null);
  9311. /**
  9312. * @internal only exposed in compat builds
  9313. */
  9314. const resolveFilter = null;
  9315. /**
  9316. * @internal only exposed in compat builds.
  9317. */
  9318. const compatUtils = (null);
  9319. const svgNS = 'http://www.w3.org/2000/svg';
  9320. const doc = (typeof document !== 'undefined' ? document : null);
  9321. const templateContainer = doc && /*#__PURE__*/ doc.createElement('template');
  9322. const nodeOps = {
  9323. insert: (child, parent, anchor) => {
  9324. parent.insertBefore(child, anchor || null);
  9325. },
  9326. remove: child => {
  9327. const parent = child.parentNode;
  9328. if (parent) {
  9329. parent.removeChild(child);
  9330. }
  9331. },
  9332. createElement: (tag, isSVG, is, props) => {
  9333. const el = isSVG
  9334. ? doc.createElementNS(svgNS, tag)
  9335. : doc.createElement(tag, is ? { is } : undefined);
  9336. if (tag === 'select' && props && props.multiple != null) {
  9337. el.setAttribute('multiple', props.multiple);
  9338. }
  9339. return el;
  9340. },
  9341. createText: text => doc.createTextNode(text),
  9342. createComment: text => doc.createComment(text),
  9343. setText: (node, text) => {
  9344. node.nodeValue = text;
  9345. },
  9346. setElementText: (el, text) => {
  9347. el.textContent = text;
  9348. },
  9349. parentNode: node => node.parentNode,
  9350. nextSibling: node => node.nextSibling,
  9351. querySelector: selector => doc.querySelector(selector),
  9352. setScopeId(el, id) {
  9353. el.setAttribute(id, '');
  9354. },
  9355. // __UNSAFE__
  9356. // Reason: innerHTML.
  9357. // Static content here can only come from compiled templates.
  9358. // As long as the user only uses trusted templates, this is safe.
  9359. insertStaticContent(content, parent, anchor, isSVG, start, end) {
  9360. // <parent> before | first ... last | anchor </parent>
  9361. const before = anchor ? anchor.previousSibling : parent.lastChild;
  9362. // #5308 can only take cached path if:
  9363. // - has a single root node
  9364. // - nextSibling info is still available
  9365. if (start && (start === end || start.nextSibling)) {
  9366. // cached
  9367. while (true) {
  9368. parent.insertBefore(start.cloneNode(true), anchor);
  9369. if (start === end || !(start = start.nextSibling))
  9370. break;
  9371. }
  9372. }
  9373. else {
  9374. // fresh insert
  9375. templateContainer.innerHTML = isSVG ? `<svg>${content}</svg>` : content;
  9376. const template = templateContainer.content;
  9377. if (isSVG) {
  9378. // remove outer svg wrapper
  9379. const wrapper = template.firstChild;
  9380. while (wrapper.firstChild) {
  9381. template.appendChild(wrapper.firstChild);
  9382. }
  9383. template.removeChild(wrapper);
  9384. }
  9385. parent.insertBefore(template, anchor);
  9386. }
  9387. return [
  9388. // first
  9389. before ? before.nextSibling : parent.firstChild,
  9390. // last
  9391. anchor ? anchor.previousSibling : parent.lastChild
  9392. ];
  9393. }
  9394. };
  9395. // compiler should normalize class + :class bindings on the same element
  9396. // into a single binding ['staticClass', dynamic]
  9397. function patchClass(el, value, isSVG) {
  9398. // directly setting className should be faster than setAttribute in theory
  9399. // if this is an element during a transition, take the temporary transition
  9400. // classes into account.
  9401. const transitionClasses = el._vtc;
  9402. if (transitionClasses) {
  9403. value = (value ? [value, ...transitionClasses] : [...transitionClasses]).join(' ');
  9404. }
  9405. if (value == null) {
  9406. el.removeAttribute('class');
  9407. }
  9408. else if (isSVG) {
  9409. el.setAttribute('class', value);
  9410. }
  9411. else {
  9412. el.className = value;
  9413. }
  9414. }
  9415. function patchStyle(el, prev, next) {
  9416. const style = el.style;
  9417. const isCssString = isString(next);
  9418. if (next && !isCssString) {
  9419. for (const key in next) {
  9420. setStyle(style, key, next[key]);
  9421. }
  9422. if (prev && !isString(prev)) {
  9423. for (const key in prev) {
  9424. if (next[key] == null) {
  9425. setStyle(style, key, '');
  9426. }
  9427. }
  9428. }
  9429. }
  9430. else {
  9431. const currentDisplay = style.display;
  9432. if (isCssString) {
  9433. if (prev !== next) {
  9434. style.cssText = next;
  9435. }
  9436. }
  9437. else if (prev) {
  9438. el.removeAttribute('style');
  9439. }
  9440. // indicates that the `display` of the element is controlled by `v-show`,
  9441. // so we always keep the current `display` value regardless of the `style`
  9442. // value, thus handing over control to `v-show`.
  9443. if ('_vod' in el) {
  9444. style.display = currentDisplay;
  9445. }
  9446. }
  9447. }
  9448. const semicolonRE = /[^\\];\s*$/;
  9449. const importantRE = /\s*!important$/;
  9450. function setStyle(style, name, val) {
  9451. if (isArray(val)) {
  9452. val.forEach(v => setStyle(style, name, v));
  9453. }
  9454. else {
  9455. if (val == null)
  9456. val = '';
  9457. {
  9458. if (semicolonRE.test(val)) {
  9459. warn$1(`Unexpected semicolon at the end of '${name}' style value: '${val}'`);
  9460. }
  9461. }
  9462. if (name.startsWith('--')) {
  9463. // custom property definition
  9464. style.setProperty(name, val);
  9465. }
  9466. else {
  9467. const prefixed = autoPrefix(style, name);
  9468. if (importantRE.test(val)) {
  9469. // !important
  9470. style.setProperty(hyphenate(prefixed), val.replace(importantRE, ''), 'important');
  9471. }
  9472. else {
  9473. style[prefixed] = val;
  9474. }
  9475. }
  9476. }
  9477. }
  9478. const prefixes = ['Webkit', 'Moz', 'ms'];
  9479. const prefixCache = {};
  9480. function autoPrefix(style, rawName) {
  9481. const cached = prefixCache[rawName];
  9482. if (cached) {
  9483. return cached;
  9484. }
  9485. let name = camelize(rawName);
  9486. if (name !== 'filter' && name in style) {
  9487. return (prefixCache[rawName] = name);
  9488. }
  9489. name = capitalize(name);
  9490. for (let i = 0; i < prefixes.length; i++) {
  9491. const prefixed = prefixes[i] + name;
  9492. if (prefixed in style) {
  9493. return (prefixCache[rawName] = prefixed);
  9494. }
  9495. }
  9496. return rawName;
  9497. }
  9498. const xlinkNS = 'http://www.w3.org/1999/xlink';
  9499. function patchAttr(el, key, value, isSVG, instance) {
  9500. if (isSVG && key.startsWith('xlink:')) {
  9501. if (value == null) {
  9502. el.removeAttributeNS(xlinkNS, key.slice(6, key.length));
  9503. }
  9504. else {
  9505. el.setAttributeNS(xlinkNS, key, value);
  9506. }
  9507. }
  9508. else {
  9509. // note we are only checking boolean attributes that don't have a
  9510. // corresponding dom prop of the same name here.
  9511. const isBoolean = isSpecialBooleanAttr(key);
  9512. if (value == null || (isBoolean && !includeBooleanAttr(value))) {
  9513. el.removeAttribute(key);
  9514. }
  9515. else {
  9516. el.setAttribute(key, isBoolean ? '' : value);
  9517. }
  9518. }
  9519. }
  9520. // __UNSAFE__
  9521. // functions. The user is responsible for using them with only trusted content.
  9522. function patchDOMProp(el, key, value,
  9523. // the following args are passed only due to potential innerHTML/textContent
  9524. // overriding existing VNodes, in which case the old tree must be properly
  9525. // unmounted.
  9526. prevChildren, parentComponent, parentSuspense, unmountChildren) {
  9527. if (key === 'innerHTML' || key === 'textContent') {
  9528. if (prevChildren) {
  9529. unmountChildren(prevChildren, parentComponent, parentSuspense);
  9530. }
  9531. el[key] = value == null ? '' : value;
  9532. return;
  9533. }
  9534. if (key === 'value' &&
  9535. el.tagName !== 'PROGRESS' &&
  9536. // custom elements may use _value internally
  9537. !el.tagName.includes('-')) {
  9538. // store value as _value as well since
  9539. // non-string values will be stringified.
  9540. el._value = value;
  9541. const newValue = value == null ? '' : value;
  9542. if (el.value !== newValue ||
  9543. // #4956: always set for OPTION elements because its value falls back to
  9544. // textContent if no value attribute is present. And setting .value for
  9545. // OPTION has no side effect
  9546. el.tagName === 'OPTION') {
  9547. el.value = newValue;
  9548. }
  9549. if (value == null) {
  9550. el.removeAttribute(key);
  9551. }
  9552. return;
  9553. }
  9554. let needRemove = false;
  9555. if (value === '' || value == null) {
  9556. const type = typeof el[key];
  9557. if (type === 'boolean') {
  9558. // e.g. <select multiple> compiles to { multiple: '' }
  9559. value = includeBooleanAttr(value);
  9560. }
  9561. else if (value == null && type === 'string') {
  9562. // e.g. <div :id="null">
  9563. value = '';
  9564. needRemove = true;
  9565. }
  9566. else if (type === 'number') {
  9567. // e.g. <img :width="null">
  9568. value = 0;
  9569. needRemove = true;
  9570. }
  9571. }
  9572. // some properties perform value validation and throw,
  9573. // some properties has getter, no setter, will error in 'use strict'
  9574. // eg. <select :type="null"></select> <select :willValidate="null"></select>
  9575. try {
  9576. el[key] = value;
  9577. }
  9578. catch (e) {
  9579. // do not warn if value is auto-coerced from nullish values
  9580. if (!needRemove) {
  9581. warn$1(`Failed setting prop "${key}" on <${el.tagName.toLowerCase()}>: ` +
  9582. `value ${value} is invalid.`, e);
  9583. }
  9584. }
  9585. needRemove && el.removeAttribute(key);
  9586. }
  9587. function addEventListener(el, event, handler, options) {
  9588. el.addEventListener(event, handler, options);
  9589. }
  9590. function removeEventListener(el, event, handler, options) {
  9591. el.removeEventListener(event, handler, options);
  9592. }
  9593. function patchEvent(el, rawName, prevValue, nextValue, instance = null) {
  9594. // vei = vue event invokers
  9595. const invokers = el._vei || (el._vei = {});
  9596. const existingInvoker = invokers[rawName];
  9597. if (nextValue && existingInvoker) {
  9598. // patch
  9599. existingInvoker.value = nextValue;
  9600. }
  9601. else {
  9602. const [name, options] = parseName(rawName);
  9603. if (nextValue) {
  9604. // add
  9605. const invoker = (invokers[rawName] = createInvoker(nextValue, instance));
  9606. addEventListener(el, name, invoker, options);
  9607. }
  9608. else if (existingInvoker) {
  9609. // remove
  9610. removeEventListener(el, name, existingInvoker, options);
  9611. invokers[rawName] = undefined;
  9612. }
  9613. }
  9614. }
  9615. const optionsModifierRE = /(?:Once|Passive|Capture)$/;
  9616. function parseName(name) {
  9617. let options;
  9618. if (optionsModifierRE.test(name)) {
  9619. options = {};
  9620. let m;
  9621. while ((m = name.match(optionsModifierRE))) {
  9622. name = name.slice(0, name.length - m[0].length);
  9623. options[m[0].toLowerCase()] = true;
  9624. }
  9625. }
  9626. const event = name[2] === ':' ? name.slice(3) : hyphenate(name.slice(2));
  9627. return [event, options];
  9628. }
  9629. // To avoid the overhead of repeatedly calling Date.now(), we cache
  9630. // and use the same timestamp for all event listeners attached in the same tick.
  9631. let cachedNow = 0;
  9632. const p = /*#__PURE__*/ Promise.resolve();
  9633. const getNow = () => cachedNow || (p.then(() => (cachedNow = 0)), (cachedNow = Date.now()));
  9634. function createInvoker(initialValue, instance) {
  9635. const invoker = (e) => {
  9636. // async edge case vuejs/vue#6566
  9637. // inner click event triggers patch, event handler
  9638. // attached to outer element during patch, and triggered again. This
  9639. // happens because browsers fire microtask ticks between event propagation.
  9640. // this no longer happens for templates in Vue 3, but could still be
  9641. // theoretically possible for hand-written render functions.
  9642. // the solution: we save the timestamp when a handler is attached,
  9643. // and also attach the timestamp to any event that was handled by vue
  9644. // for the first time (to avoid inconsistent event timestamp implementations
  9645. // or events fired from iframes, e.g. #2513)
  9646. // The handler would only fire if the event passed to it was fired
  9647. // AFTER it was attached.
  9648. if (!e._vts) {
  9649. e._vts = Date.now();
  9650. }
  9651. else if (e._vts <= invoker.attached) {
  9652. return;
  9653. }
  9654. callWithAsyncErrorHandling(patchStopImmediatePropagation(e, invoker.value), instance, 5 /* ErrorCodes.NATIVE_EVENT_HANDLER */, [e]);
  9655. };
  9656. invoker.value = initialValue;
  9657. invoker.attached = getNow();
  9658. return invoker;
  9659. }
  9660. function patchStopImmediatePropagation(e, value) {
  9661. if (isArray(value)) {
  9662. const originalStop = e.stopImmediatePropagation;
  9663. e.stopImmediatePropagation = () => {
  9664. originalStop.call(e);
  9665. e._stopped = true;
  9666. };
  9667. return value.map(fn => (e) => !e._stopped && fn && fn(e));
  9668. }
  9669. else {
  9670. return value;
  9671. }
  9672. }
  9673. const nativeOnRE = /^on[a-z]/;
  9674. const patchProp = (el, key, prevValue, nextValue, isSVG = false, prevChildren, parentComponent, parentSuspense, unmountChildren) => {
  9675. if (key === 'class') {
  9676. patchClass(el, nextValue, isSVG);
  9677. }
  9678. else if (key === 'style') {
  9679. patchStyle(el, prevValue, nextValue);
  9680. }
  9681. else if (isOn(key)) {
  9682. // ignore v-model listeners
  9683. if (!isModelListener(key)) {
  9684. patchEvent(el, key, prevValue, nextValue, parentComponent);
  9685. }
  9686. }
  9687. else if (key[0] === '.'
  9688. ? ((key = key.slice(1)), true)
  9689. : key[0] === '^'
  9690. ? ((key = key.slice(1)), false)
  9691. : shouldSetAsProp(el, key, nextValue, isSVG)) {
  9692. patchDOMProp(el, key, nextValue, prevChildren, parentComponent, parentSuspense, unmountChildren);
  9693. }
  9694. else {
  9695. // special case for <input v-model type="checkbox"> with
  9696. // :true-value & :false-value
  9697. // store value as dom properties since non-string values will be
  9698. // stringified.
  9699. if (key === 'true-value') {
  9700. el._trueValue = nextValue;
  9701. }
  9702. else if (key === 'false-value') {
  9703. el._falseValue = nextValue;
  9704. }
  9705. patchAttr(el, key, nextValue, isSVG);
  9706. }
  9707. };
  9708. function shouldSetAsProp(el, key, value, isSVG) {
  9709. if (isSVG) {
  9710. // most keys must be set as attribute on svg elements to work
  9711. // ...except innerHTML & textContent
  9712. if (key === 'innerHTML' || key === 'textContent') {
  9713. return true;
  9714. }
  9715. // or native onclick with function values
  9716. if (key in el && nativeOnRE.test(key) && isFunction(value)) {
  9717. return true;
  9718. }
  9719. return false;
  9720. }
  9721. // these are enumerated attrs, however their corresponding DOM properties
  9722. // are actually booleans - this leads to setting it with a string "false"
  9723. // value leading it to be coerced to `true`, so we need to always treat
  9724. // them as attributes.
  9725. // Note that `contentEditable` doesn't have this problem: its DOM
  9726. // property is also enumerated string values.
  9727. if (key === 'spellcheck' || key === 'draggable' || key === 'translate') {
  9728. return false;
  9729. }
  9730. // #1787, #2840 form property on form elements is readonly and must be set as
  9731. // attribute.
  9732. if (key === 'form') {
  9733. return false;
  9734. }
  9735. // #1526 <input list> must be set as attribute
  9736. if (key === 'list' && el.tagName === 'INPUT') {
  9737. return false;
  9738. }
  9739. // #2766 <textarea type> must be set as attribute
  9740. if (key === 'type' && el.tagName === 'TEXTAREA') {
  9741. return false;
  9742. }
  9743. // native onclick with string value, must be set as attribute
  9744. if (nativeOnRE.test(key) && isString(value)) {
  9745. return false;
  9746. }
  9747. return key in el;
  9748. }
  9749. function defineCustomElement(options, hydrate) {
  9750. const Comp = defineComponent(options);
  9751. class VueCustomElement extends VueElement {
  9752. constructor(initialProps) {
  9753. super(Comp, initialProps, hydrate);
  9754. }
  9755. }
  9756. VueCustomElement.def = Comp;
  9757. return VueCustomElement;
  9758. }
  9759. const defineSSRCustomElement = ((options) => {
  9760. // @ts-ignore
  9761. return defineCustomElement(options, hydrate);
  9762. });
  9763. const BaseClass = (typeof HTMLElement !== 'undefined' ? HTMLElement : class {
  9764. });
  9765. class VueElement extends BaseClass {
  9766. constructor(_def, _props = {}, hydrate) {
  9767. super();
  9768. this._def = _def;
  9769. this._props = _props;
  9770. /**
  9771. * @internal
  9772. */
  9773. this._instance = null;
  9774. this._connected = false;
  9775. this._resolved = false;
  9776. this._numberProps = null;
  9777. if (this.shadowRoot && hydrate) {
  9778. hydrate(this._createVNode(), this.shadowRoot);
  9779. }
  9780. else {
  9781. if (this.shadowRoot) {
  9782. warn$1(`Custom element has pre-rendered declarative shadow root but is not ` +
  9783. `defined as hydratable. Use \`defineSSRCustomElement\`.`);
  9784. }
  9785. this.attachShadow({ mode: 'open' });
  9786. if (!this._def.__asyncLoader) {
  9787. // for sync component defs we can immediately resolve props
  9788. this._resolveProps(this._def);
  9789. }
  9790. }
  9791. }
  9792. connectedCallback() {
  9793. this._connected = true;
  9794. if (!this._instance) {
  9795. if (this._resolved) {
  9796. this._update();
  9797. }
  9798. else {
  9799. this._resolveDef();
  9800. }
  9801. }
  9802. }
  9803. disconnectedCallback() {
  9804. this._connected = false;
  9805. nextTick(() => {
  9806. if (!this._connected) {
  9807. render(null, this.shadowRoot);
  9808. this._instance = null;
  9809. }
  9810. });
  9811. }
  9812. /**
  9813. * resolve inner component definition (handle possible async component)
  9814. */
  9815. _resolveDef() {
  9816. this._resolved = true;
  9817. // set initial attrs
  9818. for (let i = 0; i < this.attributes.length; i++) {
  9819. this._setAttr(this.attributes[i].name);
  9820. }
  9821. // watch future attr changes
  9822. new MutationObserver(mutations => {
  9823. for (const m of mutations) {
  9824. this._setAttr(m.attributeName);
  9825. }
  9826. }).observe(this, { attributes: true });
  9827. const resolve = (def, isAsync = false) => {
  9828. const { props, styles } = def;
  9829. // cast Number-type props set before resolve
  9830. let numberProps;
  9831. if (props && !isArray(props)) {
  9832. for (const key in props) {
  9833. const opt = props[key];
  9834. if (opt === Number || (opt && opt.type === Number)) {
  9835. if (key in this._props) {
  9836. this._props[key] = toNumber(this._props[key]);
  9837. }
  9838. (numberProps || (numberProps = Object.create(null)))[camelize(key)] = true;
  9839. }
  9840. }
  9841. }
  9842. this._numberProps = numberProps;
  9843. if (isAsync) {
  9844. // defining getter/setters on prototype
  9845. // for sync defs, this already happened in the constructor
  9846. this._resolveProps(def);
  9847. }
  9848. // apply CSS
  9849. this._applyStyles(styles);
  9850. // initial render
  9851. this._update();
  9852. };
  9853. const asyncDef = this._def.__asyncLoader;
  9854. if (asyncDef) {
  9855. asyncDef().then(def => resolve(def, true));
  9856. }
  9857. else {
  9858. resolve(this._def);
  9859. }
  9860. }
  9861. _resolveProps(def) {
  9862. const { props } = def;
  9863. const declaredPropKeys = isArray(props) ? props : Object.keys(props || {});
  9864. // check if there are props set pre-upgrade or connect
  9865. for (const key of Object.keys(this)) {
  9866. if (key[0] !== '_' && declaredPropKeys.includes(key)) {
  9867. this._setProp(key, this[key], true, false);
  9868. }
  9869. }
  9870. // defining getter/setters on prototype
  9871. for (const key of declaredPropKeys.map(camelize)) {
  9872. Object.defineProperty(this, key, {
  9873. get() {
  9874. return this._getProp(key);
  9875. },
  9876. set(val) {
  9877. this._setProp(key, val);
  9878. }
  9879. });
  9880. }
  9881. }
  9882. _setAttr(key) {
  9883. let value = this.getAttribute(key);
  9884. const camelKey = camelize(key);
  9885. if (this._numberProps && this._numberProps[camelKey]) {
  9886. value = toNumber(value);
  9887. }
  9888. this._setProp(camelKey, value, false);
  9889. }
  9890. /**
  9891. * @internal
  9892. */
  9893. _getProp(key) {
  9894. return this._props[key];
  9895. }
  9896. /**
  9897. * @internal
  9898. */
  9899. _setProp(key, val, shouldReflect = true, shouldUpdate = true) {
  9900. if (val !== this._props[key]) {
  9901. this._props[key] = val;
  9902. if (shouldUpdate && this._instance) {
  9903. this._update();
  9904. }
  9905. // reflect
  9906. if (shouldReflect) {
  9907. if (val === true) {
  9908. this.setAttribute(hyphenate(key), '');
  9909. }
  9910. else if (typeof val === 'string' || typeof val === 'number') {
  9911. this.setAttribute(hyphenate(key), val + '');
  9912. }
  9913. else if (!val) {
  9914. this.removeAttribute(hyphenate(key));
  9915. }
  9916. }
  9917. }
  9918. }
  9919. _update() {
  9920. render(this._createVNode(), this.shadowRoot);
  9921. }
  9922. _createVNode() {
  9923. const vnode = createVNode(this._def, extend({}, this._props));
  9924. if (!this._instance) {
  9925. vnode.ce = instance => {
  9926. this._instance = instance;
  9927. instance.isCE = true;
  9928. // HMR
  9929. {
  9930. instance.ceReload = newStyles => {
  9931. // always reset styles
  9932. if (this._styles) {
  9933. this._styles.forEach(s => this.shadowRoot.removeChild(s));
  9934. this._styles.length = 0;
  9935. }
  9936. this._applyStyles(newStyles);
  9937. this._instance = null;
  9938. this._update();
  9939. };
  9940. }
  9941. const dispatch = (event, args) => {
  9942. this.dispatchEvent(new CustomEvent(event, {
  9943. detail: args
  9944. }));
  9945. };
  9946. // intercept emit
  9947. instance.emit = (event, ...args) => {
  9948. // dispatch both the raw and hyphenated versions of an event
  9949. // to match Vue behavior
  9950. dispatch(event, args);
  9951. if (hyphenate(event) !== event) {
  9952. dispatch(hyphenate(event), args);
  9953. }
  9954. };
  9955. // locate nearest Vue custom element parent for provide/inject
  9956. let parent = this;
  9957. while ((parent =
  9958. parent && (parent.parentNode || parent.host))) {
  9959. if (parent instanceof VueElement) {
  9960. instance.parent = parent._instance;
  9961. instance.provides = parent._instance.provides;
  9962. break;
  9963. }
  9964. }
  9965. };
  9966. }
  9967. return vnode;
  9968. }
  9969. _applyStyles(styles) {
  9970. if (styles) {
  9971. styles.forEach(css => {
  9972. const s = document.createElement('style');
  9973. s.textContent = css;
  9974. this.shadowRoot.appendChild(s);
  9975. // record for HMR
  9976. {
  9977. (this._styles || (this._styles = [])).push(s);
  9978. }
  9979. });
  9980. }
  9981. }
  9982. }
  9983. function useCssModule(name = '$style') {
  9984. /* istanbul ignore else */
  9985. {
  9986. {
  9987. warn$1(`useCssModule() is not supported in the global build.`);
  9988. }
  9989. return EMPTY_OBJ;
  9990. }
  9991. }
  9992. /**
  9993. * Runtime helper for SFC's CSS variable injection feature.
  9994. * @private
  9995. */
  9996. function useCssVars(getter) {
  9997. const instance = getCurrentInstance();
  9998. /* istanbul ignore next */
  9999. if (!instance) {
  10000. warn$1(`useCssVars is called without current active component instance.`);
  10001. return;
  10002. }
  10003. const updateTeleports = (instance.ut = (vars = getter(instance.proxy)) => {
  10004. Array.from(document.querySelectorAll(`[data-v-owner="${instance.uid}"]`)).forEach(node => setVarsOnNode(node, vars));
  10005. });
  10006. const setVars = () => {
  10007. const vars = getter(instance.proxy);
  10008. setVarsOnVNode(instance.subTree, vars);
  10009. updateTeleports(vars);
  10010. };
  10011. watchPostEffect(setVars);
  10012. onMounted(() => {
  10013. const ob = new MutationObserver(setVars);
  10014. ob.observe(instance.subTree.el.parentNode, { childList: true });
  10015. onUnmounted(() => ob.disconnect());
  10016. });
  10017. }
  10018. function setVarsOnVNode(vnode, vars) {
  10019. if (vnode.shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
  10020. const suspense = vnode.suspense;
  10021. vnode = suspense.activeBranch;
  10022. if (suspense.pendingBranch && !suspense.isHydrating) {
  10023. suspense.effects.push(() => {
  10024. setVarsOnVNode(suspense.activeBranch, vars);
  10025. });
  10026. }
  10027. }
  10028. // drill down HOCs until it's a non-component vnode
  10029. while (vnode.component) {
  10030. vnode = vnode.component.subTree;
  10031. }
  10032. if (vnode.shapeFlag & 1 /* ShapeFlags.ELEMENT */ && vnode.el) {
  10033. setVarsOnNode(vnode.el, vars);
  10034. }
  10035. else if (vnode.type === Fragment) {
  10036. vnode.children.forEach(c => setVarsOnVNode(c, vars));
  10037. }
  10038. else if (vnode.type === Static) {
  10039. let { el, anchor } = vnode;
  10040. while (el) {
  10041. setVarsOnNode(el, vars);
  10042. if (el === anchor)
  10043. break;
  10044. el = el.nextSibling;
  10045. }
  10046. }
  10047. }
  10048. function setVarsOnNode(el, vars) {
  10049. if (el.nodeType === 1) {
  10050. const style = el.style;
  10051. for (const key in vars) {
  10052. style.setProperty(`--${key}`, vars[key]);
  10053. }
  10054. }
  10055. }
  10056. const TRANSITION = 'transition';
  10057. const ANIMATION = 'animation';
  10058. // DOM Transition is a higher-order-component based on the platform-agnostic
  10059. // base Transition component, with DOM-specific logic.
  10060. const Transition = (props, { slots }) => h(BaseTransition, resolveTransitionProps(props), slots);
  10061. Transition.displayName = 'Transition';
  10062. const DOMTransitionPropsValidators = {
  10063. name: String,
  10064. type: String,
  10065. css: {
  10066. type: Boolean,
  10067. default: true
  10068. },
  10069. duration: [String, Number, Object],
  10070. enterFromClass: String,
  10071. enterActiveClass: String,
  10072. enterToClass: String,
  10073. appearFromClass: String,
  10074. appearActiveClass: String,
  10075. appearToClass: String,
  10076. leaveFromClass: String,
  10077. leaveActiveClass: String,
  10078. leaveToClass: String
  10079. };
  10080. const TransitionPropsValidators = (Transition.props =
  10081. /*#__PURE__*/ extend({}, BaseTransition.props, DOMTransitionPropsValidators));
  10082. /**
  10083. * #3227 Incoming hooks may be merged into arrays when wrapping Transition
  10084. * with custom HOCs.
  10085. */
  10086. const callHook$1 = (hook, args = []) => {
  10087. if (isArray(hook)) {
  10088. hook.forEach(h => h(...args));
  10089. }
  10090. else if (hook) {
  10091. hook(...args);
  10092. }
  10093. };
  10094. /**
  10095. * Check if a hook expects a callback (2nd arg), which means the user
  10096. * intends to explicitly control the end of the transition.
  10097. */
  10098. const hasExplicitCallback = (hook) => {
  10099. return hook
  10100. ? isArray(hook)
  10101. ? hook.some(h => h.length > 1)
  10102. : hook.length > 1
  10103. : false;
  10104. };
  10105. function resolveTransitionProps(rawProps) {
  10106. const baseProps = {};
  10107. for (const key in rawProps) {
  10108. if (!(key in DOMTransitionPropsValidators)) {
  10109. baseProps[key] = rawProps[key];
  10110. }
  10111. }
  10112. if (rawProps.css === false) {
  10113. return baseProps;
  10114. }
  10115. 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;
  10116. const durations = normalizeDuration(duration);
  10117. const enterDuration = durations && durations[0];
  10118. const leaveDuration = durations && durations[1];
  10119. const { onBeforeEnter, onEnter, onEnterCancelled, onLeave, onLeaveCancelled, onBeforeAppear = onBeforeEnter, onAppear = onEnter, onAppearCancelled = onEnterCancelled } = baseProps;
  10120. const finishEnter = (el, isAppear, done) => {
  10121. removeTransitionClass(el, isAppear ? appearToClass : enterToClass);
  10122. removeTransitionClass(el, isAppear ? appearActiveClass : enterActiveClass);
  10123. done && done();
  10124. };
  10125. const finishLeave = (el, done) => {
  10126. el._isLeaving = false;
  10127. removeTransitionClass(el, leaveFromClass);
  10128. removeTransitionClass(el, leaveToClass);
  10129. removeTransitionClass(el, leaveActiveClass);
  10130. done && done();
  10131. };
  10132. const makeEnterHook = (isAppear) => {
  10133. return (el, done) => {
  10134. const hook = isAppear ? onAppear : onEnter;
  10135. const resolve = () => finishEnter(el, isAppear, done);
  10136. callHook$1(hook, [el, resolve]);
  10137. nextFrame(() => {
  10138. removeTransitionClass(el, isAppear ? appearFromClass : enterFromClass);
  10139. addTransitionClass(el, isAppear ? appearToClass : enterToClass);
  10140. if (!hasExplicitCallback(hook)) {
  10141. whenTransitionEnds(el, type, enterDuration, resolve);
  10142. }
  10143. });
  10144. };
  10145. };
  10146. return extend(baseProps, {
  10147. onBeforeEnter(el) {
  10148. callHook$1(onBeforeEnter, [el]);
  10149. addTransitionClass(el, enterFromClass);
  10150. addTransitionClass(el, enterActiveClass);
  10151. },
  10152. onBeforeAppear(el) {
  10153. callHook$1(onBeforeAppear, [el]);
  10154. addTransitionClass(el, appearFromClass);
  10155. addTransitionClass(el, appearActiveClass);
  10156. },
  10157. onEnter: makeEnterHook(false),
  10158. onAppear: makeEnterHook(true),
  10159. onLeave(el, done) {
  10160. el._isLeaving = true;
  10161. const resolve = () => finishLeave(el, done);
  10162. addTransitionClass(el, leaveFromClass);
  10163. // force reflow so *-leave-from classes immediately take effect (#2593)
  10164. forceReflow();
  10165. addTransitionClass(el, leaveActiveClass);
  10166. nextFrame(() => {
  10167. if (!el._isLeaving) {
  10168. // cancelled
  10169. return;
  10170. }
  10171. removeTransitionClass(el, leaveFromClass);
  10172. addTransitionClass(el, leaveToClass);
  10173. if (!hasExplicitCallback(onLeave)) {
  10174. whenTransitionEnds(el, type, leaveDuration, resolve);
  10175. }
  10176. });
  10177. callHook$1(onLeave, [el, resolve]);
  10178. },
  10179. onEnterCancelled(el) {
  10180. finishEnter(el, false);
  10181. callHook$1(onEnterCancelled, [el]);
  10182. },
  10183. onAppearCancelled(el) {
  10184. finishEnter(el, true);
  10185. callHook$1(onAppearCancelled, [el]);
  10186. },
  10187. onLeaveCancelled(el) {
  10188. finishLeave(el);
  10189. callHook$1(onLeaveCancelled, [el]);
  10190. }
  10191. });
  10192. }
  10193. function normalizeDuration(duration) {
  10194. if (duration == null) {
  10195. return null;
  10196. }
  10197. else if (isObject(duration)) {
  10198. return [NumberOf(duration.enter), NumberOf(duration.leave)];
  10199. }
  10200. else {
  10201. const n = NumberOf(duration);
  10202. return [n, n];
  10203. }
  10204. }
  10205. function NumberOf(val) {
  10206. const res = toNumber(val);
  10207. validateDuration(res);
  10208. return res;
  10209. }
  10210. function validateDuration(val) {
  10211. if (typeof val !== 'number') {
  10212. warn$1(`<transition> explicit duration is not a valid number - ` +
  10213. `got ${JSON.stringify(val)}.`);
  10214. }
  10215. else if (isNaN(val)) {
  10216. warn$1(`<transition> explicit duration is NaN - ` +
  10217. 'the duration expression might be incorrect.');
  10218. }
  10219. }
  10220. function addTransitionClass(el, cls) {
  10221. cls.split(/\s+/).forEach(c => c && el.classList.add(c));
  10222. (el._vtc ||
  10223. (el._vtc = new Set())).add(cls);
  10224. }
  10225. function removeTransitionClass(el, cls) {
  10226. cls.split(/\s+/).forEach(c => c && el.classList.remove(c));
  10227. const { _vtc } = el;
  10228. if (_vtc) {
  10229. _vtc.delete(cls);
  10230. if (!_vtc.size) {
  10231. el._vtc = undefined;
  10232. }
  10233. }
  10234. }
  10235. function nextFrame(cb) {
  10236. requestAnimationFrame(() => {
  10237. requestAnimationFrame(cb);
  10238. });
  10239. }
  10240. let endId = 0;
  10241. function whenTransitionEnds(el, expectedType, explicitTimeout, resolve) {
  10242. const id = (el._endId = ++endId);
  10243. const resolveIfNotStale = () => {
  10244. if (id === el._endId) {
  10245. resolve();
  10246. }
  10247. };
  10248. if (explicitTimeout) {
  10249. return setTimeout(resolveIfNotStale, explicitTimeout);
  10250. }
  10251. const { type, timeout, propCount } = getTransitionInfo(el, expectedType);
  10252. if (!type) {
  10253. return resolve();
  10254. }
  10255. const endEvent = type + 'end';
  10256. let ended = 0;
  10257. const end = () => {
  10258. el.removeEventListener(endEvent, onEnd);
  10259. resolveIfNotStale();
  10260. };
  10261. const onEnd = (e) => {
  10262. if (e.target === el && ++ended >= propCount) {
  10263. end();
  10264. }
  10265. };
  10266. setTimeout(() => {
  10267. if (ended < propCount) {
  10268. end();
  10269. }
  10270. }, timeout + 1);
  10271. el.addEventListener(endEvent, onEnd);
  10272. }
  10273. function getTransitionInfo(el, expectedType) {
  10274. const styles = window.getComputedStyle(el);
  10275. // JSDOM may return undefined for transition properties
  10276. const getStyleProperties = (key) => (styles[key] || '').split(', ');
  10277. const transitionDelays = getStyleProperties(`${TRANSITION}Delay`);
  10278. const transitionDurations = getStyleProperties(`${TRANSITION}Duration`);
  10279. const transitionTimeout = getTimeout(transitionDelays, transitionDurations);
  10280. const animationDelays = getStyleProperties(`${ANIMATION}Delay`);
  10281. const animationDurations = getStyleProperties(`${ANIMATION}Duration`);
  10282. const animationTimeout = getTimeout(animationDelays, animationDurations);
  10283. let type = null;
  10284. let timeout = 0;
  10285. let propCount = 0;
  10286. /* istanbul ignore if */
  10287. if (expectedType === TRANSITION) {
  10288. if (transitionTimeout > 0) {
  10289. type = TRANSITION;
  10290. timeout = transitionTimeout;
  10291. propCount = transitionDurations.length;
  10292. }
  10293. }
  10294. else if (expectedType === ANIMATION) {
  10295. if (animationTimeout > 0) {
  10296. type = ANIMATION;
  10297. timeout = animationTimeout;
  10298. propCount = animationDurations.length;
  10299. }
  10300. }
  10301. else {
  10302. timeout = Math.max(transitionTimeout, animationTimeout);
  10303. type =
  10304. timeout > 0
  10305. ? transitionTimeout > animationTimeout
  10306. ? TRANSITION
  10307. : ANIMATION
  10308. : null;
  10309. propCount = type
  10310. ? type === TRANSITION
  10311. ? transitionDurations.length
  10312. : animationDurations.length
  10313. : 0;
  10314. }
  10315. const hasTransform = type === TRANSITION &&
  10316. /\b(transform|all)(,|$)/.test(getStyleProperties(`${TRANSITION}Property`).toString());
  10317. return {
  10318. type,
  10319. timeout,
  10320. propCount,
  10321. hasTransform
  10322. };
  10323. }
  10324. function getTimeout(delays, durations) {
  10325. while (delays.length < durations.length) {
  10326. delays = delays.concat(delays);
  10327. }
  10328. return Math.max(...durations.map((d, i) => toMs(d) + toMs(delays[i])));
  10329. }
  10330. // Old versions of Chromium (below 61.0.3163.100) formats floating pointer
  10331. // numbers in a locale-dependent way, using a comma instead of a dot.
  10332. // If comma is not replaced with a dot, the input will be rounded down
  10333. // (i.e. acting as a floor function) causing unexpected behaviors
  10334. function toMs(s) {
  10335. return Number(s.slice(0, -1).replace(',', '.')) * 1000;
  10336. }
  10337. // synchronously force layout to put elements into a certain state
  10338. function forceReflow() {
  10339. return document.body.offsetHeight;
  10340. }
  10341. const positionMap = new WeakMap();
  10342. const newPositionMap = new WeakMap();
  10343. const TransitionGroupImpl = {
  10344. name: 'TransitionGroup',
  10345. props: /*#__PURE__*/ extend({}, TransitionPropsValidators, {
  10346. tag: String,
  10347. moveClass: String
  10348. }),
  10349. setup(props, { slots }) {
  10350. const instance = getCurrentInstance();
  10351. const state = useTransitionState();
  10352. let prevChildren;
  10353. let children;
  10354. onUpdated(() => {
  10355. // children is guaranteed to exist after initial render
  10356. if (!prevChildren.length) {
  10357. return;
  10358. }
  10359. const moveClass = props.moveClass || `${props.name || 'v'}-move`;
  10360. if (!hasCSSTransform(prevChildren[0].el, instance.vnode.el, moveClass)) {
  10361. return;
  10362. }
  10363. // we divide the work into three loops to avoid mixing DOM reads and writes
  10364. // in each iteration - which helps prevent layout thrashing.
  10365. prevChildren.forEach(callPendingCbs);
  10366. prevChildren.forEach(recordPosition);
  10367. const movedChildren = prevChildren.filter(applyTranslation);
  10368. // force reflow to put everything in position
  10369. forceReflow();
  10370. movedChildren.forEach(c => {
  10371. const el = c.el;
  10372. const style = el.style;
  10373. addTransitionClass(el, moveClass);
  10374. style.transform = style.webkitTransform = style.transitionDuration = '';
  10375. const cb = (el._moveCb = (e) => {
  10376. if (e && e.target !== el) {
  10377. return;
  10378. }
  10379. if (!e || /transform$/.test(e.propertyName)) {
  10380. el.removeEventListener('transitionend', cb);
  10381. el._moveCb = null;
  10382. removeTransitionClass(el, moveClass);
  10383. }
  10384. });
  10385. el.addEventListener('transitionend', cb);
  10386. });
  10387. });
  10388. return () => {
  10389. const rawProps = toRaw(props);
  10390. const cssTransitionProps = resolveTransitionProps(rawProps);
  10391. let tag = rawProps.tag || Fragment;
  10392. prevChildren = children;
  10393. children = slots.default ? getTransitionRawChildren(slots.default()) : [];
  10394. for (let i = 0; i < children.length; i++) {
  10395. const child = children[i];
  10396. if (child.key != null) {
  10397. setTransitionHooks(child, resolveTransitionHooks(child, cssTransitionProps, state, instance));
  10398. }
  10399. else {
  10400. warn$1(`<TransitionGroup> children must be keyed.`);
  10401. }
  10402. }
  10403. if (prevChildren) {
  10404. for (let i = 0; i < prevChildren.length; i++) {
  10405. const child = prevChildren[i];
  10406. setTransitionHooks(child, resolveTransitionHooks(child, cssTransitionProps, state, instance));
  10407. positionMap.set(child, child.el.getBoundingClientRect());
  10408. }
  10409. }
  10410. return createVNode(tag, null, children);
  10411. };
  10412. }
  10413. };
  10414. const TransitionGroup = TransitionGroupImpl;
  10415. function callPendingCbs(c) {
  10416. const el = c.el;
  10417. if (el._moveCb) {
  10418. el._moveCb();
  10419. }
  10420. if (el._enterCb) {
  10421. el._enterCb();
  10422. }
  10423. }
  10424. function recordPosition(c) {
  10425. newPositionMap.set(c, c.el.getBoundingClientRect());
  10426. }
  10427. function applyTranslation(c) {
  10428. const oldPos = positionMap.get(c);
  10429. const newPos = newPositionMap.get(c);
  10430. const dx = oldPos.left - newPos.left;
  10431. const dy = oldPos.top - newPos.top;
  10432. if (dx || dy) {
  10433. const s = c.el.style;
  10434. s.transform = s.webkitTransform = `translate(${dx}px,${dy}px)`;
  10435. s.transitionDuration = '0s';
  10436. return c;
  10437. }
  10438. }
  10439. function hasCSSTransform(el, root, moveClass) {
  10440. // Detect whether an element with the move class applied has
  10441. // CSS transitions. Since the element may be inside an entering
  10442. // transition at this very moment, we make a clone of it and remove
  10443. // all other transition classes applied to ensure only the move class
  10444. // is applied.
  10445. const clone = el.cloneNode();
  10446. if (el._vtc) {
  10447. el._vtc.forEach(cls => {
  10448. cls.split(/\s+/).forEach(c => c && clone.classList.remove(c));
  10449. });
  10450. }
  10451. moveClass.split(/\s+/).forEach(c => c && clone.classList.add(c));
  10452. clone.style.display = 'none';
  10453. const container = (root.nodeType === 1 ? root : root.parentNode);
  10454. container.appendChild(clone);
  10455. const { hasTransform } = getTransitionInfo(clone);
  10456. container.removeChild(clone);
  10457. return hasTransform;
  10458. }
  10459. const getModelAssigner = (vnode) => {
  10460. const fn = vnode.props['onUpdate:modelValue'] ||
  10461. (false );
  10462. return isArray(fn) ? value => invokeArrayFns(fn, value) : fn;
  10463. };
  10464. function onCompositionStart(e) {
  10465. e.target.composing = true;
  10466. }
  10467. function onCompositionEnd(e) {
  10468. const target = e.target;
  10469. if (target.composing) {
  10470. target.composing = false;
  10471. target.dispatchEvent(new Event('input'));
  10472. }
  10473. }
  10474. // We are exporting the v-model runtime directly as vnode hooks so that it can
  10475. // be tree-shaken in case v-model is never used.
  10476. const vModelText = {
  10477. created(el, { modifiers: { lazy, trim, number } }, vnode) {
  10478. el._assign = getModelAssigner(vnode);
  10479. const castToNumber = number || (vnode.props && vnode.props.type === 'number');
  10480. addEventListener(el, lazy ? 'change' : 'input', e => {
  10481. if (e.target.composing)
  10482. return;
  10483. let domValue = el.value;
  10484. if (trim) {
  10485. domValue = domValue.trim();
  10486. }
  10487. if (castToNumber) {
  10488. domValue = toNumber(domValue);
  10489. }
  10490. el._assign(domValue);
  10491. });
  10492. if (trim) {
  10493. addEventListener(el, 'change', () => {
  10494. el.value = el.value.trim();
  10495. });
  10496. }
  10497. if (!lazy) {
  10498. addEventListener(el, 'compositionstart', onCompositionStart);
  10499. addEventListener(el, 'compositionend', onCompositionEnd);
  10500. // Safari < 10.2 & UIWebView doesn't fire compositionend when
  10501. // switching focus before confirming composition choice
  10502. // this also fixes the issue where some browsers e.g. iOS Chrome
  10503. // fires "change" instead of "input" on autocomplete.
  10504. addEventListener(el, 'change', onCompositionEnd);
  10505. }
  10506. },
  10507. // set value on mounted so it's after min/max for type="range"
  10508. mounted(el, { value }) {
  10509. el.value = value == null ? '' : value;
  10510. },
  10511. beforeUpdate(el, { value, modifiers: { lazy, trim, number } }, vnode) {
  10512. el._assign = getModelAssigner(vnode);
  10513. // avoid clearing unresolved text. #2302
  10514. if (el.composing)
  10515. return;
  10516. if (document.activeElement === el && el.type !== 'range') {
  10517. if (lazy) {
  10518. return;
  10519. }
  10520. if (trim && el.value.trim() === value) {
  10521. return;
  10522. }
  10523. if ((number || el.type === 'number') && toNumber(el.value) === value) {
  10524. return;
  10525. }
  10526. }
  10527. const newValue = value == null ? '' : value;
  10528. if (el.value !== newValue) {
  10529. el.value = newValue;
  10530. }
  10531. }
  10532. };
  10533. const vModelCheckbox = {
  10534. // #4096 array checkboxes need to be deep traversed
  10535. deep: true,
  10536. created(el, _, vnode) {
  10537. el._assign = getModelAssigner(vnode);
  10538. addEventListener(el, 'change', () => {
  10539. const modelValue = el._modelValue;
  10540. const elementValue = getValue(el);
  10541. const checked = el.checked;
  10542. const assign = el._assign;
  10543. if (isArray(modelValue)) {
  10544. const index = looseIndexOf(modelValue, elementValue);
  10545. const found = index !== -1;
  10546. if (checked && !found) {
  10547. assign(modelValue.concat(elementValue));
  10548. }
  10549. else if (!checked && found) {
  10550. const filtered = [...modelValue];
  10551. filtered.splice(index, 1);
  10552. assign(filtered);
  10553. }
  10554. }
  10555. else if (isSet(modelValue)) {
  10556. const cloned = new Set(modelValue);
  10557. if (checked) {
  10558. cloned.add(elementValue);
  10559. }
  10560. else {
  10561. cloned.delete(elementValue);
  10562. }
  10563. assign(cloned);
  10564. }
  10565. else {
  10566. assign(getCheckboxValue(el, checked));
  10567. }
  10568. });
  10569. },
  10570. // set initial checked on mount to wait for true-value/false-value
  10571. mounted: setChecked,
  10572. beforeUpdate(el, binding, vnode) {
  10573. el._assign = getModelAssigner(vnode);
  10574. setChecked(el, binding, vnode);
  10575. }
  10576. };
  10577. function setChecked(el, { value, oldValue }, vnode) {
  10578. el._modelValue = value;
  10579. if (isArray(value)) {
  10580. el.checked = looseIndexOf(value, vnode.props.value) > -1;
  10581. }
  10582. else if (isSet(value)) {
  10583. el.checked = value.has(vnode.props.value);
  10584. }
  10585. else if (value !== oldValue) {
  10586. el.checked = looseEqual(value, getCheckboxValue(el, true));
  10587. }
  10588. }
  10589. const vModelRadio = {
  10590. created(el, { value }, vnode) {
  10591. el.checked = looseEqual(value, vnode.props.value);
  10592. el._assign = getModelAssigner(vnode);
  10593. addEventListener(el, 'change', () => {
  10594. el._assign(getValue(el));
  10595. });
  10596. },
  10597. beforeUpdate(el, { value, oldValue }, vnode) {
  10598. el._assign = getModelAssigner(vnode);
  10599. if (value !== oldValue) {
  10600. el.checked = looseEqual(value, vnode.props.value);
  10601. }
  10602. }
  10603. };
  10604. const vModelSelect = {
  10605. // <select multiple> value need to be deep traversed
  10606. deep: true,
  10607. created(el, { value, modifiers: { number } }, vnode) {
  10608. const isSetModel = isSet(value);
  10609. addEventListener(el, 'change', () => {
  10610. const selectedVal = Array.prototype.filter
  10611. .call(el.options, (o) => o.selected)
  10612. .map((o) => number ? toNumber(getValue(o)) : getValue(o));
  10613. el._assign(el.multiple
  10614. ? isSetModel
  10615. ? new Set(selectedVal)
  10616. : selectedVal
  10617. : selectedVal[0]);
  10618. });
  10619. el._assign = getModelAssigner(vnode);
  10620. },
  10621. // set value in mounted & updated because <select> relies on its children
  10622. // <option>s.
  10623. mounted(el, { value }) {
  10624. setSelected(el, value);
  10625. },
  10626. beforeUpdate(el, _binding, vnode) {
  10627. el._assign = getModelAssigner(vnode);
  10628. },
  10629. updated(el, { value }) {
  10630. setSelected(el, value);
  10631. }
  10632. };
  10633. function setSelected(el, value) {
  10634. const isMultiple = el.multiple;
  10635. if (isMultiple && !isArray(value) && !isSet(value)) {
  10636. warn$1(`<select multiple v-model> expects an Array or Set value for its binding, ` +
  10637. `but got ${Object.prototype.toString.call(value).slice(8, -1)}.`);
  10638. return;
  10639. }
  10640. for (let i = 0, l = el.options.length; i < l; i++) {
  10641. const option = el.options[i];
  10642. const optionValue = getValue(option);
  10643. if (isMultiple) {
  10644. if (isArray(value)) {
  10645. option.selected = looseIndexOf(value, optionValue) > -1;
  10646. }
  10647. else {
  10648. option.selected = value.has(optionValue);
  10649. }
  10650. }
  10651. else {
  10652. if (looseEqual(getValue(option), value)) {
  10653. if (el.selectedIndex !== i)
  10654. el.selectedIndex = i;
  10655. return;
  10656. }
  10657. }
  10658. }
  10659. if (!isMultiple && el.selectedIndex !== -1) {
  10660. el.selectedIndex = -1;
  10661. }
  10662. }
  10663. // retrieve raw value set via :value bindings
  10664. function getValue(el) {
  10665. return '_value' in el ? el._value : el.value;
  10666. }
  10667. // retrieve raw value for true-value and false-value set via :true-value or :false-value bindings
  10668. function getCheckboxValue(el, checked) {
  10669. const key = checked ? '_trueValue' : '_falseValue';
  10670. return key in el ? el[key] : checked;
  10671. }
  10672. const vModelDynamic = {
  10673. created(el, binding, vnode) {
  10674. callModelHook(el, binding, vnode, null, 'created');
  10675. },
  10676. mounted(el, binding, vnode) {
  10677. callModelHook(el, binding, vnode, null, 'mounted');
  10678. },
  10679. beforeUpdate(el, binding, vnode, prevVNode) {
  10680. callModelHook(el, binding, vnode, prevVNode, 'beforeUpdate');
  10681. },
  10682. updated(el, binding, vnode, prevVNode) {
  10683. callModelHook(el, binding, vnode, prevVNode, 'updated');
  10684. }
  10685. };
  10686. function resolveDynamicModel(tagName, type) {
  10687. switch (tagName) {
  10688. case 'SELECT':
  10689. return vModelSelect;
  10690. case 'TEXTAREA':
  10691. return vModelText;
  10692. default:
  10693. switch (type) {
  10694. case 'checkbox':
  10695. return vModelCheckbox;
  10696. case 'radio':
  10697. return vModelRadio;
  10698. default:
  10699. return vModelText;
  10700. }
  10701. }
  10702. }
  10703. function callModelHook(el, binding, vnode, prevVNode, hook) {
  10704. const modelToUse = resolveDynamicModel(el.tagName, vnode.props && vnode.props.type);
  10705. const fn = modelToUse[hook];
  10706. fn && fn(el, binding, vnode, prevVNode);
  10707. }
  10708. const systemModifiers = ['ctrl', 'shift', 'alt', 'meta'];
  10709. const modifierGuards = {
  10710. stop: e => e.stopPropagation(),
  10711. prevent: e => e.preventDefault(),
  10712. self: e => e.target !== e.currentTarget,
  10713. ctrl: e => !e.ctrlKey,
  10714. shift: e => !e.shiftKey,
  10715. alt: e => !e.altKey,
  10716. meta: e => !e.metaKey,
  10717. left: e => 'button' in e && e.button !== 0,
  10718. middle: e => 'button' in e && e.button !== 1,
  10719. right: e => 'button' in e && e.button !== 2,
  10720. exact: (e, modifiers) => systemModifiers.some(m => e[`${m}Key`] && !modifiers.includes(m))
  10721. };
  10722. /**
  10723. * @private
  10724. */
  10725. const withModifiers = (fn, modifiers) => {
  10726. return (event, ...args) => {
  10727. for (let i = 0; i < modifiers.length; i++) {
  10728. const guard = modifierGuards[modifiers[i]];
  10729. if (guard && guard(event, modifiers))
  10730. return;
  10731. }
  10732. return fn(event, ...args);
  10733. };
  10734. };
  10735. // Kept for 2.x compat.
  10736. // Note: IE11 compat for `spacebar` and `del` is removed for now.
  10737. const keyNames = {
  10738. esc: 'escape',
  10739. space: ' ',
  10740. up: 'arrow-up',
  10741. left: 'arrow-left',
  10742. right: 'arrow-right',
  10743. down: 'arrow-down',
  10744. delete: 'backspace'
  10745. };
  10746. /**
  10747. * @private
  10748. */
  10749. const withKeys = (fn, modifiers) => {
  10750. return (event) => {
  10751. if (!('key' in event)) {
  10752. return;
  10753. }
  10754. const eventKey = hyphenate(event.key);
  10755. if (modifiers.some(k => k === eventKey || keyNames[k] === eventKey)) {
  10756. return fn(event);
  10757. }
  10758. };
  10759. };
  10760. const vShow = {
  10761. beforeMount(el, { value }, { transition }) {
  10762. el._vod = el.style.display === 'none' ? '' : el.style.display;
  10763. if (transition && value) {
  10764. transition.beforeEnter(el);
  10765. }
  10766. else {
  10767. setDisplay(el, value);
  10768. }
  10769. },
  10770. mounted(el, { value }, { transition }) {
  10771. if (transition && value) {
  10772. transition.enter(el);
  10773. }
  10774. },
  10775. updated(el, { value, oldValue }, { transition }) {
  10776. if (!value === !oldValue)
  10777. return;
  10778. if (transition) {
  10779. if (value) {
  10780. transition.beforeEnter(el);
  10781. setDisplay(el, true);
  10782. transition.enter(el);
  10783. }
  10784. else {
  10785. transition.leave(el, () => {
  10786. setDisplay(el, false);
  10787. });
  10788. }
  10789. }
  10790. else {
  10791. setDisplay(el, value);
  10792. }
  10793. },
  10794. beforeUnmount(el, { value }) {
  10795. setDisplay(el, value);
  10796. }
  10797. };
  10798. function setDisplay(el, value) {
  10799. el.style.display = value ? el._vod : 'none';
  10800. }
  10801. const rendererOptions = /*#__PURE__*/ extend({ patchProp }, nodeOps);
  10802. // lazy create the renderer - this makes core renderer logic tree-shakable
  10803. // in case the user only imports reactivity utilities from Vue.
  10804. let renderer;
  10805. let enabledHydration = false;
  10806. function ensureRenderer() {
  10807. return (renderer ||
  10808. (renderer = createRenderer(rendererOptions)));
  10809. }
  10810. function ensureHydrationRenderer() {
  10811. renderer = enabledHydration
  10812. ? renderer
  10813. : createHydrationRenderer(rendererOptions);
  10814. enabledHydration = true;
  10815. return renderer;
  10816. }
  10817. // use explicit type casts here to avoid import() calls in rolled-up d.ts
  10818. const render = ((...args) => {
  10819. ensureRenderer().render(...args);
  10820. });
  10821. const hydrate = ((...args) => {
  10822. ensureHydrationRenderer().hydrate(...args);
  10823. });
  10824. const createApp = ((...args) => {
  10825. const app = ensureRenderer().createApp(...args);
  10826. {
  10827. injectNativeTagCheck(app);
  10828. injectCompilerOptionsCheck(app);
  10829. }
  10830. const { mount } = app;
  10831. app.mount = (containerOrSelector) => {
  10832. const container = normalizeContainer(containerOrSelector);
  10833. if (!container)
  10834. return;
  10835. const component = app._component;
  10836. if (!isFunction(component) && !component.render && !component.template) {
  10837. // __UNSAFE__
  10838. // Reason: potential execution of JS expressions in in-DOM template.
  10839. // The user must make sure the in-DOM template is trusted. If it's
  10840. // rendered by the server, the template should not contain any user data.
  10841. component.template = container.innerHTML;
  10842. }
  10843. // clear content before mounting
  10844. container.innerHTML = '';
  10845. const proxy = mount(container, false, container instanceof SVGElement);
  10846. if (container instanceof Element) {
  10847. container.removeAttribute('v-cloak');
  10848. container.setAttribute('data-v-app', '');
  10849. }
  10850. return proxy;
  10851. };
  10852. return app;
  10853. });
  10854. const createSSRApp = ((...args) => {
  10855. const app = ensureHydrationRenderer().createApp(...args);
  10856. {
  10857. injectNativeTagCheck(app);
  10858. injectCompilerOptionsCheck(app);
  10859. }
  10860. const { mount } = app;
  10861. app.mount = (containerOrSelector) => {
  10862. const container = normalizeContainer(containerOrSelector);
  10863. if (container) {
  10864. return mount(container, true, container instanceof SVGElement);
  10865. }
  10866. };
  10867. return app;
  10868. });
  10869. function injectNativeTagCheck(app) {
  10870. // Inject `isNativeTag`
  10871. // this is used for component name validation (dev only)
  10872. Object.defineProperty(app.config, 'isNativeTag', {
  10873. value: (tag) => isHTMLTag(tag) || isSVGTag(tag),
  10874. writable: false
  10875. });
  10876. }
  10877. // dev only
  10878. function injectCompilerOptionsCheck(app) {
  10879. if (isRuntimeOnly()) {
  10880. const isCustomElement = app.config.isCustomElement;
  10881. Object.defineProperty(app.config, 'isCustomElement', {
  10882. get() {
  10883. return isCustomElement;
  10884. },
  10885. set() {
  10886. warn$1(`The \`isCustomElement\` config option is deprecated. Use ` +
  10887. `\`compilerOptions.isCustomElement\` instead.`);
  10888. }
  10889. });
  10890. const compilerOptions = app.config.compilerOptions;
  10891. const msg = `The \`compilerOptions\` config option is only respected when using ` +
  10892. `a build of Vue.js that includes the runtime compiler (aka "full build"). ` +
  10893. `Since you are using the runtime-only build, \`compilerOptions\` ` +
  10894. `must be passed to \`@vue/compiler-dom\` in the build setup instead.\n` +
  10895. `- For vue-loader: pass it via vue-loader's \`compilerOptions\` loader option.\n` +
  10896. `- For vue-cli: see https://cli.vuejs.org/guide/webpack.html#modifying-options-of-a-loader\n` +
  10897. `- 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`;
  10898. Object.defineProperty(app.config, 'compilerOptions', {
  10899. get() {
  10900. warn$1(msg);
  10901. return compilerOptions;
  10902. },
  10903. set() {
  10904. warn$1(msg);
  10905. }
  10906. });
  10907. }
  10908. }
  10909. function normalizeContainer(container) {
  10910. if (isString(container)) {
  10911. const res = document.querySelector(container);
  10912. if (!res) {
  10913. warn$1(`Failed to mount app: mount target selector "${container}" returned null.`);
  10914. }
  10915. return res;
  10916. }
  10917. if (window.ShadowRoot &&
  10918. container instanceof window.ShadowRoot &&
  10919. container.mode === 'closed') {
  10920. warn$1(`mounting on a ShadowRoot with \`{mode: "closed"}\` may lead to unpredictable bugs`);
  10921. }
  10922. return container;
  10923. }
  10924. /**
  10925. * @internal
  10926. */
  10927. const initDirectivesForSSR = NOOP;
  10928. function initDev() {
  10929. {
  10930. {
  10931. console.info(`You are running a development build of Vue.\n` +
  10932. `Make sure to use the production build (*.prod.js) when deploying for production.`);
  10933. }
  10934. initCustomFormatter();
  10935. }
  10936. }
  10937. function defaultOnError(error) {
  10938. throw error;
  10939. }
  10940. function defaultOnWarn(msg) {
  10941. console.warn(`[Vue warn] ${msg.message}`);
  10942. }
  10943. function createCompilerError(code, loc, messages, additionalMessage) {
  10944. const msg = (messages || errorMessages)[code] + (additionalMessage || ``)
  10945. ;
  10946. const error = new SyntaxError(String(msg));
  10947. error.code = code;
  10948. error.loc = loc;
  10949. return error;
  10950. }
  10951. const errorMessages = {
  10952. // parse errors
  10953. [0 /* ErrorCodes.ABRUPT_CLOSING_OF_EMPTY_COMMENT */]: 'Illegal comment.',
  10954. [1 /* ErrorCodes.CDATA_IN_HTML_CONTENT */]: 'CDATA section is allowed only in XML context.',
  10955. [2 /* ErrorCodes.DUPLICATE_ATTRIBUTE */]: 'Duplicate attribute.',
  10956. [3 /* ErrorCodes.END_TAG_WITH_ATTRIBUTES */]: 'End tag cannot have attributes.',
  10957. [4 /* ErrorCodes.END_TAG_WITH_TRAILING_SOLIDUS */]: "Illegal '/' in tags.",
  10958. [5 /* ErrorCodes.EOF_BEFORE_TAG_NAME */]: 'Unexpected EOF in tag.',
  10959. [6 /* ErrorCodes.EOF_IN_CDATA */]: 'Unexpected EOF in CDATA section.',
  10960. [7 /* ErrorCodes.EOF_IN_COMMENT */]: 'Unexpected EOF in comment.',
  10961. [8 /* ErrorCodes.EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT */]: 'Unexpected EOF in script.',
  10962. [9 /* ErrorCodes.EOF_IN_TAG */]: 'Unexpected EOF in tag.',
  10963. [10 /* ErrorCodes.INCORRECTLY_CLOSED_COMMENT */]: 'Incorrectly closed comment.',
  10964. [11 /* ErrorCodes.INCORRECTLY_OPENED_COMMENT */]: 'Incorrectly opened comment.',
  10965. [12 /* ErrorCodes.INVALID_FIRST_CHARACTER_OF_TAG_NAME */]: "Illegal tag name. Use '&lt;' to print '<'.",
  10966. [13 /* ErrorCodes.MISSING_ATTRIBUTE_VALUE */]: 'Attribute value was expected.',
  10967. [14 /* ErrorCodes.MISSING_END_TAG_NAME */]: 'End tag name was expected.',
  10968. [15 /* ErrorCodes.MISSING_WHITESPACE_BETWEEN_ATTRIBUTES */]: 'Whitespace was expected.',
  10969. [16 /* ErrorCodes.NESTED_COMMENT */]: "Unexpected '<!--' in comment.",
  10970. [17 /* ErrorCodes.UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME */]: 'Attribute name cannot contain U+0022 ("), U+0027 (\'), and U+003C (<).',
  10971. [18 /* ErrorCodes.UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE */]: 'Unquoted attribute value cannot contain U+0022 ("), U+0027 (\'), U+003C (<), U+003D (=), and U+0060 (`).',
  10972. [19 /* ErrorCodes.UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME */]: "Attribute name cannot start with '='.",
  10973. [21 /* ErrorCodes.UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME */]: "'<?' is allowed only in XML context.",
  10974. [20 /* ErrorCodes.UNEXPECTED_NULL_CHARACTER */]: `Unexpected null character.`,
  10975. [22 /* ErrorCodes.UNEXPECTED_SOLIDUS_IN_TAG */]: "Illegal '/' in tags.",
  10976. // Vue-specific parse errors
  10977. [23 /* ErrorCodes.X_INVALID_END_TAG */]: 'Invalid end tag.',
  10978. [24 /* ErrorCodes.X_MISSING_END_TAG */]: 'Element is missing end tag.',
  10979. [25 /* ErrorCodes.X_MISSING_INTERPOLATION_END */]: 'Interpolation end sign was not found.',
  10980. [27 /* ErrorCodes.X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END */]: 'End bracket for dynamic directive argument was not found. ' +
  10981. 'Note that dynamic directive argument cannot contain spaces.',
  10982. [26 /* ErrorCodes.X_MISSING_DIRECTIVE_NAME */]: 'Legal directive name was expected.',
  10983. // transform errors
  10984. [28 /* ErrorCodes.X_V_IF_NO_EXPRESSION */]: `v-if/v-else-if is missing expression.`,
  10985. [29 /* ErrorCodes.X_V_IF_SAME_KEY */]: `v-if/else branches must use unique keys.`,
  10986. [30 /* ErrorCodes.X_V_ELSE_NO_ADJACENT_IF */]: `v-else/v-else-if has no adjacent v-if or v-else-if.`,
  10987. [31 /* ErrorCodes.X_V_FOR_NO_EXPRESSION */]: `v-for is missing expression.`,
  10988. [32 /* ErrorCodes.X_V_FOR_MALFORMED_EXPRESSION */]: `v-for has invalid expression.`,
  10989. [33 /* ErrorCodes.X_V_FOR_TEMPLATE_KEY_PLACEMENT */]: `<template v-for> key should be placed on the <template> tag.`,
  10990. [34 /* ErrorCodes.X_V_BIND_NO_EXPRESSION */]: `v-bind is missing expression.`,
  10991. [35 /* ErrorCodes.X_V_ON_NO_EXPRESSION */]: `v-on is missing expression.`,
  10992. [36 /* ErrorCodes.X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET */]: `Unexpected custom directive on <slot> outlet.`,
  10993. [37 /* ErrorCodes.X_V_SLOT_MIXED_SLOT_USAGE */]: `Mixed v-slot usage on both the component and nested <template>.` +
  10994. `When there are multiple named slots, all slots should use <template> ` +
  10995. `syntax to avoid scope ambiguity.`,
  10996. [38 /* ErrorCodes.X_V_SLOT_DUPLICATE_SLOT_NAMES */]: `Duplicate slot names found. `,
  10997. [39 /* ErrorCodes.X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN */]: `Extraneous children found when component already has explicitly named ` +
  10998. `default slot. These children will be ignored.`,
  10999. [40 /* ErrorCodes.X_V_SLOT_MISPLACED */]: `v-slot can only be used on components or <template> tags.`,
  11000. [41 /* ErrorCodes.X_V_MODEL_NO_EXPRESSION */]: `v-model is missing expression.`,
  11001. [42 /* ErrorCodes.X_V_MODEL_MALFORMED_EXPRESSION */]: `v-model value must be a valid JavaScript member expression.`,
  11002. [43 /* ErrorCodes.X_V_MODEL_ON_SCOPE_VARIABLE */]: `v-model cannot be used on v-for or v-slot scope variables because they are not writable.`,
  11003. [44 /* ErrorCodes.X_V_MODEL_ON_PROPS */]: `v-model cannot be used on a prop, because local prop bindings are not writable.\nUse a v-bind binding combined with a v-on listener that emits update:x event instead.`,
  11004. [45 /* ErrorCodes.X_INVALID_EXPRESSION */]: `Error parsing JavaScript expression: `,
  11005. [46 /* ErrorCodes.X_KEEP_ALIVE_INVALID_CHILDREN */]: `<KeepAlive> expects exactly one child component.`,
  11006. // generic errors
  11007. [47 /* ErrorCodes.X_PREFIX_ID_NOT_SUPPORTED */]: `"prefixIdentifiers" option is not supported in this build of compiler.`,
  11008. [48 /* ErrorCodes.X_MODULE_MODE_NOT_SUPPORTED */]: `ES module mode is not supported in this build of compiler.`,
  11009. [49 /* ErrorCodes.X_CACHE_HANDLER_NOT_SUPPORTED */]: `"cacheHandlers" option is only supported when the "prefixIdentifiers" option is enabled.`,
  11010. [50 /* ErrorCodes.X_SCOPE_ID_NOT_SUPPORTED */]: `"scopeId" option is only supported in module mode.`,
  11011. // just to fulfill types
  11012. [51 /* ErrorCodes.__EXTEND_POINT__ */]: ``
  11013. };
  11014. const FRAGMENT = Symbol(`Fragment` );
  11015. const TELEPORT = Symbol(`Teleport` );
  11016. const SUSPENSE = Symbol(`Suspense` );
  11017. const KEEP_ALIVE = Symbol(`KeepAlive` );
  11018. const BASE_TRANSITION = Symbol(`BaseTransition` );
  11019. const OPEN_BLOCK = Symbol(`openBlock` );
  11020. const CREATE_BLOCK = Symbol(`createBlock` );
  11021. const CREATE_ELEMENT_BLOCK = Symbol(`createElementBlock` );
  11022. const CREATE_VNODE = Symbol(`createVNode` );
  11023. const CREATE_ELEMENT_VNODE = Symbol(`createElementVNode` );
  11024. const CREATE_COMMENT = Symbol(`createCommentVNode` );
  11025. const CREATE_TEXT = Symbol(`createTextVNode` );
  11026. const CREATE_STATIC = Symbol(`createStaticVNode` );
  11027. const RESOLVE_COMPONENT = Symbol(`resolveComponent` );
  11028. const RESOLVE_DYNAMIC_COMPONENT = Symbol(`resolveDynamicComponent` );
  11029. const RESOLVE_DIRECTIVE = Symbol(`resolveDirective` );
  11030. const RESOLVE_FILTER = Symbol(`resolveFilter` );
  11031. const WITH_DIRECTIVES = Symbol(`withDirectives` );
  11032. const RENDER_LIST = Symbol(`renderList` );
  11033. const RENDER_SLOT = Symbol(`renderSlot` );
  11034. const CREATE_SLOTS = Symbol(`createSlots` );
  11035. const TO_DISPLAY_STRING = Symbol(`toDisplayString` );
  11036. const MERGE_PROPS = Symbol(`mergeProps` );
  11037. const NORMALIZE_CLASS = Symbol(`normalizeClass` );
  11038. const NORMALIZE_STYLE = Symbol(`normalizeStyle` );
  11039. const NORMALIZE_PROPS = Symbol(`normalizeProps` );
  11040. const GUARD_REACTIVE_PROPS = Symbol(`guardReactiveProps` );
  11041. const TO_HANDLERS = Symbol(`toHandlers` );
  11042. const CAMELIZE = Symbol(`camelize` );
  11043. const CAPITALIZE = Symbol(`capitalize` );
  11044. const TO_HANDLER_KEY = Symbol(`toHandlerKey` );
  11045. const SET_BLOCK_TRACKING = Symbol(`setBlockTracking` );
  11046. const PUSH_SCOPE_ID = Symbol(`pushScopeId` );
  11047. const POP_SCOPE_ID = Symbol(`popScopeId` );
  11048. const WITH_CTX = Symbol(`withCtx` );
  11049. const UNREF = Symbol(`unref` );
  11050. const IS_REF = Symbol(`isRef` );
  11051. const WITH_MEMO = Symbol(`withMemo` );
  11052. const IS_MEMO_SAME = Symbol(`isMemoSame` );
  11053. // Name mapping for runtime helpers that need to be imported from 'vue' in
  11054. // generated code. Make sure these are correctly exported in the runtime!
  11055. const helperNameMap = {
  11056. [FRAGMENT]: `Fragment`,
  11057. [TELEPORT]: `Teleport`,
  11058. [SUSPENSE]: `Suspense`,
  11059. [KEEP_ALIVE]: `KeepAlive`,
  11060. [BASE_TRANSITION]: `BaseTransition`,
  11061. [OPEN_BLOCK]: `openBlock`,
  11062. [CREATE_BLOCK]: `createBlock`,
  11063. [CREATE_ELEMENT_BLOCK]: `createElementBlock`,
  11064. [CREATE_VNODE]: `createVNode`,
  11065. [CREATE_ELEMENT_VNODE]: `createElementVNode`,
  11066. [CREATE_COMMENT]: `createCommentVNode`,
  11067. [CREATE_TEXT]: `createTextVNode`,
  11068. [CREATE_STATIC]: `createStaticVNode`,
  11069. [RESOLVE_COMPONENT]: `resolveComponent`,
  11070. [RESOLVE_DYNAMIC_COMPONENT]: `resolveDynamicComponent`,
  11071. [RESOLVE_DIRECTIVE]: `resolveDirective`,
  11072. [RESOLVE_FILTER]: `resolveFilter`,
  11073. [WITH_DIRECTIVES]: `withDirectives`,
  11074. [RENDER_LIST]: `renderList`,
  11075. [RENDER_SLOT]: `renderSlot`,
  11076. [CREATE_SLOTS]: `createSlots`,
  11077. [TO_DISPLAY_STRING]: `toDisplayString`,
  11078. [MERGE_PROPS]: `mergeProps`,
  11079. [NORMALIZE_CLASS]: `normalizeClass`,
  11080. [NORMALIZE_STYLE]: `normalizeStyle`,
  11081. [NORMALIZE_PROPS]: `normalizeProps`,
  11082. [GUARD_REACTIVE_PROPS]: `guardReactiveProps`,
  11083. [TO_HANDLERS]: `toHandlers`,
  11084. [CAMELIZE]: `camelize`,
  11085. [CAPITALIZE]: `capitalize`,
  11086. [TO_HANDLER_KEY]: `toHandlerKey`,
  11087. [SET_BLOCK_TRACKING]: `setBlockTracking`,
  11088. [PUSH_SCOPE_ID]: `pushScopeId`,
  11089. [POP_SCOPE_ID]: `popScopeId`,
  11090. [WITH_CTX]: `withCtx`,
  11091. [UNREF]: `unref`,
  11092. [IS_REF]: `isRef`,
  11093. [WITH_MEMO]: `withMemo`,
  11094. [IS_MEMO_SAME]: `isMemoSame`
  11095. };
  11096. function registerRuntimeHelpers(helpers) {
  11097. Object.getOwnPropertySymbols(helpers).forEach(s => {
  11098. helperNameMap[s] = helpers[s];
  11099. });
  11100. }
  11101. // AST Utilities ---------------------------------------------------------------
  11102. // Some expressions, e.g. sequence and conditional expressions, are never
  11103. // associated with template nodes, so their source locations are just a stub.
  11104. // Container types like CompoundExpression also don't need a real location.
  11105. const locStub = {
  11106. source: '',
  11107. start: { line: 1, column: 1, offset: 0 },
  11108. end: { line: 1, column: 1, offset: 0 }
  11109. };
  11110. function createRoot(children, loc = locStub) {
  11111. return {
  11112. type: 0 /* NodeTypes.ROOT */,
  11113. children,
  11114. helpers: [],
  11115. components: [],
  11116. directives: [],
  11117. hoists: [],
  11118. imports: [],
  11119. cached: 0,
  11120. temps: 0,
  11121. codegenNode: undefined,
  11122. loc
  11123. };
  11124. }
  11125. function createVNodeCall(context, tag, props, children, patchFlag, dynamicProps, directives, isBlock = false, disableTracking = false, isComponent = false, loc = locStub) {
  11126. if (context) {
  11127. if (isBlock) {
  11128. context.helper(OPEN_BLOCK);
  11129. context.helper(getVNodeBlockHelper(context.inSSR, isComponent));
  11130. }
  11131. else {
  11132. context.helper(getVNodeHelper(context.inSSR, isComponent));
  11133. }
  11134. if (directives) {
  11135. context.helper(WITH_DIRECTIVES);
  11136. }
  11137. }
  11138. return {
  11139. type: 13 /* NodeTypes.VNODE_CALL */,
  11140. tag,
  11141. props,
  11142. children,
  11143. patchFlag,
  11144. dynamicProps,
  11145. directives,
  11146. isBlock,
  11147. disableTracking,
  11148. isComponent,
  11149. loc
  11150. };
  11151. }
  11152. function createArrayExpression(elements, loc = locStub) {
  11153. return {
  11154. type: 17 /* NodeTypes.JS_ARRAY_EXPRESSION */,
  11155. loc,
  11156. elements
  11157. };
  11158. }
  11159. function createObjectExpression(properties, loc = locStub) {
  11160. return {
  11161. type: 15 /* NodeTypes.JS_OBJECT_EXPRESSION */,
  11162. loc,
  11163. properties
  11164. };
  11165. }
  11166. function createObjectProperty(key, value) {
  11167. return {
  11168. type: 16 /* NodeTypes.JS_PROPERTY */,
  11169. loc: locStub,
  11170. key: isString(key) ? createSimpleExpression(key, true) : key,
  11171. value
  11172. };
  11173. }
  11174. function createSimpleExpression(content, isStatic = false, loc = locStub, constType = 0 /* ConstantTypes.NOT_CONSTANT */) {
  11175. return {
  11176. type: 4 /* NodeTypes.SIMPLE_EXPRESSION */,
  11177. loc,
  11178. content,
  11179. isStatic,
  11180. constType: isStatic ? 3 /* ConstantTypes.CAN_STRINGIFY */ : constType
  11181. };
  11182. }
  11183. function createCompoundExpression(children, loc = locStub) {
  11184. return {
  11185. type: 8 /* NodeTypes.COMPOUND_EXPRESSION */,
  11186. loc,
  11187. children
  11188. };
  11189. }
  11190. function createCallExpression(callee, args = [], loc = locStub) {
  11191. return {
  11192. type: 14 /* NodeTypes.JS_CALL_EXPRESSION */,
  11193. loc,
  11194. callee,
  11195. arguments: args
  11196. };
  11197. }
  11198. function createFunctionExpression(params, returns = undefined, newline = false, isSlot = false, loc = locStub) {
  11199. return {
  11200. type: 18 /* NodeTypes.JS_FUNCTION_EXPRESSION */,
  11201. params,
  11202. returns,
  11203. newline,
  11204. isSlot,
  11205. loc
  11206. };
  11207. }
  11208. function createConditionalExpression(test, consequent, alternate, newline = true) {
  11209. return {
  11210. type: 19 /* NodeTypes.JS_CONDITIONAL_EXPRESSION */,
  11211. test,
  11212. consequent,
  11213. alternate,
  11214. newline,
  11215. loc: locStub
  11216. };
  11217. }
  11218. function createCacheExpression(index, value, isVNode = false) {
  11219. return {
  11220. type: 20 /* NodeTypes.JS_CACHE_EXPRESSION */,
  11221. index,
  11222. value,
  11223. isVNode,
  11224. loc: locStub
  11225. };
  11226. }
  11227. function createBlockStatement(body) {
  11228. return {
  11229. type: 21 /* NodeTypes.JS_BLOCK_STATEMENT */,
  11230. body,
  11231. loc: locStub
  11232. };
  11233. }
  11234. const isStaticExp = (p) => p.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ && p.isStatic;
  11235. const isBuiltInType = (tag, expected) => tag === expected || tag === hyphenate(expected);
  11236. function isCoreComponent(tag) {
  11237. if (isBuiltInType(tag, 'Teleport')) {
  11238. return TELEPORT;
  11239. }
  11240. else if (isBuiltInType(tag, 'Suspense')) {
  11241. return SUSPENSE;
  11242. }
  11243. else if (isBuiltInType(tag, 'KeepAlive')) {
  11244. return KEEP_ALIVE;
  11245. }
  11246. else if (isBuiltInType(tag, 'BaseTransition')) {
  11247. return BASE_TRANSITION;
  11248. }
  11249. }
  11250. const nonIdentifierRE = /^\d|[^\$\w]/;
  11251. const isSimpleIdentifier = (name) => !nonIdentifierRE.test(name);
  11252. const validFirstIdentCharRE = /[A-Za-z_$\xA0-\uFFFF]/;
  11253. const validIdentCharRE = /[\.\?\w$\xA0-\uFFFF]/;
  11254. const whitespaceRE = /\s+[.[]\s*|\s*[.[]\s+/g;
  11255. /**
  11256. * Simple lexer to check if an expression is a member expression. This is
  11257. * lax and only checks validity at the root level (i.e. does not validate exps
  11258. * inside square brackets), but it's ok since these are only used on template
  11259. * expressions and false positives are invalid expressions in the first place.
  11260. */
  11261. const isMemberExpressionBrowser = (path) => {
  11262. // remove whitespaces around . or [ first
  11263. path = path.trim().replace(whitespaceRE, s => s.trim());
  11264. let state = 0 /* MemberExpLexState.inMemberExp */;
  11265. let stateStack = [];
  11266. let currentOpenBracketCount = 0;
  11267. let currentOpenParensCount = 0;
  11268. let currentStringType = null;
  11269. for (let i = 0; i < path.length; i++) {
  11270. const char = path.charAt(i);
  11271. switch (state) {
  11272. case 0 /* MemberExpLexState.inMemberExp */:
  11273. if (char === '[') {
  11274. stateStack.push(state);
  11275. state = 1 /* MemberExpLexState.inBrackets */;
  11276. currentOpenBracketCount++;
  11277. }
  11278. else if (char === '(') {
  11279. stateStack.push(state);
  11280. state = 2 /* MemberExpLexState.inParens */;
  11281. currentOpenParensCount++;
  11282. }
  11283. else if (!(i === 0 ? validFirstIdentCharRE : validIdentCharRE).test(char)) {
  11284. return false;
  11285. }
  11286. break;
  11287. case 1 /* MemberExpLexState.inBrackets */:
  11288. if (char === `'` || char === `"` || char === '`') {
  11289. stateStack.push(state);
  11290. state = 3 /* MemberExpLexState.inString */;
  11291. currentStringType = char;
  11292. }
  11293. else if (char === `[`) {
  11294. currentOpenBracketCount++;
  11295. }
  11296. else if (char === `]`) {
  11297. if (!--currentOpenBracketCount) {
  11298. state = stateStack.pop();
  11299. }
  11300. }
  11301. break;
  11302. case 2 /* MemberExpLexState.inParens */:
  11303. if (char === `'` || char === `"` || char === '`') {
  11304. stateStack.push(state);
  11305. state = 3 /* MemberExpLexState.inString */;
  11306. currentStringType = char;
  11307. }
  11308. else if (char === `(`) {
  11309. currentOpenParensCount++;
  11310. }
  11311. else if (char === `)`) {
  11312. // if the exp ends as a call then it should not be considered valid
  11313. if (i === path.length - 1) {
  11314. return false;
  11315. }
  11316. if (!--currentOpenParensCount) {
  11317. state = stateStack.pop();
  11318. }
  11319. }
  11320. break;
  11321. case 3 /* MemberExpLexState.inString */:
  11322. if (char === currentStringType) {
  11323. state = stateStack.pop();
  11324. currentStringType = null;
  11325. }
  11326. break;
  11327. }
  11328. }
  11329. return !currentOpenBracketCount && !currentOpenParensCount;
  11330. };
  11331. const isMemberExpression = isMemberExpressionBrowser
  11332. ;
  11333. function getInnerRange(loc, offset, length) {
  11334. const source = loc.source.slice(offset, offset + length);
  11335. const newLoc = {
  11336. source,
  11337. start: advancePositionWithClone(loc.start, loc.source, offset),
  11338. end: loc.end
  11339. };
  11340. if (length != null) {
  11341. newLoc.end = advancePositionWithClone(loc.start, loc.source, offset + length);
  11342. }
  11343. return newLoc;
  11344. }
  11345. function advancePositionWithClone(pos, source, numberOfCharacters = source.length) {
  11346. return advancePositionWithMutation(extend({}, pos), source, numberOfCharacters);
  11347. }
  11348. // advance by mutation without cloning (for performance reasons), since this
  11349. // gets called a lot in the parser
  11350. function advancePositionWithMutation(pos, source, numberOfCharacters = source.length) {
  11351. let linesCount = 0;
  11352. let lastNewLinePos = -1;
  11353. for (let i = 0; i < numberOfCharacters; i++) {
  11354. if (source.charCodeAt(i) === 10 /* newline char code */) {
  11355. linesCount++;
  11356. lastNewLinePos = i;
  11357. }
  11358. }
  11359. pos.offset += numberOfCharacters;
  11360. pos.line += linesCount;
  11361. pos.column =
  11362. lastNewLinePos === -1
  11363. ? pos.column + numberOfCharacters
  11364. : numberOfCharacters - lastNewLinePos;
  11365. return pos;
  11366. }
  11367. function assert(condition, msg) {
  11368. /* istanbul ignore if */
  11369. if (!condition) {
  11370. throw new Error(msg || `unexpected compiler condition`);
  11371. }
  11372. }
  11373. function findDir(node, name, allowEmpty = false) {
  11374. for (let i = 0; i < node.props.length; i++) {
  11375. const p = node.props[i];
  11376. if (p.type === 7 /* NodeTypes.DIRECTIVE */ &&
  11377. (allowEmpty || p.exp) &&
  11378. (isString(name) ? p.name === name : name.test(p.name))) {
  11379. return p;
  11380. }
  11381. }
  11382. }
  11383. function findProp(node, name, dynamicOnly = false, allowEmpty = false) {
  11384. for (let i = 0; i < node.props.length; i++) {
  11385. const p = node.props[i];
  11386. if (p.type === 6 /* NodeTypes.ATTRIBUTE */) {
  11387. if (dynamicOnly)
  11388. continue;
  11389. if (p.name === name && (p.value || allowEmpty)) {
  11390. return p;
  11391. }
  11392. }
  11393. else if (p.name === 'bind' &&
  11394. (p.exp || allowEmpty) &&
  11395. isStaticArgOf(p.arg, name)) {
  11396. return p;
  11397. }
  11398. }
  11399. }
  11400. function isStaticArgOf(arg, name) {
  11401. return !!(arg && isStaticExp(arg) && arg.content === name);
  11402. }
  11403. function hasDynamicKeyVBind(node) {
  11404. return node.props.some(p => p.type === 7 /* NodeTypes.DIRECTIVE */ &&
  11405. p.name === 'bind' &&
  11406. (!p.arg || // v-bind="obj"
  11407. p.arg.type !== 4 /* NodeTypes.SIMPLE_EXPRESSION */ || // v-bind:[_ctx.foo]
  11408. !p.arg.isStatic) // v-bind:[foo]
  11409. );
  11410. }
  11411. function isText(node) {
  11412. return node.type === 5 /* NodeTypes.INTERPOLATION */ || node.type === 2 /* NodeTypes.TEXT */;
  11413. }
  11414. function isVSlot(p) {
  11415. return p.type === 7 /* NodeTypes.DIRECTIVE */ && p.name === 'slot';
  11416. }
  11417. function isTemplateNode(node) {
  11418. return (node.type === 1 /* NodeTypes.ELEMENT */ && node.tagType === 3 /* ElementTypes.TEMPLATE */);
  11419. }
  11420. function isSlotOutlet(node) {
  11421. return node.type === 1 /* NodeTypes.ELEMENT */ && node.tagType === 2 /* ElementTypes.SLOT */;
  11422. }
  11423. function getVNodeHelper(ssr, isComponent) {
  11424. return ssr || isComponent ? CREATE_VNODE : CREATE_ELEMENT_VNODE;
  11425. }
  11426. function getVNodeBlockHelper(ssr, isComponent) {
  11427. return ssr || isComponent ? CREATE_BLOCK : CREATE_ELEMENT_BLOCK;
  11428. }
  11429. const propsHelperSet = new Set([NORMALIZE_PROPS, GUARD_REACTIVE_PROPS]);
  11430. function getUnnormalizedProps(props, callPath = []) {
  11431. if (props &&
  11432. !isString(props) &&
  11433. props.type === 14 /* NodeTypes.JS_CALL_EXPRESSION */) {
  11434. const callee = props.callee;
  11435. if (!isString(callee) && propsHelperSet.has(callee)) {
  11436. return getUnnormalizedProps(props.arguments[0], callPath.concat(props));
  11437. }
  11438. }
  11439. return [props, callPath];
  11440. }
  11441. function injectProp(node, prop, context) {
  11442. let propsWithInjection;
  11443. /**
  11444. * 1. mergeProps(...)
  11445. * 2. toHandlers(...)
  11446. * 3. normalizeProps(...)
  11447. * 4. normalizeProps(guardReactiveProps(...))
  11448. *
  11449. * we need to get the real props before normalization
  11450. */
  11451. let props = node.type === 13 /* NodeTypes.VNODE_CALL */ ? node.props : node.arguments[2];
  11452. let callPath = [];
  11453. let parentCall;
  11454. if (props &&
  11455. !isString(props) &&
  11456. props.type === 14 /* NodeTypes.JS_CALL_EXPRESSION */) {
  11457. const ret = getUnnormalizedProps(props);
  11458. props = ret[0];
  11459. callPath = ret[1];
  11460. parentCall = callPath[callPath.length - 1];
  11461. }
  11462. if (props == null || isString(props)) {
  11463. propsWithInjection = createObjectExpression([prop]);
  11464. }
  11465. else if (props.type === 14 /* NodeTypes.JS_CALL_EXPRESSION */) {
  11466. // merged props... add ours
  11467. // only inject key to object literal if it's the first argument so that
  11468. // if doesn't override user provided keys
  11469. const first = props.arguments[0];
  11470. if (!isString(first) && first.type === 15 /* NodeTypes.JS_OBJECT_EXPRESSION */) {
  11471. // #6631
  11472. if (!hasProp(prop, first)) {
  11473. first.properties.unshift(prop);
  11474. }
  11475. }
  11476. else {
  11477. if (props.callee === TO_HANDLERS) {
  11478. // #2366
  11479. propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
  11480. createObjectExpression([prop]),
  11481. props
  11482. ]);
  11483. }
  11484. else {
  11485. props.arguments.unshift(createObjectExpression([prop]));
  11486. }
  11487. }
  11488. !propsWithInjection && (propsWithInjection = props);
  11489. }
  11490. else if (props.type === 15 /* NodeTypes.JS_OBJECT_EXPRESSION */) {
  11491. if (!hasProp(prop, props)) {
  11492. props.properties.unshift(prop);
  11493. }
  11494. propsWithInjection = props;
  11495. }
  11496. else {
  11497. // single v-bind with expression, return a merged replacement
  11498. propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
  11499. createObjectExpression([prop]),
  11500. props
  11501. ]);
  11502. // in the case of nested helper call, e.g. `normalizeProps(guardReactiveProps(props))`,
  11503. // it will be rewritten as `normalizeProps(mergeProps({ key: 0 }, props))`,
  11504. // the `guardReactiveProps` will no longer be needed
  11505. if (parentCall && parentCall.callee === GUARD_REACTIVE_PROPS) {
  11506. parentCall = callPath[callPath.length - 2];
  11507. }
  11508. }
  11509. if (node.type === 13 /* NodeTypes.VNODE_CALL */) {
  11510. if (parentCall) {
  11511. parentCall.arguments[0] = propsWithInjection;
  11512. }
  11513. else {
  11514. node.props = propsWithInjection;
  11515. }
  11516. }
  11517. else {
  11518. if (parentCall) {
  11519. parentCall.arguments[0] = propsWithInjection;
  11520. }
  11521. else {
  11522. node.arguments[2] = propsWithInjection;
  11523. }
  11524. }
  11525. }
  11526. // check existing key to avoid overriding user provided keys
  11527. function hasProp(prop, props) {
  11528. let result = false;
  11529. if (prop.key.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
  11530. const propKeyName = prop.key.content;
  11531. result = props.properties.some(p => p.key.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ &&
  11532. p.key.content === propKeyName);
  11533. }
  11534. return result;
  11535. }
  11536. function toValidAssetId(name, type) {
  11537. // see issue#4422, we need adding identifier on validAssetId if variable `name` has specific character
  11538. return `_${type}_${name.replace(/[^\w]/g, (searchValue, replaceValue) => {
  11539. return searchValue === '-' ? '_' : name.charCodeAt(replaceValue).toString();
  11540. })}`;
  11541. }
  11542. function getMemoedVNodeCall(node) {
  11543. if (node.type === 14 /* NodeTypes.JS_CALL_EXPRESSION */ && node.callee === WITH_MEMO) {
  11544. return node.arguments[1].returns;
  11545. }
  11546. else {
  11547. return node;
  11548. }
  11549. }
  11550. function makeBlock(node, { helper, removeHelper, inSSR }) {
  11551. if (!node.isBlock) {
  11552. node.isBlock = true;
  11553. removeHelper(getVNodeHelper(inSSR, node.isComponent));
  11554. helper(OPEN_BLOCK);
  11555. helper(getVNodeBlockHelper(inSSR, node.isComponent));
  11556. }
  11557. }
  11558. const deprecationData = {
  11559. ["COMPILER_IS_ON_ELEMENT" /* CompilerDeprecationTypes.COMPILER_IS_ON_ELEMENT */]: {
  11560. message: `Platform-native elements with "is" prop will no longer be ` +
  11561. `treated as components in Vue 3 unless the "is" value is explicitly ` +
  11562. `prefixed with "vue:".`,
  11563. link: `https://v3-migration.vuejs.org/breaking-changes/custom-elements-interop.html`
  11564. },
  11565. ["COMPILER_V_BIND_SYNC" /* CompilerDeprecationTypes.COMPILER_V_BIND_SYNC */]: {
  11566. message: key => `.sync modifier for v-bind has been removed. Use v-model with ` +
  11567. `argument instead. \`v-bind:${key}.sync\` should be changed to ` +
  11568. `\`v-model:${key}\`.`,
  11569. link: `https://v3-migration.vuejs.org/breaking-changes/v-model.html`
  11570. },
  11571. ["COMPILER_V_BIND_PROP" /* CompilerDeprecationTypes.COMPILER_V_BIND_PROP */]: {
  11572. message: `.prop modifier for v-bind has been removed and no longer necessary. ` +
  11573. `Vue 3 will automatically set a binding as DOM property when appropriate.`
  11574. },
  11575. ["COMPILER_V_BIND_OBJECT_ORDER" /* CompilerDeprecationTypes.COMPILER_V_BIND_OBJECT_ORDER */]: {
  11576. message: `v-bind="obj" usage is now order sensitive and behaves like JavaScript ` +
  11577. `object spread: it will now overwrite an existing non-mergeable attribute ` +
  11578. `that appears before v-bind in the case of conflict. ` +
  11579. `To retain 2.x behavior, move v-bind to make it the first attribute. ` +
  11580. `You can also suppress this warning if the usage is intended.`,
  11581. link: `https://v3-migration.vuejs.org/breaking-changes/v-bind.html`
  11582. },
  11583. ["COMPILER_V_ON_NATIVE" /* CompilerDeprecationTypes.COMPILER_V_ON_NATIVE */]: {
  11584. message: `.native modifier for v-on has been removed as is no longer necessary.`,
  11585. link: `https://v3-migration.vuejs.org/breaking-changes/v-on-native-modifier-removed.html`
  11586. },
  11587. ["COMPILER_V_IF_V_FOR_PRECEDENCE" /* CompilerDeprecationTypes.COMPILER_V_IF_V_FOR_PRECEDENCE */]: {
  11588. message: `v-if / v-for precedence when used on the same element has changed ` +
  11589. `in Vue 3: v-if now takes higher precedence and will no longer have ` +
  11590. `access to v-for scope variables. It is best to avoid the ambiguity ` +
  11591. `with <template> tags or use a computed property that filters v-for ` +
  11592. `data source.`,
  11593. link: `https://v3-migration.vuejs.org/breaking-changes/v-if-v-for.html`
  11594. },
  11595. ["COMPILER_NATIVE_TEMPLATE" /* CompilerDeprecationTypes.COMPILER_NATIVE_TEMPLATE */]: {
  11596. message: `<template> with no special directives will render as a native template ` +
  11597. `element instead of its inner content in Vue 3.`
  11598. },
  11599. ["COMPILER_INLINE_TEMPLATE" /* CompilerDeprecationTypes.COMPILER_INLINE_TEMPLATE */]: {
  11600. message: `"inline-template" has been removed in Vue 3.`,
  11601. link: `https://v3-migration.vuejs.org/breaking-changes/inline-template-attribute.html`
  11602. },
  11603. ["COMPILER_FILTER" /* CompilerDeprecationTypes.COMPILER_FILTERS */]: {
  11604. message: `filters have been removed in Vue 3. ` +
  11605. `The "|" symbol will be treated as native JavaScript bitwise OR operator. ` +
  11606. `Use method calls or computed properties instead.`,
  11607. link: `https://v3-migration.vuejs.org/breaking-changes/filters.html`
  11608. }
  11609. };
  11610. function getCompatValue(key, context) {
  11611. const config = context.options
  11612. ? context.options.compatConfig
  11613. : context.compatConfig;
  11614. const value = config && config[key];
  11615. if (key === 'MODE') {
  11616. return value || 3; // compiler defaults to v3 behavior
  11617. }
  11618. else {
  11619. return value;
  11620. }
  11621. }
  11622. function isCompatEnabled(key, context) {
  11623. const mode = getCompatValue('MODE', context);
  11624. const value = getCompatValue(key, context);
  11625. // in v3 mode, only enable if explicitly set to true
  11626. // otherwise enable for any non-false value
  11627. return mode === 3 ? value === true : value !== false;
  11628. }
  11629. function checkCompatEnabled(key, context, loc, ...args) {
  11630. const enabled = isCompatEnabled(key, context);
  11631. if (enabled) {
  11632. warnDeprecation(key, context, loc, ...args);
  11633. }
  11634. return enabled;
  11635. }
  11636. function warnDeprecation(key, context, loc, ...args) {
  11637. const val = getCompatValue(key, context);
  11638. if (val === 'suppress-warning') {
  11639. return;
  11640. }
  11641. const { message, link } = deprecationData[key];
  11642. const msg = `(deprecation ${key}) ${typeof message === 'function' ? message(...args) : message}${link ? `\n Details: ${link}` : ``}`;
  11643. const err = new SyntaxError(msg);
  11644. err.code = key;
  11645. if (loc)
  11646. err.loc = loc;
  11647. context.onWarn(err);
  11648. }
  11649. // The default decoder only provides escapes for characters reserved as part of
  11650. // the template syntax, and is only used if the custom renderer did not provide
  11651. // a platform-specific decoder.
  11652. const decodeRE = /&(gt|lt|amp|apos|quot);/g;
  11653. const decodeMap = {
  11654. gt: '>',
  11655. lt: '<',
  11656. amp: '&',
  11657. apos: "'",
  11658. quot: '"'
  11659. };
  11660. const defaultParserOptions = {
  11661. delimiters: [`{{`, `}}`],
  11662. getNamespace: () => 0 /* Namespaces.HTML */,
  11663. getTextMode: () => 0 /* TextModes.DATA */,
  11664. isVoidTag: NO,
  11665. isPreTag: NO,
  11666. isCustomElement: NO,
  11667. decodeEntities: (rawText) => rawText.replace(decodeRE, (_, p1) => decodeMap[p1]),
  11668. onError: defaultOnError,
  11669. onWarn: defaultOnWarn,
  11670. comments: true
  11671. };
  11672. function baseParse(content, options = {}) {
  11673. const context = createParserContext(content, options);
  11674. const start = getCursor(context);
  11675. return createRoot(parseChildren(context, 0 /* TextModes.DATA */, []), getSelection(context, start));
  11676. }
  11677. function createParserContext(content, rawOptions) {
  11678. const options = extend({}, defaultParserOptions);
  11679. let key;
  11680. for (key in rawOptions) {
  11681. // @ts-ignore
  11682. options[key] =
  11683. rawOptions[key] === undefined
  11684. ? defaultParserOptions[key]
  11685. : rawOptions[key];
  11686. }
  11687. return {
  11688. options,
  11689. column: 1,
  11690. line: 1,
  11691. offset: 0,
  11692. originalSource: content,
  11693. source: content,
  11694. inPre: false,
  11695. inVPre: false,
  11696. onWarn: options.onWarn
  11697. };
  11698. }
  11699. function parseChildren(context, mode, ancestors) {
  11700. const parent = last(ancestors);
  11701. const ns = parent ? parent.ns : 0 /* Namespaces.HTML */;
  11702. const nodes = [];
  11703. while (!isEnd(context, mode, ancestors)) {
  11704. const s = context.source;
  11705. let node = undefined;
  11706. if (mode === 0 /* TextModes.DATA */ || mode === 1 /* TextModes.RCDATA */) {
  11707. if (!context.inVPre && startsWith(s, context.options.delimiters[0])) {
  11708. // '{{'
  11709. node = parseInterpolation(context, mode);
  11710. }
  11711. else if (mode === 0 /* TextModes.DATA */ && s[0] === '<') {
  11712. // https://html.spec.whatwg.org/multipage/parsing.html#tag-open-state
  11713. if (s.length === 1) {
  11714. emitError(context, 5 /* ErrorCodes.EOF_BEFORE_TAG_NAME */, 1);
  11715. }
  11716. else if (s[1] === '!') {
  11717. // https://html.spec.whatwg.org/multipage/parsing.html#markup-declaration-open-state
  11718. if (startsWith(s, '<!--')) {
  11719. node = parseComment(context);
  11720. }
  11721. else if (startsWith(s, '<!DOCTYPE')) {
  11722. // Ignore DOCTYPE by a limitation.
  11723. node = parseBogusComment(context);
  11724. }
  11725. else if (startsWith(s, '<![CDATA[')) {
  11726. if (ns !== 0 /* Namespaces.HTML */) {
  11727. node = parseCDATA(context, ancestors);
  11728. }
  11729. else {
  11730. emitError(context, 1 /* ErrorCodes.CDATA_IN_HTML_CONTENT */);
  11731. node = parseBogusComment(context);
  11732. }
  11733. }
  11734. else {
  11735. emitError(context, 11 /* ErrorCodes.INCORRECTLY_OPENED_COMMENT */);
  11736. node = parseBogusComment(context);
  11737. }
  11738. }
  11739. else if (s[1] === '/') {
  11740. // https://html.spec.whatwg.org/multipage/parsing.html#end-tag-open-state
  11741. if (s.length === 2) {
  11742. emitError(context, 5 /* ErrorCodes.EOF_BEFORE_TAG_NAME */, 2);
  11743. }
  11744. else if (s[2] === '>') {
  11745. emitError(context, 14 /* ErrorCodes.MISSING_END_TAG_NAME */, 2);
  11746. advanceBy(context, 3);
  11747. continue;
  11748. }
  11749. else if (/[a-z]/i.test(s[2])) {
  11750. emitError(context, 23 /* ErrorCodes.X_INVALID_END_TAG */);
  11751. parseTag(context, 1 /* TagType.End */, parent);
  11752. continue;
  11753. }
  11754. else {
  11755. emitError(context, 12 /* ErrorCodes.INVALID_FIRST_CHARACTER_OF_TAG_NAME */, 2);
  11756. node = parseBogusComment(context);
  11757. }
  11758. }
  11759. else if (/[a-z]/i.test(s[1])) {
  11760. node = parseElement(context, ancestors);
  11761. }
  11762. else if (s[1] === '?') {
  11763. emitError(context, 21 /* ErrorCodes.UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME */, 1);
  11764. node = parseBogusComment(context);
  11765. }
  11766. else {
  11767. emitError(context, 12 /* ErrorCodes.INVALID_FIRST_CHARACTER_OF_TAG_NAME */, 1);
  11768. }
  11769. }
  11770. }
  11771. if (!node) {
  11772. node = parseText(context, mode);
  11773. }
  11774. if (isArray(node)) {
  11775. for (let i = 0; i < node.length; i++) {
  11776. pushNode(nodes, node[i]);
  11777. }
  11778. }
  11779. else {
  11780. pushNode(nodes, node);
  11781. }
  11782. }
  11783. // Whitespace handling strategy like v2
  11784. let removedWhitespace = false;
  11785. if (mode !== 2 /* TextModes.RAWTEXT */ && mode !== 1 /* TextModes.RCDATA */) {
  11786. const shouldCondense = context.options.whitespace !== 'preserve';
  11787. for (let i = 0; i < nodes.length; i++) {
  11788. const node = nodes[i];
  11789. if (node.type === 2 /* NodeTypes.TEXT */) {
  11790. if (!context.inPre) {
  11791. if (!/[^\t\r\n\f ]/.test(node.content)) {
  11792. const prev = nodes[i - 1];
  11793. const next = nodes[i + 1];
  11794. // Remove if:
  11795. // - the whitespace is the first or last node, or:
  11796. // - (condense mode) the whitespace is between twos comments, or:
  11797. // - (condense mode) the whitespace is between comment and element, or:
  11798. // - (condense mode) the whitespace is between two elements AND contains newline
  11799. if (!prev ||
  11800. !next ||
  11801. (shouldCondense &&
  11802. ((prev.type === 3 /* NodeTypes.COMMENT */ &&
  11803. next.type === 3 /* NodeTypes.COMMENT */) ||
  11804. (prev.type === 3 /* NodeTypes.COMMENT */ &&
  11805. next.type === 1 /* NodeTypes.ELEMENT */) ||
  11806. (prev.type === 1 /* NodeTypes.ELEMENT */ &&
  11807. next.type === 3 /* NodeTypes.COMMENT */) ||
  11808. (prev.type === 1 /* NodeTypes.ELEMENT */ &&
  11809. next.type === 1 /* NodeTypes.ELEMENT */ &&
  11810. /[\r\n]/.test(node.content))))) {
  11811. removedWhitespace = true;
  11812. nodes[i] = null;
  11813. }
  11814. else {
  11815. // Otherwise, the whitespace is condensed into a single space
  11816. node.content = ' ';
  11817. }
  11818. }
  11819. else if (shouldCondense) {
  11820. // in condense mode, consecutive whitespaces in text are condensed
  11821. // down to a single space.
  11822. node.content = node.content.replace(/[\t\r\n\f ]+/g, ' ');
  11823. }
  11824. }
  11825. else {
  11826. // #6410 normalize windows newlines in <pre>:
  11827. // in SSR, browsers normalize server-rendered \r\n into a single \n
  11828. // in the DOM
  11829. node.content = node.content.replace(/\r\n/g, '\n');
  11830. }
  11831. }
  11832. // Remove comment nodes if desired by configuration.
  11833. else if (node.type === 3 /* NodeTypes.COMMENT */ && !context.options.comments) {
  11834. removedWhitespace = true;
  11835. nodes[i] = null;
  11836. }
  11837. }
  11838. if (context.inPre && parent && context.options.isPreTag(parent.tag)) {
  11839. // remove leading newline per html spec
  11840. // https://html.spec.whatwg.org/multipage/grouping-content.html#the-pre-element
  11841. const first = nodes[0];
  11842. if (first && first.type === 2 /* NodeTypes.TEXT */) {
  11843. first.content = first.content.replace(/^\r?\n/, '');
  11844. }
  11845. }
  11846. }
  11847. return removedWhitespace ? nodes.filter(Boolean) : nodes;
  11848. }
  11849. function pushNode(nodes, node) {
  11850. if (node.type === 2 /* NodeTypes.TEXT */) {
  11851. const prev = last(nodes);
  11852. // Merge if both this and the previous node are text and those are
  11853. // consecutive. This happens for cases like "a < b".
  11854. if (prev &&
  11855. prev.type === 2 /* NodeTypes.TEXT */ &&
  11856. prev.loc.end.offset === node.loc.start.offset) {
  11857. prev.content += node.content;
  11858. prev.loc.end = node.loc.end;
  11859. prev.loc.source += node.loc.source;
  11860. return;
  11861. }
  11862. }
  11863. nodes.push(node);
  11864. }
  11865. function parseCDATA(context, ancestors) {
  11866. advanceBy(context, 9);
  11867. const nodes = parseChildren(context, 3 /* TextModes.CDATA */, ancestors);
  11868. if (context.source.length === 0) {
  11869. emitError(context, 6 /* ErrorCodes.EOF_IN_CDATA */);
  11870. }
  11871. else {
  11872. advanceBy(context, 3);
  11873. }
  11874. return nodes;
  11875. }
  11876. function parseComment(context) {
  11877. const start = getCursor(context);
  11878. let content;
  11879. // Regular comment.
  11880. const match = /--(\!)?>/.exec(context.source);
  11881. if (!match) {
  11882. content = context.source.slice(4);
  11883. advanceBy(context, context.source.length);
  11884. emitError(context, 7 /* ErrorCodes.EOF_IN_COMMENT */);
  11885. }
  11886. else {
  11887. if (match.index <= 3) {
  11888. emitError(context, 0 /* ErrorCodes.ABRUPT_CLOSING_OF_EMPTY_COMMENT */);
  11889. }
  11890. if (match[1]) {
  11891. emitError(context, 10 /* ErrorCodes.INCORRECTLY_CLOSED_COMMENT */);
  11892. }
  11893. content = context.source.slice(4, match.index);
  11894. // Advancing with reporting nested comments.
  11895. const s = context.source.slice(0, match.index);
  11896. let prevIndex = 1, nestedIndex = 0;
  11897. while ((nestedIndex = s.indexOf('<!--', prevIndex)) !== -1) {
  11898. advanceBy(context, nestedIndex - prevIndex + 1);
  11899. if (nestedIndex + 4 < s.length) {
  11900. emitError(context, 16 /* ErrorCodes.NESTED_COMMENT */);
  11901. }
  11902. prevIndex = nestedIndex + 1;
  11903. }
  11904. advanceBy(context, match.index + match[0].length - prevIndex + 1);
  11905. }
  11906. return {
  11907. type: 3 /* NodeTypes.COMMENT */,
  11908. content,
  11909. loc: getSelection(context, start)
  11910. };
  11911. }
  11912. function parseBogusComment(context) {
  11913. const start = getCursor(context);
  11914. const contentStart = context.source[1] === '?' ? 1 : 2;
  11915. let content;
  11916. const closeIndex = context.source.indexOf('>');
  11917. if (closeIndex === -1) {
  11918. content = context.source.slice(contentStart);
  11919. advanceBy(context, context.source.length);
  11920. }
  11921. else {
  11922. content = context.source.slice(contentStart, closeIndex);
  11923. advanceBy(context, closeIndex + 1);
  11924. }
  11925. return {
  11926. type: 3 /* NodeTypes.COMMENT */,
  11927. content,
  11928. loc: getSelection(context, start)
  11929. };
  11930. }
  11931. function parseElement(context, ancestors) {
  11932. // Start tag.
  11933. const wasInPre = context.inPre;
  11934. const wasInVPre = context.inVPre;
  11935. const parent = last(ancestors);
  11936. const element = parseTag(context, 0 /* TagType.Start */, parent);
  11937. const isPreBoundary = context.inPre && !wasInPre;
  11938. const isVPreBoundary = context.inVPre && !wasInVPre;
  11939. if (element.isSelfClosing || context.options.isVoidTag(element.tag)) {
  11940. // #4030 self-closing <pre> tag
  11941. if (isPreBoundary) {
  11942. context.inPre = false;
  11943. }
  11944. if (isVPreBoundary) {
  11945. context.inVPre = false;
  11946. }
  11947. return element;
  11948. }
  11949. // Children.
  11950. ancestors.push(element);
  11951. const mode = context.options.getTextMode(element, parent);
  11952. const children = parseChildren(context, mode, ancestors);
  11953. ancestors.pop();
  11954. element.children = children;
  11955. // End tag.
  11956. if (startsWithEndTagOpen(context.source, element.tag)) {
  11957. parseTag(context, 1 /* TagType.End */, parent);
  11958. }
  11959. else {
  11960. emitError(context, 24 /* ErrorCodes.X_MISSING_END_TAG */, 0, element.loc.start);
  11961. if (context.source.length === 0 && element.tag.toLowerCase() === 'script') {
  11962. const first = children[0];
  11963. if (first && startsWith(first.loc.source, '<!--')) {
  11964. emitError(context, 8 /* ErrorCodes.EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT */);
  11965. }
  11966. }
  11967. }
  11968. element.loc = getSelection(context, element.loc.start);
  11969. if (isPreBoundary) {
  11970. context.inPre = false;
  11971. }
  11972. if (isVPreBoundary) {
  11973. context.inVPre = false;
  11974. }
  11975. return element;
  11976. }
  11977. const isSpecialTemplateDirective = /*#__PURE__*/ makeMap(`if,else,else-if,for,slot`);
  11978. function parseTag(context, type, parent) {
  11979. // Tag open.
  11980. const start = getCursor(context);
  11981. const match = /^<\/?([a-z][^\t\r\n\f />]*)/i.exec(context.source);
  11982. const tag = match[1];
  11983. const ns = context.options.getNamespace(tag, parent);
  11984. advanceBy(context, match[0].length);
  11985. advanceSpaces(context);
  11986. // save current state in case we need to re-parse attributes with v-pre
  11987. const cursor = getCursor(context);
  11988. const currentSource = context.source;
  11989. // check <pre> tag
  11990. if (context.options.isPreTag(tag)) {
  11991. context.inPre = true;
  11992. }
  11993. // Attributes.
  11994. let props = parseAttributes(context, type);
  11995. // check v-pre
  11996. if (type === 0 /* TagType.Start */ &&
  11997. !context.inVPre &&
  11998. props.some(p => p.type === 7 /* NodeTypes.DIRECTIVE */ && p.name === 'pre')) {
  11999. context.inVPre = true;
  12000. // reset context
  12001. extend(context, cursor);
  12002. context.source = currentSource;
  12003. // re-parse attrs and filter out v-pre itself
  12004. props = parseAttributes(context, type).filter(p => p.name !== 'v-pre');
  12005. }
  12006. // Tag close.
  12007. let isSelfClosing = false;
  12008. if (context.source.length === 0) {
  12009. emitError(context, 9 /* ErrorCodes.EOF_IN_TAG */);
  12010. }
  12011. else {
  12012. isSelfClosing = startsWith(context.source, '/>');
  12013. if (type === 1 /* TagType.End */ && isSelfClosing) {
  12014. emitError(context, 4 /* ErrorCodes.END_TAG_WITH_TRAILING_SOLIDUS */);
  12015. }
  12016. advanceBy(context, isSelfClosing ? 2 : 1);
  12017. }
  12018. if (type === 1 /* TagType.End */) {
  12019. return;
  12020. }
  12021. let tagType = 0 /* ElementTypes.ELEMENT */;
  12022. if (!context.inVPre) {
  12023. if (tag === 'slot') {
  12024. tagType = 2 /* ElementTypes.SLOT */;
  12025. }
  12026. else if (tag === 'template') {
  12027. if (props.some(p => p.type === 7 /* NodeTypes.DIRECTIVE */ && isSpecialTemplateDirective(p.name))) {
  12028. tagType = 3 /* ElementTypes.TEMPLATE */;
  12029. }
  12030. }
  12031. else if (isComponent(tag, props, context)) {
  12032. tagType = 1 /* ElementTypes.COMPONENT */;
  12033. }
  12034. }
  12035. return {
  12036. type: 1 /* NodeTypes.ELEMENT */,
  12037. ns,
  12038. tag,
  12039. tagType,
  12040. props,
  12041. isSelfClosing,
  12042. children: [],
  12043. loc: getSelection(context, start),
  12044. codegenNode: undefined // to be created during transform phase
  12045. };
  12046. }
  12047. function isComponent(tag, props, context) {
  12048. const options = context.options;
  12049. if (options.isCustomElement(tag)) {
  12050. return false;
  12051. }
  12052. if (tag === 'component' ||
  12053. /^[A-Z]/.test(tag) ||
  12054. isCoreComponent(tag) ||
  12055. (options.isBuiltInComponent && options.isBuiltInComponent(tag)) ||
  12056. (options.isNativeTag && !options.isNativeTag(tag))) {
  12057. return true;
  12058. }
  12059. // at this point the tag should be a native tag, but check for potential "is"
  12060. // casting
  12061. for (let i = 0; i < props.length; i++) {
  12062. const p = props[i];
  12063. if (p.type === 6 /* NodeTypes.ATTRIBUTE */) {
  12064. if (p.name === 'is' && p.value) {
  12065. if (p.value.content.startsWith('vue:')) {
  12066. return true;
  12067. }
  12068. }
  12069. }
  12070. else {
  12071. // directive
  12072. // v-is (TODO Deprecate)
  12073. if (p.name === 'is') {
  12074. return true;
  12075. }
  12076. else if (
  12077. // :is on plain element - only treat as component in compat mode
  12078. p.name === 'bind' &&
  12079. isStaticArgOf(p.arg, 'is') &&
  12080. false &&
  12081. checkCompatEnabled("COMPILER_IS_ON_ELEMENT" /* CompilerDeprecationTypes.COMPILER_IS_ON_ELEMENT */, context, p.loc)) {
  12082. return true;
  12083. }
  12084. }
  12085. }
  12086. }
  12087. function parseAttributes(context, type) {
  12088. const props = [];
  12089. const attributeNames = new Set();
  12090. while (context.source.length > 0 &&
  12091. !startsWith(context.source, '>') &&
  12092. !startsWith(context.source, '/>')) {
  12093. if (startsWith(context.source, '/')) {
  12094. emitError(context, 22 /* ErrorCodes.UNEXPECTED_SOLIDUS_IN_TAG */);
  12095. advanceBy(context, 1);
  12096. advanceSpaces(context);
  12097. continue;
  12098. }
  12099. if (type === 1 /* TagType.End */) {
  12100. emitError(context, 3 /* ErrorCodes.END_TAG_WITH_ATTRIBUTES */);
  12101. }
  12102. const attr = parseAttribute(context, attributeNames);
  12103. // Trim whitespace between class
  12104. // https://github.com/vuejs/core/issues/4251
  12105. if (attr.type === 6 /* NodeTypes.ATTRIBUTE */ &&
  12106. attr.value &&
  12107. attr.name === 'class') {
  12108. attr.value.content = attr.value.content.replace(/\s+/g, ' ').trim();
  12109. }
  12110. if (type === 0 /* TagType.Start */) {
  12111. props.push(attr);
  12112. }
  12113. if (/^[^\t\r\n\f />]/.test(context.source)) {
  12114. emitError(context, 15 /* ErrorCodes.MISSING_WHITESPACE_BETWEEN_ATTRIBUTES */);
  12115. }
  12116. advanceSpaces(context);
  12117. }
  12118. return props;
  12119. }
  12120. function parseAttribute(context, nameSet) {
  12121. // Name.
  12122. const start = getCursor(context);
  12123. const match = /^[^\t\r\n\f />][^\t\r\n\f />=]*/.exec(context.source);
  12124. const name = match[0];
  12125. if (nameSet.has(name)) {
  12126. emitError(context, 2 /* ErrorCodes.DUPLICATE_ATTRIBUTE */);
  12127. }
  12128. nameSet.add(name);
  12129. if (name[0] === '=') {
  12130. emitError(context, 19 /* ErrorCodes.UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME */);
  12131. }
  12132. {
  12133. const pattern = /["'<]/g;
  12134. let m;
  12135. while ((m = pattern.exec(name))) {
  12136. emitError(context, 17 /* ErrorCodes.UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME */, m.index);
  12137. }
  12138. }
  12139. advanceBy(context, name.length);
  12140. // Value
  12141. let value = undefined;
  12142. if (/^[\t\r\n\f ]*=/.test(context.source)) {
  12143. advanceSpaces(context);
  12144. advanceBy(context, 1);
  12145. advanceSpaces(context);
  12146. value = parseAttributeValue(context);
  12147. if (!value) {
  12148. emitError(context, 13 /* ErrorCodes.MISSING_ATTRIBUTE_VALUE */);
  12149. }
  12150. }
  12151. const loc = getSelection(context, start);
  12152. if (!context.inVPre && /^(v-[A-Za-z0-9-]|:|\.|@|#)/.test(name)) {
  12153. const match = /(?:^v-([a-z0-9-]+))?(?:(?::|^\.|^@|^#)(\[[^\]]+\]|[^\.]+))?(.+)?$/i.exec(name);
  12154. let isPropShorthand = startsWith(name, '.');
  12155. let dirName = match[1] ||
  12156. (isPropShorthand || startsWith(name, ':')
  12157. ? 'bind'
  12158. : startsWith(name, '@')
  12159. ? 'on'
  12160. : 'slot');
  12161. let arg;
  12162. if (match[2]) {
  12163. const isSlot = dirName === 'slot';
  12164. const startOffset = name.lastIndexOf(match[2]);
  12165. const loc = getSelection(context, getNewPosition(context, start, startOffset), getNewPosition(context, start, startOffset + match[2].length + ((isSlot && match[3]) || '').length));
  12166. let content = match[2];
  12167. let isStatic = true;
  12168. if (content.startsWith('[')) {
  12169. isStatic = false;
  12170. if (!content.endsWith(']')) {
  12171. emitError(context, 27 /* ErrorCodes.X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END */);
  12172. content = content.slice(1);
  12173. }
  12174. else {
  12175. content = content.slice(1, content.length - 1);
  12176. }
  12177. }
  12178. else if (isSlot) {
  12179. // #1241 special case for v-slot: vuetify relies extensively on slot
  12180. // names containing dots. v-slot doesn't have any modifiers and Vue 2.x
  12181. // supports such usage so we are keeping it consistent with 2.x.
  12182. content += match[3] || '';
  12183. }
  12184. arg = {
  12185. type: 4 /* NodeTypes.SIMPLE_EXPRESSION */,
  12186. content,
  12187. isStatic,
  12188. constType: isStatic
  12189. ? 3 /* ConstantTypes.CAN_STRINGIFY */
  12190. : 0 /* ConstantTypes.NOT_CONSTANT */,
  12191. loc
  12192. };
  12193. }
  12194. if (value && value.isQuoted) {
  12195. const valueLoc = value.loc;
  12196. valueLoc.start.offset++;
  12197. valueLoc.start.column++;
  12198. valueLoc.end = advancePositionWithClone(valueLoc.start, value.content);
  12199. valueLoc.source = valueLoc.source.slice(1, -1);
  12200. }
  12201. const modifiers = match[3] ? match[3].slice(1).split('.') : [];
  12202. if (isPropShorthand)
  12203. modifiers.push('prop');
  12204. return {
  12205. type: 7 /* NodeTypes.DIRECTIVE */,
  12206. name: dirName,
  12207. exp: value && {
  12208. type: 4 /* NodeTypes.SIMPLE_EXPRESSION */,
  12209. content: value.content,
  12210. isStatic: false,
  12211. // Treat as non-constant by default. This can be potentially set to
  12212. // other values by `transformExpression` to make it eligible for hoisting.
  12213. constType: 0 /* ConstantTypes.NOT_CONSTANT */,
  12214. loc: value.loc
  12215. },
  12216. arg,
  12217. modifiers,
  12218. loc
  12219. };
  12220. }
  12221. // missing directive name or illegal directive name
  12222. if (!context.inVPre && startsWith(name, 'v-')) {
  12223. emitError(context, 26 /* ErrorCodes.X_MISSING_DIRECTIVE_NAME */);
  12224. }
  12225. return {
  12226. type: 6 /* NodeTypes.ATTRIBUTE */,
  12227. name,
  12228. value: value && {
  12229. type: 2 /* NodeTypes.TEXT */,
  12230. content: value.content,
  12231. loc: value.loc
  12232. },
  12233. loc
  12234. };
  12235. }
  12236. function parseAttributeValue(context) {
  12237. const start = getCursor(context);
  12238. let content;
  12239. const quote = context.source[0];
  12240. const isQuoted = quote === `"` || quote === `'`;
  12241. if (isQuoted) {
  12242. // Quoted value.
  12243. advanceBy(context, 1);
  12244. const endIndex = context.source.indexOf(quote);
  12245. if (endIndex === -1) {
  12246. content = parseTextData(context, context.source.length, 4 /* TextModes.ATTRIBUTE_VALUE */);
  12247. }
  12248. else {
  12249. content = parseTextData(context, endIndex, 4 /* TextModes.ATTRIBUTE_VALUE */);
  12250. advanceBy(context, 1);
  12251. }
  12252. }
  12253. else {
  12254. // Unquoted
  12255. const match = /^[^\t\r\n\f >]+/.exec(context.source);
  12256. if (!match) {
  12257. return undefined;
  12258. }
  12259. const unexpectedChars = /["'<=`]/g;
  12260. let m;
  12261. while ((m = unexpectedChars.exec(match[0]))) {
  12262. emitError(context, 18 /* ErrorCodes.UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE */, m.index);
  12263. }
  12264. content = parseTextData(context, match[0].length, 4 /* TextModes.ATTRIBUTE_VALUE */);
  12265. }
  12266. return { content, isQuoted, loc: getSelection(context, start) };
  12267. }
  12268. function parseInterpolation(context, mode) {
  12269. const [open, close] = context.options.delimiters;
  12270. const closeIndex = context.source.indexOf(close, open.length);
  12271. if (closeIndex === -1) {
  12272. emitError(context, 25 /* ErrorCodes.X_MISSING_INTERPOLATION_END */);
  12273. return undefined;
  12274. }
  12275. const start = getCursor(context);
  12276. advanceBy(context, open.length);
  12277. const innerStart = getCursor(context);
  12278. const innerEnd = getCursor(context);
  12279. const rawContentLength = closeIndex - open.length;
  12280. const rawContent = context.source.slice(0, rawContentLength);
  12281. const preTrimContent = parseTextData(context, rawContentLength, mode);
  12282. const content = preTrimContent.trim();
  12283. const startOffset = preTrimContent.indexOf(content);
  12284. if (startOffset > 0) {
  12285. advancePositionWithMutation(innerStart, rawContent, startOffset);
  12286. }
  12287. const endOffset = rawContentLength - (preTrimContent.length - content.length - startOffset);
  12288. advancePositionWithMutation(innerEnd, rawContent, endOffset);
  12289. advanceBy(context, close.length);
  12290. return {
  12291. type: 5 /* NodeTypes.INTERPOLATION */,
  12292. content: {
  12293. type: 4 /* NodeTypes.SIMPLE_EXPRESSION */,
  12294. isStatic: false,
  12295. // Set `isConstant` to false by default and will decide in transformExpression
  12296. constType: 0 /* ConstantTypes.NOT_CONSTANT */,
  12297. content,
  12298. loc: getSelection(context, innerStart, innerEnd)
  12299. },
  12300. loc: getSelection(context, start)
  12301. };
  12302. }
  12303. function parseText(context, mode) {
  12304. const endTokens = mode === 3 /* TextModes.CDATA */ ? [']]>'] : ['<', context.options.delimiters[0]];
  12305. let endIndex = context.source.length;
  12306. for (let i = 0; i < endTokens.length; i++) {
  12307. const index = context.source.indexOf(endTokens[i], 1);
  12308. if (index !== -1 && endIndex > index) {
  12309. endIndex = index;
  12310. }
  12311. }
  12312. const start = getCursor(context);
  12313. const content = parseTextData(context, endIndex, mode);
  12314. return {
  12315. type: 2 /* NodeTypes.TEXT */,
  12316. content,
  12317. loc: getSelection(context, start)
  12318. };
  12319. }
  12320. /**
  12321. * Get text data with a given length from the current location.
  12322. * This translates HTML entities in the text data.
  12323. */
  12324. function parseTextData(context, length, mode) {
  12325. const rawText = context.source.slice(0, length);
  12326. advanceBy(context, length);
  12327. if (mode === 2 /* TextModes.RAWTEXT */ ||
  12328. mode === 3 /* TextModes.CDATA */ ||
  12329. !rawText.includes('&')) {
  12330. return rawText;
  12331. }
  12332. else {
  12333. // DATA or RCDATA containing "&"". Entity decoding required.
  12334. return context.options.decodeEntities(rawText, mode === 4 /* TextModes.ATTRIBUTE_VALUE */);
  12335. }
  12336. }
  12337. function getCursor(context) {
  12338. const { column, line, offset } = context;
  12339. return { column, line, offset };
  12340. }
  12341. function getSelection(context, start, end) {
  12342. end = end || getCursor(context);
  12343. return {
  12344. start,
  12345. end,
  12346. source: context.originalSource.slice(start.offset, end.offset)
  12347. };
  12348. }
  12349. function last(xs) {
  12350. return xs[xs.length - 1];
  12351. }
  12352. function startsWith(source, searchString) {
  12353. return source.startsWith(searchString);
  12354. }
  12355. function advanceBy(context, numberOfCharacters) {
  12356. const { source } = context;
  12357. advancePositionWithMutation(context, source, numberOfCharacters);
  12358. context.source = source.slice(numberOfCharacters);
  12359. }
  12360. function advanceSpaces(context) {
  12361. const match = /^[\t\r\n\f ]+/.exec(context.source);
  12362. if (match) {
  12363. advanceBy(context, match[0].length);
  12364. }
  12365. }
  12366. function getNewPosition(context, start, numberOfCharacters) {
  12367. return advancePositionWithClone(start, context.originalSource.slice(start.offset, numberOfCharacters), numberOfCharacters);
  12368. }
  12369. function emitError(context, code, offset, loc = getCursor(context)) {
  12370. if (offset) {
  12371. loc.offset += offset;
  12372. loc.column += offset;
  12373. }
  12374. context.options.onError(createCompilerError(code, {
  12375. start: loc,
  12376. end: loc,
  12377. source: ''
  12378. }));
  12379. }
  12380. function isEnd(context, mode, ancestors) {
  12381. const s = context.source;
  12382. switch (mode) {
  12383. case 0 /* TextModes.DATA */:
  12384. if (startsWith(s, '</')) {
  12385. // TODO: probably bad performance
  12386. for (let i = ancestors.length - 1; i >= 0; --i) {
  12387. if (startsWithEndTagOpen(s, ancestors[i].tag)) {
  12388. return true;
  12389. }
  12390. }
  12391. }
  12392. break;
  12393. case 1 /* TextModes.RCDATA */:
  12394. case 2 /* TextModes.RAWTEXT */: {
  12395. const parent = last(ancestors);
  12396. if (parent && startsWithEndTagOpen(s, parent.tag)) {
  12397. return true;
  12398. }
  12399. break;
  12400. }
  12401. case 3 /* TextModes.CDATA */:
  12402. if (startsWith(s, ']]>')) {
  12403. return true;
  12404. }
  12405. break;
  12406. }
  12407. return !s;
  12408. }
  12409. function startsWithEndTagOpen(source, tag) {
  12410. return (startsWith(source, '</') &&
  12411. source.slice(2, 2 + tag.length).toLowerCase() === tag.toLowerCase() &&
  12412. /[\t\r\n\f />]/.test(source[2 + tag.length] || '>'));
  12413. }
  12414. function hoistStatic(root, context) {
  12415. walk(root, context,
  12416. // Root node is unfortunately non-hoistable due to potential parent
  12417. // fallthrough attributes.
  12418. isSingleElementRoot(root, root.children[0]));
  12419. }
  12420. function isSingleElementRoot(root, child) {
  12421. const { children } = root;
  12422. return (children.length === 1 &&
  12423. child.type === 1 /* NodeTypes.ELEMENT */ &&
  12424. !isSlotOutlet(child));
  12425. }
  12426. function walk(node, context, doNotHoistNode = false) {
  12427. const { children } = node;
  12428. const originalCount = children.length;
  12429. let hoistedCount = 0;
  12430. for (let i = 0; i < children.length; i++) {
  12431. const child = children[i];
  12432. // only plain elements & text calls are eligible for hoisting.
  12433. if (child.type === 1 /* NodeTypes.ELEMENT */ &&
  12434. child.tagType === 0 /* ElementTypes.ELEMENT */) {
  12435. const constantType = doNotHoistNode
  12436. ? 0 /* ConstantTypes.NOT_CONSTANT */
  12437. : getConstantType(child, context);
  12438. if (constantType > 0 /* ConstantTypes.NOT_CONSTANT */) {
  12439. if (constantType >= 2 /* ConstantTypes.CAN_HOIST */) {
  12440. child.codegenNode.patchFlag =
  12441. -1 /* PatchFlags.HOISTED */ + (` /* HOISTED */` );
  12442. child.codegenNode = context.hoist(child.codegenNode);
  12443. hoistedCount++;
  12444. continue;
  12445. }
  12446. }
  12447. else {
  12448. // node may contain dynamic children, but its props may be eligible for
  12449. // hoisting.
  12450. const codegenNode = child.codegenNode;
  12451. if (codegenNode.type === 13 /* NodeTypes.VNODE_CALL */) {
  12452. const flag = getPatchFlag(codegenNode);
  12453. if ((!flag ||
  12454. flag === 512 /* PatchFlags.NEED_PATCH */ ||
  12455. flag === 1 /* PatchFlags.TEXT */) &&
  12456. getGeneratedPropsConstantType(child, context) >=
  12457. 2 /* ConstantTypes.CAN_HOIST */) {
  12458. const props = getNodeProps(child);
  12459. if (props) {
  12460. codegenNode.props = context.hoist(props);
  12461. }
  12462. }
  12463. if (codegenNode.dynamicProps) {
  12464. codegenNode.dynamicProps = context.hoist(codegenNode.dynamicProps);
  12465. }
  12466. }
  12467. }
  12468. }
  12469. // walk further
  12470. if (child.type === 1 /* NodeTypes.ELEMENT */) {
  12471. const isComponent = child.tagType === 1 /* ElementTypes.COMPONENT */;
  12472. if (isComponent) {
  12473. context.scopes.vSlot++;
  12474. }
  12475. walk(child, context);
  12476. if (isComponent) {
  12477. context.scopes.vSlot--;
  12478. }
  12479. }
  12480. else if (child.type === 11 /* NodeTypes.FOR */) {
  12481. // Do not hoist v-for single child because it has to be a block
  12482. walk(child, context, child.children.length === 1);
  12483. }
  12484. else if (child.type === 9 /* NodeTypes.IF */) {
  12485. for (let i = 0; i < child.branches.length; i++) {
  12486. // Do not hoist v-if single child because it has to be a block
  12487. walk(child.branches[i], context, child.branches[i].children.length === 1);
  12488. }
  12489. }
  12490. }
  12491. if (hoistedCount && context.transformHoist) {
  12492. context.transformHoist(children, context, node);
  12493. }
  12494. // all children were hoisted - the entire children array is hoistable.
  12495. if (hoistedCount &&
  12496. hoistedCount === originalCount &&
  12497. node.type === 1 /* NodeTypes.ELEMENT */ &&
  12498. node.tagType === 0 /* ElementTypes.ELEMENT */ &&
  12499. node.codegenNode &&
  12500. node.codegenNode.type === 13 /* NodeTypes.VNODE_CALL */ &&
  12501. isArray(node.codegenNode.children)) {
  12502. node.codegenNode.children = context.hoist(createArrayExpression(node.codegenNode.children));
  12503. }
  12504. }
  12505. function getConstantType(node, context) {
  12506. const { constantCache } = context;
  12507. switch (node.type) {
  12508. case 1 /* NodeTypes.ELEMENT */:
  12509. if (node.tagType !== 0 /* ElementTypes.ELEMENT */) {
  12510. return 0 /* ConstantTypes.NOT_CONSTANT */;
  12511. }
  12512. const cached = constantCache.get(node);
  12513. if (cached !== undefined) {
  12514. return cached;
  12515. }
  12516. const codegenNode = node.codegenNode;
  12517. if (codegenNode.type !== 13 /* NodeTypes.VNODE_CALL */) {
  12518. return 0 /* ConstantTypes.NOT_CONSTANT */;
  12519. }
  12520. if (codegenNode.isBlock &&
  12521. node.tag !== 'svg' &&
  12522. node.tag !== 'foreignObject') {
  12523. return 0 /* ConstantTypes.NOT_CONSTANT */;
  12524. }
  12525. const flag = getPatchFlag(codegenNode);
  12526. if (!flag) {
  12527. let returnType = 3 /* ConstantTypes.CAN_STRINGIFY */;
  12528. // Element itself has no patch flag. However we still need to check:
  12529. // 1. Even for a node with no patch flag, it is possible for it to contain
  12530. // non-hoistable expressions that refers to scope variables, e.g. compiler
  12531. // injected keys or cached event handlers. Therefore we need to always
  12532. // check the codegenNode's props to be sure.
  12533. const generatedPropsType = getGeneratedPropsConstantType(node, context);
  12534. if (generatedPropsType === 0 /* ConstantTypes.NOT_CONSTANT */) {
  12535. constantCache.set(node, 0 /* ConstantTypes.NOT_CONSTANT */);
  12536. return 0 /* ConstantTypes.NOT_CONSTANT */;
  12537. }
  12538. if (generatedPropsType < returnType) {
  12539. returnType = generatedPropsType;
  12540. }
  12541. // 2. its children.
  12542. for (let i = 0; i < node.children.length; i++) {
  12543. const childType = getConstantType(node.children[i], context);
  12544. if (childType === 0 /* ConstantTypes.NOT_CONSTANT */) {
  12545. constantCache.set(node, 0 /* ConstantTypes.NOT_CONSTANT */);
  12546. return 0 /* ConstantTypes.NOT_CONSTANT */;
  12547. }
  12548. if (childType < returnType) {
  12549. returnType = childType;
  12550. }
  12551. }
  12552. // 3. if the type is not already CAN_SKIP_PATCH which is the lowest non-0
  12553. // type, check if any of the props can cause the type to be lowered
  12554. // we can skip can_patch because it's guaranteed by the absence of a
  12555. // patchFlag.
  12556. if (returnType > 1 /* ConstantTypes.CAN_SKIP_PATCH */) {
  12557. for (let i = 0; i < node.props.length; i++) {
  12558. const p = node.props[i];
  12559. if (p.type === 7 /* NodeTypes.DIRECTIVE */ && p.name === 'bind' && p.exp) {
  12560. const expType = getConstantType(p.exp, context);
  12561. if (expType === 0 /* ConstantTypes.NOT_CONSTANT */) {
  12562. constantCache.set(node, 0 /* ConstantTypes.NOT_CONSTANT */);
  12563. return 0 /* ConstantTypes.NOT_CONSTANT */;
  12564. }
  12565. if (expType < returnType) {
  12566. returnType = expType;
  12567. }
  12568. }
  12569. }
  12570. }
  12571. // only svg/foreignObject could be block here, however if they are
  12572. // static then they don't need to be blocks since there will be no
  12573. // nested updates.
  12574. if (codegenNode.isBlock) {
  12575. // except set custom directives.
  12576. for (let i = 0; i < node.props.length; i++) {
  12577. const p = node.props[i];
  12578. if (p.type === 7 /* NodeTypes.DIRECTIVE */) {
  12579. constantCache.set(node, 0 /* ConstantTypes.NOT_CONSTANT */);
  12580. return 0 /* ConstantTypes.NOT_CONSTANT */;
  12581. }
  12582. }
  12583. context.removeHelper(OPEN_BLOCK);
  12584. context.removeHelper(getVNodeBlockHelper(context.inSSR, codegenNode.isComponent));
  12585. codegenNode.isBlock = false;
  12586. context.helper(getVNodeHelper(context.inSSR, codegenNode.isComponent));
  12587. }
  12588. constantCache.set(node, returnType);
  12589. return returnType;
  12590. }
  12591. else {
  12592. constantCache.set(node, 0 /* ConstantTypes.NOT_CONSTANT */);
  12593. return 0 /* ConstantTypes.NOT_CONSTANT */;
  12594. }
  12595. case 2 /* NodeTypes.TEXT */:
  12596. case 3 /* NodeTypes.COMMENT */:
  12597. return 3 /* ConstantTypes.CAN_STRINGIFY */;
  12598. case 9 /* NodeTypes.IF */:
  12599. case 11 /* NodeTypes.FOR */:
  12600. case 10 /* NodeTypes.IF_BRANCH */:
  12601. return 0 /* ConstantTypes.NOT_CONSTANT */;
  12602. case 5 /* NodeTypes.INTERPOLATION */:
  12603. case 12 /* NodeTypes.TEXT_CALL */:
  12604. return getConstantType(node.content, context);
  12605. case 4 /* NodeTypes.SIMPLE_EXPRESSION */:
  12606. return node.constType;
  12607. case 8 /* NodeTypes.COMPOUND_EXPRESSION */:
  12608. let returnType = 3 /* ConstantTypes.CAN_STRINGIFY */;
  12609. for (let i = 0; i < node.children.length; i++) {
  12610. const child = node.children[i];
  12611. if (isString(child) || isSymbol(child)) {
  12612. continue;
  12613. }
  12614. const childType = getConstantType(child, context);
  12615. if (childType === 0 /* ConstantTypes.NOT_CONSTANT */) {
  12616. return 0 /* ConstantTypes.NOT_CONSTANT */;
  12617. }
  12618. else if (childType < returnType) {
  12619. returnType = childType;
  12620. }
  12621. }
  12622. return returnType;
  12623. default:
  12624. return 0 /* ConstantTypes.NOT_CONSTANT */;
  12625. }
  12626. }
  12627. const allowHoistedHelperSet = new Set([
  12628. NORMALIZE_CLASS,
  12629. NORMALIZE_STYLE,
  12630. NORMALIZE_PROPS,
  12631. GUARD_REACTIVE_PROPS
  12632. ]);
  12633. function getConstantTypeOfHelperCall(value, context) {
  12634. if (value.type === 14 /* NodeTypes.JS_CALL_EXPRESSION */ &&
  12635. !isString(value.callee) &&
  12636. allowHoistedHelperSet.has(value.callee)) {
  12637. const arg = value.arguments[0];
  12638. if (arg.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
  12639. return getConstantType(arg, context);
  12640. }
  12641. else if (arg.type === 14 /* NodeTypes.JS_CALL_EXPRESSION */) {
  12642. // in the case of nested helper call, e.g. `normalizeProps(guardReactiveProps(exp))`
  12643. return getConstantTypeOfHelperCall(arg, context);
  12644. }
  12645. }
  12646. return 0 /* ConstantTypes.NOT_CONSTANT */;
  12647. }
  12648. function getGeneratedPropsConstantType(node, context) {
  12649. let returnType = 3 /* ConstantTypes.CAN_STRINGIFY */;
  12650. const props = getNodeProps(node);
  12651. if (props && props.type === 15 /* NodeTypes.JS_OBJECT_EXPRESSION */) {
  12652. const { properties } = props;
  12653. for (let i = 0; i < properties.length; i++) {
  12654. const { key, value } = properties[i];
  12655. const keyType = getConstantType(key, context);
  12656. if (keyType === 0 /* ConstantTypes.NOT_CONSTANT */) {
  12657. return keyType;
  12658. }
  12659. if (keyType < returnType) {
  12660. returnType = keyType;
  12661. }
  12662. let valueType;
  12663. if (value.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
  12664. valueType = getConstantType(value, context);
  12665. }
  12666. else if (value.type === 14 /* NodeTypes.JS_CALL_EXPRESSION */) {
  12667. // some helper calls can be hoisted,
  12668. // such as the `normalizeProps` generated by the compiler for pre-normalize class,
  12669. // in this case we need to respect the ConstantType of the helper's arguments
  12670. valueType = getConstantTypeOfHelperCall(value, context);
  12671. }
  12672. else {
  12673. valueType = 0 /* ConstantTypes.NOT_CONSTANT */;
  12674. }
  12675. if (valueType === 0 /* ConstantTypes.NOT_CONSTANT */) {
  12676. return valueType;
  12677. }
  12678. if (valueType < returnType) {
  12679. returnType = valueType;
  12680. }
  12681. }
  12682. }
  12683. return returnType;
  12684. }
  12685. function getNodeProps(node) {
  12686. const codegenNode = node.codegenNode;
  12687. if (codegenNode.type === 13 /* NodeTypes.VNODE_CALL */) {
  12688. return codegenNode.props;
  12689. }
  12690. }
  12691. function getPatchFlag(node) {
  12692. const flag = node.patchFlag;
  12693. return flag ? parseInt(flag, 10) : undefined;
  12694. }
  12695. 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 }) {
  12696. const nameMatch = filename.replace(/\?.*$/, '').match(/([^/\\]+)\.\w+$/);
  12697. const context = {
  12698. // options
  12699. selfName: nameMatch && capitalize(camelize(nameMatch[1])),
  12700. prefixIdentifiers,
  12701. hoistStatic,
  12702. cacheHandlers,
  12703. nodeTransforms,
  12704. directiveTransforms,
  12705. transformHoist,
  12706. isBuiltInComponent,
  12707. isCustomElement,
  12708. expressionPlugins,
  12709. scopeId,
  12710. slotted,
  12711. ssr,
  12712. inSSR,
  12713. ssrCssVars,
  12714. bindingMetadata,
  12715. inline,
  12716. isTS,
  12717. onError,
  12718. onWarn,
  12719. compatConfig,
  12720. // state
  12721. root,
  12722. helpers: new Map(),
  12723. components: new Set(),
  12724. directives: new Set(),
  12725. hoists: [],
  12726. imports: [],
  12727. constantCache: new Map(),
  12728. temps: 0,
  12729. cached: 0,
  12730. identifiers: Object.create(null),
  12731. scopes: {
  12732. vFor: 0,
  12733. vSlot: 0,
  12734. vPre: 0,
  12735. vOnce: 0
  12736. },
  12737. parent: null,
  12738. currentNode: root,
  12739. childIndex: 0,
  12740. inVOnce: false,
  12741. // methods
  12742. helper(name) {
  12743. const count = context.helpers.get(name) || 0;
  12744. context.helpers.set(name, count + 1);
  12745. return name;
  12746. },
  12747. removeHelper(name) {
  12748. const count = context.helpers.get(name);
  12749. if (count) {
  12750. const currentCount = count - 1;
  12751. if (!currentCount) {
  12752. context.helpers.delete(name);
  12753. }
  12754. else {
  12755. context.helpers.set(name, currentCount);
  12756. }
  12757. }
  12758. },
  12759. helperString(name) {
  12760. return `_${helperNameMap[context.helper(name)]}`;
  12761. },
  12762. replaceNode(node) {
  12763. /* istanbul ignore if */
  12764. {
  12765. if (!context.currentNode) {
  12766. throw new Error(`Node being replaced is already removed.`);
  12767. }
  12768. if (!context.parent) {
  12769. throw new Error(`Cannot replace root node.`);
  12770. }
  12771. }
  12772. context.parent.children[context.childIndex] = context.currentNode = node;
  12773. },
  12774. removeNode(node) {
  12775. if (!context.parent) {
  12776. throw new Error(`Cannot remove root node.`);
  12777. }
  12778. const list = context.parent.children;
  12779. const removalIndex = node
  12780. ? list.indexOf(node)
  12781. : context.currentNode
  12782. ? context.childIndex
  12783. : -1;
  12784. /* istanbul ignore if */
  12785. if (removalIndex < 0) {
  12786. throw new Error(`node being removed is not a child of current parent`);
  12787. }
  12788. if (!node || node === context.currentNode) {
  12789. // current node removed
  12790. context.currentNode = null;
  12791. context.onNodeRemoved();
  12792. }
  12793. else {
  12794. // sibling node removed
  12795. if (context.childIndex > removalIndex) {
  12796. context.childIndex--;
  12797. context.onNodeRemoved();
  12798. }
  12799. }
  12800. context.parent.children.splice(removalIndex, 1);
  12801. },
  12802. onNodeRemoved: () => { },
  12803. addIdentifiers(exp) {
  12804. },
  12805. removeIdentifiers(exp) {
  12806. },
  12807. hoist(exp) {
  12808. if (isString(exp))
  12809. exp = createSimpleExpression(exp);
  12810. context.hoists.push(exp);
  12811. const identifier = createSimpleExpression(`_hoisted_${context.hoists.length}`, false, exp.loc, 2 /* ConstantTypes.CAN_HOIST */);
  12812. identifier.hoisted = exp;
  12813. return identifier;
  12814. },
  12815. cache(exp, isVNode = false) {
  12816. return createCacheExpression(context.cached++, exp, isVNode);
  12817. }
  12818. };
  12819. return context;
  12820. }
  12821. function transform(root, options) {
  12822. const context = createTransformContext(root, options);
  12823. traverseNode(root, context);
  12824. if (options.hoistStatic) {
  12825. hoistStatic(root, context);
  12826. }
  12827. if (!options.ssr) {
  12828. createRootCodegen(root, context);
  12829. }
  12830. // finalize meta information
  12831. root.helpers = [...context.helpers.keys()];
  12832. root.components = [...context.components];
  12833. root.directives = [...context.directives];
  12834. root.imports = context.imports;
  12835. root.hoists = context.hoists;
  12836. root.temps = context.temps;
  12837. root.cached = context.cached;
  12838. }
  12839. function createRootCodegen(root, context) {
  12840. const { helper } = context;
  12841. const { children } = root;
  12842. if (children.length === 1) {
  12843. const child = children[0];
  12844. // if the single child is an element, turn it into a block.
  12845. if (isSingleElementRoot(root, child) && child.codegenNode) {
  12846. // single element root is never hoisted so codegenNode will never be
  12847. // SimpleExpressionNode
  12848. const codegenNode = child.codegenNode;
  12849. if (codegenNode.type === 13 /* NodeTypes.VNODE_CALL */) {
  12850. makeBlock(codegenNode, context);
  12851. }
  12852. root.codegenNode = codegenNode;
  12853. }
  12854. else {
  12855. // - single <slot/>, IfNode, ForNode: already blocks.
  12856. // - single text node: always patched.
  12857. // root codegen falls through via genNode()
  12858. root.codegenNode = child;
  12859. }
  12860. }
  12861. else if (children.length > 1) {
  12862. // root has multiple nodes - return a fragment block.
  12863. let patchFlag = 64 /* PatchFlags.STABLE_FRAGMENT */;
  12864. let patchFlagText = PatchFlagNames[64 /* PatchFlags.STABLE_FRAGMENT */];
  12865. // check if the fragment actually contains a single valid child with
  12866. // the rest being comments
  12867. if (children.filter(c => c.type !== 3 /* NodeTypes.COMMENT */).length === 1) {
  12868. patchFlag |= 2048 /* PatchFlags.DEV_ROOT_FRAGMENT */;
  12869. patchFlagText += `, ${PatchFlagNames[2048 /* PatchFlags.DEV_ROOT_FRAGMENT */]}`;
  12870. }
  12871. root.codegenNode = createVNodeCall(context, helper(FRAGMENT), undefined, root.children, patchFlag + (` /* ${patchFlagText} */` ), undefined, undefined, true, undefined, false /* isComponent */);
  12872. }
  12873. else ;
  12874. }
  12875. function traverseChildren(parent, context) {
  12876. let i = 0;
  12877. const nodeRemoved = () => {
  12878. i--;
  12879. };
  12880. for (; i < parent.children.length; i++) {
  12881. const child = parent.children[i];
  12882. if (isString(child))
  12883. continue;
  12884. context.parent = parent;
  12885. context.childIndex = i;
  12886. context.onNodeRemoved = nodeRemoved;
  12887. traverseNode(child, context);
  12888. }
  12889. }
  12890. function traverseNode(node, context) {
  12891. context.currentNode = node;
  12892. // apply transform plugins
  12893. const { nodeTransforms } = context;
  12894. const exitFns = [];
  12895. for (let i = 0; i < nodeTransforms.length; i++) {
  12896. const onExit = nodeTransforms[i](node, context);
  12897. if (onExit) {
  12898. if (isArray(onExit)) {
  12899. exitFns.push(...onExit);
  12900. }
  12901. else {
  12902. exitFns.push(onExit);
  12903. }
  12904. }
  12905. if (!context.currentNode) {
  12906. // node was removed
  12907. return;
  12908. }
  12909. else {
  12910. // node may have been replaced
  12911. node = context.currentNode;
  12912. }
  12913. }
  12914. switch (node.type) {
  12915. case 3 /* NodeTypes.COMMENT */:
  12916. if (!context.ssr) {
  12917. // inject import for the Comment symbol, which is needed for creating
  12918. // comment nodes with `createVNode`
  12919. context.helper(CREATE_COMMENT);
  12920. }
  12921. break;
  12922. case 5 /* NodeTypes.INTERPOLATION */:
  12923. // no need to traverse, but we need to inject toString helper
  12924. if (!context.ssr) {
  12925. context.helper(TO_DISPLAY_STRING);
  12926. }
  12927. break;
  12928. // for container types, further traverse downwards
  12929. case 9 /* NodeTypes.IF */:
  12930. for (let i = 0; i < node.branches.length; i++) {
  12931. traverseNode(node.branches[i], context);
  12932. }
  12933. break;
  12934. case 10 /* NodeTypes.IF_BRANCH */:
  12935. case 11 /* NodeTypes.FOR */:
  12936. case 1 /* NodeTypes.ELEMENT */:
  12937. case 0 /* NodeTypes.ROOT */:
  12938. traverseChildren(node, context);
  12939. break;
  12940. }
  12941. // exit transforms
  12942. context.currentNode = node;
  12943. let i = exitFns.length;
  12944. while (i--) {
  12945. exitFns[i]();
  12946. }
  12947. }
  12948. function createStructuralDirectiveTransform(name, fn) {
  12949. const matches = isString(name)
  12950. ? (n) => n === name
  12951. : (n) => name.test(n);
  12952. return (node, context) => {
  12953. if (node.type === 1 /* NodeTypes.ELEMENT */) {
  12954. const { props } = node;
  12955. // structural directive transforms are not concerned with slots
  12956. // as they are handled separately in vSlot.ts
  12957. if (node.tagType === 3 /* ElementTypes.TEMPLATE */ && props.some(isVSlot)) {
  12958. return;
  12959. }
  12960. const exitFns = [];
  12961. for (let i = 0; i < props.length; i++) {
  12962. const prop = props[i];
  12963. if (prop.type === 7 /* NodeTypes.DIRECTIVE */ && matches(prop.name)) {
  12964. // structural directives are removed to avoid infinite recursion
  12965. // also we remove them *before* applying so that it can further
  12966. // traverse itself in case it moves the node around
  12967. props.splice(i, 1);
  12968. i--;
  12969. const onExit = fn(node, prop, context);
  12970. if (onExit)
  12971. exitFns.push(onExit);
  12972. }
  12973. }
  12974. return exitFns;
  12975. }
  12976. };
  12977. }
  12978. const PURE_ANNOTATION = `/*#__PURE__*/`;
  12979. const aliasHelper = (s) => `${helperNameMap[s]}: _${helperNameMap[s]}`;
  12980. 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 }) {
  12981. const context = {
  12982. mode,
  12983. prefixIdentifiers,
  12984. sourceMap,
  12985. filename,
  12986. scopeId,
  12987. optimizeImports,
  12988. runtimeGlobalName,
  12989. runtimeModuleName,
  12990. ssrRuntimeModuleName,
  12991. ssr,
  12992. isTS,
  12993. inSSR,
  12994. source: ast.loc.source,
  12995. code: ``,
  12996. column: 1,
  12997. line: 1,
  12998. offset: 0,
  12999. indentLevel: 0,
  13000. pure: false,
  13001. map: undefined,
  13002. helper(key) {
  13003. return `_${helperNameMap[key]}`;
  13004. },
  13005. push(code, node) {
  13006. context.code += code;
  13007. },
  13008. indent() {
  13009. newline(++context.indentLevel);
  13010. },
  13011. deindent(withoutNewLine = false) {
  13012. if (withoutNewLine) {
  13013. --context.indentLevel;
  13014. }
  13015. else {
  13016. newline(--context.indentLevel);
  13017. }
  13018. },
  13019. newline() {
  13020. newline(context.indentLevel);
  13021. }
  13022. };
  13023. function newline(n) {
  13024. context.push('\n' + ` `.repeat(n));
  13025. }
  13026. return context;
  13027. }
  13028. function generate(ast, options = {}) {
  13029. const context = createCodegenContext(ast, options);
  13030. if (options.onContextCreated)
  13031. options.onContextCreated(context);
  13032. const { mode, push, prefixIdentifiers, indent, deindent, newline, scopeId, ssr } = context;
  13033. const hasHelpers = ast.helpers.length > 0;
  13034. const useWithBlock = !prefixIdentifiers && mode !== 'module';
  13035. // preambles
  13036. // in setup() inline mode, the preamble is generated in a sub context
  13037. // and returned separately.
  13038. const preambleContext = context;
  13039. {
  13040. genFunctionPreamble(ast, preambleContext);
  13041. }
  13042. // enter render function
  13043. const functionName = ssr ? `ssrRender` : `render`;
  13044. const args = ssr ? ['_ctx', '_push', '_parent', '_attrs'] : ['_ctx', '_cache'];
  13045. const signature = args.join(', ');
  13046. {
  13047. push(`function ${functionName}(${signature}) {`);
  13048. }
  13049. indent();
  13050. if (useWithBlock) {
  13051. push(`with (_ctx) {`);
  13052. indent();
  13053. // function mode const declarations should be inside with block
  13054. // also they should be renamed to avoid collision with user properties
  13055. if (hasHelpers) {
  13056. push(`const { ${ast.helpers.map(aliasHelper).join(', ')} } = _Vue`);
  13057. push(`\n`);
  13058. newline();
  13059. }
  13060. }
  13061. // generate asset resolution statements
  13062. if (ast.components.length) {
  13063. genAssets(ast.components, 'component', context);
  13064. if (ast.directives.length || ast.temps > 0) {
  13065. newline();
  13066. }
  13067. }
  13068. if (ast.directives.length) {
  13069. genAssets(ast.directives, 'directive', context);
  13070. if (ast.temps > 0) {
  13071. newline();
  13072. }
  13073. }
  13074. if (ast.temps > 0) {
  13075. push(`let `);
  13076. for (let i = 0; i < ast.temps; i++) {
  13077. push(`${i > 0 ? `, ` : ``}_temp${i}`);
  13078. }
  13079. }
  13080. if (ast.components.length || ast.directives.length || ast.temps) {
  13081. push(`\n`);
  13082. newline();
  13083. }
  13084. // generate the VNode tree expression
  13085. if (!ssr) {
  13086. push(`return `);
  13087. }
  13088. if (ast.codegenNode) {
  13089. genNode(ast.codegenNode, context);
  13090. }
  13091. else {
  13092. push(`null`);
  13093. }
  13094. if (useWithBlock) {
  13095. deindent();
  13096. push(`}`);
  13097. }
  13098. deindent();
  13099. push(`}`);
  13100. return {
  13101. ast,
  13102. code: context.code,
  13103. preamble: ``,
  13104. // SourceMapGenerator does have toJSON() method but it's not in the types
  13105. map: context.map ? context.map.toJSON() : undefined
  13106. };
  13107. }
  13108. function genFunctionPreamble(ast, context) {
  13109. const { ssr, prefixIdentifiers, push, newline, runtimeModuleName, runtimeGlobalName, ssrRuntimeModuleName } = context;
  13110. const VueBinding = runtimeGlobalName;
  13111. // Generate const declaration for helpers
  13112. // In prefix mode, we place the const declaration at top so it's done
  13113. // only once; But if we not prefixing, we place the declaration inside the
  13114. // with block so it doesn't incur the `in` check cost for every helper access.
  13115. if (ast.helpers.length > 0) {
  13116. {
  13117. // "with" mode.
  13118. // save Vue in a separate variable to avoid collision
  13119. push(`const _Vue = ${VueBinding}\n`);
  13120. // in "with" mode, helpers are declared inside the with block to avoid
  13121. // has check cost, but hoists are lifted out of the function - we need
  13122. // to provide the helper here.
  13123. if (ast.hoists.length) {
  13124. const staticHelpers = [
  13125. CREATE_VNODE,
  13126. CREATE_ELEMENT_VNODE,
  13127. CREATE_COMMENT,
  13128. CREATE_TEXT,
  13129. CREATE_STATIC
  13130. ]
  13131. .filter(helper => ast.helpers.includes(helper))
  13132. .map(aliasHelper)
  13133. .join(', ');
  13134. push(`const { ${staticHelpers} } = _Vue\n`);
  13135. }
  13136. }
  13137. }
  13138. genHoists(ast.hoists, context);
  13139. newline();
  13140. push(`return `);
  13141. }
  13142. function genAssets(assets, type, { helper, push, newline, isTS }) {
  13143. const resolver = helper(type === 'component'
  13144. ? RESOLVE_COMPONENT
  13145. : RESOLVE_DIRECTIVE);
  13146. for (let i = 0; i < assets.length; i++) {
  13147. let id = assets[i];
  13148. // potential component implicit self-reference inferred from SFC filename
  13149. const maybeSelfReference = id.endsWith('__self');
  13150. if (maybeSelfReference) {
  13151. id = id.slice(0, -6);
  13152. }
  13153. push(`const ${toValidAssetId(id, type)} = ${resolver}(${JSON.stringify(id)}${maybeSelfReference ? `, true` : ``})${isTS ? `!` : ``}`);
  13154. if (i < assets.length - 1) {
  13155. newline();
  13156. }
  13157. }
  13158. }
  13159. function genHoists(hoists, context) {
  13160. if (!hoists.length) {
  13161. return;
  13162. }
  13163. context.pure = true;
  13164. const { push, newline, helper, scopeId, mode } = context;
  13165. newline();
  13166. for (let i = 0; i < hoists.length; i++) {
  13167. const exp = hoists[i];
  13168. if (exp) {
  13169. push(`const _hoisted_${i + 1} = ${``}`);
  13170. genNode(exp, context);
  13171. newline();
  13172. }
  13173. }
  13174. context.pure = false;
  13175. }
  13176. function isText$1(n) {
  13177. return (isString(n) ||
  13178. n.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ ||
  13179. n.type === 2 /* NodeTypes.TEXT */ ||
  13180. n.type === 5 /* NodeTypes.INTERPOLATION */ ||
  13181. n.type === 8 /* NodeTypes.COMPOUND_EXPRESSION */);
  13182. }
  13183. function genNodeListAsArray(nodes, context) {
  13184. const multilines = nodes.length > 3 ||
  13185. (nodes.some(n => isArray(n) || !isText$1(n)));
  13186. context.push(`[`);
  13187. multilines && context.indent();
  13188. genNodeList(nodes, context, multilines);
  13189. multilines && context.deindent();
  13190. context.push(`]`);
  13191. }
  13192. function genNodeList(nodes, context, multilines = false, comma = true) {
  13193. const { push, newline } = context;
  13194. for (let i = 0; i < nodes.length; i++) {
  13195. const node = nodes[i];
  13196. if (isString(node)) {
  13197. push(node);
  13198. }
  13199. else if (isArray(node)) {
  13200. genNodeListAsArray(node, context);
  13201. }
  13202. else {
  13203. genNode(node, context);
  13204. }
  13205. if (i < nodes.length - 1) {
  13206. if (multilines) {
  13207. comma && push(',');
  13208. newline();
  13209. }
  13210. else {
  13211. comma && push(', ');
  13212. }
  13213. }
  13214. }
  13215. }
  13216. function genNode(node, context) {
  13217. if (isString(node)) {
  13218. context.push(node);
  13219. return;
  13220. }
  13221. if (isSymbol(node)) {
  13222. context.push(context.helper(node));
  13223. return;
  13224. }
  13225. switch (node.type) {
  13226. case 1 /* NodeTypes.ELEMENT */:
  13227. case 9 /* NodeTypes.IF */:
  13228. case 11 /* NodeTypes.FOR */:
  13229. assert(node.codegenNode != null, `Codegen node is missing for element/if/for node. ` +
  13230. `Apply appropriate transforms first.`);
  13231. genNode(node.codegenNode, context);
  13232. break;
  13233. case 2 /* NodeTypes.TEXT */:
  13234. genText(node, context);
  13235. break;
  13236. case 4 /* NodeTypes.SIMPLE_EXPRESSION */:
  13237. genExpression(node, context);
  13238. break;
  13239. case 5 /* NodeTypes.INTERPOLATION */:
  13240. genInterpolation(node, context);
  13241. break;
  13242. case 12 /* NodeTypes.TEXT_CALL */:
  13243. genNode(node.codegenNode, context);
  13244. break;
  13245. case 8 /* NodeTypes.COMPOUND_EXPRESSION */:
  13246. genCompoundExpression(node, context);
  13247. break;
  13248. case 3 /* NodeTypes.COMMENT */:
  13249. genComment(node, context);
  13250. break;
  13251. case 13 /* NodeTypes.VNODE_CALL */:
  13252. genVNodeCall(node, context);
  13253. break;
  13254. case 14 /* NodeTypes.JS_CALL_EXPRESSION */:
  13255. genCallExpression(node, context);
  13256. break;
  13257. case 15 /* NodeTypes.JS_OBJECT_EXPRESSION */:
  13258. genObjectExpression(node, context);
  13259. break;
  13260. case 17 /* NodeTypes.JS_ARRAY_EXPRESSION */:
  13261. genArrayExpression(node, context);
  13262. break;
  13263. case 18 /* NodeTypes.JS_FUNCTION_EXPRESSION */:
  13264. genFunctionExpression(node, context);
  13265. break;
  13266. case 19 /* NodeTypes.JS_CONDITIONAL_EXPRESSION */:
  13267. genConditionalExpression(node, context);
  13268. break;
  13269. case 20 /* NodeTypes.JS_CACHE_EXPRESSION */:
  13270. genCacheExpression(node, context);
  13271. break;
  13272. case 21 /* NodeTypes.JS_BLOCK_STATEMENT */:
  13273. genNodeList(node.body, context, true, false);
  13274. break;
  13275. // SSR only types
  13276. case 22 /* NodeTypes.JS_TEMPLATE_LITERAL */:
  13277. break;
  13278. case 23 /* NodeTypes.JS_IF_STATEMENT */:
  13279. break;
  13280. case 24 /* NodeTypes.JS_ASSIGNMENT_EXPRESSION */:
  13281. break;
  13282. case 25 /* NodeTypes.JS_SEQUENCE_EXPRESSION */:
  13283. break;
  13284. case 26 /* NodeTypes.JS_RETURN_STATEMENT */:
  13285. break;
  13286. /* istanbul ignore next */
  13287. case 10 /* NodeTypes.IF_BRANCH */:
  13288. // noop
  13289. break;
  13290. default:
  13291. {
  13292. assert(false, `unhandled codegen node type: ${node.type}`);
  13293. // make sure we exhaust all possible types
  13294. const exhaustiveCheck = node;
  13295. return exhaustiveCheck;
  13296. }
  13297. }
  13298. }
  13299. function genText(node, context) {
  13300. context.push(JSON.stringify(node.content), node);
  13301. }
  13302. function genExpression(node, context) {
  13303. const { content, isStatic } = node;
  13304. context.push(isStatic ? JSON.stringify(content) : content, node);
  13305. }
  13306. function genInterpolation(node, context) {
  13307. const { push, helper, pure } = context;
  13308. if (pure)
  13309. push(PURE_ANNOTATION);
  13310. push(`${helper(TO_DISPLAY_STRING)}(`);
  13311. genNode(node.content, context);
  13312. push(`)`);
  13313. }
  13314. function genCompoundExpression(node, context) {
  13315. for (let i = 0; i < node.children.length; i++) {
  13316. const child = node.children[i];
  13317. if (isString(child)) {
  13318. context.push(child);
  13319. }
  13320. else {
  13321. genNode(child, context);
  13322. }
  13323. }
  13324. }
  13325. function genExpressionAsPropertyKey(node, context) {
  13326. const { push } = context;
  13327. if (node.type === 8 /* NodeTypes.COMPOUND_EXPRESSION */) {
  13328. push(`[`);
  13329. genCompoundExpression(node, context);
  13330. push(`]`);
  13331. }
  13332. else if (node.isStatic) {
  13333. // only quote keys if necessary
  13334. const text = isSimpleIdentifier(node.content)
  13335. ? node.content
  13336. : JSON.stringify(node.content);
  13337. push(text, node);
  13338. }
  13339. else {
  13340. push(`[${node.content}]`, node);
  13341. }
  13342. }
  13343. function genComment(node, context) {
  13344. const { push, helper, pure } = context;
  13345. if (pure) {
  13346. push(PURE_ANNOTATION);
  13347. }
  13348. push(`${helper(CREATE_COMMENT)}(${JSON.stringify(node.content)})`, node);
  13349. }
  13350. function genVNodeCall(node, context) {
  13351. const { push, helper, pure } = context;
  13352. const { tag, props, children, patchFlag, dynamicProps, directives, isBlock, disableTracking, isComponent } = node;
  13353. if (directives) {
  13354. push(helper(WITH_DIRECTIVES) + `(`);
  13355. }
  13356. if (isBlock) {
  13357. push(`(${helper(OPEN_BLOCK)}(${disableTracking ? `true` : ``}), `);
  13358. }
  13359. if (pure) {
  13360. push(PURE_ANNOTATION);
  13361. }
  13362. const callHelper = isBlock
  13363. ? getVNodeBlockHelper(context.inSSR, isComponent)
  13364. : getVNodeHelper(context.inSSR, isComponent);
  13365. push(helper(callHelper) + `(`, node);
  13366. genNodeList(genNullableArgs([tag, props, children, patchFlag, dynamicProps]), context);
  13367. push(`)`);
  13368. if (isBlock) {
  13369. push(`)`);
  13370. }
  13371. if (directives) {
  13372. push(`, `);
  13373. genNode(directives, context);
  13374. push(`)`);
  13375. }
  13376. }
  13377. function genNullableArgs(args) {
  13378. let i = args.length;
  13379. while (i--) {
  13380. if (args[i] != null)
  13381. break;
  13382. }
  13383. return args.slice(0, i + 1).map(arg => arg || `null`);
  13384. }
  13385. // JavaScript
  13386. function genCallExpression(node, context) {
  13387. const { push, helper, pure } = context;
  13388. const callee = isString(node.callee) ? node.callee : helper(node.callee);
  13389. if (pure) {
  13390. push(PURE_ANNOTATION);
  13391. }
  13392. push(callee + `(`, node);
  13393. genNodeList(node.arguments, context);
  13394. push(`)`);
  13395. }
  13396. function genObjectExpression(node, context) {
  13397. const { push, indent, deindent, newline } = context;
  13398. const { properties } = node;
  13399. if (!properties.length) {
  13400. push(`{}`, node);
  13401. return;
  13402. }
  13403. const multilines = properties.length > 1 ||
  13404. (properties.some(p => p.value.type !== 4 /* NodeTypes.SIMPLE_EXPRESSION */));
  13405. push(multilines ? `{` : `{ `);
  13406. multilines && indent();
  13407. for (let i = 0; i < properties.length; i++) {
  13408. const { key, value } = properties[i];
  13409. // key
  13410. genExpressionAsPropertyKey(key, context);
  13411. push(`: `);
  13412. // value
  13413. genNode(value, context);
  13414. if (i < properties.length - 1) {
  13415. // will only reach this if it's multilines
  13416. push(`,`);
  13417. newline();
  13418. }
  13419. }
  13420. multilines && deindent();
  13421. push(multilines ? `}` : ` }`);
  13422. }
  13423. function genArrayExpression(node, context) {
  13424. genNodeListAsArray(node.elements, context);
  13425. }
  13426. function genFunctionExpression(node, context) {
  13427. const { push, indent, deindent } = context;
  13428. const { params, returns, body, newline, isSlot } = node;
  13429. if (isSlot) {
  13430. // wrap slot functions with owner context
  13431. push(`_${helperNameMap[WITH_CTX]}(`);
  13432. }
  13433. push(`(`, node);
  13434. if (isArray(params)) {
  13435. genNodeList(params, context);
  13436. }
  13437. else if (params) {
  13438. genNode(params, context);
  13439. }
  13440. push(`) => `);
  13441. if (newline || body) {
  13442. push(`{`);
  13443. indent();
  13444. }
  13445. if (returns) {
  13446. if (newline) {
  13447. push(`return `);
  13448. }
  13449. if (isArray(returns)) {
  13450. genNodeListAsArray(returns, context);
  13451. }
  13452. else {
  13453. genNode(returns, context);
  13454. }
  13455. }
  13456. else if (body) {
  13457. genNode(body, context);
  13458. }
  13459. if (newline || body) {
  13460. deindent();
  13461. push(`}`);
  13462. }
  13463. if (isSlot) {
  13464. push(`)`);
  13465. }
  13466. }
  13467. function genConditionalExpression(node, context) {
  13468. const { test, consequent, alternate, newline: needNewline } = node;
  13469. const { push, indent, deindent, newline } = context;
  13470. if (test.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
  13471. const needsParens = !isSimpleIdentifier(test.content);
  13472. needsParens && push(`(`);
  13473. genExpression(test, context);
  13474. needsParens && push(`)`);
  13475. }
  13476. else {
  13477. push(`(`);
  13478. genNode(test, context);
  13479. push(`)`);
  13480. }
  13481. needNewline && indent();
  13482. context.indentLevel++;
  13483. needNewline || push(` `);
  13484. push(`? `);
  13485. genNode(consequent, context);
  13486. context.indentLevel--;
  13487. needNewline && newline();
  13488. needNewline || push(` `);
  13489. push(`: `);
  13490. const isNested = alternate.type === 19 /* NodeTypes.JS_CONDITIONAL_EXPRESSION */;
  13491. if (!isNested) {
  13492. context.indentLevel++;
  13493. }
  13494. genNode(alternate, context);
  13495. if (!isNested) {
  13496. context.indentLevel--;
  13497. }
  13498. needNewline && deindent(true /* without newline */);
  13499. }
  13500. function genCacheExpression(node, context) {
  13501. const { push, helper, indent, deindent, newline } = context;
  13502. push(`_cache[${node.index}] || (`);
  13503. if (node.isVNode) {
  13504. indent();
  13505. push(`${helper(SET_BLOCK_TRACKING)}(-1),`);
  13506. newline();
  13507. }
  13508. push(`_cache[${node.index}] = `);
  13509. genNode(node.value, context);
  13510. if (node.isVNode) {
  13511. push(`,`);
  13512. newline();
  13513. push(`${helper(SET_BLOCK_TRACKING)}(1),`);
  13514. newline();
  13515. push(`_cache[${node.index}]`);
  13516. deindent();
  13517. }
  13518. push(`)`);
  13519. }
  13520. // these keywords should not appear inside expressions, but operators like
  13521. // typeof, instanceof and in are allowed
  13522. const prohibitedKeywordRE = new RegExp('\\b' +
  13523. ('do,if,for,let,new,try,var,case,else,with,await,break,catch,class,const,' +
  13524. 'super,throw,while,yield,delete,export,import,return,switch,default,' +
  13525. 'extends,finally,continue,debugger,function,arguments,typeof,void')
  13526. .split(',')
  13527. .join('\\b|\\b') +
  13528. '\\b');
  13529. // strip strings in expressions
  13530. const stripStringRE = /'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`(?:[^`\\]|\\.)*\$\{|\}(?:[^`\\]|\\.)*`|`(?:[^`\\]|\\.)*`/g;
  13531. /**
  13532. * Validate a non-prefixed expression.
  13533. * This is only called when using the in-browser runtime compiler since it
  13534. * doesn't prefix expressions.
  13535. */
  13536. function validateBrowserExpression(node, context, asParams = false, asRawStatements = false) {
  13537. const exp = node.content;
  13538. // empty expressions are validated per-directive since some directives
  13539. // do allow empty expressions.
  13540. if (!exp.trim()) {
  13541. return;
  13542. }
  13543. try {
  13544. new Function(asRawStatements
  13545. ? ` ${exp} `
  13546. : `return ${asParams ? `(${exp}) => {}` : `(${exp})`}`);
  13547. }
  13548. catch (e) {
  13549. let message = e.message;
  13550. const keywordMatch = exp
  13551. .replace(stripStringRE, '')
  13552. .match(prohibitedKeywordRE);
  13553. if (keywordMatch) {
  13554. message = `avoid using JavaScript keyword as property name: "${keywordMatch[0]}"`;
  13555. }
  13556. context.onError(createCompilerError(45 /* ErrorCodes.X_INVALID_EXPRESSION */, node.loc, undefined, message));
  13557. }
  13558. }
  13559. const transformExpression = (node, context) => {
  13560. if (node.type === 5 /* NodeTypes.INTERPOLATION */) {
  13561. node.content = processExpression(node.content, context);
  13562. }
  13563. else if (node.type === 1 /* NodeTypes.ELEMENT */) {
  13564. // handle directives on element
  13565. for (let i = 0; i < node.props.length; i++) {
  13566. const dir = node.props[i];
  13567. // do not process for v-on & v-for since they are special handled
  13568. if (dir.type === 7 /* NodeTypes.DIRECTIVE */ && dir.name !== 'for') {
  13569. const exp = dir.exp;
  13570. const arg = dir.arg;
  13571. // do not process exp if this is v-on:arg - we need special handling
  13572. // for wrapping inline statements.
  13573. if (exp &&
  13574. exp.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ &&
  13575. !(dir.name === 'on' && arg)) {
  13576. dir.exp = processExpression(exp, context,
  13577. // slot args must be processed as function params
  13578. dir.name === 'slot');
  13579. }
  13580. if (arg && arg.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ && !arg.isStatic) {
  13581. dir.arg = processExpression(arg, context);
  13582. }
  13583. }
  13584. }
  13585. }
  13586. };
  13587. // Important: since this function uses Node.js only dependencies, it should
  13588. // always be used with a leading !true check so that it can be
  13589. // tree-shaken from the browser build.
  13590. function processExpression(node, context,
  13591. // some expressions like v-slot props & v-for aliases should be parsed as
  13592. // function params
  13593. asParams = false,
  13594. // v-on handler values may contain multiple statements
  13595. asRawStatements = false, localVars = Object.create(context.identifiers)) {
  13596. {
  13597. {
  13598. // simple in-browser validation (same logic in 2.x)
  13599. validateBrowserExpression(node, context, asParams, asRawStatements);
  13600. }
  13601. return node;
  13602. }
  13603. }
  13604. const transformIf = createStructuralDirectiveTransform(/^(if|else|else-if)$/, (node, dir, context) => {
  13605. return processIf(node, dir, context, (ifNode, branch, isRoot) => {
  13606. // #1587: We need to dynamically increment the key based on the current
  13607. // node's sibling nodes, since chained v-if/else branches are
  13608. // rendered at the same depth
  13609. const siblings = context.parent.children;
  13610. let i = siblings.indexOf(ifNode);
  13611. let key = 0;
  13612. while (i-- >= 0) {
  13613. const sibling = siblings[i];
  13614. if (sibling && sibling.type === 9 /* NodeTypes.IF */) {
  13615. key += sibling.branches.length;
  13616. }
  13617. }
  13618. // Exit callback. Complete the codegenNode when all children have been
  13619. // transformed.
  13620. return () => {
  13621. if (isRoot) {
  13622. ifNode.codegenNode = createCodegenNodeForBranch(branch, key, context);
  13623. }
  13624. else {
  13625. // attach this branch's codegen node to the v-if root.
  13626. const parentCondition = getParentCondition(ifNode.codegenNode);
  13627. parentCondition.alternate = createCodegenNodeForBranch(branch, key + ifNode.branches.length - 1, context);
  13628. }
  13629. };
  13630. });
  13631. });
  13632. // target-agnostic transform used for both Client and SSR
  13633. function processIf(node, dir, context, processCodegen) {
  13634. if (dir.name !== 'else' &&
  13635. (!dir.exp || !dir.exp.content.trim())) {
  13636. const loc = dir.exp ? dir.exp.loc : node.loc;
  13637. context.onError(createCompilerError(28 /* ErrorCodes.X_V_IF_NO_EXPRESSION */, dir.loc));
  13638. dir.exp = createSimpleExpression(`true`, false, loc);
  13639. }
  13640. if (dir.exp) {
  13641. validateBrowserExpression(dir.exp, context);
  13642. }
  13643. if (dir.name === 'if') {
  13644. const branch = createIfBranch(node, dir);
  13645. const ifNode = {
  13646. type: 9 /* NodeTypes.IF */,
  13647. loc: node.loc,
  13648. branches: [branch]
  13649. };
  13650. context.replaceNode(ifNode);
  13651. if (processCodegen) {
  13652. return processCodegen(ifNode, branch, true);
  13653. }
  13654. }
  13655. else {
  13656. // locate the adjacent v-if
  13657. const siblings = context.parent.children;
  13658. const comments = [];
  13659. let i = siblings.indexOf(node);
  13660. while (i-- >= -1) {
  13661. const sibling = siblings[i];
  13662. if (sibling && sibling.type === 3 /* NodeTypes.COMMENT */) {
  13663. context.removeNode(sibling);
  13664. comments.unshift(sibling);
  13665. continue;
  13666. }
  13667. if (sibling &&
  13668. sibling.type === 2 /* NodeTypes.TEXT */ &&
  13669. !sibling.content.trim().length) {
  13670. context.removeNode(sibling);
  13671. continue;
  13672. }
  13673. if (sibling && sibling.type === 9 /* NodeTypes.IF */) {
  13674. // Check if v-else was followed by v-else-if
  13675. if (dir.name === 'else-if' &&
  13676. sibling.branches[sibling.branches.length - 1].condition === undefined) {
  13677. context.onError(createCompilerError(30 /* ErrorCodes.X_V_ELSE_NO_ADJACENT_IF */, node.loc));
  13678. }
  13679. // move the node to the if node's branches
  13680. context.removeNode();
  13681. const branch = createIfBranch(node, dir);
  13682. if (comments.length &&
  13683. // #3619 ignore comments if the v-if is direct child of <transition>
  13684. !(context.parent &&
  13685. context.parent.type === 1 /* NodeTypes.ELEMENT */ &&
  13686. isBuiltInType(context.parent.tag, 'transition'))) {
  13687. branch.children = [...comments, ...branch.children];
  13688. }
  13689. // check if user is forcing same key on different branches
  13690. {
  13691. const key = branch.userKey;
  13692. if (key) {
  13693. sibling.branches.forEach(({ userKey }) => {
  13694. if (isSameKey(userKey, key)) {
  13695. context.onError(createCompilerError(29 /* ErrorCodes.X_V_IF_SAME_KEY */, branch.userKey.loc));
  13696. }
  13697. });
  13698. }
  13699. }
  13700. sibling.branches.push(branch);
  13701. const onExit = processCodegen && processCodegen(sibling, branch, false);
  13702. // since the branch was removed, it will not be traversed.
  13703. // make sure to traverse here.
  13704. traverseNode(branch, context);
  13705. // call on exit
  13706. if (onExit)
  13707. onExit();
  13708. // make sure to reset currentNode after traversal to indicate this
  13709. // node has been removed.
  13710. context.currentNode = null;
  13711. }
  13712. else {
  13713. context.onError(createCompilerError(30 /* ErrorCodes.X_V_ELSE_NO_ADJACENT_IF */, node.loc));
  13714. }
  13715. break;
  13716. }
  13717. }
  13718. }
  13719. function createIfBranch(node, dir) {
  13720. const isTemplateIf = node.tagType === 3 /* ElementTypes.TEMPLATE */;
  13721. return {
  13722. type: 10 /* NodeTypes.IF_BRANCH */,
  13723. loc: node.loc,
  13724. condition: dir.name === 'else' ? undefined : dir.exp,
  13725. children: isTemplateIf && !findDir(node, 'for') ? node.children : [node],
  13726. userKey: findProp(node, `key`),
  13727. isTemplateIf
  13728. };
  13729. }
  13730. function createCodegenNodeForBranch(branch, keyIndex, context) {
  13731. if (branch.condition) {
  13732. return createConditionalExpression(branch.condition, createChildrenCodegenNode(branch, keyIndex, context),
  13733. // make sure to pass in asBlock: true so that the comment node call
  13734. // closes the current block.
  13735. createCallExpression(context.helper(CREATE_COMMENT), [
  13736. '"v-if"' ,
  13737. 'true'
  13738. ]));
  13739. }
  13740. else {
  13741. return createChildrenCodegenNode(branch, keyIndex, context);
  13742. }
  13743. }
  13744. function createChildrenCodegenNode(branch, keyIndex, context) {
  13745. const { helper } = context;
  13746. const keyProperty = createObjectProperty(`key`, createSimpleExpression(`${keyIndex}`, false, locStub, 2 /* ConstantTypes.CAN_HOIST */));
  13747. const { children } = branch;
  13748. const firstChild = children[0];
  13749. const needFragmentWrapper = children.length !== 1 || firstChild.type !== 1 /* NodeTypes.ELEMENT */;
  13750. if (needFragmentWrapper) {
  13751. if (children.length === 1 && firstChild.type === 11 /* NodeTypes.FOR */) {
  13752. // optimize away nested fragments when child is a ForNode
  13753. const vnodeCall = firstChild.codegenNode;
  13754. injectProp(vnodeCall, keyProperty, context);
  13755. return vnodeCall;
  13756. }
  13757. else {
  13758. let patchFlag = 64 /* PatchFlags.STABLE_FRAGMENT */;
  13759. let patchFlagText = PatchFlagNames[64 /* PatchFlags.STABLE_FRAGMENT */];
  13760. // check if the fragment actually contains a single valid child with
  13761. // the rest being comments
  13762. if (!branch.isTemplateIf &&
  13763. children.filter(c => c.type !== 3 /* NodeTypes.COMMENT */).length === 1) {
  13764. patchFlag |= 2048 /* PatchFlags.DEV_ROOT_FRAGMENT */;
  13765. patchFlagText += `, ${PatchFlagNames[2048 /* PatchFlags.DEV_ROOT_FRAGMENT */]}`;
  13766. }
  13767. return createVNodeCall(context, helper(FRAGMENT), createObjectExpression([keyProperty]), children, patchFlag + (` /* ${patchFlagText} */` ), undefined, undefined, true, false, false /* isComponent */, branch.loc);
  13768. }
  13769. }
  13770. else {
  13771. const ret = firstChild.codegenNode;
  13772. const vnodeCall = getMemoedVNodeCall(ret);
  13773. // Change createVNode to createBlock.
  13774. if (vnodeCall.type === 13 /* NodeTypes.VNODE_CALL */) {
  13775. makeBlock(vnodeCall, context);
  13776. }
  13777. // inject branch key
  13778. injectProp(vnodeCall, keyProperty, context);
  13779. return ret;
  13780. }
  13781. }
  13782. function isSameKey(a, b) {
  13783. if (!a || a.type !== b.type) {
  13784. return false;
  13785. }
  13786. if (a.type === 6 /* NodeTypes.ATTRIBUTE */) {
  13787. if (a.value.content !== b.value.content) {
  13788. return false;
  13789. }
  13790. }
  13791. else {
  13792. // directive
  13793. const exp = a.exp;
  13794. const branchExp = b.exp;
  13795. if (exp.type !== branchExp.type) {
  13796. return false;
  13797. }
  13798. if (exp.type !== 4 /* NodeTypes.SIMPLE_EXPRESSION */ ||
  13799. exp.isStatic !== branchExp.isStatic ||
  13800. exp.content !== branchExp.content) {
  13801. return false;
  13802. }
  13803. }
  13804. return true;
  13805. }
  13806. function getParentCondition(node) {
  13807. while (true) {
  13808. if (node.type === 19 /* NodeTypes.JS_CONDITIONAL_EXPRESSION */) {
  13809. if (node.alternate.type === 19 /* NodeTypes.JS_CONDITIONAL_EXPRESSION */) {
  13810. node = node.alternate;
  13811. }
  13812. else {
  13813. return node;
  13814. }
  13815. }
  13816. else if (node.type === 20 /* NodeTypes.JS_CACHE_EXPRESSION */) {
  13817. node = node.value;
  13818. }
  13819. }
  13820. }
  13821. const transformFor = createStructuralDirectiveTransform('for', (node, dir, context) => {
  13822. const { helper, removeHelper } = context;
  13823. return processFor(node, dir, context, forNode => {
  13824. // create the loop render function expression now, and add the
  13825. // iterator on exit after all children have been traversed
  13826. const renderExp = createCallExpression(helper(RENDER_LIST), [
  13827. forNode.source
  13828. ]);
  13829. const isTemplate = isTemplateNode(node);
  13830. const memo = findDir(node, 'memo');
  13831. const keyProp = findProp(node, `key`);
  13832. const keyExp = keyProp &&
  13833. (keyProp.type === 6 /* NodeTypes.ATTRIBUTE */
  13834. ? createSimpleExpression(keyProp.value.content, true)
  13835. : keyProp.exp);
  13836. const keyProperty = keyProp ? createObjectProperty(`key`, keyExp) : null;
  13837. const isStableFragment = forNode.source.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ &&
  13838. forNode.source.constType > 0 /* ConstantTypes.NOT_CONSTANT */;
  13839. const fragmentFlag = isStableFragment
  13840. ? 64 /* PatchFlags.STABLE_FRAGMENT */
  13841. : keyProp
  13842. ? 128 /* PatchFlags.KEYED_FRAGMENT */
  13843. : 256 /* PatchFlags.UNKEYED_FRAGMENT */;
  13844. forNode.codegenNode = createVNodeCall(context, helper(FRAGMENT), undefined, renderExp, fragmentFlag +
  13845. (` /* ${PatchFlagNames[fragmentFlag]} */` ), undefined, undefined, true /* isBlock */, !isStableFragment /* disableTracking */, false /* isComponent */, node.loc);
  13846. return () => {
  13847. // finish the codegen now that all children have been traversed
  13848. let childBlock;
  13849. const { children } = forNode;
  13850. // check <template v-for> key placement
  13851. if (isTemplate) {
  13852. node.children.some(c => {
  13853. if (c.type === 1 /* NodeTypes.ELEMENT */) {
  13854. const key = findProp(c, 'key');
  13855. if (key) {
  13856. context.onError(createCompilerError(33 /* ErrorCodes.X_V_FOR_TEMPLATE_KEY_PLACEMENT */, key.loc));
  13857. return true;
  13858. }
  13859. }
  13860. });
  13861. }
  13862. const needFragmentWrapper = children.length !== 1 || children[0].type !== 1 /* NodeTypes.ELEMENT */;
  13863. const slotOutlet = isSlotOutlet(node)
  13864. ? node
  13865. : isTemplate &&
  13866. node.children.length === 1 &&
  13867. isSlotOutlet(node.children[0])
  13868. ? node.children[0] // api-extractor somehow fails to infer this
  13869. : null;
  13870. if (slotOutlet) {
  13871. // <slot v-for="..."> or <template v-for="..."><slot/></template>
  13872. childBlock = slotOutlet.codegenNode;
  13873. if (isTemplate && keyProperty) {
  13874. // <template v-for="..." :key="..."><slot/></template>
  13875. // we need to inject the key to the renderSlot() call.
  13876. // the props for renderSlot is passed as the 3rd argument.
  13877. injectProp(childBlock, keyProperty, context);
  13878. }
  13879. }
  13880. else if (needFragmentWrapper) {
  13881. // <template v-for="..."> with text or multi-elements
  13882. // should generate a fragment block for each loop
  13883. childBlock = createVNodeCall(context, helper(FRAGMENT), keyProperty ? createObjectExpression([keyProperty]) : undefined, node.children, 64 /* PatchFlags.STABLE_FRAGMENT */ +
  13884. (` /* ${PatchFlagNames[64 /* PatchFlags.STABLE_FRAGMENT */]} */`
  13885. ), undefined, undefined, true, undefined, false /* isComponent */);
  13886. }
  13887. else {
  13888. // Normal element v-for. Directly use the child's codegenNode
  13889. // but mark it as a block.
  13890. childBlock = children[0]
  13891. .codegenNode;
  13892. if (isTemplate && keyProperty) {
  13893. injectProp(childBlock, keyProperty, context);
  13894. }
  13895. if (childBlock.isBlock !== !isStableFragment) {
  13896. if (childBlock.isBlock) {
  13897. // switch from block to vnode
  13898. removeHelper(OPEN_BLOCK);
  13899. removeHelper(getVNodeBlockHelper(context.inSSR, childBlock.isComponent));
  13900. }
  13901. else {
  13902. // switch from vnode to block
  13903. removeHelper(getVNodeHelper(context.inSSR, childBlock.isComponent));
  13904. }
  13905. }
  13906. childBlock.isBlock = !isStableFragment;
  13907. if (childBlock.isBlock) {
  13908. helper(OPEN_BLOCK);
  13909. helper(getVNodeBlockHelper(context.inSSR, childBlock.isComponent));
  13910. }
  13911. else {
  13912. helper(getVNodeHelper(context.inSSR, childBlock.isComponent));
  13913. }
  13914. }
  13915. if (memo) {
  13916. const loop = createFunctionExpression(createForLoopParams(forNode.parseResult, [
  13917. createSimpleExpression(`_cached`)
  13918. ]));
  13919. loop.body = createBlockStatement([
  13920. createCompoundExpression([`const _memo = (`, memo.exp, `)`]),
  13921. createCompoundExpression([
  13922. `if (_cached`,
  13923. ...(keyExp ? [` && _cached.key === `, keyExp] : []),
  13924. ` && ${context.helperString(IS_MEMO_SAME)}(_cached, _memo)) return _cached`
  13925. ]),
  13926. createCompoundExpression([`const _item = `, childBlock]),
  13927. createSimpleExpression(`_item.memo = _memo`),
  13928. createSimpleExpression(`return _item`)
  13929. ]);
  13930. renderExp.arguments.push(loop, createSimpleExpression(`_cache`), createSimpleExpression(String(context.cached++)));
  13931. }
  13932. else {
  13933. renderExp.arguments.push(createFunctionExpression(createForLoopParams(forNode.parseResult), childBlock, true /* force newline */));
  13934. }
  13935. };
  13936. });
  13937. });
  13938. // target-agnostic transform used for both Client and SSR
  13939. function processFor(node, dir, context, processCodegen) {
  13940. if (!dir.exp) {
  13941. context.onError(createCompilerError(31 /* ErrorCodes.X_V_FOR_NO_EXPRESSION */, dir.loc));
  13942. return;
  13943. }
  13944. const parseResult = parseForExpression(
  13945. // can only be simple expression because vFor transform is applied
  13946. // before expression transform.
  13947. dir.exp, context);
  13948. if (!parseResult) {
  13949. context.onError(createCompilerError(32 /* ErrorCodes.X_V_FOR_MALFORMED_EXPRESSION */, dir.loc));
  13950. return;
  13951. }
  13952. const { addIdentifiers, removeIdentifiers, scopes } = context;
  13953. const { source, value, key, index } = parseResult;
  13954. const forNode = {
  13955. type: 11 /* NodeTypes.FOR */,
  13956. loc: dir.loc,
  13957. source,
  13958. valueAlias: value,
  13959. keyAlias: key,
  13960. objectIndexAlias: index,
  13961. parseResult,
  13962. children: isTemplateNode(node) ? node.children : [node]
  13963. };
  13964. context.replaceNode(forNode);
  13965. // bookkeeping
  13966. scopes.vFor++;
  13967. const onExit = processCodegen && processCodegen(forNode);
  13968. return () => {
  13969. scopes.vFor--;
  13970. if (onExit)
  13971. onExit();
  13972. };
  13973. }
  13974. const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/;
  13975. // This regex doesn't cover the case if key or index aliases have destructuring,
  13976. // but those do not make sense in the first place, so this works in practice.
  13977. const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/;
  13978. const stripParensRE = /^\(|\)$/g;
  13979. function parseForExpression(input, context) {
  13980. const loc = input.loc;
  13981. const exp = input.content;
  13982. const inMatch = exp.match(forAliasRE);
  13983. if (!inMatch)
  13984. return;
  13985. const [, LHS, RHS] = inMatch;
  13986. const result = {
  13987. source: createAliasExpression(loc, RHS.trim(), exp.indexOf(RHS, LHS.length)),
  13988. value: undefined,
  13989. key: undefined,
  13990. index: undefined
  13991. };
  13992. {
  13993. validateBrowserExpression(result.source, context);
  13994. }
  13995. let valueContent = LHS.trim().replace(stripParensRE, '').trim();
  13996. const trimmedOffset = LHS.indexOf(valueContent);
  13997. const iteratorMatch = valueContent.match(forIteratorRE);
  13998. if (iteratorMatch) {
  13999. valueContent = valueContent.replace(forIteratorRE, '').trim();
  14000. const keyContent = iteratorMatch[1].trim();
  14001. let keyOffset;
  14002. if (keyContent) {
  14003. keyOffset = exp.indexOf(keyContent, trimmedOffset + valueContent.length);
  14004. result.key = createAliasExpression(loc, keyContent, keyOffset);
  14005. {
  14006. validateBrowserExpression(result.key, context, true);
  14007. }
  14008. }
  14009. if (iteratorMatch[2]) {
  14010. const indexContent = iteratorMatch[2].trim();
  14011. if (indexContent) {
  14012. result.index = createAliasExpression(loc, indexContent, exp.indexOf(indexContent, result.key
  14013. ? keyOffset + keyContent.length
  14014. : trimmedOffset + valueContent.length));
  14015. {
  14016. validateBrowserExpression(result.index, context, true);
  14017. }
  14018. }
  14019. }
  14020. }
  14021. if (valueContent) {
  14022. result.value = createAliasExpression(loc, valueContent, trimmedOffset);
  14023. {
  14024. validateBrowserExpression(result.value, context, true);
  14025. }
  14026. }
  14027. return result;
  14028. }
  14029. function createAliasExpression(range, content, offset) {
  14030. return createSimpleExpression(content, false, getInnerRange(range, offset, content.length));
  14031. }
  14032. function createForLoopParams({ value, key, index }, memoArgs = []) {
  14033. return createParamsList([value, key, index, ...memoArgs]);
  14034. }
  14035. function createParamsList(args) {
  14036. let i = args.length;
  14037. while (i--) {
  14038. if (args[i])
  14039. break;
  14040. }
  14041. return args
  14042. .slice(0, i + 1)
  14043. .map((arg, i) => arg || createSimpleExpression(`_`.repeat(i + 1), false));
  14044. }
  14045. const defaultFallback = createSimpleExpression(`undefined`, false);
  14046. // A NodeTransform that:
  14047. // 1. Tracks scope identifiers for scoped slots so that they don't get prefixed
  14048. // by transformExpression. This is only applied in non-browser builds with
  14049. // { prefixIdentifiers: true }.
  14050. // 2. Track v-slot depths so that we know a slot is inside another slot.
  14051. // Note the exit callback is executed before buildSlots() on the same node,
  14052. // so only nested slots see positive numbers.
  14053. const trackSlotScopes = (node, context) => {
  14054. if (node.type === 1 /* NodeTypes.ELEMENT */ &&
  14055. (node.tagType === 1 /* ElementTypes.COMPONENT */ ||
  14056. node.tagType === 3 /* ElementTypes.TEMPLATE */)) {
  14057. // We are only checking non-empty v-slot here
  14058. // since we only care about slots that introduce scope variables.
  14059. const vSlot = findDir(node, 'slot');
  14060. if (vSlot) {
  14061. vSlot.exp;
  14062. context.scopes.vSlot++;
  14063. return () => {
  14064. context.scopes.vSlot--;
  14065. };
  14066. }
  14067. }
  14068. };
  14069. const buildClientSlotFn = (props, children, loc) => createFunctionExpression(props, children, false /* newline */, true /* isSlot */, children.length ? children[0].loc : loc);
  14070. // Instead of being a DirectiveTransform, v-slot processing is called during
  14071. // transformElement to build the slots object for a component.
  14072. function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
  14073. context.helper(WITH_CTX);
  14074. const { children, loc } = node;
  14075. const slotsProperties = [];
  14076. const dynamicSlots = [];
  14077. // If the slot is inside a v-for or another v-slot, force it to be dynamic
  14078. // since it likely uses a scope variable.
  14079. let hasDynamicSlots = context.scopes.vSlot > 0 || context.scopes.vFor > 0;
  14080. // 1. Check for slot with slotProps on component itself.
  14081. // <Comp v-slot="{ prop }"/>
  14082. const onComponentSlot = findDir(node, 'slot', true);
  14083. if (onComponentSlot) {
  14084. const { arg, exp } = onComponentSlot;
  14085. if (arg && !isStaticExp(arg)) {
  14086. hasDynamicSlots = true;
  14087. }
  14088. slotsProperties.push(createObjectProperty(arg || createSimpleExpression('default', true), buildSlotFn(exp, children, loc)));
  14089. }
  14090. // 2. Iterate through children and check for template slots
  14091. // <template v-slot:foo="{ prop }">
  14092. let hasTemplateSlots = false;
  14093. let hasNamedDefaultSlot = false;
  14094. const implicitDefaultChildren = [];
  14095. const seenSlotNames = new Set();
  14096. let conditionalBranchIndex = 0;
  14097. for (let i = 0; i < children.length; i++) {
  14098. const slotElement = children[i];
  14099. let slotDir;
  14100. if (!isTemplateNode(slotElement) ||
  14101. !(slotDir = findDir(slotElement, 'slot', true))) {
  14102. // not a <template v-slot>, skip.
  14103. if (slotElement.type !== 3 /* NodeTypes.COMMENT */) {
  14104. implicitDefaultChildren.push(slotElement);
  14105. }
  14106. continue;
  14107. }
  14108. if (onComponentSlot) {
  14109. // already has on-component slot - this is incorrect usage.
  14110. context.onError(createCompilerError(37 /* ErrorCodes.X_V_SLOT_MIXED_SLOT_USAGE */, slotDir.loc));
  14111. break;
  14112. }
  14113. hasTemplateSlots = true;
  14114. const { children: slotChildren, loc: slotLoc } = slotElement;
  14115. const { arg: slotName = createSimpleExpression(`default`, true), exp: slotProps, loc: dirLoc } = slotDir;
  14116. // check if name is dynamic.
  14117. let staticSlotName;
  14118. if (isStaticExp(slotName)) {
  14119. staticSlotName = slotName ? slotName.content : `default`;
  14120. }
  14121. else {
  14122. hasDynamicSlots = true;
  14123. }
  14124. const slotFunction = buildSlotFn(slotProps, slotChildren, slotLoc);
  14125. // check if this slot is conditional (v-if/v-for)
  14126. let vIf;
  14127. let vElse;
  14128. let vFor;
  14129. if ((vIf = findDir(slotElement, 'if'))) {
  14130. hasDynamicSlots = true;
  14131. dynamicSlots.push(createConditionalExpression(vIf.exp, buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++), defaultFallback));
  14132. }
  14133. else if ((vElse = findDir(slotElement, /^else(-if)?$/, true /* allowEmpty */))) {
  14134. // find adjacent v-if
  14135. let j = i;
  14136. let prev;
  14137. while (j--) {
  14138. prev = children[j];
  14139. if (prev.type !== 3 /* NodeTypes.COMMENT */) {
  14140. break;
  14141. }
  14142. }
  14143. if (prev && isTemplateNode(prev) && findDir(prev, 'if')) {
  14144. // remove node
  14145. children.splice(i, 1);
  14146. i--;
  14147. // attach this slot to previous conditional
  14148. let conditional = dynamicSlots[dynamicSlots.length - 1];
  14149. while (conditional.alternate.type === 19 /* NodeTypes.JS_CONDITIONAL_EXPRESSION */) {
  14150. conditional = conditional.alternate;
  14151. }
  14152. conditional.alternate = vElse.exp
  14153. ? createConditionalExpression(vElse.exp, buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++), defaultFallback)
  14154. : buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++);
  14155. }
  14156. else {
  14157. context.onError(createCompilerError(30 /* ErrorCodes.X_V_ELSE_NO_ADJACENT_IF */, vElse.loc));
  14158. }
  14159. }
  14160. else if ((vFor = findDir(slotElement, 'for'))) {
  14161. hasDynamicSlots = true;
  14162. const parseResult = vFor.parseResult ||
  14163. parseForExpression(vFor.exp, context);
  14164. if (parseResult) {
  14165. // Render the dynamic slots as an array and add it to the createSlot()
  14166. // args. The runtime knows how to handle it appropriately.
  14167. dynamicSlots.push(createCallExpression(context.helper(RENDER_LIST), [
  14168. parseResult.source,
  14169. createFunctionExpression(createForLoopParams(parseResult), buildDynamicSlot(slotName, slotFunction), true /* force newline */)
  14170. ]));
  14171. }
  14172. else {
  14173. context.onError(createCompilerError(32 /* ErrorCodes.X_V_FOR_MALFORMED_EXPRESSION */, vFor.loc));
  14174. }
  14175. }
  14176. else {
  14177. // check duplicate static names
  14178. if (staticSlotName) {
  14179. if (seenSlotNames.has(staticSlotName)) {
  14180. context.onError(createCompilerError(38 /* ErrorCodes.X_V_SLOT_DUPLICATE_SLOT_NAMES */, dirLoc));
  14181. continue;
  14182. }
  14183. seenSlotNames.add(staticSlotName);
  14184. if (staticSlotName === 'default') {
  14185. hasNamedDefaultSlot = true;
  14186. }
  14187. }
  14188. slotsProperties.push(createObjectProperty(slotName, slotFunction));
  14189. }
  14190. }
  14191. if (!onComponentSlot) {
  14192. const buildDefaultSlotProperty = (props, children) => {
  14193. const fn = buildSlotFn(props, children, loc);
  14194. return createObjectProperty(`default`, fn);
  14195. };
  14196. if (!hasTemplateSlots) {
  14197. // implicit default slot (on component)
  14198. slotsProperties.push(buildDefaultSlotProperty(undefined, children));
  14199. }
  14200. else if (implicitDefaultChildren.length &&
  14201. // #3766
  14202. // with whitespace: 'preserve', whitespaces between slots will end up in
  14203. // implicitDefaultChildren. Ignore if all implicit children are whitespaces.
  14204. implicitDefaultChildren.some(node => isNonWhitespaceContent(node))) {
  14205. // implicit default slot (mixed with named slots)
  14206. if (hasNamedDefaultSlot) {
  14207. context.onError(createCompilerError(39 /* ErrorCodes.X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN */, implicitDefaultChildren[0].loc));
  14208. }
  14209. else {
  14210. slotsProperties.push(buildDefaultSlotProperty(undefined, implicitDefaultChildren));
  14211. }
  14212. }
  14213. }
  14214. const slotFlag = hasDynamicSlots
  14215. ? 2 /* SlotFlags.DYNAMIC */
  14216. : hasForwardedSlots(node.children)
  14217. ? 3 /* SlotFlags.FORWARDED */
  14218. : 1 /* SlotFlags.STABLE */;
  14219. let slots = createObjectExpression(slotsProperties.concat(createObjectProperty(`_`,
  14220. // 2 = compiled but dynamic = can skip normalization, but must run diff
  14221. // 1 = compiled and static = can skip normalization AND diff as optimized
  14222. createSimpleExpression(slotFlag + (` /* ${slotFlagsText[slotFlag]} */` ), false))), loc);
  14223. if (dynamicSlots.length) {
  14224. slots = createCallExpression(context.helper(CREATE_SLOTS), [
  14225. slots,
  14226. createArrayExpression(dynamicSlots)
  14227. ]);
  14228. }
  14229. return {
  14230. slots,
  14231. hasDynamicSlots
  14232. };
  14233. }
  14234. function buildDynamicSlot(name, fn, index) {
  14235. const props = [
  14236. createObjectProperty(`name`, name),
  14237. createObjectProperty(`fn`, fn)
  14238. ];
  14239. if (index != null) {
  14240. props.push(createObjectProperty(`key`, createSimpleExpression(String(index), true)));
  14241. }
  14242. return createObjectExpression(props);
  14243. }
  14244. function hasForwardedSlots(children) {
  14245. for (let i = 0; i < children.length; i++) {
  14246. const child = children[i];
  14247. switch (child.type) {
  14248. case 1 /* NodeTypes.ELEMENT */:
  14249. if (child.tagType === 2 /* ElementTypes.SLOT */ ||
  14250. hasForwardedSlots(child.children)) {
  14251. return true;
  14252. }
  14253. break;
  14254. case 9 /* NodeTypes.IF */:
  14255. if (hasForwardedSlots(child.branches))
  14256. return true;
  14257. break;
  14258. case 10 /* NodeTypes.IF_BRANCH */:
  14259. case 11 /* NodeTypes.FOR */:
  14260. if (hasForwardedSlots(child.children))
  14261. return true;
  14262. break;
  14263. }
  14264. }
  14265. return false;
  14266. }
  14267. function isNonWhitespaceContent(node) {
  14268. if (node.type !== 2 /* NodeTypes.TEXT */ && node.type !== 12 /* NodeTypes.TEXT_CALL */)
  14269. return true;
  14270. return node.type === 2 /* NodeTypes.TEXT */
  14271. ? !!node.content.trim()
  14272. : isNonWhitespaceContent(node.content);
  14273. }
  14274. // some directive transforms (e.g. v-model) may return a symbol for runtime
  14275. // import, which should be used instead of a resolveDirective call.
  14276. const directiveImportMap = new WeakMap();
  14277. // generate a JavaScript AST for this element's codegen
  14278. const transformElement = (node, context) => {
  14279. // perform the work on exit, after all child expressions have been
  14280. // processed and merged.
  14281. return function postTransformElement() {
  14282. node = context.currentNode;
  14283. if (!(node.type === 1 /* NodeTypes.ELEMENT */ &&
  14284. (node.tagType === 0 /* ElementTypes.ELEMENT */ ||
  14285. node.tagType === 1 /* ElementTypes.COMPONENT */))) {
  14286. return;
  14287. }
  14288. const { tag, props } = node;
  14289. const isComponent = node.tagType === 1 /* ElementTypes.COMPONENT */;
  14290. // The goal of the transform is to create a codegenNode implementing the
  14291. // VNodeCall interface.
  14292. let vnodeTag = isComponent
  14293. ? resolveComponentType(node, context)
  14294. : `"${tag}"`;
  14295. const isDynamicComponent = isObject(vnodeTag) && vnodeTag.callee === RESOLVE_DYNAMIC_COMPONENT;
  14296. let vnodeProps;
  14297. let vnodeChildren;
  14298. let vnodePatchFlag;
  14299. let patchFlag = 0;
  14300. let vnodeDynamicProps;
  14301. let dynamicPropNames;
  14302. let vnodeDirectives;
  14303. let shouldUseBlock =
  14304. // dynamic component may resolve to plain elements
  14305. isDynamicComponent ||
  14306. vnodeTag === TELEPORT ||
  14307. vnodeTag === SUSPENSE ||
  14308. (!isComponent &&
  14309. // <svg> and <foreignObject> must be forced into blocks so that block
  14310. // updates inside get proper isSVG flag at runtime. (#639, #643)
  14311. // This is technically web-specific, but splitting the logic out of core
  14312. // leads to too much unnecessary complexity.
  14313. (tag === 'svg' || tag === 'foreignObject'));
  14314. // props
  14315. if (props.length > 0) {
  14316. const propsBuildResult = buildProps(node, context, undefined, isComponent, isDynamicComponent);
  14317. vnodeProps = propsBuildResult.props;
  14318. patchFlag = propsBuildResult.patchFlag;
  14319. dynamicPropNames = propsBuildResult.dynamicPropNames;
  14320. const directives = propsBuildResult.directives;
  14321. vnodeDirectives =
  14322. directives && directives.length
  14323. ? createArrayExpression(directives.map(dir => buildDirectiveArgs(dir, context)))
  14324. : undefined;
  14325. if (propsBuildResult.shouldUseBlock) {
  14326. shouldUseBlock = true;
  14327. }
  14328. }
  14329. // children
  14330. if (node.children.length > 0) {
  14331. if (vnodeTag === KEEP_ALIVE) {
  14332. // Although a built-in component, we compile KeepAlive with raw children
  14333. // instead of slot functions so that it can be used inside Transition
  14334. // or other Transition-wrapping HOCs.
  14335. // To ensure correct updates with block optimizations, we need to:
  14336. // 1. Force keep-alive into a block. This avoids its children being
  14337. // collected by a parent block.
  14338. shouldUseBlock = true;
  14339. // 2. Force keep-alive to always be updated, since it uses raw children.
  14340. patchFlag |= 1024 /* PatchFlags.DYNAMIC_SLOTS */;
  14341. if (node.children.length > 1) {
  14342. context.onError(createCompilerError(46 /* ErrorCodes.X_KEEP_ALIVE_INVALID_CHILDREN */, {
  14343. start: node.children[0].loc.start,
  14344. end: node.children[node.children.length - 1].loc.end,
  14345. source: ''
  14346. }));
  14347. }
  14348. }
  14349. const shouldBuildAsSlots = isComponent &&
  14350. // Teleport is not a real component and has dedicated runtime handling
  14351. vnodeTag !== TELEPORT &&
  14352. // explained above.
  14353. vnodeTag !== KEEP_ALIVE;
  14354. if (shouldBuildAsSlots) {
  14355. const { slots, hasDynamicSlots } = buildSlots(node, context);
  14356. vnodeChildren = slots;
  14357. if (hasDynamicSlots) {
  14358. patchFlag |= 1024 /* PatchFlags.DYNAMIC_SLOTS */;
  14359. }
  14360. }
  14361. else if (node.children.length === 1 && vnodeTag !== TELEPORT) {
  14362. const child = node.children[0];
  14363. const type = child.type;
  14364. // check for dynamic text children
  14365. const hasDynamicTextChild = type === 5 /* NodeTypes.INTERPOLATION */ ||
  14366. type === 8 /* NodeTypes.COMPOUND_EXPRESSION */;
  14367. if (hasDynamicTextChild &&
  14368. getConstantType(child, context) === 0 /* ConstantTypes.NOT_CONSTANT */) {
  14369. patchFlag |= 1 /* PatchFlags.TEXT */;
  14370. }
  14371. // pass directly if the only child is a text node
  14372. // (plain / interpolation / expression)
  14373. if (hasDynamicTextChild || type === 2 /* NodeTypes.TEXT */) {
  14374. vnodeChildren = child;
  14375. }
  14376. else {
  14377. vnodeChildren = node.children;
  14378. }
  14379. }
  14380. else {
  14381. vnodeChildren = node.children;
  14382. }
  14383. }
  14384. // patchFlag & dynamicPropNames
  14385. if (patchFlag !== 0) {
  14386. {
  14387. if (patchFlag < 0) {
  14388. // special flags (negative and mutually exclusive)
  14389. vnodePatchFlag = patchFlag + ` /* ${PatchFlagNames[patchFlag]} */`;
  14390. }
  14391. else {
  14392. // bitwise flags
  14393. const flagNames = Object.keys(PatchFlagNames)
  14394. .map(Number)
  14395. .filter(n => n > 0 && patchFlag & n)
  14396. .map(n => PatchFlagNames[n])
  14397. .join(`, `);
  14398. vnodePatchFlag = patchFlag + ` /* ${flagNames} */`;
  14399. }
  14400. }
  14401. if (dynamicPropNames && dynamicPropNames.length) {
  14402. vnodeDynamicProps = stringifyDynamicPropNames(dynamicPropNames);
  14403. }
  14404. }
  14405. node.codegenNode = createVNodeCall(context, vnodeTag, vnodeProps, vnodeChildren, vnodePatchFlag, vnodeDynamicProps, vnodeDirectives, !!shouldUseBlock, false /* disableTracking */, isComponent, node.loc);
  14406. };
  14407. };
  14408. function resolveComponentType(node, context, ssr = false) {
  14409. let { tag } = node;
  14410. // 1. dynamic component
  14411. const isExplicitDynamic = isComponentTag(tag);
  14412. const isProp = findProp(node, 'is');
  14413. if (isProp) {
  14414. if (isExplicitDynamic ||
  14415. (false )) {
  14416. const exp = isProp.type === 6 /* NodeTypes.ATTRIBUTE */
  14417. ? isProp.value && createSimpleExpression(isProp.value.content, true)
  14418. : isProp.exp;
  14419. if (exp) {
  14420. return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
  14421. exp
  14422. ]);
  14423. }
  14424. }
  14425. else if (isProp.type === 6 /* NodeTypes.ATTRIBUTE */ &&
  14426. isProp.value.content.startsWith('vue:')) {
  14427. // <button is="vue:xxx">
  14428. // if not <component>, only is value that starts with "vue:" will be
  14429. // treated as component by the parse phase and reach here, unless it's
  14430. // compat mode where all is values are considered components
  14431. tag = isProp.value.content.slice(4);
  14432. }
  14433. }
  14434. // 1.5 v-is (TODO: Deprecate)
  14435. const isDir = !isExplicitDynamic && findDir(node, 'is');
  14436. if (isDir && isDir.exp) {
  14437. return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
  14438. isDir.exp
  14439. ]);
  14440. }
  14441. // 2. built-in components (Teleport, Transition, KeepAlive, Suspense...)
  14442. const builtIn = isCoreComponent(tag) || context.isBuiltInComponent(tag);
  14443. if (builtIn) {
  14444. // built-ins are simply fallthroughs / have special handling during ssr
  14445. // so we don't need to import their runtime equivalents
  14446. if (!ssr)
  14447. context.helper(builtIn);
  14448. return builtIn;
  14449. }
  14450. // 5. user component (resolve)
  14451. context.helper(RESOLVE_COMPONENT);
  14452. context.components.add(tag);
  14453. return toValidAssetId(tag, `component`);
  14454. }
  14455. function buildProps(node, context, props = node.props, isComponent, isDynamicComponent, ssr = false) {
  14456. const { tag, loc: elementLoc, children } = node;
  14457. let properties = [];
  14458. const mergeArgs = [];
  14459. const runtimeDirectives = [];
  14460. const hasChildren = children.length > 0;
  14461. let shouldUseBlock = false;
  14462. // patchFlag analysis
  14463. let patchFlag = 0;
  14464. let hasRef = false;
  14465. let hasClassBinding = false;
  14466. let hasStyleBinding = false;
  14467. let hasHydrationEventBinding = false;
  14468. let hasDynamicKeys = false;
  14469. let hasVnodeHook = false;
  14470. const dynamicPropNames = [];
  14471. const pushMergeArg = (arg) => {
  14472. if (properties.length) {
  14473. mergeArgs.push(createObjectExpression(dedupeProperties(properties), elementLoc));
  14474. properties = [];
  14475. }
  14476. if (arg)
  14477. mergeArgs.push(arg);
  14478. };
  14479. const analyzePatchFlag = ({ key, value }) => {
  14480. if (isStaticExp(key)) {
  14481. const name = key.content;
  14482. const isEventHandler = isOn(name);
  14483. if (isEventHandler &&
  14484. (!isComponent || isDynamicComponent) &&
  14485. // omit the flag for click handlers because hydration gives click
  14486. // dedicated fast path.
  14487. name.toLowerCase() !== 'onclick' &&
  14488. // omit v-model handlers
  14489. name !== 'onUpdate:modelValue' &&
  14490. // omit onVnodeXXX hooks
  14491. !isReservedProp(name)) {
  14492. hasHydrationEventBinding = true;
  14493. }
  14494. if (isEventHandler && isReservedProp(name)) {
  14495. hasVnodeHook = true;
  14496. }
  14497. if (value.type === 20 /* NodeTypes.JS_CACHE_EXPRESSION */ ||
  14498. ((value.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ ||
  14499. value.type === 8 /* NodeTypes.COMPOUND_EXPRESSION */) &&
  14500. getConstantType(value, context) > 0)) {
  14501. // skip if the prop is a cached handler or has constant value
  14502. return;
  14503. }
  14504. if (name === 'ref') {
  14505. hasRef = true;
  14506. }
  14507. else if (name === 'class') {
  14508. hasClassBinding = true;
  14509. }
  14510. else if (name === 'style') {
  14511. hasStyleBinding = true;
  14512. }
  14513. else if (name !== 'key' && !dynamicPropNames.includes(name)) {
  14514. dynamicPropNames.push(name);
  14515. }
  14516. // treat the dynamic class and style binding of the component as dynamic props
  14517. if (isComponent &&
  14518. (name === 'class' || name === 'style') &&
  14519. !dynamicPropNames.includes(name)) {
  14520. dynamicPropNames.push(name);
  14521. }
  14522. }
  14523. else {
  14524. hasDynamicKeys = true;
  14525. }
  14526. };
  14527. for (let i = 0; i < props.length; i++) {
  14528. // static attribute
  14529. const prop = props[i];
  14530. if (prop.type === 6 /* NodeTypes.ATTRIBUTE */) {
  14531. const { loc, name, value } = prop;
  14532. let isStatic = true;
  14533. if (name === 'ref') {
  14534. hasRef = true;
  14535. if (context.scopes.vFor > 0) {
  14536. properties.push(createObjectProperty(createSimpleExpression('ref_for', true), createSimpleExpression('true')));
  14537. }
  14538. }
  14539. // skip is on <component>, or is="vue:xxx"
  14540. if (name === 'is' &&
  14541. (isComponentTag(tag) ||
  14542. (value && value.content.startsWith('vue:')) ||
  14543. (false ))) {
  14544. continue;
  14545. }
  14546. properties.push(createObjectProperty(createSimpleExpression(name, true, getInnerRange(loc, 0, name.length)), createSimpleExpression(value ? value.content : '', isStatic, value ? value.loc : loc)));
  14547. }
  14548. else {
  14549. // directives
  14550. const { name, arg, exp, loc } = prop;
  14551. const isVBind = name === 'bind';
  14552. const isVOn = name === 'on';
  14553. // skip v-slot - it is handled by its dedicated transform.
  14554. if (name === 'slot') {
  14555. if (!isComponent) {
  14556. context.onError(createCompilerError(40 /* ErrorCodes.X_V_SLOT_MISPLACED */, loc));
  14557. }
  14558. continue;
  14559. }
  14560. // skip v-once/v-memo - they are handled by dedicated transforms.
  14561. if (name === 'once' || name === 'memo') {
  14562. continue;
  14563. }
  14564. // skip v-is and :is on <component>
  14565. if (name === 'is' ||
  14566. (isVBind &&
  14567. isStaticArgOf(arg, 'is') &&
  14568. (isComponentTag(tag) ||
  14569. (false )))) {
  14570. continue;
  14571. }
  14572. // skip v-on in SSR compilation
  14573. if (isVOn && ssr) {
  14574. continue;
  14575. }
  14576. if (
  14577. // #938: elements with dynamic keys should be forced into blocks
  14578. (isVBind && isStaticArgOf(arg, 'key')) ||
  14579. // inline before-update hooks need to force block so that it is invoked
  14580. // before children
  14581. (isVOn && hasChildren && isStaticArgOf(arg, 'vue:before-update'))) {
  14582. shouldUseBlock = true;
  14583. }
  14584. if (isVBind && isStaticArgOf(arg, 'ref') && context.scopes.vFor > 0) {
  14585. properties.push(createObjectProperty(createSimpleExpression('ref_for', true), createSimpleExpression('true')));
  14586. }
  14587. // special case for v-bind and v-on with no argument
  14588. if (!arg && (isVBind || isVOn)) {
  14589. hasDynamicKeys = true;
  14590. if (exp) {
  14591. if (isVBind) {
  14592. // have to merge early for compat build check
  14593. pushMergeArg();
  14594. mergeArgs.push(exp);
  14595. }
  14596. else {
  14597. // v-on="obj" -> toHandlers(obj)
  14598. pushMergeArg({
  14599. type: 14 /* NodeTypes.JS_CALL_EXPRESSION */,
  14600. loc,
  14601. callee: context.helper(TO_HANDLERS),
  14602. arguments: isComponent ? [exp] : [exp, `true`]
  14603. });
  14604. }
  14605. }
  14606. else {
  14607. context.onError(createCompilerError(isVBind
  14608. ? 34 /* ErrorCodes.X_V_BIND_NO_EXPRESSION */
  14609. : 35 /* ErrorCodes.X_V_ON_NO_EXPRESSION */, loc));
  14610. }
  14611. continue;
  14612. }
  14613. const directiveTransform = context.directiveTransforms[name];
  14614. if (directiveTransform) {
  14615. // has built-in directive transform.
  14616. const { props, needRuntime } = directiveTransform(prop, node, context);
  14617. !ssr && props.forEach(analyzePatchFlag);
  14618. if (isVOn && arg && !isStaticExp(arg)) {
  14619. pushMergeArg(createObjectExpression(props, elementLoc));
  14620. }
  14621. else {
  14622. properties.push(...props);
  14623. }
  14624. if (needRuntime) {
  14625. runtimeDirectives.push(prop);
  14626. if (isSymbol(needRuntime)) {
  14627. directiveImportMap.set(prop, needRuntime);
  14628. }
  14629. }
  14630. }
  14631. else if (!isBuiltInDirective(name)) {
  14632. // no built-in transform, this is a user custom directive.
  14633. runtimeDirectives.push(prop);
  14634. // custom dirs may use beforeUpdate so they need to force blocks
  14635. // to ensure before-update gets called before children update
  14636. if (hasChildren) {
  14637. shouldUseBlock = true;
  14638. }
  14639. }
  14640. }
  14641. }
  14642. let propsExpression = undefined;
  14643. // has v-bind="object" or v-on="object", wrap with mergeProps
  14644. if (mergeArgs.length) {
  14645. // close up any not-yet-merged props
  14646. pushMergeArg();
  14647. if (mergeArgs.length > 1) {
  14648. propsExpression = createCallExpression(context.helper(MERGE_PROPS), mergeArgs, elementLoc);
  14649. }
  14650. else {
  14651. // single v-bind with nothing else - no need for a mergeProps call
  14652. propsExpression = mergeArgs[0];
  14653. }
  14654. }
  14655. else if (properties.length) {
  14656. propsExpression = createObjectExpression(dedupeProperties(properties), elementLoc);
  14657. }
  14658. // patchFlag analysis
  14659. if (hasDynamicKeys) {
  14660. patchFlag |= 16 /* PatchFlags.FULL_PROPS */;
  14661. }
  14662. else {
  14663. if (hasClassBinding && !isComponent) {
  14664. patchFlag |= 2 /* PatchFlags.CLASS */;
  14665. }
  14666. if (hasStyleBinding && !isComponent) {
  14667. patchFlag |= 4 /* PatchFlags.STYLE */;
  14668. }
  14669. if (dynamicPropNames.length) {
  14670. patchFlag |= 8 /* PatchFlags.PROPS */;
  14671. }
  14672. if (hasHydrationEventBinding) {
  14673. patchFlag |= 32 /* PatchFlags.HYDRATE_EVENTS */;
  14674. }
  14675. }
  14676. if (!shouldUseBlock &&
  14677. (patchFlag === 0 || patchFlag === 32 /* PatchFlags.HYDRATE_EVENTS */) &&
  14678. (hasRef || hasVnodeHook || runtimeDirectives.length > 0)) {
  14679. patchFlag |= 512 /* PatchFlags.NEED_PATCH */;
  14680. }
  14681. // pre-normalize props, SSR is skipped for now
  14682. if (!context.inSSR && propsExpression) {
  14683. switch (propsExpression.type) {
  14684. case 15 /* NodeTypes.JS_OBJECT_EXPRESSION */:
  14685. // means that there is no v-bind,
  14686. // but still need to deal with dynamic key binding
  14687. let classKeyIndex = -1;
  14688. let styleKeyIndex = -1;
  14689. let hasDynamicKey = false;
  14690. for (let i = 0; i < propsExpression.properties.length; i++) {
  14691. const key = propsExpression.properties[i].key;
  14692. if (isStaticExp(key)) {
  14693. if (key.content === 'class') {
  14694. classKeyIndex = i;
  14695. }
  14696. else if (key.content === 'style') {
  14697. styleKeyIndex = i;
  14698. }
  14699. }
  14700. else if (!key.isHandlerKey) {
  14701. hasDynamicKey = true;
  14702. }
  14703. }
  14704. const classProp = propsExpression.properties[classKeyIndex];
  14705. const styleProp = propsExpression.properties[styleKeyIndex];
  14706. // no dynamic key
  14707. if (!hasDynamicKey) {
  14708. if (classProp && !isStaticExp(classProp.value)) {
  14709. classProp.value = createCallExpression(context.helper(NORMALIZE_CLASS), [classProp.value]);
  14710. }
  14711. if (styleProp &&
  14712. // the static style is compiled into an object,
  14713. // so use `hasStyleBinding` to ensure that it is a dynamic style binding
  14714. (hasStyleBinding ||
  14715. (styleProp.value.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ &&
  14716. styleProp.value.content.trim()[0] === `[`) ||
  14717. // v-bind:style and style both exist,
  14718. // v-bind:style with static literal object
  14719. styleProp.value.type === 17 /* NodeTypes.JS_ARRAY_EXPRESSION */)) {
  14720. styleProp.value = createCallExpression(context.helper(NORMALIZE_STYLE), [styleProp.value]);
  14721. }
  14722. }
  14723. else {
  14724. // dynamic key binding, wrap with `normalizeProps`
  14725. propsExpression = createCallExpression(context.helper(NORMALIZE_PROPS), [propsExpression]);
  14726. }
  14727. break;
  14728. case 14 /* NodeTypes.JS_CALL_EXPRESSION */:
  14729. // mergeProps call, do nothing
  14730. break;
  14731. default:
  14732. // single v-bind
  14733. propsExpression = createCallExpression(context.helper(NORMALIZE_PROPS), [
  14734. createCallExpression(context.helper(GUARD_REACTIVE_PROPS), [
  14735. propsExpression
  14736. ])
  14737. ]);
  14738. break;
  14739. }
  14740. }
  14741. return {
  14742. props: propsExpression,
  14743. directives: runtimeDirectives,
  14744. patchFlag,
  14745. dynamicPropNames,
  14746. shouldUseBlock
  14747. };
  14748. }
  14749. // Dedupe props in an object literal.
  14750. // Literal duplicated attributes would have been warned during the parse phase,
  14751. // however, it's possible to encounter duplicated `onXXX` handlers with different
  14752. // modifiers. We also need to merge static and dynamic class / style attributes.
  14753. // - onXXX handlers / style: merge into array
  14754. // - class: merge into single expression with concatenation
  14755. function dedupeProperties(properties) {
  14756. const knownProps = new Map();
  14757. const deduped = [];
  14758. for (let i = 0; i < properties.length; i++) {
  14759. const prop = properties[i];
  14760. // dynamic keys are always allowed
  14761. if (prop.key.type === 8 /* NodeTypes.COMPOUND_EXPRESSION */ || !prop.key.isStatic) {
  14762. deduped.push(prop);
  14763. continue;
  14764. }
  14765. const name = prop.key.content;
  14766. const existing = knownProps.get(name);
  14767. if (existing) {
  14768. if (name === 'style' || name === 'class' || isOn(name)) {
  14769. mergeAsArray$1(existing, prop);
  14770. }
  14771. // unexpected duplicate, should have emitted error during parse
  14772. }
  14773. else {
  14774. knownProps.set(name, prop);
  14775. deduped.push(prop);
  14776. }
  14777. }
  14778. return deduped;
  14779. }
  14780. function mergeAsArray$1(existing, incoming) {
  14781. if (existing.value.type === 17 /* NodeTypes.JS_ARRAY_EXPRESSION */) {
  14782. existing.value.elements.push(incoming.value);
  14783. }
  14784. else {
  14785. existing.value = createArrayExpression([existing.value, incoming.value], existing.loc);
  14786. }
  14787. }
  14788. function buildDirectiveArgs(dir, context) {
  14789. const dirArgs = [];
  14790. const runtime = directiveImportMap.get(dir);
  14791. if (runtime) {
  14792. // built-in directive with runtime
  14793. dirArgs.push(context.helperString(runtime));
  14794. }
  14795. else {
  14796. {
  14797. // inject statement for resolving directive
  14798. context.helper(RESOLVE_DIRECTIVE);
  14799. context.directives.add(dir.name);
  14800. dirArgs.push(toValidAssetId(dir.name, `directive`));
  14801. }
  14802. }
  14803. const { loc } = dir;
  14804. if (dir.exp)
  14805. dirArgs.push(dir.exp);
  14806. if (dir.arg) {
  14807. if (!dir.exp) {
  14808. dirArgs.push(`void 0`);
  14809. }
  14810. dirArgs.push(dir.arg);
  14811. }
  14812. if (Object.keys(dir.modifiers).length) {
  14813. if (!dir.arg) {
  14814. if (!dir.exp) {
  14815. dirArgs.push(`void 0`);
  14816. }
  14817. dirArgs.push(`void 0`);
  14818. }
  14819. const trueExpression = createSimpleExpression(`true`, false, loc);
  14820. dirArgs.push(createObjectExpression(dir.modifiers.map(modifier => createObjectProperty(modifier, trueExpression)), loc));
  14821. }
  14822. return createArrayExpression(dirArgs, dir.loc);
  14823. }
  14824. function stringifyDynamicPropNames(props) {
  14825. let propsNamesString = `[`;
  14826. for (let i = 0, l = props.length; i < l; i++) {
  14827. propsNamesString += JSON.stringify(props[i]);
  14828. if (i < l - 1)
  14829. propsNamesString += ', ';
  14830. }
  14831. return propsNamesString + `]`;
  14832. }
  14833. function isComponentTag(tag) {
  14834. return tag === 'component' || tag === 'Component';
  14835. }
  14836. const transformSlotOutlet = (node, context) => {
  14837. if (isSlotOutlet(node)) {
  14838. const { children, loc } = node;
  14839. const { slotName, slotProps } = processSlotOutlet(node, context);
  14840. const slotArgs = [
  14841. context.prefixIdentifiers ? `_ctx.$slots` : `$slots`,
  14842. slotName,
  14843. '{}',
  14844. 'undefined',
  14845. 'true'
  14846. ];
  14847. let expectedLen = 2;
  14848. if (slotProps) {
  14849. slotArgs[2] = slotProps;
  14850. expectedLen = 3;
  14851. }
  14852. if (children.length) {
  14853. slotArgs[3] = createFunctionExpression([], children, false, false, loc);
  14854. expectedLen = 4;
  14855. }
  14856. if (context.scopeId && !context.slotted) {
  14857. expectedLen = 5;
  14858. }
  14859. slotArgs.splice(expectedLen); // remove unused arguments
  14860. node.codegenNode = createCallExpression(context.helper(RENDER_SLOT), slotArgs, loc);
  14861. }
  14862. };
  14863. function processSlotOutlet(node, context) {
  14864. let slotName = `"default"`;
  14865. let slotProps = undefined;
  14866. const nonNameProps = [];
  14867. for (let i = 0; i < node.props.length; i++) {
  14868. const p = node.props[i];
  14869. if (p.type === 6 /* NodeTypes.ATTRIBUTE */) {
  14870. if (p.value) {
  14871. if (p.name === 'name') {
  14872. slotName = JSON.stringify(p.value.content);
  14873. }
  14874. else {
  14875. p.name = camelize(p.name);
  14876. nonNameProps.push(p);
  14877. }
  14878. }
  14879. }
  14880. else {
  14881. if (p.name === 'bind' && isStaticArgOf(p.arg, 'name')) {
  14882. if (p.exp)
  14883. slotName = p.exp;
  14884. }
  14885. else {
  14886. if (p.name === 'bind' && p.arg && isStaticExp(p.arg)) {
  14887. p.arg.content = camelize(p.arg.content);
  14888. }
  14889. nonNameProps.push(p);
  14890. }
  14891. }
  14892. }
  14893. if (nonNameProps.length > 0) {
  14894. const { props, directives } = buildProps(node, context, nonNameProps, false, false);
  14895. slotProps = props;
  14896. if (directives.length) {
  14897. context.onError(createCompilerError(36 /* ErrorCodes.X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET */, directives[0].loc));
  14898. }
  14899. }
  14900. return {
  14901. slotName,
  14902. slotProps
  14903. };
  14904. }
  14905. const fnExpRE = /^\s*([\w$_]+|(async\s*)?\([^)]*?\))\s*(:[^=]+)?=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/;
  14906. const transformOn = (dir, node, context, augmentor) => {
  14907. const { loc, modifiers, arg } = dir;
  14908. if (!dir.exp && !modifiers.length) {
  14909. context.onError(createCompilerError(35 /* ErrorCodes.X_V_ON_NO_EXPRESSION */, loc));
  14910. }
  14911. let eventName;
  14912. if (arg.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
  14913. if (arg.isStatic) {
  14914. let rawName = arg.content;
  14915. // TODO deprecate @vnodeXXX usage
  14916. if (rawName.startsWith('vue:')) {
  14917. rawName = `vnode-${rawName.slice(4)}`;
  14918. }
  14919. const eventString = node.tagType !== 0 /* ElementTypes.ELEMENT */ ||
  14920. rawName.startsWith('vnode') ||
  14921. !/[A-Z]/.test(rawName)
  14922. ? // for non-element and vnode lifecycle event listeners, auto convert
  14923. // it to camelCase. See issue #2249
  14924. toHandlerKey(camelize(rawName))
  14925. : // preserve case for plain element listeners that have uppercase
  14926. // letters, as these may be custom elements' custom events
  14927. `on:${rawName}`;
  14928. eventName = createSimpleExpression(eventString, true, arg.loc);
  14929. }
  14930. else {
  14931. // #2388
  14932. eventName = createCompoundExpression([
  14933. `${context.helperString(TO_HANDLER_KEY)}(`,
  14934. arg,
  14935. `)`
  14936. ]);
  14937. }
  14938. }
  14939. else {
  14940. // already a compound expression.
  14941. eventName = arg;
  14942. eventName.children.unshift(`${context.helperString(TO_HANDLER_KEY)}(`);
  14943. eventName.children.push(`)`);
  14944. }
  14945. // handler processing
  14946. let exp = dir.exp;
  14947. if (exp && !exp.content.trim()) {
  14948. exp = undefined;
  14949. }
  14950. let shouldCache = context.cacheHandlers && !exp && !context.inVOnce;
  14951. if (exp) {
  14952. const isMemberExp = isMemberExpression(exp.content);
  14953. const isInlineStatement = !(isMemberExp || fnExpRE.test(exp.content));
  14954. const hasMultipleStatements = exp.content.includes(`;`);
  14955. {
  14956. validateBrowserExpression(exp, context, false, hasMultipleStatements);
  14957. }
  14958. if (isInlineStatement || (shouldCache && isMemberExp)) {
  14959. // wrap inline statement in a function expression
  14960. exp = createCompoundExpression([
  14961. `${isInlineStatement
  14962. ? `$event`
  14963. : `${``}(...args)`} => ${hasMultipleStatements ? `{` : `(`}`,
  14964. exp,
  14965. hasMultipleStatements ? `}` : `)`
  14966. ]);
  14967. }
  14968. }
  14969. let ret = {
  14970. props: [
  14971. createObjectProperty(eventName, exp || createSimpleExpression(`() => {}`, false, loc))
  14972. ]
  14973. };
  14974. // apply extended compiler augmentor
  14975. if (augmentor) {
  14976. ret = augmentor(ret);
  14977. }
  14978. if (shouldCache) {
  14979. // cache handlers so that it's always the same handler being passed down.
  14980. // this avoids unnecessary re-renders when users use inline handlers on
  14981. // components.
  14982. ret.props[0].value = context.cache(ret.props[0].value);
  14983. }
  14984. // mark the key as handler for props normalization check
  14985. ret.props.forEach(p => (p.key.isHandlerKey = true));
  14986. return ret;
  14987. };
  14988. // v-bind without arg is handled directly in ./transformElements.ts due to it affecting
  14989. // codegen for the entire props object. This transform here is only for v-bind
  14990. // *with* args.
  14991. const transformBind = (dir, _node, context) => {
  14992. const { exp, modifiers, loc } = dir;
  14993. const arg = dir.arg;
  14994. if (arg.type !== 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
  14995. arg.children.unshift(`(`);
  14996. arg.children.push(`) || ""`);
  14997. }
  14998. else if (!arg.isStatic) {
  14999. arg.content = `${arg.content} || ""`;
  15000. }
  15001. // .sync is replaced by v-model:arg
  15002. if (modifiers.includes('camel')) {
  15003. if (arg.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
  15004. if (arg.isStatic) {
  15005. arg.content = camelize(arg.content);
  15006. }
  15007. else {
  15008. arg.content = `${context.helperString(CAMELIZE)}(${arg.content})`;
  15009. }
  15010. }
  15011. else {
  15012. arg.children.unshift(`${context.helperString(CAMELIZE)}(`);
  15013. arg.children.push(`)`);
  15014. }
  15015. }
  15016. if (!context.inSSR) {
  15017. if (modifiers.includes('prop')) {
  15018. injectPrefix(arg, '.');
  15019. }
  15020. if (modifiers.includes('attr')) {
  15021. injectPrefix(arg, '^');
  15022. }
  15023. }
  15024. if (!exp ||
  15025. (exp.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ && !exp.content.trim())) {
  15026. context.onError(createCompilerError(34 /* ErrorCodes.X_V_BIND_NO_EXPRESSION */, loc));
  15027. return {
  15028. props: [createObjectProperty(arg, createSimpleExpression('', true, loc))]
  15029. };
  15030. }
  15031. return {
  15032. props: [createObjectProperty(arg, exp)]
  15033. };
  15034. };
  15035. const injectPrefix = (arg, prefix) => {
  15036. if (arg.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
  15037. if (arg.isStatic) {
  15038. arg.content = prefix + arg.content;
  15039. }
  15040. else {
  15041. arg.content = `\`${prefix}\${${arg.content}}\``;
  15042. }
  15043. }
  15044. else {
  15045. arg.children.unshift(`'${prefix}' + (`);
  15046. arg.children.push(`)`);
  15047. }
  15048. };
  15049. // Merge adjacent text nodes and expressions into a single expression
  15050. // e.g. <div>abc {{ d }} {{ e }}</div> should have a single expression node as child.
  15051. const transformText = (node, context) => {
  15052. if (node.type === 0 /* NodeTypes.ROOT */ ||
  15053. node.type === 1 /* NodeTypes.ELEMENT */ ||
  15054. node.type === 11 /* NodeTypes.FOR */ ||
  15055. node.type === 10 /* NodeTypes.IF_BRANCH */) {
  15056. // perform the transform on node exit so that all expressions have already
  15057. // been processed.
  15058. return () => {
  15059. const children = node.children;
  15060. let currentContainer = undefined;
  15061. let hasText = false;
  15062. for (let i = 0; i < children.length; i++) {
  15063. const child = children[i];
  15064. if (isText(child)) {
  15065. hasText = true;
  15066. for (let j = i + 1; j < children.length; j++) {
  15067. const next = children[j];
  15068. if (isText(next)) {
  15069. if (!currentContainer) {
  15070. currentContainer = children[i] = createCompoundExpression([child], child.loc);
  15071. }
  15072. // merge adjacent text node into current
  15073. currentContainer.children.push(` + `, next);
  15074. children.splice(j, 1);
  15075. j--;
  15076. }
  15077. else {
  15078. currentContainer = undefined;
  15079. break;
  15080. }
  15081. }
  15082. }
  15083. }
  15084. if (!hasText ||
  15085. // if this is a plain element with a single text child, leave it
  15086. // as-is since the runtime has dedicated fast path for this by directly
  15087. // setting textContent of the element.
  15088. // for component root it's always normalized anyway.
  15089. (children.length === 1 &&
  15090. (node.type === 0 /* NodeTypes.ROOT */ ||
  15091. (node.type === 1 /* NodeTypes.ELEMENT */ &&
  15092. node.tagType === 0 /* ElementTypes.ELEMENT */ &&
  15093. // #3756
  15094. // custom directives can potentially add DOM elements arbitrarily,
  15095. // we need to avoid setting textContent of the element at runtime
  15096. // to avoid accidentally overwriting the DOM elements added
  15097. // by the user through custom directives.
  15098. !node.props.find(p => p.type === 7 /* NodeTypes.DIRECTIVE */ &&
  15099. !context.directiveTransforms[p.name]) &&
  15100. // in compat mode, <template> tags with no special directives
  15101. // will be rendered as a fragment so its children must be
  15102. // converted into vnodes.
  15103. !(false ))))) {
  15104. return;
  15105. }
  15106. // pre-convert text nodes into createTextVNode(text) calls to avoid
  15107. // runtime normalization.
  15108. for (let i = 0; i < children.length; i++) {
  15109. const child = children[i];
  15110. if (isText(child) || child.type === 8 /* NodeTypes.COMPOUND_EXPRESSION */) {
  15111. const callArgs = [];
  15112. // createTextVNode defaults to single whitespace, so if it is a
  15113. // single space the code could be an empty call to save bytes.
  15114. if (child.type !== 2 /* NodeTypes.TEXT */ || child.content !== ' ') {
  15115. callArgs.push(child);
  15116. }
  15117. // mark dynamic text with flag so it gets patched inside a block
  15118. if (!context.ssr &&
  15119. getConstantType(child, context) === 0 /* ConstantTypes.NOT_CONSTANT */) {
  15120. callArgs.push(1 /* PatchFlags.TEXT */ +
  15121. (` /* ${PatchFlagNames[1 /* PatchFlags.TEXT */]} */` ));
  15122. }
  15123. children[i] = {
  15124. type: 12 /* NodeTypes.TEXT_CALL */,
  15125. content: child,
  15126. loc: child.loc,
  15127. codegenNode: createCallExpression(context.helper(CREATE_TEXT), callArgs)
  15128. };
  15129. }
  15130. }
  15131. };
  15132. }
  15133. };
  15134. const seen = new WeakSet();
  15135. const transformOnce = (node, context) => {
  15136. if (node.type === 1 /* NodeTypes.ELEMENT */ && findDir(node, 'once', true)) {
  15137. if (seen.has(node) || context.inVOnce) {
  15138. return;
  15139. }
  15140. seen.add(node);
  15141. context.inVOnce = true;
  15142. context.helper(SET_BLOCK_TRACKING);
  15143. return () => {
  15144. context.inVOnce = false;
  15145. const cur = context.currentNode;
  15146. if (cur.codegenNode) {
  15147. cur.codegenNode = context.cache(cur.codegenNode, true /* isVNode */);
  15148. }
  15149. };
  15150. }
  15151. };
  15152. const transformModel = (dir, node, context) => {
  15153. const { exp, arg } = dir;
  15154. if (!exp) {
  15155. context.onError(createCompilerError(41 /* ErrorCodes.X_V_MODEL_NO_EXPRESSION */, dir.loc));
  15156. return createTransformProps();
  15157. }
  15158. const rawExp = exp.loc.source;
  15159. const expString = exp.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ ? exp.content : rawExp;
  15160. // im SFC <script setup> inline mode, the exp may have been transformed into
  15161. // _unref(exp)
  15162. const bindingType = context.bindingMetadata[rawExp];
  15163. // check props
  15164. if (bindingType === "props" /* BindingTypes.PROPS */ ||
  15165. bindingType === "props-aliased" /* BindingTypes.PROPS_ALIASED */) {
  15166. context.onError(createCompilerError(44 /* ErrorCodes.X_V_MODEL_ON_PROPS */, exp.loc));
  15167. return createTransformProps();
  15168. }
  15169. const maybeRef = !true ;
  15170. if (!expString.trim() ||
  15171. (!isMemberExpression(expString) && !maybeRef)) {
  15172. context.onError(createCompilerError(42 /* ErrorCodes.X_V_MODEL_MALFORMED_EXPRESSION */, exp.loc));
  15173. return createTransformProps();
  15174. }
  15175. const propName = arg ? arg : createSimpleExpression('modelValue', true);
  15176. const eventName = arg
  15177. ? isStaticExp(arg)
  15178. ? `onUpdate:${arg.content}`
  15179. : createCompoundExpression(['"onUpdate:" + ', arg])
  15180. : `onUpdate:modelValue`;
  15181. let assignmentExp;
  15182. const eventArg = context.isTS ? `($event: any)` : `$event`;
  15183. {
  15184. assignmentExp = createCompoundExpression([
  15185. `${eventArg} => ((`,
  15186. exp,
  15187. `) = $event)`
  15188. ]);
  15189. }
  15190. const props = [
  15191. // modelValue: foo
  15192. createObjectProperty(propName, dir.exp),
  15193. // "onUpdate:modelValue": $event => (foo = $event)
  15194. createObjectProperty(eventName, assignmentExp)
  15195. ];
  15196. // modelModifiers: { foo: true, "bar-baz": true }
  15197. if (dir.modifiers.length && node.tagType === 1 /* ElementTypes.COMPONENT */) {
  15198. const modifiers = dir.modifiers
  15199. .map(m => (isSimpleIdentifier(m) ? m : JSON.stringify(m)) + `: true`)
  15200. .join(`, `);
  15201. const modifiersKey = arg
  15202. ? isStaticExp(arg)
  15203. ? `${arg.content}Modifiers`
  15204. : createCompoundExpression([arg, ' + "Modifiers"'])
  15205. : `modelModifiers`;
  15206. props.push(createObjectProperty(modifiersKey, createSimpleExpression(`{ ${modifiers} }`, false, dir.loc, 2 /* ConstantTypes.CAN_HOIST */)));
  15207. }
  15208. return createTransformProps(props);
  15209. };
  15210. function createTransformProps(props = []) {
  15211. return { props };
  15212. }
  15213. const seen$1 = new WeakSet();
  15214. const transformMemo = (node, context) => {
  15215. if (node.type === 1 /* NodeTypes.ELEMENT */) {
  15216. const dir = findDir(node, 'memo');
  15217. if (!dir || seen$1.has(node)) {
  15218. return;
  15219. }
  15220. seen$1.add(node);
  15221. return () => {
  15222. const codegenNode = node.codegenNode ||
  15223. context.currentNode.codegenNode;
  15224. if (codegenNode && codegenNode.type === 13 /* NodeTypes.VNODE_CALL */) {
  15225. // non-component sub tree should be turned into a block
  15226. if (node.tagType !== 1 /* ElementTypes.COMPONENT */) {
  15227. makeBlock(codegenNode, context);
  15228. }
  15229. node.codegenNode = createCallExpression(context.helper(WITH_MEMO), [
  15230. dir.exp,
  15231. createFunctionExpression(undefined, codegenNode),
  15232. `_cache`,
  15233. String(context.cached++)
  15234. ]);
  15235. }
  15236. };
  15237. }
  15238. };
  15239. function getBaseTransformPreset(prefixIdentifiers) {
  15240. return [
  15241. [
  15242. transformOnce,
  15243. transformIf,
  15244. transformMemo,
  15245. transformFor,
  15246. ...([]),
  15247. ...([transformExpression]
  15248. ),
  15249. transformSlotOutlet,
  15250. transformElement,
  15251. trackSlotScopes,
  15252. transformText
  15253. ],
  15254. {
  15255. on: transformOn,
  15256. bind: transformBind,
  15257. model: transformModel
  15258. }
  15259. ];
  15260. }
  15261. // we name it `baseCompile` so that higher order compilers like
  15262. // @vue/compiler-dom can export `compile` while re-exporting everything else.
  15263. function baseCompile(template, options = {}) {
  15264. const onError = options.onError || defaultOnError;
  15265. const isModuleMode = options.mode === 'module';
  15266. /* istanbul ignore if */
  15267. {
  15268. if (options.prefixIdentifiers === true) {
  15269. onError(createCompilerError(47 /* ErrorCodes.X_PREFIX_ID_NOT_SUPPORTED */));
  15270. }
  15271. else if (isModuleMode) {
  15272. onError(createCompilerError(48 /* ErrorCodes.X_MODULE_MODE_NOT_SUPPORTED */));
  15273. }
  15274. }
  15275. const prefixIdentifiers = !true ;
  15276. if (options.cacheHandlers) {
  15277. onError(createCompilerError(49 /* ErrorCodes.X_CACHE_HANDLER_NOT_SUPPORTED */));
  15278. }
  15279. if (options.scopeId && !isModuleMode) {
  15280. onError(createCompilerError(50 /* ErrorCodes.X_SCOPE_ID_NOT_SUPPORTED */));
  15281. }
  15282. const ast = isString(template) ? baseParse(template, options) : template;
  15283. const [nodeTransforms, directiveTransforms] = getBaseTransformPreset();
  15284. transform(ast, extend({}, options, {
  15285. prefixIdentifiers,
  15286. nodeTransforms: [
  15287. ...nodeTransforms,
  15288. ...(options.nodeTransforms || []) // user transforms
  15289. ],
  15290. directiveTransforms: extend({}, directiveTransforms, options.directiveTransforms || {} // user transforms
  15291. )
  15292. }));
  15293. return generate(ast, extend({}, options, {
  15294. prefixIdentifiers
  15295. }));
  15296. }
  15297. const noopDirectiveTransform = () => ({ props: [] });
  15298. const V_MODEL_RADIO = Symbol(`vModelRadio` );
  15299. const V_MODEL_CHECKBOX = Symbol(`vModelCheckbox` );
  15300. const V_MODEL_TEXT = Symbol(`vModelText` );
  15301. const V_MODEL_SELECT = Symbol(`vModelSelect` );
  15302. const V_MODEL_DYNAMIC = Symbol(`vModelDynamic` );
  15303. const V_ON_WITH_MODIFIERS = Symbol(`vOnModifiersGuard` );
  15304. const V_ON_WITH_KEYS = Symbol(`vOnKeysGuard` );
  15305. const V_SHOW = Symbol(`vShow` );
  15306. const TRANSITION$1 = Symbol(`Transition` );
  15307. const TRANSITION_GROUP = Symbol(`TransitionGroup` );
  15308. registerRuntimeHelpers({
  15309. [V_MODEL_RADIO]: `vModelRadio`,
  15310. [V_MODEL_CHECKBOX]: `vModelCheckbox`,
  15311. [V_MODEL_TEXT]: `vModelText`,
  15312. [V_MODEL_SELECT]: `vModelSelect`,
  15313. [V_MODEL_DYNAMIC]: `vModelDynamic`,
  15314. [V_ON_WITH_MODIFIERS]: `withModifiers`,
  15315. [V_ON_WITH_KEYS]: `withKeys`,
  15316. [V_SHOW]: `vShow`,
  15317. [TRANSITION$1]: `Transition`,
  15318. [TRANSITION_GROUP]: `TransitionGroup`
  15319. });
  15320. /* eslint-disable no-restricted-globals */
  15321. let decoder;
  15322. function decodeHtmlBrowser(raw, asAttr = false) {
  15323. if (!decoder) {
  15324. decoder = document.createElement('div');
  15325. }
  15326. if (asAttr) {
  15327. decoder.innerHTML = `<div foo="${raw.replace(/"/g, '&quot;')}">`;
  15328. return decoder.children[0].getAttribute('foo');
  15329. }
  15330. else {
  15331. decoder.innerHTML = raw;
  15332. return decoder.textContent;
  15333. }
  15334. }
  15335. const isRawTextContainer = /*#__PURE__*/ makeMap('style,iframe,script,noscript', true);
  15336. const parserOptions = {
  15337. isVoidTag,
  15338. isNativeTag: tag => isHTMLTag(tag) || isSVGTag(tag),
  15339. isPreTag: tag => tag === 'pre',
  15340. decodeEntities: decodeHtmlBrowser ,
  15341. isBuiltInComponent: (tag) => {
  15342. if (isBuiltInType(tag, `Transition`)) {
  15343. return TRANSITION$1;
  15344. }
  15345. else if (isBuiltInType(tag, `TransitionGroup`)) {
  15346. return TRANSITION_GROUP;
  15347. }
  15348. },
  15349. // https://html.spec.whatwg.org/multipage/parsing.html#tree-construction-dispatcher
  15350. getNamespace(tag, parent) {
  15351. let ns = parent ? parent.ns : 0 /* DOMNamespaces.HTML */;
  15352. if (parent && ns === 2 /* DOMNamespaces.MATH_ML */) {
  15353. if (parent.tag === 'annotation-xml') {
  15354. if (tag === 'svg') {
  15355. return 1 /* DOMNamespaces.SVG */;
  15356. }
  15357. if (parent.props.some(a => a.type === 6 /* NodeTypes.ATTRIBUTE */ &&
  15358. a.name === 'encoding' &&
  15359. a.value != null &&
  15360. (a.value.content === 'text/html' ||
  15361. a.value.content === 'application/xhtml+xml'))) {
  15362. ns = 0 /* DOMNamespaces.HTML */;
  15363. }
  15364. }
  15365. else if (/^m(?:[ions]|text)$/.test(parent.tag) &&
  15366. tag !== 'mglyph' &&
  15367. tag !== 'malignmark') {
  15368. ns = 0 /* DOMNamespaces.HTML */;
  15369. }
  15370. }
  15371. else if (parent && ns === 1 /* DOMNamespaces.SVG */) {
  15372. if (parent.tag === 'foreignObject' ||
  15373. parent.tag === 'desc' ||
  15374. parent.tag === 'title') {
  15375. ns = 0 /* DOMNamespaces.HTML */;
  15376. }
  15377. }
  15378. if (ns === 0 /* DOMNamespaces.HTML */) {
  15379. if (tag === 'svg') {
  15380. return 1 /* DOMNamespaces.SVG */;
  15381. }
  15382. if (tag === 'math') {
  15383. return 2 /* DOMNamespaces.MATH_ML */;
  15384. }
  15385. }
  15386. return ns;
  15387. },
  15388. // https://html.spec.whatwg.org/multipage/parsing.html#parsing-html-fragments
  15389. getTextMode({ tag, ns }) {
  15390. if (ns === 0 /* DOMNamespaces.HTML */) {
  15391. if (tag === 'textarea' || tag === 'title') {
  15392. return 1 /* TextModes.RCDATA */;
  15393. }
  15394. if (isRawTextContainer(tag)) {
  15395. return 2 /* TextModes.RAWTEXT */;
  15396. }
  15397. }
  15398. return 0 /* TextModes.DATA */;
  15399. }
  15400. };
  15401. // Parse inline CSS strings for static style attributes into an object.
  15402. // This is a NodeTransform since it works on the static `style` attribute and
  15403. // converts it into a dynamic equivalent:
  15404. // style="color: red" -> :style='{ "color": "red" }'
  15405. // It is then processed by `transformElement` and included in the generated
  15406. // props.
  15407. const transformStyle = node => {
  15408. if (node.type === 1 /* NodeTypes.ELEMENT */) {
  15409. node.props.forEach((p, i) => {
  15410. if (p.type === 6 /* NodeTypes.ATTRIBUTE */ && p.name === 'style' && p.value) {
  15411. // replace p with an expression node
  15412. node.props[i] = {
  15413. type: 7 /* NodeTypes.DIRECTIVE */,
  15414. name: `bind`,
  15415. arg: createSimpleExpression(`style`, true, p.loc),
  15416. exp: parseInlineCSS(p.value.content, p.loc),
  15417. modifiers: [],
  15418. loc: p.loc
  15419. };
  15420. }
  15421. });
  15422. }
  15423. };
  15424. const parseInlineCSS = (cssText, loc) => {
  15425. const normalized = parseStringStyle(cssText);
  15426. return createSimpleExpression(JSON.stringify(normalized), false, loc, 3 /* ConstantTypes.CAN_STRINGIFY */);
  15427. };
  15428. function createDOMCompilerError(code, loc) {
  15429. return createCompilerError(code, loc, DOMErrorMessages );
  15430. }
  15431. const DOMErrorMessages = {
  15432. [51 /* DOMErrorCodes.X_V_HTML_NO_EXPRESSION */]: `v-html is missing expression.`,
  15433. [52 /* DOMErrorCodes.X_V_HTML_WITH_CHILDREN */]: `v-html will override element children.`,
  15434. [53 /* DOMErrorCodes.X_V_TEXT_NO_EXPRESSION */]: `v-text is missing expression.`,
  15435. [54 /* DOMErrorCodes.X_V_TEXT_WITH_CHILDREN */]: `v-text will override element children.`,
  15436. [55 /* DOMErrorCodes.X_V_MODEL_ON_INVALID_ELEMENT */]: `v-model can only be used on <input>, <textarea> and <select> elements.`,
  15437. [56 /* DOMErrorCodes.X_V_MODEL_ARG_ON_ELEMENT */]: `v-model argument is not supported on plain elements.`,
  15438. [57 /* DOMErrorCodes.X_V_MODEL_ON_FILE_INPUT_ELEMENT */]: `v-model cannot be used on file inputs since they are read-only. Use a v-on:change listener instead.`,
  15439. [58 /* DOMErrorCodes.X_V_MODEL_UNNECESSARY_VALUE */]: `Unnecessary value binding used alongside v-model. It will interfere with v-model's behavior.`,
  15440. [59 /* DOMErrorCodes.X_V_SHOW_NO_EXPRESSION */]: `v-show is missing expression.`,
  15441. [60 /* DOMErrorCodes.X_TRANSITION_INVALID_CHILDREN */]: `<Transition> expects exactly one child element or component.`,
  15442. [61 /* DOMErrorCodes.X_IGNORED_SIDE_EFFECT_TAG */]: `Tags with side effect (<script> and <style>) are ignored in client component templates.`
  15443. };
  15444. const transformVHtml = (dir, node, context) => {
  15445. const { exp, loc } = dir;
  15446. if (!exp) {
  15447. context.onError(createDOMCompilerError(51 /* DOMErrorCodes.X_V_HTML_NO_EXPRESSION */, loc));
  15448. }
  15449. if (node.children.length) {
  15450. context.onError(createDOMCompilerError(52 /* DOMErrorCodes.X_V_HTML_WITH_CHILDREN */, loc));
  15451. node.children.length = 0;
  15452. }
  15453. return {
  15454. props: [
  15455. createObjectProperty(createSimpleExpression(`innerHTML`, true, loc), exp || createSimpleExpression('', true))
  15456. ]
  15457. };
  15458. };
  15459. const transformVText = (dir, node, context) => {
  15460. const { exp, loc } = dir;
  15461. if (!exp) {
  15462. context.onError(createDOMCompilerError(53 /* DOMErrorCodes.X_V_TEXT_NO_EXPRESSION */, loc));
  15463. }
  15464. if (node.children.length) {
  15465. context.onError(createDOMCompilerError(54 /* DOMErrorCodes.X_V_TEXT_WITH_CHILDREN */, loc));
  15466. node.children.length = 0;
  15467. }
  15468. return {
  15469. props: [
  15470. createObjectProperty(createSimpleExpression(`textContent`, true), exp
  15471. ? getConstantType(exp, context) > 0
  15472. ? exp
  15473. : createCallExpression(context.helperString(TO_DISPLAY_STRING), [exp], loc)
  15474. : createSimpleExpression('', true))
  15475. ]
  15476. };
  15477. };
  15478. const transformModel$1 = (dir, node, context) => {
  15479. const baseResult = transformModel(dir, node, context);
  15480. // base transform has errors OR component v-model (only need props)
  15481. if (!baseResult.props.length || node.tagType === 1 /* ElementTypes.COMPONENT */) {
  15482. return baseResult;
  15483. }
  15484. if (dir.arg) {
  15485. context.onError(createDOMCompilerError(56 /* DOMErrorCodes.X_V_MODEL_ARG_ON_ELEMENT */, dir.arg.loc));
  15486. }
  15487. function checkDuplicatedValue() {
  15488. const value = findProp(node, 'value');
  15489. if (value) {
  15490. context.onError(createDOMCompilerError(58 /* DOMErrorCodes.X_V_MODEL_UNNECESSARY_VALUE */, value.loc));
  15491. }
  15492. }
  15493. const { tag } = node;
  15494. const isCustomElement = context.isCustomElement(tag);
  15495. if (tag === 'input' ||
  15496. tag === 'textarea' ||
  15497. tag === 'select' ||
  15498. isCustomElement) {
  15499. let directiveToUse = V_MODEL_TEXT;
  15500. let isInvalidType = false;
  15501. if (tag === 'input' || isCustomElement) {
  15502. const type = findProp(node, `type`);
  15503. if (type) {
  15504. if (type.type === 7 /* NodeTypes.DIRECTIVE */) {
  15505. // :type="foo"
  15506. directiveToUse = V_MODEL_DYNAMIC;
  15507. }
  15508. else if (type.value) {
  15509. switch (type.value.content) {
  15510. case 'radio':
  15511. directiveToUse = V_MODEL_RADIO;
  15512. break;
  15513. case 'checkbox':
  15514. directiveToUse = V_MODEL_CHECKBOX;
  15515. break;
  15516. case 'file':
  15517. isInvalidType = true;
  15518. context.onError(createDOMCompilerError(57 /* DOMErrorCodes.X_V_MODEL_ON_FILE_INPUT_ELEMENT */, dir.loc));
  15519. break;
  15520. default:
  15521. // text type
  15522. checkDuplicatedValue();
  15523. break;
  15524. }
  15525. }
  15526. }
  15527. else if (hasDynamicKeyVBind(node)) {
  15528. // element has bindings with dynamic keys, which can possibly contain
  15529. // "type".
  15530. directiveToUse = V_MODEL_DYNAMIC;
  15531. }
  15532. else {
  15533. // text type
  15534. checkDuplicatedValue();
  15535. }
  15536. }
  15537. else if (tag === 'select') {
  15538. directiveToUse = V_MODEL_SELECT;
  15539. }
  15540. else {
  15541. // textarea
  15542. checkDuplicatedValue();
  15543. }
  15544. // inject runtime directive
  15545. // by returning the helper symbol via needRuntime
  15546. // the import will replaced a resolveDirective call.
  15547. if (!isInvalidType) {
  15548. baseResult.needRuntime = context.helper(directiveToUse);
  15549. }
  15550. }
  15551. else {
  15552. context.onError(createDOMCompilerError(55 /* DOMErrorCodes.X_V_MODEL_ON_INVALID_ELEMENT */, dir.loc));
  15553. }
  15554. // native vmodel doesn't need the `modelValue` props since they are also
  15555. // passed to the runtime as `binding.value`. removing it reduces code size.
  15556. baseResult.props = baseResult.props.filter(p => !(p.key.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ &&
  15557. p.key.content === 'modelValue'));
  15558. return baseResult;
  15559. };
  15560. const isEventOptionModifier = /*#__PURE__*/ makeMap(`passive,once,capture`);
  15561. const isNonKeyModifier = /*#__PURE__*/ makeMap(
  15562. // event propagation management
  15563. `stop,prevent,self,` +
  15564. // system modifiers + exact
  15565. `ctrl,shift,alt,meta,exact,` +
  15566. // mouse
  15567. `middle`);
  15568. // left & right could be mouse or key modifiers based on event type
  15569. const maybeKeyModifier = /*#__PURE__*/ makeMap('left,right');
  15570. const isKeyboardEvent = /*#__PURE__*/ makeMap(`onkeyup,onkeydown,onkeypress`, true);
  15571. const resolveModifiers = (key, modifiers, context, loc) => {
  15572. const keyModifiers = [];
  15573. const nonKeyModifiers = [];
  15574. const eventOptionModifiers = [];
  15575. for (let i = 0; i < modifiers.length; i++) {
  15576. const modifier = modifiers[i];
  15577. if (isEventOptionModifier(modifier)) {
  15578. // eventOptionModifiers: modifiers for addEventListener() options,
  15579. // e.g. .passive & .capture
  15580. eventOptionModifiers.push(modifier);
  15581. }
  15582. else {
  15583. // runtimeModifiers: modifiers that needs runtime guards
  15584. if (maybeKeyModifier(modifier)) {
  15585. if (isStaticExp(key)) {
  15586. if (isKeyboardEvent(key.content)) {
  15587. keyModifiers.push(modifier);
  15588. }
  15589. else {
  15590. nonKeyModifiers.push(modifier);
  15591. }
  15592. }
  15593. else {
  15594. keyModifiers.push(modifier);
  15595. nonKeyModifiers.push(modifier);
  15596. }
  15597. }
  15598. else {
  15599. if (isNonKeyModifier(modifier)) {
  15600. nonKeyModifiers.push(modifier);
  15601. }
  15602. else {
  15603. keyModifiers.push(modifier);
  15604. }
  15605. }
  15606. }
  15607. }
  15608. return {
  15609. keyModifiers,
  15610. nonKeyModifiers,
  15611. eventOptionModifiers
  15612. };
  15613. };
  15614. const transformClick = (key, event) => {
  15615. const isStaticClick = isStaticExp(key) && key.content.toLowerCase() === 'onclick';
  15616. return isStaticClick
  15617. ? createSimpleExpression(event, true)
  15618. : key.type !== 4 /* NodeTypes.SIMPLE_EXPRESSION */
  15619. ? createCompoundExpression([
  15620. `(`,
  15621. key,
  15622. `) === "onClick" ? "${event}" : (`,
  15623. key,
  15624. `)`
  15625. ])
  15626. : key;
  15627. };
  15628. const transformOn$1 = (dir, node, context) => {
  15629. return transformOn(dir, node, context, baseResult => {
  15630. const { modifiers } = dir;
  15631. if (!modifiers.length)
  15632. return baseResult;
  15633. let { key, value: handlerExp } = baseResult.props[0];
  15634. const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = resolveModifiers(key, modifiers, context, dir.loc);
  15635. // normalize click.right and click.middle since they don't actually fire
  15636. if (nonKeyModifiers.includes('right')) {
  15637. key = transformClick(key, `onContextmenu`);
  15638. }
  15639. if (nonKeyModifiers.includes('middle')) {
  15640. key = transformClick(key, `onMouseup`);
  15641. }
  15642. if (nonKeyModifiers.length) {
  15643. handlerExp = createCallExpression(context.helper(V_ON_WITH_MODIFIERS), [
  15644. handlerExp,
  15645. JSON.stringify(nonKeyModifiers)
  15646. ]);
  15647. }
  15648. if (keyModifiers.length &&
  15649. // if event name is dynamic, always wrap with keys guard
  15650. (!isStaticExp(key) || isKeyboardEvent(key.content))) {
  15651. handlerExp = createCallExpression(context.helper(V_ON_WITH_KEYS), [
  15652. handlerExp,
  15653. JSON.stringify(keyModifiers)
  15654. ]);
  15655. }
  15656. if (eventOptionModifiers.length) {
  15657. const modifierPostfix = eventOptionModifiers.map(capitalize).join('');
  15658. key = isStaticExp(key)
  15659. ? createSimpleExpression(`${key.content}${modifierPostfix}`, true)
  15660. : createCompoundExpression([`(`, key, `) + "${modifierPostfix}"`]);
  15661. }
  15662. return {
  15663. props: [createObjectProperty(key, handlerExp)]
  15664. };
  15665. });
  15666. };
  15667. const transformShow = (dir, node, context) => {
  15668. const { exp, loc } = dir;
  15669. if (!exp) {
  15670. context.onError(createDOMCompilerError(59 /* DOMErrorCodes.X_V_SHOW_NO_EXPRESSION */, loc));
  15671. }
  15672. return {
  15673. props: [],
  15674. needRuntime: context.helper(V_SHOW)
  15675. };
  15676. };
  15677. const transformTransition = (node, context) => {
  15678. if (node.type === 1 /* NodeTypes.ELEMENT */ &&
  15679. node.tagType === 1 /* ElementTypes.COMPONENT */) {
  15680. const component = context.isBuiltInComponent(node.tag);
  15681. if (component === TRANSITION$1) {
  15682. return () => {
  15683. if (!node.children.length) {
  15684. return;
  15685. }
  15686. // warn multiple transition children
  15687. if (hasMultipleChildren(node)) {
  15688. context.onError(createDOMCompilerError(60 /* DOMErrorCodes.X_TRANSITION_INVALID_CHILDREN */, {
  15689. start: node.children[0].loc.start,
  15690. end: node.children[node.children.length - 1].loc.end,
  15691. source: ''
  15692. }));
  15693. }
  15694. // check if it's s single child w/ v-show
  15695. // if yes, inject "persisted: true" to the transition props
  15696. const child = node.children[0];
  15697. if (child.type === 1 /* NodeTypes.ELEMENT */) {
  15698. for (const p of child.props) {
  15699. if (p.type === 7 /* NodeTypes.DIRECTIVE */ && p.name === 'show') {
  15700. node.props.push({
  15701. type: 6 /* NodeTypes.ATTRIBUTE */,
  15702. name: 'persisted',
  15703. value: undefined,
  15704. loc: node.loc
  15705. });
  15706. }
  15707. }
  15708. }
  15709. };
  15710. }
  15711. }
  15712. };
  15713. function hasMultipleChildren(node) {
  15714. // #1352 filter out potential comment nodes.
  15715. const children = (node.children = node.children.filter(c => c.type !== 3 /* NodeTypes.COMMENT */ &&
  15716. !(c.type === 2 /* NodeTypes.TEXT */ && !c.content.trim())));
  15717. const child = children[0];
  15718. return (children.length !== 1 ||
  15719. child.type === 11 /* NodeTypes.FOR */ ||
  15720. (child.type === 9 /* NodeTypes.IF */ && child.branches.some(hasMultipleChildren)));
  15721. }
  15722. const ignoreSideEffectTags = (node, context) => {
  15723. if (node.type === 1 /* NodeTypes.ELEMENT */ &&
  15724. node.tagType === 0 /* ElementTypes.ELEMENT */ &&
  15725. (node.tag === 'script' || node.tag === 'style')) {
  15726. context.onError(createDOMCompilerError(61 /* DOMErrorCodes.X_IGNORED_SIDE_EFFECT_TAG */, node.loc));
  15727. context.removeNode();
  15728. }
  15729. };
  15730. const DOMNodeTransforms = [
  15731. transformStyle,
  15732. ...([transformTransition] )
  15733. ];
  15734. const DOMDirectiveTransforms = {
  15735. cloak: noopDirectiveTransform,
  15736. html: transformVHtml,
  15737. text: transformVText,
  15738. model: transformModel$1,
  15739. on: transformOn$1,
  15740. show: transformShow
  15741. };
  15742. function compile$1(template, options = {}) {
  15743. return baseCompile(template, extend({}, parserOptions, options, {
  15744. nodeTransforms: [
  15745. // ignore <script> and <tag>
  15746. // this is not put inside DOMNodeTransforms because that list is used
  15747. // by compiler-ssr to generate vnode fallback branches
  15748. ignoreSideEffectTags,
  15749. ...DOMNodeTransforms,
  15750. ...(options.nodeTransforms || [])
  15751. ],
  15752. directiveTransforms: extend({}, DOMDirectiveTransforms, options.directiveTransforms || {}),
  15753. transformHoist: null
  15754. }));
  15755. }
  15756. // This entry is the "full-build" that includes both the runtime
  15757. {
  15758. initDev();
  15759. }
  15760. const compileCache = Object.create(null);
  15761. function compileToFunction(template, options) {
  15762. if (!isString(template)) {
  15763. if (template.nodeType) {
  15764. template = template.innerHTML;
  15765. }
  15766. else {
  15767. warn$1(`invalid template option: `, template);
  15768. return NOOP;
  15769. }
  15770. }
  15771. const key = template;
  15772. const cached = compileCache[key];
  15773. if (cached) {
  15774. return cached;
  15775. }
  15776. if (template[0] === '#') {
  15777. const el = document.querySelector(template);
  15778. if (!el) {
  15779. warn$1(`Template element not found or is empty: ${template}`);
  15780. }
  15781. // __UNSAFE__
  15782. // Reason: potential execution of JS expressions in in-DOM template.
  15783. // The user must make sure the in-DOM template is trusted. If it's rendered
  15784. // by the server, the template should not contain any user data.
  15785. template = el ? el.innerHTML : ``;
  15786. }
  15787. const opts = extend({
  15788. hoistStatic: true,
  15789. onError: onError ,
  15790. onWarn: e => onError(e, true)
  15791. }, options);
  15792. if (!opts.isCustomElement && typeof customElements !== 'undefined') {
  15793. opts.isCustomElement = tag => !!customElements.get(tag);
  15794. }
  15795. const { code } = compile$1(template, opts);
  15796. function onError(err, asWarning = false) {
  15797. const message = asWarning
  15798. ? err.message
  15799. : `Template compilation error: ${err.message}`;
  15800. const codeFrame = err.loc &&
  15801. generateCodeFrame(template, err.loc.start.offset, err.loc.end.offset);
  15802. warn$1(codeFrame ? `${message}\n${codeFrame}` : message);
  15803. }
  15804. // The wildcard import results in a huge object with every export
  15805. // with keys that cannot be mangled, and can be quite heavy size-wise.
  15806. // In the global build we know `Vue` is available globally so we can avoid
  15807. // the wildcard object.
  15808. const render = (new Function(code)() );
  15809. render._rc = true;
  15810. return (compileCache[key] = render);
  15811. }
  15812. registerRuntimeCompiler(compileToFunction);
  15813. exports.BaseTransition = BaseTransition;
  15814. exports.Comment = Comment;
  15815. exports.EffectScope = EffectScope;
  15816. exports.Fragment = Fragment;
  15817. exports.KeepAlive = KeepAlive;
  15818. exports.ReactiveEffect = ReactiveEffect;
  15819. exports.Static = Static;
  15820. exports.Suspense = Suspense;
  15821. exports.Teleport = Teleport;
  15822. exports.Text = Text;
  15823. exports.Transition = Transition;
  15824. exports.TransitionGroup = TransitionGroup;
  15825. exports.VueElement = VueElement;
  15826. exports.callWithAsyncErrorHandling = callWithAsyncErrorHandling;
  15827. exports.callWithErrorHandling = callWithErrorHandling;
  15828. exports.camelize = camelize;
  15829. exports.capitalize = capitalize;
  15830. exports.cloneVNode = cloneVNode;
  15831. exports.compatUtils = compatUtils;
  15832. exports.compile = compileToFunction;
  15833. exports.computed = computed$1;
  15834. exports.createApp = createApp;
  15835. exports.createBlock = createBlock;
  15836. exports.createCommentVNode = createCommentVNode;
  15837. exports.createElementBlock = createElementBlock;
  15838. exports.createElementVNode = createBaseVNode;
  15839. exports.createHydrationRenderer = createHydrationRenderer;
  15840. exports.createPropsRestProxy = createPropsRestProxy;
  15841. exports.createRenderer = createRenderer;
  15842. exports.createSSRApp = createSSRApp;
  15843. exports.createSlots = createSlots;
  15844. exports.createStaticVNode = createStaticVNode;
  15845. exports.createTextVNode = createTextVNode;
  15846. exports.createVNode = createVNode;
  15847. exports.customRef = customRef;
  15848. exports.defineAsyncComponent = defineAsyncComponent;
  15849. exports.defineComponent = defineComponent;
  15850. exports.defineCustomElement = defineCustomElement;
  15851. exports.defineEmits = defineEmits;
  15852. exports.defineExpose = defineExpose;
  15853. exports.defineProps = defineProps;
  15854. exports.defineSSRCustomElement = defineSSRCustomElement;
  15855. exports.effect = effect;
  15856. exports.effectScope = effectScope;
  15857. exports.getCurrentInstance = getCurrentInstance;
  15858. exports.getCurrentScope = getCurrentScope;
  15859. exports.getTransitionRawChildren = getTransitionRawChildren;
  15860. exports.guardReactiveProps = guardReactiveProps;
  15861. exports.h = h;
  15862. exports.handleError = handleError;
  15863. exports.hydrate = hydrate;
  15864. exports.initCustomFormatter = initCustomFormatter;
  15865. exports.initDirectivesForSSR = initDirectivesForSSR;
  15866. exports.inject = inject;
  15867. exports.isMemoSame = isMemoSame;
  15868. exports.isProxy = isProxy;
  15869. exports.isReactive = isReactive;
  15870. exports.isReadonly = isReadonly;
  15871. exports.isRef = isRef;
  15872. exports.isRuntimeOnly = isRuntimeOnly;
  15873. exports.isShallow = isShallow;
  15874. exports.isVNode = isVNode;
  15875. exports.markRaw = markRaw;
  15876. exports.mergeDefaults = mergeDefaults;
  15877. exports.mergeProps = mergeProps;
  15878. exports.nextTick = nextTick;
  15879. exports.normalizeClass = normalizeClass;
  15880. exports.normalizeProps = normalizeProps;
  15881. exports.normalizeStyle = normalizeStyle;
  15882. exports.onActivated = onActivated;
  15883. exports.onBeforeMount = onBeforeMount;
  15884. exports.onBeforeUnmount = onBeforeUnmount;
  15885. exports.onBeforeUpdate = onBeforeUpdate;
  15886. exports.onDeactivated = onDeactivated;
  15887. exports.onErrorCaptured = onErrorCaptured;
  15888. exports.onMounted = onMounted;
  15889. exports.onRenderTracked = onRenderTracked;
  15890. exports.onRenderTriggered = onRenderTriggered;
  15891. exports.onScopeDispose = onScopeDispose;
  15892. exports.onServerPrefetch = onServerPrefetch;
  15893. exports.onUnmounted = onUnmounted;
  15894. exports.onUpdated = onUpdated;
  15895. exports.openBlock = openBlock;
  15896. exports.popScopeId = popScopeId;
  15897. exports.provide = provide;
  15898. exports.proxyRefs = proxyRefs;
  15899. exports.pushScopeId = pushScopeId;
  15900. exports.queuePostFlushCb = queuePostFlushCb;
  15901. exports.reactive = reactive;
  15902. exports.readonly = readonly;
  15903. exports.ref = ref;
  15904. exports.registerRuntimeCompiler = registerRuntimeCompiler;
  15905. exports.render = render;
  15906. exports.renderList = renderList;
  15907. exports.renderSlot = renderSlot;
  15908. exports.resolveComponent = resolveComponent;
  15909. exports.resolveDirective = resolveDirective;
  15910. exports.resolveDynamicComponent = resolveDynamicComponent;
  15911. exports.resolveFilter = resolveFilter;
  15912. exports.resolveTransitionHooks = resolveTransitionHooks;
  15913. exports.setBlockTracking = setBlockTracking;
  15914. exports.setDevtoolsHook = setDevtoolsHook;
  15915. exports.setTransitionHooks = setTransitionHooks;
  15916. exports.shallowReactive = shallowReactive;
  15917. exports.shallowReadonly = shallowReadonly;
  15918. exports.shallowRef = shallowRef;
  15919. exports.ssrContextKey = ssrContextKey;
  15920. exports.ssrUtils = ssrUtils;
  15921. exports.stop = stop;
  15922. exports.toDisplayString = toDisplayString;
  15923. exports.toHandlerKey = toHandlerKey;
  15924. exports.toHandlers = toHandlers;
  15925. exports.toRaw = toRaw;
  15926. exports.toRef = toRef;
  15927. exports.toRefs = toRefs;
  15928. exports.transformVNodeArgs = transformVNodeArgs;
  15929. exports.triggerRef = triggerRef;
  15930. exports.unref = unref;
  15931. exports.useAttrs = useAttrs;
  15932. exports.useCssModule = useCssModule;
  15933. exports.useCssVars = useCssVars;
  15934. exports.useSSRContext = useSSRContext;
  15935. exports.useSlots = useSlots;
  15936. exports.useTransitionState = useTransitionState;
  15937. exports.vModelCheckbox = vModelCheckbox;
  15938. exports.vModelDynamic = vModelDynamic;
  15939. exports.vModelRadio = vModelRadio;
  15940. exports.vModelSelect = vModelSelect;
  15941. exports.vModelText = vModelText;
  15942. exports.vShow = vShow;
  15943. exports.version = version;
  15944. exports.warn = warn$1;
  15945. exports.watch = watch;
  15946. exports.watchEffect = watchEffect;
  15947. exports.watchPostEffect = watchPostEffect;
  15948. exports.watchSyncEffect = watchSyncEffect;
  15949. exports.withAsyncContext = withAsyncContext;
  15950. exports.withCtx = withCtx;
  15951. exports.withDefaults = withDefaults;
  15952. exports.withDirectives = withDirectives;
  15953. exports.withKeys = withKeys;
  15954. exports.withMemo = withMemo;
  15955. exports.withModifiers = withModifiers;
  15956. exports.withScopeId = withScopeId;
  15957. Object.defineProperty(exports, '__esModule', { value: true });
  15958. return exports;
  15959. }({}));