vue.global.js 610 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929
  1. var Vue = (function (exports) {
  2. 'use strict';
  3. /**
  4. * Make a map and return a function for checking if a key
  5. * is in that map.
  6. * IMPORTANT: all calls of this function must be prefixed with
  7. * \/\*#\_\_PURE\_\_\*\/
  8. * So that rollup can tree-shake them if necessary.
  9. */
  10. function makeMap(str, expectsLowerCase) {
  11. const map = Object.create(null);
  12. const list = str.split(',');
  13. for (let i = 0; i < list.length; i++) {
  14. map[list[i]] = true;
  15. }
  16. return expectsLowerCase ? val => !!map[val.toLowerCase()] : val => !!map[val];
  17. }
  18. /**
  19. * dev only flag -> name mapping
  20. */
  21. const PatchFlagNames = {
  22. [1 /* TEXT */]: `TEXT`,
  23. [2 /* CLASS */]: `CLASS`,
  24. [4 /* STYLE */]: `STYLE`,
  25. [8 /* PROPS */]: `PROPS`,
  26. [16 /* FULL_PROPS */]: `FULL_PROPS`,
  27. [32 /* HYDRATE_EVENTS */]: `HYDRATE_EVENTS`,
  28. [64 /* STABLE_FRAGMENT */]: `STABLE_FRAGMENT`,
  29. [128 /* KEYED_FRAGMENT */]: `KEYED_FRAGMENT`,
  30. [256 /* UNKEYED_FRAGMENT */]: `UNKEYED_FRAGMENT`,
  31. [512 /* NEED_PATCH */]: `NEED_PATCH`,
  32. [1024 /* DYNAMIC_SLOTS */]: `DYNAMIC_SLOTS`,
  33. [2048 /* DEV_ROOT_FRAGMENT */]: `DEV_ROOT_FRAGMENT`,
  34. [-1 /* HOISTED */]: `HOISTED`,
  35. [-2 /* BAIL */]: `BAIL`
  36. };
  37. /**
  38. * Dev only
  39. */
  40. const slotFlagsText = {
  41. [1 /* STABLE */]: 'STABLE',
  42. [2 /* DYNAMIC */]: 'DYNAMIC',
  43. [3 /* FORWARDED */]: 'FORWARDED'
  44. };
  45. const GLOBALS_WHITE_LISTED = 'Infinity,undefined,NaN,isFinite,isNaN,parseFloat,parseInt,decodeURI,' +
  46. 'decodeURIComponent,encodeURI,encodeURIComponent,Math,Number,Date,Array,' +
  47. 'Object,Boolean,String,RegExp,Map,Set,JSON,Intl,BigInt';
  48. const isGloballyWhitelisted = /*#__PURE__*/ makeMap(GLOBALS_WHITE_LISTED);
  49. const range = 2;
  50. function generateCodeFrame(source, start = 0, end = source.length) {
  51. // Split the content into individual lines but capture the newline sequence
  52. // that separated each line. This is important because the actual sequence is
  53. // needed to properly take into account the full line length for offset
  54. // comparison
  55. let lines = source.split(/(\r?\n)/);
  56. // Separate the lines and newline sequences into separate arrays for easier referencing
  57. const newlineSequences = lines.filter((_, idx) => idx % 2 === 1);
  58. lines = lines.filter((_, idx) => idx % 2 === 0);
  59. let count = 0;
  60. const res = [];
  61. for (let i = 0; i < lines.length; i++) {
  62. count +=
  63. lines[i].length +
  64. ((newlineSequences[i] && newlineSequences[i].length) || 0);
  65. if (count >= start) {
  66. for (let j = i - range; j <= i + range || end > count; j++) {
  67. if (j < 0 || j >= lines.length)
  68. continue;
  69. const line = j + 1;
  70. res.push(`${line}${' '.repeat(Math.max(3 - String(line).length, 0))}| ${lines[j]}`);
  71. const lineLength = lines[j].length;
  72. const newLineSeqLength = (newlineSequences[j] && newlineSequences[j].length) || 0;
  73. if (j === i) {
  74. // push underline
  75. const pad = start - (count - (lineLength + newLineSeqLength));
  76. const length = Math.max(1, end > count ? lineLength - pad : end - start);
  77. res.push(` | ` + ' '.repeat(pad) + '^'.repeat(length));
  78. }
  79. else if (j > i) {
  80. if (end > count) {
  81. const length = Math.max(Math.min(end - count, lineLength), 1);
  82. res.push(` | ` + '^'.repeat(length));
  83. }
  84. count += lineLength + newLineSeqLength;
  85. }
  86. }
  87. break;
  88. }
  89. }
  90. return res.join('\n');
  91. }
  92. /**
  93. * On the client we only need to offer special cases for boolean attributes that
  94. * have different names from their corresponding dom properties:
  95. * - itemscope -> N/A
  96. * - allowfullscreen -> allowFullscreen
  97. * - formnovalidate -> formNoValidate
  98. * - ismap -> isMap
  99. * - nomodule -> noModule
  100. * - novalidate -> noValidate
  101. * - readonly -> readOnly
  102. */
  103. const specialBooleanAttrs = `itemscope,allowfullscreen,formnovalidate,ismap,nomodule,novalidate,readonly`;
  104. const isSpecialBooleanAttr = /*#__PURE__*/ makeMap(specialBooleanAttrs);
  105. /**
  106. * Boolean attributes should be included if the value is truthy or ''.
  107. * e.g. `<select multiple>` compiles to `{ multiple: '' }`
  108. */
  109. function includeBooleanAttr(value) {
  110. return !!value || value === '';
  111. }
  112. function normalizeStyle(value) {
  113. if (isArray(value)) {
  114. const res = {};
  115. for (let i = 0; i < value.length; i++) {
  116. const item = value[i];
  117. const normalized = isString(item)
  118. ? parseStringStyle(item)
  119. : normalizeStyle(item);
  120. if (normalized) {
  121. for (const key in normalized) {
  122. res[key] = normalized[key];
  123. }
  124. }
  125. }
  126. return res;
  127. }
  128. else if (isString(value)) {
  129. return value;
  130. }
  131. else if (isObject(value)) {
  132. return value;
  133. }
  134. }
  135. const listDelimiterRE = /;(?![^(]*\))/g;
  136. const propertyDelimiterRE = /:(.+)/;
  137. function parseStringStyle(cssText) {
  138. const ret = {};
  139. cssText.split(listDelimiterRE).forEach(item => {
  140. if (item) {
  141. const tmp = item.split(propertyDelimiterRE);
  142. tmp.length > 1 && (ret[tmp[0].trim()] = tmp[1].trim());
  143. }
  144. });
  145. return ret;
  146. }
  147. function normalizeClass(value) {
  148. let res = '';
  149. if (isString(value)) {
  150. res = value;
  151. }
  152. else if (isArray(value)) {
  153. for (let i = 0; i < value.length; i++) {
  154. const normalized = normalizeClass(value[i]);
  155. if (normalized) {
  156. res += normalized + ' ';
  157. }
  158. }
  159. }
  160. else if (isObject(value)) {
  161. for (const name in value) {
  162. if (value[name]) {
  163. res += name + ' ';
  164. }
  165. }
  166. }
  167. return res.trim();
  168. }
  169. function normalizeProps(props) {
  170. if (!props)
  171. return null;
  172. let { class: klass, style } = props;
  173. if (klass && !isString(klass)) {
  174. props.class = normalizeClass(klass);
  175. }
  176. if (style) {
  177. props.style = normalizeStyle(style);
  178. }
  179. return props;
  180. }
  181. // These tag configs are shared between compiler-dom and runtime-dom, so they
  182. // https://developer.mozilla.org/en-US/docs/Web/HTML/Element
  183. const HTML_TAGS = 'html,body,base,head,link,meta,style,title,address,article,aside,footer,' +
  184. 'header,h1,h2,h3,h4,h5,h6,nav,section,div,dd,dl,dt,figcaption,' +
  185. 'figure,picture,hr,img,li,main,ol,p,pre,ul,a,b,abbr,bdi,bdo,br,cite,code,' +
  186. 'data,dfn,em,i,kbd,mark,q,rp,rt,ruby,s,samp,small,span,strong,sub,sup,' +
  187. 'time,u,var,wbr,area,audio,map,track,video,embed,object,param,source,' +
  188. 'canvas,script,noscript,del,ins,caption,col,colgroup,table,thead,tbody,td,' +
  189. 'th,tr,button,datalist,fieldset,form,input,label,legend,meter,optgroup,' +
  190. 'option,output,progress,select,textarea,details,dialog,menu,' +
  191. 'summary,template,blockquote,iframe,tfoot';
  192. // https://developer.mozilla.org/en-US/docs/Web/SVG/Element
  193. const SVG_TAGS = 'svg,animate,animateMotion,animateTransform,circle,clipPath,color-profile,' +
  194. 'defs,desc,discard,ellipse,feBlend,feColorMatrix,feComponentTransfer,' +
  195. 'feComposite,feConvolveMatrix,feDiffuseLighting,feDisplacementMap,' +
  196. 'feDistanceLight,feDropShadow,feFlood,feFuncA,feFuncB,feFuncG,feFuncR,' +
  197. 'feGaussianBlur,feImage,feMerge,feMergeNode,feMorphology,feOffset,' +
  198. 'fePointLight,feSpecularLighting,feSpotLight,feTile,feTurbulence,filter,' +
  199. 'foreignObject,g,hatch,hatchpath,image,line,linearGradient,marker,mask,' +
  200. 'mesh,meshgradient,meshpatch,meshrow,metadata,mpath,path,pattern,' +
  201. 'polygon,polyline,radialGradient,rect,set,solidcolor,stop,switch,symbol,' +
  202. 'text,textPath,title,tspan,unknown,use,view';
  203. const VOID_TAGS = 'area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr';
  204. /**
  205. * Compiler only.
  206. * Do NOT use in runtime code paths unless behind `true` flag.
  207. */
  208. const isHTMLTag = /*#__PURE__*/ makeMap(HTML_TAGS);
  209. /**
  210. * Compiler only.
  211. * Do NOT use in runtime code paths unless behind `true` flag.
  212. */
  213. const isSVGTag = /*#__PURE__*/ makeMap(SVG_TAGS);
  214. /**
  215. * Compiler only.
  216. * Do NOT use in runtime code paths unless behind `true` flag.
  217. */
  218. const isVoidTag = /*#__PURE__*/ makeMap(VOID_TAGS);
  219. function looseCompareArrays(a, b) {
  220. if (a.length !== b.length)
  221. return false;
  222. let equal = true;
  223. for (let i = 0; equal && i < a.length; i++) {
  224. equal = looseEqual(a[i], b[i]);
  225. }
  226. return equal;
  227. }
  228. function looseEqual(a, b) {
  229. if (a === b)
  230. return true;
  231. let aValidType = isDate(a);
  232. let bValidType = isDate(b);
  233. if (aValidType || bValidType) {
  234. return aValidType && bValidType ? a.getTime() === b.getTime() : false;
  235. }
  236. aValidType = isSymbol(a);
  237. bValidType = isSymbol(b);
  238. if (aValidType || bValidType) {
  239. return a === b;
  240. }
  241. aValidType = isArray(a);
  242. bValidType = isArray(b);
  243. if (aValidType || bValidType) {
  244. return aValidType && bValidType ? looseCompareArrays(a, b) : false;
  245. }
  246. aValidType = isObject(a);
  247. bValidType = isObject(b);
  248. if (aValidType || bValidType) {
  249. /* istanbul ignore if: this if will probably never be called */
  250. if (!aValidType || !bValidType) {
  251. return false;
  252. }
  253. const aKeysCount = Object.keys(a).length;
  254. const bKeysCount = Object.keys(b).length;
  255. if (aKeysCount !== bKeysCount) {
  256. return false;
  257. }
  258. for (const key in a) {
  259. const aHasKey = a.hasOwnProperty(key);
  260. const bHasKey = b.hasOwnProperty(key);
  261. if ((aHasKey && !bHasKey) ||
  262. (!aHasKey && bHasKey) ||
  263. !looseEqual(a[key], b[key])) {
  264. return false;
  265. }
  266. }
  267. }
  268. return String(a) === String(b);
  269. }
  270. function looseIndexOf(arr, val) {
  271. return arr.findIndex(item => looseEqual(item, val));
  272. }
  273. /**
  274. * For converting {{ interpolation }} values to displayed strings.
  275. * @private
  276. */
  277. const toDisplayString = (val) => {
  278. return isString(val)
  279. ? val
  280. : val == null
  281. ? ''
  282. : isArray(val) ||
  283. (isObject(val) &&
  284. (val.toString === objectToString || !isFunction(val.toString)))
  285. ? JSON.stringify(val, replacer, 2)
  286. : String(val);
  287. };
  288. const replacer = (_key, val) => {
  289. // can't use isRef here since @vue/shared has no deps
  290. if (val && val.__v_isRef) {
  291. return replacer(_key, val.value);
  292. }
  293. else if (isMap(val)) {
  294. return {
  295. [`Map(${val.size})`]: [...val.entries()].reduce((entries, [key, val]) => {
  296. entries[`${key} =>`] = val;
  297. return entries;
  298. }, {})
  299. };
  300. }
  301. else if (isSet(val)) {
  302. return {
  303. [`Set(${val.size})`]: [...val.values()]
  304. };
  305. }
  306. else if (isObject(val) && !isArray(val) && !isPlainObject(val)) {
  307. return String(val);
  308. }
  309. return val;
  310. };
  311. const EMPTY_OBJ = Object.freeze({})
  312. ;
  313. const EMPTY_ARR = Object.freeze([]) ;
  314. const NOOP = () => { };
  315. /**
  316. * Always return false.
  317. */
  318. const NO = () => false;
  319. const onRE = /^on[^a-z]/;
  320. const isOn = (key) => onRE.test(key);
  321. const isModelListener = (key) => key.startsWith('onUpdate:');
  322. const extend = Object.assign;
  323. const remove = (arr, el) => {
  324. const i = arr.indexOf(el);
  325. if (i > -1) {
  326. arr.splice(i, 1);
  327. }
  328. };
  329. const hasOwnProperty = Object.prototype.hasOwnProperty;
  330. const hasOwn = (val, key) => hasOwnProperty.call(val, key);
  331. const isArray = Array.isArray;
  332. const isMap = (val) => toTypeString(val) === '[object Map]';
  333. const isSet = (val) => toTypeString(val) === '[object Set]';
  334. const isDate = (val) => toTypeString(val) === '[object Date]';
  335. const isFunction = (val) => typeof val === 'function';
  336. const isString = (val) => typeof val === 'string';
  337. const isSymbol = (val) => typeof val === 'symbol';
  338. const isObject = (val) => val !== null && typeof val === 'object';
  339. const isPromise = (val) => {
  340. return isObject(val) && isFunction(val.then) && isFunction(val.catch);
  341. };
  342. const objectToString = Object.prototype.toString;
  343. const toTypeString = (value) => objectToString.call(value);
  344. const toRawType = (value) => {
  345. // extract "RawType" from strings like "[object RawType]"
  346. return toTypeString(value).slice(8, -1);
  347. };
  348. const isPlainObject = (val) => toTypeString(val) === '[object Object]';
  349. const isIntegerKey = (key) => isString(key) &&
  350. key !== 'NaN' &&
  351. key[0] !== '-' &&
  352. '' + parseInt(key, 10) === key;
  353. const isReservedProp = /*#__PURE__*/ makeMap(
  354. // the leading comma is intentional so empty string "" is also included
  355. ',key,ref,ref_for,ref_key,' +
  356. 'onVnodeBeforeMount,onVnodeMounted,' +
  357. 'onVnodeBeforeUpdate,onVnodeUpdated,' +
  358. 'onVnodeBeforeUnmount,onVnodeUnmounted');
  359. const isBuiltInDirective = /*#__PURE__*/ makeMap('bind,cloak,else-if,else,for,html,if,model,on,once,pre,show,slot,text,memo');
  360. const cacheStringFunction = (fn) => {
  361. const cache = Object.create(null);
  362. return ((str) => {
  363. const hit = cache[str];
  364. return hit || (cache[str] = fn(str));
  365. });
  366. };
  367. const camelizeRE = /-(\w)/g;
  368. /**
  369. * @private
  370. */
  371. const camelize = cacheStringFunction((str) => {
  372. return str.replace(camelizeRE, (_, c) => (c ? c.toUpperCase() : ''));
  373. });
  374. const hyphenateRE = /\B([A-Z])/g;
  375. /**
  376. * @private
  377. */
  378. const hyphenate = cacheStringFunction((str) => str.replace(hyphenateRE, '-$1').toLowerCase());
  379. /**
  380. * @private
  381. */
  382. const capitalize = cacheStringFunction((str) => str.charAt(0).toUpperCase() + str.slice(1));
  383. /**
  384. * @private
  385. */
  386. const toHandlerKey = cacheStringFunction((str) => str ? `on${capitalize(str)}` : ``);
  387. // compare whether a value has changed, accounting for NaN.
  388. const hasChanged = (value, oldValue) => !Object.is(value, oldValue);
  389. const invokeArrayFns = (fns, arg) => {
  390. for (let i = 0; i < fns.length; i++) {
  391. fns[i](arg);
  392. }
  393. };
  394. const def = (obj, key, value) => {
  395. Object.defineProperty(obj, key, {
  396. configurable: true,
  397. enumerable: false,
  398. value
  399. });
  400. };
  401. const toNumber = (val) => {
  402. const n = parseFloat(val);
  403. return isNaN(n) ? val : n;
  404. };
  405. let _globalThis;
  406. const getGlobalThis = () => {
  407. return (_globalThis ||
  408. (_globalThis =
  409. typeof globalThis !== 'undefined'
  410. ? globalThis
  411. : typeof self !== 'undefined'
  412. ? self
  413. : typeof window !== 'undefined'
  414. ? window
  415. : typeof global !== 'undefined'
  416. ? global
  417. : {}));
  418. };
  419. function warn(msg, ...args) {
  420. console.warn(`[Vue warn] ${msg}`, ...args);
  421. }
  422. let activeEffectScope;
  423. class EffectScope {
  424. constructor(detached = false) {
  425. /**
  426. * @internal
  427. */
  428. this.active = true;
  429. /**
  430. * @internal
  431. */
  432. this.effects = [];
  433. /**
  434. * @internal
  435. */
  436. this.cleanups = [];
  437. if (!detached && activeEffectScope) {
  438. this.parent = activeEffectScope;
  439. this.index =
  440. (activeEffectScope.scopes || (activeEffectScope.scopes = [])).push(this) - 1;
  441. }
  442. }
  443. run(fn) {
  444. if (this.active) {
  445. const currentEffectScope = activeEffectScope;
  446. try {
  447. activeEffectScope = this;
  448. return fn();
  449. }
  450. finally {
  451. activeEffectScope = currentEffectScope;
  452. }
  453. }
  454. else {
  455. warn(`cannot run an inactive effect scope.`);
  456. }
  457. }
  458. /**
  459. * This should only be called on non-detached scopes
  460. * @internal
  461. */
  462. on() {
  463. activeEffectScope = this;
  464. }
  465. /**
  466. * This should only be called on non-detached scopes
  467. * @internal
  468. */
  469. off() {
  470. activeEffectScope = this.parent;
  471. }
  472. stop(fromParent) {
  473. if (this.active) {
  474. let i, l;
  475. for (i = 0, l = this.effects.length; i < l; i++) {
  476. this.effects[i].stop();
  477. }
  478. for (i = 0, l = this.cleanups.length; i < l; i++) {
  479. this.cleanups[i]();
  480. }
  481. if (this.scopes) {
  482. for (i = 0, l = this.scopes.length; i < l; i++) {
  483. this.scopes[i].stop(true);
  484. }
  485. }
  486. // nested scope, dereference from parent to avoid memory leaks
  487. if (this.parent && !fromParent) {
  488. // optimized O(1) removal
  489. const last = this.parent.scopes.pop();
  490. if (last && last !== this) {
  491. this.parent.scopes[this.index] = last;
  492. last.index = this.index;
  493. }
  494. }
  495. this.active = false;
  496. }
  497. }
  498. }
  499. function effectScope(detached) {
  500. return new EffectScope(detached);
  501. }
  502. function recordEffectScope(effect, scope = activeEffectScope) {
  503. if (scope && scope.active) {
  504. scope.effects.push(effect);
  505. }
  506. }
  507. function getCurrentScope() {
  508. return activeEffectScope;
  509. }
  510. function onScopeDispose(fn) {
  511. if (activeEffectScope) {
  512. activeEffectScope.cleanups.push(fn);
  513. }
  514. else {
  515. warn(`onScopeDispose() is called when there is no active effect scope` +
  516. ` to be associated with.`);
  517. }
  518. }
  519. const createDep = (effects) => {
  520. const dep = new Set(effects);
  521. dep.w = 0;
  522. dep.n = 0;
  523. return dep;
  524. };
  525. const wasTracked = (dep) => (dep.w & trackOpBit) > 0;
  526. const newTracked = (dep) => (dep.n & trackOpBit) > 0;
  527. const initDepMarkers = ({ deps }) => {
  528. if (deps.length) {
  529. for (let i = 0; i < deps.length; i++) {
  530. deps[i].w |= trackOpBit; // set was tracked
  531. }
  532. }
  533. };
  534. const finalizeDepMarkers = (effect) => {
  535. const { deps } = effect;
  536. if (deps.length) {
  537. let ptr = 0;
  538. for (let i = 0; i < deps.length; i++) {
  539. const dep = deps[i];
  540. if (wasTracked(dep) && !newTracked(dep)) {
  541. dep.delete(effect);
  542. }
  543. else {
  544. deps[ptr++] = dep;
  545. }
  546. // clear bits
  547. dep.w &= ~trackOpBit;
  548. dep.n &= ~trackOpBit;
  549. }
  550. deps.length = ptr;
  551. }
  552. };
  553. const targetMap = new WeakMap();
  554. // The number of effects currently being tracked recursively.
  555. let effectTrackDepth = 0;
  556. let trackOpBit = 1;
  557. /**
  558. * The bitwise track markers support at most 30 levels of recursion.
  559. * This value is chosen to enable modern JS engines to use a SMI on all platforms.
  560. * When recursion depth is greater, fall back to using a full cleanup.
  561. */
  562. const maxMarkerBits = 30;
  563. let activeEffect;
  564. const ITERATE_KEY = Symbol('iterate' );
  565. const MAP_KEY_ITERATE_KEY = Symbol('Map key iterate' );
  566. class ReactiveEffect {
  567. constructor(fn, scheduler = null, scope) {
  568. this.fn = fn;
  569. this.scheduler = scheduler;
  570. this.active = true;
  571. this.deps = [];
  572. this.parent = undefined;
  573. recordEffectScope(this, scope);
  574. }
  575. run() {
  576. if (!this.active) {
  577. return this.fn();
  578. }
  579. let parent = activeEffect;
  580. let lastShouldTrack = shouldTrack;
  581. while (parent) {
  582. if (parent === this) {
  583. return;
  584. }
  585. parent = parent.parent;
  586. }
  587. try {
  588. this.parent = activeEffect;
  589. activeEffect = this;
  590. shouldTrack = true;
  591. trackOpBit = 1 << ++effectTrackDepth;
  592. if (effectTrackDepth <= maxMarkerBits) {
  593. initDepMarkers(this);
  594. }
  595. else {
  596. cleanupEffect(this);
  597. }
  598. return this.fn();
  599. }
  600. finally {
  601. if (effectTrackDepth <= maxMarkerBits) {
  602. finalizeDepMarkers(this);
  603. }
  604. trackOpBit = 1 << --effectTrackDepth;
  605. activeEffect = this.parent;
  606. shouldTrack = lastShouldTrack;
  607. this.parent = undefined;
  608. if (this.deferStop) {
  609. this.stop();
  610. }
  611. }
  612. }
  613. stop() {
  614. // stopped while running itself - defer the cleanup
  615. if (activeEffect === this) {
  616. this.deferStop = true;
  617. }
  618. else if (this.active) {
  619. cleanupEffect(this);
  620. if (this.onStop) {
  621. this.onStop();
  622. }
  623. this.active = false;
  624. }
  625. }
  626. }
  627. function cleanupEffect(effect) {
  628. const { deps } = effect;
  629. if (deps.length) {
  630. for (let i = 0; i < deps.length; i++) {
  631. deps[i].delete(effect);
  632. }
  633. deps.length = 0;
  634. }
  635. }
  636. function effect(fn, options) {
  637. if (fn.effect) {
  638. fn = fn.effect.fn;
  639. }
  640. const _effect = new ReactiveEffect(fn);
  641. if (options) {
  642. extend(_effect, options);
  643. if (options.scope)
  644. recordEffectScope(_effect, options.scope);
  645. }
  646. if (!options || !options.lazy) {
  647. _effect.run();
  648. }
  649. const runner = _effect.run.bind(_effect);
  650. runner.effect = _effect;
  651. return runner;
  652. }
  653. function stop(runner) {
  654. runner.effect.stop();
  655. }
  656. let shouldTrack = true;
  657. const trackStack = [];
  658. function pauseTracking() {
  659. trackStack.push(shouldTrack);
  660. shouldTrack = false;
  661. }
  662. function resetTracking() {
  663. const last = trackStack.pop();
  664. shouldTrack = last === undefined ? true : last;
  665. }
  666. function track(target, type, key) {
  667. if (shouldTrack && activeEffect) {
  668. let depsMap = targetMap.get(target);
  669. if (!depsMap) {
  670. targetMap.set(target, (depsMap = new Map()));
  671. }
  672. let dep = depsMap.get(key);
  673. if (!dep) {
  674. depsMap.set(key, (dep = createDep()));
  675. }
  676. const eventInfo = { effect: activeEffect, target, type, key }
  677. ;
  678. trackEffects(dep, eventInfo);
  679. }
  680. }
  681. function trackEffects(dep, debuggerEventExtraInfo) {
  682. let shouldTrack = false;
  683. if (effectTrackDepth <= maxMarkerBits) {
  684. if (!newTracked(dep)) {
  685. dep.n |= trackOpBit; // set newly tracked
  686. shouldTrack = !wasTracked(dep);
  687. }
  688. }
  689. else {
  690. // Full cleanup mode.
  691. shouldTrack = !dep.has(activeEffect);
  692. }
  693. if (shouldTrack) {
  694. dep.add(activeEffect);
  695. activeEffect.deps.push(dep);
  696. if (activeEffect.onTrack) {
  697. activeEffect.onTrack(Object.assign({ effect: activeEffect }, debuggerEventExtraInfo));
  698. }
  699. }
  700. }
  701. function trigger(target, type, key, newValue, oldValue, oldTarget) {
  702. const depsMap = targetMap.get(target);
  703. if (!depsMap) {
  704. // never been tracked
  705. return;
  706. }
  707. let deps = [];
  708. if (type === "clear" /* CLEAR */) {
  709. // collection being cleared
  710. // trigger all effects for target
  711. deps = [...depsMap.values()];
  712. }
  713. else if (key === 'length' && isArray(target)) {
  714. depsMap.forEach((dep, key) => {
  715. if (key === 'length' || key >= newValue) {
  716. deps.push(dep);
  717. }
  718. });
  719. }
  720. else {
  721. // schedule runs for SET | ADD | DELETE
  722. if (key !== void 0) {
  723. deps.push(depsMap.get(key));
  724. }
  725. // also run for iteration key on ADD | DELETE | Map.SET
  726. switch (type) {
  727. case "add" /* ADD */:
  728. if (!isArray(target)) {
  729. deps.push(depsMap.get(ITERATE_KEY));
  730. if (isMap(target)) {
  731. deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
  732. }
  733. }
  734. else if (isIntegerKey(key)) {
  735. // new index added to array -> length changes
  736. deps.push(depsMap.get('length'));
  737. }
  738. break;
  739. case "delete" /* DELETE */:
  740. if (!isArray(target)) {
  741. deps.push(depsMap.get(ITERATE_KEY));
  742. if (isMap(target)) {
  743. deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
  744. }
  745. }
  746. break;
  747. case "set" /* SET */:
  748. if (isMap(target)) {
  749. deps.push(depsMap.get(ITERATE_KEY));
  750. }
  751. break;
  752. }
  753. }
  754. const eventInfo = { target, type, key, newValue, oldValue, oldTarget }
  755. ;
  756. if (deps.length === 1) {
  757. if (deps[0]) {
  758. {
  759. triggerEffects(deps[0], eventInfo);
  760. }
  761. }
  762. }
  763. else {
  764. const effects = [];
  765. for (const dep of deps) {
  766. if (dep) {
  767. effects.push(...dep);
  768. }
  769. }
  770. {
  771. triggerEffects(createDep(effects), eventInfo);
  772. }
  773. }
  774. }
  775. function triggerEffects(dep, debuggerEventExtraInfo) {
  776. // spread into array for stabilization
  777. const effects = isArray(dep) ? dep : [...dep];
  778. for (const effect of effects) {
  779. if (effect.computed) {
  780. triggerEffect(effect, debuggerEventExtraInfo);
  781. }
  782. }
  783. for (const effect of effects) {
  784. if (!effect.computed) {
  785. triggerEffect(effect, debuggerEventExtraInfo);
  786. }
  787. }
  788. }
  789. function triggerEffect(effect, debuggerEventExtraInfo) {
  790. if (effect !== activeEffect || effect.allowRecurse) {
  791. if (effect.onTrigger) {
  792. effect.onTrigger(extend({ effect }, debuggerEventExtraInfo));
  793. }
  794. if (effect.scheduler) {
  795. effect.scheduler();
  796. }
  797. else {
  798. effect.run();
  799. }
  800. }
  801. }
  802. const isNonTrackableKeys = /*#__PURE__*/ makeMap(`__proto__,__v_isRef,__isVue`);
  803. const builtInSymbols = new Set(
  804. /*#__PURE__*/
  805. Object.getOwnPropertyNames(Symbol)
  806. // ios10.x Object.getOwnPropertyNames(Symbol) can enumerate 'arguments' and 'caller'
  807. // but accessing them on Symbol leads to TypeError because Symbol is a strict mode
  808. // function
  809. .filter(key => key !== 'arguments' && key !== 'caller')
  810. .map(key => Symbol[key])
  811. .filter(isSymbol));
  812. const get = /*#__PURE__*/ createGetter();
  813. const shallowGet = /*#__PURE__*/ createGetter(false, true);
  814. const readonlyGet = /*#__PURE__*/ createGetter(true);
  815. const shallowReadonlyGet = /*#__PURE__*/ createGetter(true, true);
  816. const arrayInstrumentations = /*#__PURE__*/ createArrayInstrumentations();
  817. function createArrayInstrumentations() {
  818. const instrumentations = {};
  819. ['includes', 'indexOf', 'lastIndexOf'].forEach(key => {
  820. instrumentations[key] = function (...args) {
  821. const arr = toRaw(this);
  822. for (let i = 0, l = this.length; i < l; i++) {
  823. track(arr, "get" /* GET */, i + '');
  824. }
  825. // we run the method using the original args first (which may be reactive)
  826. const res = arr[key](...args);
  827. if (res === -1 || res === false) {
  828. // if that didn't work, run it again using raw values.
  829. return arr[key](...args.map(toRaw));
  830. }
  831. else {
  832. return res;
  833. }
  834. };
  835. });
  836. ['push', 'pop', 'shift', 'unshift', 'splice'].forEach(key => {
  837. instrumentations[key] = function (...args) {
  838. pauseTracking();
  839. const res = toRaw(this)[key].apply(this, args);
  840. resetTracking();
  841. return res;
  842. };
  843. });
  844. return instrumentations;
  845. }
  846. function createGetter(isReadonly = false, shallow = false) {
  847. return function get(target, key, receiver) {
  848. if (key === "__v_isReactive" /* IS_REACTIVE */) {
  849. return !isReadonly;
  850. }
  851. else if (key === "__v_isReadonly" /* IS_READONLY */) {
  852. return isReadonly;
  853. }
  854. else if (key === "__v_isShallow" /* IS_SHALLOW */) {
  855. return shallow;
  856. }
  857. else if (key === "__v_raw" /* RAW */ &&
  858. receiver ===
  859. (isReadonly
  860. ? shallow
  861. ? shallowReadonlyMap
  862. : readonlyMap
  863. : shallow
  864. ? shallowReactiveMap
  865. : reactiveMap).get(target)) {
  866. return target;
  867. }
  868. const targetIsArray = isArray(target);
  869. if (!isReadonly && targetIsArray && hasOwn(arrayInstrumentations, key)) {
  870. return Reflect.get(arrayInstrumentations, key, receiver);
  871. }
  872. const res = Reflect.get(target, key, receiver);
  873. if (isSymbol(key) ? builtInSymbols.has(key) : isNonTrackableKeys(key)) {
  874. return res;
  875. }
  876. if (!isReadonly) {
  877. track(target, "get" /* GET */, key);
  878. }
  879. if (shallow) {
  880. return res;
  881. }
  882. if (isRef(res)) {
  883. // ref unwrapping - skip unwrap for Array + integer key.
  884. return targetIsArray && isIntegerKey(key) ? res : res.value;
  885. }
  886. if (isObject(res)) {
  887. // Convert returned value into a proxy as well. we do the isObject check
  888. // here to avoid invalid value warning. Also need to lazy access readonly
  889. // and reactive here to avoid circular dependency.
  890. return isReadonly ? readonly(res) : reactive(res);
  891. }
  892. return res;
  893. };
  894. }
  895. const set = /*#__PURE__*/ createSetter();
  896. const shallowSet = /*#__PURE__*/ createSetter(true);
  897. function createSetter(shallow = false) {
  898. return function set(target, key, value, receiver) {
  899. let oldValue = target[key];
  900. if (isReadonly(oldValue) && isRef(oldValue) && !isRef(value)) {
  901. return false;
  902. }
  903. if (!shallow && !isReadonly(value)) {
  904. if (!isShallow(value)) {
  905. value = toRaw(value);
  906. oldValue = toRaw(oldValue);
  907. }
  908. if (!isArray(target) && isRef(oldValue) && !isRef(value)) {
  909. oldValue.value = value;
  910. return true;
  911. }
  912. }
  913. const hadKey = isArray(target) && isIntegerKey(key)
  914. ? Number(key) < target.length
  915. : hasOwn(target, key);
  916. const result = Reflect.set(target, key, value, receiver);
  917. // don't trigger if target is something up in the prototype chain of original
  918. if (target === toRaw(receiver)) {
  919. if (!hadKey) {
  920. trigger(target, "add" /* ADD */, key, value);
  921. }
  922. else if (hasChanged(value, oldValue)) {
  923. trigger(target, "set" /* SET */, key, value, oldValue);
  924. }
  925. }
  926. return result;
  927. };
  928. }
  929. function deleteProperty(target, key) {
  930. const hadKey = hasOwn(target, key);
  931. const oldValue = target[key];
  932. const result = Reflect.deleteProperty(target, key);
  933. if (result && hadKey) {
  934. trigger(target, "delete" /* DELETE */, key, undefined, oldValue);
  935. }
  936. return result;
  937. }
  938. function has(target, key) {
  939. const result = Reflect.has(target, key);
  940. if (!isSymbol(key) || !builtInSymbols.has(key)) {
  941. track(target, "has" /* HAS */, key);
  942. }
  943. return result;
  944. }
  945. function ownKeys(target) {
  946. track(target, "iterate" /* ITERATE */, isArray(target) ? 'length' : ITERATE_KEY);
  947. return Reflect.ownKeys(target);
  948. }
  949. const mutableHandlers = {
  950. get,
  951. set,
  952. deleteProperty,
  953. has,
  954. ownKeys
  955. };
  956. const readonlyHandlers = {
  957. get: readonlyGet,
  958. set(target, key) {
  959. {
  960. warn(`Set operation on key "${String(key)}" failed: target is readonly.`, target);
  961. }
  962. return true;
  963. },
  964. deleteProperty(target, key) {
  965. {
  966. warn(`Delete operation on key "${String(key)}" failed: target is readonly.`, target);
  967. }
  968. return true;
  969. }
  970. };
  971. const shallowReactiveHandlers = /*#__PURE__*/ extend({}, mutableHandlers, {
  972. get: shallowGet,
  973. set: shallowSet
  974. });
  975. // Props handlers are special in the sense that it should not unwrap top-level
  976. // refs (in order to allow refs to be explicitly passed down), but should
  977. // retain the reactivity of the normal readonly object.
  978. const shallowReadonlyHandlers = /*#__PURE__*/ extend({}, readonlyHandlers, {
  979. get: shallowReadonlyGet
  980. });
  981. const toShallow = (value) => value;
  982. const getProto = (v) => Reflect.getPrototypeOf(v);
  983. function get$1(target, key, isReadonly = false, isShallow = false) {
  984. // #1772: readonly(reactive(Map)) should return readonly + reactive version
  985. // of the value
  986. target = target["__v_raw" /* RAW */];
  987. const rawTarget = toRaw(target);
  988. const rawKey = toRaw(key);
  989. if (!isReadonly) {
  990. if (key !== rawKey) {
  991. track(rawTarget, "get" /* GET */, key);
  992. }
  993. track(rawTarget, "get" /* GET */, rawKey);
  994. }
  995. const { has } = getProto(rawTarget);
  996. const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
  997. if (has.call(rawTarget, key)) {
  998. return wrap(target.get(key));
  999. }
  1000. else if (has.call(rawTarget, rawKey)) {
  1001. return wrap(target.get(rawKey));
  1002. }
  1003. else if (target !== rawTarget) {
  1004. // #3602 readonly(reactive(Map))
  1005. // ensure that the nested reactive `Map` can do tracking for itself
  1006. target.get(key);
  1007. }
  1008. }
  1009. function has$1(key, isReadonly = false) {
  1010. const target = this["__v_raw" /* RAW */];
  1011. const rawTarget = toRaw(target);
  1012. const rawKey = toRaw(key);
  1013. if (!isReadonly) {
  1014. if (key !== rawKey) {
  1015. track(rawTarget, "has" /* HAS */, key);
  1016. }
  1017. track(rawTarget, "has" /* HAS */, rawKey);
  1018. }
  1019. return key === rawKey
  1020. ? target.has(key)
  1021. : target.has(key) || target.has(rawKey);
  1022. }
  1023. function size(target, isReadonly = false) {
  1024. target = target["__v_raw" /* RAW */];
  1025. !isReadonly && track(toRaw(target), "iterate" /* ITERATE */, ITERATE_KEY);
  1026. return Reflect.get(target, 'size', target);
  1027. }
  1028. function add(value) {
  1029. value = toRaw(value);
  1030. const target = toRaw(this);
  1031. const proto = getProto(target);
  1032. const hadKey = proto.has.call(target, value);
  1033. if (!hadKey) {
  1034. target.add(value);
  1035. trigger(target, "add" /* ADD */, value, value);
  1036. }
  1037. return this;
  1038. }
  1039. function set$1(key, value) {
  1040. value = toRaw(value);
  1041. const target = toRaw(this);
  1042. const { has, get } = getProto(target);
  1043. let hadKey = has.call(target, key);
  1044. if (!hadKey) {
  1045. key = toRaw(key);
  1046. hadKey = has.call(target, key);
  1047. }
  1048. else {
  1049. checkIdentityKeys(target, has, key);
  1050. }
  1051. const oldValue = get.call(target, key);
  1052. target.set(key, value);
  1053. if (!hadKey) {
  1054. trigger(target, "add" /* ADD */, key, value);
  1055. }
  1056. else if (hasChanged(value, oldValue)) {
  1057. trigger(target, "set" /* SET */, key, value, oldValue);
  1058. }
  1059. return this;
  1060. }
  1061. function deleteEntry(key) {
  1062. const target = toRaw(this);
  1063. const { has, get } = getProto(target);
  1064. let hadKey = has.call(target, key);
  1065. if (!hadKey) {
  1066. key = toRaw(key);
  1067. hadKey = has.call(target, key);
  1068. }
  1069. else {
  1070. checkIdentityKeys(target, has, key);
  1071. }
  1072. const oldValue = get ? get.call(target, key) : undefined;
  1073. // forward the operation before queueing reactions
  1074. const result = target.delete(key);
  1075. if (hadKey) {
  1076. trigger(target, "delete" /* DELETE */, key, undefined, oldValue);
  1077. }
  1078. return result;
  1079. }
  1080. function clear() {
  1081. const target = toRaw(this);
  1082. const hadItems = target.size !== 0;
  1083. const oldTarget = isMap(target)
  1084. ? new Map(target)
  1085. : new Set(target)
  1086. ;
  1087. // forward the operation before queueing reactions
  1088. const result = target.clear();
  1089. if (hadItems) {
  1090. trigger(target, "clear" /* CLEAR */, undefined, undefined, oldTarget);
  1091. }
  1092. return result;
  1093. }
  1094. function createForEach(isReadonly, isShallow) {
  1095. return function forEach(callback, thisArg) {
  1096. const observed = this;
  1097. const target = observed["__v_raw" /* RAW */];
  1098. const rawTarget = toRaw(target);
  1099. const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
  1100. !isReadonly && track(rawTarget, "iterate" /* ITERATE */, ITERATE_KEY);
  1101. return target.forEach((value, key) => {
  1102. // important: make sure the callback is
  1103. // 1. invoked with the reactive map as `this` and 3rd arg
  1104. // 2. the value received should be a corresponding reactive/readonly.
  1105. return callback.call(thisArg, wrap(value), wrap(key), observed);
  1106. });
  1107. };
  1108. }
  1109. function createIterableMethod(method, isReadonly, isShallow) {
  1110. return function (...args) {
  1111. const target = this["__v_raw" /* RAW */];
  1112. const rawTarget = toRaw(target);
  1113. const targetIsMap = isMap(rawTarget);
  1114. const isPair = method === 'entries' || (method === Symbol.iterator && targetIsMap);
  1115. const isKeyOnly = method === 'keys' && targetIsMap;
  1116. const innerIterator = target[method](...args);
  1117. const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
  1118. !isReadonly &&
  1119. track(rawTarget, "iterate" /* ITERATE */, isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY);
  1120. // return a wrapped iterator which returns observed versions of the
  1121. // values emitted from the real iterator
  1122. return {
  1123. // iterator protocol
  1124. next() {
  1125. const { value, done } = innerIterator.next();
  1126. return done
  1127. ? { value, done }
  1128. : {
  1129. value: isPair ? [wrap(value[0]), wrap(value[1])] : wrap(value),
  1130. done
  1131. };
  1132. },
  1133. // iterable protocol
  1134. [Symbol.iterator]() {
  1135. return this;
  1136. }
  1137. };
  1138. };
  1139. }
  1140. function createReadonlyMethod(type) {
  1141. return function (...args) {
  1142. {
  1143. const key = args[0] ? `on key "${args[0]}" ` : ``;
  1144. console.warn(`${capitalize(type)} operation ${key}failed: target is readonly.`, toRaw(this));
  1145. }
  1146. return type === "delete" /* DELETE */ ? false : this;
  1147. };
  1148. }
  1149. function createInstrumentations() {
  1150. const mutableInstrumentations = {
  1151. get(key) {
  1152. return get$1(this, key);
  1153. },
  1154. get size() {
  1155. return size(this);
  1156. },
  1157. has: has$1,
  1158. add,
  1159. set: set$1,
  1160. delete: deleteEntry,
  1161. clear,
  1162. forEach: createForEach(false, false)
  1163. };
  1164. const shallowInstrumentations = {
  1165. get(key) {
  1166. return get$1(this, key, false, true);
  1167. },
  1168. get size() {
  1169. return size(this);
  1170. },
  1171. has: has$1,
  1172. add,
  1173. set: set$1,
  1174. delete: deleteEntry,
  1175. clear,
  1176. forEach: createForEach(false, true)
  1177. };
  1178. const readonlyInstrumentations = {
  1179. get(key) {
  1180. return get$1(this, key, true);
  1181. },
  1182. get size() {
  1183. return size(this, true);
  1184. },
  1185. has(key) {
  1186. return has$1.call(this, key, true);
  1187. },
  1188. add: createReadonlyMethod("add" /* ADD */),
  1189. set: createReadonlyMethod("set" /* SET */),
  1190. delete: createReadonlyMethod("delete" /* DELETE */),
  1191. clear: createReadonlyMethod("clear" /* CLEAR */),
  1192. forEach: createForEach(true, false)
  1193. };
  1194. const shallowReadonlyInstrumentations = {
  1195. get(key) {
  1196. return get$1(this, key, true, true);
  1197. },
  1198. get size() {
  1199. return size(this, true);
  1200. },
  1201. has(key) {
  1202. return has$1.call(this, key, true);
  1203. },
  1204. add: createReadonlyMethod("add" /* ADD */),
  1205. set: createReadonlyMethod("set" /* SET */),
  1206. delete: createReadonlyMethod("delete" /* DELETE */),
  1207. clear: createReadonlyMethod("clear" /* CLEAR */),
  1208. forEach: createForEach(true, true)
  1209. };
  1210. const iteratorMethods = ['keys', 'values', 'entries', Symbol.iterator];
  1211. iteratorMethods.forEach(method => {
  1212. mutableInstrumentations[method] = createIterableMethod(method, false, false);
  1213. readonlyInstrumentations[method] = createIterableMethod(method, true, false);
  1214. shallowInstrumentations[method] = createIterableMethod(method, false, true);
  1215. shallowReadonlyInstrumentations[method] = createIterableMethod(method, true, true);
  1216. });
  1217. return [
  1218. mutableInstrumentations,
  1219. readonlyInstrumentations,
  1220. shallowInstrumentations,
  1221. shallowReadonlyInstrumentations
  1222. ];
  1223. }
  1224. const [mutableInstrumentations, readonlyInstrumentations, shallowInstrumentations, shallowReadonlyInstrumentations] = /* #__PURE__*/ createInstrumentations();
  1225. function createInstrumentationGetter(isReadonly, shallow) {
  1226. const instrumentations = shallow
  1227. ? isReadonly
  1228. ? shallowReadonlyInstrumentations
  1229. : shallowInstrumentations
  1230. : isReadonly
  1231. ? readonlyInstrumentations
  1232. : mutableInstrumentations;
  1233. return (target, key, receiver) => {
  1234. if (key === "__v_isReactive" /* IS_REACTIVE */) {
  1235. return !isReadonly;
  1236. }
  1237. else if (key === "__v_isReadonly" /* IS_READONLY */) {
  1238. return isReadonly;
  1239. }
  1240. else if (key === "__v_raw" /* RAW */) {
  1241. return target;
  1242. }
  1243. return Reflect.get(hasOwn(instrumentations, key) && key in target
  1244. ? instrumentations
  1245. : target, key, receiver);
  1246. };
  1247. }
  1248. const mutableCollectionHandlers = {
  1249. get: /*#__PURE__*/ createInstrumentationGetter(false, false)
  1250. };
  1251. const shallowCollectionHandlers = {
  1252. get: /*#__PURE__*/ createInstrumentationGetter(false, true)
  1253. };
  1254. const readonlyCollectionHandlers = {
  1255. get: /*#__PURE__*/ createInstrumentationGetter(true, false)
  1256. };
  1257. const shallowReadonlyCollectionHandlers = {
  1258. get: /*#__PURE__*/ createInstrumentationGetter(true, true)
  1259. };
  1260. function checkIdentityKeys(target, has, key) {
  1261. const rawKey = toRaw(key);
  1262. if (rawKey !== key && has.call(target, rawKey)) {
  1263. const type = toRawType(target);
  1264. console.warn(`Reactive ${type} contains both the raw and reactive ` +
  1265. `versions of the same object${type === `Map` ? ` as keys` : ``}, ` +
  1266. `which can lead to inconsistencies. ` +
  1267. `Avoid differentiating between the raw and reactive versions ` +
  1268. `of an object and only use the reactive version if possible.`);
  1269. }
  1270. }
  1271. const reactiveMap = new WeakMap();
  1272. const shallowReactiveMap = new WeakMap();
  1273. const readonlyMap = new WeakMap();
  1274. const shallowReadonlyMap = new WeakMap();
  1275. function targetTypeMap(rawType) {
  1276. switch (rawType) {
  1277. case 'Object':
  1278. case 'Array':
  1279. return 1 /* COMMON */;
  1280. case 'Map':
  1281. case 'Set':
  1282. case 'WeakMap':
  1283. case 'WeakSet':
  1284. return 2 /* COLLECTION */;
  1285. default:
  1286. return 0 /* INVALID */;
  1287. }
  1288. }
  1289. function getTargetType(value) {
  1290. return value["__v_skip" /* SKIP */] || !Object.isExtensible(value)
  1291. ? 0 /* INVALID */
  1292. : targetTypeMap(toRawType(value));
  1293. }
  1294. function reactive(target) {
  1295. // if trying to observe a readonly proxy, return the readonly version.
  1296. if (isReadonly(target)) {
  1297. return target;
  1298. }
  1299. return createReactiveObject(target, false, mutableHandlers, mutableCollectionHandlers, reactiveMap);
  1300. }
  1301. /**
  1302. * Return a shallowly-reactive copy of the original object, where only the root
  1303. * level properties are reactive. It also does not auto-unwrap refs (even at the
  1304. * root level).
  1305. */
  1306. function shallowReactive(target) {
  1307. return createReactiveObject(target, false, shallowReactiveHandlers, shallowCollectionHandlers, shallowReactiveMap);
  1308. }
  1309. /**
  1310. * Creates a readonly copy of the original object. Note the returned copy is not
  1311. * made reactive, but `readonly` can be called on an already reactive object.
  1312. */
  1313. function readonly(target) {
  1314. return createReactiveObject(target, true, readonlyHandlers, readonlyCollectionHandlers, readonlyMap);
  1315. }
  1316. /**
  1317. * Returns a reactive-copy of the original object, where only the root level
  1318. * properties are readonly, and does NOT unwrap refs nor recursively convert
  1319. * returned properties.
  1320. * This is used for creating the props proxy object for stateful components.
  1321. */
  1322. function shallowReadonly(target) {
  1323. return createReactiveObject(target, true, shallowReadonlyHandlers, shallowReadonlyCollectionHandlers, shallowReadonlyMap);
  1324. }
  1325. function createReactiveObject(target, isReadonly, baseHandlers, collectionHandlers, proxyMap) {
  1326. if (!isObject(target)) {
  1327. {
  1328. console.warn(`value cannot be made reactive: ${String(target)}`);
  1329. }
  1330. return target;
  1331. }
  1332. // target is already a Proxy, return it.
  1333. // exception: calling readonly() on a reactive object
  1334. if (target["__v_raw" /* RAW */] &&
  1335. !(isReadonly && target["__v_isReactive" /* IS_REACTIVE */])) {
  1336. return target;
  1337. }
  1338. // target already has corresponding Proxy
  1339. const existingProxy = proxyMap.get(target);
  1340. if (existingProxy) {
  1341. return existingProxy;
  1342. }
  1343. // only specific value types can be observed.
  1344. const targetType = getTargetType(target);
  1345. if (targetType === 0 /* INVALID */) {
  1346. return target;
  1347. }
  1348. const proxy = new Proxy(target, targetType === 2 /* COLLECTION */ ? collectionHandlers : baseHandlers);
  1349. proxyMap.set(target, proxy);
  1350. return proxy;
  1351. }
  1352. function isReactive(value) {
  1353. if (isReadonly(value)) {
  1354. return isReactive(value["__v_raw" /* RAW */]);
  1355. }
  1356. return !!(value && value["__v_isReactive" /* IS_REACTIVE */]);
  1357. }
  1358. function isReadonly(value) {
  1359. return !!(value && value["__v_isReadonly" /* IS_READONLY */]);
  1360. }
  1361. function isShallow(value) {
  1362. return !!(value && value["__v_isShallow" /* IS_SHALLOW */]);
  1363. }
  1364. function isProxy(value) {
  1365. return isReactive(value) || isReadonly(value);
  1366. }
  1367. function toRaw(observed) {
  1368. const raw = observed && observed["__v_raw" /* RAW */];
  1369. return raw ? toRaw(raw) : observed;
  1370. }
  1371. function markRaw(value) {
  1372. def(value, "__v_skip" /* SKIP */, true);
  1373. return value;
  1374. }
  1375. const toReactive = (value) => isObject(value) ? reactive(value) : value;
  1376. const toReadonly = (value) => isObject(value) ? readonly(value) : value;
  1377. function trackRefValue(ref) {
  1378. if (shouldTrack && activeEffect) {
  1379. ref = toRaw(ref);
  1380. {
  1381. trackEffects(ref.dep || (ref.dep = createDep()), {
  1382. target: ref,
  1383. type: "get" /* GET */,
  1384. key: 'value'
  1385. });
  1386. }
  1387. }
  1388. }
  1389. function triggerRefValue(ref, newVal) {
  1390. ref = toRaw(ref);
  1391. if (ref.dep) {
  1392. {
  1393. triggerEffects(ref.dep, {
  1394. target: ref,
  1395. type: "set" /* SET */,
  1396. key: 'value',
  1397. newValue: newVal
  1398. });
  1399. }
  1400. }
  1401. }
  1402. function isRef(r) {
  1403. return !!(r && r.__v_isRef === true);
  1404. }
  1405. function ref(value) {
  1406. return createRef(value, false);
  1407. }
  1408. function shallowRef(value) {
  1409. return createRef(value, true);
  1410. }
  1411. function createRef(rawValue, shallow) {
  1412. if (isRef(rawValue)) {
  1413. return rawValue;
  1414. }
  1415. return new RefImpl(rawValue, shallow);
  1416. }
  1417. class RefImpl {
  1418. constructor(value, __v_isShallow) {
  1419. this.__v_isShallow = __v_isShallow;
  1420. this.dep = undefined;
  1421. this.__v_isRef = true;
  1422. this._rawValue = __v_isShallow ? value : toRaw(value);
  1423. this._value = __v_isShallow ? value : toReactive(value);
  1424. }
  1425. get value() {
  1426. trackRefValue(this);
  1427. return this._value;
  1428. }
  1429. set value(newVal) {
  1430. newVal = this.__v_isShallow ? newVal : toRaw(newVal);
  1431. if (hasChanged(newVal, this._rawValue)) {
  1432. this._rawValue = newVal;
  1433. this._value = this.__v_isShallow ? newVal : toReactive(newVal);
  1434. triggerRefValue(this, newVal);
  1435. }
  1436. }
  1437. }
  1438. function triggerRef(ref) {
  1439. triggerRefValue(ref, ref.value );
  1440. }
  1441. function unref(ref) {
  1442. return isRef(ref) ? ref.value : ref;
  1443. }
  1444. const shallowUnwrapHandlers = {
  1445. get: (target, key, receiver) => unref(Reflect.get(target, key, receiver)),
  1446. set: (target, key, value, receiver) => {
  1447. const oldValue = target[key];
  1448. if (isRef(oldValue) && !isRef(value)) {
  1449. oldValue.value = value;
  1450. return true;
  1451. }
  1452. else {
  1453. return Reflect.set(target, key, value, receiver);
  1454. }
  1455. }
  1456. };
  1457. function proxyRefs(objectWithRefs) {
  1458. return isReactive(objectWithRefs)
  1459. ? objectWithRefs
  1460. : new Proxy(objectWithRefs, shallowUnwrapHandlers);
  1461. }
  1462. class CustomRefImpl {
  1463. constructor(factory) {
  1464. this.dep = undefined;
  1465. this.__v_isRef = true;
  1466. const { get, set } = factory(() => trackRefValue(this), () => triggerRefValue(this));
  1467. this._get = get;
  1468. this._set = set;
  1469. }
  1470. get value() {
  1471. return this._get();
  1472. }
  1473. set value(newVal) {
  1474. this._set(newVal);
  1475. }
  1476. }
  1477. function customRef(factory) {
  1478. return new CustomRefImpl(factory);
  1479. }
  1480. function toRefs(object) {
  1481. if (!isProxy(object)) {
  1482. console.warn(`toRefs() expects a reactive object but received a plain one.`);
  1483. }
  1484. const ret = isArray(object) ? new Array(object.length) : {};
  1485. for (const key in object) {
  1486. ret[key] = toRef(object, key);
  1487. }
  1488. return ret;
  1489. }
  1490. class ObjectRefImpl {
  1491. constructor(_object, _key, _defaultValue) {
  1492. this._object = _object;
  1493. this._key = _key;
  1494. this._defaultValue = _defaultValue;
  1495. this.__v_isRef = true;
  1496. }
  1497. get value() {
  1498. const val = this._object[this._key];
  1499. return val === undefined ? this._defaultValue : val;
  1500. }
  1501. set value(newVal) {
  1502. this._object[this._key] = newVal;
  1503. }
  1504. }
  1505. function toRef(object, key, defaultValue) {
  1506. const val = object[key];
  1507. return isRef(val)
  1508. ? val
  1509. : new ObjectRefImpl(object, key, defaultValue);
  1510. }
  1511. class ComputedRefImpl {
  1512. constructor(getter, _setter, isReadonly, isSSR) {
  1513. this._setter = _setter;
  1514. this.dep = undefined;
  1515. this.__v_isRef = true;
  1516. this._dirty = true;
  1517. this.effect = new ReactiveEffect(getter, () => {
  1518. if (!this._dirty) {
  1519. this._dirty = true;
  1520. triggerRefValue(this);
  1521. }
  1522. });
  1523. this.effect.computed = this;
  1524. this.effect.active = this._cacheable = !isSSR;
  1525. this["__v_isReadonly" /* IS_READONLY */] = isReadonly;
  1526. }
  1527. get value() {
  1528. // the computed ref may get wrapped by other proxies e.g. readonly() #3376
  1529. const self = toRaw(this);
  1530. trackRefValue(self);
  1531. if (self._dirty || !self._cacheable) {
  1532. self._dirty = false;
  1533. self._value = self.effect.run();
  1534. }
  1535. return self._value;
  1536. }
  1537. set value(newValue) {
  1538. this._setter(newValue);
  1539. }
  1540. }
  1541. function computed(getterOrOptions, debugOptions, isSSR = false) {
  1542. let getter;
  1543. let setter;
  1544. const onlyGetter = isFunction(getterOrOptions);
  1545. if (onlyGetter) {
  1546. getter = getterOrOptions;
  1547. setter = () => {
  1548. console.warn('Write operation failed: computed value is readonly');
  1549. }
  1550. ;
  1551. }
  1552. else {
  1553. getter = getterOrOptions.get;
  1554. setter = getterOrOptions.set;
  1555. }
  1556. const cRef = new ComputedRefImpl(getter, setter, onlyGetter || !setter, isSSR);
  1557. if (debugOptions && !isSSR) {
  1558. cRef.effect.onTrack = debugOptions.onTrack;
  1559. cRef.effect.onTrigger = debugOptions.onTrigger;
  1560. }
  1561. return cRef;
  1562. }
  1563. const stack = [];
  1564. function pushWarningContext(vnode) {
  1565. stack.push(vnode);
  1566. }
  1567. function popWarningContext() {
  1568. stack.pop();
  1569. }
  1570. function warn$1(msg, ...args) {
  1571. // avoid props formatting or warn handler tracking deps that might be mutated
  1572. // during patch, leading to infinite recursion.
  1573. pauseTracking();
  1574. const instance = stack.length ? stack[stack.length - 1].component : null;
  1575. const appWarnHandler = instance && instance.appContext.config.warnHandler;
  1576. const trace = getComponentTrace();
  1577. if (appWarnHandler) {
  1578. callWithErrorHandling(appWarnHandler, instance, 11 /* APP_WARN_HANDLER */, [
  1579. msg + args.join(''),
  1580. instance && instance.proxy,
  1581. trace
  1582. .map(({ vnode }) => `at <${formatComponentName(instance, vnode.type)}>`)
  1583. .join('\n'),
  1584. trace
  1585. ]);
  1586. }
  1587. else {
  1588. const warnArgs = [`[Vue warn]: ${msg}`, ...args];
  1589. /* istanbul ignore if */
  1590. if (trace.length &&
  1591. // avoid spamming console during tests
  1592. !false) {
  1593. warnArgs.push(`\n`, ...formatTrace(trace));
  1594. }
  1595. console.warn(...warnArgs);
  1596. }
  1597. resetTracking();
  1598. }
  1599. function getComponentTrace() {
  1600. let currentVNode = stack[stack.length - 1];
  1601. if (!currentVNode) {
  1602. return [];
  1603. }
  1604. // we can't just use the stack because it will be incomplete during updates
  1605. // that did not start from the root. Re-construct the parent chain using
  1606. // instance parent pointers.
  1607. const normalizedStack = [];
  1608. while (currentVNode) {
  1609. const last = normalizedStack[0];
  1610. if (last && last.vnode === currentVNode) {
  1611. last.recurseCount++;
  1612. }
  1613. else {
  1614. normalizedStack.push({
  1615. vnode: currentVNode,
  1616. recurseCount: 0
  1617. });
  1618. }
  1619. const parentInstance = currentVNode.component && currentVNode.component.parent;
  1620. currentVNode = parentInstance && parentInstance.vnode;
  1621. }
  1622. return normalizedStack;
  1623. }
  1624. /* istanbul ignore next */
  1625. function formatTrace(trace) {
  1626. const logs = [];
  1627. trace.forEach((entry, i) => {
  1628. logs.push(...(i === 0 ? [] : [`\n`]), ...formatTraceEntry(entry));
  1629. });
  1630. return logs;
  1631. }
  1632. function formatTraceEntry({ vnode, recurseCount }) {
  1633. const postfix = recurseCount > 0 ? `... (${recurseCount} recursive calls)` : ``;
  1634. const isRoot = vnode.component ? vnode.component.parent == null : false;
  1635. const open = ` at <${formatComponentName(vnode.component, vnode.type, isRoot)}`;
  1636. const close = `>` + postfix;
  1637. return vnode.props
  1638. ? [open, ...formatProps(vnode.props), close]
  1639. : [open + close];
  1640. }
  1641. /* istanbul ignore next */
  1642. function formatProps(props) {
  1643. const res = [];
  1644. const keys = Object.keys(props);
  1645. keys.slice(0, 3).forEach(key => {
  1646. res.push(...formatProp(key, props[key]));
  1647. });
  1648. if (keys.length > 3) {
  1649. res.push(` ...`);
  1650. }
  1651. return res;
  1652. }
  1653. /* istanbul ignore next */
  1654. function formatProp(key, value, raw) {
  1655. if (isString(value)) {
  1656. value = JSON.stringify(value);
  1657. return raw ? value : [`${key}=${value}`];
  1658. }
  1659. else if (typeof value === 'number' ||
  1660. typeof value === 'boolean' ||
  1661. value == null) {
  1662. return raw ? value : [`${key}=${value}`];
  1663. }
  1664. else if (isRef(value)) {
  1665. value = formatProp(key, toRaw(value.value), true);
  1666. return raw ? value : [`${key}=Ref<`, value, `>`];
  1667. }
  1668. else if (isFunction(value)) {
  1669. return [`${key}=fn${value.name ? `<${value.name}>` : ``}`];
  1670. }
  1671. else {
  1672. value = toRaw(value);
  1673. return raw ? value : [`${key}=`, value];
  1674. }
  1675. }
  1676. const ErrorTypeStrings = {
  1677. ["sp" /* SERVER_PREFETCH */]: 'serverPrefetch hook',
  1678. ["bc" /* BEFORE_CREATE */]: 'beforeCreate hook',
  1679. ["c" /* CREATED */]: 'created hook',
  1680. ["bm" /* BEFORE_MOUNT */]: 'beforeMount hook',
  1681. ["m" /* MOUNTED */]: 'mounted hook',
  1682. ["bu" /* BEFORE_UPDATE */]: 'beforeUpdate hook',
  1683. ["u" /* UPDATED */]: 'updated',
  1684. ["bum" /* BEFORE_UNMOUNT */]: 'beforeUnmount hook',
  1685. ["um" /* UNMOUNTED */]: 'unmounted hook',
  1686. ["a" /* ACTIVATED */]: 'activated hook',
  1687. ["da" /* DEACTIVATED */]: 'deactivated hook',
  1688. ["ec" /* ERROR_CAPTURED */]: 'errorCaptured hook',
  1689. ["rtc" /* RENDER_TRACKED */]: 'renderTracked hook',
  1690. ["rtg" /* RENDER_TRIGGERED */]: 'renderTriggered hook',
  1691. [0 /* SETUP_FUNCTION */]: 'setup function',
  1692. [1 /* RENDER_FUNCTION */]: 'render function',
  1693. [2 /* WATCH_GETTER */]: 'watcher getter',
  1694. [3 /* WATCH_CALLBACK */]: 'watcher callback',
  1695. [4 /* WATCH_CLEANUP */]: 'watcher cleanup function',
  1696. [5 /* NATIVE_EVENT_HANDLER */]: 'native event handler',
  1697. [6 /* COMPONENT_EVENT_HANDLER */]: 'component event handler',
  1698. [7 /* VNODE_HOOK */]: 'vnode hook',
  1699. [8 /* DIRECTIVE_HOOK */]: 'directive hook',
  1700. [9 /* TRANSITION_HOOK */]: 'transition hook',
  1701. [10 /* APP_ERROR_HANDLER */]: 'app errorHandler',
  1702. [11 /* APP_WARN_HANDLER */]: 'app warnHandler',
  1703. [12 /* FUNCTION_REF */]: 'ref function',
  1704. [13 /* ASYNC_COMPONENT_LOADER */]: 'async component loader',
  1705. [14 /* SCHEDULER */]: 'scheduler flush. This is likely a Vue internals bug. ' +
  1706. 'Please open an issue at https://new-issue.vuejs.org/?repo=vuejs/core'
  1707. };
  1708. function callWithErrorHandling(fn, instance, type, args) {
  1709. let res;
  1710. try {
  1711. res = args ? fn(...args) : fn();
  1712. }
  1713. catch (err) {
  1714. handleError(err, instance, type);
  1715. }
  1716. return res;
  1717. }
  1718. function callWithAsyncErrorHandling(fn, instance, type, args) {
  1719. if (isFunction(fn)) {
  1720. const res = callWithErrorHandling(fn, instance, type, args);
  1721. if (res && isPromise(res)) {
  1722. res.catch(err => {
  1723. handleError(err, instance, type);
  1724. });
  1725. }
  1726. return res;
  1727. }
  1728. const values = [];
  1729. for (let i = 0; i < fn.length; i++) {
  1730. values.push(callWithAsyncErrorHandling(fn[i], instance, type, args));
  1731. }
  1732. return values;
  1733. }
  1734. function handleError(err, instance, type, throwInDev = true) {
  1735. const contextVNode = instance ? instance.vnode : null;
  1736. if (instance) {
  1737. let cur = instance.parent;
  1738. // the exposed instance is the render proxy to keep it consistent with 2.x
  1739. const exposedInstance = instance.proxy;
  1740. // in production the hook receives only the error code
  1741. const errorInfo = ErrorTypeStrings[type] ;
  1742. while (cur) {
  1743. const errorCapturedHooks = cur.ec;
  1744. if (errorCapturedHooks) {
  1745. for (let i = 0; i < errorCapturedHooks.length; i++) {
  1746. if (errorCapturedHooks[i](err, exposedInstance, errorInfo) === false) {
  1747. return;
  1748. }
  1749. }
  1750. }
  1751. cur = cur.parent;
  1752. }
  1753. // app-level handling
  1754. const appErrorHandler = instance.appContext.config.errorHandler;
  1755. if (appErrorHandler) {
  1756. callWithErrorHandling(appErrorHandler, null, 10 /* APP_ERROR_HANDLER */, [err, exposedInstance, errorInfo]);
  1757. return;
  1758. }
  1759. }
  1760. logError(err, type, contextVNode, throwInDev);
  1761. }
  1762. function logError(err, type, contextVNode, throwInDev = true) {
  1763. {
  1764. const info = ErrorTypeStrings[type];
  1765. if (contextVNode) {
  1766. pushWarningContext(contextVNode);
  1767. }
  1768. warn$1(`Unhandled error${info ? ` during execution of ${info}` : ``}`);
  1769. if (contextVNode) {
  1770. popWarningContext();
  1771. }
  1772. // crash in dev by default so it's more noticeable
  1773. if (throwInDev) {
  1774. throw err;
  1775. }
  1776. else {
  1777. console.error(err);
  1778. }
  1779. }
  1780. }
  1781. let isFlushing = false;
  1782. let isFlushPending = false;
  1783. const queue = [];
  1784. let flushIndex = 0;
  1785. const pendingPreFlushCbs = [];
  1786. let activePreFlushCbs = null;
  1787. let preFlushIndex = 0;
  1788. const pendingPostFlushCbs = [];
  1789. let activePostFlushCbs = null;
  1790. let postFlushIndex = 0;
  1791. const resolvedPromise = /*#__PURE__*/ Promise.resolve();
  1792. let currentFlushPromise = null;
  1793. let currentPreFlushParentJob = null;
  1794. const RECURSION_LIMIT = 100;
  1795. function nextTick(fn) {
  1796. const p = currentFlushPromise || resolvedPromise;
  1797. return fn ? p.then(this ? fn.bind(this) : fn) : p;
  1798. }
  1799. // #2768
  1800. // Use binary-search to find a suitable position in the queue,
  1801. // so that the queue maintains the increasing order of job's id,
  1802. // which can prevent the job from being skipped and also can avoid repeated patching.
  1803. function findInsertionIndex(id) {
  1804. // the start index should be `flushIndex + 1`
  1805. let start = flushIndex + 1;
  1806. let end = queue.length;
  1807. while (start < end) {
  1808. const middle = (start + end) >>> 1;
  1809. const middleJobId = getId(queue[middle]);
  1810. middleJobId < id ? (start = middle + 1) : (end = middle);
  1811. }
  1812. return start;
  1813. }
  1814. function queueJob(job) {
  1815. // the dedupe search uses the startIndex argument of Array.includes()
  1816. // by default the search index includes the current job that is being run
  1817. // so it cannot recursively trigger itself again.
  1818. // if the job is a watch() callback, the search will start with a +1 index to
  1819. // allow it recursively trigger itself - it is the user's responsibility to
  1820. // ensure it doesn't end up in an infinite loop.
  1821. if ((!queue.length ||
  1822. !queue.includes(job, isFlushing && job.allowRecurse ? flushIndex + 1 : flushIndex)) &&
  1823. job !== currentPreFlushParentJob) {
  1824. if (job.id == null) {
  1825. queue.push(job);
  1826. }
  1827. else {
  1828. queue.splice(findInsertionIndex(job.id), 0, job);
  1829. }
  1830. queueFlush();
  1831. }
  1832. }
  1833. function queueFlush() {
  1834. if (!isFlushing && !isFlushPending) {
  1835. isFlushPending = true;
  1836. currentFlushPromise = resolvedPromise.then(flushJobs);
  1837. }
  1838. }
  1839. function invalidateJob(job) {
  1840. const i = queue.indexOf(job);
  1841. if (i > flushIndex) {
  1842. queue.splice(i, 1);
  1843. }
  1844. }
  1845. function queueCb(cb, activeQueue, pendingQueue, index) {
  1846. if (!isArray(cb)) {
  1847. if (!activeQueue ||
  1848. !activeQueue.includes(cb, cb.allowRecurse ? index + 1 : index)) {
  1849. pendingQueue.push(cb);
  1850. }
  1851. }
  1852. else {
  1853. // if cb is an array, it is a component lifecycle hook which can only be
  1854. // triggered by a job, which is already deduped in the main queue, so
  1855. // we can skip duplicate check here to improve perf
  1856. pendingQueue.push(...cb);
  1857. }
  1858. queueFlush();
  1859. }
  1860. function queuePreFlushCb(cb) {
  1861. queueCb(cb, activePreFlushCbs, pendingPreFlushCbs, preFlushIndex);
  1862. }
  1863. function queuePostFlushCb(cb) {
  1864. queueCb(cb, activePostFlushCbs, pendingPostFlushCbs, postFlushIndex);
  1865. }
  1866. function flushPreFlushCbs(seen, parentJob = null) {
  1867. if (pendingPreFlushCbs.length) {
  1868. currentPreFlushParentJob = parentJob;
  1869. activePreFlushCbs = [...new Set(pendingPreFlushCbs)];
  1870. pendingPreFlushCbs.length = 0;
  1871. {
  1872. seen = seen || new Map();
  1873. }
  1874. for (preFlushIndex = 0; preFlushIndex < activePreFlushCbs.length; preFlushIndex++) {
  1875. if (checkRecursiveUpdates(seen, activePreFlushCbs[preFlushIndex])) {
  1876. continue;
  1877. }
  1878. activePreFlushCbs[preFlushIndex]();
  1879. }
  1880. activePreFlushCbs = null;
  1881. preFlushIndex = 0;
  1882. currentPreFlushParentJob = null;
  1883. // recursively flush until it drains
  1884. flushPreFlushCbs(seen, parentJob);
  1885. }
  1886. }
  1887. function flushPostFlushCbs(seen) {
  1888. // flush any pre cbs queued during the flush (e.g. pre watchers)
  1889. flushPreFlushCbs();
  1890. if (pendingPostFlushCbs.length) {
  1891. const deduped = [...new Set(pendingPostFlushCbs)];
  1892. pendingPostFlushCbs.length = 0;
  1893. // #1947 already has active queue, nested flushPostFlushCbs call
  1894. if (activePostFlushCbs) {
  1895. activePostFlushCbs.push(...deduped);
  1896. return;
  1897. }
  1898. activePostFlushCbs = deduped;
  1899. {
  1900. seen = seen || new Map();
  1901. }
  1902. activePostFlushCbs.sort((a, b) => getId(a) - getId(b));
  1903. for (postFlushIndex = 0; postFlushIndex < activePostFlushCbs.length; postFlushIndex++) {
  1904. if (checkRecursiveUpdates(seen, activePostFlushCbs[postFlushIndex])) {
  1905. continue;
  1906. }
  1907. activePostFlushCbs[postFlushIndex]();
  1908. }
  1909. activePostFlushCbs = null;
  1910. postFlushIndex = 0;
  1911. }
  1912. }
  1913. const getId = (job) => job.id == null ? Infinity : job.id;
  1914. function flushJobs(seen) {
  1915. isFlushPending = false;
  1916. isFlushing = true;
  1917. {
  1918. seen = seen || new Map();
  1919. }
  1920. flushPreFlushCbs(seen);
  1921. // Sort queue before flush.
  1922. // This ensures that:
  1923. // 1. Components are updated from parent to child. (because parent is always
  1924. // created before the child so its render effect will have smaller
  1925. // priority number)
  1926. // 2. If a component is unmounted during a parent component's update,
  1927. // its update can be skipped.
  1928. queue.sort((a, b) => getId(a) - getId(b));
  1929. // conditional usage of checkRecursiveUpdate must be determined out of
  1930. // try ... catch block since Rollup by default de-optimizes treeshaking
  1931. // inside try-catch. This can leave all warning code unshaked. Although
  1932. // they would get eventually shaken by a minifier like terser, some minifiers
  1933. // would fail to do that (e.g. https://github.com/evanw/esbuild/issues/1610)
  1934. const check = (job) => checkRecursiveUpdates(seen, job)
  1935. ;
  1936. try {
  1937. for (flushIndex = 0; flushIndex < queue.length; flushIndex++) {
  1938. const job = queue[flushIndex];
  1939. if (job && job.active !== false) {
  1940. if (true && check(job)) {
  1941. continue;
  1942. }
  1943. // console.log(`running:`, job.id)
  1944. callWithErrorHandling(job, null, 14 /* SCHEDULER */);
  1945. }
  1946. }
  1947. }
  1948. finally {
  1949. flushIndex = 0;
  1950. queue.length = 0;
  1951. flushPostFlushCbs(seen);
  1952. isFlushing = false;
  1953. currentFlushPromise = null;
  1954. // some postFlushCb queued jobs!
  1955. // keep flushing until it drains.
  1956. if (queue.length ||
  1957. pendingPreFlushCbs.length ||
  1958. pendingPostFlushCbs.length) {
  1959. flushJobs(seen);
  1960. }
  1961. }
  1962. }
  1963. function checkRecursiveUpdates(seen, fn) {
  1964. if (!seen.has(fn)) {
  1965. seen.set(fn, 1);
  1966. }
  1967. else {
  1968. const count = seen.get(fn);
  1969. if (count > RECURSION_LIMIT) {
  1970. const instance = fn.ownerInstance;
  1971. const componentName = instance && getComponentName(instance.type);
  1972. warn$1(`Maximum recursive updates exceeded${componentName ? ` in component <${componentName}>` : ``}. ` +
  1973. `This means you have a reactive effect that is mutating its own ` +
  1974. `dependencies and thus recursively triggering itself. Possible sources ` +
  1975. `include component template, render function, updated hook or ` +
  1976. `watcher source function.`);
  1977. return true;
  1978. }
  1979. else {
  1980. seen.set(fn, count + 1);
  1981. }
  1982. }
  1983. }
  1984. /* eslint-disable no-restricted-globals */
  1985. let isHmrUpdating = false;
  1986. const hmrDirtyComponents = new Set();
  1987. // Expose the HMR runtime on the global object
  1988. // This makes it entirely tree-shakable without polluting the exports and makes
  1989. // it easier to be used in toolings like vue-loader
  1990. // Note: for a component to be eligible for HMR it also needs the __hmrId option
  1991. // to be set so that its instances can be registered / removed.
  1992. {
  1993. getGlobalThis().__VUE_HMR_RUNTIME__ = {
  1994. createRecord: tryWrap(createRecord),
  1995. rerender: tryWrap(rerender),
  1996. reload: tryWrap(reload)
  1997. };
  1998. }
  1999. const map = new Map();
  2000. function registerHMR(instance) {
  2001. const id = instance.type.__hmrId;
  2002. let record = map.get(id);
  2003. if (!record) {
  2004. createRecord(id, instance.type);
  2005. record = map.get(id);
  2006. }
  2007. record.instances.add(instance);
  2008. }
  2009. function unregisterHMR(instance) {
  2010. map.get(instance.type.__hmrId).instances.delete(instance);
  2011. }
  2012. function createRecord(id, initialDef) {
  2013. if (map.has(id)) {
  2014. return false;
  2015. }
  2016. map.set(id, {
  2017. initialDef: normalizeClassComponent(initialDef),
  2018. instances: new Set()
  2019. });
  2020. return true;
  2021. }
  2022. function normalizeClassComponent(component) {
  2023. return isClassComponent(component) ? component.__vccOpts : component;
  2024. }
  2025. function rerender(id, newRender) {
  2026. const record = map.get(id);
  2027. if (!record) {
  2028. return;
  2029. }
  2030. // update initial record (for not-yet-rendered component)
  2031. record.initialDef.render = newRender;
  2032. [...record.instances].forEach(instance => {
  2033. if (newRender) {
  2034. instance.render = newRender;
  2035. normalizeClassComponent(instance.type).render = newRender;
  2036. }
  2037. instance.renderCache = [];
  2038. // this flag forces child components with slot content to update
  2039. isHmrUpdating = true;
  2040. instance.update();
  2041. isHmrUpdating = false;
  2042. });
  2043. }
  2044. function reload(id, newComp) {
  2045. const record = map.get(id);
  2046. if (!record)
  2047. return;
  2048. newComp = normalizeClassComponent(newComp);
  2049. // update initial def (for not-yet-rendered components)
  2050. updateComponentDef(record.initialDef, newComp);
  2051. // create a snapshot which avoids the set being mutated during updates
  2052. const instances = [...record.instances];
  2053. for (const instance of instances) {
  2054. const oldComp = normalizeClassComponent(instance.type);
  2055. if (!hmrDirtyComponents.has(oldComp)) {
  2056. // 1. Update existing comp definition to match new one
  2057. if (oldComp !== record.initialDef) {
  2058. updateComponentDef(oldComp, newComp);
  2059. }
  2060. // 2. mark definition dirty. This forces the renderer to replace the
  2061. // component on patch.
  2062. hmrDirtyComponents.add(oldComp);
  2063. }
  2064. // 3. invalidate options resolution cache
  2065. instance.appContext.optionsCache.delete(instance.type);
  2066. // 4. actually update
  2067. if (instance.ceReload) {
  2068. // custom element
  2069. hmrDirtyComponents.add(oldComp);
  2070. instance.ceReload(newComp.styles);
  2071. hmrDirtyComponents.delete(oldComp);
  2072. }
  2073. else if (instance.parent) {
  2074. // 4. Force the parent instance to re-render. This will cause all updated
  2075. // components to be unmounted and re-mounted. Queue the update so that we
  2076. // don't end up forcing the same parent to re-render multiple times.
  2077. queueJob(instance.parent.update);
  2078. // instance is the inner component of an async custom element
  2079. // invoke to reset styles
  2080. if (instance.parent.type.__asyncLoader &&
  2081. instance.parent.ceReload) {
  2082. instance.parent.ceReload(newComp.styles);
  2083. }
  2084. }
  2085. else if (instance.appContext.reload) {
  2086. // root instance mounted via createApp() has a reload method
  2087. instance.appContext.reload();
  2088. }
  2089. else if (typeof window !== 'undefined') {
  2090. // root instance inside tree created via raw render(). Force reload.
  2091. window.location.reload();
  2092. }
  2093. else {
  2094. console.warn('[HMR] Root or manually mounted instance modified. Full reload required.');
  2095. }
  2096. }
  2097. // 5. make sure to cleanup dirty hmr components after update
  2098. queuePostFlushCb(() => {
  2099. for (const instance of instances) {
  2100. hmrDirtyComponents.delete(normalizeClassComponent(instance.type));
  2101. }
  2102. });
  2103. }
  2104. function updateComponentDef(oldComp, newComp) {
  2105. extend(oldComp, newComp);
  2106. for (const key in oldComp) {
  2107. if (key !== '__file' && !(key in newComp)) {
  2108. delete oldComp[key];
  2109. }
  2110. }
  2111. }
  2112. function tryWrap(fn) {
  2113. return (id, arg) => {
  2114. try {
  2115. return fn(id, arg);
  2116. }
  2117. catch (e) {
  2118. console.error(e);
  2119. console.warn(`[HMR] Something went wrong during Vue component hot-reload. ` +
  2120. `Full reload required.`);
  2121. }
  2122. };
  2123. }
  2124. let buffer = [];
  2125. let devtoolsNotInstalled = false;
  2126. function emit(event, ...args) {
  2127. if (exports.devtools) {
  2128. exports.devtools.emit(event, ...args);
  2129. }
  2130. else if (!devtoolsNotInstalled) {
  2131. buffer.push({ event, args });
  2132. }
  2133. }
  2134. function setDevtoolsHook(hook, target) {
  2135. var _a, _b;
  2136. exports.devtools = hook;
  2137. if (exports.devtools) {
  2138. exports.devtools.enabled = true;
  2139. buffer.forEach(({ event, args }) => exports.devtools.emit(event, ...args));
  2140. buffer = [];
  2141. }
  2142. else if (
  2143. // handle late devtools injection - only do this if we are in an actual
  2144. // browser environment to avoid the timer handle stalling test runner exit
  2145. // (#4815)
  2146. typeof window !== 'undefined' &&
  2147. // some envs mock window but not fully
  2148. window.HTMLElement &&
  2149. // also exclude jsdom
  2150. !((_b = (_a = window.navigator) === null || _a === void 0 ? void 0 : _a.userAgent) === null || _b === void 0 ? void 0 : _b.includes('jsdom'))) {
  2151. const replay = (target.__VUE_DEVTOOLS_HOOK_REPLAY__ =
  2152. target.__VUE_DEVTOOLS_HOOK_REPLAY__ || []);
  2153. replay.push((newHook) => {
  2154. setDevtoolsHook(newHook, target);
  2155. });
  2156. // clear buffer after 3s - the user probably doesn't have devtools installed
  2157. // at all, and keeping the buffer will cause memory leaks (#4738)
  2158. setTimeout(() => {
  2159. if (!exports.devtools) {
  2160. target.__VUE_DEVTOOLS_HOOK_REPLAY__ = null;
  2161. devtoolsNotInstalled = true;
  2162. buffer = [];
  2163. }
  2164. }, 3000);
  2165. }
  2166. else {
  2167. // non-browser env, assume not installed
  2168. devtoolsNotInstalled = true;
  2169. buffer = [];
  2170. }
  2171. }
  2172. function devtoolsInitApp(app, version) {
  2173. emit("app:init" /* APP_INIT */, app, version, {
  2174. Fragment,
  2175. Text,
  2176. Comment,
  2177. Static
  2178. });
  2179. }
  2180. function devtoolsUnmountApp(app) {
  2181. emit("app:unmount" /* APP_UNMOUNT */, app);
  2182. }
  2183. const devtoolsComponentAdded = /*#__PURE__*/ createDevtoolsComponentHook("component:added" /* COMPONENT_ADDED */);
  2184. const devtoolsComponentUpdated =
  2185. /*#__PURE__*/ createDevtoolsComponentHook("component:updated" /* COMPONENT_UPDATED */);
  2186. const devtoolsComponentRemoved =
  2187. /*#__PURE__*/ createDevtoolsComponentHook("component:removed" /* COMPONENT_REMOVED */);
  2188. function createDevtoolsComponentHook(hook) {
  2189. return (component) => {
  2190. emit(hook, component.appContext.app, component.uid, component.parent ? component.parent.uid : undefined, component);
  2191. };
  2192. }
  2193. const devtoolsPerfStart = /*#__PURE__*/ createDevtoolsPerformanceHook("perf:start" /* PERFORMANCE_START */);
  2194. const devtoolsPerfEnd = /*#__PURE__*/ createDevtoolsPerformanceHook("perf:end" /* PERFORMANCE_END */);
  2195. function createDevtoolsPerformanceHook(hook) {
  2196. return (component, type, time) => {
  2197. emit(hook, component.appContext.app, component.uid, component, type, time);
  2198. };
  2199. }
  2200. function devtoolsComponentEmit(component, event, params) {
  2201. emit("component:emit" /* COMPONENT_EMIT */, component.appContext.app, component, event, params);
  2202. }
  2203. function emit$1(instance, event, ...rawArgs) {
  2204. if (instance.isUnmounted)
  2205. return;
  2206. const props = instance.vnode.props || EMPTY_OBJ;
  2207. {
  2208. const { emitsOptions, propsOptions: [propsOptions] } = instance;
  2209. if (emitsOptions) {
  2210. if (!(event in emitsOptions) &&
  2211. !(false )) {
  2212. if (!propsOptions || !(toHandlerKey(event) in propsOptions)) {
  2213. warn$1(`Component emitted event "${event}" but it is neither declared in ` +
  2214. `the emits option nor as an "${toHandlerKey(event)}" prop.`);
  2215. }
  2216. }
  2217. else {
  2218. const validator = emitsOptions[event];
  2219. if (isFunction(validator)) {
  2220. const isValid = validator(...rawArgs);
  2221. if (!isValid) {
  2222. warn$1(`Invalid event arguments: event validation failed for event "${event}".`);
  2223. }
  2224. }
  2225. }
  2226. }
  2227. }
  2228. let args = rawArgs;
  2229. const isModelListener = event.startsWith('update:');
  2230. // for v-model update:xxx events, apply modifiers on args
  2231. const modelArg = isModelListener && event.slice(7);
  2232. if (modelArg && modelArg in props) {
  2233. const modifiersKey = `${modelArg === 'modelValue' ? 'model' : modelArg}Modifiers`;
  2234. const { number, trim } = props[modifiersKey] || EMPTY_OBJ;
  2235. if (trim) {
  2236. args = rawArgs.map(a => a.trim());
  2237. }
  2238. if (number) {
  2239. args = rawArgs.map(toNumber);
  2240. }
  2241. }
  2242. {
  2243. devtoolsComponentEmit(instance, event, args);
  2244. }
  2245. {
  2246. const lowerCaseEvent = event.toLowerCase();
  2247. if (lowerCaseEvent !== event && props[toHandlerKey(lowerCaseEvent)]) {
  2248. warn$1(`Event "${lowerCaseEvent}" is emitted in component ` +
  2249. `${formatComponentName(instance, instance.type)} but the handler is registered for "${event}". ` +
  2250. `Note that HTML attributes are case-insensitive and you cannot use ` +
  2251. `v-on to listen to camelCase events when using in-DOM templates. ` +
  2252. `You should probably use "${hyphenate(event)}" instead of "${event}".`);
  2253. }
  2254. }
  2255. let handlerName;
  2256. let handler = props[(handlerName = toHandlerKey(event))] ||
  2257. // also try camelCase event handler (#2249)
  2258. props[(handlerName = toHandlerKey(camelize(event)))];
  2259. // for v-model update:xxx events, also trigger kebab-case equivalent
  2260. // for props passed via kebab-case
  2261. if (!handler && isModelListener) {
  2262. handler = props[(handlerName = toHandlerKey(hyphenate(event)))];
  2263. }
  2264. if (handler) {
  2265. callWithAsyncErrorHandling(handler, instance, 6 /* COMPONENT_EVENT_HANDLER */, args);
  2266. }
  2267. const onceHandler = props[handlerName + `Once`];
  2268. if (onceHandler) {
  2269. if (!instance.emitted) {
  2270. instance.emitted = {};
  2271. }
  2272. else if (instance.emitted[handlerName]) {
  2273. return;
  2274. }
  2275. instance.emitted[handlerName] = true;
  2276. callWithAsyncErrorHandling(onceHandler, instance, 6 /* COMPONENT_EVENT_HANDLER */, args);
  2277. }
  2278. }
  2279. function normalizeEmitsOptions(comp, appContext, asMixin = false) {
  2280. const cache = appContext.emitsCache;
  2281. const cached = cache.get(comp);
  2282. if (cached !== undefined) {
  2283. return cached;
  2284. }
  2285. const raw = comp.emits;
  2286. let normalized = {};
  2287. // apply mixin/extends props
  2288. let hasExtends = false;
  2289. if (!isFunction(comp)) {
  2290. const extendEmits = (raw) => {
  2291. const normalizedFromExtend = normalizeEmitsOptions(raw, appContext, true);
  2292. if (normalizedFromExtend) {
  2293. hasExtends = true;
  2294. extend(normalized, normalizedFromExtend);
  2295. }
  2296. };
  2297. if (!asMixin && appContext.mixins.length) {
  2298. appContext.mixins.forEach(extendEmits);
  2299. }
  2300. if (comp.extends) {
  2301. extendEmits(comp.extends);
  2302. }
  2303. if (comp.mixins) {
  2304. comp.mixins.forEach(extendEmits);
  2305. }
  2306. }
  2307. if (!raw && !hasExtends) {
  2308. cache.set(comp, null);
  2309. return null;
  2310. }
  2311. if (isArray(raw)) {
  2312. raw.forEach(key => (normalized[key] = null));
  2313. }
  2314. else {
  2315. extend(normalized, raw);
  2316. }
  2317. cache.set(comp, normalized);
  2318. return normalized;
  2319. }
  2320. // Check if an incoming prop key is a declared emit event listener.
  2321. // e.g. With `emits: { click: null }`, props named `onClick` and `onclick` are
  2322. // both considered matched listeners.
  2323. function isEmitListener(options, key) {
  2324. if (!options || !isOn(key)) {
  2325. return false;
  2326. }
  2327. key = key.slice(2).replace(/Once$/, '');
  2328. return (hasOwn(options, key[0].toLowerCase() + key.slice(1)) ||
  2329. hasOwn(options, hyphenate(key)) ||
  2330. hasOwn(options, key));
  2331. }
  2332. /**
  2333. * mark the current rendering instance for asset resolution (e.g.
  2334. * resolveComponent, resolveDirective) during render
  2335. */
  2336. let currentRenderingInstance = null;
  2337. let currentScopeId = null;
  2338. /**
  2339. * Note: rendering calls maybe nested. The function returns the parent rendering
  2340. * instance if present, which should be restored after the render is done:
  2341. *
  2342. * ```js
  2343. * const prev = setCurrentRenderingInstance(i)
  2344. * // ...render
  2345. * setCurrentRenderingInstance(prev)
  2346. * ```
  2347. */
  2348. function setCurrentRenderingInstance(instance) {
  2349. const prev = currentRenderingInstance;
  2350. currentRenderingInstance = instance;
  2351. currentScopeId = (instance && instance.type.__scopeId) || null;
  2352. return prev;
  2353. }
  2354. /**
  2355. * Set scope id when creating hoisted vnodes.
  2356. * @private compiler helper
  2357. */
  2358. function pushScopeId(id) {
  2359. currentScopeId = id;
  2360. }
  2361. /**
  2362. * Technically we no longer need this after 3.0.8 but we need to keep the same
  2363. * API for backwards compat w/ code generated by compilers.
  2364. * @private
  2365. */
  2366. function popScopeId() {
  2367. currentScopeId = null;
  2368. }
  2369. /**
  2370. * Only for backwards compat
  2371. * @private
  2372. */
  2373. const withScopeId = (_id) => withCtx;
  2374. /**
  2375. * Wrap a slot function to memoize current rendering instance
  2376. * @private compiler helper
  2377. */
  2378. function withCtx(fn, ctx = currentRenderingInstance, isNonScopedSlot // false only
  2379. ) {
  2380. if (!ctx)
  2381. return fn;
  2382. // already normalized
  2383. if (fn._n) {
  2384. return fn;
  2385. }
  2386. const renderFnWithContext = (...args) => {
  2387. // If a user calls a compiled slot inside a template expression (#1745), it
  2388. // can mess up block tracking, so by default we disable block tracking and
  2389. // force bail out when invoking a compiled slot (indicated by the ._d flag).
  2390. // This isn't necessary if rendering a compiled `<slot>`, so we flip the
  2391. // ._d flag off when invoking the wrapped fn inside `renderSlot`.
  2392. if (renderFnWithContext._d) {
  2393. setBlockTracking(-1);
  2394. }
  2395. const prevInstance = setCurrentRenderingInstance(ctx);
  2396. const res = fn(...args);
  2397. setCurrentRenderingInstance(prevInstance);
  2398. if (renderFnWithContext._d) {
  2399. setBlockTracking(1);
  2400. }
  2401. {
  2402. devtoolsComponentUpdated(ctx);
  2403. }
  2404. return res;
  2405. };
  2406. // mark normalized to avoid duplicated wrapping
  2407. renderFnWithContext._n = true;
  2408. // mark this as compiled by default
  2409. // this is used in vnode.ts -> normalizeChildren() to set the slot
  2410. // rendering flag.
  2411. renderFnWithContext._c = true;
  2412. // disable block tracking by default
  2413. renderFnWithContext._d = true;
  2414. return renderFnWithContext;
  2415. }
  2416. /**
  2417. * dev only flag to track whether $attrs was used during render.
  2418. * If $attrs was used during render then the warning for failed attrs
  2419. * fallthrough can be suppressed.
  2420. */
  2421. let accessedAttrs = false;
  2422. function markAttrsAccessed() {
  2423. accessedAttrs = true;
  2424. }
  2425. function renderComponentRoot(instance) {
  2426. const { type: Component, vnode, proxy, withProxy, props, propsOptions: [propsOptions], slots, attrs, emit, render, renderCache, data, setupState, ctx, inheritAttrs } = instance;
  2427. let result;
  2428. let fallthroughAttrs;
  2429. const prev = setCurrentRenderingInstance(instance);
  2430. {
  2431. accessedAttrs = false;
  2432. }
  2433. try {
  2434. if (vnode.shapeFlag & 4 /* STATEFUL_COMPONENT */) {
  2435. // withProxy is a proxy with a different `has` trap only for
  2436. // runtime-compiled render functions using `with` block.
  2437. const proxyToUse = withProxy || proxy;
  2438. result = normalizeVNode(render.call(proxyToUse, proxyToUse, renderCache, props, setupState, data, ctx));
  2439. fallthroughAttrs = attrs;
  2440. }
  2441. else {
  2442. // functional
  2443. const render = Component;
  2444. // in dev, mark attrs accessed if optional props (attrs === props)
  2445. if (true && attrs === props) {
  2446. markAttrsAccessed();
  2447. }
  2448. result = normalizeVNode(render.length > 1
  2449. ? render(props, true
  2450. ? {
  2451. get attrs() {
  2452. markAttrsAccessed();
  2453. return attrs;
  2454. },
  2455. slots,
  2456. emit
  2457. }
  2458. : { attrs, slots, emit })
  2459. : render(props, null /* we know it doesn't need it */));
  2460. fallthroughAttrs = Component.props
  2461. ? attrs
  2462. : getFunctionalFallthrough(attrs);
  2463. }
  2464. }
  2465. catch (err) {
  2466. blockStack.length = 0;
  2467. handleError(err, instance, 1 /* RENDER_FUNCTION */);
  2468. result = createVNode(Comment);
  2469. }
  2470. // attr merging
  2471. // in dev mode, comments are preserved, and it's possible for a template
  2472. // to have comments along side the root element which makes it a fragment
  2473. let root = result;
  2474. let setRoot = undefined;
  2475. if (result.patchFlag > 0 &&
  2476. result.patchFlag & 2048 /* DEV_ROOT_FRAGMENT */) {
  2477. [root, setRoot] = getChildRoot(result);
  2478. }
  2479. if (fallthroughAttrs && inheritAttrs !== false) {
  2480. const keys = Object.keys(fallthroughAttrs);
  2481. const { shapeFlag } = root;
  2482. if (keys.length) {
  2483. if (shapeFlag & (1 /* ELEMENT */ | 6 /* COMPONENT */)) {
  2484. if (propsOptions && keys.some(isModelListener)) {
  2485. // If a v-model listener (onUpdate:xxx) has a corresponding declared
  2486. // prop, it indicates this component expects to handle v-model and
  2487. // it should not fallthrough.
  2488. // related: #1543, #1643, #1989
  2489. fallthroughAttrs = filterModelListeners(fallthroughAttrs, propsOptions);
  2490. }
  2491. root = cloneVNode(root, fallthroughAttrs);
  2492. }
  2493. else if (!accessedAttrs && root.type !== Comment) {
  2494. const allAttrs = Object.keys(attrs);
  2495. const eventAttrs = [];
  2496. const extraAttrs = [];
  2497. for (let i = 0, l = allAttrs.length; i < l; i++) {
  2498. const key = allAttrs[i];
  2499. if (isOn(key)) {
  2500. // ignore v-model handlers when they fail to fallthrough
  2501. if (!isModelListener(key)) {
  2502. // remove `on`, lowercase first letter to reflect event casing
  2503. // accurately
  2504. eventAttrs.push(key[2].toLowerCase() + key.slice(3));
  2505. }
  2506. }
  2507. else {
  2508. extraAttrs.push(key);
  2509. }
  2510. }
  2511. if (extraAttrs.length) {
  2512. warn$1(`Extraneous non-props attributes (` +
  2513. `${extraAttrs.join(', ')}) ` +
  2514. `were passed to component but could not be automatically inherited ` +
  2515. `because component renders fragment or text root nodes.`);
  2516. }
  2517. if (eventAttrs.length) {
  2518. warn$1(`Extraneous non-emits event listeners (` +
  2519. `${eventAttrs.join(', ')}) ` +
  2520. `were passed to component but could not be automatically inherited ` +
  2521. `because component renders fragment or text root nodes. ` +
  2522. `If the listener is intended to be a component custom event listener only, ` +
  2523. `declare it using the "emits" option.`);
  2524. }
  2525. }
  2526. }
  2527. }
  2528. // inherit directives
  2529. if (vnode.dirs) {
  2530. if (!isElementRoot(root)) {
  2531. warn$1(`Runtime directive used on component with non-element root node. ` +
  2532. `The directives will not function as intended.`);
  2533. }
  2534. // clone before mutating since the root may be a hoisted vnode
  2535. root = cloneVNode(root);
  2536. root.dirs = root.dirs ? root.dirs.concat(vnode.dirs) : vnode.dirs;
  2537. }
  2538. // inherit transition data
  2539. if (vnode.transition) {
  2540. if (!isElementRoot(root)) {
  2541. warn$1(`Component inside <Transition> renders non-element root node ` +
  2542. `that cannot be animated.`);
  2543. }
  2544. root.transition = vnode.transition;
  2545. }
  2546. if (setRoot) {
  2547. setRoot(root);
  2548. }
  2549. else {
  2550. result = root;
  2551. }
  2552. setCurrentRenderingInstance(prev);
  2553. return result;
  2554. }
  2555. /**
  2556. * dev only
  2557. * In dev mode, template root level comments are rendered, which turns the
  2558. * template into a fragment root, but we need to locate the single element
  2559. * root for attrs and scope id processing.
  2560. */
  2561. const getChildRoot = (vnode) => {
  2562. const rawChildren = vnode.children;
  2563. const dynamicChildren = vnode.dynamicChildren;
  2564. const childRoot = filterSingleRoot(rawChildren);
  2565. if (!childRoot) {
  2566. return [vnode, undefined];
  2567. }
  2568. const index = rawChildren.indexOf(childRoot);
  2569. const dynamicIndex = dynamicChildren ? dynamicChildren.indexOf(childRoot) : -1;
  2570. const setRoot = (updatedRoot) => {
  2571. rawChildren[index] = updatedRoot;
  2572. if (dynamicChildren) {
  2573. if (dynamicIndex > -1) {
  2574. dynamicChildren[dynamicIndex] = updatedRoot;
  2575. }
  2576. else if (updatedRoot.patchFlag > 0) {
  2577. vnode.dynamicChildren = [...dynamicChildren, updatedRoot];
  2578. }
  2579. }
  2580. };
  2581. return [normalizeVNode(childRoot), setRoot];
  2582. };
  2583. function filterSingleRoot(children) {
  2584. let singleRoot;
  2585. for (let i = 0; i < children.length; i++) {
  2586. const child = children[i];
  2587. if (isVNode(child)) {
  2588. // ignore user comment
  2589. if (child.type !== Comment || child.children === 'v-if') {
  2590. if (singleRoot) {
  2591. // has more than 1 non-comment child, return now
  2592. return;
  2593. }
  2594. else {
  2595. singleRoot = child;
  2596. }
  2597. }
  2598. }
  2599. else {
  2600. return;
  2601. }
  2602. }
  2603. return singleRoot;
  2604. }
  2605. const getFunctionalFallthrough = (attrs) => {
  2606. let res;
  2607. for (const key in attrs) {
  2608. if (key === 'class' || key === 'style' || isOn(key)) {
  2609. (res || (res = {}))[key] = attrs[key];
  2610. }
  2611. }
  2612. return res;
  2613. };
  2614. const filterModelListeners = (attrs, props) => {
  2615. const res = {};
  2616. for (const key in attrs) {
  2617. if (!isModelListener(key) || !(key.slice(9) in props)) {
  2618. res[key] = attrs[key];
  2619. }
  2620. }
  2621. return res;
  2622. };
  2623. const isElementRoot = (vnode) => {
  2624. return (vnode.shapeFlag & (6 /* COMPONENT */ | 1 /* ELEMENT */) ||
  2625. vnode.type === Comment // potential v-if branch switch
  2626. );
  2627. };
  2628. function shouldUpdateComponent(prevVNode, nextVNode, optimized) {
  2629. const { props: prevProps, children: prevChildren, component } = prevVNode;
  2630. const { props: nextProps, children: nextChildren, patchFlag } = nextVNode;
  2631. const emits = component.emitsOptions;
  2632. // Parent component's render function was hot-updated. Since this may have
  2633. // caused the child component's slots content to have changed, we need to
  2634. // force the child to update as well.
  2635. if ((prevChildren || nextChildren) && isHmrUpdating) {
  2636. return true;
  2637. }
  2638. // force child update for runtime directive or transition on component vnode.
  2639. if (nextVNode.dirs || nextVNode.transition) {
  2640. return true;
  2641. }
  2642. if (optimized && patchFlag >= 0) {
  2643. if (patchFlag & 1024 /* DYNAMIC_SLOTS */) {
  2644. // slot content that references values that might have changed,
  2645. // e.g. in a v-for
  2646. return true;
  2647. }
  2648. if (patchFlag & 16 /* FULL_PROPS */) {
  2649. if (!prevProps) {
  2650. return !!nextProps;
  2651. }
  2652. // presence of this flag indicates props are always non-null
  2653. return hasPropsChanged(prevProps, nextProps, emits);
  2654. }
  2655. else if (patchFlag & 8 /* PROPS */) {
  2656. const dynamicProps = nextVNode.dynamicProps;
  2657. for (let i = 0; i < dynamicProps.length; i++) {
  2658. const key = dynamicProps[i];
  2659. if (nextProps[key] !== prevProps[key] &&
  2660. !isEmitListener(emits, key)) {
  2661. return true;
  2662. }
  2663. }
  2664. }
  2665. }
  2666. else {
  2667. // this path is only taken by manually written render functions
  2668. // so presence of any children leads to a forced update
  2669. if (prevChildren || nextChildren) {
  2670. if (!nextChildren || !nextChildren.$stable) {
  2671. return true;
  2672. }
  2673. }
  2674. if (prevProps === nextProps) {
  2675. return false;
  2676. }
  2677. if (!prevProps) {
  2678. return !!nextProps;
  2679. }
  2680. if (!nextProps) {
  2681. return true;
  2682. }
  2683. return hasPropsChanged(prevProps, nextProps, emits);
  2684. }
  2685. return false;
  2686. }
  2687. function hasPropsChanged(prevProps, nextProps, emitsOptions) {
  2688. const nextKeys = Object.keys(nextProps);
  2689. if (nextKeys.length !== Object.keys(prevProps).length) {
  2690. return true;
  2691. }
  2692. for (let i = 0; i < nextKeys.length; i++) {
  2693. const key = nextKeys[i];
  2694. if (nextProps[key] !== prevProps[key] &&
  2695. !isEmitListener(emitsOptions, key)) {
  2696. return true;
  2697. }
  2698. }
  2699. return false;
  2700. }
  2701. function updateHOCHostEl({ vnode, parent }, el // HostNode
  2702. ) {
  2703. while (parent && parent.subTree === vnode) {
  2704. (vnode = parent.vnode).el = el;
  2705. parent = parent.parent;
  2706. }
  2707. }
  2708. const isSuspense = (type) => type.__isSuspense;
  2709. // Suspense exposes a component-like API, and is treated like a component
  2710. // in the compiler, but internally it's a special built-in type that hooks
  2711. // directly into the renderer.
  2712. const SuspenseImpl = {
  2713. name: 'Suspense',
  2714. // In order to make Suspense tree-shakable, we need to avoid importing it
  2715. // directly in the renderer. The renderer checks for the __isSuspense flag
  2716. // on a vnode's type and calls the `process` method, passing in renderer
  2717. // internals.
  2718. __isSuspense: true,
  2719. process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized,
  2720. // platform-specific impl passed from renderer
  2721. rendererInternals) {
  2722. if (n1 == null) {
  2723. mountSuspense(n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, rendererInternals);
  2724. }
  2725. else {
  2726. patchSuspense(n1, n2, container, anchor, parentComponent, isSVG, slotScopeIds, optimized, rendererInternals);
  2727. }
  2728. },
  2729. hydrate: hydrateSuspense,
  2730. create: createSuspenseBoundary,
  2731. normalize: normalizeSuspenseChildren
  2732. };
  2733. // Force-casted public typing for h and TSX props inference
  2734. const Suspense = (SuspenseImpl );
  2735. function triggerEvent(vnode, name) {
  2736. const eventListener = vnode.props && vnode.props[name];
  2737. if (isFunction(eventListener)) {
  2738. eventListener();
  2739. }
  2740. }
  2741. function mountSuspense(vnode, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, rendererInternals) {
  2742. const { p: patch, o: { createElement } } = rendererInternals;
  2743. const hiddenContainer = createElement('div');
  2744. const suspense = (vnode.suspense = createSuspenseBoundary(vnode, parentSuspense, parentComponent, container, hiddenContainer, anchor, isSVG, slotScopeIds, optimized, rendererInternals));
  2745. // start mounting the content subtree in an off-dom container
  2746. patch(null, (suspense.pendingBranch = vnode.ssContent), hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds);
  2747. // now check if we have encountered any async deps
  2748. if (suspense.deps > 0) {
  2749. // has async
  2750. // invoke @fallback event
  2751. triggerEvent(vnode, 'onPending');
  2752. triggerEvent(vnode, 'onFallback');
  2753. // mount the fallback tree
  2754. patch(null, vnode.ssFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2755. isSVG, slotScopeIds);
  2756. setActiveBranch(suspense, vnode.ssFallback);
  2757. }
  2758. else {
  2759. // Suspense has no async deps. Just resolve.
  2760. suspense.resolve();
  2761. }
  2762. }
  2763. function patchSuspense(n1, n2, container, anchor, parentComponent, isSVG, slotScopeIds, optimized, { p: patch, um: unmount, o: { createElement } }) {
  2764. const suspense = (n2.suspense = n1.suspense);
  2765. suspense.vnode = n2;
  2766. n2.el = n1.el;
  2767. const newBranch = n2.ssContent;
  2768. const newFallback = n2.ssFallback;
  2769. const { activeBranch, pendingBranch, isInFallback, isHydrating } = suspense;
  2770. if (pendingBranch) {
  2771. suspense.pendingBranch = newBranch;
  2772. if (isSameVNodeType(newBranch, pendingBranch)) {
  2773. // same root type but content may have changed.
  2774. patch(pendingBranch, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2775. if (suspense.deps <= 0) {
  2776. suspense.resolve();
  2777. }
  2778. else if (isInFallback) {
  2779. patch(activeBranch, newFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2780. isSVG, slotScopeIds, optimized);
  2781. setActiveBranch(suspense, newFallback);
  2782. }
  2783. }
  2784. else {
  2785. // toggled before pending tree is resolved
  2786. suspense.pendingId++;
  2787. if (isHydrating) {
  2788. // if toggled before hydration is finished, the current DOM tree is
  2789. // no longer valid. set it as the active branch so it will be unmounted
  2790. // when resolved
  2791. suspense.isHydrating = false;
  2792. suspense.activeBranch = pendingBranch;
  2793. }
  2794. else {
  2795. unmount(pendingBranch, parentComponent, suspense);
  2796. }
  2797. // increment pending ID. this is used to invalidate async callbacks
  2798. // reset suspense state
  2799. suspense.deps = 0;
  2800. // discard effects from pending branch
  2801. suspense.effects.length = 0;
  2802. // discard previous container
  2803. suspense.hiddenContainer = createElement('div');
  2804. if (isInFallback) {
  2805. // already in fallback state
  2806. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2807. if (suspense.deps <= 0) {
  2808. suspense.resolve();
  2809. }
  2810. else {
  2811. patch(activeBranch, newFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2812. isSVG, slotScopeIds, optimized);
  2813. setActiveBranch(suspense, newFallback);
  2814. }
  2815. }
  2816. else if (activeBranch && isSameVNodeType(newBranch, activeBranch)) {
  2817. // toggled "back" to current active branch
  2818. patch(activeBranch, newBranch, container, anchor, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2819. // force resolve
  2820. suspense.resolve(true);
  2821. }
  2822. else {
  2823. // switched to a 3rd branch
  2824. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2825. if (suspense.deps <= 0) {
  2826. suspense.resolve();
  2827. }
  2828. }
  2829. }
  2830. }
  2831. else {
  2832. if (activeBranch && isSameVNodeType(newBranch, activeBranch)) {
  2833. // root did not change, just normal patch
  2834. patch(activeBranch, newBranch, container, anchor, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2835. setActiveBranch(suspense, newBranch);
  2836. }
  2837. else {
  2838. // root node toggled
  2839. // invoke @pending event
  2840. triggerEvent(n2, 'onPending');
  2841. // mount pending branch in off-dom container
  2842. suspense.pendingBranch = newBranch;
  2843. suspense.pendingId++;
  2844. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2845. if (suspense.deps <= 0) {
  2846. // incoming branch has no async deps, resolve now.
  2847. suspense.resolve();
  2848. }
  2849. else {
  2850. const { timeout, pendingId } = suspense;
  2851. if (timeout > 0) {
  2852. setTimeout(() => {
  2853. if (suspense.pendingId === pendingId) {
  2854. suspense.fallback(newFallback);
  2855. }
  2856. }, timeout);
  2857. }
  2858. else if (timeout === 0) {
  2859. suspense.fallback(newFallback);
  2860. }
  2861. }
  2862. }
  2863. }
  2864. }
  2865. let hasWarned = false;
  2866. function createSuspenseBoundary(vnode, parent, parentComponent, container, hiddenContainer, anchor, isSVG, slotScopeIds, optimized, rendererInternals, isHydrating = false) {
  2867. /* istanbul ignore if */
  2868. if (!hasWarned) {
  2869. hasWarned = true;
  2870. // @ts-ignore `console.info` cannot be null error
  2871. console[console.info ? 'info' : 'log'](`<Suspense> is an experimental feature and its API will likely change.`);
  2872. }
  2873. const { p: patch, m: move, um: unmount, n: next, o: { parentNode, remove } } = rendererInternals;
  2874. const timeout = toNumber(vnode.props && vnode.props.timeout);
  2875. const suspense = {
  2876. vnode,
  2877. parent,
  2878. parentComponent,
  2879. isSVG,
  2880. container,
  2881. hiddenContainer,
  2882. anchor,
  2883. deps: 0,
  2884. pendingId: 0,
  2885. timeout: typeof timeout === 'number' ? timeout : -1,
  2886. activeBranch: null,
  2887. pendingBranch: null,
  2888. isInFallback: true,
  2889. isHydrating,
  2890. isUnmounted: false,
  2891. effects: [],
  2892. resolve(resume = false) {
  2893. {
  2894. if (!resume && !suspense.pendingBranch) {
  2895. throw new Error(`suspense.resolve() is called without a pending branch.`);
  2896. }
  2897. if (suspense.isUnmounted) {
  2898. throw new Error(`suspense.resolve() is called on an already unmounted suspense boundary.`);
  2899. }
  2900. }
  2901. const { vnode, activeBranch, pendingBranch, pendingId, effects, parentComponent, container } = suspense;
  2902. if (suspense.isHydrating) {
  2903. suspense.isHydrating = false;
  2904. }
  2905. else if (!resume) {
  2906. const delayEnter = activeBranch &&
  2907. pendingBranch.transition &&
  2908. pendingBranch.transition.mode === 'out-in';
  2909. if (delayEnter) {
  2910. activeBranch.transition.afterLeave = () => {
  2911. if (pendingId === suspense.pendingId) {
  2912. move(pendingBranch, container, anchor, 0 /* ENTER */);
  2913. }
  2914. };
  2915. }
  2916. // this is initial anchor on mount
  2917. let { anchor } = suspense;
  2918. // unmount current active tree
  2919. if (activeBranch) {
  2920. // if the fallback tree was mounted, it may have been moved
  2921. // as part of a parent suspense. get the latest anchor for insertion
  2922. anchor = next(activeBranch);
  2923. unmount(activeBranch, parentComponent, suspense, true);
  2924. }
  2925. if (!delayEnter) {
  2926. // move content from off-dom container to actual container
  2927. move(pendingBranch, container, anchor, 0 /* ENTER */);
  2928. }
  2929. }
  2930. setActiveBranch(suspense, pendingBranch);
  2931. suspense.pendingBranch = null;
  2932. suspense.isInFallback = false;
  2933. // flush buffered effects
  2934. // check if there is a pending parent suspense
  2935. let parent = suspense.parent;
  2936. let hasUnresolvedAncestor = false;
  2937. while (parent) {
  2938. if (parent.pendingBranch) {
  2939. // found a pending parent suspense, merge buffered post jobs
  2940. // into that parent
  2941. parent.effects.push(...effects);
  2942. hasUnresolvedAncestor = true;
  2943. break;
  2944. }
  2945. parent = parent.parent;
  2946. }
  2947. // no pending parent suspense, flush all jobs
  2948. if (!hasUnresolvedAncestor) {
  2949. queuePostFlushCb(effects);
  2950. }
  2951. suspense.effects = [];
  2952. // invoke @resolve event
  2953. triggerEvent(vnode, 'onResolve');
  2954. },
  2955. fallback(fallbackVNode) {
  2956. if (!suspense.pendingBranch) {
  2957. return;
  2958. }
  2959. const { vnode, activeBranch, parentComponent, container, isSVG } = suspense;
  2960. // invoke @fallback event
  2961. triggerEvent(vnode, 'onFallback');
  2962. const anchor = next(activeBranch);
  2963. const mountFallback = () => {
  2964. if (!suspense.isInFallback) {
  2965. return;
  2966. }
  2967. // mount the fallback tree
  2968. patch(null, fallbackVNode, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2969. isSVG, slotScopeIds, optimized);
  2970. setActiveBranch(suspense, fallbackVNode);
  2971. };
  2972. const delayEnter = fallbackVNode.transition && fallbackVNode.transition.mode === 'out-in';
  2973. if (delayEnter) {
  2974. activeBranch.transition.afterLeave = mountFallback;
  2975. }
  2976. suspense.isInFallback = true;
  2977. // unmount current active branch
  2978. unmount(activeBranch, parentComponent, null, // no suspense so unmount hooks fire now
  2979. true // shouldRemove
  2980. );
  2981. if (!delayEnter) {
  2982. mountFallback();
  2983. }
  2984. },
  2985. move(container, anchor, type) {
  2986. suspense.activeBranch &&
  2987. move(suspense.activeBranch, container, anchor, type);
  2988. suspense.container = container;
  2989. },
  2990. next() {
  2991. return suspense.activeBranch && next(suspense.activeBranch);
  2992. },
  2993. registerDep(instance, setupRenderEffect) {
  2994. const isInPendingSuspense = !!suspense.pendingBranch;
  2995. if (isInPendingSuspense) {
  2996. suspense.deps++;
  2997. }
  2998. const hydratedEl = instance.vnode.el;
  2999. instance
  3000. .asyncDep.catch(err => {
  3001. handleError(err, instance, 0 /* SETUP_FUNCTION */);
  3002. })
  3003. .then(asyncSetupResult => {
  3004. // retry when the setup() promise resolves.
  3005. // component may have been unmounted before resolve.
  3006. if (instance.isUnmounted ||
  3007. suspense.isUnmounted ||
  3008. suspense.pendingId !== instance.suspenseId) {
  3009. return;
  3010. }
  3011. // retry from this component
  3012. instance.asyncResolved = true;
  3013. const { vnode } = instance;
  3014. {
  3015. pushWarningContext(vnode);
  3016. }
  3017. handleSetupResult(instance, asyncSetupResult, false);
  3018. if (hydratedEl) {
  3019. // vnode may have been replaced if an update happened before the
  3020. // async dep is resolved.
  3021. vnode.el = hydratedEl;
  3022. }
  3023. const placeholder = !hydratedEl && instance.subTree.el;
  3024. setupRenderEffect(instance, vnode,
  3025. // component may have been moved before resolve.
  3026. // if this is not a hydration, instance.subTree will be the comment
  3027. // placeholder.
  3028. parentNode(hydratedEl || instance.subTree.el),
  3029. // anchor will not be used if this is hydration, so only need to
  3030. // consider the comment placeholder case.
  3031. hydratedEl ? null : next(instance.subTree), suspense, isSVG, optimized);
  3032. if (placeholder) {
  3033. remove(placeholder);
  3034. }
  3035. updateHOCHostEl(instance, vnode.el);
  3036. {
  3037. popWarningContext();
  3038. }
  3039. // only decrease deps count if suspense is not already resolved
  3040. if (isInPendingSuspense && --suspense.deps === 0) {
  3041. suspense.resolve();
  3042. }
  3043. });
  3044. },
  3045. unmount(parentSuspense, doRemove) {
  3046. suspense.isUnmounted = true;
  3047. if (suspense.activeBranch) {
  3048. unmount(suspense.activeBranch, parentComponent, parentSuspense, doRemove);
  3049. }
  3050. if (suspense.pendingBranch) {
  3051. unmount(suspense.pendingBranch, parentComponent, parentSuspense, doRemove);
  3052. }
  3053. }
  3054. };
  3055. return suspense;
  3056. }
  3057. function hydrateSuspense(node, vnode, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, rendererInternals, hydrateNode) {
  3058. /* eslint-disable no-restricted-globals */
  3059. const suspense = (vnode.suspense = createSuspenseBoundary(vnode, parentSuspense, parentComponent, node.parentNode, document.createElement('div'), null, isSVG, slotScopeIds, optimized, rendererInternals, true /* hydrating */));
  3060. // there are two possible scenarios for server-rendered suspense:
  3061. // - success: ssr content should be fully resolved
  3062. // - failure: ssr content should be the fallback branch.
  3063. // however, on the client we don't really know if it has failed or not
  3064. // attempt to hydrate the DOM assuming it has succeeded, but we still
  3065. // need to construct a suspense boundary first
  3066. const result = hydrateNode(node, (suspense.pendingBranch = vnode.ssContent), parentComponent, suspense, slotScopeIds, optimized);
  3067. if (suspense.deps === 0) {
  3068. suspense.resolve();
  3069. }
  3070. return result;
  3071. /* eslint-enable no-restricted-globals */
  3072. }
  3073. function normalizeSuspenseChildren(vnode) {
  3074. const { shapeFlag, children } = vnode;
  3075. const isSlotChildren = shapeFlag & 32 /* SLOTS_CHILDREN */;
  3076. vnode.ssContent = normalizeSuspenseSlot(isSlotChildren ? children.default : children);
  3077. vnode.ssFallback = isSlotChildren
  3078. ? normalizeSuspenseSlot(children.fallback)
  3079. : createVNode(Comment);
  3080. }
  3081. function normalizeSuspenseSlot(s) {
  3082. let block;
  3083. if (isFunction(s)) {
  3084. const trackBlock = isBlockTreeEnabled && s._c;
  3085. if (trackBlock) {
  3086. // disableTracking: false
  3087. // allow block tracking for compiled slots
  3088. // (see ./componentRenderContext.ts)
  3089. s._d = false;
  3090. openBlock();
  3091. }
  3092. s = s();
  3093. if (trackBlock) {
  3094. s._d = true;
  3095. block = currentBlock;
  3096. closeBlock();
  3097. }
  3098. }
  3099. if (isArray(s)) {
  3100. const singleChild = filterSingleRoot(s);
  3101. if (!singleChild) {
  3102. warn$1(`<Suspense> slots expect a single root node.`);
  3103. }
  3104. s = singleChild;
  3105. }
  3106. s = normalizeVNode(s);
  3107. if (block && !s.dynamicChildren) {
  3108. s.dynamicChildren = block.filter(c => c !== s);
  3109. }
  3110. return s;
  3111. }
  3112. function queueEffectWithSuspense(fn, suspense) {
  3113. if (suspense && suspense.pendingBranch) {
  3114. if (isArray(fn)) {
  3115. suspense.effects.push(...fn);
  3116. }
  3117. else {
  3118. suspense.effects.push(fn);
  3119. }
  3120. }
  3121. else {
  3122. queuePostFlushCb(fn);
  3123. }
  3124. }
  3125. function setActiveBranch(suspense, branch) {
  3126. suspense.activeBranch = branch;
  3127. const { vnode, parentComponent } = suspense;
  3128. const el = (vnode.el = branch.el);
  3129. // in case suspense is the root node of a component,
  3130. // recursively update the HOC el
  3131. if (parentComponent && parentComponent.subTree === vnode) {
  3132. parentComponent.vnode.el = el;
  3133. updateHOCHostEl(parentComponent, el);
  3134. }
  3135. }
  3136. function provide(key, value) {
  3137. if (!currentInstance) {
  3138. {
  3139. warn$1(`provide() can only be used inside setup().`);
  3140. }
  3141. }
  3142. else {
  3143. let provides = currentInstance.provides;
  3144. // by default an instance inherits its parent's provides object
  3145. // but when it needs to provide values of its own, it creates its
  3146. // own provides object using parent provides object as prototype.
  3147. // this way in `inject` we can simply look up injections from direct
  3148. // parent and let the prototype chain do the work.
  3149. const parentProvides = currentInstance.parent && currentInstance.parent.provides;
  3150. if (parentProvides === provides) {
  3151. provides = currentInstance.provides = Object.create(parentProvides);
  3152. }
  3153. // TS doesn't allow symbol as index type
  3154. provides[key] = value;
  3155. }
  3156. }
  3157. function inject(key, defaultValue, treatDefaultAsFactory = false) {
  3158. // fallback to `currentRenderingInstance` so that this can be called in
  3159. // a functional component
  3160. const instance = currentInstance || currentRenderingInstance;
  3161. if (instance) {
  3162. // #2400
  3163. // to support `app.use` plugins,
  3164. // fallback to appContext's `provides` if the instance is at root
  3165. const provides = instance.parent == null
  3166. ? instance.vnode.appContext && instance.vnode.appContext.provides
  3167. : instance.parent.provides;
  3168. if (provides && key in provides) {
  3169. // TS doesn't allow symbol as index type
  3170. return provides[key];
  3171. }
  3172. else if (arguments.length > 1) {
  3173. return treatDefaultAsFactory && isFunction(defaultValue)
  3174. ? defaultValue.call(instance.proxy)
  3175. : defaultValue;
  3176. }
  3177. else {
  3178. warn$1(`injection "${String(key)}" not found.`);
  3179. }
  3180. }
  3181. else {
  3182. warn$1(`inject() can only be used inside setup() or functional components.`);
  3183. }
  3184. }
  3185. // Simple effect.
  3186. function watchEffect(effect, options) {
  3187. return doWatch(effect, null, options);
  3188. }
  3189. function watchPostEffect(effect, options) {
  3190. return doWatch(effect, null, (Object.assign(Object.assign({}, options), { flush: 'post' }) ));
  3191. }
  3192. function watchSyncEffect(effect, options) {
  3193. return doWatch(effect, null, (Object.assign(Object.assign({}, options), { flush: 'sync' }) ));
  3194. }
  3195. // initial value for watchers to trigger on undefined initial values
  3196. const INITIAL_WATCHER_VALUE = {};
  3197. // implementation
  3198. function watch(source, cb, options) {
  3199. if (!isFunction(cb)) {
  3200. warn$1(`\`watch(fn, options?)\` signature has been moved to a separate API. ` +
  3201. `Use \`watchEffect(fn, options?)\` instead. \`watch\` now only ` +
  3202. `supports \`watch(source, cb, options?) signature.`);
  3203. }
  3204. return doWatch(source, cb, options);
  3205. }
  3206. function doWatch(source, cb, { immediate, deep, flush, onTrack, onTrigger } = EMPTY_OBJ) {
  3207. if (!cb) {
  3208. if (immediate !== undefined) {
  3209. warn$1(`watch() "immediate" option is only respected when using the ` +
  3210. `watch(source, callback, options?) signature.`);
  3211. }
  3212. if (deep !== undefined) {
  3213. warn$1(`watch() "deep" option is only respected when using the ` +
  3214. `watch(source, callback, options?) signature.`);
  3215. }
  3216. }
  3217. const warnInvalidSource = (s) => {
  3218. warn$1(`Invalid watch source: `, s, `A watch source can only be a getter/effect function, a ref, ` +
  3219. `a reactive object, or an array of these types.`);
  3220. };
  3221. const instance = currentInstance;
  3222. let getter;
  3223. let forceTrigger = false;
  3224. let isMultiSource = false;
  3225. if (isRef(source)) {
  3226. getter = () => source.value;
  3227. forceTrigger = isShallow(source);
  3228. }
  3229. else if (isReactive(source)) {
  3230. getter = () => source;
  3231. deep = true;
  3232. }
  3233. else if (isArray(source)) {
  3234. isMultiSource = true;
  3235. forceTrigger = source.some(s => isReactive(s) || isShallow(s));
  3236. getter = () => source.map(s => {
  3237. if (isRef(s)) {
  3238. return s.value;
  3239. }
  3240. else if (isReactive(s)) {
  3241. return traverse(s);
  3242. }
  3243. else if (isFunction(s)) {
  3244. return callWithErrorHandling(s, instance, 2 /* WATCH_GETTER */);
  3245. }
  3246. else {
  3247. warnInvalidSource(s);
  3248. }
  3249. });
  3250. }
  3251. else if (isFunction(source)) {
  3252. if (cb) {
  3253. // getter with cb
  3254. getter = () => callWithErrorHandling(source, instance, 2 /* WATCH_GETTER */);
  3255. }
  3256. else {
  3257. // no cb -> simple effect
  3258. getter = () => {
  3259. if (instance && instance.isUnmounted) {
  3260. return;
  3261. }
  3262. if (cleanup) {
  3263. cleanup();
  3264. }
  3265. return callWithAsyncErrorHandling(source, instance, 3 /* WATCH_CALLBACK */, [onCleanup]);
  3266. };
  3267. }
  3268. }
  3269. else {
  3270. getter = NOOP;
  3271. warnInvalidSource(source);
  3272. }
  3273. if (cb && deep) {
  3274. const baseGetter = getter;
  3275. getter = () => traverse(baseGetter());
  3276. }
  3277. let cleanup;
  3278. let onCleanup = (fn) => {
  3279. cleanup = effect.onStop = () => {
  3280. callWithErrorHandling(fn, instance, 4 /* WATCH_CLEANUP */);
  3281. };
  3282. };
  3283. let oldValue = isMultiSource ? [] : INITIAL_WATCHER_VALUE;
  3284. const job = () => {
  3285. if (!effect.active) {
  3286. return;
  3287. }
  3288. if (cb) {
  3289. // watch(source, cb)
  3290. const newValue = effect.run();
  3291. if (deep ||
  3292. forceTrigger ||
  3293. (isMultiSource
  3294. ? newValue.some((v, i) => hasChanged(v, oldValue[i]))
  3295. : hasChanged(newValue, oldValue)) ||
  3296. (false )) {
  3297. // cleanup before running cb again
  3298. if (cleanup) {
  3299. cleanup();
  3300. }
  3301. callWithAsyncErrorHandling(cb, instance, 3 /* WATCH_CALLBACK */, [
  3302. newValue,
  3303. // pass undefined as the old value when it's changed for the first time
  3304. oldValue === INITIAL_WATCHER_VALUE ? undefined : oldValue,
  3305. onCleanup
  3306. ]);
  3307. oldValue = newValue;
  3308. }
  3309. }
  3310. else {
  3311. // watchEffect
  3312. effect.run();
  3313. }
  3314. };
  3315. // important: mark the job as a watcher callback so that scheduler knows
  3316. // it is allowed to self-trigger (#1727)
  3317. job.allowRecurse = !!cb;
  3318. let scheduler;
  3319. if (flush === 'sync') {
  3320. scheduler = job; // the scheduler function gets called directly
  3321. }
  3322. else if (flush === 'post') {
  3323. scheduler = () => queuePostRenderEffect(job, instance && instance.suspense);
  3324. }
  3325. else {
  3326. // default: 'pre'
  3327. scheduler = () => queuePreFlushCb(job);
  3328. }
  3329. const effect = new ReactiveEffect(getter, scheduler);
  3330. {
  3331. effect.onTrack = onTrack;
  3332. effect.onTrigger = onTrigger;
  3333. }
  3334. // initial run
  3335. if (cb) {
  3336. if (immediate) {
  3337. job();
  3338. }
  3339. else {
  3340. oldValue = effect.run();
  3341. }
  3342. }
  3343. else if (flush === 'post') {
  3344. queuePostRenderEffect(effect.run.bind(effect), instance && instance.suspense);
  3345. }
  3346. else {
  3347. effect.run();
  3348. }
  3349. return () => {
  3350. effect.stop();
  3351. if (instance && instance.scope) {
  3352. remove(instance.scope.effects, effect);
  3353. }
  3354. };
  3355. }
  3356. // this.$watch
  3357. function instanceWatch(source, value, options) {
  3358. const publicThis = this.proxy;
  3359. const getter = isString(source)
  3360. ? source.includes('.')
  3361. ? createPathGetter(publicThis, source)
  3362. : () => publicThis[source]
  3363. : source.bind(publicThis, publicThis);
  3364. let cb;
  3365. if (isFunction(value)) {
  3366. cb = value;
  3367. }
  3368. else {
  3369. cb = value.handler;
  3370. options = value;
  3371. }
  3372. const cur = currentInstance;
  3373. setCurrentInstance(this);
  3374. const res = doWatch(getter, cb.bind(publicThis), options);
  3375. if (cur) {
  3376. setCurrentInstance(cur);
  3377. }
  3378. else {
  3379. unsetCurrentInstance();
  3380. }
  3381. return res;
  3382. }
  3383. function createPathGetter(ctx, path) {
  3384. const segments = path.split('.');
  3385. return () => {
  3386. let cur = ctx;
  3387. for (let i = 0; i < segments.length && cur; i++) {
  3388. cur = cur[segments[i]];
  3389. }
  3390. return cur;
  3391. };
  3392. }
  3393. function traverse(value, seen) {
  3394. if (!isObject(value) || value["__v_skip" /* SKIP */]) {
  3395. return value;
  3396. }
  3397. seen = seen || new Set();
  3398. if (seen.has(value)) {
  3399. return value;
  3400. }
  3401. seen.add(value);
  3402. if (isRef(value)) {
  3403. traverse(value.value, seen);
  3404. }
  3405. else if (isArray(value)) {
  3406. for (let i = 0; i < value.length; i++) {
  3407. traverse(value[i], seen);
  3408. }
  3409. }
  3410. else if (isSet(value) || isMap(value)) {
  3411. value.forEach((v) => {
  3412. traverse(v, seen);
  3413. });
  3414. }
  3415. else if (isPlainObject(value)) {
  3416. for (const key in value) {
  3417. traverse(value[key], seen);
  3418. }
  3419. }
  3420. return value;
  3421. }
  3422. function useTransitionState() {
  3423. const state = {
  3424. isMounted: false,
  3425. isLeaving: false,
  3426. isUnmounting: false,
  3427. leavingVNodes: new Map()
  3428. };
  3429. onMounted(() => {
  3430. state.isMounted = true;
  3431. });
  3432. onBeforeUnmount(() => {
  3433. state.isUnmounting = true;
  3434. });
  3435. return state;
  3436. }
  3437. const TransitionHookValidator = [Function, Array];
  3438. const BaseTransitionImpl = {
  3439. name: `BaseTransition`,
  3440. props: {
  3441. mode: String,
  3442. appear: Boolean,
  3443. persisted: Boolean,
  3444. // enter
  3445. onBeforeEnter: TransitionHookValidator,
  3446. onEnter: TransitionHookValidator,
  3447. onAfterEnter: TransitionHookValidator,
  3448. onEnterCancelled: TransitionHookValidator,
  3449. // leave
  3450. onBeforeLeave: TransitionHookValidator,
  3451. onLeave: TransitionHookValidator,
  3452. onAfterLeave: TransitionHookValidator,
  3453. onLeaveCancelled: TransitionHookValidator,
  3454. // appear
  3455. onBeforeAppear: TransitionHookValidator,
  3456. onAppear: TransitionHookValidator,
  3457. onAfterAppear: TransitionHookValidator,
  3458. onAppearCancelled: TransitionHookValidator
  3459. },
  3460. setup(props, { slots }) {
  3461. const instance = getCurrentInstance();
  3462. const state = useTransitionState();
  3463. let prevTransitionKey;
  3464. return () => {
  3465. const children = slots.default && getTransitionRawChildren(slots.default(), true);
  3466. if (!children || !children.length) {
  3467. return;
  3468. }
  3469. let child = children[0];
  3470. if (children.length > 1) {
  3471. let hasFound = false;
  3472. // locate first non-comment child
  3473. for (const c of children) {
  3474. if (c.type !== Comment) {
  3475. if (hasFound) {
  3476. // warn more than one non-comment child
  3477. warn$1('<transition> can only be used on a single element or component. ' +
  3478. 'Use <transition-group> for lists.');
  3479. break;
  3480. }
  3481. child = c;
  3482. hasFound = true;
  3483. }
  3484. }
  3485. }
  3486. // there's no need to track reactivity for these props so use the raw
  3487. // props for a bit better perf
  3488. const rawProps = toRaw(props);
  3489. const { mode } = rawProps;
  3490. // check mode
  3491. if (mode &&
  3492. mode !== 'in-out' &&
  3493. mode !== 'out-in' &&
  3494. mode !== 'default') {
  3495. warn$1(`invalid <transition> mode: ${mode}`);
  3496. }
  3497. if (state.isLeaving) {
  3498. return emptyPlaceholder(child);
  3499. }
  3500. // in the case of <transition><keep-alive/></transition>, we need to
  3501. // compare the type of the kept-alive children.
  3502. const innerChild = getKeepAliveChild(child);
  3503. if (!innerChild) {
  3504. return emptyPlaceholder(child);
  3505. }
  3506. const enterHooks = resolveTransitionHooks(innerChild, rawProps, state, instance);
  3507. setTransitionHooks(innerChild, enterHooks);
  3508. const oldChild = instance.subTree;
  3509. const oldInnerChild = oldChild && getKeepAliveChild(oldChild);
  3510. let transitionKeyChanged = false;
  3511. const { getTransitionKey } = innerChild.type;
  3512. if (getTransitionKey) {
  3513. const key = getTransitionKey();
  3514. if (prevTransitionKey === undefined) {
  3515. prevTransitionKey = key;
  3516. }
  3517. else if (key !== prevTransitionKey) {
  3518. prevTransitionKey = key;
  3519. transitionKeyChanged = true;
  3520. }
  3521. }
  3522. // handle mode
  3523. if (oldInnerChild &&
  3524. oldInnerChild.type !== Comment &&
  3525. (!isSameVNodeType(innerChild, oldInnerChild) || transitionKeyChanged)) {
  3526. const leavingHooks = resolveTransitionHooks(oldInnerChild, rawProps, state, instance);
  3527. // update old tree's hooks in case of dynamic transition
  3528. setTransitionHooks(oldInnerChild, leavingHooks);
  3529. // switching between different views
  3530. if (mode === 'out-in') {
  3531. state.isLeaving = true;
  3532. // return placeholder node and queue update when leave finishes
  3533. leavingHooks.afterLeave = () => {
  3534. state.isLeaving = false;
  3535. instance.update();
  3536. };
  3537. return emptyPlaceholder(child);
  3538. }
  3539. else if (mode === 'in-out' && innerChild.type !== Comment) {
  3540. leavingHooks.delayLeave = (el, earlyRemove, delayedLeave) => {
  3541. const leavingVNodesCache = getLeavingNodesForType(state, oldInnerChild);
  3542. leavingVNodesCache[String(oldInnerChild.key)] = oldInnerChild;
  3543. // early removal callback
  3544. el._leaveCb = () => {
  3545. earlyRemove();
  3546. el._leaveCb = undefined;
  3547. delete enterHooks.delayedLeave;
  3548. };
  3549. enterHooks.delayedLeave = delayedLeave;
  3550. };
  3551. }
  3552. }
  3553. return child;
  3554. };
  3555. }
  3556. };
  3557. // export the public type for h/tsx inference
  3558. // also to avoid inline import() in generated d.ts files
  3559. const BaseTransition = BaseTransitionImpl;
  3560. function getLeavingNodesForType(state, vnode) {
  3561. const { leavingVNodes } = state;
  3562. let leavingVNodesCache = leavingVNodes.get(vnode.type);
  3563. if (!leavingVNodesCache) {
  3564. leavingVNodesCache = Object.create(null);
  3565. leavingVNodes.set(vnode.type, leavingVNodesCache);
  3566. }
  3567. return leavingVNodesCache;
  3568. }
  3569. // The transition hooks are attached to the vnode as vnode.transition
  3570. // and will be called at appropriate timing in the renderer.
  3571. function resolveTransitionHooks(vnode, props, state, instance) {
  3572. const { appear, mode, persisted = false, onBeforeEnter, onEnter, onAfterEnter, onEnterCancelled, onBeforeLeave, onLeave, onAfterLeave, onLeaveCancelled, onBeforeAppear, onAppear, onAfterAppear, onAppearCancelled } = props;
  3573. const key = String(vnode.key);
  3574. const leavingVNodesCache = getLeavingNodesForType(state, vnode);
  3575. const callHook = (hook, args) => {
  3576. hook &&
  3577. callWithAsyncErrorHandling(hook, instance, 9 /* TRANSITION_HOOK */, args);
  3578. };
  3579. const callAsyncHook = (hook, args) => {
  3580. const done = args[1];
  3581. callHook(hook, args);
  3582. if (isArray(hook)) {
  3583. if (hook.every(hook => hook.length <= 1))
  3584. done();
  3585. }
  3586. else if (hook.length <= 1) {
  3587. done();
  3588. }
  3589. };
  3590. const hooks = {
  3591. mode,
  3592. persisted,
  3593. beforeEnter(el) {
  3594. let hook = onBeforeEnter;
  3595. if (!state.isMounted) {
  3596. if (appear) {
  3597. hook = onBeforeAppear || onBeforeEnter;
  3598. }
  3599. else {
  3600. return;
  3601. }
  3602. }
  3603. // for same element (v-show)
  3604. if (el._leaveCb) {
  3605. el._leaveCb(true /* cancelled */);
  3606. }
  3607. // for toggled element with same key (v-if)
  3608. const leavingVNode = leavingVNodesCache[key];
  3609. if (leavingVNode &&
  3610. isSameVNodeType(vnode, leavingVNode) &&
  3611. leavingVNode.el._leaveCb) {
  3612. // force early removal (not cancelled)
  3613. leavingVNode.el._leaveCb();
  3614. }
  3615. callHook(hook, [el]);
  3616. },
  3617. enter(el) {
  3618. let hook = onEnter;
  3619. let afterHook = onAfterEnter;
  3620. let cancelHook = onEnterCancelled;
  3621. if (!state.isMounted) {
  3622. if (appear) {
  3623. hook = onAppear || onEnter;
  3624. afterHook = onAfterAppear || onAfterEnter;
  3625. cancelHook = onAppearCancelled || onEnterCancelled;
  3626. }
  3627. else {
  3628. return;
  3629. }
  3630. }
  3631. let called = false;
  3632. const done = (el._enterCb = (cancelled) => {
  3633. if (called)
  3634. return;
  3635. called = true;
  3636. if (cancelled) {
  3637. callHook(cancelHook, [el]);
  3638. }
  3639. else {
  3640. callHook(afterHook, [el]);
  3641. }
  3642. if (hooks.delayedLeave) {
  3643. hooks.delayedLeave();
  3644. }
  3645. el._enterCb = undefined;
  3646. });
  3647. if (hook) {
  3648. callAsyncHook(hook, [el, done]);
  3649. }
  3650. else {
  3651. done();
  3652. }
  3653. },
  3654. leave(el, remove) {
  3655. const key = String(vnode.key);
  3656. if (el._enterCb) {
  3657. el._enterCb(true /* cancelled */);
  3658. }
  3659. if (state.isUnmounting) {
  3660. return remove();
  3661. }
  3662. callHook(onBeforeLeave, [el]);
  3663. let called = false;
  3664. const done = (el._leaveCb = (cancelled) => {
  3665. if (called)
  3666. return;
  3667. called = true;
  3668. remove();
  3669. if (cancelled) {
  3670. callHook(onLeaveCancelled, [el]);
  3671. }
  3672. else {
  3673. callHook(onAfterLeave, [el]);
  3674. }
  3675. el._leaveCb = undefined;
  3676. if (leavingVNodesCache[key] === vnode) {
  3677. delete leavingVNodesCache[key];
  3678. }
  3679. });
  3680. leavingVNodesCache[key] = vnode;
  3681. if (onLeave) {
  3682. callAsyncHook(onLeave, [el, done]);
  3683. }
  3684. else {
  3685. done();
  3686. }
  3687. },
  3688. clone(vnode) {
  3689. return resolveTransitionHooks(vnode, props, state, instance);
  3690. }
  3691. };
  3692. return hooks;
  3693. }
  3694. // the placeholder really only handles one special case: KeepAlive
  3695. // in the case of a KeepAlive in a leave phase we need to return a KeepAlive
  3696. // placeholder with empty content to avoid the KeepAlive instance from being
  3697. // unmounted.
  3698. function emptyPlaceholder(vnode) {
  3699. if (isKeepAlive(vnode)) {
  3700. vnode = cloneVNode(vnode);
  3701. vnode.children = null;
  3702. return vnode;
  3703. }
  3704. }
  3705. function getKeepAliveChild(vnode) {
  3706. return isKeepAlive(vnode)
  3707. ? vnode.children
  3708. ? vnode.children[0]
  3709. : undefined
  3710. : vnode;
  3711. }
  3712. function setTransitionHooks(vnode, hooks) {
  3713. if (vnode.shapeFlag & 6 /* COMPONENT */ && vnode.component) {
  3714. setTransitionHooks(vnode.component.subTree, hooks);
  3715. }
  3716. else if (vnode.shapeFlag & 128 /* SUSPENSE */) {
  3717. vnode.ssContent.transition = hooks.clone(vnode.ssContent);
  3718. vnode.ssFallback.transition = hooks.clone(vnode.ssFallback);
  3719. }
  3720. else {
  3721. vnode.transition = hooks;
  3722. }
  3723. }
  3724. function getTransitionRawChildren(children, keepComment = false, parentKey) {
  3725. let ret = [];
  3726. let keyedFragmentCount = 0;
  3727. for (let i = 0; i < children.length; i++) {
  3728. let child = children[i];
  3729. // #5360 inherit parent key in case of <template v-for>
  3730. const key = parentKey == null
  3731. ? child.key
  3732. : String(parentKey) + String(child.key != null ? child.key : i);
  3733. // handle fragment children case, e.g. v-for
  3734. if (child.type === Fragment) {
  3735. if (child.patchFlag & 128 /* KEYED_FRAGMENT */)
  3736. keyedFragmentCount++;
  3737. ret = ret.concat(getTransitionRawChildren(child.children, keepComment, key));
  3738. }
  3739. // comment placeholders should be skipped, e.g. v-if
  3740. else if (keepComment || child.type !== Comment) {
  3741. ret.push(key != null ? cloneVNode(child, { key }) : child);
  3742. }
  3743. }
  3744. // #1126 if a transition children list contains multiple sub fragments, these
  3745. // fragments will be merged into a flat children array. Since each v-for
  3746. // fragment may contain different static bindings inside, we need to de-op
  3747. // these children to force full diffs to ensure correct behavior.
  3748. if (keyedFragmentCount > 1) {
  3749. for (let i = 0; i < ret.length; i++) {
  3750. ret[i].patchFlag = -2 /* BAIL */;
  3751. }
  3752. }
  3753. return ret;
  3754. }
  3755. // implementation, close to no-op
  3756. function defineComponent(options) {
  3757. return isFunction(options) ? { setup: options, name: options.name } : options;
  3758. }
  3759. const isAsyncWrapper = (i) => !!i.type.__asyncLoader;
  3760. function defineAsyncComponent(source) {
  3761. if (isFunction(source)) {
  3762. source = { loader: source };
  3763. }
  3764. const { loader, loadingComponent, errorComponent, delay = 200, timeout, // undefined = never times out
  3765. suspensible = true, onError: userOnError } = source;
  3766. let pendingRequest = null;
  3767. let resolvedComp;
  3768. let retries = 0;
  3769. const retry = () => {
  3770. retries++;
  3771. pendingRequest = null;
  3772. return load();
  3773. };
  3774. const load = () => {
  3775. let thisRequest;
  3776. return (pendingRequest ||
  3777. (thisRequest = pendingRequest =
  3778. loader()
  3779. .catch(err => {
  3780. err = err instanceof Error ? err : new Error(String(err));
  3781. if (userOnError) {
  3782. return new Promise((resolve, reject) => {
  3783. const userRetry = () => resolve(retry());
  3784. const userFail = () => reject(err);
  3785. userOnError(err, userRetry, userFail, retries + 1);
  3786. });
  3787. }
  3788. else {
  3789. throw err;
  3790. }
  3791. })
  3792. .then((comp) => {
  3793. if (thisRequest !== pendingRequest && pendingRequest) {
  3794. return pendingRequest;
  3795. }
  3796. if (!comp) {
  3797. warn$1(`Async component loader resolved to undefined. ` +
  3798. `If you are using retry(), make sure to return its return value.`);
  3799. }
  3800. // interop module default
  3801. if (comp &&
  3802. (comp.__esModule || comp[Symbol.toStringTag] === 'Module')) {
  3803. comp = comp.default;
  3804. }
  3805. if (comp && !isObject(comp) && !isFunction(comp)) {
  3806. throw new Error(`Invalid async component load result: ${comp}`);
  3807. }
  3808. resolvedComp = comp;
  3809. return comp;
  3810. })));
  3811. };
  3812. return defineComponent({
  3813. name: 'AsyncComponentWrapper',
  3814. __asyncLoader: load,
  3815. get __asyncResolved() {
  3816. return resolvedComp;
  3817. },
  3818. setup() {
  3819. const instance = currentInstance;
  3820. // already resolved
  3821. if (resolvedComp) {
  3822. return () => createInnerComp(resolvedComp, instance);
  3823. }
  3824. const onError = (err) => {
  3825. pendingRequest = null;
  3826. handleError(err, instance, 13 /* ASYNC_COMPONENT_LOADER */, !errorComponent /* do not throw in dev if user provided error component */);
  3827. };
  3828. // suspense-controlled or SSR.
  3829. if ((suspensible && instance.suspense) ||
  3830. (false )) {
  3831. return load()
  3832. .then(comp => {
  3833. return () => createInnerComp(comp, instance);
  3834. })
  3835. .catch(err => {
  3836. onError(err);
  3837. return () => errorComponent
  3838. ? createVNode(errorComponent, {
  3839. error: err
  3840. })
  3841. : null;
  3842. });
  3843. }
  3844. const loaded = ref(false);
  3845. const error = ref();
  3846. const delayed = ref(!!delay);
  3847. if (delay) {
  3848. setTimeout(() => {
  3849. delayed.value = false;
  3850. }, delay);
  3851. }
  3852. if (timeout != null) {
  3853. setTimeout(() => {
  3854. if (!loaded.value && !error.value) {
  3855. const err = new Error(`Async component timed out after ${timeout}ms.`);
  3856. onError(err);
  3857. error.value = err;
  3858. }
  3859. }, timeout);
  3860. }
  3861. load()
  3862. .then(() => {
  3863. loaded.value = true;
  3864. if (instance.parent && isKeepAlive(instance.parent.vnode)) {
  3865. // parent is keep-alive, force update so the loaded component's
  3866. // name is taken into account
  3867. queueJob(instance.parent.update);
  3868. }
  3869. })
  3870. .catch(err => {
  3871. onError(err);
  3872. error.value = err;
  3873. });
  3874. return () => {
  3875. if (loaded.value && resolvedComp) {
  3876. return createInnerComp(resolvedComp, instance);
  3877. }
  3878. else if (error.value && errorComponent) {
  3879. return createVNode(errorComponent, {
  3880. error: error.value
  3881. });
  3882. }
  3883. else if (loadingComponent && !delayed.value) {
  3884. return createVNode(loadingComponent);
  3885. }
  3886. };
  3887. }
  3888. });
  3889. }
  3890. function createInnerComp(comp, { vnode: { ref, props, children, shapeFlag }, parent }) {
  3891. const vnode = createVNode(comp, props, children);
  3892. // ensure inner component inherits the async wrapper's ref owner
  3893. vnode.ref = ref;
  3894. return vnode;
  3895. }
  3896. const isKeepAlive = (vnode) => vnode.type.__isKeepAlive;
  3897. const KeepAliveImpl = {
  3898. name: `KeepAlive`,
  3899. // Marker for special handling inside the renderer. We are not using a ===
  3900. // check directly on KeepAlive in the renderer, because importing it directly
  3901. // would prevent it from being tree-shaken.
  3902. __isKeepAlive: true,
  3903. props: {
  3904. include: [String, RegExp, Array],
  3905. exclude: [String, RegExp, Array],
  3906. max: [String, Number]
  3907. },
  3908. setup(props, { slots }) {
  3909. const instance = getCurrentInstance();
  3910. // KeepAlive communicates with the instantiated renderer via the
  3911. // ctx where the renderer passes in its internals,
  3912. // and the KeepAlive instance exposes activate/deactivate implementations.
  3913. // The whole point of this is to avoid importing KeepAlive directly in the
  3914. // renderer to facilitate tree-shaking.
  3915. const sharedContext = instance.ctx;
  3916. const cache = new Map();
  3917. const keys = new Set();
  3918. let current = null;
  3919. {
  3920. instance.__v_cache = cache;
  3921. }
  3922. const parentSuspense = instance.suspense;
  3923. const { renderer: { p: patch, m: move, um: _unmount, o: { createElement } } } = sharedContext;
  3924. const storageContainer = createElement('div');
  3925. sharedContext.activate = (vnode, container, anchor, isSVG, optimized) => {
  3926. const instance = vnode.component;
  3927. move(vnode, container, anchor, 0 /* ENTER */, parentSuspense);
  3928. // in case props have changed
  3929. patch(instance.vnode, vnode, container, anchor, instance, parentSuspense, isSVG, vnode.slotScopeIds, optimized);
  3930. queuePostRenderEffect(() => {
  3931. instance.isDeactivated = false;
  3932. if (instance.a) {
  3933. invokeArrayFns(instance.a);
  3934. }
  3935. const vnodeHook = vnode.props && vnode.props.onVnodeMounted;
  3936. if (vnodeHook) {
  3937. invokeVNodeHook(vnodeHook, instance.parent, vnode);
  3938. }
  3939. }, parentSuspense);
  3940. {
  3941. // Update components tree
  3942. devtoolsComponentAdded(instance);
  3943. }
  3944. };
  3945. sharedContext.deactivate = (vnode) => {
  3946. const instance = vnode.component;
  3947. move(vnode, storageContainer, null, 1 /* LEAVE */, parentSuspense);
  3948. queuePostRenderEffect(() => {
  3949. if (instance.da) {
  3950. invokeArrayFns(instance.da);
  3951. }
  3952. const vnodeHook = vnode.props && vnode.props.onVnodeUnmounted;
  3953. if (vnodeHook) {
  3954. invokeVNodeHook(vnodeHook, instance.parent, vnode);
  3955. }
  3956. instance.isDeactivated = true;
  3957. }, parentSuspense);
  3958. {
  3959. // Update components tree
  3960. devtoolsComponentAdded(instance);
  3961. }
  3962. };
  3963. function unmount(vnode) {
  3964. // reset the shapeFlag so it can be properly unmounted
  3965. resetShapeFlag(vnode);
  3966. _unmount(vnode, instance, parentSuspense, true);
  3967. }
  3968. function pruneCache(filter) {
  3969. cache.forEach((vnode, key) => {
  3970. const name = getComponentName(vnode.type);
  3971. if (name && (!filter || !filter(name))) {
  3972. pruneCacheEntry(key);
  3973. }
  3974. });
  3975. }
  3976. function pruneCacheEntry(key) {
  3977. const cached = cache.get(key);
  3978. if (!current || cached.type !== current.type) {
  3979. unmount(cached);
  3980. }
  3981. else if (current) {
  3982. // current active instance should no longer be kept-alive.
  3983. // we can't unmount it now but it might be later, so reset its flag now.
  3984. resetShapeFlag(current);
  3985. }
  3986. cache.delete(key);
  3987. keys.delete(key);
  3988. }
  3989. // prune cache on include/exclude prop change
  3990. watch(() => [props.include, props.exclude], ([include, exclude]) => {
  3991. include && pruneCache(name => matches(include, name));
  3992. exclude && pruneCache(name => !matches(exclude, name));
  3993. },
  3994. // prune post-render after `current` has been updated
  3995. { flush: 'post', deep: true });
  3996. // cache sub tree after render
  3997. let pendingCacheKey = null;
  3998. const cacheSubtree = () => {
  3999. // fix #1621, the pendingCacheKey could be 0
  4000. if (pendingCacheKey != null) {
  4001. cache.set(pendingCacheKey, getInnerChild(instance.subTree));
  4002. }
  4003. };
  4004. onMounted(cacheSubtree);
  4005. onUpdated(cacheSubtree);
  4006. onBeforeUnmount(() => {
  4007. cache.forEach(cached => {
  4008. const { subTree, suspense } = instance;
  4009. const vnode = getInnerChild(subTree);
  4010. if (cached.type === vnode.type) {
  4011. // current instance will be unmounted as part of keep-alive's unmount
  4012. resetShapeFlag(vnode);
  4013. // but invoke its deactivated hook here
  4014. const da = vnode.component.da;
  4015. da && queuePostRenderEffect(da, suspense);
  4016. return;
  4017. }
  4018. unmount(cached);
  4019. });
  4020. });
  4021. return () => {
  4022. pendingCacheKey = null;
  4023. if (!slots.default) {
  4024. return null;
  4025. }
  4026. const children = slots.default();
  4027. const rawVNode = children[0];
  4028. if (children.length > 1) {
  4029. {
  4030. warn$1(`KeepAlive should contain exactly one component child.`);
  4031. }
  4032. current = null;
  4033. return children;
  4034. }
  4035. else if (!isVNode(rawVNode) ||
  4036. (!(rawVNode.shapeFlag & 4 /* STATEFUL_COMPONENT */) &&
  4037. !(rawVNode.shapeFlag & 128 /* SUSPENSE */))) {
  4038. current = null;
  4039. return rawVNode;
  4040. }
  4041. let vnode = getInnerChild(rawVNode);
  4042. const comp = vnode.type;
  4043. // for async components, name check should be based in its loaded
  4044. // inner component if available
  4045. const name = getComponentName(isAsyncWrapper(vnode)
  4046. ? vnode.type.__asyncResolved || {}
  4047. : comp);
  4048. const { include, exclude, max } = props;
  4049. if ((include && (!name || !matches(include, name))) ||
  4050. (exclude && name && matches(exclude, name))) {
  4051. current = vnode;
  4052. return rawVNode;
  4053. }
  4054. const key = vnode.key == null ? comp : vnode.key;
  4055. const cachedVNode = cache.get(key);
  4056. // clone vnode if it's reused because we are going to mutate it
  4057. if (vnode.el) {
  4058. vnode = cloneVNode(vnode);
  4059. if (rawVNode.shapeFlag & 128 /* SUSPENSE */) {
  4060. rawVNode.ssContent = vnode;
  4061. }
  4062. }
  4063. // #1513 it's possible for the returned vnode to be cloned due to attr
  4064. // fallthrough or scopeId, so the vnode here may not be the final vnode
  4065. // that is mounted. Instead of caching it directly, we store the pending
  4066. // key and cache `instance.subTree` (the normalized vnode) in
  4067. // beforeMount/beforeUpdate hooks.
  4068. pendingCacheKey = key;
  4069. if (cachedVNode) {
  4070. // copy over mounted state
  4071. vnode.el = cachedVNode.el;
  4072. vnode.component = cachedVNode.component;
  4073. if (vnode.transition) {
  4074. // recursively update transition hooks on subTree
  4075. setTransitionHooks(vnode, vnode.transition);
  4076. }
  4077. // avoid vnode being mounted as fresh
  4078. vnode.shapeFlag |= 512 /* COMPONENT_KEPT_ALIVE */;
  4079. // make this key the freshest
  4080. keys.delete(key);
  4081. keys.add(key);
  4082. }
  4083. else {
  4084. keys.add(key);
  4085. // prune oldest entry
  4086. if (max && keys.size > parseInt(max, 10)) {
  4087. pruneCacheEntry(keys.values().next().value);
  4088. }
  4089. }
  4090. // avoid vnode being unmounted
  4091. vnode.shapeFlag |= 256 /* COMPONENT_SHOULD_KEEP_ALIVE */;
  4092. current = vnode;
  4093. return isSuspense(rawVNode.type) ? rawVNode : vnode;
  4094. };
  4095. }
  4096. };
  4097. // export the public type for h/tsx inference
  4098. // also to avoid inline import() in generated d.ts files
  4099. const KeepAlive = KeepAliveImpl;
  4100. function matches(pattern, name) {
  4101. if (isArray(pattern)) {
  4102. return pattern.some((p) => matches(p, name));
  4103. }
  4104. else if (isString(pattern)) {
  4105. return pattern.split(',').includes(name);
  4106. }
  4107. else if (pattern.test) {
  4108. return pattern.test(name);
  4109. }
  4110. /* istanbul ignore next */
  4111. return false;
  4112. }
  4113. function onActivated(hook, target) {
  4114. registerKeepAliveHook(hook, "a" /* ACTIVATED */, target);
  4115. }
  4116. function onDeactivated(hook, target) {
  4117. registerKeepAliveHook(hook, "da" /* DEACTIVATED */, target);
  4118. }
  4119. function registerKeepAliveHook(hook, type, target = currentInstance) {
  4120. // cache the deactivate branch check wrapper for injected hooks so the same
  4121. // hook can be properly deduped by the scheduler. "__wdc" stands for "with
  4122. // deactivation check".
  4123. const wrappedHook = hook.__wdc ||
  4124. (hook.__wdc = () => {
  4125. // only fire the hook if the target instance is NOT in a deactivated branch.
  4126. let current = target;
  4127. while (current) {
  4128. if (current.isDeactivated) {
  4129. return;
  4130. }
  4131. current = current.parent;
  4132. }
  4133. return hook();
  4134. });
  4135. injectHook(type, wrappedHook, target);
  4136. // In addition to registering it on the target instance, we walk up the parent
  4137. // chain and register it on all ancestor instances that are keep-alive roots.
  4138. // This avoids the need to walk the entire component tree when invoking these
  4139. // hooks, and more importantly, avoids the need to track child components in
  4140. // arrays.
  4141. if (target) {
  4142. let current = target.parent;
  4143. while (current && current.parent) {
  4144. if (isKeepAlive(current.parent.vnode)) {
  4145. injectToKeepAliveRoot(wrappedHook, type, target, current);
  4146. }
  4147. current = current.parent;
  4148. }
  4149. }
  4150. }
  4151. function injectToKeepAliveRoot(hook, type, target, keepAliveRoot) {
  4152. // injectHook wraps the original for error handling, so make sure to remove
  4153. // the wrapped version.
  4154. const injected = injectHook(type, hook, keepAliveRoot, true /* prepend */);
  4155. onUnmounted(() => {
  4156. remove(keepAliveRoot[type], injected);
  4157. }, target);
  4158. }
  4159. function resetShapeFlag(vnode) {
  4160. let shapeFlag = vnode.shapeFlag;
  4161. if (shapeFlag & 256 /* COMPONENT_SHOULD_KEEP_ALIVE */) {
  4162. shapeFlag -= 256 /* COMPONENT_SHOULD_KEEP_ALIVE */;
  4163. }
  4164. if (shapeFlag & 512 /* COMPONENT_KEPT_ALIVE */) {
  4165. shapeFlag -= 512 /* COMPONENT_KEPT_ALIVE */;
  4166. }
  4167. vnode.shapeFlag = shapeFlag;
  4168. }
  4169. function getInnerChild(vnode) {
  4170. return vnode.shapeFlag & 128 /* SUSPENSE */ ? vnode.ssContent : vnode;
  4171. }
  4172. function injectHook(type, hook, target = currentInstance, prepend = false) {
  4173. if (target) {
  4174. const hooks = target[type] || (target[type] = []);
  4175. // cache the error handling wrapper for injected hooks so the same hook
  4176. // can be properly deduped by the scheduler. "__weh" stands for "with error
  4177. // handling".
  4178. const wrappedHook = hook.__weh ||
  4179. (hook.__weh = (...args) => {
  4180. if (target.isUnmounted) {
  4181. return;
  4182. }
  4183. // disable tracking inside all lifecycle hooks
  4184. // since they can potentially be called inside effects.
  4185. pauseTracking();
  4186. // Set currentInstance during hook invocation.
  4187. // This assumes the hook does not synchronously trigger other hooks, which
  4188. // can only be false when the user does something really funky.
  4189. setCurrentInstance(target);
  4190. const res = callWithAsyncErrorHandling(hook, target, type, args);
  4191. unsetCurrentInstance();
  4192. resetTracking();
  4193. return res;
  4194. });
  4195. if (prepend) {
  4196. hooks.unshift(wrappedHook);
  4197. }
  4198. else {
  4199. hooks.push(wrappedHook);
  4200. }
  4201. return wrappedHook;
  4202. }
  4203. else {
  4204. const apiName = toHandlerKey(ErrorTypeStrings[type].replace(/ hook$/, ''));
  4205. warn$1(`${apiName} is called when there is no active component instance to be ` +
  4206. `associated with. ` +
  4207. `Lifecycle injection APIs can only be used during execution of setup().` +
  4208. (` If you are using async setup(), make sure to register lifecycle ` +
  4209. `hooks before the first await statement.`
  4210. ));
  4211. }
  4212. }
  4213. const createHook = (lifecycle) => (hook, target = currentInstance) =>
  4214. // post-create lifecycle registrations are noops during SSR (except for serverPrefetch)
  4215. (!isInSSRComponentSetup || lifecycle === "sp" /* SERVER_PREFETCH */) &&
  4216. injectHook(lifecycle, hook, target);
  4217. const onBeforeMount = createHook("bm" /* BEFORE_MOUNT */);
  4218. const onMounted = createHook("m" /* MOUNTED */);
  4219. const onBeforeUpdate = createHook("bu" /* BEFORE_UPDATE */);
  4220. const onUpdated = createHook("u" /* UPDATED */);
  4221. const onBeforeUnmount = createHook("bum" /* BEFORE_UNMOUNT */);
  4222. const onUnmounted = createHook("um" /* UNMOUNTED */);
  4223. const onServerPrefetch = createHook("sp" /* SERVER_PREFETCH */);
  4224. const onRenderTriggered = createHook("rtg" /* RENDER_TRIGGERED */);
  4225. const onRenderTracked = createHook("rtc" /* RENDER_TRACKED */);
  4226. function onErrorCaptured(hook, target = currentInstance) {
  4227. injectHook("ec" /* ERROR_CAPTURED */, hook, target);
  4228. }
  4229. /**
  4230. Runtime helper for applying directives to a vnode. Example usage:
  4231. const comp = resolveComponent('comp')
  4232. const foo = resolveDirective('foo')
  4233. const bar = resolveDirective('bar')
  4234. return withDirectives(h(comp), [
  4235. [foo, this.x],
  4236. [bar, this.y]
  4237. ])
  4238. */
  4239. function validateDirectiveName(name) {
  4240. if (isBuiltInDirective(name)) {
  4241. warn$1('Do not use built-in directive ids as custom directive id: ' + name);
  4242. }
  4243. }
  4244. /**
  4245. * Adds directives to a VNode.
  4246. */
  4247. function withDirectives(vnode, directives) {
  4248. const internalInstance = currentRenderingInstance;
  4249. if (internalInstance === null) {
  4250. warn$1(`withDirectives can only be used inside render functions.`);
  4251. return vnode;
  4252. }
  4253. const instance = getExposeProxy(internalInstance) ||
  4254. internalInstance.proxy;
  4255. const bindings = vnode.dirs || (vnode.dirs = []);
  4256. for (let i = 0; i < directives.length; i++) {
  4257. let [dir, value, arg, modifiers = EMPTY_OBJ] = directives[i];
  4258. if (isFunction(dir)) {
  4259. dir = {
  4260. mounted: dir,
  4261. updated: dir
  4262. };
  4263. }
  4264. if (dir.deep) {
  4265. traverse(value);
  4266. }
  4267. bindings.push({
  4268. dir,
  4269. instance,
  4270. value,
  4271. oldValue: void 0,
  4272. arg,
  4273. modifiers
  4274. });
  4275. }
  4276. return vnode;
  4277. }
  4278. function invokeDirectiveHook(vnode, prevVNode, instance, name) {
  4279. const bindings = vnode.dirs;
  4280. const oldBindings = prevVNode && prevVNode.dirs;
  4281. for (let i = 0; i < bindings.length; i++) {
  4282. const binding = bindings[i];
  4283. if (oldBindings) {
  4284. binding.oldValue = oldBindings[i].value;
  4285. }
  4286. let hook = binding.dir[name];
  4287. if (hook) {
  4288. // disable tracking inside all lifecycle hooks
  4289. // since they can potentially be called inside effects.
  4290. pauseTracking();
  4291. callWithAsyncErrorHandling(hook, instance, 8 /* DIRECTIVE_HOOK */, [
  4292. vnode.el,
  4293. binding,
  4294. vnode,
  4295. prevVNode
  4296. ]);
  4297. resetTracking();
  4298. }
  4299. }
  4300. }
  4301. const COMPONENTS = 'components';
  4302. const DIRECTIVES = 'directives';
  4303. /**
  4304. * @private
  4305. */
  4306. function resolveComponent(name, maybeSelfReference) {
  4307. return resolveAsset(COMPONENTS, name, true, maybeSelfReference) || name;
  4308. }
  4309. const NULL_DYNAMIC_COMPONENT = Symbol();
  4310. /**
  4311. * @private
  4312. */
  4313. function resolveDynamicComponent(component) {
  4314. if (isString(component)) {
  4315. return resolveAsset(COMPONENTS, component, false) || component;
  4316. }
  4317. else {
  4318. // invalid types will fallthrough to createVNode and raise warning
  4319. return (component || NULL_DYNAMIC_COMPONENT);
  4320. }
  4321. }
  4322. /**
  4323. * @private
  4324. */
  4325. function resolveDirective(name) {
  4326. return resolveAsset(DIRECTIVES, name);
  4327. }
  4328. // implementation
  4329. function resolveAsset(type, name, warnMissing = true, maybeSelfReference = false) {
  4330. const instance = currentRenderingInstance || currentInstance;
  4331. if (instance) {
  4332. const Component = instance.type;
  4333. // explicit self name has highest priority
  4334. if (type === COMPONENTS) {
  4335. const selfName = getComponentName(Component);
  4336. if (selfName &&
  4337. (selfName === name ||
  4338. selfName === camelize(name) ||
  4339. selfName === capitalize(camelize(name)))) {
  4340. return Component;
  4341. }
  4342. }
  4343. const res =
  4344. // local registration
  4345. // check instance[type] first which is resolved for options API
  4346. resolve(instance[type] || Component[type], name) ||
  4347. // global registration
  4348. resolve(instance.appContext[type], name);
  4349. if (!res && maybeSelfReference) {
  4350. // fallback to implicit self-reference
  4351. return Component;
  4352. }
  4353. if (warnMissing && !res) {
  4354. const extra = type === COMPONENTS
  4355. ? `\nIf this is a native custom element, make sure to exclude it from ` +
  4356. `component resolution via compilerOptions.isCustomElement.`
  4357. : ``;
  4358. warn$1(`Failed to resolve ${type.slice(0, -1)}: ${name}${extra}`);
  4359. }
  4360. return res;
  4361. }
  4362. else {
  4363. warn$1(`resolve${capitalize(type.slice(0, -1))} ` +
  4364. `can only be used in render() or setup().`);
  4365. }
  4366. }
  4367. function resolve(registry, name) {
  4368. return (registry &&
  4369. (registry[name] ||
  4370. registry[camelize(name)] ||
  4371. registry[capitalize(camelize(name))]));
  4372. }
  4373. /**
  4374. * Actual implementation
  4375. */
  4376. function renderList(source, renderItem, cache, index) {
  4377. let ret;
  4378. const cached = (cache && cache[index]);
  4379. if (isArray(source) || isString(source)) {
  4380. ret = new Array(source.length);
  4381. for (let i = 0, l = source.length; i < l; i++) {
  4382. ret[i] = renderItem(source[i], i, undefined, cached && cached[i]);
  4383. }
  4384. }
  4385. else if (typeof source === 'number') {
  4386. if (!Number.isInteger(source)) {
  4387. warn$1(`The v-for range expect an integer value but got ${source}.`);
  4388. }
  4389. ret = new Array(source);
  4390. for (let i = 0; i < source; i++) {
  4391. ret[i] = renderItem(i + 1, i, undefined, cached && cached[i]);
  4392. }
  4393. }
  4394. else if (isObject(source)) {
  4395. if (source[Symbol.iterator]) {
  4396. ret = Array.from(source, (item, i) => renderItem(item, i, undefined, cached && cached[i]));
  4397. }
  4398. else {
  4399. const keys = Object.keys(source);
  4400. ret = new Array(keys.length);
  4401. for (let i = 0, l = keys.length; i < l; i++) {
  4402. const key = keys[i];
  4403. ret[i] = renderItem(source[key], key, i, cached && cached[i]);
  4404. }
  4405. }
  4406. }
  4407. else {
  4408. ret = [];
  4409. }
  4410. if (cache) {
  4411. cache[index] = ret;
  4412. }
  4413. return ret;
  4414. }
  4415. /**
  4416. * Compiler runtime helper for creating dynamic slots object
  4417. * @private
  4418. */
  4419. function createSlots(slots, dynamicSlots) {
  4420. for (let i = 0; i < dynamicSlots.length; i++) {
  4421. const slot = dynamicSlots[i];
  4422. // array of dynamic slot generated by <template v-for="..." #[...]>
  4423. if (isArray(slot)) {
  4424. for (let j = 0; j < slot.length; j++) {
  4425. slots[slot[j].name] = slot[j].fn;
  4426. }
  4427. }
  4428. else if (slot) {
  4429. // conditional single slot generated by <template v-if="..." #foo>
  4430. slots[slot.name] = slot.fn;
  4431. }
  4432. }
  4433. return slots;
  4434. }
  4435. /**
  4436. * Compiler runtime helper for rendering `<slot/>`
  4437. * @private
  4438. */
  4439. function renderSlot(slots, name, props = {},
  4440. // this is not a user-facing function, so the fallback is always generated by
  4441. // the compiler and guaranteed to be a function returning an array
  4442. fallback, noSlotted) {
  4443. if (currentRenderingInstance.isCE ||
  4444. (currentRenderingInstance.parent &&
  4445. isAsyncWrapper(currentRenderingInstance.parent) &&
  4446. currentRenderingInstance.parent.isCE)) {
  4447. return createVNode('slot', name === 'default' ? null : { name }, fallback && fallback());
  4448. }
  4449. let slot = slots[name];
  4450. if (slot && slot.length > 1) {
  4451. warn$1(`SSR-optimized slot function detected in a non-SSR-optimized render ` +
  4452. `function. You need to mark this component with $dynamic-slots in the ` +
  4453. `parent template.`);
  4454. slot = () => [];
  4455. }
  4456. // a compiled slot disables block tracking by default to avoid manual
  4457. // invocation interfering with template-based block tracking, but in
  4458. // `renderSlot` we can be sure that it's template-based so we can force
  4459. // enable it.
  4460. if (slot && slot._c) {
  4461. slot._d = false;
  4462. }
  4463. openBlock();
  4464. const validSlotContent = slot && ensureValidVNode(slot(props));
  4465. const rendered = createBlock(Fragment, { key: props.key || `_${name}` }, validSlotContent || (fallback ? fallback() : []), validSlotContent && slots._ === 1 /* STABLE */
  4466. ? 64 /* STABLE_FRAGMENT */
  4467. : -2 /* BAIL */);
  4468. if (!noSlotted && rendered.scopeId) {
  4469. rendered.slotScopeIds = [rendered.scopeId + '-s'];
  4470. }
  4471. if (slot && slot._c) {
  4472. slot._d = true;
  4473. }
  4474. return rendered;
  4475. }
  4476. function ensureValidVNode(vnodes) {
  4477. return vnodes.some(child => {
  4478. if (!isVNode(child))
  4479. return true;
  4480. if (child.type === Comment)
  4481. return false;
  4482. if (child.type === Fragment &&
  4483. !ensureValidVNode(child.children))
  4484. return false;
  4485. return true;
  4486. })
  4487. ? vnodes
  4488. : null;
  4489. }
  4490. /**
  4491. * For prefixing keys in v-on="obj" with "on"
  4492. * @private
  4493. */
  4494. function toHandlers(obj) {
  4495. const ret = {};
  4496. if (!isObject(obj)) {
  4497. warn$1(`v-on with no argument expects an object value.`);
  4498. return ret;
  4499. }
  4500. for (const key in obj) {
  4501. ret[toHandlerKey(key)] = obj[key];
  4502. }
  4503. return ret;
  4504. }
  4505. /**
  4506. * #2437 In Vue 3, functional components do not have a public instance proxy but
  4507. * they exist in the internal parent chain. For code that relies on traversing
  4508. * public $parent chains, skip functional ones and go to the parent instead.
  4509. */
  4510. const getPublicInstance = (i) => {
  4511. if (!i)
  4512. return null;
  4513. if (isStatefulComponent(i))
  4514. return getExposeProxy(i) || i.proxy;
  4515. return getPublicInstance(i.parent);
  4516. };
  4517. const publicPropertiesMap =
  4518. // Move PURE marker to new line to workaround compiler discarding it
  4519. // due to type annotation
  4520. /*#__PURE__*/ extend(Object.create(null), {
  4521. $: i => i,
  4522. $el: i => i.vnode.el,
  4523. $data: i => i.data,
  4524. $props: i => (shallowReadonly(i.props) ),
  4525. $attrs: i => (shallowReadonly(i.attrs) ),
  4526. $slots: i => (shallowReadonly(i.slots) ),
  4527. $refs: i => (shallowReadonly(i.refs) ),
  4528. $parent: i => getPublicInstance(i.parent),
  4529. $root: i => getPublicInstance(i.root),
  4530. $emit: i => i.emit,
  4531. $options: i => (resolveMergedOptions(i) ),
  4532. $forceUpdate: i => i.f || (i.f = () => queueJob(i.update)),
  4533. $nextTick: i => i.n || (i.n = nextTick.bind(i.proxy)),
  4534. $watch: i => (instanceWatch.bind(i) )
  4535. });
  4536. const isReservedPrefix = (key) => key === '_' || key === '$';
  4537. const PublicInstanceProxyHandlers = {
  4538. get({ _: instance }, key) {
  4539. const { ctx, setupState, data, props, accessCache, type, appContext } = instance;
  4540. // for internal formatters to know that this is a Vue instance
  4541. if (key === '__isVue') {
  4542. return true;
  4543. }
  4544. // prioritize <script setup> bindings during dev.
  4545. // this allows even properties that start with _ or $ to be used - so that
  4546. // it aligns with the production behavior where the render fn is inlined and
  4547. // indeed has access to all declared variables.
  4548. if (setupState !== EMPTY_OBJ &&
  4549. setupState.__isScriptSetup &&
  4550. hasOwn(setupState, key)) {
  4551. return setupState[key];
  4552. }
  4553. // data / props / ctx
  4554. // This getter gets called for every property access on the render context
  4555. // during render and is a major hotspot. The most expensive part of this
  4556. // is the multiple hasOwn() calls. It's much faster to do a simple property
  4557. // access on a plain object, so we use an accessCache object (with null
  4558. // prototype) to memoize what access type a key corresponds to.
  4559. let normalizedProps;
  4560. if (key[0] !== '$') {
  4561. const n = accessCache[key];
  4562. if (n !== undefined) {
  4563. switch (n) {
  4564. case 1 /* SETUP */:
  4565. return setupState[key];
  4566. case 2 /* DATA */:
  4567. return data[key];
  4568. case 4 /* CONTEXT */:
  4569. return ctx[key];
  4570. case 3 /* PROPS */:
  4571. return props[key];
  4572. // default: just fallthrough
  4573. }
  4574. }
  4575. else if (setupState !== EMPTY_OBJ && hasOwn(setupState, key)) {
  4576. accessCache[key] = 1 /* SETUP */;
  4577. return setupState[key];
  4578. }
  4579. else if (data !== EMPTY_OBJ && hasOwn(data, key)) {
  4580. accessCache[key] = 2 /* DATA */;
  4581. return data[key];
  4582. }
  4583. else if (
  4584. // only cache other properties when instance has declared (thus stable)
  4585. // props
  4586. (normalizedProps = instance.propsOptions[0]) &&
  4587. hasOwn(normalizedProps, key)) {
  4588. accessCache[key] = 3 /* PROPS */;
  4589. return props[key];
  4590. }
  4591. else if (ctx !== EMPTY_OBJ && hasOwn(ctx, key)) {
  4592. accessCache[key] = 4 /* CONTEXT */;
  4593. return ctx[key];
  4594. }
  4595. else if (shouldCacheAccess) {
  4596. accessCache[key] = 0 /* OTHER */;
  4597. }
  4598. }
  4599. const publicGetter = publicPropertiesMap[key];
  4600. let cssModule, globalProperties;
  4601. // public $xxx properties
  4602. if (publicGetter) {
  4603. if (key === '$attrs') {
  4604. track(instance, "get" /* GET */, key);
  4605. markAttrsAccessed();
  4606. }
  4607. return publicGetter(instance);
  4608. }
  4609. else if (
  4610. // css module (injected by vue-loader)
  4611. (cssModule = type.__cssModules) &&
  4612. (cssModule = cssModule[key])) {
  4613. return cssModule;
  4614. }
  4615. else if (ctx !== EMPTY_OBJ && hasOwn(ctx, key)) {
  4616. // user may set custom properties to `this` that start with `$`
  4617. accessCache[key] = 4 /* CONTEXT */;
  4618. return ctx[key];
  4619. }
  4620. else if (
  4621. // global properties
  4622. ((globalProperties = appContext.config.globalProperties),
  4623. hasOwn(globalProperties, key))) {
  4624. {
  4625. return globalProperties[key];
  4626. }
  4627. }
  4628. else if (currentRenderingInstance &&
  4629. (!isString(key) ||
  4630. // #1091 avoid internal isRef/isVNode checks on component instance leading
  4631. // to infinite warning loop
  4632. key.indexOf('__v') !== 0)) {
  4633. if (data !== EMPTY_OBJ && isReservedPrefix(key[0]) && hasOwn(data, key)) {
  4634. warn$1(`Property ${JSON.stringify(key)} must be accessed via $data because it starts with a reserved ` +
  4635. `character ("$" or "_") and is not proxied on the render context.`);
  4636. }
  4637. else if (instance === currentRenderingInstance) {
  4638. warn$1(`Property ${JSON.stringify(key)} was accessed during render ` +
  4639. `but is not defined on instance.`);
  4640. }
  4641. }
  4642. },
  4643. set({ _: instance }, key, value) {
  4644. const { data, setupState, ctx } = instance;
  4645. if (setupState !== EMPTY_OBJ && hasOwn(setupState, key)) {
  4646. setupState[key] = value;
  4647. return true;
  4648. }
  4649. else if (data !== EMPTY_OBJ && hasOwn(data, key)) {
  4650. data[key] = value;
  4651. return true;
  4652. }
  4653. else if (hasOwn(instance.props, key)) {
  4654. warn$1(`Attempting to mutate prop "${key}". Props are readonly.`, instance);
  4655. return false;
  4656. }
  4657. if (key[0] === '$' && key.slice(1) in instance) {
  4658. warn$1(`Attempting to mutate public property "${key}". ` +
  4659. `Properties starting with $ are reserved and readonly.`, instance);
  4660. return false;
  4661. }
  4662. else {
  4663. if (key in instance.appContext.config.globalProperties) {
  4664. Object.defineProperty(ctx, key, {
  4665. enumerable: true,
  4666. configurable: true,
  4667. value
  4668. });
  4669. }
  4670. else {
  4671. ctx[key] = value;
  4672. }
  4673. }
  4674. return true;
  4675. },
  4676. has({ _: { data, setupState, accessCache, ctx, appContext, propsOptions } }, key) {
  4677. let normalizedProps;
  4678. return (!!accessCache[key] ||
  4679. (data !== EMPTY_OBJ && hasOwn(data, key)) ||
  4680. (setupState !== EMPTY_OBJ && hasOwn(setupState, key)) ||
  4681. ((normalizedProps = propsOptions[0]) && hasOwn(normalizedProps, key)) ||
  4682. hasOwn(ctx, key) ||
  4683. hasOwn(publicPropertiesMap, key) ||
  4684. hasOwn(appContext.config.globalProperties, key));
  4685. },
  4686. defineProperty(target, key, descriptor) {
  4687. if (descriptor.get != null) {
  4688. // invalidate key cache of a getter based property #5417
  4689. target._.accessCache[key] = 0;
  4690. }
  4691. else if (hasOwn(descriptor, 'value')) {
  4692. this.set(target, key, descriptor.value, null);
  4693. }
  4694. return Reflect.defineProperty(target, key, descriptor);
  4695. }
  4696. };
  4697. {
  4698. PublicInstanceProxyHandlers.ownKeys = (target) => {
  4699. warn$1(`Avoid app logic that relies on enumerating keys on a component instance. ` +
  4700. `The keys will be empty in production mode to avoid performance overhead.`);
  4701. return Reflect.ownKeys(target);
  4702. };
  4703. }
  4704. const RuntimeCompiledPublicInstanceProxyHandlers = /*#__PURE__*/ extend({}, PublicInstanceProxyHandlers, {
  4705. get(target, key) {
  4706. // fast path for unscopables when using `with` block
  4707. if (key === Symbol.unscopables) {
  4708. return;
  4709. }
  4710. return PublicInstanceProxyHandlers.get(target, key, target);
  4711. },
  4712. has(_, key) {
  4713. const has = key[0] !== '_' && !isGloballyWhitelisted(key);
  4714. if (!has && PublicInstanceProxyHandlers.has(_, key)) {
  4715. warn$1(`Property ${JSON.stringify(key)} should not start with _ which is a reserved prefix for Vue internals.`);
  4716. }
  4717. return has;
  4718. }
  4719. });
  4720. // dev only
  4721. // In dev mode, the proxy target exposes the same properties as seen on `this`
  4722. // for easier console inspection. In prod mode it will be an empty object so
  4723. // these properties definitions can be skipped.
  4724. function createDevRenderContext(instance) {
  4725. const target = {};
  4726. // expose internal instance for proxy handlers
  4727. Object.defineProperty(target, `_`, {
  4728. configurable: true,
  4729. enumerable: false,
  4730. get: () => instance
  4731. });
  4732. // expose public properties
  4733. Object.keys(publicPropertiesMap).forEach(key => {
  4734. Object.defineProperty(target, key, {
  4735. configurable: true,
  4736. enumerable: false,
  4737. get: () => publicPropertiesMap[key](instance),
  4738. // intercepted by the proxy so no need for implementation,
  4739. // but needed to prevent set errors
  4740. set: NOOP
  4741. });
  4742. });
  4743. return target;
  4744. }
  4745. // dev only
  4746. function exposePropsOnRenderContext(instance) {
  4747. const { ctx, propsOptions: [propsOptions] } = instance;
  4748. if (propsOptions) {
  4749. Object.keys(propsOptions).forEach(key => {
  4750. Object.defineProperty(ctx, key, {
  4751. enumerable: true,
  4752. configurable: true,
  4753. get: () => instance.props[key],
  4754. set: NOOP
  4755. });
  4756. });
  4757. }
  4758. }
  4759. // dev only
  4760. function exposeSetupStateOnRenderContext(instance) {
  4761. const { ctx, setupState } = instance;
  4762. Object.keys(toRaw(setupState)).forEach(key => {
  4763. if (!setupState.__isScriptSetup) {
  4764. if (isReservedPrefix(key[0])) {
  4765. warn$1(`setup() return property ${JSON.stringify(key)} should not start with "$" or "_" ` +
  4766. `which are reserved prefixes for Vue internals.`);
  4767. return;
  4768. }
  4769. Object.defineProperty(ctx, key, {
  4770. enumerable: true,
  4771. configurable: true,
  4772. get: () => setupState[key],
  4773. set: NOOP
  4774. });
  4775. }
  4776. });
  4777. }
  4778. function createDuplicateChecker() {
  4779. const cache = Object.create(null);
  4780. return (type, key) => {
  4781. if (cache[key]) {
  4782. warn$1(`${type} property "${key}" is already defined in ${cache[key]}.`);
  4783. }
  4784. else {
  4785. cache[key] = type;
  4786. }
  4787. };
  4788. }
  4789. let shouldCacheAccess = true;
  4790. function applyOptions(instance) {
  4791. const options = resolveMergedOptions(instance);
  4792. const publicThis = instance.proxy;
  4793. const ctx = instance.ctx;
  4794. // do not cache property access on public proxy during state initialization
  4795. shouldCacheAccess = false;
  4796. // call beforeCreate first before accessing other options since
  4797. // the hook may mutate resolved options (#2791)
  4798. if (options.beforeCreate) {
  4799. callHook(options.beforeCreate, instance, "bc" /* BEFORE_CREATE */);
  4800. }
  4801. const {
  4802. // state
  4803. data: dataOptions, computed: computedOptions, methods, watch: watchOptions, provide: provideOptions, inject: injectOptions,
  4804. // lifecycle
  4805. created, beforeMount, mounted, beforeUpdate, updated, activated, deactivated, beforeDestroy, beforeUnmount, destroyed, unmounted, render, renderTracked, renderTriggered, errorCaptured, serverPrefetch,
  4806. // public API
  4807. expose, inheritAttrs,
  4808. // assets
  4809. components, directives, filters } = options;
  4810. const checkDuplicateProperties = createDuplicateChecker() ;
  4811. {
  4812. const [propsOptions] = instance.propsOptions;
  4813. if (propsOptions) {
  4814. for (const key in propsOptions) {
  4815. checkDuplicateProperties("Props" /* PROPS */, key);
  4816. }
  4817. }
  4818. }
  4819. // options initialization order (to be consistent with Vue 2):
  4820. // - props (already done outside of this function)
  4821. // - inject
  4822. // - methods
  4823. // - data (deferred since it relies on `this` access)
  4824. // - computed
  4825. // - watch (deferred since it relies on `this` access)
  4826. if (injectOptions) {
  4827. resolveInjections(injectOptions, ctx, checkDuplicateProperties, instance.appContext.config.unwrapInjectedRef);
  4828. }
  4829. if (methods) {
  4830. for (const key in methods) {
  4831. const methodHandler = methods[key];
  4832. if (isFunction(methodHandler)) {
  4833. // In dev mode, we use the `createRenderContext` function to define
  4834. // methods to the proxy target, and those are read-only but
  4835. // reconfigurable, so it needs to be redefined here
  4836. {
  4837. Object.defineProperty(ctx, key, {
  4838. value: methodHandler.bind(publicThis),
  4839. configurable: true,
  4840. enumerable: true,
  4841. writable: true
  4842. });
  4843. }
  4844. {
  4845. checkDuplicateProperties("Methods" /* METHODS */, key);
  4846. }
  4847. }
  4848. else {
  4849. warn$1(`Method "${key}" has type "${typeof methodHandler}" in the component definition. ` +
  4850. `Did you reference the function correctly?`);
  4851. }
  4852. }
  4853. }
  4854. if (dataOptions) {
  4855. if (!isFunction(dataOptions)) {
  4856. warn$1(`The data option must be a function. ` +
  4857. `Plain object usage is no longer supported.`);
  4858. }
  4859. const data = dataOptions.call(publicThis, publicThis);
  4860. if (isPromise(data)) {
  4861. warn$1(`data() returned a Promise - note data() cannot be async; If you ` +
  4862. `intend to perform data fetching before component renders, use ` +
  4863. `async setup() + <Suspense>.`);
  4864. }
  4865. if (!isObject(data)) {
  4866. warn$1(`data() should return an object.`);
  4867. }
  4868. else {
  4869. instance.data = reactive(data);
  4870. {
  4871. for (const key in data) {
  4872. checkDuplicateProperties("Data" /* DATA */, key);
  4873. // expose data on ctx during dev
  4874. if (!isReservedPrefix(key[0])) {
  4875. Object.defineProperty(ctx, key, {
  4876. configurable: true,
  4877. enumerable: true,
  4878. get: () => data[key],
  4879. set: NOOP
  4880. });
  4881. }
  4882. }
  4883. }
  4884. }
  4885. }
  4886. // state initialization complete at this point - start caching access
  4887. shouldCacheAccess = true;
  4888. if (computedOptions) {
  4889. for (const key in computedOptions) {
  4890. const opt = computedOptions[key];
  4891. const get = isFunction(opt)
  4892. ? opt.bind(publicThis, publicThis)
  4893. : isFunction(opt.get)
  4894. ? opt.get.bind(publicThis, publicThis)
  4895. : NOOP;
  4896. if (get === NOOP) {
  4897. warn$1(`Computed property "${key}" has no getter.`);
  4898. }
  4899. const set = !isFunction(opt) && isFunction(opt.set)
  4900. ? opt.set.bind(publicThis)
  4901. : () => {
  4902. warn$1(`Write operation failed: computed property "${key}" is readonly.`);
  4903. }
  4904. ;
  4905. const c = computed$1({
  4906. get,
  4907. set
  4908. });
  4909. Object.defineProperty(ctx, key, {
  4910. enumerable: true,
  4911. configurable: true,
  4912. get: () => c.value,
  4913. set: v => (c.value = v)
  4914. });
  4915. {
  4916. checkDuplicateProperties("Computed" /* COMPUTED */, key);
  4917. }
  4918. }
  4919. }
  4920. if (watchOptions) {
  4921. for (const key in watchOptions) {
  4922. createWatcher(watchOptions[key], ctx, publicThis, key);
  4923. }
  4924. }
  4925. if (provideOptions) {
  4926. const provides = isFunction(provideOptions)
  4927. ? provideOptions.call(publicThis)
  4928. : provideOptions;
  4929. Reflect.ownKeys(provides).forEach(key => {
  4930. provide(key, provides[key]);
  4931. });
  4932. }
  4933. if (created) {
  4934. callHook(created, instance, "c" /* CREATED */);
  4935. }
  4936. function registerLifecycleHook(register, hook) {
  4937. if (isArray(hook)) {
  4938. hook.forEach(_hook => register(_hook.bind(publicThis)));
  4939. }
  4940. else if (hook) {
  4941. register(hook.bind(publicThis));
  4942. }
  4943. }
  4944. registerLifecycleHook(onBeforeMount, beforeMount);
  4945. registerLifecycleHook(onMounted, mounted);
  4946. registerLifecycleHook(onBeforeUpdate, beforeUpdate);
  4947. registerLifecycleHook(onUpdated, updated);
  4948. registerLifecycleHook(onActivated, activated);
  4949. registerLifecycleHook(onDeactivated, deactivated);
  4950. registerLifecycleHook(onErrorCaptured, errorCaptured);
  4951. registerLifecycleHook(onRenderTracked, renderTracked);
  4952. registerLifecycleHook(onRenderTriggered, renderTriggered);
  4953. registerLifecycleHook(onBeforeUnmount, beforeUnmount);
  4954. registerLifecycleHook(onUnmounted, unmounted);
  4955. registerLifecycleHook(onServerPrefetch, serverPrefetch);
  4956. if (isArray(expose)) {
  4957. if (expose.length) {
  4958. const exposed = instance.exposed || (instance.exposed = {});
  4959. expose.forEach(key => {
  4960. Object.defineProperty(exposed, key, {
  4961. get: () => publicThis[key],
  4962. set: val => (publicThis[key] = val)
  4963. });
  4964. });
  4965. }
  4966. else if (!instance.exposed) {
  4967. instance.exposed = {};
  4968. }
  4969. }
  4970. // options that are handled when creating the instance but also need to be
  4971. // applied from mixins
  4972. if (render && instance.render === NOOP) {
  4973. instance.render = render;
  4974. }
  4975. if (inheritAttrs != null) {
  4976. instance.inheritAttrs = inheritAttrs;
  4977. }
  4978. // asset options.
  4979. if (components)
  4980. instance.components = components;
  4981. if (directives)
  4982. instance.directives = directives;
  4983. }
  4984. function resolveInjections(injectOptions, ctx, checkDuplicateProperties = NOOP, unwrapRef = false) {
  4985. if (isArray(injectOptions)) {
  4986. injectOptions = normalizeInject(injectOptions);
  4987. }
  4988. for (const key in injectOptions) {
  4989. const opt = injectOptions[key];
  4990. let injected;
  4991. if (isObject(opt)) {
  4992. if ('default' in opt) {
  4993. injected = inject(opt.from || key, opt.default, true /* treat default function as factory */);
  4994. }
  4995. else {
  4996. injected = inject(opt.from || key);
  4997. }
  4998. }
  4999. else {
  5000. injected = inject(opt);
  5001. }
  5002. if (isRef(injected)) {
  5003. // TODO remove the check in 3.3
  5004. if (unwrapRef) {
  5005. Object.defineProperty(ctx, key, {
  5006. enumerable: true,
  5007. configurable: true,
  5008. get: () => injected.value,
  5009. set: v => (injected.value = v)
  5010. });
  5011. }
  5012. else {
  5013. {
  5014. warn$1(`injected property "${key}" is a ref and will be auto-unwrapped ` +
  5015. `and no longer needs \`.value\` in the next minor release. ` +
  5016. `To opt-in to the new behavior now, ` +
  5017. `set \`app.config.unwrapInjectedRef = true\` (this config is ` +
  5018. `temporary and will not be needed in the future.)`);
  5019. }
  5020. ctx[key] = injected;
  5021. }
  5022. }
  5023. else {
  5024. ctx[key] = injected;
  5025. }
  5026. {
  5027. checkDuplicateProperties("Inject" /* INJECT */, key);
  5028. }
  5029. }
  5030. }
  5031. function callHook(hook, instance, type) {
  5032. callWithAsyncErrorHandling(isArray(hook)
  5033. ? hook.map(h => h.bind(instance.proxy))
  5034. : hook.bind(instance.proxy), instance, type);
  5035. }
  5036. function createWatcher(raw, ctx, publicThis, key) {
  5037. const getter = key.includes('.')
  5038. ? createPathGetter(publicThis, key)
  5039. : () => publicThis[key];
  5040. if (isString(raw)) {
  5041. const handler = ctx[raw];
  5042. if (isFunction(handler)) {
  5043. watch(getter, handler);
  5044. }
  5045. else {
  5046. warn$1(`Invalid watch handler specified by key "${raw}"`, handler);
  5047. }
  5048. }
  5049. else if (isFunction(raw)) {
  5050. watch(getter, raw.bind(publicThis));
  5051. }
  5052. else if (isObject(raw)) {
  5053. if (isArray(raw)) {
  5054. raw.forEach(r => createWatcher(r, ctx, publicThis, key));
  5055. }
  5056. else {
  5057. const handler = isFunction(raw.handler)
  5058. ? raw.handler.bind(publicThis)
  5059. : ctx[raw.handler];
  5060. if (isFunction(handler)) {
  5061. watch(getter, handler, raw);
  5062. }
  5063. else {
  5064. warn$1(`Invalid watch handler specified by key "${raw.handler}"`, handler);
  5065. }
  5066. }
  5067. }
  5068. else {
  5069. warn$1(`Invalid watch option: "${key}"`, raw);
  5070. }
  5071. }
  5072. /**
  5073. * Resolve merged options and cache it on the component.
  5074. * This is done only once per-component since the merging does not involve
  5075. * instances.
  5076. */
  5077. function resolveMergedOptions(instance) {
  5078. const base = instance.type;
  5079. const { mixins, extends: extendsOptions } = base;
  5080. const { mixins: globalMixins, optionsCache: cache, config: { optionMergeStrategies } } = instance.appContext;
  5081. const cached = cache.get(base);
  5082. let resolved;
  5083. if (cached) {
  5084. resolved = cached;
  5085. }
  5086. else if (!globalMixins.length && !mixins && !extendsOptions) {
  5087. {
  5088. resolved = base;
  5089. }
  5090. }
  5091. else {
  5092. resolved = {};
  5093. if (globalMixins.length) {
  5094. globalMixins.forEach(m => mergeOptions(resolved, m, optionMergeStrategies, true));
  5095. }
  5096. mergeOptions(resolved, base, optionMergeStrategies);
  5097. }
  5098. cache.set(base, resolved);
  5099. return resolved;
  5100. }
  5101. function mergeOptions(to, from, strats, asMixin = false) {
  5102. const { mixins, extends: extendsOptions } = from;
  5103. if (extendsOptions) {
  5104. mergeOptions(to, extendsOptions, strats, true);
  5105. }
  5106. if (mixins) {
  5107. mixins.forEach((m) => mergeOptions(to, m, strats, true));
  5108. }
  5109. for (const key in from) {
  5110. if (asMixin && key === 'expose') {
  5111. warn$1(`"expose" option is ignored when declared in mixins or extends. ` +
  5112. `It should only be declared in the base component itself.`);
  5113. }
  5114. else {
  5115. const strat = internalOptionMergeStrats[key] || (strats && strats[key]);
  5116. to[key] = strat ? strat(to[key], from[key]) : from[key];
  5117. }
  5118. }
  5119. return to;
  5120. }
  5121. const internalOptionMergeStrats = {
  5122. data: mergeDataFn,
  5123. props: mergeObjectOptions,
  5124. emits: mergeObjectOptions,
  5125. // objects
  5126. methods: mergeObjectOptions,
  5127. computed: mergeObjectOptions,
  5128. // lifecycle
  5129. beforeCreate: mergeAsArray,
  5130. created: mergeAsArray,
  5131. beforeMount: mergeAsArray,
  5132. mounted: mergeAsArray,
  5133. beforeUpdate: mergeAsArray,
  5134. updated: mergeAsArray,
  5135. beforeDestroy: mergeAsArray,
  5136. beforeUnmount: mergeAsArray,
  5137. destroyed: mergeAsArray,
  5138. unmounted: mergeAsArray,
  5139. activated: mergeAsArray,
  5140. deactivated: mergeAsArray,
  5141. errorCaptured: mergeAsArray,
  5142. serverPrefetch: mergeAsArray,
  5143. // assets
  5144. components: mergeObjectOptions,
  5145. directives: mergeObjectOptions,
  5146. // watch
  5147. watch: mergeWatchOptions,
  5148. // provide / inject
  5149. provide: mergeDataFn,
  5150. inject: mergeInject
  5151. };
  5152. function mergeDataFn(to, from) {
  5153. if (!from) {
  5154. return to;
  5155. }
  5156. if (!to) {
  5157. return from;
  5158. }
  5159. return function mergedDataFn() {
  5160. return (extend)(isFunction(to) ? to.call(this, this) : to, isFunction(from) ? from.call(this, this) : from);
  5161. };
  5162. }
  5163. function mergeInject(to, from) {
  5164. return mergeObjectOptions(normalizeInject(to), normalizeInject(from));
  5165. }
  5166. function normalizeInject(raw) {
  5167. if (isArray(raw)) {
  5168. const res = {};
  5169. for (let i = 0; i < raw.length; i++) {
  5170. res[raw[i]] = raw[i];
  5171. }
  5172. return res;
  5173. }
  5174. return raw;
  5175. }
  5176. function mergeAsArray(to, from) {
  5177. return to ? [...new Set([].concat(to, from))] : from;
  5178. }
  5179. function mergeObjectOptions(to, from) {
  5180. return to ? extend(extend(Object.create(null), to), from) : from;
  5181. }
  5182. function mergeWatchOptions(to, from) {
  5183. if (!to)
  5184. return from;
  5185. if (!from)
  5186. return to;
  5187. const merged = extend(Object.create(null), to);
  5188. for (const key in from) {
  5189. merged[key] = mergeAsArray(to[key], from[key]);
  5190. }
  5191. return merged;
  5192. }
  5193. function initProps(instance, rawProps, isStateful, // result of bitwise flag comparison
  5194. isSSR = false) {
  5195. const props = {};
  5196. const attrs = {};
  5197. def(attrs, InternalObjectKey, 1);
  5198. instance.propsDefaults = Object.create(null);
  5199. setFullProps(instance, rawProps, props, attrs);
  5200. // ensure all declared prop keys are present
  5201. for (const key in instance.propsOptions[0]) {
  5202. if (!(key in props)) {
  5203. props[key] = undefined;
  5204. }
  5205. }
  5206. // validation
  5207. {
  5208. validateProps(rawProps || {}, props, instance);
  5209. }
  5210. if (isStateful) {
  5211. // stateful
  5212. instance.props = isSSR ? props : shallowReactive(props);
  5213. }
  5214. else {
  5215. if (!instance.type.props) {
  5216. // functional w/ optional props, props === attrs
  5217. instance.props = attrs;
  5218. }
  5219. else {
  5220. // functional w/ declared props
  5221. instance.props = props;
  5222. }
  5223. }
  5224. instance.attrs = attrs;
  5225. }
  5226. function updateProps(instance, rawProps, rawPrevProps, optimized) {
  5227. const { props, attrs, vnode: { patchFlag } } = instance;
  5228. const rawCurrentProps = toRaw(props);
  5229. const [options] = instance.propsOptions;
  5230. let hasAttrsChanged = false;
  5231. if (
  5232. // always force full diff in dev
  5233. // - #1942 if hmr is enabled with sfc component
  5234. // - vite#872 non-sfc component used by sfc component
  5235. !((instance.type.__hmrId ||
  5236. (instance.parent && instance.parent.type.__hmrId))) &&
  5237. (optimized || patchFlag > 0) &&
  5238. !(patchFlag & 16 /* FULL_PROPS */)) {
  5239. if (patchFlag & 8 /* PROPS */) {
  5240. // Compiler-generated props & no keys change, just set the updated
  5241. // the props.
  5242. const propsToUpdate = instance.vnode.dynamicProps;
  5243. for (let i = 0; i < propsToUpdate.length; i++) {
  5244. let key = propsToUpdate[i];
  5245. // skip if the prop key is a declared emit event listener
  5246. if (isEmitListener(instance.emitsOptions, key)) {
  5247. continue;
  5248. }
  5249. // PROPS flag guarantees rawProps to be non-null
  5250. const value = rawProps[key];
  5251. if (options) {
  5252. // attr / props separation was done on init and will be consistent
  5253. // in this code path, so just check if attrs have it.
  5254. if (hasOwn(attrs, key)) {
  5255. if (value !== attrs[key]) {
  5256. attrs[key] = value;
  5257. hasAttrsChanged = true;
  5258. }
  5259. }
  5260. else {
  5261. const camelizedKey = camelize(key);
  5262. props[camelizedKey] = resolvePropValue(options, rawCurrentProps, camelizedKey, value, instance, false /* isAbsent */);
  5263. }
  5264. }
  5265. else {
  5266. if (value !== attrs[key]) {
  5267. attrs[key] = value;
  5268. hasAttrsChanged = true;
  5269. }
  5270. }
  5271. }
  5272. }
  5273. }
  5274. else {
  5275. // full props update.
  5276. if (setFullProps(instance, rawProps, props, attrs)) {
  5277. hasAttrsChanged = true;
  5278. }
  5279. // in case of dynamic props, check if we need to delete keys from
  5280. // the props object
  5281. let kebabKey;
  5282. for (const key in rawCurrentProps) {
  5283. if (!rawProps ||
  5284. // for camelCase
  5285. (!hasOwn(rawProps, key) &&
  5286. // it's possible the original props was passed in as kebab-case
  5287. // and converted to camelCase (#955)
  5288. ((kebabKey = hyphenate(key)) === key || !hasOwn(rawProps, kebabKey)))) {
  5289. if (options) {
  5290. if (rawPrevProps &&
  5291. // for camelCase
  5292. (rawPrevProps[key] !== undefined ||
  5293. // for kebab-case
  5294. rawPrevProps[kebabKey] !== undefined)) {
  5295. props[key] = resolvePropValue(options, rawCurrentProps, key, undefined, instance, true /* isAbsent */);
  5296. }
  5297. }
  5298. else {
  5299. delete props[key];
  5300. }
  5301. }
  5302. }
  5303. // in the case of functional component w/o props declaration, props and
  5304. // attrs point to the same object so it should already have been updated.
  5305. if (attrs !== rawCurrentProps) {
  5306. for (const key in attrs) {
  5307. if (!rawProps ||
  5308. (!hasOwn(rawProps, key) &&
  5309. (!false ))) {
  5310. delete attrs[key];
  5311. hasAttrsChanged = true;
  5312. }
  5313. }
  5314. }
  5315. }
  5316. // trigger updates for $attrs in case it's used in component slots
  5317. if (hasAttrsChanged) {
  5318. trigger(instance, "set" /* SET */, '$attrs');
  5319. }
  5320. {
  5321. validateProps(rawProps || {}, props, instance);
  5322. }
  5323. }
  5324. function setFullProps(instance, rawProps, props, attrs) {
  5325. const [options, needCastKeys] = instance.propsOptions;
  5326. let hasAttrsChanged = false;
  5327. let rawCastValues;
  5328. if (rawProps) {
  5329. for (let key in rawProps) {
  5330. // key, ref are reserved and never passed down
  5331. if (isReservedProp(key)) {
  5332. continue;
  5333. }
  5334. const value = rawProps[key];
  5335. // prop option names are camelized during normalization, so to support
  5336. // kebab -> camel conversion here we need to camelize the key.
  5337. let camelKey;
  5338. if (options && hasOwn(options, (camelKey = camelize(key)))) {
  5339. if (!needCastKeys || !needCastKeys.includes(camelKey)) {
  5340. props[camelKey] = value;
  5341. }
  5342. else {
  5343. (rawCastValues || (rawCastValues = {}))[camelKey] = value;
  5344. }
  5345. }
  5346. else if (!isEmitListener(instance.emitsOptions, key)) {
  5347. if (!(key in attrs) || value !== attrs[key]) {
  5348. attrs[key] = value;
  5349. hasAttrsChanged = true;
  5350. }
  5351. }
  5352. }
  5353. }
  5354. if (needCastKeys) {
  5355. const rawCurrentProps = toRaw(props);
  5356. const castValues = rawCastValues || EMPTY_OBJ;
  5357. for (let i = 0; i < needCastKeys.length; i++) {
  5358. const key = needCastKeys[i];
  5359. props[key] = resolvePropValue(options, rawCurrentProps, key, castValues[key], instance, !hasOwn(castValues, key));
  5360. }
  5361. }
  5362. return hasAttrsChanged;
  5363. }
  5364. function resolvePropValue(options, props, key, value, instance, isAbsent) {
  5365. const opt = options[key];
  5366. if (opt != null) {
  5367. const hasDefault = hasOwn(opt, 'default');
  5368. // default values
  5369. if (hasDefault && value === undefined) {
  5370. const defaultValue = opt.default;
  5371. if (opt.type !== Function && isFunction(defaultValue)) {
  5372. const { propsDefaults } = instance;
  5373. if (key in propsDefaults) {
  5374. value = propsDefaults[key];
  5375. }
  5376. else {
  5377. setCurrentInstance(instance);
  5378. value = propsDefaults[key] = defaultValue.call(null, props);
  5379. unsetCurrentInstance();
  5380. }
  5381. }
  5382. else {
  5383. value = defaultValue;
  5384. }
  5385. }
  5386. // boolean casting
  5387. if (opt[0 /* shouldCast */]) {
  5388. if (isAbsent && !hasDefault) {
  5389. value = false;
  5390. }
  5391. else if (opt[1 /* shouldCastTrue */] &&
  5392. (value === '' || value === hyphenate(key))) {
  5393. value = true;
  5394. }
  5395. }
  5396. }
  5397. return value;
  5398. }
  5399. function normalizePropsOptions(comp, appContext, asMixin = false) {
  5400. const cache = appContext.propsCache;
  5401. const cached = cache.get(comp);
  5402. if (cached) {
  5403. return cached;
  5404. }
  5405. const raw = comp.props;
  5406. const normalized = {};
  5407. const needCastKeys = [];
  5408. // apply mixin/extends props
  5409. let hasExtends = false;
  5410. if (!isFunction(comp)) {
  5411. const extendProps = (raw) => {
  5412. hasExtends = true;
  5413. const [props, keys] = normalizePropsOptions(raw, appContext, true);
  5414. extend(normalized, props);
  5415. if (keys)
  5416. needCastKeys.push(...keys);
  5417. };
  5418. if (!asMixin && appContext.mixins.length) {
  5419. appContext.mixins.forEach(extendProps);
  5420. }
  5421. if (comp.extends) {
  5422. extendProps(comp.extends);
  5423. }
  5424. if (comp.mixins) {
  5425. comp.mixins.forEach(extendProps);
  5426. }
  5427. }
  5428. if (!raw && !hasExtends) {
  5429. cache.set(comp, EMPTY_ARR);
  5430. return EMPTY_ARR;
  5431. }
  5432. if (isArray(raw)) {
  5433. for (let i = 0; i < raw.length; i++) {
  5434. if (!isString(raw[i])) {
  5435. warn$1(`props must be strings when using array syntax.`, raw[i]);
  5436. }
  5437. const normalizedKey = camelize(raw[i]);
  5438. if (validatePropName(normalizedKey)) {
  5439. normalized[normalizedKey] = EMPTY_OBJ;
  5440. }
  5441. }
  5442. }
  5443. else if (raw) {
  5444. if (!isObject(raw)) {
  5445. warn$1(`invalid props options`, raw);
  5446. }
  5447. for (const key in raw) {
  5448. const normalizedKey = camelize(key);
  5449. if (validatePropName(normalizedKey)) {
  5450. const opt = raw[key];
  5451. const prop = (normalized[normalizedKey] =
  5452. isArray(opt) || isFunction(opt) ? { type: opt } : opt);
  5453. if (prop) {
  5454. const booleanIndex = getTypeIndex(Boolean, prop.type);
  5455. const stringIndex = getTypeIndex(String, prop.type);
  5456. prop[0 /* shouldCast */] = booleanIndex > -1;
  5457. prop[1 /* shouldCastTrue */] =
  5458. stringIndex < 0 || booleanIndex < stringIndex;
  5459. // if the prop needs boolean casting or default value
  5460. if (booleanIndex > -1 || hasOwn(prop, 'default')) {
  5461. needCastKeys.push(normalizedKey);
  5462. }
  5463. }
  5464. }
  5465. }
  5466. }
  5467. const res = [normalized, needCastKeys];
  5468. cache.set(comp, res);
  5469. return res;
  5470. }
  5471. function validatePropName(key) {
  5472. if (key[0] !== '$') {
  5473. return true;
  5474. }
  5475. else {
  5476. warn$1(`Invalid prop name: "${key}" is a reserved property.`);
  5477. }
  5478. return false;
  5479. }
  5480. // use function string name to check type constructors
  5481. // so that it works across vms / iframes.
  5482. function getType(ctor) {
  5483. const match = ctor && ctor.toString().match(/^\s*function (\w+)/);
  5484. return match ? match[1] : ctor === null ? 'null' : '';
  5485. }
  5486. function isSameType(a, b) {
  5487. return getType(a) === getType(b);
  5488. }
  5489. function getTypeIndex(type, expectedTypes) {
  5490. if (isArray(expectedTypes)) {
  5491. return expectedTypes.findIndex(t => isSameType(t, type));
  5492. }
  5493. else if (isFunction(expectedTypes)) {
  5494. return isSameType(expectedTypes, type) ? 0 : -1;
  5495. }
  5496. return -1;
  5497. }
  5498. /**
  5499. * dev only
  5500. */
  5501. function validateProps(rawProps, props, instance) {
  5502. const resolvedValues = toRaw(props);
  5503. const options = instance.propsOptions[0];
  5504. for (const key in options) {
  5505. let opt = options[key];
  5506. if (opt == null)
  5507. continue;
  5508. validateProp(key, resolvedValues[key], opt, !hasOwn(rawProps, key) && !hasOwn(rawProps, hyphenate(key)));
  5509. }
  5510. }
  5511. /**
  5512. * dev only
  5513. */
  5514. function validateProp(name, value, prop, isAbsent) {
  5515. const { type, required, validator } = prop;
  5516. // required!
  5517. if (required && isAbsent) {
  5518. warn$1('Missing required prop: "' + name + '"');
  5519. return;
  5520. }
  5521. // missing but optional
  5522. if (value == null && !prop.required) {
  5523. return;
  5524. }
  5525. // type check
  5526. if (type != null && type !== true) {
  5527. let isValid = false;
  5528. const types = isArray(type) ? type : [type];
  5529. const expectedTypes = [];
  5530. // value is valid as long as one of the specified types match
  5531. for (let i = 0; i < types.length && !isValid; i++) {
  5532. const { valid, expectedType } = assertType(value, types[i]);
  5533. expectedTypes.push(expectedType || '');
  5534. isValid = valid;
  5535. }
  5536. if (!isValid) {
  5537. warn$1(getInvalidTypeMessage(name, value, expectedTypes));
  5538. return;
  5539. }
  5540. }
  5541. // custom validator
  5542. if (validator && !validator(value)) {
  5543. warn$1('Invalid prop: custom validator check failed for prop "' + name + '".');
  5544. }
  5545. }
  5546. const isSimpleType = /*#__PURE__*/ makeMap('String,Number,Boolean,Function,Symbol,BigInt');
  5547. /**
  5548. * dev only
  5549. */
  5550. function assertType(value, type) {
  5551. let valid;
  5552. const expectedType = getType(type);
  5553. if (isSimpleType(expectedType)) {
  5554. const t = typeof value;
  5555. valid = t === expectedType.toLowerCase();
  5556. // for primitive wrapper objects
  5557. if (!valid && t === 'object') {
  5558. valid = value instanceof type;
  5559. }
  5560. }
  5561. else if (expectedType === 'Object') {
  5562. valid = isObject(value);
  5563. }
  5564. else if (expectedType === 'Array') {
  5565. valid = isArray(value);
  5566. }
  5567. else if (expectedType === 'null') {
  5568. valid = value === null;
  5569. }
  5570. else {
  5571. valid = value instanceof type;
  5572. }
  5573. return {
  5574. valid,
  5575. expectedType
  5576. };
  5577. }
  5578. /**
  5579. * dev only
  5580. */
  5581. function getInvalidTypeMessage(name, value, expectedTypes) {
  5582. let message = `Invalid prop: type check failed for prop "${name}".` +
  5583. ` Expected ${expectedTypes.map(capitalize).join(' | ')}`;
  5584. const expectedType = expectedTypes[0];
  5585. const receivedType = toRawType(value);
  5586. const expectedValue = styleValue(value, expectedType);
  5587. const receivedValue = styleValue(value, receivedType);
  5588. // check if we need to specify expected value
  5589. if (expectedTypes.length === 1 &&
  5590. isExplicable(expectedType) &&
  5591. !isBoolean(expectedType, receivedType)) {
  5592. message += ` with value ${expectedValue}`;
  5593. }
  5594. message += `, got ${receivedType} `;
  5595. // check if we need to specify received value
  5596. if (isExplicable(receivedType)) {
  5597. message += `with value ${receivedValue}.`;
  5598. }
  5599. return message;
  5600. }
  5601. /**
  5602. * dev only
  5603. */
  5604. function styleValue(value, type) {
  5605. if (type === 'String') {
  5606. return `"${value}"`;
  5607. }
  5608. else if (type === 'Number') {
  5609. return `${Number(value)}`;
  5610. }
  5611. else {
  5612. return `${value}`;
  5613. }
  5614. }
  5615. /**
  5616. * dev only
  5617. */
  5618. function isExplicable(type) {
  5619. const explicitTypes = ['string', 'number', 'boolean'];
  5620. return explicitTypes.some(elem => type.toLowerCase() === elem);
  5621. }
  5622. /**
  5623. * dev only
  5624. */
  5625. function isBoolean(...args) {
  5626. return args.some(elem => elem.toLowerCase() === 'boolean');
  5627. }
  5628. const isInternalKey = (key) => key[0] === '_' || key === '$stable';
  5629. const normalizeSlotValue = (value) => isArray(value)
  5630. ? value.map(normalizeVNode)
  5631. : [normalizeVNode(value)];
  5632. const normalizeSlot = (key, rawSlot, ctx) => {
  5633. if (rawSlot._n) {
  5634. // already normalized - #5353
  5635. return rawSlot;
  5636. }
  5637. const normalized = withCtx((...args) => {
  5638. if (currentInstance) {
  5639. warn$1(`Slot "${key}" invoked outside of the render function: ` +
  5640. `this will not track dependencies used in the slot. ` +
  5641. `Invoke the slot function inside the render function instead.`);
  5642. }
  5643. return normalizeSlotValue(rawSlot(...args));
  5644. }, ctx);
  5645. normalized._c = false;
  5646. return normalized;
  5647. };
  5648. const normalizeObjectSlots = (rawSlots, slots, instance) => {
  5649. const ctx = rawSlots._ctx;
  5650. for (const key in rawSlots) {
  5651. if (isInternalKey(key))
  5652. continue;
  5653. const value = rawSlots[key];
  5654. if (isFunction(value)) {
  5655. slots[key] = normalizeSlot(key, value, ctx);
  5656. }
  5657. else if (value != null) {
  5658. {
  5659. warn$1(`Non-function value encountered for slot "${key}". ` +
  5660. `Prefer function slots for better performance.`);
  5661. }
  5662. const normalized = normalizeSlotValue(value);
  5663. slots[key] = () => normalized;
  5664. }
  5665. }
  5666. };
  5667. const normalizeVNodeSlots = (instance, children) => {
  5668. if (!isKeepAlive(instance.vnode) &&
  5669. !(false )) {
  5670. warn$1(`Non-function value encountered for default slot. ` +
  5671. `Prefer function slots for better performance.`);
  5672. }
  5673. const normalized = normalizeSlotValue(children);
  5674. instance.slots.default = () => normalized;
  5675. };
  5676. const initSlots = (instance, children) => {
  5677. if (instance.vnode.shapeFlag & 32 /* SLOTS_CHILDREN */) {
  5678. const type = children._;
  5679. if (type) {
  5680. // users can get the shallow readonly version of the slots object through `this.$slots`,
  5681. // we should avoid the proxy object polluting the slots of the internal instance
  5682. instance.slots = toRaw(children);
  5683. // make compiler marker non-enumerable
  5684. def(children, '_', type);
  5685. }
  5686. else {
  5687. normalizeObjectSlots(children, (instance.slots = {}));
  5688. }
  5689. }
  5690. else {
  5691. instance.slots = {};
  5692. if (children) {
  5693. normalizeVNodeSlots(instance, children);
  5694. }
  5695. }
  5696. def(instance.slots, InternalObjectKey, 1);
  5697. };
  5698. const updateSlots = (instance, children, optimized) => {
  5699. const { vnode, slots } = instance;
  5700. let needDeletionCheck = true;
  5701. let deletionComparisonTarget = EMPTY_OBJ;
  5702. if (vnode.shapeFlag & 32 /* SLOTS_CHILDREN */) {
  5703. const type = children._;
  5704. if (type) {
  5705. // compiled slots.
  5706. if (isHmrUpdating) {
  5707. // Parent was HMR updated so slot content may have changed.
  5708. // force update slots and mark instance for hmr as well
  5709. extend(slots, children);
  5710. }
  5711. else if (optimized && type === 1 /* STABLE */) {
  5712. // compiled AND stable.
  5713. // no need to update, and skip stale slots removal.
  5714. needDeletionCheck = false;
  5715. }
  5716. else {
  5717. // compiled but dynamic (v-if/v-for on slots) - update slots, but skip
  5718. // normalization.
  5719. extend(slots, children);
  5720. // #2893
  5721. // when rendering the optimized slots by manually written render function,
  5722. // we need to delete the `slots._` flag if necessary to make subsequent updates reliable,
  5723. // i.e. let the `renderSlot` create the bailed Fragment
  5724. if (!optimized && type === 1 /* STABLE */) {
  5725. delete slots._;
  5726. }
  5727. }
  5728. }
  5729. else {
  5730. needDeletionCheck = !children.$stable;
  5731. normalizeObjectSlots(children, slots);
  5732. }
  5733. deletionComparisonTarget = children;
  5734. }
  5735. else if (children) {
  5736. // non slot object children (direct value) passed to a component
  5737. normalizeVNodeSlots(instance, children);
  5738. deletionComparisonTarget = { default: 1 };
  5739. }
  5740. // delete stale slots
  5741. if (needDeletionCheck) {
  5742. for (const key in slots) {
  5743. if (!isInternalKey(key) && !(key in deletionComparisonTarget)) {
  5744. delete slots[key];
  5745. }
  5746. }
  5747. }
  5748. };
  5749. function createAppContext() {
  5750. return {
  5751. app: null,
  5752. config: {
  5753. isNativeTag: NO,
  5754. performance: false,
  5755. globalProperties: {},
  5756. optionMergeStrategies: {},
  5757. errorHandler: undefined,
  5758. warnHandler: undefined,
  5759. compilerOptions: {}
  5760. },
  5761. mixins: [],
  5762. components: {},
  5763. directives: {},
  5764. provides: Object.create(null),
  5765. optionsCache: new WeakMap(),
  5766. propsCache: new WeakMap(),
  5767. emitsCache: new WeakMap()
  5768. };
  5769. }
  5770. let uid = 0;
  5771. function createAppAPI(render, hydrate) {
  5772. return function createApp(rootComponent, rootProps = null) {
  5773. if (!isFunction(rootComponent)) {
  5774. rootComponent = Object.assign({}, rootComponent);
  5775. }
  5776. if (rootProps != null && !isObject(rootProps)) {
  5777. warn$1(`root props passed to app.mount() must be an object.`);
  5778. rootProps = null;
  5779. }
  5780. const context = createAppContext();
  5781. const installedPlugins = new Set();
  5782. let isMounted = false;
  5783. const app = (context.app = {
  5784. _uid: uid++,
  5785. _component: rootComponent,
  5786. _props: rootProps,
  5787. _container: null,
  5788. _context: context,
  5789. _instance: null,
  5790. version,
  5791. get config() {
  5792. return context.config;
  5793. },
  5794. set config(v) {
  5795. {
  5796. warn$1(`app.config cannot be replaced. Modify individual options instead.`);
  5797. }
  5798. },
  5799. use(plugin, ...options) {
  5800. if (installedPlugins.has(plugin)) {
  5801. warn$1(`Plugin has already been applied to target app.`);
  5802. }
  5803. else if (plugin && isFunction(plugin.install)) {
  5804. installedPlugins.add(plugin);
  5805. plugin.install(app, ...options);
  5806. }
  5807. else if (isFunction(plugin)) {
  5808. installedPlugins.add(plugin);
  5809. plugin(app, ...options);
  5810. }
  5811. else {
  5812. warn$1(`A plugin must either be a function or an object with an "install" ` +
  5813. `function.`);
  5814. }
  5815. return app;
  5816. },
  5817. mixin(mixin) {
  5818. {
  5819. if (!context.mixins.includes(mixin)) {
  5820. context.mixins.push(mixin);
  5821. }
  5822. else {
  5823. warn$1('Mixin has already been applied to target app' +
  5824. (mixin.name ? `: ${mixin.name}` : ''));
  5825. }
  5826. }
  5827. return app;
  5828. },
  5829. component(name, component) {
  5830. {
  5831. validateComponentName(name, context.config);
  5832. }
  5833. if (!component) {
  5834. return context.components[name];
  5835. }
  5836. if (context.components[name]) {
  5837. warn$1(`Component "${name}" has already been registered in target app.`);
  5838. }
  5839. context.components[name] = component;
  5840. return app;
  5841. },
  5842. directive(name, directive) {
  5843. {
  5844. validateDirectiveName(name);
  5845. }
  5846. if (!directive) {
  5847. return context.directives[name];
  5848. }
  5849. if (context.directives[name]) {
  5850. warn$1(`Directive "${name}" has already been registered in target app.`);
  5851. }
  5852. context.directives[name] = directive;
  5853. return app;
  5854. },
  5855. mount(rootContainer, isHydrate, isSVG) {
  5856. if (!isMounted) {
  5857. // #5571
  5858. if (rootContainer.__vue_app__) {
  5859. warn$1(`There is already an app instance mounted on the host container.\n` +
  5860. ` If you want to mount another app on the same host container,` +
  5861. ` you need to unmount the previous app by calling \`app.unmount()\` first.`);
  5862. }
  5863. const vnode = createVNode(rootComponent, rootProps);
  5864. // store app context on the root VNode.
  5865. // this will be set on the root instance on initial mount.
  5866. vnode.appContext = context;
  5867. // HMR root reload
  5868. {
  5869. context.reload = () => {
  5870. render(cloneVNode(vnode), rootContainer, isSVG);
  5871. };
  5872. }
  5873. if (isHydrate && hydrate) {
  5874. hydrate(vnode, rootContainer);
  5875. }
  5876. else {
  5877. render(vnode, rootContainer, isSVG);
  5878. }
  5879. isMounted = true;
  5880. app._container = rootContainer;
  5881. rootContainer.__vue_app__ = app;
  5882. {
  5883. app._instance = vnode.component;
  5884. devtoolsInitApp(app, version);
  5885. }
  5886. return getExposeProxy(vnode.component) || vnode.component.proxy;
  5887. }
  5888. else {
  5889. warn$1(`App has already been mounted.\n` +
  5890. `If you want to remount the same app, move your app creation logic ` +
  5891. `into a factory function and create fresh app instances for each ` +
  5892. `mount - e.g. \`const createMyApp = () => createApp(App)\``);
  5893. }
  5894. },
  5895. unmount() {
  5896. if (isMounted) {
  5897. render(null, app._container);
  5898. {
  5899. app._instance = null;
  5900. devtoolsUnmountApp(app);
  5901. }
  5902. delete app._container.__vue_app__;
  5903. }
  5904. else {
  5905. warn$1(`Cannot unmount an app that is not mounted.`);
  5906. }
  5907. },
  5908. provide(key, value) {
  5909. if (key in context.provides) {
  5910. warn$1(`App already provides property with key "${String(key)}". ` +
  5911. `It will be overwritten with the new value.`);
  5912. }
  5913. context.provides[key] = value;
  5914. return app;
  5915. }
  5916. });
  5917. return app;
  5918. };
  5919. }
  5920. /**
  5921. * Function for handling a template ref
  5922. */
  5923. function setRef(rawRef, oldRawRef, parentSuspense, vnode, isUnmount = false) {
  5924. if (isArray(rawRef)) {
  5925. rawRef.forEach((r, i) => setRef(r, oldRawRef && (isArray(oldRawRef) ? oldRawRef[i] : oldRawRef), parentSuspense, vnode, isUnmount));
  5926. return;
  5927. }
  5928. if (isAsyncWrapper(vnode) && !isUnmount) {
  5929. // when mounting async components, nothing needs to be done,
  5930. // because the template ref is forwarded to inner component
  5931. return;
  5932. }
  5933. const refValue = vnode.shapeFlag & 4 /* STATEFUL_COMPONENT */
  5934. ? getExposeProxy(vnode.component) || vnode.component.proxy
  5935. : vnode.el;
  5936. const value = isUnmount ? null : refValue;
  5937. const { i: owner, r: ref } = rawRef;
  5938. if (!owner) {
  5939. warn$1(`Missing ref owner context. ref cannot be used on hoisted vnodes. ` +
  5940. `A vnode with ref must be created inside the render function.`);
  5941. return;
  5942. }
  5943. const oldRef = oldRawRef && oldRawRef.r;
  5944. const refs = owner.refs === EMPTY_OBJ ? (owner.refs = {}) : owner.refs;
  5945. const setupState = owner.setupState;
  5946. // dynamic ref changed. unset old ref
  5947. if (oldRef != null && oldRef !== ref) {
  5948. if (isString(oldRef)) {
  5949. refs[oldRef] = null;
  5950. if (hasOwn(setupState, oldRef)) {
  5951. setupState[oldRef] = null;
  5952. }
  5953. }
  5954. else if (isRef(oldRef)) {
  5955. oldRef.value = null;
  5956. }
  5957. }
  5958. if (isFunction(ref)) {
  5959. callWithErrorHandling(ref, owner, 12 /* FUNCTION_REF */, [value, refs]);
  5960. }
  5961. else {
  5962. const _isString = isString(ref);
  5963. const _isRef = isRef(ref);
  5964. if (_isString || _isRef) {
  5965. const doSet = () => {
  5966. if (rawRef.f) {
  5967. const existing = _isString ? refs[ref] : ref.value;
  5968. if (isUnmount) {
  5969. isArray(existing) && remove(existing, refValue);
  5970. }
  5971. else {
  5972. if (!isArray(existing)) {
  5973. if (_isString) {
  5974. refs[ref] = [refValue];
  5975. if (hasOwn(setupState, ref)) {
  5976. setupState[ref] = refs[ref];
  5977. }
  5978. }
  5979. else {
  5980. ref.value = [refValue];
  5981. if (rawRef.k)
  5982. refs[rawRef.k] = ref.value;
  5983. }
  5984. }
  5985. else if (!existing.includes(refValue)) {
  5986. existing.push(refValue);
  5987. }
  5988. }
  5989. }
  5990. else if (_isString) {
  5991. refs[ref] = value;
  5992. if (hasOwn(setupState, ref)) {
  5993. setupState[ref] = value;
  5994. }
  5995. }
  5996. else if (isRef(ref)) {
  5997. ref.value = value;
  5998. if (rawRef.k)
  5999. refs[rawRef.k] = value;
  6000. }
  6001. else {
  6002. warn$1('Invalid template ref type:', ref, `(${typeof ref})`);
  6003. }
  6004. };
  6005. if (value) {
  6006. doSet.id = -1;
  6007. queuePostRenderEffect(doSet, parentSuspense);
  6008. }
  6009. else {
  6010. doSet();
  6011. }
  6012. }
  6013. else {
  6014. warn$1('Invalid template ref type:', ref, `(${typeof ref})`);
  6015. }
  6016. }
  6017. }
  6018. let hasMismatch = false;
  6019. const isSVGContainer = (container) => /svg/.test(container.namespaceURI) && container.tagName !== 'foreignObject';
  6020. const isComment = (node) => node.nodeType === 8 /* COMMENT */;
  6021. // Note: hydration is DOM-specific
  6022. // But we have to place it in core due to tight coupling with core - splitting
  6023. // it out creates a ton of unnecessary complexity.
  6024. // Hydration also depends on some renderer internal logic which needs to be
  6025. // passed in via arguments.
  6026. function createHydrationFunctions(rendererInternals) {
  6027. const { mt: mountComponent, p: patch, o: { patchProp, createText, nextSibling, parentNode, remove, insert, createComment } } = rendererInternals;
  6028. const hydrate = (vnode, container) => {
  6029. if (!container.hasChildNodes()) {
  6030. warn$1(`Attempting to hydrate existing markup but container is empty. ` +
  6031. `Performing full mount instead.`);
  6032. patch(null, vnode, container);
  6033. flushPostFlushCbs();
  6034. return;
  6035. }
  6036. hasMismatch = false;
  6037. hydrateNode(container.firstChild, vnode, null, null, null);
  6038. flushPostFlushCbs();
  6039. if (hasMismatch && !false) {
  6040. // this error should show up in production
  6041. console.error(`Hydration completed but contains mismatches.`);
  6042. }
  6043. };
  6044. const hydrateNode = (node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized = false) => {
  6045. const isFragmentStart = isComment(node) && node.data === '[';
  6046. const onMismatch = () => handleMismatch(node, vnode, parentComponent, parentSuspense, slotScopeIds, isFragmentStart);
  6047. const { type, ref, shapeFlag, patchFlag } = vnode;
  6048. const domType = node.nodeType;
  6049. vnode.el = node;
  6050. if (patchFlag === -2 /* BAIL */) {
  6051. optimized = false;
  6052. vnode.dynamicChildren = null;
  6053. }
  6054. let nextNode = null;
  6055. switch (type) {
  6056. case Text:
  6057. if (domType !== 3 /* TEXT */) {
  6058. // #5728 empty text node inside a slot can cause hydration failure
  6059. // because the server rendered HTML won't contain a text node
  6060. if (vnode.children === '') {
  6061. insert((vnode.el = createText('')), parentNode(node), node);
  6062. nextNode = node;
  6063. }
  6064. else {
  6065. nextNode = onMismatch();
  6066. }
  6067. }
  6068. else {
  6069. if (node.data !== vnode.children) {
  6070. hasMismatch = true;
  6071. warn$1(`Hydration text mismatch:` +
  6072. `\n- Client: ${JSON.stringify(node.data)}` +
  6073. `\n- Server: ${JSON.stringify(vnode.children)}`);
  6074. node.data = vnode.children;
  6075. }
  6076. nextNode = nextSibling(node);
  6077. }
  6078. break;
  6079. case Comment:
  6080. if (domType !== 8 /* COMMENT */ || isFragmentStart) {
  6081. nextNode = onMismatch();
  6082. }
  6083. else {
  6084. nextNode = nextSibling(node);
  6085. }
  6086. break;
  6087. case Static:
  6088. if (domType !== 1 /* ELEMENT */) {
  6089. nextNode = onMismatch();
  6090. }
  6091. else {
  6092. // determine anchor, adopt content
  6093. nextNode = node;
  6094. // if the static vnode has its content stripped during build,
  6095. // adopt it from the server-rendered HTML.
  6096. const needToAdoptContent = !vnode.children.length;
  6097. for (let i = 0; i < vnode.staticCount; i++) {
  6098. if (needToAdoptContent)
  6099. vnode.children += nextNode.outerHTML;
  6100. if (i === vnode.staticCount - 1) {
  6101. vnode.anchor = nextNode;
  6102. }
  6103. nextNode = nextSibling(nextNode);
  6104. }
  6105. return nextNode;
  6106. }
  6107. break;
  6108. case Fragment:
  6109. if (!isFragmentStart) {
  6110. nextNode = onMismatch();
  6111. }
  6112. else {
  6113. nextNode = hydrateFragment(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized);
  6114. }
  6115. break;
  6116. default:
  6117. if (shapeFlag & 1 /* ELEMENT */) {
  6118. if (domType !== 1 /* ELEMENT */ ||
  6119. vnode.type.toLowerCase() !==
  6120. node.tagName.toLowerCase()) {
  6121. nextNode = onMismatch();
  6122. }
  6123. else {
  6124. nextNode = hydrateElement(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized);
  6125. }
  6126. }
  6127. else if (shapeFlag & 6 /* COMPONENT */) {
  6128. // when setting up the render effect, if the initial vnode already
  6129. // has .el set, the component will perform hydration instead of mount
  6130. // on its sub-tree.
  6131. vnode.slotScopeIds = slotScopeIds;
  6132. const container = parentNode(node);
  6133. mountComponent(vnode, container, null, parentComponent, parentSuspense, isSVGContainer(container), optimized);
  6134. // component may be async, so in the case of fragments we cannot rely
  6135. // on component's rendered output to determine the end of the fragment
  6136. // instead, we do a lookahead to find the end anchor node.
  6137. nextNode = isFragmentStart
  6138. ? locateClosingAsyncAnchor(node)
  6139. : nextSibling(node);
  6140. // #4293 teleport as component root
  6141. if (nextNode &&
  6142. isComment(nextNode) &&
  6143. nextNode.data === 'teleport end') {
  6144. nextNode = nextSibling(nextNode);
  6145. }
  6146. // #3787
  6147. // if component is async, it may get moved / unmounted before its
  6148. // inner component is loaded, so we need to give it a placeholder
  6149. // vnode that matches its adopted DOM.
  6150. if (isAsyncWrapper(vnode)) {
  6151. let subTree;
  6152. if (isFragmentStart) {
  6153. subTree = createVNode(Fragment);
  6154. subTree.anchor = nextNode
  6155. ? nextNode.previousSibling
  6156. : container.lastChild;
  6157. }
  6158. else {
  6159. subTree =
  6160. node.nodeType === 3 ? createTextVNode('') : createVNode('div');
  6161. }
  6162. subTree.el = node;
  6163. vnode.component.subTree = subTree;
  6164. }
  6165. }
  6166. else if (shapeFlag & 64 /* TELEPORT */) {
  6167. if (domType !== 8 /* COMMENT */) {
  6168. nextNode = onMismatch();
  6169. }
  6170. else {
  6171. nextNode = vnode.type.hydrate(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized, rendererInternals, hydrateChildren);
  6172. }
  6173. }
  6174. else if (shapeFlag & 128 /* SUSPENSE */) {
  6175. nextNode = vnode.type.hydrate(node, vnode, parentComponent, parentSuspense, isSVGContainer(parentNode(node)), slotScopeIds, optimized, rendererInternals, hydrateNode);
  6176. }
  6177. else {
  6178. warn$1('Invalid HostVNode type:', type, `(${typeof type})`);
  6179. }
  6180. }
  6181. if (ref != null) {
  6182. setRef(ref, null, parentSuspense, vnode);
  6183. }
  6184. return nextNode;
  6185. };
  6186. const hydrateElement = (el, vnode, parentComponent, parentSuspense, slotScopeIds, optimized) => {
  6187. optimized = optimized || !!vnode.dynamicChildren;
  6188. const { type, props, patchFlag, shapeFlag, dirs } = vnode;
  6189. // #4006 for form elements with non-string v-model value bindings
  6190. // e.g. <option :value="obj">, <input type="checkbox" :true-value="1">
  6191. const forcePatchValue = (type === 'input' && dirs) || type === 'option';
  6192. // skip props & children if this is hoisted static nodes
  6193. // #5405 in dev, always hydrate children for HMR
  6194. {
  6195. if (dirs) {
  6196. invokeDirectiveHook(vnode, null, parentComponent, 'created');
  6197. }
  6198. // props
  6199. if (props) {
  6200. if (forcePatchValue ||
  6201. !optimized ||
  6202. patchFlag & (16 /* FULL_PROPS */ | 32 /* HYDRATE_EVENTS */)) {
  6203. for (const key in props) {
  6204. if ((forcePatchValue && key.endsWith('value')) ||
  6205. (isOn(key) && !isReservedProp(key))) {
  6206. patchProp(el, key, null, props[key], false, undefined, parentComponent);
  6207. }
  6208. }
  6209. }
  6210. else if (props.onClick) {
  6211. // Fast path for click listeners (which is most often) to avoid
  6212. // iterating through props.
  6213. patchProp(el, 'onClick', null, props.onClick, false, undefined, parentComponent);
  6214. }
  6215. }
  6216. // vnode / directive hooks
  6217. let vnodeHooks;
  6218. if ((vnodeHooks = props && props.onVnodeBeforeMount)) {
  6219. invokeVNodeHook(vnodeHooks, parentComponent, vnode);
  6220. }
  6221. if (dirs) {
  6222. invokeDirectiveHook(vnode, null, parentComponent, 'beforeMount');
  6223. }
  6224. if ((vnodeHooks = props && props.onVnodeMounted) || dirs) {
  6225. queueEffectWithSuspense(() => {
  6226. vnodeHooks && invokeVNodeHook(vnodeHooks, parentComponent, vnode);
  6227. dirs && invokeDirectiveHook(vnode, null, parentComponent, 'mounted');
  6228. }, parentSuspense);
  6229. }
  6230. // children
  6231. if (shapeFlag & 16 /* ARRAY_CHILDREN */ &&
  6232. // skip if element has innerHTML / textContent
  6233. !(props && (props.innerHTML || props.textContent))) {
  6234. let next = hydrateChildren(el.firstChild, vnode, el, parentComponent, parentSuspense, slotScopeIds, optimized);
  6235. let hasWarned = false;
  6236. while (next) {
  6237. hasMismatch = true;
  6238. if (!hasWarned) {
  6239. warn$1(`Hydration children mismatch in <${vnode.type}>: ` +
  6240. `server rendered element contains more child nodes than client vdom.`);
  6241. hasWarned = true;
  6242. }
  6243. // The SSRed DOM contains more nodes than it should. Remove them.
  6244. const cur = next;
  6245. next = next.nextSibling;
  6246. remove(cur);
  6247. }
  6248. }
  6249. else if (shapeFlag & 8 /* TEXT_CHILDREN */) {
  6250. if (el.textContent !== vnode.children) {
  6251. hasMismatch = true;
  6252. warn$1(`Hydration text content mismatch in <${vnode.type}>:\n` +
  6253. `- Client: ${el.textContent}\n` +
  6254. `- Server: ${vnode.children}`);
  6255. el.textContent = vnode.children;
  6256. }
  6257. }
  6258. }
  6259. return el.nextSibling;
  6260. };
  6261. const hydrateChildren = (node, parentVNode, container, parentComponent, parentSuspense, slotScopeIds, optimized) => {
  6262. optimized = optimized || !!parentVNode.dynamicChildren;
  6263. const children = parentVNode.children;
  6264. const l = children.length;
  6265. let hasWarned = false;
  6266. for (let i = 0; i < l; i++) {
  6267. const vnode = optimized
  6268. ? children[i]
  6269. : (children[i] = normalizeVNode(children[i]));
  6270. if (node) {
  6271. node = hydrateNode(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized);
  6272. }
  6273. else if (vnode.type === Text && !vnode.children) {
  6274. continue;
  6275. }
  6276. else {
  6277. hasMismatch = true;
  6278. if (!hasWarned) {
  6279. warn$1(`Hydration children mismatch in <${container.tagName.toLowerCase()}>: ` +
  6280. `server rendered element contains fewer child nodes than client vdom.`);
  6281. hasWarned = true;
  6282. }
  6283. // the SSRed DOM didn't contain enough nodes. Mount the missing ones.
  6284. patch(null, vnode, container, null, parentComponent, parentSuspense, isSVGContainer(container), slotScopeIds);
  6285. }
  6286. }
  6287. return node;
  6288. };
  6289. const hydrateFragment = (node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized) => {
  6290. const { slotScopeIds: fragmentSlotScopeIds } = vnode;
  6291. if (fragmentSlotScopeIds) {
  6292. slotScopeIds = slotScopeIds
  6293. ? slotScopeIds.concat(fragmentSlotScopeIds)
  6294. : fragmentSlotScopeIds;
  6295. }
  6296. const container = parentNode(node);
  6297. const next = hydrateChildren(nextSibling(node), vnode, container, parentComponent, parentSuspense, slotScopeIds, optimized);
  6298. if (next && isComment(next) && next.data === ']') {
  6299. return nextSibling((vnode.anchor = next));
  6300. }
  6301. else {
  6302. // fragment didn't hydrate successfully, since we didn't get a end anchor
  6303. // back. This should have led to node/children mismatch warnings.
  6304. hasMismatch = true;
  6305. // since the anchor is missing, we need to create one and insert it
  6306. insert((vnode.anchor = createComment(`]`)), container, next);
  6307. return next;
  6308. }
  6309. };
  6310. const handleMismatch = (node, vnode, parentComponent, parentSuspense, slotScopeIds, isFragment) => {
  6311. hasMismatch = true;
  6312. warn$1(`Hydration node mismatch:\n- Client vnode:`, vnode.type, `\n- Server rendered DOM:`, node, node.nodeType === 3 /* TEXT */
  6313. ? `(text)`
  6314. : isComment(node) && node.data === '['
  6315. ? `(start of fragment)`
  6316. : ``);
  6317. vnode.el = null;
  6318. if (isFragment) {
  6319. // remove excessive fragment nodes
  6320. const end = locateClosingAsyncAnchor(node);
  6321. while (true) {
  6322. const next = nextSibling(node);
  6323. if (next && next !== end) {
  6324. remove(next);
  6325. }
  6326. else {
  6327. break;
  6328. }
  6329. }
  6330. }
  6331. const next = nextSibling(node);
  6332. const container = parentNode(node);
  6333. remove(node);
  6334. patch(null, vnode, container, next, parentComponent, parentSuspense, isSVGContainer(container), slotScopeIds);
  6335. return next;
  6336. };
  6337. const locateClosingAsyncAnchor = (node) => {
  6338. let match = 0;
  6339. while (node) {
  6340. node = nextSibling(node);
  6341. if (node && isComment(node)) {
  6342. if (node.data === '[')
  6343. match++;
  6344. if (node.data === ']') {
  6345. if (match === 0) {
  6346. return nextSibling(node);
  6347. }
  6348. else {
  6349. match--;
  6350. }
  6351. }
  6352. }
  6353. }
  6354. return node;
  6355. };
  6356. return [hydrate, hydrateNode];
  6357. }
  6358. /* eslint-disable no-restricted-globals */
  6359. let supported;
  6360. let perf;
  6361. function startMeasure(instance, type) {
  6362. if (instance.appContext.config.performance && isSupported()) {
  6363. perf.mark(`vue-${type}-${instance.uid}`);
  6364. }
  6365. {
  6366. devtoolsPerfStart(instance, type, isSupported() ? perf.now() : Date.now());
  6367. }
  6368. }
  6369. function endMeasure(instance, type) {
  6370. if (instance.appContext.config.performance && isSupported()) {
  6371. const startTag = `vue-${type}-${instance.uid}`;
  6372. const endTag = startTag + `:end`;
  6373. perf.mark(endTag);
  6374. perf.measure(`<${formatComponentName(instance, instance.type)}> ${type}`, startTag, endTag);
  6375. perf.clearMarks(startTag);
  6376. perf.clearMarks(endTag);
  6377. }
  6378. {
  6379. devtoolsPerfEnd(instance, type, isSupported() ? perf.now() : Date.now());
  6380. }
  6381. }
  6382. function isSupported() {
  6383. if (supported !== undefined) {
  6384. return supported;
  6385. }
  6386. if (typeof window !== 'undefined' && window.performance) {
  6387. supported = true;
  6388. perf = window.performance;
  6389. }
  6390. else {
  6391. supported = false;
  6392. }
  6393. return supported;
  6394. }
  6395. const queuePostRenderEffect = queueEffectWithSuspense
  6396. ;
  6397. /**
  6398. * The createRenderer function accepts two generic arguments:
  6399. * HostNode and HostElement, corresponding to Node and Element types in the
  6400. * host environment. For example, for runtime-dom, HostNode would be the DOM
  6401. * `Node` interface and HostElement would be the DOM `Element` interface.
  6402. *
  6403. * Custom renderers can pass in the platform specific types like this:
  6404. *
  6405. * ``` js
  6406. * const { render, createApp } = createRenderer<Node, Element>({
  6407. * patchProp,
  6408. * ...nodeOps
  6409. * })
  6410. * ```
  6411. */
  6412. function createRenderer(options) {
  6413. return baseCreateRenderer(options);
  6414. }
  6415. // Separate API for creating hydration-enabled renderer.
  6416. // Hydration logic is only used when calling this function, making it
  6417. // tree-shakable.
  6418. function createHydrationRenderer(options) {
  6419. return baseCreateRenderer(options, createHydrationFunctions);
  6420. }
  6421. // implementation
  6422. function baseCreateRenderer(options, createHydrationFns) {
  6423. const target = getGlobalThis();
  6424. target.__VUE__ = true;
  6425. {
  6426. setDevtoolsHook(target.__VUE_DEVTOOLS_GLOBAL_HOOK__, target);
  6427. }
  6428. 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;
  6429. // Note: functions inside this closure should use `const xxx = () => {}`
  6430. // style in order to prevent being inlined by minifiers.
  6431. const patch = (n1, n2, container, anchor = null, parentComponent = null, parentSuspense = null, isSVG = false, slotScopeIds = null, optimized = isHmrUpdating ? false : !!n2.dynamicChildren) => {
  6432. if (n1 === n2) {
  6433. return;
  6434. }
  6435. // patching & not same type, unmount old tree
  6436. if (n1 && !isSameVNodeType(n1, n2)) {
  6437. anchor = getNextHostNode(n1);
  6438. unmount(n1, parentComponent, parentSuspense, true);
  6439. n1 = null;
  6440. }
  6441. if (n2.patchFlag === -2 /* BAIL */) {
  6442. optimized = false;
  6443. n2.dynamicChildren = null;
  6444. }
  6445. const { type, ref, shapeFlag } = n2;
  6446. switch (type) {
  6447. case Text:
  6448. processText(n1, n2, container, anchor);
  6449. break;
  6450. case Comment:
  6451. processCommentNode(n1, n2, container, anchor);
  6452. break;
  6453. case Static:
  6454. if (n1 == null) {
  6455. mountStaticNode(n2, container, anchor, isSVG);
  6456. }
  6457. else {
  6458. patchStaticNode(n1, n2, container, isSVG);
  6459. }
  6460. break;
  6461. case Fragment:
  6462. processFragment(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6463. break;
  6464. default:
  6465. if (shapeFlag & 1 /* ELEMENT */) {
  6466. processElement(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6467. }
  6468. else if (shapeFlag & 6 /* COMPONENT */) {
  6469. processComponent(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6470. }
  6471. else if (shapeFlag & 64 /* TELEPORT */) {
  6472. type.process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, internals);
  6473. }
  6474. else if (shapeFlag & 128 /* SUSPENSE */) {
  6475. type.process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, internals);
  6476. }
  6477. else {
  6478. warn$1('Invalid VNode type:', type, `(${typeof type})`);
  6479. }
  6480. }
  6481. // set ref
  6482. if (ref != null && parentComponent) {
  6483. setRef(ref, n1 && n1.ref, parentSuspense, n2 || n1, !n2);
  6484. }
  6485. };
  6486. const processText = (n1, n2, container, anchor) => {
  6487. if (n1 == null) {
  6488. hostInsert((n2.el = hostCreateText(n2.children)), container, anchor);
  6489. }
  6490. else {
  6491. const el = (n2.el = n1.el);
  6492. if (n2.children !== n1.children) {
  6493. hostSetText(el, n2.children);
  6494. }
  6495. }
  6496. };
  6497. const processCommentNode = (n1, n2, container, anchor) => {
  6498. if (n1 == null) {
  6499. hostInsert((n2.el = hostCreateComment(n2.children || '')), container, anchor);
  6500. }
  6501. else {
  6502. // there's no support for dynamic comments
  6503. n2.el = n1.el;
  6504. }
  6505. };
  6506. const mountStaticNode = (n2, container, anchor, isSVG) => {
  6507. [n2.el, n2.anchor] = hostInsertStaticContent(n2.children, container, anchor, isSVG, n2.el, n2.anchor);
  6508. };
  6509. /**
  6510. * Dev / HMR only
  6511. */
  6512. const patchStaticNode = (n1, n2, container, isSVG) => {
  6513. // static nodes are only patched during dev for HMR
  6514. if (n2.children !== n1.children) {
  6515. const anchor = hostNextSibling(n1.anchor);
  6516. // remove existing
  6517. removeStaticNode(n1);
  6518. [n2.el, n2.anchor] = hostInsertStaticContent(n2.children, container, anchor, isSVG);
  6519. }
  6520. else {
  6521. n2.el = n1.el;
  6522. n2.anchor = n1.anchor;
  6523. }
  6524. };
  6525. const moveStaticNode = ({ el, anchor }, container, nextSibling) => {
  6526. let next;
  6527. while (el && el !== anchor) {
  6528. next = hostNextSibling(el);
  6529. hostInsert(el, container, nextSibling);
  6530. el = next;
  6531. }
  6532. hostInsert(anchor, container, nextSibling);
  6533. };
  6534. const removeStaticNode = ({ el, anchor }) => {
  6535. let next;
  6536. while (el && el !== anchor) {
  6537. next = hostNextSibling(el);
  6538. hostRemove(el);
  6539. el = next;
  6540. }
  6541. hostRemove(anchor);
  6542. };
  6543. const processElement = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6544. isSVG = isSVG || n2.type === 'svg';
  6545. if (n1 == null) {
  6546. mountElement(n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6547. }
  6548. else {
  6549. patchElement(n1, n2, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6550. }
  6551. };
  6552. const mountElement = (vnode, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6553. let el;
  6554. let vnodeHook;
  6555. const { type, props, shapeFlag, transition, patchFlag, dirs } = vnode;
  6556. {
  6557. el = vnode.el = hostCreateElement(vnode.type, isSVG, props && props.is, props);
  6558. // mount children first, since some props may rely on child content
  6559. // being already rendered, e.g. `<select value>`
  6560. if (shapeFlag & 8 /* TEXT_CHILDREN */) {
  6561. hostSetElementText(el, vnode.children);
  6562. }
  6563. else if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  6564. mountChildren(vnode.children, el, null, parentComponent, parentSuspense, isSVG && type !== 'foreignObject', slotScopeIds, optimized);
  6565. }
  6566. if (dirs) {
  6567. invokeDirectiveHook(vnode, null, parentComponent, 'created');
  6568. }
  6569. // props
  6570. if (props) {
  6571. for (const key in props) {
  6572. if (key !== 'value' && !isReservedProp(key)) {
  6573. hostPatchProp(el, key, null, props[key], isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  6574. }
  6575. }
  6576. /**
  6577. * Special case for setting value on DOM elements:
  6578. * - it can be order-sensitive (e.g. should be set *after* min/max, #2325, #4024)
  6579. * - it needs to be forced (#1471)
  6580. * #2353 proposes adding another renderer option to configure this, but
  6581. * the properties affects are so finite it is worth special casing it
  6582. * here to reduce the complexity. (Special casing it also should not
  6583. * affect non-DOM renderers)
  6584. */
  6585. if ('value' in props) {
  6586. hostPatchProp(el, 'value', null, props.value);
  6587. }
  6588. if ((vnodeHook = props.onVnodeBeforeMount)) {
  6589. invokeVNodeHook(vnodeHook, parentComponent, vnode);
  6590. }
  6591. }
  6592. // scopeId
  6593. setScopeId(el, vnode, vnode.scopeId, slotScopeIds, parentComponent);
  6594. }
  6595. {
  6596. Object.defineProperty(el, '__vnode', {
  6597. value: vnode,
  6598. enumerable: false
  6599. });
  6600. Object.defineProperty(el, '__vueParentComponent', {
  6601. value: parentComponent,
  6602. enumerable: false
  6603. });
  6604. }
  6605. if (dirs) {
  6606. invokeDirectiveHook(vnode, null, parentComponent, 'beforeMount');
  6607. }
  6608. // #1583 For inside suspense + suspense not resolved case, enter hook should call when suspense resolved
  6609. // #1689 For inside suspense + suspense resolved case, just call it
  6610. const needCallTransitionHooks = (!parentSuspense || (parentSuspense && !parentSuspense.pendingBranch)) &&
  6611. transition &&
  6612. !transition.persisted;
  6613. if (needCallTransitionHooks) {
  6614. transition.beforeEnter(el);
  6615. }
  6616. hostInsert(el, container, anchor);
  6617. if ((vnodeHook = props && props.onVnodeMounted) ||
  6618. needCallTransitionHooks ||
  6619. dirs) {
  6620. queuePostRenderEffect(() => {
  6621. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, vnode);
  6622. needCallTransitionHooks && transition.enter(el);
  6623. dirs && invokeDirectiveHook(vnode, null, parentComponent, 'mounted');
  6624. }, parentSuspense);
  6625. }
  6626. };
  6627. const setScopeId = (el, vnode, scopeId, slotScopeIds, parentComponent) => {
  6628. if (scopeId) {
  6629. hostSetScopeId(el, scopeId);
  6630. }
  6631. if (slotScopeIds) {
  6632. for (let i = 0; i < slotScopeIds.length; i++) {
  6633. hostSetScopeId(el, slotScopeIds[i]);
  6634. }
  6635. }
  6636. if (parentComponent) {
  6637. let subTree = parentComponent.subTree;
  6638. if (subTree.patchFlag > 0 &&
  6639. subTree.patchFlag & 2048 /* DEV_ROOT_FRAGMENT */) {
  6640. subTree =
  6641. filterSingleRoot(subTree.children) || subTree;
  6642. }
  6643. if (vnode === subTree) {
  6644. const parentVNode = parentComponent.vnode;
  6645. setScopeId(el, parentVNode, parentVNode.scopeId, parentVNode.slotScopeIds, parentComponent.parent);
  6646. }
  6647. }
  6648. };
  6649. const mountChildren = (children, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, start = 0) => {
  6650. for (let i = start; i < children.length; i++) {
  6651. const child = (children[i] = optimized
  6652. ? cloneIfMounted(children[i])
  6653. : normalizeVNode(children[i]));
  6654. patch(null, child, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6655. }
  6656. };
  6657. const patchElement = (n1, n2, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6658. const el = (n2.el = n1.el);
  6659. let { patchFlag, dynamicChildren, dirs } = n2;
  6660. // #1426 take the old vnode's patch flag into account since user may clone a
  6661. // compiler-generated vnode, which de-opts to FULL_PROPS
  6662. patchFlag |= n1.patchFlag & 16 /* FULL_PROPS */;
  6663. const oldProps = n1.props || EMPTY_OBJ;
  6664. const newProps = n2.props || EMPTY_OBJ;
  6665. let vnodeHook;
  6666. // disable recurse in beforeUpdate hooks
  6667. parentComponent && toggleRecurse(parentComponent, false);
  6668. if ((vnodeHook = newProps.onVnodeBeforeUpdate)) {
  6669. invokeVNodeHook(vnodeHook, parentComponent, n2, n1);
  6670. }
  6671. if (dirs) {
  6672. invokeDirectiveHook(n2, n1, parentComponent, 'beforeUpdate');
  6673. }
  6674. parentComponent && toggleRecurse(parentComponent, true);
  6675. if (isHmrUpdating) {
  6676. // HMR updated, force full diff
  6677. patchFlag = 0;
  6678. optimized = false;
  6679. dynamicChildren = null;
  6680. }
  6681. const areChildrenSVG = isSVG && n2.type !== 'foreignObject';
  6682. if (dynamicChildren) {
  6683. patchBlockChildren(n1.dynamicChildren, dynamicChildren, el, parentComponent, parentSuspense, areChildrenSVG, slotScopeIds);
  6684. if (parentComponent && parentComponent.type.__hmrId) {
  6685. traverseStaticChildren(n1, n2);
  6686. }
  6687. }
  6688. else if (!optimized) {
  6689. // full diff
  6690. patchChildren(n1, n2, el, null, parentComponent, parentSuspense, areChildrenSVG, slotScopeIds, false);
  6691. }
  6692. if (patchFlag > 0) {
  6693. // the presence of a patchFlag means this element's render code was
  6694. // generated by the compiler and can take the fast path.
  6695. // in this path old node and new node are guaranteed to have the same shape
  6696. // (i.e. at the exact same position in the source template)
  6697. if (patchFlag & 16 /* FULL_PROPS */) {
  6698. // element props contain dynamic keys, full diff needed
  6699. patchProps(el, n2, oldProps, newProps, parentComponent, parentSuspense, isSVG);
  6700. }
  6701. else {
  6702. // class
  6703. // this flag is matched when the element has dynamic class bindings.
  6704. if (patchFlag & 2 /* CLASS */) {
  6705. if (oldProps.class !== newProps.class) {
  6706. hostPatchProp(el, 'class', null, newProps.class, isSVG);
  6707. }
  6708. }
  6709. // style
  6710. // this flag is matched when the element has dynamic style bindings
  6711. if (patchFlag & 4 /* STYLE */) {
  6712. hostPatchProp(el, 'style', oldProps.style, newProps.style, isSVG);
  6713. }
  6714. // props
  6715. // This flag is matched when the element has dynamic prop/attr bindings
  6716. // other than class and style. The keys of dynamic prop/attrs are saved for
  6717. // faster iteration.
  6718. // Note dynamic keys like :[foo]="bar" will cause this optimization to
  6719. // bail out and go through a full diff because we need to unset the old key
  6720. if (patchFlag & 8 /* PROPS */) {
  6721. // if the flag is present then dynamicProps must be non-null
  6722. const propsToUpdate = n2.dynamicProps;
  6723. for (let i = 0; i < propsToUpdate.length; i++) {
  6724. const key = propsToUpdate[i];
  6725. const prev = oldProps[key];
  6726. const next = newProps[key];
  6727. // #1471 force patch value
  6728. if (next !== prev || key === 'value') {
  6729. hostPatchProp(el, key, prev, next, isSVG, n1.children, parentComponent, parentSuspense, unmountChildren);
  6730. }
  6731. }
  6732. }
  6733. }
  6734. // text
  6735. // This flag is matched when the element has only dynamic text children.
  6736. if (patchFlag & 1 /* TEXT */) {
  6737. if (n1.children !== n2.children) {
  6738. hostSetElementText(el, n2.children);
  6739. }
  6740. }
  6741. }
  6742. else if (!optimized && dynamicChildren == null) {
  6743. // unoptimized, full diff
  6744. patchProps(el, n2, oldProps, newProps, parentComponent, parentSuspense, isSVG);
  6745. }
  6746. if ((vnodeHook = newProps.onVnodeUpdated) || dirs) {
  6747. queuePostRenderEffect(() => {
  6748. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, n2, n1);
  6749. dirs && invokeDirectiveHook(n2, n1, parentComponent, 'updated');
  6750. }, parentSuspense);
  6751. }
  6752. };
  6753. // The fast path for blocks.
  6754. const patchBlockChildren = (oldChildren, newChildren, fallbackContainer, parentComponent, parentSuspense, isSVG, slotScopeIds) => {
  6755. for (let i = 0; i < newChildren.length; i++) {
  6756. const oldVNode = oldChildren[i];
  6757. const newVNode = newChildren[i];
  6758. // Determine the container (parent element) for the patch.
  6759. const container =
  6760. // oldVNode may be an errored async setup() component inside Suspense
  6761. // which will not have a mounted element
  6762. oldVNode.el &&
  6763. // - In the case of a Fragment, we need to provide the actual parent
  6764. // of the Fragment itself so it can move its children.
  6765. (oldVNode.type === Fragment ||
  6766. // - In the case of different nodes, there is going to be a replacement
  6767. // which also requires the correct parent container
  6768. !isSameVNodeType(oldVNode, newVNode) ||
  6769. // - In the case of a component, it could contain anything.
  6770. oldVNode.shapeFlag & (6 /* COMPONENT */ | 64 /* TELEPORT */))
  6771. ? hostParentNode(oldVNode.el)
  6772. : // In other cases, the parent container is not actually used so we
  6773. // just pass the block element here to avoid a DOM parentNode call.
  6774. fallbackContainer;
  6775. patch(oldVNode, newVNode, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, true);
  6776. }
  6777. };
  6778. const patchProps = (el, vnode, oldProps, newProps, parentComponent, parentSuspense, isSVG) => {
  6779. if (oldProps !== newProps) {
  6780. for (const key in newProps) {
  6781. // empty string is not valid prop
  6782. if (isReservedProp(key))
  6783. continue;
  6784. const next = newProps[key];
  6785. const prev = oldProps[key];
  6786. // defer patching value
  6787. if (next !== prev && key !== 'value') {
  6788. hostPatchProp(el, key, prev, next, isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  6789. }
  6790. }
  6791. if (oldProps !== EMPTY_OBJ) {
  6792. for (const key in oldProps) {
  6793. if (!isReservedProp(key) && !(key in newProps)) {
  6794. hostPatchProp(el, key, oldProps[key], null, isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  6795. }
  6796. }
  6797. }
  6798. if ('value' in newProps) {
  6799. hostPatchProp(el, 'value', oldProps.value, newProps.value);
  6800. }
  6801. }
  6802. };
  6803. const processFragment = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6804. const fragmentStartAnchor = (n2.el = n1 ? n1.el : hostCreateText(''));
  6805. const fragmentEndAnchor = (n2.anchor = n1 ? n1.anchor : hostCreateText(''));
  6806. let { patchFlag, dynamicChildren, slotScopeIds: fragmentSlotScopeIds } = n2;
  6807. if (// #5523 dev root fragment may inherit directives
  6808. (isHmrUpdating || patchFlag & 2048 /* DEV_ROOT_FRAGMENT */)) {
  6809. // HMR updated / Dev root fragment (w/ comments), force full diff
  6810. patchFlag = 0;
  6811. optimized = false;
  6812. dynamicChildren = null;
  6813. }
  6814. // check if this is a slot fragment with :slotted scope ids
  6815. if (fragmentSlotScopeIds) {
  6816. slotScopeIds = slotScopeIds
  6817. ? slotScopeIds.concat(fragmentSlotScopeIds)
  6818. : fragmentSlotScopeIds;
  6819. }
  6820. if (n1 == null) {
  6821. hostInsert(fragmentStartAnchor, container, anchor);
  6822. hostInsert(fragmentEndAnchor, container, anchor);
  6823. // a fragment can only have array children
  6824. // since they are either generated by the compiler, or implicitly created
  6825. // from arrays.
  6826. mountChildren(n2.children, container, fragmentEndAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6827. }
  6828. else {
  6829. if (patchFlag > 0 &&
  6830. patchFlag & 64 /* STABLE_FRAGMENT */ &&
  6831. dynamicChildren &&
  6832. // #2715 the previous fragment could've been a BAILed one as a result
  6833. // of renderSlot() with no valid children
  6834. n1.dynamicChildren) {
  6835. // a stable fragment (template root or <template v-for>) doesn't need to
  6836. // patch children order, but it may contain dynamicChildren.
  6837. patchBlockChildren(n1.dynamicChildren, dynamicChildren, container, parentComponent, parentSuspense, isSVG, slotScopeIds);
  6838. if (parentComponent && parentComponent.type.__hmrId) {
  6839. traverseStaticChildren(n1, n2);
  6840. }
  6841. else if (
  6842. // #2080 if the stable fragment has a key, it's a <template v-for> that may
  6843. // get moved around. Make sure all root level vnodes inherit el.
  6844. // #2134 or if it's a component root, it may also get moved around
  6845. // as the component is being moved.
  6846. n2.key != null ||
  6847. (parentComponent && n2 === parentComponent.subTree)) {
  6848. traverseStaticChildren(n1, n2, true /* shallow */);
  6849. }
  6850. }
  6851. else {
  6852. // keyed / unkeyed, or manual fragments.
  6853. // for keyed & unkeyed, since they are compiler generated from v-for,
  6854. // each child is guaranteed to be a block so the fragment will never
  6855. // have dynamicChildren.
  6856. patchChildren(n1, n2, container, fragmentEndAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6857. }
  6858. }
  6859. };
  6860. const processComponent = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6861. n2.slotScopeIds = slotScopeIds;
  6862. if (n1 == null) {
  6863. if (n2.shapeFlag & 512 /* COMPONENT_KEPT_ALIVE */) {
  6864. parentComponent.ctx.activate(n2, container, anchor, isSVG, optimized);
  6865. }
  6866. else {
  6867. mountComponent(n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  6868. }
  6869. }
  6870. else {
  6871. updateComponent(n1, n2, optimized);
  6872. }
  6873. };
  6874. const mountComponent = (initialVNode, container, anchor, parentComponent, parentSuspense, isSVG, optimized) => {
  6875. const instance = (initialVNode.component = createComponentInstance(initialVNode, parentComponent, parentSuspense));
  6876. if (instance.type.__hmrId) {
  6877. registerHMR(instance);
  6878. }
  6879. {
  6880. pushWarningContext(initialVNode);
  6881. startMeasure(instance, `mount`);
  6882. }
  6883. // inject renderer internals for keepAlive
  6884. if (isKeepAlive(initialVNode)) {
  6885. instance.ctx.renderer = internals;
  6886. }
  6887. // resolve props and slots for setup context
  6888. {
  6889. {
  6890. startMeasure(instance, `init`);
  6891. }
  6892. setupComponent(instance);
  6893. {
  6894. endMeasure(instance, `init`);
  6895. }
  6896. }
  6897. // setup() is async. This component relies on async logic to be resolved
  6898. // before proceeding
  6899. if (instance.asyncDep) {
  6900. parentSuspense && parentSuspense.registerDep(instance, setupRenderEffect);
  6901. // Give it a placeholder if this is not hydration
  6902. // TODO handle self-defined fallback
  6903. if (!initialVNode.el) {
  6904. const placeholder = (instance.subTree = createVNode(Comment));
  6905. processCommentNode(null, placeholder, container, anchor);
  6906. }
  6907. return;
  6908. }
  6909. setupRenderEffect(instance, initialVNode, container, anchor, parentSuspense, isSVG, optimized);
  6910. {
  6911. popWarningContext();
  6912. endMeasure(instance, `mount`);
  6913. }
  6914. };
  6915. const updateComponent = (n1, n2, optimized) => {
  6916. const instance = (n2.component = n1.component);
  6917. if (shouldUpdateComponent(n1, n2, optimized)) {
  6918. if (instance.asyncDep &&
  6919. !instance.asyncResolved) {
  6920. // async & still pending - just update props and slots
  6921. // since the component's reactive effect for render isn't set-up yet
  6922. {
  6923. pushWarningContext(n2);
  6924. }
  6925. updateComponentPreRender(instance, n2, optimized);
  6926. {
  6927. popWarningContext();
  6928. }
  6929. return;
  6930. }
  6931. else {
  6932. // normal update
  6933. instance.next = n2;
  6934. // in case the child component is also queued, remove it to avoid
  6935. // double updating the same child component in the same flush.
  6936. invalidateJob(instance.update);
  6937. // instance.update is the reactive effect.
  6938. instance.update();
  6939. }
  6940. }
  6941. else {
  6942. // no update needed. just copy over properties
  6943. n2.el = n1.el;
  6944. instance.vnode = n2;
  6945. }
  6946. };
  6947. const setupRenderEffect = (instance, initialVNode, container, anchor, parentSuspense, isSVG, optimized) => {
  6948. const componentUpdateFn = () => {
  6949. if (!instance.isMounted) {
  6950. let vnodeHook;
  6951. const { el, props } = initialVNode;
  6952. const { bm, m, parent } = instance;
  6953. const isAsyncWrapperVNode = isAsyncWrapper(initialVNode);
  6954. toggleRecurse(instance, false);
  6955. // beforeMount hook
  6956. if (bm) {
  6957. invokeArrayFns(bm);
  6958. }
  6959. // onVnodeBeforeMount
  6960. if (!isAsyncWrapperVNode &&
  6961. (vnodeHook = props && props.onVnodeBeforeMount)) {
  6962. invokeVNodeHook(vnodeHook, parent, initialVNode);
  6963. }
  6964. toggleRecurse(instance, true);
  6965. if (el && hydrateNode) {
  6966. // vnode has adopted host node - perform hydration instead of mount.
  6967. const hydrateSubTree = () => {
  6968. {
  6969. startMeasure(instance, `render`);
  6970. }
  6971. instance.subTree = renderComponentRoot(instance);
  6972. {
  6973. endMeasure(instance, `render`);
  6974. }
  6975. {
  6976. startMeasure(instance, `hydrate`);
  6977. }
  6978. hydrateNode(el, instance.subTree, instance, parentSuspense, null);
  6979. {
  6980. endMeasure(instance, `hydrate`);
  6981. }
  6982. };
  6983. if (isAsyncWrapperVNode) {
  6984. initialVNode.type.__asyncLoader().then(
  6985. // note: we are moving the render call into an async callback,
  6986. // which means it won't track dependencies - but it's ok because
  6987. // a server-rendered async wrapper is already in resolved state
  6988. // and it will never need to change.
  6989. () => !instance.isUnmounted && hydrateSubTree());
  6990. }
  6991. else {
  6992. hydrateSubTree();
  6993. }
  6994. }
  6995. else {
  6996. {
  6997. startMeasure(instance, `render`);
  6998. }
  6999. const subTree = (instance.subTree = renderComponentRoot(instance));
  7000. {
  7001. endMeasure(instance, `render`);
  7002. }
  7003. {
  7004. startMeasure(instance, `patch`);
  7005. }
  7006. patch(null, subTree, container, anchor, instance, parentSuspense, isSVG);
  7007. {
  7008. endMeasure(instance, `patch`);
  7009. }
  7010. initialVNode.el = subTree.el;
  7011. }
  7012. // mounted hook
  7013. if (m) {
  7014. queuePostRenderEffect(m, parentSuspense);
  7015. }
  7016. // onVnodeMounted
  7017. if (!isAsyncWrapperVNode &&
  7018. (vnodeHook = props && props.onVnodeMounted)) {
  7019. const scopedInitialVNode = initialVNode;
  7020. queuePostRenderEffect(() => invokeVNodeHook(vnodeHook, parent, scopedInitialVNode), parentSuspense);
  7021. }
  7022. // activated hook for keep-alive roots.
  7023. // #1742 activated hook must be accessed after first render
  7024. // since the hook may be injected by a child keep-alive
  7025. if (initialVNode.shapeFlag & 256 /* COMPONENT_SHOULD_KEEP_ALIVE */ ||
  7026. (parent &&
  7027. isAsyncWrapper(parent.vnode) &&
  7028. parent.vnode.shapeFlag & 256 /* COMPONENT_SHOULD_KEEP_ALIVE */)) {
  7029. instance.a && queuePostRenderEffect(instance.a, parentSuspense);
  7030. }
  7031. instance.isMounted = true;
  7032. {
  7033. devtoolsComponentAdded(instance);
  7034. }
  7035. // #2458: deference mount-only object parameters to prevent memleaks
  7036. initialVNode = container = anchor = null;
  7037. }
  7038. else {
  7039. // updateComponent
  7040. // This is triggered by mutation of component's own state (next: null)
  7041. // OR parent calling processComponent (next: VNode)
  7042. let { next, bu, u, parent, vnode } = instance;
  7043. let originNext = next;
  7044. let vnodeHook;
  7045. {
  7046. pushWarningContext(next || instance.vnode);
  7047. }
  7048. // Disallow component effect recursion during pre-lifecycle hooks.
  7049. toggleRecurse(instance, false);
  7050. if (next) {
  7051. next.el = vnode.el;
  7052. updateComponentPreRender(instance, next, optimized);
  7053. }
  7054. else {
  7055. next = vnode;
  7056. }
  7057. // beforeUpdate hook
  7058. if (bu) {
  7059. invokeArrayFns(bu);
  7060. }
  7061. // onVnodeBeforeUpdate
  7062. if ((vnodeHook = next.props && next.props.onVnodeBeforeUpdate)) {
  7063. invokeVNodeHook(vnodeHook, parent, next, vnode);
  7064. }
  7065. toggleRecurse(instance, true);
  7066. // render
  7067. {
  7068. startMeasure(instance, `render`);
  7069. }
  7070. const nextTree = renderComponentRoot(instance);
  7071. {
  7072. endMeasure(instance, `render`);
  7073. }
  7074. const prevTree = instance.subTree;
  7075. instance.subTree = nextTree;
  7076. {
  7077. startMeasure(instance, `patch`);
  7078. }
  7079. patch(prevTree, nextTree,
  7080. // parent may have changed if it's in a teleport
  7081. hostParentNode(prevTree.el),
  7082. // anchor may have changed if it's in a fragment
  7083. getNextHostNode(prevTree), instance, parentSuspense, isSVG);
  7084. {
  7085. endMeasure(instance, `patch`);
  7086. }
  7087. next.el = nextTree.el;
  7088. if (originNext === null) {
  7089. // self-triggered update. In case of HOC, update parent component
  7090. // vnode el. HOC is indicated by parent instance's subTree pointing
  7091. // to child component's vnode
  7092. updateHOCHostEl(instance, nextTree.el);
  7093. }
  7094. // updated hook
  7095. if (u) {
  7096. queuePostRenderEffect(u, parentSuspense);
  7097. }
  7098. // onVnodeUpdated
  7099. if ((vnodeHook = next.props && next.props.onVnodeUpdated)) {
  7100. queuePostRenderEffect(() => invokeVNodeHook(vnodeHook, parent, next, vnode), parentSuspense);
  7101. }
  7102. {
  7103. devtoolsComponentUpdated(instance);
  7104. }
  7105. {
  7106. popWarningContext();
  7107. }
  7108. }
  7109. };
  7110. // create reactive effect for rendering
  7111. const effect = (instance.effect = new ReactiveEffect(componentUpdateFn, () => queueJob(update), instance.scope // track it in component's effect scope
  7112. ));
  7113. const update = (instance.update = () => effect.run());
  7114. update.id = instance.uid;
  7115. // allowRecurse
  7116. // #1801, #2043 component render effects should allow recursive updates
  7117. toggleRecurse(instance, true);
  7118. {
  7119. effect.onTrack = instance.rtc
  7120. ? e => invokeArrayFns(instance.rtc, e)
  7121. : void 0;
  7122. effect.onTrigger = instance.rtg
  7123. ? e => invokeArrayFns(instance.rtg, e)
  7124. : void 0;
  7125. update.ownerInstance = instance;
  7126. }
  7127. update();
  7128. };
  7129. const updateComponentPreRender = (instance, nextVNode, optimized) => {
  7130. nextVNode.component = instance;
  7131. const prevProps = instance.vnode.props;
  7132. instance.vnode = nextVNode;
  7133. instance.next = null;
  7134. updateProps(instance, nextVNode.props, prevProps, optimized);
  7135. updateSlots(instance, nextVNode.children, optimized);
  7136. pauseTracking();
  7137. // props update may have triggered pre-flush watchers.
  7138. // flush them before the render update.
  7139. flushPreFlushCbs(undefined, instance.update);
  7140. resetTracking();
  7141. };
  7142. const patchChildren = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized = false) => {
  7143. const c1 = n1 && n1.children;
  7144. const prevShapeFlag = n1 ? n1.shapeFlag : 0;
  7145. const c2 = n2.children;
  7146. const { patchFlag, shapeFlag } = n2;
  7147. // fast path
  7148. if (patchFlag > 0) {
  7149. if (patchFlag & 128 /* KEYED_FRAGMENT */) {
  7150. // this could be either fully-keyed or mixed (some keyed some not)
  7151. // presence of patchFlag means children are guaranteed to be arrays
  7152. patchKeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7153. return;
  7154. }
  7155. else if (patchFlag & 256 /* UNKEYED_FRAGMENT */) {
  7156. // unkeyed
  7157. patchUnkeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7158. return;
  7159. }
  7160. }
  7161. // children has 3 possibilities: text, array or no children.
  7162. if (shapeFlag & 8 /* TEXT_CHILDREN */) {
  7163. // text children fast path
  7164. if (prevShapeFlag & 16 /* ARRAY_CHILDREN */) {
  7165. unmountChildren(c1, parentComponent, parentSuspense);
  7166. }
  7167. if (c2 !== c1) {
  7168. hostSetElementText(container, c2);
  7169. }
  7170. }
  7171. else {
  7172. if (prevShapeFlag & 16 /* ARRAY_CHILDREN */) {
  7173. // prev children was array
  7174. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  7175. // two arrays, cannot assume anything, do full diff
  7176. patchKeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7177. }
  7178. else {
  7179. // no new children, just unmount old
  7180. unmountChildren(c1, parentComponent, parentSuspense, true);
  7181. }
  7182. }
  7183. else {
  7184. // prev children was text OR null
  7185. // new children is array OR null
  7186. if (prevShapeFlag & 8 /* TEXT_CHILDREN */) {
  7187. hostSetElementText(container, '');
  7188. }
  7189. // mount new if array
  7190. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  7191. mountChildren(c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7192. }
  7193. }
  7194. }
  7195. };
  7196. const patchUnkeyedChildren = (c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  7197. c1 = c1 || EMPTY_ARR;
  7198. c2 = c2 || EMPTY_ARR;
  7199. const oldLength = c1.length;
  7200. const newLength = c2.length;
  7201. const commonLength = Math.min(oldLength, newLength);
  7202. let i;
  7203. for (i = 0; i < commonLength; i++) {
  7204. const nextChild = (c2[i] = optimized
  7205. ? cloneIfMounted(c2[i])
  7206. : normalizeVNode(c2[i]));
  7207. patch(c1[i], nextChild, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7208. }
  7209. if (oldLength > newLength) {
  7210. // remove old
  7211. unmountChildren(c1, parentComponent, parentSuspense, true, false, commonLength);
  7212. }
  7213. else {
  7214. // mount new
  7215. mountChildren(c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, commonLength);
  7216. }
  7217. };
  7218. // can be all-keyed or mixed
  7219. const patchKeyedChildren = (c1, c2, container, parentAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  7220. let i = 0;
  7221. const l2 = c2.length;
  7222. let e1 = c1.length - 1; // prev ending index
  7223. let e2 = l2 - 1; // next ending index
  7224. // 1. sync from start
  7225. // (a b) c
  7226. // (a b) d e
  7227. while (i <= e1 && i <= e2) {
  7228. const n1 = c1[i];
  7229. const n2 = (c2[i] = optimized
  7230. ? cloneIfMounted(c2[i])
  7231. : normalizeVNode(c2[i]));
  7232. if (isSameVNodeType(n1, n2)) {
  7233. patch(n1, n2, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7234. }
  7235. else {
  7236. break;
  7237. }
  7238. i++;
  7239. }
  7240. // 2. sync from end
  7241. // a (b c)
  7242. // d e (b c)
  7243. while (i <= e1 && i <= e2) {
  7244. const n1 = c1[e1];
  7245. const n2 = (c2[e2] = optimized
  7246. ? cloneIfMounted(c2[e2])
  7247. : normalizeVNode(c2[e2]));
  7248. if (isSameVNodeType(n1, n2)) {
  7249. patch(n1, n2, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7250. }
  7251. else {
  7252. break;
  7253. }
  7254. e1--;
  7255. e2--;
  7256. }
  7257. // 3. common sequence + mount
  7258. // (a b)
  7259. // (a b) c
  7260. // i = 2, e1 = 1, e2 = 2
  7261. // (a b)
  7262. // c (a b)
  7263. // i = 0, e1 = -1, e2 = 0
  7264. if (i > e1) {
  7265. if (i <= e2) {
  7266. const nextPos = e2 + 1;
  7267. const anchor = nextPos < l2 ? c2[nextPos].el : parentAnchor;
  7268. while (i <= e2) {
  7269. patch(null, (c2[i] = optimized
  7270. ? cloneIfMounted(c2[i])
  7271. : normalizeVNode(c2[i])), container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7272. i++;
  7273. }
  7274. }
  7275. }
  7276. // 4. common sequence + unmount
  7277. // (a b) c
  7278. // (a b)
  7279. // i = 2, e1 = 2, e2 = 1
  7280. // a (b c)
  7281. // (b c)
  7282. // i = 0, e1 = 0, e2 = -1
  7283. else if (i > e2) {
  7284. while (i <= e1) {
  7285. unmount(c1[i], parentComponent, parentSuspense, true);
  7286. i++;
  7287. }
  7288. }
  7289. // 5. unknown sequence
  7290. // [i ... e1 + 1]: a b [c d e] f g
  7291. // [i ... e2 + 1]: a b [e d c h] f g
  7292. // i = 2, e1 = 4, e2 = 5
  7293. else {
  7294. const s1 = i; // prev starting index
  7295. const s2 = i; // next starting index
  7296. // 5.1 build key:index map for newChildren
  7297. const keyToNewIndexMap = new Map();
  7298. for (i = s2; i <= e2; i++) {
  7299. const nextChild = (c2[i] = optimized
  7300. ? cloneIfMounted(c2[i])
  7301. : normalizeVNode(c2[i]));
  7302. if (nextChild.key != null) {
  7303. if (keyToNewIndexMap.has(nextChild.key)) {
  7304. warn$1(`Duplicate keys found during update:`, JSON.stringify(nextChild.key), `Make sure keys are unique.`);
  7305. }
  7306. keyToNewIndexMap.set(nextChild.key, i);
  7307. }
  7308. }
  7309. // 5.2 loop through old children left to be patched and try to patch
  7310. // matching nodes & remove nodes that are no longer present
  7311. let j;
  7312. let patched = 0;
  7313. const toBePatched = e2 - s2 + 1;
  7314. let moved = false;
  7315. // used to track whether any node has moved
  7316. let maxNewIndexSoFar = 0;
  7317. // works as Map<newIndex, oldIndex>
  7318. // Note that oldIndex is offset by +1
  7319. // and oldIndex = 0 is a special value indicating the new node has
  7320. // no corresponding old node.
  7321. // used for determining longest stable subsequence
  7322. const newIndexToOldIndexMap = new Array(toBePatched);
  7323. for (i = 0; i < toBePatched; i++)
  7324. newIndexToOldIndexMap[i] = 0;
  7325. for (i = s1; i <= e1; i++) {
  7326. const prevChild = c1[i];
  7327. if (patched >= toBePatched) {
  7328. // all new children have been patched so this can only be a removal
  7329. unmount(prevChild, parentComponent, parentSuspense, true);
  7330. continue;
  7331. }
  7332. let newIndex;
  7333. if (prevChild.key != null) {
  7334. newIndex = keyToNewIndexMap.get(prevChild.key);
  7335. }
  7336. else {
  7337. // key-less node, try to locate a key-less node of the same type
  7338. for (j = s2; j <= e2; j++) {
  7339. if (newIndexToOldIndexMap[j - s2] === 0 &&
  7340. isSameVNodeType(prevChild, c2[j])) {
  7341. newIndex = j;
  7342. break;
  7343. }
  7344. }
  7345. }
  7346. if (newIndex === undefined) {
  7347. unmount(prevChild, parentComponent, parentSuspense, true);
  7348. }
  7349. else {
  7350. newIndexToOldIndexMap[newIndex - s2] = i + 1;
  7351. if (newIndex >= maxNewIndexSoFar) {
  7352. maxNewIndexSoFar = newIndex;
  7353. }
  7354. else {
  7355. moved = true;
  7356. }
  7357. patch(prevChild, c2[newIndex], container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7358. patched++;
  7359. }
  7360. }
  7361. // 5.3 move and mount
  7362. // generate longest stable subsequence only when nodes have moved
  7363. const increasingNewIndexSequence = moved
  7364. ? getSequence(newIndexToOldIndexMap)
  7365. : EMPTY_ARR;
  7366. j = increasingNewIndexSequence.length - 1;
  7367. // looping backwards so that we can use last patched node as anchor
  7368. for (i = toBePatched - 1; i >= 0; i--) {
  7369. const nextIndex = s2 + i;
  7370. const nextChild = c2[nextIndex];
  7371. const anchor = nextIndex + 1 < l2 ? c2[nextIndex + 1].el : parentAnchor;
  7372. if (newIndexToOldIndexMap[i] === 0) {
  7373. // mount new
  7374. patch(null, nextChild, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7375. }
  7376. else if (moved) {
  7377. // move if:
  7378. // There is no stable subsequence (e.g. a reverse)
  7379. // OR current node is not among the stable sequence
  7380. if (j < 0 || i !== increasingNewIndexSequence[j]) {
  7381. move(nextChild, container, anchor, 2 /* REORDER */);
  7382. }
  7383. else {
  7384. j--;
  7385. }
  7386. }
  7387. }
  7388. }
  7389. };
  7390. const move = (vnode, container, anchor, moveType, parentSuspense = null) => {
  7391. const { el, type, transition, children, shapeFlag } = vnode;
  7392. if (shapeFlag & 6 /* COMPONENT */) {
  7393. move(vnode.component.subTree, container, anchor, moveType);
  7394. return;
  7395. }
  7396. if (shapeFlag & 128 /* SUSPENSE */) {
  7397. vnode.suspense.move(container, anchor, moveType);
  7398. return;
  7399. }
  7400. if (shapeFlag & 64 /* TELEPORT */) {
  7401. type.move(vnode, container, anchor, internals);
  7402. return;
  7403. }
  7404. if (type === Fragment) {
  7405. hostInsert(el, container, anchor);
  7406. for (let i = 0; i < children.length; i++) {
  7407. move(children[i], container, anchor, moveType);
  7408. }
  7409. hostInsert(vnode.anchor, container, anchor);
  7410. return;
  7411. }
  7412. if (type === Static) {
  7413. moveStaticNode(vnode, container, anchor);
  7414. return;
  7415. }
  7416. // single nodes
  7417. const needTransition = moveType !== 2 /* REORDER */ &&
  7418. shapeFlag & 1 /* ELEMENT */ &&
  7419. transition;
  7420. if (needTransition) {
  7421. if (moveType === 0 /* ENTER */) {
  7422. transition.beforeEnter(el);
  7423. hostInsert(el, container, anchor);
  7424. queuePostRenderEffect(() => transition.enter(el), parentSuspense);
  7425. }
  7426. else {
  7427. const { leave, delayLeave, afterLeave } = transition;
  7428. const remove = () => hostInsert(el, container, anchor);
  7429. const performLeave = () => {
  7430. leave(el, () => {
  7431. remove();
  7432. afterLeave && afterLeave();
  7433. });
  7434. };
  7435. if (delayLeave) {
  7436. delayLeave(el, remove, performLeave);
  7437. }
  7438. else {
  7439. performLeave();
  7440. }
  7441. }
  7442. }
  7443. else {
  7444. hostInsert(el, container, anchor);
  7445. }
  7446. };
  7447. const unmount = (vnode, parentComponent, parentSuspense, doRemove = false, optimized = false) => {
  7448. const { type, props, ref, children, dynamicChildren, shapeFlag, patchFlag, dirs } = vnode;
  7449. // unset ref
  7450. if (ref != null) {
  7451. setRef(ref, null, parentSuspense, vnode, true);
  7452. }
  7453. if (shapeFlag & 256 /* COMPONENT_SHOULD_KEEP_ALIVE */) {
  7454. parentComponent.ctx.deactivate(vnode);
  7455. return;
  7456. }
  7457. const shouldInvokeDirs = shapeFlag & 1 /* ELEMENT */ && dirs;
  7458. const shouldInvokeVnodeHook = !isAsyncWrapper(vnode);
  7459. let vnodeHook;
  7460. if (shouldInvokeVnodeHook &&
  7461. (vnodeHook = props && props.onVnodeBeforeUnmount)) {
  7462. invokeVNodeHook(vnodeHook, parentComponent, vnode);
  7463. }
  7464. if (shapeFlag & 6 /* COMPONENT */) {
  7465. unmountComponent(vnode.component, parentSuspense, doRemove);
  7466. }
  7467. else {
  7468. if (shapeFlag & 128 /* SUSPENSE */) {
  7469. vnode.suspense.unmount(parentSuspense, doRemove);
  7470. return;
  7471. }
  7472. if (shouldInvokeDirs) {
  7473. invokeDirectiveHook(vnode, null, parentComponent, 'beforeUnmount');
  7474. }
  7475. if (shapeFlag & 64 /* TELEPORT */) {
  7476. vnode.type.remove(vnode, parentComponent, parentSuspense, optimized, internals, doRemove);
  7477. }
  7478. else if (dynamicChildren &&
  7479. // #1153: fast path should not be taken for non-stable (v-for) fragments
  7480. (type !== Fragment ||
  7481. (patchFlag > 0 && patchFlag & 64 /* STABLE_FRAGMENT */))) {
  7482. // fast path for block nodes: only need to unmount dynamic children.
  7483. unmountChildren(dynamicChildren, parentComponent, parentSuspense, false, true);
  7484. }
  7485. else if ((type === Fragment &&
  7486. patchFlag &
  7487. (128 /* KEYED_FRAGMENT */ | 256 /* UNKEYED_FRAGMENT */)) ||
  7488. (!optimized && shapeFlag & 16 /* ARRAY_CHILDREN */)) {
  7489. unmountChildren(children, parentComponent, parentSuspense);
  7490. }
  7491. if (doRemove) {
  7492. remove(vnode);
  7493. }
  7494. }
  7495. if ((shouldInvokeVnodeHook &&
  7496. (vnodeHook = props && props.onVnodeUnmounted)) ||
  7497. shouldInvokeDirs) {
  7498. queuePostRenderEffect(() => {
  7499. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, vnode);
  7500. shouldInvokeDirs &&
  7501. invokeDirectiveHook(vnode, null, parentComponent, 'unmounted');
  7502. }, parentSuspense);
  7503. }
  7504. };
  7505. const remove = vnode => {
  7506. const { type, el, anchor, transition } = vnode;
  7507. if (type === Fragment) {
  7508. if (vnode.patchFlag > 0 &&
  7509. vnode.patchFlag & 2048 /* DEV_ROOT_FRAGMENT */ &&
  7510. transition &&
  7511. !transition.persisted) {
  7512. vnode.children.forEach(child => {
  7513. if (child.type === Comment) {
  7514. hostRemove(child.el);
  7515. }
  7516. else {
  7517. remove(child);
  7518. }
  7519. });
  7520. }
  7521. else {
  7522. removeFragment(el, anchor);
  7523. }
  7524. return;
  7525. }
  7526. if (type === Static) {
  7527. removeStaticNode(vnode);
  7528. return;
  7529. }
  7530. const performRemove = () => {
  7531. hostRemove(el);
  7532. if (transition && !transition.persisted && transition.afterLeave) {
  7533. transition.afterLeave();
  7534. }
  7535. };
  7536. if (vnode.shapeFlag & 1 /* ELEMENT */ &&
  7537. transition &&
  7538. !transition.persisted) {
  7539. const { leave, delayLeave } = transition;
  7540. const performLeave = () => leave(el, performRemove);
  7541. if (delayLeave) {
  7542. delayLeave(vnode.el, performRemove, performLeave);
  7543. }
  7544. else {
  7545. performLeave();
  7546. }
  7547. }
  7548. else {
  7549. performRemove();
  7550. }
  7551. };
  7552. const removeFragment = (cur, end) => {
  7553. // For fragments, directly remove all contained DOM nodes.
  7554. // (fragment child nodes cannot have transition)
  7555. let next;
  7556. while (cur !== end) {
  7557. next = hostNextSibling(cur);
  7558. hostRemove(cur);
  7559. cur = next;
  7560. }
  7561. hostRemove(end);
  7562. };
  7563. const unmountComponent = (instance, parentSuspense, doRemove) => {
  7564. if (instance.type.__hmrId) {
  7565. unregisterHMR(instance);
  7566. }
  7567. const { bum, scope, update, subTree, um } = instance;
  7568. // beforeUnmount hook
  7569. if (bum) {
  7570. invokeArrayFns(bum);
  7571. }
  7572. // stop effects in component scope
  7573. scope.stop();
  7574. // update may be null if a component is unmounted before its async
  7575. // setup has resolved.
  7576. if (update) {
  7577. // so that scheduler will no longer invoke it
  7578. update.active = false;
  7579. unmount(subTree, instance, parentSuspense, doRemove);
  7580. }
  7581. // unmounted hook
  7582. if (um) {
  7583. queuePostRenderEffect(um, parentSuspense);
  7584. }
  7585. queuePostRenderEffect(() => {
  7586. instance.isUnmounted = true;
  7587. }, parentSuspense);
  7588. // A component with async dep inside a pending suspense is unmounted before
  7589. // its async dep resolves. This should remove the dep from the suspense, and
  7590. // cause the suspense to resolve immediately if that was the last dep.
  7591. if (parentSuspense &&
  7592. parentSuspense.pendingBranch &&
  7593. !parentSuspense.isUnmounted &&
  7594. instance.asyncDep &&
  7595. !instance.asyncResolved &&
  7596. instance.suspenseId === parentSuspense.pendingId) {
  7597. parentSuspense.deps--;
  7598. if (parentSuspense.deps === 0) {
  7599. parentSuspense.resolve();
  7600. }
  7601. }
  7602. {
  7603. devtoolsComponentRemoved(instance);
  7604. }
  7605. };
  7606. const unmountChildren = (children, parentComponent, parentSuspense, doRemove = false, optimized = false, start = 0) => {
  7607. for (let i = start; i < children.length; i++) {
  7608. unmount(children[i], parentComponent, parentSuspense, doRemove, optimized);
  7609. }
  7610. };
  7611. const getNextHostNode = vnode => {
  7612. if (vnode.shapeFlag & 6 /* COMPONENT */) {
  7613. return getNextHostNode(vnode.component.subTree);
  7614. }
  7615. if (vnode.shapeFlag & 128 /* SUSPENSE */) {
  7616. return vnode.suspense.next();
  7617. }
  7618. return hostNextSibling((vnode.anchor || vnode.el));
  7619. };
  7620. const render = (vnode, container, isSVG) => {
  7621. if (vnode == null) {
  7622. if (container._vnode) {
  7623. unmount(container._vnode, null, null, true);
  7624. }
  7625. }
  7626. else {
  7627. patch(container._vnode || null, vnode, container, null, null, null, isSVG);
  7628. }
  7629. flushPostFlushCbs();
  7630. container._vnode = vnode;
  7631. };
  7632. const internals = {
  7633. p: patch,
  7634. um: unmount,
  7635. m: move,
  7636. r: remove,
  7637. mt: mountComponent,
  7638. mc: mountChildren,
  7639. pc: patchChildren,
  7640. pbc: patchBlockChildren,
  7641. n: getNextHostNode,
  7642. o: options
  7643. };
  7644. let hydrate;
  7645. let hydrateNode;
  7646. if (createHydrationFns) {
  7647. [hydrate, hydrateNode] = createHydrationFns(internals);
  7648. }
  7649. return {
  7650. render,
  7651. hydrate,
  7652. createApp: createAppAPI(render, hydrate)
  7653. };
  7654. }
  7655. function toggleRecurse({ effect, update }, allowed) {
  7656. effect.allowRecurse = update.allowRecurse = allowed;
  7657. }
  7658. /**
  7659. * #1156
  7660. * When a component is HMR-enabled, we need to make sure that all static nodes
  7661. * inside a block also inherit the DOM element from the previous tree so that
  7662. * HMR updates (which are full updates) can retrieve the element for patching.
  7663. *
  7664. * #2080
  7665. * Inside keyed `template` fragment static children, if a fragment is moved,
  7666. * the children will always be moved. Therefore, in order to ensure correct move
  7667. * position, el should be inherited from previous nodes.
  7668. */
  7669. function traverseStaticChildren(n1, n2, shallow = false) {
  7670. const ch1 = n1.children;
  7671. const ch2 = n2.children;
  7672. if (isArray(ch1) && isArray(ch2)) {
  7673. for (let i = 0; i < ch1.length; i++) {
  7674. // this is only called in the optimized path so array children are
  7675. // guaranteed to be vnodes
  7676. const c1 = ch1[i];
  7677. let c2 = ch2[i];
  7678. if (c2.shapeFlag & 1 /* ELEMENT */ && !c2.dynamicChildren) {
  7679. if (c2.patchFlag <= 0 || c2.patchFlag === 32 /* HYDRATE_EVENTS */) {
  7680. c2 = ch2[i] = cloneIfMounted(ch2[i]);
  7681. c2.el = c1.el;
  7682. }
  7683. if (!shallow)
  7684. traverseStaticChildren(c1, c2);
  7685. }
  7686. // also inherit for comment nodes, but not placeholders (e.g. v-if which
  7687. // would have received .el during block patch)
  7688. if (c2.type === Comment && !c2.el) {
  7689. c2.el = c1.el;
  7690. }
  7691. }
  7692. }
  7693. }
  7694. // https://en.wikipedia.org/wiki/Longest_increasing_subsequence
  7695. function getSequence(arr) {
  7696. const p = arr.slice();
  7697. const result = [0];
  7698. let i, j, u, v, c;
  7699. const len = arr.length;
  7700. for (i = 0; i < len; i++) {
  7701. const arrI = arr[i];
  7702. if (arrI !== 0) {
  7703. j = result[result.length - 1];
  7704. if (arr[j] < arrI) {
  7705. p[i] = j;
  7706. result.push(i);
  7707. continue;
  7708. }
  7709. u = 0;
  7710. v = result.length - 1;
  7711. while (u < v) {
  7712. c = (u + v) >> 1;
  7713. if (arr[result[c]] < arrI) {
  7714. u = c + 1;
  7715. }
  7716. else {
  7717. v = c;
  7718. }
  7719. }
  7720. if (arrI < arr[result[u]]) {
  7721. if (u > 0) {
  7722. p[i] = result[u - 1];
  7723. }
  7724. result[u] = i;
  7725. }
  7726. }
  7727. }
  7728. u = result.length;
  7729. v = result[u - 1];
  7730. while (u-- > 0) {
  7731. result[u] = v;
  7732. v = p[v];
  7733. }
  7734. return result;
  7735. }
  7736. const isTeleport = (type) => type.__isTeleport;
  7737. const isTeleportDisabled = (props) => props && (props.disabled || props.disabled === '');
  7738. const isTargetSVG = (target) => typeof SVGElement !== 'undefined' && target instanceof SVGElement;
  7739. const resolveTarget = (props, select) => {
  7740. const targetSelector = props && props.to;
  7741. if (isString(targetSelector)) {
  7742. if (!select) {
  7743. warn$1(`Current renderer does not support string target for Teleports. ` +
  7744. `(missing querySelector renderer option)`);
  7745. return null;
  7746. }
  7747. else {
  7748. const target = select(targetSelector);
  7749. if (!target) {
  7750. warn$1(`Failed to locate Teleport target with selector "${targetSelector}". ` +
  7751. `Note the target element must exist before the component is mounted - ` +
  7752. `i.e. the target cannot be rendered by the component itself, and ` +
  7753. `ideally should be outside of the entire Vue component tree.`);
  7754. }
  7755. return target;
  7756. }
  7757. }
  7758. else {
  7759. if (!targetSelector && !isTeleportDisabled(props)) {
  7760. warn$1(`Invalid Teleport target: ${targetSelector}`);
  7761. }
  7762. return targetSelector;
  7763. }
  7764. };
  7765. const TeleportImpl = {
  7766. __isTeleport: true,
  7767. process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, internals) {
  7768. const { mc: mountChildren, pc: patchChildren, pbc: patchBlockChildren, o: { insert, querySelector, createText, createComment } } = internals;
  7769. const disabled = isTeleportDisabled(n2.props);
  7770. let { shapeFlag, children, dynamicChildren } = n2;
  7771. // #3302
  7772. // HMR updated, force full diff
  7773. if (isHmrUpdating) {
  7774. optimized = false;
  7775. dynamicChildren = null;
  7776. }
  7777. if (n1 == null) {
  7778. // insert anchors in the main view
  7779. const placeholder = (n2.el = createComment('teleport start')
  7780. );
  7781. const mainAnchor = (n2.anchor = createComment('teleport end')
  7782. );
  7783. insert(placeholder, container, anchor);
  7784. insert(mainAnchor, container, anchor);
  7785. const target = (n2.target = resolveTarget(n2.props, querySelector));
  7786. const targetAnchor = (n2.targetAnchor = createText(''));
  7787. if (target) {
  7788. insert(targetAnchor, target);
  7789. // #2652 we could be teleporting from a non-SVG tree into an SVG tree
  7790. isSVG = isSVG || isTargetSVG(target);
  7791. }
  7792. else if (!disabled) {
  7793. warn$1('Invalid Teleport target on mount:', target, `(${typeof target})`);
  7794. }
  7795. const mount = (container, anchor) => {
  7796. // Teleport *always* has Array children. This is enforced in both the
  7797. // compiler and vnode children normalization.
  7798. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  7799. mountChildren(children, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7800. }
  7801. };
  7802. if (disabled) {
  7803. mount(container, mainAnchor);
  7804. }
  7805. else if (target) {
  7806. mount(target, targetAnchor);
  7807. }
  7808. }
  7809. else {
  7810. // update content
  7811. n2.el = n1.el;
  7812. const mainAnchor = (n2.anchor = n1.anchor);
  7813. const target = (n2.target = n1.target);
  7814. const targetAnchor = (n2.targetAnchor = n1.targetAnchor);
  7815. const wasDisabled = isTeleportDisabled(n1.props);
  7816. const currentContainer = wasDisabled ? container : target;
  7817. const currentAnchor = wasDisabled ? mainAnchor : targetAnchor;
  7818. isSVG = isSVG || isTargetSVG(target);
  7819. if (dynamicChildren) {
  7820. // fast path when the teleport happens to be a block root
  7821. patchBlockChildren(n1.dynamicChildren, dynamicChildren, currentContainer, parentComponent, parentSuspense, isSVG, slotScopeIds);
  7822. // even in block tree mode we need to make sure all root-level nodes
  7823. // in the teleport inherit previous DOM references so that they can
  7824. // be moved in future patches.
  7825. traverseStaticChildren(n1, n2, true);
  7826. }
  7827. else if (!optimized) {
  7828. patchChildren(n1, n2, currentContainer, currentAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, false);
  7829. }
  7830. if (disabled) {
  7831. if (!wasDisabled) {
  7832. // enabled -> disabled
  7833. // move into main container
  7834. moveTeleport(n2, container, mainAnchor, internals, 1 /* TOGGLE */);
  7835. }
  7836. }
  7837. else {
  7838. // target changed
  7839. if ((n2.props && n2.props.to) !== (n1.props && n1.props.to)) {
  7840. const nextTarget = (n2.target = resolveTarget(n2.props, querySelector));
  7841. if (nextTarget) {
  7842. moveTeleport(n2, nextTarget, null, internals, 0 /* TARGET_CHANGE */);
  7843. }
  7844. else {
  7845. warn$1('Invalid Teleport target on update:', target, `(${typeof target})`);
  7846. }
  7847. }
  7848. else if (wasDisabled) {
  7849. // disabled -> enabled
  7850. // move into teleport target
  7851. moveTeleport(n2, target, targetAnchor, internals, 1 /* TOGGLE */);
  7852. }
  7853. }
  7854. }
  7855. },
  7856. remove(vnode, parentComponent, parentSuspense, optimized, { um: unmount, o: { remove: hostRemove } }, doRemove) {
  7857. const { shapeFlag, children, anchor, targetAnchor, target, props } = vnode;
  7858. if (target) {
  7859. hostRemove(targetAnchor);
  7860. }
  7861. // an unmounted teleport should always remove its children if not disabled
  7862. if (doRemove || !isTeleportDisabled(props)) {
  7863. hostRemove(anchor);
  7864. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  7865. for (let i = 0; i < children.length; i++) {
  7866. const child = children[i];
  7867. unmount(child, parentComponent, parentSuspense, true, !!child.dynamicChildren);
  7868. }
  7869. }
  7870. }
  7871. },
  7872. move: moveTeleport,
  7873. hydrate: hydrateTeleport
  7874. };
  7875. function moveTeleport(vnode, container, parentAnchor, { o: { insert }, m: move }, moveType = 2 /* REORDER */) {
  7876. // move target anchor if this is a target change.
  7877. if (moveType === 0 /* TARGET_CHANGE */) {
  7878. insert(vnode.targetAnchor, container, parentAnchor);
  7879. }
  7880. const { el, anchor, shapeFlag, children, props } = vnode;
  7881. const isReorder = moveType === 2 /* REORDER */;
  7882. // move main view anchor if this is a re-order.
  7883. if (isReorder) {
  7884. insert(el, container, parentAnchor);
  7885. }
  7886. // if this is a re-order and teleport is enabled (content is in target)
  7887. // do not move children. So the opposite is: only move children if this
  7888. // is not a reorder, or the teleport is disabled
  7889. if (!isReorder || isTeleportDisabled(props)) {
  7890. // Teleport has either Array children or no children.
  7891. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  7892. for (let i = 0; i < children.length; i++) {
  7893. move(children[i], container, parentAnchor, 2 /* REORDER */);
  7894. }
  7895. }
  7896. }
  7897. // move main view anchor if this is a re-order.
  7898. if (isReorder) {
  7899. insert(anchor, container, parentAnchor);
  7900. }
  7901. }
  7902. function hydrateTeleport(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized, { o: { nextSibling, parentNode, querySelector } }, hydrateChildren) {
  7903. const target = (vnode.target = resolveTarget(vnode.props, querySelector));
  7904. if (target) {
  7905. // if multiple teleports rendered to the same target element, we need to
  7906. // pick up from where the last teleport finished instead of the first node
  7907. const targetNode = target._lpa || target.firstChild;
  7908. if (vnode.shapeFlag & 16 /* ARRAY_CHILDREN */) {
  7909. if (isTeleportDisabled(vnode.props)) {
  7910. vnode.anchor = hydrateChildren(nextSibling(node), vnode, parentNode(node), parentComponent, parentSuspense, slotScopeIds, optimized);
  7911. vnode.targetAnchor = targetNode;
  7912. }
  7913. else {
  7914. vnode.anchor = nextSibling(node);
  7915. // lookahead until we find the target anchor
  7916. // we cannot rely on return value of hydrateChildren() because there
  7917. // could be nested teleports
  7918. let targetAnchor = targetNode;
  7919. while (targetAnchor) {
  7920. targetAnchor = nextSibling(targetAnchor);
  7921. if (targetAnchor &&
  7922. targetAnchor.nodeType === 8 &&
  7923. targetAnchor.data === 'teleport anchor') {
  7924. vnode.targetAnchor = targetAnchor;
  7925. target._lpa =
  7926. vnode.targetAnchor && nextSibling(vnode.targetAnchor);
  7927. break;
  7928. }
  7929. }
  7930. hydrateChildren(targetNode, vnode, target, parentComponent, parentSuspense, slotScopeIds, optimized);
  7931. }
  7932. }
  7933. }
  7934. return vnode.anchor && nextSibling(vnode.anchor);
  7935. }
  7936. // Force-casted public typing for h and TSX props inference
  7937. const Teleport = TeleportImpl;
  7938. const Fragment = Symbol('Fragment' );
  7939. const Text = Symbol('Text' );
  7940. const Comment = Symbol('Comment' );
  7941. const Static = Symbol('Static' );
  7942. // Since v-if and v-for are the two possible ways node structure can dynamically
  7943. // change, once we consider v-if branches and each v-for fragment a block, we
  7944. // can divide a template into nested blocks, and within each block the node
  7945. // structure would be stable. This allows us to skip most children diffing
  7946. // and only worry about the dynamic nodes (indicated by patch flags).
  7947. const blockStack = [];
  7948. let currentBlock = null;
  7949. /**
  7950. * Open a block.
  7951. * This must be called before `createBlock`. It cannot be part of `createBlock`
  7952. * because the children of the block are evaluated before `createBlock` itself
  7953. * is called. The generated code typically looks like this:
  7954. *
  7955. * ```js
  7956. * function render() {
  7957. * return (openBlock(),createBlock('div', null, [...]))
  7958. * }
  7959. * ```
  7960. * disableTracking is true when creating a v-for fragment block, since a v-for
  7961. * fragment always diffs its children.
  7962. *
  7963. * @private
  7964. */
  7965. function openBlock(disableTracking = false) {
  7966. blockStack.push((currentBlock = disableTracking ? null : []));
  7967. }
  7968. function closeBlock() {
  7969. blockStack.pop();
  7970. currentBlock = blockStack[blockStack.length - 1] || null;
  7971. }
  7972. // Whether we should be tracking dynamic child nodes inside a block.
  7973. // Only tracks when this value is > 0
  7974. // We are not using a simple boolean because this value may need to be
  7975. // incremented/decremented by nested usage of v-once (see below)
  7976. let isBlockTreeEnabled = 1;
  7977. /**
  7978. * Block tracking sometimes needs to be disabled, for example during the
  7979. * creation of a tree that needs to be cached by v-once. The compiler generates
  7980. * code like this:
  7981. *
  7982. * ``` js
  7983. * _cache[1] || (
  7984. * setBlockTracking(-1),
  7985. * _cache[1] = createVNode(...),
  7986. * setBlockTracking(1),
  7987. * _cache[1]
  7988. * )
  7989. * ```
  7990. *
  7991. * @private
  7992. */
  7993. function setBlockTracking(value) {
  7994. isBlockTreeEnabled += value;
  7995. }
  7996. function setupBlock(vnode) {
  7997. // save current block children on the block vnode
  7998. vnode.dynamicChildren =
  7999. isBlockTreeEnabled > 0 ? currentBlock || EMPTY_ARR : null;
  8000. // close block
  8001. closeBlock();
  8002. // a block is always going to be patched, so track it as a child of its
  8003. // parent block
  8004. if (isBlockTreeEnabled > 0 && currentBlock) {
  8005. currentBlock.push(vnode);
  8006. }
  8007. return vnode;
  8008. }
  8009. /**
  8010. * @private
  8011. */
  8012. function createElementBlock(type, props, children, patchFlag, dynamicProps, shapeFlag) {
  8013. return setupBlock(createBaseVNode(type, props, children, patchFlag, dynamicProps, shapeFlag, true /* isBlock */));
  8014. }
  8015. /**
  8016. * Create a block root vnode. Takes the same exact arguments as `createVNode`.
  8017. * A block root keeps track of dynamic nodes within the block in the
  8018. * `dynamicChildren` array.
  8019. *
  8020. * @private
  8021. */
  8022. function createBlock(type, props, children, patchFlag, dynamicProps) {
  8023. return setupBlock(createVNode(type, props, children, patchFlag, dynamicProps, true /* isBlock: prevent a block from tracking itself */));
  8024. }
  8025. function isVNode(value) {
  8026. return value ? value.__v_isVNode === true : false;
  8027. }
  8028. function isSameVNodeType(n1, n2) {
  8029. if (n2.shapeFlag & 6 /* COMPONENT */ &&
  8030. hmrDirtyComponents.has(n2.type)) {
  8031. // HMR only: if the component has been hot-updated, force a reload.
  8032. return false;
  8033. }
  8034. return n1.type === n2.type && n1.key === n2.key;
  8035. }
  8036. let vnodeArgsTransformer;
  8037. /**
  8038. * Internal API for registering an arguments transform for createVNode
  8039. * used for creating stubs in the test-utils
  8040. * It is *internal* but needs to be exposed for test-utils to pick up proper
  8041. * typings
  8042. */
  8043. function transformVNodeArgs(transformer) {
  8044. vnodeArgsTransformer = transformer;
  8045. }
  8046. const createVNodeWithArgsTransform = (...args) => {
  8047. return _createVNode(...(vnodeArgsTransformer
  8048. ? vnodeArgsTransformer(args, currentRenderingInstance)
  8049. : args));
  8050. };
  8051. const InternalObjectKey = `__vInternal`;
  8052. const normalizeKey = ({ key }) => key != null ? key : null;
  8053. const normalizeRef = ({ ref, ref_key, ref_for }) => {
  8054. return (ref != null
  8055. ? isString(ref) || isRef(ref) || isFunction(ref)
  8056. ? { i: currentRenderingInstance, r: ref, k: ref_key, f: !!ref_for }
  8057. : ref
  8058. : null);
  8059. };
  8060. function createBaseVNode(type, props = null, children = null, patchFlag = 0, dynamicProps = null, shapeFlag = type === Fragment ? 0 : 1 /* ELEMENT */, isBlockNode = false, needFullChildrenNormalization = false) {
  8061. const vnode = {
  8062. __v_isVNode: true,
  8063. __v_skip: true,
  8064. type,
  8065. props,
  8066. key: props && normalizeKey(props),
  8067. ref: props && normalizeRef(props),
  8068. scopeId: currentScopeId,
  8069. slotScopeIds: null,
  8070. children,
  8071. component: null,
  8072. suspense: null,
  8073. ssContent: null,
  8074. ssFallback: null,
  8075. dirs: null,
  8076. transition: null,
  8077. el: null,
  8078. anchor: null,
  8079. target: null,
  8080. targetAnchor: null,
  8081. staticCount: 0,
  8082. shapeFlag,
  8083. patchFlag,
  8084. dynamicProps,
  8085. dynamicChildren: null,
  8086. appContext: null
  8087. };
  8088. if (needFullChildrenNormalization) {
  8089. normalizeChildren(vnode, children);
  8090. // normalize suspense children
  8091. if (shapeFlag & 128 /* SUSPENSE */) {
  8092. type.normalize(vnode);
  8093. }
  8094. }
  8095. else if (children) {
  8096. // compiled element vnode - if children is passed, only possible types are
  8097. // string or Array.
  8098. vnode.shapeFlag |= isString(children)
  8099. ? 8 /* TEXT_CHILDREN */
  8100. : 16 /* ARRAY_CHILDREN */;
  8101. }
  8102. // validate key
  8103. if (vnode.key !== vnode.key) {
  8104. warn$1(`VNode created with invalid key (NaN). VNode type:`, vnode.type);
  8105. }
  8106. // track vnode for block tree
  8107. if (isBlockTreeEnabled > 0 &&
  8108. // avoid a block node from tracking itself
  8109. !isBlockNode &&
  8110. // has current parent block
  8111. currentBlock &&
  8112. // presence of a patch flag indicates this node needs patching on updates.
  8113. // component nodes also should always be patched, because even if the
  8114. // component doesn't need to update, it needs to persist the instance on to
  8115. // the next vnode so that it can be properly unmounted later.
  8116. (vnode.patchFlag > 0 || shapeFlag & 6 /* COMPONENT */) &&
  8117. // the EVENTS flag is only for hydration and if it is the only flag, the
  8118. // vnode should not be considered dynamic due to handler caching.
  8119. vnode.patchFlag !== 32 /* HYDRATE_EVENTS */) {
  8120. currentBlock.push(vnode);
  8121. }
  8122. return vnode;
  8123. }
  8124. const createVNode = (createVNodeWithArgsTransform );
  8125. function _createVNode(type, props = null, children = null, patchFlag = 0, dynamicProps = null, isBlockNode = false) {
  8126. if (!type || type === NULL_DYNAMIC_COMPONENT) {
  8127. if (!type) {
  8128. warn$1(`Invalid vnode type when creating vnode: ${type}.`);
  8129. }
  8130. type = Comment;
  8131. }
  8132. if (isVNode(type)) {
  8133. // createVNode receiving an existing vnode. This happens in cases like
  8134. // <component :is="vnode"/>
  8135. // #2078 make sure to merge refs during the clone instead of overwriting it
  8136. const cloned = cloneVNode(type, props, true /* mergeRef: true */);
  8137. if (children) {
  8138. normalizeChildren(cloned, children);
  8139. }
  8140. if (isBlockTreeEnabled > 0 && !isBlockNode && currentBlock) {
  8141. if (cloned.shapeFlag & 6 /* COMPONENT */) {
  8142. currentBlock[currentBlock.indexOf(type)] = cloned;
  8143. }
  8144. else {
  8145. currentBlock.push(cloned);
  8146. }
  8147. }
  8148. cloned.patchFlag |= -2 /* BAIL */;
  8149. return cloned;
  8150. }
  8151. // class component normalization.
  8152. if (isClassComponent(type)) {
  8153. type = type.__vccOpts;
  8154. }
  8155. // class & style normalization.
  8156. if (props) {
  8157. // for reactive or proxy objects, we need to clone it to enable mutation.
  8158. props = guardReactiveProps(props);
  8159. let { class: klass, style } = props;
  8160. if (klass && !isString(klass)) {
  8161. props.class = normalizeClass(klass);
  8162. }
  8163. if (isObject(style)) {
  8164. // reactive state objects need to be cloned since they are likely to be
  8165. // mutated
  8166. if (isProxy(style) && !isArray(style)) {
  8167. style = extend({}, style);
  8168. }
  8169. props.style = normalizeStyle(style);
  8170. }
  8171. }
  8172. // encode the vnode type information into a bitmap
  8173. const shapeFlag = isString(type)
  8174. ? 1 /* ELEMENT */
  8175. : isSuspense(type)
  8176. ? 128 /* SUSPENSE */
  8177. : isTeleport(type)
  8178. ? 64 /* TELEPORT */
  8179. : isObject(type)
  8180. ? 4 /* STATEFUL_COMPONENT */
  8181. : isFunction(type)
  8182. ? 2 /* FUNCTIONAL_COMPONENT */
  8183. : 0;
  8184. if (shapeFlag & 4 /* STATEFUL_COMPONENT */ && isProxy(type)) {
  8185. type = toRaw(type);
  8186. warn$1(`Vue received a Component which was made a reactive object. This can ` +
  8187. `lead to unnecessary performance overhead, and should be avoided by ` +
  8188. `marking the component with \`markRaw\` or using \`shallowRef\` ` +
  8189. `instead of \`ref\`.`, `\nComponent that was made reactive: `, type);
  8190. }
  8191. return createBaseVNode(type, props, children, patchFlag, dynamicProps, shapeFlag, isBlockNode, true);
  8192. }
  8193. function guardReactiveProps(props) {
  8194. if (!props)
  8195. return null;
  8196. return isProxy(props) || InternalObjectKey in props
  8197. ? extend({}, props)
  8198. : props;
  8199. }
  8200. function cloneVNode(vnode, extraProps, mergeRef = false) {
  8201. // This is intentionally NOT using spread or extend to avoid the runtime
  8202. // key enumeration cost.
  8203. const { props, ref, patchFlag, children } = vnode;
  8204. const mergedProps = extraProps ? mergeProps(props || {}, extraProps) : props;
  8205. const cloned = {
  8206. __v_isVNode: true,
  8207. __v_skip: true,
  8208. type: vnode.type,
  8209. props: mergedProps,
  8210. key: mergedProps && normalizeKey(mergedProps),
  8211. ref: extraProps && extraProps.ref
  8212. ? // #2078 in the case of <component :is="vnode" ref="extra"/>
  8213. // if the vnode itself already has a ref, cloneVNode will need to merge
  8214. // the refs so the single vnode can be set on multiple refs
  8215. mergeRef && ref
  8216. ? isArray(ref)
  8217. ? ref.concat(normalizeRef(extraProps))
  8218. : [ref, normalizeRef(extraProps)]
  8219. : normalizeRef(extraProps)
  8220. : ref,
  8221. scopeId: vnode.scopeId,
  8222. slotScopeIds: vnode.slotScopeIds,
  8223. children: patchFlag === -1 /* HOISTED */ && isArray(children)
  8224. ? children.map(deepCloneVNode)
  8225. : children,
  8226. target: vnode.target,
  8227. targetAnchor: vnode.targetAnchor,
  8228. staticCount: vnode.staticCount,
  8229. shapeFlag: vnode.shapeFlag,
  8230. // if the vnode is cloned with extra props, we can no longer assume its
  8231. // existing patch flag to be reliable and need to add the FULL_PROPS flag.
  8232. // note: preserve flag for fragments since they use the flag for children
  8233. // fast paths only.
  8234. patchFlag: extraProps && vnode.type !== Fragment
  8235. ? patchFlag === -1 // hoisted node
  8236. ? 16 /* FULL_PROPS */
  8237. : patchFlag | 16 /* FULL_PROPS */
  8238. : patchFlag,
  8239. dynamicProps: vnode.dynamicProps,
  8240. dynamicChildren: vnode.dynamicChildren,
  8241. appContext: vnode.appContext,
  8242. dirs: vnode.dirs,
  8243. transition: vnode.transition,
  8244. // These should technically only be non-null on mounted VNodes. However,
  8245. // they *should* be copied for kept-alive vnodes. So we just always copy
  8246. // them since them being non-null during a mount doesn't affect the logic as
  8247. // they will simply be overwritten.
  8248. component: vnode.component,
  8249. suspense: vnode.suspense,
  8250. ssContent: vnode.ssContent && cloneVNode(vnode.ssContent),
  8251. ssFallback: vnode.ssFallback && cloneVNode(vnode.ssFallback),
  8252. el: vnode.el,
  8253. anchor: vnode.anchor
  8254. };
  8255. return cloned;
  8256. }
  8257. /**
  8258. * Dev only, for HMR of hoisted vnodes reused in v-for
  8259. * https://github.com/vitejs/vite/issues/2022
  8260. */
  8261. function deepCloneVNode(vnode) {
  8262. const cloned = cloneVNode(vnode);
  8263. if (isArray(vnode.children)) {
  8264. cloned.children = vnode.children.map(deepCloneVNode);
  8265. }
  8266. return cloned;
  8267. }
  8268. /**
  8269. * @private
  8270. */
  8271. function createTextVNode(text = ' ', flag = 0) {
  8272. return createVNode(Text, null, text, flag);
  8273. }
  8274. /**
  8275. * @private
  8276. */
  8277. function createStaticVNode(content, numberOfNodes) {
  8278. // A static vnode can contain multiple stringified elements, and the number
  8279. // of elements is necessary for hydration.
  8280. const vnode = createVNode(Static, null, content);
  8281. vnode.staticCount = numberOfNodes;
  8282. return vnode;
  8283. }
  8284. /**
  8285. * @private
  8286. */
  8287. function createCommentVNode(text = '',
  8288. // when used as the v-else branch, the comment node must be created as a
  8289. // block to ensure correct updates.
  8290. asBlock = false) {
  8291. return asBlock
  8292. ? (openBlock(), createBlock(Comment, null, text))
  8293. : createVNode(Comment, null, text);
  8294. }
  8295. function normalizeVNode(child) {
  8296. if (child == null || typeof child === 'boolean') {
  8297. // empty placeholder
  8298. return createVNode(Comment);
  8299. }
  8300. else if (isArray(child)) {
  8301. // fragment
  8302. return createVNode(Fragment, null,
  8303. // #3666, avoid reference pollution when reusing vnode
  8304. child.slice());
  8305. }
  8306. else if (typeof child === 'object') {
  8307. // already vnode, this should be the most common since compiled templates
  8308. // always produce all-vnode children arrays
  8309. return cloneIfMounted(child);
  8310. }
  8311. else {
  8312. // strings and numbers
  8313. return createVNode(Text, null, String(child));
  8314. }
  8315. }
  8316. // optimized normalization for template-compiled render fns
  8317. function cloneIfMounted(child) {
  8318. return child.el === null || child.memo ? child : cloneVNode(child);
  8319. }
  8320. function normalizeChildren(vnode, children) {
  8321. let type = 0;
  8322. const { shapeFlag } = vnode;
  8323. if (children == null) {
  8324. children = null;
  8325. }
  8326. else if (isArray(children)) {
  8327. type = 16 /* ARRAY_CHILDREN */;
  8328. }
  8329. else if (typeof children === 'object') {
  8330. if (shapeFlag & (1 /* ELEMENT */ | 64 /* TELEPORT */)) {
  8331. // Normalize slot to plain children for plain element and Teleport
  8332. const slot = children.default;
  8333. if (slot) {
  8334. // _c marker is added by withCtx() indicating this is a compiled slot
  8335. slot._c && (slot._d = false);
  8336. normalizeChildren(vnode, slot());
  8337. slot._c && (slot._d = true);
  8338. }
  8339. return;
  8340. }
  8341. else {
  8342. type = 32 /* SLOTS_CHILDREN */;
  8343. const slotFlag = children._;
  8344. if (!slotFlag && !(InternalObjectKey in children)) {
  8345. children._ctx = currentRenderingInstance;
  8346. }
  8347. else if (slotFlag === 3 /* FORWARDED */ && currentRenderingInstance) {
  8348. // a child component receives forwarded slots from the parent.
  8349. // its slot type is determined by its parent's slot type.
  8350. if (currentRenderingInstance.slots._ === 1 /* STABLE */) {
  8351. children._ = 1 /* STABLE */;
  8352. }
  8353. else {
  8354. children._ = 2 /* DYNAMIC */;
  8355. vnode.patchFlag |= 1024 /* DYNAMIC_SLOTS */;
  8356. }
  8357. }
  8358. }
  8359. }
  8360. else if (isFunction(children)) {
  8361. children = { default: children, _ctx: currentRenderingInstance };
  8362. type = 32 /* SLOTS_CHILDREN */;
  8363. }
  8364. else {
  8365. children = String(children);
  8366. // force teleport children to array so it can be moved around
  8367. if (shapeFlag & 64 /* TELEPORT */) {
  8368. type = 16 /* ARRAY_CHILDREN */;
  8369. children = [createTextVNode(children)];
  8370. }
  8371. else {
  8372. type = 8 /* TEXT_CHILDREN */;
  8373. }
  8374. }
  8375. vnode.children = children;
  8376. vnode.shapeFlag |= type;
  8377. }
  8378. function mergeProps(...args) {
  8379. const ret = {};
  8380. for (let i = 0; i < args.length; i++) {
  8381. const toMerge = args[i];
  8382. for (const key in toMerge) {
  8383. if (key === 'class') {
  8384. if (ret.class !== toMerge.class) {
  8385. ret.class = normalizeClass([ret.class, toMerge.class]);
  8386. }
  8387. }
  8388. else if (key === 'style') {
  8389. ret.style = normalizeStyle([ret.style, toMerge.style]);
  8390. }
  8391. else if (isOn(key)) {
  8392. const existing = ret[key];
  8393. const incoming = toMerge[key];
  8394. if (incoming &&
  8395. existing !== incoming &&
  8396. !(isArray(existing) && existing.includes(incoming))) {
  8397. ret[key] = existing
  8398. ? [].concat(existing, incoming)
  8399. : incoming;
  8400. }
  8401. }
  8402. else if (key !== '') {
  8403. ret[key] = toMerge[key];
  8404. }
  8405. }
  8406. }
  8407. return ret;
  8408. }
  8409. function invokeVNodeHook(hook, instance, vnode, prevVNode = null) {
  8410. callWithAsyncErrorHandling(hook, instance, 7 /* VNODE_HOOK */, [
  8411. vnode,
  8412. prevVNode
  8413. ]);
  8414. }
  8415. const emptyAppContext = createAppContext();
  8416. let uid$1 = 0;
  8417. function createComponentInstance(vnode, parent, suspense) {
  8418. const type = vnode.type;
  8419. // inherit parent app context - or - if root, adopt from root vnode
  8420. const appContext = (parent ? parent.appContext : vnode.appContext) || emptyAppContext;
  8421. const instance = {
  8422. uid: uid$1++,
  8423. vnode,
  8424. type,
  8425. parent,
  8426. appContext,
  8427. root: null,
  8428. next: null,
  8429. subTree: null,
  8430. effect: null,
  8431. update: null,
  8432. scope: new EffectScope(true /* detached */),
  8433. render: null,
  8434. proxy: null,
  8435. exposed: null,
  8436. exposeProxy: null,
  8437. withProxy: null,
  8438. provides: parent ? parent.provides : Object.create(appContext.provides),
  8439. accessCache: null,
  8440. renderCache: [],
  8441. // local resolved assets
  8442. components: null,
  8443. directives: null,
  8444. // resolved props and emits options
  8445. propsOptions: normalizePropsOptions(type, appContext),
  8446. emitsOptions: normalizeEmitsOptions(type, appContext),
  8447. // emit
  8448. emit: null,
  8449. emitted: null,
  8450. // props default value
  8451. propsDefaults: EMPTY_OBJ,
  8452. // inheritAttrs
  8453. inheritAttrs: type.inheritAttrs,
  8454. // state
  8455. ctx: EMPTY_OBJ,
  8456. data: EMPTY_OBJ,
  8457. props: EMPTY_OBJ,
  8458. attrs: EMPTY_OBJ,
  8459. slots: EMPTY_OBJ,
  8460. refs: EMPTY_OBJ,
  8461. setupState: EMPTY_OBJ,
  8462. setupContext: null,
  8463. // suspense related
  8464. suspense,
  8465. suspenseId: suspense ? suspense.pendingId : 0,
  8466. asyncDep: null,
  8467. asyncResolved: false,
  8468. // lifecycle hooks
  8469. // not using enums here because it results in computed properties
  8470. isMounted: false,
  8471. isUnmounted: false,
  8472. isDeactivated: false,
  8473. bc: null,
  8474. c: null,
  8475. bm: null,
  8476. m: null,
  8477. bu: null,
  8478. u: null,
  8479. um: null,
  8480. bum: null,
  8481. da: null,
  8482. a: null,
  8483. rtg: null,
  8484. rtc: null,
  8485. ec: null,
  8486. sp: null
  8487. };
  8488. {
  8489. instance.ctx = createDevRenderContext(instance);
  8490. }
  8491. instance.root = parent ? parent.root : instance;
  8492. instance.emit = emit$1.bind(null, instance);
  8493. // apply custom element special handling
  8494. if (vnode.ce) {
  8495. vnode.ce(instance);
  8496. }
  8497. return instance;
  8498. }
  8499. let currentInstance = null;
  8500. const getCurrentInstance = () => currentInstance || currentRenderingInstance;
  8501. const setCurrentInstance = (instance) => {
  8502. currentInstance = instance;
  8503. instance.scope.on();
  8504. };
  8505. const unsetCurrentInstance = () => {
  8506. currentInstance && currentInstance.scope.off();
  8507. currentInstance = null;
  8508. };
  8509. const isBuiltInTag = /*#__PURE__*/ makeMap('slot,component');
  8510. function validateComponentName(name, config) {
  8511. const appIsNativeTag = config.isNativeTag || NO;
  8512. if (isBuiltInTag(name) || appIsNativeTag(name)) {
  8513. warn$1('Do not use built-in or reserved HTML elements as component id: ' + name);
  8514. }
  8515. }
  8516. function isStatefulComponent(instance) {
  8517. return instance.vnode.shapeFlag & 4 /* STATEFUL_COMPONENT */;
  8518. }
  8519. let isInSSRComponentSetup = false;
  8520. function setupComponent(instance, isSSR = false) {
  8521. isInSSRComponentSetup = isSSR;
  8522. const { props, children } = instance.vnode;
  8523. const isStateful = isStatefulComponent(instance);
  8524. initProps(instance, props, isStateful, isSSR);
  8525. initSlots(instance, children);
  8526. const setupResult = isStateful
  8527. ? setupStatefulComponent(instance, isSSR)
  8528. : undefined;
  8529. isInSSRComponentSetup = false;
  8530. return setupResult;
  8531. }
  8532. function setupStatefulComponent(instance, isSSR) {
  8533. var _a;
  8534. const Component = instance.type;
  8535. {
  8536. if (Component.name) {
  8537. validateComponentName(Component.name, instance.appContext.config);
  8538. }
  8539. if (Component.components) {
  8540. const names = Object.keys(Component.components);
  8541. for (let i = 0; i < names.length; i++) {
  8542. validateComponentName(names[i], instance.appContext.config);
  8543. }
  8544. }
  8545. if (Component.directives) {
  8546. const names = Object.keys(Component.directives);
  8547. for (let i = 0; i < names.length; i++) {
  8548. validateDirectiveName(names[i]);
  8549. }
  8550. }
  8551. if (Component.compilerOptions && isRuntimeOnly()) {
  8552. warn$1(`"compilerOptions" is only supported when using a build of Vue that ` +
  8553. `includes the runtime compiler. Since you are using a runtime-only ` +
  8554. `build, the options should be passed via your build tool config instead.`);
  8555. }
  8556. }
  8557. // 0. create render proxy property access cache
  8558. instance.accessCache = Object.create(null);
  8559. // 1. create public instance / render proxy
  8560. // also mark it raw so it's never observed
  8561. instance.proxy = markRaw(new Proxy(instance.ctx, PublicInstanceProxyHandlers));
  8562. {
  8563. exposePropsOnRenderContext(instance);
  8564. }
  8565. // 2. call setup()
  8566. const { setup } = Component;
  8567. if (setup) {
  8568. const setupContext = (instance.setupContext =
  8569. setup.length > 1 ? createSetupContext(instance) : null);
  8570. setCurrentInstance(instance);
  8571. pauseTracking();
  8572. const setupResult = callWithErrorHandling(setup, instance, 0 /* SETUP_FUNCTION */, [shallowReadonly(instance.props) , setupContext]);
  8573. resetTracking();
  8574. unsetCurrentInstance();
  8575. if (isPromise(setupResult)) {
  8576. setupResult.then(unsetCurrentInstance, unsetCurrentInstance);
  8577. if (isSSR) {
  8578. // return the promise so server-renderer can wait on it
  8579. return setupResult
  8580. .then((resolvedResult) => {
  8581. handleSetupResult(instance, resolvedResult, isSSR);
  8582. })
  8583. .catch(e => {
  8584. handleError(e, instance, 0 /* SETUP_FUNCTION */);
  8585. });
  8586. }
  8587. else {
  8588. // async setup returned Promise.
  8589. // bail here and wait for re-entry.
  8590. instance.asyncDep = setupResult;
  8591. if (!instance.suspense) {
  8592. const name = (_a = Component.name) !== null && _a !== void 0 ? _a : 'Anonymous';
  8593. warn$1(`Component <${name}>: setup function returned a promise, but no ` +
  8594. `<Suspense> boundary was found in the parent component tree. ` +
  8595. `A component with async setup() must be nested in a <Suspense> ` +
  8596. `in order to be rendered.`);
  8597. }
  8598. }
  8599. }
  8600. else {
  8601. handleSetupResult(instance, setupResult, isSSR);
  8602. }
  8603. }
  8604. else {
  8605. finishComponentSetup(instance, isSSR);
  8606. }
  8607. }
  8608. function handleSetupResult(instance, setupResult, isSSR) {
  8609. if (isFunction(setupResult)) {
  8610. // setup returned an inline render function
  8611. {
  8612. instance.render = setupResult;
  8613. }
  8614. }
  8615. else if (isObject(setupResult)) {
  8616. if (isVNode(setupResult)) {
  8617. warn$1(`setup() should not return VNodes directly - ` +
  8618. `return a render function instead.`);
  8619. }
  8620. // setup returned bindings.
  8621. // assuming a render function compiled from template is present.
  8622. {
  8623. instance.devtoolsRawSetupState = setupResult;
  8624. }
  8625. instance.setupState = proxyRefs(setupResult);
  8626. {
  8627. exposeSetupStateOnRenderContext(instance);
  8628. }
  8629. }
  8630. else if (setupResult !== undefined) {
  8631. warn$1(`setup() should return an object. Received: ${setupResult === null ? 'null' : typeof setupResult}`);
  8632. }
  8633. finishComponentSetup(instance, isSSR);
  8634. }
  8635. let compile;
  8636. let installWithProxy;
  8637. /**
  8638. * For runtime-dom to register the compiler.
  8639. * Note the exported method uses any to avoid d.ts relying on the compiler types.
  8640. */
  8641. function registerRuntimeCompiler(_compile) {
  8642. compile = _compile;
  8643. installWithProxy = i => {
  8644. if (i.render._rc) {
  8645. i.withProxy = new Proxy(i.ctx, RuntimeCompiledPublicInstanceProxyHandlers);
  8646. }
  8647. };
  8648. }
  8649. // dev only
  8650. const isRuntimeOnly = () => !compile;
  8651. function finishComponentSetup(instance, isSSR, skipOptions) {
  8652. const Component = instance.type;
  8653. // template / render function normalization
  8654. // could be already set when returned from setup()
  8655. if (!instance.render) {
  8656. // only do on-the-fly compile if not in SSR - SSR on-the-fly compilation
  8657. // is done by server-renderer
  8658. if (!isSSR && compile && !Component.render) {
  8659. const template = Component.template;
  8660. if (template) {
  8661. {
  8662. startMeasure(instance, `compile`);
  8663. }
  8664. const { isCustomElement, compilerOptions } = instance.appContext.config;
  8665. const { delimiters, compilerOptions: componentCompilerOptions } = Component;
  8666. const finalCompilerOptions = extend(extend({
  8667. isCustomElement,
  8668. delimiters
  8669. }, compilerOptions), componentCompilerOptions);
  8670. Component.render = compile(template, finalCompilerOptions);
  8671. {
  8672. endMeasure(instance, `compile`);
  8673. }
  8674. }
  8675. }
  8676. instance.render = (Component.render || NOOP);
  8677. // for runtime-compiled render functions using `with` blocks, the render
  8678. // proxy used needs a different `has` handler which is more performant and
  8679. // also only allows a whitelist of globals to fallthrough.
  8680. if (installWithProxy) {
  8681. installWithProxy(instance);
  8682. }
  8683. }
  8684. // support for 2.x options
  8685. {
  8686. setCurrentInstance(instance);
  8687. pauseTracking();
  8688. applyOptions(instance);
  8689. resetTracking();
  8690. unsetCurrentInstance();
  8691. }
  8692. // warn missing template/render
  8693. // the runtime compilation of template in SSR is done by server-render
  8694. if (!Component.render && instance.render === NOOP && !isSSR) {
  8695. /* istanbul ignore if */
  8696. if (!compile && Component.template) {
  8697. warn$1(`Component provided template option but ` +
  8698. `runtime compilation is not supported in this build of Vue.` +
  8699. (` Use "vue.global.js" instead.`
  8700. ) /* should not happen */);
  8701. }
  8702. else {
  8703. warn$1(`Component is missing template or render function.`);
  8704. }
  8705. }
  8706. }
  8707. function createAttrsProxy(instance) {
  8708. return new Proxy(instance.attrs, {
  8709. get(target, key) {
  8710. markAttrsAccessed();
  8711. track(instance, "get" /* GET */, '$attrs');
  8712. return target[key];
  8713. },
  8714. set() {
  8715. warn$1(`setupContext.attrs is readonly.`);
  8716. return false;
  8717. },
  8718. deleteProperty() {
  8719. warn$1(`setupContext.attrs is readonly.`);
  8720. return false;
  8721. }
  8722. }
  8723. );
  8724. }
  8725. function createSetupContext(instance) {
  8726. const expose = exposed => {
  8727. if (instance.exposed) {
  8728. warn$1(`expose() should be called only once per setup().`);
  8729. }
  8730. instance.exposed = exposed || {};
  8731. };
  8732. let attrs;
  8733. {
  8734. // We use getters in dev in case libs like test-utils overwrite instance
  8735. // properties (overwrites should not be done in prod)
  8736. return Object.freeze({
  8737. get attrs() {
  8738. return attrs || (attrs = createAttrsProxy(instance));
  8739. },
  8740. get slots() {
  8741. return shallowReadonly(instance.slots);
  8742. },
  8743. get emit() {
  8744. return (event, ...args) => instance.emit(event, ...args);
  8745. },
  8746. expose
  8747. });
  8748. }
  8749. }
  8750. function getExposeProxy(instance) {
  8751. if (instance.exposed) {
  8752. return (instance.exposeProxy ||
  8753. (instance.exposeProxy = new Proxy(proxyRefs(markRaw(instance.exposed)), {
  8754. get(target, key) {
  8755. if (key in target) {
  8756. return target[key];
  8757. }
  8758. else if (key in publicPropertiesMap) {
  8759. return publicPropertiesMap[key](instance);
  8760. }
  8761. }
  8762. })));
  8763. }
  8764. }
  8765. const classifyRE = /(?:^|[-_])(\w)/g;
  8766. const classify = (str) => str.replace(classifyRE, c => c.toUpperCase()).replace(/[-_]/g, '');
  8767. function getComponentName(Component) {
  8768. return isFunction(Component)
  8769. ? Component.displayName || Component.name
  8770. : Component.name;
  8771. }
  8772. /* istanbul ignore next */
  8773. function formatComponentName(instance, Component, isRoot = false) {
  8774. let name = getComponentName(Component);
  8775. if (!name && Component.__file) {
  8776. const match = Component.__file.match(/([^/\\]+)\.\w+$/);
  8777. if (match) {
  8778. name = match[1];
  8779. }
  8780. }
  8781. if (!name && instance && instance.parent) {
  8782. // try to infer the name based on reverse resolution
  8783. const inferFromRegistry = (registry) => {
  8784. for (const key in registry) {
  8785. if (registry[key] === Component) {
  8786. return key;
  8787. }
  8788. }
  8789. };
  8790. name =
  8791. inferFromRegistry(instance.components ||
  8792. instance.parent.type.components) || inferFromRegistry(instance.appContext.components);
  8793. }
  8794. return name ? classify(name) : isRoot ? `App` : `Anonymous`;
  8795. }
  8796. function isClassComponent(value) {
  8797. return isFunction(value) && '__vccOpts' in value;
  8798. }
  8799. const computed$1 = ((getterOrOptions, debugOptions) => {
  8800. // @ts-ignore
  8801. return computed(getterOrOptions, debugOptions, isInSSRComponentSetup);
  8802. });
  8803. // dev only
  8804. const warnRuntimeUsage = (method) => warn$1(`${method}() is a compiler-hint helper that is only usable inside ` +
  8805. `<script setup> of a single file component. Its arguments should be ` +
  8806. `compiled away and passing it at runtime has no effect.`);
  8807. // implementation
  8808. function defineProps() {
  8809. {
  8810. warnRuntimeUsage(`defineProps`);
  8811. }
  8812. return null;
  8813. }
  8814. // implementation
  8815. function defineEmits() {
  8816. {
  8817. warnRuntimeUsage(`defineEmits`);
  8818. }
  8819. return null;
  8820. }
  8821. /**
  8822. * Vue `<script setup>` compiler macro for declaring a component's exposed
  8823. * instance properties when it is accessed by a parent component via template
  8824. * refs.
  8825. *
  8826. * `<script setup>` components are closed by default - i.e. variables inside
  8827. * the `<script setup>` scope is not exposed to parent unless explicitly exposed
  8828. * via `defineExpose`.
  8829. *
  8830. * This is only usable inside `<script setup>`, is compiled away in the
  8831. * output and should **not** be actually called at runtime.
  8832. */
  8833. function defineExpose(exposed) {
  8834. {
  8835. warnRuntimeUsage(`defineExpose`);
  8836. }
  8837. }
  8838. /**
  8839. * Vue `<script setup>` compiler macro for providing props default values when
  8840. * using type-based `defineProps` declaration.
  8841. *
  8842. * Example usage:
  8843. * ```ts
  8844. * withDefaults(defineProps<{
  8845. * size?: number
  8846. * labels?: string[]
  8847. * }>(), {
  8848. * size: 3,
  8849. * labels: () => ['default label']
  8850. * })
  8851. * ```
  8852. *
  8853. * This is only usable inside `<script setup>`, is compiled away in the output
  8854. * and should **not** be actually called at runtime.
  8855. */
  8856. function withDefaults(props, defaults) {
  8857. {
  8858. warnRuntimeUsage(`withDefaults`);
  8859. }
  8860. return null;
  8861. }
  8862. function useSlots() {
  8863. return getContext().slots;
  8864. }
  8865. function useAttrs() {
  8866. return getContext().attrs;
  8867. }
  8868. function getContext() {
  8869. const i = getCurrentInstance();
  8870. if (!i) {
  8871. warn$1(`useContext() called without active instance.`);
  8872. }
  8873. return i.setupContext || (i.setupContext = createSetupContext(i));
  8874. }
  8875. /**
  8876. * Runtime helper for merging default declarations. Imported by compiled code
  8877. * only.
  8878. * @internal
  8879. */
  8880. function mergeDefaults(raw, defaults) {
  8881. const props = isArray(raw)
  8882. ? raw.reduce((normalized, p) => ((normalized[p] = {}), normalized), {})
  8883. : raw;
  8884. for (const key in defaults) {
  8885. const opt = props[key];
  8886. if (opt) {
  8887. if (isArray(opt) || isFunction(opt)) {
  8888. props[key] = { type: opt, default: defaults[key] };
  8889. }
  8890. else {
  8891. opt.default = defaults[key];
  8892. }
  8893. }
  8894. else if (opt === null) {
  8895. props[key] = { default: defaults[key] };
  8896. }
  8897. else {
  8898. warn$1(`props default key "${key}" has no corresponding declaration.`);
  8899. }
  8900. }
  8901. return props;
  8902. }
  8903. /**
  8904. * Used to create a proxy for the rest element when destructuring props with
  8905. * defineProps().
  8906. * @internal
  8907. */
  8908. function createPropsRestProxy(props, excludedKeys) {
  8909. const ret = {};
  8910. for (const key in props) {
  8911. if (!excludedKeys.includes(key)) {
  8912. Object.defineProperty(ret, key, {
  8913. enumerable: true,
  8914. get: () => props[key]
  8915. });
  8916. }
  8917. }
  8918. return ret;
  8919. }
  8920. /**
  8921. * `<script setup>` helper for persisting the current instance context over
  8922. * async/await flows.
  8923. *
  8924. * `@vue/compiler-sfc` converts the following:
  8925. *
  8926. * ```ts
  8927. * const x = await foo()
  8928. * ```
  8929. *
  8930. * into:
  8931. *
  8932. * ```ts
  8933. * let __temp, __restore
  8934. * const x = (([__temp, __restore] = withAsyncContext(() => foo())),__temp=await __temp,__restore(),__temp)
  8935. * ```
  8936. * @internal
  8937. */
  8938. function withAsyncContext(getAwaitable) {
  8939. const ctx = getCurrentInstance();
  8940. if (!ctx) {
  8941. warn$1(`withAsyncContext called without active current instance. ` +
  8942. `This is likely a bug.`);
  8943. }
  8944. let awaitable = getAwaitable();
  8945. unsetCurrentInstance();
  8946. if (isPromise(awaitable)) {
  8947. awaitable = awaitable.catch(e => {
  8948. setCurrentInstance(ctx);
  8949. throw e;
  8950. });
  8951. }
  8952. return [awaitable, () => setCurrentInstance(ctx)];
  8953. }
  8954. // Actual implementation
  8955. function h(type, propsOrChildren, children) {
  8956. const l = arguments.length;
  8957. if (l === 2) {
  8958. if (isObject(propsOrChildren) && !isArray(propsOrChildren)) {
  8959. // single vnode without props
  8960. if (isVNode(propsOrChildren)) {
  8961. return createVNode(type, null, [propsOrChildren]);
  8962. }
  8963. // props without children
  8964. return createVNode(type, propsOrChildren);
  8965. }
  8966. else {
  8967. // omit props
  8968. return createVNode(type, null, propsOrChildren);
  8969. }
  8970. }
  8971. else {
  8972. if (l > 3) {
  8973. children = Array.prototype.slice.call(arguments, 2);
  8974. }
  8975. else if (l === 3 && isVNode(children)) {
  8976. children = [children];
  8977. }
  8978. return createVNode(type, propsOrChildren, children);
  8979. }
  8980. }
  8981. const ssrContextKey = Symbol(`ssrContext` );
  8982. const useSSRContext = () => {
  8983. {
  8984. warn$1(`useSSRContext() is not supported in the global build.`);
  8985. }
  8986. };
  8987. function initCustomFormatter() {
  8988. /* eslint-disable no-restricted-globals */
  8989. if (typeof window === 'undefined') {
  8990. return;
  8991. }
  8992. const vueStyle = { style: 'color:#3ba776' };
  8993. const numberStyle = { style: 'color:#0b1bc9' };
  8994. const stringStyle = { style: 'color:#b62e24' };
  8995. const keywordStyle = { style: 'color:#9d288c' };
  8996. // custom formatter for Chrome
  8997. // https://www.mattzeunert.com/2016/02/19/custom-chrome-devtools-object-formatters.html
  8998. const formatter = {
  8999. header(obj) {
  9000. // TODO also format ComponentPublicInstance & ctx.slots/attrs in setup
  9001. if (!isObject(obj)) {
  9002. return null;
  9003. }
  9004. if (obj.__isVue) {
  9005. return ['div', vueStyle, `VueInstance`];
  9006. }
  9007. else if (isRef(obj)) {
  9008. return [
  9009. 'div',
  9010. {},
  9011. ['span', vueStyle, genRefFlag(obj)],
  9012. '<',
  9013. formatValue(obj.value),
  9014. `>`
  9015. ];
  9016. }
  9017. else if (isReactive(obj)) {
  9018. return [
  9019. 'div',
  9020. {},
  9021. ['span', vueStyle, isShallow(obj) ? 'ShallowReactive' : 'Reactive'],
  9022. '<',
  9023. formatValue(obj),
  9024. `>${isReadonly(obj) ? ` (readonly)` : ``}`
  9025. ];
  9026. }
  9027. else if (isReadonly(obj)) {
  9028. return [
  9029. 'div',
  9030. {},
  9031. ['span', vueStyle, isShallow(obj) ? 'ShallowReadonly' : 'Readonly'],
  9032. '<',
  9033. formatValue(obj),
  9034. '>'
  9035. ];
  9036. }
  9037. return null;
  9038. },
  9039. hasBody(obj) {
  9040. return obj && obj.__isVue;
  9041. },
  9042. body(obj) {
  9043. if (obj && obj.__isVue) {
  9044. return [
  9045. 'div',
  9046. {},
  9047. ...formatInstance(obj.$)
  9048. ];
  9049. }
  9050. }
  9051. };
  9052. function formatInstance(instance) {
  9053. const blocks = [];
  9054. if (instance.type.props && instance.props) {
  9055. blocks.push(createInstanceBlock('props', toRaw(instance.props)));
  9056. }
  9057. if (instance.setupState !== EMPTY_OBJ) {
  9058. blocks.push(createInstanceBlock('setup', instance.setupState));
  9059. }
  9060. if (instance.data !== EMPTY_OBJ) {
  9061. blocks.push(createInstanceBlock('data', toRaw(instance.data)));
  9062. }
  9063. const computed = extractKeys(instance, 'computed');
  9064. if (computed) {
  9065. blocks.push(createInstanceBlock('computed', computed));
  9066. }
  9067. const injected = extractKeys(instance, 'inject');
  9068. if (injected) {
  9069. blocks.push(createInstanceBlock('injected', injected));
  9070. }
  9071. blocks.push([
  9072. 'div',
  9073. {},
  9074. [
  9075. 'span',
  9076. {
  9077. style: keywordStyle.style + ';opacity:0.66'
  9078. },
  9079. '$ (internal): '
  9080. ],
  9081. ['object', { object: instance }]
  9082. ]);
  9083. return blocks;
  9084. }
  9085. function createInstanceBlock(type, target) {
  9086. target = extend({}, target);
  9087. if (!Object.keys(target).length) {
  9088. return ['span', {}];
  9089. }
  9090. return [
  9091. 'div',
  9092. { style: 'line-height:1.25em;margin-bottom:0.6em' },
  9093. [
  9094. 'div',
  9095. {
  9096. style: 'color:#476582'
  9097. },
  9098. type
  9099. ],
  9100. [
  9101. 'div',
  9102. {
  9103. style: 'padding-left:1.25em'
  9104. },
  9105. ...Object.keys(target).map(key => {
  9106. return [
  9107. 'div',
  9108. {},
  9109. ['span', keywordStyle, key + ': '],
  9110. formatValue(target[key], false)
  9111. ];
  9112. })
  9113. ]
  9114. ];
  9115. }
  9116. function formatValue(v, asRaw = true) {
  9117. if (typeof v === 'number') {
  9118. return ['span', numberStyle, v];
  9119. }
  9120. else if (typeof v === 'string') {
  9121. return ['span', stringStyle, JSON.stringify(v)];
  9122. }
  9123. else if (typeof v === 'boolean') {
  9124. return ['span', keywordStyle, v];
  9125. }
  9126. else if (isObject(v)) {
  9127. return ['object', { object: asRaw ? toRaw(v) : v }];
  9128. }
  9129. else {
  9130. return ['span', stringStyle, String(v)];
  9131. }
  9132. }
  9133. function extractKeys(instance, type) {
  9134. const Comp = instance.type;
  9135. if (isFunction(Comp)) {
  9136. return;
  9137. }
  9138. const extracted = {};
  9139. for (const key in instance.ctx) {
  9140. if (isKeyOfType(Comp, key, type)) {
  9141. extracted[key] = instance.ctx[key];
  9142. }
  9143. }
  9144. return extracted;
  9145. }
  9146. function isKeyOfType(Comp, key, type) {
  9147. const opts = Comp[type];
  9148. if ((isArray(opts) && opts.includes(key)) ||
  9149. (isObject(opts) && key in opts)) {
  9150. return true;
  9151. }
  9152. if (Comp.extends && isKeyOfType(Comp.extends, key, type)) {
  9153. return true;
  9154. }
  9155. if (Comp.mixins && Comp.mixins.some(m => isKeyOfType(m, key, type))) {
  9156. return true;
  9157. }
  9158. }
  9159. function genRefFlag(v) {
  9160. if (isShallow(v)) {
  9161. return `ShallowRef`;
  9162. }
  9163. if (v.effect) {
  9164. return `ComputedRef`;
  9165. }
  9166. return `Ref`;
  9167. }
  9168. if (window.devtoolsFormatters) {
  9169. window.devtoolsFormatters.push(formatter);
  9170. }
  9171. else {
  9172. window.devtoolsFormatters = [formatter];
  9173. }
  9174. }
  9175. function withMemo(memo, render, cache, index) {
  9176. const cached = cache[index];
  9177. if (cached && isMemoSame(cached, memo)) {
  9178. return cached;
  9179. }
  9180. const ret = render();
  9181. // shallow clone
  9182. ret.memo = memo.slice();
  9183. return (cache[index] = ret);
  9184. }
  9185. function isMemoSame(cached, memo) {
  9186. const prev = cached.memo;
  9187. if (prev.length != memo.length) {
  9188. return false;
  9189. }
  9190. for (let i = 0; i < prev.length; i++) {
  9191. if (hasChanged(prev[i], memo[i])) {
  9192. return false;
  9193. }
  9194. }
  9195. // make sure to let parent block track it when returning cached
  9196. if (isBlockTreeEnabled > 0 && currentBlock) {
  9197. currentBlock.push(cached);
  9198. }
  9199. return true;
  9200. }
  9201. // Core API ------------------------------------------------------------------
  9202. const version = "3.2.36";
  9203. /**
  9204. * SSR utils for \@vue/server-renderer. Only exposed in cjs builds.
  9205. * @internal
  9206. */
  9207. const ssrUtils = (null);
  9208. /**
  9209. * @internal only exposed in compat builds
  9210. */
  9211. const resolveFilter = null;
  9212. /**
  9213. * @internal only exposed in compat builds.
  9214. */
  9215. const compatUtils = (null);
  9216. const svgNS = 'http://www.w3.org/2000/svg';
  9217. const doc = (typeof document !== 'undefined' ? document : null);
  9218. const templateContainer = doc && /*#__PURE__*/ doc.createElement('template');
  9219. const nodeOps = {
  9220. insert: (child, parent, anchor) => {
  9221. parent.insertBefore(child, anchor || null);
  9222. },
  9223. remove: child => {
  9224. const parent = child.parentNode;
  9225. if (parent) {
  9226. parent.removeChild(child);
  9227. }
  9228. },
  9229. createElement: (tag, isSVG, is, props) => {
  9230. const el = isSVG
  9231. ? doc.createElementNS(svgNS, tag)
  9232. : doc.createElement(tag, is ? { is } : undefined);
  9233. if (tag === 'select' && props && props.multiple != null) {
  9234. el.setAttribute('multiple', props.multiple);
  9235. }
  9236. return el;
  9237. },
  9238. createText: text => doc.createTextNode(text),
  9239. createComment: text => doc.createComment(text),
  9240. setText: (node, text) => {
  9241. node.nodeValue = text;
  9242. },
  9243. setElementText: (el, text) => {
  9244. el.textContent = text;
  9245. },
  9246. parentNode: node => node.parentNode,
  9247. nextSibling: node => node.nextSibling,
  9248. querySelector: selector => doc.querySelector(selector),
  9249. setScopeId(el, id) {
  9250. el.setAttribute(id, '');
  9251. },
  9252. cloneNode(el) {
  9253. const cloned = el.cloneNode(true);
  9254. // #3072
  9255. // - in `patchDOMProp`, we store the actual value in the `el._value` property.
  9256. // - normally, elements using `:value` bindings will not be hoisted, but if
  9257. // the bound value is a constant, e.g. `:value="true"` - they do get
  9258. // hoisted.
  9259. // - in production, hoisted nodes are cloned when subsequent inserts, but
  9260. // cloneNode() does not copy the custom property we attached.
  9261. // - This may need to account for other custom DOM properties we attach to
  9262. // elements in addition to `_value` in the future.
  9263. if (`_value` in el) {
  9264. cloned._value = el._value;
  9265. }
  9266. return cloned;
  9267. },
  9268. // __UNSAFE__
  9269. // Reason: innerHTML.
  9270. // Static content here can only come from compiled templates.
  9271. // As long as the user only uses trusted templates, this is safe.
  9272. insertStaticContent(content, parent, anchor, isSVG, start, end) {
  9273. // <parent> before | first ... last | anchor </parent>
  9274. const before = anchor ? anchor.previousSibling : parent.lastChild;
  9275. // #5308 can only take cached path if:
  9276. // - has a single root node
  9277. // - nextSibling info is still available
  9278. if (start && (start === end || start.nextSibling)) {
  9279. // cached
  9280. while (true) {
  9281. parent.insertBefore(start.cloneNode(true), anchor);
  9282. if (start === end || !(start = start.nextSibling))
  9283. break;
  9284. }
  9285. }
  9286. else {
  9287. // fresh insert
  9288. templateContainer.innerHTML = isSVG ? `<svg>${content}</svg>` : content;
  9289. const template = templateContainer.content;
  9290. if (isSVG) {
  9291. // remove outer svg wrapper
  9292. const wrapper = template.firstChild;
  9293. while (wrapper.firstChild) {
  9294. template.appendChild(wrapper.firstChild);
  9295. }
  9296. template.removeChild(wrapper);
  9297. }
  9298. parent.insertBefore(template, anchor);
  9299. }
  9300. return [
  9301. // first
  9302. before ? before.nextSibling : parent.firstChild,
  9303. // last
  9304. anchor ? anchor.previousSibling : parent.lastChild
  9305. ];
  9306. }
  9307. };
  9308. // compiler should normalize class + :class bindings on the same element
  9309. // into a single binding ['staticClass', dynamic]
  9310. function patchClass(el, value, isSVG) {
  9311. // directly setting className should be faster than setAttribute in theory
  9312. // if this is an element during a transition, take the temporary transition
  9313. // classes into account.
  9314. const transitionClasses = el._vtc;
  9315. if (transitionClasses) {
  9316. value = (value ? [value, ...transitionClasses] : [...transitionClasses]).join(' ');
  9317. }
  9318. if (value == null) {
  9319. el.removeAttribute('class');
  9320. }
  9321. else if (isSVG) {
  9322. el.setAttribute('class', value);
  9323. }
  9324. else {
  9325. el.className = value;
  9326. }
  9327. }
  9328. function patchStyle(el, prev, next) {
  9329. const style = el.style;
  9330. const isCssString = isString(next);
  9331. if (next && !isCssString) {
  9332. for (const key in next) {
  9333. setStyle(style, key, next[key]);
  9334. }
  9335. if (prev && !isString(prev)) {
  9336. for (const key in prev) {
  9337. if (next[key] == null) {
  9338. setStyle(style, key, '');
  9339. }
  9340. }
  9341. }
  9342. }
  9343. else {
  9344. const currentDisplay = style.display;
  9345. if (isCssString) {
  9346. if (prev !== next) {
  9347. style.cssText = next;
  9348. }
  9349. }
  9350. else if (prev) {
  9351. el.removeAttribute('style');
  9352. }
  9353. // indicates that the `display` of the element is controlled by `v-show`,
  9354. // so we always keep the current `display` value regardless of the `style`
  9355. // value, thus handing over control to `v-show`.
  9356. if ('_vod' in el) {
  9357. style.display = currentDisplay;
  9358. }
  9359. }
  9360. }
  9361. const importantRE = /\s*!important$/;
  9362. function setStyle(style, name, val) {
  9363. if (isArray(val)) {
  9364. val.forEach(v => setStyle(style, name, v));
  9365. }
  9366. else {
  9367. if (val == null)
  9368. val = '';
  9369. if (name.startsWith('--')) {
  9370. // custom property definition
  9371. style.setProperty(name, val);
  9372. }
  9373. else {
  9374. const prefixed = autoPrefix(style, name);
  9375. if (importantRE.test(val)) {
  9376. // !important
  9377. style.setProperty(hyphenate(prefixed), val.replace(importantRE, ''), 'important');
  9378. }
  9379. else {
  9380. style[prefixed] = val;
  9381. }
  9382. }
  9383. }
  9384. }
  9385. const prefixes = ['Webkit', 'Moz', 'ms'];
  9386. const prefixCache = {};
  9387. function autoPrefix(style, rawName) {
  9388. const cached = prefixCache[rawName];
  9389. if (cached) {
  9390. return cached;
  9391. }
  9392. let name = camelize(rawName);
  9393. if (name !== 'filter' && name in style) {
  9394. return (prefixCache[rawName] = name);
  9395. }
  9396. name = capitalize(name);
  9397. for (let i = 0; i < prefixes.length; i++) {
  9398. const prefixed = prefixes[i] + name;
  9399. if (prefixed in style) {
  9400. return (prefixCache[rawName] = prefixed);
  9401. }
  9402. }
  9403. return rawName;
  9404. }
  9405. const xlinkNS = 'http://www.w3.org/1999/xlink';
  9406. function patchAttr(el, key, value, isSVG, instance) {
  9407. if (isSVG && key.startsWith('xlink:')) {
  9408. if (value == null) {
  9409. el.removeAttributeNS(xlinkNS, key.slice(6, key.length));
  9410. }
  9411. else {
  9412. el.setAttributeNS(xlinkNS, key, value);
  9413. }
  9414. }
  9415. else {
  9416. // note we are only checking boolean attributes that don't have a
  9417. // corresponding dom prop of the same name here.
  9418. const isBoolean = isSpecialBooleanAttr(key);
  9419. if (value == null || (isBoolean && !includeBooleanAttr(value))) {
  9420. el.removeAttribute(key);
  9421. }
  9422. else {
  9423. el.setAttribute(key, isBoolean ? '' : value);
  9424. }
  9425. }
  9426. }
  9427. // __UNSAFE__
  9428. // functions. The user is responsible for using them with only trusted content.
  9429. function patchDOMProp(el, key, value,
  9430. // the following args are passed only due to potential innerHTML/textContent
  9431. // overriding existing VNodes, in which case the old tree must be properly
  9432. // unmounted.
  9433. prevChildren, parentComponent, parentSuspense, unmountChildren) {
  9434. if (key === 'innerHTML' || key === 'textContent') {
  9435. if (prevChildren) {
  9436. unmountChildren(prevChildren, parentComponent, parentSuspense);
  9437. }
  9438. el[key] = value == null ? '' : value;
  9439. return;
  9440. }
  9441. if (key === 'value' &&
  9442. el.tagName !== 'PROGRESS' &&
  9443. // custom elements may use _value internally
  9444. !el.tagName.includes('-')) {
  9445. // store value as _value as well since
  9446. // non-string values will be stringified.
  9447. el._value = value;
  9448. const newValue = value == null ? '' : value;
  9449. if (el.value !== newValue ||
  9450. // #4956: always set for OPTION elements because its value falls back to
  9451. // textContent if no value attribute is present. And setting .value for
  9452. // OPTION has no side effect
  9453. el.tagName === 'OPTION') {
  9454. el.value = newValue;
  9455. }
  9456. if (value == null) {
  9457. el.removeAttribute(key);
  9458. }
  9459. return;
  9460. }
  9461. let needRemove = false;
  9462. if (value === '' || value == null) {
  9463. const type = typeof el[key];
  9464. if (type === 'boolean') {
  9465. // e.g. <select multiple> compiles to { multiple: '' }
  9466. value = includeBooleanAttr(value);
  9467. }
  9468. else if (value == null && type === 'string') {
  9469. // e.g. <div :id="null">
  9470. value = '';
  9471. needRemove = true;
  9472. }
  9473. else if (type === 'number') {
  9474. // e.g. <img :width="null">
  9475. // the value of some IDL attr must be greater than 0, e.g. input.size = 0 -> error
  9476. value = 0;
  9477. needRemove = true;
  9478. }
  9479. }
  9480. // some properties perform value validation and throw,
  9481. // some properties has getter, no setter, will error in 'use strict'
  9482. // eg. <select :type="null"></select> <select :willValidate="null"></select>
  9483. try {
  9484. el[key] = value;
  9485. }
  9486. catch (e) {
  9487. {
  9488. warn$1(`Failed setting prop "${key}" on <${el.tagName.toLowerCase()}>: ` +
  9489. `value ${value} is invalid.`, e);
  9490. }
  9491. }
  9492. needRemove && el.removeAttribute(key);
  9493. }
  9494. // Async edge case fix requires storing an event listener's attach timestamp.
  9495. const [_getNow, skipTimestampCheck] = /*#__PURE__*/ (() => {
  9496. let _getNow = Date.now;
  9497. let skipTimestampCheck = false;
  9498. if (typeof window !== 'undefined') {
  9499. // Determine what event timestamp the browser is using. Annoyingly, the
  9500. // timestamp can either be hi-res (relative to page load) or low-res
  9501. // (relative to UNIX epoch), so in order to compare time we have to use the
  9502. // same timestamp type when saving the flush timestamp.
  9503. if (Date.now() > document.createEvent('Event').timeStamp) {
  9504. // if the low-res timestamp which is bigger than the event timestamp
  9505. // (which is evaluated AFTER) it means the event is using a hi-res timestamp,
  9506. // and we need to use the hi-res version for event listeners as well.
  9507. _getNow = performance.now.bind(performance);
  9508. }
  9509. // #3485: Firefox <= 53 has incorrect Event.timeStamp implementation
  9510. // and does not fire microtasks in between event propagation, so safe to exclude.
  9511. const ffMatch = navigator.userAgent.match(/firefox\/(\d+)/i);
  9512. skipTimestampCheck = !!(ffMatch && Number(ffMatch[1]) <= 53);
  9513. }
  9514. return [_getNow, skipTimestampCheck];
  9515. })();
  9516. // To avoid the overhead of repeatedly calling performance.now(), we cache
  9517. // and use the same timestamp for all event listeners attached in the same tick.
  9518. let cachedNow = 0;
  9519. const p = /*#__PURE__*/ Promise.resolve();
  9520. const reset = () => {
  9521. cachedNow = 0;
  9522. };
  9523. const getNow = () => cachedNow || (p.then(reset), (cachedNow = _getNow()));
  9524. function addEventListener(el, event, handler, options) {
  9525. el.addEventListener(event, handler, options);
  9526. }
  9527. function removeEventListener(el, event, handler, options) {
  9528. el.removeEventListener(event, handler, options);
  9529. }
  9530. function patchEvent(el, rawName, prevValue, nextValue, instance = null) {
  9531. // vei = vue event invokers
  9532. const invokers = el._vei || (el._vei = {});
  9533. const existingInvoker = invokers[rawName];
  9534. if (nextValue && existingInvoker) {
  9535. // patch
  9536. existingInvoker.value = nextValue;
  9537. }
  9538. else {
  9539. const [name, options] = parseName(rawName);
  9540. if (nextValue) {
  9541. // add
  9542. const invoker = (invokers[rawName] = createInvoker(nextValue, instance));
  9543. addEventListener(el, name, invoker, options);
  9544. }
  9545. else if (existingInvoker) {
  9546. // remove
  9547. removeEventListener(el, name, existingInvoker, options);
  9548. invokers[rawName] = undefined;
  9549. }
  9550. }
  9551. }
  9552. const optionsModifierRE = /(?:Once|Passive|Capture)$/;
  9553. function parseName(name) {
  9554. let options;
  9555. if (optionsModifierRE.test(name)) {
  9556. options = {};
  9557. let m;
  9558. while ((m = name.match(optionsModifierRE))) {
  9559. name = name.slice(0, name.length - m[0].length);
  9560. options[m[0].toLowerCase()] = true;
  9561. }
  9562. }
  9563. return [hyphenate(name.slice(2)), options];
  9564. }
  9565. function createInvoker(initialValue, instance) {
  9566. const invoker = (e) => {
  9567. // async edge case #6566: inner click event triggers patch, event handler
  9568. // attached to outer element during patch, and triggered again. This
  9569. // happens because browsers fire microtask ticks between event propagation.
  9570. // the solution is simple: we save the timestamp when a handler is attached,
  9571. // and the handler would only fire if the event passed to it was fired
  9572. // AFTER it was attached.
  9573. const timeStamp = e.timeStamp || _getNow();
  9574. if (skipTimestampCheck || timeStamp >= invoker.attached - 1) {
  9575. callWithAsyncErrorHandling(patchStopImmediatePropagation(e, invoker.value), instance, 5 /* NATIVE_EVENT_HANDLER */, [e]);
  9576. }
  9577. };
  9578. invoker.value = initialValue;
  9579. invoker.attached = getNow();
  9580. return invoker;
  9581. }
  9582. function patchStopImmediatePropagation(e, value) {
  9583. if (isArray(value)) {
  9584. const originalStop = e.stopImmediatePropagation;
  9585. e.stopImmediatePropagation = () => {
  9586. originalStop.call(e);
  9587. e._stopped = true;
  9588. };
  9589. return value.map(fn => (e) => !e._stopped && fn && fn(e));
  9590. }
  9591. else {
  9592. return value;
  9593. }
  9594. }
  9595. const nativeOnRE = /^on[a-z]/;
  9596. const patchProp = (el, key, prevValue, nextValue, isSVG = false, prevChildren, parentComponent, parentSuspense, unmountChildren) => {
  9597. if (key === 'class') {
  9598. patchClass(el, nextValue, isSVG);
  9599. }
  9600. else if (key === 'style') {
  9601. patchStyle(el, prevValue, nextValue);
  9602. }
  9603. else if (isOn(key)) {
  9604. // ignore v-model listeners
  9605. if (!isModelListener(key)) {
  9606. patchEvent(el, key, prevValue, nextValue, parentComponent);
  9607. }
  9608. }
  9609. else if (key[0] === '.'
  9610. ? ((key = key.slice(1)), true)
  9611. : key[0] === '^'
  9612. ? ((key = key.slice(1)), false)
  9613. : shouldSetAsProp(el, key, nextValue, isSVG)) {
  9614. patchDOMProp(el, key, nextValue, prevChildren, parentComponent, parentSuspense, unmountChildren);
  9615. }
  9616. else {
  9617. // special case for <input v-model type="checkbox"> with
  9618. // :true-value & :false-value
  9619. // store value as dom properties since non-string values will be
  9620. // stringified.
  9621. if (key === 'true-value') {
  9622. el._trueValue = nextValue;
  9623. }
  9624. else if (key === 'false-value') {
  9625. el._falseValue = nextValue;
  9626. }
  9627. patchAttr(el, key, nextValue, isSVG);
  9628. }
  9629. };
  9630. function shouldSetAsProp(el, key, value, isSVG) {
  9631. if (isSVG) {
  9632. // most keys must be set as attribute on svg elements to work
  9633. // ...except innerHTML & textContent
  9634. if (key === 'innerHTML' || key === 'textContent') {
  9635. return true;
  9636. }
  9637. // or native onclick with function values
  9638. if (key in el && nativeOnRE.test(key) && isFunction(value)) {
  9639. return true;
  9640. }
  9641. return false;
  9642. }
  9643. // these are enumerated attrs, however their corresponding DOM properties
  9644. // are actually booleans - this leads to setting it with a string "false"
  9645. // value leading it to be coerced to `true`, so we need to always treat
  9646. // them as attributes.
  9647. // Note that `contentEditable` doesn't have this problem: its DOM
  9648. // property is also enumerated string values.
  9649. if (key === 'spellcheck' || key === 'draggable' || key === 'translate') {
  9650. return false;
  9651. }
  9652. // #1787, #2840 form property on form elements is readonly and must be set as
  9653. // attribute.
  9654. if (key === 'form') {
  9655. return false;
  9656. }
  9657. // #1526 <input list> must be set as attribute
  9658. if (key === 'list' && el.tagName === 'INPUT') {
  9659. return false;
  9660. }
  9661. // #2766 <textarea type> must be set as attribute
  9662. if (key === 'type' && el.tagName === 'TEXTAREA') {
  9663. return false;
  9664. }
  9665. // native onclick with string value, must be set as attribute
  9666. if (nativeOnRE.test(key) && isString(value)) {
  9667. return false;
  9668. }
  9669. return key in el;
  9670. }
  9671. function defineCustomElement(options, hydrate) {
  9672. const Comp = defineComponent(options);
  9673. class VueCustomElement extends VueElement {
  9674. constructor(initialProps) {
  9675. super(Comp, initialProps, hydrate);
  9676. }
  9677. }
  9678. VueCustomElement.def = Comp;
  9679. return VueCustomElement;
  9680. }
  9681. const defineSSRCustomElement = ((options) => {
  9682. // @ts-ignore
  9683. return defineCustomElement(options, hydrate);
  9684. });
  9685. const BaseClass = (typeof HTMLElement !== 'undefined' ? HTMLElement : class {
  9686. });
  9687. class VueElement extends BaseClass {
  9688. constructor(_def, _props = {}, hydrate) {
  9689. super();
  9690. this._def = _def;
  9691. this._props = _props;
  9692. /**
  9693. * @internal
  9694. */
  9695. this._instance = null;
  9696. this._connected = false;
  9697. this._resolved = false;
  9698. this._numberProps = null;
  9699. if (this.shadowRoot && hydrate) {
  9700. hydrate(this._createVNode(), this.shadowRoot);
  9701. }
  9702. else {
  9703. if (this.shadowRoot) {
  9704. warn$1(`Custom element has pre-rendered declarative shadow root but is not ` +
  9705. `defined as hydratable. Use \`defineSSRCustomElement\`.`);
  9706. }
  9707. this.attachShadow({ mode: 'open' });
  9708. }
  9709. }
  9710. connectedCallback() {
  9711. this._connected = true;
  9712. if (!this._instance) {
  9713. this._resolveDef();
  9714. }
  9715. }
  9716. disconnectedCallback() {
  9717. this._connected = false;
  9718. nextTick(() => {
  9719. if (!this._connected) {
  9720. render(null, this.shadowRoot);
  9721. this._instance = null;
  9722. }
  9723. });
  9724. }
  9725. /**
  9726. * resolve inner component definition (handle possible async component)
  9727. */
  9728. _resolveDef() {
  9729. if (this._resolved) {
  9730. return;
  9731. }
  9732. this._resolved = true;
  9733. // set initial attrs
  9734. for (let i = 0; i < this.attributes.length; i++) {
  9735. this._setAttr(this.attributes[i].name);
  9736. }
  9737. // watch future attr changes
  9738. new MutationObserver(mutations => {
  9739. for (const m of mutations) {
  9740. this._setAttr(m.attributeName);
  9741. }
  9742. }).observe(this, { attributes: true });
  9743. const resolve = (def) => {
  9744. const { props, styles } = def;
  9745. const hasOptions = !isArray(props);
  9746. const rawKeys = props ? (hasOptions ? Object.keys(props) : props) : [];
  9747. // cast Number-type props set before resolve
  9748. let numberProps;
  9749. if (hasOptions) {
  9750. for (const key in this._props) {
  9751. const opt = props[key];
  9752. if (opt === Number || (opt && opt.type === Number)) {
  9753. this._props[key] = toNumber(this._props[key]);
  9754. (numberProps || (numberProps = Object.create(null)))[key] = true;
  9755. }
  9756. }
  9757. }
  9758. this._numberProps = numberProps;
  9759. // check if there are props set pre-upgrade or connect
  9760. for (const key of Object.keys(this)) {
  9761. if (key[0] !== '_') {
  9762. this._setProp(key, this[key], true, false);
  9763. }
  9764. }
  9765. // defining getter/setters on prototype
  9766. for (const key of rawKeys.map(camelize)) {
  9767. Object.defineProperty(this, key, {
  9768. get() {
  9769. return this._getProp(key);
  9770. },
  9771. set(val) {
  9772. this._setProp(key, val);
  9773. }
  9774. });
  9775. }
  9776. // apply CSS
  9777. this._applyStyles(styles);
  9778. // initial render
  9779. this._update();
  9780. };
  9781. const asyncDef = this._def.__asyncLoader;
  9782. if (asyncDef) {
  9783. asyncDef().then(resolve);
  9784. }
  9785. else {
  9786. resolve(this._def);
  9787. }
  9788. }
  9789. _setAttr(key) {
  9790. let value = this.getAttribute(key);
  9791. if (this._numberProps && this._numberProps[key]) {
  9792. value = toNumber(value);
  9793. }
  9794. this._setProp(camelize(key), value, false);
  9795. }
  9796. /**
  9797. * @internal
  9798. */
  9799. _getProp(key) {
  9800. return this._props[key];
  9801. }
  9802. /**
  9803. * @internal
  9804. */
  9805. _setProp(key, val, shouldReflect = true, shouldUpdate = true) {
  9806. if (val !== this._props[key]) {
  9807. this._props[key] = val;
  9808. if (shouldUpdate && this._instance) {
  9809. this._update();
  9810. }
  9811. // reflect
  9812. if (shouldReflect) {
  9813. if (val === true) {
  9814. this.setAttribute(hyphenate(key), '');
  9815. }
  9816. else if (typeof val === 'string' || typeof val === 'number') {
  9817. this.setAttribute(hyphenate(key), val + '');
  9818. }
  9819. else if (!val) {
  9820. this.removeAttribute(hyphenate(key));
  9821. }
  9822. }
  9823. }
  9824. }
  9825. _update() {
  9826. render(this._createVNode(), this.shadowRoot);
  9827. }
  9828. _createVNode() {
  9829. const vnode = createVNode(this._def, extend({}, this._props));
  9830. if (!this._instance) {
  9831. vnode.ce = instance => {
  9832. this._instance = instance;
  9833. instance.isCE = true;
  9834. // HMR
  9835. {
  9836. instance.ceReload = newStyles => {
  9837. // always reset styles
  9838. if (this._styles) {
  9839. this._styles.forEach(s => this.shadowRoot.removeChild(s));
  9840. this._styles.length = 0;
  9841. }
  9842. this._applyStyles(newStyles);
  9843. // if this is an async component, ceReload is called from the inner
  9844. // component so no need to reload the async wrapper
  9845. if (!this._def.__asyncLoader) {
  9846. // reload
  9847. this._instance = null;
  9848. this._update();
  9849. }
  9850. };
  9851. }
  9852. // intercept emit
  9853. instance.emit = (event, ...args) => {
  9854. this.dispatchEvent(new CustomEvent(event, {
  9855. detail: args
  9856. }));
  9857. };
  9858. // locate nearest Vue custom element parent for provide/inject
  9859. let parent = this;
  9860. while ((parent =
  9861. parent && (parent.parentNode || parent.host))) {
  9862. if (parent instanceof VueElement) {
  9863. instance.parent = parent._instance;
  9864. break;
  9865. }
  9866. }
  9867. };
  9868. }
  9869. return vnode;
  9870. }
  9871. _applyStyles(styles) {
  9872. if (styles) {
  9873. styles.forEach(css => {
  9874. const s = document.createElement('style');
  9875. s.textContent = css;
  9876. this.shadowRoot.appendChild(s);
  9877. // record for HMR
  9878. {
  9879. (this._styles || (this._styles = [])).push(s);
  9880. }
  9881. });
  9882. }
  9883. }
  9884. }
  9885. function useCssModule(name = '$style') {
  9886. /* istanbul ignore else */
  9887. {
  9888. {
  9889. warn$1(`useCssModule() is not supported in the global build.`);
  9890. }
  9891. return EMPTY_OBJ;
  9892. }
  9893. }
  9894. /**
  9895. * Runtime helper for SFC's CSS variable injection feature.
  9896. * @private
  9897. */
  9898. function useCssVars(getter) {
  9899. const instance = getCurrentInstance();
  9900. /* istanbul ignore next */
  9901. if (!instance) {
  9902. warn$1(`useCssVars is called without current active component instance.`);
  9903. return;
  9904. }
  9905. const setVars = () => setVarsOnVNode(instance.subTree, getter(instance.proxy));
  9906. watchPostEffect(setVars);
  9907. onMounted(() => {
  9908. const ob = new MutationObserver(setVars);
  9909. ob.observe(instance.subTree.el.parentNode, { childList: true });
  9910. onUnmounted(() => ob.disconnect());
  9911. });
  9912. }
  9913. function setVarsOnVNode(vnode, vars) {
  9914. if (vnode.shapeFlag & 128 /* SUSPENSE */) {
  9915. const suspense = vnode.suspense;
  9916. vnode = suspense.activeBranch;
  9917. if (suspense.pendingBranch && !suspense.isHydrating) {
  9918. suspense.effects.push(() => {
  9919. setVarsOnVNode(suspense.activeBranch, vars);
  9920. });
  9921. }
  9922. }
  9923. // drill down HOCs until it's a non-component vnode
  9924. while (vnode.component) {
  9925. vnode = vnode.component.subTree;
  9926. }
  9927. if (vnode.shapeFlag & 1 /* ELEMENT */ && vnode.el) {
  9928. setVarsOnNode(vnode.el, vars);
  9929. }
  9930. else if (vnode.type === Fragment) {
  9931. vnode.children.forEach(c => setVarsOnVNode(c, vars));
  9932. }
  9933. else if (vnode.type === Static) {
  9934. let { el, anchor } = vnode;
  9935. while (el) {
  9936. setVarsOnNode(el, vars);
  9937. if (el === anchor)
  9938. break;
  9939. el = el.nextSibling;
  9940. }
  9941. }
  9942. }
  9943. function setVarsOnNode(el, vars) {
  9944. if (el.nodeType === 1) {
  9945. const style = el.style;
  9946. for (const key in vars) {
  9947. style.setProperty(`--${key}`, vars[key]);
  9948. }
  9949. }
  9950. }
  9951. const TRANSITION = 'transition';
  9952. const ANIMATION = 'animation';
  9953. // DOM Transition is a higher-order-component based on the platform-agnostic
  9954. // base Transition component, with DOM-specific logic.
  9955. const Transition = (props, { slots }) => h(BaseTransition, resolveTransitionProps(props), slots);
  9956. Transition.displayName = 'Transition';
  9957. const DOMTransitionPropsValidators = {
  9958. name: String,
  9959. type: String,
  9960. css: {
  9961. type: Boolean,
  9962. default: true
  9963. },
  9964. duration: [String, Number, Object],
  9965. enterFromClass: String,
  9966. enterActiveClass: String,
  9967. enterToClass: String,
  9968. appearFromClass: String,
  9969. appearActiveClass: String,
  9970. appearToClass: String,
  9971. leaveFromClass: String,
  9972. leaveActiveClass: String,
  9973. leaveToClass: String
  9974. };
  9975. const TransitionPropsValidators = (Transition.props =
  9976. /*#__PURE__*/ extend({}, BaseTransition.props, DOMTransitionPropsValidators));
  9977. /**
  9978. * #3227 Incoming hooks may be merged into arrays when wrapping Transition
  9979. * with custom HOCs.
  9980. */
  9981. const callHook$1 = (hook, args = []) => {
  9982. if (isArray(hook)) {
  9983. hook.forEach(h => h(...args));
  9984. }
  9985. else if (hook) {
  9986. hook(...args);
  9987. }
  9988. };
  9989. /**
  9990. * Check if a hook expects a callback (2nd arg), which means the user
  9991. * intends to explicitly control the end of the transition.
  9992. */
  9993. const hasExplicitCallback = (hook) => {
  9994. return hook
  9995. ? isArray(hook)
  9996. ? hook.some(h => h.length > 1)
  9997. : hook.length > 1
  9998. : false;
  9999. };
  10000. function resolveTransitionProps(rawProps) {
  10001. const baseProps = {};
  10002. for (const key in rawProps) {
  10003. if (!(key in DOMTransitionPropsValidators)) {
  10004. baseProps[key] = rawProps[key];
  10005. }
  10006. }
  10007. if (rawProps.css === false) {
  10008. return baseProps;
  10009. }
  10010. 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;
  10011. const durations = normalizeDuration(duration);
  10012. const enterDuration = durations && durations[0];
  10013. const leaveDuration = durations && durations[1];
  10014. const { onBeforeEnter, onEnter, onEnterCancelled, onLeave, onLeaveCancelled, onBeforeAppear = onBeforeEnter, onAppear = onEnter, onAppearCancelled = onEnterCancelled } = baseProps;
  10015. const finishEnter = (el, isAppear, done) => {
  10016. removeTransitionClass(el, isAppear ? appearToClass : enterToClass);
  10017. removeTransitionClass(el, isAppear ? appearActiveClass : enterActiveClass);
  10018. done && done();
  10019. };
  10020. const finishLeave = (el, done) => {
  10021. el._isLeaving = false;
  10022. removeTransitionClass(el, leaveFromClass);
  10023. removeTransitionClass(el, leaveToClass);
  10024. removeTransitionClass(el, leaveActiveClass);
  10025. done && done();
  10026. };
  10027. const makeEnterHook = (isAppear) => {
  10028. return (el, done) => {
  10029. const hook = isAppear ? onAppear : onEnter;
  10030. const resolve = () => finishEnter(el, isAppear, done);
  10031. callHook$1(hook, [el, resolve]);
  10032. nextFrame(() => {
  10033. removeTransitionClass(el, isAppear ? appearFromClass : enterFromClass);
  10034. addTransitionClass(el, isAppear ? appearToClass : enterToClass);
  10035. if (!hasExplicitCallback(hook)) {
  10036. whenTransitionEnds(el, type, enterDuration, resolve);
  10037. }
  10038. });
  10039. };
  10040. };
  10041. return extend(baseProps, {
  10042. onBeforeEnter(el) {
  10043. callHook$1(onBeforeEnter, [el]);
  10044. addTransitionClass(el, enterFromClass);
  10045. addTransitionClass(el, enterActiveClass);
  10046. },
  10047. onBeforeAppear(el) {
  10048. callHook$1(onBeforeAppear, [el]);
  10049. addTransitionClass(el, appearFromClass);
  10050. addTransitionClass(el, appearActiveClass);
  10051. },
  10052. onEnter: makeEnterHook(false),
  10053. onAppear: makeEnterHook(true),
  10054. onLeave(el, done) {
  10055. el._isLeaving = true;
  10056. const resolve = () => finishLeave(el, done);
  10057. addTransitionClass(el, leaveFromClass);
  10058. // force reflow so *-leave-from classes immediately take effect (#2593)
  10059. forceReflow();
  10060. addTransitionClass(el, leaveActiveClass);
  10061. nextFrame(() => {
  10062. if (!el._isLeaving) {
  10063. // cancelled
  10064. return;
  10065. }
  10066. removeTransitionClass(el, leaveFromClass);
  10067. addTransitionClass(el, leaveToClass);
  10068. if (!hasExplicitCallback(onLeave)) {
  10069. whenTransitionEnds(el, type, leaveDuration, resolve);
  10070. }
  10071. });
  10072. callHook$1(onLeave, [el, resolve]);
  10073. },
  10074. onEnterCancelled(el) {
  10075. finishEnter(el, false);
  10076. callHook$1(onEnterCancelled, [el]);
  10077. },
  10078. onAppearCancelled(el) {
  10079. finishEnter(el, true);
  10080. callHook$1(onAppearCancelled, [el]);
  10081. },
  10082. onLeaveCancelled(el) {
  10083. finishLeave(el);
  10084. callHook$1(onLeaveCancelled, [el]);
  10085. }
  10086. });
  10087. }
  10088. function normalizeDuration(duration) {
  10089. if (duration == null) {
  10090. return null;
  10091. }
  10092. else if (isObject(duration)) {
  10093. return [NumberOf(duration.enter), NumberOf(duration.leave)];
  10094. }
  10095. else {
  10096. const n = NumberOf(duration);
  10097. return [n, n];
  10098. }
  10099. }
  10100. function NumberOf(val) {
  10101. const res = toNumber(val);
  10102. validateDuration(res);
  10103. return res;
  10104. }
  10105. function validateDuration(val) {
  10106. if (typeof val !== 'number') {
  10107. warn$1(`<transition> explicit duration is not a valid number - ` +
  10108. `got ${JSON.stringify(val)}.`);
  10109. }
  10110. else if (isNaN(val)) {
  10111. warn$1(`<transition> explicit duration is NaN - ` +
  10112. 'the duration expression might be incorrect.');
  10113. }
  10114. }
  10115. function addTransitionClass(el, cls) {
  10116. cls.split(/\s+/).forEach(c => c && el.classList.add(c));
  10117. (el._vtc ||
  10118. (el._vtc = new Set())).add(cls);
  10119. }
  10120. function removeTransitionClass(el, cls) {
  10121. cls.split(/\s+/).forEach(c => c && el.classList.remove(c));
  10122. const { _vtc } = el;
  10123. if (_vtc) {
  10124. _vtc.delete(cls);
  10125. if (!_vtc.size) {
  10126. el._vtc = undefined;
  10127. }
  10128. }
  10129. }
  10130. function nextFrame(cb) {
  10131. requestAnimationFrame(() => {
  10132. requestAnimationFrame(cb);
  10133. });
  10134. }
  10135. let endId = 0;
  10136. function whenTransitionEnds(el, expectedType, explicitTimeout, resolve) {
  10137. const id = (el._endId = ++endId);
  10138. const resolveIfNotStale = () => {
  10139. if (id === el._endId) {
  10140. resolve();
  10141. }
  10142. };
  10143. if (explicitTimeout) {
  10144. return setTimeout(resolveIfNotStale, explicitTimeout);
  10145. }
  10146. const { type, timeout, propCount } = getTransitionInfo(el, expectedType);
  10147. if (!type) {
  10148. return resolve();
  10149. }
  10150. const endEvent = type + 'end';
  10151. let ended = 0;
  10152. const end = () => {
  10153. el.removeEventListener(endEvent, onEnd);
  10154. resolveIfNotStale();
  10155. };
  10156. const onEnd = (e) => {
  10157. if (e.target === el && ++ended >= propCount) {
  10158. end();
  10159. }
  10160. };
  10161. setTimeout(() => {
  10162. if (ended < propCount) {
  10163. end();
  10164. }
  10165. }, timeout + 1);
  10166. el.addEventListener(endEvent, onEnd);
  10167. }
  10168. function getTransitionInfo(el, expectedType) {
  10169. const styles = window.getComputedStyle(el);
  10170. // JSDOM may return undefined for transition properties
  10171. const getStyleProperties = (key) => (styles[key] || '').split(', ');
  10172. const transitionDelays = getStyleProperties(TRANSITION + 'Delay');
  10173. const transitionDurations = getStyleProperties(TRANSITION + 'Duration');
  10174. const transitionTimeout = getTimeout(transitionDelays, transitionDurations);
  10175. const animationDelays = getStyleProperties(ANIMATION + 'Delay');
  10176. const animationDurations = getStyleProperties(ANIMATION + 'Duration');
  10177. const animationTimeout = getTimeout(animationDelays, animationDurations);
  10178. let type = null;
  10179. let timeout = 0;
  10180. let propCount = 0;
  10181. /* istanbul ignore if */
  10182. if (expectedType === TRANSITION) {
  10183. if (transitionTimeout > 0) {
  10184. type = TRANSITION;
  10185. timeout = transitionTimeout;
  10186. propCount = transitionDurations.length;
  10187. }
  10188. }
  10189. else if (expectedType === ANIMATION) {
  10190. if (animationTimeout > 0) {
  10191. type = ANIMATION;
  10192. timeout = animationTimeout;
  10193. propCount = animationDurations.length;
  10194. }
  10195. }
  10196. else {
  10197. timeout = Math.max(transitionTimeout, animationTimeout);
  10198. type =
  10199. timeout > 0
  10200. ? transitionTimeout > animationTimeout
  10201. ? TRANSITION
  10202. : ANIMATION
  10203. : null;
  10204. propCount = type
  10205. ? type === TRANSITION
  10206. ? transitionDurations.length
  10207. : animationDurations.length
  10208. : 0;
  10209. }
  10210. const hasTransform = type === TRANSITION &&
  10211. /\b(transform|all)(,|$)/.test(styles[TRANSITION + 'Property']);
  10212. return {
  10213. type,
  10214. timeout,
  10215. propCount,
  10216. hasTransform
  10217. };
  10218. }
  10219. function getTimeout(delays, durations) {
  10220. while (delays.length < durations.length) {
  10221. delays = delays.concat(delays);
  10222. }
  10223. return Math.max(...durations.map((d, i) => toMs(d) + toMs(delays[i])));
  10224. }
  10225. // Old versions of Chromium (below 61.0.3163.100) formats floating pointer
  10226. // numbers in a locale-dependent way, using a comma instead of a dot.
  10227. // If comma is not replaced with a dot, the input will be rounded down
  10228. // (i.e. acting as a floor function) causing unexpected behaviors
  10229. function toMs(s) {
  10230. return Number(s.slice(0, -1).replace(',', '.')) * 1000;
  10231. }
  10232. // synchronously force layout to put elements into a certain state
  10233. function forceReflow() {
  10234. return document.body.offsetHeight;
  10235. }
  10236. const positionMap = new WeakMap();
  10237. const newPositionMap = new WeakMap();
  10238. const TransitionGroupImpl = {
  10239. name: 'TransitionGroup',
  10240. props: /*#__PURE__*/ extend({}, TransitionPropsValidators, {
  10241. tag: String,
  10242. moveClass: String
  10243. }),
  10244. setup(props, { slots }) {
  10245. const instance = getCurrentInstance();
  10246. const state = useTransitionState();
  10247. let prevChildren;
  10248. let children;
  10249. onUpdated(() => {
  10250. // children is guaranteed to exist after initial render
  10251. if (!prevChildren.length) {
  10252. return;
  10253. }
  10254. const moveClass = props.moveClass || `${props.name || 'v'}-move`;
  10255. if (!hasCSSTransform(prevChildren[0].el, instance.vnode.el, moveClass)) {
  10256. return;
  10257. }
  10258. // we divide the work into three loops to avoid mixing DOM reads and writes
  10259. // in each iteration - which helps prevent layout thrashing.
  10260. prevChildren.forEach(callPendingCbs);
  10261. prevChildren.forEach(recordPosition);
  10262. const movedChildren = prevChildren.filter(applyTranslation);
  10263. // force reflow to put everything in position
  10264. forceReflow();
  10265. movedChildren.forEach(c => {
  10266. const el = c.el;
  10267. const style = el.style;
  10268. addTransitionClass(el, moveClass);
  10269. style.transform = style.webkitTransform = style.transitionDuration = '';
  10270. const cb = (el._moveCb = (e) => {
  10271. if (e && e.target !== el) {
  10272. return;
  10273. }
  10274. if (!e || /transform$/.test(e.propertyName)) {
  10275. el.removeEventListener('transitionend', cb);
  10276. el._moveCb = null;
  10277. removeTransitionClass(el, moveClass);
  10278. }
  10279. });
  10280. el.addEventListener('transitionend', cb);
  10281. });
  10282. });
  10283. return () => {
  10284. const rawProps = toRaw(props);
  10285. const cssTransitionProps = resolveTransitionProps(rawProps);
  10286. let tag = rawProps.tag || Fragment;
  10287. prevChildren = children;
  10288. children = slots.default ? getTransitionRawChildren(slots.default()) : [];
  10289. for (let i = 0; i < children.length; i++) {
  10290. const child = children[i];
  10291. if (child.key != null) {
  10292. setTransitionHooks(child, resolveTransitionHooks(child, cssTransitionProps, state, instance));
  10293. }
  10294. else {
  10295. warn$1(`<TransitionGroup> children must be keyed.`);
  10296. }
  10297. }
  10298. if (prevChildren) {
  10299. for (let i = 0; i < prevChildren.length; i++) {
  10300. const child = prevChildren[i];
  10301. setTransitionHooks(child, resolveTransitionHooks(child, cssTransitionProps, state, instance));
  10302. positionMap.set(child, child.el.getBoundingClientRect());
  10303. }
  10304. }
  10305. return createVNode(tag, null, children);
  10306. };
  10307. }
  10308. };
  10309. const TransitionGroup = TransitionGroupImpl;
  10310. function callPendingCbs(c) {
  10311. const el = c.el;
  10312. if (el._moveCb) {
  10313. el._moveCb();
  10314. }
  10315. if (el._enterCb) {
  10316. el._enterCb();
  10317. }
  10318. }
  10319. function recordPosition(c) {
  10320. newPositionMap.set(c, c.el.getBoundingClientRect());
  10321. }
  10322. function applyTranslation(c) {
  10323. const oldPos = positionMap.get(c);
  10324. const newPos = newPositionMap.get(c);
  10325. const dx = oldPos.left - newPos.left;
  10326. const dy = oldPos.top - newPos.top;
  10327. if (dx || dy) {
  10328. const s = c.el.style;
  10329. s.transform = s.webkitTransform = `translate(${dx}px,${dy}px)`;
  10330. s.transitionDuration = '0s';
  10331. return c;
  10332. }
  10333. }
  10334. function hasCSSTransform(el, root, moveClass) {
  10335. // Detect whether an element with the move class applied has
  10336. // CSS transitions. Since the element may be inside an entering
  10337. // transition at this very moment, we make a clone of it and remove
  10338. // all other transition classes applied to ensure only the move class
  10339. // is applied.
  10340. const clone = el.cloneNode();
  10341. if (el._vtc) {
  10342. el._vtc.forEach(cls => {
  10343. cls.split(/\s+/).forEach(c => c && clone.classList.remove(c));
  10344. });
  10345. }
  10346. moveClass.split(/\s+/).forEach(c => c && clone.classList.add(c));
  10347. clone.style.display = 'none';
  10348. const container = (root.nodeType === 1 ? root : root.parentNode);
  10349. container.appendChild(clone);
  10350. const { hasTransform } = getTransitionInfo(clone);
  10351. container.removeChild(clone);
  10352. return hasTransform;
  10353. }
  10354. const getModelAssigner = (vnode) => {
  10355. const fn = vnode.props['onUpdate:modelValue'] ||
  10356. (false );
  10357. return isArray(fn) ? value => invokeArrayFns(fn, value) : fn;
  10358. };
  10359. function onCompositionStart(e) {
  10360. e.target.composing = true;
  10361. }
  10362. function onCompositionEnd(e) {
  10363. const target = e.target;
  10364. if (target.composing) {
  10365. target.composing = false;
  10366. target.dispatchEvent(new Event('input'));
  10367. }
  10368. }
  10369. // We are exporting the v-model runtime directly as vnode hooks so that it can
  10370. // be tree-shaken in case v-model is never used.
  10371. const vModelText = {
  10372. created(el, { modifiers: { lazy, trim, number } }, vnode) {
  10373. el._assign = getModelAssigner(vnode);
  10374. const castToNumber = number || (vnode.props && vnode.props.type === 'number');
  10375. addEventListener(el, lazy ? 'change' : 'input', e => {
  10376. if (e.target.composing)
  10377. return;
  10378. let domValue = el.value;
  10379. if (trim) {
  10380. domValue = domValue.trim();
  10381. }
  10382. if (castToNumber) {
  10383. domValue = toNumber(domValue);
  10384. }
  10385. el._assign(domValue);
  10386. });
  10387. if (trim) {
  10388. addEventListener(el, 'change', () => {
  10389. el.value = el.value.trim();
  10390. });
  10391. }
  10392. if (!lazy) {
  10393. addEventListener(el, 'compositionstart', onCompositionStart);
  10394. addEventListener(el, 'compositionend', onCompositionEnd);
  10395. // Safari < 10.2 & UIWebView doesn't fire compositionend when
  10396. // switching focus before confirming composition choice
  10397. // this also fixes the issue where some browsers e.g. iOS Chrome
  10398. // fires "change" instead of "input" on autocomplete.
  10399. addEventListener(el, 'change', onCompositionEnd);
  10400. }
  10401. },
  10402. // set value on mounted so it's after min/max for type="range"
  10403. mounted(el, { value }) {
  10404. el.value = value == null ? '' : value;
  10405. },
  10406. beforeUpdate(el, { value, modifiers: { lazy, trim, number } }, vnode) {
  10407. el._assign = getModelAssigner(vnode);
  10408. // avoid clearing unresolved text. #2302
  10409. if (el.composing)
  10410. return;
  10411. if (document.activeElement === el && el.type !== 'range') {
  10412. if (lazy) {
  10413. return;
  10414. }
  10415. if (trim && el.value.trim() === value) {
  10416. return;
  10417. }
  10418. if ((number || el.type === 'number') && toNumber(el.value) === value) {
  10419. return;
  10420. }
  10421. }
  10422. const newValue = value == null ? '' : value;
  10423. if (el.value !== newValue) {
  10424. el.value = newValue;
  10425. }
  10426. }
  10427. };
  10428. const vModelCheckbox = {
  10429. // #4096 array checkboxes need to be deep traversed
  10430. deep: true,
  10431. created(el, _, vnode) {
  10432. el._assign = getModelAssigner(vnode);
  10433. addEventListener(el, 'change', () => {
  10434. const modelValue = el._modelValue;
  10435. const elementValue = getValue(el);
  10436. const checked = el.checked;
  10437. const assign = el._assign;
  10438. if (isArray(modelValue)) {
  10439. const index = looseIndexOf(modelValue, elementValue);
  10440. const found = index !== -1;
  10441. if (checked && !found) {
  10442. assign(modelValue.concat(elementValue));
  10443. }
  10444. else if (!checked && found) {
  10445. const filtered = [...modelValue];
  10446. filtered.splice(index, 1);
  10447. assign(filtered);
  10448. }
  10449. }
  10450. else if (isSet(modelValue)) {
  10451. const cloned = new Set(modelValue);
  10452. if (checked) {
  10453. cloned.add(elementValue);
  10454. }
  10455. else {
  10456. cloned.delete(elementValue);
  10457. }
  10458. assign(cloned);
  10459. }
  10460. else {
  10461. assign(getCheckboxValue(el, checked));
  10462. }
  10463. });
  10464. },
  10465. // set initial checked on mount to wait for true-value/false-value
  10466. mounted: setChecked,
  10467. beforeUpdate(el, binding, vnode) {
  10468. el._assign = getModelAssigner(vnode);
  10469. setChecked(el, binding, vnode);
  10470. }
  10471. };
  10472. function setChecked(el, { value, oldValue }, vnode) {
  10473. el._modelValue = value;
  10474. if (isArray(value)) {
  10475. el.checked = looseIndexOf(value, vnode.props.value) > -1;
  10476. }
  10477. else if (isSet(value)) {
  10478. el.checked = value.has(vnode.props.value);
  10479. }
  10480. else if (value !== oldValue) {
  10481. el.checked = looseEqual(value, getCheckboxValue(el, true));
  10482. }
  10483. }
  10484. const vModelRadio = {
  10485. created(el, { value }, vnode) {
  10486. el.checked = looseEqual(value, vnode.props.value);
  10487. el._assign = getModelAssigner(vnode);
  10488. addEventListener(el, 'change', () => {
  10489. el._assign(getValue(el));
  10490. });
  10491. },
  10492. beforeUpdate(el, { value, oldValue }, vnode) {
  10493. el._assign = getModelAssigner(vnode);
  10494. if (value !== oldValue) {
  10495. el.checked = looseEqual(value, vnode.props.value);
  10496. }
  10497. }
  10498. };
  10499. const vModelSelect = {
  10500. // <select multiple> value need to be deep traversed
  10501. deep: true,
  10502. created(el, { value, modifiers: { number } }, vnode) {
  10503. const isSetModel = isSet(value);
  10504. addEventListener(el, 'change', () => {
  10505. const selectedVal = Array.prototype.filter
  10506. .call(el.options, (o) => o.selected)
  10507. .map((o) => number ? toNumber(getValue(o)) : getValue(o));
  10508. el._assign(el.multiple
  10509. ? isSetModel
  10510. ? new Set(selectedVal)
  10511. : selectedVal
  10512. : selectedVal[0]);
  10513. });
  10514. el._assign = getModelAssigner(vnode);
  10515. },
  10516. // set value in mounted & updated because <select> relies on its children
  10517. // <option>s.
  10518. mounted(el, { value }) {
  10519. setSelected(el, value);
  10520. },
  10521. beforeUpdate(el, _binding, vnode) {
  10522. el._assign = getModelAssigner(vnode);
  10523. },
  10524. updated(el, { value }) {
  10525. setSelected(el, value);
  10526. }
  10527. };
  10528. function setSelected(el, value) {
  10529. const isMultiple = el.multiple;
  10530. if (isMultiple && !isArray(value) && !isSet(value)) {
  10531. warn$1(`<select multiple v-model> expects an Array or Set value for its binding, ` +
  10532. `but got ${Object.prototype.toString.call(value).slice(8, -1)}.`);
  10533. return;
  10534. }
  10535. for (let i = 0, l = el.options.length; i < l; i++) {
  10536. const option = el.options[i];
  10537. const optionValue = getValue(option);
  10538. if (isMultiple) {
  10539. if (isArray(value)) {
  10540. option.selected = looseIndexOf(value, optionValue) > -1;
  10541. }
  10542. else {
  10543. option.selected = value.has(optionValue);
  10544. }
  10545. }
  10546. else {
  10547. if (looseEqual(getValue(option), value)) {
  10548. if (el.selectedIndex !== i)
  10549. el.selectedIndex = i;
  10550. return;
  10551. }
  10552. }
  10553. }
  10554. if (!isMultiple && el.selectedIndex !== -1) {
  10555. el.selectedIndex = -1;
  10556. }
  10557. }
  10558. // retrieve raw value set via :value bindings
  10559. function getValue(el) {
  10560. return '_value' in el ? el._value : el.value;
  10561. }
  10562. // retrieve raw value for true-value and false-value set via :true-value or :false-value bindings
  10563. function getCheckboxValue(el, checked) {
  10564. const key = checked ? '_trueValue' : '_falseValue';
  10565. return key in el ? el[key] : checked;
  10566. }
  10567. const vModelDynamic = {
  10568. created(el, binding, vnode) {
  10569. callModelHook(el, binding, vnode, null, 'created');
  10570. },
  10571. mounted(el, binding, vnode) {
  10572. callModelHook(el, binding, vnode, null, 'mounted');
  10573. },
  10574. beforeUpdate(el, binding, vnode, prevVNode) {
  10575. callModelHook(el, binding, vnode, prevVNode, 'beforeUpdate');
  10576. },
  10577. updated(el, binding, vnode, prevVNode) {
  10578. callModelHook(el, binding, vnode, prevVNode, 'updated');
  10579. }
  10580. };
  10581. function resolveDynamicModel(tagName, type) {
  10582. switch (tagName) {
  10583. case 'SELECT':
  10584. return vModelSelect;
  10585. case 'TEXTAREA':
  10586. return vModelText;
  10587. default:
  10588. switch (type) {
  10589. case 'checkbox':
  10590. return vModelCheckbox;
  10591. case 'radio':
  10592. return vModelRadio;
  10593. default:
  10594. return vModelText;
  10595. }
  10596. }
  10597. }
  10598. function callModelHook(el, binding, vnode, prevVNode, hook) {
  10599. const modelToUse = resolveDynamicModel(el.tagName, vnode.props && vnode.props.type);
  10600. const fn = modelToUse[hook];
  10601. fn && fn(el, binding, vnode, prevVNode);
  10602. }
  10603. const systemModifiers = ['ctrl', 'shift', 'alt', 'meta'];
  10604. const modifierGuards = {
  10605. stop: e => e.stopPropagation(),
  10606. prevent: e => e.preventDefault(),
  10607. self: e => e.target !== e.currentTarget,
  10608. ctrl: e => !e.ctrlKey,
  10609. shift: e => !e.shiftKey,
  10610. alt: e => !e.altKey,
  10611. meta: e => !e.metaKey,
  10612. left: e => 'button' in e && e.button !== 0,
  10613. middle: e => 'button' in e && e.button !== 1,
  10614. right: e => 'button' in e && e.button !== 2,
  10615. exact: (e, modifiers) => systemModifiers.some(m => e[`${m}Key`] && !modifiers.includes(m))
  10616. };
  10617. /**
  10618. * @private
  10619. */
  10620. const withModifiers = (fn, modifiers) => {
  10621. return (event, ...args) => {
  10622. for (let i = 0; i < modifiers.length; i++) {
  10623. const guard = modifierGuards[modifiers[i]];
  10624. if (guard && guard(event, modifiers))
  10625. return;
  10626. }
  10627. return fn(event, ...args);
  10628. };
  10629. };
  10630. // Kept for 2.x compat.
  10631. // Note: IE11 compat for `spacebar` and `del` is removed for now.
  10632. const keyNames = {
  10633. esc: 'escape',
  10634. space: ' ',
  10635. up: 'arrow-up',
  10636. left: 'arrow-left',
  10637. right: 'arrow-right',
  10638. down: 'arrow-down',
  10639. delete: 'backspace'
  10640. };
  10641. /**
  10642. * @private
  10643. */
  10644. const withKeys = (fn, modifiers) => {
  10645. return (event) => {
  10646. if (!('key' in event)) {
  10647. return;
  10648. }
  10649. const eventKey = hyphenate(event.key);
  10650. if (modifiers.some(k => k === eventKey || keyNames[k] === eventKey)) {
  10651. return fn(event);
  10652. }
  10653. };
  10654. };
  10655. const vShow = {
  10656. beforeMount(el, { value }, { transition }) {
  10657. el._vod = el.style.display === 'none' ? '' : el.style.display;
  10658. if (transition && value) {
  10659. transition.beforeEnter(el);
  10660. }
  10661. else {
  10662. setDisplay(el, value);
  10663. }
  10664. },
  10665. mounted(el, { value }, { transition }) {
  10666. if (transition && value) {
  10667. transition.enter(el);
  10668. }
  10669. },
  10670. updated(el, { value, oldValue }, { transition }) {
  10671. if (!value === !oldValue)
  10672. return;
  10673. if (transition) {
  10674. if (value) {
  10675. transition.beforeEnter(el);
  10676. setDisplay(el, true);
  10677. transition.enter(el);
  10678. }
  10679. else {
  10680. transition.leave(el, () => {
  10681. setDisplay(el, false);
  10682. });
  10683. }
  10684. }
  10685. else {
  10686. setDisplay(el, value);
  10687. }
  10688. },
  10689. beforeUnmount(el, { value }) {
  10690. setDisplay(el, value);
  10691. }
  10692. };
  10693. function setDisplay(el, value) {
  10694. el.style.display = value ? el._vod : 'none';
  10695. }
  10696. const rendererOptions = /*#__PURE__*/ extend({ patchProp }, nodeOps);
  10697. // lazy create the renderer - this makes core renderer logic tree-shakable
  10698. // in case the user only imports reactivity utilities from Vue.
  10699. let renderer;
  10700. let enabledHydration = false;
  10701. function ensureRenderer() {
  10702. return (renderer ||
  10703. (renderer = createRenderer(rendererOptions)));
  10704. }
  10705. function ensureHydrationRenderer() {
  10706. renderer = enabledHydration
  10707. ? renderer
  10708. : createHydrationRenderer(rendererOptions);
  10709. enabledHydration = true;
  10710. return renderer;
  10711. }
  10712. // use explicit type casts here to avoid import() calls in rolled-up d.ts
  10713. const render = ((...args) => {
  10714. ensureRenderer().render(...args);
  10715. });
  10716. const hydrate = ((...args) => {
  10717. ensureHydrationRenderer().hydrate(...args);
  10718. });
  10719. const createApp = ((...args) => {
  10720. const app = ensureRenderer().createApp(...args);
  10721. {
  10722. injectNativeTagCheck(app);
  10723. injectCompilerOptionsCheck(app);
  10724. }
  10725. const { mount } = app;
  10726. app.mount = (containerOrSelector) => {
  10727. const container = normalizeContainer(containerOrSelector);
  10728. if (!container)
  10729. return;
  10730. const component = app._component;
  10731. if (!isFunction(component) && !component.render && !component.template) {
  10732. // __UNSAFE__
  10733. // Reason: potential execution of JS expressions in in-DOM template.
  10734. // The user must make sure the in-DOM template is trusted. If it's
  10735. // rendered by the server, the template should not contain any user data.
  10736. component.template = container.innerHTML;
  10737. }
  10738. // clear content before mounting
  10739. container.innerHTML = '';
  10740. const proxy = mount(container, false, container instanceof SVGElement);
  10741. if (container instanceof Element) {
  10742. container.removeAttribute('v-cloak');
  10743. container.setAttribute('data-v-app', '');
  10744. }
  10745. return proxy;
  10746. };
  10747. return app;
  10748. });
  10749. const createSSRApp = ((...args) => {
  10750. const app = ensureHydrationRenderer().createApp(...args);
  10751. {
  10752. injectNativeTagCheck(app);
  10753. injectCompilerOptionsCheck(app);
  10754. }
  10755. const { mount } = app;
  10756. app.mount = (containerOrSelector) => {
  10757. const container = normalizeContainer(containerOrSelector);
  10758. if (container) {
  10759. return mount(container, true, container instanceof SVGElement);
  10760. }
  10761. };
  10762. return app;
  10763. });
  10764. function injectNativeTagCheck(app) {
  10765. // Inject `isNativeTag`
  10766. // this is used for component name validation (dev only)
  10767. Object.defineProperty(app.config, 'isNativeTag', {
  10768. value: (tag) => isHTMLTag(tag) || isSVGTag(tag),
  10769. writable: false
  10770. });
  10771. }
  10772. // dev only
  10773. function injectCompilerOptionsCheck(app) {
  10774. if (isRuntimeOnly()) {
  10775. const isCustomElement = app.config.isCustomElement;
  10776. Object.defineProperty(app.config, 'isCustomElement', {
  10777. get() {
  10778. return isCustomElement;
  10779. },
  10780. set() {
  10781. warn$1(`The \`isCustomElement\` config option is deprecated. Use ` +
  10782. `\`compilerOptions.isCustomElement\` instead.`);
  10783. }
  10784. });
  10785. const compilerOptions = app.config.compilerOptions;
  10786. const msg = `The \`compilerOptions\` config option is only respected when using ` +
  10787. `a build of Vue.js that includes the runtime compiler (aka "full build"). ` +
  10788. `Since you are using the runtime-only build, \`compilerOptions\` ` +
  10789. `must be passed to \`@vue/compiler-dom\` in the build setup instead.\n` +
  10790. `- For vue-loader: pass it via vue-loader's \`compilerOptions\` loader option.\n` +
  10791. `- For vue-cli: see https://cli.vuejs.org/guide/webpack.html#modifying-options-of-a-loader\n` +
  10792. `- 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`;
  10793. Object.defineProperty(app.config, 'compilerOptions', {
  10794. get() {
  10795. warn$1(msg);
  10796. return compilerOptions;
  10797. },
  10798. set() {
  10799. warn$1(msg);
  10800. }
  10801. });
  10802. }
  10803. }
  10804. function normalizeContainer(container) {
  10805. if (isString(container)) {
  10806. const res = document.querySelector(container);
  10807. if (!res) {
  10808. warn$1(`Failed to mount app: mount target selector "${container}" returned null.`);
  10809. }
  10810. return res;
  10811. }
  10812. if (window.ShadowRoot &&
  10813. container instanceof window.ShadowRoot &&
  10814. container.mode === 'closed') {
  10815. warn$1(`mounting on a ShadowRoot with \`{mode: "closed"}\` may lead to unpredictable bugs`);
  10816. }
  10817. return container;
  10818. }
  10819. /**
  10820. * @internal
  10821. */
  10822. const initDirectivesForSSR = NOOP;
  10823. function initDev() {
  10824. {
  10825. {
  10826. console.info(`You are running a development build of Vue.\n` +
  10827. `Make sure to use the production build (*.prod.js) when deploying for production.`);
  10828. }
  10829. initCustomFormatter();
  10830. }
  10831. }
  10832. function defaultOnError(error) {
  10833. throw error;
  10834. }
  10835. function defaultOnWarn(msg) {
  10836. console.warn(`[Vue warn] ${msg.message}`);
  10837. }
  10838. function createCompilerError(code, loc, messages, additionalMessage) {
  10839. const msg = (messages || errorMessages)[code] + (additionalMessage || ``)
  10840. ;
  10841. const error = new SyntaxError(String(msg));
  10842. error.code = code;
  10843. error.loc = loc;
  10844. return error;
  10845. }
  10846. const errorMessages = {
  10847. // parse errors
  10848. [0 /* ABRUPT_CLOSING_OF_EMPTY_COMMENT */]: 'Illegal comment.',
  10849. [1 /* CDATA_IN_HTML_CONTENT */]: 'CDATA section is allowed only in XML context.',
  10850. [2 /* DUPLICATE_ATTRIBUTE */]: 'Duplicate attribute.',
  10851. [3 /* END_TAG_WITH_ATTRIBUTES */]: 'End tag cannot have attributes.',
  10852. [4 /* END_TAG_WITH_TRAILING_SOLIDUS */]: "Illegal '/' in tags.",
  10853. [5 /* EOF_BEFORE_TAG_NAME */]: 'Unexpected EOF in tag.',
  10854. [6 /* EOF_IN_CDATA */]: 'Unexpected EOF in CDATA section.',
  10855. [7 /* EOF_IN_COMMENT */]: 'Unexpected EOF in comment.',
  10856. [8 /* EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT */]: 'Unexpected EOF in script.',
  10857. [9 /* EOF_IN_TAG */]: 'Unexpected EOF in tag.',
  10858. [10 /* INCORRECTLY_CLOSED_COMMENT */]: 'Incorrectly closed comment.',
  10859. [11 /* INCORRECTLY_OPENED_COMMENT */]: 'Incorrectly opened comment.',
  10860. [12 /* INVALID_FIRST_CHARACTER_OF_TAG_NAME */]: "Illegal tag name. Use '&lt;' to print '<'.",
  10861. [13 /* MISSING_ATTRIBUTE_VALUE */]: 'Attribute value was expected.',
  10862. [14 /* MISSING_END_TAG_NAME */]: 'End tag name was expected.',
  10863. [15 /* MISSING_WHITESPACE_BETWEEN_ATTRIBUTES */]: 'Whitespace was expected.',
  10864. [16 /* NESTED_COMMENT */]: "Unexpected '<!--' in comment.",
  10865. [17 /* UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME */]: 'Attribute name cannot contain U+0022 ("), U+0027 (\'), and U+003C (<).',
  10866. [18 /* UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE */]: 'Unquoted attribute value cannot contain U+0022 ("), U+0027 (\'), U+003C (<), U+003D (=), and U+0060 (`).',
  10867. [19 /* UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME */]: "Attribute name cannot start with '='.",
  10868. [21 /* UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME */]: "'<?' is allowed only in XML context.",
  10869. [20 /* UNEXPECTED_NULL_CHARACTER */]: `Unexpected null character.`,
  10870. [22 /* UNEXPECTED_SOLIDUS_IN_TAG */]: "Illegal '/' in tags.",
  10871. // Vue-specific parse errors
  10872. [23 /* X_INVALID_END_TAG */]: 'Invalid end tag.',
  10873. [24 /* X_MISSING_END_TAG */]: 'Element is missing end tag.',
  10874. [25 /* X_MISSING_INTERPOLATION_END */]: 'Interpolation end sign was not found.',
  10875. [27 /* X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END */]: 'End bracket for dynamic directive argument was not found. ' +
  10876. 'Note that dynamic directive argument cannot contain spaces.',
  10877. [26 /* X_MISSING_DIRECTIVE_NAME */]: 'Legal directive name was expected.',
  10878. // transform errors
  10879. [28 /* X_V_IF_NO_EXPRESSION */]: `v-if/v-else-if is missing expression.`,
  10880. [29 /* X_V_IF_SAME_KEY */]: `v-if/else branches must use unique keys.`,
  10881. [30 /* X_V_ELSE_NO_ADJACENT_IF */]: `v-else/v-else-if has no adjacent v-if or v-else-if.`,
  10882. [31 /* X_V_FOR_NO_EXPRESSION */]: `v-for is missing expression.`,
  10883. [32 /* X_V_FOR_MALFORMED_EXPRESSION */]: `v-for has invalid expression.`,
  10884. [33 /* X_V_FOR_TEMPLATE_KEY_PLACEMENT */]: `<template v-for> key should be placed on the <template> tag.`,
  10885. [34 /* X_V_BIND_NO_EXPRESSION */]: `v-bind is missing expression.`,
  10886. [35 /* X_V_ON_NO_EXPRESSION */]: `v-on is missing expression.`,
  10887. [36 /* X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET */]: `Unexpected custom directive on <slot> outlet.`,
  10888. [37 /* X_V_SLOT_MIXED_SLOT_USAGE */]: `Mixed v-slot usage on both the component and nested <template>.` +
  10889. `When there are multiple named slots, all slots should use <template> ` +
  10890. `syntax to avoid scope ambiguity.`,
  10891. [38 /* X_V_SLOT_DUPLICATE_SLOT_NAMES */]: `Duplicate slot names found. `,
  10892. [39 /* X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN */]: `Extraneous children found when component already has explicitly named ` +
  10893. `default slot. These children will be ignored.`,
  10894. [40 /* X_V_SLOT_MISPLACED */]: `v-slot can only be used on components or <template> tags.`,
  10895. [41 /* X_V_MODEL_NO_EXPRESSION */]: `v-model is missing expression.`,
  10896. [42 /* X_V_MODEL_MALFORMED_EXPRESSION */]: `v-model value must be a valid JavaScript member expression.`,
  10897. [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.`,
  10898. [44 /* X_INVALID_EXPRESSION */]: `Error parsing JavaScript expression: `,
  10899. [45 /* X_KEEP_ALIVE_INVALID_CHILDREN */]: `<KeepAlive> expects exactly one child component.`,
  10900. // generic errors
  10901. [46 /* X_PREFIX_ID_NOT_SUPPORTED */]: `"prefixIdentifiers" option is not supported in this build of compiler.`,
  10902. [47 /* X_MODULE_MODE_NOT_SUPPORTED */]: `ES module mode is not supported in this build of compiler.`,
  10903. [48 /* X_CACHE_HANDLER_NOT_SUPPORTED */]: `"cacheHandlers" option is only supported when the "prefixIdentifiers" option is enabled.`,
  10904. [49 /* X_SCOPE_ID_NOT_SUPPORTED */]: `"scopeId" option is only supported in module mode.`,
  10905. // just to fulfill types
  10906. [50 /* __EXTEND_POINT__ */]: ``
  10907. };
  10908. const FRAGMENT = Symbol(`Fragment` );
  10909. const TELEPORT = Symbol(`Teleport` );
  10910. const SUSPENSE = Symbol(`Suspense` );
  10911. const KEEP_ALIVE = Symbol(`KeepAlive` );
  10912. const BASE_TRANSITION = Symbol(`BaseTransition` );
  10913. const OPEN_BLOCK = Symbol(`openBlock` );
  10914. const CREATE_BLOCK = Symbol(`createBlock` );
  10915. const CREATE_ELEMENT_BLOCK = Symbol(`createElementBlock` );
  10916. const CREATE_VNODE = Symbol(`createVNode` );
  10917. const CREATE_ELEMENT_VNODE = Symbol(`createElementVNode` );
  10918. const CREATE_COMMENT = Symbol(`createCommentVNode` );
  10919. const CREATE_TEXT = Symbol(`createTextVNode` );
  10920. const CREATE_STATIC = Symbol(`createStaticVNode` );
  10921. const RESOLVE_COMPONENT = Symbol(`resolveComponent` );
  10922. const RESOLVE_DYNAMIC_COMPONENT = Symbol(`resolveDynamicComponent` );
  10923. const RESOLVE_DIRECTIVE = Symbol(`resolveDirective` );
  10924. const RESOLVE_FILTER = Symbol(`resolveFilter` );
  10925. const WITH_DIRECTIVES = Symbol(`withDirectives` );
  10926. const RENDER_LIST = Symbol(`renderList` );
  10927. const RENDER_SLOT = Symbol(`renderSlot` );
  10928. const CREATE_SLOTS = Symbol(`createSlots` );
  10929. const TO_DISPLAY_STRING = Symbol(`toDisplayString` );
  10930. const MERGE_PROPS = Symbol(`mergeProps` );
  10931. const NORMALIZE_CLASS = Symbol(`normalizeClass` );
  10932. const NORMALIZE_STYLE = Symbol(`normalizeStyle` );
  10933. const NORMALIZE_PROPS = Symbol(`normalizeProps` );
  10934. const GUARD_REACTIVE_PROPS = Symbol(`guardReactiveProps` );
  10935. const TO_HANDLERS = Symbol(`toHandlers` );
  10936. const CAMELIZE = Symbol(`camelize` );
  10937. const CAPITALIZE = Symbol(`capitalize` );
  10938. const TO_HANDLER_KEY = Symbol(`toHandlerKey` );
  10939. const SET_BLOCK_TRACKING = Symbol(`setBlockTracking` );
  10940. const PUSH_SCOPE_ID = Symbol(`pushScopeId` );
  10941. const POP_SCOPE_ID = Symbol(`popScopeId` );
  10942. const WITH_CTX = Symbol(`withCtx` );
  10943. const UNREF = Symbol(`unref` );
  10944. const IS_REF = Symbol(`isRef` );
  10945. const WITH_MEMO = Symbol(`withMemo` );
  10946. const IS_MEMO_SAME = Symbol(`isMemoSame` );
  10947. // Name mapping for runtime helpers that need to be imported from 'vue' in
  10948. // generated code. Make sure these are correctly exported in the runtime!
  10949. // Using `any` here because TS doesn't allow symbols as index type.
  10950. const helperNameMap = {
  10951. [FRAGMENT]: `Fragment`,
  10952. [TELEPORT]: `Teleport`,
  10953. [SUSPENSE]: `Suspense`,
  10954. [KEEP_ALIVE]: `KeepAlive`,
  10955. [BASE_TRANSITION]: `BaseTransition`,
  10956. [OPEN_BLOCK]: `openBlock`,
  10957. [CREATE_BLOCK]: `createBlock`,
  10958. [CREATE_ELEMENT_BLOCK]: `createElementBlock`,
  10959. [CREATE_VNODE]: `createVNode`,
  10960. [CREATE_ELEMENT_VNODE]: `createElementVNode`,
  10961. [CREATE_COMMENT]: `createCommentVNode`,
  10962. [CREATE_TEXT]: `createTextVNode`,
  10963. [CREATE_STATIC]: `createStaticVNode`,
  10964. [RESOLVE_COMPONENT]: `resolveComponent`,
  10965. [RESOLVE_DYNAMIC_COMPONENT]: `resolveDynamicComponent`,
  10966. [RESOLVE_DIRECTIVE]: `resolveDirective`,
  10967. [RESOLVE_FILTER]: `resolveFilter`,
  10968. [WITH_DIRECTIVES]: `withDirectives`,
  10969. [RENDER_LIST]: `renderList`,
  10970. [RENDER_SLOT]: `renderSlot`,
  10971. [CREATE_SLOTS]: `createSlots`,
  10972. [TO_DISPLAY_STRING]: `toDisplayString`,
  10973. [MERGE_PROPS]: `mergeProps`,
  10974. [NORMALIZE_CLASS]: `normalizeClass`,
  10975. [NORMALIZE_STYLE]: `normalizeStyle`,
  10976. [NORMALIZE_PROPS]: `normalizeProps`,
  10977. [GUARD_REACTIVE_PROPS]: `guardReactiveProps`,
  10978. [TO_HANDLERS]: `toHandlers`,
  10979. [CAMELIZE]: `camelize`,
  10980. [CAPITALIZE]: `capitalize`,
  10981. [TO_HANDLER_KEY]: `toHandlerKey`,
  10982. [SET_BLOCK_TRACKING]: `setBlockTracking`,
  10983. [PUSH_SCOPE_ID]: `pushScopeId`,
  10984. [POP_SCOPE_ID]: `popScopeId`,
  10985. [WITH_CTX]: `withCtx`,
  10986. [UNREF]: `unref`,
  10987. [IS_REF]: `isRef`,
  10988. [WITH_MEMO]: `withMemo`,
  10989. [IS_MEMO_SAME]: `isMemoSame`
  10990. };
  10991. function registerRuntimeHelpers(helpers) {
  10992. Object.getOwnPropertySymbols(helpers).forEach(s => {
  10993. helperNameMap[s] = helpers[s];
  10994. });
  10995. }
  10996. // AST Utilities ---------------------------------------------------------------
  10997. // Some expressions, e.g. sequence and conditional expressions, are never
  10998. // associated with template nodes, so their source locations are just a stub.
  10999. // Container types like CompoundExpression also don't need a real location.
  11000. const locStub = {
  11001. source: '',
  11002. start: { line: 1, column: 1, offset: 0 },
  11003. end: { line: 1, column: 1, offset: 0 }
  11004. };
  11005. function createRoot(children, loc = locStub) {
  11006. return {
  11007. type: 0 /* ROOT */,
  11008. children,
  11009. helpers: [],
  11010. components: [],
  11011. directives: [],
  11012. hoists: [],
  11013. imports: [],
  11014. cached: 0,
  11015. temps: 0,
  11016. codegenNode: undefined,
  11017. loc
  11018. };
  11019. }
  11020. function createVNodeCall(context, tag, props, children, patchFlag, dynamicProps, directives, isBlock = false, disableTracking = false, isComponent = false, loc = locStub) {
  11021. if (context) {
  11022. if (isBlock) {
  11023. context.helper(OPEN_BLOCK);
  11024. context.helper(getVNodeBlockHelper(context.inSSR, isComponent));
  11025. }
  11026. else {
  11027. context.helper(getVNodeHelper(context.inSSR, isComponent));
  11028. }
  11029. if (directives) {
  11030. context.helper(WITH_DIRECTIVES);
  11031. }
  11032. }
  11033. return {
  11034. type: 13 /* VNODE_CALL */,
  11035. tag,
  11036. props,
  11037. children,
  11038. patchFlag,
  11039. dynamicProps,
  11040. directives,
  11041. isBlock,
  11042. disableTracking,
  11043. isComponent,
  11044. loc
  11045. };
  11046. }
  11047. function createArrayExpression(elements, loc = locStub) {
  11048. return {
  11049. type: 17 /* JS_ARRAY_EXPRESSION */,
  11050. loc,
  11051. elements
  11052. };
  11053. }
  11054. function createObjectExpression(properties, loc = locStub) {
  11055. return {
  11056. type: 15 /* JS_OBJECT_EXPRESSION */,
  11057. loc,
  11058. properties
  11059. };
  11060. }
  11061. function createObjectProperty(key, value) {
  11062. return {
  11063. type: 16 /* JS_PROPERTY */,
  11064. loc: locStub,
  11065. key: isString(key) ? createSimpleExpression(key, true) : key,
  11066. value
  11067. };
  11068. }
  11069. function createSimpleExpression(content, isStatic = false, loc = locStub, constType = 0 /* NOT_CONSTANT */) {
  11070. return {
  11071. type: 4 /* SIMPLE_EXPRESSION */,
  11072. loc,
  11073. content,
  11074. isStatic,
  11075. constType: isStatic ? 3 /* CAN_STRINGIFY */ : constType
  11076. };
  11077. }
  11078. function createCompoundExpression(children, loc = locStub) {
  11079. return {
  11080. type: 8 /* COMPOUND_EXPRESSION */,
  11081. loc,
  11082. children
  11083. };
  11084. }
  11085. function createCallExpression(callee, args = [], loc = locStub) {
  11086. return {
  11087. type: 14 /* JS_CALL_EXPRESSION */,
  11088. loc,
  11089. callee,
  11090. arguments: args
  11091. };
  11092. }
  11093. function createFunctionExpression(params, returns = undefined, newline = false, isSlot = false, loc = locStub) {
  11094. return {
  11095. type: 18 /* JS_FUNCTION_EXPRESSION */,
  11096. params,
  11097. returns,
  11098. newline,
  11099. isSlot,
  11100. loc
  11101. };
  11102. }
  11103. function createConditionalExpression(test, consequent, alternate, newline = true) {
  11104. return {
  11105. type: 19 /* JS_CONDITIONAL_EXPRESSION */,
  11106. test,
  11107. consequent,
  11108. alternate,
  11109. newline,
  11110. loc: locStub
  11111. };
  11112. }
  11113. function createCacheExpression(index, value, isVNode = false) {
  11114. return {
  11115. type: 20 /* JS_CACHE_EXPRESSION */,
  11116. index,
  11117. value,
  11118. isVNode,
  11119. loc: locStub
  11120. };
  11121. }
  11122. function createBlockStatement(body) {
  11123. return {
  11124. type: 21 /* JS_BLOCK_STATEMENT */,
  11125. body,
  11126. loc: locStub
  11127. };
  11128. }
  11129. const isStaticExp = (p) => p.type === 4 /* SIMPLE_EXPRESSION */ && p.isStatic;
  11130. const isBuiltInType = (tag, expected) => tag === expected || tag === hyphenate(expected);
  11131. function isCoreComponent(tag) {
  11132. if (isBuiltInType(tag, 'Teleport')) {
  11133. return TELEPORT;
  11134. }
  11135. else if (isBuiltInType(tag, 'Suspense')) {
  11136. return SUSPENSE;
  11137. }
  11138. else if (isBuiltInType(tag, 'KeepAlive')) {
  11139. return KEEP_ALIVE;
  11140. }
  11141. else if (isBuiltInType(tag, 'BaseTransition')) {
  11142. return BASE_TRANSITION;
  11143. }
  11144. }
  11145. const nonIdentifierRE = /^\d|[^\$\w]/;
  11146. const isSimpleIdentifier = (name) => !nonIdentifierRE.test(name);
  11147. const validFirstIdentCharRE = /[A-Za-z_$\xA0-\uFFFF]/;
  11148. const validIdentCharRE = /[\.\?\w$\xA0-\uFFFF]/;
  11149. const whitespaceRE = /\s+[.[]\s*|\s*[.[]\s+/g;
  11150. /**
  11151. * Simple lexer to check if an expression is a member expression. This is
  11152. * lax and only checks validity at the root level (i.e. does not validate exps
  11153. * inside square brackets), but it's ok since these are only used on template
  11154. * expressions and false positives are invalid expressions in the first place.
  11155. */
  11156. const isMemberExpressionBrowser = (path) => {
  11157. // remove whitespaces around . or [ first
  11158. path = path.trim().replace(whitespaceRE, s => s.trim());
  11159. let state = 0 /* inMemberExp */;
  11160. let stateStack = [];
  11161. let currentOpenBracketCount = 0;
  11162. let currentOpenParensCount = 0;
  11163. let currentStringType = null;
  11164. for (let i = 0; i < path.length; i++) {
  11165. const char = path.charAt(i);
  11166. switch (state) {
  11167. case 0 /* inMemberExp */:
  11168. if (char === '[') {
  11169. stateStack.push(state);
  11170. state = 1 /* inBrackets */;
  11171. currentOpenBracketCount++;
  11172. }
  11173. else if (char === '(') {
  11174. stateStack.push(state);
  11175. state = 2 /* inParens */;
  11176. currentOpenParensCount++;
  11177. }
  11178. else if (!(i === 0 ? validFirstIdentCharRE : validIdentCharRE).test(char)) {
  11179. return false;
  11180. }
  11181. break;
  11182. case 1 /* inBrackets */:
  11183. if (char === `'` || char === `"` || char === '`') {
  11184. stateStack.push(state);
  11185. state = 3 /* inString */;
  11186. currentStringType = char;
  11187. }
  11188. else if (char === `[`) {
  11189. currentOpenBracketCount++;
  11190. }
  11191. else if (char === `]`) {
  11192. if (!--currentOpenBracketCount) {
  11193. state = stateStack.pop();
  11194. }
  11195. }
  11196. break;
  11197. case 2 /* inParens */:
  11198. if (char === `'` || char === `"` || char === '`') {
  11199. stateStack.push(state);
  11200. state = 3 /* inString */;
  11201. currentStringType = char;
  11202. }
  11203. else if (char === `(`) {
  11204. currentOpenParensCount++;
  11205. }
  11206. else if (char === `)`) {
  11207. // if the exp ends as a call then it should not be considered valid
  11208. if (i === path.length - 1) {
  11209. return false;
  11210. }
  11211. if (!--currentOpenParensCount) {
  11212. state = stateStack.pop();
  11213. }
  11214. }
  11215. break;
  11216. case 3 /* inString */:
  11217. if (char === currentStringType) {
  11218. state = stateStack.pop();
  11219. currentStringType = null;
  11220. }
  11221. break;
  11222. }
  11223. }
  11224. return !currentOpenBracketCount && !currentOpenParensCount;
  11225. };
  11226. const isMemberExpression = isMemberExpressionBrowser
  11227. ;
  11228. function getInnerRange(loc, offset, length) {
  11229. const source = loc.source.slice(offset, offset + length);
  11230. const newLoc = {
  11231. source,
  11232. start: advancePositionWithClone(loc.start, loc.source, offset),
  11233. end: loc.end
  11234. };
  11235. if (length != null) {
  11236. newLoc.end = advancePositionWithClone(loc.start, loc.source, offset + length);
  11237. }
  11238. return newLoc;
  11239. }
  11240. function advancePositionWithClone(pos, source, numberOfCharacters = source.length) {
  11241. return advancePositionWithMutation(extend({}, pos), source, numberOfCharacters);
  11242. }
  11243. // advance by mutation without cloning (for performance reasons), since this
  11244. // gets called a lot in the parser
  11245. function advancePositionWithMutation(pos, source, numberOfCharacters = source.length) {
  11246. let linesCount = 0;
  11247. let lastNewLinePos = -1;
  11248. for (let i = 0; i < numberOfCharacters; i++) {
  11249. if (source.charCodeAt(i) === 10 /* newline char code */) {
  11250. linesCount++;
  11251. lastNewLinePos = i;
  11252. }
  11253. }
  11254. pos.offset += numberOfCharacters;
  11255. pos.line += linesCount;
  11256. pos.column =
  11257. lastNewLinePos === -1
  11258. ? pos.column + numberOfCharacters
  11259. : numberOfCharacters - lastNewLinePos;
  11260. return pos;
  11261. }
  11262. function assert(condition, msg) {
  11263. /* istanbul ignore if */
  11264. if (!condition) {
  11265. throw new Error(msg || `unexpected compiler condition`);
  11266. }
  11267. }
  11268. function findDir(node, name, allowEmpty = false) {
  11269. for (let i = 0; i < node.props.length; i++) {
  11270. const p = node.props[i];
  11271. if (p.type === 7 /* DIRECTIVE */ &&
  11272. (allowEmpty || p.exp) &&
  11273. (isString(name) ? p.name === name : name.test(p.name))) {
  11274. return p;
  11275. }
  11276. }
  11277. }
  11278. function findProp(node, name, dynamicOnly = false, allowEmpty = false) {
  11279. for (let i = 0; i < node.props.length; i++) {
  11280. const p = node.props[i];
  11281. if (p.type === 6 /* ATTRIBUTE */) {
  11282. if (dynamicOnly)
  11283. continue;
  11284. if (p.name === name && (p.value || allowEmpty)) {
  11285. return p;
  11286. }
  11287. }
  11288. else if (p.name === 'bind' &&
  11289. (p.exp || allowEmpty) &&
  11290. isStaticArgOf(p.arg, name)) {
  11291. return p;
  11292. }
  11293. }
  11294. }
  11295. function isStaticArgOf(arg, name) {
  11296. return !!(arg && isStaticExp(arg) && arg.content === name);
  11297. }
  11298. function hasDynamicKeyVBind(node) {
  11299. return node.props.some(p => p.type === 7 /* DIRECTIVE */ &&
  11300. p.name === 'bind' &&
  11301. (!p.arg || // v-bind="obj"
  11302. p.arg.type !== 4 /* SIMPLE_EXPRESSION */ || // v-bind:[_ctx.foo]
  11303. !p.arg.isStatic) // v-bind:[foo]
  11304. );
  11305. }
  11306. function isText(node) {
  11307. return node.type === 5 /* INTERPOLATION */ || node.type === 2 /* TEXT */;
  11308. }
  11309. function isVSlot(p) {
  11310. return p.type === 7 /* DIRECTIVE */ && p.name === 'slot';
  11311. }
  11312. function isTemplateNode(node) {
  11313. return (node.type === 1 /* ELEMENT */ && node.tagType === 3 /* TEMPLATE */);
  11314. }
  11315. function isSlotOutlet(node) {
  11316. return node.type === 1 /* ELEMENT */ && node.tagType === 2 /* SLOT */;
  11317. }
  11318. function getVNodeHelper(ssr, isComponent) {
  11319. return ssr || isComponent ? CREATE_VNODE : CREATE_ELEMENT_VNODE;
  11320. }
  11321. function getVNodeBlockHelper(ssr, isComponent) {
  11322. return ssr || isComponent ? CREATE_BLOCK : CREATE_ELEMENT_BLOCK;
  11323. }
  11324. const propsHelperSet = new Set([NORMALIZE_PROPS, GUARD_REACTIVE_PROPS]);
  11325. function getUnnormalizedProps(props, callPath = []) {
  11326. if (props &&
  11327. !isString(props) &&
  11328. props.type === 14 /* JS_CALL_EXPRESSION */) {
  11329. const callee = props.callee;
  11330. if (!isString(callee) && propsHelperSet.has(callee)) {
  11331. return getUnnormalizedProps(props.arguments[0], callPath.concat(props));
  11332. }
  11333. }
  11334. return [props, callPath];
  11335. }
  11336. function injectProp(node, prop, context) {
  11337. let propsWithInjection;
  11338. /**
  11339. * 1. mergeProps(...)
  11340. * 2. toHandlers(...)
  11341. * 3. normalizeProps(...)
  11342. * 4. normalizeProps(guardReactiveProps(...))
  11343. *
  11344. * we need to get the real props before normalization
  11345. */
  11346. let props = node.type === 13 /* VNODE_CALL */ ? node.props : node.arguments[2];
  11347. let callPath = [];
  11348. let parentCall;
  11349. if (props &&
  11350. !isString(props) &&
  11351. props.type === 14 /* JS_CALL_EXPRESSION */) {
  11352. const ret = getUnnormalizedProps(props);
  11353. props = ret[0];
  11354. callPath = ret[1];
  11355. parentCall = callPath[callPath.length - 1];
  11356. }
  11357. if (props == null || isString(props)) {
  11358. propsWithInjection = createObjectExpression([prop]);
  11359. }
  11360. else if (props.type === 14 /* JS_CALL_EXPRESSION */) {
  11361. // merged props... add ours
  11362. // only inject key to object literal if it's the first argument so that
  11363. // if doesn't override user provided keys
  11364. const first = props.arguments[0];
  11365. if (!isString(first) && first.type === 15 /* JS_OBJECT_EXPRESSION */) {
  11366. first.properties.unshift(prop);
  11367. }
  11368. else {
  11369. if (props.callee === TO_HANDLERS) {
  11370. // #2366
  11371. propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
  11372. createObjectExpression([prop]),
  11373. props
  11374. ]);
  11375. }
  11376. else {
  11377. props.arguments.unshift(createObjectExpression([prop]));
  11378. }
  11379. }
  11380. !propsWithInjection && (propsWithInjection = props);
  11381. }
  11382. else if (props.type === 15 /* JS_OBJECT_EXPRESSION */) {
  11383. let alreadyExists = false;
  11384. // check existing key to avoid overriding user provided keys
  11385. if (prop.key.type === 4 /* SIMPLE_EXPRESSION */) {
  11386. const propKeyName = prop.key.content;
  11387. alreadyExists = props.properties.some(p => p.key.type === 4 /* SIMPLE_EXPRESSION */ &&
  11388. p.key.content === propKeyName);
  11389. }
  11390. if (!alreadyExists) {
  11391. props.properties.unshift(prop);
  11392. }
  11393. propsWithInjection = props;
  11394. }
  11395. else {
  11396. // single v-bind with expression, return a merged replacement
  11397. propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
  11398. createObjectExpression([prop]),
  11399. props
  11400. ]);
  11401. // in the case of nested helper call, e.g. `normalizeProps(guardReactiveProps(props))`,
  11402. // it will be rewritten as `normalizeProps(mergeProps({ key: 0 }, props))`,
  11403. // the `guardReactiveProps` will no longer be needed
  11404. if (parentCall && parentCall.callee === GUARD_REACTIVE_PROPS) {
  11405. parentCall = callPath[callPath.length - 2];
  11406. }
  11407. }
  11408. if (node.type === 13 /* VNODE_CALL */) {
  11409. if (parentCall) {
  11410. parentCall.arguments[0] = propsWithInjection;
  11411. }
  11412. else {
  11413. node.props = propsWithInjection;
  11414. }
  11415. }
  11416. else {
  11417. if (parentCall) {
  11418. parentCall.arguments[0] = propsWithInjection;
  11419. }
  11420. else {
  11421. node.arguments[2] = propsWithInjection;
  11422. }
  11423. }
  11424. }
  11425. function toValidAssetId(name, type) {
  11426. // see issue#4422, we need adding identifier on validAssetId if variable `name` has specific character
  11427. return `_${type}_${name.replace(/[^\w]/g, (searchValue, replaceValue) => {
  11428. return searchValue === '-' ? '_' : name.charCodeAt(replaceValue).toString();
  11429. })}`;
  11430. }
  11431. function getMemoedVNodeCall(node) {
  11432. if (node.type === 14 /* JS_CALL_EXPRESSION */ && node.callee === WITH_MEMO) {
  11433. return node.arguments[1].returns;
  11434. }
  11435. else {
  11436. return node;
  11437. }
  11438. }
  11439. function makeBlock(node, { helper, removeHelper, inSSR }) {
  11440. if (!node.isBlock) {
  11441. node.isBlock = true;
  11442. removeHelper(getVNodeHelper(inSSR, node.isComponent));
  11443. helper(OPEN_BLOCK);
  11444. helper(getVNodeBlockHelper(inSSR, node.isComponent));
  11445. }
  11446. }
  11447. const deprecationData = {
  11448. ["COMPILER_IS_ON_ELEMENT" /* COMPILER_IS_ON_ELEMENT */]: {
  11449. message: `Platform-native elements with "is" prop will no longer be ` +
  11450. `treated as components in Vue 3 unless the "is" value is explicitly ` +
  11451. `prefixed with "vue:".`,
  11452. link: `https://v3-migration.vuejs.org/breaking-changes/custom-elements-interop.html`
  11453. },
  11454. ["COMPILER_V_BIND_SYNC" /* COMPILER_V_BIND_SYNC */]: {
  11455. message: key => `.sync modifier for v-bind has been removed. Use v-model with ` +
  11456. `argument instead. \`v-bind:${key}.sync\` should be changed to ` +
  11457. `\`v-model:${key}\`.`,
  11458. link: `https://v3-migration.vuejs.org/breaking-changes/v-model.html`
  11459. },
  11460. ["COMPILER_V_BIND_PROP" /* COMPILER_V_BIND_PROP */]: {
  11461. message: `.prop modifier for v-bind has been removed and no longer necessary. ` +
  11462. `Vue 3 will automatically set a binding as DOM property when appropriate.`
  11463. },
  11464. ["COMPILER_V_BIND_OBJECT_ORDER" /* COMPILER_V_BIND_OBJECT_ORDER */]: {
  11465. message: `v-bind="obj" usage is now order sensitive and behaves like JavaScript ` +
  11466. `object spread: it will now overwrite an existing non-mergeable attribute ` +
  11467. `that appears before v-bind in the case of conflict. ` +
  11468. `To retain 2.x behavior, move v-bind to make it the first attribute. ` +
  11469. `You can also suppress this warning if the usage is intended.`,
  11470. link: `https://v3-migration.vuejs.org/breaking-changes/v-bind.html`
  11471. },
  11472. ["COMPILER_V_ON_NATIVE" /* COMPILER_V_ON_NATIVE */]: {
  11473. message: `.native modifier for v-on has been removed as is no longer necessary.`,
  11474. link: `https://v3-migration.vuejs.org/breaking-changes/v-on-native-modifier-removed.html`
  11475. },
  11476. ["COMPILER_V_IF_V_FOR_PRECEDENCE" /* COMPILER_V_IF_V_FOR_PRECEDENCE */]: {
  11477. message: `v-if / v-for precedence when used on the same element has changed ` +
  11478. `in Vue 3: v-if now takes higher precedence and will no longer have ` +
  11479. `access to v-for scope variables. It is best to avoid the ambiguity ` +
  11480. `with <template> tags or use a computed property that filters v-for ` +
  11481. `data source.`,
  11482. link: `https://v3-migration.vuejs.org/breaking-changes/v-if-v-for.html`
  11483. },
  11484. ["COMPILER_NATIVE_TEMPLATE" /* COMPILER_NATIVE_TEMPLATE */]: {
  11485. message: `<template> with no special directives will render as a native template ` +
  11486. `element instead of its inner content in Vue 3.`
  11487. },
  11488. ["COMPILER_INLINE_TEMPLATE" /* COMPILER_INLINE_TEMPLATE */]: {
  11489. message: `"inline-template" has been removed in Vue 3.`,
  11490. link: `https://v3-migration.vuejs.org/breaking-changes/inline-template-attribute.html`
  11491. },
  11492. ["COMPILER_FILTER" /* COMPILER_FILTERS */]: {
  11493. message: `filters have been removed in Vue 3. ` +
  11494. `The "|" symbol will be treated as native JavaScript bitwise OR operator. ` +
  11495. `Use method calls or computed properties instead.`,
  11496. link: `https://v3-migration.vuejs.org/breaking-changes/filters.html`
  11497. }
  11498. };
  11499. function getCompatValue(key, context) {
  11500. const config = context.options
  11501. ? context.options.compatConfig
  11502. : context.compatConfig;
  11503. const value = config && config[key];
  11504. if (key === 'MODE') {
  11505. return value || 3; // compiler defaults to v3 behavior
  11506. }
  11507. else {
  11508. return value;
  11509. }
  11510. }
  11511. function isCompatEnabled(key, context) {
  11512. const mode = getCompatValue('MODE', context);
  11513. const value = getCompatValue(key, context);
  11514. // in v3 mode, only enable if explicitly set to true
  11515. // otherwise enable for any non-false value
  11516. return mode === 3 ? value === true : value !== false;
  11517. }
  11518. function checkCompatEnabled(key, context, loc, ...args) {
  11519. const enabled = isCompatEnabled(key, context);
  11520. if (enabled) {
  11521. warnDeprecation(key, context, loc, ...args);
  11522. }
  11523. return enabled;
  11524. }
  11525. function warnDeprecation(key, context, loc, ...args) {
  11526. const val = getCompatValue(key, context);
  11527. if (val === 'suppress-warning') {
  11528. return;
  11529. }
  11530. const { message, link } = deprecationData[key];
  11531. const msg = `(deprecation ${key}) ${typeof message === 'function' ? message(...args) : message}${link ? `\n Details: ${link}` : ``}`;
  11532. const err = new SyntaxError(msg);
  11533. err.code = key;
  11534. if (loc)
  11535. err.loc = loc;
  11536. context.onWarn(err);
  11537. }
  11538. // The default decoder only provides escapes for characters reserved as part of
  11539. // the template syntax, and is only used if the custom renderer did not provide
  11540. // a platform-specific decoder.
  11541. const decodeRE = /&(gt|lt|amp|apos|quot);/g;
  11542. const decodeMap = {
  11543. gt: '>',
  11544. lt: '<',
  11545. amp: '&',
  11546. apos: "'",
  11547. quot: '"'
  11548. };
  11549. const defaultParserOptions = {
  11550. delimiters: [`{{`, `}}`],
  11551. getNamespace: () => 0 /* HTML */,
  11552. getTextMode: () => 0 /* DATA */,
  11553. isVoidTag: NO,
  11554. isPreTag: NO,
  11555. isCustomElement: NO,
  11556. decodeEntities: (rawText) => rawText.replace(decodeRE, (_, p1) => decodeMap[p1]),
  11557. onError: defaultOnError,
  11558. onWarn: defaultOnWarn,
  11559. comments: true
  11560. };
  11561. function baseParse(content, options = {}) {
  11562. const context = createParserContext(content, options);
  11563. const start = getCursor(context);
  11564. return createRoot(parseChildren(context, 0 /* DATA */, []), getSelection(context, start));
  11565. }
  11566. function createParserContext(content, rawOptions) {
  11567. const options = extend({}, defaultParserOptions);
  11568. let key;
  11569. for (key in rawOptions) {
  11570. // @ts-ignore
  11571. options[key] =
  11572. rawOptions[key] === undefined
  11573. ? defaultParserOptions[key]
  11574. : rawOptions[key];
  11575. }
  11576. return {
  11577. options,
  11578. column: 1,
  11579. line: 1,
  11580. offset: 0,
  11581. originalSource: content,
  11582. source: content,
  11583. inPre: false,
  11584. inVPre: false,
  11585. onWarn: options.onWarn
  11586. };
  11587. }
  11588. function parseChildren(context, mode, ancestors) {
  11589. const parent = last(ancestors);
  11590. const ns = parent ? parent.ns : 0 /* HTML */;
  11591. const nodes = [];
  11592. while (!isEnd(context, mode, ancestors)) {
  11593. const s = context.source;
  11594. let node = undefined;
  11595. if (mode === 0 /* DATA */ || mode === 1 /* RCDATA */) {
  11596. if (!context.inVPre && startsWith(s, context.options.delimiters[0])) {
  11597. // '{{'
  11598. node = parseInterpolation(context, mode);
  11599. }
  11600. else if (mode === 0 /* DATA */ && s[0] === '<') {
  11601. // https://html.spec.whatwg.org/multipage/parsing.html#tag-open-state
  11602. if (s.length === 1) {
  11603. emitError(context, 5 /* EOF_BEFORE_TAG_NAME */, 1);
  11604. }
  11605. else if (s[1] === '!') {
  11606. // https://html.spec.whatwg.org/multipage/parsing.html#markup-declaration-open-state
  11607. if (startsWith(s, '<!--')) {
  11608. node = parseComment(context);
  11609. }
  11610. else if (startsWith(s, '<!DOCTYPE')) {
  11611. // Ignore DOCTYPE by a limitation.
  11612. node = parseBogusComment(context);
  11613. }
  11614. else if (startsWith(s, '<![CDATA[')) {
  11615. if (ns !== 0 /* HTML */) {
  11616. node = parseCDATA(context, ancestors);
  11617. }
  11618. else {
  11619. emitError(context, 1 /* CDATA_IN_HTML_CONTENT */);
  11620. node = parseBogusComment(context);
  11621. }
  11622. }
  11623. else {
  11624. emitError(context, 11 /* INCORRECTLY_OPENED_COMMENT */);
  11625. node = parseBogusComment(context);
  11626. }
  11627. }
  11628. else if (s[1] === '/') {
  11629. // https://html.spec.whatwg.org/multipage/parsing.html#end-tag-open-state
  11630. if (s.length === 2) {
  11631. emitError(context, 5 /* EOF_BEFORE_TAG_NAME */, 2);
  11632. }
  11633. else if (s[2] === '>') {
  11634. emitError(context, 14 /* MISSING_END_TAG_NAME */, 2);
  11635. advanceBy(context, 3);
  11636. continue;
  11637. }
  11638. else if (/[a-z]/i.test(s[2])) {
  11639. emitError(context, 23 /* X_INVALID_END_TAG */);
  11640. parseTag(context, 1 /* End */, parent);
  11641. continue;
  11642. }
  11643. else {
  11644. emitError(context, 12 /* INVALID_FIRST_CHARACTER_OF_TAG_NAME */, 2);
  11645. node = parseBogusComment(context);
  11646. }
  11647. }
  11648. else if (/[a-z]/i.test(s[1])) {
  11649. node = parseElement(context, ancestors);
  11650. }
  11651. else if (s[1] === '?') {
  11652. emitError(context, 21 /* UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME */, 1);
  11653. node = parseBogusComment(context);
  11654. }
  11655. else {
  11656. emitError(context, 12 /* INVALID_FIRST_CHARACTER_OF_TAG_NAME */, 1);
  11657. }
  11658. }
  11659. }
  11660. if (!node) {
  11661. node = parseText(context, mode);
  11662. }
  11663. if (isArray(node)) {
  11664. for (let i = 0; i < node.length; i++) {
  11665. pushNode(nodes, node[i]);
  11666. }
  11667. }
  11668. else {
  11669. pushNode(nodes, node);
  11670. }
  11671. }
  11672. // Whitespace handling strategy like v2
  11673. let removedWhitespace = false;
  11674. if (mode !== 2 /* RAWTEXT */ && mode !== 1 /* RCDATA */) {
  11675. const shouldCondense = context.options.whitespace !== 'preserve';
  11676. for (let i = 0; i < nodes.length; i++) {
  11677. const node = nodes[i];
  11678. if (!context.inPre && node.type === 2 /* TEXT */) {
  11679. if (!/[^\t\r\n\f ]/.test(node.content)) {
  11680. const prev = nodes[i - 1];
  11681. const next = nodes[i + 1];
  11682. // Remove if:
  11683. // - the whitespace is the first or last node, or:
  11684. // - (condense mode) the whitespace is adjacent to a comment, or:
  11685. // - (condense mode) the whitespace is between two elements AND contains newline
  11686. if (!prev ||
  11687. !next ||
  11688. (shouldCondense &&
  11689. (prev.type === 3 /* COMMENT */ ||
  11690. next.type === 3 /* COMMENT */ ||
  11691. (prev.type === 1 /* ELEMENT */ &&
  11692. next.type === 1 /* ELEMENT */ &&
  11693. /[\r\n]/.test(node.content))))) {
  11694. removedWhitespace = true;
  11695. nodes[i] = null;
  11696. }
  11697. else {
  11698. // Otherwise, the whitespace is condensed into a single space
  11699. node.content = ' ';
  11700. }
  11701. }
  11702. else if (shouldCondense) {
  11703. // in condense mode, consecutive whitespaces in text are condensed
  11704. // down to a single space.
  11705. node.content = node.content.replace(/[\t\r\n\f ]+/g, ' ');
  11706. }
  11707. }
  11708. // Remove comment nodes if desired by configuration.
  11709. else if (node.type === 3 /* COMMENT */ && !context.options.comments) {
  11710. removedWhitespace = true;
  11711. nodes[i] = null;
  11712. }
  11713. }
  11714. if (context.inPre && parent && context.options.isPreTag(parent.tag)) {
  11715. // remove leading newline per html spec
  11716. // https://html.spec.whatwg.org/multipage/grouping-content.html#the-pre-element
  11717. const first = nodes[0];
  11718. if (first && first.type === 2 /* TEXT */) {
  11719. first.content = first.content.replace(/^\r?\n/, '');
  11720. }
  11721. }
  11722. }
  11723. return removedWhitespace ? nodes.filter(Boolean) : nodes;
  11724. }
  11725. function pushNode(nodes, node) {
  11726. if (node.type === 2 /* TEXT */) {
  11727. const prev = last(nodes);
  11728. // Merge if both this and the previous node are text and those are
  11729. // consecutive. This happens for cases like "a < b".
  11730. if (prev &&
  11731. prev.type === 2 /* TEXT */ &&
  11732. prev.loc.end.offset === node.loc.start.offset) {
  11733. prev.content += node.content;
  11734. prev.loc.end = node.loc.end;
  11735. prev.loc.source += node.loc.source;
  11736. return;
  11737. }
  11738. }
  11739. nodes.push(node);
  11740. }
  11741. function parseCDATA(context, ancestors) {
  11742. advanceBy(context, 9);
  11743. const nodes = parseChildren(context, 3 /* CDATA */, ancestors);
  11744. if (context.source.length === 0) {
  11745. emitError(context, 6 /* EOF_IN_CDATA */);
  11746. }
  11747. else {
  11748. advanceBy(context, 3);
  11749. }
  11750. return nodes;
  11751. }
  11752. function parseComment(context) {
  11753. const start = getCursor(context);
  11754. let content;
  11755. // Regular comment.
  11756. const match = /--(\!)?>/.exec(context.source);
  11757. if (!match) {
  11758. content = context.source.slice(4);
  11759. advanceBy(context, context.source.length);
  11760. emitError(context, 7 /* EOF_IN_COMMENT */);
  11761. }
  11762. else {
  11763. if (match.index <= 3) {
  11764. emitError(context, 0 /* ABRUPT_CLOSING_OF_EMPTY_COMMENT */);
  11765. }
  11766. if (match[1]) {
  11767. emitError(context, 10 /* INCORRECTLY_CLOSED_COMMENT */);
  11768. }
  11769. content = context.source.slice(4, match.index);
  11770. // Advancing with reporting nested comments.
  11771. const s = context.source.slice(0, match.index);
  11772. let prevIndex = 1, nestedIndex = 0;
  11773. while ((nestedIndex = s.indexOf('<!--', prevIndex)) !== -1) {
  11774. advanceBy(context, nestedIndex - prevIndex + 1);
  11775. if (nestedIndex + 4 < s.length) {
  11776. emitError(context, 16 /* NESTED_COMMENT */);
  11777. }
  11778. prevIndex = nestedIndex + 1;
  11779. }
  11780. advanceBy(context, match.index + match[0].length - prevIndex + 1);
  11781. }
  11782. return {
  11783. type: 3 /* COMMENT */,
  11784. content,
  11785. loc: getSelection(context, start)
  11786. };
  11787. }
  11788. function parseBogusComment(context) {
  11789. const start = getCursor(context);
  11790. const contentStart = context.source[1] === '?' ? 1 : 2;
  11791. let content;
  11792. const closeIndex = context.source.indexOf('>');
  11793. if (closeIndex === -1) {
  11794. content = context.source.slice(contentStart);
  11795. advanceBy(context, context.source.length);
  11796. }
  11797. else {
  11798. content = context.source.slice(contentStart, closeIndex);
  11799. advanceBy(context, closeIndex + 1);
  11800. }
  11801. return {
  11802. type: 3 /* COMMENT */,
  11803. content,
  11804. loc: getSelection(context, start)
  11805. };
  11806. }
  11807. function parseElement(context, ancestors) {
  11808. // Start tag.
  11809. const wasInPre = context.inPre;
  11810. const wasInVPre = context.inVPre;
  11811. const parent = last(ancestors);
  11812. const element = parseTag(context, 0 /* Start */, parent);
  11813. const isPreBoundary = context.inPre && !wasInPre;
  11814. const isVPreBoundary = context.inVPre && !wasInVPre;
  11815. if (element.isSelfClosing || context.options.isVoidTag(element.tag)) {
  11816. // #4030 self-closing <pre> tag
  11817. if (isPreBoundary) {
  11818. context.inPre = false;
  11819. }
  11820. if (isVPreBoundary) {
  11821. context.inVPre = false;
  11822. }
  11823. return element;
  11824. }
  11825. // Children.
  11826. ancestors.push(element);
  11827. const mode = context.options.getTextMode(element, parent);
  11828. const children = parseChildren(context, mode, ancestors);
  11829. ancestors.pop();
  11830. element.children = children;
  11831. // End tag.
  11832. if (startsWithEndTagOpen(context.source, element.tag)) {
  11833. parseTag(context, 1 /* End */, parent);
  11834. }
  11835. else {
  11836. emitError(context, 24 /* X_MISSING_END_TAG */, 0, element.loc.start);
  11837. if (context.source.length === 0 && element.tag.toLowerCase() === 'script') {
  11838. const first = children[0];
  11839. if (first && startsWith(first.loc.source, '<!--')) {
  11840. emitError(context, 8 /* EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT */);
  11841. }
  11842. }
  11843. }
  11844. element.loc = getSelection(context, element.loc.start);
  11845. if (isPreBoundary) {
  11846. context.inPre = false;
  11847. }
  11848. if (isVPreBoundary) {
  11849. context.inVPre = false;
  11850. }
  11851. return element;
  11852. }
  11853. const isSpecialTemplateDirective = /*#__PURE__*/ makeMap(`if,else,else-if,for,slot`);
  11854. function parseTag(context, type, parent) {
  11855. // Tag open.
  11856. const start = getCursor(context);
  11857. const match = /^<\/?([a-z][^\t\r\n\f />]*)/i.exec(context.source);
  11858. const tag = match[1];
  11859. const ns = context.options.getNamespace(tag, parent);
  11860. advanceBy(context, match[0].length);
  11861. advanceSpaces(context);
  11862. // save current state in case we need to re-parse attributes with v-pre
  11863. const cursor = getCursor(context);
  11864. const currentSource = context.source;
  11865. // check <pre> tag
  11866. if (context.options.isPreTag(tag)) {
  11867. context.inPre = true;
  11868. }
  11869. // Attributes.
  11870. let props = parseAttributes(context, type);
  11871. // check v-pre
  11872. if (type === 0 /* Start */ &&
  11873. !context.inVPre &&
  11874. props.some(p => p.type === 7 /* DIRECTIVE */ && p.name === 'pre')) {
  11875. context.inVPre = true;
  11876. // reset context
  11877. extend(context, cursor);
  11878. context.source = currentSource;
  11879. // re-parse attrs and filter out v-pre itself
  11880. props = parseAttributes(context, type).filter(p => p.name !== 'v-pre');
  11881. }
  11882. // Tag close.
  11883. let isSelfClosing = false;
  11884. if (context.source.length === 0) {
  11885. emitError(context, 9 /* EOF_IN_TAG */);
  11886. }
  11887. else {
  11888. isSelfClosing = startsWith(context.source, '/>');
  11889. if (type === 1 /* End */ && isSelfClosing) {
  11890. emitError(context, 4 /* END_TAG_WITH_TRAILING_SOLIDUS */);
  11891. }
  11892. advanceBy(context, isSelfClosing ? 2 : 1);
  11893. }
  11894. if (type === 1 /* End */) {
  11895. return;
  11896. }
  11897. let tagType = 0 /* ELEMENT */;
  11898. if (!context.inVPre) {
  11899. if (tag === 'slot') {
  11900. tagType = 2 /* SLOT */;
  11901. }
  11902. else if (tag === 'template') {
  11903. if (props.some(p => p.type === 7 /* DIRECTIVE */ && isSpecialTemplateDirective(p.name))) {
  11904. tagType = 3 /* TEMPLATE */;
  11905. }
  11906. }
  11907. else if (isComponent(tag, props, context)) {
  11908. tagType = 1 /* COMPONENT */;
  11909. }
  11910. }
  11911. return {
  11912. type: 1 /* ELEMENT */,
  11913. ns,
  11914. tag,
  11915. tagType,
  11916. props,
  11917. isSelfClosing,
  11918. children: [],
  11919. loc: getSelection(context, start),
  11920. codegenNode: undefined // to be created during transform phase
  11921. };
  11922. }
  11923. function isComponent(tag, props, context) {
  11924. const options = context.options;
  11925. if (options.isCustomElement(tag)) {
  11926. return false;
  11927. }
  11928. if (tag === 'component' ||
  11929. /^[A-Z]/.test(tag) ||
  11930. isCoreComponent(tag) ||
  11931. (options.isBuiltInComponent && options.isBuiltInComponent(tag)) ||
  11932. (options.isNativeTag && !options.isNativeTag(tag))) {
  11933. return true;
  11934. }
  11935. // at this point the tag should be a native tag, but check for potential "is"
  11936. // casting
  11937. for (let i = 0; i < props.length; i++) {
  11938. const p = props[i];
  11939. if (p.type === 6 /* ATTRIBUTE */) {
  11940. if (p.name === 'is' && p.value) {
  11941. if (p.value.content.startsWith('vue:')) {
  11942. return true;
  11943. }
  11944. }
  11945. }
  11946. else {
  11947. // directive
  11948. // v-is (TODO Deprecate)
  11949. if (p.name === 'is') {
  11950. return true;
  11951. }
  11952. else if (
  11953. // :is on plain element - only treat as component in compat mode
  11954. p.name === 'bind' &&
  11955. isStaticArgOf(p.arg, 'is') &&
  11956. false &&
  11957. checkCompatEnabled("COMPILER_IS_ON_ELEMENT" /* COMPILER_IS_ON_ELEMENT */, context, p.loc)) {
  11958. return true;
  11959. }
  11960. }
  11961. }
  11962. }
  11963. function parseAttributes(context, type) {
  11964. const props = [];
  11965. const attributeNames = new Set();
  11966. while (context.source.length > 0 &&
  11967. !startsWith(context.source, '>') &&
  11968. !startsWith(context.source, '/>')) {
  11969. if (startsWith(context.source, '/')) {
  11970. emitError(context, 22 /* UNEXPECTED_SOLIDUS_IN_TAG */);
  11971. advanceBy(context, 1);
  11972. advanceSpaces(context);
  11973. continue;
  11974. }
  11975. if (type === 1 /* End */) {
  11976. emitError(context, 3 /* END_TAG_WITH_ATTRIBUTES */);
  11977. }
  11978. const attr = parseAttribute(context, attributeNames);
  11979. // Trim whitespace between class
  11980. // https://github.com/vuejs/core/issues/4251
  11981. if (attr.type === 6 /* ATTRIBUTE */ &&
  11982. attr.value &&
  11983. attr.name === 'class') {
  11984. attr.value.content = attr.value.content.replace(/\s+/g, ' ').trim();
  11985. }
  11986. if (type === 0 /* Start */) {
  11987. props.push(attr);
  11988. }
  11989. if (/^[^\t\r\n\f />]/.test(context.source)) {
  11990. emitError(context, 15 /* MISSING_WHITESPACE_BETWEEN_ATTRIBUTES */);
  11991. }
  11992. advanceSpaces(context);
  11993. }
  11994. return props;
  11995. }
  11996. function parseAttribute(context, nameSet) {
  11997. // Name.
  11998. const start = getCursor(context);
  11999. const match = /^[^\t\r\n\f />][^\t\r\n\f />=]*/.exec(context.source);
  12000. const name = match[0];
  12001. if (nameSet.has(name)) {
  12002. emitError(context, 2 /* DUPLICATE_ATTRIBUTE */);
  12003. }
  12004. nameSet.add(name);
  12005. if (name[0] === '=') {
  12006. emitError(context, 19 /* UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME */);
  12007. }
  12008. {
  12009. const pattern = /["'<]/g;
  12010. let m;
  12011. while ((m = pattern.exec(name))) {
  12012. emitError(context, 17 /* UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME */, m.index);
  12013. }
  12014. }
  12015. advanceBy(context, name.length);
  12016. // Value
  12017. let value = undefined;
  12018. if (/^[\t\r\n\f ]*=/.test(context.source)) {
  12019. advanceSpaces(context);
  12020. advanceBy(context, 1);
  12021. advanceSpaces(context);
  12022. value = parseAttributeValue(context);
  12023. if (!value) {
  12024. emitError(context, 13 /* MISSING_ATTRIBUTE_VALUE */);
  12025. }
  12026. }
  12027. const loc = getSelection(context, start);
  12028. if (!context.inVPre && /^(v-[A-Za-z0-9-]|:|\.|@|#)/.test(name)) {
  12029. const match = /(?:^v-([a-z0-9-]+))?(?:(?::|^\.|^@|^#)(\[[^\]]+\]|[^\.]+))?(.+)?$/i.exec(name);
  12030. let isPropShorthand = startsWith(name, '.');
  12031. let dirName = match[1] ||
  12032. (isPropShorthand || startsWith(name, ':')
  12033. ? 'bind'
  12034. : startsWith(name, '@')
  12035. ? 'on'
  12036. : 'slot');
  12037. let arg;
  12038. if (match[2]) {
  12039. const isSlot = dirName === 'slot';
  12040. const startOffset = name.lastIndexOf(match[2]);
  12041. const loc = getSelection(context, getNewPosition(context, start, startOffset), getNewPosition(context, start, startOffset + match[2].length + ((isSlot && match[3]) || '').length));
  12042. let content = match[2];
  12043. let isStatic = true;
  12044. if (content.startsWith('[')) {
  12045. isStatic = false;
  12046. if (!content.endsWith(']')) {
  12047. emitError(context, 27 /* X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END */);
  12048. content = content.slice(1);
  12049. }
  12050. else {
  12051. content = content.slice(1, content.length - 1);
  12052. }
  12053. }
  12054. else if (isSlot) {
  12055. // #1241 special case for v-slot: vuetify relies extensively on slot
  12056. // names containing dots. v-slot doesn't have any modifiers and Vue 2.x
  12057. // supports such usage so we are keeping it consistent with 2.x.
  12058. content += match[3] || '';
  12059. }
  12060. arg = {
  12061. type: 4 /* SIMPLE_EXPRESSION */,
  12062. content,
  12063. isStatic,
  12064. constType: isStatic
  12065. ? 3 /* CAN_STRINGIFY */
  12066. : 0 /* NOT_CONSTANT */,
  12067. loc
  12068. };
  12069. }
  12070. if (value && value.isQuoted) {
  12071. const valueLoc = value.loc;
  12072. valueLoc.start.offset++;
  12073. valueLoc.start.column++;
  12074. valueLoc.end = advancePositionWithClone(valueLoc.start, value.content);
  12075. valueLoc.source = valueLoc.source.slice(1, -1);
  12076. }
  12077. const modifiers = match[3] ? match[3].slice(1).split('.') : [];
  12078. if (isPropShorthand)
  12079. modifiers.push('prop');
  12080. return {
  12081. type: 7 /* DIRECTIVE */,
  12082. name: dirName,
  12083. exp: value && {
  12084. type: 4 /* SIMPLE_EXPRESSION */,
  12085. content: value.content,
  12086. isStatic: false,
  12087. // Treat as non-constant by default. This can be potentially set to
  12088. // other values by `transformExpression` to make it eligible for hoisting.
  12089. constType: 0 /* NOT_CONSTANT */,
  12090. loc: value.loc
  12091. },
  12092. arg,
  12093. modifiers,
  12094. loc
  12095. };
  12096. }
  12097. // missing directive name or illegal directive name
  12098. if (!context.inVPre && startsWith(name, 'v-')) {
  12099. emitError(context, 26 /* X_MISSING_DIRECTIVE_NAME */);
  12100. }
  12101. return {
  12102. type: 6 /* ATTRIBUTE */,
  12103. name,
  12104. value: value && {
  12105. type: 2 /* TEXT */,
  12106. content: value.content,
  12107. loc: value.loc
  12108. },
  12109. loc
  12110. };
  12111. }
  12112. function parseAttributeValue(context) {
  12113. const start = getCursor(context);
  12114. let content;
  12115. const quote = context.source[0];
  12116. const isQuoted = quote === `"` || quote === `'`;
  12117. if (isQuoted) {
  12118. // Quoted value.
  12119. advanceBy(context, 1);
  12120. const endIndex = context.source.indexOf(quote);
  12121. if (endIndex === -1) {
  12122. content = parseTextData(context, context.source.length, 4 /* ATTRIBUTE_VALUE */);
  12123. }
  12124. else {
  12125. content = parseTextData(context, endIndex, 4 /* ATTRIBUTE_VALUE */);
  12126. advanceBy(context, 1);
  12127. }
  12128. }
  12129. else {
  12130. // Unquoted
  12131. const match = /^[^\t\r\n\f >]+/.exec(context.source);
  12132. if (!match) {
  12133. return undefined;
  12134. }
  12135. const unexpectedChars = /["'<=`]/g;
  12136. let m;
  12137. while ((m = unexpectedChars.exec(match[0]))) {
  12138. emitError(context, 18 /* UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE */, m.index);
  12139. }
  12140. content = parseTextData(context, match[0].length, 4 /* ATTRIBUTE_VALUE */);
  12141. }
  12142. return { content, isQuoted, loc: getSelection(context, start) };
  12143. }
  12144. function parseInterpolation(context, mode) {
  12145. const [open, close] = context.options.delimiters;
  12146. const closeIndex = context.source.indexOf(close, open.length);
  12147. if (closeIndex === -1) {
  12148. emitError(context, 25 /* X_MISSING_INTERPOLATION_END */);
  12149. return undefined;
  12150. }
  12151. const start = getCursor(context);
  12152. advanceBy(context, open.length);
  12153. const innerStart = getCursor(context);
  12154. const innerEnd = getCursor(context);
  12155. const rawContentLength = closeIndex - open.length;
  12156. const rawContent = context.source.slice(0, rawContentLength);
  12157. const preTrimContent = parseTextData(context, rawContentLength, mode);
  12158. const content = preTrimContent.trim();
  12159. const startOffset = preTrimContent.indexOf(content);
  12160. if (startOffset > 0) {
  12161. advancePositionWithMutation(innerStart, rawContent, startOffset);
  12162. }
  12163. const endOffset = rawContentLength - (preTrimContent.length - content.length - startOffset);
  12164. advancePositionWithMutation(innerEnd, rawContent, endOffset);
  12165. advanceBy(context, close.length);
  12166. return {
  12167. type: 5 /* INTERPOLATION */,
  12168. content: {
  12169. type: 4 /* SIMPLE_EXPRESSION */,
  12170. isStatic: false,
  12171. // Set `isConstant` to false by default and will decide in transformExpression
  12172. constType: 0 /* NOT_CONSTANT */,
  12173. content,
  12174. loc: getSelection(context, innerStart, innerEnd)
  12175. },
  12176. loc: getSelection(context, start)
  12177. };
  12178. }
  12179. function parseText(context, mode) {
  12180. const endTokens = mode === 3 /* CDATA */ ? [']]>'] : ['<', context.options.delimiters[0]];
  12181. let endIndex = context.source.length;
  12182. for (let i = 0; i < endTokens.length; i++) {
  12183. const index = context.source.indexOf(endTokens[i], 1);
  12184. if (index !== -1 && endIndex > index) {
  12185. endIndex = index;
  12186. }
  12187. }
  12188. const start = getCursor(context);
  12189. const content = parseTextData(context, endIndex, mode);
  12190. return {
  12191. type: 2 /* TEXT */,
  12192. content,
  12193. loc: getSelection(context, start)
  12194. };
  12195. }
  12196. /**
  12197. * Get text data with a given length from the current location.
  12198. * This translates HTML entities in the text data.
  12199. */
  12200. function parseTextData(context, length, mode) {
  12201. const rawText = context.source.slice(0, length);
  12202. advanceBy(context, length);
  12203. if (mode === 2 /* RAWTEXT */ ||
  12204. mode === 3 /* CDATA */ ||
  12205. !rawText.includes('&')) {
  12206. return rawText;
  12207. }
  12208. else {
  12209. // DATA or RCDATA containing "&"". Entity decoding required.
  12210. return context.options.decodeEntities(rawText, mode === 4 /* ATTRIBUTE_VALUE */);
  12211. }
  12212. }
  12213. function getCursor(context) {
  12214. const { column, line, offset } = context;
  12215. return { column, line, offset };
  12216. }
  12217. function getSelection(context, start, end) {
  12218. end = end || getCursor(context);
  12219. return {
  12220. start,
  12221. end,
  12222. source: context.originalSource.slice(start.offset, end.offset)
  12223. };
  12224. }
  12225. function last(xs) {
  12226. return xs[xs.length - 1];
  12227. }
  12228. function startsWith(source, searchString) {
  12229. return source.startsWith(searchString);
  12230. }
  12231. function advanceBy(context, numberOfCharacters) {
  12232. const { source } = context;
  12233. advancePositionWithMutation(context, source, numberOfCharacters);
  12234. context.source = source.slice(numberOfCharacters);
  12235. }
  12236. function advanceSpaces(context) {
  12237. const match = /^[\t\r\n\f ]+/.exec(context.source);
  12238. if (match) {
  12239. advanceBy(context, match[0].length);
  12240. }
  12241. }
  12242. function getNewPosition(context, start, numberOfCharacters) {
  12243. return advancePositionWithClone(start, context.originalSource.slice(start.offset, numberOfCharacters), numberOfCharacters);
  12244. }
  12245. function emitError(context, code, offset, loc = getCursor(context)) {
  12246. if (offset) {
  12247. loc.offset += offset;
  12248. loc.column += offset;
  12249. }
  12250. context.options.onError(createCompilerError(code, {
  12251. start: loc,
  12252. end: loc,
  12253. source: ''
  12254. }));
  12255. }
  12256. function isEnd(context, mode, ancestors) {
  12257. const s = context.source;
  12258. switch (mode) {
  12259. case 0 /* DATA */:
  12260. if (startsWith(s, '</')) {
  12261. // TODO: probably bad performance
  12262. for (let i = ancestors.length - 1; i >= 0; --i) {
  12263. if (startsWithEndTagOpen(s, ancestors[i].tag)) {
  12264. return true;
  12265. }
  12266. }
  12267. }
  12268. break;
  12269. case 1 /* RCDATA */:
  12270. case 2 /* RAWTEXT */: {
  12271. const parent = last(ancestors);
  12272. if (parent && startsWithEndTagOpen(s, parent.tag)) {
  12273. return true;
  12274. }
  12275. break;
  12276. }
  12277. case 3 /* CDATA */:
  12278. if (startsWith(s, ']]>')) {
  12279. return true;
  12280. }
  12281. break;
  12282. }
  12283. return !s;
  12284. }
  12285. function startsWithEndTagOpen(source, tag) {
  12286. return (startsWith(source, '</') &&
  12287. source.slice(2, 2 + tag.length).toLowerCase() === tag.toLowerCase() &&
  12288. /[\t\r\n\f />]/.test(source[2 + tag.length] || '>'));
  12289. }
  12290. function hoistStatic(root, context) {
  12291. walk(root, context,
  12292. // Root node is unfortunately non-hoistable due to potential parent
  12293. // fallthrough attributes.
  12294. isSingleElementRoot(root, root.children[0]));
  12295. }
  12296. function isSingleElementRoot(root, child) {
  12297. const { children } = root;
  12298. return (children.length === 1 &&
  12299. child.type === 1 /* ELEMENT */ &&
  12300. !isSlotOutlet(child));
  12301. }
  12302. function walk(node, context, doNotHoistNode = false) {
  12303. const { children } = node;
  12304. const originalCount = children.length;
  12305. let hoistedCount = 0;
  12306. for (let i = 0; i < children.length; i++) {
  12307. const child = children[i];
  12308. // only plain elements & text calls are eligible for hoisting.
  12309. if (child.type === 1 /* ELEMENT */ &&
  12310. child.tagType === 0 /* ELEMENT */) {
  12311. const constantType = doNotHoistNode
  12312. ? 0 /* NOT_CONSTANT */
  12313. : getConstantType(child, context);
  12314. if (constantType > 0 /* NOT_CONSTANT */) {
  12315. if (constantType >= 2 /* CAN_HOIST */) {
  12316. child.codegenNode.patchFlag =
  12317. -1 /* HOISTED */ + (` /* HOISTED */` );
  12318. child.codegenNode = context.hoist(child.codegenNode);
  12319. hoistedCount++;
  12320. continue;
  12321. }
  12322. }
  12323. else {
  12324. // node may contain dynamic children, but its props may be eligible for
  12325. // hoisting.
  12326. const codegenNode = child.codegenNode;
  12327. if (codegenNode.type === 13 /* VNODE_CALL */) {
  12328. const flag = getPatchFlag(codegenNode);
  12329. if ((!flag ||
  12330. flag === 512 /* NEED_PATCH */ ||
  12331. flag === 1 /* TEXT */) &&
  12332. getGeneratedPropsConstantType(child, context) >=
  12333. 2 /* CAN_HOIST */) {
  12334. const props = getNodeProps(child);
  12335. if (props) {
  12336. codegenNode.props = context.hoist(props);
  12337. }
  12338. }
  12339. if (codegenNode.dynamicProps) {
  12340. codegenNode.dynamicProps = context.hoist(codegenNode.dynamicProps);
  12341. }
  12342. }
  12343. }
  12344. }
  12345. else if (child.type === 12 /* TEXT_CALL */ &&
  12346. getConstantType(child.content, context) >= 2 /* CAN_HOIST */) {
  12347. child.codegenNode = context.hoist(child.codegenNode);
  12348. hoistedCount++;
  12349. }
  12350. // walk further
  12351. if (child.type === 1 /* ELEMENT */) {
  12352. const isComponent = child.tagType === 1 /* COMPONENT */;
  12353. if (isComponent) {
  12354. context.scopes.vSlot++;
  12355. }
  12356. walk(child, context);
  12357. if (isComponent) {
  12358. context.scopes.vSlot--;
  12359. }
  12360. }
  12361. else if (child.type === 11 /* FOR */) {
  12362. // Do not hoist v-for single child because it has to be a block
  12363. walk(child, context, child.children.length === 1);
  12364. }
  12365. else if (child.type === 9 /* IF */) {
  12366. for (let i = 0; i < child.branches.length; i++) {
  12367. // Do not hoist v-if single child because it has to be a block
  12368. walk(child.branches[i], context, child.branches[i].children.length === 1);
  12369. }
  12370. }
  12371. }
  12372. if (hoistedCount && context.transformHoist) {
  12373. context.transformHoist(children, context, node);
  12374. }
  12375. // all children were hoisted - the entire children array is hoistable.
  12376. if (hoistedCount &&
  12377. hoistedCount === originalCount &&
  12378. node.type === 1 /* ELEMENT */ &&
  12379. node.tagType === 0 /* ELEMENT */ &&
  12380. node.codegenNode &&
  12381. node.codegenNode.type === 13 /* VNODE_CALL */ &&
  12382. isArray(node.codegenNode.children)) {
  12383. node.codegenNode.children = context.hoist(createArrayExpression(node.codegenNode.children));
  12384. }
  12385. }
  12386. function getConstantType(node, context) {
  12387. const { constantCache } = context;
  12388. switch (node.type) {
  12389. case 1 /* ELEMENT */:
  12390. if (node.tagType !== 0 /* ELEMENT */) {
  12391. return 0 /* NOT_CONSTANT */;
  12392. }
  12393. const cached = constantCache.get(node);
  12394. if (cached !== undefined) {
  12395. return cached;
  12396. }
  12397. const codegenNode = node.codegenNode;
  12398. if (codegenNode.type !== 13 /* VNODE_CALL */) {
  12399. return 0 /* NOT_CONSTANT */;
  12400. }
  12401. if (codegenNode.isBlock &&
  12402. node.tag !== 'svg' &&
  12403. node.tag !== 'foreignObject') {
  12404. return 0 /* NOT_CONSTANT */;
  12405. }
  12406. const flag = getPatchFlag(codegenNode);
  12407. if (!flag) {
  12408. let returnType = 3 /* CAN_STRINGIFY */;
  12409. // Element itself has no patch flag. However we still need to check:
  12410. // 1. Even for a node with no patch flag, it is possible for it to contain
  12411. // non-hoistable expressions that refers to scope variables, e.g. compiler
  12412. // injected keys or cached event handlers. Therefore we need to always
  12413. // check the codegenNode's props to be sure.
  12414. const generatedPropsType = getGeneratedPropsConstantType(node, context);
  12415. if (generatedPropsType === 0 /* NOT_CONSTANT */) {
  12416. constantCache.set(node, 0 /* NOT_CONSTANT */);
  12417. return 0 /* NOT_CONSTANT */;
  12418. }
  12419. if (generatedPropsType < returnType) {
  12420. returnType = generatedPropsType;
  12421. }
  12422. // 2. its children.
  12423. for (let i = 0; i < node.children.length; i++) {
  12424. const childType = getConstantType(node.children[i], context);
  12425. if (childType === 0 /* NOT_CONSTANT */) {
  12426. constantCache.set(node, 0 /* NOT_CONSTANT */);
  12427. return 0 /* NOT_CONSTANT */;
  12428. }
  12429. if (childType < returnType) {
  12430. returnType = childType;
  12431. }
  12432. }
  12433. // 3. if the type is not already CAN_SKIP_PATCH which is the lowest non-0
  12434. // type, check if any of the props can cause the type to be lowered
  12435. // we can skip can_patch because it's guaranteed by the absence of a
  12436. // patchFlag.
  12437. if (returnType > 1 /* CAN_SKIP_PATCH */) {
  12438. for (let i = 0; i < node.props.length; i++) {
  12439. const p = node.props[i];
  12440. if (p.type === 7 /* DIRECTIVE */ && p.name === 'bind' && p.exp) {
  12441. const expType = getConstantType(p.exp, context);
  12442. if (expType === 0 /* NOT_CONSTANT */) {
  12443. constantCache.set(node, 0 /* NOT_CONSTANT */);
  12444. return 0 /* NOT_CONSTANT */;
  12445. }
  12446. if (expType < returnType) {
  12447. returnType = expType;
  12448. }
  12449. }
  12450. }
  12451. }
  12452. // only svg/foreignObject could be block here, however if they are
  12453. // static then they don't need to be blocks since there will be no
  12454. // nested updates.
  12455. if (codegenNode.isBlock) {
  12456. // except set custom directives.
  12457. for (let i = 0; i < node.props.length; i++) {
  12458. const p = node.props[i];
  12459. if (p.type === 7 /* DIRECTIVE */) {
  12460. constantCache.set(node, 0 /* NOT_CONSTANT */);
  12461. return 0 /* NOT_CONSTANT */;
  12462. }
  12463. }
  12464. context.removeHelper(OPEN_BLOCK);
  12465. context.removeHelper(getVNodeBlockHelper(context.inSSR, codegenNode.isComponent));
  12466. codegenNode.isBlock = false;
  12467. context.helper(getVNodeHelper(context.inSSR, codegenNode.isComponent));
  12468. }
  12469. constantCache.set(node, returnType);
  12470. return returnType;
  12471. }
  12472. else {
  12473. constantCache.set(node, 0 /* NOT_CONSTANT */);
  12474. return 0 /* NOT_CONSTANT */;
  12475. }
  12476. case 2 /* TEXT */:
  12477. case 3 /* COMMENT */:
  12478. return 3 /* CAN_STRINGIFY */;
  12479. case 9 /* IF */:
  12480. case 11 /* FOR */:
  12481. case 10 /* IF_BRANCH */:
  12482. return 0 /* NOT_CONSTANT */;
  12483. case 5 /* INTERPOLATION */:
  12484. case 12 /* TEXT_CALL */:
  12485. return getConstantType(node.content, context);
  12486. case 4 /* SIMPLE_EXPRESSION */:
  12487. return node.constType;
  12488. case 8 /* COMPOUND_EXPRESSION */:
  12489. let returnType = 3 /* CAN_STRINGIFY */;
  12490. for (let i = 0; i < node.children.length; i++) {
  12491. const child = node.children[i];
  12492. if (isString(child) || isSymbol(child)) {
  12493. continue;
  12494. }
  12495. const childType = getConstantType(child, context);
  12496. if (childType === 0 /* NOT_CONSTANT */) {
  12497. return 0 /* NOT_CONSTANT */;
  12498. }
  12499. else if (childType < returnType) {
  12500. returnType = childType;
  12501. }
  12502. }
  12503. return returnType;
  12504. default:
  12505. return 0 /* NOT_CONSTANT */;
  12506. }
  12507. }
  12508. const allowHoistedHelperSet = new Set([
  12509. NORMALIZE_CLASS,
  12510. NORMALIZE_STYLE,
  12511. NORMALIZE_PROPS,
  12512. GUARD_REACTIVE_PROPS
  12513. ]);
  12514. function getConstantTypeOfHelperCall(value, context) {
  12515. if (value.type === 14 /* JS_CALL_EXPRESSION */ &&
  12516. !isString(value.callee) &&
  12517. allowHoistedHelperSet.has(value.callee)) {
  12518. const arg = value.arguments[0];
  12519. if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
  12520. return getConstantType(arg, context);
  12521. }
  12522. else if (arg.type === 14 /* JS_CALL_EXPRESSION */) {
  12523. // in the case of nested helper call, e.g. `normalizeProps(guardReactiveProps(exp))`
  12524. return getConstantTypeOfHelperCall(arg, context);
  12525. }
  12526. }
  12527. return 0 /* NOT_CONSTANT */;
  12528. }
  12529. function getGeneratedPropsConstantType(node, context) {
  12530. let returnType = 3 /* CAN_STRINGIFY */;
  12531. const props = getNodeProps(node);
  12532. if (props && props.type === 15 /* JS_OBJECT_EXPRESSION */) {
  12533. const { properties } = props;
  12534. for (let i = 0; i < properties.length; i++) {
  12535. const { key, value } = properties[i];
  12536. const keyType = getConstantType(key, context);
  12537. if (keyType === 0 /* NOT_CONSTANT */) {
  12538. return keyType;
  12539. }
  12540. if (keyType < returnType) {
  12541. returnType = keyType;
  12542. }
  12543. let valueType;
  12544. if (value.type === 4 /* SIMPLE_EXPRESSION */) {
  12545. valueType = getConstantType(value, context);
  12546. }
  12547. else if (value.type === 14 /* JS_CALL_EXPRESSION */) {
  12548. // some helper calls can be hoisted,
  12549. // such as the `normalizeProps` generated by the compiler for pre-normalize class,
  12550. // in this case we need to respect the ConstantType of the helper's arguments
  12551. valueType = getConstantTypeOfHelperCall(value, context);
  12552. }
  12553. else {
  12554. valueType = 0 /* NOT_CONSTANT */;
  12555. }
  12556. if (valueType === 0 /* NOT_CONSTANT */) {
  12557. return valueType;
  12558. }
  12559. if (valueType < returnType) {
  12560. returnType = valueType;
  12561. }
  12562. }
  12563. }
  12564. return returnType;
  12565. }
  12566. function getNodeProps(node) {
  12567. const codegenNode = node.codegenNode;
  12568. if (codegenNode.type === 13 /* VNODE_CALL */) {
  12569. return codegenNode.props;
  12570. }
  12571. }
  12572. function getPatchFlag(node) {
  12573. const flag = node.patchFlag;
  12574. return flag ? parseInt(flag, 10) : undefined;
  12575. }
  12576. 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 }) {
  12577. const nameMatch = filename.replace(/\?.*$/, '').match(/([^/\\]+)\.\w+$/);
  12578. const context = {
  12579. // options
  12580. selfName: nameMatch && capitalize(camelize(nameMatch[1])),
  12581. prefixIdentifiers,
  12582. hoistStatic,
  12583. cacheHandlers,
  12584. nodeTransforms,
  12585. directiveTransforms,
  12586. transformHoist,
  12587. isBuiltInComponent,
  12588. isCustomElement,
  12589. expressionPlugins,
  12590. scopeId,
  12591. slotted,
  12592. ssr,
  12593. inSSR,
  12594. ssrCssVars,
  12595. bindingMetadata,
  12596. inline,
  12597. isTS,
  12598. onError,
  12599. onWarn,
  12600. compatConfig,
  12601. // state
  12602. root,
  12603. helpers: new Map(),
  12604. components: new Set(),
  12605. directives: new Set(),
  12606. hoists: [],
  12607. imports: [],
  12608. constantCache: new Map(),
  12609. temps: 0,
  12610. cached: 0,
  12611. identifiers: Object.create(null),
  12612. scopes: {
  12613. vFor: 0,
  12614. vSlot: 0,
  12615. vPre: 0,
  12616. vOnce: 0
  12617. },
  12618. parent: null,
  12619. currentNode: root,
  12620. childIndex: 0,
  12621. inVOnce: false,
  12622. // methods
  12623. helper(name) {
  12624. const count = context.helpers.get(name) || 0;
  12625. context.helpers.set(name, count + 1);
  12626. return name;
  12627. },
  12628. removeHelper(name) {
  12629. const count = context.helpers.get(name);
  12630. if (count) {
  12631. const currentCount = count - 1;
  12632. if (!currentCount) {
  12633. context.helpers.delete(name);
  12634. }
  12635. else {
  12636. context.helpers.set(name, currentCount);
  12637. }
  12638. }
  12639. },
  12640. helperString(name) {
  12641. return `_${helperNameMap[context.helper(name)]}`;
  12642. },
  12643. replaceNode(node) {
  12644. /* istanbul ignore if */
  12645. {
  12646. if (!context.currentNode) {
  12647. throw new Error(`Node being replaced is already removed.`);
  12648. }
  12649. if (!context.parent) {
  12650. throw new Error(`Cannot replace root node.`);
  12651. }
  12652. }
  12653. context.parent.children[context.childIndex] = context.currentNode = node;
  12654. },
  12655. removeNode(node) {
  12656. if (!context.parent) {
  12657. throw new Error(`Cannot remove root node.`);
  12658. }
  12659. const list = context.parent.children;
  12660. const removalIndex = node
  12661. ? list.indexOf(node)
  12662. : context.currentNode
  12663. ? context.childIndex
  12664. : -1;
  12665. /* istanbul ignore if */
  12666. if (removalIndex < 0) {
  12667. throw new Error(`node being removed is not a child of current parent`);
  12668. }
  12669. if (!node || node === context.currentNode) {
  12670. // current node removed
  12671. context.currentNode = null;
  12672. context.onNodeRemoved();
  12673. }
  12674. else {
  12675. // sibling node removed
  12676. if (context.childIndex > removalIndex) {
  12677. context.childIndex--;
  12678. context.onNodeRemoved();
  12679. }
  12680. }
  12681. context.parent.children.splice(removalIndex, 1);
  12682. },
  12683. onNodeRemoved: () => { },
  12684. addIdentifiers(exp) {
  12685. },
  12686. removeIdentifiers(exp) {
  12687. },
  12688. hoist(exp) {
  12689. if (isString(exp))
  12690. exp = createSimpleExpression(exp);
  12691. context.hoists.push(exp);
  12692. const identifier = createSimpleExpression(`_hoisted_${context.hoists.length}`, false, exp.loc, 2 /* CAN_HOIST */);
  12693. identifier.hoisted = exp;
  12694. return identifier;
  12695. },
  12696. cache(exp, isVNode = false) {
  12697. return createCacheExpression(context.cached++, exp, isVNode);
  12698. }
  12699. };
  12700. return context;
  12701. }
  12702. function transform(root, options) {
  12703. const context = createTransformContext(root, options);
  12704. traverseNode(root, context);
  12705. if (options.hoistStatic) {
  12706. hoistStatic(root, context);
  12707. }
  12708. if (!options.ssr) {
  12709. createRootCodegen(root, context);
  12710. }
  12711. // finalize meta information
  12712. root.helpers = [...context.helpers.keys()];
  12713. root.components = [...context.components];
  12714. root.directives = [...context.directives];
  12715. root.imports = context.imports;
  12716. root.hoists = context.hoists;
  12717. root.temps = context.temps;
  12718. root.cached = context.cached;
  12719. }
  12720. function createRootCodegen(root, context) {
  12721. const { helper } = context;
  12722. const { children } = root;
  12723. if (children.length === 1) {
  12724. const child = children[0];
  12725. // if the single child is an element, turn it into a block.
  12726. if (isSingleElementRoot(root, child) && child.codegenNode) {
  12727. // single element root is never hoisted so codegenNode will never be
  12728. // SimpleExpressionNode
  12729. const codegenNode = child.codegenNode;
  12730. if (codegenNode.type === 13 /* VNODE_CALL */) {
  12731. makeBlock(codegenNode, context);
  12732. }
  12733. root.codegenNode = codegenNode;
  12734. }
  12735. else {
  12736. // - single <slot/>, IfNode, ForNode: already blocks.
  12737. // - single text node: always patched.
  12738. // root codegen falls through via genNode()
  12739. root.codegenNode = child;
  12740. }
  12741. }
  12742. else if (children.length > 1) {
  12743. // root has multiple nodes - return a fragment block.
  12744. let patchFlag = 64 /* STABLE_FRAGMENT */;
  12745. let patchFlagText = PatchFlagNames[64 /* STABLE_FRAGMENT */];
  12746. // check if the fragment actually contains a single valid child with
  12747. // the rest being comments
  12748. if (children.filter(c => c.type !== 3 /* COMMENT */).length === 1) {
  12749. patchFlag |= 2048 /* DEV_ROOT_FRAGMENT */;
  12750. patchFlagText += `, ${PatchFlagNames[2048 /* DEV_ROOT_FRAGMENT */]}`;
  12751. }
  12752. root.codegenNode = createVNodeCall(context, helper(FRAGMENT), undefined, root.children, patchFlag + (` /* ${patchFlagText} */` ), undefined, undefined, true, undefined, false /* isComponent */);
  12753. }
  12754. else ;
  12755. }
  12756. function traverseChildren(parent, context) {
  12757. let i = 0;
  12758. const nodeRemoved = () => {
  12759. i--;
  12760. };
  12761. for (; i < parent.children.length; i++) {
  12762. const child = parent.children[i];
  12763. if (isString(child))
  12764. continue;
  12765. context.parent = parent;
  12766. context.childIndex = i;
  12767. context.onNodeRemoved = nodeRemoved;
  12768. traverseNode(child, context);
  12769. }
  12770. }
  12771. function traverseNode(node, context) {
  12772. context.currentNode = node;
  12773. // apply transform plugins
  12774. const { nodeTransforms } = context;
  12775. const exitFns = [];
  12776. for (let i = 0; i < nodeTransforms.length; i++) {
  12777. const onExit = nodeTransforms[i](node, context);
  12778. if (onExit) {
  12779. if (isArray(onExit)) {
  12780. exitFns.push(...onExit);
  12781. }
  12782. else {
  12783. exitFns.push(onExit);
  12784. }
  12785. }
  12786. if (!context.currentNode) {
  12787. // node was removed
  12788. return;
  12789. }
  12790. else {
  12791. // node may have been replaced
  12792. node = context.currentNode;
  12793. }
  12794. }
  12795. switch (node.type) {
  12796. case 3 /* COMMENT */:
  12797. if (!context.ssr) {
  12798. // inject import for the Comment symbol, which is needed for creating
  12799. // comment nodes with `createVNode`
  12800. context.helper(CREATE_COMMENT);
  12801. }
  12802. break;
  12803. case 5 /* INTERPOLATION */:
  12804. // no need to traverse, but we need to inject toString helper
  12805. if (!context.ssr) {
  12806. context.helper(TO_DISPLAY_STRING);
  12807. }
  12808. break;
  12809. // for container types, further traverse downwards
  12810. case 9 /* IF */:
  12811. for (let i = 0; i < node.branches.length; i++) {
  12812. traverseNode(node.branches[i], context);
  12813. }
  12814. break;
  12815. case 10 /* IF_BRANCH */:
  12816. case 11 /* FOR */:
  12817. case 1 /* ELEMENT */:
  12818. case 0 /* ROOT */:
  12819. traverseChildren(node, context);
  12820. break;
  12821. }
  12822. // exit transforms
  12823. context.currentNode = node;
  12824. let i = exitFns.length;
  12825. while (i--) {
  12826. exitFns[i]();
  12827. }
  12828. }
  12829. function createStructuralDirectiveTransform(name, fn) {
  12830. const matches = isString(name)
  12831. ? (n) => n === name
  12832. : (n) => name.test(n);
  12833. return (node, context) => {
  12834. if (node.type === 1 /* ELEMENT */) {
  12835. const { props } = node;
  12836. // structural directive transforms are not concerned with slots
  12837. // as they are handled separately in vSlot.ts
  12838. if (node.tagType === 3 /* TEMPLATE */ && props.some(isVSlot)) {
  12839. return;
  12840. }
  12841. const exitFns = [];
  12842. for (let i = 0; i < props.length; i++) {
  12843. const prop = props[i];
  12844. if (prop.type === 7 /* DIRECTIVE */ && matches(prop.name)) {
  12845. // structural directives are removed to avoid infinite recursion
  12846. // also we remove them *before* applying so that it can further
  12847. // traverse itself in case it moves the node around
  12848. props.splice(i, 1);
  12849. i--;
  12850. const onExit = fn(node, prop, context);
  12851. if (onExit)
  12852. exitFns.push(onExit);
  12853. }
  12854. }
  12855. return exitFns;
  12856. }
  12857. };
  12858. }
  12859. const PURE_ANNOTATION = `/*#__PURE__*/`;
  12860. const aliasHelper = (s) => `${helperNameMap[s]}: _${helperNameMap[s]}`;
  12861. 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 }) {
  12862. const context = {
  12863. mode,
  12864. prefixIdentifiers,
  12865. sourceMap,
  12866. filename,
  12867. scopeId,
  12868. optimizeImports,
  12869. runtimeGlobalName,
  12870. runtimeModuleName,
  12871. ssrRuntimeModuleName,
  12872. ssr,
  12873. isTS,
  12874. inSSR,
  12875. source: ast.loc.source,
  12876. code: ``,
  12877. column: 1,
  12878. line: 1,
  12879. offset: 0,
  12880. indentLevel: 0,
  12881. pure: false,
  12882. map: undefined,
  12883. helper(key) {
  12884. return `_${helperNameMap[key]}`;
  12885. },
  12886. push(code, node) {
  12887. context.code += code;
  12888. },
  12889. indent() {
  12890. newline(++context.indentLevel);
  12891. },
  12892. deindent(withoutNewLine = false) {
  12893. if (withoutNewLine) {
  12894. --context.indentLevel;
  12895. }
  12896. else {
  12897. newline(--context.indentLevel);
  12898. }
  12899. },
  12900. newline() {
  12901. newline(context.indentLevel);
  12902. }
  12903. };
  12904. function newline(n) {
  12905. context.push('\n' + ` `.repeat(n));
  12906. }
  12907. return context;
  12908. }
  12909. function generate(ast, options = {}) {
  12910. const context = createCodegenContext(ast, options);
  12911. if (options.onContextCreated)
  12912. options.onContextCreated(context);
  12913. const { mode, push, prefixIdentifiers, indent, deindent, newline, scopeId, ssr } = context;
  12914. const hasHelpers = ast.helpers.length > 0;
  12915. const useWithBlock = !prefixIdentifiers && mode !== 'module';
  12916. // preambles
  12917. // in setup() inline mode, the preamble is generated in a sub context
  12918. // and returned separately.
  12919. const preambleContext = context;
  12920. {
  12921. genFunctionPreamble(ast, preambleContext);
  12922. }
  12923. // enter render function
  12924. const functionName = ssr ? `ssrRender` : `render`;
  12925. const args = ssr ? ['_ctx', '_push', '_parent', '_attrs'] : ['_ctx', '_cache'];
  12926. const signature = args.join(', ');
  12927. {
  12928. push(`function ${functionName}(${signature}) {`);
  12929. }
  12930. indent();
  12931. if (useWithBlock) {
  12932. push(`with (_ctx) {`);
  12933. indent();
  12934. // function mode const declarations should be inside with block
  12935. // also they should be renamed to avoid collision with user properties
  12936. if (hasHelpers) {
  12937. push(`const { ${ast.helpers.map(aliasHelper).join(', ')} } = _Vue`);
  12938. push(`\n`);
  12939. newline();
  12940. }
  12941. }
  12942. // generate asset resolution statements
  12943. if (ast.components.length) {
  12944. genAssets(ast.components, 'component', context);
  12945. if (ast.directives.length || ast.temps > 0) {
  12946. newline();
  12947. }
  12948. }
  12949. if (ast.directives.length) {
  12950. genAssets(ast.directives, 'directive', context);
  12951. if (ast.temps > 0) {
  12952. newline();
  12953. }
  12954. }
  12955. if (ast.temps > 0) {
  12956. push(`let `);
  12957. for (let i = 0; i < ast.temps; i++) {
  12958. push(`${i > 0 ? `, ` : ``}_temp${i}`);
  12959. }
  12960. }
  12961. if (ast.components.length || ast.directives.length || ast.temps) {
  12962. push(`\n`);
  12963. newline();
  12964. }
  12965. // generate the VNode tree expression
  12966. if (!ssr) {
  12967. push(`return `);
  12968. }
  12969. if (ast.codegenNode) {
  12970. genNode(ast.codegenNode, context);
  12971. }
  12972. else {
  12973. push(`null`);
  12974. }
  12975. if (useWithBlock) {
  12976. deindent();
  12977. push(`}`);
  12978. }
  12979. deindent();
  12980. push(`}`);
  12981. return {
  12982. ast,
  12983. code: context.code,
  12984. preamble: ``,
  12985. // SourceMapGenerator does have toJSON() method but it's not in the types
  12986. map: context.map ? context.map.toJSON() : undefined
  12987. };
  12988. }
  12989. function genFunctionPreamble(ast, context) {
  12990. const { ssr, prefixIdentifiers, push, newline, runtimeModuleName, runtimeGlobalName, ssrRuntimeModuleName } = context;
  12991. const VueBinding = runtimeGlobalName;
  12992. // Generate const declaration for helpers
  12993. // In prefix mode, we place the const declaration at top so it's done
  12994. // only once; But if we not prefixing, we place the declaration inside the
  12995. // with block so it doesn't incur the `in` check cost for every helper access.
  12996. if (ast.helpers.length > 0) {
  12997. {
  12998. // "with" mode.
  12999. // save Vue in a separate variable to avoid collision
  13000. push(`const _Vue = ${VueBinding}\n`);
  13001. // in "with" mode, helpers are declared inside the with block to avoid
  13002. // has check cost, but hoists are lifted out of the function - we need
  13003. // to provide the helper here.
  13004. if (ast.hoists.length) {
  13005. const staticHelpers = [
  13006. CREATE_VNODE,
  13007. CREATE_ELEMENT_VNODE,
  13008. CREATE_COMMENT,
  13009. CREATE_TEXT,
  13010. CREATE_STATIC
  13011. ]
  13012. .filter(helper => ast.helpers.includes(helper))
  13013. .map(aliasHelper)
  13014. .join(', ');
  13015. push(`const { ${staticHelpers} } = _Vue\n`);
  13016. }
  13017. }
  13018. }
  13019. genHoists(ast.hoists, context);
  13020. newline();
  13021. push(`return `);
  13022. }
  13023. function genAssets(assets, type, { helper, push, newline, isTS }) {
  13024. const resolver = helper(type === 'component'
  13025. ? RESOLVE_COMPONENT
  13026. : RESOLVE_DIRECTIVE);
  13027. for (let i = 0; i < assets.length; i++) {
  13028. let id = assets[i];
  13029. // potential component implicit self-reference inferred from SFC filename
  13030. const maybeSelfReference = id.endsWith('__self');
  13031. if (maybeSelfReference) {
  13032. id = id.slice(0, -6);
  13033. }
  13034. push(`const ${toValidAssetId(id, type)} = ${resolver}(${JSON.stringify(id)}${maybeSelfReference ? `, true` : ``})${isTS ? `!` : ``}`);
  13035. if (i < assets.length - 1) {
  13036. newline();
  13037. }
  13038. }
  13039. }
  13040. function genHoists(hoists, context) {
  13041. if (!hoists.length) {
  13042. return;
  13043. }
  13044. context.pure = true;
  13045. const { push, newline, helper, scopeId, mode } = context;
  13046. newline();
  13047. for (let i = 0; i < hoists.length; i++) {
  13048. const exp = hoists[i];
  13049. if (exp) {
  13050. push(`const _hoisted_${i + 1} = ${``}`);
  13051. genNode(exp, context);
  13052. newline();
  13053. }
  13054. }
  13055. context.pure = false;
  13056. }
  13057. function isText$1(n) {
  13058. return (isString(n) ||
  13059. n.type === 4 /* SIMPLE_EXPRESSION */ ||
  13060. n.type === 2 /* TEXT */ ||
  13061. n.type === 5 /* INTERPOLATION */ ||
  13062. n.type === 8 /* COMPOUND_EXPRESSION */);
  13063. }
  13064. function genNodeListAsArray(nodes, context) {
  13065. const multilines = nodes.length > 3 ||
  13066. (nodes.some(n => isArray(n) || !isText$1(n)));
  13067. context.push(`[`);
  13068. multilines && context.indent();
  13069. genNodeList(nodes, context, multilines);
  13070. multilines && context.deindent();
  13071. context.push(`]`);
  13072. }
  13073. function genNodeList(nodes, context, multilines = false, comma = true) {
  13074. const { push, newline } = context;
  13075. for (let i = 0; i < nodes.length; i++) {
  13076. const node = nodes[i];
  13077. if (isString(node)) {
  13078. push(node);
  13079. }
  13080. else if (isArray(node)) {
  13081. genNodeListAsArray(node, context);
  13082. }
  13083. else {
  13084. genNode(node, context);
  13085. }
  13086. if (i < nodes.length - 1) {
  13087. if (multilines) {
  13088. comma && push(',');
  13089. newline();
  13090. }
  13091. else {
  13092. comma && push(', ');
  13093. }
  13094. }
  13095. }
  13096. }
  13097. function genNode(node, context) {
  13098. if (isString(node)) {
  13099. context.push(node);
  13100. return;
  13101. }
  13102. if (isSymbol(node)) {
  13103. context.push(context.helper(node));
  13104. return;
  13105. }
  13106. switch (node.type) {
  13107. case 1 /* ELEMENT */:
  13108. case 9 /* IF */:
  13109. case 11 /* FOR */:
  13110. assert(node.codegenNode != null, `Codegen node is missing for element/if/for node. ` +
  13111. `Apply appropriate transforms first.`);
  13112. genNode(node.codegenNode, context);
  13113. break;
  13114. case 2 /* TEXT */:
  13115. genText(node, context);
  13116. break;
  13117. case 4 /* SIMPLE_EXPRESSION */:
  13118. genExpression(node, context);
  13119. break;
  13120. case 5 /* INTERPOLATION */:
  13121. genInterpolation(node, context);
  13122. break;
  13123. case 12 /* TEXT_CALL */:
  13124. genNode(node.codegenNode, context);
  13125. break;
  13126. case 8 /* COMPOUND_EXPRESSION */:
  13127. genCompoundExpression(node, context);
  13128. break;
  13129. case 3 /* COMMENT */:
  13130. genComment(node, context);
  13131. break;
  13132. case 13 /* VNODE_CALL */:
  13133. genVNodeCall(node, context);
  13134. break;
  13135. case 14 /* JS_CALL_EXPRESSION */:
  13136. genCallExpression(node, context);
  13137. break;
  13138. case 15 /* JS_OBJECT_EXPRESSION */:
  13139. genObjectExpression(node, context);
  13140. break;
  13141. case 17 /* JS_ARRAY_EXPRESSION */:
  13142. genArrayExpression(node, context);
  13143. break;
  13144. case 18 /* JS_FUNCTION_EXPRESSION */:
  13145. genFunctionExpression(node, context);
  13146. break;
  13147. case 19 /* JS_CONDITIONAL_EXPRESSION */:
  13148. genConditionalExpression(node, context);
  13149. break;
  13150. case 20 /* JS_CACHE_EXPRESSION */:
  13151. genCacheExpression(node, context);
  13152. break;
  13153. case 21 /* JS_BLOCK_STATEMENT */:
  13154. genNodeList(node.body, context, true, false);
  13155. break;
  13156. // SSR only types
  13157. case 22 /* JS_TEMPLATE_LITERAL */:
  13158. break;
  13159. case 23 /* JS_IF_STATEMENT */:
  13160. break;
  13161. case 24 /* JS_ASSIGNMENT_EXPRESSION */:
  13162. break;
  13163. case 25 /* JS_SEQUENCE_EXPRESSION */:
  13164. break;
  13165. case 26 /* JS_RETURN_STATEMENT */:
  13166. break;
  13167. /* istanbul ignore next */
  13168. case 10 /* IF_BRANCH */:
  13169. // noop
  13170. break;
  13171. default:
  13172. {
  13173. assert(false, `unhandled codegen node type: ${node.type}`);
  13174. // make sure we exhaust all possible types
  13175. const exhaustiveCheck = node;
  13176. return exhaustiveCheck;
  13177. }
  13178. }
  13179. }
  13180. function genText(node, context) {
  13181. context.push(JSON.stringify(node.content), node);
  13182. }
  13183. function genExpression(node, context) {
  13184. const { content, isStatic } = node;
  13185. context.push(isStatic ? JSON.stringify(content) : content, node);
  13186. }
  13187. function genInterpolation(node, context) {
  13188. const { push, helper, pure } = context;
  13189. if (pure)
  13190. push(PURE_ANNOTATION);
  13191. push(`${helper(TO_DISPLAY_STRING)}(`);
  13192. genNode(node.content, context);
  13193. push(`)`);
  13194. }
  13195. function genCompoundExpression(node, context) {
  13196. for (let i = 0; i < node.children.length; i++) {
  13197. const child = node.children[i];
  13198. if (isString(child)) {
  13199. context.push(child);
  13200. }
  13201. else {
  13202. genNode(child, context);
  13203. }
  13204. }
  13205. }
  13206. function genExpressionAsPropertyKey(node, context) {
  13207. const { push } = context;
  13208. if (node.type === 8 /* COMPOUND_EXPRESSION */) {
  13209. push(`[`);
  13210. genCompoundExpression(node, context);
  13211. push(`]`);
  13212. }
  13213. else if (node.isStatic) {
  13214. // only quote keys if necessary
  13215. const text = isSimpleIdentifier(node.content)
  13216. ? node.content
  13217. : JSON.stringify(node.content);
  13218. push(text, node);
  13219. }
  13220. else {
  13221. push(`[${node.content}]`, node);
  13222. }
  13223. }
  13224. function genComment(node, context) {
  13225. const { push, helper, pure } = context;
  13226. if (pure) {
  13227. push(PURE_ANNOTATION);
  13228. }
  13229. push(`${helper(CREATE_COMMENT)}(${JSON.stringify(node.content)})`, node);
  13230. }
  13231. function genVNodeCall(node, context) {
  13232. const { push, helper, pure } = context;
  13233. const { tag, props, children, patchFlag, dynamicProps, directives, isBlock, disableTracking, isComponent } = node;
  13234. if (directives) {
  13235. push(helper(WITH_DIRECTIVES) + `(`);
  13236. }
  13237. if (isBlock) {
  13238. push(`(${helper(OPEN_BLOCK)}(${disableTracking ? `true` : ``}), `);
  13239. }
  13240. if (pure) {
  13241. push(PURE_ANNOTATION);
  13242. }
  13243. const callHelper = isBlock
  13244. ? getVNodeBlockHelper(context.inSSR, isComponent)
  13245. : getVNodeHelper(context.inSSR, isComponent);
  13246. push(helper(callHelper) + `(`, node);
  13247. genNodeList(genNullableArgs([tag, props, children, patchFlag, dynamicProps]), context);
  13248. push(`)`);
  13249. if (isBlock) {
  13250. push(`)`);
  13251. }
  13252. if (directives) {
  13253. push(`, `);
  13254. genNode(directives, context);
  13255. push(`)`);
  13256. }
  13257. }
  13258. function genNullableArgs(args) {
  13259. let i = args.length;
  13260. while (i--) {
  13261. if (args[i] != null)
  13262. break;
  13263. }
  13264. return args.slice(0, i + 1).map(arg => arg || `null`);
  13265. }
  13266. // JavaScript
  13267. function genCallExpression(node, context) {
  13268. const { push, helper, pure } = context;
  13269. const callee = isString(node.callee) ? node.callee : helper(node.callee);
  13270. if (pure) {
  13271. push(PURE_ANNOTATION);
  13272. }
  13273. push(callee + `(`, node);
  13274. genNodeList(node.arguments, context);
  13275. push(`)`);
  13276. }
  13277. function genObjectExpression(node, context) {
  13278. const { push, indent, deindent, newline } = context;
  13279. const { properties } = node;
  13280. if (!properties.length) {
  13281. push(`{}`, node);
  13282. return;
  13283. }
  13284. const multilines = properties.length > 1 ||
  13285. (properties.some(p => p.value.type !== 4 /* SIMPLE_EXPRESSION */));
  13286. push(multilines ? `{` : `{ `);
  13287. multilines && indent();
  13288. for (let i = 0; i < properties.length; i++) {
  13289. const { key, value } = properties[i];
  13290. // key
  13291. genExpressionAsPropertyKey(key, context);
  13292. push(`: `);
  13293. // value
  13294. genNode(value, context);
  13295. if (i < properties.length - 1) {
  13296. // will only reach this if it's multilines
  13297. push(`,`);
  13298. newline();
  13299. }
  13300. }
  13301. multilines && deindent();
  13302. push(multilines ? `}` : ` }`);
  13303. }
  13304. function genArrayExpression(node, context) {
  13305. genNodeListAsArray(node.elements, context);
  13306. }
  13307. function genFunctionExpression(node, context) {
  13308. const { push, indent, deindent } = context;
  13309. const { params, returns, body, newline, isSlot } = node;
  13310. if (isSlot) {
  13311. // wrap slot functions with owner context
  13312. push(`_${helperNameMap[WITH_CTX]}(`);
  13313. }
  13314. push(`(`, node);
  13315. if (isArray(params)) {
  13316. genNodeList(params, context);
  13317. }
  13318. else if (params) {
  13319. genNode(params, context);
  13320. }
  13321. push(`) => `);
  13322. if (newline || body) {
  13323. push(`{`);
  13324. indent();
  13325. }
  13326. if (returns) {
  13327. if (newline) {
  13328. push(`return `);
  13329. }
  13330. if (isArray(returns)) {
  13331. genNodeListAsArray(returns, context);
  13332. }
  13333. else {
  13334. genNode(returns, context);
  13335. }
  13336. }
  13337. else if (body) {
  13338. genNode(body, context);
  13339. }
  13340. if (newline || body) {
  13341. deindent();
  13342. push(`}`);
  13343. }
  13344. if (isSlot) {
  13345. push(`)`);
  13346. }
  13347. }
  13348. function genConditionalExpression(node, context) {
  13349. const { test, consequent, alternate, newline: needNewline } = node;
  13350. const { push, indent, deindent, newline } = context;
  13351. if (test.type === 4 /* SIMPLE_EXPRESSION */) {
  13352. const needsParens = !isSimpleIdentifier(test.content);
  13353. needsParens && push(`(`);
  13354. genExpression(test, context);
  13355. needsParens && push(`)`);
  13356. }
  13357. else {
  13358. push(`(`);
  13359. genNode(test, context);
  13360. push(`)`);
  13361. }
  13362. needNewline && indent();
  13363. context.indentLevel++;
  13364. needNewline || push(` `);
  13365. push(`? `);
  13366. genNode(consequent, context);
  13367. context.indentLevel--;
  13368. needNewline && newline();
  13369. needNewline || push(` `);
  13370. push(`: `);
  13371. const isNested = alternate.type === 19 /* JS_CONDITIONAL_EXPRESSION */;
  13372. if (!isNested) {
  13373. context.indentLevel++;
  13374. }
  13375. genNode(alternate, context);
  13376. if (!isNested) {
  13377. context.indentLevel--;
  13378. }
  13379. needNewline && deindent(true /* without newline */);
  13380. }
  13381. function genCacheExpression(node, context) {
  13382. const { push, helper, indent, deindent, newline } = context;
  13383. push(`_cache[${node.index}] || (`);
  13384. if (node.isVNode) {
  13385. indent();
  13386. push(`${helper(SET_BLOCK_TRACKING)}(-1),`);
  13387. newline();
  13388. }
  13389. push(`_cache[${node.index}] = `);
  13390. genNode(node.value, context);
  13391. if (node.isVNode) {
  13392. push(`,`);
  13393. newline();
  13394. push(`${helper(SET_BLOCK_TRACKING)}(1),`);
  13395. newline();
  13396. push(`_cache[${node.index}]`);
  13397. deindent();
  13398. }
  13399. push(`)`);
  13400. }
  13401. // these keywords should not appear inside expressions, but operators like
  13402. // typeof, instanceof and in are allowed
  13403. const prohibitedKeywordRE = new RegExp('\\b' +
  13404. ('do,if,for,let,new,try,var,case,else,with,await,break,catch,class,const,' +
  13405. 'super,throw,while,yield,delete,export,import,return,switch,default,' +
  13406. 'extends,finally,continue,debugger,function,arguments,typeof,void')
  13407. .split(',')
  13408. .join('\\b|\\b') +
  13409. '\\b');
  13410. // strip strings in expressions
  13411. const stripStringRE = /'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`(?:[^`\\]|\\.)*\$\{|\}(?:[^`\\]|\\.)*`|`(?:[^`\\]|\\.)*`/g;
  13412. /**
  13413. * Validate a non-prefixed expression.
  13414. * This is only called when using the in-browser runtime compiler since it
  13415. * doesn't prefix expressions.
  13416. */
  13417. function validateBrowserExpression(node, context, asParams = false, asRawStatements = false) {
  13418. const exp = node.content;
  13419. // empty expressions are validated per-directive since some directives
  13420. // do allow empty expressions.
  13421. if (!exp.trim()) {
  13422. return;
  13423. }
  13424. try {
  13425. new Function(asRawStatements
  13426. ? ` ${exp} `
  13427. : `return ${asParams ? `(${exp}) => {}` : `(${exp})`}`);
  13428. }
  13429. catch (e) {
  13430. let message = e.message;
  13431. const keywordMatch = exp
  13432. .replace(stripStringRE, '')
  13433. .match(prohibitedKeywordRE);
  13434. if (keywordMatch) {
  13435. message = `avoid using JavaScript keyword as property name: "${keywordMatch[0]}"`;
  13436. }
  13437. context.onError(createCompilerError(44 /* X_INVALID_EXPRESSION */, node.loc, undefined, message));
  13438. }
  13439. }
  13440. const transformExpression = (node, context) => {
  13441. if (node.type === 5 /* INTERPOLATION */) {
  13442. node.content = processExpression(node.content, context);
  13443. }
  13444. else if (node.type === 1 /* ELEMENT */) {
  13445. // handle directives on element
  13446. for (let i = 0; i < node.props.length; i++) {
  13447. const dir = node.props[i];
  13448. // do not process for v-on & v-for since they are special handled
  13449. if (dir.type === 7 /* DIRECTIVE */ && dir.name !== 'for') {
  13450. const exp = dir.exp;
  13451. const arg = dir.arg;
  13452. // do not process exp if this is v-on:arg - we need special handling
  13453. // for wrapping inline statements.
  13454. if (exp &&
  13455. exp.type === 4 /* SIMPLE_EXPRESSION */ &&
  13456. !(dir.name === 'on' && arg)) {
  13457. dir.exp = processExpression(exp, context,
  13458. // slot args must be processed as function params
  13459. dir.name === 'slot');
  13460. }
  13461. if (arg && arg.type === 4 /* SIMPLE_EXPRESSION */ && !arg.isStatic) {
  13462. dir.arg = processExpression(arg, context);
  13463. }
  13464. }
  13465. }
  13466. }
  13467. };
  13468. // Important: since this function uses Node.js only dependencies, it should
  13469. // always be used with a leading !true check so that it can be
  13470. // tree-shaken from the browser build.
  13471. function processExpression(node, context,
  13472. // some expressions like v-slot props & v-for aliases should be parsed as
  13473. // function params
  13474. asParams = false,
  13475. // v-on handler values may contain multiple statements
  13476. asRawStatements = false, localVars = Object.create(context.identifiers)) {
  13477. {
  13478. {
  13479. // simple in-browser validation (same logic in 2.x)
  13480. validateBrowserExpression(node, context, asParams, asRawStatements);
  13481. }
  13482. return node;
  13483. }
  13484. }
  13485. const transformIf = createStructuralDirectiveTransform(/^(if|else|else-if)$/, (node, dir, context) => {
  13486. return processIf(node, dir, context, (ifNode, branch, isRoot) => {
  13487. // #1587: We need to dynamically increment the key based on the current
  13488. // node's sibling nodes, since chained v-if/else branches are
  13489. // rendered at the same depth
  13490. const siblings = context.parent.children;
  13491. let i = siblings.indexOf(ifNode);
  13492. let key = 0;
  13493. while (i-- >= 0) {
  13494. const sibling = siblings[i];
  13495. if (sibling && sibling.type === 9 /* IF */) {
  13496. key += sibling.branches.length;
  13497. }
  13498. }
  13499. // Exit callback. Complete the codegenNode when all children have been
  13500. // transformed.
  13501. return () => {
  13502. if (isRoot) {
  13503. ifNode.codegenNode = createCodegenNodeForBranch(branch, key, context);
  13504. }
  13505. else {
  13506. // attach this branch's codegen node to the v-if root.
  13507. const parentCondition = getParentCondition(ifNode.codegenNode);
  13508. parentCondition.alternate = createCodegenNodeForBranch(branch, key + ifNode.branches.length - 1, context);
  13509. }
  13510. };
  13511. });
  13512. });
  13513. // target-agnostic transform used for both Client and SSR
  13514. function processIf(node, dir, context, processCodegen) {
  13515. if (dir.name !== 'else' &&
  13516. (!dir.exp || !dir.exp.content.trim())) {
  13517. const loc = dir.exp ? dir.exp.loc : node.loc;
  13518. context.onError(createCompilerError(28 /* X_V_IF_NO_EXPRESSION */, dir.loc));
  13519. dir.exp = createSimpleExpression(`true`, false, loc);
  13520. }
  13521. if (dir.exp) {
  13522. validateBrowserExpression(dir.exp, context);
  13523. }
  13524. if (dir.name === 'if') {
  13525. const branch = createIfBranch(node, dir);
  13526. const ifNode = {
  13527. type: 9 /* IF */,
  13528. loc: node.loc,
  13529. branches: [branch]
  13530. };
  13531. context.replaceNode(ifNode);
  13532. if (processCodegen) {
  13533. return processCodegen(ifNode, branch, true);
  13534. }
  13535. }
  13536. else {
  13537. // locate the adjacent v-if
  13538. const siblings = context.parent.children;
  13539. const comments = [];
  13540. let i = siblings.indexOf(node);
  13541. while (i-- >= -1) {
  13542. const sibling = siblings[i];
  13543. if (sibling && sibling.type === 3 /* COMMENT */) {
  13544. context.removeNode(sibling);
  13545. comments.unshift(sibling);
  13546. continue;
  13547. }
  13548. if (sibling &&
  13549. sibling.type === 2 /* TEXT */ &&
  13550. !sibling.content.trim().length) {
  13551. context.removeNode(sibling);
  13552. continue;
  13553. }
  13554. if (sibling && sibling.type === 9 /* IF */) {
  13555. // Check if v-else was followed by v-else-if
  13556. if (dir.name === 'else-if' &&
  13557. sibling.branches[sibling.branches.length - 1].condition === undefined) {
  13558. context.onError(createCompilerError(30 /* X_V_ELSE_NO_ADJACENT_IF */, node.loc));
  13559. }
  13560. // move the node to the if node's branches
  13561. context.removeNode();
  13562. const branch = createIfBranch(node, dir);
  13563. if (comments.length &&
  13564. // #3619 ignore comments if the v-if is direct child of <transition>
  13565. !(context.parent &&
  13566. context.parent.type === 1 /* ELEMENT */ &&
  13567. isBuiltInType(context.parent.tag, 'transition'))) {
  13568. branch.children = [...comments, ...branch.children];
  13569. }
  13570. // check if user is forcing same key on different branches
  13571. {
  13572. const key = branch.userKey;
  13573. if (key) {
  13574. sibling.branches.forEach(({ userKey }) => {
  13575. if (isSameKey(userKey, key)) {
  13576. context.onError(createCompilerError(29 /* X_V_IF_SAME_KEY */, branch.userKey.loc));
  13577. }
  13578. });
  13579. }
  13580. }
  13581. sibling.branches.push(branch);
  13582. const onExit = processCodegen && processCodegen(sibling, branch, false);
  13583. // since the branch was removed, it will not be traversed.
  13584. // make sure to traverse here.
  13585. traverseNode(branch, context);
  13586. // call on exit
  13587. if (onExit)
  13588. onExit();
  13589. // make sure to reset currentNode after traversal to indicate this
  13590. // node has been removed.
  13591. context.currentNode = null;
  13592. }
  13593. else {
  13594. context.onError(createCompilerError(30 /* X_V_ELSE_NO_ADJACENT_IF */, node.loc));
  13595. }
  13596. break;
  13597. }
  13598. }
  13599. }
  13600. function createIfBranch(node, dir) {
  13601. const isTemplateIf = node.tagType === 3 /* TEMPLATE */;
  13602. return {
  13603. type: 10 /* IF_BRANCH */,
  13604. loc: node.loc,
  13605. condition: dir.name === 'else' ? undefined : dir.exp,
  13606. children: isTemplateIf && !findDir(node, 'for') ? node.children : [node],
  13607. userKey: findProp(node, `key`),
  13608. isTemplateIf
  13609. };
  13610. }
  13611. function createCodegenNodeForBranch(branch, keyIndex, context) {
  13612. if (branch.condition) {
  13613. return createConditionalExpression(branch.condition, createChildrenCodegenNode(branch, keyIndex, context),
  13614. // make sure to pass in asBlock: true so that the comment node call
  13615. // closes the current block.
  13616. createCallExpression(context.helper(CREATE_COMMENT), [
  13617. '"v-if"' ,
  13618. 'true'
  13619. ]));
  13620. }
  13621. else {
  13622. return createChildrenCodegenNode(branch, keyIndex, context);
  13623. }
  13624. }
  13625. function createChildrenCodegenNode(branch, keyIndex, context) {
  13626. const { helper } = context;
  13627. const keyProperty = createObjectProperty(`key`, createSimpleExpression(`${keyIndex}`, false, locStub, 2 /* CAN_HOIST */));
  13628. const { children } = branch;
  13629. const firstChild = children[0];
  13630. const needFragmentWrapper = children.length !== 1 || firstChild.type !== 1 /* ELEMENT */;
  13631. if (needFragmentWrapper) {
  13632. if (children.length === 1 && firstChild.type === 11 /* FOR */) {
  13633. // optimize away nested fragments when child is a ForNode
  13634. const vnodeCall = firstChild.codegenNode;
  13635. injectProp(vnodeCall, keyProperty, context);
  13636. return vnodeCall;
  13637. }
  13638. else {
  13639. let patchFlag = 64 /* STABLE_FRAGMENT */;
  13640. let patchFlagText = PatchFlagNames[64 /* STABLE_FRAGMENT */];
  13641. // check if the fragment actually contains a single valid child with
  13642. // the rest being comments
  13643. if (!branch.isTemplateIf &&
  13644. children.filter(c => c.type !== 3 /* COMMENT */).length === 1) {
  13645. patchFlag |= 2048 /* DEV_ROOT_FRAGMENT */;
  13646. patchFlagText += `, ${PatchFlagNames[2048 /* DEV_ROOT_FRAGMENT */]}`;
  13647. }
  13648. return createVNodeCall(context, helper(FRAGMENT), createObjectExpression([keyProperty]), children, patchFlag + (` /* ${patchFlagText} */` ), undefined, undefined, true, false, false /* isComponent */, branch.loc);
  13649. }
  13650. }
  13651. else {
  13652. const ret = firstChild.codegenNode;
  13653. const vnodeCall = getMemoedVNodeCall(ret);
  13654. // Change createVNode to createBlock.
  13655. if (vnodeCall.type === 13 /* VNODE_CALL */) {
  13656. makeBlock(vnodeCall, context);
  13657. }
  13658. // inject branch key
  13659. injectProp(vnodeCall, keyProperty, context);
  13660. return ret;
  13661. }
  13662. }
  13663. function isSameKey(a, b) {
  13664. if (!a || a.type !== b.type) {
  13665. return false;
  13666. }
  13667. if (a.type === 6 /* ATTRIBUTE */) {
  13668. if (a.value.content !== b.value.content) {
  13669. return false;
  13670. }
  13671. }
  13672. else {
  13673. // directive
  13674. const exp = a.exp;
  13675. const branchExp = b.exp;
  13676. if (exp.type !== branchExp.type) {
  13677. return false;
  13678. }
  13679. if (exp.type !== 4 /* SIMPLE_EXPRESSION */ ||
  13680. exp.isStatic !== branchExp.isStatic ||
  13681. exp.content !== branchExp.content) {
  13682. return false;
  13683. }
  13684. }
  13685. return true;
  13686. }
  13687. function getParentCondition(node) {
  13688. while (true) {
  13689. if (node.type === 19 /* JS_CONDITIONAL_EXPRESSION */) {
  13690. if (node.alternate.type === 19 /* JS_CONDITIONAL_EXPRESSION */) {
  13691. node = node.alternate;
  13692. }
  13693. else {
  13694. return node;
  13695. }
  13696. }
  13697. else if (node.type === 20 /* JS_CACHE_EXPRESSION */) {
  13698. node = node.value;
  13699. }
  13700. }
  13701. }
  13702. const transformFor = createStructuralDirectiveTransform('for', (node, dir, context) => {
  13703. const { helper, removeHelper } = context;
  13704. return processFor(node, dir, context, forNode => {
  13705. // create the loop render function expression now, and add the
  13706. // iterator on exit after all children have been traversed
  13707. const renderExp = createCallExpression(helper(RENDER_LIST), [
  13708. forNode.source
  13709. ]);
  13710. const isTemplate = isTemplateNode(node);
  13711. const memo = findDir(node, 'memo');
  13712. const keyProp = findProp(node, `key`);
  13713. const keyExp = keyProp &&
  13714. (keyProp.type === 6 /* ATTRIBUTE */
  13715. ? createSimpleExpression(keyProp.value.content, true)
  13716. : keyProp.exp);
  13717. const keyProperty = keyProp ? createObjectProperty(`key`, keyExp) : null;
  13718. const isStableFragment = forNode.source.type === 4 /* SIMPLE_EXPRESSION */ &&
  13719. forNode.source.constType > 0 /* NOT_CONSTANT */;
  13720. const fragmentFlag = isStableFragment
  13721. ? 64 /* STABLE_FRAGMENT */
  13722. : keyProp
  13723. ? 128 /* KEYED_FRAGMENT */
  13724. : 256 /* UNKEYED_FRAGMENT */;
  13725. forNode.codegenNode = createVNodeCall(context, helper(FRAGMENT), undefined, renderExp, fragmentFlag +
  13726. (` /* ${PatchFlagNames[fragmentFlag]} */` ), undefined, undefined, true /* isBlock */, !isStableFragment /* disableTracking */, false /* isComponent */, node.loc);
  13727. return () => {
  13728. // finish the codegen now that all children have been traversed
  13729. let childBlock;
  13730. const { children } = forNode;
  13731. // check <template v-for> key placement
  13732. if (isTemplate) {
  13733. node.children.some(c => {
  13734. if (c.type === 1 /* ELEMENT */) {
  13735. const key = findProp(c, 'key');
  13736. if (key) {
  13737. context.onError(createCompilerError(33 /* X_V_FOR_TEMPLATE_KEY_PLACEMENT */, key.loc));
  13738. return true;
  13739. }
  13740. }
  13741. });
  13742. }
  13743. const needFragmentWrapper = children.length !== 1 || children[0].type !== 1 /* ELEMENT */;
  13744. const slotOutlet = isSlotOutlet(node)
  13745. ? node
  13746. : isTemplate &&
  13747. node.children.length === 1 &&
  13748. isSlotOutlet(node.children[0])
  13749. ? node.children[0] // api-extractor somehow fails to infer this
  13750. : null;
  13751. if (slotOutlet) {
  13752. // <slot v-for="..."> or <template v-for="..."><slot/></template>
  13753. childBlock = slotOutlet.codegenNode;
  13754. if (isTemplate && keyProperty) {
  13755. // <template v-for="..." :key="..."><slot/></template>
  13756. // we need to inject the key to the renderSlot() call.
  13757. // the props for renderSlot is passed as the 3rd argument.
  13758. injectProp(childBlock, keyProperty, context);
  13759. }
  13760. }
  13761. else if (needFragmentWrapper) {
  13762. // <template v-for="..."> with text or multi-elements
  13763. // should generate a fragment block for each loop
  13764. childBlock = createVNodeCall(context, helper(FRAGMENT), keyProperty ? createObjectExpression([keyProperty]) : undefined, node.children, 64 /* STABLE_FRAGMENT */ +
  13765. (` /* ${PatchFlagNames[64 /* STABLE_FRAGMENT */]} */`
  13766. ), undefined, undefined, true, undefined, false /* isComponent */);
  13767. }
  13768. else {
  13769. // Normal element v-for. Directly use the child's codegenNode
  13770. // but mark it as a block.
  13771. childBlock = children[0]
  13772. .codegenNode;
  13773. if (isTemplate && keyProperty) {
  13774. injectProp(childBlock, keyProperty, context);
  13775. }
  13776. if (childBlock.isBlock !== !isStableFragment) {
  13777. if (childBlock.isBlock) {
  13778. // switch from block to vnode
  13779. removeHelper(OPEN_BLOCK);
  13780. removeHelper(getVNodeBlockHelper(context.inSSR, childBlock.isComponent));
  13781. }
  13782. else {
  13783. // switch from vnode to block
  13784. removeHelper(getVNodeHelper(context.inSSR, childBlock.isComponent));
  13785. }
  13786. }
  13787. childBlock.isBlock = !isStableFragment;
  13788. if (childBlock.isBlock) {
  13789. helper(OPEN_BLOCK);
  13790. helper(getVNodeBlockHelper(context.inSSR, childBlock.isComponent));
  13791. }
  13792. else {
  13793. helper(getVNodeHelper(context.inSSR, childBlock.isComponent));
  13794. }
  13795. }
  13796. if (memo) {
  13797. const loop = createFunctionExpression(createForLoopParams(forNode.parseResult, [
  13798. createSimpleExpression(`_cached`)
  13799. ]));
  13800. loop.body = createBlockStatement([
  13801. createCompoundExpression([`const _memo = (`, memo.exp, `)`]),
  13802. createCompoundExpression([
  13803. `if (_cached`,
  13804. ...(keyExp ? [` && _cached.key === `, keyExp] : []),
  13805. ` && ${context.helperString(IS_MEMO_SAME)}(_cached, _memo)) return _cached`
  13806. ]),
  13807. createCompoundExpression([`const _item = `, childBlock]),
  13808. createSimpleExpression(`_item.memo = _memo`),
  13809. createSimpleExpression(`return _item`)
  13810. ]);
  13811. renderExp.arguments.push(loop, createSimpleExpression(`_cache`), createSimpleExpression(String(context.cached++)));
  13812. }
  13813. else {
  13814. renderExp.arguments.push(createFunctionExpression(createForLoopParams(forNode.parseResult), childBlock, true /* force newline */));
  13815. }
  13816. };
  13817. });
  13818. });
  13819. // target-agnostic transform used for both Client and SSR
  13820. function processFor(node, dir, context, processCodegen) {
  13821. if (!dir.exp) {
  13822. context.onError(createCompilerError(31 /* X_V_FOR_NO_EXPRESSION */, dir.loc));
  13823. return;
  13824. }
  13825. const parseResult = parseForExpression(
  13826. // can only be simple expression because vFor transform is applied
  13827. // before expression transform.
  13828. dir.exp, context);
  13829. if (!parseResult) {
  13830. context.onError(createCompilerError(32 /* X_V_FOR_MALFORMED_EXPRESSION */, dir.loc));
  13831. return;
  13832. }
  13833. const { addIdentifiers, removeIdentifiers, scopes } = context;
  13834. const { source, value, key, index } = parseResult;
  13835. const forNode = {
  13836. type: 11 /* FOR */,
  13837. loc: dir.loc,
  13838. source,
  13839. valueAlias: value,
  13840. keyAlias: key,
  13841. objectIndexAlias: index,
  13842. parseResult,
  13843. children: isTemplateNode(node) ? node.children : [node]
  13844. };
  13845. context.replaceNode(forNode);
  13846. // bookkeeping
  13847. scopes.vFor++;
  13848. const onExit = processCodegen && processCodegen(forNode);
  13849. return () => {
  13850. scopes.vFor--;
  13851. if (onExit)
  13852. onExit();
  13853. };
  13854. }
  13855. const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/;
  13856. // This regex doesn't cover the case if key or index aliases have destructuring,
  13857. // but those do not make sense in the first place, so this works in practice.
  13858. const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/;
  13859. const stripParensRE = /^\(|\)$/g;
  13860. function parseForExpression(input, context) {
  13861. const loc = input.loc;
  13862. const exp = input.content;
  13863. const inMatch = exp.match(forAliasRE);
  13864. if (!inMatch)
  13865. return;
  13866. const [, LHS, RHS] = inMatch;
  13867. const result = {
  13868. source: createAliasExpression(loc, RHS.trim(), exp.indexOf(RHS, LHS.length)),
  13869. value: undefined,
  13870. key: undefined,
  13871. index: undefined
  13872. };
  13873. {
  13874. validateBrowserExpression(result.source, context);
  13875. }
  13876. let valueContent = LHS.trim().replace(stripParensRE, '').trim();
  13877. const trimmedOffset = LHS.indexOf(valueContent);
  13878. const iteratorMatch = valueContent.match(forIteratorRE);
  13879. if (iteratorMatch) {
  13880. valueContent = valueContent.replace(forIteratorRE, '').trim();
  13881. const keyContent = iteratorMatch[1].trim();
  13882. let keyOffset;
  13883. if (keyContent) {
  13884. keyOffset = exp.indexOf(keyContent, trimmedOffset + valueContent.length);
  13885. result.key = createAliasExpression(loc, keyContent, keyOffset);
  13886. {
  13887. validateBrowserExpression(result.key, context, true);
  13888. }
  13889. }
  13890. if (iteratorMatch[2]) {
  13891. const indexContent = iteratorMatch[2].trim();
  13892. if (indexContent) {
  13893. result.index = createAliasExpression(loc, indexContent, exp.indexOf(indexContent, result.key
  13894. ? keyOffset + keyContent.length
  13895. : trimmedOffset + valueContent.length));
  13896. {
  13897. validateBrowserExpression(result.index, context, true);
  13898. }
  13899. }
  13900. }
  13901. }
  13902. if (valueContent) {
  13903. result.value = createAliasExpression(loc, valueContent, trimmedOffset);
  13904. {
  13905. validateBrowserExpression(result.value, context, true);
  13906. }
  13907. }
  13908. return result;
  13909. }
  13910. function createAliasExpression(range, content, offset) {
  13911. return createSimpleExpression(content, false, getInnerRange(range, offset, content.length));
  13912. }
  13913. function createForLoopParams({ value, key, index }, memoArgs = []) {
  13914. return createParamsList([value, key, index, ...memoArgs]);
  13915. }
  13916. function createParamsList(args) {
  13917. let i = args.length;
  13918. while (i--) {
  13919. if (args[i])
  13920. break;
  13921. }
  13922. return args
  13923. .slice(0, i + 1)
  13924. .map((arg, i) => arg || createSimpleExpression(`_`.repeat(i + 1), false));
  13925. }
  13926. const defaultFallback = createSimpleExpression(`undefined`, false);
  13927. // A NodeTransform that:
  13928. // 1. Tracks scope identifiers for scoped slots so that they don't get prefixed
  13929. // by transformExpression. This is only applied in non-browser builds with
  13930. // { prefixIdentifiers: true }.
  13931. // 2. Track v-slot depths so that we know a slot is inside another slot.
  13932. // Note the exit callback is executed before buildSlots() on the same node,
  13933. // so only nested slots see positive numbers.
  13934. const trackSlotScopes = (node, context) => {
  13935. if (node.type === 1 /* ELEMENT */ &&
  13936. (node.tagType === 1 /* COMPONENT */ ||
  13937. node.tagType === 3 /* TEMPLATE */)) {
  13938. // We are only checking non-empty v-slot here
  13939. // since we only care about slots that introduce scope variables.
  13940. const vSlot = findDir(node, 'slot');
  13941. if (vSlot) {
  13942. vSlot.exp;
  13943. context.scopes.vSlot++;
  13944. return () => {
  13945. context.scopes.vSlot--;
  13946. };
  13947. }
  13948. }
  13949. };
  13950. const buildClientSlotFn = (props, children, loc) => createFunctionExpression(props, children, false /* newline */, true /* isSlot */, children.length ? children[0].loc : loc);
  13951. // Instead of being a DirectiveTransform, v-slot processing is called during
  13952. // transformElement to build the slots object for a component.
  13953. function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
  13954. context.helper(WITH_CTX);
  13955. const { children, loc } = node;
  13956. const slotsProperties = [];
  13957. const dynamicSlots = [];
  13958. // If the slot is inside a v-for or another v-slot, force it to be dynamic
  13959. // since it likely uses a scope variable.
  13960. let hasDynamicSlots = context.scopes.vSlot > 0 || context.scopes.vFor > 0;
  13961. // 1. Check for slot with slotProps on component itself.
  13962. // <Comp v-slot="{ prop }"/>
  13963. const onComponentSlot = findDir(node, 'slot', true);
  13964. if (onComponentSlot) {
  13965. const { arg, exp } = onComponentSlot;
  13966. if (arg && !isStaticExp(arg)) {
  13967. hasDynamicSlots = true;
  13968. }
  13969. slotsProperties.push(createObjectProperty(arg || createSimpleExpression('default', true), buildSlotFn(exp, children, loc)));
  13970. }
  13971. // 2. Iterate through children and check for template slots
  13972. // <template v-slot:foo="{ prop }">
  13973. let hasTemplateSlots = false;
  13974. let hasNamedDefaultSlot = false;
  13975. const implicitDefaultChildren = [];
  13976. const seenSlotNames = new Set();
  13977. for (let i = 0; i < children.length; i++) {
  13978. const slotElement = children[i];
  13979. let slotDir;
  13980. if (!isTemplateNode(slotElement) ||
  13981. !(slotDir = findDir(slotElement, 'slot', true))) {
  13982. // not a <template v-slot>, skip.
  13983. if (slotElement.type !== 3 /* COMMENT */) {
  13984. implicitDefaultChildren.push(slotElement);
  13985. }
  13986. continue;
  13987. }
  13988. if (onComponentSlot) {
  13989. // already has on-component slot - this is incorrect usage.
  13990. context.onError(createCompilerError(37 /* X_V_SLOT_MIXED_SLOT_USAGE */, slotDir.loc));
  13991. break;
  13992. }
  13993. hasTemplateSlots = true;
  13994. const { children: slotChildren, loc: slotLoc } = slotElement;
  13995. const { arg: slotName = createSimpleExpression(`default`, true), exp: slotProps, loc: dirLoc } = slotDir;
  13996. // check if name is dynamic.
  13997. let staticSlotName;
  13998. if (isStaticExp(slotName)) {
  13999. staticSlotName = slotName ? slotName.content : `default`;
  14000. }
  14001. else {
  14002. hasDynamicSlots = true;
  14003. }
  14004. const slotFunction = buildSlotFn(slotProps, slotChildren, slotLoc);
  14005. // check if this slot is conditional (v-if/v-for)
  14006. let vIf;
  14007. let vElse;
  14008. let vFor;
  14009. if ((vIf = findDir(slotElement, 'if'))) {
  14010. hasDynamicSlots = true;
  14011. dynamicSlots.push(createConditionalExpression(vIf.exp, buildDynamicSlot(slotName, slotFunction), defaultFallback));
  14012. }
  14013. else if ((vElse = findDir(slotElement, /^else(-if)?$/, true /* allowEmpty */))) {
  14014. // find adjacent v-if
  14015. let j = i;
  14016. let prev;
  14017. while (j--) {
  14018. prev = children[j];
  14019. if (prev.type !== 3 /* COMMENT */) {
  14020. break;
  14021. }
  14022. }
  14023. if (prev && isTemplateNode(prev) && findDir(prev, 'if')) {
  14024. // remove node
  14025. children.splice(i, 1);
  14026. i--;
  14027. // attach this slot to previous conditional
  14028. let conditional = dynamicSlots[dynamicSlots.length - 1];
  14029. while (conditional.alternate.type === 19 /* JS_CONDITIONAL_EXPRESSION */) {
  14030. conditional = conditional.alternate;
  14031. }
  14032. conditional.alternate = vElse.exp
  14033. ? createConditionalExpression(vElse.exp, buildDynamicSlot(slotName, slotFunction), defaultFallback)
  14034. : buildDynamicSlot(slotName, slotFunction);
  14035. }
  14036. else {
  14037. context.onError(createCompilerError(30 /* X_V_ELSE_NO_ADJACENT_IF */, vElse.loc));
  14038. }
  14039. }
  14040. else if ((vFor = findDir(slotElement, 'for'))) {
  14041. hasDynamicSlots = true;
  14042. const parseResult = vFor.parseResult ||
  14043. parseForExpression(vFor.exp, context);
  14044. if (parseResult) {
  14045. // Render the dynamic slots as an array and add it to the createSlot()
  14046. // args. The runtime knows how to handle it appropriately.
  14047. dynamicSlots.push(createCallExpression(context.helper(RENDER_LIST), [
  14048. parseResult.source,
  14049. createFunctionExpression(createForLoopParams(parseResult), buildDynamicSlot(slotName, slotFunction), true /* force newline */)
  14050. ]));
  14051. }
  14052. else {
  14053. context.onError(createCompilerError(32 /* X_V_FOR_MALFORMED_EXPRESSION */, vFor.loc));
  14054. }
  14055. }
  14056. else {
  14057. // check duplicate static names
  14058. if (staticSlotName) {
  14059. if (seenSlotNames.has(staticSlotName)) {
  14060. context.onError(createCompilerError(38 /* X_V_SLOT_DUPLICATE_SLOT_NAMES */, dirLoc));
  14061. continue;
  14062. }
  14063. seenSlotNames.add(staticSlotName);
  14064. if (staticSlotName === 'default') {
  14065. hasNamedDefaultSlot = true;
  14066. }
  14067. }
  14068. slotsProperties.push(createObjectProperty(slotName, slotFunction));
  14069. }
  14070. }
  14071. if (!onComponentSlot) {
  14072. const buildDefaultSlotProperty = (props, children) => {
  14073. const fn = buildSlotFn(props, children, loc);
  14074. return createObjectProperty(`default`, fn);
  14075. };
  14076. if (!hasTemplateSlots) {
  14077. // implicit default slot (on component)
  14078. slotsProperties.push(buildDefaultSlotProperty(undefined, children));
  14079. }
  14080. else if (implicitDefaultChildren.length &&
  14081. // #3766
  14082. // with whitespace: 'preserve', whitespaces between slots will end up in
  14083. // implicitDefaultChildren. Ignore if all implicit children are whitespaces.
  14084. implicitDefaultChildren.some(node => isNonWhitespaceContent(node))) {
  14085. // implicit default slot (mixed with named slots)
  14086. if (hasNamedDefaultSlot) {
  14087. context.onError(createCompilerError(39 /* X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN */, implicitDefaultChildren[0].loc));
  14088. }
  14089. else {
  14090. slotsProperties.push(buildDefaultSlotProperty(undefined, implicitDefaultChildren));
  14091. }
  14092. }
  14093. }
  14094. const slotFlag = hasDynamicSlots
  14095. ? 2 /* DYNAMIC */
  14096. : hasForwardedSlots(node.children)
  14097. ? 3 /* FORWARDED */
  14098. : 1 /* STABLE */;
  14099. let slots = createObjectExpression(slotsProperties.concat(createObjectProperty(`_`,
  14100. // 2 = compiled but dynamic = can skip normalization, but must run diff
  14101. // 1 = compiled and static = can skip normalization AND diff as optimized
  14102. createSimpleExpression(slotFlag + (` /* ${slotFlagsText[slotFlag]} */` ), false))), loc);
  14103. if (dynamicSlots.length) {
  14104. slots = createCallExpression(context.helper(CREATE_SLOTS), [
  14105. slots,
  14106. createArrayExpression(dynamicSlots)
  14107. ]);
  14108. }
  14109. return {
  14110. slots,
  14111. hasDynamicSlots
  14112. };
  14113. }
  14114. function buildDynamicSlot(name, fn) {
  14115. return createObjectExpression([
  14116. createObjectProperty(`name`, name),
  14117. createObjectProperty(`fn`, fn)
  14118. ]);
  14119. }
  14120. function hasForwardedSlots(children) {
  14121. for (let i = 0; i < children.length; i++) {
  14122. const child = children[i];
  14123. switch (child.type) {
  14124. case 1 /* ELEMENT */:
  14125. if (child.tagType === 2 /* SLOT */ ||
  14126. hasForwardedSlots(child.children)) {
  14127. return true;
  14128. }
  14129. break;
  14130. case 9 /* IF */:
  14131. if (hasForwardedSlots(child.branches))
  14132. return true;
  14133. break;
  14134. case 10 /* IF_BRANCH */:
  14135. case 11 /* FOR */:
  14136. if (hasForwardedSlots(child.children))
  14137. return true;
  14138. break;
  14139. }
  14140. }
  14141. return false;
  14142. }
  14143. function isNonWhitespaceContent(node) {
  14144. if (node.type !== 2 /* TEXT */ && node.type !== 12 /* TEXT_CALL */)
  14145. return true;
  14146. return node.type === 2 /* TEXT */
  14147. ? !!node.content.trim()
  14148. : isNonWhitespaceContent(node.content);
  14149. }
  14150. // some directive transforms (e.g. v-model) may return a symbol for runtime
  14151. // import, which should be used instead of a resolveDirective call.
  14152. const directiveImportMap = new WeakMap();
  14153. // generate a JavaScript AST for this element's codegen
  14154. const transformElement = (node, context) => {
  14155. // perform the work on exit, after all child expressions have been
  14156. // processed and merged.
  14157. return function postTransformElement() {
  14158. node = context.currentNode;
  14159. if (!(node.type === 1 /* ELEMENT */ &&
  14160. (node.tagType === 0 /* ELEMENT */ ||
  14161. node.tagType === 1 /* COMPONENT */))) {
  14162. return;
  14163. }
  14164. const { tag, props } = node;
  14165. const isComponent = node.tagType === 1 /* COMPONENT */;
  14166. // The goal of the transform is to create a codegenNode implementing the
  14167. // VNodeCall interface.
  14168. let vnodeTag = isComponent
  14169. ? resolveComponentType(node, context)
  14170. : `"${tag}"`;
  14171. const isDynamicComponent = isObject(vnodeTag) && vnodeTag.callee === RESOLVE_DYNAMIC_COMPONENT;
  14172. let vnodeProps;
  14173. let vnodeChildren;
  14174. let vnodePatchFlag;
  14175. let patchFlag = 0;
  14176. let vnodeDynamicProps;
  14177. let dynamicPropNames;
  14178. let vnodeDirectives;
  14179. let shouldUseBlock =
  14180. // dynamic component may resolve to plain elements
  14181. isDynamicComponent ||
  14182. vnodeTag === TELEPORT ||
  14183. vnodeTag === SUSPENSE ||
  14184. (!isComponent &&
  14185. // <svg> and <foreignObject> must be forced into blocks so that block
  14186. // updates inside get proper isSVG flag at runtime. (#639, #643)
  14187. // This is technically web-specific, but splitting the logic out of core
  14188. // leads to too much unnecessary complexity.
  14189. (tag === 'svg' || tag === 'foreignObject'));
  14190. // props
  14191. if (props.length > 0) {
  14192. const propsBuildResult = buildProps(node, context, undefined, isComponent, isDynamicComponent);
  14193. vnodeProps = propsBuildResult.props;
  14194. patchFlag = propsBuildResult.patchFlag;
  14195. dynamicPropNames = propsBuildResult.dynamicPropNames;
  14196. const directives = propsBuildResult.directives;
  14197. vnodeDirectives =
  14198. directives && directives.length
  14199. ? createArrayExpression(directives.map(dir => buildDirectiveArgs(dir, context)))
  14200. : undefined;
  14201. if (propsBuildResult.shouldUseBlock) {
  14202. shouldUseBlock = true;
  14203. }
  14204. }
  14205. // children
  14206. if (node.children.length > 0) {
  14207. if (vnodeTag === KEEP_ALIVE) {
  14208. // Although a built-in component, we compile KeepAlive with raw children
  14209. // instead of slot functions so that it can be used inside Transition
  14210. // or other Transition-wrapping HOCs.
  14211. // To ensure correct updates with block optimizations, we need to:
  14212. // 1. Force keep-alive into a block. This avoids its children being
  14213. // collected by a parent block.
  14214. shouldUseBlock = true;
  14215. // 2. Force keep-alive to always be updated, since it uses raw children.
  14216. patchFlag |= 1024 /* DYNAMIC_SLOTS */;
  14217. if (node.children.length > 1) {
  14218. context.onError(createCompilerError(45 /* X_KEEP_ALIVE_INVALID_CHILDREN */, {
  14219. start: node.children[0].loc.start,
  14220. end: node.children[node.children.length - 1].loc.end,
  14221. source: ''
  14222. }));
  14223. }
  14224. }
  14225. const shouldBuildAsSlots = isComponent &&
  14226. // Teleport is not a real component and has dedicated runtime handling
  14227. vnodeTag !== TELEPORT &&
  14228. // explained above.
  14229. vnodeTag !== KEEP_ALIVE;
  14230. if (shouldBuildAsSlots) {
  14231. const { slots, hasDynamicSlots } = buildSlots(node, context);
  14232. vnodeChildren = slots;
  14233. if (hasDynamicSlots) {
  14234. patchFlag |= 1024 /* DYNAMIC_SLOTS */;
  14235. }
  14236. }
  14237. else if (node.children.length === 1 && vnodeTag !== TELEPORT) {
  14238. const child = node.children[0];
  14239. const type = child.type;
  14240. // check for dynamic text children
  14241. const hasDynamicTextChild = type === 5 /* INTERPOLATION */ ||
  14242. type === 8 /* COMPOUND_EXPRESSION */;
  14243. if (hasDynamicTextChild &&
  14244. getConstantType(child, context) === 0 /* NOT_CONSTANT */) {
  14245. patchFlag |= 1 /* TEXT */;
  14246. }
  14247. // pass directly if the only child is a text node
  14248. // (plain / interpolation / expression)
  14249. if (hasDynamicTextChild || type === 2 /* TEXT */) {
  14250. vnodeChildren = child;
  14251. }
  14252. else {
  14253. vnodeChildren = node.children;
  14254. }
  14255. }
  14256. else {
  14257. vnodeChildren = node.children;
  14258. }
  14259. }
  14260. // patchFlag & dynamicPropNames
  14261. if (patchFlag !== 0) {
  14262. {
  14263. if (patchFlag < 0) {
  14264. // special flags (negative and mutually exclusive)
  14265. vnodePatchFlag = patchFlag + ` /* ${PatchFlagNames[patchFlag]} */`;
  14266. }
  14267. else {
  14268. // bitwise flags
  14269. const flagNames = Object.keys(PatchFlagNames)
  14270. .map(Number)
  14271. .filter(n => n > 0 && patchFlag & n)
  14272. .map(n => PatchFlagNames[n])
  14273. .join(`, `);
  14274. vnodePatchFlag = patchFlag + ` /* ${flagNames} */`;
  14275. }
  14276. }
  14277. if (dynamicPropNames && dynamicPropNames.length) {
  14278. vnodeDynamicProps = stringifyDynamicPropNames(dynamicPropNames);
  14279. }
  14280. }
  14281. node.codegenNode = createVNodeCall(context, vnodeTag, vnodeProps, vnodeChildren, vnodePatchFlag, vnodeDynamicProps, vnodeDirectives, !!shouldUseBlock, false /* disableTracking */, isComponent, node.loc);
  14282. };
  14283. };
  14284. function resolveComponentType(node, context, ssr = false) {
  14285. let { tag } = node;
  14286. // 1. dynamic component
  14287. const isExplicitDynamic = isComponentTag(tag);
  14288. const isProp = findProp(node, 'is');
  14289. if (isProp) {
  14290. if (isExplicitDynamic ||
  14291. (false )) {
  14292. const exp = isProp.type === 6 /* ATTRIBUTE */
  14293. ? isProp.value && createSimpleExpression(isProp.value.content, true)
  14294. : isProp.exp;
  14295. if (exp) {
  14296. return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
  14297. exp
  14298. ]);
  14299. }
  14300. }
  14301. else if (isProp.type === 6 /* ATTRIBUTE */ &&
  14302. isProp.value.content.startsWith('vue:')) {
  14303. // <button is="vue:xxx">
  14304. // if not <component>, only is value that starts with "vue:" will be
  14305. // treated as component by the parse phase and reach here, unless it's
  14306. // compat mode where all is values are considered components
  14307. tag = isProp.value.content.slice(4);
  14308. }
  14309. }
  14310. // 1.5 v-is (TODO: Deprecate)
  14311. const isDir = !isExplicitDynamic && findDir(node, 'is');
  14312. if (isDir && isDir.exp) {
  14313. return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
  14314. isDir.exp
  14315. ]);
  14316. }
  14317. // 2. built-in components (Teleport, Transition, KeepAlive, Suspense...)
  14318. const builtIn = isCoreComponent(tag) || context.isBuiltInComponent(tag);
  14319. if (builtIn) {
  14320. // built-ins are simply fallthroughs / have special handling during ssr
  14321. // so we don't need to import their runtime equivalents
  14322. if (!ssr)
  14323. context.helper(builtIn);
  14324. return builtIn;
  14325. }
  14326. // 5. user component (resolve)
  14327. context.helper(RESOLVE_COMPONENT);
  14328. context.components.add(tag);
  14329. return toValidAssetId(tag, `component`);
  14330. }
  14331. function buildProps(node, context, props = node.props, isComponent, isDynamicComponent, ssr = false) {
  14332. const { tag, loc: elementLoc, children } = node;
  14333. let properties = [];
  14334. const mergeArgs = [];
  14335. const runtimeDirectives = [];
  14336. const hasChildren = children.length > 0;
  14337. let shouldUseBlock = false;
  14338. // patchFlag analysis
  14339. let patchFlag = 0;
  14340. let hasRef = false;
  14341. let hasClassBinding = false;
  14342. let hasStyleBinding = false;
  14343. let hasHydrationEventBinding = false;
  14344. let hasDynamicKeys = false;
  14345. let hasVnodeHook = false;
  14346. const dynamicPropNames = [];
  14347. const analyzePatchFlag = ({ key, value }) => {
  14348. if (isStaticExp(key)) {
  14349. const name = key.content;
  14350. const isEventHandler = isOn(name);
  14351. if (isEventHandler &&
  14352. (!isComponent || isDynamicComponent) &&
  14353. // omit the flag for click handlers because hydration gives click
  14354. // dedicated fast path.
  14355. name.toLowerCase() !== 'onclick' &&
  14356. // omit v-model handlers
  14357. name !== 'onUpdate:modelValue' &&
  14358. // omit onVnodeXXX hooks
  14359. !isReservedProp(name)) {
  14360. hasHydrationEventBinding = true;
  14361. }
  14362. if (isEventHandler && isReservedProp(name)) {
  14363. hasVnodeHook = true;
  14364. }
  14365. if (value.type === 20 /* JS_CACHE_EXPRESSION */ ||
  14366. ((value.type === 4 /* SIMPLE_EXPRESSION */ ||
  14367. value.type === 8 /* COMPOUND_EXPRESSION */) &&
  14368. getConstantType(value, context) > 0)) {
  14369. // skip if the prop is a cached handler or has constant value
  14370. return;
  14371. }
  14372. if (name === 'ref') {
  14373. hasRef = true;
  14374. }
  14375. else if (name === 'class') {
  14376. hasClassBinding = true;
  14377. }
  14378. else if (name === 'style') {
  14379. hasStyleBinding = true;
  14380. }
  14381. else if (name !== 'key' && !dynamicPropNames.includes(name)) {
  14382. dynamicPropNames.push(name);
  14383. }
  14384. // treat the dynamic class and style binding of the component as dynamic props
  14385. if (isComponent &&
  14386. (name === 'class' || name === 'style') &&
  14387. !dynamicPropNames.includes(name)) {
  14388. dynamicPropNames.push(name);
  14389. }
  14390. }
  14391. else {
  14392. hasDynamicKeys = true;
  14393. }
  14394. };
  14395. for (let i = 0; i < props.length; i++) {
  14396. // static attribute
  14397. const prop = props[i];
  14398. if (prop.type === 6 /* ATTRIBUTE */) {
  14399. const { loc, name, value } = prop;
  14400. let isStatic = true;
  14401. if (name === 'ref') {
  14402. hasRef = true;
  14403. if (context.scopes.vFor > 0) {
  14404. properties.push(createObjectProperty(createSimpleExpression('ref_for', true), createSimpleExpression('true')));
  14405. }
  14406. }
  14407. // skip is on <component>, or is="vue:xxx"
  14408. if (name === 'is' &&
  14409. (isComponentTag(tag) ||
  14410. (value && value.content.startsWith('vue:')) ||
  14411. (false ))) {
  14412. continue;
  14413. }
  14414. properties.push(createObjectProperty(createSimpleExpression(name, true, getInnerRange(loc, 0, name.length)), createSimpleExpression(value ? value.content : '', isStatic, value ? value.loc : loc)));
  14415. }
  14416. else {
  14417. // directives
  14418. const { name, arg, exp, loc } = prop;
  14419. const isVBind = name === 'bind';
  14420. const isVOn = name === 'on';
  14421. // skip v-slot - it is handled by its dedicated transform.
  14422. if (name === 'slot') {
  14423. if (!isComponent) {
  14424. context.onError(createCompilerError(40 /* X_V_SLOT_MISPLACED */, loc));
  14425. }
  14426. continue;
  14427. }
  14428. // skip v-once/v-memo - they are handled by dedicated transforms.
  14429. if (name === 'once' || name === 'memo') {
  14430. continue;
  14431. }
  14432. // skip v-is and :is on <component>
  14433. if (name === 'is' ||
  14434. (isVBind &&
  14435. isStaticArgOf(arg, 'is') &&
  14436. (isComponentTag(tag) ||
  14437. (false )))) {
  14438. continue;
  14439. }
  14440. // skip v-on in SSR compilation
  14441. if (isVOn && ssr) {
  14442. continue;
  14443. }
  14444. if (
  14445. // #938: elements with dynamic keys should be forced into blocks
  14446. (isVBind && isStaticArgOf(arg, 'key')) ||
  14447. // inline before-update hooks need to force block so that it is invoked
  14448. // before children
  14449. (isVOn && hasChildren && isStaticArgOf(arg, 'vue:before-update'))) {
  14450. shouldUseBlock = true;
  14451. }
  14452. if (isVBind && isStaticArgOf(arg, 'ref') && context.scopes.vFor > 0) {
  14453. properties.push(createObjectProperty(createSimpleExpression('ref_for', true), createSimpleExpression('true')));
  14454. }
  14455. // special case for v-bind and v-on with no argument
  14456. if (!arg && (isVBind || isVOn)) {
  14457. hasDynamicKeys = true;
  14458. if (exp) {
  14459. if (properties.length) {
  14460. mergeArgs.push(createObjectExpression(dedupeProperties(properties), elementLoc));
  14461. properties = [];
  14462. }
  14463. if (isVBind) {
  14464. mergeArgs.push(exp);
  14465. }
  14466. else {
  14467. // v-on="obj" -> toHandlers(obj)
  14468. mergeArgs.push({
  14469. type: 14 /* JS_CALL_EXPRESSION */,
  14470. loc,
  14471. callee: context.helper(TO_HANDLERS),
  14472. arguments: [exp]
  14473. });
  14474. }
  14475. }
  14476. else {
  14477. context.onError(createCompilerError(isVBind
  14478. ? 34 /* X_V_BIND_NO_EXPRESSION */
  14479. : 35 /* X_V_ON_NO_EXPRESSION */, loc));
  14480. }
  14481. continue;
  14482. }
  14483. const directiveTransform = context.directiveTransforms[name];
  14484. if (directiveTransform) {
  14485. // has built-in directive transform.
  14486. const { props, needRuntime } = directiveTransform(prop, node, context);
  14487. !ssr && props.forEach(analyzePatchFlag);
  14488. properties.push(...props);
  14489. if (needRuntime) {
  14490. runtimeDirectives.push(prop);
  14491. if (isSymbol(needRuntime)) {
  14492. directiveImportMap.set(prop, needRuntime);
  14493. }
  14494. }
  14495. }
  14496. else if (!isBuiltInDirective(name)) {
  14497. // no built-in transform, this is a user custom directive.
  14498. runtimeDirectives.push(prop);
  14499. // custom dirs may use beforeUpdate so they need to force blocks
  14500. // to ensure before-update gets called before children update
  14501. if (hasChildren) {
  14502. shouldUseBlock = true;
  14503. }
  14504. }
  14505. }
  14506. }
  14507. let propsExpression = undefined;
  14508. // has v-bind="object" or v-on="object", wrap with mergeProps
  14509. if (mergeArgs.length) {
  14510. if (properties.length) {
  14511. mergeArgs.push(createObjectExpression(dedupeProperties(properties), elementLoc));
  14512. }
  14513. if (mergeArgs.length > 1) {
  14514. propsExpression = createCallExpression(context.helper(MERGE_PROPS), mergeArgs, elementLoc);
  14515. }
  14516. else {
  14517. // single v-bind with nothing else - no need for a mergeProps call
  14518. propsExpression = mergeArgs[0];
  14519. }
  14520. }
  14521. else if (properties.length) {
  14522. propsExpression = createObjectExpression(dedupeProperties(properties), elementLoc);
  14523. }
  14524. // patchFlag analysis
  14525. if (hasDynamicKeys) {
  14526. patchFlag |= 16 /* FULL_PROPS */;
  14527. }
  14528. else {
  14529. if (hasClassBinding && !isComponent) {
  14530. patchFlag |= 2 /* CLASS */;
  14531. }
  14532. if (hasStyleBinding && !isComponent) {
  14533. patchFlag |= 4 /* STYLE */;
  14534. }
  14535. if (dynamicPropNames.length) {
  14536. patchFlag |= 8 /* PROPS */;
  14537. }
  14538. if (hasHydrationEventBinding) {
  14539. patchFlag |= 32 /* HYDRATE_EVENTS */;
  14540. }
  14541. }
  14542. if (!shouldUseBlock &&
  14543. (patchFlag === 0 || patchFlag === 32 /* HYDRATE_EVENTS */) &&
  14544. (hasRef || hasVnodeHook || runtimeDirectives.length > 0)) {
  14545. patchFlag |= 512 /* NEED_PATCH */;
  14546. }
  14547. // pre-normalize props, SSR is skipped for now
  14548. if (!context.inSSR && propsExpression) {
  14549. switch (propsExpression.type) {
  14550. case 15 /* JS_OBJECT_EXPRESSION */:
  14551. // means that there is no v-bind,
  14552. // but still need to deal with dynamic key binding
  14553. let classKeyIndex = -1;
  14554. let styleKeyIndex = -1;
  14555. let hasDynamicKey = false;
  14556. for (let i = 0; i < propsExpression.properties.length; i++) {
  14557. const key = propsExpression.properties[i].key;
  14558. if (isStaticExp(key)) {
  14559. if (key.content === 'class') {
  14560. classKeyIndex = i;
  14561. }
  14562. else if (key.content === 'style') {
  14563. styleKeyIndex = i;
  14564. }
  14565. }
  14566. else if (!key.isHandlerKey) {
  14567. hasDynamicKey = true;
  14568. }
  14569. }
  14570. const classProp = propsExpression.properties[classKeyIndex];
  14571. const styleProp = propsExpression.properties[styleKeyIndex];
  14572. // no dynamic key
  14573. if (!hasDynamicKey) {
  14574. if (classProp && !isStaticExp(classProp.value)) {
  14575. classProp.value = createCallExpression(context.helper(NORMALIZE_CLASS), [classProp.value]);
  14576. }
  14577. if (styleProp &&
  14578. // the static style is compiled into an object,
  14579. // so use `hasStyleBinding` to ensure that it is a dynamic style binding
  14580. (hasStyleBinding ||
  14581. (styleProp.value.type === 4 /* SIMPLE_EXPRESSION */ &&
  14582. styleProp.value.content.trim()[0] === `[`) ||
  14583. // v-bind:style and style both exist,
  14584. // v-bind:style with static literal object
  14585. styleProp.value.type === 17 /* JS_ARRAY_EXPRESSION */)) {
  14586. styleProp.value = createCallExpression(context.helper(NORMALIZE_STYLE), [styleProp.value]);
  14587. }
  14588. }
  14589. else {
  14590. // dynamic key binding, wrap with `normalizeProps`
  14591. propsExpression = createCallExpression(context.helper(NORMALIZE_PROPS), [propsExpression]);
  14592. }
  14593. break;
  14594. case 14 /* JS_CALL_EXPRESSION */:
  14595. // mergeProps call, do nothing
  14596. break;
  14597. default:
  14598. // single v-bind
  14599. propsExpression = createCallExpression(context.helper(NORMALIZE_PROPS), [
  14600. createCallExpression(context.helper(GUARD_REACTIVE_PROPS), [
  14601. propsExpression
  14602. ])
  14603. ]);
  14604. break;
  14605. }
  14606. }
  14607. return {
  14608. props: propsExpression,
  14609. directives: runtimeDirectives,
  14610. patchFlag,
  14611. dynamicPropNames,
  14612. shouldUseBlock
  14613. };
  14614. }
  14615. // Dedupe props in an object literal.
  14616. // Literal duplicated attributes would have been warned during the parse phase,
  14617. // however, it's possible to encounter duplicated `onXXX` handlers with different
  14618. // modifiers. We also need to merge static and dynamic class / style attributes.
  14619. // - onXXX handlers / style: merge into array
  14620. // - class: merge into single expression with concatenation
  14621. function dedupeProperties(properties) {
  14622. const knownProps = new Map();
  14623. const deduped = [];
  14624. for (let i = 0; i < properties.length; i++) {
  14625. const prop = properties[i];
  14626. // dynamic keys are always allowed
  14627. if (prop.key.type === 8 /* COMPOUND_EXPRESSION */ || !prop.key.isStatic) {
  14628. deduped.push(prop);
  14629. continue;
  14630. }
  14631. const name = prop.key.content;
  14632. const existing = knownProps.get(name);
  14633. if (existing) {
  14634. if (name === 'style' || name === 'class' || isOn(name)) {
  14635. mergeAsArray$1(existing, prop);
  14636. }
  14637. // unexpected duplicate, should have emitted error during parse
  14638. }
  14639. else {
  14640. knownProps.set(name, prop);
  14641. deduped.push(prop);
  14642. }
  14643. }
  14644. return deduped;
  14645. }
  14646. function mergeAsArray$1(existing, incoming) {
  14647. if (existing.value.type === 17 /* JS_ARRAY_EXPRESSION */) {
  14648. existing.value.elements.push(incoming.value);
  14649. }
  14650. else {
  14651. existing.value = createArrayExpression([existing.value, incoming.value], existing.loc);
  14652. }
  14653. }
  14654. function buildDirectiveArgs(dir, context) {
  14655. const dirArgs = [];
  14656. const runtime = directiveImportMap.get(dir);
  14657. if (runtime) {
  14658. // built-in directive with runtime
  14659. dirArgs.push(context.helperString(runtime));
  14660. }
  14661. else {
  14662. {
  14663. // inject statement for resolving directive
  14664. context.helper(RESOLVE_DIRECTIVE);
  14665. context.directives.add(dir.name);
  14666. dirArgs.push(toValidAssetId(dir.name, `directive`));
  14667. }
  14668. }
  14669. const { loc } = dir;
  14670. if (dir.exp)
  14671. dirArgs.push(dir.exp);
  14672. if (dir.arg) {
  14673. if (!dir.exp) {
  14674. dirArgs.push(`void 0`);
  14675. }
  14676. dirArgs.push(dir.arg);
  14677. }
  14678. if (Object.keys(dir.modifiers).length) {
  14679. if (!dir.arg) {
  14680. if (!dir.exp) {
  14681. dirArgs.push(`void 0`);
  14682. }
  14683. dirArgs.push(`void 0`);
  14684. }
  14685. const trueExpression = createSimpleExpression(`true`, false, loc);
  14686. dirArgs.push(createObjectExpression(dir.modifiers.map(modifier => createObjectProperty(modifier, trueExpression)), loc));
  14687. }
  14688. return createArrayExpression(dirArgs, dir.loc);
  14689. }
  14690. function stringifyDynamicPropNames(props) {
  14691. let propsNamesString = `[`;
  14692. for (let i = 0, l = props.length; i < l; i++) {
  14693. propsNamesString += JSON.stringify(props[i]);
  14694. if (i < l - 1)
  14695. propsNamesString += ', ';
  14696. }
  14697. return propsNamesString + `]`;
  14698. }
  14699. function isComponentTag(tag) {
  14700. return tag === 'component' || tag === 'Component';
  14701. }
  14702. const transformSlotOutlet = (node, context) => {
  14703. if (isSlotOutlet(node)) {
  14704. const { children, loc } = node;
  14705. const { slotName, slotProps } = processSlotOutlet(node, context);
  14706. const slotArgs = [
  14707. context.prefixIdentifiers ? `_ctx.$slots` : `$slots`,
  14708. slotName,
  14709. '{}',
  14710. 'undefined',
  14711. 'true'
  14712. ];
  14713. let expectedLen = 2;
  14714. if (slotProps) {
  14715. slotArgs[2] = slotProps;
  14716. expectedLen = 3;
  14717. }
  14718. if (children.length) {
  14719. slotArgs[3] = createFunctionExpression([], children, false, false, loc);
  14720. expectedLen = 4;
  14721. }
  14722. if (context.scopeId && !context.slotted) {
  14723. expectedLen = 5;
  14724. }
  14725. slotArgs.splice(expectedLen); // remove unused arguments
  14726. node.codegenNode = createCallExpression(context.helper(RENDER_SLOT), slotArgs, loc);
  14727. }
  14728. };
  14729. function processSlotOutlet(node, context) {
  14730. let slotName = `"default"`;
  14731. let slotProps = undefined;
  14732. const nonNameProps = [];
  14733. for (let i = 0; i < node.props.length; i++) {
  14734. const p = node.props[i];
  14735. if (p.type === 6 /* ATTRIBUTE */) {
  14736. if (p.value) {
  14737. if (p.name === 'name') {
  14738. slotName = JSON.stringify(p.value.content);
  14739. }
  14740. else {
  14741. p.name = camelize(p.name);
  14742. nonNameProps.push(p);
  14743. }
  14744. }
  14745. }
  14746. else {
  14747. if (p.name === 'bind' && isStaticArgOf(p.arg, 'name')) {
  14748. if (p.exp)
  14749. slotName = p.exp;
  14750. }
  14751. else {
  14752. if (p.name === 'bind' && p.arg && isStaticExp(p.arg)) {
  14753. p.arg.content = camelize(p.arg.content);
  14754. }
  14755. nonNameProps.push(p);
  14756. }
  14757. }
  14758. }
  14759. if (nonNameProps.length > 0) {
  14760. const { props, directives } = buildProps(node, context, nonNameProps, false, false);
  14761. slotProps = props;
  14762. if (directives.length) {
  14763. context.onError(createCompilerError(36 /* X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET */, directives[0].loc));
  14764. }
  14765. }
  14766. return {
  14767. slotName,
  14768. slotProps
  14769. };
  14770. }
  14771. const fnExpRE = /^\s*([\w$_]+|(async\s*)?\([^)]*?\))\s*=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/;
  14772. const transformOn = (dir, node, context, augmentor) => {
  14773. const { loc, modifiers, arg } = dir;
  14774. if (!dir.exp && !modifiers.length) {
  14775. context.onError(createCompilerError(35 /* X_V_ON_NO_EXPRESSION */, loc));
  14776. }
  14777. let eventName;
  14778. if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
  14779. if (arg.isStatic) {
  14780. let rawName = arg.content;
  14781. // TODO deprecate @vnodeXXX usage
  14782. if (rawName.startsWith('vue:')) {
  14783. rawName = `vnode-${rawName.slice(4)}`;
  14784. }
  14785. // for all event listeners, auto convert it to camelCase. See issue #2249
  14786. eventName = createSimpleExpression(toHandlerKey(camelize(rawName)), true, arg.loc);
  14787. }
  14788. else {
  14789. // #2388
  14790. eventName = createCompoundExpression([
  14791. `${context.helperString(TO_HANDLER_KEY)}(`,
  14792. arg,
  14793. `)`
  14794. ]);
  14795. }
  14796. }
  14797. else {
  14798. // already a compound expression.
  14799. eventName = arg;
  14800. eventName.children.unshift(`${context.helperString(TO_HANDLER_KEY)}(`);
  14801. eventName.children.push(`)`);
  14802. }
  14803. // handler processing
  14804. let exp = dir.exp;
  14805. if (exp && !exp.content.trim()) {
  14806. exp = undefined;
  14807. }
  14808. let shouldCache = context.cacheHandlers && !exp && !context.inVOnce;
  14809. if (exp) {
  14810. const isMemberExp = isMemberExpression(exp.content);
  14811. const isInlineStatement = !(isMemberExp || fnExpRE.test(exp.content));
  14812. const hasMultipleStatements = exp.content.includes(`;`);
  14813. {
  14814. validateBrowserExpression(exp, context, false, hasMultipleStatements);
  14815. }
  14816. if (isInlineStatement || (shouldCache && isMemberExp)) {
  14817. // wrap inline statement in a function expression
  14818. exp = createCompoundExpression([
  14819. `${isInlineStatement
  14820. ? `$event`
  14821. : `${``}(...args)`} => ${hasMultipleStatements ? `{` : `(`}`,
  14822. exp,
  14823. hasMultipleStatements ? `}` : `)`
  14824. ]);
  14825. }
  14826. }
  14827. let ret = {
  14828. props: [
  14829. createObjectProperty(eventName, exp || createSimpleExpression(`() => {}`, false, loc))
  14830. ]
  14831. };
  14832. // apply extended compiler augmentor
  14833. if (augmentor) {
  14834. ret = augmentor(ret);
  14835. }
  14836. if (shouldCache) {
  14837. // cache handlers so that it's always the same handler being passed down.
  14838. // this avoids unnecessary re-renders when users use inline handlers on
  14839. // components.
  14840. ret.props[0].value = context.cache(ret.props[0].value);
  14841. }
  14842. // mark the key as handler for props normalization check
  14843. ret.props.forEach(p => (p.key.isHandlerKey = true));
  14844. return ret;
  14845. };
  14846. // v-bind without arg is handled directly in ./transformElements.ts due to it affecting
  14847. // codegen for the entire props object. This transform here is only for v-bind
  14848. // *with* args.
  14849. const transformBind = (dir, _node, context) => {
  14850. const { exp, modifiers, loc } = dir;
  14851. const arg = dir.arg;
  14852. if (arg.type !== 4 /* SIMPLE_EXPRESSION */) {
  14853. arg.children.unshift(`(`);
  14854. arg.children.push(`) || ""`);
  14855. }
  14856. else if (!arg.isStatic) {
  14857. arg.content = `${arg.content} || ""`;
  14858. }
  14859. // .sync is replaced by v-model:arg
  14860. if (modifiers.includes('camel')) {
  14861. if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
  14862. if (arg.isStatic) {
  14863. arg.content = camelize(arg.content);
  14864. }
  14865. else {
  14866. arg.content = `${context.helperString(CAMELIZE)}(${arg.content})`;
  14867. }
  14868. }
  14869. else {
  14870. arg.children.unshift(`${context.helperString(CAMELIZE)}(`);
  14871. arg.children.push(`)`);
  14872. }
  14873. }
  14874. if (!context.inSSR) {
  14875. if (modifiers.includes('prop')) {
  14876. injectPrefix(arg, '.');
  14877. }
  14878. if (modifiers.includes('attr')) {
  14879. injectPrefix(arg, '^');
  14880. }
  14881. }
  14882. if (!exp ||
  14883. (exp.type === 4 /* SIMPLE_EXPRESSION */ && !exp.content.trim())) {
  14884. context.onError(createCompilerError(34 /* X_V_BIND_NO_EXPRESSION */, loc));
  14885. return {
  14886. props: [createObjectProperty(arg, createSimpleExpression('', true, loc))]
  14887. };
  14888. }
  14889. return {
  14890. props: [createObjectProperty(arg, exp)]
  14891. };
  14892. };
  14893. const injectPrefix = (arg, prefix) => {
  14894. if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
  14895. if (arg.isStatic) {
  14896. arg.content = prefix + arg.content;
  14897. }
  14898. else {
  14899. arg.content = `\`${prefix}\${${arg.content}}\``;
  14900. }
  14901. }
  14902. else {
  14903. arg.children.unshift(`'${prefix}' + (`);
  14904. arg.children.push(`)`);
  14905. }
  14906. };
  14907. // Merge adjacent text nodes and expressions into a single expression
  14908. // e.g. <div>abc {{ d }} {{ e }}</div> should have a single expression node as child.
  14909. const transformText = (node, context) => {
  14910. if (node.type === 0 /* ROOT */ ||
  14911. node.type === 1 /* ELEMENT */ ||
  14912. node.type === 11 /* FOR */ ||
  14913. node.type === 10 /* IF_BRANCH */) {
  14914. // perform the transform on node exit so that all expressions have already
  14915. // been processed.
  14916. return () => {
  14917. const children = node.children;
  14918. let currentContainer = undefined;
  14919. let hasText = false;
  14920. for (let i = 0; i < children.length; i++) {
  14921. const child = children[i];
  14922. if (isText(child)) {
  14923. hasText = true;
  14924. for (let j = i + 1; j < children.length; j++) {
  14925. const next = children[j];
  14926. if (isText(next)) {
  14927. if (!currentContainer) {
  14928. currentContainer = children[i] = createCompoundExpression([child], child.loc);
  14929. }
  14930. // merge adjacent text node into current
  14931. currentContainer.children.push(` + `, next);
  14932. children.splice(j, 1);
  14933. j--;
  14934. }
  14935. else {
  14936. currentContainer = undefined;
  14937. break;
  14938. }
  14939. }
  14940. }
  14941. }
  14942. if (!hasText ||
  14943. // if this is a plain element with a single text child, leave it
  14944. // as-is since the runtime has dedicated fast path for this by directly
  14945. // setting textContent of the element.
  14946. // for component root it's always normalized anyway.
  14947. (children.length === 1 &&
  14948. (node.type === 0 /* ROOT */ ||
  14949. (node.type === 1 /* ELEMENT */ &&
  14950. node.tagType === 0 /* ELEMENT */ &&
  14951. // #3756
  14952. // custom directives can potentially add DOM elements arbitrarily,
  14953. // we need to avoid setting textContent of the element at runtime
  14954. // to avoid accidentally overwriting the DOM elements added
  14955. // by the user through custom directives.
  14956. !node.props.find(p => p.type === 7 /* DIRECTIVE */ &&
  14957. !context.directiveTransforms[p.name]) &&
  14958. // in compat mode, <template> tags with no special directives
  14959. // will be rendered as a fragment so its children must be
  14960. // converted into vnodes.
  14961. !(false ))))) {
  14962. return;
  14963. }
  14964. // pre-convert text nodes into createTextVNode(text) calls to avoid
  14965. // runtime normalization.
  14966. for (let i = 0; i < children.length; i++) {
  14967. const child = children[i];
  14968. if (isText(child) || child.type === 8 /* COMPOUND_EXPRESSION */) {
  14969. const callArgs = [];
  14970. // createTextVNode defaults to single whitespace, so if it is a
  14971. // single space the code could be an empty call to save bytes.
  14972. if (child.type !== 2 /* TEXT */ || child.content !== ' ') {
  14973. callArgs.push(child);
  14974. }
  14975. // mark dynamic text with flag so it gets patched inside a block
  14976. if (!context.ssr &&
  14977. getConstantType(child, context) === 0 /* NOT_CONSTANT */) {
  14978. callArgs.push(1 /* TEXT */ +
  14979. (` /* ${PatchFlagNames[1 /* TEXT */]} */` ));
  14980. }
  14981. children[i] = {
  14982. type: 12 /* TEXT_CALL */,
  14983. content: child,
  14984. loc: child.loc,
  14985. codegenNode: createCallExpression(context.helper(CREATE_TEXT), callArgs)
  14986. };
  14987. }
  14988. }
  14989. };
  14990. }
  14991. };
  14992. const seen = new WeakSet();
  14993. const transformOnce = (node, context) => {
  14994. if (node.type === 1 /* ELEMENT */ && findDir(node, 'once', true)) {
  14995. if (seen.has(node) || context.inVOnce) {
  14996. return;
  14997. }
  14998. seen.add(node);
  14999. context.inVOnce = true;
  15000. context.helper(SET_BLOCK_TRACKING);
  15001. return () => {
  15002. context.inVOnce = false;
  15003. const cur = context.currentNode;
  15004. if (cur.codegenNode) {
  15005. cur.codegenNode = context.cache(cur.codegenNode, true /* isVNode */);
  15006. }
  15007. };
  15008. }
  15009. };
  15010. const transformModel = (dir, node, context) => {
  15011. const { exp, arg } = dir;
  15012. if (!exp) {
  15013. context.onError(createCompilerError(41 /* X_V_MODEL_NO_EXPRESSION */, dir.loc));
  15014. return createTransformProps();
  15015. }
  15016. const rawExp = exp.loc.source;
  15017. const expString = exp.type === 4 /* SIMPLE_EXPRESSION */ ? exp.content : rawExp;
  15018. // im SFC <script setup> inline mode, the exp may have been transformed into
  15019. // _unref(exp)
  15020. context.bindingMetadata[rawExp];
  15021. const maybeRef = !true /* SETUP_CONST */;
  15022. if (!expString.trim() ||
  15023. (!isMemberExpression(expString) && !maybeRef)) {
  15024. context.onError(createCompilerError(42 /* X_V_MODEL_MALFORMED_EXPRESSION */, exp.loc));
  15025. return createTransformProps();
  15026. }
  15027. const propName = arg ? arg : createSimpleExpression('modelValue', true);
  15028. const eventName = arg
  15029. ? isStaticExp(arg)
  15030. ? `onUpdate:${arg.content}`
  15031. : createCompoundExpression(['"onUpdate:" + ', arg])
  15032. : `onUpdate:modelValue`;
  15033. let assignmentExp;
  15034. const eventArg = context.isTS ? `($event: any)` : `$event`;
  15035. {
  15036. assignmentExp = createCompoundExpression([
  15037. `${eventArg} => ((`,
  15038. exp,
  15039. `) = $event)`
  15040. ]);
  15041. }
  15042. const props = [
  15043. // modelValue: foo
  15044. createObjectProperty(propName, dir.exp),
  15045. // "onUpdate:modelValue": $event => (foo = $event)
  15046. createObjectProperty(eventName, assignmentExp)
  15047. ];
  15048. // modelModifiers: { foo: true, "bar-baz": true }
  15049. if (dir.modifiers.length && node.tagType === 1 /* COMPONENT */) {
  15050. const modifiers = dir.modifiers
  15051. .map(m => (isSimpleIdentifier(m) ? m : JSON.stringify(m)) + `: true`)
  15052. .join(`, `);
  15053. const modifiersKey = arg
  15054. ? isStaticExp(arg)
  15055. ? `${arg.content}Modifiers`
  15056. : createCompoundExpression([arg, ' + "Modifiers"'])
  15057. : `modelModifiers`;
  15058. props.push(createObjectProperty(modifiersKey, createSimpleExpression(`{ ${modifiers} }`, false, dir.loc, 2 /* CAN_HOIST */)));
  15059. }
  15060. return createTransformProps(props);
  15061. };
  15062. function createTransformProps(props = []) {
  15063. return { props };
  15064. }
  15065. const seen$1 = new WeakSet();
  15066. const transformMemo = (node, context) => {
  15067. if (node.type === 1 /* ELEMENT */) {
  15068. const dir = findDir(node, 'memo');
  15069. if (!dir || seen$1.has(node)) {
  15070. return;
  15071. }
  15072. seen$1.add(node);
  15073. return () => {
  15074. const codegenNode = node.codegenNode ||
  15075. context.currentNode.codegenNode;
  15076. if (codegenNode && codegenNode.type === 13 /* VNODE_CALL */) {
  15077. // non-component sub tree should be turned into a block
  15078. if (node.tagType !== 1 /* COMPONENT */) {
  15079. makeBlock(codegenNode, context);
  15080. }
  15081. node.codegenNode = createCallExpression(context.helper(WITH_MEMO), [
  15082. dir.exp,
  15083. createFunctionExpression(undefined, codegenNode),
  15084. `_cache`,
  15085. String(context.cached++)
  15086. ]);
  15087. }
  15088. };
  15089. }
  15090. };
  15091. function getBaseTransformPreset(prefixIdentifiers) {
  15092. return [
  15093. [
  15094. transformOnce,
  15095. transformIf,
  15096. transformMemo,
  15097. transformFor,
  15098. ...([]),
  15099. ...([transformExpression]
  15100. ),
  15101. transformSlotOutlet,
  15102. transformElement,
  15103. trackSlotScopes,
  15104. transformText
  15105. ],
  15106. {
  15107. on: transformOn,
  15108. bind: transformBind,
  15109. model: transformModel
  15110. }
  15111. ];
  15112. }
  15113. // we name it `baseCompile` so that higher order compilers like
  15114. // @vue/compiler-dom can export `compile` while re-exporting everything else.
  15115. function baseCompile(template, options = {}) {
  15116. const onError = options.onError || defaultOnError;
  15117. const isModuleMode = options.mode === 'module';
  15118. /* istanbul ignore if */
  15119. {
  15120. if (options.prefixIdentifiers === true) {
  15121. onError(createCompilerError(46 /* X_PREFIX_ID_NOT_SUPPORTED */));
  15122. }
  15123. else if (isModuleMode) {
  15124. onError(createCompilerError(47 /* X_MODULE_MODE_NOT_SUPPORTED */));
  15125. }
  15126. }
  15127. const prefixIdentifiers = !true ;
  15128. if (options.cacheHandlers) {
  15129. onError(createCompilerError(48 /* X_CACHE_HANDLER_NOT_SUPPORTED */));
  15130. }
  15131. if (options.scopeId && !isModuleMode) {
  15132. onError(createCompilerError(49 /* X_SCOPE_ID_NOT_SUPPORTED */));
  15133. }
  15134. const ast = isString(template) ? baseParse(template, options) : template;
  15135. const [nodeTransforms, directiveTransforms] = getBaseTransformPreset();
  15136. transform(ast, extend({}, options, {
  15137. prefixIdentifiers,
  15138. nodeTransforms: [
  15139. ...nodeTransforms,
  15140. ...(options.nodeTransforms || []) // user transforms
  15141. ],
  15142. directiveTransforms: extend({}, directiveTransforms, options.directiveTransforms || {} // user transforms
  15143. )
  15144. }));
  15145. return generate(ast, extend({}, options, {
  15146. prefixIdentifiers
  15147. }));
  15148. }
  15149. const noopDirectiveTransform = () => ({ props: [] });
  15150. const V_MODEL_RADIO = Symbol(`vModelRadio` );
  15151. const V_MODEL_CHECKBOX = Symbol(`vModelCheckbox` );
  15152. const V_MODEL_TEXT = Symbol(`vModelText` );
  15153. const V_MODEL_SELECT = Symbol(`vModelSelect` );
  15154. const V_MODEL_DYNAMIC = Symbol(`vModelDynamic` );
  15155. const V_ON_WITH_MODIFIERS = Symbol(`vOnModifiersGuard` );
  15156. const V_ON_WITH_KEYS = Symbol(`vOnKeysGuard` );
  15157. const V_SHOW = Symbol(`vShow` );
  15158. const TRANSITION$1 = Symbol(`Transition` );
  15159. const TRANSITION_GROUP = Symbol(`TransitionGroup` );
  15160. registerRuntimeHelpers({
  15161. [V_MODEL_RADIO]: `vModelRadio`,
  15162. [V_MODEL_CHECKBOX]: `vModelCheckbox`,
  15163. [V_MODEL_TEXT]: `vModelText`,
  15164. [V_MODEL_SELECT]: `vModelSelect`,
  15165. [V_MODEL_DYNAMIC]: `vModelDynamic`,
  15166. [V_ON_WITH_MODIFIERS]: `withModifiers`,
  15167. [V_ON_WITH_KEYS]: `withKeys`,
  15168. [V_SHOW]: `vShow`,
  15169. [TRANSITION$1]: `Transition`,
  15170. [TRANSITION_GROUP]: `TransitionGroup`
  15171. });
  15172. /* eslint-disable no-restricted-globals */
  15173. let decoder;
  15174. function decodeHtmlBrowser(raw, asAttr = false) {
  15175. if (!decoder) {
  15176. decoder = document.createElement('div');
  15177. }
  15178. if (asAttr) {
  15179. decoder.innerHTML = `<div foo="${raw.replace(/"/g, '&quot;')}">`;
  15180. return decoder.children[0].getAttribute('foo');
  15181. }
  15182. else {
  15183. decoder.innerHTML = raw;
  15184. return decoder.textContent;
  15185. }
  15186. }
  15187. const isRawTextContainer = /*#__PURE__*/ makeMap('style,iframe,script,noscript', true);
  15188. const parserOptions = {
  15189. isVoidTag,
  15190. isNativeTag: tag => isHTMLTag(tag) || isSVGTag(tag),
  15191. isPreTag: tag => tag === 'pre',
  15192. decodeEntities: decodeHtmlBrowser ,
  15193. isBuiltInComponent: (tag) => {
  15194. if (isBuiltInType(tag, `Transition`)) {
  15195. return TRANSITION$1;
  15196. }
  15197. else if (isBuiltInType(tag, `TransitionGroup`)) {
  15198. return TRANSITION_GROUP;
  15199. }
  15200. },
  15201. // https://html.spec.whatwg.org/multipage/parsing.html#tree-construction-dispatcher
  15202. getNamespace(tag, parent) {
  15203. let ns = parent ? parent.ns : 0 /* HTML */;
  15204. if (parent && ns === 2 /* MATH_ML */) {
  15205. if (parent.tag === 'annotation-xml') {
  15206. if (tag === 'svg') {
  15207. return 1 /* SVG */;
  15208. }
  15209. if (parent.props.some(a => a.type === 6 /* ATTRIBUTE */ &&
  15210. a.name === 'encoding' &&
  15211. a.value != null &&
  15212. (a.value.content === 'text/html' ||
  15213. a.value.content === 'application/xhtml+xml'))) {
  15214. ns = 0 /* HTML */;
  15215. }
  15216. }
  15217. else if (/^m(?:[ions]|text)$/.test(parent.tag) &&
  15218. tag !== 'mglyph' &&
  15219. tag !== 'malignmark') {
  15220. ns = 0 /* HTML */;
  15221. }
  15222. }
  15223. else if (parent && ns === 1 /* SVG */) {
  15224. if (parent.tag === 'foreignObject' ||
  15225. parent.tag === 'desc' ||
  15226. parent.tag === 'title') {
  15227. ns = 0 /* HTML */;
  15228. }
  15229. }
  15230. if (ns === 0 /* HTML */) {
  15231. if (tag === 'svg') {
  15232. return 1 /* SVG */;
  15233. }
  15234. if (tag === 'math') {
  15235. return 2 /* MATH_ML */;
  15236. }
  15237. }
  15238. return ns;
  15239. },
  15240. // https://html.spec.whatwg.org/multipage/parsing.html#parsing-html-fragments
  15241. getTextMode({ tag, ns }) {
  15242. if (ns === 0 /* HTML */) {
  15243. if (tag === 'textarea' || tag === 'title') {
  15244. return 1 /* RCDATA */;
  15245. }
  15246. if (isRawTextContainer(tag)) {
  15247. return 2 /* RAWTEXT */;
  15248. }
  15249. }
  15250. return 0 /* DATA */;
  15251. }
  15252. };
  15253. // Parse inline CSS strings for static style attributes into an object.
  15254. // This is a NodeTransform since it works on the static `style` attribute and
  15255. // converts it into a dynamic equivalent:
  15256. // style="color: red" -> :style='{ "color": "red" }'
  15257. // It is then processed by `transformElement` and included in the generated
  15258. // props.
  15259. const transformStyle = node => {
  15260. if (node.type === 1 /* ELEMENT */) {
  15261. node.props.forEach((p, i) => {
  15262. if (p.type === 6 /* ATTRIBUTE */ && p.name === 'style' && p.value) {
  15263. // replace p with an expression node
  15264. node.props[i] = {
  15265. type: 7 /* DIRECTIVE */,
  15266. name: `bind`,
  15267. arg: createSimpleExpression(`style`, true, p.loc),
  15268. exp: parseInlineCSS(p.value.content, p.loc),
  15269. modifiers: [],
  15270. loc: p.loc
  15271. };
  15272. }
  15273. });
  15274. }
  15275. };
  15276. const parseInlineCSS = (cssText, loc) => {
  15277. const normalized = parseStringStyle(cssText);
  15278. return createSimpleExpression(JSON.stringify(normalized), false, loc, 3 /* CAN_STRINGIFY */);
  15279. };
  15280. function createDOMCompilerError(code, loc) {
  15281. return createCompilerError(code, loc, DOMErrorMessages );
  15282. }
  15283. const DOMErrorMessages = {
  15284. [50 /* X_V_HTML_NO_EXPRESSION */]: `v-html is missing expression.`,
  15285. [51 /* X_V_HTML_WITH_CHILDREN */]: `v-html will override element children.`,
  15286. [52 /* X_V_TEXT_NO_EXPRESSION */]: `v-text is missing expression.`,
  15287. [53 /* X_V_TEXT_WITH_CHILDREN */]: `v-text will override element children.`,
  15288. [54 /* X_V_MODEL_ON_INVALID_ELEMENT */]: `v-model can only be used on <input>, <textarea> and <select> elements.`,
  15289. [55 /* X_V_MODEL_ARG_ON_ELEMENT */]: `v-model argument is not supported on plain elements.`,
  15290. [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.`,
  15291. [57 /* X_V_MODEL_UNNECESSARY_VALUE */]: `Unnecessary value binding used alongside v-model. It will interfere with v-model's behavior.`,
  15292. [58 /* X_V_SHOW_NO_EXPRESSION */]: `v-show is missing expression.`,
  15293. [59 /* X_TRANSITION_INVALID_CHILDREN */]: `<Transition> expects exactly one child element or component.`,
  15294. [60 /* X_IGNORED_SIDE_EFFECT_TAG */]: `Tags with side effect (<script> and <style>) are ignored in client component templates.`
  15295. };
  15296. const transformVHtml = (dir, node, context) => {
  15297. const { exp, loc } = dir;
  15298. if (!exp) {
  15299. context.onError(createDOMCompilerError(50 /* X_V_HTML_NO_EXPRESSION */, loc));
  15300. }
  15301. if (node.children.length) {
  15302. context.onError(createDOMCompilerError(51 /* X_V_HTML_WITH_CHILDREN */, loc));
  15303. node.children.length = 0;
  15304. }
  15305. return {
  15306. props: [
  15307. createObjectProperty(createSimpleExpression(`innerHTML`, true, loc), exp || createSimpleExpression('', true))
  15308. ]
  15309. };
  15310. };
  15311. const transformVText = (dir, node, context) => {
  15312. const { exp, loc } = dir;
  15313. if (!exp) {
  15314. context.onError(createDOMCompilerError(52 /* X_V_TEXT_NO_EXPRESSION */, loc));
  15315. }
  15316. if (node.children.length) {
  15317. context.onError(createDOMCompilerError(53 /* X_V_TEXT_WITH_CHILDREN */, loc));
  15318. node.children.length = 0;
  15319. }
  15320. return {
  15321. props: [
  15322. createObjectProperty(createSimpleExpression(`textContent`, true), exp
  15323. ? getConstantType(exp, context) > 0
  15324. ? exp
  15325. : createCallExpression(context.helperString(TO_DISPLAY_STRING), [exp], loc)
  15326. : createSimpleExpression('', true))
  15327. ]
  15328. };
  15329. };
  15330. const transformModel$1 = (dir, node, context) => {
  15331. const baseResult = transformModel(dir, node, context);
  15332. // base transform has errors OR component v-model (only need props)
  15333. if (!baseResult.props.length || node.tagType === 1 /* COMPONENT */) {
  15334. return baseResult;
  15335. }
  15336. if (dir.arg) {
  15337. context.onError(createDOMCompilerError(55 /* X_V_MODEL_ARG_ON_ELEMENT */, dir.arg.loc));
  15338. }
  15339. function checkDuplicatedValue() {
  15340. const value = findProp(node, 'value');
  15341. if (value) {
  15342. context.onError(createDOMCompilerError(57 /* X_V_MODEL_UNNECESSARY_VALUE */, value.loc));
  15343. }
  15344. }
  15345. const { tag } = node;
  15346. const isCustomElement = context.isCustomElement(tag);
  15347. if (tag === 'input' ||
  15348. tag === 'textarea' ||
  15349. tag === 'select' ||
  15350. isCustomElement) {
  15351. let directiveToUse = V_MODEL_TEXT;
  15352. let isInvalidType = false;
  15353. if (tag === 'input' || isCustomElement) {
  15354. const type = findProp(node, `type`);
  15355. if (type) {
  15356. if (type.type === 7 /* DIRECTIVE */) {
  15357. // :type="foo"
  15358. directiveToUse = V_MODEL_DYNAMIC;
  15359. }
  15360. else if (type.value) {
  15361. switch (type.value.content) {
  15362. case 'radio':
  15363. directiveToUse = V_MODEL_RADIO;
  15364. break;
  15365. case 'checkbox':
  15366. directiveToUse = V_MODEL_CHECKBOX;
  15367. break;
  15368. case 'file':
  15369. isInvalidType = true;
  15370. context.onError(createDOMCompilerError(56 /* X_V_MODEL_ON_FILE_INPUT_ELEMENT */, dir.loc));
  15371. break;
  15372. default:
  15373. // text type
  15374. checkDuplicatedValue();
  15375. break;
  15376. }
  15377. }
  15378. }
  15379. else if (hasDynamicKeyVBind(node)) {
  15380. // element has bindings with dynamic keys, which can possibly contain
  15381. // "type".
  15382. directiveToUse = V_MODEL_DYNAMIC;
  15383. }
  15384. else {
  15385. // text type
  15386. checkDuplicatedValue();
  15387. }
  15388. }
  15389. else if (tag === 'select') {
  15390. directiveToUse = V_MODEL_SELECT;
  15391. }
  15392. else {
  15393. // textarea
  15394. checkDuplicatedValue();
  15395. }
  15396. // inject runtime directive
  15397. // by returning the helper symbol via needRuntime
  15398. // the import will replaced a resolveDirective call.
  15399. if (!isInvalidType) {
  15400. baseResult.needRuntime = context.helper(directiveToUse);
  15401. }
  15402. }
  15403. else {
  15404. context.onError(createDOMCompilerError(54 /* X_V_MODEL_ON_INVALID_ELEMENT */, dir.loc));
  15405. }
  15406. // native vmodel doesn't need the `modelValue` props since they are also
  15407. // passed to the runtime as `binding.value`. removing it reduces code size.
  15408. baseResult.props = baseResult.props.filter(p => !(p.key.type === 4 /* SIMPLE_EXPRESSION */ &&
  15409. p.key.content === 'modelValue'));
  15410. return baseResult;
  15411. };
  15412. const isEventOptionModifier = /*#__PURE__*/ makeMap(`passive,once,capture`);
  15413. const isNonKeyModifier = /*#__PURE__*/ makeMap(
  15414. // event propagation management
  15415. `stop,prevent,self,` +
  15416. // system modifiers + exact
  15417. `ctrl,shift,alt,meta,exact,` +
  15418. // mouse
  15419. `middle`);
  15420. // left & right could be mouse or key modifiers based on event type
  15421. const maybeKeyModifier = /*#__PURE__*/ makeMap('left,right');
  15422. const isKeyboardEvent = /*#__PURE__*/ makeMap(`onkeyup,onkeydown,onkeypress`, true);
  15423. const resolveModifiers = (key, modifiers, context, loc) => {
  15424. const keyModifiers = [];
  15425. const nonKeyModifiers = [];
  15426. const eventOptionModifiers = [];
  15427. for (let i = 0; i < modifiers.length; i++) {
  15428. const modifier = modifiers[i];
  15429. if (isEventOptionModifier(modifier)) {
  15430. // eventOptionModifiers: modifiers for addEventListener() options,
  15431. // e.g. .passive & .capture
  15432. eventOptionModifiers.push(modifier);
  15433. }
  15434. else {
  15435. // runtimeModifiers: modifiers that needs runtime guards
  15436. if (maybeKeyModifier(modifier)) {
  15437. if (isStaticExp(key)) {
  15438. if (isKeyboardEvent(key.content)) {
  15439. keyModifiers.push(modifier);
  15440. }
  15441. else {
  15442. nonKeyModifiers.push(modifier);
  15443. }
  15444. }
  15445. else {
  15446. keyModifiers.push(modifier);
  15447. nonKeyModifiers.push(modifier);
  15448. }
  15449. }
  15450. else {
  15451. if (isNonKeyModifier(modifier)) {
  15452. nonKeyModifiers.push(modifier);
  15453. }
  15454. else {
  15455. keyModifiers.push(modifier);
  15456. }
  15457. }
  15458. }
  15459. }
  15460. return {
  15461. keyModifiers,
  15462. nonKeyModifiers,
  15463. eventOptionModifiers
  15464. };
  15465. };
  15466. const transformClick = (key, event) => {
  15467. const isStaticClick = isStaticExp(key) && key.content.toLowerCase() === 'onclick';
  15468. return isStaticClick
  15469. ? createSimpleExpression(event, true)
  15470. : key.type !== 4 /* SIMPLE_EXPRESSION */
  15471. ? createCompoundExpression([
  15472. `(`,
  15473. key,
  15474. `) === "onClick" ? "${event}" : (`,
  15475. key,
  15476. `)`
  15477. ])
  15478. : key;
  15479. };
  15480. const transformOn$1 = (dir, node, context) => {
  15481. return transformOn(dir, node, context, baseResult => {
  15482. const { modifiers } = dir;
  15483. if (!modifiers.length)
  15484. return baseResult;
  15485. let { key, value: handlerExp } = baseResult.props[0];
  15486. const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = resolveModifiers(key, modifiers, context, dir.loc);
  15487. // normalize click.right and click.middle since they don't actually fire
  15488. if (nonKeyModifiers.includes('right')) {
  15489. key = transformClick(key, `onContextmenu`);
  15490. }
  15491. if (nonKeyModifiers.includes('middle')) {
  15492. key = transformClick(key, `onMouseup`);
  15493. }
  15494. if (nonKeyModifiers.length) {
  15495. handlerExp = createCallExpression(context.helper(V_ON_WITH_MODIFIERS), [
  15496. handlerExp,
  15497. JSON.stringify(nonKeyModifiers)
  15498. ]);
  15499. }
  15500. if (keyModifiers.length &&
  15501. // if event name is dynamic, always wrap with keys guard
  15502. (!isStaticExp(key) || isKeyboardEvent(key.content))) {
  15503. handlerExp = createCallExpression(context.helper(V_ON_WITH_KEYS), [
  15504. handlerExp,
  15505. JSON.stringify(keyModifiers)
  15506. ]);
  15507. }
  15508. if (eventOptionModifiers.length) {
  15509. const modifierPostfix = eventOptionModifiers.map(capitalize).join('');
  15510. key = isStaticExp(key)
  15511. ? createSimpleExpression(`${key.content}${modifierPostfix}`, true)
  15512. : createCompoundExpression([`(`, key, `) + "${modifierPostfix}"`]);
  15513. }
  15514. return {
  15515. props: [createObjectProperty(key, handlerExp)]
  15516. };
  15517. });
  15518. };
  15519. const transformShow = (dir, node, context) => {
  15520. const { exp, loc } = dir;
  15521. if (!exp) {
  15522. context.onError(createDOMCompilerError(58 /* X_V_SHOW_NO_EXPRESSION */, loc));
  15523. }
  15524. return {
  15525. props: [],
  15526. needRuntime: context.helper(V_SHOW)
  15527. };
  15528. };
  15529. const transformTransition = (node, context) => {
  15530. if (node.type === 1 /* ELEMENT */ &&
  15531. node.tagType === 1 /* COMPONENT */) {
  15532. const component = context.isBuiltInComponent(node.tag);
  15533. if (component === TRANSITION$1) {
  15534. return () => {
  15535. if (!node.children.length) {
  15536. return;
  15537. }
  15538. // warn multiple transition children
  15539. if (hasMultipleChildren(node)) {
  15540. context.onError(createDOMCompilerError(59 /* X_TRANSITION_INVALID_CHILDREN */, {
  15541. start: node.children[0].loc.start,
  15542. end: node.children[node.children.length - 1].loc.end,
  15543. source: ''
  15544. }));
  15545. }
  15546. // check if it's s single child w/ v-show
  15547. // if yes, inject "persisted: true" to the transition props
  15548. const child = node.children[0];
  15549. if (child.type === 1 /* ELEMENT */) {
  15550. for (const p of child.props) {
  15551. if (p.type === 7 /* DIRECTIVE */ && p.name === 'show') {
  15552. node.props.push({
  15553. type: 6 /* ATTRIBUTE */,
  15554. name: 'persisted',
  15555. value: undefined,
  15556. loc: node.loc
  15557. });
  15558. }
  15559. }
  15560. }
  15561. };
  15562. }
  15563. }
  15564. };
  15565. function hasMultipleChildren(node) {
  15566. // #1352 filter out potential comment nodes.
  15567. const children = (node.children = node.children.filter(c => c.type !== 3 /* COMMENT */ &&
  15568. !(c.type === 2 /* TEXT */ && !c.content.trim())));
  15569. const child = children[0];
  15570. return (children.length !== 1 ||
  15571. child.type === 11 /* FOR */ ||
  15572. (child.type === 9 /* IF */ && child.branches.some(hasMultipleChildren)));
  15573. }
  15574. const ignoreSideEffectTags = (node, context) => {
  15575. if (node.type === 1 /* ELEMENT */ &&
  15576. node.tagType === 0 /* ELEMENT */ &&
  15577. (node.tag === 'script' || node.tag === 'style')) {
  15578. context.onError(createDOMCompilerError(60 /* X_IGNORED_SIDE_EFFECT_TAG */, node.loc));
  15579. context.removeNode();
  15580. }
  15581. };
  15582. const DOMNodeTransforms = [
  15583. transformStyle,
  15584. ...([transformTransition] )
  15585. ];
  15586. const DOMDirectiveTransforms = {
  15587. cloak: noopDirectiveTransform,
  15588. html: transformVHtml,
  15589. text: transformVText,
  15590. model: transformModel$1,
  15591. on: transformOn$1,
  15592. show: transformShow
  15593. };
  15594. function compile$1(template, options = {}) {
  15595. return baseCompile(template, extend({}, parserOptions, options, {
  15596. nodeTransforms: [
  15597. // ignore <script> and <tag>
  15598. // this is not put inside DOMNodeTransforms because that list is used
  15599. // by compiler-ssr to generate vnode fallback branches
  15600. ignoreSideEffectTags,
  15601. ...DOMNodeTransforms,
  15602. ...(options.nodeTransforms || [])
  15603. ],
  15604. directiveTransforms: extend({}, DOMDirectiveTransforms, options.directiveTransforms || {}),
  15605. transformHoist: null
  15606. }));
  15607. }
  15608. // This entry is the "full-build" that includes both the runtime
  15609. {
  15610. initDev();
  15611. }
  15612. const compileCache = Object.create(null);
  15613. function compileToFunction(template, options) {
  15614. if (!isString(template)) {
  15615. if (template.nodeType) {
  15616. template = template.innerHTML;
  15617. }
  15618. else {
  15619. warn$1(`invalid template option: `, template);
  15620. return NOOP;
  15621. }
  15622. }
  15623. const key = template;
  15624. const cached = compileCache[key];
  15625. if (cached) {
  15626. return cached;
  15627. }
  15628. if (template[0] === '#') {
  15629. const el = document.querySelector(template);
  15630. if (!el) {
  15631. warn$1(`Template element not found or is empty: ${template}`);
  15632. }
  15633. // __UNSAFE__
  15634. // Reason: potential execution of JS expressions in in-DOM template.
  15635. // The user must make sure the in-DOM template is trusted. If it's rendered
  15636. // by the server, the template should not contain any user data.
  15637. template = el ? el.innerHTML : ``;
  15638. }
  15639. const { code } = compile$1(template, extend({
  15640. hoistStatic: true,
  15641. onError: onError ,
  15642. onWarn: e => onError(e, true)
  15643. }, options));
  15644. function onError(err, asWarning = false) {
  15645. const message = asWarning
  15646. ? err.message
  15647. : `Template compilation error: ${err.message}`;
  15648. const codeFrame = err.loc &&
  15649. generateCodeFrame(template, err.loc.start.offset, err.loc.end.offset);
  15650. warn$1(codeFrame ? `${message}\n${codeFrame}` : message);
  15651. }
  15652. // The wildcard import results in a huge object with every export
  15653. // with keys that cannot be mangled, and can be quite heavy size-wise.
  15654. // In the global build we know `Vue` is available globally so we can avoid
  15655. // the wildcard object.
  15656. const render = (new Function(code)() );
  15657. render._rc = true;
  15658. return (compileCache[key] = render);
  15659. }
  15660. registerRuntimeCompiler(compileToFunction);
  15661. exports.BaseTransition = BaseTransition;
  15662. exports.Comment = Comment;
  15663. exports.EffectScope = EffectScope;
  15664. exports.Fragment = Fragment;
  15665. exports.KeepAlive = KeepAlive;
  15666. exports.ReactiveEffect = ReactiveEffect;
  15667. exports.Static = Static;
  15668. exports.Suspense = Suspense;
  15669. exports.Teleport = Teleport;
  15670. exports.Text = Text;
  15671. exports.Transition = Transition;
  15672. exports.TransitionGroup = TransitionGroup;
  15673. exports.VueElement = VueElement;
  15674. exports.callWithAsyncErrorHandling = callWithAsyncErrorHandling;
  15675. exports.callWithErrorHandling = callWithErrorHandling;
  15676. exports.camelize = camelize;
  15677. exports.capitalize = capitalize;
  15678. exports.cloneVNode = cloneVNode;
  15679. exports.compatUtils = compatUtils;
  15680. exports.compile = compileToFunction;
  15681. exports.computed = computed$1;
  15682. exports.createApp = createApp;
  15683. exports.createBlock = createBlock;
  15684. exports.createCommentVNode = createCommentVNode;
  15685. exports.createElementBlock = createElementBlock;
  15686. exports.createElementVNode = createBaseVNode;
  15687. exports.createHydrationRenderer = createHydrationRenderer;
  15688. exports.createPropsRestProxy = createPropsRestProxy;
  15689. exports.createRenderer = createRenderer;
  15690. exports.createSSRApp = createSSRApp;
  15691. exports.createSlots = createSlots;
  15692. exports.createStaticVNode = createStaticVNode;
  15693. exports.createTextVNode = createTextVNode;
  15694. exports.createVNode = createVNode;
  15695. exports.customRef = customRef;
  15696. exports.defineAsyncComponent = defineAsyncComponent;
  15697. exports.defineComponent = defineComponent;
  15698. exports.defineCustomElement = defineCustomElement;
  15699. exports.defineEmits = defineEmits;
  15700. exports.defineExpose = defineExpose;
  15701. exports.defineProps = defineProps;
  15702. exports.defineSSRCustomElement = defineSSRCustomElement;
  15703. exports.effect = effect;
  15704. exports.effectScope = effectScope;
  15705. exports.getCurrentInstance = getCurrentInstance;
  15706. exports.getCurrentScope = getCurrentScope;
  15707. exports.getTransitionRawChildren = getTransitionRawChildren;
  15708. exports.guardReactiveProps = guardReactiveProps;
  15709. exports.h = h;
  15710. exports.handleError = handleError;
  15711. exports.hydrate = hydrate;
  15712. exports.initCustomFormatter = initCustomFormatter;
  15713. exports.initDirectivesForSSR = initDirectivesForSSR;
  15714. exports.inject = inject;
  15715. exports.isMemoSame = isMemoSame;
  15716. exports.isProxy = isProxy;
  15717. exports.isReactive = isReactive;
  15718. exports.isReadonly = isReadonly;
  15719. exports.isRef = isRef;
  15720. exports.isRuntimeOnly = isRuntimeOnly;
  15721. exports.isShallow = isShallow;
  15722. exports.isVNode = isVNode;
  15723. exports.markRaw = markRaw;
  15724. exports.mergeDefaults = mergeDefaults;
  15725. exports.mergeProps = mergeProps;
  15726. exports.nextTick = nextTick;
  15727. exports.normalizeClass = normalizeClass;
  15728. exports.normalizeProps = normalizeProps;
  15729. exports.normalizeStyle = normalizeStyle;
  15730. exports.onActivated = onActivated;
  15731. exports.onBeforeMount = onBeforeMount;
  15732. exports.onBeforeUnmount = onBeforeUnmount;
  15733. exports.onBeforeUpdate = onBeforeUpdate;
  15734. exports.onDeactivated = onDeactivated;
  15735. exports.onErrorCaptured = onErrorCaptured;
  15736. exports.onMounted = onMounted;
  15737. exports.onRenderTracked = onRenderTracked;
  15738. exports.onRenderTriggered = onRenderTriggered;
  15739. exports.onScopeDispose = onScopeDispose;
  15740. exports.onServerPrefetch = onServerPrefetch;
  15741. exports.onUnmounted = onUnmounted;
  15742. exports.onUpdated = onUpdated;
  15743. exports.openBlock = openBlock;
  15744. exports.popScopeId = popScopeId;
  15745. exports.provide = provide;
  15746. exports.proxyRefs = proxyRefs;
  15747. exports.pushScopeId = pushScopeId;
  15748. exports.queuePostFlushCb = queuePostFlushCb;
  15749. exports.reactive = reactive;
  15750. exports.readonly = readonly;
  15751. exports.ref = ref;
  15752. exports.registerRuntimeCompiler = registerRuntimeCompiler;
  15753. exports.render = render;
  15754. exports.renderList = renderList;
  15755. exports.renderSlot = renderSlot;
  15756. exports.resolveComponent = resolveComponent;
  15757. exports.resolveDirective = resolveDirective;
  15758. exports.resolveDynamicComponent = resolveDynamicComponent;
  15759. exports.resolveFilter = resolveFilter;
  15760. exports.resolveTransitionHooks = resolveTransitionHooks;
  15761. exports.setBlockTracking = setBlockTracking;
  15762. exports.setDevtoolsHook = setDevtoolsHook;
  15763. exports.setTransitionHooks = setTransitionHooks;
  15764. exports.shallowReactive = shallowReactive;
  15765. exports.shallowReadonly = shallowReadonly;
  15766. exports.shallowRef = shallowRef;
  15767. exports.ssrContextKey = ssrContextKey;
  15768. exports.ssrUtils = ssrUtils;
  15769. exports.stop = stop;
  15770. exports.toDisplayString = toDisplayString;
  15771. exports.toHandlerKey = toHandlerKey;
  15772. exports.toHandlers = toHandlers;
  15773. exports.toRaw = toRaw;
  15774. exports.toRef = toRef;
  15775. exports.toRefs = toRefs;
  15776. exports.transformVNodeArgs = transformVNodeArgs;
  15777. exports.triggerRef = triggerRef;
  15778. exports.unref = unref;
  15779. exports.useAttrs = useAttrs;
  15780. exports.useCssModule = useCssModule;
  15781. exports.useCssVars = useCssVars;
  15782. exports.useSSRContext = useSSRContext;
  15783. exports.useSlots = useSlots;
  15784. exports.useTransitionState = useTransitionState;
  15785. exports.vModelCheckbox = vModelCheckbox;
  15786. exports.vModelDynamic = vModelDynamic;
  15787. exports.vModelRadio = vModelRadio;
  15788. exports.vModelSelect = vModelSelect;
  15789. exports.vModelText = vModelText;
  15790. exports.vShow = vShow;
  15791. exports.version = version;
  15792. exports.warn = warn$1;
  15793. exports.watch = watch;
  15794. exports.watchEffect = watchEffect;
  15795. exports.watchPostEffect = watchPostEffect;
  15796. exports.watchSyncEffect = watchSyncEffect;
  15797. exports.withAsyncContext = withAsyncContext;
  15798. exports.withCtx = withCtx;
  15799. exports.withDefaults = withDefaults;
  15800. exports.withDirectives = withDirectives;
  15801. exports.withKeys = withKeys;
  15802. exports.withMemo = withMemo;
  15803. exports.withModifiers = withModifiers;
  15804. exports.withScopeId = withScopeId;
  15805. Object.defineProperty(exports, '__esModule', { value: true });
  15806. return exports;
  15807. }({}));