vue.global.js 615 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704
  1. var Vue = (function (exports) {
  2. 'use strict';
  3. /**
  4. * Make a map and return a function for checking if a key
  5. * is in that map.
  6. * IMPORTANT: all calls of this function must be prefixed with
  7. * \/\*#\_\_PURE\_\_\*\/
  8. * So that rollup can tree-shake them if necessary.
  9. */
  10. function makeMap(str, expectsLowerCase) {
  11. const map = Object.create(null);
  12. const list = str.split(',');
  13. for (let i = 0; i < list.length; i++) {
  14. map[list[i]] = true;
  15. }
  16. return expectsLowerCase ? val => !!map[val.toLowerCase()] : val => !!map[val];
  17. }
  18. /**
  19. * dev only flag -> name mapping
  20. */
  21. const PatchFlagNames = {
  22. [1 /* TEXT */]: `TEXT`,
  23. [2 /* CLASS */]: `CLASS`,
  24. [4 /* STYLE */]: `STYLE`,
  25. [8 /* PROPS */]: `PROPS`,
  26. [16 /* FULL_PROPS */]: `FULL_PROPS`,
  27. [32 /* HYDRATE_EVENTS */]: `HYDRATE_EVENTS`,
  28. [64 /* STABLE_FRAGMENT */]: `STABLE_FRAGMENT`,
  29. [128 /* KEYED_FRAGMENT */]: `KEYED_FRAGMENT`,
  30. [256 /* UNKEYED_FRAGMENT */]: `UNKEYED_FRAGMENT`,
  31. [512 /* NEED_PATCH */]: `NEED_PATCH`,
  32. [1024 /* DYNAMIC_SLOTS */]: `DYNAMIC_SLOTS`,
  33. [2048 /* DEV_ROOT_FRAGMENT */]: `DEV_ROOT_FRAGMENT`,
  34. [-1 /* HOISTED */]: `HOISTED`,
  35. [-2 /* BAIL */]: `BAIL`
  36. };
  37. /**
  38. * Dev only
  39. */
  40. const slotFlagsText = {
  41. [1 /* STABLE */]: 'STABLE',
  42. [2 /* DYNAMIC */]: 'DYNAMIC',
  43. [3 /* FORWARDED */]: 'FORWARDED'
  44. };
  45. const GLOBALS_WHITE_LISTED = 'Infinity,undefined,NaN,isFinite,isNaN,parseFloat,parseInt,decodeURI,' +
  46. 'decodeURIComponent,encodeURI,encodeURIComponent,Math,Number,Date,Array,' +
  47. 'Object,Boolean,String,RegExp,Map,Set,JSON,Intl,BigInt';
  48. const isGloballyWhitelisted = /*#__PURE__*/ makeMap(GLOBALS_WHITE_LISTED);
  49. const range = 2;
  50. function generateCodeFrame(source, start = 0, end = source.length) {
  51. // Split the content into individual lines but capture the newline sequence
  52. // that separated each line. This is important because the actual sequence is
  53. // needed to properly take into account the full line length for offset
  54. // comparison
  55. let lines = source.split(/(\r?\n)/);
  56. // Separate the lines and newline sequences into separate arrays for easier referencing
  57. const newlineSequences = lines.filter((_, idx) => idx % 2 === 1);
  58. lines = lines.filter((_, idx) => idx % 2 === 0);
  59. let count = 0;
  60. const res = [];
  61. for (let i = 0; i < lines.length; i++) {
  62. count +=
  63. lines[i].length +
  64. ((newlineSequences[i] && newlineSequences[i].length) || 0);
  65. if (count >= start) {
  66. for (let j = i - range; j <= i + range || end > count; j++) {
  67. if (j < 0 || j >= lines.length)
  68. continue;
  69. const line = j + 1;
  70. res.push(`${line}${' '.repeat(Math.max(3 - String(line).length, 0))}| ${lines[j]}`);
  71. const lineLength = lines[j].length;
  72. const newLineSeqLength = (newlineSequences[j] && newlineSequences[j].length) || 0;
  73. if (j === i) {
  74. // push underline
  75. const pad = start - (count - (lineLength + newLineSeqLength));
  76. const length = Math.max(1, end > count ? lineLength - pad : end - start);
  77. res.push(` | ` + ' '.repeat(pad) + '^'.repeat(length));
  78. }
  79. else if (j > i) {
  80. if (end > count) {
  81. const length = Math.max(Math.min(end - count, lineLength), 1);
  82. res.push(` | ` + '^'.repeat(length));
  83. }
  84. count += lineLength + newLineSeqLength;
  85. }
  86. }
  87. break;
  88. }
  89. }
  90. return res.join('\n');
  91. }
  92. /**
  93. * On the client we only need to offer special cases for boolean attributes that
  94. * have different names from their corresponding dom properties:
  95. * - itemscope -> N/A
  96. * - allowfullscreen -> allowFullscreen
  97. * - formnovalidate -> formNoValidate
  98. * - ismap -> isMap
  99. * - nomodule -> noModule
  100. * - novalidate -> noValidate
  101. * - readonly -> readOnly
  102. */
  103. const specialBooleanAttrs = `itemscope,allowfullscreen,formnovalidate,ismap,nomodule,novalidate,readonly`;
  104. const isSpecialBooleanAttr = /*#__PURE__*/ makeMap(specialBooleanAttrs);
  105. /**
  106. * Boolean attributes should be included if the value is truthy or ''.
  107. * e.g. `<select multiple>` compiles to `{ multiple: '' }`
  108. */
  109. function includeBooleanAttr(value) {
  110. return !!value || value === '';
  111. }
  112. function normalizeStyle(value) {
  113. if (isArray(value)) {
  114. const res = {};
  115. for (let i = 0; i < value.length; i++) {
  116. const item = value[i];
  117. const normalized = isString(item)
  118. ? parseStringStyle(item)
  119. : normalizeStyle(item);
  120. if (normalized) {
  121. for (const key in normalized) {
  122. res[key] = normalized[key];
  123. }
  124. }
  125. }
  126. return res;
  127. }
  128. else if (isString(value)) {
  129. return value;
  130. }
  131. else if (isObject(value)) {
  132. return value;
  133. }
  134. }
  135. const listDelimiterRE = /;(?![^(]*\))/g;
  136. const propertyDelimiterRE = /:(.+)/;
  137. function parseStringStyle(cssText) {
  138. const ret = {};
  139. cssText.split(listDelimiterRE).forEach(item => {
  140. if (item) {
  141. const tmp = item.split(propertyDelimiterRE);
  142. tmp.length > 1 && (ret[tmp[0].trim()] = tmp[1].trim());
  143. }
  144. });
  145. return ret;
  146. }
  147. function normalizeClass(value) {
  148. let res = '';
  149. if (isString(value)) {
  150. res = value;
  151. }
  152. else if (isArray(value)) {
  153. for (let i = 0; i < value.length; i++) {
  154. const normalized = normalizeClass(value[i]);
  155. if (normalized) {
  156. res += normalized + ' ';
  157. }
  158. }
  159. }
  160. else if (isObject(value)) {
  161. for (const name in value) {
  162. if (value[name]) {
  163. res += name + ' ';
  164. }
  165. }
  166. }
  167. return res.trim();
  168. }
  169. function normalizeProps(props) {
  170. if (!props)
  171. return null;
  172. let { class: klass, style } = props;
  173. if (klass && !isString(klass)) {
  174. props.class = normalizeClass(klass);
  175. }
  176. if (style) {
  177. props.style = normalizeStyle(style);
  178. }
  179. return props;
  180. }
  181. // These tag configs are shared between compiler-dom and runtime-dom, so they
  182. // https://developer.mozilla.org/en-US/docs/Web/HTML/Element
  183. const HTML_TAGS = 'html,body,base,head,link,meta,style,title,address,article,aside,footer,' +
  184. 'header,h1,h2,h3,h4,h5,h6,nav,section,div,dd,dl,dt,figcaption,' +
  185. 'figure,picture,hr,img,li,main,ol,p,pre,ul,a,b,abbr,bdi,bdo,br,cite,code,' +
  186. 'data,dfn,em,i,kbd,mark,q,rp,rt,ruby,s,samp,small,span,strong,sub,sup,' +
  187. 'time,u,var,wbr,area,audio,map,track,video,embed,object,param,source,' +
  188. 'canvas,script,noscript,del,ins,caption,col,colgroup,table,thead,tbody,td,' +
  189. 'th,tr,button,datalist,fieldset,form,input,label,legend,meter,optgroup,' +
  190. 'option,output,progress,select,textarea,details,dialog,menu,' +
  191. 'summary,template,blockquote,iframe,tfoot';
  192. // https://developer.mozilla.org/en-US/docs/Web/SVG/Element
  193. const SVG_TAGS = 'svg,animate,animateMotion,animateTransform,circle,clipPath,color-profile,' +
  194. 'defs,desc,discard,ellipse,feBlend,feColorMatrix,feComponentTransfer,' +
  195. 'feComposite,feConvolveMatrix,feDiffuseLighting,feDisplacementMap,' +
  196. 'feDistanceLight,feDropShadow,feFlood,feFuncA,feFuncB,feFuncG,feFuncR,' +
  197. 'feGaussianBlur,feImage,feMerge,feMergeNode,feMorphology,feOffset,' +
  198. 'fePointLight,feSpecularLighting,feSpotLight,feTile,feTurbulence,filter,' +
  199. 'foreignObject,g,hatch,hatchpath,image,line,linearGradient,marker,mask,' +
  200. 'mesh,meshgradient,meshpatch,meshrow,metadata,mpath,path,pattern,' +
  201. 'polygon,polyline,radialGradient,rect,set,solidcolor,stop,switch,symbol,' +
  202. 'text,textPath,title,tspan,unknown,use,view';
  203. const VOID_TAGS = 'area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr';
  204. const isHTMLTag = /*#__PURE__*/ makeMap(HTML_TAGS);
  205. const isSVGTag = /*#__PURE__*/ makeMap(SVG_TAGS);
  206. const isVoidTag = /*#__PURE__*/ makeMap(VOID_TAGS);
  207. function looseCompareArrays(a, b) {
  208. if (a.length !== b.length)
  209. return false;
  210. let equal = true;
  211. for (let i = 0; equal && i < a.length; i++) {
  212. equal = looseEqual(a[i], b[i]);
  213. }
  214. return equal;
  215. }
  216. function looseEqual(a, b) {
  217. if (a === b)
  218. return true;
  219. let aValidType = isDate(a);
  220. let bValidType = isDate(b);
  221. if (aValidType || bValidType) {
  222. return aValidType && bValidType ? a.getTime() === b.getTime() : false;
  223. }
  224. aValidType = isArray(a);
  225. bValidType = isArray(b);
  226. if (aValidType || bValidType) {
  227. return aValidType && bValidType ? looseCompareArrays(a, b) : false;
  228. }
  229. aValidType = isObject(a);
  230. bValidType = isObject(b);
  231. if (aValidType || bValidType) {
  232. /* istanbul ignore if: this if will probably never be called */
  233. if (!aValidType || !bValidType) {
  234. return false;
  235. }
  236. const aKeysCount = Object.keys(a).length;
  237. const bKeysCount = Object.keys(b).length;
  238. if (aKeysCount !== bKeysCount) {
  239. return false;
  240. }
  241. for (const key in a) {
  242. const aHasKey = a.hasOwnProperty(key);
  243. const bHasKey = b.hasOwnProperty(key);
  244. if ((aHasKey && !bHasKey) ||
  245. (!aHasKey && bHasKey) ||
  246. !looseEqual(a[key], b[key])) {
  247. return false;
  248. }
  249. }
  250. }
  251. return String(a) === String(b);
  252. }
  253. function looseIndexOf(arr, val) {
  254. return arr.findIndex(item => looseEqual(item, val));
  255. }
  256. /**
  257. * For converting {{ interpolation }} values to displayed strings.
  258. * @private
  259. */
  260. const toDisplayString = (val) => {
  261. return val == null
  262. ? ''
  263. : isArray(val) ||
  264. (isObject(val) &&
  265. (val.toString === objectToString || !isFunction(val.toString)))
  266. ? JSON.stringify(val, replacer, 2)
  267. : String(val);
  268. };
  269. const replacer = (_key, val) => {
  270. // can't use isRef here since @vue/shared has no deps
  271. if (val && val.__v_isRef) {
  272. return replacer(_key, val.value);
  273. }
  274. else if (isMap(val)) {
  275. return {
  276. [`Map(${val.size})`]: [...val.entries()].reduce((entries, [key, val]) => {
  277. entries[`${key} =>`] = val;
  278. return entries;
  279. }, {})
  280. };
  281. }
  282. else if (isSet(val)) {
  283. return {
  284. [`Set(${val.size})`]: [...val.values()]
  285. };
  286. }
  287. else if (isObject(val) && !isArray(val) && !isPlainObject(val)) {
  288. return String(val);
  289. }
  290. return val;
  291. };
  292. const EMPTY_OBJ = Object.freeze({})
  293. ;
  294. const EMPTY_ARR = Object.freeze([]) ;
  295. const NOOP = () => { };
  296. /**
  297. * Always return false.
  298. */
  299. const NO = () => false;
  300. const onRE = /^on[^a-z]/;
  301. const isOn = (key) => onRE.test(key);
  302. const isModelListener = (key) => key.startsWith('onUpdate:');
  303. const extend = Object.assign;
  304. const remove = (arr, el) => {
  305. const i = arr.indexOf(el);
  306. if (i > -1) {
  307. arr.splice(i, 1);
  308. }
  309. };
  310. const hasOwnProperty = Object.prototype.hasOwnProperty;
  311. const hasOwn = (val, key) => hasOwnProperty.call(val, key);
  312. const isArray = Array.isArray;
  313. const isMap = (val) => toTypeString(val) === '[object Map]';
  314. const isSet = (val) => toTypeString(val) === '[object Set]';
  315. const isDate = (val) => val instanceof Date;
  316. const isFunction = (val) => typeof val === 'function';
  317. const isString = (val) => typeof val === 'string';
  318. const isSymbol = (val) => typeof val === 'symbol';
  319. const isObject = (val) => val !== null && typeof val === 'object';
  320. const isPromise = (val) => {
  321. return isObject(val) && isFunction(val.then) && isFunction(val.catch);
  322. };
  323. const objectToString = Object.prototype.toString;
  324. const toTypeString = (value) => objectToString.call(value);
  325. const toRawType = (value) => {
  326. // extract "RawType" from strings like "[object RawType]"
  327. return toTypeString(value).slice(8, -1);
  328. };
  329. const isPlainObject = (val) => toTypeString(val) === '[object Object]';
  330. const isIntegerKey = (key) => isString(key) &&
  331. key !== 'NaN' &&
  332. key[0] !== '-' &&
  333. '' + parseInt(key, 10) === key;
  334. const isReservedProp = /*#__PURE__*/ makeMap(
  335. // the leading comma is intentional so empty string "" is also included
  336. ',key,ref,ref_for,ref_key,' +
  337. 'onVnodeBeforeMount,onVnodeMounted,' +
  338. 'onVnodeBeforeUpdate,onVnodeUpdated,' +
  339. 'onVnodeBeforeUnmount,onVnodeUnmounted');
  340. const cacheStringFunction = (fn) => {
  341. const cache = Object.create(null);
  342. return ((str) => {
  343. const hit = cache[str];
  344. return hit || (cache[str] = fn(str));
  345. });
  346. };
  347. const camelizeRE = /-(\w)/g;
  348. /**
  349. * @private
  350. */
  351. const camelize = cacheStringFunction((str) => {
  352. return str.replace(camelizeRE, (_, c) => (c ? c.toUpperCase() : ''));
  353. });
  354. const hyphenateRE = /\B([A-Z])/g;
  355. /**
  356. * @private
  357. */
  358. const hyphenate = cacheStringFunction((str) => str.replace(hyphenateRE, '-$1').toLowerCase());
  359. /**
  360. * @private
  361. */
  362. const capitalize = cacheStringFunction((str) => str.charAt(0).toUpperCase() + str.slice(1));
  363. /**
  364. * @private
  365. */
  366. const toHandlerKey = cacheStringFunction((str) => str ? `on${capitalize(str)}` : ``);
  367. // compare whether a value has changed, accounting for NaN.
  368. const hasChanged = (value, oldValue) => !Object.is(value, oldValue);
  369. const invokeArrayFns = (fns, arg) => {
  370. for (let i = 0; i < fns.length; i++) {
  371. fns[i](arg);
  372. }
  373. };
  374. const def = (obj, key, value) => {
  375. Object.defineProperty(obj, key, {
  376. configurable: true,
  377. enumerable: false,
  378. value
  379. });
  380. };
  381. const toNumber = (val) => {
  382. const n = parseFloat(val);
  383. return isNaN(n) ? val : n;
  384. };
  385. let _globalThis;
  386. const getGlobalThis = () => {
  387. return (_globalThis ||
  388. (_globalThis =
  389. typeof globalThis !== 'undefined'
  390. ? globalThis
  391. : typeof self !== 'undefined'
  392. ? self
  393. : typeof window !== 'undefined'
  394. ? window
  395. : typeof global !== 'undefined'
  396. ? global
  397. : {}));
  398. };
  399. function warn(msg, ...args) {
  400. console.warn(`[Vue warn] ${msg}`, ...args);
  401. }
  402. let activeEffectScope;
  403. const effectScopeStack = [];
  404. class EffectScope {
  405. constructor(detached = false) {
  406. this.active = true;
  407. this.effects = [];
  408. this.cleanups = [];
  409. if (!detached && activeEffectScope) {
  410. this.parent = activeEffectScope;
  411. this.index =
  412. (activeEffectScope.scopes || (activeEffectScope.scopes = [])).push(this) - 1;
  413. }
  414. }
  415. run(fn) {
  416. if (this.active) {
  417. try {
  418. this.on();
  419. return fn();
  420. }
  421. finally {
  422. this.off();
  423. }
  424. }
  425. else {
  426. warn(`cannot run an inactive effect scope.`);
  427. }
  428. }
  429. on() {
  430. if (this.active) {
  431. effectScopeStack.push(this);
  432. activeEffectScope = this;
  433. }
  434. }
  435. off() {
  436. if (this.active) {
  437. effectScopeStack.pop();
  438. activeEffectScope = effectScopeStack[effectScopeStack.length - 1];
  439. }
  440. }
  441. stop(fromParent) {
  442. if (this.active) {
  443. this.effects.forEach(e => e.stop());
  444. this.cleanups.forEach(cleanup => cleanup());
  445. if (this.scopes) {
  446. this.scopes.forEach(e => e.stop(true));
  447. }
  448. // nested scope, dereference from parent to avoid memory leaks
  449. if (this.parent && !fromParent) {
  450. // optimized O(1) removal
  451. const last = this.parent.scopes.pop();
  452. if (last && last !== this) {
  453. this.parent.scopes[this.index] = last;
  454. last.index = this.index;
  455. }
  456. }
  457. this.active = false;
  458. }
  459. }
  460. }
  461. function effectScope(detached) {
  462. return new EffectScope(detached);
  463. }
  464. function recordEffectScope(effect, scope) {
  465. scope = scope || activeEffectScope;
  466. if (scope && scope.active) {
  467. scope.effects.push(effect);
  468. }
  469. }
  470. function getCurrentScope() {
  471. return activeEffectScope;
  472. }
  473. function onScopeDispose(fn) {
  474. if (activeEffectScope) {
  475. activeEffectScope.cleanups.push(fn);
  476. }
  477. else {
  478. warn(`onScopeDispose() is called when there is no active effect scope` +
  479. ` to be associated with.`);
  480. }
  481. }
  482. const createDep = (effects) => {
  483. const dep = new Set(effects);
  484. dep.w = 0;
  485. dep.n = 0;
  486. return dep;
  487. };
  488. const wasTracked = (dep) => (dep.w & trackOpBit) > 0;
  489. const newTracked = (dep) => (dep.n & trackOpBit) > 0;
  490. const initDepMarkers = ({ deps }) => {
  491. if (deps.length) {
  492. for (let i = 0; i < deps.length; i++) {
  493. deps[i].w |= trackOpBit; // set was tracked
  494. }
  495. }
  496. };
  497. const finalizeDepMarkers = (effect) => {
  498. const { deps } = effect;
  499. if (deps.length) {
  500. let ptr = 0;
  501. for (let i = 0; i < deps.length; i++) {
  502. const dep = deps[i];
  503. if (wasTracked(dep) && !newTracked(dep)) {
  504. dep.delete(effect);
  505. }
  506. else {
  507. deps[ptr++] = dep;
  508. }
  509. // clear bits
  510. dep.w &= ~trackOpBit;
  511. dep.n &= ~trackOpBit;
  512. }
  513. deps.length = ptr;
  514. }
  515. };
  516. const targetMap = new WeakMap();
  517. // The number of effects currently being tracked recursively.
  518. let effectTrackDepth = 0;
  519. let trackOpBit = 1;
  520. /**
  521. * The bitwise track markers support at most 30 levels of recursion.
  522. * This value is chosen to enable modern JS engines to use a SMI on all platforms.
  523. * When recursion depth is greater, fall back to using a full cleanup.
  524. */
  525. const maxMarkerBits = 30;
  526. const effectStack = [];
  527. let activeEffect;
  528. const ITERATE_KEY = Symbol('iterate' );
  529. const MAP_KEY_ITERATE_KEY = Symbol('Map key iterate' );
  530. class ReactiveEffect {
  531. constructor(fn, scheduler = null, scope) {
  532. this.fn = fn;
  533. this.scheduler = scheduler;
  534. this.active = true;
  535. this.deps = [];
  536. recordEffectScope(this, scope);
  537. }
  538. run() {
  539. if (!this.active) {
  540. return this.fn();
  541. }
  542. if (!effectStack.includes(this)) {
  543. try {
  544. effectStack.push((activeEffect = this));
  545. enableTracking();
  546. trackOpBit = 1 << ++effectTrackDepth;
  547. if (effectTrackDepth <= maxMarkerBits) {
  548. initDepMarkers(this);
  549. }
  550. else {
  551. cleanupEffect(this);
  552. }
  553. return this.fn();
  554. }
  555. finally {
  556. if (effectTrackDepth <= maxMarkerBits) {
  557. finalizeDepMarkers(this);
  558. }
  559. trackOpBit = 1 << --effectTrackDepth;
  560. resetTracking();
  561. effectStack.pop();
  562. const n = effectStack.length;
  563. activeEffect = n > 0 ? effectStack[n - 1] : undefined;
  564. }
  565. }
  566. }
  567. stop() {
  568. if (this.active) {
  569. cleanupEffect(this);
  570. if (this.onStop) {
  571. this.onStop();
  572. }
  573. this.active = false;
  574. }
  575. }
  576. }
  577. function cleanupEffect(effect) {
  578. const { deps } = effect;
  579. if (deps.length) {
  580. for (let i = 0; i < deps.length; i++) {
  581. deps[i].delete(effect);
  582. }
  583. deps.length = 0;
  584. }
  585. }
  586. function effect(fn, options) {
  587. if (fn.effect) {
  588. fn = fn.effect.fn;
  589. }
  590. const _effect = new ReactiveEffect(fn);
  591. if (options) {
  592. extend(_effect, options);
  593. if (options.scope)
  594. recordEffectScope(_effect, options.scope);
  595. }
  596. if (!options || !options.lazy) {
  597. _effect.run();
  598. }
  599. const runner = _effect.run.bind(_effect);
  600. runner.effect = _effect;
  601. return runner;
  602. }
  603. function stop(runner) {
  604. runner.effect.stop();
  605. }
  606. let shouldTrack = true;
  607. const trackStack = [];
  608. function pauseTracking() {
  609. trackStack.push(shouldTrack);
  610. shouldTrack = false;
  611. }
  612. function enableTracking() {
  613. trackStack.push(shouldTrack);
  614. shouldTrack = true;
  615. }
  616. function resetTracking() {
  617. const last = trackStack.pop();
  618. shouldTrack = last === undefined ? true : last;
  619. }
  620. function track(target, type, key) {
  621. if (!isTracking()) {
  622. return;
  623. }
  624. let depsMap = targetMap.get(target);
  625. if (!depsMap) {
  626. targetMap.set(target, (depsMap = new Map()));
  627. }
  628. let dep = depsMap.get(key);
  629. if (!dep) {
  630. depsMap.set(key, (dep = createDep()));
  631. }
  632. const eventInfo = { effect: activeEffect, target, type, key }
  633. ;
  634. trackEffects(dep, eventInfo);
  635. }
  636. function isTracking() {
  637. return shouldTrack && activeEffect !== undefined;
  638. }
  639. function trackEffects(dep, debuggerEventExtraInfo) {
  640. let shouldTrack = false;
  641. if (effectTrackDepth <= maxMarkerBits) {
  642. if (!newTracked(dep)) {
  643. dep.n |= trackOpBit; // set newly tracked
  644. shouldTrack = !wasTracked(dep);
  645. }
  646. }
  647. else {
  648. // Full cleanup mode.
  649. shouldTrack = !dep.has(activeEffect);
  650. }
  651. if (shouldTrack) {
  652. dep.add(activeEffect);
  653. activeEffect.deps.push(dep);
  654. if (activeEffect.onTrack) {
  655. activeEffect.onTrack(Object.assign({
  656. effect: activeEffect
  657. }, debuggerEventExtraInfo));
  658. }
  659. }
  660. }
  661. function trigger(target, type, key, newValue, oldValue, oldTarget) {
  662. const depsMap = targetMap.get(target);
  663. if (!depsMap) {
  664. // never been tracked
  665. return;
  666. }
  667. let deps = [];
  668. if (type === "clear" /* CLEAR */) {
  669. // collection being cleared
  670. // trigger all effects for target
  671. deps = [...depsMap.values()];
  672. }
  673. else if (key === 'length' && isArray(target)) {
  674. depsMap.forEach((dep, key) => {
  675. if (key === 'length' || key >= newValue) {
  676. deps.push(dep);
  677. }
  678. });
  679. }
  680. else {
  681. // schedule runs for SET | ADD | DELETE
  682. if (key !== void 0) {
  683. deps.push(depsMap.get(key));
  684. }
  685. // also run for iteration key on ADD | DELETE | Map.SET
  686. switch (type) {
  687. case "add" /* ADD */:
  688. if (!isArray(target)) {
  689. deps.push(depsMap.get(ITERATE_KEY));
  690. if (isMap(target)) {
  691. deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
  692. }
  693. }
  694. else if (isIntegerKey(key)) {
  695. // new index added to array -> length changes
  696. deps.push(depsMap.get('length'));
  697. }
  698. break;
  699. case "delete" /* DELETE */:
  700. if (!isArray(target)) {
  701. deps.push(depsMap.get(ITERATE_KEY));
  702. if (isMap(target)) {
  703. deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
  704. }
  705. }
  706. break;
  707. case "set" /* SET */:
  708. if (isMap(target)) {
  709. deps.push(depsMap.get(ITERATE_KEY));
  710. }
  711. break;
  712. }
  713. }
  714. const eventInfo = { target, type, key, newValue, oldValue, oldTarget }
  715. ;
  716. if (deps.length === 1) {
  717. if (deps[0]) {
  718. {
  719. triggerEffects(deps[0], eventInfo);
  720. }
  721. }
  722. }
  723. else {
  724. const effects = [];
  725. for (const dep of deps) {
  726. if (dep) {
  727. effects.push(...dep);
  728. }
  729. }
  730. {
  731. triggerEffects(createDep(effects), eventInfo);
  732. }
  733. }
  734. }
  735. function triggerEffects(dep, debuggerEventExtraInfo) {
  736. // spread into array for stabilization
  737. for (const effect of isArray(dep) ? dep : [...dep]) {
  738. if (effect !== activeEffect || effect.allowRecurse) {
  739. if (effect.onTrigger) {
  740. effect.onTrigger(extend({ effect }, debuggerEventExtraInfo));
  741. }
  742. if (effect.scheduler) {
  743. effect.scheduler();
  744. }
  745. else {
  746. effect.run();
  747. }
  748. }
  749. }
  750. }
  751. const isNonTrackableKeys = /*#__PURE__*/ makeMap(`__proto__,__v_isRef,__isVue`);
  752. const builtInSymbols = new Set(Object.getOwnPropertyNames(Symbol)
  753. .map(key => Symbol[key])
  754. .filter(isSymbol));
  755. const get = /*#__PURE__*/ createGetter();
  756. const shallowGet = /*#__PURE__*/ createGetter(false, true);
  757. const readonlyGet = /*#__PURE__*/ createGetter(true);
  758. const shallowReadonlyGet = /*#__PURE__*/ createGetter(true, true);
  759. const arrayInstrumentations = /*#__PURE__*/ createArrayInstrumentations();
  760. function createArrayInstrumentations() {
  761. const instrumentations = {};
  762. ['includes', 'indexOf', 'lastIndexOf'].forEach(key => {
  763. instrumentations[key] = function (...args) {
  764. const arr = toRaw(this);
  765. for (let i = 0, l = this.length; i < l; i++) {
  766. track(arr, "get" /* GET */, i + '');
  767. }
  768. // we run the method using the original args first (which may be reactive)
  769. const res = arr[key](...args);
  770. if (res === -1 || res === false) {
  771. // if that didn't work, run it again using raw values.
  772. return arr[key](...args.map(toRaw));
  773. }
  774. else {
  775. return res;
  776. }
  777. };
  778. });
  779. ['push', 'pop', 'shift', 'unshift', 'splice'].forEach(key => {
  780. instrumentations[key] = function (...args) {
  781. pauseTracking();
  782. const res = toRaw(this)[key].apply(this, args);
  783. resetTracking();
  784. return res;
  785. };
  786. });
  787. return instrumentations;
  788. }
  789. function createGetter(isReadonly = false, shallow = false) {
  790. return function get(target, key, receiver) {
  791. if (key === "__v_isReactive" /* IS_REACTIVE */) {
  792. return !isReadonly;
  793. }
  794. else if (key === "__v_isReadonly" /* IS_READONLY */) {
  795. return isReadonly;
  796. }
  797. else if (key === "__v_raw" /* RAW */ &&
  798. receiver ===
  799. (isReadonly
  800. ? shallow
  801. ? shallowReadonlyMap
  802. : readonlyMap
  803. : shallow
  804. ? shallowReactiveMap
  805. : reactiveMap).get(target)) {
  806. return target;
  807. }
  808. const targetIsArray = isArray(target);
  809. if (!isReadonly && targetIsArray && hasOwn(arrayInstrumentations, key)) {
  810. return Reflect.get(arrayInstrumentations, key, receiver);
  811. }
  812. const res = Reflect.get(target, key, receiver);
  813. if (isSymbol(key) ? builtInSymbols.has(key) : isNonTrackableKeys(key)) {
  814. return res;
  815. }
  816. if (!isReadonly) {
  817. track(target, "get" /* GET */, key);
  818. }
  819. if (shallow) {
  820. return res;
  821. }
  822. if (isRef(res)) {
  823. // ref unwrapping - does not apply for Array + integer key.
  824. const shouldUnwrap = !targetIsArray || !isIntegerKey(key);
  825. return shouldUnwrap ? res.value : res;
  826. }
  827. if (isObject(res)) {
  828. // Convert returned value into a proxy as well. we do the isObject check
  829. // here to avoid invalid value warning. Also need to lazy access readonly
  830. // and reactive here to avoid circular dependency.
  831. return isReadonly ? readonly(res) : reactive(res);
  832. }
  833. return res;
  834. };
  835. }
  836. const set = /*#__PURE__*/ createSetter();
  837. const shallowSet = /*#__PURE__*/ createSetter(true);
  838. function createSetter(shallow = false) {
  839. return function set(target, key, value, receiver) {
  840. let oldValue = target[key];
  841. if (!shallow && !isReadonly(value)) {
  842. value = toRaw(value);
  843. oldValue = toRaw(oldValue);
  844. if (!isArray(target) && isRef(oldValue) && !isRef(value)) {
  845. oldValue.value = value;
  846. return true;
  847. }
  848. }
  849. const hadKey = isArray(target) && isIntegerKey(key)
  850. ? Number(key) < target.length
  851. : hasOwn(target, key);
  852. const result = Reflect.set(target, key, value, receiver);
  853. // don't trigger if target is something up in the prototype chain of original
  854. if (target === toRaw(receiver)) {
  855. if (!hadKey) {
  856. trigger(target, "add" /* ADD */, key, value);
  857. }
  858. else if (hasChanged(value, oldValue)) {
  859. trigger(target, "set" /* SET */, key, value, oldValue);
  860. }
  861. }
  862. return result;
  863. };
  864. }
  865. function deleteProperty(target, key) {
  866. const hadKey = hasOwn(target, key);
  867. const oldValue = target[key];
  868. const result = Reflect.deleteProperty(target, key);
  869. if (result && hadKey) {
  870. trigger(target, "delete" /* DELETE */, key, undefined, oldValue);
  871. }
  872. return result;
  873. }
  874. function has(target, key) {
  875. const result = Reflect.has(target, key);
  876. if (!isSymbol(key) || !builtInSymbols.has(key)) {
  877. track(target, "has" /* HAS */, key);
  878. }
  879. return result;
  880. }
  881. function ownKeys(target) {
  882. track(target, "iterate" /* ITERATE */, isArray(target) ? 'length' : ITERATE_KEY);
  883. return Reflect.ownKeys(target);
  884. }
  885. const mutableHandlers = {
  886. get,
  887. set,
  888. deleteProperty,
  889. has,
  890. ownKeys
  891. };
  892. const readonlyHandlers = {
  893. get: readonlyGet,
  894. set(target, key) {
  895. {
  896. console.warn(`Set operation on key "${String(key)}" failed: target is readonly.`, target);
  897. }
  898. return true;
  899. },
  900. deleteProperty(target, key) {
  901. {
  902. console.warn(`Delete operation on key "${String(key)}" failed: target is readonly.`, target);
  903. }
  904. return true;
  905. }
  906. };
  907. const shallowReactiveHandlers = /*#__PURE__*/ extend({}, mutableHandlers, {
  908. get: shallowGet,
  909. set: shallowSet
  910. });
  911. // Props handlers are special in the sense that it should not unwrap top-level
  912. // refs (in order to allow refs to be explicitly passed down), but should
  913. // retain the reactivity of the normal readonly object.
  914. const shallowReadonlyHandlers = /*#__PURE__*/ extend({}, readonlyHandlers, {
  915. get: shallowReadonlyGet
  916. });
  917. const toShallow = (value) => value;
  918. const getProto = (v) => Reflect.getPrototypeOf(v);
  919. function get$1(target, key, isReadonly = false, isShallow = false) {
  920. // #1772: readonly(reactive(Map)) should return readonly + reactive version
  921. // of the value
  922. target = target["__v_raw" /* RAW */];
  923. const rawTarget = toRaw(target);
  924. const rawKey = toRaw(key);
  925. if (key !== rawKey) {
  926. !isReadonly && track(rawTarget, "get" /* GET */, key);
  927. }
  928. !isReadonly && track(rawTarget, "get" /* GET */, rawKey);
  929. const { has } = getProto(rawTarget);
  930. const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
  931. if (has.call(rawTarget, key)) {
  932. return wrap(target.get(key));
  933. }
  934. else if (has.call(rawTarget, rawKey)) {
  935. return wrap(target.get(rawKey));
  936. }
  937. else if (target !== rawTarget) {
  938. // #3602 readonly(reactive(Map))
  939. // ensure that the nested reactive `Map` can do tracking for itself
  940. target.get(key);
  941. }
  942. }
  943. function has$1(key, isReadonly = false) {
  944. const target = this["__v_raw" /* RAW */];
  945. const rawTarget = toRaw(target);
  946. const rawKey = toRaw(key);
  947. if (key !== rawKey) {
  948. !isReadonly && track(rawTarget, "has" /* HAS */, key);
  949. }
  950. !isReadonly && track(rawTarget, "has" /* HAS */, rawKey);
  951. return key === rawKey
  952. ? target.has(key)
  953. : target.has(key) || target.has(rawKey);
  954. }
  955. function size(target, isReadonly = false) {
  956. target = target["__v_raw" /* RAW */];
  957. !isReadonly && track(toRaw(target), "iterate" /* ITERATE */, ITERATE_KEY);
  958. return Reflect.get(target, 'size', target);
  959. }
  960. function add(value) {
  961. value = toRaw(value);
  962. const target = toRaw(this);
  963. const proto = getProto(target);
  964. const hadKey = proto.has.call(target, value);
  965. if (!hadKey) {
  966. target.add(value);
  967. trigger(target, "add" /* ADD */, value, value);
  968. }
  969. return this;
  970. }
  971. function set$1(key, value) {
  972. value = toRaw(value);
  973. const target = toRaw(this);
  974. const { has, get } = getProto(target);
  975. let hadKey = has.call(target, key);
  976. if (!hadKey) {
  977. key = toRaw(key);
  978. hadKey = has.call(target, key);
  979. }
  980. else {
  981. checkIdentityKeys(target, has, key);
  982. }
  983. const oldValue = get.call(target, key);
  984. target.set(key, value);
  985. if (!hadKey) {
  986. trigger(target, "add" /* ADD */, key, value);
  987. }
  988. else if (hasChanged(value, oldValue)) {
  989. trigger(target, "set" /* SET */, key, value, oldValue);
  990. }
  991. return this;
  992. }
  993. function deleteEntry(key) {
  994. const target = toRaw(this);
  995. const { has, get } = getProto(target);
  996. let hadKey = has.call(target, key);
  997. if (!hadKey) {
  998. key = toRaw(key);
  999. hadKey = has.call(target, key);
  1000. }
  1001. else {
  1002. checkIdentityKeys(target, has, key);
  1003. }
  1004. const oldValue = get ? get.call(target, key) : undefined;
  1005. // forward the operation before queueing reactions
  1006. const result = target.delete(key);
  1007. if (hadKey) {
  1008. trigger(target, "delete" /* DELETE */, key, undefined, oldValue);
  1009. }
  1010. return result;
  1011. }
  1012. function clear() {
  1013. const target = toRaw(this);
  1014. const hadItems = target.size !== 0;
  1015. const oldTarget = isMap(target)
  1016. ? new Map(target)
  1017. : new Set(target)
  1018. ;
  1019. // forward the operation before queueing reactions
  1020. const result = target.clear();
  1021. if (hadItems) {
  1022. trigger(target, "clear" /* CLEAR */, undefined, undefined, oldTarget);
  1023. }
  1024. return result;
  1025. }
  1026. function createForEach(isReadonly, isShallow) {
  1027. return function forEach(callback, thisArg) {
  1028. const observed = this;
  1029. const target = observed["__v_raw" /* RAW */];
  1030. const rawTarget = toRaw(target);
  1031. const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
  1032. !isReadonly && track(rawTarget, "iterate" /* ITERATE */, ITERATE_KEY);
  1033. return target.forEach((value, key) => {
  1034. // important: make sure the callback is
  1035. // 1. invoked with the reactive map as `this` and 3rd arg
  1036. // 2. the value received should be a corresponding reactive/readonly.
  1037. return callback.call(thisArg, wrap(value), wrap(key), observed);
  1038. });
  1039. };
  1040. }
  1041. function createIterableMethod(method, isReadonly, isShallow) {
  1042. return function (...args) {
  1043. const target = this["__v_raw" /* RAW */];
  1044. const rawTarget = toRaw(target);
  1045. const targetIsMap = isMap(rawTarget);
  1046. const isPair = method === 'entries' || (method === Symbol.iterator && targetIsMap);
  1047. const isKeyOnly = method === 'keys' && targetIsMap;
  1048. const innerIterator = target[method](...args);
  1049. const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
  1050. !isReadonly &&
  1051. track(rawTarget, "iterate" /* ITERATE */, isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY);
  1052. // return a wrapped iterator which returns observed versions of the
  1053. // values emitted from the real iterator
  1054. return {
  1055. // iterator protocol
  1056. next() {
  1057. const { value, done } = innerIterator.next();
  1058. return done
  1059. ? { value, done }
  1060. : {
  1061. value: isPair ? [wrap(value[0]), wrap(value[1])] : wrap(value),
  1062. done
  1063. };
  1064. },
  1065. // iterable protocol
  1066. [Symbol.iterator]() {
  1067. return this;
  1068. }
  1069. };
  1070. };
  1071. }
  1072. function createReadonlyMethod(type) {
  1073. return function (...args) {
  1074. {
  1075. const key = args[0] ? `on key "${args[0]}" ` : ``;
  1076. console.warn(`${capitalize(type)} operation ${key}failed: target is readonly.`, toRaw(this));
  1077. }
  1078. return type === "delete" /* DELETE */ ? false : this;
  1079. };
  1080. }
  1081. function createInstrumentations() {
  1082. const mutableInstrumentations = {
  1083. get(key) {
  1084. return get$1(this, key);
  1085. },
  1086. get size() {
  1087. return size(this);
  1088. },
  1089. has: has$1,
  1090. add,
  1091. set: set$1,
  1092. delete: deleteEntry,
  1093. clear,
  1094. forEach: createForEach(false, false)
  1095. };
  1096. const shallowInstrumentations = {
  1097. get(key) {
  1098. return get$1(this, key, false, true);
  1099. },
  1100. get size() {
  1101. return size(this);
  1102. },
  1103. has: has$1,
  1104. add,
  1105. set: set$1,
  1106. delete: deleteEntry,
  1107. clear,
  1108. forEach: createForEach(false, true)
  1109. };
  1110. const readonlyInstrumentations = {
  1111. get(key) {
  1112. return get$1(this, key, true);
  1113. },
  1114. get size() {
  1115. return size(this, true);
  1116. },
  1117. has(key) {
  1118. return has$1.call(this, key, true);
  1119. },
  1120. add: createReadonlyMethod("add" /* ADD */),
  1121. set: createReadonlyMethod("set" /* SET */),
  1122. delete: createReadonlyMethod("delete" /* DELETE */),
  1123. clear: createReadonlyMethod("clear" /* CLEAR */),
  1124. forEach: createForEach(true, false)
  1125. };
  1126. const shallowReadonlyInstrumentations = {
  1127. get(key) {
  1128. return get$1(this, key, true, true);
  1129. },
  1130. get size() {
  1131. return size(this, true);
  1132. },
  1133. has(key) {
  1134. return has$1.call(this, key, true);
  1135. },
  1136. add: createReadonlyMethod("add" /* ADD */),
  1137. set: createReadonlyMethod("set" /* SET */),
  1138. delete: createReadonlyMethod("delete" /* DELETE */),
  1139. clear: createReadonlyMethod("clear" /* CLEAR */),
  1140. forEach: createForEach(true, true)
  1141. };
  1142. const iteratorMethods = ['keys', 'values', 'entries', Symbol.iterator];
  1143. iteratorMethods.forEach(method => {
  1144. mutableInstrumentations[method] = createIterableMethod(method, false, false);
  1145. readonlyInstrumentations[method] = createIterableMethod(method, true, false);
  1146. shallowInstrumentations[method] = createIterableMethod(method, false, true);
  1147. shallowReadonlyInstrumentations[method] = createIterableMethod(method, true, true);
  1148. });
  1149. return [
  1150. mutableInstrumentations,
  1151. readonlyInstrumentations,
  1152. shallowInstrumentations,
  1153. shallowReadonlyInstrumentations
  1154. ];
  1155. }
  1156. const [mutableInstrumentations, readonlyInstrumentations, shallowInstrumentations, shallowReadonlyInstrumentations] = /* #__PURE__*/ createInstrumentations();
  1157. function createInstrumentationGetter(isReadonly, shallow) {
  1158. const instrumentations = shallow
  1159. ? isReadonly
  1160. ? shallowReadonlyInstrumentations
  1161. : shallowInstrumentations
  1162. : isReadonly
  1163. ? readonlyInstrumentations
  1164. : mutableInstrumentations;
  1165. return (target, key, receiver) => {
  1166. if (key === "__v_isReactive" /* IS_REACTIVE */) {
  1167. return !isReadonly;
  1168. }
  1169. else if (key === "__v_isReadonly" /* IS_READONLY */) {
  1170. return isReadonly;
  1171. }
  1172. else if (key === "__v_raw" /* RAW */) {
  1173. return target;
  1174. }
  1175. return Reflect.get(hasOwn(instrumentations, key) && key in target
  1176. ? instrumentations
  1177. : target, key, receiver);
  1178. };
  1179. }
  1180. const mutableCollectionHandlers = {
  1181. get: /*#__PURE__*/ createInstrumentationGetter(false, false)
  1182. };
  1183. const shallowCollectionHandlers = {
  1184. get: /*#__PURE__*/ createInstrumentationGetter(false, true)
  1185. };
  1186. const readonlyCollectionHandlers = {
  1187. get: /*#__PURE__*/ createInstrumentationGetter(true, false)
  1188. };
  1189. const shallowReadonlyCollectionHandlers = {
  1190. get: /*#__PURE__*/ createInstrumentationGetter(true, true)
  1191. };
  1192. function checkIdentityKeys(target, has, key) {
  1193. const rawKey = toRaw(key);
  1194. if (rawKey !== key && has.call(target, rawKey)) {
  1195. const type = toRawType(target);
  1196. console.warn(`Reactive ${type} contains both the raw and reactive ` +
  1197. `versions of the same object${type === `Map` ? ` as keys` : ``}, ` +
  1198. `which can lead to inconsistencies. ` +
  1199. `Avoid differentiating between the raw and reactive versions ` +
  1200. `of an object and only use the reactive version if possible.`);
  1201. }
  1202. }
  1203. const reactiveMap = new WeakMap();
  1204. const shallowReactiveMap = new WeakMap();
  1205. const readonlyMap = new WeakMap();
  1206. const shallowReadonlyMap = new WeakMap();
  1207. function targetTypeMap(rawType) {
  1208. switch (rawType) {
  1209. case 'Object':
  1210. case 'Array':
  1211. return 1 /* COMMON */;
  1212. case 'Map':
  1213. case 'Set':
  1214. case 'WeakMap':
  1215. case 'WeakSet':
  1216. return 2 /* COLLECTION */;
  1217. default:
  1218. return 0 /* INVALID */;
  1219. }
  1220. }
  1221. function getTargetType(value) {
  1222. return value["__v_skip" /* SKIP */] || !Object.isExtensible(value)
  1223. ? 0 /* INVALID */
  1224. : targetTypeMap(toRawType(value));
  1225. }
  1226. function reactive(target) {
  1227. // if trying to observe a readonly proxy, return the readonly version.
  1228. if (target && target["__v_isReadonly" /* IS_READONLY */]) {
  1229. return target;
  1230. }
  1231. return createReactiveObject(target, false, mutableHandlers, mutableCollectionHandlers, reactiveMap);
  1232. }
  1233. /**
  1234. * Return a shallowly-reactive copy of the original object, where only the root
  1235. * level properties are reactive. It also does not auto-unwrap refs (even at the
  1236. * root level).
  1237. */
  1238. function shallowReactive(target) {
  1239. return createReactiveObject(target, false, shallowReactiveHandlers, shallowCollectionHandlers, shallowReactiveMap);
  1240. }
  1241. /**
  1242. * Creates a readonly copy of the original object. Note the returned copy is not
  1243. * made reactive, but `readonly` can be called on an already reactive object.
  1244. */
  1245. function readonly(target) {
  1246. return createReactiveObject(target, true, readonlyHandlers, readonlyCollectionHandlers, readonlyMap);
  1247. }
  1248. /**
  1249. * Returns a reactive-copy of the original object, where only the root level
  1250. * properties are readonly, and does NOT unwrap refs nor recursively convert
  1251. * returned properties.
  1252. * This is used for creating the props proxy object for stateful components.
  1253. */
  1254. function shallowReadonly(target) {
  1255. return createReactiveObject(target, true, shallowReadonlyHandlers, shallowReadonlyCollectionHandlers, shallowReadonlyMap);
  1256. }
  1257. function createReactiveObject(target, isReadonly, baseHandlers, collectionHandlers, proxyMap) {
  1258. if (!isObject(target)) {
  1259. {
  1260. console.warn(`value cannot be made reactive: ${String(target)}`);
  1261. }
  1262. return target;
  1263. }
  1264. // target is already a Proxy, return it.
  1265. // exception: calling readonly() on a reactive object
  1266. if (target["__v_raw" /* RAW */] &&
  1267. !(isReadonly && target["__v_isReactive" /* IS_REACTIVE */])) {
  1268. return target;
  1269. }
  1270. // target already has corresponding Proxy
  1271. const existingProxy = proxyMap.get(target);
  1272. if (existingProxy) {
  1273. return existingProxy;
  1274. }
  1275. // only a whitelist of value types can be observed.
  1276. const targetType = getTargetType(target);
  1277. if (targetType === 0 /* INVALID */) {
  1278. return target;
  1279. }
  1280. const proxy = new Proxy(target, targetType === 2 /* COLLECTION */ ? collectionHandlers : baseHandlers);
  1281. proxyMap.set(target, proxy);
  1282. return proxy;
  1283. }
  1284. function isReactive(value) {
  1285. if (isReadonly(value)) {
  1286. return isReactive(value["__v_raw" /* RAW */]);
  1287. }
  1288. return !!(value && value["__v_isReactive" /* IS_REACTIVE */]);
  1289. }
  1290. function isReadonly(value) {
  1291. return !!(value && value["__v_isReadonly" /* IS_READONLY */]);
  1292. }
  1293. function isProxy(value) {
  1294. return isReactive(value) || isReadonly(value);
  1295. }
  1296. function toRaw(observed) {
  1297. const raw = observed && observed["__v_raw" /* RAW */];
  1298. return raw ? toRaw(raw) : observed;
  1299. }
  1300. function markRaw(value) {
  1301. def(value, "__v_skip" /* SKIP */, true);
  1302. return value;
  1303. }
  1304. const toReactive = (value) => isObject(value) ? reactive(value) : value;
  1305. const toReadonly = (value) => isObject(value) ? readonly(value) : value;
  1306. function trackRefValue(ref) {
  1307. if (isTracking()) {
  1308. ref = toRaw(ref);
  1309. if (!ref.dep) {
  1310. ref.dep = createDep();
  1311. }
  1312. {
  1313. trackEffects(ref.dep, {
  1314. target: ref,
  1315. type: "get" /* GET */,
  1316. key: 'value'
  1317. });
  1318. }
  1319. }
  1320. }
  1321. function triggerRefValue(ref, newVal) {
  1322. ref = toRaw(ref);
  1323. if (ref.dep) {
  1324. {
  1325. triggerEffects(ref.dep, {
  1326. target: ref,
  1327. type: "set" /* SET */,
  1328. key: 'value',
  1329. newValue: newVal
  1330. });
  1331. }
  1332. }
  1333. }
  1334. function isRef(r) {
  1335. return Boolean(r && r.__v_isRef === true);
  1336. }
  1337. function ref(value) {
  1338. return createRef(value, false);
  1339. }
  1340. function shallowRef(value) {
  1341. return createRef(value, true);
  1342. }
  1343. function createRef(rawValue, shallow) {
  1344. if (isRef(rawValue)) {
  1345. return rawValue;
  1346. }
  1347. return new RefImpl(rawValue, shallow);
  1348. }
  1349. class RefImpl {
  1350. constructor(value, _shallow) {
  1351. this._shallow = _shallow;
  1352. this.dep = undefined;
  1353. this.__v_isRef = true;
  1354. this._rawValue = _shallow ? value : toRaw(value);
  1355. this._value = _shallow ? value : toReactive(value);
  1356. }
  1357. get value() {
  1358. trackRefValue(this);
  1359. return this._value;
  1360. }
  1361. set value(newVal) {
  1362. newVal = this._shallow ? newVal : toRaw(newVal);
  1363. if (hasChanged(newVal, this._rawValue)) {
  1364. this._rawValue = newVal;
  1365. this._value = this._shallow ? newVal : toReactive(newVal);
  1366. triggerRefValue(this, newVal);
  1367. }
  1368. }
  1369. }
  1370. function triggerRef(ref) {
  1371. triggerRefValue(ref, ref.value );
  1372. }
  1373. function unref(ref) {
  1374. return isRef(ref) ? ref.value : ref;
  1375. }
  1376. const shallowUnwrapHandlers = {
  1377. get: (target, key, receiver) => unref(Reflect.get(target, key, receiver)),
  1378. set: (target, key, value, receiver) => {
  1379. const oldValue = target[key];
  1380. if (isRef(oldValue) && !isRef(value)) {
  1381. oldValue.value = value;
  1382. return true;
  1383. }
  1384. else {
  1385. return Reflect.set(target, key, value, receiver);
  1386. }
  1387. }
  1388. };
  1389. function proxyRefs(objectWithRefs) {
  1390. return isReactive(objectWithRefs)
  1391. ? objectWithRefs
  1392. : new Proxy(objectWithRefs, shallowUnwrapHandlers);
  1393. }
  1394. class CustomRefImpl {
  1395. constructor(factory) {
  1396. this.dep = undefined;
  1397. this.__v_isRef = true;
  1398. const { get, set } = factory(() => trackRefValue(this), () => triggerRefValue(this));
  1399. this._get = get;
  1400. this._set = set;
  1401. }
  1402. get value() {
  1403. return this._get();
  1404. }
  1405. set value(newVal) {
  1406. this._set(newVal);
  1407. }
  1408. }
  1409. function customRef(factory) {
  1410. return new CustomRefImpl(factory);
  1411. }
  1412. function toRefs(object) {
  1413. if (!isProxy(object)) {
  1414. console.warn(`toRefs() expects a reactive object but received a plain one.`);
  1415. }
  1416. const ret = isArray(object) ? new Array(object.length) : {};
  1417. for (const key in object) {
  1418. ret[key] = toRef(object, key);
  1419. }
  1420. return ret;
  1421. }
  1422. class ObjectRefImpl {
  1423. constructor(_object, _key, _defaultValue) {
  1424. this._object = _object;
  1425. this._key = _key;
  1426. this._defaultValue = _defaultValue;
  1427. this.__v_isRef = true;
  1428. }
  1429. get value() {
  1430. const val = this._object[this._key];
  1431. return val === undefined ? this._defaultValue : val;
  1432. }
  1433. set value(newVal) {
  1434. this._object[this._key] = newVal;
  1435. }
  1436. }
  1437. function toRef(object, key, defaultValue) {
  1438. const val = object[key];
  1439. return isRef(val)
  1440. ? val
  1441. : new ObjectRefImpl(object, key, defaultValue);
  1442. }
  1443. class ComputedRefImpl {
  1444. constructor(getter, _setter, isReadonly) {
  1445. this._setter = _setter;
  1446. this.dep = undefined;
  1447. this._dirty = true;
  1448. this.__v_isRef = true;
  1449. this.effect = new ReactiveEffect(getter, () => {
  1450. if (!this._dirty) {
  1451. this._dirty = true;
  1452. triggerRefValue(this);
  1453. }
  1454. });
  1455. this["__v_isReadonly" /* IS_READONLY */] = isReadonly;
  1456. }
  1457. get value() {
  1458. // the computed ref may get wrapped by other proxies e.g. readonly() #3376
  1459. const self = toRaw(this);
  1460. trackRefValue(self);
  1461. if (self._dirty) {
  1462. self._dirty = false;
  1463. self._value = self.effect.run();
  1464. }
  1465. return self._value;
  1466. }
  1467. set value(newValue) {
  1468. this._setter(newValue);
  1469. }
  1470. }
  1471. function computed(getterOrOptions, debugOptions) {
  1472. let getter;
  1473. let setter;
  1474. const onlyGetter = isFunction(getterOrOptions);
  1475. if (onlyGetter) {
  1476. getter = getterOrOptions;
  1477. setter = () => {
  1478. console.warn('Write operation failed: computed value is readonly');
  1479. }
  1480. ;
  1481. }
  1482. else {
  1483. getter = getterOrOptions.get;
  1484. setter = getterOrOptions.set;
  1485. }
  1486. const cRef = new ComputedRefImpl(getter, setter, onlyGetter || !setter);
  1487. if (debugOptions) {
  1488. cRef.effect.onTrack = debugOptions.onTrack;
  1489. cRef.effect.onTrigger = debugOptions.onTrigger;
  1490. }
  1491. return cRef;
  1492. }
  1493. /* eslint-disable no-restricted-globals */
  1494. let isHmrUpdating = false;
  1495. const hmrDirtyComponents = new Set();
  1496. // Expose the HMR runtime on the global object
  1497. // This makes it entirely tree-shakable without polluting the exports and makes
  1498. // it easier to be used in toolings like vue-loader
  1499. // Note: for a component to be eligible for HMR it also needs the __hmrId option
  1500. // to be set so that its instances can be registered / removed.
  1501. {
  1502. getGlobalThis().__VUE_HMR_RUNTIME__ = {
  1503. createRecord: tryWrap(createRecord),
  1504. rerender: tryWrap(rerender),
  1505. reload: tryWrap(reload)
  1506. };
  1507. }
  1508. const map = new Map();
  1509. function registerHMR(instance) {
  1510. const id = instance.type.__hmrId;
  1511. let record = map.get(id);
  1512. if (!record) {
  1513. createRecord(id, instance.type);
  1514. record = map.get(id);
  1515. }
  1516. record.instances.add(instance);
  1517. }
  1518. function unregisterHMR(instance) {
  1519. map.get(instance.type.__hmrId).instances.delete(instance);
  1520. }
  1521. function createRecord(id, initialDef) {
  1522. if (map.has(id)) {
  1523. return false;
  1524. }
  1525. map.set(id, {
  1526. initialDef: normalizeClassComponent(initialDef),
  1527. instances: new Set()
  1528. });
  1529. return true;
  1530. }
  1531. function normalizeClassComponent(component) {
  1532. return isClassComponent(component) ? component.__vccOpts : component;
  1533. }
  1534. function rerender(id, newRender) {
  1535. const record = map.get(id);
  1536. if (!record) {
  1537. return;
  1538. }
  1539. // update initial record (for not-yet-rendered component)
  1540. record.initialDef.render = newRender;
  1541. [...record.instances].forEach(instance => {
  1542. if (newRender) {
  1543. instance.render = newRender;
  1544. normalizeClassComponent(instance.type).render = newRender;
  1545. }
  1546. instance.renderCache = [];
  1547. // this flag forces child components with slot content to update
  1548. isHmrUpdating = true;
  1549. instance.update();
  1550. isHmrUpdating = false;
  1551. });
  1552. }
  1553. function reload(id, newComp) {
  1554. const record = map.get(id);
  1555. if (!record)
  1556. return;
  1557. newComp = normalizeClassComponent(newComp);
  1558. // update initial def (for not-yet-rendered components)
  1559. updateComponentDef(record.initialDef, newComp);
  1560. // create a snapshot which avoids the set being mutated during updates
  1561. const instances = [...record.instances];
  1562. for (const instance of instances) {
  1563. const oldComp = normalizeClassComponent(instance.type);
  1564. if (!hmrDirtyComponents.has(oldComp)) {
  1565. // 1. Update existing comp definition to match new one
  1566. if (oldComp !== record.initialDef) {
  1567. updateComponentDef(oldComp, newComp);
  1568. }
  1569. // 2. mark definition dirty. This forces the renderer to replace the
  1570. // component on patch.
  1571. hmrDirtyComponents.add(oldComp);
  1572. }
  1573. // 3. invalidate options resolution cache
  1574. instance.appContext.optionsCache.delete(instance.type);
  1575. // 4. actually update
  1576. if (instance.ceReload) {
  1577. // custom element
  1578. hmrDirtyComponents.add(oldComp);
  1579. instance.ceReload(newComp.styles);
  1580. hmrDirtyComponents.delete(oldComp);
  1581. }
  1582. else if (instance.parent) {
  1583. // 4. Force the parent instance to re-render. This will cause all updated
  1584. // components to be unmounted and re-mounted. Queue the update so that we
  1585. // don't end up forcing the same parent to re-render multiple times.
  1586. queueJob(instance.parent.update);
  1587. // instance is the inner component of an async custom element
  1588. // invoke to reset styles
  1589. if (instance.parent.type.__asyncLoader &&
  1590. instance.parent.ceReload) {
  1591. instance.parent.ceReload(newComp.styles);
  1592. }
  1593. }
  1594. else if (instance.appContext.reload) {
  1595. // root instance mounted via createApp() has a reload method
  1596. instance.appContext.reload();
  1597. }
  1598. else if (typeof window !== 'undefined') {
  1599. // root instance inside tree created via raw render(). Force reload.
  1600. window.location.reload();
  1601. }
  1602. else {
  1603. console.warn('[HMR] Root or manually mounted instance modified. Full reload required.');
  1604. }
  1605. }
  1606. // 5. make sure to cleanup dirty hmr components after update
  1607. queuePostFlushCb(() => {
  1608. for (const instance of instances) {
  1609. hmrDirtyComponents.delete(normalizeClassComponent(instance.type));
  1610. }
  1611. });
  1612. }
  1613. function updateComponentDef(oldComp, newComp) {
  1614. extend(oldComp, newComp);
  1615. for (const key in oldComp) {
  1616. if (key !== '__file' && !(key in newComp)) {
  1617. delete oldComp[key];
  1618. }
  1619. }
  1620. }
  1621. function tryWrap(fn) {
  1622. return (id, arg) => {
  1623. try {
  1624. return fn(id, arg);
  1625. }
  1626. catch (e) {
  1627. console.error(e);
  1628. console.warn(`[HMR] Something went wrong during Vue component hot-reload. ` +
  1629. `Full reload required.`);
  1630. }
  1631. };
  1632. }
  1633. let buffer = [];
  1634. let devtoolsNotInstalled = false;
  1635. function emit(event, ...args) {
  1636. if (exports.devtools) {
  1637. exports.devtools.emit(event, ...args);
  1638. }
  1639. else if (!devtoolsNotInstalled) {
  1640. buffer.push({ event, args });
  1641. }
  1642. }
  1643. function setDevtoolsHook(hook, target) {
  1644. var _a, _b;
  1645. exports.devtools = hook;
  1646. if (exports.devtools) {
  1647. exports.devtools.enabled = true;
  1648. buffer.forEach(({ event, args }) => exports.devtools.emit(event, ...args));
  1649. buffer = [];
  1650. }
  1651. else if (
  1652. // handle late devtools injection - only do this if we are in an actual
  1653. // browser environment to avoid the timer handle stalling test runner exit
  1654. // (#4815)
  1655. // eslint-disable-next-line no-restricted-globals
  1656. typeof window !== 'undefined' &&
  1657. // some envs mock window but not fully
  1658. window.HTMLElement &&
  1659. // also exclude jsdom
  1660. !((_b = (_a = window.navigator) === null || _a === void 0 ? void 0 : _a.userAgent) === null || _b === void 0 ? void 0 : _b.includes('jsdom'))) {
  1661. const replay = (target.__VUE_DEVTOOLS_HOOK_REPLAY__ =
  1662. target.__VUE_DEVTOOLS_HOOK_REPLAY__ || []);
  1663. replay.push((newHook) => {
  1664. setDevtoolsHook(newHook, target);
  1665. });
  1666. // clear buffer after 3s - the user probably doesn't have devtools installed
  1667. // at all, and keeping the buffer will cause memory leaks (#4738)
  1668. setTimeout(() => {
  1669. if (!exports.devtools) {
  1670. target.__VUE_DEVTOOLS_HOOK_REPLAY__ = null;
  1671. devtoolsNotInstalled = true;
  1672. buffer = [];
  1673. }
  1674. }, 3000);
  1675. }
  1676. else {
  1677. // non-browser env, assume not installed
  1678. devtoolsNotInstalled = true;
  1679. buffer = [];
  1680. }
  1681. }
  1682. function devtoolsInitApp(app, version) {
  1683. emit("app:init" /* APP_INIT */, app, version, {
  1684. Fragment,
  1685. Text,
  1686. Comment,
  1687. Static
  1688. });
  1689. }
  1690. function devtoolsUnmountApp(app) {
  1691. emit("app:unmount" /* APP_UNMOUNT */, app);
  1692. }
  1693. const devtoolsComponentAdded = /*#__PURE__*/ createDevtoolsComponentHook("component:added" /* COMPONENT_ADDED */);
  1694. const devtoolsComponentUpdated =
  1695. /*#__PURE__*/ createDevtoolsComponentHook("component:updated" /* COMPONENT_UPDATED */);
  1696. const devtoolsComponentRemoved =
  1697. /*#__PURE__*/ createDevtoolsComponentHook("component:removed" /* COMPONENT_REMOVED */);
  1698. function createDevtoolsComponentHook(hook) {
  1699. return (component) => {
  1700. emit(hook, component.appContext.app, component.uid, component.parent ? component.parent.uid : undefined, component);
  1701. };
  1702. }
  1703. const devtoolsPerfStart = /*#__PURE__*/ createDevtoolsPerformanceHook("perf:start" /* PERFORMANCE_START */);
  1704. const devtoolsPerfEnd = /*#__PURE__*/ createDevtoolsPerformanceHook("perf:end" /* PERFORMANCE_END */);
  1705. function createDevtoolsPerformanceHook(hook) {
  1706. return (component, type, time) => {
  1707. emit(hook, component.appContext.app, component.uid, component, type, time);
  1708. };
  1709. }
  1710. function devtoolsComponentEmit(component, event, params) {
  1711. emit("component:emit" /* COMPONENT_EMIT */, component.appContext.app, component, event, params);
  1712. }
  1713. function emit$1(instance, event, ...rawArgs) {
  1714. const props = instance.vnode.props || EMPTY_OBJ;
  1715. {
  1716. const { emitsOptions, propsOptions: [propsOptions] } = instance;
  1717. if (emitsOptions) {
  1718. if (!(event in emitsOptions) &&
  1719. !(false )) {
  1720. if (!propsOptions || !(toHandlerKey(event) in propsOptions)) {
  1721. warn$1(`Component emitted event "${event}" but it is neither declared in ` +
  1722. `the emits option nor as an "${toHandlerKey(event)}" prop.`);
  1723. }
  1724. }
  1725. else {
  1726. const validator = emitsOptions[event];
  1727. if (isFunction(validator)) {
  1728. const isValid = validator(...rawArgs);
  1729. if (!isValid) {
  1730. warn$1(`Invalid event arguments: event validation failed for event "${event}".`);
  1731. }
  1732. }
  1733. }
  1734. }
  1735. }
  1736. let args = rawArgs;
  1737. const isModelListener = event.startsWith('update:');
  1738. // for v-model update:xxx events, apply modifiers on args
  1739. const modelArg = isModelListener && event.slice(7);
  1740. if (modelArg && modelArg in props) {
  1741. const modifiersKey = `${modelArg === 'modelValue' ? 'model' : modelArg}Modifiers`;
  1742. const { number, trim } = props[modifiersKey] || EMPTY_OBJ;
  1743. if (trim) {
  1744. args = rawArgs.map(a => a.trim());
  1745. }
  1746. else if (number) {
  1747. args = rawArgs.map(toNumber);
  1748. }
  1749. }
  1750. {
  1751. devtoolsComponentEmit(instance, event, args);
  1752. }
  1753. {
  1754. const lowerCaseEvent = event.toLowerCase();
  1755. if (lowerCaseEvent !== event && props[toHandlerKey(lowerCaseEvent)]) {
  1756. warn$1(`Event "${lowerCaseEvent}" is emitted in component ` +
  1757. `${formatComponentName(instance, instance.type)} but the handler is registered for "${event}". ` +
  1758. `Note that HTML attributes are case-insensitive and you cannot use ` +
  1759. `v-on to listen to camelCase events when using in-DOM templates. ` +
  1760. `You should probably use "${hyphenate(event)}" instead of "${event}".`);
  1761. }
  1762. }
  1763. let handlerName;
  1764. let handler = props[(handlerName = toHandlerKey(event))] ||
  1765. // also try camelCase event handler (#2249)
  1766. props[(handlerName = toHandlerKey(camelize(event)))];
  1767. // for v-model update:xxx events, also trigger kebab-case equivalent
  1768. // for props passed via kebab-case
  1769. if (!handler && isModelListener) {
  1770. handler = props[(handlerName = toHandlerKey(hyphenate(event)))];
  1771. }
  1772. if (handler) {
  1773. callWithAsyncErrorHandling(handler, instance, 6 /* COMPONENT_EVENT_HANDLER */, args);
  1774. }
  1775. const onceHandler = props[handlerName + `Once`];
  1776. if (onceHandler) {
  1777. if (!instance.emitted) {
  1778. instance.emitted = {};
  1779. }
  1780. else if (instance.emitted[handlerName]) {
  1781. return;
  1782. }
  1783. instance.emitted[handlerName] = true;
  1784. callWithAsyncErrorHandling(onceHandler, instance, 6 /* COMPONENT_EVENT_HANDLER */, args);
  1785. }
  1786. }
  1787. function normalizeEmitsOptions(comp, appContext, asMixin = false) {
  1788. const cache = appContext.emitsCache;
  1789. const cached = cache.get(comp);
  1790. if (cached !== undefined) {
  1791. return cached;
  1792. }
  1793. const raw = comp.emits;
  1794. let normalized = {};
  1795. // apply mixin/extends props
  1796. let hasExtends = false;
  1797. if (!isFunction(comp)) {
  1798. const extendEmits = (raw) => {
  1799. const normalizedFromExtend = normalizeEmitsOptions(raw, appContext, true);
  1800. if (normalizedFromExtend) {
  1801. hasExtends = true;
  1802. extend(normalized, normalizedFromExtend);
  1803. }
  1804. };
  1805. if (!asMixin && appContext.mixins.length) {
  1806. appContext.mixins.forEach(extendEmits);
  1807. }
  1808. if (comp.extends) {
  1809. extendEmits(comp.extends);
  1810. }
  1811. if (comp.mixins) {
  1812. comp.mixins.forEach(extendEmits);
  1813. }
  1814. }
  1815. if (!raw && !hasExtends) {
  1816. cache.set(comp, null);
  1817. return null;
  1818. }
  1819. if (isArray(raw)) {
  1820. raw.forEach(key => (normalized[key] = null));
  1821. }
  1822. else {
  1823. extend(normalized, raw);
  1824. }
  1825. cache.set(comp, normalized);
  1826. return normalized;
  1827. }
  1828. // Check if an incoming prop key is a declared emit event listener.
  1829. // e.g. With `emits: { click: null }`, props named `onClick` and `onclick` are
  1830. // both considered matched listeners.
  1831. function isEmitListener(options, key) {
  1832. if (!options || !isOn(key)) {
  1833. return false;
  1834. }
  1835. key = key.slice(2).replace(/Once$/, '');
  1836. return (hasOwn(options, key[0].toLowerCase() + key.slice(1)) ||
  1837. hasOwn(options, hyphenate(key)) ||
  1838. hasOwn(options, key));
  1839. }
  1840. /**
  1841. * mark the current rendering instance for asset resolution (e.g.
  1842. * resolveComponent, resolveDirective) during render
  1843. */
  1844. let currentRenderingInstance = null;
  1845. let currentScopeId = null;
  1846. /**
  1847. * Note: rendering calls maybe nested. The function returns the parent rendering
  1848. * instance if present, which should be restored after the render is done:
  1849. *
  1850. * ```js
  1851. * const prev = setCurrentRenderingInstance(i)
  1852. * // ...render
  1853. * setCurrentRenderingInstance(prev)
  1854. * ```
  1855. */
  1856. function setCurrentRenderingInstance(instance) {
  1857. const prev = currentRenderingInstance;
  1858. currentRenderingInstance = instance;
  1859. currentScopeId = (instance && instance.type.__scopeId) || null;
  1860. return prev;
  1861. }
  1862. /**
  1863. * Set scope id when creating hoisted vnodes.
  1864. * @private compiler helper
  1865. */
  1866. function pushScopeId(id) {
  1867. currentScopeId = id;
  1868. }
  1869. /**
  1870. * Technically we no longer need this after 3.0.8 but we need to keep the same
  1871. * API for backwards compat w/ code generated by compilers.
  1872. * @private
  1873. */
  1874. function popScopeId() {
  1875. currentScopeId = null;
  1876. }
  1877. /**
  1878. * Only for backwards compat
  1879. * @private
  1880. */
  1881. const withScopeId = (_id) => withCtx;
  1882. /**
  1883. * Wrap a slot function to memoize current rendering instance
  1884. * @private compiler helper
  1885. */
  1886. function withCtx(fn, ctx = currentRenderingInstance, isNonScopedSlot // false only
  1887. ) {
  1888. if (!ctx)
  1889. return fn;
  1890. // already normalized
  1891. if (fn._n) {
  1892. return fn;
  1893. }
  1894. const renderFnWithContext = (...args) => {
  1895. // If a user calls a compiled slot inside a template expression (#1745), it
  1896. // can mess up block tracking, so by default we disable block tracking and
  1897. // force bail out when invoking a compiled slot (indicated by the ._d flag).
  1898. // This isn't necessary if rendering a compiled `<slot>`, so we flip the
  1899. // ._d flag off when invoking the wrapped fn inside `renderSlot`.
  1900. if (renderFnWithContext._d) {
  1901. setBlockTracking(-1);
  1902. }
  1903. const prevInstance = setCurrentRenderingInstance(ctx);
  1904. const res = fn(...args);
  1905. setCurrentRenderingInstance(prevInstance);
  1906. if (renderFnWithContext._d) {
  1907. setBlockTracking(1);
  1908. }
  1909. {
  1910. devtoolsComponentUpdated(ctx);
  1911. }
  1912. return res;
  1913. };
  1914. // mark normalized to avoid duplicated wrapping
  1915. renderFnWithContext._n = true;
  1916. // mark this as compiled by default
  1917. // this is used in vnode.ts -> normalizeChildren() to set the slot
  1918. // rendering flag.
  1919. renderFnWithContext._c = true;
  1920. // disable block tracking by default
  1921. renderFnWithContext._d = true;
  1922. return renderFnWithContext;
  1923. }
  1924. /**
  1925. * dev only flag to track whether $attrs was used during render.
  1926. * If $attrs was used during render then the warning for failed attrs
  1927. * fallthrough can be suppressed.
  1928. */
  1929. let accessedAttrs = false;
  1930. function markAttrsAccessed() {
  1931. accessedAttrs = true;
  1932. }
  1933. function renderComponentRoot(instance) {
  1934. const { type: Component, vnode, proxy, withProxy, props, propsOptions: [propsOptions], slots, attrs, emit, render, renderCache, data, setupState, ctx, inheritAttrs } = instance;
  1935. let result;
  1936. let fallthroughAttrs;
  1937. const prev = setCurrentRenderingInstance(instance);
  1938. {
  1939. accessedAttrs = false;
  1940. }
  1941. try {
  1942. if (vnode.shapeFlag & 4 /* STATEFUL_COMPONENT */) {
  1943. // withProxy is a proxy with a different `has` trap only for
  1944. // runtime-compiled render functions using `with` block.
  1945. const proxyToUse = withProxy || proxy;
  1946. result = normalizeVNode(render.call(proxyToUse, proxyToUse, renderCache, props, setupState, data, ctx));
  1947. fallthroughAttrs = attrs;
  1948. }
  1949. else {
  1950. // functional
  1951. const render = Component;
  1952. // in dev, mark attrs accessed if optional props (attrs === props)
  1953. if (true && attrs === props) {
  1954. markAttrsAccessed();
  1955. }
  1956. result = normalizeVNode(render.length > 1
  1957. ? render(props, true
  1958. ? {
  1959. get attrs() {
  1960. markAttrsAccessed();
  1961. return attrs;
  1962. },
  1963. slots,
  1964. emit
  1965. }
  1966. : { attrs, slots, emit })
  1967. : render(props, null /* we know it doesn't need it */));
  1968. fallthroughAttrs = Component.props
  1969. ? attrs
  1970. : getFunctionalFallthrough(attrs);
  1971. }
  1972. }
  1973. catch (err) {
  1974. blockStack.length = 0;
  1975. handleError(err, instance, 1 /* RENDER_FUNCTION */);
  1976. result = createVNode(Comment);
  1977. }
  1978. // attr merging
  1979. // in dev mode, comments are preserved, and it's possible for a template
  1980. // to have comments along side the root element which makes it a fragment
  1981. let root = result;
  1982. let setRoot = undefined;
  1983. if (result.patchFlag > 0 &&
  1984. result.patchFlag & 2048 /* DEV_ROOT_FRAGMENT */) {
  1985. [root, setRoot] = getChildRoot(result);
  1986. }
  1987. if (fallthroughAttrs && inheritAttrs !== false) {
  1988. const keys = Object.keys(fallthroughAttrs);
  1989. const { shapeFlag } = root;
  1990. if (keys.length) {
  1991. if (shapeFlag & (1 /* ELEMENT */ | 6 /* COMPONENT */)) {
  1992. if (propsOptions && keys.some(isModelListener)) {
  1993. // If a v-model listener (onUpdate:xxx) has a corresponding declared
  1994. // prop, it indicates this component expects to handle v-model and
  1995. // it should not fallthrough.
  1996. // related: #1543, #1643, #1989
  1997. fallthroughAttrs = filterModelListeners(fallthroughAttrs, propsOptions);
  1998. }
  1999. root = cloneVNode(root, fallthroughAttrs);
  2000. }
  2001. else if (!accessedAttrs && root.type !== Comment) {
  2002. const allAttrs = Object.keys(attrs);
  2003. const eventAttrs = [];
  2004. const extraAttrs = [];
  2005. for (let i = 0, l = allAttrs.length; i < l; i++) {
  2006. const key = allAttrs[i];
  2007. if (isOn(key)) {
  2008. // ignore v-model handlers when they fail to fallthrough
  2009. if (!isModelListener(key)) {
  2010. // remove `on`, lowercase first letter to reflect event casing
  2011. // accurately
  2012. eventAttrs.push(key[2].toLowerCase() + key.slice(3));
  2013. }
  2014. }
  2015. else {
  2016. extraAttrs.push(key);
  2017. }
  2018. }
  2019. if (extraAttrs.length) {
  2020. warn$1(`Extraneous non-props attributes (` +
  2021. `${extraAttrs.join(', ')}) ` +
  2022. `were passed to component but could not be automatically inherited ` +
  2023. `because component renders fragment or text root nodes.`);
  2024. }
  2025. if (eventAttrs.length) {
  2026. warn$1(`Extraneous non-emits event listeners (` +
  2027. `${eventAttrs.join(', ')}) ` +
  2028. `were passed to component but could not be automatically inherited ` +
  2029. `because component renders fragment or text root nodes. ` +
  2030. `If the listener is intended to be a component custom event listener only, ` +
  2031. `declare it using the "emits" option.`);
  2032. }
  2033. }
  2034. }
  2035. }
  2036. // inherit directives
  2037. if (vnode.dirs) {
  2038. if (!isElementRoot(root)) {
  2039. warn$1(`Runtime directive used on component with non-element root node. ` +
  2040. `The directives will not function as intended.`);
  2041. }
  2042. root.dirs = root.dirs ? root.dirs.concat(vnode.dirs) : vnode.dirs;
  2043. }
  2044. // inherit transition data
  2045. if (vnode.transition) {
  2046. if (!isElementRoot(root)) {
  2047. warn$1(`Component inside <Transition> renders non-element root node ` +
  2048. `that cannot be animated.`);
  2049. }
  2050. root.transition = vnode.transition;
  2051. }
  2052. if (setRoot) {
  2053. setRoot(root);
  2054. }
  2055. else {
  2056. result = root;
  2057. }
  2058. setCurrentRenderingInstance(prev);
  2059. return result;
  2060. }
  2061. /**
  2062. * dev only
  2063. * In dev mode, template root level comments are rendered, which turns the
  2064. * template into a fragment root, but we need to locate the single element
  2065. * root for attrs and scope id processing.
  2066. */
  2067. const getChildRoot = (vnode) => {
  2068. const rawChildren = vnode.children;
  2069. const dynamicChildren = vnode.dynamicChildren;
  2070. const childRoot = filterSingleRoot(rawChildren);
  2071. if (!childRoot) {
  2072. return [vnode, undefined];
  2073. }
  2074. const index = rawChildren.indexOf(childRoot);
  2075. const dynamicIndex = dynamicChildren ? dynamicChildren.indexOf(childRoot) : -1;
  2076. const setRoot = (updatedRoot) => {
  2077. rawChildren[index] = updatedRoot;
  2078. if (dynamicChildren) {
  2079. if (dynamicIndex > -1) {
  2080. dynamicChildren[dynamicIndex] = updatedRoot;
  2081. }
  2082. else if (updatedRoot.patchFlag > 0) {
  2083. vnode.dynamicChildren = [...dynamicChildren, updatedRoot];
  2084. }
  2085. }
  2086. };
  2087. return [normalizeVNode(childRoot), setRoot];
  2088. };
  2089. function filterSingleRoot(children) {
  2090. let singleRoot;
  2091. for (let i = 0; i < children.length; i++) {
  2092. const child = children[i];
  2093. if (isVNode(child)) {
  2094. // ignore user comment
  2095. if (child.type !== Comment || child.children === 'v-if') {
  2096. if (singleRoot) {
  2097. // has more than 1 non-comment child, return now
  2098. return;
  2099. }
  2100. else {
  2101. singleRoot = child;
  2102. }
  2103. }
  2104. }
  2105. else {
  2106. return;
  2107. }
  2108. }
  2109. return singleRoot;
  2110. }
  2111. const getFunctionalFallthrough = (attrs) => {
  2112. let res;
  2113. for (const key in attrs) {
  2114. if (key === 'class' || key === 'style' || isOn(key)) {
  2115. (res || (res = {}))[key] = attrs[key];
  2116. }
  2117. }
  2118. return res;
  2119. };
  2120. const filterModelListeners = (attrs, props) => {
  2121. const res = {};
  2122. for (const key in attrs) {
  2123. if (!isModelListener(key) || !(key.slice(9) in props)) {
  2124. res[key] = attrs[key];
  2125. }
  2126. }
  2127. return res;
  2128. };
  2129. const isElementRoot = (vnode) => {
  2130. return (vnode.shapeFlag & (6 /* COMPONENT */ | 1 /* ELEMENT */) ||
  2131. vnode.type === Comment // potential v-if branch switch
  2132. );
  2133. };
  2134. function shouldUpdateComponent(prevVNode, nextVNode, optimized) {
  2135. const { props: prevProps, children: prevChildren, component } = prevVNode;
  2136. const { props: nextProps, children: nextChildren, patchFlag } = nextVNode;
  2137. const emits = component.emitsOptions;
  2138. // Parent component's render function was hot-updated. Since this may have
  2139. // caused the child component's slots content to have changed, we need to
  2140. // force the child to update as well.
  2141. if ((prevChildren || nextChildren) && isHmrUpdating) {
  2142. return true;
  2143. }
  2144. // force child update for runtime directive or transition on component vnode.
  2145. if (nextVNode.dirs || nextVNode.transition) {
  2146. return true;
  2147. }
  2148. if (optimized && patchFlag >= 0) {
  2149. if (patchFlag & 1024 /* DYNAMIC_SLOTS */) {
  2150. // slot content that references values that might have changed,
  2151. // e.g. in a v-for
  2152. return true;
  2153. }
  2154. if (patchFlag & 16 /* FULL_PROPS */) {
  2155. if (!prevProps) {
  2156. return !!nextProps;
  2157. }
  2158. // presence of this flag indicates props are always non-null
  2159. return hasPropsChanged(prevProps, nextProps, emits);
  2160. }
  2161. else if (patchFlag & 8 /* PROPS */) {
  2162. const dynamicProps = nextVNode.dynamicProps;
  2163. for (let i = 0; i < dynamicProps.length; i++) {
  2164. const key = dynamicProps[i];
  2165. if (nextProps[key] !== prevProps[key] &&
  2166. !isEmitListener(emits, key)) {
  2167. return true;
  2168. }
  2169. }
  2170. }
  2171. }
  2172. else {
  2173. // this path is only taken by manually written render functions
  2174. // so presence of any children leads to a forced update
  2175. if (prevChildren || nextChildren) {
  2176. if (!nextChildren || !nextChildren.$stable) {
  2177. return true;
  2178. }
  2179. }
  2180. if (prevProps === nextProps) {
  2181. return false;
  2182. }
  2183. if (!prevProps) {
  2184. return !!nextProps;
  2185. }
  2186. if (!nextProps) {
  2187. return true;
  2188. }
  2189. return hasPropsChanged(prevProps, nextProps, emits);
  2190. }
  2191. return false;
  2192. }
  2193. function hasPropsChanged(prevProps, nextProps, emitsOptions) {
  2194. const nextKeys = Object.keys(nextProps);
  2195. if (nextKeys.length !== Object.keys(prevProps).length) {
  2196. return true;
  2197. }
  2198. for (let i = 0; i < nextKeys.length; i++) {
  2199. const key = nextKeys[i];
  2200. if (nextProps[key] !== prevProps[key] &&
  2201. !isEmitListener(emitsOptions, key)) {
  2202. return true;
  2203. }
  2204. }
  2205. return false;
  2206. }
  2207. function updateHOCHostEl({ vnode, parent }, el // HostNode
  2208. ) {
  2209. while (parent && parent.subTree === vnode) {
  2210. (vnode = parent.vnode).el = el;
  2211. parent = parent.parent;
  2212. }
  2213. }
  2214. const isSuspense = (type) => type.__isSuspense;
  2215. // Suspense exposes a component-like API, and is treated like a component
  2216. // in the compiler, but internally it's a special built-in type that hooks
  2217. // directly into the renderer.
  2218. const SuspenseImpl = {
  2219. name: 'Suspense',
  2220. // In order to make Suspense tree-shakable, we need to avoid importing it
  2221. // directly in the renderer. The renderer checks for the __isSuspense flag
  2222. // on a vnode's type and calls the `process` method, passing in renderer
  2223. // internals.
  2224. __isSuspense: true,
  2225. process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized,
  2226. // platform-specific impl passed from renderer
  2227. rendererInternals) {
  2228. if (n1 == null) {
  2229. mountSuspense(n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, rendererInternals);
  2230. }
  2231. else {
  2232. patchSuspense(n1, n2, container, anchor, parentComponent, isSVG, slotScopeIds, optimized, rendererInternals);
  2233. }
  2234. },
  2235. hydrate: hydrateSuspense,
  2236. create: createSuspenseBoundary,
  2237. normalize: normalizeSuspenseChildren
  2238. };
  2239. // Force-casted public typing for h and TSX props inference
  2240. const Suspense = (SuspenseImpl );
  2241. function triggerEvent(vnode, name) {
  2242. const eventListener = vnode.props && vnode.props[name];
  2243. if (isFunction(eventListener)) {
  2244. eventListener();
  2245. }
  2246. }
  2247. function mountSuspense(vnode, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, rendererInternals) {
  2248. const { p: patch, o: { createElement } } = rendererInternals;
  2249. const hiddenContainer = createElement('div');
  2250. const suspense = (vnode.suspense = createSuspenseBoundary(vnode, parentSuspense, parentComponent, container, hiddenContainer, anchor, isSVG, slotScopeIds, optimized, rendererInternals));
  2251. // start mounting the content subtree in an off-dom container
  2252. patch(null, (suspense.pendingBranch = vnode.ssContent), hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds);
  2253. // now check if we have encountered any async deps
  2254. if (suspense.deps > 0) {
  2255. // has async
  2256. // invoke @fallback event
  2257. triggerEvent(vnode, 'onPending');
  2258. triggerEvent(vnode, 'onFallback');
  2259. // mount the fallback tree
  2260. patch(null, vnode.ssFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2261. isSVG, slotScopeIds);
  2262. setActiveBranch(suspense, vnode.ssFallback);
  2263. }
  2264. else {
  2265. // Suspense has no async deps. Just resolve.
  2266. suspense.resolve();
  2267. }
  2268. }
  2269. function patchSuspense(n1, n2, container, anchor, parentComponent, isSVG, slotScopeIds, optimized, { p: patch, um: unmount, o: { createElement } }) {
  2270. const suspense = (n2.suspense = n1.suspense);
  2271. suspense.vnode = n2;
  2272. n2.el = n1.el;
  2273. const newBranch = n2.ssContent;
  2274. const newFallback = n2.ssFallback;
  2275. const { activeBranch, pendingBranch, isInFallback, isHydrating } = suspense;
  2276. if (pendingBranch) {
  2277. suspense.pendingBranch = newBranch;
  2278. if (isSameVNodeType(newBranch, pendingBranch)) {
  2279. // same root type but content may have changed.
  2280. patch(pendingBranch, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2281. if (suspense.deps <= 0) {
  2282. suspense.resolve();
  2283. }
  2284. else if (isInFallback) {
  2285. patch(activeBranch, newFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2286. isSVG, slotScopeIds, optimized);
  2287. setActiveBranch(suspense, newFallback);
  2288. }
  2289. }
  2290. else {
  2291. // toggled before pending tree is resolved
  2292. suspense.pendingId++;
  2293. if (isHydrating) {
  2294. // if toggled before hydration is finished, the current DOM tree is
  2295. // no longer valid. set it as the active branch so it will be unmounted
  2296. // when resolved
  2297. suspense.isHydrating = false;
  2298. suspense.activeBranch = pendingBranch;
  2299. }
  2300. else {
  2301. unmount(pendingBranch, parentComponent, suspense);
  2302. }
  2303. // increment pending ID. this is used to invalidate async callbacks
  2304. // reset suspense state
  2305. suspense.deps = 0;
  2306. // discard effects from pending branch
  2307. suspense.effects.length = 0;
  2308. // discard previous container
  2309. suspense.hiddenContainer = createElement('div');
  2310. if (isInFallback) {
  2311. // already in fallback state
  2312. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2313. if (suspense.deps <= 0) {
  2314. suspense.resolve();
  2315. }
  2316. else {
  2317. patch(activeBranch, newFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2318. isSVG, slotScopeIds, optimized);
  2319. setActiveBranch(suspense, newFallback);
  2320. }
  2321. }
  2322. else if (activeBranch && isSameVNodeType(newBranch, activeBranch)) {
  2323. // toggled "back" to current active branch
  2324. patch(activeBranch, newBranch, container, anchor, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2325. // force resolve
  2326. suspense.resolve(true);
  2327. }
  2328. else {
  2329. // switched to a 3rd branch
  2330. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2331. if (suspense.deps <= 0) {
  2332. suspense.resolve();
  2333. }
  2334. }
  2335. }
  2336. }
  2337. else {
  2338. if (activeBranch && isSameVNodeType(newBranch, activeBranch)) {
  2339. // root did not change, just normal patch
  2340. patch(activeBranch, newBranch, container, anchor, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2341. setActiveBranch(suspense, newBranch);
  2342. }
  2343. else {
  2344. // root node toggled
  2345. // invoke @pending event
  2346. triggerEvent(n2, 'onPending');
  2347. // mount pending branch in off-dom container
  2348. suspense.pendingBranch = newBranch;
  2349. suspense.pendingId++;
  2350. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2351. if (suspense.deps <= 0) {
  2352. // incoming branch has no async deps, resolve now.
  2353. suspense.resolve();
  2354. }
  2355. else {
  2356. const { timeout, pendingId } = suspense;
  2357. if (timeout > 0) {
  2358. setTimeout(() => {
  2359. if (suspense.pendingId === pendingId) {
  2360. suspense.fallback(newFallback);
  2361. }
  2362. }, timeout);
  2363. }
  2364. else if (timeout === 0) {
  2365. suspense.fallback(newFallback);
  2366. }
  2367. }
  2368. }
  2369. }
  2370. }
  2371. let hasWarned = false;
  2372. function createSuspenseBoundary(vnode, parent, parentComponent, container, hiddenContainer, anchor, isSVG, slotScopeIds, optimized, rendererInternals, isHydrating = false) {
  2373. /* istanbul ignore if */
  2374. if (!hasWarned) {
  2375. hasWarned = true;
  2376. // @ts-ignore `console.info` cannot be null error
  2377. console[console.info ? 'info' : 'log'](`<Suspense> is an experimental feature and its API will likely change.`);
  2378. }
  2379. const { p: patch, m: move, um: unmount, n: next, o: { parentNode, remove } } = rendererInternals;
  2380. const timeout = toNumber(vnode.props && vnode.props.timeout);
  2381. const suspense = {
  2382. vnode,
  2383. parent,
  2384. parentComponent,
  2385. isSVG,
  2386. container,
  2387. hiddenContainer,
  2388. anchor,
  2389. deps: 0,
  2390. pendingId: 0,
  2391. timeout: typeof timeout === 'number' ? timeout : -1,
  2392. activeBranch: null,
  2393. pendingBranch: null,
  2394. isInFallback: true,
  2395. isHydrating,
  2396. isUnmounted: false,
  2397. effects: [],
  2398. resolve(resume = false) {
  2399. {
  2400. if (!resume && !suspense.pendingBranch) {
  2401. throw new Error(`suspense.resolve() is called without a pending branch.`);
  2402. }
  2403. if (suspense.isUnmounted) {
  2404. throw new Error(`suspense.resolve() is called on an already unmounted suspense boundary.`);
  2405. }
  2406. }
  2407. const { vnode, activeBranch, pendingBranch, pendingId, effects, parentComponent, container } = suspense;
  2408. if (suspense.isHydrating) {
  2409. suspense.isHydrating = false;
  2410. }
  2411. else if (!resume) {
  2412. const delayEnter = activeBranch &&
  2413. pendingBranch.transition &&
  2414. pendingBranch.transition.mode === 'out-in';
  2415. if (delayEnter) {
  2416. activeBranch.transition.afterLeave = () => {
  2417. if (pendingId === suspense.pendingId) {
  2418. move(pendingBranch, container, anchor, 0 /* ENTER */);
  2419. }
  2420. };
  2421. }
  2422. // this is initial anchor on mount
  2423. let { anchor } = suspense;
  2424. // unmount current active tree
  2425. if (activeBranch) {
  2426. // if the fallback tree was mounted, it may have been moved
  2427. // as part of a parent suspense. get the latest anchor for insertion
  2428. anchor = next(activeBranch);
  2429. unmount(activeBranch, parentComponent, suspense, true);
  2430. }
  2431. if (!delayEnter) {
  2432. // move content from off-dom container to actual container
  2433. move(pendingBranch, container, anchor, 0 /* ENTER */);
  2434. }
  2435. }
  2436. setActiveBranch(suspense, pendingBranch);
  2437. suspense.pendingBranch = null;
  2438. suspense.isInFallback = false;
  2439. // flush buffered effects
  2440. // check if there is a pending parent suspense
  2441. let parent = suspense.parent;
  2442. let hasUnresolvedAncestor = false;
  2443. while (parent) {
  2444. if (parent.pendingBranch) {
  2445. // found a pending parent suspense, merge buffered post jobs
  2446. // into that parent
  2447. parent.effects.push(...effects);
  2448. hasUnresolvedAncestor = true;
  2449. break;
  2450. }
  2451. parent = parent.parent;
  2452. }
  2453. // no pending parent suspense, flush all jobs
  2454. if (!hasUnresolvedAncestor) {
  2455. queuePostFlushCb(effects);
  2456. }
  2457. suspense.effects = [];
  2458. // invoke @resolve event
  2459. triggerEvent(vnode, 'onResolve');
  2460. },
  2461. fallback(fallbackVNode) {
  2462. if (!suspense.pendingBranch) {
  2463. return;
  2464. }
  2465. const { vnode, activeBranch, parentComponent, container, isSVG } = suspense;
  2466. // invoke @fallback event
  2467. triggerEvent(vnode, 'onFallback');
  2468. const anchor = next(activeBranch);
  2469. const mountFallback = () => {
  2470. if (!suspense.isInFallback) {
  2471. return;
  2472. }
  2473. // mount the fallback tree
  2474. patch(null, fallbackVNode, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2475. isSVG, slotScopeIds, optimized);
  2476. setActiveBranch(suspense, fallbackVNode);
  2477. };
  2478. const delayEnter = fallbackVNode.transition && fallbackVNode.transition.mode === 'out-in';
  2479. if (delayEnter) {
  2480. activeBranch.transition.afterLeave = mountFallback;
  2481. }
  2482. suspense.isInFallback = true;
  2483. // unmount current active branch
  2484. unmount(activeBranch, parentComponent, null, // no suspense so unmount hooks fire now
  2485. true // shouldRemove
  2486. );
  2487. if (!delayEnter) {
  2488. mountFallback();
  2489. }
  2490. },
  2491. move(container, anchor, type) {
  2492. suspense.activeBranch &&
  2493. move(suspense.activeBranch, container, anchor, type);
  2494. suspense.container = container;
  2495. },
  2496. next() {
  2497. return suspense.activeBranch && next(suspense.activeBranch);
  2498. },
  2499. registerDep(instance, setupRenderEffect) {
  2500. const isInPendingSuspense = !!suspense.pendingBranch;
  2501. if (isInPendingSuspense) {
  2502. suspense.deps++;
  2503. }
  2504. const hydratedEl = instance.vnode.el;
  2505. instance
  2506. .asyncDep.catch(err => {
  2507. handleError(err, instance, 0 /* SETUP_FUNCTION */);
  2508. })
  2509. .then(asyncSetupResult => {
  2510. // retry when the setup() promise resolves.
  2511. // component may have been unmounted before resolve.
  2512. if (instance.isUnmounted ||
  2513. suspense.isUnmounted ||
  2514. suspense.pendingId !== instance.suspenseId) {
  2515. return;
  2516. }
  2517. // retry from this component
  2518. instance.asyncResolved = true;
  2519. const { vnode } = instance;
  2520. {
  2521. pushWarningContext(vnode);
  2522. }
  2523. handleSetupResult(instance, asyncSetupResult, false);
  2524. if (hydratedEl) {
  2525. // vnode may have been replaced if an update happened before the
  2526. // async dep is resolved.
  2527. vnode.el = hydratedEl;
  2528. }
  2529. const placeholder = !hydratedEl && instance.subTree.el;
  2530. setupRenderEffect(instance, vnode,
  2531. // component may have been moved before resolve.
  2532. // if this is not a hydration, instance.subTree will be the comment
  2533. // placeholder.
  2534. parentNode(hydratedEl || instance.subTree.el),
  2535. // anchor will not be used if this is hydration, so only need to
  2536. // consider the comment placeholder case.
  2537. hydratedEl ? null : next(instance.subTree), suspense, isSVG, optimized);
  2538. if (placeholder) {
  2539. remove(placeholder);
  2540. }
  2541. updateHOCHostEl(instance, vnode.el);
  2542. {
  2543. popWarningContext();
  2544. }
  2545. // only decrease deps count if suspense is not already resolved
  2546. if (isInPendingSuspense && --suspense.deps === 0) {
  2547. suspense.resolve();
  2548. }
  2549. });
  2550. },
  2551. unmount(parentSuspense, doRemove) {
  2552. suspense.isUnmounted = true;
  2553. if (suspense.activeBranch) {
  2554. unmount(suspense.activeBranch, parentComponent, parentSuspense, doRemove);
  2555. }
  2556. if (suspense.pendingBranch) {
  2557. unmount(suspense.pendingBranch, parentComponent, parentSuspense, doRemove);
  2558. }
  2559. }
  2560. };
  2561. return suspense;
  2562. }
  2563. function hydrateSuspense(node, vnode, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, rendererInternals, hydrateNode) {
  2564. /* eslint-disable no-restricted-globals */
  2565. const suspense = (vnode.suspense = createSuspenseBoundary(vnode, parentSuspense, parentComponent, node.parentNode, document.createElement('div'), null, isSVG, slotScopeIds, optimized, rendererInternals, true /* hydrating */));
  2566. // there are two possible scenarios for server-rendered suspense:
  2567. // - success: ssr content should be fully resolved
  2568. // - failure: ssr content should be the fallback branch.
  2569. // however, on the client we don't really know if it has failed or not
  2570. // attempt to hydrate the DOM assuming it has succeeded, but we still
  2571. // need to construct a suspense boundary first
  2572. const result = hydrateNode(node, (suspense.pendingBranch = vnode.ssContent), parentComponent, suspense, slotScopeIds, optimized);
  2573. if (suspense.deps === 0) {
  2574. suspense.resolve();
  2575. }
  2576. return result;
  2577. /* eslint-enable no-restricted-globals */
  2578. }
  2579. function normalizeSuspenseChildren(vnode) {
  2580. const { shapeFlag, children } = vnode;
  2581. const isSlotChildren = shapeFlag & 32 /* SLOTS_CHILDREN */;
  2582. vnode.ssContent = normalizeSuspenseSlot(isSlotChildren ? children.default : children);
  2583. vnode.ssFallback = isSlotChildren
  2584. ? normalizeSuspenseSlot(children.fallback)
  2585. : createVNode(Comment);
  2586. }
  2587. function normalizeSuspenseSlot(s) {
  2588. let block;
  2589. if (isFunction(s)) {
  2590. const trackBlock = isBlockTreeEnabled && s._c;
  2591. if (trackBlock) {
  2592. // disableTracking: false
  2593. // allow block tracking for compiled slots
  2594. // (see ./componentRenderContext.ts)
  2595. s._d = false;
  2596. openBlock();
  2597. }
  2598. s = s();
  2599. if (trackBlock) {
  2600. s._d = true;
  2601. block = currentBlock;
  2602. closeBlock();
  2603. }
  2604. }
  2605. if (isArray(s)) {
  2606. const singleChild = filterSingleRoot(s);
  2607. if (!singleChild) {
  2608. warn$1(`<Suspense> slots expect a single root node.`);
  2609. }
  2610. s = singleChild;
  2611. }
  2612. s = normalizeVNode(s);
  2613. if (block && !s.dynamicChildren) {
  2614. s.dynamicChildren = block.filter(c => c !== s);
  2615. }
  2616. return s;
  2617. }
  2618. function queueEffectWithSuspense(fn, suspense) {
  2619. if (suspense && suspense.pendingBranch) {
  2620. if (isArray(fn)) {
  2621. suspense.effects.push(...fn);
  2622. }
  2623. else {
  2624. suspense.effects.push(fn);
  2625. }
  2626. }
  2627. else {
  2628. queuePostFlushCb(fn);
  2629. }
  2630. }
  2631. function setActiveBranch(suspense, branch) {
  2632. suspense.activeBranch = branch;
  2633. const { vnode, parentComponent } = suspense;
  2634. const el = (vnode.el = branch.el);
  2635. // in case suspense is the root node of a component,
  2636. // recursively update the HOC el
  2637. if (parentComponent && parentComponent.subTree === vnode) {
  2638. parentComponent.vnode.el = el;
  2639. updateHOCHostEl(parentComponent, el);
  2640. }
  2641. }
  2642. function provide(key, value) {
  2643. if (!currentInstance) {
  2644. {
  2645. warn$1(`provide() can only be used inside setup().`);
  2646. }
  2647. }
  2648. else {
  2649. let provides = currentInstance.provides;
  2650. // by default an instance inherits its parent's provides object
  2651. // but when it needs to provide values of its own, it creates its
  2652. // own provides object using parent provides object as prototype.
  2653. // this way in `inject` we can simply look up injections from direct
  2654. // parent and let the prototype chain do the work.
  2655. const parentProvides = currentInstance.parent && currentInstance.parent.provides;
  2656. if (parentProvides === provides) {
  2657. provides = currentInstance.provides = Object.create(parentProvides);
  2658. }
  2659. // TS doesn't allow symbol as index type
  2660. provides[key] = value;
  2661. }
  2662. }
  2663. function inject(key, defaultValue, treatDefaultAsFactory = false) {
  2664. // fallback to `currentRenderingInstance` so that this can be called in
  2665. // a functional component
  2666. const instance = currentInstance || currentRenderingInstance;
  2667. if (instance) {
  2668. // #2400
  2669. // to support `app.use` plugins,
  2670. // fallback to appContext's `provides` if the intance is at root
  2671. const provides = instance.parent == null
  2672. ? instance.vnode.appContext && instance.vnode.appContext.provides
  2673. : instance.parent.provides;
  2674. if (provides && key in provides) {
  2675. // TS doesn't allow symbol as index type
  2676. return provides[key];
  2677. }
  2678. else if (arguments.length > 1) {
  2679. return treatDefaultAsFactory && isFunction(defaultValue)
  2680. ? defaultValue.call(instance.proxy)
  2681. : defaultValue;
  2682. }
  2683. else {
  2684. warn$1(`injection "${String(key)}" not found.`);
  2685. }
  2686. }
  2687. else {
  2688. warn$1(`inject() can only be used inside setup() or functional components.`);
  2689. }
  2690. }
  2691. function useTransitionState() {
  2692. const state = {
  2693. isMounted: false,
  2694. isLeaving: false,
  2695. isUnmounting: false,
  2696. leavingVNodes: new Map()
  2697. };
  2698. onMounted(() => {
  2699. state.isMounted = true;
  2700. });
  2701. onBeforeUnmount(() => {
  2702. state.isUnmounting = true;
  2703. });
  2704. return state;
  2705. }
  2706. const TransitionHookValidator = [Function, Array];
  2707. const BaseTransitionImpl = {
  2708. name: `BaseTransition`,
  2709. props: {
  2710. mode: String,
  2711. appear: Boolean,
  2712. persisted: Boolean,
  2713. // enter
  2714. onBeforeEnter: TransitionHookValidator,
  2715. onEnter: TransitionHookValidator,
  2716. onAfterEnter: TransitionHookValidator,
  2717. onEnterCancelled: TransitionHookValidator,
  2718. // leave
  2719. onBeforeLeave: TransitionHookValidator,
  2720. onLeave: TransitionHookValidator,
  2721. onAfterLeave: TransitionHookValidator,
  2722. onLeaveCancelled: TransitionHookValidator,
  2723. // appear
  2724. onBeforeAppear: TransitionHookValidator,
  2725. onAppear: TransitionHookValidator,
  2726. onAfterAppear: TransitionHookValidator,
  2727. onAppearCancelled: TransitionHookValidator
  2728. },
  2729. setup(props, { slots }) {
  2730. const instance = getCurrentInstance();
  2731. const state = useTransitionState();
  2732. let prevTransitionKey;
  2733. return () => {
  2734. const children = slots.default && getTransitionRawChildren(slots.default(), true);
  2735. if (!children || !children.length) {
  2736. return;
  2737. }
  2738. // warn multiple elements
  2739. if (children.length > 1) {
  2740. warn$1('<transition> can only be used on a single element or component. Use ' +
  2741. '<transition-group> for lists.');
  2742. }
  2743. // there's no need to track reactivity for these props so use the raw
  2744. // props for a bit better perf
  2745. const rawProps = toRaw(props);
  2746. const { mode } = rawProps;
  2747. // check mode
  2748. if (mode &&
  2749. mode !== 'in-out' && mode !== 'out-in' && mode !== 'default') {
  2750. warn$1(`invalid <transition> mode: ${mode}`);
  2751. }
  2752. // at this point children has a guaranteed length of 1.
  2753. const child = children[0];
  2754. if (state.isLeaving) {
  2755. return emptyPlaceholder(child);
  2756. }
  2757. // in the case of <transition><keep-alive/></transition>, we need to
  2758. // compare the type of the kept-alive children.
  2759. const innerChild = getKeepAliveChild(child);
  2760. if (!innerChild) {
  2761. return emptyPlaceholder(child);
  2762. }
  2763. const enterHooks = resolveTransitionHooks(innerChild, rawProps, state, instance);
  2764. setTransitionHooks(innerChild, enterHooks);
  2765. const oldChild = instance.subTree;
  2766. const oldInnerChild = oldChild && getKeepAliveChild(oldChild);
  2767. let transitionKeyChanged = false;
  2768. const { getTransitionKey } = innerChild.type;
  2769. if (getTransitionKey) {
  2770. const key = getTransitionKey();
  2771. if (prevTransitionKey === undefined) {
  2772. prevTransitionKey = key;
  2773. }
  2774. else if (key !== prevTransitionKey) {
  2775. prevTransitionKey = key;
  2776. transitionKeyChanged = true;
  2777. }
  2778. }
  2779. // handle mode
  2780. if (oldInnerChild &&
  2781. oldInnerChild.type !== Comment &&
  2782. (!isSameVNodeType(innerChild, oldInnerChild) || transitionKeyChanged)) {
  2783. const leavingHooks = resolveTransitionHooks(oldInnerChild, rawProps, state, instance);
  2784. // update old tree's hooks in case of dynamic transition
  2785. setTransitionHooks(oldInnerChild, leavingHooks);
  2786. // switching between different views
  2787. if (mode === 'out-in') {
  2788. state.isLeaving = true;
  2789. // return placeholder node and queue update when leave finishes
  2790. leavingHooks.afterLeave = () => {
  2791. state.isLeaving = false;
  2792. instance.update();
  2793. };
  2794. return emptyPlaceholder(child);
  2795. }
  2796. else if (mode === 'in-out' && innerChild.type !== Comment) {
  2797. leavingHooks.delayLeave = (el, earlyRemove, delayedLeave) => {
  2798. const leavingVNodesCache = getLeavingNodesForType(state, oldInnerChild);
  2799. leavingVNodesCache[String(oldInnerChild.key)] = oldInnerChild;
  2800. // early removal callback
  2801. el._leaveCb = () => {
  2802. earlyRemove();
  2803. el._leaveCb = undefined;
  2804. delete enterHooks.delayedLeave;
  2805. };
  2806. enterHooks.delayedLeave = delayedLeave;
  2807. };
  2808. }
  2809. }
  2810. return child;
  2811. };
  2812. }
  2813. };
  2814. // export the public type for h/tsx inference
  2815. // also to avoid inline import() in generated d.ts files
  2816. const BaseTransition = BaseTransitionImpl;
  2817. function getLeavingNodesForType(state, vnode) {
  2818. const { leavingVNodes } = state;
  2819. let leavingVNodesCache = leavingVNodes.get(vnode.type);
  2820. if (!leavingVNodesCache) {
  2821. leavingVNodesCache = Object.create(null);
  2822. leavingVNodes.set(vnode.type, leavingVNodesCache);
  2823. }
  2824. return leavingVNodesCache;
  2825. }
  2826. // The transition hooks are attached to the vnode as vnode.transition
  2827. // and will be called at appropriate timing in the renderer.
  2828. function resolveTransitionHooks(vnode, props, state, instance) {
  2829. const { appear, mode, persisted = false, onBeforeEnter, onEnter, onAfterEnter, onEnterCancelled, onBeforeLeave, onLeave, onAfterLeave, onLeaveCancelled, onBeforeAppear, onAppear, onAfterAppear, onAppearCancelled } = props;
  2830. const key = String(vnode.key);
  2831. const leavingVNodesCache = getLeavingNodesForType(state, vnode);
  2832. const callHook = (hook, args) => {
  2833. hook &&
  2834. callWithAsyncErrorHandling(hook, instance, 9 /* TRANSITION_HOOK */, args);
  2835. };
  2836. const hooks = {
  2837. mode,
  2838. persisted,
  2839. beforeEnter(el) {
  2840. let hook = onBeforeEnter;
  2841. if (!state.isMounted) {
  2842. if (appear) {
  2843. hook = onBeforeAppear || onBeforeEnter;
  2844. }
  2845. else {
  2846. return;
  2847. }
  2848. }
  2849. // for same element (v-show)
  2850. if (el._leaveCb) {
  2851. el._leaveCb(true /* cancelled */);
  2852. }
  2853. // for toggled element with same key (v-if)
  2854. const leavingVNode = leavingVNodesCache[key];
  2855. if (leavingVNode &&
  2856. isSameVNodeType(vnode, leavingVNode) &&
  2857. leavingVNode.el._leaveCb) {
  2858. // force early removal (not cancelled)
  2859. leavingVNode.el._leaveCb();
  2860. }
  2861. callHook(hook, [el]);
  2862. },
  2863. enter(el) {
  2864. let hook = onEnter;
  2865. let afterHook = onAfterEnter;
  2866. let cancelHook = onEnterCancelled;
  2867. if (!state.isMounted) {
  2868. if (appear) {
  2869. hook = onAppear || onEnter;
  2870. afterHook = onAfterAppear || onAfterEnter;
  2871. cancelHook = onAppearCancelled || onEnterCancelled;
  2872. }
  2873. else {
  2874. return;
  2875. }
  2876. }
  2877. let called = false;
  2878. const done = (el._enterCb = (cancelled) => {
  2879. if (called)
  2880. return;
  2881. called = true;
  2882. if (cancelled) {
  2883. callHook(cancelHook, [el]);
  2884. }
  2885. else {
  2886. callHook(afterHook, [el]);
  2887. }
  2888. if (hooks.delayedLeave) {
  2889. hooks.delayedLeave();
  2890. }
  2891. el._enterCb = undefined;
  2892. });
  2893. if (hook) {
  2894. hook(el, done);
  2895. if (hook.length <= 1) {
  2896. done();
  2897. }
  2898. }
  2899. else {
  2900. done();
  2901. }
  2902. },
  2903. leave(el, remove) {
  2904. const key = String(vnode.key);
  2905. if (el._enterCb) {
  2906. el._enterCb(true /* cancelled */);
  2907. }
  2908. if (state.isUnmounting) {
  2909. return remove();
  2910. }
  2911. callHook(onBeforeLeave, [el]);
  2912. let called = false;
  2913. const done = (el._leaveCb = (cancelled) => {
  2914. if (called)
  2915. return;
  2916. called = true;
  2917. remove();
  2918. if (cancelled) {
  2919. callHook(onLeaveCancelled, [el]);
  2920. }
  2921. else {
  2922. callHook(onAfterLeave, [el]);
  2923. }
  2924. el._leaveCb = undefined;
  2925. if (leavingVNodesCache[key] === vnode) {
  2926. delete leavingVNodesCache[key];
  2927. }
  2928. });
  2929. leavingVNodesCache[key] = vnode;
  2930. if (onLeave) {
  2931. onLeave(el, done);
  2932. if (onLeave.length <= 1) {
  2933. done();
  2934. }
  2935. }
  2936. else {
  2937. done();
  2938. }
  2939. },
  2940. clone(vnode) {
  2941. return resolveTransitionHooks(vnode, props, state, instance);
  2942. }
  2943. };
  2944. return hooks;
  2945. }
  2946. // the placeholder really only handles one special case: KeepAlive
  2947. // in the case of a KeepAlive in a leave phase we need to return a KeepAlive
  2948. // placeholder with empty content to avoid the KeepAlive instance from being
  2949. // unmounted.
  2950. function emptyPlaceholder(vnode) {
  2951. if (isKeepAlive(vnode)) {
  2952. vnode = cloneVNode(vnode);
  2953. vnode.children = null;
  2954. return vnode;
  2955. }
  2956. }
  2957. function getKeepAliveChild(vnode) {
  2958. return isKeepAlive(vnode)
  2959. ? vnode.children
  2960. ? vnode.children[0]
  2961. : undefined
  2962. : vnode;
  2963. }
  2964. function setTransitionHooks(vnode, hooks) {
  2965. if (vnode.shapeFlag & 6 /* COMPONENT */ && vnode.component) {
  2966. setTransitionHooks(vnode.component.subTree, hooks);
  2967. }
  2968. else if (vnode.shapeFlag & 128 /* SUSPENSE */) {
  2969. vnode.ssContent.transition = hooks.clone(vnode.ssContent);
  2970. vnode.ssFallback.transition = hooks.clone(vnode.ssFallback);
  2971. }
  2972. else {
  2973. vnode.transition = hooks;
  2974. }
  2975. }
  2976. function getTransitionRawChildren(children, keepComment = false) {
  2977. let ret = [];
  2978. let keyedFragmentCount = 0;
  2979. for (let i = 0; i < children.length; i++) {
  2980. const child = children[i];
  2981. // handle fragment children case, e.g. v-for
  2982. if (child.type === Fragment) {
  2983. if (child.patchFlag & 128 /* KEYED_FRAGMENT */)
  2984. keyedFragmentCount++;
  2985. ret = ret.concat(getTransitionRawChildren(child.children, keepComment));
  2986. }
  2987. // comment placeholders should be skipped, e.g. v-if
  2988. else if (keepComment || child.type !== Comment) {
  2989. ret.push(child);
  2990. }
  2991. }
  2992. // #1126 if a transition children list contains multiple sub fragments, these
  2993. // fragments will be merged into a flat children array. Since each v-for
  2994. // fragment may contain different static bindings inside, we need to de-op
  2995. // these children to force full diffs to ensure correct behavior.
  2996. if (keyedFragmentCount > 1) {
  2997. for (let i = 0; i < ret.length; i++) {
  2998. ret[i].patchFlag = -2 /* BAIL */;
  2999. }
  3000. }
  3001. return ret;
  3002. }
  3003. // implementation, close to no-op
  3004. function defineComponent(options) {
  3005. return isFunction(options) ? { setup: options, name: options.name } : options;
  3006. }
  3007. const isAsyncWrapper = (i) => !!i.type.__asyncLoader;
  3008. function defineAsyncComponent(source) {
  3009. if (isFunction(source)) {
  3010. source = { loader: source };
  3011. }
  3012. const { loader, loadingComponent, errorComponent, delay = 200, timeout, // undefined = never times out
  3013. suspensible = true, onError: userOnError } = source;
  3014. let pendingRequest = null;
  3015. let resolvedComp;
  3016. let retries = 0;
  3017. const retry = () => {
  3018. retries++;
  3019. pendingRequest = null;
  3020. return load();
  3021. };
  3022. const load = () => {
  3023. let thisRequest;
  3024. return (pendingRequest ||
  3025. (thisRequest = pendingRequest =
  3026. loader()
  3027. .catch(err => {
  3028. err = err instanceof Error ? err : new Error(String(err));
  3029. if (userOnError) {
  3030. return new Promise((resolve, reject) => {
  3031. const userRetry = () => resolve(retry());
  3032. const userFail = () => reject(err);
  3033. userOnError(err, userRetry, userFail, retries + 1);
  3034. });
  3035. }
  3036. else {
  3037. throw err;
  3038. }
  3039. })
  3040. .then((comp) => {
  3041. if (thisRequest !== pendingRequest && pendingRequest) {
  3042. return pendingRequest;
  3043. }
  3044. if (!comp) {
  3045. warn$1(`Async component loader resolved to undefined. ` +
  3046. `If you are using retry(), make sure to return its return value.`);
  3047. }
  3048. // interop module default
  3049. if (comp &&
  3050. (comp.__esModule || comp[Symbol.toStringTag] === 'Module')) {
  3051. comp = comp.default;
  3052. }
  3053. if (comp && !isObject(comp) && !isFunction(comp)) {
  3054. throw new Error(`Invalid async component load result: ${comp}`);
  3055. }
  3056. resolvedComp = comp;
  3057. return comp;
  3058. })));
  3059. };
  3060. return defineComponent({
  3061. name: 'AsyncComponentWrapper',
  3062. __asyncLoader: load,
  3063. get __asyncResolved() {
  3064. return resolvedComp;
  3065. },
  3066. setup() {
  3067. const instance = currentInstance;
  3068. // already resolved
  3069. if (resolvedComp) {
  3070. return () => createInnerComp(resolvedComp, instance);
  3071. }
  3072. const onError = (err) => {
  3073. pendingRequest = null;
  3074. handleError(err, instance, 13 /* ASYNC_COMPONENT_LOADER */, !errorComponent /* do not throw in dev if user provided error component */);
  3075. };
  3076. // suspense-controlled or SSR.
  3077. if ((suspensible && instance.suspense) ||
  3078. (false )) {
  3079. return load()
  3080. .then(comp => {
  3081. return () => createInnerComp(comp, instance);
  3082. })
  3083. .catch(err => {
  3084. onError(err);
  3085. return () => errorComponent
  3086. ? createVNode(errorComponent, {
  3087. error: err
  3088. })
  3089. : null;
  3090. });
  3091. }
  3092. const loaded = ref(false);
  3093. const error = ref();
  3094. const delayed = ref(!!delay);
  3095. if (delay) {
  3096. setTimeout(() => {
  3097. delayed.value = false;
  3098. }, delay);
  3099. }
  3100. if (timeout != null) {
  3101. setTimeout(() => {
  3102. if (!loaded.value && !error.value) {
  3103. const err = new Error(`Async component timed out after ${timeout}ms.`);
  3104. onError(err);
  3105. error.value = err;
  3106. }
  3107. }, timeout);
  3108. }
  3109. load()
  3110. .then(() => {
  3111. loaded.value = true;
  3112. if (instance.parent && isKeepAlive(instance.parent.vnode)) {
  3113. // parent is keep-alive, force update so the loaded component's
  3114. // name is taken into account
  3115. queueJob(instance.parent.update);
  3116. }
  3117. })
  3118. .catch(err => {
  3119. onError(err);
  3120. error.value = err;
  3121. });
  3122. return () => {
  3123. if (loaded.value && resolvedComp) {
  3124. return createInnerComp(resolvedComp, instance);
  3125. }
  3126. else if (error.value && errorComponent) {
  3127. return createVNode(errorComponent, {
  3128. error: error.value
  3129. });
  3130. }
  3131. else if (loadingComponent && !delayed.value) {
  3132. return createVNode(loadingComponent);
  3133. }
  3134. };
  3135. }
  3136. });
  3137. }
  3138. function createInnerComp(comp, { vnode: { ref, props, children } }) {
  3139. const vnode = createVNode(comp, props, children);
  3140. // ensure inner component inherits the async wrapper's ref owner
  3141. vnode.ref = ref;
  3142. return vnode;
  3143. }
  3144. const isKeepAlive = (vnode) => vnode.type.__isKeepAlive;
  3145. const KeepAliveImpl = {
  3146. name: `KeepAlive`,
  3147. // Marker for special handling inside the renderer. We are not using a ===
  3148. // check directly on KeepAlive in the renderer, because importing it directly
  3149. // would prevent it from being tree-shaken.
  3150. __isKeepAlive: true,
  3151. props: {
  3152. include: [String, RegExp, Array],
  3153. exclude: [String, RegExp, Array],
  3154. max: [String, Number]
  3155. },
  3156. setup(props, { slots }) {
  3157. const instance = getCurrentInstance();
  3158. // KeepAlive communicates with the instantiated renderer via the
  3159. // ctx where the renderer passes in its internals,
  3160. // and the KeepAlive instance exposes activate/deactivate implementations.
  3161. // The whole point of this is to avoid importing KeepAlive directly in the
  3162. // renderer to facilitate tree-shaking.
  3163. const sharedContext = instance.ctx;
  3164. // if the internal renderer is not registered, it indicates that this is server-side rendering,
  3165. // for KeepAlive, we just need to render its children
  3166. if (!sharedContext.renderer) {
  3167. return slots.default;
  3168. }
  3169. const cache = new Map();
  3170. const keys = new Set();
  3171. let current = null;
  3172. {
  3173. instance.__v_cache = cache;
  3174. }
  3175. const parentSuspense = instance.suspense;
  3176. const { renderer: { p: patch, m: move, um: _unmount, o: { createElement } } } = sharedContext;
  3177. const storageContainer = createElement('div');
  3178. sharedContext.activate = (vnode, container, anchor, isSVG, optimized) => {
  3179. const instance = vnode.component;
  3180. move(vnode, container, anchor, 0 /* ENTER */, parentSuspense);
  3181. // in case props have changed
  3182. patch(instance.vnode, vnode, container, anchor, instance, parentSuspense, isSVG, vnode.slotScopeIds, optimized);
  3183. queuePostRenderEffect(() => {
  3184. instance.isDeactivated = false;
  3185. if (instance.a) {
  3186. invokeArrayFns(instance.a);
  3187. }
  3188. const vnodeHook = vnode.props && vnode.props.onVnodeMounted;
  3189. if (vnodeHook) {
  3190. invokeVNodeHook(vnodeHook, instance.parent, vnode);
  3191. }
  3192. }, parentSuspense);
  3193. {
  3194. // Update components tree
  3195. devtoolsComponentAdded(instance);
  3196. }
  3197. };
  3198. sharedContext.deactivate = (vnode) => {
  3199. const instance = vnode.component;
  3200. move(vnode, storageContainer, null, 1 /* LEAVE */, parentSuspense);
  3201. queuePostRenderEffect(() => {
  3202. if (instance.da) {
  3203. invokeArrayFns(instance.da);
  3204. }
  3205. const vnodeHook = vnode.props && vnode.props.onVnodeUnmounted;
  3206. if (vnodeHook) {
  3207. invokeVNodeHook(vnodeHook, instance.parent, vnode);
  3208. }
  3209. instance.isDeactivated = true;
  3210. }, parentSuspense);
  3211. {
  3212. // Update components tree
  3213. devtoolsComponentAdded(instance);
  3214. }
  3215. };
  3216. function unmount(vnode) {
  3217. // reset the shapeFlag so it can be properly unmounted
  3218. resetShapeFlag(vnode);
  3219. _unmount(vnode, instance, parentSuspense);
  3220. }
  3221. function pruneCache(filter) {
  3222. cache.forEach((vnode, key) => {
  3223. const name = getComponentName(vnode.type);
  3224. if (name && (!filter || !filter(name))) {
  3225. pruneCacheEntry(key);
  3226. }
  3227. });
  3228. }
  3229. function pruneCacheEntry(key) {
  3230. const cached = cache.get(key);
  3231. if (!current || cached.type !== current.type) {
  3232. unmount(cached);
  3233. }
  3234. else if (current) {
  3235. // current active instance should no longer be kept-alive.
  3236. // we can't unmount it now but it might be later, so reset its flag now.
  3237. resetShapeFlag(current);
  3238. }
  3239. cache.delete(key);
  3240. keys.delete(key);
  3241. }
  3242. // prune cache on include/exclude prop change
  3243. watch(() => [props.include, props.exclude], ([include, exclude]) => {
  3244. include && pruneCache(name => matches(include, name));
  3245. exclude && pruneCache(name => !matches(exclude, name));
  3246. },
  3247. // prune post-render after `current` has been updated
  3248. { flush: 'post', deep: true });
  3249. // cache sub tree after render
  3250. let pendingCacheKey = null;
  3251. const cacheSubtree = () => {
  3252. // fix #1621, the pendingCacheKey could be 0
  3253. if (pendingCacheKey != null) {
  3254. cache.set(pendingCacheKey, getInnerChild(instance.subTree));
  3255. }
  3256. };
  3257. onMounted(cacheSubtree);
  3258. onUpdated(cacheSubtree);
  3259. onBeforeUnmount(() => {
  3260. cache.forEach(cached => {
  3261. const { subTree, suspense } = instance;
  3262. const vnode = getInnerChild(subTree);
  3263. if (cached.type === vnode.type) {
  3264. // current instance will be unmounted as part of keep-alive's unmount
  3265. resetShapeFlag(vnode);
  3266. // but invoke its deactivated hook here
  3267. const da = vnode.component.da;
  3268. da && queuePostRenderEffect(da, suspense);
  3269. return;
  3270. }
  3271. unmount(cached);
  3272. });
  3273. });
  3274. return () => {
  3275. pendingCacheKey = null;
  3276. if (!slots.default) {
  3277. return null;
  3278. }
  3279. const children = slots.default();
  3280. const rawVNode = children[0];
  3281. if (children.length > 1) {
  3282. {
  3283. warn$1(`KeepAlive should contain exactly one component child.`);
  3284. }
  3285. current = null;
  3286. return children;
  3287. }
  3288. else if (!isVNode(rawVNode) ||
  3289. (!(rawVNode.shapeFlag & 4 /* STATEFUL_COMPONENT */) &&
  3290. !(rawVNode.shapeFlag & 128 /* SUSPENSE */))) {
  3291. current = null;
  3292. return rawVNode;
  3293. }
  3294. let vnode = getInnerChild(rawVNode);
  3295. const comp = vnode.type;
  3296. // for async components, name check should be based in its loaded
  3297. // inner component if available
  3298. const name = getComponentName(isAsyncWrapper(vnode)
  3299. ? vnode.type.__asyncResolved || {}
  3300. : comp);
  3301. const { include, exclude, max } = props;
  3302. if ((include && (!name || !matches(include, name))) ||
  3303. (exclude && name && matches(exclude, name))) {
  3304. current = vnode;
  3305. return rawVNode;
  3306. }
  3307. const key = vnode.key == null ? comp : vnode.key;
  3308. const cachedVNode = cache.get(key);
  3309. // clone vnode if it's reused because we are going to mutate it
  3310. if (vnode.el) {
  3311. vnode = cloneVNode(vnode);
  3312. if (rawVNode.shapeFlag & 128 /* SUSPENSE */) {
  3313. rawVNode.ssContent = vnode;
  3314. }
  3315. }
  3316. // #1513 it's possible for the returned vnode to be cloned due to attr
  3317. // fallthrough or scopeId, so the vnode here may not be the final vnode
  3318. // that is mounted. Instead of caching it directly, we store the pending
  3319. // key and cache `instance.subTree` (the normalized vnode) in
  3320. // beforeMount/beforeUpdate hooks.
  3321. pendingCacheKey = key;
  3322. if (cachedVNode) {
  3323. // copy over mounted state
  3324. vnode.el = cachedVNode.el;
  3325. vnode.component = cachedVNode.component;
  3326. if (vnode.transition) {
  3327. // recursively update transition hooks on subTree
  3328. setTransitionHooks(vnode, vnode.transition);
  3329. }
  3330. // avoid vnode being mounted as fresh
  3331. vnode.shapeFlag |= 512 /* COMPONENT_KEPT_ALIVE */;
  3332. // make this key the freshest
  3333. keys.delete(key);
  3334. keys.add(key);
  3335. }
  3336. else {
  3337. keys.add(key);
  3338. // prune oldest entry
  3339. if (max && keys.size > parseInt(max, 10)) {
  3340. pruneCacheEntry(keys.values().next().value);
  3341. }
  3342. }
  3343. // avoid vnode being unmounted
  3344. vnode.shapeFlag |= 256 /* COMPONENT_SHOULD_KEEP_ALIVE */;
  3345. current = vnode;
  3346. return rawVNode;
  3347. };
  3348. }
  3349. };
  3350. // export the public type for h/tsx inference
  3351. // also to avoid inline import() in generated d.ts files
  3352. const KeepAlive = KeepAliveImpl;
  3353. function matches(pattern, name) {
  3354. if (isArray(pattern)) {
  3355. return pattern.some((p) => matches(p, name));
  3356. }
  3357. else if (isString(pattern)) {
  3358. return pattern.split(',').indexOf(name) > -1;
  3359. }
  3360. else if (pattern.test) {
  3361. return pattern.test(name);
  3362. }
  3363. /* istanbul ignore next */
  3364. return false;
  3365. }
  3366. function onActivated(hook, target) {
  3367. registerKeepAliveHook(hook, "a" /* ACTIVATED */, target);
  3368. }
  3369. function onDeactivated(hook, target) {
  3370. registerKeepAliveHook(hook, "da" /* DEACTIVATED */, target);
  3371. }
  3372. function registerKeepAliveHook(hook, type, target = currentInstance) {
  3373. // cache the deactivate branch check wrapper for injected hooks so the same
  3374. // hook can be properly deduped by the scheduler. "__wdc" stands for "with
  3375. // deactivation check".
  3376. const wrappedHook = hook.__wdc ||
  3377. (hook.__wdc = () => {
  3378. // only fire the hook if the target instance is NOT in a deactivated branch.
  3379. let current = target;
  3380. while (current) {
  3381. if (current.isDeactivated) {
  3382. return;
  3383. }
  3384. current = current.parent;
  3385. }
  3386. return hook();
  3387. });
  3388. injectHook(type, wrappedHook, target);
  3389. // In addition to registering it on the target instance, we walk up the parent
  3390. // chain and register it on all ancestor instances that are keep-alive roots.
  3391. // This avoids the need to walk the entire component tree when invoking these
  3392. // hooks, and more importantly, avoids the need to track child components in
  3393. // arrays.
  3394. if (target) {
  3395. let current = target.parent;
  3396. while (current && current.parent) {
  3397. if (isKeepAlive(current.parent.vnode)) {
  3398. injectToKeepAliveRoot(wrappedHook, type, target, current);
  3399. }
  3400. current = current.parent;
  3401. }
  3402. }
  3403. }
  3404. function injectToKeepAliveRoot(hook, type, target, keepAliveRoot) {
  3405. // injectHook wraps the original for error handling, so make sure to remove
  3406. // the wrapped version.
  3407. const injected = injectHook(type, hook, keepAliveRoot, true /* prepend */);
  3408. onUnmounted(() => {
  3409. remove(keepAliveRoot[type], injected);
  3410. }, target);
  3411. }
  3412. function resetShapeFlag(vnode) {
  3413. let shapeFlag = vnode.shapeFlag;
  3414. if (shapeFlag & 256 /* COMPONENT_SHOULD_KEEP_ALIVE */) {
  3415. shapeFlag -= 256 /* COMPONENT_SHOULD_KEEP_ALIVE */;
  3416. }
  3417. if (shapeFlag & 512 /* COMPONENT_KEPT_ALIVE */) {
  3418. shapeFlag -= 512 /* COMPONENT_KEPT_ALIVE */;
  3419. }
  3420. vnode.shapeFlag = shapeFlag;
  3421. }
  3422. function getInnerChild(vnode) {
  3423. return vnode.shapeFlag & 128 /* SUSPENSE */ ? vnode.ssContent : vnode;
  3424. }
  3425. function injectHook(type, hook, target = currentInstance, prepend = false) {
  3426. if (target) {
  3427. const hooks = target[type] || (target[type] = []);
  3428. // cache the error handling wrapper for injected hooks so the same hook
  3429. // can be properly deduped by the scheduler. "__weh" stands for "with error
  3430. // handling".
  3431. const wrappedHook = hook.__weh ||
  3432. (hook.__weh = (...args) => {
  3433. if (target.isUnmounted) {
  3434. return;
  3435. }
  3436. // disable tracking inside all lifecycle hooks
  3437. // since they can potentially be called inside effects.
  3438. pauseTracking();
  3439. // Set currentInstance during hook invocation.
  3440. // This assumes the hook does not synchronously trigger other hooks, which
  3441. // can only be false when the user does something really funky.
  3442. setCurrentInstance(target);
  3443. const res = callWithAsyncErrorHandling(hook, target, type, args);
  3444. unsetCurrentInstance();
  3445. resetTracking();
  3446. return res;
  3447. });
  3448. if (prepend) {
  3449. hooks.unshift(wrappedHook);
  3450. }
  3451. else {
  3452. hooks.push(wrappedHook);
  3453. }
  3454. return wrappedHook;
  3455. }
  3456. else {
  3457. const apiName = toHandlerKey(ErrorTypeStrings[type].replace(/ hook$/, ''));
  3458. warn$1(`${apiName} is called when there is no active component instance to be ` +
  3459. `associated with. ` +
  3460. `Lifecycle injection APIs can only be used during execution of setup().` +
  3461. (` If you are using async setup(), make sure to register lifecycle ` +
  3462. `hooks before the first await statement.`
  3463. ));
  3464. }
  3465. }
  3466. const createHook = (lifecycle) => (hook, target = currentInstance) =>
  3467. // post-create lifecycle registrations are noops during SSR (except for serverPrefetch)
  3468. (!isInSSRComponentSetup || lifecycle === "sp" /* SERVER_PREFETCH */) &&
  3469. injectHook(lifecycle, hook, target);
  3470. const onBeforeMount = createHook("bm" /* BEFORE_MOUNT */);
  3471. const onMounted = createHook("m" /* MOUNTED */);
  3472. const onBeforeUpdate = createHook("bu" /* BEFORE_UPDATE */);
  3473. const onUpdated = createHook("u" /* UPDATED */);
  3474. const onBeforeUnmount = createHook("bum" /* BEFORE_UNMOUNT */);
  3475. const onUnmounted = createHook("um" /* UNMOUNTED */);
  3476. const onServerPrefetch = createHook("sp" /* SERVER_PREFETCH */);
  3477. const onRenderTriggered = createHook("rtg" /* RENDER_TRIGGERED */);
  3478. const onRenderTracked = createHook("rtc" /* RENDER_TRACKED */);
  3479. function onErrorCaptured(hook, target = currentInstance) {
  3480. injectHook("ec" /* ERROR_CAPTURED */, hook, target);
  3481. }
  3482. function createDuplicateChecker() {
  3483. const cache = Object.create(null);
  3484. return (type, key) => {
  3485. if (cache[key]) {
  3486. warn$1(`${type} property "${key}" is already defined in ${cache[key]}.`);
  3487. }
  3488. else {
  3489. cache[key] = type;
  3490. }
  3491. };
  3492. }
  3493. let shouldCacheAccess = true;
  3494. function applyOptions(instance) {
  3495. const options = resolveMergedOptions(instance);
  3496. const publicThis = instance.proxy;
  3497. const ctx = instance.ctx;
  3498. // do not cache property access on public proxy during state initialization
  3499. shouldCacheAccess = false;
  3500. // call beforeCreate first before accessing other options since
  3501. // the hook may mutate resolved options (#2791)
  3502. if (options.beforeCreate) {
  3503. callHook(options.beforeCreate, instance, "bc" /* BEFORE_CREATE */);
  3504. }
  3505. const {
  3506. // state
  3507. data: dataOptions, computed: computedOptions, methods, watch: watchOptions, provide: provideOptions, inject: injectOptions,
  3508. // lifecycle
  3509. created, beforeMount, mounted, beforeUpdate, updated, activated, deactivated, beforeDestroy, beforeUnmount, destroyed, unmounted, render, renderTracked, renderTriggered, errorCaptured, serverPrefetch,
  3510. // public API
  3511. expose, inheritAttrs,
  3512. // assets
  3513. components, directives, filters } = options;
  3514. const checkDuplicateProperties = createDuplicateChecker() ;
  3515. {
  3516. const [propsOptions] = instance.propsOptions;
  3517. if (propsOptions) {
  3518. for (const key in propsOptions) {
  3519. checkDuplicateProperties("Props" /* PROPS */, key);
  3520. }
  3521. }
  3522. }
  3523. // options initialization order (to be consistent with Vue 2):
  3524. // - props (already done outside of this function)
  3525. // - inject
  3526. // - methods
  3527. // - data (deferred since it relies on `this` access)
  3528. // - computed
  3529. // - watch (deferred since it relies on `this` access)
  3530. if (injectOptions) {
  3531. resolveInjections(injectOptions, ctx, checkDuplicateProperties, instance.appContext.config.unwrapInjectedRef);
  3532. }
  3533. if (methods) {
  3534. for (const key in methods) {
  3535. const methodHandler = methods[key];
  3536. if (isFunction(methodHandler)) {
  3537. // In dev mode, we use the `createRenderContext` function to define
  3538. // methods to the proxy target, and those are read-only but
  3539. // reconfigurable, so it needs to be redefined here
  3540. {
  3541. Object.defineProperty(ctx, key, {
  3542. value: methodHandler.bind(publicThis),
  3543. configurable: true,
  3544. enumerable: true,
  3545. writable: true
  3546. });
  3547. }
  3548. {
  3549. checkDuplicateProperties("Methods" /* METHODS */, key);
  3550. }
  3551. }
  3552. else {
  3553. warn$1(`Method "${key}" has type "${typeof methodHandler}" in the component definition. ` +
  3554. `Did you reference the function correctly?`);
  3555. }
  3556. }
  3557. }
  3558. if (dataOptions) {
  3559. if (!isFunction(dataOptions)) {
  3560. warn$1(`The data option must be a function. ` +
  3561. `Plain object usage is no longer supported.`);
  3562. }
  3563. const data = dataOptions.call(publicThis, publicThis);
  3564. if (isPromise(data)) {
  3565. warn$1(`data() returned a Promise - note data() cannot be async; If you ` +
  3566. `intend to perform data fetching before component renders, use ` +
  3567. `async setup() + <Suspense>.`);
  3568. }
  3569. if (!isObject(data)) {
  3570. warn$1(`data() should return an object.`);
  3571. }
  3572. else {
  3573. instance.data = reactive(data);
  3574. {
  3575. for (const key in data) {
  3576. checkDuplicateProperties("Data" /* DATA */, key);
  3577. // expose data on ctx during dev
  3578. if (key[0] !== '$' && key[0] !== '_') {
  3579. Object.defineProperty(ctx, key, {
  3580. configurable: true,
  3581. enumerable: true,
  3582. get: () => data[key],
  3583. set: NOOP
  3584. });
  3585. }
  3586. }
  3587. }
  3588. }
  3589. }
  3590. // state initialization complete at this point - start caching access
  3591. shouldCacheAccess = true;
  3592. if (computedOptions) {
  3593. for (const key in computedOptions) {
  3594. const opt = computedOptions[key];
  3595. const get = isFunction(opt)
  3596. ? opt.bind(publicThis, publicThis)
  3597. : isFunction(opt.get)
  3598. ? opt.get.bind(publicThis, publicThis)
  3599. : NOOP;
  3600. if (get === NOOP) {
  3601. warn$1(`Computed property "${key}" has no getter.`);
  3602. }
  3603. const set = !isFunction(opt) && isFunction(opt.set)
  3604. ? opt.set.bind(publicThis)
  3605. : () => {
  3606. warn$1(`Write operation failed: computed property "${key}" is readonly.`);
  3607. }
  3608. ;
  3609. const c = computed({
  3610. get,
  3611. set
  3612. });
  3613. Object.defineProperty(ctx, key, {
  3614. enumerable: true,
  3615. configurable: true,
  3616. get: () => c.value,
  3617. set: v => (c.value = v)
  3618. });
  3619. {
  3620. checkDuplicateProperties("Computed" /* COMPUTED */, key);
  3621. }
  3622. }
  3623. }
  3624. if (watchOptions) {
  3625. for (const key in watchOptions) {
  3626. createWatcher(watchOptions[key], ctx, publicThis, key);
  3627. }
  3628. }
  3629. if (provideOptions) {
  3630. const provides = isFunction(provideOptions)
  3631. ? provideOptions.call(publicThis)
  3632. : provideOptions;
  3633. Reflect.ownKeys(provides).forEach(key => {
  3634. provide(key, provides[key]);
  3635. });
  3636. }
  3637. if (created) {
  3638. callHook(created, instance, "c" /* CREATED */);
  3639. }
  3640. function registerLifecycleHook(register, hook) {
  3641. if (isArray(hook)) {
  3642. hook.forEach(_hook => register(_hook.bind(publicThis)));
  3643. }
  3644. else if (hook) {
  3645. register(hook.bind(publicThis));
  3646. }
  3647. }
  3648. registerLifecycleHook(onBeforeMount, beforeMount);
  3649. registerLifecycleHook(onMounted, mounted);
  3650. registerLifecycleHook(onBeforeUpdate, beforeUpdate);
  3651. registerLifecycleHook(onUpdated, updated);
  3652. registerLifecycleHook(onActivated, activated);
  3653. registerLifecycleHook(onDeactivated, deactivated);
  3654. registerLifecycleHook(onErrorCaptured, errorCaptured);
  3655. registerLifecycleHook(onRenderTracked, renderTracked);
  3656. registerLifecycleHook(onRenderTriggered, renderTriggered);
  3657. registerLifecycleHook(onBeforeUnmount, beforeUnmount);
  3658. registerLifecycleHook(onUnmounted, unmounted);
  3659. registerLifecycleHook(onServerPrefetch, serverPrefetch);
  3660. if (isArray(expose)) {
  3661. if (expose.length) {
  3662. const exposed = instance.exposed || (instance.exposed = {});
  3663. expose.forEach(key => {
  3664. Object.defineProperty(exposed, key, {
  3665. get: () => publicThis[key],
  3666. set: val => (publicThis[key] = val)
  3667. });
  3668. });
  3669. }
  3670. else if (!instance.exposed) {
  3671. instance.exposed = {};
  3672. }
  3673. }
  3674. // options that are handled when creating the instance but also need to be
  3675. // applied from mixins
  3676. if (render && instance.render === NOOP) {
  3677. instance.render = render;
  3678. }
  3679. if (inheritAttrs != null) {
  3680. instance.inheritAttrs = inheritAttrs;
  3681. }
  3682. // asset options.
  3683. if (components)
  3684. instance.components = components;
  3685. if (directives)
  3686. instance.directives = directives;
  3687. }
  3688. function resolveInjections(injectOptions, ctx, checkDuplicateProperties = NOOP, unwrapRef = false) {
  3689. if (isArray(injectOptions)) {
  3690. injectOptions = normalizeInject(injectOptions);
  3691. }
  3692. for (const key in injectOptions) {
  3693. const opt = injectOptions[key];
  3694. let injected;
  3695. if (isObject(opt)) {
  3696. if ('default' in opt) {
  3697. injected = inject(opt.from || key, opt.default, true /* treat default function as factory */);
  3698. }
  3699. else {
  3700. injected = inject(opt.from || key);
  3701. }
  3702. }
  3703. else {
  3704. injected = inject(opt);
  3705. }
  3706. if (isRef(injected)) {
  3707. // TODO remove the check in 3.3
  3708. if (unwrapRef) {
  3709. Object.defineProperty(ctx, key, {
  3710. enumerable: true,
  3711. configurable: true,
  3712. get: () => injected.value,
  3713. set: v => (injected.value = v)
  3714. });
  3715. }
  3716. else {
  3717. {
  3718. warn$1(`injected property "${key}" is a ref and will be auto-unwrapped ` +
  3719. `and no longer needs \`.value\` in the next minor release. ` +
  3720. `To opt-in to the new behavior now, ` +
  3721. `set \`app.config.unwrapInjectedRef = true\` (this config is ` +
  3722. `temporary and will not be needed in the future.)`);
  3723. }
  3724. ctx[key] = injected;
  3725. }
  3726. }
  3727. else {
  3728. ctx[key] = injected;
  3729. }
  3730. {
  3731. checkDuplicateProperties("Inject" /* INJECT */, key);
  3732. }
  3733. }
  3734. }
  3735. function callHook(hook, instance, type) {
  3736. callWithAsyncErrorHandling(isArray(hook)
  3737. ? hook.map(h => h.bind(instance.proxy))
  3738. : hook.bind(instance.proxy), instance, type);
  3739. }
  3740. function createWatcher(raw, ctx, publicThis, key) {
  3741. const getter = key.includes('.')
  3742. ? createPathGetter(publicThis, key)
  3743. : () => publicThis[key];
  3744. if (isString(raw)) {
  3745. const handler = ctx[raw];
  3746. if (isFunction(handler)) {
  3747. watch(getter, handler);
  3748. }
  3749. else {
  3750. warn$1(`Invalid watch handler specified by key "${raw}"`, handler);
  3751. }
  3752. }
  3753. else if (isFunction(raw)) {
  3754. watch(getter, raw.bind(publicThis));
  3755. }
  3756. else if (isObject(raw)) {
  3757. if (isArray(raw)) {
  3758. raw.forEach(r => createWatcher(r, ctx, publicThis, key));
  3759. }
  3760. else {
  3761. const handler = isFunction(raw.handler)
  3762. ? raw.handler.bind(publicThis)
  3763. : ctx[raw.handler];
  3764. if (isFunction(handler)) {
  3765. watch(getter, handler, raw);
  3766. }
  3767. else {
  3768. warn$1(`Invalid watch handler specified by key "${raw.handler}"`, handler);
  3769. }
  3770. }
  3771. }
  3772. else {
  3773. warn$1(`Invalid watch option: "${key}"`, raw);
  3774. }
  3775. }
  3776. /**
  3777. * Resolve merged options and cache it on the component.
  3778. * This is done only once per-component since the merging does not involve
  3779. * instances.
  3780. */
  3781. function resolveMergedOptions(instance) {
  3782. const base = instance.type;
  3783. const { mixins, extends: extendsOptions } = base;
  3784. const { mixins: globalMixins, optionsCache: cache, config: { optionMergeStrategies } } = instance.appContext;
  3785. const cached = cache.get(base);
  3786. let resolved;
  3787. if (cached) {
  3788. resolved = cached;
  3789. }
  3790. else if (!globalMixins.length && !mixins && !extendsOptions) {
  3791. {
  3792. resolved = base;
  3793. }
  3794. }
  3795. else {
  3796. resolved = {};
  3797. if (globalMixins.length) {
  3798. globalMixins.forEach(m => mergeOptions(resolved, m, optionMergeStrategies, true));
  3799. }
  3800. mergeOptions(resolved, base, optionMergeStrategies);
  3801. }
  3802. cache.set(base, resolved);
  3803. return resolved;
  3804. }
  3805. function mergeOptions(to, from, strats, asMixin = false) {
  3806. const { mixins, extends: extendsOptions } = from;
  3807. if (extendsOptions) {
  3808. mergeOptions(to, extendsOptions, strats, true);
  3809. }
  3810. if (mixins) {
  3811. mixins.forEach((m) => mergeOptions(to, m, strats, true));
  3812. }
  3813. for (const key in from) {
  3814. if (asMixin && key === 'expose') {
  3815. warn$1(`"expose" option is ignored when declared in mixins or extends. ` +
  3816. `It should only be declared in the base component itself.`);
  3817. }
  3818. else {
  3819. const strat = internalOptionMergeStrats[key] || (strats && strats[key]);
  3820. to[key] = strat ? strat(to[key], from[key]) : from[key];
  3821. }
  3822. }
  3823. return to;
  3824. }
  3825. const internalOptionMergeStrats = {
  3826. data: mergeDataFn,
  3827. props: mergeObjectOptions,
  3828. emits: mergeObjectOptions,
  3829. // objects
  3830. methods: mergeObjectOptions,
  3831. computed: mergeObjectOptions,
  3832. // lifecycle
  3833. beforeCreate: mergeAsArray,
  3834. created: mergeAsArray,
  3835. beforeMount: mergeAsArray,
  3836. mounted: mergeAsArray,
  3837. beforeUpdate: mergeAsArray,
  3838. updated: mergeAsArray,
  3839. beforeDestroy: mergeAsArray,
  3840. beforeUnmount: mergeAsArray,
  3841. destroyed: mergeAsArray,
  3842. unmounted: mergeAsArray,
  3843. activated: mergeAsArray,
  3844. deactivated: mergeAsArray,
  3845. errorCaptured: mergeAsArray,
  3846. serverPrefetch: mergeAsArray,
  3847. // assets
  3848. components: mergeObjectOptions,
  3849. directives: mergeObjectOptions,
  3850. // watch
  3851. watch: mergeWatchOptions,
  3852. // provide / inject
  3853. provide: mergeDataFn,
  3854. inject: mergeInject
  3855. };
  3856. function mergeDataFn(to, from) {
  3857. if (!from) {
  3858. return to;
  3859. }
  3860. if (!to) {
  3861. return from;
  3862. }
  3863. return function mergedDataFn() {
  3864. return (extend)(isFunction(to) ? to.call(this, this) : to, isFunction(from) ? from.call(this, this) : from);
  3865. };
  3866. }
  3867. function mergeInject(to, from) {
  3868. return mergeObjectOptions(normalizeInject(to), normalizeInject(from));
  3869. }
  3870. function normalizeInject(raw) {
  3871. if (isArray(raw)) {
  3872. const res = {};
  3873. for (let i = 0; i < raw.length; i++) {
  3874. res[raw[i]] = raw[i];
  3875. }
  3876. return res;
  3877. }
  3878. return raw;
  3879. }
  3880. function mergeAsArray(to, from) {
  3881. return to ? [...new Set([].concat(to, from))] : from;
  3882. }
  3883. function mergeObjectOptions(to, from) {
  3884. return to ? extend(extend(Object.create(null), to), from) : from;
  3885. }
  3886. function mergeWatchOptions(to, from) {
  3887. if (!to)
  3888. return from;
  3889. if (!from)
  3890. return to;
  3891. const merged = extend(Object.create(null), to);
  3892. for (const key in from) {
  3893. merged[key] = mergeAsArray(to[key], from[key]);
  3894. }
  3895. return merged;
  3896. }
  3897. function initProps(instance, rawProps, isStateful, // result of bitwise flag comparison
  3898. isSSR = false) {
  3899. const props = {};
  3900. const attrs = {};
  3901. def(attrs, InternalObjectKey, 1);
  3902. instance.propsDefaults = Object.create(null);
  3903. setFullProps(instance, rawProps, props, attrs);
  3904. // ensure all declared prop keys are present
  3905. for (const key in instance.propsOptions[0]) {
  3906. if (!(key in props)) {
  3907. props[key] = undefined;
  3908. }
  3909. }
  3910. // validation
  3911. {
  3912. validateProps(rawProps || {}, props, instance);
  3913. }
  3914. if (isStateful) {
  3915. // stateful
  3916. instance.props = isSSR ? props : shallowReactive(props);
  3917. }
  3918. else {
  3919. if (!instance.type.props) {
  3920. // functional w/ optional props, props === attrs
  3921. instance.props = attrs;
  3922. }
  3923. else {
  3924. // functional w/ declared props
  3925. instance.props = props;
  3926. }
  3927. }
  3928. instance.attrs = attrs;
  3929. }
  3930. function updateProps(instance, rawProps, rawPrevProps, optimized) {
  3931. const { props, attrs, vnode: { patchFlag } } = instance;
  3932. const rawCurrentProps = toRaw(props);
  3933. const [options] = instance.propsOptions;
  3934. let hasAttrsChanged = false;
  3935. if (
  3936. // always force full diff in dev
  3937. // - #1942 if hmr is enabled with sfc component
  3938. // - vite#872 non-sfc component used by sfc component
  3939. !((instance.type.__hmrId ||
  3940. (instance.parent && instance.parent.type.__hmrId))) &&
  3941. (optimized || patchFlag > 0) &&
  3942. !(patchFlag & 16 /* FULL_PROPS */)) {
  3943. if (patchFlag & 8 /* PROPS */) {
  3944. // Compiler-generated props & no keys change, just set the updated
  3945. // the props.
  3946. const propsToUpdate = instance.vnode.dynamicProps;
  3947. for (let i = 0; i < propsToUpdate.length; i++) {
  3948. let key = propsToUpdate[i];
  3949. // PROPS flag guarantees rawProps to be non-null
  3950. const value = rawProps[key];
  3951. if (options) {
  3952. // attr / props separation was done on init and will be consistent
  3953. // in this code path, so just check if attrs have it.
  3954. if (hasOwn(attrs, key)) {
  3955. if (value !== attrs[key]) {
  3956. attrs[key] = value;
  3957. hasAttrsChanged = true;
  3958. }
  3959. }
  3960. else {
  3961. const camelizedKey = camelize(key);
  3962. props[camelizedKey] = resolvePropValue(options, rawCurrentProps, camelizedKey, value, instance, false /* isAbsent */);
  3963. }
  3964. }
  3965. else {
  3966. if (value !== attrs[key]) {
  3967. attrs[key] = value;
  3968. hasAttrsChanged = true;
  3969. }
  3970. }
  3971. }
  3972. }
  3973. }
  3974. else {
  3975. // full props update.
  3976. if (setFullProps(instance, rawProps, props, attrs)) {
  3977. hasAttrsChanged = true;
  3978. }
  3979. // in case of dynamic props, check if we need to delete keys from
  3980. // the props object
  3981. let kebabKey;
  3982. for (const key in rawCurrentProps) {
  3983. if (!rawProps ||
  3984. // for camelCase
  3985. (!hasOwn(rawProps, key) &&
  3986. // it's possible the original props was passed in as kebab-case
  3987. // and converted to camelCase (#955)
  3988. ((kebabKey = hyphenate(key)) === key || !hasOwn(rawProps, kebabKey)))) {
  3989. if (options) {
  3990. if (rawPrevProps &&
  3991. // for camelCase
  3992. (rawPrevProps[key] !== undefined ||
  3993. // for kebab-case
  3994. rawPrevProps[kebabKey] !== undefined)) {
  3995. props[key] = resolvePropValue(options, rawCurrentProps, key, undefined, instance, true /* isAbsent */);
  3996. }
  3997. }
  3998. else {
  3999. delete props[key];
  4000. }
  4001. }
  4002. }
  4003. // in the case of functional component w/o props declaration, props and
  4004. // attrs point to the same object so it should already have been updated.
  4005. if (attrs !== rawCurrentProps) {
  4006. for (const key in attrs) {
  4007. if (!rawProps || !hasOwn(rawProps, key)) {
  4008. delete attrs[key];
  4009. hasAttrsChanged = true;
  4010. }
  4011. }
  4012. }
  4013. }
  4014. // trigger updates for $attrs in case it's used in component slots
  4015. if (hasAttrsChanged) {
  4016. trigger(instance, "set" /* SET */, '$attrs');
  4017. }
  4018. {
  4019. validateProps(rawProps || {}, props, instance);
  4020. }
  4021. }
  4022. function setFullProps(instance, rawProps, props, attrs) {
  4023. const [options, needCastKeys] = instance.propsOptions;
  4024. let hasAttrsChanged = false;
  4025. let rawCastValues;
  4026. if (rawProps) {
  4027. for (let key in rawProps) {
  4028. // key, ref are reserved and never passed down
  4029. if (isReservedProp(key)) {
  4030. continue;
  4031. }
  4032. const value = rawProps[key];
  4033. // prop option names are camelized during normalization, so to support
  4034. // kebab -> camel conversion here we need to camelize the key.
  4035. let camelKey;
  4036. if (options && hasOwn(options, (camelKey = camelize(key)))) {
  4037. if (!needCastKeys || !needCastKeys.includes(camelKey)) {
  4038. props[camelKey] = value;
  4039. }
  4040. else {
  4041. (rawCastValues || (rawCastValues = {}))[camelKey] = value;
  4042. }
  4043. }
  4044. else if (!isEmitListener(instance.emitsOptions, key)) {
  4045. if (!(key in attrs) || value !== attrs[key]) {
  4046. attrs[key] = value;
  4047. hasAttrsChanged = true;
  4048. }
  4049. }
  4050. }
  4051. }
  4052. if (needCastKeys) {
  4053. const rawCurrentProps = toRaw(props);
  4054. const castValues = rawCastValues || EMPTY_OBJ;
  4055. for (let i = 0; i < needCastKeys.length; i++) {
  4056. const key = needCastKeys[i];
  4057. props[key] = resolvePropValue(options, rawCurrentProps, key, castValues[key], instance, !hasOwn(castValues, key));
  4058. }
  4059. }
  4060. return hasAttrsChanged;
  4061. }
  4062. function resolvePropValue(options, props, key, value, instance, isAbsent) {
  4063. const opt = options[key];
  4064. if (opt != null) {
  4065. const hasDefault = hasOwn(opt, 'default');
  4066. // default values
  4067. if (hasDefault && value === undefined) {
  4068. const defaultValue = opt.default;
  4069. if (opt.type !== Function && isFunction(defaultValue)) {
  4070. const { propsDefaults } = instance;
  4071. if (key in propsDefaults) {
  4072. value = propsDefaults[key];
  4073. }
  4074. else {
  4075. setCurrentInstance(instance);
  4076. value = propsDefaults[key] = defaultValue.call(null, props);
  4077. unsetCurrentInstance();
  4078. }
  4079. }
  4080. else {
  4081. value = defaultValue;
  4082. }
  4083. }
  4084. // boolean casting
  4085. if (opt[0 /* shouldCast */]) {
  4086. if (isAbsent && !hasDefault) {
  4087. value = false;
  4088. }
  4089. else if (opt[1 /* shouldCastTrue */] &&
  4090. (value === '' || value === hyphenate(key))) {
  4091. value = true;
  4092. }
  4093. }
  4094. }
  4095. return value;
  4096. }
  4097. function normalizePropsOptions(comp, appContext, asMixin = false) {
  4098. const cache = appContext.propsCache;
  4099. const cached = cache.get(comp);
  4100. if (cached) {
  4101. return cached;
  4102. }
  4103. const raw = comp.props;
  4104. const normalized = {};
  4105. const needCastKeys = [];
  4106. // apply mixin/extends props
  4107. let hasExtends = false;
  4108. if (!isFunction(comp)) {
  4109. const extendProps = (raw) => {
  4110. hasExtends = true;
  4111. const [props, keys] = normalizePropsOptions(raw, appContext, true);
  4112. extend(normalized, props);
  4113. if (keys)
  4114. needCastKeys.push(...keys);
  4115. };
  4116. if (!asMixin && appContext.mixins.length) {
  4117. appContext.mixins.forEach(extendProps);
  4118. }
  4119. if (comp.extends) {
  4120. extendProps(comp.extends);
  4121. }
  4122. if (comp.mixins) {
  4123. comp.mixins.forEach(extendProps);
  4124. }
  4125. }
  4126. if (!raw && !hasExtends) {
  4127. cache.set(comp, EMPTY_ARR);
  4128. return EMPTY_ARR;
  4129. }
  4130. if (isArray(raw)) {
  4131. for (let i = 0; i < raw.length; i++) {
  4132. if (!isString(raw[i])) {
  4133. warn$1(`props must be strings when using array syntax.`, raw[i]);
  4134. }
  4135. const normalizedKey = camelize(raw[i]);
  4136. if (validatePropName(normalizedKey)) {
  4137. normalized[normalizedKey] = EMPTY_OBJ;
  4138. }
  4139. }
  4140. }
  4141. else if (raw) {
  4142. if (!isObject(raw)) {
  4143. warn$1(`invalid props options`, raw);
  4144. }
  4145. for (const key in raw) {
  4146. const normalizedKey = camelize(key);
  4147. if (validatePropName(normalizedKey)) {
  4148. const opt = raw[key];
  4149. const prop = (normalized[normalizedKey] =
  4150. isArray(opt) || isFunction(opt) ? { type: opt } : opt);
  4151. if (prop) {
  4152. const booleanIndex = getTypeIndex(Boolean, prop.type);
  4153. const stringIndex = getTypeIndex(String, prop.type);
  4154. prop[0 /* shouldCast */] = booleanIndex > -1;
  4155. prop[1 /* shouldCastTrue */] =
  4156. stringIndex < 0 || booleanIndex < stringIndex;
  4157. // if the prop needs boolean casting or default value
  4158. if (booleanIndex > -1 || hasOwn(prop, 'default')) {
  4159. needCastKeys.push(normalizedKey);
  4160. }
  4161. }
  4162. }
  4163. }
  4164. }
  4165. const res = [normalized, needCastKeys];
  4166. cache.set(comp, res);
  4167. return res;
  4168. }
  4169. function validatePropName(key) {
  4170. if (key[0] !== '$') {
  4171. return true;
  4172. }
  4173. else {
  4174. warn$1(`Invalid prop name: "${key}" is a reserved property.`);
  4175. }
  4176. return false;
  4177. }
  4178. // use function string name to check type constructors
  4179. // so that it works across vms / iframes.
  4180. function getType(ctor) {
  4181. const match = ctor && ctor.toString().match(/^\s*function (\w+)/);
  4182. return match ? match[1] : ctor === null ? 'null' : '';
  4183. }
  4184. function isSameType(a, b) {
  4185. return getType(a) === getType(b);
  4186. }
  4187. function getTypeIndex(type, expectedTypes) {
  4188. if (isArray(expectedTypes)) {
  4189. return expectedTypes.findIndex(t => isSameType(t, type));
  4190. }
  4191. else if (isFunction(expectedTypes)) {
  4192. return isSameType(expectedTypes, type) ? 0 : -1;
  4193. }
  4194. return -1;
  4195. }
  4196. /**
  4197. * dev only
  4198. */
  4199. function validateProps(rawProps, props, instance) {
  4200. const resolvedValues = toRaw(props);
  4201. const options = instance.propsOptions[0];
  4202. for (const key in options) {
  4203. let opt = options[key];
  4204. if (opt == null)
  4205. continue;
  4206. validateProp(key, resolvedValues[key], opt, !hasOwn(rawProps, key) && !hasOwn(rawProps, hyphenate(key)));
  4207. }
  4208. }
  4209. /**
  4210. * dev only
  4211. */
  4212. function validateProp(name, value, prop, isAbsent) {
  4213. const { type, required, validator } = prop;
  4214. // required!
  4215. if (required && isAbsent) {
  4216. warn$1('Missing required prop: "' + name + '"');
  4217. return;
  4218. }
  4219. // missing but optional
  4220. if (value == null && !prop.required) {
  4221. return;
  4222. }
  4223. // type check
  4224. if (type != null && type !== true) {
  4225. let isValid = false;
  4226. const types = isArray(type) ? type : [type];
  4227. const expectedTypes = [];
  4228. // value is valid as long as one of the specified types match
  4229. for (let i = 0; i < types.length && !isValid; i++) {
  4230. const { valid, expectedType } = assertType(value, types[i]);
  4231. expectedTypes.push(expectedType || '');
  4232. isValid = valid;
  4233. }
  4234. if (!isValid) {
  4235. warn$1(getInvalidTypeMessage(name, value, expectedTypes));
  4236. return;
  4237. }
  4238. }
  4239. // custom validator
  4240. if (validator && !validator(value)) {
  4241. warn$1('Invalid prop: custom validator check failed for prop "' + name + '".');
  4242. }
  4243. }
  4244. const isSimpleType = /*#__PURE__*/ makeMap('String,Number,Boolean,Function,Symbol,BigInt');
  4245. /**
  4246. * dev only
  4247. */
  4248. function assertType(value, type) {
  4249. let valid;
  4250. const expectedType = getType(type);
  4251. if (isSimpleType(expectedType)) {
  4252. const t = typeof value;
  4253. valid = t === expectedType.toLowerCase();
  4254. // for primitive wrapper objects
  4255. if (!valid && t === 'object') {
  4256. valid = value instanceof type;
  4257. }
  4258. }
  4259. else if (expectedType === 'Object') {
  4260. valid = isObject(value);
  4261. }
  4262. else if (expectedType === 'Array') {
  4263. valid = isArray(value);
  4264. }
  4265. else if (expectedType === 'null') {
  4266. valid = value === null;
  4267. }
  4268. else {
  4269. valid = value instanceof type;
  4270. }
  4271. return {
  4272. valid,
  4273. expectedType
  4274. };
  4275. }
  4276. /**
  4277. * dev only
  4278. */
  4279. function getInvalidTypeMessage(name, value, expectedTypes) {
  4280. let message = `Invalid prop: type check failed for prop "${name}".` +
  4281. ` Expected ${expectedTypes.map(capitalize).join(' | ')}`;
  4282. const expectedType = expectedTypes[0];
  4283. const receivedType = toRawType(value);
  4284. const expectedValue = styleValue(value, expectedType);
  4285. const receivedValue = styleValue(value, receivedType);
  4286. // check if we need to specify expected value
  4287. if (expectedTypes.length === 1 &&
  4288. isExplicable(expectedType) &&
  4289. !isBoolean(expectedType, receivedType)) {
  4290. message += ` with value ${expectedValue}`;
  4291. }
  4292. message += `, got ${receivedType} `;
  4293. // check if we need to specify received value
  4294. if (isExplicable(receivedType)) {
  4295. message += `with value ${receivedValue}.`;
  4296. }
  4297. return message;
  4298. }
  4299. /**
  4300. * dev only
  4301. */
  4302. function styleValue(value, type) {
  4303. if (type === 'String') {
  4304. return `"${value}"`;
  4305. }
  4306. else if (type === 'Number') {
  4307. return `${Number(value)}`;
  4308. }
  4309. else {
  4310. return `${value}`;
  4311. }
  4312. }
  4313. /**
  4314. * dev only
  4315. */
  4316. function isExplicable(type) {
  4317. const explicitTypes = ['string', 'number', 'boolean'];
  4318. return explicitTypes.some(elem => type.toLowerCase() === elem);
  4319. }
  4320. /**
  4321. * dev only
  4322. */
  4323. function isBoolean(...args) {
  4324. return args.some(elem => elem.toLowerCase() === 'boolean');
  4325. }
  4326. const isInternalKey = (key) => key[0] === '_' || key === '$stable';
  4327. const normalizeSlotValue = (value) => isArray(value)
  4328. ? value.map(normalizeVNode)
  4329. : [normalizeVNode(value)];
  4330. const normalizeSlot = (key, rawSlot, ctx) => {
  4331. const normalized = withCtx((...args) => {
  4332. if (currentInstance) {
  4333. warn$1(`Slot "${key}" invoked outside of the render function: ` +
  4334. `this will not track dependencies used in the slot. ` +
  4335. `Invoke the slot function inside the render function instead.`);
  4336. }
  4337. return normalizeSlotValue(rawSlot(...args));
  4338. }, ctx);
  4339. normalized._c = false;
  4340. return normalized;
  4341. };
  4342. const normalizeObjectSlots = (rawSlots, slots, instance) => {
  4343. const ctx = rawSlots._ctx;
  4344. for (const key in rawSlots) {
  4345. if (isInternalKey(key))
  4346. continue;
  4347. const value = rawSlots[key];
  4348. if (isFunction(value)) {
  4349. slots[key] = normalizeSlot(key, value, ctx);
  4350. }
  4351. else if (value != null) {
  4352. {
  4353. warn$1(`Non-function value encountered for slot "${key}". ` +
  4354. `Prefer function slots for better performance.`);
  4355. }
  4356. const normalized = normalizeSlotValue(value);
  4357. slots[key] = () => normalized;
  4358. }
  4359. }
  4360. };
  4361. const normalizeVNodeSlots = (instance, children) => {
  4362. if (!isKeepAlive(instance.vnode) &&
  4363. !(false )) {
  4364. warn$1(`Non-function value encountered for default slot. ` +
  4365. `Prefer function slots for better performance.`);
  4366. }
  4367. const normalized = normalizeSlotValue(children);
  4368. instance.slots.default = () => normalized;
  4369. };
  4370. const initSlots = (instance, children) => {
  4371. if (instance.vnode.shapeFlag & 32 /* SLOTS_CHILDREN */) {
  4372. const type = children._;
  4373. if (type) {
  4374. // users can get the shallow readonly version of the slots object through `this.$slots`,
  4375. // we should avoid the proxy object polluting the slots of the internal instance
  4376. instance.slots = toRaw(children);
  4377. // make compiler marker non-enumerable
  4378. def(children, '_', type);
  4379. }
  4380. else {
  4381. normalizeObjectSlots(children, (instance.slots = {}));
  4382. }
  4383. }
  4384. else {
  4385. instance.slots = {};
  4386. if (children) {
  4387. normalizeVNodeSlots(instance, children);
  4388. }
  4389. }
  4390. def(instance.slots, InternalObjectKey, 1);
  4391. };
  4392. const updateSlots = (instance, children, optimized) => {
  4393. const { vnode, slots } = instance;
  4394. let needDeletionCheck = true;
  4395. let deletionComparisonTarget = EMPTY_OBJ;
  4396. if (vnode.shapeFlag & 32 /* SLOTS_CHILDREN */) {
  4397. const type = children._;
  4398. if (type) {
  4399. // compiled slots.
  4400. if (isHmrUpdating) {
  4401. // Parent was HMR updated so slot content may have changed.
  4402. // force update slots and mark instance for hmr as well
  4403. extend(slots, children);
  4404. }
  4405. else if (optimized && type === 1 /* STABLE */) {
  4406. // compiled AND stable.
  4407. // no need to update, and skip stale slots removal.
  4408. needDeletionCheck = false;
  4409. }
  4410. else {
  4411. // compiled but dynamic (v-if/v-for on slots) - update slots, but skip
  4412. // normalization.
  4413. extend(slots, children);
  4414. // #2893
  4415. // when rendering the optimized slots by manually written render function,
  4416. // we need to delete the `slots._` flag if necessary to make subsequent updates reliable,
  4417. // i.e. let the `renderSlot` create the bailed Fragment
  4418. if (!optimized && type === 1 /* STABLE */) {
  4419. delete slots._;
  4420. }
  4421. }
  4422. }
  4423. else {
  4424. needDeletionCheck = !children.$stable;
  4425. normalizeObjectSlots(children, slots);
  4426. }
  4427. deletionComparisonTarget = children;
  4428. }
  4429. else if (children) {
  4430. // non slot object children (direct value) passed to a component
  4431. normalizeVNodeSlots(instance, children);
  4432. deletionComparisonTarget = { default: 1 };
  4433. }
  4434. // delete stale slots
  4435. if (needDeletionCheck) {
  4436. for (const key in slots) {
  4437. if (!isInternalKey(key) && !(key in deletionComparisonTarget)) {
  4438. delete slots[key];
  4439. }
  4440. }
  4441. }
  4442. };
  4443. /**
  4444. Runtime helper for applying directives to a vnode. Example usage:
  4445. const comp = resolveComponent('comp')
  4446. const foo = resolveDirective('foo')
  4447. const bar = resolveDirective('bar')
  4448. return withDirectives(h(comp), [
  4449. [foo, this.x],
  4450. [bar, this.y]
  4451. ])
  4452. */
  4453. const isBuiltInDirective = /*#__PURE__*/ makeMap('bind,cloak,else-if,else,for,html,if,model,on,once,pre,show,slot,text,memo');
  4454. function validateDirectiveName(name) {
  4455. if (isBuiltInDirective(name)) {
  4456. warn$1('Do not use built-in directive ids as custom directive id: ' + name);
  4457. }
  4458. }
  4459. /**
  4460. * Adds directives to a VNode.
  4461. */
  4462. function withDirectives(vnode, directives) {
  4463. const internalInstance = currentRenderingInstance;
  4464. if (internalInstance === null) {
  4465. warn$1(`withDirectives can only be used inside render functions.`);
  4466. return vnode;
  4467. }
  4468. const instance = internalInstance.proxy;
  4469. const bindings = vnode.dirs || (vnode.dirs = []);
  4470. for (let i = 0; i < directives.length; i++) {
  4471. let [dir, value, arg, modifiers = EMPTY_OBJ] = directives[i];
  4472. if (isFunction(dir)) {
  4473. dir = {
  4474. mounted: dir,
  4475. updated: dir
  4476. };
  4477. }
  4478. if (dir.deep) {
  4479. traverse(value);
  4480. }
  4481. bindings.push({
  4482. dir,
  4483. instance,
  4484. value,
  4485. oldValue: void 0,
  4486. arg,
  4487. modifiers
  4488. });
  4489. }
  4490. return vnode;
  4491. }
  4492. function invokeDirectiveHook(vnode, prevVNode, instance, name) {
  4493. const bindings = vnode.dirs;
  4494. const oldBindings = prevVNode && prevVNode.dirs;
  4495. for (let i = 0; i < bindings.length; i++) {
  4496. const binding = bindings[i];
  4497. if (oldBindings) {
  4498. binding.oldValue = oldBindings[i].value;
  4499. }
  4500. let hook = binding.dir[name];
  4501. if (hook) {
  4502. // disable tracking inside all lifecycle hooks
  4503. // since they can potentially be called inside effects.
  4504. pauseTracking();
  4505. callWithAsyncErrorHandling(hook, instance, 8 /* DIRECTIVE_HOOK */, [
  4506. vnode.el,
  4507. binding,
  4508. vnode,
  4509. prevVNode
  4510. ]);
  4511. resetTracking();
  4512. }
  4513. }
  4514. }
  4515. function createAppContext() {
  4516. return {
  4517. app: null,
  4518. config: {
  4519. isNativeTag: NO,
  4520. performance: false,
  4521. globalProperties: {},
  4522. optionMergeStrategies: {},
  4523. errorHandler: undefined,
  4524. warnHandler: undefined,
  4525. compilerOptions: {}
  4526. },
  4527. mixins: [],
  4528. components: {},
  4529. directives: {},
  4530. provides: Object.create(null),
  4531. optionsCache: new WeakMap(),
  4532. propsCache: new WeakMap(),
  4533. emitsCache: new WeakMap()
  4534. };
  4535. }
  4536. let uid = 0;
  4537. function createAppAPI(render, hydrate) {
  4538. return function createApp(rootComponent, rootProps = null) {
  4539. if (rootProps != null && !isObject(rootProps)) {
  4540. warn$1(`root props passed to app.mount() must be an object.`);
  4541. rootProps = null;
  4542. }
  4543. const context = createAppContext();
  4544. const installedPlugins = new Set();
  4545. let isMounted = false;
  4546. const app = (context.app = {
  4547. _uid: uid++,
  4548. _component: rootComponent,
  4549. _props: rootProps,
  4550. _container: null,
  4551. _context: context,
  4552. _instance: null,
  4553. version,
  4554. get config() {
  4555. return context.config;
  4556. },
  4557. set config(v) {
  4558. {
  4559. warn$1(`app.config cannot be replaced. Modify individual options instead.`);
  4560. }
  4561. },
  4562. use(plugin, ...options) {
  4563. if (installedPlugins.has(plugin)) {
  4564. warn$1(`Plugin has already been applied to target app.`);
  4565. }
  4566. else if (plugin && isFunction(plugin.install)) {
  4567. installedPlugins.add(plugin);
  4568. plugin.install(app, ...options);
  4569. }
  4570. else if (isFunction(plugin)) {
  4571. installedPlugins.add(plugin);
  4572. plugin(app, ...options);
  4573. }
  4574. else {
  4575. warn$1(`A plugin must either be a function or an object with an "install" ` +
  4576. `function.`);
  4577. }
  4578. return app;
  4579. },
  4580. mixin(mixin) {
  4581. {
  4582. if (!context.mixins.includes(mixin)) {
  4583. context.mixins.push(mixin);
  4584. }
  4585. else {
  4586. warn$1('Mixin has already been applied to target app' +
  4587. (mixin.name ? `: ${mixin.name}` : ''));
  4588. }
  4589. }
  4590. return app;
  4591. },
  4592. component(name, component) {
  4593. {
  4594. validateComponentName(name, context.config);
  4595. }
  4596. if (!component) {
  4597. return context.components[name];
  4598. }
  4599. if (context.components[name]) {
  4600. warn$1(`Component "${name}" has already been registered in target app.`);
  4601. }
  4602. context.components[name] = component;
  4603. return app;
  4604. },
  4605. directive(name, directive) {
  4606. {
  4607. validateDirectiveName(name);
  4608. }
  4609. if (!directive) {
  4610. return context.directives[name];
  4611. }
  4612. if (context.directives[name]) {
  4613. warn$1(`Directive "${name}" has already been registered in target app.`);
  4614. }
  4615. context.directives[name] = directive;
  4616. return app;
  4617. },
  4618. mount(rootContainer, isHydrate, isSVG) {
  4619. if (!isMounted) {
  4620. const vnode = createVNode(rootComponent, rootProps);
  4621. // store app context on the root VNode.
  4622. // this will be set on the root instance on initial mount.
  4623. vnode.appContext = context;
  4624. // HMR root reload
  4625. {
  4626. context.reload = () => {
  4627. render(cloneVNode(vnode), rootContainer, isSVG);
  4628. };
  4629. }
  4630. if (isHydrate && hydrate) {
  4631. hydrate(vnode, rootContainer);
  4632. }
  4633. else {
  4634. render(vnode, rootContainer, isSVG);
  4635. }
  4636. isMounted = true;
  4637. app._container = rootContainer;
  4638. rootContainer.__vue_app__ = app;
  4639. {
  4640. app._instance = vnode.component;
  4641. devtoolsInitApp(app, version);
  4642. }
  4643. return getExposeProxy(vnode.component) || vnode.component.proxy;
  4644. }
  4645. else {
  4646. warn$1(`App has already been mounted.\n` +
  4647. `If you want to remount the same app, move your app creation logic ` +
  4648. `into a factory function and create fresh app instances for each ` +
  4649. `mount - e.g. \`const createMyApp = () => createApp(App)\``);
  4650. }
  4651. },
  4652. unmount() {
  4653. if (isMounted) {
  4654. render(null, app._container);
  4655. {
  4656. app._instance = null;
  4657. devtoolsUnmountApp(app);
  4658. }
  4659. delete app._container.__vue_app__;
  4660. }
  4661. else {
  4662. warn$1(`Cannot unmount an app that is not mounted.`);
  4663. }
  4664. },
  4665. provide(key, value) {
  4666. if (key in context.provides) {
  4667. warn$1(`App already provides property with key "${String(key)}". ` +
  4668. `It will be overwritten with the new value.`);
  4669. }
  4670. // TypeScript doesn't allow symbols as index type
  4671. // https://github.com/Microsoft/TypeScript/issues/24587
  4672. context.provides[key] = value;
  4673. return app;
  4674. }
  4675. });
  4676. return app;
  4677. };
  4678. }
  4679. /**
  4680. * Function for handling a template ref
  4681. */
  4682. function setRef(rawRef, oldRawRef, parentSuspense, vnode, isUnmount = false) {
  4683. if (isArray(rawRef)) {
  4684. rawRef.forEach((r, i) => setRef(r, oldRawRef && (isArray(oldRawRef) ? oldRawRef[i] : oldRawRef), parentSuspense, vnode, isUnmount));
  4685. return;
  4686. }
  4687. if (isAsyncWrapper(vnode) && !isUnmount) {
  4688. // when mounting async components, nothing needs to be done,
  4689. // because the template ref is forwarded to inner component
  4690. return;
  4691. }
  4692. const refValue = vnode.shapeFlag & 4 /* STATEFUL_COMPONENT */
  4693. ? getExposeProxy(vnode.component) || vnode.component.proxy
  4694. : vnode.el;
  4695. const value = isUnmount ? null : refValue;
  4696. const { i: owner, r: ref } = rawRef;
  4697. if (!owner) {
  4698. warn$1(`Missing ref owner context. ref cannot be used on hoisted vnodes. ` +
  4699. `A vnode with ref must be created inside the render function.`);
  4700. return;
  4701. }
  4702. const oldRef = oldRawRef && oldRawRef.r;
  4703. const refs = owner.refs === EMPTY_OBJ ? (owner.refs = {}) : owner.refs;
  4704. const setupState = owner.setupState;
  4705. // dynamic ref changed. unset old ref
  4706. if (oldRef != null && oldRef !== ref) {
  4707. if (isString(oldRef)) {
  4708. refs[oldRef] = null;
  4709. if (hasOwn(setupState, oldRef)) {
  4710. setupState[oldRef] = null;
  4711. }
  4712. }
  4713. else if (isRef(oldRef)) {
  4714. oldRef.value = null;
  4715. }
  4716. }
  4717. if (isFunction(ref)) {
  4718. callWithErrorHandling(ref, owner, 12 /* FUNCTION_REF */, [value, refs]);
  4719. }
  4720. else {
  4721. const _isString = isString(ref);
  4722. const _isRef = isRef(ref);
  4723. if (_isString || _isRef) {
  4724. const doSet = () => {
  4725. if (rawRef.f) {
  4726. const existing = _isString ? refs[ref] : ref.value;
  4727. if (isUnmount) {
  4728. isArray(existing) && remove(existing, refValue);
  4729. }
  4730. else {
  4731. if (!isArray(existing)) {
  4732. if (_isString) {
  4733. refs[ref] = [refValue];
  4734. }
  4735. else {
  4736. ref.value = [refValue];
  4737. if (rawRef.k)
  4738. refs[rawRef.k] = ref.value;
  4739. }
  4740. }
  4741. else if (!existing.includes(refValue)) {
  4742. existing.push(refValue);
  4743. }
  4744. }
  4745. }
  4746. else if (_isString) {
  4747. refs[ref] = value;
  4748. if (hasOwn(setupState, ref)) {
  4749. setupState[ref] = value;
  4750. }
  4751. }
  4752. else if (isRef(ref)) {
  4753. ref.value = value;
  4754. if (rawRef.k)
  4755. refs[rawRef.k] = value;
  4756. }
  4757. else {
  4758. warn$1('Invalid template ref type:', ref, `(${typeof ref})`);
  4759. }
  4760. };
  4761. if (value) {
  4762. doSet.id = -1;
  4763. queuePostRenderEffect(doSet, parentSuspense);
  4764. }
  4765. else {
  4766. doSet();
  4767. }
  4768. }
  4769. else {
  4770. warn$1('Invalid template ref type:', ref, `(${typeof ref})`);
  4771. }
  4772. }
  4773. }
  4774. let hasMismatch = false;
  4775. const isSVGContainer = (container) => /svg/.test(container.namespaceURI) && container.tagName !== 'foreignObject';
  4776. const isComment = (node) => node.nodeType === 8 /* COMMENT */;
  4777. // Note: hydration is DOM-specific
  4778. // But we have to place it in core due to tight coupling with core - splitting
  4779. // it out creates a ton of unnecessary complexity.
  4780. // Hydration also depends on some renderer internal logic which needs to be
  4781. // passed in via arguments.
  4782. function createHydrationFunctions(rendererInternals) {
  4783. const { mt: mountComponent, p: patch, o: { patchProp, nextSibling, parentNode, remove, insert, createComment } } = rendererInternals;
  4784. const hydrate = (vnode, container) => {
  4785. if (!container.hasChildNodes()) {
  4786. warn$1(`Attempting to hydrate existing markup but container is empty. ` +
  4787. `Performing full mount instead.`);
  4788. patch(null, vnode, container);
  4789. flushPostFlushCbs();
  4790. return;
  4791. }
  4792. hasMismatch = false;
  4793. hydrateNode(container.firstChild, vnode, null, null, null);
  4794. flushPostFlushCbs();
  4795. if (hasMismatch && !false) {
  4796. // this error should show up in production
  4797. console.error(`Hydration completed but contains mismatches.`);
  4798. }
  4799. };
  4800. const hydrateNode = (node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized = false) => {
  4801. const isFragmentStart = isComment(node) && node.data === '[';
  4802. const onMismatch = () => handleMismatch(node, vnode, parentComponent, parentSuspense, slotScopeIds, isFragmentStart);
  4803. const { type, ref, shapeFlag } = vnode;
  4804. const domType = node.nodeType;
  4805. vnode.el = node;
  4806. let nextNode = null;
  4807. switch (type) {
  4808. case Text:
  4809. if (domType !== 3 /* TEXT */) {
  4810. nextNode = onMismatch();
  4811. }
  4812. else {
  4813. if (node.data !== vnode.children) {
  4814. hasMismatch = true;
  4815. warn$1(`Hydration text mismatch:` +
  4816. `\n- Client: ${JSON.stringify(node.data)}` +
  4817. `\n- Server: ${JSON.stringify(vnode.children)}`);
  4818. node.data = vnode.children;
  4819. }
  4820. nextNode = nextSibling(node);
  4821. }
  4822. break;
  4823. case Comment:
  4824. if (domType !== 8 /* COMMENT */ || isFragmentStart) {
  4825. nextNode = onMismatch();
  4826. }
  4827. else {
  4828. nextNode = nextSibling(node);
  4829. }
  4830. break;
  4831. case Static:
  4832. if (domType !== 1 /* ELEMENT */) {
  4833. nextNode = onMismatch();
  4834. }
  4835. else {
  4836. // determine anchor, adopt content
  4837. nextNode = node;
  4838. // if the static vnode has its content stripped during build,
  4839. // adopt it from the server-rendered HTML.
  4840. const needToAdoptContent = !vnode.children.length;
  4841. for (let i = 0; i < vnode.staticCount; i++) {
  4842. if (needToAdoptContent)
  4843. vnode.children += nextNode.outerHTML;
  4844. if (i === vnode.staticCount - 1) {
  4845. vnode.anchor = nextNode;
  4846. }
  4847. nextNode = nextSibling(nextNode);
  4848. }
  4849. return nextNode;
  4850. }
  4851. break;
  4852. case Fragment:
  4853. if (!isFragmentStart) {
  4854. nextNode = onMismatch();
  4855. }
  4856. else {
  4857. nextNode = hydrateFragment(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized);
  4858. }
  4859. break;
  4860. default:
  4861. if (shapeFlag & 1 /* ELEMENT */) {
  4862. if (domType !== 1 /* ELEMENT */ ||
  4863. vnode.type.toLowerCase() !==
  4864. node.tagName.toLowerCase()) {
  4865. nextNode = onMismatch();
  4866. }
  4867. else {
  4868. nextNode = hydrateElement(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized);
  4869. }
  4870. }
  4871. else if (shapeFlag & 6 /* COMPONENT */) {
  4872. // when setting up the render effect, if the initial vnode already
  4873. // has .el set, the component will perform hydration instead of mount
  4874. // on its sub-tree.
  4875. vnode.slotScopeIds = slotScopeIds;
  4876. const container = parentNode(node);
  4877. mountComponent(vnode, container, null, parentComponent, parentSuspense, isSVGContainer(container), optimized);
  4878. // component may be async, so in the case of fragments we cannot rely
  4879. // on component's rendered output to determine the end of the fragment
  4880. // instead, we do a lookahead to find the end anchor node.
  4881. nextNode = isFragmentStart
  4882. ? locateClosingAsyncAnchor(node)
  4883. : nextSibling(node);
  4884. // #3787
  4885. // if component is async, it may get moved / unmounted before its
  4886. // inner component is loaded, so we need to give it a placeholder
  4887. // vnode that matches its adopted DOM.
  4888. if (isAsyncWrapper(vnode)) {
  4889. let subTree;
  4890. if (isFragmentStart) {
  4891. subTree = createVNode(Fragment);
  4892. subTree.anchor = nextNode
  4893. ? nextNode.previousSibling
  4894. : container.lastChild;
  4895. }
  4896. else {
  4897. subTree =
  4898. node.nodeType === 3 ? createTextVNode('') : createVNode('div');
  4899. }
  4900. subTree.el = node;
  4901. vnode.component.subTree = subTree;
  4902. }
  4903. }
  4904. else if (shapeFlag & 64 /* TELEPORT */) {
  4905. if (domType !== 8 /* COMMENT */) {
  4906. nextNode = onMismatch();
  4907. }
  4908. else {
  4909. nextNode = vnode.type.hydrate(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized, rendererInternals, hydrateChildren);
  4910. }
  4911. }
  4912. else if (shapeFlag & 128 /* SUSPENSE */) {
  4913. nextNode = vnode.type.hydrate(node, vnode, parentComponent, parentSuspense, isSVGContainer(parentNode(node)), slotScopeIds, optimized, rendererInternals, hydrateNode);
  4914. }
  4915. else {
  4916. warn$1('Invalid HostVNode type:', type, `(${typeof type})`);
  4917. }
  4918. }
  4919. if (ref != null) {
  4920. setRef(ref, null, parentSuspense, vnode);
  4921. }
  4922. return nextNode;
  4923. };
  4924. const hydrateElement = (el, vnode, parentComponent, parentSuspense, slotScopeIds, optimized) => {
  4925. optimized = optimized || !!vnode.dynamicChildren;
  4926. const { type, props, patchFlag, shapeFlag, dirs } = vnode;
  4927. // #4006 for form elements with non-string v-model value bindings
  4928. // e.g. <option :value="obj">, <input type="checkbox" :true-value="1">
  4929. const forcePatchValue = (type === 'input' && dirs) || type === 'option';
  4930. // skip props & children if this is hoisted static nodes
  4931. if (forcePatchValue || patchFlag !== -1 /* HOISTED */) {
  4932. if (dirs) {
  4933. invokeDirectiveHook(vnode, null, parentComponent, 'created');
  4934. }
  4935. // props
  4936. if (props) {
  4937. if (forcePatchValue ||
  4938. !optimized ||
  4939. patchFlag & (16 /* FULL_PROPS */ | 32 /* HYDRATE_EVENTS */)) {
  4940. for (const key in props) {
  4941. if ((forcePatchValue && key.endsWith('value')) ||
  4942. (isOn(key) && !isReservedProp(key))) {
  4943. patchProp(el, key, null, props[key], false, undefined, parentComponent);
  4944. }
  4945. }
  4946. }
  4947. else if (props.onClick) {
  4948. // Fast path for click listeners (which is most often) to avoid
  4949. // iterating through props.
  4950. patchProp(el, 'onClick', null, props.onClick, false, undefined, parentComponent);
  4951. }
  4952. }
  4953. // vnode / directive hooks
  4954. let vnodeHooks;
  4955. if ((vnodeHooks = props && props.onVnodeBeforeMount)) {
  4956. invokeVNodeHook(vnodeHooks, parentComponent, vnode);
  4957. }
  4958. if (dirs) {
  4959. invokeDirectiveHook(vnode, null, parentComponent, 'beforeMount');
  4960. }
  4961. if ((vnodeHooks = props && props.onVnodeMounted) || dirs) {
  4962. queueEffectWithSuspense(() => {
  4963. vnodeHooks && invokeVNodeHook(vnodeHooks, parentComponent, vnode);
  4964. dirs && invokeDirectiveHook(vnode, null, parentComponent, 'mounted');
  4965. }, parentSuspense);
  4966. }
  4967. // children
  4968. if (shapeFlag & 16 /* ARRAY_CHILDREN */ &&
  4969. // skip if element has innerHTML / textContent
  4970. !(props && (props.innerHTML || props.textContent))) {
  4971. let next = hydrateChildren(el.firstChild, vnode, el, parentComponent, parentSuspense, slotScopeIds, optimized);
  4972. let hasWarned = false;
  4973. while (next) {
  4974. hasMismatch = true;
  4975. if (!hasWarned) {
  4976. warn$1(`Hydration children mismatch in <${vnode.type}>: ` +
  4977. `server rendered element contains more child nodes than client vdom.`);
  4978. hasWarned = true;
  4979. }
  4980. // The SSRed DOM contains more nodes than it should. Remove them.
  4981. const cur = next;
  4982. next = next.nextSibling;
  4983. remove(cur);
  4984. }
  4985. }
  4986. else if (shapeFlag & 8 /* TEXT_CHILDREN */) {
  4987. if (el.textContent !== vnode.children) {
  4988. hasMismatch = true;
  4989. warn$1(`Hydration text content mismatch in <${vnode.type}>:\n` +
  4990. `- Client: ${el.textContent}\n` +
  4991. `- Server: ${vnode.children}`);
  4992. el.textContent = vnode.children;
  4993. }
  4994. }
  4995. }
  4996. return el.nextSibling;
  4997. };
  4998. const hydrateChildren = (node, parentVNode, container, parentComponent, parentSuspense, slotScopeIds, optimized) => {
  4999. optimized = optimized || !!parentVNode.dynamicChildren;
  5000. const children = parentVNode.children;
  5001. const l = children.length;
  5002. let hasWarned = false;
  5003. for (let i = 0; i < l; i++) {
  5004. const vnode = optimized
  5005. ? children[i]
  5006. : (children[i] = normalizeVNode(children[i]));
  5007. if (node) {
  5008. node = hydrateNode(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized);
  5009. }
  5010. else if (vnode.type === Text && !vnode.children) {
  5011. continue;
  5012. }
  5013. else {
  5014. hasMismatch = true;
  5015. if (!hasWarned) {
  5016. warn$1(`Hydration children mismatch in <${container.tagName.toLowerCase()}>: ` +
  5017. `server rendered element contains fewer child nodes than client vdom.`);
  5018. hasWarned = true;
  5019. }
  5020. // the SSRed DOM didn't contain enough nodes. Mount the missing ones.
  5021. patch(null, vnode, container, null, parentComponent, parentSuspense, isSVGContainer(container), slotScopeIds);
  5022. }
  5023. }
  5024. return node;
  5025. };
  5026. const hydrateFragment = (node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized) => {
  5027. const { slotScopeIds: fragmentSlotScopeIds } = vnode;
  5028. if (fragmentSlotScopeIds) {
  5029. slotScopeIds = slotScopeIds
  5030. ? slotScopeIds.concat(fragmentSlotScopeIds)
  5031. : fragmentSlotScopeIds;
  5032. }
  5033. const container = parentNode(node);
  5034. const next = hydrateChildren(nextSibling(node), vnode, container, parentComponent, parentSuspense, slotScopeIds, optimized);
  5035. if (next && isComment(next) && next.data === ']') {
  5036. return nextSibling((vnode.anchor = next));
  5037. }
  5038. else {
  5039. // fragment didn't hydrate successfully, since we didn't get a end anchor
  5040. // back. This should have led to node/children mismatch warnings.
  5041. hasMismatch = true;
  5042. // since the anchor is missing, we need to create one and insert it
  5043. insert((vnode.anchor = createComment(`]`)), container, next);
  5044. return next;
  5045. }
  5046. };
  5047. const handleMismatch = (node, vnode, parentComponent, parentSuspense, slotScopeIds, isFragment) => {
  5048. hasMismatch = true;
  5049. warn$1(`Hydration node mismatch:\n- Client vnode:`, vnode.type, `\n- Server rendered DOM:`, node, node.nodeType === 3 /* TEXT */
  5050. ? `(text)`
  5051. : isComment(node) && node.data === '['
  5052. ? `(start of fragment)`
  5053. : ``);
  5054. vnode.el = null;
  5055. if (isFragment) {
  5056. // remove excessive fragment nodes
  5057. const end = locateClosingAsyncAnchor(node);
  5058. while (true) {
  5059. const next = nextSibling(node);
  5060. if (next && next !== end) {
  5061. remove(next);
  5062. }
  5063. else {
  5064. break;
  5065. }
  5066. }
  5067. }
  5068. const next = nextSibling(node);
  5069. const container = parentNode(node);
  5070. remove(node);
  5071. patch(null, vnode, container, next, parentComponent, parentSuspense, isSVGContainer(container), slotScopeIds);
  5072. return next;
  5073. };
  5074. const locateClosingAsyncAnchor = (node) => {
  5075. let match = 0;
  5076. while (node) {
  5077. node = nextSibling(node);
  5078. if (node && isComment(node)) {
  5079. if (node.data === '[')
  5080. match++;
  5081. if (node.data === ']') {
  5082. if (match === 0) {
  5083. return nextSibling(node);
  5084. }
  5085. else {
  5086. match--;
  5087. }
  5088. }
  5089. }
  5090. }
  5091. return node;
  5092. };
  5093. return [hydrate, hydrateNode];
  5094. }
  5095. let supported;
  5096. let perf;
  5097. function startMeasure(instance, type) {
  5098. if (instance.appContext.config.performance && isSupported()) {
  5099. perf.mark(`vue-${type}-${instance.uid}`);
  5100. }
  5101. {
  5102. devtoolsPerfStart(instance, type, supported ? perf.now() : Date.now());
  5103. }
  5104. }
  5105. function endMeasure(instance, type) {
  5106. if (instance.appContext.config.performance && isSupported()) {
  5107. const startTag = `vue-${type}-${instance.uid}`;
  5108. const endTag = startTag + `:end`;
  5109. perf.mark(endTag);
  5110. perf.measure(`<${formatComponentName(instance, instance.type)}> ${type}`, startTag, endTag);
  5111. perf.clearMarks(startTag);
  5112. perf.clearMarks(endTag);
  5113. }
  5114. {
  5115. devtoolsPerfEnd(instance, type, supported ? perf.now() : Date.now());
  5116. }
  5117. }
  5118. function isSupported() {
  5119. if (supported !== undefined) {
  5120. return supported;
  5121. }
  5122. /* eslint-disable no-restricted-globals */
  5123. if (typeof window !== 'undefined' && window.performance) {
  5124. supported = true;
  5125. perf = window.performance;
  5126. }
  5127. else {
  5128. supported = false;
  5129. }
  5130. /* eslint-enable no-restricted-globals */
  5131. return supported;
  5132. }
  5133. const queuePostRenderEffect = queueEffectWithSuspense
  5134. ;
  5135. /**
  5136. * The createRenderer function accepts two generic arguments:
  5137. * HostNode and HostElement, corresponding to Node and Element types in the
  5138. * host environment. For example, for runtime-dom, HostNode would be the DOM
  5139. * `Node` interface and HostElement would be the DOM `Element` interface.
  5140. *
  5141. * Custom renderers can pass in the platform specific types like this:
  5142. *
  5143. * ``` js
  5144. * const { render, createApp } = createRenderer<Node, Element>({
  5145. * patchProp,
  5146. * ...nodeOps
  5147. * })
  5148. * ```
  5149. */
  5150. function createRenderer(options) {
  5151. return baseCreateRenderer(options);
  5152. }
  5153. // Separate API for creating hydration-enabled renderer.
  5154. // Hydration logic is only used when calling this function, making it
  5155. // tree-shakable.
  5156. function createHydrationRenderer(options) {
  5157. return baseCreateRenderer(options, createHydrationFunctions);
  5158. }
  5159. // implementation
  5160. function baseCreateRenderer(options, createHydrationFns) {
  5161. const target = getGlobalThis();
  5162. target.__VUE__ = true;
  5163. {
  5164. setDevtoolsHook(target.__VUE_DEVTOOLS_GLOBAL_HOOK__, target);
  5165. }
  5166. const { insert: hostInsert, remove: hostRemove, patchProp: hostPatchProp, createElement: hostCreateElement, createText: hostCreateText, createComment: hostCreateComment, setText: hostSetText, setElementText: hostSetElementText, parentNode: hostParentNode, nextSibling: hostNextSibling, setScopeId: hostSetScopeId = NOOP, cloneNode: hostCloneNode, insertStaticContent: hostInsertStaticContent } = options;
  5167. // Note: functions inside this closure should use `const xxx = () => {}`
  5168. // style in order to prevent being inlined by minifiers.
  5169. const patch = (n1, n2, container, anchor = null, parentComponent = null, parentSuspense = null, isSVG = false, slotScopeIds = null, optimized = isHmrUpdating ? false : !!n2.dynamicChildren) => {
  5170. if (n1 === n2) {
  5171. return;
  5172. }
  5173. // patching & not same type, unmount old tree
  5174. if (n1 && !isSameVNodeType(n1, n2)) {
  5175. anchor = getNextHostNode(n1);
  5176. unmount(n1, parentComponent, parentSuspense, true);
  5177. n1 = null;
  5178. }
  5179. if (n2.patchFlag === -2 /* BAIL */) {
  5180. optimized = false;
  5181. n2.dynamicChildren = null;
  5182. }
  5183. const { type, ref, shapeFlag } = n2;
  5184. switch (type) {
  5185. case Text:
  5186. processText(n1, n2, container, anchor);
  5187. break;
  5188. case Comment:
  5189. processCommentNode(n1, n2, container, anchor);
  5190. break;
  5191. case Static:
  5192. if (n1 == null) {
  5193. mountStaticNode(n2, container, anchor, isSVG);
  5194. }
  5195. else {
  5196. patchStaticNode(n1, n2, container, isSVG);
  5197. }
  5198. break;
  5199. case Fragment:
  5200. processFragment(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5201. break;
  5202. default:
  5203. if (shapeFlag & 1 /* ELEMENT */) {
  5204. processElement(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5205. }
  5206. else if (shapeFlag & 6 /* COMPONENT */) {
  5207. processComponent(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5208. }
  5209. else if (shapeFlag & 64 /* TELEPORT */) {
  5210. type.process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, internals);
  5211. }
  5212. else if (shapeFlag & 128 /* SUSPENSE */) {
  5213. type.process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, internals);
  5214. }
  5215. else {
  5216. warn$1('Invalid VNode type:', type, `(${typeof type})`);
  5217. }
  5218. }
  5219. // set ref
  5220. if (ref != null && parentComponent) {
  5221. setRef(ref, n1 && n1.ref, parentSuspense, n2 || n1, !n2);
  5222. }
  5223. };
  5224. const processText = (n1, n2, container, anchor) => {
  5225. if (n1 == null) {
  5226. hostInsert((n2.el = hostCreateText(n2.children)), container, anchor);
  5227. }
  5228. else {
  5229. const el = (n2.el = n1.el);
  5230. if (n2.children !== n1.children) {
  5231. hostSetText(el, n2.children);
  5232. }
  5233. }
  5234. };
  5235. const processCommentNode = (n1, n2, container, anchor) => {
  5236. if (n1 == null) {
  5237. hostInsert((n2.el = hostCreateComment(n2.children || '')), container, anchor);
  5238. }
  5239. else {
  5240. // there's no support for dynamic comments
  5241. n2.el = n1.el;
  5242. }
  5243. };
  5244. const mountStaticNode = (n2, container, anchor, isSVG) => {
  5245. [n2.el, n2.anchor] = hostInsertStaticContent(n2.children, container, anchor, isSVG);
  5246. };
  5247. /**
  5248. * Dev / HMR only
  5249. */
  5250. const patchStaticNode = (n1, n2, container, isSVG) => {
  5251. // static nodes are only patched during dev for HMR
  5252. if (n2.children !== n1.children) {
  5253. const anchor = hostNextSibling(n1.anchor);
  5254. // remove existing
  5255. removeStaticNode(n1);
  5256. [n2.el, n2.anchor] = hostInsertStaticContent(n2.children, container, anchor, isSVG);
  5257. }
  5258. else {
  5259. n2.el = n1.el;
  5260. n2.anchor = n1.anchor;
  5261. }
  5262. };
  5263. const moveStaticNode = ({ el, anchor }, container, nextSibling) => {
  5264. let next;
  5265. while (el && el !== anchor) {
  5266. next = hostNextSibling(el);
  5267. hostInsert(el, container, nextSibling);
  5268. el = next;
  5269. }
  5270. hostInsert(anchor, container, nextSibling);
  5271. };
  5272. const removeStaticNode = ({ el, anchor }) => {
  5273. let next;
  5274. while (el && el !== anchor) {
  5275. next = hostNextSibling(el);
  5276. hostRemove(el);
  5277. el = next;
  5278. }
  5279. hostRemove(anchor);
  5280. };
  5281. const processElement = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  5282. isSVG = isSVG || n2.type === 'svg';
  5283. if (n1 == null) {
  5284. mountElement(n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5285. }
  5286. else {
  5287. patchElement(n1, n2, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5288. }
  5289. };
  5290. const mountElement = (vnode, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  5291. let el;
  5292. let vnodeHook;
  5293. const { type, props, shapeFlag, transition, patchFlag, dirs } = vnode;
  5294. {
  5295. el = vnode.el = hostCreateElement(vnode.type, isSVG, props && props.is, props);
  5296. // mount children first, since some props may rely on child content
  5297. // being already rendered, e.g. `<select value>`
  5298. if (shapeFlag & 8 /* TEXT_CHILDREN */) {
  5299. hostSetElementText(el, vnode.children);
  5300. }
  5301. else if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  5302. mountChildren(vnode.children, el, null, parentComponent, parentSuspense, isSVG && type !== 'foreignObject', slotScopeIds, optimized);
  5303. }
  5304. if (dirs) {
  5305. invokeDirectiveHook(vnode, null, parentComponent, 'created');
  5306. }
  5307. // props
  5308. if (props) {
  5309. for (const key in props) {
  5310. if (key !== 'value' && !isReservedProp(key)) {
  5311. hostPatchProp(el, key, null, props[key], isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  5312. }
  5313. }
  5314. /**
  5315. * Special case for setting value on DOM elements:
  5316. * - it can be order-sensitive (e.g. should be set *after* min/max, #2325, #4024)
  5317. * - it needs to be forced (#1471)
  5318. * #2353 proposes adding another renderer option to configure this, but
  5319. * the properties affects are so finite it is worth special casing it
  5320. * here to reduce the complexity. (Special casing it also should not
  5321. * affect non-DOM renderers)
  5322. */
  5323. if ('value' in props) {
  5324. hostPatchProp(el, 'value', null, props.value);
  5325. }
  5326. if ((vnodeHook = props.onVnodeBeforeMount)) {
  5327. invokeVNodeHook(vnodeHook, parentComponent, vnode);
  5328. }
  5329. }
  5330. // scopeId
  5331. setScopeId(el, vnode, vnode.scopeId, slotScopeIds, parentComponent);
  5332. }
  5333. {
  5334. Object.defineProperty(el, '__vnode', {
  5335. value: vnode,
  5336. enumerable: false
  5337. });
  5338. Object.defineProperty(el, '__vueParentComponent', {
  5339. value: parentComponent,
  5340. enumerable: false
  5341. });
  5342. }
  5343. if (dirs) {
  5344. invokeDirectiveHook(vnode, null, parentComponent, 'beforeMount');
  5345. }
  5346. // #1583 For inside suspense + suspense not resolved case, enter hook should call when suspense resolved
  5347. // #1689 For inside suspense + suspense resolved case, just call it
  5348. const needCallTransitionHooks = (!parentSuspense || (parentSuspense && !parentSuspense.pendingBranch)) &&
  5349. transition &&
  5350. !transition.persisted;
  5351. if (needCallTransitionHooks) {
  5352. transition.beforeEnter(el);
  5353. }
  5354. hostInsert(el, container, anchor);
  5355. if ((vnodeHook = props && props.onVnodeMounted) ||
  5356. needCallTransitionHooks ||
  5357. dirs) {
  5358. queuePostRenderEffect(() => {
  5359. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, vnode);
  5360. needCallTransitionHooks && transition.enter(el);
  5361. dirs && invokeDirectiveHook(vnode, null, parentComponent, 'mounted');
  5362. }, parentSuspense);
  5363. }
  5364. };
  5365. const setScopeId = (el, vnode, scopeId, slotScopeIds, parentComponent) => {
  5366. if (scopeId) {
  5367. hostSetScopeId(el, scopeId);
  5368. }
  5369. if (slotScopeIds) {
  5370. for (let i = 0; i < slotScopeIds.length; i++) {
  5371. hostSetScopeId(el, slotScopeIds[i]);
  5372. }
  5373. }
  5374. if (parentComponent) {
  5375. let subTree = parentComponent.subTree;
  5376. if (subTree.patchFlag > 0 &&
  5377. subTree.patchFlag & 2048 /* DEV_ROOT_FRAGMENT */) {
  5378. subTree =
  5379. filterSingleRoot(subTree.children) || subTree;
  5380. }
  5381. if (vnode === subTree) {
  5382. const parentVNode = parentComponent.vnode;
  5383. setScopeId(el, parentVNode, parentVNode.scopeId, parentVNode.slotScopeIds, parentComponent.parent);
  5384. }
  5385. }
  5386. };
  5387. const mountChildren = (children, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, start = 0) => {
  5388. for (let i = start; i < children.length; i++) {
  5389. const child = (children[i] = optimized
  5390. ? cloneIfMounted(children[i])
  5391. : normalizeVNode(children[i]));
  5392. patch(null, child, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5393. }
  5394. };
  5395. const patchElement = (n1, n2, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  5396. const el = (n2.el = n1.el);
  5397. let { patchFlag, dynamicChildren, dirs } = n2;
  5398. // #1426 take the old vnode's patch flag into account since user may clone a
  5399. // compiler-generated vnode, which de-opts to FULL_PROPS
  5400. patchFlag |= n1.patchFlag & 16 /* FULL_PROPS */;
  5401. const oldProps = n1.props || EMPTY_OBJ;
  5402. const newProps = n2.props || EMPTY_OBJ;
  5403. let vnodeHook;
  5404. // disable recurse in beforeUpdate hooks
  5405. parentComponent && toggleRecurse(parentComponent, false);
  5406. if ((vnodeHook = newProps.onVnodeBeforeUpdate)) {
  5407. invokeVNodeHook(vnodeHook, parentComponent, n2, n1);
  5408. }
  5409. if (dirs) {
  5410. invokeDirectiveHook(n2, n1, parentComponent, 'beforeUpdate');
  5411. }
  5412. parentComponent && toggleRecurse(parentComponent, true);
  5413. if (isHmrUpdating) {
  5414. // HMR updated, force full diff
  5415. patchFlag = 0;
  5416. optimized = false;
  5417. dynamicChildren = null;
  5418. }
  5419. const areChildrenSVG = isSVG && n2.type !== 'foreignObject';
  5420. if (dynamicChildren) {
  5421. patchBlockChildren(n1.dynamicChildren, dynamicChildren, el, parentComponent, parentSuspense, areChildrenSVG, slotScopeIds);
  5422. if (parentComponent && parentComponent.type.__hmrId) {
  5423. traverseStaticChildren(n1, n2);
  5424. }
  5425. }
  5426. else if (!optimized) {
  5427. // full diff
  5428. patchChildren(n1, n2, el, null, parentComponent, parentSuspense, areChildrenSVG, slotScopeIds, false);
  5429. }
  5430. if (patchFlag > 0) {
  5431. // the presence of a patchFlag means this element's render code was
  5432. // generated by the compiler and can take the fast path.
  5433. // in this path old node and new node are guaranteed to have the same shape
  5434. // (i.e. at the exact same position in the source template)
  5435. if (patchFlag & 16 /* FULL_PROPS */) {
  5436. // element props contain dynamic keys, full diff needed
  5437. patchProps(el, n2, oldProps, newProps, parentComponent, parentSuspense, isSVG);
  5438. }
  5439. else {
  5440. // class
  5441. // this flag is matched when the element has dynamic class bindings.
  5442. if (patchFlag & 2 /* CLASS */) {
  5443. if (oldProps.class !== newProps.class) {
  5444. hostPatchProp(el, 'class', null, newProps.class, isSVG);
  5445. }
  5446. }
  5447. // style
  5448. // this flag is matched when the element has dynamic style bindings
  5449. if (patchFlag & 4 /* STYLE */) {
  5450. hostPatchProp(el, 'style', oldProps.style, newProps.style, isSVG);
  5451. }
  5452. // props
  5453. // This flag is matched when the element has dynamic prop/attr bindings
  5454. // other than class and style. The keys of dynamic prop/attrs are saved for
  5455. // faster iteration.
  5456. // Note dynamic keys like :[foo]="bar" will cause this optimization to
  5457. // bail out and go through a full diff because we need to unset the old key
  5458. if (patchFlag & 8 /* PROPS */) {
  5459. // if the flag is present then dynamicProps must be non-null
  5460. const propsToUpdate = n2.dynamicProps;
  5461. for (let i = 0; i < propsToUpdate.length; i++) {
  5462. const key = propsToUpdate[i];
  5463. const prev = oldProps[key];
  5464. const next = newProps[key];
  5465. // #1471 force patch value
  5466. if (next !== prev || key === 'value') {
  5467. hostPatchProp(el, key, prev, next, isSVG, n1.children, parentComponent, parentSuspense, unmountChildren);
  5468. }
  5469. }
  5470. }
  5471. }
  5472. // text
  5473. // This flag is matched when the element has only dynamic text children.
  5474. if (patchFlag & 1 /* TEXT */) {
  5475. if (n1.children !== n2.children) {
  5476. hostSetElementText(el, n2.children);
  5477. }
  5478. }
  5479. }
  5480. else if (!optimized && dynamicChildren == null) {
  5481. // unoptimized, full diff
  5482. patchProps(el, n2, oldProps, newProps, parentComponent, parentSuspense, isSVG);
  5483. }
  5484. if ((vnodeHook = newProps.onVnodeUpdated) || dirs) {
  5485. queuePostRenderEffect(() => {
  5486. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, n2, n1);
  5487. dirs && invokeDirectiveHook(n2, n1, parentComponent, 'updated');
  5488. }, parentSuspense);
  5489. }
  5490. };
  5491. // The fast path for blocks.
  5492. const patchBlockChildren = (oldChildren, newChildren, fallbackContainer, parentComponent, parentSuspense, isSVG, slotScopeIds) => {
  5493. for (let i = 0; i < newChildren.length; i++) {
  5494. const oldVNode = oldChildren[i];
  5495. const newVNode = newChildren[i];
  5496. // Determine the container (parent element) for the patch.
  5497. const container =
  5498. // oldVNode may be an errored async setup() component inside Suspense
  5499. // which will not have a mounted element
  5500. oldVNode.el &&
  5501. // - In the case of a Fragment, we need to provide the actual parent
  5502. // of the Fragment itself so it can move its children.
  5503. (oldVNode.type === Fragment ||
  5504. // - In the case of different nodes, there is going to be a replacement
  5505. // which also requires the correct parent container
  5506. !isSameVNodeType(oldVNode, newVNode) ||
  5507. // - In the case of a component, it could contain anything.
  5508. oldVNode.shapeFlag & (6 /* COMPONENT */ | 64 /* TELEPORT */))
  5509. ? hostParentNode(oldVNode.el)
  5510. : // In other cases, the parent container is not actually used so we
  5511. // just pass the block element here to avoid a DOM parentNode call.
  5512. fallbackContainer;
  5513. patch(oldVNode, newVNode, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, true);
  5514. }
  5515. };
  5516. const patchProps = (el, vnode, oldProps, newProps, parentComponent, parentSuspense, isSVG) => {
  5517. if (oldProps !== newProps) {
  5518. for (const key in newProps) {
  5519. // empty string is not valid prop
  5520. if (isReservedProp(key))
  5521. continue;
  5522. const next = newProps[key];
  5523. const prev = oldProps[key];
  5524. // defer patching value
  5525. if (next !== prev && key !== 'value') {
  5526. hostPatchProp(el, key, prev, next, isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  5527. }
  5528. }
  5529. if (oldProps !== EMPTY_OBJ) {
  5530. for (const key in oldProps) {
  5531. if (!isReservedProp(key) && !(key in newProps)) {
  5532. hostPatchProp(el, key, oldProps[key], null, isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  5533. }
  5534. }
  5535. }
  5536. if ('value' in newProps) {
  5537. hostPatchProp(el, 'value', oldProps.value, newProps.value);
  5538. }
  5539. }
  5540. };
  5541. const processFragment = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  5542. const fragmentStartAnchor = (n2.el = n1 ? n1.el : hostCreateText(''));
  5543. const fragmentEndAnchor = (n2.anchor = n1 ? n1.anchor : hostCreateText(''));
  5544. let { patchFlag, dynamicChildren, slotScopeIds: fragmentSlotScopeIds } = n2;
  5545. if (isHmrUpdating) {
  5546. // HMR updated, force full diff
  5547. patchFlag = 0;
  5548. optimized = false;
  5549. dynamicChildren = null;
  5550. }
  5551. // check if this is a slot fragment with :slotted scope ids
  5552. if (fragmentSlotScopeIds) {
  5553. slotScopeIds = slotScopeIds
  5554. ? slotScopeIds.concat(fragmentSlotScopeIds)
  5555. : fragmentSlotScopeIds;
  5556. }
  5557. if (n1 == null) {
  5558. hostInsert(fragmentStartAnchor, container, anchor);
  5559. hostInsert(fragmentEndAnchor, container, anchor);
  5560. // a fragment can only have array children
  5561. // since they are either generated by the compiler, or implicitly created
  5562. // from arrays.
  5563. mountChildren(n2.children, container, fragmentEndAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5564. }
  5565. else {
  5566. if (patchFlag > 0 &&
  5567. patchFlag & 64 /* STABLE_FRAGMENT */ &&
  5568. dynamicChildren &&
  5569. // #2715 the previous fragment could've been a BAILed one as a result
  5570. // of renderSlot() with no valid children
  5571. n1.dynamicChildren) {
  5572. // a stable fragment (template root or <template v-for>) doesn't need to
  5573. // patch children order, but it may contain dynamicChildren.
  5574. patchBlockChildren(n1.dynamicChildren, dynamicChildren, container, parentComponent, parentSuspense, isSVG, slotScopeIds);
  5575. if (parentComponent && parentComponent.type.__hmrId) {
  5576. traverseStaticChildren(n1, n2);
  5577. }
  5578. else if (
  5579. // #2080 if the stable fragment has a key, it's a <template v-for> that may
  5580. // get moved around. Make sure all root level vnodes inherit el.
  5581. // #2134 or if it's a component root, it may also get moved around
  5582. // as the component is being moved.
  5583. n2.key != null ||
  5584. (parentComponent && n2 === parentComponent.subTree)) {
  5585. traverseStaticChildren(n1, n2, true /* shallow */);
  5586. }
  5587. }
  5588. else {
  5589. // keyed / unkeyed, or manual fragments.
  5590. // for keyed & unkeyed, since they are compiler generated from v-for,
  5591. // each child is guaranteed to be a block so the fragment will never
  5592. // have dynamicChildren.
  5593. patchChildren(n1, n2, container, fragmentEndAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5594. }
  5595. }
  5596. };
  5597. const processComponent = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  5598. n2.slotScopeIds = slotScopeIds;
  5599. if (n1 == null) {
  5600. if (n2.shapeFlag & 512 /* COMPONENT_KEPT_ALIVE */) {
  5601. parentComponent.ctx.activate(n2, container, anchor, isSVG, optimized);
  5602. }
  5603. else {
  5604. mountComponent(n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  5605. }
  5606. }
  5607. else {
  5608. updateComponent(n1, n2, optimized);
  5609. }
  5610. };
  5611. const mountComponent = (initialVNode, container, anchor, parentComponent, parentSuspense, isSVG, optimized) => {
  5612. const instance = (initialVNode.component = createComponentInstance(initialVNode, parentComponent, parentSuspense));
  5613. if (instance.type.__hmrId) {
  5614. registerHMR(instance);
  5615. }
  5616. {
  5617. pushWarningContext(initialVNode);
  5618. startMeasure(instance, `mount`);
  5619. }
  5620. // inject renderer internals for keepAlive
  5621. if (isKeepAlive(initialVNode)) {
  5622. instance.ctx.renderer = internals;
  5623. }
  5624. // resolve props and slots for setup context
  5625. {
  5626. {
  5627. startMeasure(instance, `init`);
  5628. }
  5629. setupComponent(instance);
  5630. {
  5631. endMeasure(instance, `init`);
  5632. }
  5633. }
  5634. // setup() is async. This component relies on async logic to be resolved
  5635. // before proceeding
  5636. if (instance.asyncDep) {
  5637. parentSuspense && parentSuspense.registerDep(instance, setupRenderEffect);
  5638. // Give it a placeholder if this is not hydration
  5639. // TODO handle self-defined fallback
  5640. if (!initialVNode.el) {
  5641. const placeholder = (instance.subTree = createVNode(Comment));
  5642. processCommentNode(null, placeholder, container, anchor);
  5643. }
  5644. return;
  5645. }
  5646. setupRenderEffect(instance, initialVNode, container, anchor, parentSuspense, isSVG, optimized);
  5647. {
  5648. popWarningContext();
  5649. endMeasure(instance, `mount`);
  5650. }
  5651. };
  5652. const updateComponent = (n1, n2, optimized) => {
  5653. const instance = (n2.component = n1.component);
  5654. if (shouldUpdateComponent(n1, n2, optimized)) {
  5655. if (instance.asyncDep &&
  5656. !instance.asyncResolved) {
  5657. // async & still pending - just update props and slots
  5658. // since the component's reactive effect for render isn't set-up yet
  5659. {
  5660. pushWarningContext(n2);
  5661. }
  5662. updateComponentPreRender(instance, n2, optimized);
  5663. {
  5664. popWarningContext();
  5665. }
  5666. return;
  5667. }
  5668. else {
  5669. // normal update
  5670. instance.next = n2;
  5671. // in case the child component is also queued, remove it to avoid
  5672. // double updating the same child component in the same flush.
  5673. invalidateJob(instance.update);
  5674. // instance.update is the reactive effect.
  5675. instance.update();
  5676. }
  5677. }
  5678. else {
  5679. // no update needed. just copy over properties
  5680. n2.component = n1.component;
  5681. n2.el = n1.el;
  5682. instance.vnode = n2;
  5683. }
  5684. };
  5685. const setupRenderEffect = (instance, initialVNode, container, anchor, parentSuspense, isSVG, optimized) => {
  5686. const componentUpdateFn = () => {
  5687. if (!instance.isMounted) {
  5688. let vnodeHook;
  5689. const { el, props } = initialVNode;
  5690. const { bm, m, parent } = instance;
  5691. const isAsyncWrapperVNode = isAsyncWrapper(initialVNode);
  5692. toggleRecurse(instance, false);
  5693. // beforeMount hook
  5694. if (bm) {
  5695. invokeArrayFns(bm);
  5696. }
  5697. // onVnodeBeforeMount
  5698. if (!isAsyncWrapperVNode &&
  5699. (vnodeHook = props && props.onVnodeBeforeMount)) {
  5700. invokeVNodeHook(vnodeHook, parent, initialVNode);
  5701. }
  5702. toggleRecurse(instance, true);
  5703. if (el && hydrateNode) {
  5704. // vnode has adopted host node - perform hydration instead of mount.
  5705. const hydrateSubTree = () => {
  5706. {
  5707. startMeasure(instance, `render`);
  5708. }
  5709. instance.subTree = renderComponentRoot(instance);
  5710. {
  5711. endMeasure(instance, `render`);
  5712. }
  5713. {
  5714. startMeasure(instance, `hydrate`);
  5715. }
  5716. hydrateNode(el, instance.subTree, instance, parentSuspense, null);
  5717. {
  5718. endMeasure(instance, `hydrate`);
  5719. }
  5720. };
  5721. if (isAsyncWrapperVNode) {
  5722. initialVNode.type.__asyncLoader().then(
  5723. // note: we are moving the render call into an async callback,
  5724. // which means it won't track dependencies - but it's ok because
  5725. // a server-rendered async wrapper is already in resolved state
  5726. // and it will never need to change.
  5727. () => !instance.isUnmounted && hydrateSubTree());
  5728. }
  5729. else {
  5730. hydrateSubTree();
  5731. }
  5732. }
  5733. else {
  5734. {
  5735. startMeasure(instance, `render`);
  5736. }
  5737. const subTree = (instance.subTree = renderComponentRoot(instance));
  5738. {
  5739. endMeasure(instance, `render`);
  5740. }
  5741. {
  5742. startMeasure(instance, `patch`);
  5743. }
  5744. patch(null, subTree, container, anchor, instance, parentSuspense, isSVG);
  5745. {
  5746. endMeasure(instance, `patch`);
  5747. }
  5748. initialVNode.el = subTree.el;
  5749. }
  5750. // mounted hook
  5751. if (m) {
  5752. queuePostRenderEffect(m, parentSuspense);
  5753. }
  5754. // onVnodeMounted
  5755. if (!isAsyncWrapperVNode &&
  5756. (vnodeHook = props && props.onVnodeMounted)) {
  5757. const scopedInitialVNode = initialVNode;
  5758. queuePostRenderEffect(() => invokeVNodeHook(vnodeHook, parent, scopedInitialVNode), parentSuspense);
  5759. }
  5760. // activated hook for keep-alive roots.
  5761. // #1742 activated hook must be accessed after first render
  5762. // since the hook may be injected by a child keep-alive
  5763. if (initialVNode.shapeFlag & 256 /* COMPONENT_SHOULD_KEEP_ALIVE */) {
  5764. instance.a && queuePostRenderEffect(instance.a, parentSuspense);
  5765. }
  5766. instance.isMounted = true;
  5767. {
  5768. devtoolsComponentAdded(instance);
  5769. }
  5770. // #2458: deference mount-only object parameters to prevent memleaks
  5771. initialVNode = container = anchor = null;
  5772. }
  5773. else {
  5774. // updateComponent
  5775. // This is triggered by mutation of component's own state (next: null)
  5776. // OR parent calling processComponent (next: VNode)
  5777. let { next, bu, u, parent, vnode } = instance;
  5778. let originNext = next;
  5779. let vnodeHook;
  5780. {
  5781. pushWarningContext(next || instance.vnode);
  5782. }
  5783. // Disallow component effect recursion during pre-lifecycle hooks.
  5784. toggleRecurse(instance, false);
  5785. if (next) {
  5786. next.el = vnode.el;
  5787. updateComponentPreRender(instance, next, optimized);
  5788. }
  5789. else {
  5790. next = vnode;
  5791. }
  5792. // beforeUpdate hook
  5793. if (bu) {
  5794. invokeArrayFns(bu);
  5795. }
  5796. // onVnodeBeforeUpdate
  5797. if ((vnodeHook = next.props && next.props.onVnodeBeforeUpdate)) {
  5798. invokeVNodeHook(vnodeHook, parent, next, vnode);
  5799. }
  5800. toggleRecurse(instance, true);
  5801. // render
  5802. {
  5803. startMeasure(instance, `render`);
  5804. }
  5805. const nextTree = renderComponentRoot(instance);
  5806. {
  5807. endMeasure(instance, `render`);
  5808. }
  5809. const prevTree = instance.subTree;
  5810. instance.subTree = nextTree;
  5811. {
  5812. startMeasure(instance, `patch`);
  5813. }
  5814. patch(prevTree, nextTree,
  5815. // parent may have changed if it's in a teleport
  5816. hostParentNode(prevTree.el),
  5817. // anchor may have changed if it's in a fragment
  5818. getNextHostNode(prevTree), instance, parentSuspense, isSVG);
  5819. {
  5820. endMeasure(instance, `patch`);
  5821. }
  5822. next.el = nextTree.el;
  5823. if (originNext === null) {
  5824. // self-triggered update. In case of HOC, update parent component
  5825. // vnode el. HOC is indicated by parent instance's subTree pointing
  5826. // to child component's vnode
  5827. updateHOCHostEl(instance, nextTree.el);
  5828. }
  5829. // updated hook
  5830. if (u) {
  5831. queuePostRenderEffect(u, parentSuspense);
  5832. }
  5833. // onVnodeUpdated
  5834. if ((vnodeHook = next.props && next.props.onVnodeUpdated)) {
  5835. queuePostRenderEffect(() => invokeVNodeHook(vnodeHook, parent, next, vnode), parentSuspense);
  5836. }
  5837. {
  5838. devtoolsComponentUpdated(instance);
  5839. }
  5840. {
  5841. popWarningContext();
  5842. }
  5843. }
  5844. };
  5845. // create reactive effect for rendering
  5846. const effect = (instance.effect = new ReactiveEffect(componentUpdateFn, () => queueJob(instance.update), instance.scope // track it in component's effect scope
  5847. ));
  5848. const update = (instance.update = effect.run.bind(effect));
  5849. update.id = instance.uid;
  5850. // allowRecurse
  5851. // #1801, #2043 component render effects should allow recursive updates
  5852. toggleRecurse(instance, true);
  5853. {
  5854. effect.onTrack = instance.rtc
  5855. ? e => invokeArrayFns(instance.rtc, e)
  5856. : void 0;
  5857. effect.onTrigger = instance.rtg
  5858. ? e => invokeArrayFns(instance.rtg, e)
  5859. : void 0;
  5860. // @ts-ignore (for scheduler)
  5861. update.ownerInstance = instance;
  5862. }
  5863. update();
  5864. };
  5865. const updateComponentPreRender = (instance, nextVNode, optimized) => {
  5866. nextVNode.component = instance;
  5867. const prevProps = instance.vnode.props;
  5868. instance.vnode = nextVNode;
  5869. instance.next = null;
  5870. updateProps(instance, nextVNode.props, prevProps, optimized);
  5871. updateSlots(instance, nextVNode.children, optimized);
  5872. pauseTracking();
  5873. // props update may have triggered pre-flush watchers.
  5874. // flush them before the render update.
  5875. flushPreFlushCbs(undefined, instance.update);
  5876. resetTracking();
  5877. };
  5878. const patchChildren = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized = false) => {
  5879. const c1 = n1 && n1.children;
  5880. const prevShapeFlag = n1 ? n1.shapeFlag : 0;
  5881. const c2 = n2.children;
  5882. const { patchFlag, shapeFlag } = n2;
  5883. // fast path
  5884. if (patchFlag > 0) {
  5885. if (patchFlag & 128 /* KEYED_FRAGMENT */) {
  5886. // this could be either fully-keyed or mixed (some keyed some not)
  5887. // presence of patchFlag means children are guaranteed to be arrays
  5888. patchKeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5889. return;
  5890. }
  5891. else if (patchFlag & 256 /* UNKEYED_FRAGMENT */) {
  5892. // unkeyed
  5893. patchUnkeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5894. return;
  5895. }
  5896. }
  5897. // children has 3 possibilities: text, array or no children.
  5898. if (shapeFlag & 8 /* TEXT_CHILDREN */) {
  5899. // text children fast path
  5900. if (prevShapeFlag & 16 /* ARRAY_CHILDREN */) {
  5901. unmountChildren(c1, parentComponent, parentSuspense);
  5902. }
  5903. if (c2 !== c1) {
  5904. hostSetElementText(container, c2);
  5905. }
  5906. }
  5907. else {
  5908. if (prevShapeFlag & 16 /* ARRAY_CHILDREN */) {
  5909. // prev children was array
  5910. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  5911. // two arrays, cannot assume anything, do full diff
  5912. patchKeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5913. }
  5914. else {
  5915. // no new children, just unmount old
  5916. unmountChildren(c1, parentComponent, parentSuspense, true);
  5917. }
  5918. }
  5919. else {
  5920. // prev children was text OR null
  5921. // new children is array OR null
  5922. if (prevShapeFlag & 8 /* TEXT_CHILDREN */) {
  5923. hostSetElementText(container, '');
  5924. }
  5925. // mount new if array
  5926. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  5927. mountChildren(c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5928. }
  5929. }
  5930. }
  5931. };
  5932. const patchUnkeyedChildren = (c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  5933. c1 = c1 || EMPTY_ARR;
  5934. c2 = c2 || EMPTY_ARR;
  5935. const oldLength = c1.length;
  5936. const newLength = c2.length;
  5937. const commonLength = Math.min(oldLength, newLength);
  5938. let i;
  5939. for (i = 0; i < commonLength; i++) {
  5940. const nextChild = (c2[i] = optimized
  5941. ? cloneIfMounted(c2[i])
  5942. : normalizeVNode(c2[i]));
  5943. patch(c1[i], nextChild, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5944. }
  5945. if (oldLength > newLength) {
  5946. // remove old
  5947. unmountChildren(c1, parentComponent, parentSuspense, true, false, commonLength);
  5948. }
  5949. else {
  5950. // mount new
  5951. mountChildren(c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, commonLength);
  5952. }
  5953. };
  5954. // can be all-keyed or mixed
  5955. const patchKeyedChildren = (c1, c2, container, parentAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  5956. let i = 0;
  5957. const l2 = c2.length;
  5958. let e1 = c1.length - 1; // prev ending index
  5959. let e2 = l2 - 1; // next ending index
  5960. // 1. sync from start
  5961. // (a b) c
  5962. // (a b) d e
  5963. while (i <= e1 && i <= e2) {
  5964. const n1 = c1[i];
  5965. const n2 = (c2[i] = optimized
  5966. ? cloneIfMounted(c2[i])
  5967. : normalizeVNode(c2[i]));
  5968. if (isSameVNodeType(n1, n2)) {
  5969. patch(n1, n2, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5970. }
  5971. else {
  5972. break;
  5973. }
  5974. i++;
  5975. }
  5976. // 2. sync from end
  5977. // a (b c)
  5978. // d e (b c)
  5979. while (i <= e1 && i <= e2) {
  5980. const n1 = c1[e1];
  5981. const n2 = (c2[e2] = optimized
  5982. ? cloneIfMounted(c2[e2])
  5983. : normalizeVNode(c2[e2]));
  5984. if (isSameVNodeType(n1, n2)) {
  5985. patch(n1, n2, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5986. }
  5987. else {
  5988. break;
  5989. }
  5990. e1--;
  5991. e2--;
  5992. }
  5993. // 3. common sequence + mount
  5994. // (a b)
  5995. // (a b) c
  5996. // i = 2, e1 = 1, e2 = 2
  5997. // (a b)
  5998. // c (a b)
  5999. // i = 0, e1 = -1, e2 = 0
  6000. if (i > e1) {
  6001. if (i <= e2) {
  6002. const nextPos = e2 + 1;
  6003. const anchor = nextPos < l2 ? c2[nextPos].el : parentAnchor;
  6004. while (i <= e2) {
  6005. patch(null, (c2[i] = optimized
  6006. ? cloneIfMounted(c2[i])
  6007. : normalizeVNode(c2[i])), container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6008. i++;
  6009. }
  6010. }
  6011. }
  6012. // 4. common sequence + unmount
  6013. // (a b) c
  6014. // (a b)
  6015. // i = 2, e1 = 2, e2 = 1
  6016. // a (b c)
  6017. // (b c)
  6018. // i = 0, e1 = 0, e2 = -1
  6019. else if (i > e2) {
  6020. while (i <= e1) {
  6021. unmount(c1[i], parentComponent, parentSuspense, true);
  6022. i++;
  6023. }
  6024. }
  6025. // 5. unknown sequence
  6026. // [i ... e1 + 1]: a b [c d e] f g
  6027. // [i ... e2 + 1]: a b [e d c h] f g
  6028. // i = 2, e1 = 4, e2 = 5
  6029. else {
  6030. const s1 = i; // prev starting index
  6031. const s2 = i; // next starting index
  6032. // 5.1 build key:index map for newChildren
  6033. const keyToNewIndexMap = new Map();
  6034. for (i = s2; i <= e2; i++) {
  6035. const nextChild = (c2[i] = optimized
  6036. ? cloneIfMounted(c2[i])
  6037. : normalizeVNode(c2[i]));
  6038. if (nextChild.key != null) {
  6039. if (keyToNewIndexMap.has(nextChild.key)) {
  6040. warn$1(`Duplicate keys found during update:`, JSON.stringify(nextChild.key), `Make sure keys are unique.`);
  6041. }
  6042. keyToNewIndexMap.set(nextChild.key, i);
  6043. }
  6044. }
  6045. // 5.2 loop through old children left to be patched and try to patch
  6046. // matching nodes & remove nodes that are no longer present
  6047. let j;
  6048. let patched = 0;
  6049. const toBePatched = e2 - s2 + 1;
  6050. let moved = false;
  6051. // used to track whether any node has moved
  6052. let maxNewIndexSoFar = 0;
  6053. // works as Map<newIndex, oldIndex>
  6054. // Note that oldIndex is offset by +1
  6055. // and oldIndex = 0 is a special value indicating the new node has
  6056. // no corresponding old node.
  6057. // used for determining longest stable subsequence
  6058. const newIndexToOldIndexMap = new Array(toBePatched);
  6059. for (i = 0; i < toBePatched; i++)
  6060. newIndexToOldIndexMap[i] = 0;
  6061. for (i = s1; i <= e1; i++) {
  6062. const prevChild = c1[i];
  6063. if (patched >= toBePatched) {
  6064. // all new children have been patched so this can only be a removal
  6065. unmount(prevChild, parentComponent, parentSuspense, true);
  6066. continue;
  6067. }
  6068. let newIndex;
  6069. if (prevChild.key != null) {
  6070. newIndex = keyToNewIndexMap.get(prevChild.key);
  6071. }
  6072. else {
  6073. // key-less node, try to locate a key-less node of the same type
  6074. for (j = s2; j <= e2; j++) {
  6075. if (newIndexToOldIndexMap[j - s2] === 0 &&
  6076. isSameVNodeType(prevChild, c2[j])) {
  6077. newIndex = j;
  6078. break;
  6079. }
  6080. }
  6081. }
  6082. if (newIndex === undefined) {
  6083. unmount(prevChild, parentComponent, parentSuspense, true);
  6084. }
  6085. else {
  6086. newIndexToOldIndexMap[newIndex - s2] = i + 1;
  6087. if (newIndex >= maxNewIndexSoFar) {
  6088. maxNewIndexSoFar = newIndex;
  6089. }
  6090. else {
  6091. moved = true;
  6092. }
  6093. patch(prevChild, c2[newIndex], container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6094. patched++;
  6095. }
  6096. }
  6097. // 5.3 move and mount
  6098. // generate longest stable subsequence only when nodes have moved
  6099. const increasingNewIndexSequence = moved
  6100. ? getSequence(newIndexToOldIndexMap)
  6101. : EMPTY_ARR;
  6102. j = increasingNewIndexSequence.length - 1;
  6103. // looping backwards so that we can use last patched node as anchor
  6104. for (i = toBePatched - 1; i >= 0; i--) {
  6105. const nextIndex = s2 + i;
  6106. const nextChild = c2[nextIndex];
  6107. const anchor = nextIndex + 1 < l2 ? c2[nextIndex + 1].el : parentAnchor;
  6108. if (newIndexToOldIndexMap[i] === 0) {
  6109. // mount new
  6110. patch(null, nextChild, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6111. }
  6112. else if (moved) {
  6113. // move if:
  6114. // There is no stable subsequence (e.g. a reverse)
  6115. // OR current node is not among the stable sequence
  6116. if (j < 0 || i !== increasingNewIndexSequence[j]) {
  6117. move(nextChild, container, anchor, 2 /* REORDER */);
  6118. }
  6119. else {
  6120. j--;
  6121. }
  6122. }
  6123. }
  6124. }
  6125. };
  6126. const move = (vnode, container, anchor, moveType, parentSuspense = null) => {
  6127. const { el, type, transition, children, shapeFlag } = vnode;
  6128. if (shapeFlag & 6 /* COMPONENT */) {
  6129. move(vnode.component.subTree, container, anchor, moveType);
  6130. return;
  6131. }
  6132. if (shapeFlag & 128 /* SUSPENSE */) {
  6133. vnode.suspense.move(container, anchor, moveType);
  6134. return;
  6135. }
  6136. if (shapeFlag & 64 /* TELEPORT */) {
  6137. type.move(vnode, container, anchor, internals);
  6138. return;
  6139. }
  6140. if (type === Fragment) {
  6141. hostInsert(el, container, anchor);
  6142. for (let i = 0; i < children.length; i++) {
  6143. move(children[i], container, anchor, moveType);
  6144. }
  6145. hostInsert(vnode.anchor, container, anchor);
  6146. return;
  6147. }
  6148. if (type === Static) {
  6149. moveStaticNode(vnode, container, anchor);
  6150. return;
  6151. }
  6152. // single nodes
  6153. const needTransition = moveType !== 2 /* REORDER */ &&
  6154. shapeFlag & 1 /* ELEMENT */ &&
  6155. transition;
  6156. if (needTransition) {
  6157. if (moveType === 0 /* ENTER */) {
  6158. transition.beforeEnter(el);
  6159. hostInsert(el, container, anchor);
  6160. queuePostRenderEffect(() => transition.enter(el), parentSuspense);
  6161. }
  6162. else {
  6163. const { leave, delayLeave, afterLeave } = transition;
  6164. const remove = () => hostInsert(el, container, anchor);
  6165. const performLeave = () => {
  6166. leave(el, () => {
  6167. remove();
  6168. afterLeave && afterLeave();
  6169. });
  6170. };
  6171. if (delayLeave) {
  6172. delayLeave(el, remove, performLeave);
  6173. }
  6174. else {
  6175. performLeave();
  6176. }
  6177. }
  6178. }
  6179. else {
  6180. hostInsert(el, container, anchor);
  6181. }
  6182. };
  6183. const unmount = (vnode, parentComponent, parentSuspense, doRemove = false, optimized = false) => {
  6184. const { type, props, ref, children, dynamicChildren, shapeFlag, patchFlag, dirs } = vnode;
  6185. // unset ref
  6186. if (ref != null) {
  6187. setRef(ref, null, parentSuspense, vnode, true);
  6188. }
  6189. if (shapeFlag & 256 /* COMPONENT_SHOULD_KEEP_ALIVE */) {
  6190. parentComponent.ctx.deactivate(vnode);
  6191. return;
  6192. }
  6193. const shouldInvokeDirs = shapeFlag & 1 /* ELEMENT */ && dirs;
  6194. const shouldInvokeVnodeHook = !isAsyncWrapper(vnode);
  6195. let vnodeHook;
  6196. if (shouldInvokeVnodeHook &&
  6197. (vnodeHook = props && props.onVnodeBeforeUnmount)) {
  6198. invokeVNodeHook(vnodeHook, parentComponent, vnode);
  6199. }
  6200. if (shapeFlag & 6 /* COMPONENT */) {
  6201. unmountComponent(vnode.component, parentSuspense, doRemove);
  6202. }
  6203. else {
  6204. if (shapeFlag & 128 /* SUSPENSE */) {
  6205. vnode.suspense.unmount(parentSuspense, doRemove);
  6206. return;
  6207. }
  6208. if (shouldInvokeDirs) {
  6209. invokeDirectiveHook(vnode, null, parentComponent, 'beforeUnmount');
  6210. }
  6211. if (shapeFlag & 64 /* TELEPORT */) {
  6212. vnode.type.remove(vnode, parentComponent, parentSuspense, optimized, internals, doRemove);
  6213. }
  6214. else if (dynamicChildren &&
  6215. // #1153: fast path should not be taken for non-stable (v-for) fragments
  6216. (type !== Fragment ||
  6217. (patchFlag > 0 && patchFlag & 64 /* STABLE_FRAGMENT */))) {
  6218. // fast path for block nodes: only need to unmount dynamic children.
  6219. unmountChildren(dynamicChildren, parentComponent, parentSuspense, false, true);
  6220. }
  6221. else if ((type === Fragment &&
  6222. patchFlag &
  6223. (128 /* KEYED_FRAGMENT */ | 256 /* UNKEYED_FRAGMENT */)) ||
  6224. (!optimized && shapeFlag & 16 /* ARRAY_CHILDREN */)) {
  6225. unmountChildren(children, parentComponent, parentSuspense);
  6226. }
  6227. if (doRemove) {
  6228. remove(vnode);
  6229. }
  6230. }
  6231. if ((shouldInvokeVnodeHook &&
  6232. (vnodeHook = props && props.onVnodeUnmounted)) ||
  6233. shouldInvokeDirs) {
  6234. queuePostRenderEffect(() => {
  6235. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, vnode);
  6236. shouldInvokeDirs &&
  6237. invokeDirectiveHook(vnode, null, parentComponent, 'unmounted');
  6238. }, parentSuspense);
  6239. }
  6240. };
  6241. const remove = vnode => {
  6242. const { type, el, anchor, transition } = vnode;
  6243. if (type === Fragment) {
  6244. removeFragment(el, anchor);
  6245. return;
  6246. }
  6247. if (type === Static) {
  6248. removeStaticNode(vnode);
  6249. return;
  6250. }
  6251. const performRemove = () => {
  6252. hostRemove(el);
  6253. if (transition && !transition.persisted && transition.afterLeave) {
  6254. transition.afterLeave();
  6255. }
  6256. };
  6257. if (vnode.shapeFlag & 1 /* ELEMENT */ &&
  6258. transition &&
  6259. !transition.persisted) {
  6260. const { leave, delayLeave } = transition;
  6261. const performLeave = () => leave(el, performRemove);
  6262. if (delayLeave) {
  6263. delayLeave(vnode.el, performRemove, performLeave);
  6264. }
  6265. else {
  6266. performLeave();
  6267. }
  6268. }
  6269. else {
  6270. performRemove();
  6271. }
  6272. };
  6273. const removeFragment = (cur, end) => {
  6274. // For fragments, directly remove all contained DOM nodes.
  6275. // (fragment child nodes cannot have transition)
  6276. let next;
  6277. while (cur !== end) {
  6278. next = hostNextSibling(cur);
  6279. hostRemove(cur);
  6280. cur = next;
  6281. }
  6282. hostRemove(end);
  6283. };
  6284. const unmountComponent = (instance, parentSuspense, doRemove) => {
  6285. if (instance.type.__hmrId) {
  6286. unregisterHMR(instance);
  6287. }
  6288. const { bum, scope, update, subTree, um } = instance;
  6289. // beforeUnmount hook
  6290. if (bum) {
  6291. invokeArrayFns(bum);
  6292. }
  6293. // stop effects in component scope
  6294. scope.stop();
  6295. // update may be null if a component is unmounted before its async
  6296. // setup has resolved.
  6297. if (update) {
  6298. // so that scheduler will no longer invoke it
  6299. update.active = false;
  6300. unmount(subTree, instance, parentSuspense, doRemove);
  6301. }
  6302. // unmounted hook
  6303. if (um) {
  6304. queuePostRenderEffect(um, parentSuspense);
  6305. }
  6306. queuePostRenderEffect(() => {
  6307. instance.isUnmounted = true;
  6308. }, parentSuspense);
  6309. // A component with async dep inside a pending suspense is unmounted before
  6310. // its async dep resolves. This should remove the dep from the suspense, and
  6311. // cause the suspense to resolve immediately if that was the last dep.
  6312. if (parentSuspense &&
  6313. parentSuspense.pendingBranch &&
  6314. !parentSuspense.isUnmounted &&
  6315. instance.asyncDep &&
  6316. !instance.asyncResolved &&
  6317. instance.suspenseId === parentSuspense.pendingId) {
  6318. parentSuspense.deps--;
  6319. if (parentSuspense.deps === 0) {
  6320. parentSuspense.resolve();
  6321. }
  6322. }
  6323. {
  6324. devtoolsComponentRemoved(instance);
  6325. }
  6326. };
  6327. const unmountChildren = (children, parentComponent, parentSuspense, doRemove = false, optimized = false, start = 0) => {
  6328. for (let i = start; i < children.length; i++) {
  6329. unmount(children[i], parentComponent, parentSuspense, doRemove, optimized);
  6330. }
  6331. };
  6332. const getNextHostNode = vnode => {
  6333. if (vnode.shapeFlag & 6 /* COMPONENT */) {
  6334. return getNextHostNode(vnode.component.subTree);
  6335. }
  6336. if (vnode.shapeFlag & 128 /* SUSPENSE */) {
  6337. return vnode.suspense.next();
  6338. }
  6339. return hostNextSibling((vnode.anchor || vnode.el));
  6340. };
  6341. const render = (vnode, container, isSVG) => {
  6342. if (vnode == null) {
  6343. if (container._vnode) {
  6344. unmount(container._vnode, null, null, true);
  6345. }
  6346. }
  6347. else {
  6348. patch(container._vnode || null, vnode, container, null, null, null, isSVG);
  6349. }
  6350. flushPostFlushCbs();
  6351. container._vnode = vnode;
  6352. };
  6353. const internals = {
  6354. p: patch,
  6355. um: unmount,
  6356. m: move,
  6357. r: remove,
  6358. mt: mountComponent,
  6359. mc: mountChildren,
  6360. pc: patchChildren,
  6361. pbc: patchBlockChildren,
  6362. n: getNextHostNode,
  6363. o: options
  6364. };
  6365. let hydrate;
  6366. let hydrateNode;
  6367. if (createHydrationFns) {
  6368. [hydrate, hydrateNode] = createHydrationFns(internals);
  6369. }
  6370. return {
  6371. render,
  6372. hydrate,
  6373. createApp: createAppAPI(render, hydrate)
  6374. };
  6375. }
  6376. function toggleRecurse({ effect, update }, allowed) {
  6377. effect.allowRecurse = update.allowRecurse = allowed;
  6378. }
  6379. /**
  6380. * #1156
  6381. * When a component is HMR-enabled, we need to make sure that all static nodes
  6382. * inside a block also inherit the DOM element from the previous tree so that
  6383. * HMR updates (which are full updates) can retrieve the element for patching.
  6384. *
  6385. * #2080
  6386. * Inside keyed `template` fragment static children, if a fragment is moved,
  6387. * the children will always be moved. Therefore, in order to ensure correct move
  6388. * position, el should be inherited from previous nodes.
  6389. */
  6390. function traverseStaticChildren(n1, n2, shallow = false) {
  6391. const ch1 = n1.children;
  6392. const ch2 = n2.children;
  6393. if (isArray(ch1) && isArray(ch2)) {
  6394. for (let i = 0; i < ch1.length; i++) {
  6395. // this is only called in the optimized path so array children are
  6396. // guaranteed to be vnodes
  6397. const c1 = ch1[i];
  6398. let c2 = ch2[i];
  6399. if (c2.shapeFlag & 1 /* ELEMENT */ && !c2.dynamicChildren) {
  6400. if (c2.patchFlag <= 0 || c2.patchFlag === 32 /* HYDRATE_EVENTS */) {
  6401. c2 = ch2[i] = cloneIfMounted(ch2[i]);
  6402. c2.el = c1.el;
  6403. }
  6404. if (!shallow)
  6405. traverseStaticChildren(c1, c2);
  6406. }
  6407. // also inherit for comment nodes, but not placeholders (e.g. v-if which
  6408. // would have received .el during block patch)
  6409. if (c2.type === Comment && !c2.el) {
  6410. c2.el = c1.el;
  6411. }
  6412. }
  6413. }
  6414. }
  6415. // https://en.wikipedia.org/wiki/Longest_increasing_subsequence
  6416. function getSequence(arr) {
  6417. const p = arr.slice();
  6418. const result = [0];
  6419. let i, j, u, v, c;
  6420. const len = arr.length;
  6421. for (i = 0; i < len; i++) {
  6422. const arrI = arr[i];
  6423. if (arrI !== 0) {
  6424. j = result[result.length - 1];
  6425. if (arr[j] < arrI) {
  6426. p[i] = j;
  6427. result.push(i);
  6428. continue;
  6429. }
  6430. u = 0;
  6431. v = result.length - 1;
  6432. while (u < v) {
  6433. c = (u + v) >> 1;
  6434. if (arr[result[c]] < arrI) {
  6435. u = c + 1;
  6436. }
  6437. else {
  6438. v = c;
  6439. }
  6440. }
  6441. if (arrI < arr[result[u]]) {
  6442. if (u > 0) {
  6443. p[i] = result[u - 1];
  6444. }
  6445. result[u] = i;
  6446. }
  6447. }
  6448. }
  6449. u = result.length;
  6450. v = result[u - 1];
  6451. while (u-- > 0) {
  6452. result[u] = v;
  6453. v = p[v];
  6454. }
  6455. return result;
  6456. }
  6457. const isTeleport = (type) => type.__isTeleport;
  6458. const isTeleportDisabled = (props) => props && (props.disabled || props.disabled === '');
  6459. const isTargetSVG = (target) => typeof SVGElement !== 'undefined' && target instanceof SVGElement;
  6460. const resolveTarget = (props, select) => {
  6461. const targetSelector = props && props.to;
  6462. if (isString(targetSelector)) {
  6463. if (!select) {
  6464. warn$1(`Current renderer does not support string target for Teleports. ` +
  6465. `(missing querySelector renderer option)`);
  6466. return null;
  6467. }
  6468. else {
  6469. const target = select(targetSelector);
  6470. if (!target) {
  6471. warn$1(`Failed to locate Teleport target with selector "${targetSelector}". ` +
  6472. `Note the target element must exist before the component is mounted - ` +
  6473. `i.e. the target cannot be rendered by the component itself, and ` +
  6474. `ideally should be outside of the entire Vue component tree.`);
  6475. }
  6476. return target;
  6477. }
  6478. }
  6479. else {
  6480. if (!targetSelector && !isTeleportDisabled(props)) {
  6481. warn$1(`Invalid Teleport target: ${targetSelector}`);
  6482. }
  6483. return targetSelector;
  6484. }
  6485. };
  6486. const TeleportImpl = {
  6487. __isTeleport: true,
  6488. process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, internals) {
  6489. const { mc: mountChildren, pc: patchChildren, pbc: patchBlockChildren, o: { insert, querySelector, createText, createComment } } = internals;
  6490. const disabled = isTeleportDisabled(n2.props);
  6491. let { shapeFlag, children, dynamicChildren } = n2;
  6492. // #3302
  6493. // HMR updated, force full diff
  6494. if (isHmrUpdating) {
  6495. optimized = false;
  6496. dynamicChildren = null;
  6497. }
  6498. if (n1 == null) {
  6499. // insert anchors in the main view
  6500. const placeholder = (n2.el = createComment('teleport start')
  6501. );
  6502. const mainAnchor = (n2.anchor = createComment('teleport end')
  6503. );
  6504. insert(placeholder, container, anchor);
  6505. insert(mainAnchor, container, anchor);
  6506. const target = (n2.target = resolveTarget(n2.props, querySelector));
  6507. const targetAnchor = (n2.targetAnchor = createText(''));
  6508. if (target) {
  6509. insert(targetAnchor, target);
  6510. // #2652 we could be teleporting from a non-SVG tree into an SVG tree
  6511. isSVG = isSVG || isTargetSVG(target);
  6512. }
  6513. else if (!disabled) {
  6514. warn$1('Invalid Teleport target on mount:', target, `(${typeof target})`);
  6515. }
  6516. const mount = (container, anchor) => {
  6517. // Teleport *always* has Array children. This is enforced in both the
  6518. // compiler and vnode children normalization.
  6519. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  6520. mountChildren(children, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6521. }
  6522. };
  6523. if (disabled) {
  6524. mount(container, mainAnchor);
  6525. }
  6526. else if (target) {
  6527. mount(target, targetAnchor);
  6528. }
  6529. }
  6530. else {
  6531. // update content
  6532. n2.el = n1.el;
  6533. const mainAnchor = (n2.anchor = n1.anchor);
  6534. const target = (n2.target = n1.target);
  6535. const targetAnchor = (n2.targetAnchor = n1.targetAnchor);
  6536. const wasDisabled = isTeleportDisabled(n1.props);
  6537. const currentContainer = wasDisabled ? container : target;
  6538. const currentAnchor = wasDisabled ? mainAnchor : targetAnchor;
  6539. isSVG = isSVG || isTargetSVG(target);
  6540. if (dynamicChildren) {
  6541. // fast path when the teleport happens to be a block root
  6542. patchBlockChildren(n1.dynamicChildren, dynamicChildren, currentContainer, parentComponent, parentSuspense, isSVG, slotScopeIds);
  6543. // even in block tree mode we need to make sure all root-level nodes
  6544. // in the teleport inherit previous DOM references so that they can
  6545. // be moved in future patches.
  6546. traverseStaticChildren(n1, n2, true);
  6547. }
  6548. else if (!optimized) {
  6549. patchChildren(n1, n2, currentContainer, currentAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, false);
  6550. }
  6551. if (disabled) {
  6552. if (!wasDisabled) {
  6553. // enabled -> disabled
  6554. // move into main container
  6555. moveTeleport(n2, container, mainAnchor, internals, 1 /* TOGGLE */);
  6556. }
  6557. }
  6558. else {
  6559. // target changed
  6560. if ((n2.props && n2.props.to) !== (n1.props && n1.props.to)) {
  6561. const nextTarget = (n2.target = resolveTarget(n2.props, querySelector));
  6562. if (nextTarget) {
  6563. moveTeleport(n2, nextTarget, null, internals, 0 /* TARGET_CHANGE */);
  6564. }
  6565. else {
  6566. warn$1('Invalid Teleport target on update:', target, `(${typeof target})`);
  6567. }
  6568. }
  6569. else if (wasDisabled) {
  6570. // disabled -> enabled
  6571. // move into teleport target
  6572. moveTeleport(n2, target, targetAnchor, internals, 1 /* TOGGLE */);
  6573. }
  6574. }
  6575. }
  6576. },
  6577. remove(vnode, parentComponent, parentSuspense, optimized, { um: unmount, o: { remove: hostRemove } }, doRemove) {
  6578. const { shapeFlag, children, anchor, targetAnchor, target, props } = vnode;
  6579. if (target) {
  6580. hostRemove(targetAnchor);
  6581. }
  6582. // an unmounted teleport should always remove its children if not disabled
  6583. if (doRemove || !isTeleportDisabled(props)) {
  6584. hostRemove(anchor);
  6585. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  6586. for (let i = 0; i < children.length; i++) {
  6587. const child = children[i];
  6588. unmount(child, parentComponent, parentSuspense, true, !!child.dynamicChildren);
  6589. }
  6590. }
  6591. }
  6592. },
  6593. move: moveTeleport,
  6594. hydrate: hydrateTeleport
  6595. };
  6596. function moveTeleport(vnode, container, parentAnchor, { o: { insert }, m: move }, moveType = 2 /* REORDER */) {
  6597. // move target anchor if this is a target change.
  6598. if (moveType === 0 /* TARGET_CHANGE */) {
  6599. insert(vnode.targetAnchor, container, parentAnchor);
  6600. }
  6601. const { el, anchor, shapeFlag, children, props } = vnode;
  6602. const isReorder = moveType === 2 /* REORDER */;
  6603. // move main view anchor if this is a re-order.
  6604. if (isReorder) {
  6605. insert(el, container, parentAnchor);
  6606. }
  6607. // if this is a re-order and teleport is enabled (content is in target)
  6608. // do not move children. So the opposite is: only move children if this
  6609. // is not a reorder, or the teleport is disabled
  6610. if (!isReorder || isTeleportDisabled(props)) {
  6611. // Teleport has either Array children or no children.
  6612. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  6613. for (let i = 0; i < children.length; i++) {
  6614. move(children[i], container, parentAnchor, 2 /* REORDER */);
  6615. }
  6616. }
  6617. }
  6618. // move main view anchor if this is a re-order.
  6619. if (isReorder) {
  6620. insert(anchor, container, parentAnchor);
  6621. }
  6622. }
  6623. function hydrateTeleport(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized, { o: { nextSibling, parentNode, querySelector } }, hydrateChildren) {
  6624. const target = (vnode.target = resolveTarget(vnode.props, querySelector));
  6625. if (target) {
  6626. // if multiple teleports rendered to the same target element, we need to
  6627. // pick up from where the last teleport finished instead of the first node
  6628. const targetNode = target._lpa || target.firstChild;
  6629. if (vnode.shapeFlag & 16 /* ARRAY_CHILDREN */) {
  6630. if (isTeleportDisabled(vnode.props)) {
  6631. vnode.anchor = hydrateChildren(nextSibling(node), vnode, parentNode(node), parentComponent, parentSuspense, slotScopeIds, optimized);
  6632. vnode.targetAnchor = targetNode;
  6633. }
  6634. else {
  6635. vnode.anchor = nextSibling(node);
  6636. vnode.targetAnchor = hydrateChildren(targetNode, vnode, target, parentComponent, parentSuspense, slotScopeIds, optimized);
  6637. }
  6638. target._lpa =
  6639. vnode.targetAnchor && nextSibling(vnode.targetAnchor);
  6640. }
  6641. }
  6642. return vnode.anchor && nextSibling(vnode.anchor);
  6643. }
  6644. // Force-casted public typing for h and TSX props inference
  6645. const Teleport = TeleportImpl;
  6646. const COMPONENTS = 'components';
  6647. const DIRECTIVES = 'directives';
  6648. /**
  6649. * @private
  6650. */
  6651. function resolveComponent(name, maybeSelfReference) {
  6652. return resolveAsset(COMPONENTS, name, true, maybeSelfReference) || name;
  6653. }
  6654. const NULL_DYNAMIC_COMPONENT = Symbol();
  6655. /**
  6656. * @private
  6657. */
  6658. function resolveDynamicComponent(component) {
  6659. if (isString(component)) {
  6660. return resolveAsset(COMPONENTS, component, false) || component;
  6661. }
  6662. else {
  6663. // invalid types will fallthrough to createVNode and raise warning
  6664. return (component || NULL_DYNAMIC_COMPONENT);
  6665. }
  6666. }
  6667. /**
  6668. * @private
  6669. */
  6670. function resolveDirective(name) {
  6671. return resolveAsset(DIRECTIVES, name);
  6672. }
  6673. // implementation
  6674. function resolveAsset(type, name, warnMissing = true, maybeSelfReference = false) {
  6675. const instance = currentRenderingInstance || currentInstance;
  6676. if (instance) {
  6677. const Component = instance.type;
  6678. // explicit self name has highest priority
  6679. if (type === COMPONENTS) {
  6680. const selfName = getComponentName(Component);
  6681. if (selfName &&
  6682. (selfName === name ||
  6683. selfName === camelize(name) ||
  6684. selfName === capitalize(camelize(name)))) {
  6685. return Component;
  6686. }
  6687. }
  6688. const res =
  6689. // local registration
  6690. // check instance[type] first which is resolved for options API
  6691. resolve(instance[type] || Component[type], name) ||
  6692. // global registration
  6693. resolve(instance.appContext[type], name);
  6694. if (!res && maybeSelfReference) {
  6695. // fallback to implicit self-reference
  6696. return Component;
  6697. }
  6698. if (warnMissing && !res) {
  6699. const extra = type === COMPONENTS
  6700. ? `\nIf this is a native custom element, make sure to exclude it from ` +
  6701. `component resolution via compilerOptions.isCustomElement.`
  6702. : ``;
  6703. warn$1(`Failed to resolve ${type.slice(0, -1)}: ${name}${extra}`);
  6704. }
  6705. return res;
  6706. }
  6707. else {
  6708. warn$1(`resolve${capitalize(type.slice(0, -1))} ` +
  6709. `can only be used in render() or setup().`);
  6710. }
  6711. }
  6712. function resolve(registry, name) {
  6713. return (registry &&
  6714. (registry[name] ||
  6715. registry[camelize(name)] ||
  6716. registry[capitalize(camelize(name))]));
  6717. }
  6718. const Fragment = Symbol('Fragment' );
  6719. const Text = Symbol('Text' );
  6720. const Comment = Symbol('Comment' );
  6721. const Static = Symbol('Static' );
  6722. // Since v-if and v-for are the two possible ways node structure can dynamically
  6723. // change, once we consider v-if branches and each v-for fragment a block, we
  6724. // can divide a template into nested blocks, and within each block the node
  6725. // structure would be stable. This allows us to skip most children diffing
  6726. // and only worry about the dynamic nodes (indicated by patch flags).
  6727. const blockStack = [];
  6728. let currentBlock = null;
  6729. /**
  6730. * Open a block.
  6731. * This must be called before `createBlock`. It cannot be part of `createBlock`
  6732. * because the children of the block are evaluated before `createBlock` itself
  6733. * is called. The generated code typically looks like this:
  6734. *
  6735. * ```js
  6736. * function render() {
  6737. * return (openBlock(),createBlock('div', null, [...]))
  6738. * }
  6739. * ```
  6740. * disableTracking is true when creating a v-for fragment block, since a v-for
  6741. * fragment always diffs its children.
  6742. *
  6743. * @private
  6744. */
  6745. function openBlock(disableTracking = false) {
  6746. blockStack.push((currentBlock = disableTracking ? null : []));
  6747. }
  6748. function closeBlock() {
  6749. blockStack.pop();
  6750. currentBlock = blockStack[blockStack.length - 1] || null;
  6751. }
  6752. // Whether we should be tracking dynamic child nodes inside a block.
  6753. // Only tracks when this value is > 0
  6754. // We are not using a simple boolean because this value may need to be
  6755. // incremented/decremented by nested usage of v-once (see below)
  6756. let isBlockTreeEnabled = 1;
  6757. /**
  6758. * Block tracking sometimes needs to be disabled, for example during the
  6759. * creation of a tree that needs to be cached by v-once. The compiler generates
  6760. * code like this:
  6761. *
  6762. * ``` js
  6763. * _cache[1] || (
  6764. * setBlockTracking(-1),
  6765. * _cache[1] = createVNode(...),
  6766. * setBlockTracking(1),
  6767. * _cache[1]
  6768. * )
  6769. * ```
  6770. *
  6771. * @private
  6772. */
  6773. function setBlockTracking(value) {
  6774. isBlockTreeEnabled += value;
  6775. }
  6776. function setupBlock(vnode) {
  6777. // save current block children on the block vnode
  6778. vnode.dynamicChildren =
  6779. isBlockTreeEnabled > 0 ? currentBlock || EMPTY_ARR : null;
  6780. // close block
  6781. closeBlock();
  6782. // a block is always going to be patched, so track it as a child of its
  6783. // parent block
  6784. if (isBlockTreeEnabled > 0 && currentBlock) {
  6785. currentBlock.push(vnode);
  6786. }
  6787. return vnode;
  6788. }
  6789. /**
  6790. * @private
  6791. */
  6792. function createElementBlock(type, props, children, patchFlag, dynamicProps, shapeFlag) {
  6793. return setupBlock(createBaseVNode(type, props, children, patchFlag, dynamicProps, shapeFlag, true /* isBlock */));
  6794. }
  6795. /**
  6796. * Create a block root vnode. Takes the same exact arguments as `createVNode`.
  6797. * A block root keeps track of dynamic nodes within the block in the
  6798. * `dynamicChildren` array.
  6799. *
  6800. * @private
  6801. */
  6802. function createBlock(type, props, children, patchFlag, dynamicProps) {
  6803. return setupBlock(createVNode(type, props, children, patchFlag, dynamicProps, true /* isBlock: prevent a block from tracking itself */));
  6804. }
  6805. function isVNode(value) {
  6806. return value ? value.__v_isVNode === true : false;
  6807. }
  6808. function isSameVNodeType(n1, n2) {
  6809. if (n2.shapeFlag & 6 /* COMPONENT */ &&
  6810. hmrDirtyComponents.has(n2.type)) {
  6811. // HMR only: if the component has been hot-updated, force a reload.
  6812. return false;
  6813. }
  6814. return n1.type === n2.type && n1.key === n2.key;
  6815. }
  6816. let vnodeArgsTransformer;
  6817. /**
  6818. * Internal API for registering an arguments transform for createVNode
  6819. * used for creating stubs in the test-utils
  6820. * It is *internal* but needs to be exposed for test-utils to pick up proper
  6821. * typings
  6822. */
  6823. function transformVNodeArgs(transformer) {
  6824. vnodeArgsTransformer = transformer;
  6825. }
  6826. const createVNodeWithArgsTransform = (...args) => {
  6827. return _createVNode(...(vnodeArgsTransformer
  6828. ? vnodeArgsTransformer(args, currentRenderingInstance)
  6829. : args));
  6830. };
  6831. const InternalObjectKey = `__vInternal`;
  6832. const normalizeKey = ({ key }) => key != null ? key : null;
  6833. const normalizeRef = ({ ref, ref_key, ref_for }) => {
  6834. return (ref != null
  6835. ? isString(ref) || isRef(ref) || isFunction(ref)
  6836. ? { i: currentRenderingInstance, r: ref, k: ref_key, f: !!ref_for }
  6837. : ref
  6838. : null);
  6839. };
  6840. function createBaseVNode(type, props = null, children = null, patchFlag = 0, dynamicProps = null, shapeFlag = type === Fragment ? 0 : 1 /* ELEMENT */, isBlockNode = false, needFullChildrenNormalization = false) {
  6841. const vnode = {
  6842. __v_isVNode: true,
  6843. __v_skip: true,
  6844. type,
  6845. props,
  6846. key: props && normalizeKey(props),
  6847. ref: props && normalizeRef(props),
  6848. scopeId: currentScopeId,
  6849. slotScopeIds: null,
  6850. children,
  6851. component: null,
  6852. suspense: null,
  6853. ssContent: null,
  6854. ssFallback: null,
  6855. dirs: null,
  6856. transition: null,
  6857. el: null,
  6858. anchor: null,
  6859. target: null,
  6860. targetAnchor: null,
  6861. staticCount: 0,
  6862. shapeFlag,
  6863. patchFlag,
  6864. dynamicProps,
  6865. dynamicChildren: null,
  6866. appContext: null
  6867. };
  6868. if (needFullChildrenNormalization) {
  6869. normalizeChildren(vnode, children);
  6870. // normalize suspense children
  6871. if (shapeFlag & 128 /* SUSPENSE */) {
  6872. type.normalize(vnode);
  6873. }
  6874. }
  6875. else if (children) {
  6876. // compiled element vnode - if children is passed, only possible types are
  6877. // string or Array.
  6878. vnode.shapeFlag |= isString(children)
  6879. ? 8 /* TEXT_CHILDREN */
  6880. : 16 /* ARRAY_CHILDREN */;
  6881. }
  6882. // validate key
  6883. if (vnode.key !== vnode.key) {
  6884. warn$1(`VNode created with invalid key (NaN). VNode type:`, vnode.type);
  6885. }
  6886. // track vnode for block tree
  6887. if (isBlockTreeEnabled > 0 &&
  6888. // avoid a block node from tracking itself
  6889. !isBlockNode &&
  6890. // has current parent block
  6891. currentBlock &&
  6892. // presence of a patch flag indicates this node needs patching on updates.
  6893. // component nodes also should always be patched, because even if the
  6894. // component doesn't need to update, it needs to persist the instance on to
  6895. // the next vnode so that it can be properly unmounted later.
  6896. (vnode.patchFlag > 0 || shapeFlag & 6 /* COMPONENT */) &&
  6897. // the EVENTS flag is only for hydration and if it is the only flag, the
  6898. // vnode should not be considered dynamic due to handler caching.
  6899. vnode.patchFlag !== 32 /* HYDRATE_EVENTS */) {
  6900. currentBlock.push(vnode);
  6901. }
  6902. return vnode;
  6903. }
  6904. const createVNode = (createVNodeWithArgsTransform );
  6905. function _createVNode(type, props = null, children = null, patchFlag = 0, dynamicProps = null, isBlockNode = false) {
  6906. if (!type || type === NULL_DYNAMIC_COMPONENT) {
  6907. if (!type) {
  6908. warn$1(`Invalid vnode type when creating vnode: ${type}.`);
  6909. }
  6910. type = Comment;
  6911. }
  6912. if (isVNode(type)) {
  6913. // createVNode receiving an existing vnode. This happens in cases like
  6914. // <component :is="vnode"/>
  6915. // #2078 make sure to merge refs during the clone instead of overwriting it
  6916. const cloned = cloneVNode(type, props, true /* mergeRef: true */);
  6917. if (children) {
  6918. normalizeChildren(cloned, children);
  6919. }
  6920. return cloned;
  6921. }
  6922. // class component normalization.
  6923. if (isClassComponent(type)) {
  6924. type = type.__vccOpts;
  6925. }
  6926. // class & style normalization.
  6927. if (props) {
  6928. // for reactive or proxy objects, we need to clone it to enable mutation.
  6929. props = guardReactiveProps(props);
  6930. let { class: klass, style } = props;
  6931. if (klass && !isString(klass)) {
  6932. props.class = normalizeClass(klass);
  6933. }
  6934. if (isObject(style)) {
  6935. // reactive state objects need to be cloned since they are likely to be
  6936. // mutated
  6937. if (isProxy(style) && !isArray(style)) {
  6938. style = extend({}, style);
  6939. }
  6940. props.style = normalizeStyle(style);
  6941. }
  6942. }
  6943. // encode the vnode type information into a bitmap
  6944. const shapeFlag = isString(type)
  6945. ? 1 /* ELEMENT */
  6946. : isSuspense(type)
  6947. ? 128 /* SUSPENSE */
  6948. : isTeleport(type)
  6949. ? 64 /* TELEPORT */
  6950. : isObject(type)
  6951. ? 4 /* STATEFUL_COMPONENT */
  6952. : isFunction(type)
  6953. ? 2 /* FUNCTIONAL_COMPONENT */
  6954. : 0;
  6955. if (shapeFlag & 4 /* STATEFUL_COMPONENT */ && isProxy(type)) {
  6956. type = toRaw(type);
  6957. warn$1(`Vue received a Component which was made a reactive object. This can ` +
  6958. `lead to unnecessary performance overhead, and should be avoided by ` +
  6959. `marking the component with \`markRaw\` or using \`shallowRef\` ` +
  6960. `instead of \`ref\`.`, `\nComponent that was made reactive: `, type);
  6961. }
  6962. return createBaseVNode(type, props, children, patchFlag, dynamicProps, shapeFlag, isBlockNode, true);
  6963. }
  6964. function guardReactiveProps(props) {
  6965. if (!props)
  6966. return null;
  6967. return isProxy(props) || InternalObjectKey in props
  6968. ? extend({}, props)
  6969. : props;
  6970. }
  6971. function cloneVNode(vnode, extraProps, mergeRef = false) {
  6972. // This is intentionally NOT using spread or extend to avoid the runtime
  6973. // key enumeration cost.
  6974. const { props, ref, patchFlag, children } = vnode;
  6975. const mergedProps = extraProps ? mergeProps(props || {}, extraProps) : props;
  6976. const cloned = {
  6977. __v_isVNode: true,
  6978. __v_skip: true,
  6979. type: vnode.type,
  6980. props: mergedProps,
  6981. key: mergedProps && normalizeKey(mergedProps),
  6982. ref: extraProps && extraProps.ref
  6983. ? // #2078 in the case of <component :is="vnode" ref="extra"/>
  6984. // if the vnode itself already has a ref, cloneVNode will need to merge
  6985. // the refs so the single vnode can be set on multiple refs
  6986. mergeRef && ref
  6987. ? isArray(ref)
  6988. ? ref.concat(normalizeRef(extraProps))
  6989. : [ref, normalizeRef(extraProps)]
  6990. : normalizeRef(extraProps)
  6991. : ref,
  6992. scopeId: vnode.scopeId,
  6993. slotScopeIds: vnode.slotScopeIds,
  6994. children: patchFlag === -1 /* HOISTED */ && isArray(children)
  6995. ? children.map(deepCloneVNode)
  6996. : children,
  6997. target: vnode.target,
  6998. targetAnchor: vnode.targetAnchor,
  6999. staticCount: vnode.staticCount,
  7000. shapeFlag: vnode.shapeFlag,
  7001. // if the vnode is cloned with extra props, we can no longer assume its
  7002. // existing patch flag to be reliable and need to add the FULL_PROPS flag.
  7003. // note: perserve flag for fragments since they use the flag for children
  7004. // fast paths only.
  7005. patchFlag: extraProps && vnode.type !== Fragment
  7006. ? patchFlag === -1 // hoisted node
  7007. ? 16 /* FULL_PROPS */
  7008. : patchFlag | 16 /* FULL_PROPS */
  7009. : patchFlag,
  7010. dynamicProps: vnode.dynamicProps,
  7011. dynamicChildren: vnode.dynamicChildren,
  7012. appContext: vnode.appContext,
  7013. dirs: vnode.dirs,
  7014. transition: vnode.transition,
  7015. // These should technically only be non-null on mounted VNodes. However,
  7016. // they *should* be copied for kept-alive vnodes. So we just always copy
  7017. // them since them being non-null during a mount doesn't affect the logic as
  7018. // they will simply be overwritten.
  7019. component: vnode.component,
  7020. suspense: vnode.suspense,
  7021. ssContent: vnode.ssContent && cloneVNode(vnode.ssContent),
  7022. ssFallback: vnode.ssFallback && cloneVNode(vnode.ssFallback),
  7023. el: vnode.el,
  7024. anchor: vnode.anchor
  7025. };
  7026. return cloned;
  7027. }
  7028. /**
  7029. * Dev only, for HMR of hoisted vnodes reused in v-for
  7030. * https://github.com/vitejs/vite/issues/2022
  7031. */
  7032. function deepCloneVNode(vnode) {
  7033. const cloned = cloneVNode(vnode);
  7034. if (isArray(vnode.children)) {
  7035. cloned.children = vnode.children.map(deepCloneVNode);
  7036. }
  7037. return cloned;
  7038. }
  7039. /**
  7040. * @private
  7041. */
  7042. function createTextVNode(text = ' ', flag = 0) {
  7043. return createVNode(Text, null, text, flag);
  7044. }
  7045. /**
  7046. * @private
  7047. */
  7048. function createStaticVNode(content, numberOfNodes) {
  7049. // A static vnode can contain multiple stringified elements, and the number
  7050. // of elements is necessary for hydration.
  7051. const vnode = createVNode(Static, null, content);
  7052. vnode.staticCount = numberOfNodes;
  7053. return vnode;
  7054. }
  7055. /**
  7056. * @private
  7057. */
  7058. function createCommentVNode(text = '',
  7059. // when used as the v-else branch, the comment node must be created as a
  7060. // block to ensure correct updates.
  7061. asBlock = false) {
  7062. return asBlock
  7063. ? (openBlock(), createBlock(Comment, null, text))
  7064. : createVNode(Comment, null, text);
  7065. }
  7066. function normalizeVNode(child) {
  7067. if (child == null || typeof child === 'boolean') {
  7068. // empty placeholder
  7069. return createVNode(Comment);
  7070. }
  7071. else if (isArray(child)) {
  7072. // fragment
  7073. return createVNode(Fragment, null,
  7074. // #3666, avoid reference pollution when reusing vnode
  7075. child.slice());
  7076. }
  7077. else if (typeof child === 'object') {
  7078. // already vnode, this should be the most common since compiled templates
  7079. // always produce all-vnode children arrays
  7080. return cloneIfMounted(child);
  7081. }
  7082. else {
  7083. // strings and numbers
  7084. return createVNode(Text, null, String(child));
  7085. }
  7086. }
  7087. // optimized normalization for template-compiled render fns
  7088. function cloneIfMounted(child) {
  7089. return child.el === null || child.memo ? child : cloneVNode(child);
  7090. }
  7091. function normalizeChildren(vnode, children) {
  7092. let type = 0;
  7093. const { shapeFlag } = vnode;
  7094. if (children == null) {
  7095. children = null;
  7096. }
  7097. else if (isArray(children)) {
  7098. type = 16 /* ARRAY_CHILDREN */;
  7099. }
  7100. else if (typeof children === 'object') {
  7101. if (shapeFlag & (1 /* ELEMENT */ | 64 /* TELEPORT */)) {
  7102. // Normalize slot to plain children for plain element and Teleport
  7103. const slot = children.default;
  7104. if (slot) {
  7105. // _c marker is added by withCtx() indicating this is a compiled slot
  7106. slot._c && (slot._d = false);
  7107. normalizeChildren(vnode, slot());
  7108. slot._c && (slot._d = true);
  7109. }
  7110. return;
  7111. }
  7112. else {
  7113. type = 32 /* SLOTS_CHILDREN */;
  7114. const slotFlag = children._;
  7115. if (!slotFlag && !(InternalObjectKey in children)) {
  7116. children._ctx = currentRenderingInstance;
  7117. }
  7118. else if (slotFlag === 3 /* FORWARDED */ && currentRenderingInstance) {
  7119. // a child component receives forwarded slots from the parent.
  7120. // its slot type is determined by its parent's slot type.
  7121. if (currentRenderingInstance.slots._ === 1 /* STABLE */) {
  7122. children._ = 1 /* STABLE */;
  7123. }
  7124. else {
  7125. children._ = 2 /* DYNAMIC */;
  7126. vnode.patchFlag |= 1024 /* DYNAMIC_SLOTS */;
  7127. }
  7128. }
  7129. }
  7130. }
  7131. else if (isFunction(children)) {
  7132. children = { default: children, _ctx: currentRenderingInstance };
  7133. type = 32 /* SLOTS_CHILDREN */;
  7134. }
  7135. else {
  7136. children = String(children);
  7137. // force teleport children to array so it can be moved around
  7138. if (shapeFlag & 64 /* TELEPORT */) {
  7139. type = 16 /* ARRAY_CHILDREN */;
  7140. children = [createTextVNode(children)];
  7141. }
  7142. else {
  7143. type = 8 /* TEXT_CHILDREN */;
  7144. }
  7145. }
  7146. vnode.children = children;
  7147. vnode.shapeFlag |= type;
  7148. }
  7149. function mergeProps(...args) {
  7150. const ret = {};
  7151. for (let i = 0; i < args.length; i++) {
  7152. const toMerge = args[i];
  7153. for (const key in toMerge) {
  7154. if (key === 'class') {
  7155. if (ret.class !== toMerge.class) {
  7156. ret.class = normalizeClass([ret.class, toMerge.class]);
  7157. }
  7158. }
  7159. else if (key === 'style') {
  7160. ret.style = normalizeStyle([ret.style, toMerge.style]);
  7161. }
  7162. else if (isOn(key)) {
  7163. const existing = ret[key];
  7164. const incoming = toMerge[key];
  7165. if (existing !== incoming &&
  7166. !(isArray(existing) && existing.includes(incoming))) {
  7167. ret[key] = existing
  7168. ? [].concat(existing, incoming)
  7169. : incoming;
  7170. }
  7171. }
  7172. else if (key !== '') {
  7173. ret[key] = toMerge[key];
  7174. }
  7175. }
  7176. }
  7177. return ret;
  7178. }
  7179. function invokeVNodeHook(hook, instance, vnode, prevVNode = null) {
  7180. callWithAsyncErrorHandling(hook, instance, 7 /* VNODE_HOOK */, [
  7181. vnode,
  7182. prevVNode
  7183. ]);
  7184. }
  7185. /**
  7186. * Actual implementation
  7187. */
  7188. function renderList(source, renderItem, cache, index) {
  7189. let ret;
  7190. const cached = (cache && cache[index]);
  7191. if (isArray(source) || isString(source)) {
  7192. ret = new Array(source.length);
  7193. for (let i = 0, l = source.length; i < l; i++) {
  7194. ret[i] = renderItem(source[i], i, undefined, cached && cached[i]);
  7195. }
  7196. }
  7197. else if (typeof source === 'number') {
  7198. if (!Number.isInteger(source)) {
  7199. warn$1(`The v-for range expect an integer value but got ${source}.`);
  7200. return [];
  7201. }
  7202. ret = new Array(source);
  7203. for (let i = 0; i < source; i++) {
  7204. ret[i] = renderItem(i + 1, i, undefined, cached && cached[i]);
  7205. }
  7206. }
  7207. else if (isObject(source)) {
  7208. if (source[Symbol.iterator]) {
  7209. ret = Array.from(source, (item, i) => renderItem(item, i, undefined, cached && cached[i]));
  7210. }
  7211. else {
  7212. const keys = Object.keys(source);
  7213. ret = new Array(keys.length);
  7214. for (let i = 0, l = keys.length; i < l; i++) {
  7215. const key = keys[i];
  7216. ret[i] = renderItem(source[key], key, i, cached && cached[i]);
  7217. }
  7218. }
  7219. }
  7220. else {
  7221. ret = [];
  7222. }
  7223. if (cache) {
  7224. cache[index] = ret;
  7225. }
  7226. return ret;
  7227. }
  7228. /**
  7229. * Compiler runtime helper for creating dynamic slots object
  7230. * @private
  7231. */
  7232. function createSlots(slots, dynamicSlots) {
  7233. for (let i = 0; i < dynamicSlots.length; i++) {
  7234. const slot = dynamicSlots[i];
  7235. // array of dynamic slot generated by <template v-for="..." #[...]>
  7236. if (isArray(slot)) {
  7237. for (let j = 0; j < slot.length; j++) {
  7238. slots[slot[j].name] = slot[j].fn;
  7239. }
  7240. }
  7241. else if (slot) {
  7242. // conditional single slot generated by <template v-if="..." #foo>
  7243. slots[slot.name] = slot.fn;
  7244. }
  7245. }
  7246. return slots;
  7247. }
  7248. /**
  7249. * Compiler runtime helper for rendering `<slot/>`
  7250. * @private
  7251. */
  7252. function renderSlot(slots, name, props = {},
  7253. // this is not a user-facing function, so the fallback is always generated by
  7254. // the compiler and guaranteed to be a function returning an array
  7255. fallback, noSlotted) {
  7256. if (currentRenderingInstance.isCE) {
  7257. return createVNode('slot', name === 'default' ? null : { name }, fallback && fallback());
  7258. }
  7259. let slot = slots[name];
  7260. if (slot && slot.length > 1) {
  7261. warn$1(`SSR-optimized slot function detected in a non-SSR-optimized render ` +
  7262. `function. You need to mark this component with $dynamic-slots in the ` +
  7263. `parent template.`);
  7264. slot = () => [];
  7265. }
  7266. // a compiled slot disables block tracking by default to avoid manual
  7267. // invocation interfering with template-based block tracking, but in
  7268. // `renderSlot` we can be sure that it's template-based so we can force
  7269. // enable it.
  7270. if (slot && slot._c) {
  7271. slot._d = false;
  7272. }
  7273. openBlock();
  7274. const validSlotContent = slot && ensureValidVNode(slot(props));
  7275. const rendered = createBlock(Fragment, { key: props.key || `_${name}` }, validSlotContent || (fallback ? fallback() : []), validSlotContent && slots._ === 1 /* STABLE */
  7276. ? 64 /* STABLE_FRAGMENT */
  7277. : -2 /* BAIL */);
  7278. if (!noSlotted && rendered.scopeId) {
  7279. rendered.slotScopeIds = [rendered.scopeId + '-s'];
  7280. }
  7281. if (slot && slot._c) {
  7282. slot._d = true;
  7283. }
  7284. return rendered;
  7285. }
  7286. function ensureValidVNode(vnodes) {
  7287. return vnodes.some(child => {
  7288. if (!isVNode(child))
  7289. return true;
  7290. if (child.type === Comment)
  7291. return false;
  7292. if (child.type === Fragment &&
  7293. !ensureValidVNode(child.children))
  7294. return false;
  7295. return true;
  7296. })
  7297. ? vnodes
  7298. : null;
  7299. }
  7300. /**
  7301. * For prefixing keys in v-on="obj" with "on"
  7302. * @private
  7303. */
  7304. function toHandlers(obj) {
  7305. const ret = {};
  7306. if (!isObject(obj)) {
  7307. warn$1(`v-on with no argument expects an object value.`);
  7308. return ret;
  7309. }
  7310. for (const key in obj) {
  7311. ret[toHandlerKey(key)] = obj[key];
  7312. }
  7313. return ret;
  7314. }
  7315. /**
  7316. * #2437 In Vue 3, functional components do not have a public instance proxy but
  7317. * they exist in the internal parent chain. For code that relies on traversing
  7318. * public $parent chains, skip functional ones and go to the parent instead.
  7319. */
  7320. const getPublicInstance = (i) => {
  7321. if (!i)
  7322. return null;
  7323. if (isStatefulComponent(i))
  7324. return getExposeProxy(i) || i.proxy;
  7325. return getPublicInstance(i.parent);
  7326. };
  7327. const publicPropertiesMap = extend(Object.create(null), {
  7328. $: i => i,
  7329. $el: i => i.vnode.el,
  7330. $data: i => i.data,
  7331. $props: i => (shallowReadonly(i.props) ),
  7332. $attrs: i => (shallowReadonly(i.attrs) ),
  7333. $slots: i => (shallowReadonly(i.slots) ),
  7334. $refs: i => (shallowReadonly(i.refs) ),
  7335. $parent: i => getPublicInstance(i.parent),
  7336. $root: i => getPublicInstance(i.root),
  7337. $emit: i => i.emit,
  7338. $options: i => (resolveMergedOptions(i) ),
  7339. $forceUpdate: i => () => queueJob(i.update),
  7340. $nextTick: i => nextTick.bind(i.proxy),
  7341. $watch: i => (instanceWatch.bind(i) )
  7342. });
  7343. const PublicInstanceProxyHandlers = {
  7344. get({ _: instance }, key) {
  7345. const { ctx, setupState, data, props, accessCache, type, appContext } = instance;
  7346. // for internal formatters to know that this is a Vue instance
  7347. if (key === '__isVue') {
  7348. return true;
  7349. }
  7350. // prioritize <script setup> bindings during dev.
  7351. // this allows even properties that start with _ or $ to be used - so that
  7352. // it aligns with the production behavior where the render fn is inlined and
  7353. // indeed has access to all declared variables.
  7354. if (setupState !== EMPTY_OBJ &&
  7355. setupState.__isScriptSetup &&
  7356. hasOwn(setupState, key)) {
  7357. return setupState[key];
  7358. }
  7359. // data / props / ctx
  7360. // This getter gets called for every property access on the render context
  7361. // during render and is a major hotspot. The most expensive part of this
  7362. // is the multiple hasOwn() calls. It's much faster to do a simple property
  7363. // access on a plain object, so we use an accessCache object (with null
  7364. // prototype) to memoize what access type a key corresponds to.
  7365. let normalizedProps;
  7366. if (key[0] !== '$') {
  7367. const n = accessCache[key];
  7368. if (n !== undefined) {
  7369. switch (n) {
  7370. case 1 /* SETUP */:
  7371. return setupState[key];
  7372. case 2 /* DATA */:
  7373. return data[key];
  7374. case 4 /* CONTEXT */:
  7375. return ctx[key];
  7376. case 3 /* PROPS */:
  7377. return props[key];
  7378. // default: just fallthrough
  7379. }
  7380. }
  7381. else if (setupState !== EMPTY_OBJ && hasOwn(setupState, key)) {
  7382. accessCache[key] = 1 /* SETUP */;
  7383. return setupState[key];
  7384. }
  7385. else if (data !== EMPTY_OBJ && hasOwn(data, key)) {
  7386. accessCache[key] = 2 /* DATA */;
  7387. return data[key];
  7388. }
  7389. else if (
  7390. // only cache other properties when instance has declared (thus stable)
  7391. // props
  7392. (normalizedProps = instance.propsOptions[0]) &&
  7393. hasOwn(normalizedProps, key)) {
  7394. accessCache[key] = 3 /* PROPS */;
  7395. return props[key];
  7396. }
  7397. else if (ctx !== EMPTY_OBJ && hasOwn(ctx, key)) {
  7398. accessCache[key] = 4 /* CONTEXT */;
  7399. return ctx[key];
  7400. }
  7401. else if (shouldCacheAccess) {
  7402. accessCache[key] = 0 /* OTHER */;
  7403. }
  7404. }
  7405. const publicGetter = publicPropertiesMap[key];
  7406. let cssModule, globalProperties;
  7407. // public $xxx properties
  7408. if (publicGetter) {
  7409. if (key === '$attrs') {
  7410. track(instance, "get" /* GET */, key);
  7411. markAttrsAccessed();
  7412. }
  7413. return publicGetter(instance);
  7414. }
  7415. else if (
  7416. // css module (injected by vue-loader)
  7417. (cssModule = type.__cssModules) &&
  7418. (cssModule = cssModule[key])) {
  7419. return cssModule;
  7420. }
  7421. else if (ctx !== EMPTY_OBJ && hasOwn(ctx, key)) {
  7422. // user may set custom properties to `this` that start with `$`
  7423. accessCache[key] = 4 /* CONTEXT */;
  7424. return ctx[key];
  7425. }
  7426. else if (
  7427. // global properties
  7428. ((globalProperties = appContext.config.globalProperties),
  7429. hasOwn(globalProperties, key))) {
  7430. {
  7431. return globalProperties[key];
  7432. }
  7433. }
  7434. else if (currentRenderingInstance &&
  7435. (!isString(key) ||
  7436. // #1091 avoid internal isRef/isVNode checks on component instance leading
  7437. // to infinite warning loop
  7438. key.indexOf('__v') !== 0)) {
  7439. if (data !== EMPTY_OBJ &&
  7440. (key[0] === '$' || key[0] === '_') &&
  7441. hasOwn(data, key)) {
  7442. warn$1(`Property ${JSON.stringify(key)} must be accessed via $data because it starts with a reserved ` +
  7443. `character ("$" or "_") and is not proxied on the render context.`);
  7444. }
  7445. else if (instance === currentRenderingInstance) {
  7446. warn$1(`Property ${JSON.stringify(key)} was accessed during render ` +
  7447. `but is not defined on instance.`);
  7448. }
  7449. }
  7450. },
  7451. set({ _: instance }, key, value) {
  7452. const { data, setupState, ctx } = instance;
  7453. if (setupState !== EMPTY_OBJ && hasOwn(setupState, key)) {
  7454. setupState[key] = value;
  7455. }
  7456. else if (data !== EMPTY_OBJ && hasOwn(data, key)) {
  7457. data[key] = value;
  7458. }
  7459. else if (hasOwn(instance.props, key)) {
  7460. warn$1(`Attempting to mutate prop "${key}". Props are readonly.`, instance);
  7461. return false;
  7462. }
  7463. if (key[0] === '$' && key.slice(1) in instance) {
  7464. warn$1(`Attempting to mutate public property "${key}". ` +
  7465. `Properties starting with $ are reserved and readonly.`, instance);
  7466. return false;
  7467. }
  7468. else {
  7469. if (key in instance.appContext.config.globalProperties) {
  7470. Object.defineProperty(ctx, key, {
  7471. enumerable: true,
  7472. configurable: true,
  7473. value
  7474. });
  7475. }
  7476. else {
  7477. ctx[key] = value;
  7478. }
  7479. }
  7480. return true;
  7481. },
  7482. has({ _: { data, setupState, accessCache, ctx, appContext, propsOptions } }, key) {
  7483. let normalizedProps;
  7484. return (!!accessCache[key] ||
  7485. (data !== EMPTY_OBJ && hasOwn(data, key)) ||
  7486. (setupState !== EMPTY_OBJ && hasOwn(setupState, key)) ||
  7487. ((normalizedProps = propsOptions[0]) && hasOwn(normalizedProps, key)) ||
  7488. hasOwn(ctx, key) ||
  7489. hasOwn(publicPropertiesMap, key) ||
  7490. hasOwn(appContext.config.globalProperties, key));
  7491. }
  7492. };
  7493. {
  7494. PublicInstanceProxyHandlers.ownKeys = (target) => {
  7495. warn$1(`Avoid app logic that relies on enumerating keys on a component instance. ` +
  7496. `The keys will be empty in production mode to avoid performance overhead.`);
  7497. return Reflect.ownKeys(target);
  7498. };
  7499. }
  7500. const RuntimeCompiledPublicInstanceProxyHandlers = /*#__PURE__*/ extend({}, PublicInstanceProxyHandlers, {
  7501. get(target, key) {
  7502. // fast path for unscopables when using `with` block
  7503. if (key === Symbol.unscopables) {
  7504. return;
  7505. }
  7506. return PublicInstanceProxyHandlers.get(target, key, target);
  7507. },
  7508. has(_, key) {
  7509. const has = key[0] !== '_' && !isGloballyWhitelisted(key);
  7510. if (!has && PublicInstanceProxyHandlers.has(_, key)) {
  7511. warn$1(`Property ${JSON.stringify(key)} should not start with _ which is a reserved prefix for Vue internals.`);
  7512. }
  7513. return has;
  7514. }
  7515. });
  7516. // dev only
  7517. // In dev mode, the proxy target exposes the same properties as seen on `this`
  7518. // for easier console inspection. In prod mode it will be an empty object so
  7519. // these properties definitions can be skipped.
  7520. function createDevRenderContext(instance) {
  7521. const target = {};
  7522. // expose internal instance for proxy handlers
  7523. Object.defineProperty(target, `_`, {
  7524. configurable: true,
  7525. enumerable: false,
  7526. get: () => instance
  7527. });
  7528. // expose public properties
  7529. Object.keys(publicPropertiesMap).forEach(key => {
  7530. Object.defineProperty(target, key, {
  7531. configurable: true,
  7532. enumerable: false,
  7533. get: () => publicPropertiesMap[key](instance),
  7534. // intercepted by the proxy so no need for implementation,
  7535. // but needed to prevent set errors
  7536. set: NOOP
  7537. });
  7538. });
  7539. return target;
  7540. }
  7541. // dev only
  7542. function exposePropsOnRenderContext(instance) {
  7543. const { ctx, propsOptions: [propsOptions] } = instance;
  7544. if (propsOptions) {
  7545. Object.keys(propsOptions).forEach(key => {
  7546. Object.defineProperty(ctx, key, {
  7547. enumerable: true,
  7548. configurable: true,
  7549. get: () => instance.props[key],
  7550. set: NOOP
  7551. });
  7552. });
  7553. }
  7554. }
  7555. // dev only
  7556. function exposeSetupStateOnRenderContext(instance) {
  7557. const { ctx, setupState } = instance;
  7558. Object.keys(toRaw(setupState)).forEach(key => {
  7559. if (!setupState.__isScriptSetup) {
  7560. if (key[0] === '$' || key[0] === '_') {
  7561. warn$1(`setup() return property ${JSON.stringify(key)} should not start with "$" or "_" ` +
  7562. `which are reserved prefixes for Vue internals.`);
  7563. return;
  7564. }
  7565. Object.defineProperty(ctx, key, {
  7566. enumerable: true,
  7567. configurable: true,
  7568. get: () => setupState[key],
  7569. set: NOOP
  7570. });
  7571. }
  7572. });
  7573. }
  7574. const emptyAppContext = createAppContext();
  7575. let uid$1 = 0;
  7576. function createComponentInstance(vnode, parent, suspense) {
  7577. const type = vnode.type;
  7578. // inherit parent app context - or - if root, adopt from root vnode
  7579. const appContext = (parent ? parent.appContext : vnode.appContext) || emptyAppContext;
  7580. const instance = {
  7581. uid: uid$1++,
  7582. vnode,
  7583. type,
  7584. parent,
  7585. appContext,
  7586. root: null,
  7587. next: null,
  7588. subTree: null,
  7589. effect: null,
  7590. update: null,
  7591. scope: new EffectScope(true /* detached */),
  7592. render: null,
  7593. proxy: null,
  7594. exposed: null,
  7595. exposeProxy: null,
  7596. withProxy: null,
  7597. provides: parent ? parent.provides : Object.create(appContext.provides),
  7598. accessCache: null,
  7599. renderCache: [],
  7600. // local resovled assets
  7601. components: null,
  7602. directives: null,
  7603. // resolved props and emits options
  7604. propsOptions: normalizePropsOptions(type, appContext),
  7605. emitsOptions: normalizeEmitsOptions(type, appContext),
  7606. // emit
  7607. emit: null,
  7608. emitted: null,
  7609. // props default value
  7610. propsDefaults: EMPTY_OBJ,
  7611. // inheritAttrs
  7612. inheritAttrs: type.inheritAttrs,
  7613. // state
  7614. ctx: EMPTY_OBJ,
  7615. data: EMPTY_OBJ,
  7616. props: EMPTY_OBJ,
  7617. attrs: EMPTY_OBJ,
  7618. slots: EMPTY_OBJ,
  7619. refs: EMPTY_OBJ,
  7620. setupState: EMPTY_OBJ,
  7621. setupContext: null,
  7622. // suspense related
  7623. suspense,
  7624. suspenseId: suspense ? suspense.pendingId : 0,
  7625. asyncDep: null,
  7626. asyncResolved: false,
  7627. // lifecycle hooks
  7628. // not using enums here because it results in computed properties
  7629. isMounted: false,
  7630. isUnmounted: false,
  7631. isDeactivated: false,
  7632. bc: null,
  7633. c: null,
  7634. bm: null,
  7635. m: null,
  7636. bu: null,
  7637. u: null,
  7638. um: null,
  7639. bum: null,
  7640. da: null,
  7641. a: null,
  7642. rtg: null,
  7643. rtc: null,
  7644. ec: null,
  7645. sp: null
  7646. };
  7647. {
  7648. instance.ctx = createDevRenderContext(instance);
  7649. }
  7650. instance.root = parent ? parent.root : instance;
  7651. instance.emit = emit$1.bind(null, instance);
  7652. // apply custom element special handling
  7653. if (vnode.ce) {
  7654. vnode.ce(instance);
  7655. }
  7656. return instance;
  7657. }
  7658. let currentInstance = null;
  7659. const getCurrentInstance = () => currentInstance || currentRenderingInstance;
  7660. const setCurrentInstance = (instance) => {
  7661. currentInstance = instance;
  7662. instance.scope.on();
  7663. };
  7664. const unsetCurrentInstance = () => {
  7665. currentInstance && currentInstance.scope.off();
  7666. currentInstance = null;
  7667. };
  7668. const isBuiltInTag = /*#__PURE__*/ makeMap('slot,component');
  7669. function validateComponentName(name, config) {
  7670. const appIsNativeTag = config.isNativeTag || NO;
  7671. if (isBuiltInTag(name) || appIsNativeTag(name)) {
  7672. warn$1('Do not use built-in or reserved HTML elements as component id: ' + name);
  7673. }
  7674. }
  7675. function isStatefulComponent(instance) {
  7676. return instance.vnode.shapeFlag & 4 /* STATEFUL_COMPONENT */;
  7677. }
  7678. let isInSSRComponentSetup = false;
  7679. function setupComponent(instance, isSSR = false) {
  7680. isInSSRComponentSetup = isSSR;
  7681. const { props, children } = instance.vnode;
  7682. const isStateful = isStatefulComponent(instance);
  7683. initProps(instance, props, isStateful, isSSR);
  7684. initSlots(instance, children);
  7685. const setupResult = isStateful
  7686. ? setupStatefulComponent(instance, isSSR)
  7687. : undefined;
  7688. isInSSRComponentSetup = false;
  7689. return setupResult;
  7690. }
  7691. function setupStatefulComponent(instance, isSSR) {
  7692. const Component = instance.type;
  7693. {
  7694. if (Component.name) {
  7695. validateComponentName(Component.name, instance.appContext.config);
  7696. }
  7697. if (Component.components) {
  7698. const names = Object.keys(Component.components);
  7699. for (let i = 0; i < names.length; i++) {
  7700. validateComponentName(names[i], instance.appContext.config);
  7701. }
  7702. }
  7703. if (Component.directives) {
  7704. const names = Object.keys(Component.directives);
  7705. for (let i = 0; i < names.length; i++) {
  7706. validateDirectiveName(names[i]);
  7707. }
  7708. }
  7709. if (Component.compilerOptions && isRuntimeOnly()) {
  7710. warn$1(`"compilerOptions" is only supported when using a build of Vue that ` +
  7711. `includes the runtime compiler. Since you are using a runtime-only ` +
  7712. `build, the options should be passed via your build tool config instead.`);
  7713. }
  7714. }
  7715. // 0. create render proxy property access cache
  7716. instance.accessCache = Object.create(null);
  7717. // 1. create public instance / render proxy
  7718. // also mark it raw so it's never observed
  7719. instance.proxy = markRaw(new Proxy(instance.ctx, PublicInstanceProxyHandlers));
  7720. {
  7721. exposePropsOnRenderContext(instance);
  7722. }
  7723. // 2. call setup()
  7724. const { setup } = Component;
  7725. if (setup) {
  7726. const setupContext = (instance.setupContext =
  7727. setup.length > 1 ? createSetupContext(instance) : null);
  7728. setCurrentInstance(instance);
  7729. pauseTracking();
  7730. const setupResult = callWithErrorHandling(setup, instance, 0 /* SETUP_FUNCTION */, [shallowReadonly(instance.props) , setupContext]);
  7731. resetTracking();
  7732. unsetCurrentInstance();
  7733. if (isPromise(setupResult)) {
  7734. setupResult.then(unsetCurrentInstance, unsetCurrentInstance);
  7735. if (isSSR) {
  7736. // return the promise so server-renderer can wait on it
  7737. return setupResult
  7738. .then((resolvedResult) => {
  7739. handleSetupResult(instance, resolvedResult, isSSR);
  7740. })
  7741. .catch(e => {
  7742. handleError(e, instance, 0 /* SETUP_FUNCTION */);
  7743. });
  7744. }
  7745. else {
  7746. // async setup returned Promise.
  7747. // bail here and wait for re-entry.
  7748. instance.asyncDep = setupResult;
  7749. }
  7750. }
  7751. else {
  7752. handleSetupResult(instance, setupResult, isSSR);
  7753. }
  7754. }
  7755. else {
  7756. finishComponentSetup(instance, isSSR);
  7757. }
  7758. }
  7759. function handleSetupResult(instance, setupResult, isSSR) {
  7760. if (isFunction(setupResult)) {
  7761. // setup returned an inline render function
  7762. {
  7763. instance.render = setupResult;
  7764. }
  7765. }
  7766. else if (isObject(setupResult)) {
  7767. if (isVNode(setupResult)) {
  7768. warn$1(`setup() should not return VNodes directly - ` +
  7769. `return a render function instead.`);
  7770. }
  7771. // setup returned bindings.
  7772. // assuming a render function compiled from template is present.
  7773. {
  7774. instance.devtoolsRawSetupState = setupResult;
  7775. }
  7776. instance.setupState = proxyRefs(setupResult);
  7777. {
  7778. exposeSetupStateOnRenderContext(instance);
  7779. }
  7780. }
  7781. else if (setupResult !== undefined) {
  7782. warn$1(`setup() should return an object. Received: ${setupResult === null ? 'null' : typeof setupResult}`);
  7783. }
  7784. finishComponentSetup(instance, isSSR);
  7785. }
  7786. let compile;
  7787. let installWithProxy;
  7788. /**
  7789. * For runtime-dom to register the compiler.
  7790. * Note the exported method uses any to avoid d.ts relying on the compiler types.
  7791. */
  7792. function registerRuntimeCompiler(_compile) {
  7793. compile = _compile;
  7794. installWithProxy = i => {
  7795. if (i.render._rc) {
  7796. i.withProxy = new Proxy(i.ctx, RuntimeCompiledPublicInstanceProxyHandlers);
  7797. }
  7798. };
  7799. }
  7800. // dev only
  7801. const isRuntimeOnly = () => !compile;
  7802. function finishComponentSetup(instance, isSSR, skipOptions) {
  7803. const Component = instance.type;
  7804. // template / render function normalization
  7805. // could be already set when returned from setup()
  7806. if (!instance.render) {
  7807. // only do on-the-fly compile if not in SSR - SSR on-the-fly compliation
  7808. // is done by server-renderer
  7809. if (!isSSR && compile && !Component.render) {
  7810. const template = Component.template;
  7811. if (template) {
  7812. {
  7813. startMeasure(instance, `compile`);
  7814. }
  7815. const { isCustomElement, compilerOptions } = instance.appContext.config;
  7816. const { delimiters, compilerOptions: componentCompilerOptions } = Component;
  7817. const finalCompilerOptions = extend(extend({
  7818. isCustomElement,
  7819. delimiters
  7820. }, compilerOptions), componentCompilerOptions);
  7821. Component.render = compile(template, finalCompilerOptions);
  7822. {
  7823. endMeasure(instance, `compile`);
  7824. }
  7825. }
  7826. }
  7827. instance.render = (Component.render || NOOP);
  7828. // for runtime-compiled render functions using `with` blocks, the render
  7829. // proxy used needs a different `has` handler which is more performant and
  7830. // also only allows a whitelist of globals to fallthrough.
  7831. if (installWithProxy) {
  7832. installWithProxy(instance);
  7833. }
  7834. }
  7835. // support for 2.x options
  7836. {
  7837. setCurrentInstance(instance);
  7838. pauseTracking();
  7839. applyOptions(instance);
  7840. resetTracking();
  7841. unsetCurrentInstance();
  7842. }
  7843. // warn missing template/render
  7844. // the runtime compilation of template in SSR is done by server-render
  7845. if (!Component.render && instance.render === NOOP && !isSSR) {
  7846. /* istanbul ignore if */
  7847. if (!compile && Component.template) {
  7848. warn$1(`Component provided template option but ` +
  7849. `runtime compilation is not supported in this build of Vue.` +
  7850. (` Use "vue.global.js" instead.`
  7851. ) /* should not happen */);
  7852. }
  7853. else {
  7854. warn$1(`Component is missing template or render function.`);
  7855. }
  7856. }
  7857. }
  7858. function createAttrsProxy(instance) {
  7859. return new Proxy(instance.attrs, {
  7860. get(target, key) {
  7861. markAttrsAccessed();
  7862. track(instance, "get" /* GET */, '$attrs');
  7863. return target[key];
  7864. },
  7865. set() {
  7866. warn$1(`setupContext.attrs is readonly.`);
  7867. return false;
  7868. },
  7869. deleteProperty() {
  7870. warn$1(`setupContext.attrs is readonly.`);
  7871. return false;
  7872. }
  7873. }
  7874. );
  7875. }
  7876. function createSetupContext(instance) {
  7877. const expose = exposed => {
  7878. if (instance.exposed) {
  7879. warn$1(`expose() should be called only once per setup().`);
  7880. }
  7881. instance.exposed = exposed || {};
  7882. };
  7883. let attrs;
  7884. {
  7885. // We use getters in dev in case libs like test-utils overwrite instance
  7886. // properties (overwrites should not be done in prod)
  7887. return Object.freeze({
  7888. get attrs() {
  7889. return attrs || (attrs = createAttrsProxy(instance));
  7890. },
  7891. get slots() {
  7892. return shallowReadonly(instance.slots);
  7893. },
  7894. get emit() {
  7895. return (event, ...args) => instance.emit(event, ...args);
  7896. },
  7897. expose
  7898. });
  7899. }
  7900. }
  7901. function getExposeProxy(instance) {
  7902. if (instance.exposed) {
  7903. return (instance.exposeProxy ||
  7904. (instance.exposeProxy = new Proxy(proxyRefs(markRaw(instance.exposed)), {
  7905. get(target, key) {
  7906. if (key in target) {
  7907. return target[key];
  7908. }
  7909. else if (key in publicPropertiesMap) {
  7910. return publicPropertiesMap[key](instance);
  7911. }
  7912. }
  7913. })));
  7914. }
  7915. }
  7916. const classifyRE = /(?:^|[-_])(\w)/g;
  7917. const classify = (str) => str.replace(classifyRE, c => c.toUpperCase()).replace(/[-_]/g, '');
  7918. function getComponentName(Component) {
  7919. return isFunction(Component)
  7920. ? Component.displayName || Component.name
  7921. : Component.name;
  7922. }
  7923. /* istanbul ignore next */
  7924. function formatComponentName(instance, Component, isRoot = false) {
  7925. let name = getComponentName(Component);
  7926. if (!name && Component.__file) {
  7927. const match = Component.__file.match(/([^/\\]+)\.\w+$/);
  7928. if (match) {
  7929. name = match[1];
  7930. }
  7931. }
  7932. if (!name && instance && instance.parent) {
  7933. // try to infer the name based on reverse resolution
  7934. const inferFromRegistry = (registry) => {
  7935. for (const key in registry) {
  7936. if (registry[key] === Component) {
  7937. return key;
  7938. }
  7939. }
  7940. };
  7941. name =
  7942. inferFromRegistry(instance.components ||
  7943. instance.parent.type.components) || inferFromRegistry(instance.appContext.components);
  7944. }
  7945. return name ? classify(name) : isRoot ? `App` : `Anonymous`;
  7946. }
  7947. function isClassComponent(value) {
  7948. return isFunction(value) && '__vccOpts' in value;
  7949. }
  7950. const stack = [];
  7951. function pushWarningContext(vnode) {
  7952. stack.push(vnode);
  7953. }
  7954. function popWarningContext() {
  7955. stack.pop();
  7956. }
  7957. function warn$1(msg, ...args) {
  7958. // avoid props formatting or warn handler tracking deps that might be mutated
  7959. // during patch, leading to infinite recursion.
  7960. pauseTracking();
  7961. const instance = stack.length ? stack[stack.length - 1].component : null;
  7962. const appWarnHandler = instance && instance.appContext.config.warnHandler;
  7963. const trace = getComponentTrace();
  7964. if (appWarnHandler) {
  7965. callWithErrorHandling(appWarnHandler, instance, 11 /* APP_WARN_HANDLER */, [
  7966. msg + args.join(''),
  7967. instance && instance.proxy,
  7968. trace
  7969. .map(({ vnode }) => `at <${formatComponentName(instance, vnode.type)}>`)
  7970. .join('\n'),
  7971. trace
  7972. ]);
  7973. }
  7974. else {
  7975. const warnArgs = [`[Vue warn]: ${msg}`, ...args];
  7976. /* istanbul ignore if */
  7977. if (trace.length &&
  7978. // avoid spamming console during tests
  7979. !false) {
  7980. warnArgs.push(`\n`, ...formatTrace(trace));
  7981. }
  7982. console.warn(...warnArgs);
  7983. }
  7984. resetTracking();
  7985. }
  7986. function getComponentTrace() {
  7987. let currentVNode = stack[stack.length - 1];
  7988. if (!currentVNode) {
  7989. return [];
  7990. }
  7991. // we can't just use the stack because it will be incomplete during updates
  7992. // that did not start from the root. Re-construct the parent chain using
  7993. // instance parent pointers.
  7994. const normalizedStack = [];
  7995. while (currentVNode) {
  7996. const last = normalizedStack[0];
  7997. if (last && last.vnode === currentVNode) {
  7998. last.recurseCount++;
  7999. }
  8000. else {
  8001. normalizedStack.push({
  8002. vnode: currentVNode,
  8003. recurseCount: 0
  8004. });
  8005. }
  8006. const parentInstance = currentVNode.component && currentVNode.component.parent;
  8007. currentVNode = parentInstance && parentInstance.vnode;
  8008. }
  8009. return normalizedStack;
  8010. }
  8011. /* istanbul ignore next */
  8012. function formatTrace(trace) {
  8013. const logs = [];
  8014. trace.forEach((entry, i) => {
  8015. logs.push(...(i === 0 ? [] : [`\n`]), ...formatTraceEntry(entry));
  8016. });
  8017. return logs;
  8018. }
  8019. function formatTraceEntry({ vnode, recurseCount }) {
  8020. const postfix = recurseCount > 0 ? `... (${recurseCount} recursive calls)` : ``;
  8021. const isRoot = vnode.component ? vnode.component.parent == null : false;
  8022. const open = ` at <${formatComponentName(vnode.component, vnode.type, isRoot)}`;
  8023. const close = `>` + postfix;
  8024. return vnode.props
  8025. ? [open, ...formatProps(vnode.props), close]
  8026. : [open + close];
  8027. }
  8028. /* istanbul ignore next */
  8029. function formatProps(props) {
  8030. const res = [];
  8031. const keys = Object.keys(props);
  8032. keys.slice(0, 3).forEach(key => {
  8033. res.push(...formatProp(key, props[key]));
  8034. });
  8035. if (keys.length > 3) {
  8036. res.push(` ...`);
  8037. }
  8038. return res;
  8039. }
  8040. /* istanbul ignore next */
  8041. function formatProp(key, value, raw) {
  8042. if (isString(value)) {
  8043. value = JSON.stringify(value);
  8044. return raw ? value : [`${key}=${value}`];
  8045. }
  8046. else if (typeof value === 'number' ||
  8047. typeof value === 'boolean' ||
  8048. value == null) {
  8049. return raw ? value : [`${key}=${value}`];
  8050. }
  8051. else if (isRef(value)) {
  8052. value = formatProp(key, toRaw(value.value), true);
  8053. return raw ? value : [`${key}=Ref<`, value, `>`];
  8054. }
  8055. else if (isFunction(value)) {
  8056. return [`${key}=fn${value.name ? `<${value.name}>` : ``}`];
  8057. }
  8058. else {
  8059. value = toRaw(value);
  8060. return raw ? value : [`${key}=`, value];
  8061. }
  8062. }
  8063. const ErrorTypeStrings = {
  8064. ["sp" /* SERVER_PREFETCH */]: 'serverPrefetch hook',
  8065. ["bc" /* BEFORE_CREATE */]: 'beforeCreate hook',
  8066. ["c" /* CREATED */]: 'created hook',
  8067. ["bm" /* BEFORE_MOUNT */]: 'beforeMount hook',
  8068. ["m" /* MOUNTED */]: 'mounted hook',
  8069. ["bu" /* BEFORE_UPDATE */]: 'beforeUpdate hook',
  8070. ["u" /* UPDATED */]: 'updated',
  8071. ["bum" /* BEFORE_UNMOUNT */]: 'beforeUnmount hook',
  8072. ["um" /* UNMOUNTED */]: 'unmounted hook',
  8073. ["a" /* ACTIVATED */]: 'activated hook',
  8074. ["da" /* DEACTIVATED */]: 'deactivated hook',
  8075. ["ec" /* ERROR_CAPTURED */]: 'errorCaptured hook',
  8076. ["rtc" /* RENDER_TRACKED */]: 'renderTracked hook',
  8077. ["rtg" /* RENDER_TRIGGERED */]: 'renderTriggered hook',
  8078. [0 /* SETUP_FUNCTION */]: 'setup function',
  8079. [1 /* RENDER_FUNCTION */]: 'render function',
  8080. [2 /* WATCH_GETTER */]: 'watcher getter',
  8081. [3 /* WATCH_CALLBACK */]: 'watcher callback',
  8082. [4 /* WATCH_CLEANUP */]: 'watcher cleanup function',
  8083. [5 /* NATIVE_EVENT_HANDLER */]: 'native event handler',
  8084. [6 /* COMPONENT_EVENT_HANDLER */]: 'component event handler',
  8085. [7 /* VNODE_HOOK */]: 'vnode hook',
  8086. [8 /* DIRECTIVE_HOOK */]: 'directive hook',
  8087. [9 /* TRANSITION_HOOK */]: 'transition hook',
  8088. [10 /* APP_ERROR_HANDLER */]: 'app errorHandler',
  8089. [11 /* APP_WARN_HANDLER */]: 'app warnHandler',
  8090. [12 /* FUNCTION_REF */]: 'ref function',
  8091. [13 /* ASYNC_COMPONENT_LOADER */]: 'async component loader',
  8092. [14 /* SCHEDULER */]: 'scheduler flush. This is likely a Vue internals bug. ' +
  8093. 'Please open an issue at https://new-issue.vuejs.org/?repo=vuejs/vue-next'
  8094. };
  8095. function callWithErrorHandling(fn, instance, type, args) {
  8096. let res;
  8097. try {
  8098. res = args ? fn(...args) : fn();
  8099. }
  8100. catch (err) {
  8101. handleError(err, instance, type);
  8102. }
  8103. return res;
  8104. }
  8105. function callWithAsyncErrorHandling(fn, instance, type, args) {
  8106. if (isFunction(fn)) {
  8107. const res = callWithErrorHandling(fn, instance, type, args);
  8108. if (res && isPromise(res)) {
  8109. res.catch(err => {
  8110. handleError(err, instance, type);
  8111. });
  8112. }
  8113. return res;
  8114. }
  8115. const values = [];
  8116. for (let i = 0; i < fn.length; i++) {
  8117. values.push(callWithAsyncErrorHandling(fn[i], instance, type, args));
  8118. }
  8119. return values;
  8120. }
  8121. function handleError(err, instance, type, throwInDev = true) {
  8122. const contextVNode = instance ? instance.vnode : null;
  8123. if (instance) {
  8124. let cur = instance.parent;
  8125. // the exposed instance is the render proxy to keep it consistent with 2.x
  8126. const exposedInstance = instance.proxy;
  8127. // in production the hook receives only the error code
  8128. const errorInfo = ErrorTypeStrings[type] ;
  8129. while (cur) {
  8130. const errorCapturedHooks = cur.ec;
  8131. if (errorCapturedHooks) {
  8132. for (let i = 0; i < errorCapturedHooks.length; i++) {
  8133. if (errorCapturedHooks[i](err, exposedInstance, errorInfo) === false) {
  8134. return;
  8135. }
  8136. }
  8137. }
  8138. cur = cur.parent;
  8139. }
  8140. // app-level handling
  8141. const appErrorHandler = instance.appContext.config.errorHandler;
  8142. if (appErrorHandler) {
  8143. callWithErrorHandling(appErrorHandler, null, 10 /* APP_ERROR_HANDLER */, [err, exposedInstance, errorInfo]);
  8144. return;
  8145. }
  8146. }
  8147. logError(err, type, contextVNode, throwInDev);
  8148. }
  8149. function logError(err, type, contextVNode, throwInDev = true) {
  8150. {
  8151. const info = ErrorTypeStrings[type];
  8152. if (contextVNode) {
  8153. pushWarningContext(contextVNode);
  8154. }
  8155. warn$1(`Unhandled error${info ? ` during execution of ${info}` : ``}`);
  8156. if (contextVNode) {
  8157. popWarningContext();
  8158. }
  8159. // crash in dev by default so it's more noticeable
  8160. if (throwInDev) {
  8161. throw err;
  8162. }
  8163. else {
  8164. console.error(err);
  8165. }
  8166. }
  8167. }
  8168. let isFlushing = false;
  8169. let isFlushPending = false;
  8170. const queue = [];
  8171. let flushIndex = 0;
  8172. const pendingPreFlushCbs = [];
  8173. let activePreFlushCbs = null;
  8174. let preFlushIndex = 0;
  8175. const pendingPostFlushCbs = [];
  8176. let activePostFlushCbs = null;
  8177. let postFlushIndex = 0;
  8178. const resolvedPromise = Promise.resolve();
  8179. let currentFlushPromise = null;
  8180. let currentPreFlushParentJob = null;
  8181. const RECURSION_LIMIT = 100;
  8182. function nextTick(fn) {
  8183. const p = currentFlushPromise || resolvedPromise;
  8184. return fn ? p.then(this ? fn.bind(this) : fn) : p;
  8185. }
  8186. // #2768
  8187. // Use binary-search to find a suitable position in the queue,
  8188. // so that the queue maintains the increasing order of job's id,
  8189. // which can prevent the job from being skipped and also can avoid repeated patching.
  8190. function findInsertionIndex(id) {
  8191. // the start index should be `flushIndex + 1`
  8192. let start = flushIndex + 1;
  8193. let end = queue.length;
  8194. while (start < end) {
  8195. const middle = (start + end) >>> 1;
  8196. const middleJobId = getId(queue[middle]);
  8197. middleJobId < id ? (start = middle + 1) : (end = middle);
  8198. }
  8199. return start;
  8200. }
  8201. function queueJob(job) {
  8202. // the dedupe search uses the startIndex argument of Array.includes()
  8203. // by default the search index includes the current job that is being run
  8204. // so it cannot recursively trigger itself again.
  8205. // if the job is a watch() callback, the search will start with a +1 index to
  8206. // allow it recursively trigger itself - it is the user's responsibility to
  8207. // ensure it doesn't end up in an infinite loop.
  8208. if ((!queue.length ||
  8209. !queue.includes(job, isFlushing && job.allowRecurse ? flushIndex + 1 : flushIndex)) &&
  8210. job !== currentPreFlushParentJob) {
  8211. if (job.id == null) {
  8212. queue.push(job);
  8213. }
  8214. else {
  8215. queue.splice(findInsertionIndex(job.id), 0, job);
  8216. }
  8217. queueFlush();
  8218. }
  8219. }
  8220. function queueFlush() {
  8221. if (!isFlushing && !isFlushPending) {
  8222. isFlushPending = true;
  8223. currentFlushPromise = resolvedPromise.then(flushJobs);
  8224. }
  8225. }
  8226. function invalidateJob(job) {
  8227. const i = queue.indexOf(job);
  8228. if (i > flushIndex) {
  8229. queue.splice(i, 1);
  8230. }
  8231. }
  8232. function queueCb(cb, activeQueue, pendingQueue, index) {
  8233. if (!isArray(cb)) {
  8234. if (!activeQueue ||
  8235. !activeQueue.includes(cb, cb.allowRecurse ? index + 1 : index)) {
  8236. pendingQueue.push(cb);
  8237. }
  8238. }
  8239. else {
  8240. // if cb is an array, it is a component lifecycle hook which can only be
  8241. // triggered by a job, which is already deduped in the main queue, so
  8242. // we can skip duplicate check here to improve perf
  8243. pendingQueue.push(...cb);
  8244. }
  8245. queueFlush();
  8246. }
  8247. function queuePreFlushCb(cb) {
  8248. queueCb(cb, activePreFlushCbs, pendingPreFlushCbs, preFlushIndex);
  8249. }
  8250. function queuePostFlushCb(cb) {
  8251. queueCb(cb, activePostFlushCbs, pendingPostFlushCbs, postFlushIndex);
  8252. }
  8253. function flushPreFlushCbs(seen, parentJob = null) {
  8254. if (pendingPreFlushCbs.length) {
  8255. currentPreFlushParentJob = parentJob;
  8256. activePreFlushCbs = [...new Set(pendingPreFlushCbs)];
  8257. pendingPreFlushCbs.length = 0;
  8258. {
  8259. seen = seen || new Map();
  8260. }
  8261. for (preFlushIndex = 0; preFlushIndex < activePreFlushCbs.length; preFlushIndex++) {
  8262. if (checkRecursiveUpdates(seen, activePreFlushCbs[preFlushIndex])) {
  8263. continue;
  8264. }
  8265. activePreFlushCbs[preFlushIndex]();
  8266. }
  8267. activePreFlushCbs = null;
  8268. preFlushIndex = 0;
  8269. currentPreFlushParentJob = null;
  8270. // recursively flush until it drains
  8271. flushPreFlushCbs(seen, parentJob);
  8272. }
  8273. }
  8274. function flushPostFlushCbs(seen) {
  8275. if (pendingPostFlushCbs.length) {
  8276. const deduped = [...new Set(pendingPostFlushCbs)];
  8277. pendingPostFlushCbs.length = 0;
  8278. // #1947 already has active queue, nested flushPostFlushCbs call
  8279. if (activePostFlushCbs) {
  8280. activePostFlushCbs.push(...deduped);
  8281. return;
  8282. }
  8283. activePostFlushCbs = deduped;
  8284. {
  8285. seen = seen || new Map();
  8286. }
  8287. activePostFlushCbs.sort((a, b) => getId(a) - getId(b));
  8288. for (postFlushIndex = 0; postFlushIndex < activePostFlushCbs.length; postFlushIndex++) {
  8289. if (checkRecursiveUpdates(seen, activePostFlushCbs[postFlushIndex])) {
  8290. continue;
  8291. }
  8292. activePostFlushCbs[postFlushIndex]();
  8293. }
  8294. activePostFlushCbs = null;
  8295. postFlushIndex = 0;
  8296. }
  8297. }
  8298. const getId = (job) => job.id == null ? Infinity : job.id;
  8299. function flushJobs(seen) {
  8300. isFlushPending = false;
  8301. isFlushing = true;
  8302. {
  8303. seen = seen || new Map();
  8304. }
  8305. flushPreFlushCbs(seen);
  8306. // Sort queue before flush.
  8307. // This ensures that:
  8308. // 1. Components are updated from parent to child. (because parent is always
  8309. // created before the child so its render effect will have smaller
  8310. // priority number)
  8311. // 2. If a component is unmounted during a parent component's update,
  8312. // its update can be skipped.
  8313. queue.sort((a, b) => getId(a) - getId(b));
  8314. // conditional usage of checkRecursiveUpdate must be determined out of
  8315. // try ... catch block since Rollup by default de-optimizes treeshaking
  8316. // inside try-catch. This can leave all warning code unshaked. Although
  8317. // they would get eventually shaken by a minifier like terser, some minifiers
  8318. // would fail to do that (e.g. https://github.com/evanw/esbuild/issues/1610)
  8319. const check = (job) => checkRecursiveUpdates(seen, job)
  8320. ;
  8321. try {
  8322. for (flushIndex = 0; flushIndex < queue.length; flushIndex++) {
  8323. const job = queue[flushIndex];
  8324. if (job && job.active !== false) {
  8325. if (true && check(job)) {
  8326. continue;
  8327. }
  8328. // console.log(`running:`, job.id)
  8329. callWithErrorHandling(job, null, 14 /* SCHEDULER */);
  8330. }
  8331. }
  8332. }
  8333. finally {
  8334. flushIndex = 0;
  8335. queue.length = 0;
  8336. flushPostFlushCbs(seen);
  8337. isFlushing = false;
  8338. currentFlushPromise = null;
  8339. // some postFlushCb queued jobs!
  8340. // keep flushing until it drains.
  8341. if (queue.length ||
  8342. pendingPreFlushCbs.length ||
  8343. pendingPostFlushCbs.length) {
  8344. flushJobs(seen);
  8345. }
  8346. }
  8347. }
  8348. function checkRecursiveUpdates(seen, fn) {
  8349. if (!seen.has(fn)) {
  8350. seen.set(fn, 1);
  8351. }
  8352. else {
  8353. const count = seen.get(fn);
  8354. if (count > RECURSION_LIMIT) {
  8355. const instance = fn.ownerInstance;
  8356. const componentName = instance && getComponentName(instance.type);
  8357. warn$1(`Maximum recursive updates exceeded${componentName ? ` in component <${componentName}>` : ``}. ` +
  8358. `This means you have a reactive effect that is mutating its own ` +
  8359. `dependencies and thus recursively triggering itself. Possible sources ` +
  8360. `include component template, render function, updated hook or ` +
  8361. `watcher source function.`);
  8362. return true;
  8363. }
  8364. else {
  8365. seen.set(fn, count + 1);
  8366. }
  8367. }
  8368. }
  8369. // Simple effect.
  8370. function watchEffect(effect, options) {
  8371. return doWatch(effect, null, options);
  8372. }
  8373. function watchPostEffect(effect, options) {
  8374. return doWatch(effect, null, (Object.assign(options || {}, { flush: 'post' })
  8375. ));
  8376. }
  8377. function watchSyncEffect(effect, options) {
  8378. return doWatch(effect, null, (Object.assign(options || {}, { flush: 'sync' })
  8379. ));
  8380. }
  8381. // initial value for watchers to trigger on undefined initial values
  8382. const INITIAL_WATCHER_VALUE = {};
  8383. // implementation
  8384. function watch(source, cb, options) {
  8385. if (!isFunction(cb)) {
  8386. warn$1(`\`watch(fn, options?)\` signature has been moved to a separate API. ` +
  8387. `Use \`watchEffect(fn, options?)\` instead. \`watch\` now only ` +
  8388. `supports \`watch(source, cb, options?) signature.`);
  8389. }
  8390. return doWatch(source, cb, options);
  8391. }
  8392. function doWatch(source, cb, { immediate, deep, flush, onTrack, onTrigger } = EMPTY_OBJ) {
  8393. if (!cb) {
  8394. if (immediate !== undefined) {
  8395. warn$1(`watch() "immediate" option is only respected when using the ` +
  8396. `watch(source, callback, options?) signature.`);
  8397. }
  8398. if (deep !== undefined) {
  8399. warn$1(`watch() "deep" option is only respected when using the ` +
  8400. `watch(source, callback, options?) signature.`);
  8401. }
  8402. }
  8403. const warnInvalidSource = (s) => {
  8404. warn$1(`Invalid watch source: `, s, `A watch source can only be a getter/effect function, a ref, ` +
  8405. `a reactive object, or an array of these types.`);
  8406. };
  8407. const instance = currentInstance;
  8408. let getter;
  8409. let forceTrigger = false;
  8410. let isMultiSource = false;
  8411. if (isRef(source)) {
  8412. getter = () => source.value;
  8413. forceTrigger = !!source._shallow;
  8414. }
  8415. else if (isReactive(source)) {
  8416. getter = () => source;
  8417. deep = true;
  8418. }
  8419. else if (isArray(source)) {
  8420. isMultiSource = true;
  8421. forceTrigger = source.some(isReactive);
  8422. getter = () => source.map(s => {
  8423. if (isRef(s)) {
  8424. return s.value;
  8425. }
  8426. else if (isReactive(s)) {
  8427. return traverse(s);
  8428. }
  8429. else if (isFunction(s)) {
  8430. return callWithErrorHandling(s, instance, 2 /* WATCH_GETTER */);
  8431. }
  8432. else {
  8433. warnInvalidSource(s);
  8434. }
  8435. });
  8436. }
  8437. else if (isFunction(source)) {
  8438. if (cb) {
  8439. // getter with cb
  8440. getter = () => callWithErrorHandling(source, instance, 2 /* WATCH_GETTER */);
  8441. }
  8442. else {
  8443. // no cb -> simple effect
  8444. getter = () => {
  8445. if (instance && instance.isUnmounted) {
  8446. return;
  8447. }
  8448. if (cleanup) {
  8449. cleanup();
  8450. }
  8451. return callWithAsyncErrorHandling(source, instance, 3 /* WATCH_CALLBACK */, [onInvalidate]);
  8452. };
  8453. }
  8454. }
  8455. else {
  8456. getter = NOOP;
  8457. warnInvalidSource(source);
  8458. }
  8459. if (cb && deep) {
  8460. const baseGetter = getter;
  8461. getter = () => traverse(baseGetter());
  8462. }
  8463. let cleanup;
  8464. let onInvalidate = (fn) => {
  8465. cleanup = effect.onStop = () => {
  8466. callWithErrorHandling(fn, instance, 4 /* WATCH_CLEANUP */);
  8467. };
  8468. };
  8469. let oldValue = isMultiSource ? [] : INITIAL_WATCHER_VALUE;
  8470. const job = () => {
  8471. if (!effect.active) {
  8472. return;
  8473. }
  8474. if (cb) {
  8475. // watch(source, cb)
  8476. const newValue = effect.run();
  8477. if (deep ||
  8478. forceTrigger ||
  8479. (isMultiSource
  8480. ? newValue.some((v, i) => hasChanged(v, oldValue[i]))
  8481. : hasChanged(newValue, oldValue)) ||
  8482. (false )) {
  8483. // cleanup before running cb again
  8484. if (cleanup) {
  8485. cleanup();
  8486. }
  8487. callWithAsyncErrorHandling(cb, instance, 3 /* WATCH_CALLBACK */, [
  8488. newValue,
  8489. // pass undefined as the old value when it's changed for the first time
  8490. oldValue === INITIAL_WATCHER_VALUE ? undefined : oldValue,
  8491. onInvalidate
  8492. ]);
  8493. oldValue = newValue;
  8494. }
  8495. }
  8496. else {
  8497. // watchEffect
  8498. effect.run();
  8499. }
  8500. };
  8501. // important: mark the job as a watcher callback so that scheduler knows
  8502. // it is allowed to self-trigger (#1727)
  8503. job.allowRecurse = !!cb;
  8504. let scheduler;
  8505. if (flush === 'sync') {
  8506. scheduler = job; // the scheduler function gets called directly
  8507. }
  8508. else if (flush === 'post') {
  8509. scheduler = () => queuePostRenderEffect(job, instance && instance.suspense);
  8510. }
  8511. else {
  8512. // default: 'pre'
  8513. scheduler = () => {
  8514. if (!instance || instance.isMounted) {
  8515. queuePreFlushCb(job);
  8516. }
  8517. else {
  8518. // with 'pre' option, the first call must happen before
  8519. // the component is mounted so it is called synchronously.
  8520. job();
  8521. }
  8522. };
  8523. }
  8524. const effect = new ReactiveEffect(getter, scheduler);
  8525. {
  8526. effect.onTrack = onTrack;
  8527. effect.onTrigger = onTrigger;
  8528. }
  8529. // initial run
  8530. if (cb) {
  8531. if (immediate) {
  8532. job();
  8533. }
  8534. else {
  8535. oldValue = effect.run();
  8536. }
  8537. }
  8538. else if (flush === 'post') {
  8539. queuePostRenderEffect(effect.run.bind(effect), instance && instance.suspense);
  8540. }
  8541. else {
  8542. effect.run();
  8543. }
  8544. return () => {
  8545. effect.stop();
  8546. if (instance && instance.scope) {
  8547. remove(instance.scope.effects, effect);
  8548. }
  8549. };
  8550. }
  8551. // this.$watch
  8552. function instanceWatch(source, value, options) {
  8553. const publicThis = this.proxy;
  8554. const getter = isString(source)
  8555. ? source.includes('.')
  8556. ? createPathGetter(publicThis, source)
  8557. : () => publicThis[source]
  8558. : source.bind(publicThis, publicThis);
  8559. let cb;
  8560. if (isFunction(value)) {
  8561. cb = value;
  8562. }
  8563. else {
  8564. cb = value.handler;
  8565. options = value;
  8566. }
  8567. const cur = currentInstance;
  8568. setCurrentInstance(this);
  8569. const res = doWatch(getter, cb.bind(publicThis), options);
  8570. if (cur) {
  8571. setCurrentInstance(cur);
  8572. }
  8573. else {
  8574. unsetCurrentInstance();
  8575. }
  8576. return res;
  8577. }
  8578. function createPathGetter(ctx, path) {
  8579. const segments = path.split('.');
  8580. return () => {
  8581. let cur = ctx;
  8582. for (let i = 0; i < segments.length && cur; i++) {
  8583. cur = cur[segments[i]];
  8584. }
  8585. return cur;
  8586. };
  8587. }
  8588. function traverse(value, seen) {
  8589. if (!isObject(value) || value["__v_skip" /* SKIP */]) {
  8590. return value;
  8591. }
  8592. seen = seen || new Set();
  8593. if (seen.has(value)) {
  8594. return value;
  8595. }
  8596. seen.add(value);
  8597. if (isRef(value)) {
  8598. traverse(value.value, seen);
  8599. }
  8600. else if (isArray(value)) {
  8601. for (let i = 0; i < value.length; i++) {
  8602. traverse(value[i], seen);
  8603. }
  8604. }
  8605. else if (isSet(value) || isMap(value)) {
  8606. value.forEach((v) => {
  8607. traverse(v, seen);
  8608. });
  8609. }
  8610. else if (isPlainObject(value)) {
  8611. for (const key in value) {
  8612. traverse(value[key], seen);
  8613. }
  8614. }
  8615. return value;
  8616. }
  8617. // dev only
  8618. const warnRuntimeUsage = (method) => warn$1(`${method}() is a compiler-hint helper that is only usable inside ` +
  8619. `<script setup> of a single file component. Its arguments should be ` +
  8620. `compiled away and passing it at runtime has no effect.`);
  8621. // implementation
  8622. function defineProps() {
  8623. {
  8624. warnRuntimeUsage(`defineProps`);
  8625. }
  8626. return null;
  8627. }
  8628. // implementation
  8629. function defineEmits() {
  8630. {
  8631. warnRuntimeUsage(`defineEmits`);
  8632. }
  8633. return null;
  8634. }
  8635. /**
  8636. * Vue `<script setup>` compiler macro for declaring a component's exposed
  8637. * instance properties when it is accessed by a parent component via template
  8638. * refs.
  8639. *
  8640. * `<script setup>` components are closed by default - i.e. varaibles inside
  8641. * the `<script setup>` scope is not exposed to parent unless explicitly exposed
  8642. * via `defineExpose`.
  8643. *
  8644. * This is only usable inside `<script setup>`, is compiled away in the
  8645. * output and should **not** be actually called at runtime.
  8646. */
  8647. function defineExpose(exposed) {
  8648. {
  8649. warnRuntimeUsage(`defineExpose`);
  8650. }
  8651. }
  8652. /**
  8653. * Vue `<script setup>` compiler macro for providing props default values when
  8654. * using type-based `defineProps` declaration.
  8655. *
  8656. * Example usage:
  8657. * ```ts
  8658. * withDefaults(defineProps<{
  8659. * size?: number
  8660. * labels?: string[]
  8661. * }>(), {
  8662. * size: 3,
  8663. * labels: () => ['default label']
  8664. * })
  8665. * ```
  8666. *
  8667. * This is only usable inside `<script setup>`, is compiled away in the output
  8668. * and should **not** be actually called at runtime.
  8669. */
  8670. function withDefaults(props, defaults) {
  8671. {
  8672. warnRuntimeUsage(`withDefaults`);
  8673. }
  8674. return null;
  8675. }
  8676. function useSlots() {
  8677. return getContext().slots;
  8678. }
  8679. function useAttrs() {
  8680. return getContext().attrs;
  8681. }
  8682. function getContext() {
  8683. const i = getCurrentInstance();
  8684. if (!i) {
  8685. warn$1(`useContext() called without active instance.`);
  8686. }
  8687. return i.setupContext || (i.setupContext = createSetupContext(i));
  8688. }
  8689. /**
  8690. * Runtime helper for merging default declarations. Imported by compiled code
  8691. * only.
  8692. * @internal
  8693. */
  8694. function mergeDefaults(raw, defaults) {
  8695. const props = isArray(raw)
  8696. ? raw.reduce((normalized, p) => ((normalized[p] = {}), normalized), {})
  8697. : raw;
  8698. for (const key in defaults) {
  8699. const opt = props[key];
  8700. if (opt) {
  8701. if (isArray(opt) || isFunction(opt)) {
  8702. props[key] = { type: opt, default: defaults[key] };
  8703. }
  8704. else {
  8705. opt.default = defaults[key];
  8706. }
  8707. }
  8708. else if (opt === null) {
  8709. props[key] = { default: defaults[key] };
  8710. }
  8711. else {
  8712. warn$1(`props default key "${key}" has no corresponding declaration.`);
  8713. }
  8714. }
  8715. return props;
  8716. }
  8717. /**
  8718. * Used to create a proxy for the rest element when destructuring props with
  8719. * defineProps().
  8720. * @internal
  8721. */
  8722. function createPropsRestProxy(props, excludedKeys) {
  8723. const ret = {};
  8724. for (const key in props) {
  8725. if (!excludedKeys.includes(key)) {
  8726. Object.defineProperty(ret, key, {
  8727. enumerable: true,
  8728. get: () => props[key]
  8729. });
  8730. }
  8731. }
  8732. return ret;
  8733. }
  8734. /**
  8735. * `<script setup>` helper for persisting the current instance context over
  8736. * async/await flows.
  8737. *
  8738. * `@vue/compiler-sfc` converts the following:
  8739. *
  8740. * ```ts
  8741. * const x = await foo()
  8742. * ```
  8743. *
  8744. * into:
  8745. *
  8746. * ```ts
  8747. * let __temp, __restore
  8748. * const x = (([__temp, __restore] = withAsyncContext(() => foo())),__temp=await __temp,__restore(),__temp)
  8749. * ```
  8750. * @internal
  8751. */
  8752. function withAsyncContext(getAwaitable) {
  8753. const ctx = getCurrentInstance();
  8754. if (!ctx) {
  8755. warn$1(`withAsyncContext called without active current instance. ` +
  8756. `This is likely a bug.`);
  8757. }
  8758. let awaitable = getAwaitable();
  8759. unsetCurrentInstance();
  8760. if (isPromise(awaitable)) {
  8761. awaitable = awaitable.catch(e => {
  8762. setCurrentInstance(ctx);
  8763. throw e;
  8764. });
  8765. }
  8766. return [awaitable, () => setCurrentInstance(ctx)];
  8767. }
  8768. // Actual implementation
  8769. function h(type, propsOrChildren, children) {
  8770. const l = arguments.length;
  8771. if (l === 2) {
  8772. if (isObject(propsOrChildren) && !isArray(propsOrChildren)) {
  8773. // single vnode without props
  8774. if (isVNode(propsOrChildren)) {
  8775. return createVNode(type, null, [propsOrChildren]);
  8776. }
  8777. // props without children
  8778. return createVNode(type, propsOrChildren);
  8779. }
  8780. else {
  8781. // omit props
  8782. return createVNode(type, null, propsOrChildren);
  8783. }
  8784. }
  8785. else {
  8786. if (l > 3) {
  8787. children = Array.prototype.slice.call(arguments, 2);
  8788. }
  8789. else if (l === 3 && isVNode(children)) {
  8790. children = [children];
  8791. }
  8792. return createVNode(type, propsOrChildren, children);
  8793. }
  8794. }
  8795. const ssrContextKey = Symbol(`ssrContext` );
  8796. const useSSRContext = () => {
  8797. {
  8798. warn$1(`useSSRContext() is not supported in the global build.`);
  8799. }
  8800. };
  8801. function initCustomFormatter() {
  8802. /* eslint-disable no-restricted-globals */
  8803. if (typeof window === 'undefined') {
  8804. return;
  8805. }
  8806. const vueStyle = { style: 'color:#3ba776' };
  8807. const numberStyle = { style: 'color:#0b1bc9' };
  8808. const stringStyle = { style: 'color:#b62e24' };
  8809. const keywordStyle = { style: 'color:#9d288c' };
  8810. // custom formatter for Chrome
  8811. // https://www.mattzeunert.com/2016/02/19/custom-chrome-devtools-object-formatters.html
  8812. const formatter = {
  8813. header(obj) {
  8814. // TODO also format ComponentPublicInstance & ctx.slots/attrs in setup
  8815. if (!isObject(obj)) {
  8816. return null;
  8817. }
  8818. if (obj.__isVue) {
  8819. return ['div', vueStyle, `VueInstance`];
  8820. }
  8821. else if (isRef(obj)) {
  8822. return [
  8823. 'div',
  8824. {},
  8825. ['span', vueStyle, genRefFlag(obj)],
  8826. '<',
  8827. formatValue(obj.value),
  8828. `>`
  8829. ];
  8830. }
  8831. else if (isReactive(obj)) {
  8832. return [
  8833. 'div',
  8834. {},
  8835. ['span', vueStyle, 'Reactive'],
  8836. '<',
  8837. formatValue(obj),
  8838. `>${isReadonly(obj) ? ` (readonly)` : ``}`
  8839. ];
  8840. }
  8841. else if (isReadonly(obj)) {
  8842. return [
  8843. 'div',
  8844. {},
  8845. ['span', vueStyle, 'Readonly'],
  8846. '<',
  8847. formatValue(obj),
  8848. '>'
  8849. ];
  8850. }
  8851. return null;
  8852. },
  8853. hasBody(obj) {
  8854. return obj && obj.__isVue;
  8855. },
  8856. body(obj) {
  8857. if (obj && obj.__isVue) {
  8858. return [
  8859. 'div',
  8860. {},
  8861. ...formatInstance(obj.$)
  8862. ];
  8863. }
  8864. }
  8865. };
  8866. function formatInstance(instance) {
  8867. const blocks = [];
  8868. if (instance.type.props && instance.props) {
  8869. blocks.push(createInstanceBlock('props', toRaw(instance.props)));
  8870. }
  8871. if (instance.setupState !== EMPTY_OBJ) {
  8872. blocks.push(createInstanceBlock('setup', instance.setupState));
  8873. }
  8874. if (instance.data !== EMPTY_OBJ) {
  8875. blocks.push(createInstanceBlock('data', toRaw(instance.data)));
  8876. }
  8877. const computed = extractKeys(instance, 'computed');
  8878. if (computed) {
  8879. blocks.push(createInstanceBlock('computed', computed));
  8880. }
  8881. const injected = extractKeys(instance, 'inject');
  8882. if (injected) {
  8883. blocks.push(createInstanceBlock('injected', injected));
  8884. }
  8885. blocks.push([
  8886. 'div',
  8887. {},
  8888. [
  8889. 'span',
  8890. {
  8891. style: keywordStyle.style + ';opacity:0.66'
  8892. },
  8893. '$ (internal): '
  8894. ],
  8895. ['object', { object: instance }]
  8896. ]);
  8897. return blocks;
  8898. }
  8899. function createInstanceBlock(type, target) {
  8900. target = extend({}, target);
  8901. if (!Object.keys(target).length) {
  8902. return ['span', {}];
  8903. }
  8904. return [
  8905. 'div',
  8906. { style: 'line-height:1.25em;margin-bottom:0.6em' },
  8907. [
  8908. 'div',
  8909. {
  8910. style: 'color:#476582'
  8911. },
  8912. type
  8913. ],
  8914. [
  8915. 'div',
  8916. {
  8917. style: 'padding-left:1.25em'
  8918. },
  8919. ...Object.keys(target).map(key => {
  8920. return [
  8921. 'div',
  8922. {},
  8923. ['span', keywordStyle, key + ': '],
  8924. formatValue(target[key], false)
  8925. ];
  8926. })
  8927. ]
  8928. ];
  8929. }
  8930. function formatValue(v, asRaw = true) {
  8931. if (typeof v === 'number') {
  8932. return ['span', numberStyle, v];
  8933. }
  8934. else if (typeof v === 'string') {
  8935. return ['span', stringStyle, JSON.stringify(v)];
  8936. }
  8937. else if (typeof v === 'boolean') {
  8938. return ['span', keywordStyle, v];
  8939. }
  8940. else if (isObject(v)) {
  8941. return ['object', { object: asRaw ? toRaw(v) : v }];
  8942. }
  8943. else {
  8944. return ['span', stringStyle, String(v)];
  8945. }
  8946. }
  8947. function extractKeys(instance, type) {
  8948. const Comp = instance.type;
  8949. if (isFunction(Comp)) {
  8950. return;
  8951. }
  8952. const extracted = {};
  8953. for (const key in instance.ctx) {
  8954. if (isKeyOfType(Comp, key, type)) {
  8955. extracted[key] = instance.ctx[key];
  8956. }
  8957. }
  8958. return extracted;
  8959. }
  8960. function isKeyOfType(Comp, key, type) {
  8961. const opts = Comp[type];
  8962. if ((isArray(opts) && opts.includes(key)) ||
  8963. (isObject(opts) && key in opts)) {
  8964. return true;
  8965. }
  8966. if (Comp.extends && isKeyOfType(Comp.extends, key, type)) {
  8967. return true;
  8968. }
  8969. if (Comp.mixins && Comp.mixins.some(m => isKeyOfType(m, key, type))) {
  8970. return true;
  8971. }
  8972. }
  8973. function genRefFlag(v) {
  8974. if (v._shallow) {
  8975. return `ShallowRef`;
  8976. }
  8977. if (v.effect) {
  8978. return `ComputedRef`;
  8979. }
  8980. return `Ref`;
  8981. }
  8982. if (window.devtoolsFormatters) {
  8983. window.devtoolsFormatters.push(formatter);
  8984. }
  8985. else {
  8986. window.devtoolsFormatters = [formatter];
  8987. }
  8988. }
  8989. function withMemo(memo, render, cache, index) {
  8990. const cached = cache[index];
  8991. if (cached && isMemoSame(cached, memo)) {
  8992. return cached;
  8993. }
  8994. const ret = render();
  8995. // shallow clone
  8996. ret.memo = memo.slice();
  8997. return (cache[index] = ret);
  8998. }
  8999. function isMemoSame(cached, memo) {
  9000. const prev = cached.memo;
  9001. if (prev.length != memo.length) {
  9002. return false;
  9003. }
  9004. for (let i = 0; i < prev.length; i++) {
  9005. if (prev[i] !== memo[i]) {
  9006. return false;
  9007. }
  9008. }
  9009. // make sure to let parent block track it when returning cached
  9010. if (isBlockTreeEnabled > 0 && currentBlock) {
  9011. currentBlock.push(cached);
  9012. }
  9013. return true;
  9014. }
  9015. // Core API ------------------------------------------------------------------
  9016. const version = "3.2.25";
  9017. /**
  9018. * SSR utils for \@vue/server-renderer. Only exposed in cjs builds.
  9019. * @internal
  9020. */
  9021. const ssrUtils = (null);
  9022. /**
  9023. * @internal only exposed in compat builds
  9024. */
  9025. const resolveFilter = null;
  9026. /**
  9027. * @internal only exposed in compat builds.
  9028. */
  9029. const compatUtils = (null);
  9030. const svgNS = 'http://www.w3.org/2000/svg';
  9031. const doc = (typeof document !== 'undefined' ? document : null);
  9032. const staticTemplateCache = new Map();
  9033. const nodeOps = {
  9034. insert: (child, parent, anchor) => {
  9035. parent.insertBefore(child, anchor || null);
  9036. },
  9037. remove: child => {
  9038. const parent = child.parentNode;
  9039. if (parent) {
  9040. parent.removeChild(child);
  9041. }
  9042. },
  9043. createElement: (tag, isSVG, is, props) => {
  9044. const el = isSVG
  9045. ? doc.createElementNS(svgNS, tag)
  9046. : doc.createElement(tag, is ? { is } : undefined);
  9047. if (tag === 'select' && props && props.multiple != null) {
  9048. el.setAttribute('multiple', props.multiple);
  9049. }
  9050. return el;
  9051. },
  9052. createText: text => doc.createTextNode(text),
  9053. createComment: text => doc.createComment(text),
  9054. setText: (node, text) => {
  9055. node.nodeValue = text;
  9056. },
  9057. setElementText: (el, text) => {
  9058. el.textContent = text;
  9059. },
  9060. parentNode: node => node.parentNode,
  9061. nextSibling: node => node.nextSibling,
  9062. querySelector: selector => doc.querySelector(selector),
  9063. setScopeId(el, id) {
  9064. el.setAttribute(id, '');
  9065. },
  9066. cloneNode(el) {
  9067. const cloned = el.cloneNode(true);
  9068. // #3072
  9069. // - in `patchDOMProp`, we store the actual value in the `el._value` property.
  9070. // - normally, elements using `:value` bindings will not be hoisted, but if
  9071. // the bound value is a constant, e.g. `:value="true"` - they do get
  9072. // hoisted.
  9073. // - in production, hoisted nodes are cloned when subsequent inserts, but
  9074. // cloneNode() does not copy the custom property we attached.
  9075. // - This may need to account for other custom DOM properties we attach to
  9076. // elements in addition to `_value` in the future.
  9077. if (`_value` in el) {
  9078. cloned._value = el._value;
  9079. }
  9080. return cloned;
  9081. },
  9082. // __UNSAFE__
  9083. // Reason: innerHTML.
  9084. // Static content here can only come from compiled templates.
  9085. // As long as the user only uses trusted templates, this is safe.
  9086. insertStaticContent(content, parent, anchor, isSVG) {
  9087. // <parent> before | first ... last | anchor </parent>
  9088. const before = anchor ? anchor.previousSibling : parent.lastChild;
  9089. let template = staticTemplateCache.get(content);
  9090. if (!template) {
  9091. const t = doc.createElement('template');
  9092. t.innerHTML = isSVG ? `<svg>${content}</svg>` : content;
  9093. template = t.content;
  9094. if (isSVG) {
  9095. // remove outer svg wrapper
  9096. const wrapper = template.firstChild;
  9097. while (wrapper.firstChild) {
  9098. template.appendChild(wrapper.firstChild);
  9099. }
  9100. template.removeChild(wrapper);
  9101. }
  9102. staticTemplateCache.set(content, template);
  9103. }
  9104. parent.insertBefore(template.cloneNode(true), anchor);
  9105. return [
  9106. // first
  9107. before ? before.nextSibling : parent.firstChild,
  9108. // last
  9109. anchor ? anchor.previousSibling : parent.lastChild
  9110. ];
  9111. }
  9112. };
  9113. // compiler should normalize class + :class bindings on the same element
  9114. // into a single binding ['staticClass', dynamic]
  9115. function patchClass(el, value, isSVG) {
  9116. // directly setting className should be faster than setAttribute in theory
  9117. // if this is an element during a transition, take the temporary transition
  9118. // classes into account.
  9119. const transitionClasses = el._vtc;
  9120. if (transitionClasses) {
  9121. value = (value ? [value, ...transitionClasses] : [...transitionClasses]).join(' ');
  9122. }
  9123. if (value == null) {
  9124. el.removeAttribute('class');
  9125. }
  9126. else if (isSVG) {
  9127. el.setAttribute('class', value);
  9128. }
  9129. else {
  9130. el.className = value;
  9131. }
  9132. }
  9133. function patchStyle(el, prev, next) {
  9134. const style = el.style;
  9135. const isCssString = isString(next);
  9136. if (next && !isCssString) {
  9137. for (const key in next) {
  9138. setStyle(style, key, next[key]);
  9139. }
  9140. if (prev && !isString(prev)) {
  9141. for (const key in prev) {
  9142. if (next[key] == null) {
  9143. setStyle(style, key, '');
  9144. }
  9145. }
  9146. }
  9147. }
  9148. else {
  9149. const currentDisplay = style.display;
  9150. if (isCssString) {
  9151. if (prev !== next) {
  9152. style.cssText = next;
  9153. }
  9154. }
  9155. else if (prev) {
  9156. el.removeAttribute('style');
  9157. }
  9158. // indicates that the `display` of the element is controlled by `v-show`,
  9159. // so we always keep the current `display` value regardless of the `style`
  9160. // value, thus handing over control to `v-show`.
  9161. if ('_vod' in el) {
  9162. style.display = currentDisplay;
  9163. }
  9164. }
  9165. }
  9166. const importantRE = /\s*!important$/;
  9167. function setStyle(style, name, val) {
  9168. if (isArray(val)) {
  9169. val.forEach(v => setStyle(style, name, v));
  9170. }
  9171. else {
  9172. if (name.startsWith('--')) {
  9173. // custom property definition
  9174. style.setProperty(name, val);
  9175. }
  9176. else {
  9177. const prefixed = autoPrefix(style, name);
  9178. if (importantRE.test(val)) {
  9179. // !important
  9180. style.setProperty(hyphenate(prefixed), val.replace(importantRE, ''), 'important');
  9181. }
  9182. else {
  9183. style[prefixed] = val;
  9184. }
  9185. }
  9186. }
  9187. }
  9188. const prefixes = ['Webkit', 'Moz', 'ms'];
  9189. const prefixCache = {};
  9190. function autoPrefix(style, rawName) {
  9191. const cached = prefixCache[rawName];
  9192. if (cached) {
  9193. return cached;
  9194. }
  9195. let name = camelize(rawName);
  9196. if (name !== 'filter' && name in style) {
  9197. return (prefixCache[rawName] = name);
  9198. }
  9199. name = capitalize(name);
  9200. for (let i = 0; i < prefixes.length; i++) {
  9201. const prefixed = prefixes[i] + name;
  9202. if (prefixed in style) {
  9203. return (prefixCache[rawName] = prefixed);
  9204. }
  9205. }
  9206. return rawName;
  9207. }
  9208. const xlinkNS = 'http://www.w3.org/1999/xlink';
  9209. function patchAttr(el, key, value, isSVG, instance) {
  9210. if (isSVG && key.startsWith('xlink:')) {
  9211. if (value == null) {
  9212. el.removeAttributeNS(xlinkNS, key.slice(6, key.length));
  9213. }
  9214. else {
  9215. el.setAttributeNS(xlinkNS, key, value);
  9216. }
  9217. }
  9218. else {
  9219. // note we are only checking boolean attributes that don't have a
  9220. // corresponding dom prop of the same name here.
  9221. const isBoolean = isSpecialBooleanAttr(key);
  9222. if (value == null || (isBoolean && !includeBooleanAttr(value))) {
  9223. el.removeAttribute(key);
  9224. }
  9225. else {
  9226. el.setAttribute(key, isBoolean ? '' : value);
  9227. }
  9228. }
  9229. }
  9230. // __UNSAFE__
  9231. // functions. The user is responsible for using them with only trusted content.
  9232. function patchDOMProp(el, key, value,
  9233. // the following args are passed only due to potential innerHTML/textContent
  9234. // overriding existing VNodes, in which case the old tree must be properly
  9235. // unmounted.
  9236. prevChildren, parentComponent, parentSuspense, unmountChildren) {
  9237. if (key === 'innerHTML' || key === 'textContent') {
  9238. if (prevChildren) {
  9239. unmountChildren(prevChildren, parentComponent, parentSuspense);
  9240. }
  9241. el[key] = value == null ? '' : value;
  9242. return;
  9243. }
  9244. if (key === 'value' &&
  9245. el.tagName !== 'PROGRESS' &&
  9246. // custom elements may use _value internally
  9247. !el.tagName.includes('-')) {
  9248. // store value as _value as well since
  9249. // non-string values will be stringified.
  9250. el._value = value;
  9251. const newValue = value == null ? '' : value;
  9252. if (el.value !== newValue ||
  9253. // #4956: always set for OPTION elements because its value falls back to
  9254. // textContent if no value attribute is present. And setting .value for
  9255. // OPTION has no side effect
  9256. el.tagName === 'OPTION') {
  9257. el.value = newValue;
  9258. }
  9259. if (value == null) {
  9260. el.removeAttribute(key);
  9261. }
  9262. return;
  9263. }
  9264. if (value === '' || value == null) {
  9265. const type = typeof el[key];
  9266. if (type === 'boolean') {
  9267. // e.g. <select multiple> compiles to { multiple: '' }
  9268. el[key] = includeBooleanAttr(value);
  9269. return;
  9270. }
  9271. else if (value == null && type === 'string') {
  9272. // e.g. <div :id="null">
  9273. el[key] = '';
  9274. el.removeAttribute(key);
  9275. return;
  9276. }
  9277. else if (type === 'number') {
  9278. // e.g. <img :width="null">
  9279. // the value of some IDL attr must be greater than 0, e.g. input.size = 0 -> error
  9280. try {
  9281. el[key] = 0;
  9282. }
  9283. catch (_a) { }
  9284. el.removeAttribute(key);
  9285. return;
  9286. }
  9287. }
  9288. // some properties perform value validation and throw
  9289. try {
  9290. el[key] = value;
  9291. }
  9292. catch (e) {
  9293. {
  9294. warn$1(`Failed setting prop "${key}" on <${el.tagName.toLowerCase()}>: ` +
  9295. `value ${value} is invalid.`, e);
  9296. }
  9297. }
  9298. }
  9299. // Async edge case fix requires storing an event listener's attach timestamp.
  9300. let _getNow = Date.now;
  9301. let skipTimestampCheck = false;
  9302. if (typeof window !== 'undefined') {
  9303. // Determine what event timestamp the browser is using. Annoyingly, the
  9304. // timestamp can either be hi-res (relative to page load) or low-res
  9305. // (relative to UNIX epoch), so in order to compare time we have to use the
  9306. // same timestamp type when saving the flush timestamp.
  9307. if (_getNow() > document.createEvent('Event').timeStamp) {
  9308. // if the low-res timestamp which is bigger than the event timestamp
  9309. // (which is evaluated AFTER) it means the event is using a hi-res timestamp,
  9310. // and we need to use the hi-res version for event listeners as well.
  9311. _getNow = () => performance.now();
  9312. }
  9313. // #3485: Firefox <= 53 has incorrect Event.timeStamp implementation
  9314. // and does not fire microtasks in between event propagation, so safe to exclude.
  9315. const ffMatch = navigator.userAgent.match(/firefox\/(\d+)/i);
  9316. skipTimestampCheck = !!(ffMatch && Number(ffMatch[1]) <= 53);
  9317. }
  9318. // To avoid the overhead of repeatedly calling performance.now(), we cache
  9319. // and use the same timestamp for all event listeners attached in the same tick.
  9320. let cachedNow = 0;
  9321. const p = Promise.resolve();
  9322. const reset = () => {
  9323. cachedNow = 0;
  9324. };
  9325. const getNow = () => cachedNow || (p.then(reset), (cachedNow = _getNow()));
  9326. function addEventListener(el, event, handler, options) {
  9327. el.addEventListener(event, handler, options);
  9328. }
  9329. function removeEventListener(el, event, handler, options) {
  9330. el.removeEventListener(event, handler, options);
  9331. }
  9332. function patchEvent(el, rawName, prevValue, nextValue, instance = null) {
  9333. // vei = vue event invokers
  9334. const invokers = el._vei || (el._vei = {});
  9335. const existingInvoker = invokers[rawName];
  9336. if (nextValue && existingInvoker) {
  9337. // patch
  9338. existingInvoker.value = nextValue;
  9339. }
  9340. else {
  9341. const [name, options] = parseName(rawName);
  9342. if (nextValue) {
  9343. // add
  9344. const invoker = (invokers[rawName] = createInvoker(nextValue, instance));
  9345. addEventListener(el, name, invoker, options);
  9346. }
  9347. else if (existingInvoker) {
  9348. // remove
  9349. removeEventListener(el, name, existingInvoker, options);
  9350. invokers[rawName] = undefined;
  9351. }
  9352. }
  9353. }
  9354. const optionsModifierRE = /(?:Once|Passive|Capture)$/;
  9355. function parseName(name) {
  9356. let options;
  9357. if (optionsModifierRE.test(name)) {
  9358. options = {};
  9359. let m;
  9360. while ((m = name.match(optionsModifierRE))) {
  9361. name = name.slice(0, name.length - m[0].length);
  9362. options[m[0].toLowerCase()] = true;
  9363. }
  9364. }
  9365. return [hyphenate(name.slice(2)), options];
  9366. }
  9367. function createInvoker(initialValue, instance) {
  9368. const invoker = (e) => {
  9369. // async edge case #6566: inner click event triggers patch, event handler
  9370. // attached to outer element during patch, and triggered again. This
  9371. // happens because browsers fire microtask ticks between event propagation.
  9372. // the solution is simple: we save the timestamp when a handler is attached,
  9373. // and the handler would only fire if the event passed to it was fired
  9374. // AFTER it was attached.
  9375. const timeStamp = e.timeStamp || _getNow();
  9376. if (skipTimestampCheck || timeStamp >= invoker.attached - 1) {
  9377. callWithAsyncErrorHandling(patchStopImmediatePropagation(e, invoker.value), instance, 5 /* NATIVE_EVENT_HANDLER */, [e]);
  9378. }
  9379. };
  9380. invoker.value = initialValue;
  9381. invoker.attached = getNow();
  9382. return invoker;
  9383. }
  9384. function patchStopImmediatePropagation(e, value) {
  9385. if (isArray(value)) {
  9386. const originalStop = e.stopImmediatePropagation;
  9387. e.stopImmediatePropagation = () => {
  9388. originalStop.call(e);
  9389. e._stopped = true;
  9390. };
  9391. return value.map(fn => (e) => !e._stopped && fn(e));
  9392. }
  9393. else {
  9394. return value;
  9395. }
  9396. }
  9397. const nativeOnRE = /^on[a-z]/;
  9398. const patchProp = (el, key, prevValue, nextValue, isSVG = false, prevChildren, parentComponent, parentSuspense, unmountChildren) => {
  9399. if (key === 'class') {
  9400. patchClass(el, nextValue, isSVG);
  9401. }
  9402. else if (key === 'style') {
  9403. patchStyle(el, prevValue, nextValue);
  9404. }
  9405. else if (isOn(key)) {
  9406. // ignore v-model listeners
  9407. if (!isModelListener(key)) {
  9408. patchEvent(el, key, prevValue, nextValue, parentComponent);
  9409. }
  9410. }
  9411. else if (key[0] === '.'
  9412. ? ((key = key.slice(1)), true)
  9413. : key[0] === '^'
  9414. ? ((key = key.slice(1)), false)
  9415. : shouldSetAsProp(el, key, nextValue, isSVG)) {
  9416. patchDOMProp(el, key, nextValue, prevChildren, parentComponent, parentSuspense, unmountChildren);
  9417. }
  9418. else {
  9419. // special case for <input v-model type="checkbox"> with
  9420. // :true-value & :false-value
  9421. // store value as dom properties since non-string values will be
  9422. // stringified.
  9423. if (key === 'true-value') {
  9424. el._trueValue = nextValue;
  9425. }
  9426. else if (key === 'false-value') {
  9427. el._falseValue = nextValue;
  9428. }
  9429. patchAttr(el, key, nextValue, isSVG);
  9430. }
  9431. };
  9432. function shouldSetAsProp(el, key, value, isSVG) {
  9433. if (isSVG) {
  9434. // most keys must be set as attribute on svg elements to work
  9435. // ...except innerHTML & textContent
  9436. if (key === 'innerHTML' || key === 'textContent') {
  9437. return true;
  9438. }
  9439. // or native onclick with function values
  9440. if (key in el && nativeOnRE.test(key) && isFunction(value)) {
  9441. return true;
  9442. }
  9443. return false;
  9444. }
  9445. // spellcheck and draggable are numerated attrs, however their
  9446. // corresponding DOM properties are actually booleans - this leads to
  9447. // setting it with a string "false" value leading it to be coerced to
  9448. // `true`, so we need to always treat them as attributes.
  9449. // Note that `contentEditable` doesn't have this problem: its DOM
  9450. // property is also enumerated string values.
  9451. if (key === 'spellcheck' || key === 'draggable') {
  9452. return false;
  9453. }
  9454. // #1787, #2840 form property on form elements is readonly and must be set as
  9455. // attribute.
  9456. if (key === 'form') {
  9457. return false;
  9458. }
  9459. // #1526 <input list> must be set as attribute
  9460. if (key === 'list' && el.tagName === 'INPUT') {
  9461. return false;
  9462. }
  9463. // #2766 <textarea type> must be set as attribute
  9464. if (key === 'type' && el.tagName === 'TEXTAREA') {
  9465. return false;
  9466. }
  9467. // native onclick with string value, must be set as attribute
  9468. if (nativeOnRE.test(key) && isString(value)) {
  9469. return false;
  9470. }
  9471. return key in el;
  9472. }
  9473. function defineCustomElement(options, hydate) {
  9474. const Comp = defineComponent(options);
  9475. class VueCustomElement extends VueElement {
  9476. constructor(initialProps) {
  9477. super(Comp, initialProps, hydate);
  9478. }
  9479. }
  9480. VueCustomElement.def = Comp;
  9481. return VueCustomElement;
  9482. }
  9483. const defineSSRCustomElement = ((options) => {
  9484. // @ts-ignore
  9485. return defineCustomElement(options, hydrate);
  9486. });
  9487. const BaseClass = (typeof HTMLElement !== 'undefined' ? HTMLElement : class {
  9488. });
  9489. class VueElement extends BaseClass {
  9490. constructor(_def, _props = {}, hydrate) {
  9491. super();
  9492. this._def = _def;
  9493. this._props = _props;
  9494. /**
  9495. * @internal
  9496. */
  9497. this._instance = null;
  9498. this._connected = false;
  9499. this._resolved = false;
  9500. this._numberProps = null;
  9501. if (this.shadowRoot && hydrate) {
  9502. hydrate(this._createVNode(), this.shadowRoot);
  9503. }
  9504. else {
  9505. if (this.shadowRoot) {
  9506. warn$1(`Custom element has pre-rendered declarative shadow root but is not ` +
  9507. `defined as hydratable. Use \`defineSSRCustomElement\`.`);
  9508. }
  9509. this.attachShadow({ mode: 'open' });
  9510. }
  9511. }
  9512. connectedCallback() {
  9513. this._connected = true;
  9514. if (!this._instance) {
  9515. this._resolveDef();
  9516. }
  9517. }
  9518. disconnectedCallback() {
  9519. this._connected = false;
  9520. nextTick(() => {
  9521. if (!this._connected) {
  9522. render(null, this.shadowRoot);
  9523. this._instance = null;
  9524. }
  9525. });
  9526. }
  9527. /**
  9528. * resolve inner component definition (handle possible async component)
  9529. */
  9530. _resolveDef() {
  9531. if (this._resolved) {
  9532. return;
  9533. }
  9534. this._resolved = true;
  9535. // set initial attrs
  9536. for (let i = 0; i < this.attributes.length; i++) {
  9537. this._setAttr(this.attributes[i].name);
  9538. }
  9539. // watch future attr changes
  9540. new MutationObserver(mutations => {
  9541. for (const m of mutations) {
  9542. this._setAttr(m.attributeName);
  9543. }
  9544. }).observe(this, { attributes: true });
  9545. const resolve = (def) => {
  9546. const { props, styles } = def;
  9547. const hasOptions = !isArray(props);
  9548. const rawKeys = props ? (hasOptions ? Object.keys(props) : props) : [];
  9549. // cast Number-type props set before resolve
  9550. let numberProps;
  9551. if (hasOptions) {
  9552. for (const key in this._props) {
  9553. const opt = props[key];
  9554. if (opt === Number || (opt && opt.type === Number)) {
  9555. this._props[key] = toNumber(this._props[key]);
  9556. (numberProps || (numberProps = Object.create(null)))[key] = true;
  9557. }
  9558. }
  9559. }
  9560. this._numberProps = numberProps;
  9561. // check if there are props set pre-upgrade or connect
  9562. for (const key of Object.keys(this)) {
  9563. if (key[0] !== '_') {
  9564. this._setProp(key, this[key], true, false);
  9565. }
  9566. }
  9567. // defining getter/setters on prototype
  9568. for (const key of rawKeys.map(camelize)) {
  9569. Object.defineProperty(this, key, {
  9570. get() {
  9571. return this._getProp(key);
  9572. },
  9573. set(val) {
  9574. this._setProp(key, val);
  9575. }
  9576. });
  9577. }
  9578. // apply CSS
  9579. this._applyStyles(styles);
  9580. // initial render
  9581. this._update();
  9582. };
  9583. const asyncDef = this._def.__asyncLoader;
  9584. if (asyncDef) {
  9585. asyncDef().then(resolve);
  9586. }
  9587. else {
  9588. resolve(this._def);
  9589. }
  9590. }
  9591. _setAttr(key) {
  9592. let value = this.getAttribute(key);
  9593. if (this._numberProps && this._numberProps[key]) {
  9594. value = toNumber(value);
  9595. }
  9596. this._setProp(camelize(key), value, false);
  9597. }
  9598. /**
  9599. * @internal
  9600. */
  9601. _getProp(key) {
  9602. return this._props[key];
  9603. }
  9604. /**
  9605. * @internal
  9606. */
  9607. _setProp(key, val, shouldReflect = true, shouldUpdate = true) {
  9608. if (val !== this._props[key]) {
  9609. this._props[key] = val;
  9610. if (shouldUpdate && this._instance) {
  9611. this._update();
  9612. }
  9613. // reflect
  9614. if (shouldReflect) {
  9615. if (val === true) {
  9616. this.setAttribute(hyphenate(key), '');
  9617. }
  9618. else if (typeof val === 'string' || typeof val === 'number') {
  9619. this.setAttribute(hyphenate(key), val + '');
  9620. }
  9621. else if (!val) {
  9622. this.removeAttribute(hyphenate(key));
  9623. }
  9624. }
  9625. }
  9626. }
  9627. _update() {
  9628. render(this._createVNode(), this.shadowRoot);
  9629. }
  9630. _createVNode() {
  9631. const vnode = createVNode(this._def, extend({}, this._props));
  9632. if (!this._instance) {
  9633. vnode.ce = instance => {
  9634. this._instance = instance;
  9635. instance.isCE = true;
  9636. // HMR
  9637. {
  9638. instance.ceReload = newStyles => {
  9639. // always reset styles
  9640. if (this._styles) {
  9641. this._styles.forEach(s => this.shadowRoot.removeChild(s));
  9642. this._styles.length = 0;
  9643. }
  9644. this._applyStyles(newStyles);
  9645. // if this is an async component, ceReload is called from the inner
  9646. // component so no need to reload the async wrapper
  9647. if (!this._def.__asyncLoader) {
  9648. // reload
  9649. this._instance = null;
  9650. this._update();
  9651. }
  9652. };
  9653. }
  9654. // intercept emit
  9655. instance.emit = (event, ...args) => {
  9656. this.dispatchEvent(new CustomEvent(event, {
  9657. detail: args
  9658. }));
  9659. };
  9660. // locate nearest Vue custom element parent for provide/inject
  9661. let parent = this;
  9662. while ((parent =
  9663. parent && (parent.parentNode || parent.host))) {
  9664. if (parent instanceof VueElement) {
  9665. instance.parent = parent._instance;
  9666. break;
  9667. }
  9668. }
  9669. };
  9670. }
  9671. return vnode;
  9672. }
  9673. _applyStyles(styles) {
  9674. if (styles) {
  9675. styles.forEach(css => {
  9676. const s = document.createElement('style');
  9677. s.textContent = css;
  9678. this.shadowRoot.appendChild(s);
  9679. // record for HMR
  9680. {
  9681. (this._styles || (this._styles = [])).push(s);
  9682. }
  9683. });
  9684. }
  9685. }
  9686. }
  9687. function useCssModule(name = '$style') {
  9688. /* istanbul ignore else */
  9689. {
  9690. {
  9691. warn$1(`useCssModule() is not supported in the global build.`);
  9692. }
  9693. return EMPTY_OBJ;
  9694. }
  9695. }
  9696. /**
  9697. * Runtime helper for SFC's CSS variable injection feature.
  9698. * @private
  9699. */
  9700. function useCssVars(getter) {
  9701. const instance = getCurrentInstance();
  9702. /* istanbul ignore next */
  9703. if (!instance) {
  9704. warn$1(`useCssVars is called without current active component instance.`);
  9705. return;
  9706. }
  9707. const setVars = () => setVarsOnVNode(instance.subTree, getter(instance.proxy));
  9708. watchPostEffect(setVars);
  9709. onMounted(() => {
  9710. const ob = new MutationObserver(setVars);
  9711. ob.observe(instance.subTree.el.parentNode, { childList: true });
  9712. onUnmounted(() => ob.disconnect());
  9713. });
  9714. }
  9715. function setVarsOnVNode(vnode, vars) {
  9716. if (vnode.shapeFlag & 128 /* SUSPENSE */) {
  9717. const suspense = vnode.suspense;
  9718. vnode = suspense.activeBranch;
  9719. if (suspense.pendingBranch && !suspense.isHydrating) {
  9720. suspense.effects.push(() => {
  9721. setVarsOnVNode(suspense.activeBranch, vars);
  9722. });
  9723. }
  9724. }
  9725. // drill down HOCs until it's a non-component vnode
  9726. while (vnode.component) {
  9727. vnode = vnode.component.subTree;
  9728. }
  9729. if (vnode.shapeFlag & 1 /* ELEMENT */ && vnode.el) {
  9730. setVarsOnNode(vnode.el, vars);
  9731. }
  9732. else if (vnode.type === Fragment) {
  9733. vnode.children.forEach(c => setVarsOnVNode(c, vars));
  9734. }
  9735. else if (vnode.type === Static) {
  9736. let { el, anchor } = vnode;
  9737. while (el) {
  9738. setVarsOnNode(el, vars);
  9739. if (el === anchor)
  9740. break;
  9741. el = el.nextSibling;
  9742. }
  9743. }
  9744. }
  9745. function setVarsOnNode(el, vars) {
  9746. if (el.nodeType === 1) {
  9747. const style = el.style;
  9748. for (const key in vars) {
  9749. style.setProperty(`--${key}`, vars[key]);
  9750. }
  9751. }
  9752. }
  9753. const TRANSITION = 'transition';
  9754. const ANIMATION = 'animation';
  9755. // DOM Transition is a higher-order-component based on the platform-agnostic
  9756. // base Transition component, with DOM-specific logic.
  9757. const Transition = (props, { slots }) => h(BaseTransition, resolveTransitionProps(props), slots);
  9758. Transition.displayName = 'Transition';
  9759. const DOMTransitionPropsValidators = {
  9760. name: String,
  9761. type: String,
  9762. css: {
  9763. type: Boolean,
  9764. default: true
  9765. },
  9766. duration: [String, Number, Object],
  9767. enterFromClass: String,
  9768. enterActiveClass: String,
  9769. enterToClass: String,
  9770. appearFromClass: String,
  9771. appearActiveClass: String,
  9772. appearToClass: String,
  9773. leaveFromClass: String,
  9774. leaveActiveClass: String,
  9775. leaveToClass: String
  9776. };
  9777. const TransitionPropsValidators = (Transition.props =
  9778. /*#__PURE__*/ extend({}, BaseTransition.props, DOMTransitionPropsValidators));
  9779. /**
  9780. * #3227 Incoming hooks may be merged into arrays when wrapping Transition
  9781. * with custom HOCs.
  9782. */
  9783. const callHook$1 = (hook, args = []) => {
  9784. if (isArray(hook)) {
  9785. hook.forEach(h => h(...args));
  9786. }
  9787. else if (hook) {
  9788. hook(...args);
  9789. }
  9790. };
  9791. /**
  9792. * Check if a hook expects a callback (2nd arg), which means the user
  9793. * intends to explicitly control the end of the transition.
  9794. */
  9795. const hasExplicitCallback = (hook) => {
  9796. return hook
  9797. ? isArray(hook)
  9798. ? hook.some(h => h.length > 1)
  9799. : hook.length > 1
  9800. : false;
  9801. };
  9802. function resolveTransitionProps(rawProps) {
  9803. const baseProps = {};
  9804. for (const key in rawProps) {
  9805. if (!(key in DOMTransitionPropsValidators)) {
  9806. baseProps[key] = rawProps[key];
  9807. }
  9808. }
  9809. if (rawProps.css === false) {
  9810. return baseProps;
  9811. }
  9812. 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;
  9813. const durations = normalizeDuration(duration);
  9814. const enterDuration = durations && durations[0];
  9815. const leaveDuration = durations && durations[1];
  9816. const { onBeforeEnter, onEnter, onEnterCancelled, onLeave, onLeaveCancelled, onBeforeAppear = onBeforeEnter, onAppear = onEnter, onAppearCancelled = onEnterCancelled } = baseProps;
  9817. const finishEnter = (el, isAppear, done) => {
  9818. removeTransitionClass(el, isAppear ? appearToClass : enterToClass);
  9819. removeTransitionClass(el, isAppear ? appearActiveClass : enterActiveClass);
  9820. done && done();
  9821. };
  9822. const finishLeave = (el, done) => {
  9823. removeTransitionClass(el, leaveToClass);
  9824. removeTransitionClass(el, leaveActiveClass);
  9825. done && done();
  9826. };
  9827. const makeEnterHook = (isAppear) => {
  9828. return (el, done) => {
  9829. const hook = isAppear ? onAppear : onEnter;
  9830. const resolve = () => finishEnter(el, isAppear, done);
  9831. callHook$1(hook, [el, resolve]);
  9832. nextFrame(() => {
  9833. removeTransitionClass(el, isAppear ? appearFromClass : enterFromClass);
  9834. addTransitionClass(el, isAppear ? appearToClass : enterToClass);
  9835. if (!hasExplicitCallback(hook)) {
  9836. whenTransitionEnds(el, type, enterDuration, resolve);
  9837. }
  9838. });
  9839. };
  9840. };
  9841. return extend(baseProps, {
  9842. onBeforeEnter(el) {
  9843. callHook$1(onBeforeEnter, [el]);
  9844. addTransitionClass(el, enterFromClass);
  9845. addTransitionClass(el, enterActiveClass);
  9846. },
  9847. onBeforeAppear(el) {
  9848. callHook$1(onBeforeAppear, [el]);
  9849. addTransitionClass(el, appearFromClass);
  9850. addTransitionClass(el, appearActiveClass);
  9851. },
  9852. onEnter: makeEnterHook(false),
  9853. onAppear: makeEnterHook(true),
  9854. onLeave(el, done) {
  9855. const resolve = () => finishLeave(el, done);
  9856. addTransitionClass(el, leaveFromClass);
  9857. // force reflow so *-leave-from classes immediately take effect (#2593)
  9858. forceReflow();
  9859. addTransitionClass(el, leaveActiveClass);
  9860. nextFrame(() => {
  9861. removeTransitionClass(el, leaveFromClass);
  9862. addTransitionClass(el, leaveToClass);
  9863. if (!hasExplicitCallback(onLeave)) {
  9864. whenTransitionEnds(el, type, leaveDuration, resolve);
  9865. }
  9866. });
  9867. callHook$1(onLeave, [el, resolve]);
  9868. },
  9869. onEnterCancelled(el) {
  9870. finishEnter(el, false);
  9871. callHook$1(onEnterCancelled, [el]);
  9872. },
  9873. onAppearCancelled(el) {
  9874. finishEnter(el, true);
  9875. callHook$1(onAppearCancelled, [el]);
  9876. },
  9877. onLeaveCancelled(el) {
  9878. finishLeave(el);
  9879. callHook$1(onLeaveCancelled, [el]);
  9880. }
  9881. });
  9882. }
  9883. function normalizeDuration(duration) {
  9884. if (duration == null) {
  9885. return null;
  9886. }
  9887. else if (isObject(duration)) {
  9888. return [NumberOf(duration.enter), NumberOf(duration.leave)];
  9889. }
  9890. else {
  9891. const n = NumberOf(duration);
  9892. return [n, n];
  9893. }
  9894. }
  9895. function NumberOf(val) {
  9896. const res = toNumber(val);
  9897. validateDuration(res);
  9898. return res;
  9899. }
  9900. function validateDuration(val) {
  9901. if (typeof val !== 'number') {
  9902. warn$1(`<transition> explicit duration is not a valid number - ` +
  9903. `got ${JSON.stringify(val)}.`);
  9904. }
  9905. else if (isNaN(val)) {
  9906. warn$1(`<transition> explicit duration is NaN - ` +
  9907. 'the duration expression might be incorrect.');
  9908. }
  9909. }
  9910. function addTransitionClass(el, cls) {
  9911. cls.split(/\s+/).forEach(c => c && el.classList.add(c));
  9912. (el._vtc ||
  9913. (el._vtc = new Set())).add(cls);
  9914. }
  9915. function removeTransitionClass(el, cls) {
  9916. cls.split(/\s+/).forEach(c => c && el.classList.remove(c));
  9917. const { _vtc } = el;
  9918. if (_vtc) {
  9919. _vtc.delete(cls);
  9920. if (!_vtc.size) {
  9921. el._vtc = undefined;
  9922. }
  9923. }
  9924. }
  9925. function nextFrame(cb) {
  9926. requestAnimationFrame(() => {
  9927. requestAnimationFrame(cb);
  9928. });
  9929. }
  9930. let endId = 0;
  9931. function whenTransitionEnds(el, expectedType, explicitTimeout, resolve) {
  9932. const id = (el._endId = ++endId);
  9933. const resolveIfNotStale = () => {
  9934. if (id === el._endId) {
  9935. resolve();
  9936. }
  9937. };
  9938. if (explicitTimeout) {
  9939. return setTimeout(resolveIfNotStale, explicitTimeout);
  9940. }
  9941. const { type, timeout, propCount } = getTransitionInfo(el, expectedType);
  9942. if (!type) {
  9943. return resolve();
  9944. }
  9945. const endEvent = type + 'end';
  9946. let ended = 0;
  9947. const end = () => {
  9948. el.removeEventListener(endEvent, onEnd);
  9949. resolveIfNotStale();
  9950. };
  9951. const onEnd = (e) => {
  9952. if (e.target === el && ++ended >= propCount) {
  9953. end();
  9954. }
  9955. };
  9956. setTimeout(() => {
  9957. if (ended < propCount) {
  9958. end();
  9959. }
  9960. }, timeout + 1);
  9961. el.addEventListener(endEvent, onEnd);
  9962. }
  9963. function getTransitionInfo(el, expectedType) {
  9964. const styles = window.getComputedStyle(el);
  9965. // JSDOM may return undefined for transition properties
  9966. const getStyleProperties = (key) => (styles[key] || '').split(', ');
  9967. const transitionDelays = getStyleProperties(TRANSITION + 'Delay');
  9968. const transitionDurations = getStyleProperties(TRANSITION + 'Duration');
  9969. const transitionTimeout = getTimeout(transitionDelays, transitionDurations);
  9970. const animationDelays = getStyleProperties(ANIMATION + 'Delay');
  9971. const animationDurations = getStyleProperties(ANIMATION + 'Duration');
  9972. const animationTimeout = getTimeout(animationDelays, animationDurations);
  9973. let type = null;
  9974. let timeout = 0;
  9975. let propCount = 0;
  9976. /* istanbul ignore if */
  9977. if (expectedType === TRANSITION) {
  9978. if (transitionTimeout > 0) {
  9979. type = TRANSITION;
  9980. timeout = transitionTimeout;
  9981. propCount = transitionDurations.length;
  9982. }
  9983. }
  9984. else if (expectedType === ANIMATION) {
  9985. if (animationTimeout > 0) {
  9986. type = ANIMATION;
  9987. timeout = animationTimeout;
  9988. propCount = animationDurations.length;
  9989. }
  9990. }
  9991. else {
  9992. timeout = Math.max(transitionTimeout, animationTimeout);
  9993. type =
  9994. timeout > 0
  9995. ? transitionTimeout > animationTimeout
  9996. ? TRANSITION
  9997. : ANIMATION
  9998. : null;
  9999. propCount = type
  10000. ? type === TRANSITION
  10001. ? transitionDurations.length
  10002. : animationDurations.length
  10003. : 0;
  10004. }
  10005. const hasTransform = type === TRANSITION &&
  10006. /\b(transform|all)(,|$)/.test(styles[TRANSITION + 'Property']);
  10007. return {
  10008. type,
  10009. timeout,
  10010. propCount,
  10011. hasTransform
  10012. };
  10013. }
  10014. function getTimeout(delays, durations) {
  10015. while (delays.length < durations.length) {
  10016. delays = delays.concat(delays);
  10017. }
  10018. return Math.max(...durations.map((d, i) => toMs(d) + toMs(delays[i])));
  10019. }
  10020. // Old versions of Chromium (below 61.0.3163.100) formats floating pointer
  10021. // numbers in a locale-dependent way, using a comma instead of a dot.
  10022. // If comma is not replaced with a dot, the input will be rounded down
  10023. // (i.e. acting as a floor function) causing unexpected behaviors
  10024. function toMs(s) {
  10025. return Number(s.slice(0, -1).replace(',', '.')) * 1000;
  10026. }
  10027. // synchronously force layout to put elements into a certain state
  10028. function forceReflow() {
  10029. return document.body.offsetHeight;
  10030. }
  10031. const positionMap = new WeakMap();
  10032. const newPositionMap = new WeakMap();
  10033. const TransitionGroupImpl = {
  10034. name: 'TransitionGroup',
  10035. props: /*#__PURE__*/ extend({}, TransitionPropsValidators, {
  10036. tag: String,
  10037. moveClass: String
  10038. }),
  10039. setup(props, { slots }) {
  10040. const instance = getCurrentInstance();
  10041. const state = useTransitionState();
  10042. let prevChildren;
  10043. let children;
  10044. onUpdated(() => {
  10045. // children is guaranteed to exist after initial render
  10046. if (!prevChildren.length) {
  10047. return;
  10048. }
  10049. const moveClass = props.moveClass || `${props.name || 'v'}-move`;
  10050. if (!hasCSSTransform(prevChildren[0].el, instance.vnode.el, moveClass)) {
  10051. return;
  10052. }
  10053. // we divide the work into three loops to avoid mixing DOM reads and writes
  10054. // in each iteration - which helps prevent layout thrashing.
  10055. prevChildren.forEach(callPendingCbs);
  10056. prevChildren.forEach(recordPosition);
  10057. const movedChildren = prevChildren.filter(applyTranslation);
  10058. // force reflow to put everything in position
  10059. forceReflow();
  10060. movedChildren.forEach(c => {
  10061. const el = c.el;
  10062. const style = el.style;
  10063. addTransitionClass(el, moveClass);
  10064. style.transform = style.webkitTransform = style.transitionDuration = '';
  10065. const cb = (el._moveCb = (e) => {
  10066. if (e && e.target !== el) {
  10067. return;
  10068. }
  10069. if (!e || /transform$/.test(e.propertyName)) {
  10070. el.removeEventListener('transitionend', cb);
  10071. el._moveCb = null;
  10072. removeTransitionClass(el, moveClass);
  10073. }
  10074. });
  10075. el.addEventListener('transitionend', cb);
  10076. });
  10077. });
  10078. return () => {
  10079. const rawProps = toRaw(props);
  10080. const cssTransitionProps = resolveTransitionProps(rawProps);
  10081. let tag = rawProps.tag || Fragment;
  10082. prevChildren = children;
  10083. children = slots.default ? getTransitionRawChildren(slots.default()) : [];
  10084. for (let i = 0; i < children.length; i++) {
  10085. const child = children[i];
  10086. if (child.key != null) {
  10087. setTransitionHooks(child, resolveTransitionHooks(child, cssTransitionProps, state, instance));
  10088. }
  10089. else {
  10090. warn$1(`<TransitionGroup> children must be keyed.`);
  10091. }
  10092. }
  10093. if (prevChildren) {
  10094. for (let i = 0; i < prevChildren.length; i++) {
  10095. const child = prevChildren[i];
  10096. setTransitionHooks(child, resolveTransitionHooks(child, cssTransitionProps, state, instance));
  10097. positionMap.set(child, child.el.getBoundingClientRect());
  10098. }
  10099. }
  10100. return createVNode(tag, null, children);
  10101. };
  10102. }
  10103. };
  10104. const TransitionGroup = TransitionGroupImpl;
  10105. function callPendingCbs(c) {
  10106. const el = c.el;
  10107. if (el._moveCb) {
  10108. el._moveCb();
  10109. }
  10110. if (el._enterCb) {
  10111. el._enterCb();
  10112. }
  10113. }
  10114. function recordPosition(c) {
  10115. newPositionMap.set(c, c.el.getBoundingClientRect());
  10116. }
  10117. function applyTranslation(c) {
  10118. const oldPos = positionMap.get(c);
  10119. const newPos = newPositionMap.get(c);
  10120. const dx = oldPos.left - newPos.left;
  10121. const dy = oldPos.top - newPos.top;
  10122. if (dx || dy) {
  10123. const s = c.el.style;
  10124. s.transform = s.webkitTransform = `translate(${dx}px,${dy}px)`;
  10125. s.transitionDuration = '0s';
  10126. return c;
  10127. }
  10128. }
  10129. function hasCSSTransform(el, root, moveClass) {
  10130. // Detect whether an element with the move class applied has
  10131. // CSS transitions. Since the element may be inside an entering
  10132. // transition at this very moment, we make a clone of it and remove
  10133. // all other transition classes applied to ensure only the move class
  10134. // is applied.
  10135. const clone = el.cloneNode();
  10136. if (el._vtc) {
  10137. el._vtc.forEach(cls => {
  10138. cls.split(/\s+/).forEach(c => c && clone.classList.remove(c));
  10139. });
  10140. }
  10141. moveClass.split(/\s+/).forEach(c => c && clone.classList.add(c));
  10142. clone.style.display = 'none';
  10143. const container = (root.nodeType === 1 ? root : root.parentNode);
  10144. container.appendChild(clone);
  10145. const { hasTransform } = getTransitionInfo(clone);
  10146. container.removeChild(clone);
  10147. return hasTransform;
  10148. }
  10149. const getModelAssigner = (vnode) => {
  10150. const fn = vnode.props['onUpdate:modelValue'];
  10151. return isArray(fn) ? value => invokeArrayFns(fn, value) : fn;
  10152. };
  10153. function onCompositionStart(e) {
  10154. e.target.composing = true;
  10155. }
  10156. function onCompositionEnd(e) {
  10157. const target = e.target;
  10158. if (target.composing) {
  10159. target.composing = false;
  10160. trigger$1(target, 'input');
  10161. }
  10162. }
  10163. function trigger$1(el, type) {
  10164. const e = document.createEvent('HTMLEvents');
  10165. e.initEvent(type, true, true);
  10166. el.dispatchEvent(e);
  10167. }
  10168. // We are exporting the v-model runtime directly as vnode hooks so that it can
  10169. // be tree-shaken in case v-model is never used.
  10170. const vModelText = {
  10171. created(el, { modifiers: { lazy, trim, number } }, vnode) {
  10172. el._assign = getModelAssigner(vnode);
  10173. const castToNumber = number || (vnode.props && vnode.props.type === 'number');
  10174. addEventListener(el, lazy ? 'change' : 'input', e => {
  10175. if (e.target.composing)
  10176. return;
  10177. let domValue = el.value;
  10178. if (trim) {
  10179. domValue = domValue.trim();
  10180. }
  10181. else if (castToNumber) {
  10182. domValue = toNumber(domValue);
  10183. }
  10184. el._assign(domValue);
  10185. });
  10186. if (trim) {
  10187. addEventListener(el, 'change', () => {
  10188. el.value = el.value.trim();
  10189. });
  10190. }
  10191. if (!lazy) {
  10192. addEventListener(el, 'compositionstart', onCompositionStart);
  10193. addEventListener(el, 'compositionend', onCompositionEnd);
  10194. // Safari < 10.2 & UIWebView doesn't fire compositionend when
  10195. // switching focus before confirming composition choice
  10196. // this also fixes the issue where some browsers e.g. iOS Chrome
  10197. // fires "change" instead of "input" on autocomplete.
  10198. addEventListener(el, 'change', onCompositionEnd);
  10199. }
  10200. },
  10201. // set value on mounted so it's after min/max for type="range"
  10202. mounted(el, { value }) {
  10203. el.value = value == null ? '' : value;
  10204. },
  10205. beforeUpdate(el, { value, modifiers: { lazy, trim, number } }, vnode) {
  10206. el._assign = getModelAssigner(vnode);
  10207. // avoid clearing unresolved text. #2302
  10208. if (el.composing)
  10209. return;
  10210. if (document.activeElement === el) {
  10211. if (lazy) {
  10212. return;
  10213. }
  10214. if (trim && el.value.trim() === value) {
  10215. return;
  10216. }
  10217. if ((number || el.type === 'number') && toNumber(el.value) === value) {
  10218. return;
  10219. }
  10220. }
  10221. const newValue = value == null ? '' : value;
  10222. if (el.value !== newValue) {
  10223. el.value = newValue;
  10224. }
  10225. }
  10226. };
  10227. const vModelCheckbox = {
  10228. // #4096 array checkboxes need to be deep traversed
  10229. deep: true,
  10230. created(el, _, vnode) {
  10231. el._assign = getModelAssigner(vnode);
  10232. addEventListener(el, 'change', () => {
  10233. const modelValue = el._modelValue;
  10234. const elementValue = getValue(el);
  10235. const checked = el.checked;
  10236. const assign = el._assign;
  10237. if (isArray(modelValue)) {
  10238. const index = looseIndexOf(modelValue, elementValue);
  10239. const found = index !== -1;
  10240. if (checked && !found) {
  10241. assign(modelValue.concat(elementValue));
  10242. }
  10243. else if (!checked && found) {
  10244. const filtered = [...modelValue];
  10245. filtered.splice(index, 1);
  10246. assign(filtered);
  10247. }
  10248. }
  10249. else if (isSet(modelValue)) {
  10250. const cloned = new Set(modelValue);
  10251. if (checked) {
  10252. cloned.add(elementValue);
  10253. }
  10254. else {
  10255. cloned.delete(elementValue);
  10256. }
  10257. assign(cloned);
  10258. }
  10259. else {
  10260. assign(getCheckboxValue(el, checked));
  10261. }
  10262. });
  10263. },
  10264. // set initial checked on mount to wait for true-value/false-value
  10265. mounted: setChecked,
  10266. beforeUpdate(el, binding, vnode) {
  10267. el._assign = getModelAssigner(vnode);
  10268. setChecked(el, binding, vnode);
  10269. }
  10270. };
  10271. function setChecked(el, { value, oldValue }, vnode) {
  10272. el._modelValue = value;
  10273. if (isArray(value)) {
  10274. el.checked = looseIndexOf(value, vnode.props.value) > -1;
  10275. }
  10276. else if (isSet(value)) {
  10277. el.checked = value.has(vnode.props.value);
  10278. }
  10279. else if (value !== oldValue) {
  10280. el.checked = looseEqual(value, getCheckboxValue(el, true));
  10281. }
  10282. }
  10283. const vModelRadio = {
  10284. created(el, { value }, vnode) {
  10285. el.checked = looseEqual(value, vnode.props.value);
  10286. el._assign = getModelAssigner(vnode);
  10287. addEventListener(el, 'change', () => {
  10288. el._assign(getValue(el));
  10289. });
  10290. },
  10291. beforeUpdate(el, { value, oldValue }, vnode) {
  10292. el._assign = getModelAssigner(vnode);
  10293. if (value !== oldValue) {
  10294. el.checked = looseEqual(value, vnode.props.value);
  10295. }
  10296. }
  10297. };
  10298. const vModelSelect = {
  10299. // <select multiple> value need to be deep traversed
  10300. deep: true,
  10301. created(el, { value, modifiers: { number } }, vnode) {
  10302. const isSetModel = isSet(value);
  10303. addEventListener(el, 'change', () => {
  10304. const selectedVal = Array.prototype.filter
  10305. .call(el.options, (o) => o.selected)
  10306. .map((o) => number ? toNumber(getValue(o)) : getValue(o));
  10307. el._assign(el.multiple
  10308. ? isSetModel
  10309. ? new Set(selectedVal)
  10310. : selectedVal
  10311. : selectedVal[0]);
  10312. });
  10313. el._assign = getModelAssigner(vnode);
  10314. },
  10315. // set value in mounted & updated because <select> relies on its children
  10316. // <option>s.
  10317. mounted(el, { value }) {
  10318. setSelected(el, value);
  10319. },
  10320. beforeUpdate(el, _binding, vnode) {
  10321. el._assign = getModelAssigner(vnode);
  10322. },
  10323. updated(el, { value }) {
  10324. setSelected(el, value);
  10325. }
  10326. };
  10327. function setSelected(el, value) {
  10328. const isMultiple = el.multiple;
  10329. if (isMultiple && !isArray(value) && !isSet(value)) {
  10330. warn$1(`<select multiple v-model> expects an Array or Set value for its binding, ` +
  10331. `but got ${Object.prototype.toString.call(value).slice(8, -1)}.`);
  10332. return;
  10333. }
  10334. for (let i = 0, l = el.options.length; i < l; i++) {
  10335. const option = el.options[i];
  10336. const optionValue = getValue(option);
  10337. if (isMultiple) {
  10338. if (isArray(value)) {
  10339. option.selected = looseIndexOf(value, optionValue) > -1;
  10340. }
  10341. else {
  10342. option.selected = value.has(optionValue);
  10343. }
  10344. }
  10345. else {
  10346. if (looseEqual(getValue(option), value)) {
  10347. if (el.selectedIndex !== i)
  10348. el.selectedIndex = i;
  10349. return;
  10350. }
  10351. }
  10352. }
  10353. if (!isMultiple && el.selectedIndex !== -1) {
  10354. el.selectedIndex = -1;
  10355. }
  10356. }
  10357. // retrieve raw value set via :value bindings
  10358. function getValue(el) {
  10359. return '_value' in el ? el._value : el.value;
  10360. }
  10361. // retrieve raw value for true-value and false-value set via :true-value or :false-value bindings
  10362. function getCheckboxValue(el, checked) {
  10363. const key = checked ? '_trueValue' : '_falseValue';
  10364. return key in el ? el[key] : checked;
  10365. }
  10366. const vModelDynamic = {
  10367. created(el, binding, vnode) {
  10368. callModelHook(el, binding, vnode, null, 'created');
  10369. },
  10370. mounted(el, binding, vnode) {
  10371. callModelHook(el, binding, vnode, null, 'mounted');
  10372. },
  10373. beforeUpdate(el, binding, vnode, prevVNode) {
  10374. callModelHook(el, binding, vnode, prevVNode, 'beforeUpdate');
  10375. },
  10376. updated(el, binding, vnode, prevVNode) {
  10377. callModelHook(el, binding, vnode, prevVNode, 'updated');
  10378. }
  10379. };
  10380. function callModelHook(el, binding, vnode, prevVNode, hook) {
  10381. let modelToUse;
  10382. switch (el.tagName) {
  10383. case 'SELECT':
  10384. modelToUse = vModelSelect;
  10385. break;
  10386. case 'TEXTAREA':
  10387. modelToUse = vModelText;
  10388. break;
  10389. default:
  10390. switch (vnode.props && vnode.props.type) {
  10391. case 'checkbox':
  10392. modelToUse = vModelCheckbox;
  10393. break;
  10394. case 'radio':
  10395. modelToUse = vModelRadio;
  10396. break;
  10397. default:
  10398. modelToUse = vModelText;
  10399. }
  10400. }
  10401. const fn = modelToUse[hook];
  10402. fn && fn(el, binding, vnode, prevVNode);
  10403. }
  10404. const systemModifiers = ['ctrl', 'shift', 'alt', 'meta'];
  10405. const modifierGuards = {
  10406. stop: e => e.stopPropagation(),
  10407. prevent: e => e.preventDefault(),
  10408. self: e => e.target !== e.currentTarget,
  10409. ctrl: e => !e.ctrlKey,
  10410. shift: e => !e.shiftKey,
  10411. alt: e => !e.altKey,
  10412. meta: e => !e.metaKey,
  10413. left: e => 'button' in e && e.button !== 0,
  10414. middle: e => 'button' in e && e.button !== 1,
  10415. right: e => 'button' in e && e.button !== 2,
  10416. exact: (e, modifiers) => systemModifiers.some(m => e[`${m}Key`] && !modifiers.includes(m))
  10417. };
  10418. /**
  10419. * @private
  10420. */
  10421. const withModifiers = (fn, modifiers) => {
  10422. return (event, ...args) => {
  10423. for (let i = 0; i < modifiers.length; i++) {
  10424. const guard = modifierGuards[modifiers[i]];
  10425. if (guard && guard(event, modifiers))
  10426. return;
  10427. }
  10428. return fn(event, ...args);
  10429. };
  10430. };
  10431. // Kept for 2.x compat.
  10432. // Note: IE11 compat for `spacebar` and `del` is removed for now.
  10433. const keyNames = {
  10434. esc: 'escape',
  10435. space: ' ',
  10436. up: 'arrow-up',
  10437. left: 'arrow-left',
  10438. right: 'arrow-right',
  10439. down: 'arrow-down',
  10440. delete: 'backspace'
  10441. };
  10442. /**
  10443. * @private
  10444. */
  10445. const withKeys = (fn, modifiers) => {
  10446. return (event) => {
  10447. if (!('key' in event)) {
  10448. return;
  10449. }
  10450. const eventKey = hyphenate(event.key);
  10451. if (modifiers.some(k => k === eventKey || keyNames[k] === eventKey)) {
  10452. return fn(event);
  10453. }
  10454. };
  10455. };
  10456. const vShow = {
  10457. beforeMount(el, { value }, { transition }) {
  10458. el._vod = el.style.display === 'none' ? '' : el.style.display;
  10459. if (transition && value) {
  10460. transition.beforeEnter(el);
  10461. }
  10462. else {
  10463. setDisplay(el, value);
  10464. }
  10465. },
  10466. mounted(el, { value }, { transition }) {
  10467. if (transition && value) {
  10468. transition.enter(el);
  10469. }
  10470. },
  10471. updated(el, { value, oldValue }, { transition }) {
  10472. if (!value === !oldValue)
  10473. return;
  10474. if (transition) {
  10475. if (value) {
  10476. transition.beforeEnter(el);
  10477. setDisplay(el, true);
  10478. transition.enter(el);
  10479. }
  10480. else {
  10481. transition.leave(el, () => {
  10482. setDisplay(el, false);
  10483. });
  10484. }
  10485. }
  10486. else {
  10487. setDisplay(el, value);
  10488. }
  10489. },
  10490. beforeUnmount(el, { value }) {
  10491. setDisplay(el, value);
  10492. }
  10493. };
  10494. function setDisplay(el, value) {
  10495. el.style.display = value ? el._vod : 'none';
  10496. }
  10497. const rendererOptions = extend({ patchProp }, nodeOps);
  10498. // lazy create the renderer - this makes core renderer logic tree-shakable
  10499. // in case the user only imports reactivity utilities from Vue.
  10500. let renderer;
  10501. let enabledHydration = false;
  10502. function ensureRenderer() {
  10503. return (renderer ||
  10504. (renderer = createRenderer(rendererOptions)));
  10505. }
  10506. function ensureHydrationRenderer() {
  10507. renderer = enabledHydration
  10508. ? renderer
  10509. : createHydrationRenderer(rendererOptions);
  10510. enabledHydration = true;
  10511. return renderer;
  10512. }
  10513. // use explicit type casts here to avoid import() calls in rolled-up d.ts
  10514. const render = ((...args) => {
  10515. ensureRenderer().render(...args);
  10516. });
  10517. const hydrate = ((...args) => {
  10518. ensureHydrationRenderer().hydrate(...args);
  10519. });
  10520. const createApp = ((...args) => {
  10521. const app = ensureRenderer().createApp(...args);
  10522. {
  10523. injectNativeTagCheck(app);
  10524. injectCompilerOptionsCheck(app);
  10525. }
  10526. const { mount } = app;
  10527. app.mount = (containerOrSelector) => {
  10528. const container = normalizeContainer(containerOrSelector);
  10529. if (!container)
  10530. return;
  10531. const component = app._component;
  10532. if (!isFunction(component) && !component.render && !component.template) {
  10533. // __UNSAFE__
  10534. // Reason: potential execution of JS expressions in in-DOM template.
  10535. // The user must make sure the in-DOM template is trusted. If it's
  10536. // rendered by the server, the template should not contain any user data.
  10537. component.template = container.innerHTML;
  10538. }
  10539. // clear content before mounting
  10540. container.innerHTML = '';
  10541. const proxy = mount(container, false, container instanceof SVGElement);
  10542. if (container instanceof Element) {
  10543. container.removeAttribute('v-cloak');
  10544. container.setAttribute('data-v-app', '');
  10545. }
  10546. return proxy;
  10547. };
  10548. return app;
  10549. });
  10550. const createSSRApp = ((...args) => {
  10551. const app = ensureHydrationRenderer().createApp(...args);
  10552. {
  10553. injectNativeTagCheck(app);
  10554. injectCompilerOptionsCheck(app);
  10555. }
  10556. const { mount } = app;
  10557. app.mount = (containerOrSelector) => {
  10558. const container = normalizeContainer(containerOrSelector);
  10559. if (container) {
  10560. return mount(container, true, container instanceof SVGElement);
  10561. }
  10562. };
  10563. return app;
  10564. });
  10565. function injectNativeTagCheck(app) {
  10566. // Inject `isNativeTag`
  10567. // this is used for component name validation (dev only)
  10568. Object.defineProperty(app.config, 'isNativeTag', {
  10569. value: (tag) => isHTMLTag(tag) || isSVGTag(tag),
  10570. writable: false
  10571. });
  10572. }
  10573. // dev only
  10574. function injectCompilerOptionsCheck(app) {
  10575. if (isRuntimeOnly()) {
  10576. const isCustomElement = app.config.isCustomElement;
  10577. Object.defineProperty(app.config, 'isCustomElement', {
  10578. get() {
  10579. return isCustomElement;
  10580. },
  10581. set() {
  10582. warn$1(`The \`isCustomElement\` config option is deprecated. Use ` +
  10583. `\`compilerOptions.isCustomElement\` instead.`);
  10584. }
  10585. });
  10586. const compilerOptions = app.config.compilerOptions;
  10587. const msg = `The \`compilerOptions\` config option is only respected when using ` +
  10588. `a build of Vue.js that includes the runtime compiler (aka "full build"). ` +
  10589. `Since you are using the runtime-only build, \`compilerOptions\` ` +
  10590. `must be passed to \`@vue/compiler-dom\` in the build setup instead.\n` +
  10591. `- For vue-loader: pass it via vue-loader's \`compilerOptions\` loader option.\n` +
  10592. `- For vue-cli: see https://cli.vuejs.org/guide/webpack.html#modifying-options-of-a-loader\n` +
  10593. `- 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`;
  10594. Object.defineProperty(app.config, 'compilerOptions', {
  10595. get() {
  10596. warn$1(msg);
  10597. return compilerOptions;
  10598. },
  10599. set() {
  10600. warn$1(msg);
  10601. }
  10602. });
  10603. }
  10604. }
  10605. function normalizeContainer(container) {
  10606. if (isString(container)) {
  10607. const res = document.querySelector(container);
  10608. if (!res) {
  10609. warn$1(`Failed to mount app: mount target selector "${container}" returned null.`);
  10610. }
  10611. return res;
  10612. }
  10613. if (window.ShadowRoot &&
  10614. container instanceof window.ShadowRoot &&
  10615. container.mode === 'closed') {
  10616. warn$1(`mounting on a ShadowRoot with \`{mode: "closed"}\` may lead to unpredictable bugs`);
  10617. }
  10618. return container;
  10619. }
  10620. /**
  10621. * @internal
  10622. */
  10623. const initDirectivesForSSR = NOOP;
  10624. function initDev() {
  10625. {
  10626. {
  10627. console.info(`You are running a development build of Vue.\n` +
  10628. `Make sure to use the production build (*.prod.js) when deploying for production.`);
  10629. }
  10630. initCustomFormatter();
  10631. }
  10632. }
  10633. function defaultOnError(error) {
  10634. throw error;
  10635. }
  10636. function defaultOnWarn(msg) {
  10637. console.warn(`[Vue warn] ${msg.message}`);
  10638. }
  10639. function createCompilerError(code, loc, messages, additionalMessage) {
  10640. const msg = (messages || errorMessages)[code] + (additionalMessage || ``)
  10641. ;
  10642. const error = new SyntaxError(String(msg));
  10643. error.code = code;
  10644. error.loc = loc;
  10645. return error;
  10646. }
  10647. const errorMessages = {
  10648. // parse errors
  10649. [0 /* ABRUPT_CLOSING_OF_EMPTY_COMMENT */]: 'Illegal comment.',
  10650. [1 /* CDATA_IN_HTML_CONTENT */]: 'CDATA section is allowed only in XML context.',
  10651. [2 /* DUPLICATE_ATTRIBUTE */]: 'Duplicate attribute.',
  10652. [3 /* END_TAG_WITH_ATTRIBUTES */]: 'End tag cannot have attributes.',
  10653. [4 /* END_TAG_WITH_TRAILING_SOLIDUS */]: "Illegal '/' in tags.",
  10654. [5 /* EOF_BEFORE_TAG_NAME */]: 'Unexpected EOF in tag.',
  10655. [6 /* EOF_IN_CDATA */]: 'Unexpected EOF in CDATA section.',
  10656. [7 /* EOF_IN_COMMENT */]: 'Unexpected EOF in comment.',
  10657. [8 /* EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT */]: 'Unexpected EOF in script.',
  10658. [9 /* EOF_IN_TAG */]: 'Unexpected EOF in tag.',
  10659. [10 /* INCORRECTLY_CLOSED_COMMENT */]: 'Incorrectly closed comment.',
  10660. [11 /* INCORRECTLY_OPENED_COMMENT */]: 'Incorrectly opened comment.',
  10661. [12 /* INVALID_FIRST_CHARACTER_OF_TAG_NAME */]: "Illegal tag name. Use '&lt;' to print '<'.",
  10662. [13 /* MISSING_ATTRIBUTE_VALUE */]: 'Attribute value was expected.',
  10663. [14 /* MISSING_END_TAG_NAME */]: 'End tag name was expected.',
  10664. [15 /* MISSING_WHITESPACE_BETWEEN_ATTRIBUTES */]: 'Whitespace was expected.',
  10665. [16 /* NESTED_COMMENT */]: "Unexpected '<!--' in comment.",
  10666. [17 /* UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME */]: 'Attribute name cannot contain U+0022 ("), U+0027 (\'), and U+003C (<).',
  10667. [18 /* UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE */]: 'Unquoted attribute value cannot contain U+0022 ("), U+0027 (\'), U+003C (<), U+003D (=), and U+0060 (`).',
  10668. [19 /* UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME */]: "Attribute name cannot start with '='.",
  10669. [21 /* UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME */]: "'<?' is allowed only in XML context.",
  10670. [20 /* UNEXPECTED_NULL_CHARACTER */]: `Unexpected null character.`,
  10671. [22 /* UNEXPECTED_SOLIDUS_IN_TAG */]: "Illegal '/' in tags.",
  10672. // Vue-specific parse errors
  10673. [23 /* X_INVALID_END_TAG */]: 'Invalid end tag.',
  10674. [24 /* X_MISSING_END_TAG */]: 'Element is missing end tag.',
  10675. [25 /* X_MISSING_INTERPOLATION_END */]: 'Interpolation end sign was not found.',
  10676. [27 /* X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END */]: 'End bracket for dynamic directive argument was not found. ' +
  10677. 'Note that dynamic directive argument cannot contain spaces.',
  10678. [26 /* X_MISSING_DIRECTIVE_NAME */]: 'Legal directive name was expected.',
  10679. // transform errors
  10680. [28 /* X_V_IF_NO_EXPRESSION */]: `v-if/v-else-if is missing expression.`,
  10681. [29 /* X_V_IF_SAME_KEY */]: `v-if/else branches must use unique keys.`,
  10682. [30 /* X_V_ELSE_NO_ADJACENT_IF */]: `v-else/v-else-if has no adjacent v-if or v-else-if.`,
  10683. [31 /* X_V_FOR_NO_EXPRESSION */]: `v-for is missing expression.`,
  10684. [32 /* X_V_FOR_MALFORMED_EXPRESSION */]: `v-for has invalid expression.`,
  10685. [33 /* X_V_FOR_TEMPLATE_KEY_PLACEMENT */]: `<template v-for> key should be placed on the <template> tag.`,
  10686. [34 /* X_V_BIND_NO_EXPRESSION */]: `v-bind is missing expression.`,
  10687. [35 /* X_V_ON_NO_EXPRESSION */]: `v-on is missing expression.`,
  10688. [36 /* X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET */]: `Unexpected custom directive on <slot> outlet.`,
  10689. [37 /* X_V_SLOT_MIXED_SLOT_USAGE */]: `Mixed v-slot usage on both the component and nested <template>.` +
  10690. `When there are multiple named slots, all slots should use <template> ` +
  10691. `syntax to avoid scope ambiguity.`,
  10692. [38 /* X_V_SLOT_DUPLICATE_SLOT_NAMES */]: `Duplicate slot names found. `,
  10693. [39 /* X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN */]: `Extraneous children found when component already has explicitly named ` +
  10694. `default slot. These children will be ignored.`,
  10695. [40 /* X_V_SLOT_MISPLACED */]: `v-slot can only be used on components or <template> tags.`,
  10696. [41 /* X_V_MODEL_NO_EXPRESSION */]: `v-model is missing expression.`,
  10697. [42 /* X_V_MODEL_MALFORMED_EXPRESSION */]: `v-model value must be a valid JavaScript member expression.`,
  10698. [43 /* X_V_MODEL_ON_SCOPE_VARIABLE */]: `v-model cannot be used on v-for or v-slot scope variables because they are not writable.`,
  10699. [44 /* X_INVALID_EXPRESSION */]: `Error parsing JavaScript expression: `,
  10700. [45 /* X_KEEP_ALIVE_INVALID_CHILDREN */]: `<KeepAlive> expects exactly one child component.`,
  10701. // generic errors
  10702. [46 /* X_PREFIX_ID_NOT_SUPPORTED */]: `"prefixIdentifiers" option is not supported in this build of compiler.`,
  10703. [47 /* X_MODULE_MODE_NOT_SUPPORTED */]: `ES module mode is not supported in this build of compiler.`,
  10704. [48 /* X_CACHE_HANDLER_NOT_SUPPORTED */]: `"cacheHandlers" option is only supported when the "prefixIdentifiers" option is enabled.`,
  10705. [49 /* X_SCOPE_ID_NOT_SUPPORTED */]: `"scopeId" option is only supported in module mode.`,
  10706. // just to fulfill types
  10707. [50 /* __EXTEND_POINT__ */]: ``
  10708. };
  10709. const FRAGMENT = Symbol(`Fragment` );
  10710. const TELEPORT = Symbol(`Teleport` );
  10711. const SUSPENSE = Symbol(`Suspense` );
  10712. const KEEP_ALIVE = Symbol(`KeepAlive` );
  10713. const BASE_TRANSITION = Symbol(`BaseTransition` );
  10714. const OPEN_BLOCK = Symbol(`openBlock` );
  10715. const CREATE_BLOCK = Symbol(`createBlock` );
  10716. const CREATE_ELEMENT_BLOCK = Symbol(`createElementBlock` );
  10717. const CREATE_VNODE = Symbol(`createVNode` );
  10718. const CREATE_ELEMENT_VNODE = Symbol(`createElementVNode` );
  10719. const CREATE_COMMENT = Symbol(`createCommentVNode` );
  10720. const CREATE_TEXT = Symbol(`createTextVNode` );
  10721. const CREATE_STATIC = Symbol(`createStaticVNode` );
  10722. const RESOLVE_COMPONENT = Symbol(`resolveComponent` );
  10723. const RESOLVE_DYNAMIC_COMPONENT = Symbol(`resolveDynamicComponent` );
  10724. const RESOLVE_DIRECTIVE = Symbol(`resolveDirective` );
  10725. const RESOLVE_FILTER = Symbol(`resolveFilter` );
  10726. const WITH_DIRECTIVES = Symbol(`withDirectives` );
  10727. const RENDER_LIST = Symbol(`renderList` );
  10728. const RENDER_SLOT = Symbol(`renderSlot` );
  10729. const CREATE_SLOTS = Symbol(`createSlots` );
  10730. const TO_DISPLAY_STRING = Symbol(`toDisplayString` );
  10731. const MERGE_PROPS = Symbol(`mergeProps` );
  10732. const NORMALIZE_CLASS = Symbol(`normalizeClass` );
  10733. const NORMALIZE_STYLE = Symbol(`normalizeStyle` );
  10734. const NORMALIZE_PROPS = Symbol(`normalizeProps` );
  10735. const GUARD_REACTIVE_PROPS = Symbol(`guardReactiveProps` );
  10736. const TO_HANDLERS = Symbol(`toHandlers` );
  10737. const CAMELIZE = Symbol(`camelize` );
  10738. const CAPITALIZE = Symbol(`capitalize` );
  10739. const TO_HANDLER_KEY = Symbol(`toHandlerKey` );
  10740. const SET_BLOCK_TRACKING = Symbol(`setBlockTracking` );
  10741. const PUSH_SCOPE_ID = Symbol(`pushScopeId` );
  10742. const POP_SCOPE_ID = Symbol(`popScopeId` );
  10743. const WITH_CTX = Symbol(`withCtx` );
  10744. const UNREF = Symbol(`unref` );
  10745. const IS_REF = Symbol(`isRef` );
  10746. const WITH_MEMO = Symbol(`withMemo` );
  10747. const IS_MEMO_SAME = Symbol(`isMemoSame` );
  10748. // Name mapping for runtime helpers that need to be imported from 'vue' in
  10749. // generated code. Make sure these are correctly exported in the runtime!
  10750. // Using `any` here because TS doesn't allow symbols as index type.
  10751. const helperNameMap = {
  10752. [FRAGMENT]: `Fragment`,
  10753. [TELEPORT]: `Teleport`,
  10754. [SUSPENSE]: `Suspense`,
  10755. [KEEP_ALIVE]: `KeepAlive`,
  10756. [BASE_TRANSITION]: `BaseTransition`,
  10757. [OPEN_BLOCK]: `openBlock`,
  10758. [CREATE_BLOCK]: `createBlock`,
  10759. [CREATE_ELEMENT_BLOCK]: `createElementBlock`,
  10760. [CREATE_VNODE]: `createVNode`,
  10761. [CREATE_ELEMENT_VNODE]: `createElementVNode`,
  10762. [CREATE_COMMENT]: `createCommentVNode`,
  10763. [CREATE_TEXT]: `createTextVNode`,
  10764. [CREATE_STATIC]: `createStaticVNode`,
  10765. [RESOLVE_COMPONENT]: `resolveComponent`,
  10766. [RESOLVE_DYNAMIC_COMPONENT]: `resolveDynamicComponent`,
  10767. [RESOLVE_DIRECTIVE]: `resolveDirective`,
  10768. [RESOLVE_FILTER]: `resolveFilter`,
  10769. [WITH_DIRECTIVES]: `withDirectives`,
  10770. [RENDER_LIST]: `renderList`,
  10771. [RENDER_SLOT]: `renderSlot`,
  10772. [CREATE_SLOTS]: `createSlots`,
  10773. [TO_DISPLAY_STRING]: `toDisplayString`,
  10774. [MERGE_PROPS]: `mergeProps`,
  10775. [NORMALIZE_CLASS]: `normalizeClass`,
  10776. [NORMALIZE_STYLE]: `normalizeStyle`,
  10777. [NORMALIZE_PROPS]: `normalizeProps`,
  10778. [GUARD_REACTIVE_PROPS]: `guardReactiveProps`,
  10779. [TO_HANDLERS]: `toHandlers`,
  10780. [CAMELIZE]: `camelize`,
  10781. [CAPITALIZE]: `capitalize`,
  10782. [TO_HANDLER_KEY]: `toHandlerKey`,
  10783. [SET_BLOCK_TRACKING]: `setBlockTracking`,
  10784. [PUSH_SCOPE_ID]: `pushScopeId`,
  10785. [POP_SCOPE_ID]: `popScopeId`,
  10786. [WITH_CTX]: `withCtx`,
  10787. [UNREF]: `unref`,
  10788. [IS_REF]: `isRef`,
  10789. [WITH_MEMO]: `withMemo`,
  10790. [IS_MEMO_SAME]: `isMemoSame`
  10791. };
  10792. function registerRuntimeHelpers(helpers) {
  10793. Object.getOwnPropertySymbols(helpers).forEach(s => {
  10794. helperNameMap[s] = helpers[s];
  10795. });
  10796. }
  10797. // AST Utilities ---------------------------------------------------------------
  10798. // Some expressions, e.g. sequence and conditional expressions, are never
  10799. // associated with template nodes, so their source locations are just a stub.
  10800. // Container types like CompoundExpression also don't need a real location.
  10801. const locStub = {
  10802. source: '',
  10803. start: { line: 1, column: 1, offset: 0 },
  10804. end: { line: 1, column: 1, offset: 0 }
  10805. };
  10806. function createRoot(children, loc = locStub) {
  10807. return {
  10808. type: 0 /* ROOT */,
  10809. children,
  10810. helpers: [],
  10811. components: [],
  10812. directives: [],
  10813. hoists: [],
  10814. imports: [],
  10815. cached: 0,
  10816. temps: 0,
  10817. codegenNode: undefined,
  10818. loc
  10819. };
  10820. }
  10821. function createVNodeCall(context, tag, props, children, patchFlag, dynamicProps, directives, isBlock = false, disableTracking = false, isComponent = false, loc = locStub) {
  10822. if (context) {
  10823. if (isBlock) {
  10824. context.helper(OPEN_BLOCK);
  10825. context.helper(getVNodeBlockHelper(context.inSSR, isComponent));
  10826. }
  10827. else {
  10828. context.helper(getVNodeHelper(context.inSSR, isComponent));
  10829. }
  10830. if (directives) {
  10831. context.helper(WITH_DIRECTIVES);
  10832. }
  10833. }
  10834. return {
  10835. type: 13 /* VNODE_CALL */,
  10836. tag,
  10837. props,
  10838. children,
  10839. patchFlag,
  10840. dynamicProps,
  10841. directives,
  10842. isBlock,
  10843. disableTracking,
  10844. isComponent,
  10845. loc
  10846. };
  10847. }
  10848. function createArrayExpression(elements, loc = locStub) {
  10849. return {
  10850. type: 17 /* JS_ARRAY_EXPRESSION */,
  10851. loc,
  10852. elements
  10853. };
  10854. }
  10855. function createObjectExpression(properties, loc = locStub) {
  10856. return {
  10857. type: 15 /* JS_OBJECT_EXPRESSION */,
  10858. loc,
  10859. properties
  10860. };
  10861. }
  10862. function createObjectProperty(key, value) {
  10863. return {
  10864. type: 16 /* JS_PROPERTY */,
  10865. loc: locStub,
  10866. key: isString(key) ? createSimpleExpression(key, true) : key,
  10867. value
  10868. };
  10869. }
  10870. function createSimpleExpression(content, isStatic = false, loc = locStub, constType = 0 /* NOT_CONSTANT */) {
  10871. return {
  10872. type: 4 /* SIMPLE_EXPRESSION */,
  10873. loc,
  10874. content,
  10875. isStatic,
  10876. constType: isStatic ? 3 /* CAN_STRINGIFY */ : constType
  10877. };
  10878. }
  10879. function createCompoundExpression(children, loc = locStub) {
  10880. return {
  10881. type: 8 /* COMPOUND_EXPRESSION */,
  10882. loc,
  10883. children
  10884. };
  10885. }
  10886. function createCallExpression(callee, args = [], loc = locStub) {
  10887. return {
  10888. type: 14 /* JS_CALL_EXPRESSION */,
  10889. loc,
  10890. callee,
  10891. arguments: args
  10892. };
  10893. }
  10894. function createFunctionExpression(params, returns = undefined, newline = false, isSlot = false, loc = locStub) {
  10895. return {
  10896. type: 18 /* JS_FUNCTION_EXPRESSION */,
  10897. params,
  10898. returns,
  10899. newline,
  10900. isSlot,
  10901. loc
  10902. };
  10903. }
  10904. function createConditionalExpression(test, consequent, alternate, newline = true) {
  10905. return {
  10906. type: 19 /* JS_CONDITIONAL_EXPRESSION */,
  10907. test,
  10908. consequent,
  10909. alternate,
  10910. newline,
  10911. loc: locStub
  10912. };
  10913. }
  10914. function createCacheExpression(index, value, isVNode = false) {
  10915. return {
  10916. type: 20 /* JS_CACHE_EXPRESSION */,
  10917. index,
  10918. value,
  10919. isVNode,
  10920. loc: locStub
  10921. };
  10922. }
  10923. function createBlockStatement(body) {
  10924. return {
  10925. type: 21 /* JS_BLOCK_STATEMENT */,
  10926. body,
  10927. loc: locStub
  10928. };
  10929. }
  10930. const isStaticExp = (p) => p.type === 4 /* SIMPLE_EXPRESSION */ && p.isStatic;
  10931. const isBuiltInType = (tag, expected) => tag === expected || tag === hyphenate(expected);
  10932. function isCoreComponent(tag) {
  10933. if (isBuiltInType(tag, 'Teleport')) {
  10934. return TELEPORT;
  10935. }
  10936. else if (isBuiltInType(tag, 'Suspense')) {
  10937. return SUSPENSE;
  10938. }
  10939. else if (isBuiltInType(tag, 'KeepAlive')) {
  10940. return KEEP_ALIVE;
  10941. }
  10942. else if (isBuiltInType(tag, 'BaseTransition')) {
  10943. return BASE_TRANSITION;
  10944. }
  10945. }
  10946. const nonIdentifierRE = /^\d|[^\$\w]/;
  10947. const isSimpleIdentifier = (name) => !nonIdentifierRE.test(name);
  10948. const validFirstIdentCharRE = /[A-Za-z_$\xA0-\uFFFF]/;
  10949. const validIdentCharRE = /[\.\?\w$\xA0-\uFFFF]/;
  10950. const whitespaceRE = /\s+[.[]\s*|\s*[.[]\s+/g;
  10951. /**
  10952. * Simple lexer to check if an expression is a member expression. This is
  10953. * lax and only checks validity at the root level (i.e. does not validate exps
  10954. * inside square brackets), but it's ok since these are only used on template
  10955. * expressions and false positives are invalid expressions in the first place.
  10956. */
  10957. const isMemberExpressionBrowser = (path) => {
  10958. // remove whitespaces around . or [ first
  10959. path = path.trim().replace(whitespaceRE, s => s.trim());
  10960. let state = 0 /* inMemberExp */;
  10961. let stateStack = [];
  10962. let currentOpenBracketCount = 0;
  10963. let currentOpenParensCount = 0;
  10964. let currentStringType = null;
  10965. for (let i = 0; i < path.length; i++) {
  10966. const char = path.charAt(i);
  10967. switch (state) {
  10968. case 0 /* inMemberExp */:
  10969. if (char === '[') {
  10970. stateStack.push(state);
  10971. state = 1 /* inBrackets */;
  10972. currentOpenBracketCount++;
  10973. }
  10974. else if (char === '(') {
  10975. stateStack.push(state);
  10976. state = 2 /* inParens */;
  10977. currentOpenParensCount++;
  10978. }
  10979. else if (!(i === 0 ? validFirstIdentCharRE : validIdentCharRE).test(char)) {
  10980. return false;
  10981. }
  10982. break;
  10983. case 1 /* inBrackets */:
  10984. if (char === `'` || char === `"` || char === '`') {
  10985. stateStack.push(state);
  10986. state = 3 /* inString */;
  10987. currentStringType = char;
  10988. }
  10989. else if (char === `[`) {
  10990. currentOpenBracketCount++;
  10991. }
  10992. else if (char === `]`) {
  10993. if (!--currentOpenBracketCount) {
  10994. state = stateStack.pop();
  10995. }
  10996. }
  10997. break;
  10998. case 2 /* inParens */:
  10999. if (char === `'` || char === `"` || char === '`') {
  11000. stateStack.push(state);
  11001. state = 3 /* inString */;
  11002. currentStringType = char;
  11003. }
  11004. else if (char === `(`) {
  11005. currentOpenParensCount++;
  11006. }
  11007. else if (char === `)`) {
  11008. // if the exp ends as a call then it should not be considered valid
  11009. if (i === path.length - 1) {
  11010. return false;
  11011. }
  11012. if (!--currentOpenParensCount) {
  11013. state = stateStack.pop();
  11014. }
  11015. }
  11016. break;
  11017. case 3 /* inString */:
  11018. if (char === currentStringType) {
  11019. state = stateStack.pop();
  11020. currentStringType = null;
  11021. }
  11022. break;
  11023. }
  11024. }
  11025. return !currentOpenBracketCount && !currentOpenParensCount;
  11026. };
  11027. const isMemberExpression = isMemberExpressionBrowser
  11028. ;
  11029. function getInnerRange(loc, offset, length) {
  11030. const source = loc.source.slice(offset, offset + length);
  11031. const newLoc = {
  11032. source,
  11033. start: advancePositionWithClone(loc.start, loc.source, offset),
  11034. end: loc.end
  11035. };
  11036. if (length != null) {
  11037. newLoc.end = advancePositionWithClone(loc.start, loc.source, offset + length);
  11038. }
  11039. return newLoc;
  11040. }
  11041. function advancePositionWithClone(pos, source, numberOfCharacters = source.length) {
  11042. return advancePositionWithMutation(extend({}, pos), source, numberOfCharacters);
  11043. }
  11044. // advance by mutation without cloning (for performance reasons), since this
  11045. // gets called a lot in the parser
  11046. function advancePositionWithMutation(pos, source, numberOfCharacters = source.length) {
  11047. let linesCount = 0;
  11048. let lastNewLinePos = -1;
  11049. for (let i = 0; i < numberOfCharacters; i++) {
  11050. if (source.charCodeAt(i) === 10 /* newline char code */) {
  11051. linesCount++;
  11052. lastNewLinePos = i;
  11053. }
  11054. }
  11055. pos.offset += numberOfCharacters;
  11056. pos.line += linesCount;
  11057. pos.column =
  11058. lastNewLinePos === -1
  11059. ? pos.column + numberOfCharacters
  11060. : numberOfCharacters - lastNewLinePos;
  11061. return pos;
  11062. }
  11063. function assert(condition, msg) {
  11064. /* istanbul ignore if */
  11065. if (!condition) {
  11066. throw new Error(msg || `unexpected compiler condition`);
  11067. }
  11068. }
  11069. function findDir(node, name, allowEmpty = false) {
  11070. for (let i = 0; i < node.props.length; i++) {
  11071. const p = node.props[i];
  11072. if (p.type === 7 /* DIRECTIVE */ &&
  11073. (allowEmpty || p.exp) &&
  11074. (isString(name) ? p.name === name : name.test(p.name))) {
  11075. return p;
  11076. }
  11077. }
  11078. }
  11079. function findProp(node, name, dynamicOnly = false, allowEmpty = false) {
  11080. for (let i = 0; i < node.props.length; i++) {
  11081. const p = node.props[i];
  11082. if (p.type === 6 /* ATTRIBUTE */) {
  11083. if (dynamicOnly)
  11084. continue;
  11085. if (p.name === name && (p.value || allowEmpty)) {
  11086. return p;
  11087. }
  11088. }
  11089. else if (p.name === 'bind' &&
  11090. (p.exp || allowEmpty) &&
  11091. isStaticArgOf(p.arg, name)) {
  11092. return p;
  11093. }
  11094. }
  11095. }
  11096. function isStaticArgOf(arg, name) {
  11097. return !!(arg && isStaticExp(arg) && arg.content === name);
  11098. }
  11099. function hasDynamicKeyVBind(node) {
  11100. return node.props.some(p => p.type === 7 /* DIRECTIVE */ &&
  11101. p.name === 'bind' &&
  11102. (!p.arg || // v-bind="obj"
  11103. p.arg.type !== 4 /* SIMPLE_EXPRESSION */ || // v-bind:[_ctx.foo]
  11104. !p.arg.isStatic) // v-bind:[foo]
  11105. );
  11106. }
  11107. function isText(node) {
  11108. return node.type === 5 /* INTERPOLATION */ || node.type === 2 /* TEXT */;
  11109. }
  11110. function isVSlot(p) {
  11111. return p.type === 7 /* DIRECTIVE */ && p.name === 'slot';
  11112. }
  11113. function isTemplateNode(node) {
  11114. return (node.type === 1 /* ELEMENT */ && node.tagType === 3 /* TEMPLATE */);
  11115. }
  11116. function isSlotOutlet(node) {
  11117. return node.type === 1 /* ELEMENT */ && node.tagType === 2 /* SLOT */;
  11118. }
  11119. function getVNodeHelper(ssr, isComponent) {
  11120. return ssr || isComponent ? CREATE_VNODE : CREATE_ELEMENT_VNODE;
  11121. }
  11122. function getVNodeBlockHelper(ssr, isComponent) {
  11123. return ssr || isComponent ? CREATE_BLOCK : CREATE_ELEMENT_BLOCK;
  11124. }
  11125. const propsHelperSet = new Set([NORMALIZE_PROPS, GUARD_REACTIVE_PROPS]);
  11126. function getUnnormalizedProps(props, callPath = []) {
  11127. if (props &&
  11128. !isString(props) &&
  11129. props.type === 14 /* JS_CALL_EXPRESSION */) {
  11130. const callee = props.callee;
  11131. if (!isString(callee) && propsHelperSet.has(callee)) {
  11132. return getUnnormalizedProps(props.arguments[0], callPath.concat(props));
  11133. }
  11134. }
  11135. return [props, callPath];
  11136. }
  11137. function injectProp(node, prop, context) {
  11138. let propsWithInjection;
  11139. /**
  11140. * 1. mergeProps(...)
  11141. * 2. toHandlers(...)
  11142. * 3. normalizeProps(...)
  11143. * 4. normalizeProps(guardReactiveProps(...))
  11144. *
  11145. * we need to get the real props before normalization
  11146. */
  11147. let props = node.type === 13 /* VNODE_CALL */ ? node.props : node.arguments[2];
  11148. let callPath = [];
  11149. let parentCall;
  11150. if (props &&
  11151. !isString(props) &&
  11152. props.type === 14 /* JS_CALL_EXPRESSION */) {
  11153. const ret = getUnnormalizedProps(props);
  11154. props = ret[0];
  11155. callPath = ret[1];
  11156. parentCall = callPath[callPath.length - 1];
  11157. }
  11158. if (props == null || isString(props)) {
  11159. propsWithInjection = createObjectExpression([prop]);
  11160. }
  11161. else if (props.type === 14 /* JS_CALL_EXPRESSION */) {
  11162. // merged props... add ours
  11163. // only inject key to object literal if it's the first argument so that
  11164. // if doesn't override user provided keys
  11165. const first = props.arguments[0];
  11166. if (!isString(first) && first.type === 15 /* JS_OBJECT_EXPRESSION */) {
  11167. first.properties.unshift(prop);
  11168. }
  11169. else {
  11170. if (props.callee === TO_HANDLERS) {
  11171. // #2366
  11172. propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
  11173. createObjectExpression([prop]),
  11174. props
  11175. ]);
  11176. }
  11177. else {
  11178. props.arguments.unshift(createObjectExpression([prop]));
  11179. }
  11180. }
  11181. !propsWithInjection && (propsWithInjection = props);
  11182. }
  11183. else if (props.type === 15 /* JS_OBJECT_EXPRESSION */) {
  11184. let alreadyExists = false;
  11185. // check existing key to avoid overriding user provided keys
  11186. if (prop.key.type === 4 /* SIMPLE_EXPRESSION */) {
  11187. const propKeyName = prop.key.content;
  11188. alreadyExists = props.properties.some(p => p.key.type === 4 /* SIMPLE_EXPRESSION */ &&
  11189. p.key.content === propKeyName);
  11190. }
  11191. if (!alreadyExists) {
  11192. props.properties.unshift(prop);
  11193. }
  11194. propsWithInjection = props;
  11195. }
  11196. else {
  11197. // single v-bind with expression, return a merged replacement
  11198. propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
  11199. createObjectExpression([prop]),
  11200. props
  11201. ]);
  11202. // in the case of nested helper call, e.g. `normalizeProps(guardReactiveProps(props))`,
  11203. // it will be rewritten as `normalizeProps(mergeProps({ key: 0 }, props))`,
  11204. // the `guardReactiveProps` will no longer be needed
  11205. if (parentCall && parentCall.callee === GUARD_REACTIVE_PROPS) {
  11206. parentCall = callPath[callPath.length - 2];
  11207. }
  11208. }
  11209. if (node.type === 13 /* VNODE_CALL */) {
  11210. if (parentCall) {
  11211. parentCall.arguments[0] = propsWithInjection;
  11212. }
  11213. else {
  11214. node.props = propsWithInjection;
  11215. }
  11216. }
  11217. else {
  11218. if (parentCall) {
  11219. parentCall.arguments[0] = propsWithInjection;
  11220. }
  11221. else {
  11222. node.arguments[2] = propsWithInjection;
  11223. }
  11224. }
  11225. }
  11226. function toValidAssetId(name, type) {
  11227. // see issue#4422, we need adding identifier on validAssetId if variable `name` has specific character
  11228. return `_${type}_${name.replace(/[^\w]/g, (searchValue, replaceValue) => {
  11229. return searchValue === '-' ? '_' : name.charCodeAt(replaceValue).toString();
  11230. })}`;
  11231. }
  11232. function getMemoedVNodeCall(node) {
  11233. if (node.type === 14 /* JS_CALL_EXPRESSION */ && node.callee === WITH_MEMO) {
  11234. return node.arguments[1].returns;
  11235. }
  11236. else {
  11237. return node;
  11238. }
  11239. }
  11240. function makeBlock(node, { helper, removeHelper, inSSR }) {
  11241. if (!node.isBlock) {
  11242. node.isBlock = true;
  11243. removeHelper(getVNodeHelper(inSSR, node.isComponent));
  11244. helper(OPEN_BLOCK);
  11245. helper(getVNodeBlockHelper(inSSR, node.isComponent));
  11246. }
  11247. }
  11248. const deprecationData = {
  11249. ["COMPILER_IS_ON_ELEMENT" /* COMPILER_IS_ON_ELEMENT */]: {
  11250. message: `Platform-native elements with "is" prop will no longer be ` +
  11251. `treated as components in Vue 3 unless the "is" value is explicitly ` +
  11252. `prefixed with "vue:".`,
  11253. link: `https://v3.vuejs.org/guide/migration/custom-elements-interop.html`
  11254. },
  11255. ["COMPILER_V_BIND_SYNC" /* COMPILER_V_BIND_SYNC */]: {
  11256. message: key => `.sync modifier for v-bind has been removed. Use v-model with ` +
  11257. `argument instead. \`v-bind:${key}.sync\` should be changed to ` +
  11258. `\`v-model:${key}\`.`,
  11259. link: `https://v3.vuejs.org/guide/migration/v-model.html`
  11260. },
  11261. ["COMPILER_V_BIND_PROP" /* COMPILER_V_BIND_PROP */]: {
  11262. message: `.prop modifier for v-bind has been removed and no longer necessary. ` +
  11263. `Vue 3 will automatically set a binding as DOM property when appropriate.`
  11264. },
  11265. ["COMPILER_V_BIND_OBJECT_ORDER" /* COMPILER_V_BIND_OBJECT_ORDER */]: {
  11266. message: `v-bind="obj" usage is now order sensitive and behaves like JavaScript ` +
  11267. `object spread: it will now overwrite an existing non-mergeable attribute ` +
  11268. `that appears before v-bind in the case of conflict. ` +
  11269. `To retain 2.x behavior, move v-bind to make it the first attribute. ` +
  11270. `You can also suppress this warning if the usage is intended.`,
  11271. link: `https://v3.vuejs.org/guide/migration/v-bind.html`
  11272. },
  11273. ["COMPILER_V_ON_NATIVE" /* COMPILER_V_ON_NATIVE */]: {
  11274. message: `.native modifier for v-on has been removed as is no longer necessary.`,
  11275. link: `https://v3.vuejs.org/guide/migration/v-on-native-modifier-removed.html`
  11276. },
  11277. ["COMPILER_V_IF_V_FOR_PRECEDENCE" /* COMPILER_V_IF_V_FOR_PRECEDENCE */]: {
  11278. message: `v-if / v-for precedence when used on the same element has changed ` +
  11279. `in Vue 3: v-if now takes higher precedence and will no longer have ` +
  11280. `access to v-for scope variables. It is best to avoid the ambiguity ` +
  11281. `with <template> tags or use a computed property that filters v-for ` +
  11282. `data source.`,
  11283. link: `https://v3.vuejs.org/guide/migration/v-if-v-for.html`
  11284. },
  11285. ["COMPILER_NATIVE_TEMPLATE" /* COMPILER_NATIVE_TEMPLATE */]: {
  11286. message: `<template> with no special directives will render as a native template ` +
  11287. `element instead of its inner content in Vue 3.`
  11288. },
  11289. ["COMPILER_INLINE_TEMPLATE" /* COMPILER_INLINE_TEMPLATE */]: {
  11290. message: `"inline-template" has been removed in Vue 3.`,
  11291. link: `https://v3.vuejs.org/guide/migration/inline-template-attribute.html`
  11292. },
  11293. ["COMPILER_FILTER" /* COMPILER_FILTERS */]: {
  11294. message: `filters have been removed in Vue 3. ` +
  11295. `The "|" symbol will be treated as native JavaScript bitwise OR operator. ` +
  11296. `Use method calls or computed properties instead.`,
  11297. link: `https://v3.vuejs.org/guide/migration/filters.html`
  11298. }
  11299. };
  11300. function getCompatValue(key, context) {
  11301. const config = context.options
  11302. ? context.options.compatConfig
  11303. : context.compatConfig;
  11304. const value = config && config[key];
  11305. if (key === 'MODE') {
  11306. return value || 3; // compiler defaults to v3 behavior
  11307. }
  11308. else {
  11309. return value;
  11310. }
  11311. }
  11312. function isCompatEnabled(key, context) {
  11313. const mode = getCompatValue('MODE', context);
  11314. const value = getCompatValue(key, context);
  11315. // in v3 mode, only enable if explicitly set to true
  11316. // otherwise enable for any non-false value
  11317. return mode === 3 ? value === true : value !== false;
  11318. }
  11319. function checkCompatEnabled(key, context, loc, ...args) {
  11320. const enabled = isCompatEnabled(key, context);
  11321. if (enabled) {
  11322. warnDeprecation(key, context, loc, ...args);
  11323. }
  11324. return enabled;
  11325. }
  11326. function warnDeprecation(key, context, loc, ...args) {
  11327. const val = getCompatValue(key, context);
  11328. if (val === 'suppress-warning') {
  11329. return;
  11330. }
  11331. const { message, link } = deprecationData[key];
  11332. const msg = `(deprecation ${key}) ${typeof message === 'function' ? message(...args) : message}${link ? `\n Details: ${link}` : ``}`;
  11333. const err = new SyntaxError(msg);
  11334. err.code = key;
  11335. if (loc)
  11336. err.loc = loc;
  11337. context.onWarn(err);
  11338. }
  11339. // The default decoder only provides escapes for characters reserved as part of
  11340. // the template syntax, and is only used if the custom renderer did not provide
  11341. // a platform-specific decoder.
  11342. const decodeRE = /&(gt|lt|amp|apos|quot);/g;
  11343. const decodeMap = {
  11344. gt: '>',
  11345. lt: '<',
  11346. amp: '&',
  11347. apos: "'",
  11348. quot: '"'
  11349. };
  11350. const defaultParserOptions = {
  11351. delimiters: [`{{`, `}}`],
  11352. getNamespace: () => 0 /* HTML */,
  11353. getTextMode: () => 0 /* DATA */,
  11354. isVoidTag: NO,
  11355. isPreTag: NO,
  11356. isCustomElement: NO,
  11357. decodeEntities: (rawText) => rawText.replace(decodeRE, (_, p1) => decodeMap[p1]),
  11358. onError: defaultOnError,
  11359. onWarn: defaultOnWarn,
  11360. comments: true
  11361. };
  11362. function baseParse(content, options = {}) {
  11363. const context = createParserContext(content, options);
  11364. const start = getCursor(context);
  11365. return createRoot(parseChildren(context, 0 /* DATA */, []), getSelection(context, start));
  11366. }
  11367. function createParserContext(content, rawOptions) {
  11368. const options = extend({}, defaultParserOptions);
  11369. let key;
  11370. for (key in rawOptions) {
  11371. // @ts-ignore
  11372. options[key] =
  11373. rawOptions[key] === undefined
  11374. ? defaultParserOptions[key]
  11375. : rawOptions[key];
  11376. }
  11377. return {
  11378. options,
  11379. column: 1,
  11380. line: 1,
  11381. offset: 0,
  11382. originalSource: content,
  11383. source: content,
  11384. inPre: false,
  11385. inVPre: false,
  11386. onWarn: options.onWarn
  11387. };
  11388. }
  11389. function parseChildren(context, mode, ancestors) {
  11390. const parent = last(ancestors);
  11391. const ns = parent ? parent.ns : 0 /* HTML */;
  11392. const nodes = [];
  11393. while (!isEnd(context, mode, ancestors)) {
  11394. const s = context.source;
  11395. let node = undefined;
  11396. if (mode === 0 /* DATA */ || mode === 1 /* RCDATA */) {
  11397. if (!context.inVPre && startsWith(s, context.options.delimiters[0])) {
  11398. // '{{'
  11399. node = parseInterpolation(context, mode);
  11400. }
  11401. else if (mode === 0 /* DATA */ && s[0] === '<') {
  11402. // https://html.spec.whatwg.org/multipage/parsing.html#tag-open-state
  11403. if (s.length === 1) {
  11404. emitError(context, 5 /* EOF_BEFORE_TAG_NAME */, 1);
  11405. }
  11406. else if (s[1] === '!') {
  11407. // https://html.spec.whatwg.org/multipage/parsing.html#markup-declaration-open-state
  11408. if (startsWith(s, '<!--')) {
  11409. node = parseComment(context);
  11410. }
  11411. else if (startsWith(s, '<!DOCTYPE')) {
  11412. // Ignore DOCTYPE by a limitation.
  11413. node = parseBogusComment(context);
  11414. }
  11415. else if (startsWith(s, '<![CDATA[')) {
  11416. if (ns !== 0 /* HTML */) {
  11417. node = parseCDATA(context, ancestors);
  11418. }
  11419. else {
  11420. emitError(context, 1 /* CDATA_IN_HTML_CONTENT */);
  11421. node = parseBogusComment(context);
  11422. }
  11423. }
  11424. else {
  11425. emitError(context, 11 /* INCORRECTLY_OPENED_COMMENT */);
  11426. node = parseBogusComment(context);
  11427. }
  11428. }
  11429. else if (s[1] === '/') {
  11430. // https://html.spec.whatwg.org/multipage/parsing.html#end-tag-open-state
  11431. if (s.length === 2) {
  11432. emitError(context, 5 /* EOF_BEFORE_TAG_NAME */, 2);
  11433. }
  11434. else if (s[2] === '>') {
  11435. emitError(context, 14 /* MISSING_END_TAG_NAME */, 2);
  11436. advanceBy(context, 3);
  11437. continue;
  11438. }
  11439. else if (/[a-z]/i.test(s[2])) {
  11440. emitError(context, 23 /* X_INVALID_END_TAG */);
  11441. parseTag(context, 1 /* End */, parent);
  11442. continue;
  11443. }
  11444. else {
  11445. emitError(context, 12 /* INVALID_FIRST_CHARACTER_OF_TAG_NAME */, 2);
  11446. node = parseBogusComment(context);
  11447. }
  11448. }
  11449. else if (/[a-z]/i.test(s[1])) {
  11450. node = parseElement(context, ancestors);
  11451. }
  11452. else if (s[1] === '?') {
  11453. emitError(context, 21 /* UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME */, 1);
  11454. node = parseBogusComment(context);
  11455. }
  11456. else {
  11457. emitError(context, 12 /* INVALID_FIRST_CHARACTER_OF_TAG_NAME */, 1);
  11458. }
  11459. }
  11460. }
  11461. if (!node) {
  11462. node = parseText(context, mode);
  11463. }
  11464. if (isArray(node)) {
  11465. for (let i = 0; i < node.length; i++) {
  11466. pushNode(nodes, node[i]);
  11467. }
  11468. }
  11469. else {
  11470. pushNode(nodes, node);
  11471. }
  11472. }
  11473. // Whitespace handling strategy like v2
  11474. let removedWhitespace = false;
  11475. if (mode !== 2 /* RAWTEXT */ && mode !== 1 /* RCDATA */) {
  11476. const shouldCondense = context.options.whitespace !== 'preserve';
  11477. for (let i = 0; i < nodes.length; i++) {
  11478. const node = nodes[i];
  11479. if (!context.inPre && node.type === 2 /* TEXT */) {
  11480. if (!/[^\t\r\n\f ]/.test(node.content)) {
  11481. const prev = nodes[i - 1];
  11482. const next = nodes[i + 1];
  11483. // Remove if:
  11484. // - the whitespace is the first or last node, or:
  11485. // - (condense mode) the whitespace is adjacent to a comment, or:
  11486. // - (condense mode) the whitespace is between two elements AND contains newline
  11487. if (!prev ||
  11488. !next ||
  11489. (shouldCondense &&
  11490. (prev.type === 3 /* COMMENT */ ||
  11491. next.type === 3 /* COMMENT */ ||
  11492. (prev.type === 1 /* ELEMENT */ &&
  11493. next.type === 1 /* ELEMENT */ &&
  11494. /[\r\n]/.test(node.content))))) {
  11495. removedWhitespace = true;
  11496. nodes[i] = null;
  11497. }
  11498. else {
  11499. // Otherwise, the whitespace is condensed into a single space
  11500. node.content = ' ';
  11501. }
  11502. }
  11503. else if (shouldCondense) {
  11504. // in condense mode, consecutive whitespaces in text are condensed
  11505. // down to a single space.
  11506. node.content = node.content.replace(/[\t\r\n\f ]+/g, ' ');
  11507. }
  11508. }
  11509. // Remove comment nodes if desired by configuration.
  11510. else if (node.type === 3 /* COMMENT */ && !context.options.comments) {
  11511. removedWhitespace = true;
  11512. nodes[i] = null;
  11513. }
  11514. }
  11515. if (context.inPre && parent && context.options.isPreTag(parent.tag)) {
  11516. // remove leading newline per html spec
  11517. // https://html.spec.whatwg.org/multipage/grouping-content.html#the-pre-element
  11518. const first = nodes[0];
  11519. if (first && first.type === 2 /* TEXT */) {
  11520. first.content = first.content.replace(/^\r?\n/, '');
  11521. }
  11522. }
  11523. }
  11524. return removedWhitespace ? nodes.filter(Boolean) : nodes;
  11525. }
  11526. function pushNode(nodes, node) {
  11527. if (node.type === 2 /* TEXT */) {
  11528. const prev = last(nodes);
  11529. // Merge if both this and the previous node are text and those are
  11530. // consecutive. This happens for cases like "a < b".
  11531. if (prev &&
  11532. prev.type === 2 /* TEXT */ &&
  11533. prev.loc.end.offset === node.loc.start.offset) {
  11534. prev.content += node.content;
  11535. prev.loc.end = node.loc.end;
  11536. prev.loc.source += node.loc.source;
  11537. return;
  11538. }
  11539. }
  11540. nodes.push(node);
  11541. }
  11542. function parseCDATA(context, ancestors) {
  11543. advanceBy(context, 9);
  11544. const nodes = parseChildren(context, 3 /* CDATA */, ancestors);
  11545. if (context.source.length === 0) {
  11546. emitError(context, 6 /* EOF_IN_CDATA */);
  11547. }
  11548. else {
  11549. advanceBy(context, 3);
  11550. }
  11551. return nodes;
  11552. }
  11553. function parseComment(context) {
  11554. const start = getCursor(context);
  11555. let content;
  11556. // Regular comment.
  11557. const match = /--(\!)?>/.exec(context.source);
  11558. if (!match) {
  11559. content = context.source.slice(4);
  11560. advanceBy(context, context.source.length);
  11561. emitError(context, 7 /* EOF_IN_COMMENT */);
  11562. }
  11563. else {
  11564. if (match.index <= 3) {
  11565. emitError(context, 0 /* ABRUPT_CLOSING_OF_EMPTY_COMMENT */);
  11566. }
  11567. if (match[1]) {
  11568. emitError(context, 10 /* INCORRECTLY_CLOSED_COMMENT */);
  11569. }
  11570. content = context.source.slice(4, match.index);
  11571. // Advancing with reporting nested comments.
  11572. const s = context.source.slice(0, match.index);
  11573. let prevIndex = 1, nestedIndex = 0;
  11574. while ((nestedIndex = s.indexOf('<!--', prevIndex)) !== -1) {
  11575. advanceBy(context, nestedIndex - prevIndex + 1);
  11576. if (nestedIndex + 4 < s.length) {
  11577. emitError(context, 16 /* NESTED_COMMENT */);
  11578. }
  11579. prevIndex = nestedIndex + 1;
  11580. }
  11581. advanceBy(context, match.index + match[0].length - prevIndex + 1);
  11582. }
  11583. return {
  11584. type: 3 /* COMMENT */,
  11585. content,
  11586. loc: getSelection(context, start)
  11587. };
  11588. }
  11589. function parseBogusComment(context) {
  11590. const start = getCursor(context);
  11591. const contentStart = context.source[1] === '?' ? 1 : 2;
  11592. let content;
  11593. const closeIndex = context.source.indexOf('>');
  11594. if (closeIndex === -1) {
  11595. content = context.source.slice(contentStart);
  11596. advanceBy(context, context.source.length);
  11597. }
  11598. else {
  11599. content = context.source.slice(contentStart, closeIndex);
  11600. advanceBy(context, closeIndex + 1);
  11601. }
  11602. return {
  11603. type: 3 /* COMMENT */,
  11604. content,
  11605. loc: getSelection(context, start)
  11606. };
  11607. }
  11608. function parseElement(context, ancestors) {
  11609. // Start tag.
  11610. const wasInPre = context.inPre;
  11611. const wasInVPre = context.inVPre;
  11612. const parent = last(ancestors);
  11613. const element = parseTag(context, 0 /* Start */, parent);
  11614. const isPreBoundary = context.inPre && !wasInPre;
  11615. const isVPreBoundary = context.inVPre && !wasInVPre;
  11616. if (element.isSelfClosing || context.options.isVoidTag(element.tag)) {
  11617. // #4030 self-closing <pre> tag
  11618. if (isPreBoundary) {
  11619. context.inPre = false;
  11620. }
  11621. if (isVPreBoundary) {
  11622. context.inVPre = false;
  11623. }
  11624. return element;
  11625. }
  11626. // Children.
  11627. ancestors.push(element);
  11628. const mode = context.options.getTextMode(element, parent);
  11629. const children = parseChildren(context, mode, ancestors);
  11630. ancestors.pop();
  11631. element.children = children;
  11632. // End tag.
  11633. if (startsWithEndTagOpen(context.source, element.tag)) {
  11634. parseTag(context, 1 /* End */, parent);
  11635. }
  11636. else {
  11637. emitError(context, 24 /* X_MISSING_END_TAG */, 0, element.loc.start);
  11638. if (context.source.length === 0 && element.tag.toLowerCase() === 'script') {
  11639. const first = children[0];
  11640. if (first && startsWith(first.loc.source, '<!--')) {
  11641. emitError(context, 8 /* EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT */);
  11642. }
  11643. }
  11644. }
  11645. element.loc = getSelection(context, element.loc.start);
  11646. if (isPreBoundary) {
  11647. context.inPre = false;
  11648. }
  11649. if (isVPreBoundary) {
  11650. context.inVPre = false;
  11651. }
  11652. return element;
  11653. }
  11654. const isSpecialTemplateDirective = /*#__PURE__*/ makeMap(`if,else,else-if,for,slot`);
  11655. function parseTag(context, type, parent) {
  11656. // Tag open.
  11657. const start = getCursor(context);
  11658. const match = /^<\/?([a-z][^\t\r\n\f />]*)/i.exec(context.source);
  11659. const tag = match[1];
  11660. const ns = context.options.getNamespace(tag, parent);
  11661. advanceBy(context, match[0].length);
  11662. advanceSpaces(context);
  11663. // save current state in case we need to re-parse attributes with v-pre
  11664. const cursor = getCursor(context);
  11665. const currentSource = context.source;
  11666. // check <pre> tag
  11667. if (context.options.isPreTag(tag)) {
  11668. context.inPre = true;
  11669. }
  11670. // Attributes.
  11671. let props = parseAttributes(context, type);
  11672. // check v-pre
  11673. if (type === 0 /* Start */ &&
  11674. !context.inVPre &&
  11675. props.some(p => p.type === 7 /* DIRECTIVE */ && p.name === 'pre')) {
  11676. context.inVPre = true;
  11677. // reset context
  11678. extend(context, cursor);
  11679. context.source = currentSource;
  11680. // re-parse attrs and filter out v-pre itself
  11681. props = parseAttributes(context, type).filter(p => p.name !== 'v-pre');
  11682. }
  11683. // Tag close.
  11684. let isSelfClosing = false;
  11685. if (context.source.length === 0) {
  11686. emitError(context, 9 /* EOF_IN_TAG */);
  11687. }
  11688. else {
  11689. isSelfClosing = startsWith(context.source, '/>');
  11690. if (type === 1 /* End */ && isSelfClosing) {
  11691. emitError(context, 4 /* END_TAG_WITH_TRAILING_SOLIDUS */);
  11692. }
  11693. advanceBy(context, isSelfClosing ? 2 : 1);
  11694. }
  11695. if (type === 1 /* End */) {
  11696. return;
  11697. }
  11698. let tagType = 0 /* ELEMENT */;
  11699. if (!context.inVPre) {
  11700. if (tag === 'slot') {
  11701. tagType = 2 /* SLOT */;
  11702. }
  11703. else if (tag === 'template') {
  11704. if (props.some(p => p.type === 7 /* DIRECTIVE */ && isSpecialTemplateDirective(p.name))) {
  11705. tagType = 3 /* TEMPLATE */;
  11706. }
  11707. }
  11708. else if (isComponent(tag, props, context)) {
  11709. tagType = 1 /* COMPONENT */;
  11710. }
  11711. }
  11712. return {
  11713. type: 1 /* ELEMENT */,
  11714. ns,
  11715. tag,
  11716. tagType,
  11717. props,
  11718. isSelfClosing,
  11719. children: [],
  11720. loc: getSelection(context, start),
  11721. codegenNode: undefined // to be created during transform phase
  11722. };
  11723. }
  11724. function isComponent(tag, props, context) {
  11725. const options = context.options;
  11726. if (options.isCustomElement(tag)) {
  11727. return false;
  11728. }
  11729. if (tag === 'component' ||
  11730. /^[A-Z]/.test(tag) ||
  11731. isCoreComponent(tag) ||
  11732. (options.isBuiltInComponent && options.isBuiltInComponent(tag)) ||
  11733. (options.isNativeTag && !options.isNativeTag(tag))) {
  11734. return true;
  11735. }
  11736. // at this point the tag should be a native tag, but check for potential "is"
  11737. // casting
  11738. for (let i = 0; i < props.length; i++) {
  11739. const p = props[i];
  11740. if (p.type === 6 /* ATTRIBUTE */) {
  11741. if (p.name === 'is' && p.value) {
  11742. if (p.value.content.startsWith('vue:')) {
  11743. return true;
  11744. }
  11745. }
  11746. }
  11747. else {
  11748. // directive
  11749. // v-is (TODO Deprecate)
  11750. if (p.name === 'is') {
  11751. return true;
  11752. }
  11753. else if (
  11754. // :is on plain element - only treat as component in compat mode
  11755. p.name === 'bind' &&
  11756. isStaticArgOf(p.arg, 'is') &&
  11757. false &&
  11758. checkCompatEnabled("COMPILER_IS_ON_ELEMENT" /* COMPILER_IS_ON_ELEMENT */, context, p.loc)) {
  11759. return true;
  11760. }
  11761. }
  11762. }
  11763. }
  11764. function parseAttributes(context, type) {
  11765. const props = [];
  11766. const attributeNames = new Set();
  11767. while (context.source.length > 0 &&
  11768. !startsWith(context.source, '>') &&
  11769. !startsWith(context.source, '/>')) {
  11770. if (startsWith(context.source, '/')) {
  11771. emitError(context, 22 /* UNEXPECTED_SOLIDUS_IN_TAG */);
  11772. advanceBy(context, 1);
  11773. advanceSpaces(context);
  11774. continue;
  11775. }
  11776. if (type === 1 /* End */) {
  11777. emitError(context, 3 /* END_TAG_WITH_ATTRIBUTES */);
  11778. }
  11779. const attr = parseAttribute(context, attributeNames);
  11780. // Trim whitespace between class
  11781. // https://github.com/vuejs/vue-next/issues/4251
  11782. if (attr.type === 6 /* ATTRIBUTE */ &&
  11783. attr.value &&
  11784. attr.name === 'class') {
  11785. attr.value.content = attr.value.content.replace(/\s+/g, ' ').trim();
  11786. }
  11787. if (type === 0 /* Start */) {
  11788. props.push(attr);
  11789. }
  11790. if (/^[^\t\r\n\f />]/.test(context.source)) {
  11791. emitError(context, 15 /* MISSING_WHITESPACE_BETWEEN_ATTRIBUTES */);
  11792. }
  11793. advanceSpaces(context);
  11794. }
  11795. return props;
  11796. }
  11797. function parseAttribute(context, nameSet) {
  11798. // Name.
  11799. const start = getCursor(context);
  11800. const match = /^[^\t\r\n\f />][^\t\r\n\f />=]*/.exec(context.source);
  11801. const name = match[0];
  11802. if (nameSet.has(name)) {
  11803. emitError(context, 2 /* DUPLICATE_ATTRIBUTE */);
  11804. }
  11805. nameSet.add(name);
  11806. if (name[0] === '=') {
  11807. emitError(context, 19 /* UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME */);
  11808. }
  11809. {
  11810. const pattern = /["'<]/g;
  11811. let m;
  11812. while ((m = pattern.exec(name))) {
  11813. emitError(context, 17 /* UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME */, m.index);
  11814. }
  11815. }
  11816. advanceBy(context, name.length);
  11817. // Value
  11818. let value = undefined;
  11819. if (/^[\t\r\n\f ]*=/.test(context.source)) {
  11820. advanceSpaces(context);
  11821. advanceBy(context, 1);
  11822. advanceSpaces(context);
  11823. value = parseAttributeValue(context);
  11824. if (!value) {
  11825. emitError(context, 13 /* MISSING_ATTRIBUTE_VALUE */);
  11826. }
  11827. }
  11828. const loc = getSelection(context, start);
  11829. if (!context.inVPre && /^(v-[A-Za-z0-9-]|:|\.|@|#)/.test(name)) {
  11830. const match = /(?:^v-([a-z0-9-]+))?(?:(?::|^\.|^@|^#)(\[[^\]]+\]|[^\.]+))?(.+)?$/i.exec(name);
  11831. let isPropShorthand = startsWith(name, '.');
  11832. let dirName = match[1] ||
  11833. (isPropShorthand || startsWith(name, ':')
  11834. ? 'bind'
  11835. : startsWith(name, '@')
  11836. ? 'on'
  11837. : 'slot');
  11838. let arg;
  11839. if (match[2]) {
  11840. const isSlot = dirName === 'slot';
  11841. const startOffset = name.lastIndexOf(match[2]);
  11842. const loc = getSelection(context, getNewPosition(context, start, startOffset), getNewPosition(context, start, startOffset + match[2].length + ((isSlot && match[3]) || '').length));
  11843. let content = match[2];
  11844. let isStatic = true;
  11845. if (content.startsWith('[')) {
  11846. isStatic = false;
  11847. if (!content.endsWith(']')) {
  11848. emitError(context, 27 /* X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END */);
  11849. content = content.slice(1);
  11850. }
  11851. else {
  11852. content = content.slice(1, content.length - 1);
  11853. }
  11854. }
  11855. else if (isSlot) {
  11856. // #1241 special case for v-slot: vuetify relies extensively on slot
  11857. // names containing dots. v-slot doesn't have any modifiers and Vue 2.x
  11858. // supports such usage so we are keeping it consistent with 2.x.
  11859. content += match[3] || '';
  11860. }
  11861. arg = {
  11862. type: 4 /* SIMPLE_EXPRESSION */,
  11863. content,
  11864. isStatic,
  11865. constType: isStatic
  11866. ? 3 /* CAN_STRINGIFY */
  11867. : 0 /* NOT_CONSTANT */,
  11868. loc
  11869. };
  11870. }
  11871. if (value && value.isQuoted) {
  11872. const valueLoc = value.loc;
  11873. valueLoc.start.offset++;
  11874. valueLoc.start.column++;
  11875. valueLoc.end = advancePositionWithClone(valueLoc.start, value.content);
  11876. valueLoc.source = valueLoc.source.slice(1, -1);
  11877. }
  11878. const modifiers = match[3] ? match[3].slice(1).split('.') : [];
  11879. if (isPropShorthand)
  11880. modifiers.push('prop');
  11881. return {
  11882. type: 7 /* DIRECTIVE */,
  11883. name: dirName,
  11884. exp: value && {
  11885. type: 4 /* SIMPLE_EXPRESSION */,
  11886. content: value.content,
  11887. isStatic: false,
  11888. // Treat as non-constant by default. This can be potentially set to
  11889. // other values by `transformExpression` to make it eligible for hoisting.
  11890. constType: 0 /* NOT_CONSTANT */,
  11891. loc: value.loc
  11892. },
  11893. arg,
  11894. modifiers,
  11895. loc
  11896. };
  11897. }
  11898. // missing directive name or illegal directive name
  11899. if (!context.inVPre && startsWith(name, 'v-')) {
  11900. emitError(context, 26 /* X_MISSING_DIRECTIVE_NAME */);
  11901. }
  11902. return {
  11903. type: 6 /* ATTRIBUTE */,
  11904. name,
  11905. value: value && {
  11906. type: 2 /* TEXT */,
  11907. content: value.content,
  11908. loc: value.loc
  11909. },
  11910. loc
  11911. };
  11912. }
  11913. function parseAttributeValue(context) {
  11914. const start = getCursor(context);
  11915. let content;
  11916. const quote = context.source[0];
  11917. const isQuoted = quote === `"` || quote === `'`;
  11918. if (isQuoted) {
  11919. // Quoted value.
  11920. advanceBy(context, 1);
  11921. const endIndex = context.source.indexOf(quote);
  11922. if (endIndex === -1) {
  11923. content = parseTextData(context, context.source.length, 4 /* ATTRIBUTE_VALUE */);
  11924. }
  11925. else {
  11926. content = parseTextData(context, endIndex, 4 /* ATTRIBUTE_VALUE */);
  11927. advanceBy(context, 1);
  11928. }
  11929. }
  11930. else {
  11931. // Unquoted
  11932. const match = /^[^\t\r\n\f >]+/.exec(context.source);
  11933. if (!match) {
  11934. return undefined;
  11935. }
  11936. const unexpectedChars = /["'<=`]/g;
  11937. let m;
  11938. while ((m = unexpectedChars.exec(match[0]))) {
  11939. emitError(context, 18 /* UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE */, m.index);
  11940. }
  11941. content = parseTextData(context, match[0].length, 4 /* ATTRIBUTE_VALUE */);
  11942. }
  11943. return { content, isQuoted, loc: getSelection(context, start) };
  11944. }
  11945. function parseInterpolation(context, mode) {
  11946. const [open, close] = context.options.delimiters;
  11947. const closeIndex = context.source.indexOf(close, open.length);
  11948. if (closeIndex === -1) {
  11949. emitError(context, 25 /* X_MISSING_INTERPOLATION_END */);
  11950. return undefined;
  11951. }
  11952. const start = getCursor(context);
  11953. advanceBy(context, open.length);
  11954. const innerStart = getCursor(context);
  11955. const innerEnd = getCursor(context);
  11956. const rawContentLength = closeIndex - open.length;
  11957. const rawContent = context.source.slice(0, rawContentLength);
  11958. const preTrimContent = parseTextData(context, rawContentLength, mode);
  11959. const content = preTrimContent.trim();
  11960. const startOffset = preTrimContent.indexOf(content);
  11961. if (startOffset > 0) {
  11962. advancePositionWithMutation(innerStart, rawContent, startOffset);
  11963. }
  11964. const endOffset = rawContentLength - (preTrimContent.length - content.length - startOffset);
  11965. advancePositionWithMutation(innerEnd, rawContent, endOffset);
  11966. advanceBy(context, close.length);
  11967. return {
  11968. type: 5 /* INTERPOLATION */,
  11969. content: {
  11970. type: 4 /* SIMPLE_EXPRESSION */,
  11971. isStatic: false,
  11972. // Set `isConstant` to false by default and will decide in transformExpression
  11973. constType: 0 /* NOT_CONSTANT */,
  11974. content,
  11975. loc: getSelection(context, innerStart, innerEnd)
  11976. },
  11977. loc: getSelection(context, start)
  11978. };
  11979. }
  11980. function parseText(context, mode) {
  11981. const endTokens = mode === 3 /* CDATA */ ? [']]>'] : ['<', context.options.delimiters[0]];
  11982. let endIndex = context.source.length;
  11983. for (let i = 0; i < endTokens.length; i++) {
  11984. const index = context.source.indexOf(endTokens[i], 1);
  11985. if (index !== -1 && endIndex > index) {
  11986. endIndex = index;
  11987. }
  11988. }
  11989. const start = getCursor(context);
  11990. const content = parseTextData(context, endIndex, mode);
  11991. return {
  11992. type: 2 /* TEXT */,
  11993. content,
  11994. loc: getSelection(context, start)
  11995. };
  11996. }
  11997. /**
  11998. * Get text data with a given length from the current location.
  11999. * This translates HTML entities in the text data.
  12000. */
  12001. function parseTextData(context, length, mode) {
  12002. const rawText = context.source.slice(0, length);
  12003. advanceBy(context, length);
  12004. if (mode === 2 /* RAWTEXT */ ||
  12005. mode === 3 /* CDATA */ ||
  12006. rawText.indexOf('&') === -1) {
  12007. return rawText;
  12008. }
  12009. else {
  12010. // DATA or RCDATA containing "&"". Entity decoding required.
  12011. return context.options.decodeEntities(rawText, mode === 4 /* ATTRIBUTE_VALUE */);
  12012. }
  12013. }
  12014. function getCursor(context) {
  12015. const { column, line, offset } = context;
  12016. return { column, line, offset };
  12017. }
  12018. function getSelection(context, start, end) {
  12019. end = end || getCursor(context);
  12020. return {
  12021. start,
  12022. end,
  12023. source: context.originalSource.slice(start.offset, end.offset)
  12024. };
  12025. }
  12026. function last(xs) {
  12027. return xs[xs.length - 1];
  12028. }
  12029. function startsWith(source, searchString) {
  12030. return source.startsWith(searchString);
  12031. }
  12032. function advanceBy(context, numberOfCharacters) {
  12033. const { source } = context;
  12034. advancePositionWithMutation(context, source, numberOfCharacters);
  12035. context.source = source.slice(numberOfCharacters);
  12036. }
  12037. function advanceSpaces(context) {
  12038. const match = /^[\t\r\n\f ]+/.exec(context.source);
  12039. if (match) {
  12040. advanceBy(context, match[0].length);
  12041. }
  12042. }
  12043. function getNewPosition(context, start, numberOfCharacters) {
  12044. return advancePositionWithClone(start, context.originalSource.slice(start.offset, numberOfCharacters), numberOfCharacters);
  12045. }
  12046. function emitError(context, code, offset, loc = getCursor(context)) {
  12047. if (offset) {
  12048. loc.offset += offset;
  12049. loc.column += offset;
  12050. }
  12051. context.options.onError(createCompilerError(code, {
  12052. start: loc,
  12053. end: loc,
  12054. source: ''
  12055. }));
  12056. }
  12057. function isEnd(context, mode, ancestors) {
  12058. const s = context.source;
  12059. switch (mode) {
  12060. case 0 /* DATA */:
  12061. if (startsWith(s, '</')) {
  12062. // TODO: probably bad performance
  12063. for (let i = ancestors.length - 1; i >= 0; --i) {
  12064. if (startsWithEndTagOpen(s, ancestors[i].tag)) {
  12065. return true;
  12066. }
  12067. }
  12068. }
  12069. break;
  12070. case 1 /* RCDATA */:
  12071. case 2 /* RAWTEXT */: {
  12072. const parent = last(ancestors);
  12073. if (parent && startsWithEndTagOpen(s, parent.tag)) {
  12074. return true;
  12075. }
  12076. break;
  12077. }
  12078. case 3 /* CDATA */:
  12079. if (startsWith(s, ']]>')) {
  12080. return true;
  12081. }
  12082. break;
  12083. }
  12084. return !s;
  12085. }
  12086. function startsWithEndTagOpen(source, tag) {
  12087. return (startsWith(source, '</') &&
  12088. source.slice(2, 2 + tag.length).toLowerCase() === tag.toLowerCase() &&
  12089. /[\t\r\n\f />]/.test(source[2 + tag.length] || '>'));
  12090. }
  12091. function hoistStatic(root, context) {
  12092. walk(root, context,
  12093. // Root node is unfortunately non-hoistable due to potential parent
  12094. // fallthrough attributes.
  12095. isSingleElementRoot(root, root.children[0]));
  12096. }
  12097. function isSingleElementRoot(root, child) {
  12098. const { children } = root;
  12099. return (children.length === 1 &&
  12100. child.type === 1 /* ELEMENT */ &&
  12101. !isSlotOutlet(child));
  12102. }
  12103. function walk(node, context, doNotHoistNode = false) {
  12104. const { children } = node;
  12105. const originalCount = children.length;
  12106. let hoistedCount = 0;
  12107. for (let i = 0; i < children.length; i++) {
  12108. const child = children[i];
  12109. // only plain elements & text calls are eligible for hoisting.
  12110. if (child.type === 1 /* ELEMENT */ &&
  12111. child.tagType === 0 /* ELEMENT */) {
  12112. const constantType = doNotHoistNode
  12113. ? 0 /* NOT_CONSTANT */
  12114. : getConstantType(child, context);
  12115. if (constantType > 0 /* NOT_CONSTANT */) {
  12116. if (constantType >= 2 /* CAN_HOIST */) {
  12117. child.codegenNode.patchFlag =
  12118. -1 /* HOISTED */ + (` /* HOISTED */` );
  12119. child.codegenNode = context.hoist(child.codegenNode);
  12120. hoistedCount++;
  12121. continue;
  12122. }
  12123. }
  12124. else {
  12125. // node may contain dynamic children, but its props may be eligible for
  12126. // hoisting.
  12127. const codegenNode = child.codegenNode;
  12128. if (codegenNode.type === 13 /* VNODE_CALL */) {
  12129. const flag = getPatchFlag(codegenNode);
  12130. if ((!flag ||
  12131. flag === 512 /* NEED_PATCH */ ||
  12132. flag === 1 /* TEXT */) &&
  12133. getGeneratedPropsConstantType(child, context) >=
  12134. 2 /* CAN_HOIST */) {
  12135. const props = getNodeProps(child);
  12136. if (props) {
  12137. codegenNode.props = context.hoist(props);
  12138. }
  12139. }
  12140. if (codegenNode.dynamicProps) {
  12141. codegenNode.dynamicProps = context.hoist(codegenNode.dynamicProps);
  12142. }
  12143. }
  12144. }
  12145. }
  12146. else if (child.type === 12 /* TEXT_CALL */ &&
  12147. getConstantType(child.content, context) >= 2 /* CAN_HOIST */) {
  12148. child.codegenNode = context.hoist(child.codegenNode);
  12149. hoistedCount++;
  12150. }
  12151. // walk further
  12152. if (child.type === 1 /* ELEMENT */) {
  12153. const isComponent = child.tagType === 1 /* COMPONENT */;
  12154. if (isComponent) {
  12155. context.scopes.vSlot++;
  12156. }
  12157. walk(child, context);
  12158. if (isComponent) {
  12159. context.scopes.vSlot--;
  12160. }
  12161. }
  12162. else if (child.type === 11 /* FOR */) {
  12163. // Do not hoist v-for single child because it has to be a block
  12164. walk(child, context, child.children.length === 1);
  12165. }
  12166. else if (child.type === 9 /* IF */) {
  12167. for (let i = 0; i < child.branches.length; i++) {
  12168. // Do not hoist v-if single child because it has to be a block
  12169. walk(child.branches[i], context, child.branches[i].children.length === 1);
  12170. }
  12171. }
  12172. }
  12173. if (hoistedCount && context.transformHoist) {
  12174. context.transformHoist(children, context, node);
  12175. }
  12176. // all children were hoisted - the entire children array is hoistable.
  12177. if (hoistedCount &&
  12178. hoistedCount === originalCount &&
  12179. node.type === 1 /* ELEMENT */ &&
  12180. node.tagType === 0 /* ELEMENT */ &&
  12181. node.codegenNode &&
  12182. node.codegenNode.type === 13 /* VNODE_CALL */ &&
  12183. isArray(node.codegenNode.children)) {
  12184. node.codegenNode.children = context.hoist(createArrayExpression(node.codegenNode.children));
  12185. }
  12186. }
  12187. function getConstantType(node, context) {
  12188. const { constantCache } = context;
  12189. switch (node.type) {
  12190. case 1 /* ELEMENT */:
  12191. if (node.tagType !== 0 /* ELEMENT */) {
  12192. return 0 /* NOT_CONSTANT */;
  12193. }
  12194. const cached = constantCache.get(node);
  12195. if (cached !== undefined) {
  12196. return cached;
  12197. }
  12198. const codegenNode = node.codegenNode;
  12199. if (codegenNode.type !== 13 /* VNODE_CALL */) {
  12200. return 0 /* NOT_CONSTANT */;
  12201. }
  12202. if (codegenNode.isBlock &&
  12203. node.tag !== 'svg' &&
  12204. node.tag !== 'foreignObject') {
  12205. return 0 /* NOT_CONSTANT */;
  12206. }
  12207. const flag = getPatchFlag(codegenNode);
  12208. if (!flag) {
  12209. let returnType = 3 /* CAN_STRINGIFY */;
  12210. // Element itself has no patch flag. However we still need to check:
  12211. // 1. Even for a node with no patch flag, it is possible for it to contain
  12212. // non-hoistable expressions that refers to scope variables, e.g. compiler
  12213. // injected keys or cached event handlers. Therefore we need to always
  12214. // check the codegenNode's props to be sure.
  12215. const generatedPropsType = getGeneratedPropsConstantType(node, context);
  12216. if (generatedPropsType === 0 /* NOT_CONSTANT */) {
  12217. constantCache.set(node, 0 /* NOT_CONSTANT */);
  12218. return 0 /* NOT_CONSTANT */;
  12219. }
  12220. if (generatedPropsType < returnType) {
  12221. returnType = generatedPropsType;
  12222. }
  12223. // 2. its children.
  12224. for (let i = 0; i < node.children.length; i++) {
  12225. const childType = getConstantType(node.children[i], context);
  12226. if (childType === 0 /* NOT_CONSTANT */) {
  12227. constantCache.set(node, 0 /* NOT_CONSTANT */);
  12228. return 0 /* NOT_CONSTANT */;
  12229. }
  12230. if (childType < returnType) {
  12231. returnType = childType;
  12232. }
  12233. }
  12234. // 3. if the type is not already CAN_SKIP_PATCH which is the lowest non-0
  12235. // type, check if any of the props can cause the type to be lowered
  12236. // we can skip can_patch because it's guaranteed by the absence of a
  12237. // patchFlag.
  12238. if (returnType > 1 /* CAN_SKIP_PATCH */) {
  12239. for (let i = 0; i < node.props.length; i++) {
  12240. const p = node.props[i];
  12241. if (p.type === 7 /* DIRECTIVE */ && p.name === 'bind' && p.exp) {
  12242. const expType = getConstantType(p.exp, context);
  12243. if (expType === 0 /* NOT_CONSTANT */) {
  12244. constantCache.set(node, 0 /* NOT_CONSTANT */);
  12245. return 0 /* NOT_CONSTANT */;
  12246. }
  12247. if (expType < returnType) {
  12248. returnType = expType;
  12249. }
  12250. }
  12251. }
  12252. }
  12253. // only svg/foreignObject could be block here, however if they are
  12254. // static then they don't need to be blocks since there will be no
  12255. // nested updates.
  12256. if (codegenNode.isBlock) {
  12257. context.removeHelper(OPEN_BLOCK);
  12258. context.removeHelper(getVNodeBlockHelper(context.inSSR, codegenNode.isComponent));
  12259. codegenNode.isBlock = false;
  12260. context.helper(getVNodeHelper(context.inSSR, codegenNode.isComponent));
  12261. }
  12262. constantCache.set(node, returnType);
  12263. return returnType;
  12264. }
  12265. else {
  12266. constantCache.set(node, 0 /* NOT_CONSTANT */);
  12267. return 0 /* NOT_CONSTANT */;
  12268. }
  12269. case 2 /* TEXT */:
  12270. case 3 /* COMMENT */:
  12271. return 3 /* CAN_STRINGIFY */;
  12272. case 9 /* IF */:
  12273. case 11 /* FOR */:
  12274. case 10 /* IF_BRANCH */:
  12275. return 0 /* NOT_CONSTANT */;
  12276. case 5 /* INTERPOLATION */:
  12277. case 12 /* TEXT_CALL */:
  12278. return getConstantType(node.content, context);
  12279. case 4 /* SIMPLE_EXPRESSION */:
  12280. return node.constType;
  12281. case 8 /* COMPOUND_EXPRESSION */:
  12282. let returnType = 3 /* CAN_STRINGIFY */;
  12283. for (let i = 0; i < node.children.length; i++) {
  12284. const child = node.children[i];
  12285. if (isString(child) || isSymbol(child)) {
  12286. continue;
  12287. }
  12288. const childType = getConstantType(child, context);
  12289. if (childType === 0 /* NOT_CONSTANT */) {
  12290. return 0 /* NOT_CONSTANT */;
  12291. }
  12292. else if (childType < returnType) {
  12293. returnType = childType;
  12294. }
  12295. }
  12296. return returnType;
  12297. default:
  12298. return 0 /* NOT_CONSTANT */;
  12299. }
  12300. }
  12301. const allowHoistedHelperSet = new Set([
  12302. NORMALIZE_CLASS,
  12303. NORMALIZE_STYLE,
  12304. NORMALIZE_PROPS,
  12305. GUARD_REACTIVE_PROPS
  12306. ]);
  12307. function getConstantTypeOfHelperCall(value, context) {
  12308. if (value.type === 14 /* JS_CALL_EXPRESSION */ &&
  12309. !isString(value.callee) &&
  12310. allowHoistedHelperSet.has(value.callee)) {
  12311. const arg = value.arguments[0];
  12312. if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
  12313. return getConstantType(arg, context);
  12314. }
  12315. else if (arg.type === 14 /* JS_CALL_EXPRESSION */) {
  12316. // in the case of nested helper call, e.g. `normalizeProps(guardReactiveProps(exp))`
  12317. return getConstantTypeOfHelperCall(arg, context);
  12318. }
  12319. }
  12320. return 0 /* NOT_CONSTANT */;
  12321. }
  12322. function getGeneratedPropsConstantType(node, context) {
  12323. let returnType = 3 /* CAN_STRINGIFY */;
  12324. const props = getNodeProps(node);
  12325. if (props && props.type === 15 /* JS_OBJECT_EXPRESSION */) {
  12326. const { properties } = props;
  12327. for (let i = 0; i < properties.length; i++) {
  12328. const { key, value } = properties[i];
  12329. const keyType = getConstantType(key, context);
  12330. if (keyType === 0 /* NOT_CONSTANT */) {
  12331. return keyType;
  12332. }
  12333. if (keyType < returnType) {
  12334. returnType = keyType;
  12335. }
  12336. let valueType;
  12337. if (value.type === 4 /* SIMPLE_EXPRESSION */) {
  12338. valueType = getConstantType(value, context);
  12339. }
  12340. else if (value.type === 14 /* JS_CALL_EXPRESSION */) {
  12341. // some helper calls can be hoisted,
  12342. // such as the `normalizeProps` generated by the compiler for pre-normalize class,
  12343. // in this case we need to respect the ConstantType of the helper's arguments
  12344. valueType = getConstantTypeOfHelperCall(value, context);
  12345. }
  12346. else {
  12347. valueType = 0 /* NOT_CONSTANT */;
  12348. }
  12349. if (valueType === 0 /* NOT_CONSTANT */) {
  12350. return valueType;
  12351. }
  12352. if (valueType < returnType) {
  12353. returnType = valueType;
  12354. }
  12355. }
  12356. }
  12357. return returnType;
  12358. }
  12359. function getNodeProps(node) {
  12360. const codegenNode = node.codegenNode;
  12361. if (codegenNode.type === 13 /* VNODE_CALL */) {
  12362. return codegenNode.props;
  12363. }
  12364. }
  12365. function getPatchFlag(node) {
  12366. const flag = node.patchFlag;
  12367. return flag ? parseInt(flag, 10) : undefined;
  12368. }
  12369. 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 }) {
  12370. const nameMatch = filename.replace(/\?.*$/, '').match(/([^/\\]+)\.\w+$/);
  12371. const context = {
  12372. // options
  12373. selfName: nameMatch && capitalize(camelize(nameMatch[1])),
  12374. prefixIdentifiers,
  12375. hoistStatic,
  12376. cacheHandlers,
  12377. nodeTransforms,
  12378. directiveTransforms,
  12379. transformHoist,
  12380. isBuiltInComponent,
  12381. isCustomElement,
  12382. expressionPlugins,
  12383. scopeId,
  12384. slotted,
  12385. ssr,
  12386. inSSR,
  12387. ssrCssVars,
  12388. bindingMetadata,
  12389. inline,
  12390. isTS,
  12391. onError,
  12392. onWarn,
  12393. compatConfig,
  12394. // state
  12395. root,
  12396. helpers: new Map(),
  12397. components: new Set(),
  12398. directives: new Set(),
  12399. hoists: [],
  12400. imports: [],
  12401. constantCache: new Map(),
  12402. temps: 0,
  12403. cached: 0,
  12404. identifiers: Object.create(null),
  12405. scopes: {
  12406. vFor: 0,
  12407. vSlot: 0,
  12408. vPre: 0,
  12409. vOnce: 0
  12410. },
  12411. parent: null,
  12412. currentNode: root,
  12413. childIndex: 0,
  12414. inVOnce: false,
  12415. // methods
  12416. helper(name) {
  12417. const count = context.helpers.get(name) || 0;
  12418. context.helpers.set(name, count + 1);
  12419. return name;
  12420. },
  12421. removeHelper(name) {
  12422. const count = context.helpers.get(name);
  12423. if (count) {
  12424. const currentCount = count - 1;
  12425. if (!currentCount) {
  12426. context.helpers.delete(name);
  12427. }
  12428. else {
  12429. context.helpers.set(name, currentCount);
  12430. }
  12431. }
  12432. },
  12433. helperString(name) {
  12434. return `_${helperNameMap[context.helper(name)]}`;
  12435. },
  12436. replaceNode(node) {
  12437. /* istanbul ignore if */
  12438. {
  12439. if (!context.currentNode) {
  12440. throw new Error(`Node being replaced is already removed.`);
  12441. }
  12442. if (!context.parent) {
  12443. throw new Error(`Cannot replace root node.`);
  12444. }
  12445. }
  12446. context.parent.children[context.childIndex] = context.currentNode = node;
  12447. },
  12448. removeNode(node) {
  12449. if (!context.parent) {
  12450. throw new Error(`Cannot remove root node.`);
  12451. }
  12452. const list = context.parent.children;
  12453. const removalIndex = node
  12454. ? list.indexOf(node)
  12455. : context.currentNode
  12456. ? context.childIndex
  12457. : -1;
  12458. /* istanbul ignore if */
  12459. if (removalIndex < 0) {
  12460. throw new Error(`node being removed is not a child of current parent`);
  12461. }
  12462. if (!node || node === context.currentNode) {
  12463. // current node removed
  12464. context.currentNode = null;
  12465. context.onNodeRemoved();
  12466. }
  12467. else {
  12468. // sibling node removed
  12469. if (context.childIndex > removalIndex) {
  12470. context.childIndex--;
  12471. context.onNodeRemoved();
  12472. }
  12473. }
  12474. context.parent.children.splice(removalIndex, 1);
  12475. },
  12476. onNodeRemoved: () => { },
  12477. addIdentifiers(exp) {
  12478. },
  12479. removeIdentifiers(exp) {
  12480. },
  12481. hoist(exp) {
  12482. if (isString(exp))
  12483. exp = createSimpleExpression(exp);
  12484. context.hoists.push(exp);
  12485. const identifier = createSimpleExpression(`_hoisted_${context.hoists.length}`, false, exp.loc, 2 /* CAN_HOIST */);
  12486. identifier.hoisted = exp;
  12487. return identifier;
  12488. },
  12489. cache(exp, isVNode = false) {
  12490. return createCacheExpression(context.cached++, exp, isVNode);
  12491. }
  12492. };
  12493. return context;
  12494. }
  12495. function transform(root, options) {
  12496. const context = createTransformContext(root, options);
  12497. traverseNode(root, context);
  12498. if (options.hoistStatic) {
  12499. hoistStatic(root, context);
  12500. }
  12501. if (!options.ssr) {
  12502. createRootCodegen(root, context);
  12503. }
  12504. // finalize meta information
  12505. root.helpers = [...context.helpers.keys()];
  12506. root.components = [...context.components];
  12507. root.directives = [...context.directives];
  12508. root.imports = context.imports;
  12509. root.hoists = context.hoists;
  12510. root.temps = context.temps;
  12511. root.cached = context.cached;
  12512. }
  12513. function createRootCodegen(root, context) {
  12514. const { helper } = context;
  12515. const { children } = root;
  12516. if (children.length === 1) {
  12517. const child = children[0];
  12518. // if the single child is an element, turn it into a block.
  12519. if (isSingleElementRoot(root, child) && child.codegenNode) {
  12520. // single element root is never hoisted so codegenNode will never be
  12521. // SimpleExpressionNode
  12522. const codegenNode = child.codegenNode;
  12523. if (codegenNode.type === 13 /* VNODE_CALL */) {
  12524. makeBlock(codegenNode, context);
  12525. }
  12526. root.codegenNode = codegenNode;
  12527. }
  12528. else {
  12529. // - single <slot/>, IfNode, ForNode: already blocks.
  12530. // - single text node: always patched.
  12531. // root codegen falls through via genNode()
  12532. root.codegenNode = child;
  12533. }
  12534. }
  12535. else if (children.length > 1) {
  12536. // root has multiple nodes - return a fragment block.
  12537. let patchFlag = 64 /* STABLE_FRAGMENT */;
  12538. let patchFlagText = PatchFlagNames[64 /* STABLE_FRAGMENT */];
  12539. // check if the fragment actually contains a single valid child with
  12540. // the rest being comments
  12541. if (children.filter(c => c.type !== 3 /* COMMENT */).length === 1) {
  12542. patchFlag |= 2048 /* DEV_ROOT_FRAGMENT */;
  12543. patchFlagText += `, ${PatchFlagNames[2048 /* DEV_ROOT_FRAGMENT */]}`;
  12544. }
  12545. root.codegenNode = createVNodeCall(context, helper(FRAGMENT), undefined, root.children, patchFlag + (` /* ${patchFlagText} */` ), undefined, undefined, true, undefined, false /* isComponent */);
  12546. }
  12547. else ;
  12548. }
  12549. function traverseChildren(parent, context) {
  12550. let i = 0;
  12551. const nodeRemoved = () => {
  12552. i--;
  12553. };
  12554. for (; i < parent.children.length; i++) {
  12555. const child = parent.children[i];
  12556. if (isString(child))
  12557. continue;
  12558. context.parent = parent;
  12559. context.childIndex = i;
  12560. context.onNodeRemoved = nodeRemoved;
  12561. traverseNode(child, context);
  12562. }
  12563. }
  12564. function traverseNode(node, context) {
  12565. context.currentNode = node;
  12566. // apply transform plugins
  12567. const { nodeTransforms } = context;
  12568. const exitFns = [];
  12569. for (let i = 0; i < nodeTransforms.length; i++) {
  12570. const onExit = nodeTransforms[i](node, context);
  12571. if (onExit) {
  12572. if (isArray(onExit)) {
  12573. exitFns.push(...onExit);
  12574. }
  12575. else {
  12576. exitFns.push(onExit);
  12577. }
  12578. }
  12579. if (!context.currentNode) {
  12580. // node was removed
  12581. return;
  12582. }
  12583. else {
  12584. // node may have been replaced
  12585. node = context.currentNode;
  12586. }
  12587. }
  12588. switch (node.type) {
  12589. case 3 /* COMMENT */:
  12590. if (!context.ssr) {
  12591. // inject import for the Comment symbol, which is needed for creating
  12592. // comment nodes with `createVNode`
  12593. context.helper(CREATE_COMMENT);
  12594. }
  12595. break;
  12596. case 5 /* INTERPOLATION */:
  12597. // no need to traverse, but we need to inject toString helper
  12598. if (!context.ssr) {
  12599. context.helper(TO_DISPLAY_STRING);
  12600. }
  12601. break;
  12602. // for container types, further traverse downwards
  12603. case 9 /* IF */:
  12604. for (let i = 0; i < node.branches.length; i++) {
  12605. traverseNode(node.branches[i], context);
  12606. }
  12607. break;
  12608. case 10 /* IF_BRANCH */:
  12609. case 11 /* FOR */:
  12610. case 1 /* ELEMENT */:
  12611. case 0 /* ROOT */:
  12612. traverseChildren(node, context);
  12613. break;
  12614. }
  12615. // exit transforms
  12616. context.currentNode = node;
  12617. let i = exitFns.length;
  12618. while (i--) {
  12619. exitFns[i]();
  12620. }
  12621. }
  12622. function createStructuralDirectiveTransform(name, fn) {
  12623. const matches = isString(name)
  12624. ? (n) => n === name
  12625. : (n) => name.test(n);
  12626. return (node, context) => {
  12627. if (node.type === 1 /* ELEMENT */) {
  12628. const { props } = node;
  12629. // structural directive transforms are not concerned with slots
  12630. // as they are handled separately in vSlot.ts
  12631. if (node.tagType === 3 /* TEMPLATE */ && props.some(isVSlot)) {
  12632. return;
  12633. }
  12634. const exitFns = [];
  12635. for (let i = 0; i < props.length; i++) {
  12636. const prop = props[i];
  12637. if (prop.type === 7 /* DIRECTIVE */ && matches(prop.name)) {
  12638. // structural directives are removed to avoid infinite recursion
  12639. // also we remove them *before* applying so that it can further
  12640. // traverse itself in case it moves the node around
  12641. props.splice(i, 1);
  12642. i--;
  12643. const onExit = fn(node, prop, context);
  12644. if (onExit)
  12645. exitFns.push(onExit);
  12646. }
  12647. }
  12648. return exitFns;
  12649. }
  12650. };
  12651. }
  12652. const PURE_ANNOTATION = `/*#__PURE__*/`;
  12653. 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 }) {
  12654. const context = {
  12655. mode,
  12656. prefixIdentifiers,
  12657. sourceMap,
  12658. filename,
  12659. scopeId,
  12660. optimizeImports,
  12661. runtimeGlobalName,
  12662. runtimeModuleName,
  12663. ssrRuntimeModuleName,
  12664. ssr,
  12665. isTS,
  12666. inSSR,
  12667. source: ast.loc.source,
  12668. code: ``,
  12669. column: 1,
  12670. line: 1,
  12671. offset: 0,
  12672. indentLevel: 0,
  12673. pure: false,
  12674. map: undefined,
  12675. helper(key) {
  12676. return `_${helperNameMap[key]}`;
  12677. },
  12678. push(code, node) {
  12679. context.code += code;
  12680. },
  12681. indent() {
  12682. newline(++context.indentLevel);
  12683. },
  12684. deindent(withoutNewLine = false) {
  12685. if (withoutNewLine) {
  12686. --context.indentLevel;
  12687. }
  12688. else {
  12689. newline(--context.indentLevel);
  12690. }
  12691. },
  12692. newline() {
  12693. newline(context.indentLevel);
  12694. }
  12695. };
  12696. function newline(n) {
  12697. context.push('\n' + ` `.repeat(n));
  12698. }
  12699. return context;
  12700. }
  12701. function generate(ast, options = {}) {
  12702. const context = createCodegenContext(ast, options);
  12703. if (options.onContextCreated)
  12704. options.onContextCreated(context);
  12705. const { mode, push, prefixIdentifiers, indent, deindent, newline, scopeId, ssr } = context;
  12706. const hasHelpers = ast.helpers.length > 0;
  12707. const useWithBlock = !prefixIdentifiers && mode !== 'module';
  12708. // preambles
  12709. // in setup() inline mode, the preamble is generated in a sub context
  12710. // and returned separately.
  12711. const preambleContext = context;
  12712. {
  12713. genFunctionPreamble(ast, preambleContext);
  12714. }
  12715. // enter render function
  12716. const functionName = ssr ? `ssrRender` : `render`;
  12717. const args = ssr ? ['_ctx', '_push', '_parent', '_attrs'] : ['_ctx', '_cache'];
  12718. const signature = args.join(', ');
  12719. {
  12720. push(`function ${functionName}(${signature}) {`);
  12721. }
  12722. indent();
  12723. if (useWithBlock) {
  12724. push(`with (_ctx) {`);
  12725. indent();
  12726. // function mode const declarations should be inside with block
  12727. // also they should be renamed to avoid collision with user properties
  12728. if (hasHelpers) {
  12729. push(`const { ${ast.helpers
  12730. .map(s => `${helperNameMap[s]}: _${helperNameMap[s]}`)
  12731. .join(', ')} } = _Vue`);
  12732. push(`\n`);
  12733. newline();
  12734. }
  12735. }
  12736. // generate asset resolution statements
  12737. if (ast.components.length) {
  12738. genAssets(ast.components, 'component', context);
  12739. if (ast.directives.length || ast.temps > 0) {
  12740. newline();
  12741. }
  12742. }
  12743. if (ast.directives.length) {
  12744. genAssets(ast.directives, 'directive', context);
  12745. if (ast.temps > 0) {
  12746. newline();
  12747. }
  12748. }
  12749. if (ast.temps > 0) {
  12750. push(`let `);
  12751. for (let i = 0; i < ast.temps; i++) {
  12752. push(`${i > 0 ? `, ` : ``}_temp${i}`);
  12753. }
  12754. }
  12755. if (ast.components.length || ast.directives.length || ast.temps) {
  12756. push(`\n`);
  12757. newline();
  12758. }
  12759. // generate the VNode tree expression
  12760. if (!ssr) {
  12761. push(`return `);
  12762. }
  12763. if (ast.codegenNode) {
  12764. genNode(ast.codegenNode, context);
  12765. }
  12766. else {
  12767. push(`null`);
  12768. }
  12769. if (useWithBlock) {
  12770. deindent();
  12771. push(`}`);
  12772. }
  12773. deindent();
  12774. push(`}`);
  12775. return {
  12776. ast,
  12777. code: context.code,
  12778. preamble: ``,
  12779. // SourceMapGenerator does have toJSON() method but it's not in the types
  12780. map: context.map ? context.map.toJSON() : undefined
  12781. };
  12782. }
  12783. function genFunctionPreamble(ast, context) {
  12784. const { ssr, prefixIdentifiers, push, newline, runtimeModuleName, runtimeGlobalName, ssrRuntimeModuleName } = context;
  12785. const VueBinding = runtimeGlobalName;
  12786. const aliasHelper = (s) => `${helperNameMap[s]}: _${helperNameMap[s]}`;
  12787. // Generate const declaration for helpers
  12788. // In prefix mode, we place the const declaration at top so it's done
  12789. // only once; But if we not prefixing, we place the declaration inside the
  12790. // with block so it doesn't incur the `in` check cost for every helper access.
  12791. if (ast.helpers.length > 0) {
  12792. {
  12793. // "with" mode.
  12794. // save Vue in a separate variable to avoid collision
  12795. push(`const _Vue = ${VueBinding}\n`);
  12796. // in "with" mode, helpers are declared inside the with block to avoid
  12797. // has check cost, but hoists are lifted out of the function - we need
  12798. // to provide the helper here.
  12799. if (ast.hoists.length) {
  12800. const staticHelpers = [
  12801. CREATE_VNODE,
  12802. CREATE_ELEMENT_VNODE,
  12803. CREATE_COMMENT,
  12804. CREATE_TEXT,
  12805. CREATE_STATIC
  12806. ]
  12807. .filter(helper => ast.helpers.includes(helper))
  12808. .map(aliasHelper)
  12809. .join(', ');
  12810. push(`const { ${staticHelpers} } = _Vue\n`);
  12811. }
  12812. }
  12813. }
  12814. genHoists(ast.hoists, context);
  12815. newline();
  12816. push(`return `);
  12817. }
  12818. function genAssets(assets, type, { helper, push, newline, isTS }) {
  12819. const resolver = helper(type === 'component'
  12820. ? RESOLVE_COMPONENT
  12821. : RESOLVE_DIRECTIVE);
  12822. for (let i = 0; i < assets.length; i++) {
  12823. let id = assets[i];
  12824. // potential component implicit self-reference inferred from SFC filename
  12825. const maybeSelfReference = id.endsWith('__self');
  12826. if (maybeSelfReference) {
  12827. id = id.slice(0, -6);
  12828. }
  12829. push(`const ${toValidAssetId(id, type)} = ${resolver}(${JSON.stringify(id)}${maybeSelfReference ? `, true` : ``})${isTS ? `!` : ``}`);
  12830. if (i < assets.length - 1) {
  12831. newline();
  12832. }
  12833. }
  12834. }
  12835. function genHoists(hoists, context) {
  12836. if (!hoists.length) {
  12837. return;
  12838. }
  12839. context.pure = true;
  12840. const { push, newline, helper, scopeId, mode } = context;
  12841. newline();
  12842. for (let i = 0; i < hoists.length; i++) {
  12843. const exp = hoists[i];
  12844. if (exp) {
  12845. push(`const _hoisted_${i + 1} = ${``}`);
  12846. genNode(exp, context);
  12847. newline();
  12848. }
  12849. }
  12850. context.pure = false;
  12851. }
  12852. function isText$1(n) {
  12853. return (isString(n) ||
  12854. n.type === 4 /* SIMPLE_EXPRESSION */ ||
  12855. n.type === 2 /* TEXT */ ||
  12856. n.type === 5 /* INTERPOLATION */ ||
  12857. n.type === 8 /* COMPOUND_EXPRESSION */);
  12858. }
  12859. function genNodeListAsArray(nodes, context) {
  12860. const multilines = nodes.length > 3 ||
  12861. (nodes.some(n => isArray(n) || !isText$1(n)));
  12862. context.push(`[`);
  12863. multilines && context.indent();
  12864. genNodeList(nodes, context, multilines);
  12865. multilines && context.deindent();
  12866. context.push(`]`);
  12867. }
  12868. function genNodeList(nodes, context, multilines = false, comma = true) {
  12869. const { push, newline } = context;
  12870. for (let i = 0; i < nodes.length; i++) {
  12871. const node = nodes[i];
  12872. if (isString(node)) {
  12873. push(node);
  12874. }
  12875. else if (isArray(node)) {
  12876. genNodeListAsArray(node, context);
  12877. }
  12878. else {
  12879. genNode(node, context);
  12880. }
  12881. if (i < nodes.length - 1) {
  12882. if (multilines) {
  12883. comma && push(',');
  12884. newline();
  12885. }
  12886. else {
  12887. comma && push(', ');
  12888. }
  12889. }
  12890. }
  12891. }
  12892. function genNode(node, context) {
  12893. if (isString(node)) {
  12894. context.push(node);
  12895. return;
  12896. }
  12897. if (isSymbol(node)) {
  12898. context.push(context.helper(node));
  12899. return;
  12900. }
  12901. switch (node.type) {
  12902. case 1 /* ELEMENT */:
  12903. case 9 /* IF */:
  12904. case 11 /* FOR */:
  12905. assert(node.codegenNode != null, `Codegen node is missing for element/if/for node. ` +
  12906. `Apply appropriate transforms first.`);
  12907. genNode(node.codegenNode, context);
  12908. break;
  12909. case 2 /* TEXT */:
  12910. genText(node, context);
  12911. break;
  12912. case 4 /* SIMPLE_EXPRESSION */:
  12913. genExpression(node, context);
  12914. break;
  12915. case 5 /* INTERPOLATION */:
  12916. genInterpolation(node, context);
  12917. break;
  12918. case 12 /* TEXT_CALL */:
  12919. genNode(node.codegenNode, context);
  12920. break;
  12921. case 8 /* COMPOUND_EXPRESSION */:
  12922. genCompoundExpression(node, context);
  12923. break;
  12924. case 3 /* COMMENT */:
  12925. genComment(node, context);
  12926. break;
  12927. case 13 /* VNODE_CALL */:
  12928. genVNodeCall(node, context);
  12929. break;
  12930. case 14 /* JS_CALL_EXPRESSION */:
  12931. genCallExpression(node, context);
  12932. break;
  12933. case 15 /* JS_OBJECT_EXPRESSION */:
  12934. genObjectExpression(node, context);
  12935. break;
  12936. case 17 /* JS_ARRAY_EXPRESSION */:
  12937. genArrayExpression(node, context);
  12938. break;
  12939. case 18 /* JS_FUNCTION_EXPRESSION */:
  12940. genFunctionExpression(node, context);
  12941. break;
  12942. case 19 /* JS_CONDITIONAL_EXPRESSION */:
  12943. genConditionalExpression(node, context);
  12944. break;
  12945. case 20 /* JS_CACHE_EXPRESSION */:
  12946. genCacheExpression(node, context);
  12947. break;
  12948. case 21 /* JS_BLOCK_STATEMENT */:
  12949. genNodeList(node.body, context, true, false);
  12950. break;
  12951. // SSR only types
  12952. case 22 /* JS_TEMPLATE_LITERAL */:
  12953. break;
  12954. case 23 /* JS_IF_STATEMENT */:
  12955. break;
  12956. case 24 /* JS_ASSIGNMENT_EXPRESSION */:
  12957. break;
  12958. case 25 /* JS_SEQUENCE_EXPRESSION */:
  12959. break;
  12960. case 26 /* JS_RETURN_STATEMENT */:
  12961. break;
  12962. /* istanbul ignore next */
  12963. case 10 /* IF_BRANCH */:
  12964. // noop
  12965. break;
  12966. default:
  12967. {
  12968. assert(false, `unhandled codegen node type: ${node.type}`);
  12969. // make sure we exhaust all possible types
  12970. const exhaustiveCheck = node;
  12971. return exhaustiveCheck;
  12972. }
  12973. }
  12974. }
  12975. function genText(node, context) {
  12976. context.push(JSON.stringify(node.content), node);
  12977. }
  12978. function genExpression(node, context) {
  12979. const { content, isStatic } = node;
  12980. context.push(isStatic ? JSON.stringify(content) : content, node);
  12981. }
  12982. function genInterpolation(node, context) {
  12983. const { push, helper, pure } = context;
  12984. if (pure)
  12985. push(PURE_ANNOTATION);
  12986. push(`${helper(TO_DISPLAY_STRING)}(`);
  12987. genNode(node.content, context);
  12988. push(`)`);
  12989. }
  12990. function genCompoundExpression(node, context) {
  12991. for (let i = 0; i < node.children.length; i++) {
  12992. const child = node.children[i];
  12993. if (isString(child)) {
  12994. context.push(child);
  12995. }
  12996. else {
  12997. genNode(child, context);
  12998. }
  12999. }
  13000. }
  13001. function genExpressionAsPropertyKey(node, context) {
  13002. const { push } = context;
  13003. if (node.type === 8 /* COMPOUND_EXPRESSION */) {
  13004. push(`[`);
  13005. genCompoundExpression(node, context);
  13006. push(`]`);
  13007. }
  13008. else if (node.isStatic) {
  13009. // only quote keys if necessary
  13010. const text = isSimpleIdentifier(node.content)
  13011. ? node.content
  13012. : JSON.stringify(node.content);
  13013. push(text, node);
  13014. }
  13015. else {
  13016. push(`[${node.content}]`, node);
  13017. }
  13018. }
  13019. function genComment(node, context) {
  13020. const { push, helper, pure } = context;
  13021. if (pure) {
  13022. push(PURE_ANNOTATION);
  13023. }
  13024. push(`${helper(CREATE_COMMENT)}(${JSON.stringify(node.content)})`, node);
  13025. }
  13026. function genVNodeCall(node, context) {
  13027. const { push, helper, pure } = context;
  13028. const { tag, props, children, patchFlag, dynamicProps, directives, isBlock, disableTracking, isComponent } = node;
  13029. if (directives) {
  13030. push(helper(WITH_DIRECTIVES) + `(`);
  13031. }
  13032. if (isBlock) {
  13033. push(`(${helper(OPEN_BLOCK)}(${disableTracking ? `true` : ``}), `);
  13034. }
  13035. if (pure) {
  13036. push(PURE_ANNOTATION);
  13037. }
  13038. const callHelper = isBlock
  13039. ? getVNodeBlockHelper(context.inSSR, isComponent)
  13040. : getVNodeHelper(context.inSSR, isComponent);
  13041. push(helper(callHelper) + `(`, node);
  13042. genNodeList(genNullableArgs([tag, props, children, patchFlag, dynamicProps]), context);
  13043. push(`)`);
  13044. if (isBlock) {
  13045. push(`)`);
  13046. }
  13047. if (directives) {
  13048. push(`, `);
  13049. genNode(directives, context);
  13050. push(`)`);
  13051. }
  13052. }
  13053. function genNullableArgs(args) {
  13054. let i = args.length;
  13055. while (i--) {
  13056. if (args[i] != null)
  13057. break;
  13058. }
  13059. return args.slice(0, i + 1).map(arg => arg || `null`);
  13060. }
  13061. // JavaScript
  13062. function genCallExpression(node, context) {
  13063. const { push, helper, pure } = context;
  13064. const callee = isString(node.callee) ? node.callee : helper(node.callee);
  13065. if (pure) {
  13066. push(PURE_ANNOTATION);
  13067. }
  13068. push(callee + `(`, node);
  13069. genNodeList(node.arguments, context);
  13070. push(`)`);
  13071. }
  13072. function genObjectExpression(node, context) {
  13073. const { push, indent, deindent, newline } = context;
  13074. const { properties } = node;
  13075. if (!properties.length) {
  13076. push(`{}`, node);
  13077. return;
  13078. }
  13079. const multilines = properties.length > 1 ||
  13080. (properties.some(p => p.value.type !== 4 /* SIMPLE_EXPRESSION */));
  13081. push(multilines ? `{` : `{ `);
  13082. multilines && indent();
  13083. for (let i = 0; i < properties.length; i++) {
  13084. const { key, value } = properties[i];
  13085. // key
  13086. genExpressionAsPropertyKey(key, context);
  13087. push(`: `);
  13088. // value
  13089. genNode(value, context);
  13090. if (i < properties.length - 1) {
  13091. // will only reach this if it's multilines
  13092. push(`,`);
  13093. newline();
  13094. }
  13095. }
  13096. multilines && deindent();
  13097. push(multilines ? `}` : ` }`);
  13098. }
  13099. function genArrayExpression(node, context) {
  13100. genNodeListAsArray(node.elements, context);
  13101. }
  13102. function genFunctionExpression(node, context) {
  13103. const { push, indent, deindent } = context;
  13104. const { params, returns, body, newline, isSlot } = node;
  13105. if (isSlot) {
  13106. // wrap slot functions with owner context
  13107. push(`_${helperNameMap[WITH_CTX]}(`);
  13108. }
  13109. push(`(`, node);
  13110. if (isArray(params)) {
  13111. genNodeList(params, context);
  13112. }
  13113. else if (params) {
  13114. genNode(params, context);
  13115. }
  13116. push(`) => `);
  13117. if (newline || body) {
  13118. push(`{`);
  13119. indent();
  13120. }
  13121. if (returns) {
  13122. if (newline) {
  13123. push(`return `);
  13124. }
  13125. if (isArray(returns)) {
  13126. genNodeListAsArray(returns, context);
  13127. }
  13128. else {
  13129. genNode(returns, context);
  13130. }
  13131. }
  13132. else if (body) {
  13133. genNode(body, context);
  13134. }
  13135. if (newline || body) {
  13136. deindent();
  13137. push(`}`);
  13138. }
  13139. if (isSlot) {
  13140. push(`)`);
  13141. }
  13142. }
  13143. function genConditionalExpression(node, context) {
  13144. const { test, consequent, alternate, newline: needNewline } = node;
  13145. const { push, indent, deindent, newline } = context;
  13146. if (test.type === 4 /* SIMPLE_EXPRESSION */) {
  13147. const needsParens = !isSimpleIdentifier(test.content);
  13148. needsParens && push(`(`);
  13149. genExpression(test, context);
  13150. needsParens && push(`)`);
  13151. }
  13152. else {
  13153. push(`(`);
  13154. genNode(test, context);
  13155. push(`)`);
  13156. }
  13157. needNewline && indent();
  13158. context.indentLevel++;
  13159. needNewline || push(` `);
  13160. push(`? `);
  13161. genNode(consequent, context);
  13162. context.indentLevel--;
  13163. needNewline && newline();
  13164. needNewline || push(` `);
  13165. push(`: `);
  13166. const isNested = alternate.type === 19 /* JS_CONDITIONAL_EXPRESSION */;
  13167. if (!isNested) {
  13168. context.indentLevel++;
  13169. }
  13170. genNode(alternate, context);
  13171. if (!isNested) {
  13172. context.indentLevel--;
  13173. }
  13174. needNewline && deindent(true /* without newline */);
  13175. }
  13176. function genCacheExpression(node, context) {
  13177. const { push, helper, indent, deindent, newline } = context;
  13178. push(`_cache[${node.index}] || (`);
  13179. if (node.isVNode) {
  13180. indent();
  13181. push(`${helper(SET_BLOCK_TRACKING)}(-1),`);
  13182. newline();
  13183. }
  13184. push(`_cache[${node.index}] = `);
  13185. genNode(node.value, context);
  13186. if (node.isVNode) {
  13187. push(`,`);
  13188. newline();
  13189. push(`${helper(SET_BLOCK_TRACKING)}(1),`);
  13190. newline();
  13191. push(`_cache[${node.index}]`);
  13192. deindent();
  13193. }
  13194. push(`)`);
  13195. }
  13196. // these keywords should not appear inside expressions, but operators like
  13197. // typeof, instanceof and in are allowed
  13198. const prohibitedKeywordRE = new RegExp('\\b' +
  13199. ('do,if,for,let,new,try,var,case,else,with,await,break,catch,class,const,' +
  13200. 'super,throw,while,yield,delete,export,import,return,switch,default,' +
  13201. 'extends,finally,continue,debugger,function,arguments,typeof,void')
  13202. .split(',')
  13203. .join('\\b|\\b') +
  13204. '\\b');
  13205. // strip strings in expressions
  13206. const stripStringRE = /'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`(?:[^`\\]|\\.)*\$\{|\}(?:[^`\\]|\\.)*`|`(?:[^`\\]|\\.)*`/g;
  13207. /**
  13208. * Validate a non-prefixed expression.
  13209. * This is only called when using the in-browser runtime compiler since it
  13210. * doesn't prefix expressions.
  13211. */
  13212. function validateBrowserExpression(node, context, asParams = false, asRawStatements = false) {
  13213. const exp = node.content;
  13214. // empty expressions are validated per-directive since some directives
  13215. // do allow empty expressions.
  13216. if (!exp.trim()) {
  13217. return;
  13218. }
  13219. try {
  13220. new Function(asRawStatements
  13221. ? ` ${exp} `
  13222. : `return ${asParams ? `(${exp}) => {}` : `(${exp})`}`);
  13223. }
  13224. catch (e) {
  13225. let message = e.message;
  13226. const keywordMatch = exp
  13227. .replace(stripStringRE, '')
  13228. .match(prohibitedKeywordRE);
  13229. if (keywordMatch) {
  13230. message = `avoid using JavaScript keyword as property name: "${keywordMatch[0]}"`;
  13231. }
  13232. context.onError(createCompilerError(44 /* X_INVALID_EXPRESSION */, node.loc, undefined, message));
  13233. }
  13234. }
  13235. const transformExpression = (node, context) => {
  13236. if (node.type === 5 /* INTERPOLATION */) {
  13237. node.content = processExpression(node.content, context);
  13238. }
  13239. else if (node.type === 1 /* ELEMENT */) {
  13240. // handle directives on element
  13241. for (let i = 0; i < node.props.length; i++) {
  13242. const dir = node.props[i];
  13243. // do not process for v-on & v-for since they are special handled
  13244. if (dir.type === 7 /* DIRECTIVE */ && dir.name !== 'for') {
  13245. const exp = dir.exp;
  13246. const arg = dir.arg;
  13247. // do not process exp if this is v-on:arg - we need special handling
  13248. // for wrapping inline statements.
  13249. if (exp &&
  13250. exp.type === 4 /* SIMPLE_EXPRESSION */ &&
  13251. !(dir.name === 'on' && arg)) {
  13252. dir.exp = processExpression(exp, context,
  13253. // slot args must be processed as function params
  13254. dir.name === 'slot');
  13255. }
  13256. if (arg && arg.type === 4 /* SIMPLE_EXPRESSION */ && !arg.isStatic) {
  13257. dir.arg = processExpression(arg, context);
  13258. }
  13259. }
  13260. }
  13261. }
  13262. };
  13263. // Important: since this function uses Node.js only dependencies, it should
  13264. // always be used with a leading !true check so that it can be
  13265. // tree-shaken from the browser build.
  13266. function processExpression(node, context,
  13267. // some expressions like v-slot props & v-for aliases should be parsed as
  13268. // function params
  13269. asParams = false,
  13270. // v-on handler values may contain multiple statements
  13271. asRawStatements = false, localVars = Object.create(context.identifiers)) {
  13272. {
  13273. {
  13274. // simple in-browser validation (same logic in 2.x)
  13275. validateBrowserExpression(node, context, asParams, asRawStatements);
  13276. }
  13277. return node;
  13278. }
  13279. }
  13280. const transformIf = createStructuralDirectiveTransform(/^(if|else|else-if)$/, (node, dir, context) => {
  13281. return processIf(node, dir, context, (ifNode, branch, isRoot) => {
  13282. // #1587: We need to dynamically increment the key based on the current
  13283. // node's sibling nodes, since chained v-if/else branches are
  13284. // rendered at the same depth
  13285. const siblings = context.parent.children;
  13286. let i = siblings.indexOf(ifNode);
  13287. let key = 0;
  13288. while (i-- >= 0) {
  13289. const sibling = siblings[i];
  13290. if (sibling && sibling.type === 9 /* IF */) {
  13291. key += sibling.branches.length;
  13292. }
  13293. }
  13294. // Exit callback. Complete the codegenNode when all children have been
  13295. // transformed.
  13296. return () => {
  13297. if (isRoot) {
  13298. ifNode.codegenNode = createCodegenNodeForBranch(branch, key, context);
  13299. }
  13300. else {
  13301. // attach this branch's codegen node to the v-if root.
  13302. const parentCondition = getParentCondition(ifNode.codegenNode);
  13303. parentCondition.alternate = createCodegenNodeForBranch(branch, key + ifNode.branches.length - 1, context);
  13304. }
  13305. };
  13306. });
  13307. });
  13308. // target-agnostic transform used for both Client and SSR
  13309. function processIf(node, dir, context, processCodegen) {
  13310. if (dir.name !== 'else' &&
  13311. (!dir.exp || !dir.exp.content.trim())) {
  13312. const loc = dir.exp ? dir.exp.loc : node.loc;
  13313. context.onError(createCompilerError(28 /* X_V_IF_NO_EXPRESSION */, dir.loc));
  13314. dir.exp = createSimpleExpression(`true`, false, loc);
  13315. }
  13316. if (dir.exp) {
  13317. validateBrowserExpression(dir.exp, context);
  13318. }
  13319. if (dir.name === 'if') {
  13320. const branch = createIfBranch(node, dir);
  13321. const ifNode = {
  13322. type: 9 /* IF */,
  13323. loc: node.loc,
  13324. branches: [branch]
  13325. };
  13326. context.replaceNode(ifNode);
  13327. if (processCodegen) {
  13328. return processCodegen(ifNode, branch, true);
  13329. }
  13330. }
  13331. else {
  13332. // locate the adjacent v-if
  13333. const siblings = context.parent.children;
  13334. const comments = [];
  13335. let i = siblings.indexOf(node);
  13336. while (i-- >= -1) {
  13337. const sibling = siblings[i];
  13338. if (sibling && sibling.type === 3 /* COMMENT */) {
  13339. context.removeNode(sibling);
  13340. comments.unshift(sibling);
  13341. continue;
  13342. }
  13343. if (sibling &&
  13344. sibling.type === 2 /* TEXT */ &&
  13345. !sibling.content.trim().length) {
  13346. context.removeNode(sibling);
  13347. continue;
  13348. }
  13349. if (sibling && sibling.type === 9 /* IF */) {
  13350. // Check if v-else was followed by v-else-if
  13351. if (dir.name === 'else-if' &&
  13352. sibling.branches[sibling.branches.length - 1].condition === undefined) {
  13353. context.onError(createCompilerError(30 /* X_V_ELSE_NO_ADJACENT_IF */, node.loc));
  13354. }
  13355. // move the node to the if node's branches
  13356. context.removeNode();
  13357. const branch = createIfBranch(node, dir);
  13358. if (comments.length &&
  13359. // #3619 ignore comments if the v-if is direct child of <transition>
  13360. !(context.parent &&
  13361. context.parent.type === 1 /* ELEMENT */ &&
  13362. isBuiltInType(context.parent.tag, 'transition'))) {
  13363. branch.children = [...comments, ...branch.children];
  13364. }
  13365. // check if user is forcing same key on different branches
  13366. {
  13367. const key = branch.userKey;
  13368. if (key) {
  13369. sibling.branches.forEach(({ userKey }) => {
  13370. if (isSameKey(userKey, key)) {
  13371. context.onError(createCompilerError(29 /* X_V_IF_SAME_KEY */, branch.userKey.loc));
  13372. }
  13373. });
  13374. }
  13375. }
  13376. sibling.branches.push(branch);
  13377. const onExit = processCodegen && processCodegen(sibling, branch, false);
  13378. // since the branch was removed, it will not be traversed.
  13379. // make sure to traverse here.
  13380. traverseNode(branch, context);
  13381. // call on exit
  13382. if (onExit)
  13383. onExit();
  13384. // make sure to reset currentNode after traversal to indicate this
  13385. // node has been removed.
  13386. context.currentNode = null;
  13387. }
  13388. else {
  13389. context.onError(createCompilerError(30 /* X_V_ELSE_NO_ADJACENT_IF */, node.loc));
  13390. }
  13391. break;
  13392. }
  13393. }
  13394. }
  13395. function createIfBranch(node, dir) {
  13396. return {
  13397. type: 10 /* IF_BRANCH */,
  13398. loc: node.loc,
  13399. condition: dir.name === 'else' ? undefined : dir.exp,
  13400. children: node.tagType === 3 /* TEMPLATE */ && !findDir(node, 'for')
  13401. ? node.children
  13402. : [node],
  13403. userKey: findProp(node, `key`)
  13404. };
  13405. }
  13406. function createCodegenNodeForBranch(branch, keyIndex, context) {
  13407. if (branch.condition) {
  13408. return createConditionalExpression(branch.condition, createChildrenCodegenNode(branch, keyIndex, context),
  13409. // make sure to pass in asBlock: true so that the comment node call
  13410. // closes the current block.
  13411. createCallExpression(context.helper(CREATE_COMMENT), [
  13412. '"v-if"' ,
  13413. 'true'
  13414. ]));
  13415. }
  13416. else {
  13417. return createChildrenCodegenNode(branch, keyIndex, context);
  13418. }
  13419. }
  13420. function createChildrenCodegenNode(branch, keyIndex, context) {
  13421. const { helper } = context;
  13422. const keyProperty = createObjectProperty(`key`, createSimpleExpression(`${keyIndex}`, false, locStub, 2 /* CAN_HOIST */));
  13423. const { children } = branch;
  13424. const firstChild = children[0];
  13425. const needFragmentWrapper = children.length !== 1 || firstChild.type !== 1 /* ELEMENT */;
  13426. if (needFragmentWrapper) {
  13427. if (children.length === 1 && firstChild.type === 11 /* FOR */) {
  13428. // optimize away nested fragments when child is a ForNode
  13429. const vnodeCall = firstChild.codegenNode;
  13430. injectProp(vnodeCall, keyProperty, context);
  13431. return vnodeCall;
  13432. }
  13433. else {
  13434. let patchFlag = 64 /* STABLE_FRAGMENT */;
  13435. let patchFlagText = PatchFlagNames[64 /* STABLE_FRAGMENT */];
  13436. // check if the fragment actually contains a single valid child with
  13437. // the rest being comments
  13438. if (children.filter(c => c.type !== 3 /* COMMENT */).length === 1) {
  13439. patchFlag |= 2048 /* DEV_ROOT_FRAGMENT */;
  13440. patchFlagText += `, ${PatchFlagNames[2048 /* DEV_ROOT_FRAGMENT */]}`;
  13441. }
  13442. return createVNodeCall(context, helper(FRAGMENT), createObjectExpression([keyProperty]), children, patchFlag + (` /* ${patchFlagText} */` ), undefined, undefined, true, false, false /* isComponent */, branch.loc);
  13443. }
  13444. }
  13445. else {
  13446. const ret = firstChild.codegenNode;
  13447. const vnodeCall = getMemoedVNodeCall(ret);
  13448. // Change createVNode to createBlock.
  13449. if (vnodeCall.type === 13 /* VNODE_CALL */) {
  13450. makeBlock(vnodeCall, context);
  13451. }
  13452. // inject branch key
  13453. injectProp(vnodeCall, keyProperty, context);
  13454. return ret;
  13455. }
  13456. }
  13457. function isSameKey(a, b) {
  13458. if (!a || a.type !== b.type) {
  13459. return false;
  13460. }
  13461. if (a.type === 6 /* ATTRIBUTE */) {
  13462. if (a.value.content !== b.value.content) {
  13463. return false;
  13464. }
  13465. }
  13466. else {
  13467. // directive
  13468. const exp = a.exp;
  13469. const branchExp = b.exp;
  13470. if (exp.type !== branchExp.type) {
  13471. return false;
  13472. }
  13473. if (exp.type !== 4 /* SIMPLE_EXPRESSION */ ||
  13474. exp.isStatic !== branchExp.isStatic ||
  13475. exp.content !== branchExp.content) {
  13476. return false;
  13477. }
  13478. }
  13479. return true;
  13480. }
  13481. function getParentCondition(node) {
  13482. while (true) {
  13483. if (node.type === 19 /* JS_CONDITIONAL_EXPRESSION */) {
  13484. if (node.alternate.type === 19 /* JS_CONDITIONAL_EXPRESSION */) {
  13485. node = node.alternate;
  13486. }
  13487. else {
  13488. return node;
  13489. }
  13490. }
  13491. else if (node.type === 20 /* JS_CACHE_EXPRESSION */) {
  13492. node = node.value;
  13493. }
  13494. }
  13495. }
  13496. const transformFor = createStructuralDirectiveTransform('for', (node, dir, context) => {
  13497. const { helper, removeHelper } = context;
  13498. return processFor(node, dir, context, forNode => {
  13499. // create the loop render function expression now, and add the
  13500. // iterator on exit after all children have been traversed
  13501. const renderExp = createCallExpression(helper(RENDER_LIST), [
  13502. forNode.source
  13503. ]);
  13504. const memo = findDir(node, 'memo');
  13505. const keyProp = findProp(node, `key`);
  13506. const keyExp = keyProp &&
  13507. (keyProp.type === 6 /* ATTRIBUTE */
  13508. ? createSimpleExpression(keyProp.value.content, true)
  13509. : keyProp.exp);
  13510. const keyProperty = keyProp ? createObjectProperty(`key`, keyExp) : null;
  13511. const isStableFragment = forNode.source.type === 4 /* SIMPLE_EXPRESSION */ &&
  13512. forNode.source.constType > 0 /* NOT_CONSTANT */;
  13513. const fragmentFlag = isStableFragment
  13514. ? 64 /* STABLE_FRAGMENT */
  13515. : keyProp
  13516. ? 128 /* KEYED_FRAGMENT */
  13517. : 256 /* UNKEYED_FRAGMENT */;
  13518. forNode.codegenNode = createVNodeCall(context, helper(FRAGMENT), undefined, renderExp, fragmentFlag +
  13519. (` /* ${PatchFlagNames[fragmentFlag]} */` ), undefined, undefined, true /* isBlock */, !isStableFragment /* disableTracking */, false /* isComponent */, node.loc);
  13520. return () => {
  13521. // finish the codegen now that all children have been traversed
  13522. let childBlock;
  13523. const isTemplate = isTemplateNode(node);
  13524. const { children } = forNode;
  13525. // check <template v-for> key placement
  13526. if (isTemplate) {
  13527. node.children.some(c => {
  13528. if (c.type === 1 /* ELEMENT */) {
  13529. const key = findProp(c, 'key');
  13530. if (key) {
  13531. context.onError(createCompilerError(33 /* X_V_FOR_TEMPLATE_KEY_PLACEMENT */, key.loc));
  13532. return true;
  13533. }
  13534. }
  13535. });
  13536. }
  13537. const needFragmentWrapper = children.length !== 1 || children[0].type !== 1 /* ELEMENT */;
  13538. const slotOutlet = isSlotOutlet(node)
  13539. ? node
  13540. : isTemplate &&
  13541. node.children.length === 1 &&
  13542. isSlotOutlet(node.children[0])
  13543. ? node.children[0] // api-extractor somehow fails to infer this
  13544. : null;
  13545. if (slotOutlet) {
  13546. // <slot v-for="..."> or <template v-for="..."><slot/></template>
  13547. childBlock = slotOutlet.codegenNode;
  13548. if (isTemplate && keyProperty) {
  13549. // <template v-for="..." :key="..."><slot/></template>
  13550. // we need to inject the key to the renderSlot() call.
  13551. // the props for renderSlot is passed as the 3rd argument.
  13552. injectProp(childBlock, keyProperty, context);
  13553. }
  13554. }
  13555. else if (needFragmentWrapper) {
  13556. // <template v-for="..."> with text or multi-elements
  13557. // should generate a fragment block for each loop
  13558. childBlock = createVNodeCall(context, helper(FRAGMENT), keyProperty ? createObjectExpression([keyProperty]) : undefined, node.children, 64 /* STABLE_FRAGMENT */ +
  13559. (` /* ${PatchFlagNames[64 /* STABLE_FRAGMENT */]} */`
  13560. ), undefined, undefined, true, undefined, false /* isComponent */);
  13561. }
  13562. else {
  13563. // Normal element v-for. Directly use the child's codegenNode
  13564. // but mark it as a block.
  13565. childBlock = children[0]
  13566. .codegenNode;
  13567. if (isTemplate && keyProperty) {
  13568. injectProp(childBlock, keyProperty, context);
  13569. }
  13570. if (childBlock.isBlock !== !isStableFragment) {
  13571. if (childBlock.isBlock) {
  13572. // switch from block to vnode
  13573. removeHelper(OPEN_BLOCK);
  13574. removeHelper(getVNodeBlockHelper(context.inSSR, childBlock.isComponent));
  13575. }
  13576. else {
  13577. // switch from vnode to block
  13578. removeHelper(getVNodeHelper(context.inSSR, childBlock.isComponent));
  13579. }
  13580. }
  13581. childBlock.isBlock = !isStableFragment;
  13582. if (childBlock.isBlock) {
  13583. helper(OPEN_BLOCK);
  13584. helper(getVNodeBlockHelper(context.inSSR, childBlock.isComponent));
  13585. }
  13586. else {
  13587. helper(getVNodeHelper(context.inSSR, childBlock.isComponent));
  13588. }
  13589. }
  13590. if (memo) {
  13591. const loop = createFunctionExpression(createForLoopParams(forNode.parseResult, [
  13592. createSimpleExpression(`_cached`)
  13593. ]));
  13594. loop.body = createBlockStatement([
  13595. createCompoundExpression([`const _memo = (`, memo.exp, `)`]),
  13596. createCompoundExpression([
  13597. `if (_cached`,
  13598. ...(keyExp ? [` && _cached.key === `, keyExp] : []),
  13599. ` && ${context.helperString(IS_MEMO_SAME)}(_cached, _memo)) return _cached`
  13600. ]),
  13601. createCompoundExpression([`const _item = `, childBlock]),
  13602. createSimpleExpression(`_item.memo = _memo`),
  13603. createSimpleExpression(`return _item`)
  13604. ]);
  13605. renderExp.arguments.push(loop, createSimpleExpression(`_cache`), createSimpleExpression(String(context.cached++)));
  13606. }
  13607. else {
  13608. renderExp.arguments.push(createFunctionExpression(createForLoopParams(forNode.parseResult), childBlock, true /* force newline */));
  13609. }
  13610. };
  13611. });
  13612. });
  13613. // target-agnostic transform used for both Client and SSR
  13614. function processFor(node, dir, context, processCodegen) {
  13615. if (!dir.exp) {
  13616. context.onError(createCompilerError(31 /* X_V_FOR_NO_EXPRESSION */, dir.loc));
  13617. return;
  13618. }
  13619. const parseResult = parseForExpression(
  13620. // can only be simple expression because vFor transform is applied
  13621. // before expression transform.
  13622. dir.exp, context);
  13623. if (!parseResult) {
  13624. context.onError(createCompilerError(32 /* X_V_FOR_MALFORMED_EXPRESSION */, dir.loc));
  13625. return;
  13626. }
  13627. const { addIdentifiers, removeIdentifiers, scopes } = context;
  13628. const { source, value, key, index } = parseResult;
  13629. const forNode = {
  13630. type: 11 /* FOR */,
  13631. loc: dir.loc,
  13632. source,
  13633. valueAlias: value,
  13634. keyAlias: key,
  13635. objectIndexAlias: index,
  13636. parseResult,
  13637. children: isTemplateNode(node) ? node.children : [node]
  13638. };
  13639. context.replaceNode(forNode);
  13640. // bookkeeping
  13641. scopes.vFor++;
  13642. const onExit = processCodegen && processCodegen(forNode);
  13643. return () => {
  13644. scopes.vFor--;
  13645. if (onExit)
  13646. onExit();
  13647. };
  13648. }
  13649. const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/;
  13650. // This regex doesn't cover the case if key or index aliases have destructuring,
  13651. // but those do not make sense in the first place, so this works in practice.
  13652. const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/;
  13653. const stripParensRE = /^\(|\)$/g;
  13654. function parseForExpression(input, context) {
  13655. const loc = input.loc;
  13656. const exp = input.content;
  13657. const inMatch = exp.match(forAliasRE);
  13658. if (!inMatch)
  13659. return;
  13660. const [, LHS, RHS] = inMatch;
  13661. const result = {
  13662. source: createAliasExpression(loc, RHS.trim(), exp.indexOf(RHS, LHS.length)),
  13663. value: undefined,
  13664. key: undefined,
  13665. index: undefined
  13666. };
  13667. {
  13668. validateBrowserExpression(result.source, context);
  13669. }
  13670. let valueContent = LHS.trim().replace(stripParensRE, '').trim();
  13671. const trimmedOffset = LHS.indexOf(valueContent);
  13672. const iteratorMatch = valueContent.match(forIteratorRE);
  13673. if (iteratorMatch) {
  13674. valueContent = valueContent.replace(forIteratorRE, '').trim();
  13675. const keyContent = iteratorMatch[1].trim();
  13676. let keyOffset;
  13677. if (keyContent) {
  13678. keyOffset = exp.indexOf(keyContent, trimmedOffset + valueContent.length);
  13679. result.key = createAliasExpression(loc, keyContent, keyOffset);
  13680. {
  13681. validateBrowserExpression(result.key, context, true);
  13682. }
  13683. }
  13684. if (iteratorMatch[2]) {
  13685. const indexContent = iteratorMatch[2].trim();
  13686. if (indexContent) {
  13687. result.index = createAliasExpression(loc, indexContent, exp.indexOf(indexContent, result.key
  13688. ? keyOffset + keyContent.length
  13689. : trimmedOffset + valueContent.length));
  13690. {
  13691. validateBrowserExpression(result.index, context, true);
  13692. }
  13693. }
  13694. }
  13695. }
  13696. if (valueContent) {
  13697. result.value = createAliasExpression(loc, valueContent, trimmedOffset);
  13698. {
  13699. validateBrowserExpression(result.value, context, true);
  13700. }
  13701. }
  13702. return result;
  13703. }
  13704. function createAliasExpression(range, content, offset) {
  13705. return createSimpleExpression(content, false, getInnerRange(range, offset, content.length));
  13706. }
  13707. function createForLoopParams({ value, key, index }, memoArgs = []) {
  13708. return createParamsList([value, key, index, ...memoArgs]);
  13709. }
  13710. function createParamsList(args) {
  13711. let i = args.length;
  13712. while (i--) {
  13713. if (args[i])
  13714. break;
  13715. }
  13716. return args
  13717. .slice(0, i + 1)
  13718. .map((arg, i) => arg || createSimpleExpression(`_`.repeat(i + 1), false));
  13719. }
  13720. const defaultFallback = createSimpleExpression(`undefined`, false);
  13721. // A NodeTransform that:
  13722. // 1. Tracks scope identifiers for scoped slots so that they don't get prefixed
  13723. // by transformExpression. This is only applied in non-browser builds with
  13724. // { prefixIdentifiers: true }.
  13725. // 2. Track v-slot depths so that we know a slot is inside another slot.
  13726. // Note the exit callback is executed before buildSlots() on the same node,
  13727. // so only nested slots see positive numbers.
  13728. const trackSlotScopes = (node, context) => {
  13729. if (node.type === 1 /* ELEMENT */ &&
  13730. (node.tagType === 1 /* COMPONENT */ ||
  13731. node.tagType === 3 /* TEMPLATE */)) {
  13732. // We are only checking non-empty v-slot here
  13733. // since we only care about slots that introduce scope variables.
  13734. const vSlot = findDir(node, 'slot');
  13735. if (vSlot) {
  13736. vSlot.exp;
  13737. context.scopes.vSlot++;
  13738. return () => {
  13739. context.scopes.vSlot--;
  13740. };
  13741. }
  13742. }
  13743. };
  13744. const buildClientSlotFn = (props, children, loc) => createFunctionExpression(props, children, false /* newline */, true /* isSlot */, children.length ? children[0].loc : loc);
  13745. // Instead of being a DirectiveTransform, v-slot processing is called during
  13746. // transformElement to build the slots object for a component.
  13747. function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
  13748. context.helper(WITH_CTX);
  13749. const { children, loc } = node;
  13750. const slotsProperties = [];
  13751. const dynamicSlots = [];
  13752. // If the slot is inside a v-for or another v-slot, force it to be dynamic
  13753. // since it likely uses a scope variable.
  13754. let hasDynamicSlots = context.scopes.vSlot > 0 || context.scopes.vFor > 0;
  13755. // 1. Check for slot with slotProps on component itself.
  13756. // <Comp v-slot="{ prop }"/>
  13757. const onComponentSlot = findDir(node, 'slot', true);
  13758. if (onComponentSlot) {
  13759. const { arg, exp } = onComponentSlot;
  13760. if (arg && !isStaticExp(arg)) {
  13761. hasDynamicSlots = true;
  13762. }
  13763. slotsProperties.push(createObjectProperty(arg || createSimpleExpression('default', true), buildSlotFn(exp, children, loc)));
  13764. }
  13765. // 2. Iterate through children and check for template slots
  13766. // <template v-slot:foo="{ prop }">
  13767. let hasTemplateSlots = false;
  13768. let hasNamedDefaultSlot = false;
  13769. const implicitDefaultChildren = [];
  13770. const seenSlotNames = new Set();
  13771. for (let i = 0; i < children.length; i++) {
  13772. const slotElement = children[i];
  13773. let slotDir;
  13774. if (!isTemplateNode(slotElement) ||
  13775. !(slotDir = findDir(slotElement, 'slot', true))) {
  13776. // not a <template v-slot>, skip.
  13777. if (slotElement.type !== 3 /* COMMENT */) {
  13778. implicitDefaultChildren.push(slotElement);
  13779. }
  13780. continue;
  13781. }
  13782. if (onComponentSlot) {
  13783. // already has on-component slot - this is incorrect usage.
  13784. context.onError(createCompilerError(37 /* X_V_SLOT_MIXED_SLOT_USAGE */, slotDir.loc));
  13785. break;
  13786. }
  13787. hasTemplateSlots = true;
  13788. const { children: slotChildren, loc: slotLoc } = slotElement;
  13789. const { arg: slotName = createSimpleExpression(`default`, true), exp: slotProps, loc: dirLoc } = slotDir;
  13790. // check if name is dynamic.
  13791. let staticSlotName;
  13792. if (isStaticExp(slotName)) {
  13793. staticSlotName = slotName ? slotName.content : `default`;
  13794. }
  13795. else {
  13796. hasDynamicSlots = true;
  13797. }
  13798. const slotFunction = buildSlotFn(slotProps, slotChildren, slotLoc);
  13799. // check if this slot is conditional (v-if/v-for)
  13800. let vIf;
  13801. let vElse;
  13802. let vFor;
  13803. if ((vIf = findDir(slotElement, 'if'))) {
  13804. hasDynamicSlots = true;
  13805. dynamicSlots.push(createConditionalExpression(vIf.exp, buildDynamicSlot(slotName, slotFunction), defaultFallback));
  13806. }
  13807. else if ((vElse = findDir(slotElement, /^else(-if)?$/, true /* allowEmpty */))) {
  13808. // find adjacent v-if
  13809. let j = i;
  13810. let prev;
  13811. while (j--) {
  13812. prev = children[j];
  13813. if (prev.type !== 3 /* COMMENT */) {
  13814. break;
  13815. }
  13816. }
  13817. if (prev && isTemplateNode(prev) && findDir(prev, 'if')) {
  13818. // remove node
  13819. children.splice(i, 1);
  13820. i--;
  13821. // attach this slot to previous conditional
  13822. let conditional = dynamicSlots[dynamicSlots.length - 1];
  13823. while (conditional.alternate.type === 19 /* JS_CONDITIONAL_EXPRESSION */) {
  13824. conditional = conditional.alternate;
  13825. }
  13826. conditional.alternate = vElse.exp
  13827. ? createConditionalExpression(vElse.exp, buildDynamicSlot(slotName, slotFunction), defaultFallback)
  13828. : buildDynamicSlot(slotName, slotFunction);
  13829. }
  13830. else {
  13831. context.onError(createCompilerError(30 /* X_V_ELSE_NO_ADJACENT_IF */, vElse.loc));
  13832. }
  13833. }
  13834. else if ((vFor = findDir(slotElement, 'for'))) {
  13835. hasDynamicSlots = true;
  13836. const parseResult = vFor.parseResult ||
  13837. parseForExpression(vFor.exp, context);
  13838. if (parseResult) {
  13839. // Render the dynamic slots as an array and add it to the createSlot()
  13840. // args. The runtime knows how to handle it appropriately.
  13841. dynamicSlots.push(createCallExpression(context.helper(RENDER_LIST), [
  13842. parseResult.source,
  13843. createFunctionExpression(createForLoopParams(parseResult), buildDynamicSlot(slotName, slotFunction), true /* force newline */)
  13844. ]));
  13845. }
  13846. else {
  13847. context.onError(createCompilerError(32 /* X_V_FOR_MALFORMED_EXPRESSION */, vFor.loc));
  13848. }
  13849. }
  13850. else {
  13851. // check duplicate static names
  13852. if (staticSlotName) {
  13853. if (seenSlotNames.has(staticSlotName)) {
  13854. context.onError(createCompilerError(38 /* X_V_SLOT_DUPLICATE_SLOT_NAMES */, dirLoc));
  13855. continue;
  13856. }
  13857. seenSlotNames.add(staticSlotName);
  13858. if (staticSlotName === 'default') {
  13859. hasNamedDefaultSlot = true;
  13860. }
  13861. }
  13862. slotsProperties.push(createObjectProperty(slotName, slotFunction));
  13863. }
  13864. }
  13865. if (!onComponentSlot) {
  13866. const buildDefaultSlotProperty = (props, children) => {
  13867. const fn = buildSlotFn(props, children, loc);
  13868. return createObjectProperty(`default`, fn);
  13869. };
  13870. if (!hasTemplateSlots) {
  13871. // implicit default slot (on component)
  13872. slotsProperties.push(buildDefaultSlotProperty(undefined, children));
  13873. }
  13874. else if (implicitDefaultChildren.length &&
  13875. // #3766
  13876. // with whitespace: 'preserve', whitespaces between slots will end up in
  13877. // implicitDefaultChildren. Ignore if all implicit children are whitespaces.
  13878. implicitDefaultChildren.some(node => isNonWhitespaceContent(node))) {
  13879. // implicit default slot (mixed with named slots)
  13880. if (hasNamedDefaultSlot) {
  13881. context.onError(createCompilerError(39 /* X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN */, implicitDefaultChildren[0].loc));
  13882. }
  13883. else {
  13884. slotsProperties.push(buildDefaultSlotProperty(undefined, implicitDefaultChildren));
  13885. }
  13886. }
  13887. }
  13888. const slotFlag = hasDynamicSlots
  13889. ? 2 /* DYNAMIC */
  13890. : hasForwardedSlots(node.children)
  13891. ? 3 /* FORWARDED */
  13892. : 1 /* STABLE */;
  13893. let slots = createObjectExpression(slotsProperties.concat(createObjectProperty(`_`,
  13894. // 2 = compiled but dynamic = can skip normalization, but must run diff
  13895. // 1 = compiled and static = can skip normalization AND diff as optimized
  13896. createSimpleExpression(slotFlag + (` /* ${slotFlagsText[slotFlag]} */` ), false))), loc);
  13897. if (dynamicSlots.length) {
  13898. slots = createCallExpression(context.helper(CREATE_SLOTS), [
  13899. slots,
  13900. createArrayExpression(dynamicSlots)
  13901. ]);
  13902. }
  13903. return {
  13904. slots,
  13905. hasDynamicSlots
  13906. };
  13907. }
  13908. function buildDynamicSlot(name, fn) {
  13909. return createObjectExpression([
  13910. createObjectProperty(`name`, name),
  13911. createObjectProperty(`fn`, fn)
  13912. ]);
  13913. }
  13914. function hasForwardedSlots(children) {
  13915. for (let i = 0; i < children.length; i++) {
  13916. const child = children[i];
  13917. switch (child.type) {
  13918. case 1 /* ELEMENT */:
  13919. if (child.tagType === 2 /* SLOT */ ||
  13920. hasForwardedSlots(child.children)) {
  13921. return true;
  13922. }
  13923. break;
  13924. case 9 /* IF */:
  13925. if (hasForwardedSlots(child.branches))
  13926. return true;
  13927. break;
  13928. case 10 /* IF_BRANCH */:
  13929. case 11 /* FOR */:
  13930. if (hasForwardedSlots(child.children))
  13931. return true;
  13932. break;
  13933. }
  13934. }
  13935. return false;
  13936. }
  13937. function isNonWhitespaceContent(node) {
  13938. if (node.type !== 2 /* TEXT */ && node.type !== 12 /* TEXT_CALL */)
  13939. return true;
  13940. return node.type === 2 /* TEXT */
  13941. ? !!node.content.trim()
  13942. : isNonWhitespaceContent(node.content);
  13943. }
  13944. // some directive transforms (e.g. v-model) may return a symbol for runtime
  13945. // import, which should be used instead of a resolveDirective call.
  13946. const directiveImportMap = new WeakMap();
  13947. // generate a JavaScript AST for this element's codegen
  13948. const transformElement = (node, context) => {
  13949. // perform the work on exit, after all child expressions have been
  13950. // processed and merged.
  13951. return function postTransformElement() {
  13952. node = context.currentNode;
  13953. if (!(node.type === 1 /* ELEMENT */ &&
  13954. (node.tagType === 0 /* ELEMENT */ ||
  13955. node.tagType === 1 /* COMPONENT */))) {
  13956. return;
  13957. }
  13958. const { tag, props } = node;
  13959. const isComponent = node.tagType === 1 /* COMPONENT */;
  13960. // The goal of the transform is to create a codegenNode implementing the
  13961. // VNodeCall interface.
  13962. let vnodeTag = isComponent
  13963. ? resolveComponentType(node, context)
  13964. : `"${tag}"`;
  13965. const isDynamicComponent = isObject(vnodeTag) && vnodeTag.callee === RESOLVE_DYNAMIC_COMPONENT;
  13966. let vnodeProps;
  13967. let vnodeChildren;
  13968. let vnodePatchFlag;
  13969. let patchFlag = 0;
  13970. let vnodeDynamicProps;
  13971. let dynamicPropNames;
  13972. let vnodeDirectives;
  13973. let shouldUseBlock =
  13974. // dynamic component may resolve to plain elements
  13975. isDynamicComponent ||
  13976. vnodeTag === TELEPORT ||
  13977. vnodeTag === SUSPENSE ||
  13978. (!isComponent &&
  13979. // <svg> and <foreignObject> must be forced into blocks so that block
  13980. // updates inside get proper isSVG flag at runtime. (#639, #643)
  13981. // This is technically web-specific, but splitting the logic out of core
  13982. // leads to too much unnecessary complexity.
  13983. (tag === 'svg' || tag === 'foreignObject'));
  13984. // props
  13985. if (props.length > 0) {
  13986. const propsBuildResult = buildProps(node, context);
  13987. vnodeProps = propsBuildResult.props;
  13988. patchFlag = propsBuildResult.patchFlag;
  13989. dynamicPropNames = propsBuildResult.dynamicPropNames;
  13990. const directives = propsBuildResult.directives;
  13991. vnodeDirectives =
  13992. directives && directives.length
  13993. ? createArrayExpression(directives.map(dir => buildDirectiveArgs(dir, context)))
  13994. : undefined;
  13995. if (propsBuildResult.shouldUseBlock) {
  13996. shouldUseBlock = true;
  13997. }
  13998. }
  13999. // children
  14000. if (node.children.length > 0) {
  14001. if (vnodeTag === KEEP_ALIVE) {
  14002. // Although a built-in component, we compile KeepAlive with raw children
  14003. // instead of slot functions so that it can be used inside Transition
  14004. // or other Transition-wrapping HOCs.
  14005. // To ensure correct updates with block optimizations, we need to:
  14006. // 1. Force keep-alive into a block. This avoids its children being
  14007. // collected by a parent block.
  14008. shouldUseBlock = true;
  14009. // 2. Force keep-alive to always be updated, since it uses raw children.
  14010. patchFlag |= 1024 /* DYNAMIC_SLOTS */;
  14011. if (node.children.length > 1) {
  14012. context.onError(createCompilerError(45 /* X_KEEP_ALIVE_INVALID_CHILDREN */, {
  14013. start: node.children[0].loc.start,
  14014. end: node.children[node.children.length - 1].loc.end,
  14015. source: ''
  14016. }));
  14017. }
  14018. }
  14019. const shouldBuildAsSlots = isComponent &&
  14020. // Teleport is not a real component and has dedicated runtime handling
  14021. vnodeTag !== TELEPORT &&
  14022. // explained above.
  14023. vnodeTag !== KEEP_ALIVE;
  14024. if (shouldBuildAsSlots) {
  14025. const { slots, hasDynamicSlots } = buildSlots(node, context);
  14026. vnodeChildren = slots;
  14027. if (hasDynamicSlots) {
  14028. patchFlag |= 1024 /* DYNAMIC_SLOTS */;
  14029. }
  14030. }
  14031. else if (node.children.length === 1 && vnodeTag !== TELEPORT) {
  14032. const child = node.children[0];
  14033. const type = child.type;
  14034. // check for dynamic text children
  14035. const hasDynamicTextChild = type === 5 /* INTERPOLATION */ ||
  14036. type === 8 /* COMPOUND_EXPRESSION */;
  14037. if (hasDynamicTextChild &&
  14038. getConstantType(child, context) === 0 /* NOT_CONSTANT */) {
  14039. patchFlag |= 1 /* TEXT */;
  14040. }
  14041. // pass directly if the only child is a text node
  14042. // (plain / interpolation / expression)
  14043. if (hasDynamicTextChild || type === 2 /* TEXT */) {
  14044. vnodeChildren = child;
  14045. }
  14046. else {
  14047. vnodeChildren = node.children;
  14048. }
  14049. }
  14050. else {
  14051. vnodeChildren = node.children;
  14052. }
  14053. }
  14054. // patchFlag & dynamicPropNames
  14055. if (patchFlag !== 0) {
  14056. {
  14057. if (patchFlag < 0) {
  14058. // special flags (negative and mutually exclusive)
  14059. vnodePatchFlag = patchFlag + ` /* ${PatchFlagNames[patchFlag]} */`;
  14060. }
  14061. else {
  14062. // bitwise flags
  14063. const flagNames = Object.keys(PatchFlagNames)
  14064. .map(Number)
  14065. .filter(n => n > 0 && patchFlag & n)
  14066. .map(n => PatchFlagNames[n])
  14067. .join(`, `);
  14068. vnodePatchFlag = patchFlag + ` /* ${flagNames} */`;
  14069. }
  14070. }
  14071. if (dynamicPropNames && dynamicPropNames.length) {
  14072. vnodeDynamicProps = stringifyDynamicPropNames(dynamicPropNames);
  14073. }
  14074. }
  14075. node.codegenNode = createVNodeCall(context, vnodeTag, vnodeProps, vnodeChildren, vnodePatchFlag, vnodeDynamicProps, vnodeDirectives, !!shouldUseBlock, false /* disableTracking */, isComponent, node.loc);
  14076. };
  14077. };
  14078. function resolveComponentType(node, context, ssr = false) {
  14079. let { tag } = node;
  14080. // 1. dynamic component
  14081. const isExplicitDynamic = isComponentTag(tag);
  14082. const isProp = findProp(node, 'is');
  14083. if (isProp) {
  14084. if (isExplicitDynamic ||
  14085. (false )) {
  14086. const exp = isProp.type === 6 /* ATTRIBUTE */
  14087. ? isProp.value && createSimpleExpression(isProp.value.content, true)
  14088. : isProp.exp;
  14089. if (exp) {
  14090. return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
  14091. exp
  14092. ]);
  14093. }
  14094. }
  14095. else if (isProp.type === 6 /* ATTRIBUTE */ &&
  14096. isProp.value.content.startsWith('vue:')) {
  14097. // <button is="vue:xxx">
  14098. // if not <component>, only is value that starts with "vue:" will be
  14099. // treated as component by the parse phase and reach here, unless it's
  14100. // compat mode where all is values are considered components
  14101. tag = isProp.value.content.slice(4);
  14102. }
  14103. }
  14104. // 1.5 v-is (TODO: Deprecate)
  14105. const isDir = !isExplicitDynamic && findDir(node, 'is');
  14106. if (isDir && isDir.exp) {
  14107. return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
  14108. isDir.exp
  14109. ]);
  14110. }
  14111. // 2. built-in components (Teleport, Transition, KeepAlive, Suspense...)
  14112. const builtIn = isCoreComponent(tag) || context.isBuiltInComponent(tag);
  14113. if (builtIn) {
  14114. // built-ins are simply fallthroughs / have special handling during ssr
  14115. // so we don't need to import their runtime equivalents
  14116. if (!ssr)
  14117. context.helper(builtIn);
  14118. return builtIn;
  14119. }
  14120. // 5. user component (resolve)
  14121. context.helper(RESOLVE_COMPONENT);
  14122. context.components.add(tag);
  14123. return toValidAssetId(tag, `component`);
  14124. }
  14125. function buildProps(node, context, props = node.props, ssr = false) {
  14126. const { tag, loc: elementLoc, children } = node;
  14127. const isComponent = node.tagType === 1 /* COMPONENT */;
  14128. let properties = [];
  14129. const mergeArgs = [];
  14130. const runtimeDirectives = [];
  14131. const hasChildren = children.length > 0;
  14132. let shouldUseBlock = false;
  14133. // patchFlag analysis
  14134. let patchFlag = 0;
  14135. let hasRef = false;
  14136. let hasClassBinding = false;
  14137. let hasStyleBinding = false;
  14138. let hasHydrationEventBinding = false;
  14139. let hasDynamicKeys = false;
  14140. let hasVnodeHook = false;
  14141. const dynamicPropNames = [];
  14142. const analyzePatchFlag = ({ key, value }) => {
  14143. if (isStaticExp(key)) {
  14144. const name = key.content;
  14145. const isEventHandler = isOn(name);
  14146. if (!isComponent &&
  14147. isEventHandler &&
  14148. // omit the flag for click handlers because hydration gives click
  14149. // dedicated fast path.
  14150. name.toLowerCase() !== 'onclick' &&
  14151. // omit v-model handlers
  14152. name !== 'onUpdate:modelValue' &&
  14153. // omit onVnodeXXX hooks
  14154. !isReservedProp(name)) {
  14155. hasHydrationEventBinding = true;
  14156. }
  14157. if (isEventHandler && isReservedProp(name)) {
  14158. hasVnodeHook = true;
  14159. }
  14160. if (value.type === 20 /* JS_CACHE_EXPRESSION */ ||
  14161. ((value.type === 4 /* SIMPLE_EXPRESSION */ ||
  14162. value.type === 8 /* COMPOUND_EXPRESSION */) &&
  14163. getConstantType(value, context) > 0)) {
  14164. // skip if the prop is a cached handler or has constant value
  14165. return;
  14166. }
  14167. if (name === 'ref') {
  14168. hasRef = true;
  14169. }
  14170. else if (name === 'class') {
  14171. hasClassBinding = true;
  14172. }
  14173. else if (name === 'style') {
  14174. hasStyleBinding = true;
  14175. }
  14176. else if (name !== 'key' && !dynamicPropNames.includes(name)) {
  14177. dynamicPropNames.push(name);
  14178. }
  14179. // treat the dynamic class and style binding of the component as dynamic props
  14180. if (isComponent &&
  14181. (name === 'class' || name === 'style') &&
  14182. !dynamicPropNames.includes(name)) {
  14183. dynamicPropNames.push(name);
  14184. }
  14185. }
  14186. else {
  14187. hasDynamicKeys = true;
  14188. }
  14189. };
  14190. for (let i = 0; i < props.length; i++) {
  14191. // static attribute
  14192. const prop = props[i];
  14193. if (prop.type === 6 /* ATTRIBUTE */) {
  14194. const { loc, name, value } = prop;
  14195. let isStatic = true;
  14196. if (name === 'ref') {
  14197. hasRef = true;
  14198. if (context.scopes.vFor > 0) {
  14199. properties.push(createObjectProperty(createSimpleExpression('ref_for', true), createSimpleExpression('true')));
  14200. }
  14201. }
  14202. // skip is on <component>, or is="vue:xxx"
  14203. if (name === 'is' &&
  14204. (isComponentTag(tag) ||
  14205. (value && value.content.startsWith('vue:')) ||
  14206. (false ))) {
  14207. continue;
  14208. }
  14209. properties.push(createObjectProperty(createSimpleExpression(name, true, getInnerRange(loc, 0, name.length)), createSimpleExpression(value ? value.content : '', isStatic, value ? value.loc : loc)));
  14210. }
  14211. else {
  14212. // directives
  14213. const { name, arg, exp, loc } = prop;
  14214. const isVBind = name === 'bind';
  14215. const isVOn = name === 'on';
  14216. // skip v-slot - it is handled by its dedicated transform.
  14217. if (name === 'slot') {
  14218. if (!isComponent) {
  14219. context.onError(createCompilerError(40 /* X_V_SLOT_MISPLACED */, loc));
  14220. }
  14221. continue;
  14222. }
  14223. // skip v-once/v-memo - they are handled by dedicated transforms.
  14224. if (name === 'once' || name === 'memo') {
  14225. continue;
  14226. }
  14227. // skip v-is and :is on <component>
  14228. if (name === 'is' ||
  14229. (isVBind &&
  14230. isStaticArgOf(arg, 'is') &&
  14231. (isComponentTag(tag) ||
  14232. (false )))) {
  14233. continue;
  14234. }
  14235. // skip v-on in SSR compilation
  14236. if (isVOn && ssr) {
  14237. continue;
  14238. }
  14239. if (
  14240. // #938: elements with dynamic keys should be forced into blocks
  14241. (isVBind && isStaticArgOf(arg, 'key')) ||
  14242. // inline before-update hooks need to force block so that it is invoked
  14243. // before children
  14244. (isVOn && hasChildren && isStaticArgOf(arg, 'vue:before-update'))) {
  14245. shouldUseBlock = true;
  14246. }
  14247. if (isVBind && isStaticArgOf(arg, 'ref') && context.scopes.vFor > 0) {
  14248. properties.push(createObjectProperty(createSimpleExpression('ref_for', true), createSimpleExpression('true')));
  14249. }
  14250. // special case for v-bind and v-on with no argument
  14251. if (!arg && (isVBind || isVOn)) {
  14252. hasDynamicKeys = true;
  14253. if (exp) {
  14254. if (properties.length) {
  14255. mergeArgs.push(createObjectExpression(dedupeProperties(properties), elementLoc));
  14256. properties = [];
  14257. }
  14258. if (isVBind) {
  14259. mergeArgs.push(exp);
  14260. }
  14261. else {
  14262. // v-on="obj" -> toHandlers(obj)
  14263. mergeArgs.push({
  14264. type: 14 /* JS_CALL_EXPRESSION */,
  14265. loc,
  14266. callee: context.helper(TO_HANDLERS),
  14267. arguments: [exp]
  14268. });
  14269. }
  14270. }
  14271. else {
  14272. context.onError(createCompilerError(isVBind
  14273. ? 34 /* X_V_BIND_NO_EXPRESSION */
  14274. : 35 /* X_V_ON_NO_EXPRESSION */, loc));
  14275. }
  14276. continue;
  14277. }
  14278. const directiveTransform = context.directiveTransforms[name];
  14279. if (directiveTransform) {
  14280. // has built-in directive transform.
  14281. const { props, needRuntime } = directiveTransform(prop, node, context);
  14282. !ssr && props.forEach(analyzePatchFlag);
  14283. properties.push(...props);
  14284. if (needRuntime) {
  14285. runtimeDirectives.push(prop);
  14286. if (isSymbol(needRuntime)) {
  14287. directiveImportMap.set(prop, needRuntime);
  14288. }
  14289. }
  14290. }
  14291. else {
  14292. // no built-in transform, this is a user custom directive.
  14293. runtimeDirectives.push(prop);
  14294. // custom dirs may use beforeUpdate so they need to force blocks
  14295. // to ensure before-update gets called before children update
  14296. if (hasChildren) {
  14297. shouldUseBlock = true;
  14298. }
  14299. }
  14300. }
  14301. }
  14302. let propsExpression = undefined;
  14303. // has v-bind="object" or v-on="object", wrap with mergeProps
  14304. if (mergeArgs.length) {
  14305. if (properties.length) {
  14306. mergeArgs.push(createObjectExpression(dedupeProperties(properties), elementLoc));
  14307. }
  14308. if (mergeArgs.length > 1) {
  14309. propsExpression = createCallExpression(context.helper(MERGE_PROPS), mergeArgs, elementLoc);
  14310. }
  14311. else {
  14312. // single v-bind with nothing else - no need for a mergeProps call
  14313. propsExpression = mergeArgs[0];
  14314. }
  14315. }
  14316. else if (properties.length) {
  14317. propsExpression = createObjectExpression(dedupeProperties(properties), elementLoc);
  14318. }
  14319. // patchFlag analysis
  14320. if (hasDynamicKeys) {
  14321. patchFlag |= 16 /* FULL_PROPS */;
  14322. }
  14323. else {
  14324. if (hasClassBinding && !isComponent) {
  14325. patchFlag |= 2 /* CLASS */;
  14326. }
  14327. if (hasStyleBinding && !isComponent) {
  14328. patchFlag |= 4 /* STYLE */;
  14329. }
  14330. if (dynamicPropNames.length) {
  14331. patchFlag |= 8 /* PROPS */;
  14332. }
  14333. if (hasHydrationEventBinding) {
  14334. patchFlag |= 32 /* HYDRATE_EVENTS */;
  14335. }
  14336. }
  14337. if (!shouldUseBlock &&
  14338. (patchFlag === 0 || patchFlag === 32 /* HYDRATE_EVENTS */) &&
  14339. (hasRef || hasVnodeHook || runtimeDirectives.length > 0)) {
  14340. patchFlag |= 512 /* NEED_PATCH */;
  14341. }
  14342. // pre-normalize props, SSR is skipped for now
  14343. if (!context.inSSR && propsExpression) {
  14344. switch (propsExpression.type) {
  14345. case 15 /* JS_OBJECT_EXPRESSION */:
  14346. // means that there is no v-bind,
  14347. // but still need to deal with dynamic key binding
  14348. let classKeyIndex = -1;
  14349. let styleKeyIndex = -1;
  14350. let hasDynamicKey = false;
  14351. for (let i = 0; i < propsExpression.properties.length; i++) {
  14352. const key = propsExpression.properties[i].key;
  14353. if (isStaticExp(key)) {
  14354. if (key.content === 'class') {
  14355. classKeyIndex = i;
  14356. }
  14357. else if (key.content === 'style') {
  14358. styleKeyIndex = i;
  14359. }
  14360. }
  14361. else if (!key.isHandlerKey) {
  14362. hasDynamicKey = true;
  14363. }
  14364. }
  14365. const classProp = propsExpression.properties[classKeyIndex];
  14366. const styleProp = propsExpression.properties[styleKeyIndex];
  14367. // no dynamic key
  14368. if (!hasDynamicKey) {
  14369. if (classProp && !isStaticExp(classProp.value)) {
  14370. classProp.value = createCallExpression(context.helper(NORMALIZE_CLASS), [classProp.value]);
  14371. }
  14372. if (styleProp &&
  14373. !isStaticExp(styleProp.value) &&
  14374. // the static style is compiled into an object,
  14375. // so use `hasStyleBinding` to ensure that it is a dynamic style binding
  14376. (hasStyleBinding ||
  14377. // v-bind:style and style both exist,
  14378. // v-bind:style with static literal object
  14379. styleProp.value.type === 17 /* JS_ARRAY_EXPRESSION */)) {
  14380. styleProp.value = createCallExpression(context.helper(NORMALIZE_STYLE), [styleProp.value]);
  14381. }
  14382. }
  14383. else {
  14384. // dynamic key binding, wrap with `normalizeProps`
  14385. propsExpression = createCallExpression(context.helper(NORMALIZE_PROPS), [propsExpression]);
  14386. }
  14387. break;
  14388. case 14 /* JS_CALL_EXPRESSION */:
  14389. // mergeProps call, do nothing
  14390. break;
  14391. default:
  14392. // single v-bind
  14393. propsExpression = createCallExpression(context.helper(NORMALIZE_PROPS), [
  14394. createCallExpression(context.helper(GUARD_REACTIVE_PROPS), [
  14395. propsExpression
  14396. ])
  14397. ]);
  14398. break;
  14399. }
  14400. }
  14401. return {
  14402. props: propsExpression,
  14403. directives: runtimeDirectives,
  14404. patchFlag,
  14405. dynamicPropNames,
  14406. shouldUseBlock
  14407. };
  14408. }
  14409. // Dedupe props in an object literal.
  14410. // Literal duplicated attributes would have been warned during the parse phase,
  14411. // however, it's possible to encounter duplicated `onXXX` handlers with different
  14412. // modifiers. We also need to merge static and dynamic class / style attributes.
  14413. // - onXXX handlers / style: merge into array
  14414. // - class: merge into single expression with concatenation
  14415. function dedupeProperties(properties) {
  14416. const knownProps = new Map();
  14417. const deduped = [];
  14418. for (let i = 0; i < properties.length; i++) {
  14419. const prop = properties[i];
  14420. // dynamic keys are always allowed
  14421. if (prop.key.type === 8 /* COMPOUND_EXPRESSION */ || !prop.key.isStatic) {
  14422. deduped.push(prop);
  14423. continue;
  14424. }
  14425. const name = prop.key.content;
  14426. const existing = knownProps.get(name);
  14427. if (existing) {
  14428. if (name === 'style' || name === 'class' || isOn(name)) {
  14429. mergeAsArray$1(existing, prop);
  14430. }
  14431. // unexpected duplicate, should have emitted error during parse
  14432. }
  14433. else {
  14434. knownProps.set(name, prop);
  14435. deduped.push(prop);
  14436. }
  14437. }
  14438. return deduped;
  14439. }
  14440. function mergeAsArray$1(existing, incoming) {
  14441. if (existing.value.type === 17 /* JS_ARRAY_EXPRESSION */) {
  14442. existing.value.elements.push(incoming.value);
  14443. }
  14444. else {
  14445. existing.value = createArrayExpression([existing.value, incoming.value], existing.loc);
  14446. }
  14447. }
  14448. function buildDirectiveArgs(dir, context) {
  14449. const dirArgs = [];
  14450. const runtime = directiveImportMap.get(dir);
  14451. if (runtime) {
  14452. // built-in directive with runtime
  14453. dirArgs.push(context.helperString(runtime));
  14454. }
  14455. else {
  14456. {
  14457. // inject statement for resolving directive
  14458. context.helper(RESOLVE_DIRECTIVE);
  14459. context.directives.add(dir.name);
  14460. dirArgs.push(toValidAssetId(dir.name, `directive`));
  14461. }
  14462. }
  14463. const { loc } = dir;
  14464. if (dir.exp)
  14465. dirArgs.push(dir.exp);
  14466. if (dir.arg) {
  14467. if (!dir.exp) {
  14468. dirArgs.push(`void 0`);
  14469. }
  14470. dirArgs.push(dir.arg);
  14471. }
  14472. if (Object.keys(dir.modifiers).length) {
  14473. if (!dir.arg) {
  14474. if (!dir.exp) {
  14475. dirArgs.push(`void 0`);
  14476. }
  14477. dirArgs.push(`void 0`);
  14478. }
  14479. const trueExpression = createSimpleExpression(`true`, false, loc);
  14480. dirArgs.push(createObjectExpression(dir.modifiers.map(modifier => createObjectProperty(modifier, trueExpression)), loc));
  14481. }
  14482. return createArrayExpression(dirArgs, dir.loc);
  14483. }
  14484. function stringifyDynamicPropNames(props) {
  14485. let propsNamesString = `[`;
  14486. for (let i = 0, l = props.length; i < l; i++) {
  14487. propsNamesString += JSON.stringify(props[i]);
  14488. if (i < l - 1)
  14489. propsNamesString += ', ';
  14490. }
  14491. return propsNamesString + `]`;
  14492. }
  14493. function isComponentTag(tag) {
  14494. return tag === 'component' || tag === 'Component';
  14495. }
  14496. const transformSlotOutlet = (node, context) => {
  14497. if (isSlotOutlet(node)) {
  14498. const { children, loc } = node;
  14499. const { slotName, slotProps } = processSlotOutlet(node, context);
  14500. const slotArgs = [
  14501. context.prefixIdentifiers ? `_ctx.$slots` : `$slots`,
  14502. slotName,
  14503. '{}',
  14504. 'undefined',
  14505. 'true'
  14506. ];
  14507. let expectedLen = 2;
  14508. if (slotProps) {
  14509. slotArgs[2] = slotProps;
  14510. expectedLen = 3;
  14511. }
  14512. if (children.length) {
  14513. slotArgs[3] = createFunctionExpression([], children, false, false, loc);
  14514. expectedLen = 4;
  14515. }
  14516. if (context.scopeId && !context.slotted) {
  14517. expectedLen = 5;
  14518. }
  14519. slotArgs.splice(expectedLen); // remove unused arguments
  14520. node.codegenNode = createCallExpression(context.helper(RENDER_SLOT), slotArgs, loc);
  14521. }
  14522. };
  14523. function processSlotOutlet(node, context) {
  14524. let slotName = `"default"`;
  14525. let slotProps = undefined;
  14526. const nonNameProps = [];
  14527. for (let i = 0; i < node.props.length; i++) {
  14528. const p = node.props[i];
  14529. if (p.type === 6 /* ATTRIBUTE */) {
  14530. if (p.value) {
  14531. if (p.name === 'name') {
  14532. slotName = JSON.stringify(p.value.content);
  14533. }
  14534. else {
  14535. p.name = camelize(p.name);
  14536. nonNameProps.push(p);
  14537. }
  14538. }
  14539. }
  14540. else {
  14541. if (p.name === 'bind' && isStaticArgOf(p.arg, 'name')) {
  14542. if (p.exp)
  14543. slotName = p.exp;
  14544. }
  14545. else {
  14546. if (p.name === 'bind' && p.arg && isStaticExp(p.arg)) {
  14547. p.arg.content = camelize(p.arg.content);
  14548. }
  14549. nonNameProps.push(p);
  14550. }
  14551. }
  14552. }
  14553. if (nonNameProps.length > 0) {
  14554. const { props, directives } = buildProps(node, context, nonNameProps);
  14555. slotProps = props;
  14556. if (directives.length) {
  14557. context.onError(createCompilerError(36 /* X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET */, directives[0].loc));
  14558. }
  14559. }
  14560. return {
  14561. slotName,
  14562. slotProps
  14563. };
  14564. }
  14565. const fnExpRE = /^\s*([\w$_]+|(async\s*)?\([^)]*?\))\s*=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/;
  14566. const transformOn = (dir, node, context, augmentor) => {
  14567. const { loc, modifiers, arg } = dir;
  14568. if (!dir.exp && !modifiers.length) {
  14569. context.onError(createCompilerError(35 /* X_V_ON_NO_EXPRESSION */, loc));
  14570. }
  14571. let eventName;
  14572. if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
  14573. if (arg.isStatic) {
  14574. let rawName = arg.content;
  14575. // TODO deprecate @vnodeXXX usage
  14576. if (rawName.startsWith('vue:')) {
  14577. rawName = `vnode-${rawName.slice(4)}`;
  14578. }
  14579. // for all event listeners, auto convert it to camelCase. See issue #2249
  14580. eventName = createSimpleExpression(toHandlerKey(camelize(rawName)), true, arg.loc);
  14581. }
  14582. else {
  14583. // #2388
  14584. eventName = createCompoundExpression([
  14585. `${context.helperString(TO_HANDLER_KEY)}(`,
  14586. arg,
  14587. `)`
  14588. ]);
  14589. }
  14590. }
  14591. else {
  14592. // already a compound expression.
  14593. eventName = arg;
  14594. eventName.children.unshift(`${context.helperString(TO_HANDLER_KEY)}(`);
  14595. eventName.children.push(`)`);
  14596. }
  14597. // handler processing
  14598. let exp = dir.exp;
  14599. if (exp && !exp.content.trim()) {
  14600. exp = undefined;
  14601. }
  14602. let shouldCache = context.cacheHandlers && !exp && !context.inVOnce;
  14603. if (exp) {
  14604. const isMemberExp = isMemberExpression(exp.content);
  14605. const isInlineStatement = !(isMemberExp || fnExpRE.test(exp.content));
  14606. const hasMultipleStatements = exp.content.includes(`;`);
  14607. {
  14608. validateBrowserExpression(exp, context, false, hasMultipleStatements);
  14609. }
  14610. if (isInlineStatement || (shouldCache && isMemberExp)) {
  14611. // wrap inline statement in a function expression
  14612. exp = createCompoundExpression([
  14613. `${isInlineStatement
  14614. ? `$event`
  14615. : `${``}(...args)`} => ${hasMultipleStatements ? `{` : `(`}`,
  14616. exp,
  14617. hasMultipleStatements ? `}` : `)`
  14618. ]);
  14619. }
  14620. }
  14621. let ret = {
  14622. props: [
  14623. createObjectProperty(eventName, exp || createSimpleExpression(`() => {}`, false, loc))
  14624. ]
  14625. };
  14626. // apply extended compiler augmentor
  14627. if (augmentor) {
  14628. ret = augmentor(ret);
  14629. }
  14630. if (shouldCache) {
  14631. // cache handlers so that it's always the same handler being passed down.
  14632. // this avoids unnecessary re-renders when users use inline handlers on
  14633. // components.
  14634. ret.props[0].value = context.cache(ret.props[0].value);
  14635. }
  14636. // mark the key as handler for props normalization check
  14637. ret.props.forEach(p => (p.key.isHandlerKey = true));
  14638. return ret;
  14639. };
  14640. // v-bind without arg is handled directly in ./transformElements.ts due to it affecting
  14641. // codegen for the entire props object. This transform here is only for v-bind
  14642. // *with* args.
  14643. const transformBind = (dir, _node, context) => {
  14644. const { exp, modifiers, loc } = dir;
  14645. const arg = dir.arg;
  14646. if (arg.type !== 4 /* SIMPLE_EXPRESSION */) {
  14647. arg.children.unshift(`(`);
  14648. arg.children.push(`) || ""`);
  14649. }
  14650. else if (!arg.isStatic) {
  14651. arg.content = `${arg.content} || ""`;
  14652. }
  14653. // .sync is replaced by v-model:arg
  14654. if (modifiers.includes('camel')) {
  14655. if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
  14656. if (arg.isStatic) {
  14657. arg.content = camelize(arg.content);
  14658. }
  14659. else {
  14660. arg.content = `${context.helperString(CAMELIZE)}(${arg.content})`;
  14661. }
  14662. }
  14663. else {
  14664. arg.children.unshift(`${context.helperString(CAMELIZE)}(`);
  14665. arg.children.push(`)`);
  14666. }
  14667. }
  14668. if (!context.inSSR) {
  14669. if (modifiers.includes('prop')) {
  14670. injectPrefix(arg, '.');
  14671. }
  14672. if (modifiers.includes('attr')) {
  14673. injectPrefix(arg, '^');
  14674. }
  14675. }
  14676. if (!exp ||
  14677. (exp.type === 4 /* SIMPLE_EXPRESSION */ && !exp.content.trim())) {
  14678. context.onError(createCompilerError(34 /* X_V_BIND_NO_EXPRESSION */, loc));
  14679. return {
  14680. props: [createObjectProperty(arg, createSimpleExpression('', true, loc))]
  14681. };
  14682. }
  14683. return {
  14684. props: [createObjectProperty(arg, exp)]
  14685. };
  14686. };
  14687. const injectPrefix = (arg, prefix) => {
  14688. if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
  14689. if (arg.isStatic) {
  14690. arg.content = prefix + arg.content;
  14691. }
  14692. else {
  14693. arg.content = `\`${prefix}\${${arg.content}}\``;
  14694. }
  14695. }
  14696. else {
  14697. arg.children.unshift(`'${prefix}' + (`);
  14698. arg.children.push(`)`);
  14699. }
  14700. };
  14701. // Merge adjacent text nodes and expressions into a single expression
  14702. // e.g. <div>abc {{ d }} {{ e }}</div> should have a single expression node as child.
  14703. const transformText = (node, context) => {
  14704. if (node.type === 0 /* ROOT */ ||
  14705. node.type === 1 /* ELEMENT */ ||
  14706. node.type === 11 /* FOR */ ||
  14707. node.type === 10 /* IF_BRANCH */) {
  14708. // perform the transform on node exit so that all expressions have already
  14709. // been processed.
  14710. return () => {
  14711. const children = node.children;
  14712. let currentContainer = undefined;
  14713. let hasText = false;
  14714. for (let i = 0; i < children.length; i++) {
  14715. const child = children[i];
  14716. if (isText(child)) {
  14717. hasText = true;
  14718. for (let j = i + 1; j < children.length; j++) {
  14719. const next = children[j];
  14720. if (isText(next)) {
  14721. if (!currentContainer) {
  14722. currentContainer = children[i] = {
  14723. type: 8 /* COMPOUND_EXPRESSION */,
  14724. loc: child.loc,
  14725. children: [child]
  14726. };
  14727. }
  14728. // merge adjacent text node into current
  14729. currentContainer.children.push(` + `, next);
  14730. children.splice(j, 1);
  14731. j--;
  14732. }
  14733. else {
  14734. currentContainer = undefined;
  14735. break;
  14736. }
  14737. }
  14738. }
  14739. }
  14740. if (!hasText ||
  14741. // if this is a plain element with a single text child, leave it
  14742. // as-is since the runtime has dedicated fast path for this by directly
  14743. // setting textContent of the element.
  14744. // for component root it's always normalized anyway.
  14745. (children.length === 1 &&
  14746. (node.type === 0 /* ROOT */ ||
  14747. (node.type === 1 /* ELEMENT */ &&
  14748. node.tagType === 0 /* ELEMENT */ &&
  14749. // #3756
  14750. // custom directives can potentially add DOM elements arbitrarily,
  14751. // we need to avoid setting textContent of the element at runtime
  14752. // to avoid accidentally overwriting the DOM elements added
  14753. // by the user through custom directives.
  14754. !node.props.find(p => p.type === 7 /* DIRECTIVE */ &&
  14755. !context.directiveTransforms[p.name]) &&
  14756. // in compat mode, <template> tags with no special directives
  14757. // will be rendered as a fragment so its children must be
  14758. // converted into vnodes.
  14759. !(false ))))) {
  14760. return;
  14761. }
  14762. // pre-convert text nodes into createTextVNode(text) calls to avoid
  14763. // runtime normalization.
  14764. for (let i = 0; i < children.length; i++) {
  14765. const child = children[i];
  14766. if (isText(child) || child.type === 8 /* COMPOUND_EXPRESSION */) {
  14767. const callArgs = [];
  14768. // createTextVNode defaults to single whitespace, so if it is a
  14769. // single space the code could be an empty call to save bytes.
  14770. if (child.type !== 2 /* TEXT */ || child.content !== ' ') {
  14771. callArgs.push(child);
  14772. }
  14773. // mark dynamic text with flag so it gets patched inside a block
  14774. if (!context.ssr &&
  14775. getConstantType(child, context) === 0 /* NOT_CONSTANT */) {
  14776. callArgs.push(1 /* TEXT */ +
  14777. (` /* ${PatchFlagNames[1 /* TEXT */]} */` ));
  14778. }
  14779. children[i] = {
  14780. type: 12 /* TEXT_CALL */,
  14781. content: child,
  14782. loc: child.loc,
  14783. codegenNode: createCallExpression(context.helper(CREATE_TEXT), callArgs)
  14784. };
  14785. }
  14786. }
  14787. };
  14788. }
  14789. };
  14790. const seen = new WeakSet();
  14791. const transformOnce = (node, context) => {
  14792. if (node.type === 1 /* ELEMENT */ && findDir(node, 'once', true)) {
  14793. if (seen.has(node) || context.inVOnce) {
  14794. return;
  14795. }
  14796. seen.add(node);
  14797. context.inVOnce = true;
  14798. context.helper(SET_BLOCK_TRACKING);
  14799. return () => {
  14800. context.inVOnce = false;
  14801. const cur = context.currentNode;
  14802. if (cur.codegenNode) {
  14803. cur.codegenNode = context.cache(cur.codegenNode, true /* isVNode */);
  14804. }
  14805. };
  14806. }
  14807. };
  14808. const transformModel = (dir, node, context) => {
  14809. const { exp, arg } = dir;
  14810. if (!exp) {
  14811. context.onError(createCompilerError(41 /* X_V_MODEL_NO_EXPRESSION */, dir.loc));
  14812. return createTransformProps();
  14813. }
  14814. const rawExp = exp.loc.source;
  14815. const expString = exp.type === 4 /* SIMPLE_EXPRESSION */ ? exp.content : rawExp;
  14816. // im SFC <script setup> inline mode, the exp may have been transformed into
  14817. // _unref(exp)
  14818. context.bindingMetadata[rawExp];
  14819. const maybeRef = !true /* SETUP_CONST */;
  14820. if (!expString.trim() ||
  14821. (!isMemberExpression(expString) && !maybeRef)) {
  14822. context.onError(createCompilerError(42 /* X_V_MODEL_MALFORMED_EXPRESSION */, exp.loc));
  14823. return createTransformProps();
  14824. }
  14825. const propName = arg ? arg : createSimpleExpression('modelValue', true);
  14826. const eventName = arg
  14827. ? isStaticExp(arg)
  14828. ? `onUpdate:${arg.content}`
  14829. : createCompoundExpression(['"onUpdate:" + ', arg])
  14830. : `onUpdate:modelValue`;
  14831. let assignmentExp;
  14832. const eventArg = context.isTS ? `($event: any)` : `$event`;
  14833. {
  14834. assignmentExp = createCompoundExpression([
  14835. `${eventArg} => ((`,
  14836. exp,
  14837. `) = $event)`
  14838. ]);
  14839. }
  14840. const props = [
  14841. // modelValue: foo
  14842. createObjectProperty(propName, dir.exp),
  14843. // "onUpdate:modelValue": $event => (foo = $event)
  14844. createObjectProperty(eventName, assignmentExp)
  14845. ];
  14846. // modelModifiers: { foo: true, "bar-baz": true }
  14847. if (dir.modifiers.length && node.tagType === 1 /* COMPONENT */) {
  14848. const modifiers = dir.modifiers
  14849. .map(m => (isSimpleIdentifier(m) ? m : JSON.stringify(m)) + `: true`)
  14850. .join(`, `);
  14851. const modifiersKey = arg
  14852. ? isStaticExp(arg)
  14853. ? `${arg.content}Modifiers`
  14854. : createCompoundExpression([arg, ' + "Modifiers"'])
  14855. : `modelModifiers`;
  14856. props.push(createObjectProperty(modifiersKey, createSimpleExpression(`{ ${modifiers} }`, false, dir.loc, 2 /* CAN_HOIST */)));
  14857. }
  14858. return createTransformProps(props);
  14859. };
  14860. function createTransformProps(props = []) {
  14861. return { props };
  14862. }
  14863. const seen$1 = new WeakSet();
  14864. const transformMemo = (node, context) => {
  14865. if (node.type === 1 /* ELEMENT */) {
  14866. const dir = findDir(node, 'memo');
  14867. if (!dir || seen$1.has(node)) {
  14868. return;
  14869. }
  14870. seen$1.add(node);
  14871. return () => {
  14872. const codegenNode = node.codegenNode ||
  14873. context.currentNode.codegenNode;
  14874. if (codegenNode && codegenNode.type === 13 /* VNODE_CALL */) {
  14875. // non-component sub tree should be turned into a block
  14876. if (node.tagType !== 1 /* COMPONENT */) {
  14877. makeBlock(codegenNode, context);
  14878. }
  14879. node.codegenNode = createCallExpression(context.helper(WITH_MEMO), [
  14880. dir.exp,
  14881. createFunctionExpression(undefined, codegenNode),
  14882. `_cache`,
  14883. String(context.cached++)
  14884. ]);
  14885. }
  14886. };
  14887. }
  14888. };
  14889. function getBaseTransformPreset(prefixIdentifiers) {
  14890. return [
  14891. [
  14892. transformOnce,
  14893. transformIf,
  14894. transformMemo,
  14895. transformFor,
  14896. ...([]),
  14897. ...([transformExpression]
  14898. ),
  14899. transformSlotOutlet,
  14900. transformElement,
  14901. trackSlotScopes,
  14902. transformText
  14903. ],
  14904. {
  14905. on: transformOn,
  14906. bind: transformBind,
  14907. model: transformModel
  14908. }
  14909. ];
  14910. }
  14911. // we name it `baseCompile` so that higher order compilers like
  14912. // @vue/compiler-dom can export `compile` while re-exporting everything else.
  14913. function baseCompile(template, options = {}) {
  14914. const onError = options.onError || defaultOnError;
  14915. const isModuleMode = options.mode === 'module';
  14916. /* istanbul ignore if */
  14917. {
  14918. if (options.prefixIdentifiers === true) {
  14919. onError(createCompilerError(46 /* X_PREFIX_ID_NOT_SUPPORTED */));
  14920. }
  14921. else if (isModuleMode) {
  14922. onError(createCompilerError(47 /* X_MODULE_MODE_NOT_SUPPORTED */));
  14923. }
  14924. }
  14925. const prefixIdentifiers = !true ;
  14926. if (options.cacheHandlers) {
  14927. onError(createCompilerError(48 /* X_CACHE_HANDLER_NOT_SUPPORTED */));
  14928. }
  14929. if (options.scopeId && !isModuleMode) {
  14930. onError(createCompilerError(49 /* X_SCOPE_ID_NOT_SUPPORTED */));
  14931. }
  14932. const ast = isString(template) ? baseParse(template, options) : template;
  14933. const [nodeTransforms, directiveTransforms] = getBaseTransformPreset();
  14934. transform(ast, extend({}, options, {
  14935. prefixIdentifiers,
  14936. nodeTransforms: [
  14937. ...nodeTransforms,
  14938. ...(options.nodeTransforms || []) // user transforms
  14939. ],
  14940. directiveTransforms: extend({}, directiveTransforms, options.directiveTransforms || {} // user transforms
  14941. )
  14942. }));
  14943. return generate(ast, extend({}, options, {
  14944. prefixIdentifiers
  14945. }));
  14946. }
  14947. const noopDirectiveTransform = () => ({ props: [] });
  14948. const V_MODEL_RADIO = Symbol(`vModelRadio` );
  14949. const V_MODEL_CHECKBOX = Symbol(`vModelCheckbox` );
  14950. const V_MODEL_TEXT = Symbol(`vModelText` );
  14951. const V_MODEL_SELECT = Symbol(`vModelSelect` );
  14952. const V_MODEL_DYNAMIC = Symbol(`vModelDynamic` );
  14953. const V_ON_WITH_MODIFIERS = Symbol(`vOnModifiersGuard` );
  14954. const V_ON_WITH_KEYS = Symbol(`vOnKeysGuard` );
  14955. const V_SHOW = Symbol(`vShow` );
  14956. const TRANSITION$1 = Symbol(`Transition` );
  14957. const TRANSITION_GROUP = Symbol(`TransitionGroup` );
  14958. registerRuntimeHelpers({
  14959. [V_MODEL_RADIO]: `vModelRadio`,
  14960. [V_MODEL_CHECKBOX]: `vModelCheckbox`,
  14961. [V_MODEL_TEXT]: `vModelText`,
  14962. [V_MODEL_SELECT]: `vModelSelect`,
  14963. [V_MODEL_DYNAMIC]: `vModelDynamic`,
  14964. [V_ON_WITH_MODIFIERS]: `withModifiers`,
  14965. [V_ON_WITH_KEYS]: `withKeys`,
  14966. [V_SHOW]: `vShow`,
  14967. [TRANSITION$1]: `Transition`,
  14968. [TRANSITION_GROUP]: `TransitionGroup`
  14969. });
  14970. /* eslint-disable no-restricted-globals */
  14971. let decoder;
  14972. function decodeHtmlBrowser(raw, asAttr = false) {
  14973. if (!decoder) {
  14974. decoder = document.createElement('div');
  14975. }
  14976. if (asAttr) {
  14977. decoder.innerHTML = `<div foo="${raw.replace(/"/g, '&quot;')}">`;
  14978. return decoder.children[0].getAttribute('foo');
  14979. }
  14980. else {
  14981. decoder.innerHTML = raw;
  14982. return decoder.textContent;
  14983. }
  14984. }
  14985. const isRawTextContainer = /*#__PURE__*/ makeMap('style,iframe,script,noscript', true);
  14986. const parserOptions = {
  14987. isVoidTag,
  14988. isNativeTag: tag => isHTMLTag(tag) || isSVGTag(tag),
  14989. isPreTag: tag => tag === 'pre',
  14990. decodeEntities: decodeHtmlBrowser ,
  14991. isBuiltInComponent: (tag) => {
  14992. if (isBuiltInType(tag, `Transition`)) {
  14993. return TRANSITION$1;
  14994. }
  14995. else if (isBuiltInType(tag, `TransitionGroup`)) {
  14996. return TRANSITION_GROUP;
  14997. }
  14998. },
  14999. // https://html.spec.whatwg.org/multipage/parsing.html#tree-construction-dispatcher
  15000. getNamespace(tag, parent) {
  15001. let ns = parent ? parent.ns : 0 /* HTML */;
  15002. if (parent && ns === 2 /* MATH_ML */) {
  15003. if (parent.tag === 'annotation-xml') {
  15004. if (tag === 'svg') {
  15005. return 1 /* SVG */;
  15006. }
  15007. if (parent.props.some(a => a.type === 6 /* ATTRIBUTE */ &&
  15008. a.name === 'encoding' &&
  15009. a.value != null &&
  15010. (a.value.content === 'text/html' ||
  15011. a.value.content === 'application/xhtml+xml'))) {
  15012. ns = 0 /* HTML */;
  15013. }
  15014. }
  15015. else if (/^m(?:[ions]|text)$/.test(parent.tag) &&
  15016. tag !== 'mglyph' &&
  15017. tag !== 'malignmark') {
  15018. ns = 0 /* HTML */;
  15019. }
  15020. }
  15021. else if (parent && ns === 1 /* SVG */) {
  15022. if (parent.tag === 'foreignObject' ||
  15023. parent.tag === 'desc' ||
  15024. parent.tag === 'title') {
  15025. ns = 0 /* HTML */;
  15026. }
  15027. }
  15028. if (ns === 0 /* HTML */) {
  15029. if (tag === 'svg') {
  15030. return 1 /* SVG */;
  15031. }
  15032. if (tag === 'math') {
  15033. return 2 /* MATH_ML */;
  15034. }
  15035. }
  15036. return ns;
  15037. },
  15038. // https://html.spec.whatwg.org/multipage/parsing.html#parsing-html-fragments
  15039. getTextMode({ tag, ns }) {
  15040. if (ns === 0 /* HTML */) {
  15041. if (tag === 'textarea' || tag === 'title') {
  15042. return 1 /* RCDATA */;
  15043. }
  15044. if (isRawTextContainer(tag)) {
  15045. return 2 /* RAWTEXT */;
  15046. }
  15047. }
  15048. return 0 /* DATA */;
  15049. }
  15050. };
  15051. // Parse inline CSS strings for static style attributes into an object.
  15052. // This is a NodeTransform since it works on the static `style` attribute and
  15053. // converts it into a dynamic equivalent:
  15054. // style="color: red" -> :style='{ "color": "red" }'
  15055. // It is then processed by `transformElement` and included in the generated
  15056. // props.
  15057. const transformStyle = node => {
  15058. if (node.type === 1 /* ELEMENT */) {
  15059. node.props.forEach((p, i) => {
  15060. if (p.type === 6 /* ATTRIBUTE */ && p.name === 'style' && p.value) {
  15061. // replace p with an expression node
  15062. node.props[i] = {
  15063. type: 7 /* DIRECTIVE */,
  15064. name: `bind`,
  15065. arg: createSimpleExpression(`style`, true, p.loc),
  15066. exp: parseInlineCSS(p.value.content, p.loc),
  15067. modifiers: [],
  15068. loc: p.loc
  15069. };
  15070. }
  15071. });
  15072. }
  15073. };
  15074. const parseInlineCSS = (cssText, loc) => {
  15075. const normalized = parseStringStyle(cssText);
  15076. return createSimpleExpression(JSON.stringify(normalized), false, loc, 3 /* CAN_STRINGIFY */);
  15077. };
  15078. function createDOMCompilerError(code, loc) {
  15079. return createCompilerError(code, loc, DOMErrorMessages );
  15080. }
  15081. const DOMErrorMessages = {
  15082. [50 /* X_V_HTML_NO_EXPRESSION */]: `v-html is missing expression.`,
  15083. [51 /* X_V_HTML_WITH_CHILDREN */]: `v-html will override element children.`,
  15084. [52 /* X_V_TEXT_NO_EXPRESSION */]: `v-text is missing expression.`,
  15085. [53 /* X_V_TEXT_WITH_CHILDREN */]: `v-text will override element children.`,
  15086. [54 /* X_V_MODEL_ON_INVALID_ELEMENT */]: `v-model can only be used on <input>, <textarea> and <select> elements.`,
  15087. [55 /* X_V_MODEL_ARG_ON_ELEMENT */]: `v-model argument is not supported on plain elements.`,
  15088. [56 /* X_V_MODEL_ON_FILE_INPUT_ELEMENT */]: `v-model cannot be used on file inputs since they are read-only. Use a v-on:change listener instead.`,
  15089. [57 /* X_V_MODEL_UNNECESSARY_VALUE */]: `Unnecessary value binding used alongside v-model. It will interfere with v-model's behavior.`,
  15090. [58 /* X_V_SHOW_NO_EXPRESSION */]: `v-show is missing expression.`,
  15091. [59 /* X_TRANSITION_INVALID_CHILDREN */]: `<Transition> expects exactly one child element or component.`,
  15092. [60 /* X_IGNORED_SIDE_EFFECT_TAG */]: `Tags with side effect (<script> and <style>) are ignored in client component templates.`
  15093. };
  15094. const transformVHtml = (dir, node, context) => {
  15095. const { exp, loc } = dir;
  15096. if (!exp) {
  15097. context.onError(createDOMCompilerError(50 /* X_V_HTML_NO_EXPRESSION */, loc));
  15098. }
  15099. if (node.children.length) {
  15100. context.onError(createDOMCompilerError(51 /* X_V_HTML_WITH_CHILDREN */, loc));
  15101. node.children.length = 0;
  15102. }
  15103. return {
  15104. props: [
  15105. createObjectProperty(createSimpleExpression(`innerHTML`, true, loc), exp || createSimpleExpression('', true))
  15106. ]
  15107. };
  15108. };
  15109. const transformVText = (dir, node, context) => {
  15110. const { exp, loc } = dir;
  15111. if (!exp) {
  15112. context.onError(createDOMCompilerError(52 /* X_V_TEXT_NO_EXPRESSION */, loc));
  15113. }
  15114. if (node.children.length) {
  15115. context.onError(createDOMCompilerError(53 /* X_V_TEXT_WITH_CHILDREN */, loc));
  15116. node.children.length = 0;
  15117. }
  15118. return {
  15119. props: [
  15120. createObjectProperty(createSimpleExpression(`textContent`, true), exp
  15121. ? createCallExpression(context.helperString(TO_DISPLAY_STRING), [exp], loc)
  15122. : createSimpleExpression('', true))
  15123. ]
  15124. };
  15125. };
  15126. const transformModel$1 = (dir, node, context) => {
  15127. const baseResult = transformModel(dir, node, context);
  15128. // base transform has errors OR component v-model (only need props)
  15129. if (!baseResult.props.length || node.tagType === 1 /* COMPONENT */) {
  15130. return baseResult;
  15131. }
  15132. if (dir.arg) {
  15133. context.onError(createDOMCompilerError(55 /* X_V_MODEL_ARG_ON_ELEMENT */, dir.arg.loc));
  15134. }
  15135. function checkDuplicatedValue() {
  15136. const value = findProp(node, 'value');
  15137. if (value) {
  15138. context.onError(createDOMCompilerError(57 /* X_V_MODEL_UNNECESSARY_VALUE */, value.loc));
  15139. }
  15140. }
  15141. const { tag } = node;
  15142. const isCustomElement = context.isCustomElement(tag);
  15143. if (tag === 'input' ||
  15144. tag === 'textarea' ||
  15145. tag === 'select' ||
  15146. isCustomElement) {
  15147. let directiveToUse = V_MODEL_TEXT;
  15148. let isInvalidType = false;
  15149. if (tag === 'input' || isCustomElement) {
  15150. const type = findProp(node, `type`);
  15151. if (type) {
  15152. if (type.type === 7 /* DIRECTIVE */) {
  15153. // :type="foo"
  15154. directiveToUse = V_MODEL_DYNAMIC;
  15155. }
  15156. else if (type.value) {
  15157. switch (type.value.content) {
  15158. case 'radio':
  15159. directiveToUse = V_MODEL_RADIO;
  15160. break;
  15161. case 'checkbox':
  15162. directiveToUse = V_MODEL_CHECKBOX;
  15163. break;
  15164. case 'file':
  15165. isInvalidType = true;
  15166. context.onError(createDOMCompilerError(56 /* X_V_MODEL_ON_FILE_INPUT_ELEMENT */, dir.loc));
  15167. break;
  15168. default:
  15169. // text type
  15170. checkDuplicatedValue();
  15171. break;
  15172. }
  15173. }
  15174. }
  15175. else if (hasDynamicKeyVBind(node)) {
  15176. // element has bindings with dynamic keys, which can possibly contain
  15177. // "type".
  15178. directiveToUse = V_MODEL_DYNAMIC;
  15179. }
  15180. else {
  15181. // text type
  15182. checkDuplicatedValue();
  15183. }
  15184. }
  15185. else if (tag === 'select') {
  15186. directiveToUse = V_MODEL_SELECT;
  15187. }
  15188. else {
  15189. // textarea
  15190. checkDuplicatedValue();
  15191. }
  15192. // inject runtime directive
  15193. // by returning the helper symbol via needRuntime
  15194. // the import will replaced a resolveDirective call.
  15195. if (!isInvalidType) {
  15196. baseResult.needRuntime = context.helper(directiveToUse);
  15197. }
  15198. }
  15199. else {
  15200. context.onError(createDOMCompilerError(54 /* X_V_MODEL_ON_INVALID_ELEMENT */, dir.loc));
  15201. }
  15202. // native vmodel doesn't need the `modelValue` props since they are also
  15203. // passed to the runtime as `binding.value`. removing it reduces code size.
  15204. baseResult.props = baseResult.props.filter(p => !(p.key.type === 4 /* SIMPLE_EXPRESSION */ &&
  15205. p.key.content === 'modelValue'));
  15206. return baseResult;
  15207. };
  15208. const isEventOptionModifier = /*#__PURE__*/ makeMap(`passive,once,capture`);
  15209. const isNonKeyModifier = /*#__PURE__*/ makeMap(
  15210. // event propagation management
  15211. `stop,prevent,self,` +
  15212. // system modifiers + exact
  15213. `ctrl,shift,alt,meta,exact,` +
  15214. // mouse
  15215. `middle`);
  15216. // left & right could be mouse or key modifiers based on event type
  15217. const maybeKeyModifier = /*#__PURE__*/ makeMap('left,right');
  15218. const isKeyboardEvent = /*#__PURE__*/ makeMap(`onkeyup,onkeydown,onkeypress`, true);
  15219. const resolveModifiers = (key, modifiers, context, loc) => {
  15220. const keyModifiers = [];
  15221. const nonKeyModifiers = [];
  15222. const eventOptionModifiers = [];
  15223. for (let i = 0; i < modifiers.length; i++) {
  15224. const modifier = modifiers[i];
  15225. if (isEventOptionModifier(modifier)) {
  15226. // eventOptionModifiers: modifiers for addEventListener() options,
  15227. // e.g. .passive & .capture
  15228. eventOptionModifiers.push(modifier);
  15229. }
  15230. else {
  15231. // runtimeModifiers: modifiers that needs runtime guards
  15232. if (maybeKeyModifier(modifier)) {
  15233. if (isStaticExp(key)) {
  15234. if (isKeyboardEvent(key.content)) {
  15235. keyModifiers.push(modifier);
  15236. }
  15237. else {
  15238. nonKeyModifiers.push(modifier);
  15239. }
  15240. }
  15241. else {
  15242. keyModifiers.push(modifier);
  15243. nonKeyModifiers.push(modifier);
  15244. }
  15245. }
  15246. else {
  15247. if (isNonKeyModifier(modifier)) {
  15248. nonKeyModifiers.push(modifier);
  15249. }
  15250. else {
  15251. keyModifiers.push(modifier);
  15252. }
  15253. }
  15254. }
  15255. }
  15256. return {
  15257. keyModifiers,
  15258. nonKeyModifiers,
  15259. eventOptionModifiers
  15260. };
  15261. };
  15262. const transformClick = (key, event) => {
  15263. const isStaticClick = isStaticExp(key) && key.content.toLowerCase() === 'onclick';
  15264. return isStaticClick
  15265. ? createSimpleExpression(event, true)
  15266. : key.type !== 4 /* SIMPLE_EXPRESSION */
  15267. ? createCompoundExpression([
  15268. `(`,
  15269. key,
  15270. `) === "onClick" ? "${event}" : (`,
  15271. key,
  15272. `)`
  15273. ])
  15274. : key;
  15275. };
  15276. const transformOn$1 = (dir, node, context) => {
  15277. return transformOn(dir, node, context, baseResult => {
  15278. const { modifiers } = dir;
  15279. if (!modifiers.length)
  15280. return baseResult;
  15281. let { key, value: handlerExp } = baseResult.props[0];
  15282. const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = resolveModifiers(key, modifiers, context, dir.loc);
  15283. // normalize click.right and click.middle since they don't actually fire
  15284. if (nonKeyModifiers.includes('right')) {
  15285. key = transformClick(key, `onContextmenu`);
  15286. }
  15287. if (nonKeyModifiers.includes('middle')) {
  15288. key = transformClick(key, `onMouseup`);
  15289. }
  15290. if (nonKeyModifiers.length) {
  15291. handlerExp = createCallExpression(context.helper(V_ON_WITH_MODIFIERS), [
  15292. handlerExp,
  15293. JSON.stringify(nonKeyModifiers)
  15294. ]);
  15295. }
  15296. if (keyModifiers.length &&
  15297. // if event name is dynamic, always wrap with keys guard
  15298. (!isStaticExp(key) || isKeyboardEvent(key.content))) {
  15299. handlerExp = createCallExpression(context.helper(V_ON_WITH_KEYS), [
  15300. handlerExp,
  15301. JSON.stringify(keyModifiers)
  15302. ]);
  15303. }
  15304. if (eventOptionModifiers.length) {
  15305. const modifierPostfix = eventOptionModifiers.map(capitalize).join('');
  15306. key = isStaticExp(key)
  15307. ? createSimpleExpression(`${key.content}${modifierPostfix}`, true)
  15308. : createCompoundExpression([`(`, key, `) + "${modifierPostfix}"`]);
  15309. }
  15310. return {
  15311. props: [createObjectProperty(key, handlerExp)]
  15312. };
  15313. });
  15314. };
  15315. const transformShow = (dir, node, context) => {
  15316. const { exp, loc } = dir;
  15317. if (!exp) {
  15318. context.onError(createDOMCompilerError(58 /* X_V_SHOW_NO_EXPRESSION */, loc));
  15319. }
  15320. return {
  15321. props: [],
  15322. needRuntime: context.helper(V_SHOW)
  15323. };
  15324. };
  15325. const warnTransitionChildren = (node, context) => {
  15326. if (node.type === 1 /* ELEMENT */ &&
  15327. node.tagType === 1 /* COMPONENT */) {
  15328. const component = context.isBuiltInComponent(node.tag);
  15329. if (component === TRANSITION$1) {
  15330. return () => {
  15331. if (node.children.length && hasMultipleChildren(node)) {
  15332. context.onError(createDOMCompilerError(59 /* X_TRANSITION_INVALID_CHILDREN */, {
  15333. start: node.children[0].loc.start,
  15334. end: node.children[node.children.length - 1].loc.end,
  15335. source: ''
  15336. }));
  15337. }
  15338. };
  15339. }
  15340. }
  15341. };
  15342. function hasMultipleChildren(node) {
  15343. // #1352 filter out potential comment nodes.
  15344. const children = (node.children = node.children.filter(c => c.type !== 3 /* COMMENT */ &&
  15345. !(c.type === 2 /* TEXT */ && !c.content.trim())));
  15346. const child = children[0];
  15347. return (children.length !== 1 ||
  15348. child.type === 11 /* FOR */ ||
  15349. (child.type === 9 /* IF */ && child.branches.some(hasMultipleChildren)));
  15350. }
  15351. const ignoreSideEffectTags = (node, context) => {
  15352. if (node.type === 1 /* ELEMENT */ &&
  15353. node.tagType === 0 /* ELEMENT */ &&
  15354. (node.tag === 'script' || node.tag === 'style')) {
  15355. context.onError(createDOMCompilerError(60 /* X_IGNORED_SIDE_EFFECT_TAG */, node.loc));
  15356. context.removeNode();
  15357. }
  15358. };
  15359. const DOMNodeTransforms = [
  15360. transformStyle,
  15361. ...([warnTransitionChildren] )
  15362. ];
  15363. const DOMDirectiveTransforms = {
  15364. cloak: noopDirectiveTransform,
  15365. html: transformVHtml,
  15366. text: transformVText,
  15367. model: transformModel$1,
  15368. on: transformOn$1,
  15369. show: transformShow
  15370. };
  15371. function compile$1(template, options = {}) {
  15372. return baseCompile(template, extend({}, parserOptions, options, {
  15373. nodeTransforms: [
  15374. // ignore <script> and <tag>
  15375. // this is not put inside DOMNodeTransforms because that list is used
  15376. // by compiler-ssr to generate vnode fallback branches
  15377. ignoreSideEffectTags,
  15378. ...DOMNodeTransforms,
  15379. ...(options.nodeTransforms || [])
  15380. ],
  15381. directiveTransforms: extend({}, DOMDirectiveTransforms, options.directiveTransforms || {}),
  15382. transformHoist: null
  15383. }));
  15384. }
  15385. // This entry is the "full-build" that includes both the runtime
  15386. {
  15387. initDev();
  15388. }
  15389. const compileCache = Object.create(null);
  15390. function compileToFunction(template, options) {
  15391. if (!isString(template)) {
  15392. if (template.nodeType) {
  15393. template = template.innerHTML;
  15394. }
  15395. else {
  15396. warn$1(`invalid template option: `, template);
  15397. return NOOP;
  15398. }
  15399. }
  15400. const key = template;
  15401. const cached = compileCache[key];
  15402. if (cached) {
  15403. return cached;
  15404. }
  15405. if (template[0] === '#') {
  15406. const el = document.querySelector(template);
  15407. if (!el) {
  15408. warn$1(`Template element not found or is empty: ${template}`);
  15409. }
  15410. // __UNSAFE__
  15411. // Reason: potential execution of JS expressions in in-DOM template.
  15412. // The user must make sure the in-DOM template is trusted. If it's rendered
  15413. // by the server, the template should not contain any user data.
  15414. template = el ? el.innerHTML : ``;
  15415. }
  15416. const { code } = compile$1(template, extend({
  15417. hoistStatic: true,
  15418. onError: onError ,
  15419. onWarn: e => onError(e, true)
  15420. }, options));
  15421. function onError(err, asWarning = false) {
  15422. const message = asWarning
  15423. ? err.message
  15424. : `Template compilation error: ${err.message}`;
  15425. const codeFrame = err.loc &&
  15426. generateCodeFrame(template, err.loc.start.offset, err.loc.end.offset);
  15427. warn$1(codeFrame ? `${message}\n${codeFrame}` : message);
  15428. }
  15429. // The wildcard import results in a huge object with every export
  15430. // with keys that cannot be mangled, and can be quite heavy size-wise.
  15431. // In the global build we know `Vue` is available globally so we can avoid
  15432. // the wildcard object.
  15433. const render = (new Function(code)() );
  15434. render._rc = true;
  15435. return (compileCache[key] = render);
  15436. }
  15437. registerRuntimeCompiler(compileToFunction);
  15438. exports.BaseTransition = BaseTransition;
  15439. exports.Comment = Comment;
  15440. exports.EffectScope = EffectScope;
  15441. exports.Fragment = Fragment;
  15442. exports.KeepAlive = KeepAlive;
  15443. exports.ReactiveEffect = ReactiveEffect;
  15444. exports.Static = Static;
  15445. exports.Suspense = Suspense;
  15446. exports.Teleport = Teleport;
  15447. exports.Text = Text;
  15448. exports.Transition = Transition;
  15449. exports.TransitionGroup = TransitionGroup;
  15450. exports.VueElement = VueElement;
  15451. exports.callWithAsyncErrorHandling = callWithAsyncErrorHandling;
  15452. exports.callWithErrorHandling = callWithErrorHandling;
  15453. exports.camelize = camelize;
  15454. exports.capitalize = capitalize;
  15455. exports.cloneVNode = cloneVNode;
  15456. exports.compatUtils = compatUtils;
  15457. exports.compile = compileToFunction;
  15458. exports.computed = computed;
  15459. exports.createApp = createApp;
  15460. exports.createBlock = createBlock;
  15461. exports.createCommentVNode = createCommentVNode;
  15462. exports.createElementBlock = createElementBlock;
  15463. exports.createElementVNode = createBaseVNode;
  15464. exports.createHydrationRenderer = createHydrationRenderer;
  15465. exports.createPropsRestProxy = createPropsRestProxy;
  15466. exports.createRenderer = createRenderer;
  15467. exports.createSSRApp = createSSRApp;
  15468. exports.createSlots = createSlots;
  15469. exports.createStaticVNode = createStaticVNode;
  15470. exports.createTextVNode = createTextVNode;
  15471. exports.createVNode = createVNode;
  15472. exports.customRef = customRef;
  15473. exports.defineAsyncComponent = defineAsyncComponent;
  15474. exports.defineComponent = defineComponent;
  15475. exports.defineCustomElement = defineCustomElement;
  15476. exports.defineEmits = defineEmits;
  15477. exports.defineExpose = defineExpose;
  15478. exports.defineProps = defineProps;
  15479. exports.defineSSRCustomElement = defineSSRCustomElement;
  15480. exports.effect = effect;
  15481. exports.effectScope = effectScope;
  15482. exports.getCurrentInstance = getCurrentInstance;
  15483. exports.getCurrentScope = getCurrentScope;
  15484. exports.getTransitionRawChildren = getTransitionRawChildren;
  15485. exports.guardReactiveProps = guardReactiveProps;
  15486. exports.h = h;
  15487. exports.handleError = handleError;
  15488. exports.hydrate = hydrate;
  15489. exports.initCustomFormatter = initCustomFormatter;
  15490. exports.initDirectivesForSSR = initDirectivesForSSR;
  15491. exports.inject = inject;
  15492. exports.isMemoSame = isMemoSame;
  15493. exports.isProxy = isProxy;
  15494. exports.isReactive = isReactive;
  15495. exports.isReadonly = isReadonly;
  15496. exports.isRef = isRef;
  15497. exports.isRuntimeOnly = isRuntimeOnly;
  15498. exports.isVNode = isVNode;
  15499. exports.markRaw = markRaw;
  15500. exports.mergeDefaults = mergeDefaults;
  15501. exports.mergeProps = mergeProps;
  15502. exports.nextTick = nextTick;
  15503. exports.normalizeClass = normalizeClass;
  15504. exports.normalizeProps = normalizeProps;
  15505. exports.normalizeStyle = normalizeStyle;
  15506. exports.onActivated = onActivated;
  15507. exports.onBeforeMount = onBeforeMount;
  15508. exports.onBeforeUnmount = onBeforeUnmount;
  15509. exports.onBeforeUpdate = onBeforeUpdate;
  15510. exports.onDeactivated = onDeactivated;
  15511. exports.onErrorCaptured = onErrorCaptured;
  15512. exports.onMounted = onMounted;
  15513. exports.onRenderTracked = onRenderTracked;
  15514. exports.onRenderTriggered = onRenderTriggered;
  15515. exports.onScopeDispose = onScopeDispose;
  15516. exports.onServerPrefetch = onServerPrefetch;
  15517. exports.onUnmounted = onUnmounted;
  15518. exports.onUpdated = onUpdated;
  15519. exports.openBlock = openBlock;
  15520. exports.popScopeId = popScopeId;
  15521. exports.provide = provide;
  15522. exports.proxyRefs = proxyRefs;
  15523. exports.pushScopeId = pushScopeId;
  15524. exports.queuePostFlushCb = queuePostFlushCb;
  15525. exports.reactive = reactive;
  15526. exports.readonly = readonly;
  15527. exports.ref = ref;
  15528. exports.registerRuntimeCompiler = registerRuntimeCompiler;
  15529. exports.render = render;
  15530. exports.renderList = renderList;
  15531. exports.renderSlot = renderSlot;
  15532. exports.resolveComponent = resolveComponent;
  15533. exports.resolveDirective = resolveDirective;
  15534. exports.resolveDynamicComponent = resolveDynamicComponent;
  15535. exports.resolveFilter = resolveFilter;
  15536. exports.resolveTransitionHooks = resolveTransitionHooks;
  15537. exports.setBlockTracking = setBlockTracking;
  15538. exports.setDevtoolsHook = setDevtoolsHook;
  15539. exports.setTransitionHooks = setTransitionHooks;
  15540. exports.shallowReactive = shallowReactive;
  15541. exports.shallowReadonly = shallowReadonly;
  15542. exports.shallowRef = shallowRef;
  15543. exports.ssrContextKey = ssrContextKey;
  15544. exports.ssrUtils = ssrUtils;
  15545. exports.stop = stop;
  15546. exports.toDisplayString = toDisplayString;
  15547. exports.toHandlerKey = toHandlerKey;
  15548. exports.toHandlers = toHandlers;
  15549. exports.toRaw = toRaw;
  15550. exports.toRef = toRef;
  15551. exports.toRefs = toRefs;
  15552. exports.transformVNodeArgs = transformVNodeArgs;
  15553. exports.triggerRef = triggerRef;
  15554. exports.unref = unref;
  15555. exports.useAttrs = useAttrs;
  15556. exports.useCssModule = useCssModule;
  15557. exports.useCssVars = useCssVars;
  15558. exports.useSSRContext = useSSRContext;
  15559. exports.useSlots = useSlots;
  15560. exports.useTransitionState = useTransitionState;
  15561. exports.vModelCheckbox = vModelCheckbox;
  15562. exports.vModelDynamic = vModelDynamic;
  15563. exports.vModelRadio = vModelRadio;
  15564. exports.vModelSelect = vModelSelect;
  15565. exports.vModelText = vModelText;
  15566. exports.vShow = vShow;
  15567. exports.version = version;
  15568. exports.warn = warn$1;
  15569. exports.watch = watch;
  15570. exports.watchEffect = watchEffect;
  15571. exports.watchPostEffect = watchPostEffect;
  15572. exports.watchSyncEffect = watchSyncEffect;
  15573. exports.withAsyncContext = withAsyncContext;
  15574. exports.withCtx = withCtx;
  15575. exports.withDefaults = withDefaults;
  15576. exports.withDirectives = withDirectives;
  15577. exports.withKeys = withKeys;
  15578. exports.withMemo = withMemo;
  15579. exports.withModifiers = withModifiers;
  15580. exports.withScopeId = withScopeId;
  15581. Object.defineProperty(exports, '__esModule', { value: true });
  15582. return exports;
  15583. }({}));