runtime-core.esm-bundler.js 304 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717
  1. import { toRaw, ref, pauseTracking, resetTracking, reactive, computed, isRef, shallowReactive, trigger, ReactiveEffect, isProxy, shallowReadonly, track, EffectScope, markRaw, proxyRefs, isReactive, isReadonly } from '@vue/reactivity';
  2. export { EffectScope, ReactiveEffect, computed, customRef, effect, effectScope, getCurrentScope, isProxy, isReactive, isReadonly, isRef, markRaw, onScopeDispose, proxyRefs, reactive, readonly, ref, shallowReactive, shallowReadonly, shallowRef, stop, toRaw, toRef, toRefs, triggerRef, unref } from '@vue/reactivity';
  3. import { getGlobalThis, extend, EMPTY_OBJ, toHandlerKey, isFunction, toNumber, hyphenate, camelize, isArray, isOn, hasOwn, isModelListener, isObject, remove, isString, invokeArrayFns, isPromise, NOOP, def, isReservedProp, EMPTY_ARR, capitalize, toRawType, makeMap, NO, normalizeClass, normalizeStyle, isGloballyWhitelisted, hasChanged, isSet, isMap, isPlainObject } from '@vue/shared';
  4. export { camelize, capitalize, normalizeClass, normalizeProps, normalizeStyle, toDisplayString, toHandlerKey } from '@vue/shared';
  5. /* eslint-disable no-restricted-globals */
  6. let isHmrUpdating = false;
  7. const hmrDirtyComponents = new Set();
  8. // Expose the HMR runtime on the global object
  9. // This makes it entirely tree-shakable without polluting the exports and makes
  10. // it easier to be used in toolings like vue-loader
  11. // Note: for a component to be eligible for HMR it also needs the __hmrId option
  12. // to be set so that its instances can be registered / removed.
  13. if ((process.env.NODE_ENV !== 'production')) {
  14. getGlobalThis().__VUE_HMR_RUNTIME__ = {
  15. createRecord: tryWrap(createRecord),
  16. rerender: tryWrap(rerender),
  17. reload: tryWrap(reload)
  18. };
  19. }
  20. const map = new Map();
  21. function registerHMR(instance) {
  22. const id = instance.type.__hmrId;
  23. let record = map.get(id);
  24. if (!record) {
  25. createRecord(id, instance.type);
  26. record = map.get(id);
  27. }
  28. record.instances.add(instance);
  29. }
  30. function unregisterHMR(instance) {
  31. map.get(instance.type.__hmrId).instances.delete(instance);
  32. }
  33. function createRecord(id, initialDef) {
  34. if (map.has(id)) {
  35. return false;
  36. }
  37. map.set(id, {
  38. initialDef: normalizeClassComponent(initialDef),
  39. instances: new Set()
  40. });
  41. return true;
  42. }
  43. function normalizeClassComponent(component) {
  44. return isClassComponent(component) ? component.__vccOpts : component;
  45. }
  46. function rerender(id, newRender) {
  47. const record = map.get(id);
  48. if (!record) {
  49. return;
  50. }
  51. // update initial record (for not-yet-rendered component)
  52. record.initialDef.render = newRender;
  53. [...record.instances].forEach(instance => {
  54. if (newRender) {
  55. instance.render = newRender;
  56. normalizeClassComponent(instance.type).render = newRender;
  57. }
  58. instance.renderCache = [];
  59. // this flag forces child components with slot content to update
  60. isHmrUpdating = true;
  61. instance.update();
  62. isHmrUpdating = false;
  63. });
  64. }
  65. function reload(id, newComp) {
  66. const record = map.get(id);
  67. if (!record)
  68. return;
  69. newComp = normalizeClassComponent(newComp);
  70. // update initial def (for not-yet-rendered components)
  71. updateComponentDef(record.initialDef, newComp);
  72. // create a snapshot which avoids the set being mutated during updates
  73. const instances = [...record.instances];
  74. for (const instance of instances) {
  75. const oldComp = normalizeClassComponent(instance.type);
  76. if (!hmrDirtyComponents.has(oldComp)) {
  77. // 1. Update existing comp definition to match new one
  78. if (oldComp !== record.initialDef) {
  79. updateComponentDef(oldComp, newComp);
  80. }
  81. // 2. mark definition dirty. This forces the renderer to replace the
  82. // component on patch.
  83. hmrDirtyComponents.add(oldComp);
  84. }
  85. // 3. invalidate options resolution cache
  86. instance.appContext.optionsCache.delete(instance.type);
  87. // 4. actually update
  88. if (instance.ceReload) {
  89. // custom element
  90. hmrDirtyComponents.add(oldComp);
  91. instance.ceReload(newComp.styles);
  92. hmrDirtyComponents.delete(oldComp);
  93. }
  94. else if (instance.parent) {
  95. // 4. Force the parent instance to re-render. This will cause all updated
  96. // components to be unmounted and re-mounted. Queue the update so that we
  97. // don't end up forcing the same parent to re-render multiple times.
  98. queueJob(instance.parent.update);
  99. // instance is the inner component of an async custom element
  100. // invoke to reset styles
  101. if (instance.parent.type.__asyncLoader &&
  102. instance.parent.ceReload) {
  103. instance.parent.ceReload(newComp.styles);
  104. }
  105. }
  106. else if (instance.appContext.reload) {
  107. // root instance mounted via createApp() has a reload method
  108. instance.appContext.reload();
  109. }
  110. else if (typeof window !== 'undefined') {
  111. // root instance inside tree created via raw render(). Force reload.
  112. window.location.reload();
  113. }
  114. else {
  115. console.warn('[HMR] Root or manually mounted instance modified. Full reload required.');
  116. }
  117. }
  118. // 5. make sure to cleanup dirty hmr components after update
  119. queuePostFlushCb(() => {
  120. for (const instance of instances) {
  121. hmrDirtyComponents.delete(normalizeClassComponent(instance.type));
  122. }
  123. });
  124. }
  125. function updateComponentDef(oldComp, newComp) {
  126. extend(oldComp, newComp);
  127. for (const key in oldComp) {
  128. if (key !== '__file' && !(key in newComp)) {
  129. delete oldComp[key];
  130. }
  131. }
  132. }
  133. function tryWrap(fn) {
  134. return (id, arg) => {
  135. try {
  136. return fn(id, arg);
  137. }
  138. catch (e) {
  139. console.error(e);
  140. console.warn(`[HMR] Something went wrong during Vue component hot-reload. ` +
  141. `Full reload required.`);
  142. }
  143. };
  144. }
  145. let devtools;
  146. let buffer = [];
  147. let devtoolsNotInstalled = false;
  148. function emit(event, ...args) {
  149. if (devtools) {
  150. devtools.emit(event, ...args);
  151. }
  152. else if (!devtoolsNotInstalled) {
  153. buffer.push({ event, args });
  154. }
  155. }
  156. function setDevtoolsHook(hook, target) {
  157. var _a, _b;
  158. devtools = hook;
  159. if (devtools) {
  160. devtools.enabled = true;
  161. buffer.forEach(({ event, args }) => devtools.emit(event, ...args));
  162. buffer = [];
  163. }
  164. else if (
  165. // handle late devtools injection - only do this if we are in an actual
  166. // browser environment to avoid the timer handle stalling test runner exit
  167. // (#4815)
  168. // eslint-disable-next-line no-restricted-globals
  169. typeof window !== 'undefined' &&
  170. // some envs mock window but not fully
  171. window.HTMLElement &&
  172. // also exclude jsdom
  173. !((_b = (_a = window.navigator) === null || _a === void 0 ? void 0 : _a.userAgent) === null || _b === void 0 ? void 0 : _b.includes('jsdom'))) {
  174. const replay = (target.__VUE_DEVTOOLS_HOOK_REPLAY__ =
  175. target.__VUE_DEVTOOLS_HOOK_REPLAY__ || []);
  176. replay.push((newHook) => {
  177. setDevtoolsHook(newHook, target);
  178. });
  179. // clear buffer after 3s - the user probably doesn't have devtools installed
  180. // at all, and keeping the buffer will cause memory leaks (#4738)
  181. setTimeout(() => {
  182. if (!devtools) {
  183. target.__VUE_DEVTOOLS_HOOK_REPLAY__ = null;
  184. devtoolsNotInstalled = true;
  185. buffer = [];
  186. }
  187. }, 3000);
  188. }
  189. else {
  190. // non-browser env, assume not installed
  191. devtoolsNotInstalled = true;
  192. buffer = [];
  193. }
  194. }
  195. function devtoolsInitApp(app, version) {
  196. emit("app:init" /* APP_INIT */, app, version, {
  197. Fragment,
  198. Text,
  199. Comment,
  200. Static
  201. });
  202. }
  203. function devtoolsUnmountApp(app) {
  204. emit("app:unmount" /* APP_UNMOUNT */, app);
  205. }
  206. const devtoolsComponentAdded = /*#__PURE__*/ createDevtoolsComponentHook("component:added" /* COMPONENT_ADDED */);
  207. const devtoolsComponentUpdated =
  208. /*#__PURE__*/ createDevtoolsComponentHook("component:updated" /* COMPONENT_UPDATED */);
  209. const devtoolsComponentRemoved =
  210. /*#__PURE__*/ createDevtoolsComponentHook("component:removed" /* COMPONENT_REMOVED */);
  211. function createDevtoolsComponentHook(hook) {
  212. return (component) => {
  213. emit(hook, component.appContext.app, component.uid, component.parent ? component.parent.uid : undefined, component);
  214. };
  215. }
  216. const devtoolsPerfStart = /*#__PURE__*/ createDevtoolsPerformanceHook("perf:start" /* PERFORMANCE_START */);
  217. const devtoolsPerfEnd = /*#__PURE__*/ createDevtoolsPerformanceHook("perf:end" /* PERFORMANCE_END */);
  218. function createDevtoolsPerformanceHook(hook) {
  219. return (component, type, time) => {
  220. emit(hook, component.appContext.app, component.uid, component, type, time);
  221. };
  222. }
  223. function devtoolsComponentEmit(component, event, params) {
  224. emit("component:emit" /* COMPONENT_EMIT */, component.appContext.app, component, event, params);
  225. }
  226. function emit$1(instance, event, ...rawArgs) {
  227. const props = instance.vnode.props || EMPTY_OBJ;
  228. if ((process.env.NODE_ENV !== 'production')) {
  229. const { emitsOptions, propsOptions: [propsOptions] } = instance;
  230. if (emitsOptions) {
  231. if (!(event in emitsOptions) &&
  232. !(false )) {
  233. if (!propsOptions || !(toHandlerKey(event) in propsOptions)) {
  234. warn(`Component emitted event "${event}" but it is neither declared in ` +
  235. `the emits option nor as an "${toHandlerKey(event)}" prop.`);
  236. }
  237. }
  238. else {
  239. const validator = emitsOptions[event];
  240. if (isFunction(validator)) {
  241. const isValid = validator(...rawArgs);
  242. if (!isValid) {
  243. warn(`Invalid event arguments: event validation failed for event "${event}".`);
  244. }
  245. }
  246. }
  247. }
  248. }
  249. let args = rawArgs;
  250. const isModelListener = event.startsWith('update:');
  251. // for v-model update:xxx events, apply modifiers on args
  252. const modelArg = isModelListener && event.slice(7);
  253. if (modelArg && modelArg in props) {
  254. const modifiersKey = `${modelArg === 'modelValue' ? 'model' : modelArg}Modifiers`;
  255. const { number, trim } = props[modifiersKey] || EMPTY_OBJ;
  256. if (trim) {
  257. args = rawArgs.map(a => a.trim());
  258. }
  259. else if (number) {
  260. args = rawArgs.map(toNumber);
  261. }
  262. }
  263. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  264. devtoolsComponentEmit(instance, event, args);
  265. }
  266. if ((process.env.NODE_ENV !== 'production')) {
  267. const lowerCaseEvent = event.toLowerCase();
  268. if (lowerCaseEvent !== event && props[toHandlerKey(lowerCaseEvent)]) {
  269. warn(`Event "${lowerCaseEvent}" is emitted in component ` +
  270. `${formatComponentName(instance, instance.type)} but the handler is registered for "${event}". ` +
  271. `Note that HTML attributes are case-insensitive and you cannot use ` +
  272. `v-on to listen to camelCase events when using in-DOM templates. ` +
  273. `You should probably use "${hyphenate(event)}" instead of "${event}".`);
  274. }
  275. }
  276. let handlerName;
  277. let handler = props[(handlerName = toHandlerKey(event))] ||
  278. // also try camelCase event handler (#2249)
  279. props[(handlerName = toHandlerKey(camelize(event)))];
  280. // for v-model update:xxx events, also trigger kebab-case equivalent
  281. // for props passed via kebab-case
  282. if (!handler && isModelListener) {
  283. handler = props[(handlerName = toHandlerKey(hyphenate(event)))];
  284. }
  285. if (handler) {
  286. callWithAsyncErrorHandling(handler, instance, 6 /* COMPONENT_EVENT_HANDLER */, args);
  287. }
  288. const onceHandler = props[handlerName + `Once`];
  289. if (onceHandler) {
  290. if (!instance.emitted) {
  291. instance.emitted = {};
  292. }
  293. else if (instance.emitted[handlerName]) {
  294. return;
  295. }
  296. instance.emitted[handlerName] = true;
  297. callWithAsyncErrorHandling(onceHandler, instance, 6 /* COMPONENT_EVENT_HANDLER */, args);
  298. }
  299. }
  300. function normalizeEmitsOptions(comp, appContext, asMixin = false) {
  301. const cache = appContext.emitsCache;
  302. const cached = cache.get(comp);
  303. if (cached !== undefined) {
  304. return cached;
  305. }
  306. const raw = comp.emits;
  307. let normalized = {};
  308. // apply mixin/extends props
  309. let hasExtends = false;
  310. if (__VUE_OPTIONS_API__ && !isFunction(comp)) {
  311. const extendEmits = (raw) => {
  312. const normalizedFromExtend = normalizeEmitsOptions(raw, appContext, true);
  313. if (normalizedFromExtend) {
  314. hasExtends = true;
  315. extend(normalized, normalizedFromExtend);
  316. }
  317. };
  318. if (!asMixin && appContext.mixins.length) {
  319. appContext.mixins.forEach(extendEmits);
  320. }
  321. if (comp.extends) {
  322. extendEmits(comp.extends);
  323. }
  324. if (comp.mixins) {
  325. comp.mixins.forEach(extendEmits);
  326. }
  327. }
  328. if (!raw && !hasExtends) {
  329. cache.set(comp, null);
  330. return null;
  331. }
  332. if (isArray(raw)) {
  333. raw.forEach(key => (normalized[key] = null));
  334. }
  335. else {
  336. extend(normalized, raw);
  337. }
  338. cache.set(comp, normalized);
  339. return normalized;
  340. }
  341. // Check if an incoming prop key is a declared emit event listener.
  342. // e.g. With `emits: { click: null }`, props named `onClick` and `onclick` are
  343. // both considered matched listeners.
  344. function isEmitListener(options, key) {
  345. if (!options || !isOn(key)) {
  346. return false;
  347. }
  348. key = key.slice(2).replace(/Once$/, '');
  349. return (hasOwn(options, key[0].toLowerCase() + key.slice(1)) ||
  350. hasOwn(options, hyphenate(key)) ||
  351. hasOwn(options, key));
  352. }
  353. /**
  354. * mark the current rendering instance for asset resolution (e.g.
  355. * resolveComponent, resolveDirective) during render
  356. */
  357. let currentRenderingInstance = null;
  358. let currentScopeId = null;
  359. /**
  360. * Note: rendering calls maybe nested. The function returns the parent rendering
  361. * instance if present, which should be restored after the render is done:
  362. *
  363. * ```js
  364. * const prev = setCurrentRenderingInstance(i)
  365. * // ...render
  366. * setCurrentRenderingInstance(prev)
  367. * ```
  368. */
  369. function setCurrentRenderingInstance(instance) {
  370. const prev = currentRenderingInstance;
  371. currentRenderingInstance = instance;
  372. currentScopeId = (instance && instance.type.__scopeId) || null;
  373. return prev;
  374. }
  375. /**
  376. * Set scope id when creating hoisted vnodes.
  377. * @private compiler helper
  378. */
  379. function pushScopeId(id) {
  380. currentScopeId = id;
  381. }
  382. /**
  383. * Technically we no longer need this after 3.0.8 but we need to keep the same
  384. * API for backwards compat w/ code generated by compilers.
  385. * @private
  386. */
  387. function popScopeId() {
  388. currentScopeId = null;
  389. }
  390. /**
  391. * Only for backwards compat
  392. * @private
  393. */
  394. const withScopeId = (_id) => withCtx;
  395. /**
  396. * Wrap a slot function to memoize current rendering instance
  397. * @private compiler helper
  398. */
  399. function withCtx(fn, ctx = currentRenderingInstance, isNonScopedSlot // false only
  400. ) {
  401. if (!ctx)
  402. return fn;
  403. // already normalized
  404. if (fn._n) {
  405. return fn;
  406. }
  407. const renderFnWithContext = (...args) => {
  408. // If a user calls a compiled slot inside a template expression (#1745), it
  409. // can mess up block tracking, so by default we disable block tracking and
  410. // force bail out when invoking a compiled slot (indicated by the ._d flag).
  411. // This isn't necessary if rendering a compiled `<slot>`, so we flip the
  412. // ._d flag off when invoking the wrapped fn inside `renderSlot`.
  413. if (renderFnWithContext._d) {
  414. setBlockTracking(-1);
  415. }
  416. const prevInstance = setCurrentRenderingInstance(ctx);
  417. const res = fn(...args);
  418. setCurrentRenderingInstance(prevInstance);
  419. if (renderFnWithContext._d) {
  420. setBlockTracking(1);
  421. }
  422. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  423. devtoolsComponentUpdated(ctx);
  424. }
  425. return res;
  426. };
  427. // mark normalized to avoid duplicated wrapping
  428. renderFnWithContext._n = true;
  429. // mark this as compiled by default
  430. // this is used in vnode.ts -> normalizeChildren() to set the slot
  431. // rendering flag.
  432. renderFnWithContext._c = true;
  433. // disable block tracking by default
  434. renderFnWithContext._d = true;
  435. return renderFnWithContext;
  436. }
  437. /**
  438. * dev only flag to track whether $attrs was used during render.
  439. * If $attrs was used during render then the warning for failed attrs
  440. * fallthrough can be suppressed.
  441. */
  442. let accessedAttrs = false;
  443. function markAttrsAccessed() {
  444. accessedAttrs = true;
  445. }
  446. function renderComponentRoot(instance) {
  447. const { type: Component, vnode, proxy, withProxy, props, propsOptions: [propsOptions], slots, attrs, emit, render, renderCache, data, setupState, ctx, inheritAttrs } = instance;
  448. let result;
  449. let fallthroughAttrs;
  450. const prev = setCurrentRenderingInstance(instance);
  451. if ((process.env.NODE_ENV !== 'production')) {
  452. accessedAttrs = false;
  453. }
  454. try {
  455. if (vnode.shapeFlag & 4 /* STATEFUL_COMPONENT */) {
  456. // withProxy is a proxy with a different `has` trap only for
  457. // runtime-compiled render functions using `with` block.
  458. const proxyToUse = withProxy || proxy;
  459. result = normalizeVNode(render.call(proxyToUse, proxyToUse, renderCache, props, setupState, data, ctx));
  460. fallthroughAttrs = attrs;
  461. }
  462. else {
  463. // functional
  464. const render = Component;
  465. // in dev, mark attrs accessed if optional props (attrs === props)
  466. if ((process.env.NODE_ENV !== 'production') && attrs === props) {
  467. markAttrsAccessed();
  468. }
  469. result = normalizeVNode(render.length > 1
  470. ? render(props, (process.env.NODE_ENV !== 'production')
  471. ? {
  472. get attrs() {
  473. markAttrsAccessed();
  474. return attrs;
  475. },
  476. slots,
  477. emit
  478. }
  479. : { attrs, slots, emit })
  480. : render(props, null /* we know it doesn't need it */));
  481. fallthroughAttrs = Component.props
  482. ? attrs
  483. : getFunctionalFallthrough(attrs);
  484. }
  485. }
  486. catch (err) {
  487. blockStack.length = 0;
  488. handleError(err, instance, 1 /* RENDER_FUNCTION */);
  489. result = createVNode(Comment);
  490. }
  491. // attr merging
  492. // in dev mode, comments are preserved, and it's possible for a template
  493. // to have comments along side the root element which makes it a fragment
  494. let root = result;
  495. let setRoot = undefined;
  496. if ((process.env.NODE_ENV !== 'production') &&
  497. result.patchFlag > 0 &&
  498. result.patchFlag & 2048 /* DEV_ROOT_FRAGMENT */) {
  499. [root, setRoot] = getChildRoot(result);
  500. }
  501. if (fallthroughAttrs && inheritAttrs !== false) {
  502. const keys = Object.keys(fallthroughAttrs);
  503. const { shapeFlag } = root;
  504. if (keys.length) {
  505. if (shapeFlag & (1 /* ELEMENT */ | 6 /* COMPONENT */)) {
  506. if (propsOptions && keys.some(isModelListener)) {
  507. // If a v-model listener (onUpdate:xxx) has a corresponding declared
  508. // prop, it indicates this component expects to handle v-model and
  509. // it should not fallthrough.
  510. // related: #1543, #1643, #1989
  511. fallthroughAttrs = filterModelListeners(fallthroughAttrs, propsOptions);
  512. }
  513. root = cloneVNode(root, fallthroughAttrs);
  514. }
  515. else if ((process.env.NODE_ENV !== 'production') && !accessedAttrs && root.type !== Comment) {
  516. const allAttrs = Object.keys(attrs);
  517. const eventAttrs = [];
  518. const extraAttrs = [];
  519. for (let i = 0, l = allAttrs.length; i < l; i++) {
  520. const key = allAttrs[i];
  521. if (isOn(key)) {
  522. // ignore v-model handlers when they fail to fallthrough
  523. if (!isModelListener(key)) {
  524. // remove `on`, lowercase first letter to reflect event casing
  525. // accurately
  526. eventAttrs.push(key[2].toLowerCase() + key.slice(3));
  527. }
  528. }
  529. else {
  530. extraAttrs.push(key);
  531. }
  532. }
  533. if (extraAttrs.length) {
  534. warn(`Extraneous non-props attributes (` +
  535. `${extraAttrs.join(', ')}) ` +
  536. `were passed to component but could not be automatically inherited ` +
  537. `because component renders fragment or text root nodes.`);
  538. }
  539. if (eventAttrs.length) {
  540. warn(`Extraneous non-emits event listeners (` +
  541. `${eventAttrs.join(', ')}) ` +
  542. `were passed to component but could not be automatically inherited ` +
  543. `because component renders fragment or text root nodes. ` +
  544. `If the listener is intended to be a component custom event listener only, ` +
  545. `declare it using the "emits" option.`);
  546. }
  547. }
  548. }
  549. }
  550. // inherit directives
  551. if (vnode.dirs) {
  552. if ((process.env.NODE_ENV !== 'production') && !isElementRoot(root)) {
  553. warn(`Runtime directive used on component with non-element root node. ` +
  554. `The directives will not function as intended.`);
  555. }
  556. root.dirs = root.dirs ? root.dirs.concat(vnode.dirs) : vnode.dirs;
  557. }
  558. // inherit transition data
  559. if (vnode.transition) {
  560. if ((process.env.NODE_ENV !== 'production') && !isElementRoot(root)) {
  561. warn(`Component inside <Transition> renders non-element root node ` +
  562. `that cannot be animated.`);
  563. }
  564. root.transition = vnode.transition;
  565. }
  566. if ((process.env.NODE_ENV !== 'production') && setRoot) {
  567. setRoot(root);
  568. }
  569. else {
  570. result = root;
  571. }
  572. setCurrentRenderingInstance(prev);
  573. return result;
  574. }
  575. /**
  576. * dev only
  577. * In dev mode, template root level comments are rendered, which turns the
  578. * template into a fragment root, but we need to locate the single element
  579. * root for attrs and scope id processing.
  580. */
  581. const getChildRoot = (vnode) => {
  582. const rawChildren = vnode.children;
  583. const dynamicChildren = vnode.dynamicChildren;
  584. const childRoot = filterSingleRoot(rawChildren);
  585. if (!childRoot) {
  586. return [vnode, undefined];
  587. }
  588. const index = rawChildren.indexOf(childRoot);
  589. const dynamicIndex = dynamicChildren ? dynamicChildren.indexOf(childRoot) : -1;
  590. const setRoot = (updatedRoot) => {
  591. rawChildren[index] = updatedRoot;
  592. if (dynamicChildren) {
  593. if (dynamicIndex > -1) {
  594. dynamicChildren[dynamicIndex] = updatedRoot;
  595. }
  596. else if (updatedRoot.patchFlag > 0) {
  597. vnode.dynamicChildren = [...dynamicChildren, updatedRoot];
  598. }
  599. }
  600. };
  601. return [normalizeVNode(childRoot), setRoot];
  602. };
  603. function filterSingleRoot(children) {
  604. let singleRoot;
  605. for (let i = 0; i < children.length; i++) {
  606. const child = children[i];
  607. if (isVNode(child)) {
  608. // ignore user comment
  609. if (child.type !== Comment || child.children === 'v-if') {
  610. if (singleRoot) {
  611. // has more than 1 non-comment child, return now
  612. return;
  613. }
  614. else {
  615. singleRoot = child;
  616. }
  617. }
  618. }
  619. else {
  620. return;
  621. }
  622. }
  623. return singleRoot;
  624. }
  625. const getFunctionalFallthrough = (attrs) => {
  626. let res;
  627. for (const key in attrs) {
  628. if (key === 'class' || key === 'style' || isOn(key)) {
  629. (res || (res = {}))[key] = attrs[key];
  630. }
  631. }
  632. return res;
  633. };
  634. const filterModelListeners = (attrs, props) => {
  635. const res = {};
  636. for (const key in attrs) {
  637. if (!isModelListener(key) || !(key.slice(9) in props)) {
  638. res[key] = attrs[key];
  639. }
  640. }
  641. return res;
  642. };
  643. const isElementRoot = (vnode) => {
  644. return (vnode.shapeFlag & (6 /* COMPONENT */ | 1 /* ELEMENT */) ||
  645. vnode.type === Comment // potential v-if branch switch
  646. );
  647. };
  648. function shouldUpdateComponent(prevVNode, nextVNode, optimized) {
  649. const { props: prevProps, children: prevChildren, component } = prevVNode;
  650. const { props: nextProps, children: nextChildren, patchFlag } = nextVNode;
  651. const emits = component.emitsOptions;
  652. // Parent component's render function was hot-updated. Since this may have
  653. // caused the child component's slots content to have changed, we need to
  654. // force the child to update as well.
  655. if ((process.env.NODE_ENV !== 'production') && (prevChildren || nextChildren) && isHmrUpdating) {
  656. return true;
  657. }
  658. // force child update for runtime directive or transition on component vnode.
  659. if (nextVNode.dirs || nextVNode.transition) {
  660. return true;
  661. }
  662. if (optimized && patchFlag >= 0) {
  663. if (patchFlag & 1024 /* DYNAMIC_SLOTS */) {
  664. // slot content that references values that might have changed,
  665. // e.g. in a v-for
  666. return true;
  667. }
  668. if (patchFlag & 16 /* FULL_PROPS */) {
  669. if (!prevProps) {
  670. return !!nextProps;
  671. }
  672. // presence of this flag indicates props are always non-null
  673. return hasPropsChanged(prevProps, nextProps, emits);
  674. }
  675. else if (patchFlag & 8 /* PROPS */) {
  676. const dynamicProps = nextVNode.dynamicProps;
  677. for (let i = 0; i < dynamicProps.length; i++) {
  678. const key = dynamicProps[i];
  679. if (nextProps[key] !== prevProps[key] &&
  680. !isEmitListener(emits, key)) {
  681. return true;
  682. }
  683. }
  684. }
  685. }
  686. else {
  687. // this path is only taken by manually written render functions
  688. // so presence of any children leads to a forced update
  689. if (prevChildren || nextChildren) {
  690. if (!nextChildren || !nextChildren.$stable) {
  691. return true;
  692. }
  693. }
  694. if (prevProps === nextProps) {
  695. return false;
  696. }
  697. if (!prevProps) {
  698. return !!nextProps;
  699. }
  700. if (!nextProps) {
  701. return true;
  702. }
  703. return hasPropsChanged(prevProps, nextProps, emits);
  704. }
  705. return false;
  706. }
  707. function hasPropsChanged(prevProps, nextProps, emitsOptions) {
  708. const nextKeys = Object.keys(nextProps);
  709. if (nextKeys.length !== Object.keys(prevProps).length) {
  710. return true;
  711. }
  712. for (let i = 0; i < nextKeys.length; i++) {
  713. const key = nextKeys[i];
  714. if (nextProps[key] !== prevProps[key] &&
  715. !isEmitListener(emitsOptions, key)) {
  716. return true;
  717. }
  718. }
  719. return false;
  720. }
  721. function updateHOCHostEl({ vnode, parent }, el // HostNode
  722. ) {
  723. while (parent && parent.subTree === vnode) {
  724. (vnode = parent.vnode).el = el;
  725. parent = parent.parent;
  726. }
  727. }
  728. const isSuspense = (type) => type.__isSuspense;
  729. // Suspense exposes a component-like API, and is treated like a component
  730. // in the compiler, but internally it's a special built-in type that hooks
  731. // directly into the renderer.
  732. const SuspenseImpl = {
  733. name: 'Suspense',
  734. // In order to make Suspense tree-shakable, we need to avoid importing it
  735. // directly in the renderer. The renderer checks for the __isSuspense flag
  736. // on a vnode's type and calls the `process` method, passing in renderer
  737. // internals.
  738. __isSuspense: true,
  739. process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized,
  740. // platform-specific impl passed from renderer
  741. rendererInternals) {
  742. if (n1 == null) {
  743. mountSuspense(n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, rendererInternals);
  744. }
  745. else {
  746. patchSuspense(n1, n2, container, anchor, parentComponent, isSVG, slotScopeIds, optimized, rendererInternals);
  747. }
  748. },
  749. hydrate: hydrateSuspense,
  750. create: createSuspenseBoundary,
  751. normalize: normalizeSuspenseChildren
  752. };
  753. // Force-casted public typing for h and TSX props inference
  754. const Suspense = (SuspenseImpl );
  755. function triggerEvent(vnode, name) {
  756. const eventListener = vnode.props && vnode.props[name];
  757. if (isFunction(eventListener)) {
  758. eventListener();
  759. }
  760. }
  761. function mountSuspense(vnode, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, rendererInternals) {
  762. const { p: patch, o: { createElement } } = rendererInternals;
  763. const hiddenContainer = createElement('div');
  764. const suspense = (vnode.suspense = createSuspenseBoundary(vnode, parentSuspense, parentComponent, container, hiddenContainer, anchor, isSVG, slotScopeIds, optimized, rendererInternals));
  765. // start mounting the content subtree in an off-dom container
  766. patch(null, (suspense.pendingBranch = vnode.ssContent), hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds);
  767. // now check if we have encountered any async deps
  768. if (suspense.deps > 0) {
  769. // has async
  770. // invoke @fallback event
  771. triggerEvent(vnode, 'onPending');
  772. triggerEvent(vnode, 'onFallback');
  773. // mount the fallback tree
  774. patch(null, vnode.ssFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  775. isSVG, slotScopeIds);
  776. setActiveBranch(suspense, vnode.ssFallback);
  777. }
  778. else {
  779. // Suspense has no async deps. Just resolve.
  780. suspense.resolve();
  781. }
  782. }
  783. function patchSuspense(n1, n2, container, anchor, parentComponent, isSVG, slotScopeIds, optimized, { p: patch, um: unmount, o: { createElement } }) {
  784. const suspense = (n2.suspense = n1.suspense);
  785. suspense.vnode = n2;
  786. n2.el = n1.el;
  787. const newBranch = n2.ssContent;
  788. const newFallback = n2.ssFallback;
  789. const { activeBranch, pendingBranch, isInFallback, isHydrating } = suspense;
  790. if (pendingBranch) {
  791. suspense.pendingBranch = newBranch;
  792. if (isSameVNodeType(newBranch, pendingBranch)) {
  793. // same root type but content may have changed.
  794. patch(pendingBranch, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  795. if (suspense.deps <= 0) {
  796. suspense.resolve();
  797. }
  798. else if (isInFallback) {
  799. patch(activeBranch, newFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  800. isSVG, slotScopeIds, optimized);
  801. setActiveBranch(suspense, newFallback);
  802. }
  803. }
  804. else {
  805. // toggled before pending tree is resolved
  806. suspense.pendingId++;
  807. if (isHydrating) {
  808. // if toggled before hydration is finished, the current DOM tree is
  809. // no longer valid. set it as the active branch so it will be unmounted
  810. // when resolved
  811. suspense.isHydrating = false;
  812. suspense.activeBranch = pendingBranch;
  813. }
  814. else {
  815. unmount(pendingBranch, parentComponent, suspense);
  816. }
  817. // increment pending ID. this is used to invalidate async callbacks
  818. // reset suspense state
  819. suspense.deps = 0;
  820. // discard effects from pending branch
  821. suspense.effects.length = 0;
  822. // discard previous container
  823. suspense.hiddenContainer = createElement('div');
  824. if (isInFallback) {
  825. // already in fallback state
  826. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  827. if (suspense.deps <= 0) {
  828. suspense.resolve();
  829. }
  830. else {
  831. patch(activeBranch, newFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  832. isSVG, slotScopeIds, optimized);
  833. setActiveBranch(suspense, newFallback);
  834. }
  835. }
  836. else if (activeBranch && isSameVNodeType(newBranch, activeBranch)) {
  837. // toggled "back" to current active branch
  838. patch(activeBranch, newBranch, container, anchor, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  839. // force resolve
  840. suspense.resolve(true);
  841. }
  842. else {
  843. // switched to a 3rd branch
  844. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  845. if (suspense.deps <= 0) {
  846. suspense.resolve();
  847. }
  848. }
  849. }
  850. }
  851. else {
  852. if (activeBranch && isSameVNodeType(newBranch, activeBranch)) {
  853. // root did not change, just normal patch
  854. patch(activeBranch, newBranch, container, anchor, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  855. setActiveBranch(suspense, newBranch);
  856. }
  857. else {
  858. // root node toggled
  859. // invoke @pending event
  860. triggerEvent(n2, 'onPending');
  861. // mount pending branch in off-dom container
  862. suspense.pendingBranch = newBranch;
  863. suspense.pendingId++;
  864. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  865. if (suspense.deps <= 0) {
  866. // incoming branch has no async deps, resolve now.
  867. suspense.resolve();
  868. }
  869. else {
  870. const { timeout, pendingId } = suspense;
  871. if (timeout > 0) {
  872. setTimeout(() => {
  873. if (suspense.pendingId === pendingId) {
  874. suspense.fallback(newFallback);
  875. }
  876. }, timeout);
  877. }
  878. else if (timeout === 0) {
  879. suspense.fallback(newFallback);
  880. }
  881. }
  882. }
  883. }
  884. }
  885. let hasWarned = false;
  886. function createSuspenseBoundary(vnode, parent, parentComponent, container, hiddenContainer, anchor, isSVG, slotScopeIds, optimized, rendererInternals, isHydrating = false) {
  887. /* istanbul ignore if */
  888. if ((process.env.NODE_ENV !== 'production') && !false && !hasWarned) {
  889. hasWarned = true;
  890. // @ts-ignore `console.info` cannot be null error
  891. console[console.info ? 'info' : 'log'](`<Suspense> is an experimental feature and its API will likely change.`);
  892. }
  893. const { p: patch, m: move, um: unmount, n: next, o: { parentNode, remove } } = rendererInternals;
  894. const timeout = toNumber(vnode.props && vnode.props.timeout);
  895. const suspense = {
  896. vnode,
  897. parent,
  898. parentComponent,
  899. isSVG,
  900. container,
  901. hiddenContainer,
  902. anchor,
  903. deps: 0,
  904. pendingId: 0,
  905. timeout: typeof timeout === 'number' ? timeout : -1,
  906. activeBranch: null,
  907. pendingBranch: null,
  908. isInFallback: true,
  909. isHydrating,
  910. isUnmounted: false,
  911. effects: [],
  912. resolve(resume = false) {
  913. if ((process.env.NODE_ENV !== 'production')) {
  914. if (!resume && !suspense.pendingBranch) {
  915. throw new Error(`suspense.resolve() is called without a pending branch.`);
  916. }
  917. if (suspense.isUnmounted) {
  918. throw new Error(`suspense.resolve() is called on an already unmounted suspense boundary.`);
  919. }
  920. }
  921. const { vnode, activeBranch, pendingBranch, pendingId, effects, parentComponent, container } = suspense;
  922. if (suspense.isHydrating) {
  923. suspense.isHydrating = false;
  924. }
  925. else if (!resume) {
  926. const delayEnter = activeBranch &&
  927. pendingBranch.transition &&
  928. pendingBranch.transition.mode === 'out-in';
  929. if (delayEnter) {
  930. activeBranch.transition.afterLeave = () => {
  931. if (pendingId === suspense.pendingId) {
  932. move(pendingBranch, container, anchor, 0 /* ENTER */);
  933. }
  934. };
  935. }
  936. // this is initial anchor on mount
  937. let { anchor } = suspense;
  938. // unmount current active tree
  939. if (activeBranch) {
  940. // if the fallback tree was mounted, it may have been moved
  941. // as part of a parent suspense. get the latest anchor for insertion
  942. anchor = next(activeBranch);
  943. unmount(activeBranch, parentComponent, suspense, true);
  944. }
  945. if (!delayEnter) {
  946. // move content from off-dom container to actual container
  947. move(pendingBranch, container, anchor, 0 /* ENTER */);
  948. }
  949. }
  950. setActiveBranch(suspense, pendingBranch);
  951. suspense.pendingBranch = null;
  952. suspense.isInFallback = false;
  953. // flush buffered effects
  954. // check if there is a pending parent suspense
  955. let parent = suspense.parent;
  956. let hasUnresolvedAncestor = false;
  957. while (parent) {
  958. if (parent.pendingBranch) {
  959. // found a pending parent suspense, merge buffered post jobs
  960. // into that parent
  961. parent.effects.push(...effects);
  962. hasUnresolvedAncestor = true;
  963. break;
  964. }
  965. parent = parent.parent;
  966. }
  967. // no pending parent suspense, flush all jobs
  968. if (!hasUnresolvedAncestor) {
  969. queuePostFlushCb(effects);
  970. }
  971. suspense.effects = [];
  972. // invoke @resolve event
  973. triggerEvent(vnode, 'onResolve');
  974. },
  975. fallback(fallbackVNode) {
  976. if (!suspense.pendingBranch) {
  977. return;
  978. }
  979. const { vnode, activeBranch, parentComponent, container, isSVG } = suspense;
  980. // invoke @fallback event
  981. triggerEvent(vnode, 'onFallback');
  982. const anchor = next(activeBranch);
  983. const mountFallback = () => {
  984. if (!suspense.isInFallback) {
  985. return;
  986. }
  987. // mount the fallback tree
  988. patch(null, fallbackVNode, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  989. isSVG, slotScopeIds, optimized);
  990. setActiveBranch(suspense, fallbackVNode);
  991. };
  992. const delayEnter = fallbackVNode.transition && fallbackVNode.transition.mode === 'out-in';
  993. if (delayEnter) {
  994. activeBranch.transition.afterLeave = mountFallback;
  995. }
  996. suspense.isInFallback = true;
  997. // unmount current active branch
  998. unmount(activeBranch, parentComponent, null, // no suspense so unmount hooks fire now
  999. true // shouldRemove
  1000. );
  1001. if (!delayEnter) {
  1002. mountFallback();
  1003. }
  1004. },
  1005. move(container, anchor, type) {
  1006. suspense.activeBranch &&
  1007. move(suspense.activeBranch, container, anchor, type);
  1008. suspense.container = container;
  1009. },
  1010. next() {
  1011. return suspense.activeBranch && next(suspense.activeBranch);
  1012. },
  1013. registerDep(instance, setupRenderEffect) {
  1014. const isInPendingSuspense = !!suspense.pendingBranch;
  1015. if (isInPendingSuspense) {
  1016. suspense.deps++;
  1017. }
  1018. const hydratedEl = instance.vnode.el;
  1019. instance
  1020. .asyncDep.catch(err => {
  1021. handleError(err, instance, 0 /* SETUP_FUNCTION */);
  1022. })
  1023. .then(asyncSetupResult => {
  1024. // retry when the setup() promise resolves.
  1025. // component may have been unmounted before resolve.
  1026. if (instance.isUnmounted ||
  1027. suspense.isUnmounted ||
  1028. suspense.pendingId !== instance.suspenseId) {
  1029. return;
  1030. }
  1031. // retry from this component
  1032. instance.asyncResolved = true;
  1033. const { vnode } = instance;
  1034. if ((process.env.NODE_ENV !== 'production')) {
  1035. pushWarningContext(vnode);
  1036. }
  1037. handleSetupResult(instance, asyncSetupResult, false);
  1038. if (hydratedEl) {
  1039. // vnode may have been replaced if an update happened before the
  1040. // async dep is resolved.
  1041. vnode.el = hydratedEl;
  1042. }
  1043. const placeholder = !hydratedEl && instance.subTree.el;
  1044. setupRenderEffect(instance, vnode,
  1045. // component may have been moved before resolve.
  1046. // if this is not a hydration, instance.subTree will be the comment
  1047. // placeholder.
  1048. parentNode(hydratedEl || instance.subTree.el),
  1049. // anchor will not be used if this is hydration, so only need to
  1050. // consider the comment placeholder case.
  1051. hydratedEl ? null : next(instance.subTree), suspense, isSVG, optimized);
  1052. if (placeholder) {
  1053. remove(placeholder);
  1054. }
  1055. updateHOCHostEl(instance, vnode.el);
  1056. if ((process.env.NODE_ENV !== 'production')) {
  1057. popWarningContext();
  1058. }
  1059. // only decrease deps count if suspense is not already resolved
  1060. if (isInPendingSuspense && --suspense.deps === 0) {
  1061. suspense.resolve();
  1062. }
  1063. });
  1064. },
  1065. unmount(parentSuspense, doRemove) {
  1066. suspense.isUnmounted = true;
  1067. if (suspense.activeBranch) {
  1068. unmount(suspense.activeBranch, parentComponent, parentSuspense, doRemove);
  1069. }
  1070. if (suspense.pendingBranch) {
  1071. unmount(suspense.pendingBranch, parentComponent, parentSuspense, doRemove);
  1072. }
  1073. }
  1074. };
  1075. return suspense;
  1076. }
  1077. function hydrateSuspense(node, vnode, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, rendererInternals, hydrateNode) {
  1078. /* eslint-disable no-restricted-globals */
  1079. const suspense = (vnode.suspense = createSuspenseBoundary(vnode, parentSuspense, parentComponent, node.parentNode, document.createElement('div'), null, isSVG, slotScopeIds, optimized, rendererInternals, true /* hydrating */));
  1080. // there are two possible scenarios for server-rendered suspense:
  1081. // - success: ssr content should be fully resolved
  1082. // - failure: ssr content should be the fallback branch.
  1083. // however, on the client we don't really know if it has failed or not
  1084. // attempt to hydrate the DOM assuming it has succeeded, but we still
  1085. // need to construct a suspense boundary first
  1086. const result = hydrateNode(node, (suspense.pendingBranch = vnode.ssContent), parentComponent, suspense, slotScopeIds, optimized);
  1087. if (suspense.deps === 0) {
  1088. suspense.resolve();
  1089. }
  1090. return result;
  1091. /* eslint-enable no-restricted-globals */
  1092. }
  1093. function normalizeSuspenseChildren(vnode) {
  1094. const { shapeFlag, children } = vnode;
  1095. const isSlotChildren = shapeFlag & 32 /* SLOTS_CHILDREN */;
  1096. vnode.ssContent = normalizeSuspenseSlot(isSlotChildren ? children.default : children);
  1097. vnode.ssFallback = isSlotChildren
  1098. ? normalizeSuspenseSlot(children.fallback)
  1099. : createVNode(Comment);
  1100. }
  1101. function normalizeSuspenseSlot(s) {
  1102. let block;
  1103. if (isFunction(s)) {
  1104. const trackBlock = isBlockTreeEnabled && s._c;
  1105. if (trackBlock) {
  1106. // disableTracking: false
  1107. // allow block tracking for compiled slots
  1108. // (see ./componentRenderContext.ts)
  1109. s._d = false;
  1110. openBlock();
  1111. }
  1112. s = s();
  1113. if (trackBlock) {
  1114. s._d = true;
  1115. block = currentBlock;
  1116. closeBlock();
  1117. }
  1118. }
  1119. if (isArray(s)) {
  1120. const singleChild = filterSingleRoot(s);
  1121. if ((process.env.NODE_ENV !== 'production') && !singleChild) {
  1122. warn(`<Suspense> slots expect a single root node.`);
  1123. }
  1124. s = singleChild;
  1125. }
  1126. s = normalizeVNode(s);
  1127. if (block && !s.dynamicChildren) {
  1128. s.dynamicChildren = block.filter(c => c !== s);
  1129. }
  1130. return s;
  1131. }
  1132. function queueEffectWithSuspense(fn, suspense) {
  1133. if (suspense && suspense.pendingBranch) {
  1134. if (isArray(fn)) {
  1135. suspense.effects.push(...fn);
  1136. }
  1137. else {
  1138. suspense.effects.push(fn);
  1139. }
  1140. }
  1141. else {
  1142. queuePostFlushCb(fn);
  1143. }
  1144. }
  1145. function setActiveBranch(suspense, branch) {
  1146. suspense.activeBranch = branch;
  1147. const { vnode, parentComponent } = suspense;
  1148. const el = (vnode.el = branch.el);
  1149. // in case suspense is the root node of a component,
  1150. // recursively update the HOC el
  1151. if (parentComponent && parentComponent.subTree === vnode) {
  1152. parentComponent.vnode.el = el;
  1153. updateHOCHostEl(parentComponent, el);
  1154. }
  1155. }
  1156. function provide(key, value) {
  1157. if (!currentInstance) {
  1158. if ((process.env.NODE_ENV !== 'production')) {
  1159. warn(`provide() can only be used inside setup().`);
  1160. }
  1161. }
  1162. else {
  1163. let provides = currentInstance.provides;
  1164. // by default an instance inherits its parent's provides object
  1165. // but when it needs to provide values of its own, it creates its
  1166. // own provides object using parent provides object as prototype.
  1167. // this way in `inject` we can simply look up injections from direct
  1168. // parent and let the prototype chain do the work.
  1169. const parentProvides = currentInstance.parent && currentInstance.parent.provides;
  1170. if (parentProvides === provides) {
  1171. provides = currentInstance.provides = Object.create(parentProvides);
  1172. }
  1173. // TS doesn't allow symbol as index type
  1174. provides[key] = value;
  1175. }
  1176. }
  1177. function inject(key, defaultValue, treatDefaultAsFactory = false) {
  1178. // fallback to `currentRenderingInstance` so that this can be called in
  1179. // a functional component
  1180. const instance = currentInstance || currentRenderingInstance;
  1181. if (instance) {
  1182. // #2400
  1183. // to support `app.use` plugins,
  1184. // fallback to appContext's `provides` if the intance is at root
  1185. const provides = instance.parent == null
  1186. ? instance.vnode.appContext && instance.vnode.appContext.provides
  1187. : instance.parent.provides;
  1188. if (provides && key in provides) {
  1189. // TS doesn't allow symbol as index type
  1190. return provides[key];
  1191. }
  1192. else if (arguments.length > 1) {
  1193. return treatDefaultAsFactory && isFunction(defaultValue)
  1194. ? defaultValue.call(instance.proxy)
  1195. : defaultValue;
  1196. }
  1197. else if ((process.env.NODE_ENV !== 'production')) {
  1198. warn(`injection "${String(key)}" not found.`);
  1199. }
  1200. }
  1201. else if ((process.env.NODE_ENV !== 'production')) {
  1202. warn(`inject() can only be used inside setup() or functional components.`);
  1203. }
  1204. }
  1205. function useTransitionState() {
  1206. const state = {
  1207. isMounted: false,
  1208. isLeaving: false,
  1209. isUnmounting: false,
  1210. leavingVNodes: new Map()
  1211. };
  1212. onMounted(() => {
  1213. state.isMounted = true;
  1214. });
  1215. onBeforeUnmount(() => {
  1216. state.isUnmounting = true;
  1217. });
  1218. return state;
  1219. }
  1220. const TransitionHookValidator = [Function, Array];
  1221. const BaseTransitionImpl = {
  1222. name: `BaseTransition`,
  1223. props: {
  1224. mode: String,
  1225. appear: Boolean,
  1226. persisted: Boolean,
  1227. // enter
  1228. onBeforeEnter: TransitionHookValidator,
  1229. onEnter: TransitionHookValidator,
  1230. onAfterEnter: TransitionHookValidator,
  1231. onEnterCancelled: TransitionHookValidator,
  1232. // leave
  1233. onBeforeLeave: TransitionHookValidator,
  1234. onLeave: TransitionHookValidator,
  1235. onAfterLeave: TransitionHookValidator,
  1236. onLeaveCancelled: TransitionHookValidator,
  1237. // appear
  1238. onBeforeAppear: TransitionHookValidator,
  1239. onAppear: TransitionHookValidator,
  1240. onAfterAppear: TransitionHookValidator,
  1241. onAppearCancelled: TransitionHookValidator
  1242. },
  1243. setup(props, { slots }) {
  1244. const instance = getCurrentInstance();
  1245. const state = useTransitionState();
  1246. let prevTransitionKey;
  1247. return () => {
  1248. const children = slots.default && getTransitionRawChildren(slots.default(), true);
  1249. if (!children || !children.length) {
  1250. return;
  1251. }
  1252. // warn multiple elements
  1253. if ((process.env.NODE_ENV !== 'production') && children.length > 1) {
  1254. warn('<transition> can only be used on a single element or component. Use ' +
  1255. '<transition-group> for lists.');
  1256. }
  1257. // there's no need to track reactivity for these props so use the raw
  1258. // props for a bit better perf
  1259. const rawProps = toRaw(props);
  1260. const { mode } = rawProps;
  1261. // check mode
  1262. if ((process.env.NODE_ENV !== 'production') &&
  1263. mode &&
  1264. mode !== 'in-out' && mode !== 'out-in' && mode !== 'default') {
  1265. warn(`invalid <transition> mode: ${mode}`);
  1266. }
  1267. // at this point children has a guaranteed length of 1.
  1268. const child = children[0];
  1269. if (state.isLeaving) {
  1270. return emptyPlaceholder(child);
  1271. }
  1272. // in the case of <transition><keep-alive/></transition>, we need to
  1273. // compare the type of the kept-alive children.
  1274. const innerChild = getKeepAliveChild(child);
  1275. if (!innerChild) {
  1276. return emptyPlaceholder(child);
  1277. }
  1278. const enterHooks = resolveTransitionHooks(innerChild, rawProps, state, instance);
  1279. setTransitionHooks(innerChild, enterHooks);
  1280. const oldChild = instance.subTree;
  1281. const oldInnerChild = oldChild && getKeepAliveChild(oldChild);
  1282. let transitionKeyChanged = false;
  1283. const { getTransitionKey } = innerChild.type;
  1284. if (getTransitionKey) {
  1285. const key = getTransitionKey();
  1286. if (prevTransitionKey === undefined) {
  1287. prevTransitionKey = key;
  1288. }
  1289. else if (key !== prevTransitionKey) {
  1290. prevTransitionKey = key;
  1291. transitionKeyChanged = true;
  1292. }
  1293. }
  1294. // handle mode
  1295. if (oldInnerChild &&
  1296. oldInnerChild.type !== Comment &&
  1297. (!isSameVNodeType(innerChild, oldInnerChild) || transitionKeyChanged)) {
  1298. const leavingHooks = resolveTransitionHooks(oldInnerChild, rawProps, state, instance);
  1299. // update old tree's hooks in case of dynamic transition
  1300. setTransitionHooks(oldInnerChild, leavingHooks);
  1301. // switching between different views
  1302. if (mode === 'out-in') {
  1303. state.isLeaving = true;
  1304. // return placeholder node and queue update when leave finishes
  1305. leavingHooks.afterLeave = () => {
  1306. state.isLeaving = false;
  1307. instance.update();
  1308. };
  1309. return emptyPlaceholder(child);
  1310. }
  1311. else if (mode === 'in-out' && innerChild.type !== Comment) {
  1312. leavingHooks.delayLeave = (el, earlyRemove, delayedLeave) => {
  1313. const leavingVNodesCache = getLeavingNodesForType(state, oldInnerChild);
  1314. leavingVNodesCache[String(oldInnerChild.key)] = oldInnerChild;
  1315. // early removal callback
  1316. el._leaveCb = () => {
  1317. earlyRemove();
  1318. el._leaveCb = undefined;
  1319. delete enterHooks.delayedLeave;
  1320. };
  1321. enterHooks.delayedLeave = delayedLeave;
  1322. };
  1323. }
  1324. }
  1325. return child;
  1326. };
  1327. }
  1328. };
  1329. // export the public type for h/tsx inference
  1330. // also to avoid inline import() in generated d.ts files
  1331. const BaseTransition = BaseTransitionImpl;
  1332. function getLeavingNodesForType(state, vnode) {
  1333. const { leavingVNodes } = state;
  1334. let leavingVNodesCache = leavingVNodes.get(vnode.type);
  1335. if (!leavingVNodesCache) {
  1336. leavingVNodesCache = Object.create(null);
  1337. leavingVNodes.set(vnode.type, leavingVNodesCache);
  1338. }
  1339. return leavingVNodesCache;
  1340. }
  1341. // The transition hooks are attached to the vnode as vnode.transition
  1342. // and will be called at appropriate timing in the renderer.
  1343. function resolveTransitionHooks(vnode, props, state, instance) {
  1344. const { appear, mode, persisted = false, onBeforeEnter, onEnter, onAfterEnter, onEnterCancelled, onBeforeLeave, onLeave, onAfterLeave, onLeaveCancelled, onBeforeAppear, onAppear, onAfterAppear, onAppearCancelled } = props;
  1345. const key = String(vnode.key);
  1346. const leavingVNodesCache = getLeavingNodesForType(state, vnode);
  1347. const callHook = (hook, args) => {
  1348. hook &&
  1349. callWithAsyncErrorHandling(hook, instance, 9 /* TRANSITION_HOOK */, args);
  1350. };
  1351. const hooks = {
  1352. mode,
  1353. persisted,
  1354. beforeEnter(el) {
  1355. let hook = onBeforeEnter;
  1356. if (!state.isMounted) {
  1357. if (appear) {
  1358. hook = onBeforeAppear || onBeforeEnter;
  1359. }
  1360. else {
  1361. return;
  1362. }
  1363. }
  1364. // for same element (v-show)
  1365. if (el._leaveCb) {
  1366. el._leaveCb(true /* cancelled */);
  1367. }
  1368. // for toggled element with same key (v-if)
  1369. const leavingVNode = leavingVNodesCache[key];
  1370. if (leavingVNode &&
  1371. isSameVNodeType(vnode, leavingVNode) &&
  1372. leavingVNode.el._leaveCb) {
  1373. // force early removal (not cancelled)
  1374. leavingVNode.el._leaveCb();
  1375. }
  1376. callHook(hook, [el]);
  1377. },
  1378. enter(el) {
  1379. let hook = onEnter;
  1380. let afterHook = onAfterEnter;
  1381. let cancelHook = onEnterCancelled;
  1382. if (!state.isMounted) {
  1383. if (appear) {
  1384. hook = onAppear || onEnter;
  1385. afterHook = onAfterAppear || onAfterEnter;
  1386. cancelHook = onAppearCancelled || onEnterCancelled;
  1387. }
  1388. else {
  1389. return;
  1390. }
  1391. }
  1392. let called = false;
  1393. const done = (el._enterCb = (cancelled) => {
  1394. if (called)
  1395. return;
  1396. called = true;
  1397. if (cancelled) {
  1398. callHook(cancelHook, [el]);
  1399. }
  1400. else {
  1401. callHook(afterHook, [el]);
  1402. }
  1403. if (hooks.delayedLeave) {
  1404. hooks.delayedLeave();
  1405. }
  1406. el._enterCb = undefined;
  1407. });
  1408. if (hook) {
  1409. hook(el, done);
  1410. if (hook.length <= 1) {
  1411. done();
  1412. }
  1413. }
  1414. else {
  1415. done();
  1416. }
  1417. },
  1418. leave(el, remove) {
  1419. const key = String(vnode.key);
  1420. if (el._enterCb) {
  1421. el._enterCb(true /* cancelled */);
  1422. }
  1423. if (state.isUnmounting) {
  1424. return remove();
  1425. }
  1426. callHook(onBeforeLeave, [el]);
  1427. let called = false;
  1428. const done = (el._leaveCb = (cancelled) => {
  1429. if (called)
  1430. return;
  1431. called = true;
  1432. remove();
  1433. if (cancelled) {
  1434. callHook(onLeaveCancelled, [el]);
  1435. }
  1436. else {
  1437. callHook(onAfterLeave, [el]);
  1438. }
  1439. el._leaveCb = undefined;
  1440. if (leavingVNodesCache[key] === vnode) {
  1441. delete leavingVNodesCache[key];
  1442. }
  1443. });
  1444. leavingVNodesCache[key] = vnode;
  1445. if (onLeave) {
  1446. onLeave(el, done);
  1447. if (onLeave.length <= 1) {
  1448. done();
  1449. }
  1450. }
  1451. else {
  1452. done();
  1453. }
  1454. },
  1455. clone(vnode) {
  1456. return resolveTransitionHooks(vnode, props, state, instance);
  1457. }
  1458. };
  1459. return hooks;
  1460. }
  1461. // the placeholder really only handles one special case: KeepAlive
  1462. // in the case of a KeepAlive in a leave phase we need to return a KeepAlive
  1463. // placeholder with empty content to avoid the KeepAlive instance from being
  1464. // unmounted.
  1465. function emptyPlaceholder(vnode) {
  1466. if (isKeepAlive(vnode)) {
  1467. vnode = cloneVNode(vnode);
  1468. vnode.children = null;
  1469. return vnode;
  1470. }
  1471. }
  1472. function getKeepAliveChild(vnode) {
  1473. return isKeepAlive(vnode)
  1474. ? vnode.children
  1475. ? vnode.children[0]
  1476. : undefined
  1477. : vnode;
  1478. }
  1479. function setTransitionHooks(vnode, hooks) {
  1480. if (vnode.shapeFlag & 6 /* COMPONENT */ && vnode.component) {
  1481. setTransitionHooks(vnode.component.subTree, hooks);
  1482. }
  1483. else if (vnode.shapeFlag & 128 /* SUSPENSE */) {
  1484. vnode.ssContent.transition = hooks.clone(vnode.ssContent);
  1485. vnode.ssFallback.transition = hooks.clone(vnode.ssFallback);
  1486. }
  1487. else {
  1488. vnode.transition = hooks;
  1489. }
  1490. }
  1491. function getTransitionRawChildren(children, keepComment = false) {
  1492. let ret = [];
  1493. let keyedFragmentCount = 0;
  1494. for (let i = 0; i < children.length; i++) {
  1495. const child = children[i];
  1496. // handle fragment children case, e.g. v-for
  1497. if (child.type === Fragment) {
  1498. if (child.patchFlag & 128 /* KEYED_FRAGMENT */)
  1499. keyedFragmentCount++;
  1500. ret = ret.concat(getTransitionRawChildren(child.children, keepComment));
  1501. }
  1502. // comment placeholders should be skipped, e.g. v-if
  1503. else if (keepComment || child.type !== Comment) {
  1504. ret.push(child);
  1505. }
  1506. }
  1507. // #1126 if a transition children list contains multiple sub fragments, these
  1508. // fragments will be merged into a flat children array. Since each v-for
  1509. // fragment may contain different static bindings inside, we need to de-op
  1510. // these children to force full diffs to ensure correct behavior.
  1511. if (keyedFragmentCount > 1) {
  1512. for (let i = 0; i < ret.length; i++) {
  1513. ret[i].patchFlag = -2 /* BAIL */;
  1514. }
  1515. }
  1516. return ret;
  1517. }
  1518. // implementation, close to no-op
  1519. function defineComponent(options) {
  1520. return isFunction(options) ? { setup: options, name: options.name } : options;
  1521. }
  1522. const isAsyncWrapper = (i) => !!i.type.__asyncLoader;
  1523. function defineAsyncComponent(source) {
  1524. if (isFunction(source)) {
  1525. source = { loader: source };
  1526. }
  1527. const { loader, loadingComponent, errorComponent, delay = 200, timeout, // undefined = never times out
  1528. suspensible = true, onError: userOnError } = source;
  1529. let pendingRequest = null;
  1530. let resolvedComp;
  1531. let retries = 0;
  1532. const retry = () => {
  1533. retries++;
  1534. pendingRequest = null;
  1535. return load();
  1536. };
  1537. const load = () => {
  1538. let thisRequest;
  1539. return (pendingRequest ||
  1540. (thisRequest = pendingRequest =
  1541. loader()
  1542. .catch(err => {
  1543. err = err instanceof Error ? err : new Error(String(err));
  1544. if (userOnError) {
  1545. return new Promise((resolve, reject) => {
  1546. const userRetry = () => resolve(retry());
  1547. const userFail = () => reject(err);
  1548. userOnError(err, userRetry, userFail, retries + 1);
  1549. });
  1550. }
  1551. else {
  1552. throw err;
  1553. }
  1554. })
  1555. .then((comp) => {
  1556. if (thisRequest !== pendingRequest && pendingRequest) {
  1557. return pendingRequest;
  1558. }
  1559. if ((process.env.NODE_ENV !== 'production') && !comp) {
  1560. warn(`Async component loader resolved to undefined. ` +
  1561. `If you are using retry(), make sure to return its return value.`);
  1562. }
  1563. // interop module default
  1564. if (comp &&
  1565. (comp.__esModule || comp[Symbol.toStringTag] === 'Module')) {
  1566. comp = comp.default;
  1567. }
  1568. if ((process.env.NODE_ENV !== 'production') && comp && !isObject(comp) && !isFunction(comp)) {
  1569. throw new Error(`Invalid async component load result: ${comp}`);
  1570. }
  1571. resolvedComp = comp;
  1572. return comp;
  1573. })));
  1574. };
  1575. return defineComponent({
  1576. name: 'AsyncComponentWrapper',
  1577. __asyncLoader: load,
  1578. get __asyncResolved() {
  1579. return resolvedComp;
  1580. },
  1581. setup() {
  1582. const instance = currentInstance;
  1583. // already resolved
  1584. if (resolvedComp) {
  1585. return () => createInnerComp(resolvedComp, instance);
  1586. }
  1587. const onError = (err) => {
  1588. pendingRequest = null;
  1589. handleError(err, instance, 13 /* ASYNC_COMPONENT_LOADER */, !errorComponent /* do not throw in dev if user provided error component */);
  1590. };
  1591. // suspense-controlled or SSR.
  1592. if ((suspensible && instance.suspense) ||
  1593. (isInSSRComponentSetup)) {
  1594. return load()
  1595. .then(comp => {
  1596. return () => createInnerComp(comp, instance);
  1597. })
  1598. .catch(err => {
  1599. onError(err);
  1600. return () => errorComponent
  1601. ? createVNode(errorComponent, {
  1602. error: err
  1603. })
  1604. : null;
  1605. });
  1606. }
  1607. const loaded = ref(false);
  1608. const error = ref();
  1609. const delayed = ref(!!delay);
  1610. if (delay) {
  1611. setTimeout(() => {
  1612. delayed.value = false;
  1613. }, delay);
  1614. }
  1615. if (timeout != null) {
  1616. setTimeout(() => {
  1617. if (!loaded.value && !error.value) {
  1618. const err = new Error(`Async component timed out after ${timeout}ms.`);
  1619. onError(err);
  1620. error.value = err;
  1621. }
  1622. }, timeout);
  1623. }
  1624. load()
  1625. .then(() => {
  1626. loaded.value = true;
  1627. if (instance.parent && isKeepAlive(instance.parent.vnode)) {
  1628. // parent is keep-alive, force update so the loaded component's
  1629. // name is taken into account
  1630. queueJob(instance.parent.update);
  1631. }
  1632. })
  1633. .catch(err => {
  1634. onError(err);
  1635. error.value = err;
  1636. });
  1637. return () => {
  1638. if (loaded.value && resolvedComp) {
  1639. return createInnerComp(resolvedComp, instance);
  1640. }
  1641. else if (error.value && errorComponent) {
  1642. return createVNode(errorComponent, {
  1643. error: error.value
  1644. });
  1645. }
  1646. else if (loadingComponent && !delayed.value) {
  1647. return createVNode(loadingComponent);
  1648. }
  1649. };
  1650. }
  1651. });
  1652. }
  1653. function createInnerComp(comp, { vnode: { ref, props, children } }) {
  1654. const vnode = createVNode(comp, props, children);
  1655. // ensure inner component inherits the async wrapper's ref owner
  1656. vnode.ref = ref;
  1657. return vnode;
  1658. }
  1659. const isKeepAlive = (vnode) => vnode.type.__isKeepAlive;
  1660. const KeepAliveImpl = {
  1661. name: `KeepAlive`,
  1662. // Marker for special handling inside the renderer. We are not using a ===
  1663. // check directly on KeepAlive in the renderer, because importing it directly
  1664. // would prevent it from being tree-shaken.
  1665. __isKeepAlive: true,
  1666. props: {
  1667. include: [String, RegExp, Array],
  1668. exclude: [String, RegExp, Array],
  1669. max: [String, Number]
  1670. },
  1671. setup(props, { slots }) {
  1672. const instance = getCurrentInstance();
  1673. // KeepAlive communicates with the instantiated renderer via the
  1674. // ctx where the renderer passes in its internals,
  1675. // and the KeepAlive instance exposes activate/deactivate implementations.
  1676. // The whole point of this is to avoid importing KeepAlive directly in the
  1677. // renderer to facilitate tree-shaking.
  1678. const sharedContext = instance.ctx;
  1679. // if the internal renderer is not registered, it indicates that this is server-side rendering,
  1680. // for KeepAlive, we just need to render its children
  1681. if (!sharedContext.renderer) {
  1682. return slots.default;
  1683. }
  1684. const cache = new Map();
  1685. const keys = new Set();
  1686. let current = null;
  1687. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  1688. instance.__v_cache = cache;
  1689. }
  1690. const parentSuspense = instance.suspense;
  1691. const { renderer: { p: patch, m: move, um: _unmount, o: { createElement } } } = sharedContext;
  1692. const storageContainer = createElement('div');
  1693. sharedContext.activate = (vnode, container, anchor, isSVG, optimized) => {
  1694. const instance = vnode.component;
  1695. move(vnode, container, anchor, 0 /* ENTER */, parentSuspense);
  1696. // in case props have changed
  1697. patch(instance.vnode, vnode, container, anchor, instance, parentSuspense, isSVG, vnode.slotScopeIds, optimized);
  1698. queuePostRenderEffect(() => {
  1699. instance.isDeactivated = false;
  1700. if (instance.a) {
  1701. invokeArrayFns(instance.a);
  1702. }
  1703. const vnodeHook = vnode.props && vnode.props.onVnodeMounted;
  1704. if (vnodeHook) {
  1705. invokeVNodeHook(vnodeHook, instance.parent, vnode);
  1706. }
  1707. }, parentSuspense);
  1708. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  1709. // Update components tree
  1710. devtoolsComponentAdded(instance);
  1711. }
  1712. };
  1713. sharedContext.deactivate = (vnode) => {
  1714. const instance = vnode.component;
  1715. move(vnode, storageContainer, null, 1 /* LEAVE */, parentSuspense);
  1716. queuePostRenderEffect(() => {
  1717. if (instance.da) {
  1718. invokeArrayFns(instance.da);
  1719. }
  1720. const vnodeHook = vnode.props && vnode.props.onVnodeUnmounted;
  1721. if (vnodeHook) {
  1722. invokeVNodeHook(vnodeHook, instance.parent, vnode);
  1723. }
  1724. instance.isDeactivated = true;
  1725. }, parentSuspense);
  1726. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  1727. // Update components tree
  1728. devtoolsComponentAdded(instance);
  1729. }
  1730. };
  1731. function unmount(vnode) {
  1732. // reset the shapeFlag so it can be properly unmounted
  1733. resetShapeFlag(vnode);
  1734. _unmount(vnode, instance, parentSuspense);
  1735. }
  1736. function pruneCache(filter) {
  1737. cache.forEach((vnode, key) => {
  1738. const name = getComponentName(vnode.type);
  1739. if (name && (!filter || !filter(name))) {
  1740. pruneCacheEntry(key);
  1741. }
  1742. });
  1743. }
  1744. function pruneCacheEntry(key) {
  1745. const cached = cache.get(key);
  1746. if (!current || cached.type !== current.type) {
  1747. unmount(cached);
  1748. }
  1749. else if (current) {
  1750. // current active instance should no longer be kept-alive.
  1751. // we can't unmount it now but it might be later, so reset its flag now.
  1752. resetShapeFlag(current);
  1753. }
  1754. cache.delete(key);
  1755. keys.delete(key);
  1756. }
  1757. // prune cache on include/exclude prop change
  1758. watch(() => [props.include, props.exclude], ([include, exclude]) => {
  1759. include && pruneCache(name => matches(include, name));
  1760. exclude && pruneCache(name => !matches(exclude, name));
  1761. },
  1762. // prune post-render after `current` has been updated
  1763. { flush: 'post', deep: true });
  1764. // cache sub tree after render
  1765. let pendingCacheKey = null;
  1766. const cacheSubtree = () => {
  1767. // fix #1621, the pendingCacheKey could be 0
  1768. if (pendingCacheKey != null) {
  1769. cache.set(pendingCacheKey, getInnerChild(instance.subTree));
  1770. }
  1771. };
  1772. onMounted(cacheSubtree);
  1773. onUpdated(cacheSubtree);
  1774. onBeforeUnmount(() => {
  1775. cache.forEach(cached => {
  1776. const { subTree, suspense } = instance;
  1777. const vnode = getInnerChild(subTree);
  1778. if (cached.type === vnode.type) {
  1779. // current instance will be unmounted as part of keep-alive's unmount
  1780. resetShapeFlag(vnode);
  1781. // but invoke its deactivated hook here
  1782. const da = vnode.component.da;
  1783. da && queuePostRenderEffect(da, suspense);
  1784. return;
  1785. }
  1786. unmount(cached);
  1787. });
  1788. });
  1789. return () => {
  1790. pendingCacheKey = null;
  1791. if (!slots.default) {
  1792. return null;
  1793. }
  1794. const children = slots.default();
  1795. const rawVNode = children[0];
  1796. if (children.length > 1) {
  1797. if ((process.env.NODE_ENV !== 'production')) {
  1798. warn(`KeepAlive should contain exactly one component child.`);
  1799. }
  1800. current = null;
  1801. return children;
  1802. }
  1803. else if (!isVNode(rawVNode) ||
  1804. (!(rawVNode.shapeFlag & 4 /* STATEFUL_COMPONENT */) &&
  1805. !(rawVNode.shapeFlag & 128 /* SUSPENSE */))) {
  1806. current = null;
  1807. return rawVNode;
  1808. }
  1809. let vnode = getInnerChild(rawVNode);
  1810. const comp = vnode.type;
  1811. // for async components, name check should be based in its loaded
  1812. // inner component if available
  1813. const name = getComponentName(isAsyncWrapper(vnode)
  1814. ? vnode.type.__asyncResolved || {}
  1815. : comp);
  1816. const { include, exclude, max } = props;
  1817. if ((include && (!name || !matches(include, name))) ||
  1818. (exclude && name && matches(exclude, name))) {
  1819. current = vnode;
  1820. return rawVNode;
  1821. }
  1822. const key = vnode.key == null ? comp : vnode.key;
  1823. const cachedVNode = cache.get(key);
  1824. // clone vnode if it's reused because we are going to mutate it
  1825. if (vnode.el) {
  1826. vnode = cloneVNode(vnode);
  1827. if (rawVNode.shapeFlag & 128 /* SUSPENSE */) {
  1828. rawVNode.ssContent = vnode;
  1829. }
  1830. }
  1831. // #1513 it's possible for the returned vnode to be cloned due to attr
  1832. // fallthrough or scopeId, so the vnode here may not be the final vnode
  1833. // that is mounted. Instead of caching it directly, we store the pending
  1834. // key and cache `instance.subTree` (the normalized vnode) in
  1835. // beforeMount/beforeUpdate hooks.
  1836. pendingCacheKey = key;
  1837. if (cachedVNode) {
  1838. // copy over mounted state
  1839. vnode.el = cachedVNode.el;
  1840. vnode.component = cachedVNode.component;
  1841. if (vnode.transition) {
  1842. // recursively update transition hooks on subTree
  1843. setTransitionHooks(vnode, vnode.transition);
  1844. }
  1845. // avoid vnode being mounted as fresh
  1846. vnode.shapeFlag |= 512 /* COMPONENT_KEPT_ALIVE */;
  1847. // make this key the freshest
  1848. keys.delete(key);
  1849. keys.add(key);
  1850. }
  1851. else {
  1852. keys.add(key);
  1853. // prune oldest entry
  1854. if (max && keys.size > parseInt(max, 10)) {
  1855. pruneCacheEntry(keys.values().next().value);
  1856. }
  1857. }
  1858. // avoid vnode being unmounted
  1859. vnode.shapeFlag |= 256 /* COMPONENT_SHOULD_KEEP_ALIVE */;
  1860. current = vnode;
  1861. return rawVNode;
  1862. };
  1863. }
  1864. };
  1865. // export the public type for h/tsx inference
  1866. // also to avoid inline import() in generated d.ts files
  1867. const KeepAlive = KeepAliveImpl;
  1868. function matches(pattern, name) {
  1869. if (isArray(pattern)) {
  1870. return pattern.some((p) => matches(p, name));
  1871. }
  1872. else if (isString(pattern)) {
  1873. return pattern.split(',').indexOf(name) > -1;
  1874. }
  1875. else if (pattern.test) {
  1876. return pattern.test(name);
  1877. }
  1878. /* istanbul ignore next */
  1879. return false;
  1880. }
  1881. function onActivated(hook, target) {
  1882. registerKeepAliveHook(hook, "a" /* ACTIVATED */, target);
  1883. }
  1884. function onDeactivated(hook, target) {
  1885. registerKeepAliveHook(hook, "da" /* DEACTIVATED */, target);
  1886. }
  1887. function registerKeepAliveHook(hook, type, target = currentInstance) {
  1888. // cache the deactivate branch check wrapper for injected hooks so the same
  1889. // hook can be properly deduped by the scheduler. "__wdc" stands for "with
  1890. // deactivation check".
  1891. const wrappedHook = hook.__wdc ||
  1892. (hook.__wdc = () => {
  1893. // only fire the hook if the target instance is NOT in a deactivated branch.
  1894. let current = target;
  1895. while (current) {
  1896. if (current.isDeactivated) {
  1897. return;
  1898. }
  1899. current = current.parent;
  1900. }
  1901. return hook();
  1902. });
  1903. injectHook(type, wrappedHook, target);
  1904. // In addition to registering it on the target instance, we walk up the parent
  1905. // chain and register it on all ancestor instances that are keep-alive roots.
  1906. // This avoids the need to walk the entire component tree when invoking these
  1907. // hooks, and more importantly, avoids the need to track child components in
  1908. // arrays.
  1909. if (target) {
  1910. let current = target.parent;
  1911. while (current && current.parent) {
  1912. if (isKeepAlive(current.parent.vnode)) {
  1913. injectToKeepAliveRoot(wrappedHook, type, target, current);
  1914. }
  1915. current = current.parent;
  1916. }
  1917. }
  1918. }
  1919. function injectToKeepAliveRoot(hook, type, target, keepAliveRoot) {
  1920. // injectHook wraps the original for error handling, so make sure to remove
  1921. // the wrapped version.
  1922. const injected = injectHook(type, hook, keepAliveRoot, true /* prepend */);
  1923. onUnmounted(() => {
  1924. remove(keepAliveRoot[type], injected);
  1925. }, target);
  1926. }
  1927. function resetShapeFlag(vnode) {
  1928. let shapeFlag = vnode.shapeFlag;
  1929. if (shapeFlag & 256 /* COMPONENT_SHOULD_KEEP_ALIVE */) {
  1930. shapeFlag -= 256 /* COMPONENT_SHOULD_KEEP_ALIVE */;
  1931. }
  1932. if (shapeFlag & 512 /* COMPONENT_KEPT_ALIVE */) {
  1933. shapeFlag -= 512 /* COMPONENT_KEPT_ALIVE */;
  1934. }
  1935. vnode.shapeFlag = shapeFlag;
  1936. }
  1937. function getInnerChild(vnode) {
  1938. return vnode.shapeFlag & 128 /* SUSPENSE */ ? vnode.ssContent : vnode;
  1939. }
  1940. function injectHook(type, hook, target = currentInstance, prepend = false) {
  1941. if (target) {
  1942. const hooks = target[type] || (target[type] = []);
  1943. // cache the error handling wrapper for injected hooks so the same hook
  1944. // can be properly deduped by the scheduler. "__weh" stands for "with error
  1945. // handling".
  1946. const wrappedHook = hook.__weh ||
  1947. (hook.__weh = (...args) => {
  1948. if (target.isUnmounted) {
  1949. return;
  1950. }
  1951. // disable tracking inside all lifecycle hooks
  1952. // since they can potentially be called inside effects.
  1953. pauseTracking();
  1954. // Set currentInstance during hook invocation.
  1955. // This assumes the hook does not synchronously trigger other hooks, which
  1956. // can only be false when the user does something really funky.
  1957. setCurrentInstance(target);
  1958. const res = callWithAsyncErrorHandling(hook, target, type, args);
  1959. unsetCurrentInstance();
  1960. resetTracking();
  1961. return res;
  1962. });
  1963. if (prepend) {
  1964. hooks.unshift(wrappedHook);
  1965. }
  1966. else {
  1967. hooks.push(wrappedHook);
  1968. }
  1969. return wrappedHook;
  1970. }
  1971. else if ((process.env.NODE_ENV !== 'production')) {
  1972. const apiName = toHandlerKey(ErrorTypeStrings[type].replace(/ hook$/, ''));
  1973. warn(`${apiName} is called when there is no active component instance to be ` +
  1974. `associated with. ` +
  1975. `Lifecycle injection APIs can only be used during execution of setup().` +
  1976. (` If you are using async setup(), make sure to register lifecycle ` +
  1977. `hooks before the first await statement.`
  1978. ));
  1979. }
  1980. }
  1981. const createHook = (lifecycle) => (hook, target = currentInstance) =>
  1982. // post-create lifecycle registrations are noops during SSR (except for serverPrefetch)
  1983. (!isInSSRComponentSetup || lifecycle === "sp" /* SERVER_PREFETCH */) &&
  1984. injectHook(lifecycle, hook, target);
  1985. const onBeforeMount = createHook("bm" /* BEFORE_MOUNT */);
  1986. const onMounted = createHook("m" /* MOUNTED */);
  1987. const onBeforeUpdate = createHook("bu" /* BEFORE_UPDATE */);
  1988. const onUpdated = createHook("u" /* UPDATED */);
  1989. const onBeforeUnmount = createHook("bum" /* BEFORE_UNMOUNT */);
  1990. const onUnmounted = createHook("um" /* UNMOUNTED */);
  1991. const onServerPrefetch = createHook("sp" /* SERVER_PREFETCH */);
  1992. const onRenderTriggered = createHook("rtg" /* RENDER_TRIGGERED */);
  1993. const onRenderTracked = createHook("rtc" /* RENDER_TRACKED */);
  1994. function onErrorCaptured(hook, target = currentInstance) {
  1995. injectHook("ec" /* ERROR_CAPTURED */, hook, target);
  1996. }
  1997. function createDuplicateChecker() {
  1998. const cache = Object.create(null);
  1999. return (type, key) => {
  2000. if (cache[key]) {
  2001. warn(`${type} property "${key}" is already defined in ${cache[key]}.`);
  2002. }
  2003. else {
  2004. cache[key] = type;
  2005. }
  2006. };
  2007. }
  2008. let shouldCacheAccess = true;
  2009. function applyOptions(instance) {
  2010. const options = resolveMergedOptions(instance);
  2011. const publicThis = instance.proxy;
  2012. const ctx = instance.ctx;
  2013. // do not cache property access on public proxy during state initialization
  2014. shouldCacheAccess = false;
  2015. // call beforeCreate first before accessing other options since
  2016. // the hook may mutate resolved options (#2791)
  2017. if (options.beforeCreate) {
  2018. callHook(options.beforeCreate, instance, "bc" /* BEFORE_CREATE */);
  2019. }
  2020. const {
  2021. // state
  2022. data: dataOptions, computed: computedOptions, methods, watch: watchOptions, provide: provideOptions, inject: injectOptions,
  2023. // lifecycle
  2024. created, beforeMount, mounted, beforeUpdate, updated, activated, deactivated, beforeDestroy, beforeUnmount, destroyed, unmounted, render, renderTracked, renderTriggered, errorCaptured, serverPrefetch,
  2025. // public API
  2026. expose, inheritAttrs,
  2027. // assets
  2028. components, directives, filters } = options;
  2029. const checkDuplicateProperties = (process.env.NODE_ENV !== 'production') ? createDuplicateChecker() : null;
  2030. if ((process.env.NODE_ENV !== 'production')) {
  2031. const [propsOptions] = instance.propsOptions;
  2032. if (propsOptions) {
  2033. for (const key in propsOptions) {
  2034. checkDuplicateProperties("Props" /* PROPS */, key);
  2035. }
  2036. }
  2037. }
  2038. // options initialization order (to be consistent with Vue 2):
  2039. // - props (already done outside of this function)
  2040. // - inject
  2041. // - methods
  2042. // - data (deferred since it relies on `this` access)
  2043. // - computed
  2044. // - watch (deferred since it relies on `this` access)
  2045. if (injectOptions) {
  2046. resolveInjections(injectOptions, ctx, checkDuplicateProperties, instance.appContext.config.unwrapInjectedRef);
  2047. }
  2048. if (methods) {
  2049. for (const key in methods) {
  2050. const methodHandler = methods[key];
  2051. if (isFunction(methodHandler)) {
  2052. // In dev mode, we use the `createRenderContext` function to define
  2053. // methods to the proxy target, and those are read-only but
  2054. // reconfigurable, so it needs to be redefined here
  2055. if ((process.env.NODE_ENV !== 'production')) {
  2056. Object.defineProperty(ctx, key, {
  2057. value: methodHandler.bind(publicThis),
  2058. configurable: true,
  2059. enumerable: true,
  2060. writable: true
  2061. });
  2062. }
  2063. else {
  2064. ctx[key] = methodHandler.bind(publicThis);
  2065. }
  2066. if ((process.env.NODE_ENV !== 'production')) {
  2067. checkDuplicateProperties("Methods" /* METHODS */, key);
  2068. }
  2069. }
  2070. else if ((process.env.NODE_ENV !== 'production')) {
  2071. warn(`Method "${key}" has type "${typeof methodHandler}" in the component definition. ` +
  2072. `Did you reference the function correctly?`);
  2073. }
  2074. }
  2075. }
  2076. if (dataOptions) {
  2077. if ((process.env.NODE_ENV !== 'production') && !isFunction(dataOptions)) {
  2078. warn(`The data option must be a function. ` +
  2079. `Plain object usage is no longer supported.`);
  2080. }
  2081. const data = dataOptions.call(publicThis, publicThis);
  2082. if ((process.env.NODE_ENV !== 'production') && isPromise(data)) {
  2083. warn(`data() returned a Promise - note data() cannot be async; If you ` +
  2084. `intend to perform data fetching before component renders, use ` +
  2085. `async setup() + <Suspense>.`);
  2086. }
  2087. if (!isObject(data)) {
  2088. (process.env.NODE_ENV !== 'production') && warn(`data() should return an object.`);
  2089. }
  2090. else {
  2091. instance.data = reactive(data);
  2092. if ((process.env.NODE_ENV !== 'production')) {
  2093. for (const key in data) {
  2094. checkDuplicateProperties("Data" /* DATA */, key);
  2095. // expose data on ctx during dev
  2096. if (key[0] !== '$' && key[0] !== '_') {
  2097. Object.defineProperty(ctx, key, {
  2098. configurable: true,
  2099. enumerable: true,
  2100. get: () => data[key],
  2101. set: NOOP
  2102. });
  2103. }
  2104. }
  2105. }
  2106. }
  2107. }
  2108. // state initialization complete at this point - start caching access
  2109. shouldCacheAccess = true;
  2110. if (computedOptions) {
  2111. for (const key in computedOptions) {
  2112. const opt = computedOptions[key];
  2113. const get = isFunction(opt)
  2114. ? opt.bind(publicThis, publicThis)
  2115. : isFunction(opt.get)
  2116. ? opt.get.bind(publicThis, publicThis)
  2117. : NOOP;
  2118. if ((process.env.NODE_ENV !== 'production') && get === NOOP) {
  2119. warn(`Computed property "${key}" has no getter.`);
  2120. }
  2121. const set = !isFunction(opt) && isFunction(opt.set)
  2122. ? opt.set.bind(publicThis)
  2123. : (process.env.NODE_ENV !== 'production')
  2124. ? () => {
  2125. warn(`Write operation failed: computed property "${key}" is readonly.`);
  2126. }
  2127. : NOOP;
  2128. const c = computed({
  2129. get,
  2130. set
  2131. });
  2132. Object.defineProperty(ctx, key, {
  2133. enumerable: true,
  2134. configurable: true,
  2135. get: () => c.value,
  2136. set: v => (c.value = v)
  2137. });
  2138. if ((process.env.NODE_ENV !== 'production')) {
  2139. checkDuplicateProperties("Computed" /* COMPUTED */, key);
  2140. }
  2141. }
  2142. }
  2143. if (watchOptions) {
  2144. for (const key in watchOptions) {
  2145. createWatcher(watchOptions[key], ctx, publicThis, key);
  2146. }
  2147. }
  2148. if (provideOptions) {
  2149. const provides = isFunction(provideOptions)
  2150. ? provideOptions.call(publicThis)
  2151. : provideOptions;
  2152. Reflect.ownKeys(provides).forEach(key => {
  2153. provide(key, provides[key]);
  2154. });
  2155. }
  2156. if (created) {
  2157. callHook(created, instance, "c" /* CREATED */);
  2158. }
  2159. function registerLifecycleHook(register, hook) {
  2160. if (isArray(hook)) {
  2161. hook.forEach(_hook => register(_hook.bind(publicThis)));
  2162. }
  2163. else if (hook) {
  2164. register(hook.bind(publicThis));
  2165. }
  2166. }
  2167. registerLifecycleHook(onBeforeMount, beforeMount);
  2168. registerLifecycleHook(onMounted, mounted);
  2169. registerLifecycleHook(onBeforeUpdate, beforeUpdate);
  2170. registerLifecycleHook(onUpdated, updated);
  2171. registerLifecycleHook(onActivated, activated);
  2172. registerLifecycleHook(onDeactivated, deactivated);
  2173. registerLifecycleHook(onErrorCaptured, errorCaptured);
  2174. registerLifecycleHook(onRenderTracked, renderTracked);
  2175. registerLifecycleHook(onRenderTriggered, renderTriggered);
  2176. registerLifecycleHook(onBeforeUnmount, beforeUnmount);
  2177. registerLifecycleHook(onUnmounted, unmounted);
  2178. registerLifecycleHook(onServerPrefetch, serverPrefetch);
  2179. if (isArray(expose)) {
  2180. if (expose.length) {
  2181. const exposed = instance.exposed || (instance.exposed = {});
  2182. expose.forEach(key => {
  2183. Object.defineProperty(exposed, key, {
  2184. get: () => publicThis[key],
  2185. set: val => (publicThis[key] = val)
  2186. });
  2187. });
  2188. }
  2189. else if (!instance.exposed) {
  2190. instance.exposed = {};
  2191. }
  2192. }
  2193. // options that are handled when creating the instance but also need to be
  2194. // applied from mixins
  2195. if (render && instance.render === NOOP) {
  2196. instance.render = render;
  2197. }
  2198. if (inheritAttrs != null) {
  2199. instance.inheritAttrs = inheritAttrs;
  2200. }
  2201. // asset options.
  2202. if (components)
  2203. instance.components = components;
  2204. if (directives)
  2205. instance.directives = directives;
  2206. }
  2207. function resolveInjections(injectOptions, ctx, checkDuplicateProperties = NOOP, unwrapRef = false) {
  2208. if (isArray(injectOptions)) {
  2209. injectOptions = normalizeInject(injectOptions);
  2210. }
  2211. for (const key in injectOptions) {
  2212. const opt = injectOptions[key];
  2213. let injected;
  2214. if (isObject(opt)) {
  2215. if ('default' in opt) {
  2216. injected = inject(opt.from || key, opt.default, true /* treat default function as factory */);
  2217. }
  2218. else {
  2219. injected = inject(opt.from || key);
  2220. }
  2221. }
  2222. else {
  2223. injected = inject(opt);
  2224. }
  2225. if (isRef(injected)) {
  2226. // TODO remove the check in 3.3
  2227. if (unwrapRef) {
  2228. Object.defineProperty(ctx, key, {
  2229. enumerable: true,
  2230. configurable: true,
  2231. get: () => injected.value,
  2232. set: v => (injected.value = v)
  2233. });
  2234. }
  2235. else {
  2236. if ((process.env.NODE_ENV !== 'production')) {
  2237. warn(`injected property "${key}" is a ref and will be auto-unwrapped ` +
  2238. `and no longer needs \`.value\` in the next minor release. ` +
  2239. `To opt-in to the new behavior now, ` +
  2240. `set \`app.config.unwrapInjectedRef = true\` (this config is ` +
  2241. `temporary and will not be needed in the future.)`);
  2242. }
  2243. ctx[key] = injected;
  2244. }
  2245. }
  2246. else {
  2247. ctx[key] = injected;
  2248. }
  2249. if ((process.env.NODE_ENV !== 'production')) {
  2250. checkDuplicateProperties("Inject" /* INJECT */, key);
  2251. }
  2252. }
  2253. }
  2254. function callHook(hook, instance, type) {
  2255. callWithAsyncErrorHandling(isArray(hook)
  2256. ? hook.map(h => h.bind(instance.proxy))
  2257. : hook.bind(instance.proxy), instance, type);
  2258. }
  2259. function createWatcher(raw, ctx, publicThis, key) {
  2260. const getter = key.includes('.')
  2261. ? createPathGetter(publicThis, key)
  2262. : () => publicThis[key];
  2263. if (isString(raw)) {
  2264. const handler = ctx[raw];
  2265. if (isFunction(handler)) {
  2266. watch(getter, handler);
  2267. }
  2268. else if ((process.env.NODE_ENV !== 'production')) {
  2269. warn(`Invalid watch handler specified by key "${raw}"`, handler);
  2270. }
  2271. }
  2272. else if (isFunction(raw)) {
  2273. watch(getter, raw.bind(publicThis));
  2274. }
  2275. else if (isObject(raw)) {
  2276. if (isArray(raw)) {
  2277. raw.forEach(r => createWatcher(r, ctx, publicThis, key));
  2278. }
  2279. else {
  2280. const handler = isFunction(raw.handler)
  2281. ? raw.handler.bind(publicThis)
  2282. : ctx[raw.handler];
  2283. if (isFunction(handler)) {
  2284. watch(getter, handler, raw);
  2285. }
  2286. else if ((process.env.NODE_ENV !== 'production')) {
  2287. warn(`Invalid watch handler specified by key "${raw.handler}"`, handler);
  2288. }
  2289. }
  2290. }
  2291. else if ((process.env.NODE_ENV !== 'production')) {
  2292. warn(`Invalid watch option: "${key}"`, raw);
  2293. }
  2294. }
  2295. /**
  2296. * Resolve merged options and cache it on the component.
  2297. * This is done only once per-component since the merging does not involve
  2298. * instances.
  2299. */
  2300. function resolveMergedOptions(instance) {
  2301. const base = instance.type;
  2302. const { mixins, extends: extendsOptions } = base;
  2303. const { mixins: globalMixins, optionsCache: cache, config: { optionMergeStrategies } } = instance.appContext;
  2304. const cached = cache.get(base);
  2305. let resolved;
  2306. if (cached) {
  2307. resolved = cached;
  2308. }
  2309. else if (!globalMixins.length && !mixins && !extendsOptions) {
  2310. {
  2311. resolved = base;
  2312. }
  2313. }
  2314. else {
  2315. resolved = {};
  2316. if (globalMixins.length) {
  2317. globalMixins.forEach(m => mergeOptions(resolved, m, optionMergeStrategies, true));
  2318. }
  2319. mergeOptions(resolved, base, optionMergeStrategies);
  2320. }
  2321. cache.set(base, resolved);
  2322. return resolved;
  2323. }
  2324. function mergeOptions(to, from, strats, asMixin = false) {
  2325. const { mixins, extends: extendsOptions } = from;
  2326. if (extendsOptions) {
  2327. mergeOptions(to, extendsOptions, strats, true);
  2328. }
  2329. if (mixins) {
  2330. mixins.forEach((m) => mergeOptions(to, m, strats, true));
  2331. }
  2332. for (const key in from) {
  2333. if (asMixin && key === 'expose') {
  2334. (process.env.NODE_ENV !== 'production') &&
  2335. warn(`"expose" option is ignored when declared in mixins or extends. ` +
  2336. `It should only be declared in the base component itself.`);
  2337. }
  2338. else {
  2339. const strat = internalOptionMergeStrats[key] || (strats && strats[key]);
  2340. to[key] = strat ? strat(to[key], from[key]) : from[key];
  2341. }
  2342. }
  2343. return to;
  2344. }
  2345. const internalOptionMergeStrats = {
  2346. data: mergeDataFn,
  2347. props: mergeObjectOptions,
  2348. emits: mergeObjectOptions,
  2349. // objects
  2350. methods: mergeObjectOptions,
  2351. computed: mergeObjectOptions,
  2352. // lifecycle
  2353. beforeCreate: mergeAsArray,
  2354. created: mergeAsArray,
  2355. beforeMount: mergeAsArray,
  2356. mounted: mergeAsArray,
  2357. beforeUpdate: mergeAsArray,
  2358. updated: mergeAsArray,
  2359. beforeDestroy: mergeAsArray,
  2360. beforeUnmount: mergeAsArray,
  2361. destroyed: mergeAsArray,
  2362. unmounted: mergeAsArray,
  2363. activated: mergeAsArray,
  2364. deactivated: mergeAsArray,
  2365. errorCaptured: mergeAsArray,
  2366. serverPrefetch: mergeAsArray,
  2367. // assets
  2368. components: mergeObjectOptions,
  2369. directives: mergeObjectOptions,
  2370. // watch
  2371. watch: mergeWatchOptions,
  2372. // provide / inject
  2373. provide: mergeDataFn,
  2374. inject: mergeInject
  2375. };
  2376. function mergeDataFn(to, from) {
  2377. if (!from) {
  2378. return to;
  2379. }
  2380. if (!to) {
  2381. return from;
  2382. }
  2383. return function mergedDataFn() {
  2384. return (extend)(isFunction(to) ? to.call(this, this) : to, isFunction(from) ? from.call(this, this) : from);
  2385. };
  2386. }
  2387. function mergeInject(to, from) {
  2388. return mergeObjectOptions(normalizeInject(to), normalizeInject(from));
  2389. }
  2390. function normalizeInject(raw) {
  2391. if (isArray(raw)) {
  2392. const res = {};
  2393. for (let i = 0; i < raw.length; i++) {
  2394. res[raw[i]] = raw[i];
  2395. }
  2396. return res;
  2397. }
  2398. return raw;
  2399. }
  2400. function mergeAsArray(to, from) {
  2401. return to ? [...new Set([].concat(to, from))] : from;
  2402. }
  2403. function mergeObjectOptions(to, from) {
  2404. return to ? extend(extend(Object.create(null), to), from) : from;
  2405. }
  2406. function mergeWatchOptions(to, from) {
  2407. if (!to)
  2408. return from;
  2409. if (!from)
  2410. return to;
  2411. const merged = extend(Object.create(null), to);
  2412. for (const key in from) {
  2413. merged[key] = mergeAsArray(to[key], from[key]);
  2414. }
  2415. return merged;
  2416. }
  2417. function initProps(instance, rawProps, isStateful, // result of bitwise flag comparison
  2418. isSSR = false) {
  2419. const props = {};
  2420. const attrs = {};
  2421. def(attrs, InternalObjectKey, 1);
  2422. instance.propsDefaults = Object.create(null);
  2423. setFullProps(instance, rawProps, props, attrs);
  2424. // ensure all declared prop keys are present
  2425. for (const key in instance.propsOptions[0]) {
  2426. if (!(key in props)) {
  2427. props[key] = undefined;
  2428. }
  2429. }
  2430. // validation
  2431. if ((process.env.NODE_ENV !== 'production')) {
  2432. validateProps(rawProps || {}, props, instance);
  2433. }
  2434. if (isStateful) {
  2435. // stateful
  2436. instance.props = isSSR ? props : shallowReactive(props);
  2437. }
  2438. else {
  2439. if (!instance.type.props) {
  2440. // functional w/ optional props, props === attrs
  2441. instance.props = attrs;
  2442. }
  2443. else {
  2444. // functional w/ declared props
  2445. instance.props = props;
  2446. }
  2447. }
  2448. instance.attrs = attrs;
  2449. }
  2450. function updateProps(instance, rawProps, rawPrevProps, optimized) {
  2451. const { props, attrs, vnode: { patchFlag } } = instance;
  2452. const rawCurrentProps = toRaw(props);
  2453. const [options] = instance.propsOptions;
  2454. let hasAttrsChanged = false;
  2455. if (
  2456. // always force full diff in dev
  2457. // - #1942 if hmr is enabled with sfc component
  2458. // - vite#872 non-sfc component used by sfc component
  2459. !((process.env.NODE_ENV !== 'production') &&
  2460. (instance.type.__hmrId ||
  2461. (instance.parent && instance.parent.type.__hmrId))) &&
  2462. (optimized || patchFlag > 0) &&
  2463. !(patchFlag & 16 /* FULL_PROPS */)) {
  2464. if (patchFlag & 8 /* PROPS */) {
  2465. // Compiler-generated props & no keys change, just set the updated
  2466. // the props.
  2467. const propsToUpdate = instance.vnode.dynamicProps;
  2468. for (let i = 0; i < propsToUpdate.length; i++) {
  2469. let key = propsToUpdate[i];
  2470. // PROPS flag guarantees rawProps to be non-null
  2471. const value = rawProps[key];
  2472. if (options) {
  2473. // attr / props separation was done on init and will be consistent
  2474. // in this code path, so just check if attrs have it.
  2475. if (hasOwn(attrs, key)) {
  2476. if (value !== attrs[key]) {
  2477. attrs[key] = value;
  2478. hasAttrsChanged = true;
  2479. }
  2480. }
  2481. else {
  2482. const camelizedKey = camelize(key);
  2483. props[camelizedKey] = resolvePropValue(options, rawCurrentProps, camelizedKey, value, instance, false /* isAbsent */);
  2484. }
  2485. }
  2486. else {
  2487. if (value !== attrs[key]) {
  2488. attrs[key] = value;
  2489. hasAttrsChanged = true;
  2490. }
  2491. }
  2492. }
  2493. }
  2494. }
  2495. else {
  2496. // full props update.
  2497. if (setFullProps(instance, rawProps, props, attrs)) {
  2498. hasAttrsChanged = true;
  2499. }
  2500. // in case of dynamic props, check if we need to delete keys from
  2501. // the props object
  2502. let kebabKey;
  2503. for (const key in rawCurrentProps) {
  2504. if (!rawProps ||
  2505. // for camelCase
  2506. (!hasOwn(rawProps, key) &&
  2507. // it's possible the original props was passed in as kebab-case
  2508. // and converted to camelCase (#955)
  2509. ((kebabKey = hyphenate(key)) === key || !hasOwn(rawProps, kebabKey)))) {
  2510. if (options) {
  2511. if (rawPrevProps &&
  2512. // for camelCase
  2513. (rawPrevProps[key] !== undefined ||
  2514. // for kebab-case
  2515. rawPrevProps[kebabKey] !== undefined)) {
  2516. props[key] = resolvePropValue(options, rawCurrentProps, key, undefined, instance, true /* isAbsent */);
  2517. }
  2518. }
  2519. else {
  2520. delete props[key];
  2521. }
  2522. }
  2523. }
  2524. // in the case of functional component w/o props declaration, props and
  2525. // attrs point to the same object so it should already have been updated.
  2526. if (attrs !== rawCurrentProps) {
  2527. for (const key in attrs) {
  2528. if (!rawProps || !hasOwn(rawProps, key)) {
  2529. delete attrs[key];
  2530. hasAttrsChanged = true;
  2531. }
  2532. }
  2533. }
  2534. }
  2535. // trigger updates for $attrs in case it's used in component slots
  2536. if (hasAttrsChanged) {
  2537. trigger(instance, "set" /* SET */, '$attrs');
  2538. }
  2539. if ((process.env.NODE_ENV !== 'production')) {
  2540. validateProps(rawProps || {}, props, instance);
  2541. }
  2542. }
  2543. function setFullProps(instance, rawProps, props, attrs) {
  2544. const [options, needCastKeys] = instance.propsOptions;
  2545. let hasAttrsChanged = false;
  2546. let rawCastValues;
  2547. if (rawProps) {
  2548. for (let key in rawProps) {
  2549. // key, ref are reserved and never passed down
  2550. if (isReservedProp(key)) {
  2551. continue;
  2552. }
  2553. const value = rawProps[key];
  2554. // prop option names are camelized during normalization, so to support
  2555. // kebab -> camel conversion here we need to camelize the key.
  2556. let camelKey;
  2557. if (options && hasOwn(options, (camelKey = camelize(key)))) {
  2558. if (!needCastKeys || !needCastKeys.includes(camelKey)) {
  2559. props[camelKey] = value;
  2560. }
  2561. else {
  2562. (rawCastValues || (rawCastValues = {}))[camelKey] = value;
  2563. }
  2564. }
  2565. else if (!isEmitListener(instance.emitsOptions, key)) {
  2566. if (!(key in attrs) || value !== attrs[key]) {
  2567. attrs[key] = value;
  2568. hasAttrsChanged = true;
  2569. }
  2570. }
  2571. }
  2572. }
  2573. if (needCastKeys) {
  2574. const rawCurrentProps = toRaw(props);
  2575. const castValues = rawCastValues || EMPTY_OBJ;
  2576. for (let i = 0; i < needCastKeys.length; i++) {
  2577. const key = needCastKeys[i];
  2578. props[key] = resolvePropValue(options, rawCurrentProps, key, castValues[key], instance, !hasOwn(castValues, key));
  2579. }
  2580. }
  2581. return hasAttrsChanged;
  2582. }
  2583. function resolvePropValue(options, props, key, value, instance, isAbsent) {
  2584. const opt = options[key];
  2585. if (opt != null) {
  2586. const hasDefault = hasOwn(opt, 'default');
  2587. // default values
  2588. if (hasDefault && value === undefined) {
  2589. const defaultValue = opt.default;
  2590. if (opt.type !== Function && isFunction(defaultValue)) {
  2591. const { propsDefaults } = instance;
  2592. if (key in propsDefaults) {
  2593. value = propsDefaults[key];
  2594. }
  2595. else {
  2596. setCurrentInstance(instance);
  2597. value = propsDefaults[key] = defaultValue.call(null, props);
  2598. unsetCurrentInstance();
  2599. }
  2600. }
  2601. else {
  2602. value = defaultValue;
  2603. }
  2604. }
  2605. // boolean casting
  2606. if (opt[0 /* shouldCast */]) {
  2607. if (isAbsent && !hasDefault) {
  2608. value = false;
  2609. }
  2610. else if (opt[1 /* shouldCastTrue */] &&
  2611. (value === '' || value === hyphenate(key))) {
  2612. value = true;
  2613. }
  2614. }
  2615. }
  2616. return value;
  2617. }
  2618. function normalizePropsOptions(comp, appContext, asMixin = false) {
  2619. const cache = appContext.propsCache;
  2620. const cached = cache.get(comp);
  2621. if (cached) {
  2622. return cached;
  2623. }
  2624. const raw = comp.props;
  2625. const normalized = {};
  2626. const needCastKeys = [];
  2627. // apply mixin/extends props
  2628. let hasExtends = false;
  2629. if (__VUE_OPTIONS_API__ && !isFunction(comp)) {
  2630. const extendProps = (raw) => {
  2631. hasExtends = true;
  2632. const [props, keys] = normalizePropsOptions(raw, appContext, true);
  2633. extend(normalized, props);
  2634. if (keys)
  2635. needCastKeys.push(...keys);
  2636. };
  2637. if (!asMixin && appContext.mixins.length) {
  2638. appContext.mixins.forEach(extendProps);
  2639. }
  2640. if (comp.extends) {
  2641. extendProps(comp.extends);
  2642. }
  2643. if (comp.mixins) {
  2644. comp.mixins.forEach(extendProps);
  2645. }
  2646. }
  2647. if (!raw && !hasExtends) {
  2648. cache.set(comp, EMPTY_ARR);
  2649. return EMPTY_ARR;
  2650. }
  2651. if (isArray(raw)) {
  2652. for (let i = 0; i < raw.length; i++) {
  2653. if ((process.env.NODE_ENV !== 'production') && !isString(raw[i])) {
  2654. warn(`props must be strings when using array syntax.`, raw[i]);
  2655. }
  2656. const normalizedKey = camelize(raw[i]);
  2657. if (validatePropName(normalizedKey)) {
  2658. normalized[normalizedKey] = EMPTY_OBJ;
  2659. }
  2660. }
  2661. }
  2662. else if (raw) {
  2663. if ((process.env.NODE_ENV !== 'production') && !isObject(raw)) {
  2664. warn(`invalid props options`, raw);
  2665. }
  2666. for (const key in raw) {
  2667. const normalizedKey = camelize(key);
  2668. if (validatePropName(normalizedKey)) {
  2669. const opt = raw[key];
  2670. const prop = (normalized[normalizedKey] =
  2671. isArray(opt) || isFunction(opt) ? { type: opt } : opt);
  2672. if (prop) {
  2673. const booleanIndex = getTypeIndex(Boolean, prop.type);
  2674. const stringIndex = getTypeIndex(String, prop.type);
  2675. prop[0 /* shouldCast */] = booleanIndex > -1;
  2676. prop[1 /* shouldCastTrue */] =
  2677. stringIndex < 0 || booleanIndex < stringIndex;
  2678. // if the prop needs boolean casting or default value
  2679. if (booleanIndex > -1 || hasOwn(prop, 'default')) {
  2680. needCastKeys.push(normalizedKey);
  2681. }
  2682. }
  2683. }
  2684. }
  2685. }
  2686. const res = [normalized, needCastKeys];
  2687. cache.set(comp, res);
  2688. return res;
  2689. }
  2690. function validatePropName(key) {
  2691. if (key[0] !== '$') {
  2692. return true;
  2693. }
  2694. else if ((process.env.NODE_ENV !== 'production')) {
  2695. warn(`Invalid prop name: "${key}" is a reserved property.`);
  2696. }
  2697. return false;
  2698. }
  2699. // use function string name to check type constructors
  2700. // so that it works across vms / iframes.
  2701. function getType(ctor) {
  2702. const match = ctor && ctor.toString().match(/^\s*function (\w+)/);
  2703. return match ? match[1] : ctor === null ? 'null' : '';
  2704. }
  2705. function isSameType(a, b) {
  2706. return getType(a) === getType(b);
  2707. }
  2708. function getTypeIndex(type, expectedTypes) {
  2709. if (isArray(expectedTypes)) {
  2710. return expectedTypes.findIndex(t => isSameType(t, type));
  2711. }
  2712. else if (isFunction(expectedTypes)) {
  2713. return isSameType(expectedTypes, type) ? 0 : -1;
  2714. }
  2715. return -1;
  2716. }
  2717. /**
  2718. * dev only
  2719. */
  2720. function validateProps(rawProps, props, instance) {
  2721. const resolvedValues = toRaw(props);
  2722. const options = instance.propsOptions[0];
  2723. for (const key in options) {
  2724. let opt = options[key];
  2725. if (opt == null)
  2726. continue;
  2727. validateProp(key, resolvedValues[key], opt, !hasOwn(rawProps, key) && !hasOwn(rawProps, hyphenate(key)));
  2728. }
  2729. }
  2730. /**
  2731. * dev only
  2732. */
  2733. function validateProp(name, value, prop, isAbsent) {
  2734. const { type, required, validator } = prop;
  2735. // required!
  2736. if (required && isAbsent) {
  2737. warn('Missing required prop: "' + name + '"');
  2738. return;
  2739. }
  2740. // missing but optional
  2741. if (value == null && !prop.required) {
  2742. return;
  2743. }
  2744. // type check
  2745. if (type != null && type !== true) {
  2746. let isValid = false;
  2747. const types = isArray(type) ? type : [type];
  2748. const expectedTypes = [];
  2749. // value is valid as long as one of the specified types match
  2750. for (let i = 0; i < types.length && !isValid; i++) {
  2751. const { valid, expectedType } = assertType(value, types[i]);
  2752. expectedTypes.push(expectedType || '');
  2753. isValid = valid;
  2754. }
  2755. if (!isValid) {
  2756. warn(getInvalidTypeMessage(name, value, expectedTypes));
  2757. return;
  2758. }
  2759. }
  2760. // custom validator
  2761. if (validator && !validator(value)) {
  2762. warn('Invalid prop: custom validator check failed for prop "' + name + '".');
  2763. }
  2764. }
  2765. const isSimpleType = /*#__PURE__*/ makeMap('String,Number,Boolean,Function,Symbol,BigInt');
  2766. /**
  2767. * dev only
  2768. */
  2769. function assertType(value, type) {
  2770. let valid;
  2771. const expectedType = getType(type);
  2772. if (isSimpleType(expectedType)) {
  2773. const t = typeof value;
  2774. valid = t === expectedType.toLowerCase();
  2775. // for primitive wrapper objects
  2776. if (!valid && t === 'object') {
  2777. valid = value instanceof type;
  2778. }
  2779. }
  2780. else if (expectedType === 'Object') {
  2781. valid = isObject(value);
  2782. }
  2783. else if (expectedType === 'Array') {
  2784. valid = isArray(value);
  2785. }
  2786. else if (expectedType === 'null') {
  2787. valid = value === null;
  2788. }
  2789. else {
  2790. valid = value instanceof type;
  2791. }
  2792. return {
  2793. valid,
  2794. expectedType
  2795. };
  2796. }
  2797. /**
  2798. * dev only
  2799. */
  2800. function getInvalidTypeMessage(name, value, expectedTypes) {
  2801. let message = `Invalid prop: type check failed for prop "${name}".` +
  2802. ` Expected ${expectedTypes.map(capitalize).join(' | ')}`;
  2803. const expectedType = expectedTypes[0];
  2804. const receivedType = toRawType(value);
  2805. const expectedValue = styleValue(value, expectedType);
  2806. const receivedValue = styleValue(value, receivedType);
  2807. // check if we need to specify expected value
  2808. if (expectedTypes.length === 1 &&
  2809. isExplicable(expectedType) &&
  2810. !isBoolean(expectedType, receivedType)) {
  2811. message += ` with value ${expectedValue}`;
  2812. }
  2813. message += `, got ${receivedType} `;
  2814. // check if we need to specify received value
  2815. if (isExplicable(receivedType)) {
  2816. message += `with value ${receivedValue}.`;
  2817. }
  2818. return message;
  2819. }
  2820. /**
  2821. * dev only
  2822. */
  2823. function styleValue(value, type) {
  2824. if (type === 'String') {
  2825. return `"${value}"`;
  2826. }
  2827. else if (type === 'Number') {
  2828. return `${Number(value)}`;
  2829. }
  2830. else {
  2831. return `${value}`;
  2832. }
  2833. }
  2834. /**
  2835. * dev only
  2836. */
  2837. function isExplicable(type) {
  2838. const explicitTypes = ['string', 'number', 'boolean'];
  2839. return explicitTypes.some(elem => type.toLowerCase() === elem);
  2840. }
  2841. /**
  2842. * dev only
  2843. */
  2844. function isBoolean(...args) {
  2845. return args.some(elem => elem.toLowerCase() === 'boolean');
  2846. }
  2847. const isInternalKey = (key) => key[0] === '_' || key === '$stable';
  2848. const normalizeSlotValue = (value) => isArray(value)
  2849. ? value.map(normalizeVNode)
  2850. : [normalizeVNode(value)];
  2851. const normalizeSlot = (key, rawSlot, ctx) => {
  2852. const normalized = withCtx((...args) => {
  2853. if ((process.env.NODE_ENV !== 'production') && currentInstance) {
  2854. warn(`Slot "${key}" invoked outside of the render function: ` +
  2855. `this will not track dependencies used in the slot. ` +
  2856. `Invoke the slot function inside the render function instead.`);
  2857. }
  2858. return normalizeSlotValue(rawSlot(...args));
  2859. }, ctx);
  2860. normalized._c = false;
  2861. return normalized;
  2862. };
  2863. const normalizeObjectSlots = (rawSlots, slots, instance) => {
  2864. const ctx = rawSlots._ctx;
  2865. for (const key in rawSlots) {
  2866. if (isInternalKey(key))
  2867. continue;
  2868. const value = rawSlots[key];
  2869. if (isFunction(value)) {
  2870. slots[key] = normalizeSlot(key, value, ctx);
  2871. }
  2872. else if (value != null) {
  2873. if ((process.env.NODE_ENV !== 'production') &&
  2874. !(false )) {
  2875. warn(`Non-function value encountered for slot "${key}". ` +
  2876. `Prefer function slots for better performance.`);
  2877. }
  2878. const normalized = normalizeSlotValue(value);
  2879. slots[key] = () => normalized;
  2880. }
  2881. }
  2882. };
  2883. const normalizeVNodeSlots = (instance, children) => {
  2884. if ((process.env.NODE_ENV !== 'production') &&
  2885. !isKeepAlive(instance.vnode) &&
  2886. !(false )) {
  2887. warn(`Non-function value encountered for default slot. ` +
  2888. `Prefer function slots for better performance.`);
  2889. }
  2890. const normalized = normalizeSlotValue(children);
  2891. instance.slots.default = () => normalized;
  2892. };
  2893. const initSlots = (instance, children) => {
  2894. if (instance.vnode.shapeFlag & 32 /* SLOTS_CHILDREN */) {
  2895. const type = children._;
  2896. if (type) {
  2897. // users can get the shallow readonly version of the slots object through `this.$slots`,
  2898. // we should avoid the proxy object polluting the slots of the internal instance
  2899. instance.slots = toRaw(children);
  2900. // make compiler marker non-enumerable
  2901. def(children, '_', type);
  2902. }
  2903. else {
  2904. normalizeObjectSlots(children, (instance.slots = {}));
  2905. }
  2906. }
  2907. else {
  2908. instance.slots = {};
  2909. if (children) {
  2910. normalizeVNodeSlots(instance, children);
  2911. }
  2912. }
  2913. def(instance.slots, InternalObjectKey, 1);
  2914. };
  2915. const updateSlots = (instance, children, optimized) => {
  2916. const { vnode, slots } = instance;
  2917. let needDeletionCheck = true;
  2918. let deletionComparisonTarget = EMPTY_OBJ;
  2919. if (vnode.shapeFlag & 32 /* SLOTS_CHILDREN */) {
  2920. const type = children._;
  2921. if (type) {
  2922. // compiled slots.
  2923. if ((process.env.NODE_ENV !== 'production') && isHmrUpdating) {
  2924. // Parent was HMR updated so slot content may have changed.
  2925. // force update slots and mark instance for hmr as well
  2926. extend(slots, children);
  2927. }
  2928. else if (optimized && type === 1 /* STABLE */) {
  2929. // compiled AND stable.
  2930. // no need to update, and skip stale slots removal.
  2931. needDeletionCheck = false;
  2932. }
  2933. else {
  2934. // compiled but dynamic (v-if/v-for on slots) - update slots, but skip
  2935. // normalization.
  2936. extend(slots, children);
  2937. // #2893
  2938. // when rendering the optimized slots by manually written render function,
  2939. // we need to delete the `slots._` flag if necessary to make subsequent updates reliable,
  2940. // i.e. let the `renderSlot` create the bailed Fragment
  2941. if (!optimized && type === 1 /* STABLE */) {
  2942. delete slots._;
  2943. }
  2944. }
  2945. }
  2946. else {
  2947. needDeletionCheck = !children.$stable;
  2948. normalizeObjectSlots(children, slots);
  2949. }
  2950. deletionComparisonTarget = children;
  2951. }
  2952. else if (children) {
  2953. // non slot object children (direct value) passed to a component
  2954. normalizeVNodeSlots(instance, children);
  2955. deletionComparisonTarget = { default: 1 };
  2956. }
  2957. // delete stale slots
  2958. if (needDeletionCheck) {
  2959. for (const key in slots) {
  2960. if (!isInternalKey(key) && !(key in deletionComparisonTarget)) {
  2961. delete slots[key];
  2962. }
  2963. }
  2964. }
  2965. };
  2966. /**
  2967. Runtime helper for applying directives to a vnode. Example usage:
  2968. const comp = resolveComponent('comp')
  2969. const foo = resolveDirective('foo')
  2970. const bar = resolveDirective('bar')
  2971. return withDirectives(h(comp), [
  2972. [foo, this.x],
  2973. [bar, this.y]
  2974. ])
  2975. */
  2976. const isBuiltInDirective = /*#__PURE__*/ makeMap('bind,cloak,else-if,else,for,html,if,model,on,once,pre,show,slot,text,memo');
  2977. function validateDirectiveName(name) {
  2978. if (isBuiltInDirective(name)) {
  2979. warn('Do not use built-in directive ids as custom directive id: ' + name);
  2980. }
  2981. }
  2982. /**
  2983. * Adds directives to a VNode.
  2984. */
  2985. function withDirectives(vnode, directives) {
  2986. const internalInstance = currentRenderingInstance;
  2987. if (internalInstance === null) {
  2988. (process.env.NODE_ENV !== 'production') && warn(`withDirectives can only be used inside render functions.`);
  2989. return vnode;
  2990. }
  2991. const instance = internalInstance.proxy;
  2992. const bindings = vnode.dirs || (vnode.dirs = []);
  2993. for (let i = 0; i < directives.length; i++) {
  2994. let [dir, value, arg, modifiers = EMPTY_OBJ] = directives[i];
  2995. if (isFunction(dir)) {
  2996. dir = {
  2997. mounted: dir,
  2998. updated: dir
  2999. };
  3000. }
  3001. if (dir.deep) {
  3002. traverse(value);
  3003. }
  3004. bindings.push({
  3005. dir,
  3006. instance,
  3007. value,
  3008. oldValue: void 0,
  3009. arg,
  3010. modifiers
  3011. });
  3012. }
  3013. return vnode;
  3014. }
  3015. function invokeDirectiveHook(vnode, prevVNode, instance, name) {
  3016. const bindings = vnode.dirs;
  3017. const oldBindings = prevVNode && prevVNode.dirs;
  3018. for (let i = 0; i < bindings.length; i++) {
  3019. const binding = bindings[i];
  3020. if (oldBindings) {
  3021. binding.oldValue = oldBindings[i].value;
  3022. }
  3023. let hook = binding.dir[name];
  3024. if (hook) {
  3025. // disable tracking inside all lifecycle hooks
  3026. // since they can potentially be called inside effects.
  3027. pauseTracking();
  3028. callWithAsyncErrorHandling(hook, instance, 8 /* DIRECTIVE_HOOK */, [
  3029. vnode.el,
  3030. binding,
  3031. vnode,
  3032. prevVNode
  3033. ]);
  3034. resetTracking();
  3035. }
  3036. }
  3037. }
  3038. function createAppContext() {
  3039. return {
  3040. app: null,
  3041. config: {
  3042. isNativeTag: NO,
  3043. performance: false,
  3044. globalProperties: {},
  3045. optionMergeStrategies: {},
  3046. errorHandler: undefined,
  3047. warnHandler: undefined,
  3048. compilerOptions: {}
  3049. },
  3050. mixins: [],
  3051. components: {},
  3052. directives: {},
  3053. provides: Object.create(null),
  3054. optionsCache: new WeakMap(),
  3055. propsCache: new WeakMap(),
  3056. emitsCache: new WeakMap()
  3057. };
  3058. }
  3059. let uid = 0;
  3060. function createAppAPI(render, hydrate) {
  3061. return function createApp(rootComponent, rootProps = null) {
  3062. if (rootProps != null && !isObject(rootProps)) {
  3063. (process.env.NODE_ENV !== 'production') && warn(`root props passed to app.mount() must be an object.`);
  3064. rootProps = null;
  3065. }
  3066. const context = createAppContext();
  3067. const installedPlugins = new Set();
  3068. let isMounted = false;
  3069. const app = (context.app = {
  3070. _uid: uid++,
  3071. _component: rootComponent,
  3072. _props: rootProps,
  3073. _container: null,
  3074. _context: context,
  3075. _instance: null,
  3076. version,
  3077. get config() {
  3078. return context.config;
  3079. },
  3080. set config(v) {
  3081. if ((process.env.NODE_ENV !== 'production')) {
  3082. warn(`app.config cannot be replaced. Modify individual options instead.`);
  3083. }
  3084. },
  3085. use(plugin, ...options) {
  3086. if (installedPlugins.has(plugin)) {
  3087. (process.env.NODE_ENV !== 'production') && warn(`Plugin has already been applied to target app.`);
  3088. }
  3089. else if (plugin && isFunction(plugin.install)) {
  3090. installedPlugins.add(plugin);
  3091. plugin.install(app, ...options);
  3092. }
  3093. else if (isFunction(plugin)) {
  3094. installedPlugins.add(plugin);
  3095. plugin(app, ...options);
  3096. }
  3097. else if ((process.env.NODE_ENV !== 'production')) {
  3098. warn(`A plugin must either be a function or an object with an "install" ` +
  3099. `function.`);
  3100. }
  3101. return app;
  3102. },
  3103. mixin(mixin) {
  3104. if (__VUE_OPTIONS_API__) {
  3105. if (!context.mixins.includes(mixin)) {
  3106. context.mixins.push(mixin);
  3107. }
  3108. else if ((process.env.NODE_ENV !== 'production')) {
  3109. warn('Mixin has already been applied to target app' +
  3110. (mixin.name ? `: ${mixin.name}` : ''));
  3111. }
  3112. }
  3113. else if ((process.env.NODE_ENV !== 'production')) {
  3114. warn('Mixins are only available in builds supporting Options API');
  3115. }
  3116. return app;
  3117. },
  3118. component(name, component) {
  3119. if ((process.env.NODE_ENV !== 'production')) {
  3120. validateComponentName(name, context.config);
  3121. }
  3122. if (!component) {
  3123. return context.components[name];
  3124. }
  3125. if ((process.env.NODE_ENV !== 'production') && context.components[name]) {
  3126. warn(`Component "${name}" has already been registered in target app.`);
  3127. }
  3128. context.components[name] = component;
  3129. return app;
  3130. },
  3131. directive(name, directive) {
  3132. if ((process.env.NODE_ENV !== 'production')) {
  3133. validateDirectiveName(name);
  3134. }
  3135. if (!directive) {
  3136. return context.directives[name];
  3137. }
  3138. if ((process.env.NODE_ENV !== 'production') && context.directives[name]) {
  3139. warn(`Directive "${name}" has already been registered in target app.`);
  3140. }
  3141. context.directives[name] = directive;
  3142. return app;
  3143. },
  3144. mount(rootContainer, isHydrate, isSVG) {
  3145. if (!isMounted) {
  3146. const vnode = createVNode(rootComponent, rootProps);
  3147. // store app context on the root VNode.
  3148. // this will be set on the root instance on initial mount.
  3149. vnode.appContext = context;
  3150. // HMR root reload
  3151. if ((process.env.NODE_ENV !== 'production')) {
  3152. context.reload = () => {
  3153. render(cloneVNode(vnode), rootContainer, isSVG);
  3154. };
  3155. }
  3156. if (isHydrate && hydrate) {
  3157. hydrate(vnode, rootContainer);
  3158. }
  3159. else {
  3160. render(vnode, rootContainer, isSVG);
  3161. }
  3162. isMounted = true;
  3163. app._container = rootContainer;
  3164. rootContainer.__vue_app__ = app;
  3165. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  3166. app._instance = vnode.component;
  3167. devtoolsInitApp(app, version);
  3168. }
  3169. return getExposeProxy(vnode.component) || vnode.component.proxy;
  3170. }
  3171. else if ((process.env.NODE_ENV !== 'production')) {
  3172. warn(`App has already been mounted.\n` +
  3173. `If you want to remount the same app, move your app creation logic ` +
  3174. `into a factory function and create fresh app instances for each ` +
  3175. `mount - e.g. \`const createMyApp = () => createApp(App)\``);
  3176. }
  3177. },
  3178. unmount() {
  3179. if (isMounted) {
  3180. render(null, app._container);
  3181. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  3182. app._instance = null;
  3183. devtoolsUnmountApp(app);
  3184. }
  3185. delete app._container.__vue_app__;
  3186. }
  3187. else if ((process.env.NODE_ENV !== 'production')) {
  3188. warn(`Cannot unmount an app that is not mounted.`);
  3189. }
  3190. },
  3191. provide(key, value) {
  3192. if ((process.env.NODE_ENV !== 'production') && key in context.provides) {
  3193. warn(`App already provides property with key "${String(key)}". ` +
  3194. `It will be overwritten with the new value.`);
  3195. }
  3196. // TypeScript doesn't allow symbols as index type
  3197. // https://github.com/Microsoft/TypeScript/issues/24587
  3198. context.provides[key] = value;
  3199. return app;
  3200. }
  3201. });
  3202. return app;
  3203. };
  3204. }
  3205. /**
  3206. * Function for handling a template ref
  3207. */
  3208. function setRef(rawRef, oldRawRef, parentSuspense, vnode, isUnmount = false) {
  3209. if (isArray(rawRef)) {
  3210. rawRef.forEach((r, i) => setRef(r, oldRawRef && (isArray(oldRawRef) ? oldRawRef[i] : oldRawRef), parentSuspense, vnode, isUnmount));
  3211. return;
  3212. }
  3213. if (isAsyncWrapper(vnode) && !isUnmount) {
  3214. // when mounting async components, nothing needs to be done,
  3215. // because the template ref is forwarded to inner component
  3216. return;
  3217. }
  3218. const refValue = vnode.shapeFlag & 4 /* STATEFUL_COMPONENT */
  3219. ? getExposeProxy(vnode.component) || vnode.component.proxy
  3220. : vnode.el;
  3221. const value = isUnmount ? null : refValue;
  3222. const { i: owner, r: ref } = rawRef;
  3223. if ((process.env.NODE_ENV !== 'production') && !owner) {
  3224. warn(`Missing ref owner context. ref cannot be used on hoisted vnodes. ` +
  3225. `A vnode with ref must be created inside the render function.`);
  3226. return;
  3227. }
  3228. const oldRef = oldRawRef && oldRawRef.r;
  3229. const refs = owner.refs === EMPTY_OBJ ? (owner.refs = {}) : owner.refs;
  3230. const setupState = owner.setupState;
  3231. // dynamic ref changed. unset old ref
  3232. if (oldRef != null && oldRef !== ref) {
  3233. if (isString(oldRef)) {
  3234. refs[oldRef] = null;
  3235. if (hasOwn(setupState, oldRef)) {
  3236. setupState[oldRef] = null;
  3237. }
  3238. }
  3239. else if (isRef(oldRef)) {
  3240. oldRef.value = null;
  3241. }
  3242. }
  3243. if (isFunction(ref)) {
  3244. callWithErrorHandling(ref, owner, 12 /* FUNCTION_REF */, [value, refs]);
  3245. }
  3246. else {
  3247. const _isString = isString(ref);
  3248. const _isRef = isRef(ref);
  3249. if (_isString || _isRef) {
  3250. const doSet = () => {
  3251. if (rawRef.f) {
  3252. const existing = _isString ? refs[ref] : ref.value;
  3253. if (isUnmount) {
  3254. isArray(existing) && remove(existing, refValue);
  3255. }
  3256. else {
  3257. if (!isArray(existing)) {
  3258. if (_isString) {
  3259. refs[ref] = [refValue];
  3260. }
  3261. else {
  3262. ref.value = [refValue];
  3263. if (rawRef.k)
  3264. refs[rawRef.k] = ref.value;
  3265. }
  3266. }
  3267. else if (!existing.includes(refValue)) {
  3268. existing.push(refValue);
  3269. }
  3270. }
  3271. }
  3272. else if (_isString) {
  3273. refs[ref] = value;
  3274. if (hasOwn(setupState, ref)) {
  3275. setupState[ref] = value;
  3276. }
  3277. }
  3278. else if (isRef(ref)) {
  3279. ref.value = value;
  3280. if (rawRef.k)
  3281. refs[rawRef.k] = value;
  3282. }
  3283. else if ((process.env.NODE_ENV !== 'production')) {
  3284. warn('Invalid template ref type:', ref, `(${typeof ref})`);
  3285. }
  3286. };
  3287. if (value) {
  3288. doSet.id = -1;
  3289. queuePostRenderEffect(doSet, parentSuspense);
  3290. }
  3291. else {
  3292. doSet();
  3293. }
  3294. }
  3295. else if ((process.env.NODE_ENV !== 'production')) {
  3296. warn('Invalid template ref type:', ref, `(${typeof ref})`);
  3297. }
  3298. }
  3299. }
  3300. let hasMismatch = false;
  3301. const isSVGContainer = (container) => /svg/.test(container.namespaceURI) && container.tagName !== 'foreignObject';
  3302. const isComment = (node) => node.nodeType === 8 /* COMMENT */;
  3303. // Note: hydration is DOM-specific
  3304. // But we have to place it in core due to tight coupling with core - splitting
  3305. // it out creates a ton of unnecessary complexity.
  3306. // Hydration also depends on some renderer internal logic which needs to be
  3307. // passed in via arguments.
  3308. function createHydrationFunctions(rendererInternals) {
  3309. const { mt: mountComponent, p: patch, o: { patchProp, nextSibling, parentNode, remove, insert, createComment } } = rendererInternals;
  3310. const hydrate = (vnode, container) => {
  3311. if (!container.hasChildNodes()) {
  3312. (process.env.NODE_ENV !== 'production') &&
  3313. warn(`Attempting to hydrate existing markup but container is empty. ` +
  3314. `Performing full mount instead.`);
  3315. patch(null, vnode, container);
  3316. flushPostFlushCbs();
  3317. return;
  3318. }
  3319. hasMismatch = false;
  3320. hydrateNode(container.firstChild, vnode, null, null, null);
  3321. flushPostFlushCbs();
  3322. if (hasMismatch && !false) {
  3323. // this error should show up in production
  3324. console.error(`Hydration completed but contains mismatches.`);
  3325. }
  3326. };
  3327. const hydrateNode = (node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized = false) => {
  3328. const isFragmentStart = isComment(node) && node.data === '[';
  3329. const onMismatch = () => handleMismatch(node, vnode, parentComponent, parentSuspense, slotScopeIds, isFragmentStart);
  3330. const { type, ref, shapeFlag } = vnode;
  3331. const domType = node.nodeType;
  3332. vnode.el = node;
  3333. let nextNode = null;
  3334. switch (type) {
  3335. case Text:
  3336. if (domType !== 3 /* TEXT */) {
  3337. nextNode = onMismatch();
  3338. }
  3339. else {
  3340. if (node.data !== vnode.children) {
  3341. hasMismatch = true;
  3342. (process.env.NODE_ENV !== 'production') &&
  3343. warn(`Hydration text mismatch:` +
  3344. `\n- Client: ${JSON.stringify(node.data)}` +
  3345. `\n- Server: ${JSON.stringify(vnode.children)}`);
  3346. node.data = vnode.children;
  3347. }
  3348. nextNode = nextSibling(node);
  3349. }
  3350. break;
  3351. case Comment:
  3352. if (domType !== 8 /* COMMENT */ || isFragmentStart) {
  3353. nextNode = onMismatch();
  3354. }
  3355. else {
  3356. nextNode = nextSibling(node);
  3357. }
  3358. break;
  3359. case Static:
  3360. if (domType !== 1 /* ELEMENT */) {
  3361. nextNode = onMismatch();
  3362. }
  3363. else {
  3364. // determine anchor, adopt content
  3365. nextNode = node;
  3366. // if the static vnode has its content stripped during build,
  3367. // adopt it from the server-rendered HTML.
  3368. const needToAdoptContent = !vnode.children.length;
  3369. for (let i = 0; i < vnode.staticCount; i++) {
  3370. if (needToAdoptContent)
  3371. vnode.children += nextNode.outerHTML;
  3372. if (i === vnode.staticCount - 1) {
  3373. vnode.anchor = nextNode;
  3374. }
  3375. nextNode = nextSibling(nextNode);
  3376. }
  3377. return nextNode;
  3378. }
  3379. break;
  3380. case Fragment:
  3381. if (!isFragmentStart) {
  3382. nextNode = onMismatch();
  3383. }
  3384. else {
  3385. nextNode = hydrateFragment(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized);
  3386. }
  3387. break;
  3388. default:
  3389. if (shapeFlag & 1 /* ELEMENT */) {
  3390. if (domType !== 1 /* ELEMENT */ ||
  3391. vnode.type.toLowerCase() !==
  3392. node.tagName.toLowerCase()) {
  3393. nextNode = onMismatch();
  3394. }
  3395. else {
  3396. nextNode = hydrateElement(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized);
  3397. }
  3398. }
  3399. else if (shapeFlag & 6 /* COMPONENT */) {
  3400. // when setting up the render effect, if the initial vnode already
  3401. // has .el set, the component will perform hydration instead of mount
  3402. // on its sub-tree.
  3403. vnode.slotScopeIds = slotScopeIds;
  3404. const container = parentNode(node);
  3405. mountComponent(vnode, container, null, parentComponent, parentSuspense, isSVGContainer(container), optimized);
  3406. // component may be async, so in the case of fragments we cannot rely
  3407. // on component's rendered output to determine the end of the fragment
  3408. // instead, we do a lookahead to find the end anchor node.
  3409. nextNode = isFragmentStart
  3410. ? locateClosingAsyncAnchor(node)
  3411. : nextSibling(node);
  3412. // #3787
  3413. // if component is async, it may get moved / unmounted before its
  3414. // inner component is loaded, so we need to give it a placeholder
  3415. // vnode that matches its adopted DOM.
  3416. if (isAsyncWrapper(vnode)) {
  3417. let subTree;
  3418. if (isFragmentStart) {
  3419. subTree = createVNode(Fragment);
  3420. subTree.anchor = nextNode
  3421. ? nextNode.previousSibling
  3422. : container.lastChild;
  3423. }
  3424. else {
  3425. subTree =
  3426. node.nodeType === 3 ? createTextVNode('') : createVNode('div');
  3427. }
  3428. subTree.el = node;
  3429. vnode.component.subTree = subTree;
  3430. }
  3431. }
  3432. else if (shapeFlag & 64 /* TELEPORT */) {
  3433. if (domType !== 8 /* COMMENT */) {
  3434. nextNode = onMismatch();
  3435. }
  3436. else {
  3437. nextNode = vnode.type.hydrate(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized, rendererInternals, hydrateChildren);
  3438. }
  3439. }
  3440. else if (shapeFlag & 128 /* SUSPENSE */) {
  3441. nextNode = vnode.type.hydrate(node, vnode, parentComponent, parentSuspense, isSVGContainer(parentNode(node)), slotScopeIds, optimized, rendererInternals, hydrateNode);
  3442. }
  3443. else if ((process.env.NODE_ENV !== 'production')) {
  3444. warn('Invalid HostVNode type:', type, `(${typeof type})`);
  3445. }
  3446. }
  3447. if (ref != null) {
  3448. setRef(ref, null, parentSuspense, vnode);
  3449. }
  3450. return nextNode;
  3451. };
  3452. const hydrateElement = (el, vnode, parentComponent, parentSuspense, slotScopeIds, optimized) => {
  3453. optimized = optimized || !!vnode.dynamicChildren;
  3454. const { type, props, patchFlag, shapeFlag, dirs } = vnode;
  3455. // #4006 for form elements with non-string v-model value bindings
  3456. // e.g. <option :value="obj">, <input type="checkbox" :true-value="1">
  3457. const forcePatchValue = (type === 'input' && dirs) || type === 'option';
  3458. // skip props & children if this is hoisted static nodes
  3459. if (forcePatchValue || patchFlag !== -1 /* HOISTED */) {
  3460. if (dirs) {
  3461. invokeDirectiveHook(vnode, null, parentComponent, 'created');
  3462. }
  3463. // props
  3464. if (props) {
  3465. if (forcePatchValue ||
  3466. !optimized ||
  3467. patchFlag & (16 /* FULL_PROPS */ | 32 /* HYDRATE_EVENTS */)) {
  3468. for (const key in props) {
  3469. if ((forcePatchValue && key.endsWith('value')) ||
  3470. (isOn(key) && !isReservedProp(key))) {
  3471. patchProp(el, key, null, props[key], false, undefined, parentComponent);
  3472. }
  3473. }
  3474. }
  3475. else if (props.onClick) {
  3476. // Fast path for click listeners (which is most often) to avoid
  3477. // iterating through props.
  3478. patchProp(el, 'onClick', null, props.onClick, false, undefined, parentComponent);
  3479. }
  3480. }
  3481. // vnode / directive hooks
  3482. let vnodeHooks;
  3483. if ((vnodeHooks = props && props.onVnodeBeforeMount)) {
  3484. invokeVNodeHook(vnodeHooks, parentComponent, vnode);
  3485. }
  3486. if (dirs) {
  3487. invokeDirectiveHook(vnode, null, parentComponent, 'beforeMount');
  3488. }
  3489. if ((vnodeHooks = props && props.onVnodeMounted) || dirs) {
  3490. queueEffectWithSuspense(() => {
  3491. vnodeHooks && invokeVNodeHook(vnodeHooks, parentComponent, vnode);
  3492. dirs && invokeDirectiveHook(vnode, null, parentComponent, 'mounted');
  3493. }, parentSuspense);
  3494. }
  3495. // children
  3496. if (shapeFlag & 16 /* ARRAY_CHILDREN */ &&
  3497. // skip if element has innerHTML / textContent
  3498. !(props && (props.innerHTML || props.textContent))) {
  3499. let next = hydrateChildren(el.firstChild, vnode, el, parentComponent, parentSuspense, slotScopeIds, optimized);
  3500. let hasWarned = false;
  3501. while (next) {
  3502. hasMismatch = true;
  3503. if ((process.env.NODE_ENV !== 'production') && !hasWarned) {
  3504. warn(`Hydration children mismatch in <${vnode.type}>: ` +
  3505. `server rendered element contains more child nodes than client vdom.`);
  3506. hasWarned = true;
  3507. }
  3508. // The SSRed DOM contains more nodes than it should. Remove them.
  3509. const cur = next;
  3510. next = next.nextSibling;
  3511. remove(cur);
  3512. }
  3513. }
  3514. else if (shapeFlag & 8 /* TEXT_CHILDREN */) {
  3515. if (el.textContent !== vnode.children) {
  3516. hasMismatch = true;
  3517. (process.env.NODE_ENV !== 'production') &&
  3518. warn(`Hydration text content mismatch in <${vnode.type}>:\n` +
  3519. `- Client: ${el.textContent}\n` +
  3520. `- Server: ${vnode.children}`);
  3521. el.textContent = vnode.children;
  3522. }
  3523. }
  3524. }
  3525. return el.nextSibling;
  3526. };
  3527. const hydrateChildren = (node, parentVNode, container, parentComponent, parentSuspense, slotScopeIds, optimized) => {
  3528. optimized = optimized || !!parentVNode.dynamicChildren;
  3529. const children = parentVNode.children;
  3530. const l = children.length;
  3531. let hasWarned = false;
  3532. for (let i = 0; i < l; i++) {
  3533. const vnode = optimized
  3534. ? children[i]
  3535. : (children[i] = normalizeVNode(children[i]));
  3536. if (node) {
  3537. node = hydrateNode(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized);
  3538. }
  3539. else if (vnode.type === Text && !vnode.children) {
  3540. continue;
  3541. }
  3542. else {
  3543. hasMismatch = true;
  3544. if ((process.env.NODE_ENV !== 'production') && !hasWarned) {
  3545. warn(`Hydration children mismatch in <${container.tagName.toLowerCase()}>: ` +
  3546. `server rendered element contains fewer child nodes than client vdom.`);
  3547. hasWarned = true;
  3548. }
  3549. // the SSRed DOM didn't contain enough nodes. Mount the missing ones.
  3550. patch(null, vnode, container, null, parentComponent, parentSuspense, isSVGContainer(container), slotScopeIds);
  3551. }
  3552. }
  3553. return node;
  3554. };
  3555. const hydrateFragment = (node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized) => {
  3556. const { slotScopeIds: fragmentSlotScopeIds } = vnode;
  3557. if (fragmentSlotScopeIds) {
  3558. slotScopeIds = slotScopeIds
  3559. ? slotScopeIds.concat(fragmentSlotScopeIds)
  3560. : fragmentSlotScopeIds;
  3561. }
  3562. const container = parentNode(node);
  3563. const next = hydrateChildren(nextSibling(node), vnode, container, parentComponent, parentSuspense, slotScopeIds, optimized);
  3564. if (next && isComment(next) && next.data === ']') {
  3565. return nextSibling((vnode.anchor = next));
  3566. }
  3567. else {
  3568. // fragment didn't hydrate successfully, since we didn't get a end anchor
  3569. // back. This should have led to node/children mismatch warnings.
  3570. hasMismatch = true;
  3571. // since the anchor is missing, we need to create one and insert it
  3572. insert((vnode.anchor = createComment(`]`)), container, next);
  3573. return next;
  3574. }
  3575. };
  3576. const handleMismatch = (node, vnode, parentComponent, parentSuspense, slotScopeIds, isFragment) => {
  3577. hasMismatch = true;
  3578. (process.env.NODE_ENV !== 'production') &&
  3579. warn(`Hydration node mismatch:\n- Client vnode:`, vnode.type, `\n- Server rendered DOM:`, node, node.nodeType === 3 /* TEXT */
  3580. ? `(text)`
  3581. : isComment(node) && node.data === '['
  3582. ? `(start of fragment)`
  3583. : ``);
  3584. vnode.el = null;
  3585. if (isFragment) {
  3586. // remove excessive fragment nodes
  3587. const end = locateClosingAsyncAnchor(node);
  3588. while (true) {
  3589. const next = nextSibling(node);
  3590. if (next && next !== end) {
  3591. remove(next);
  3592. }
  3593. else {
  3594. break;
  3595. }
  3596. }
  3597. }
  3598. const next = nextSibling(node);
  3599. const container = parentNode(node);
  3600. remove(node);
  3601. patch(null, vnode, container, next, parentComponent, parentSuspense, isSVGContainer(container), slotScopeIds);
  3602. return next;
  3603. };
  3604. const locateClosingAsyncAnchor = (node) => {
  3605. let match = 0;
  3606. while (node) {
  3607. node = nextSibling(node);
  3608. if (node && isComment(node)) {
  3609. if (node.data === '[')
  3610. match++;
  3611. if (node.data === ']') {
  3612. if (match === 0) {
  3613. return nextSibling(node);
  3614. }
  3615. else {
  3616. match--;
  3617. }
  3618. }
  3619. }
  3620. }
  3621. return node;
  3622. };
  3623. return [hydrate, hydrateNode];
  3624. }
  3625. let supported;
  3626. let perf;
  3627. function startMeasure(instance, type) {
  3628. if (instance.appContext.config.performance && isSupported()) {
  3629. perf.mark(`vue-${type}-${instance.uid}`);
  3630. }
  3631. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  3632. devtoolsPerfStart(instance, type, supported ? perf.now() : Date.now());
  3633. }
  3634. }
  3635. function endMeasure(instance, type) {
  3636. if (instance.appContext.config.performance && isSupported()) {
  3637. const startTag = `vue-${type}-${instance.uid}`;
  3638. const endTag = startTag + `:end`;
  3639. perf.mark(endTag);
  3640. perf.measure(`<${formatComponentName(instance, instance.type)}> ${type}`, startTag, endTag);
  3641. perf.clearMarks(startTag);
  3642. perf.clearMarks(endTag);
  3643. }
  3644. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  3645. devtoolsPerfEnd(instance, type, supported ? perf.now() : Date.now());
  3646. }
  3647. }
  3648. function isSupported() {
  3649. if (supported !== undefined) {
  3650. return supported;
  3651. }
  3652. /* eslint-disable no-restricted-globals */
  3653. if (typeof window !== 'undefined' && window.performance) {
  3654. supported = true;
  3655. perf = window.performance;
  3656. }
  3657. else {
  3658. supported = false;
  3659. }
  3660. /* eslint-enable no-restricted-globals */
  3661. return supported;
  3662. }
  3663. /**
  3664. * This is only called in esm-bundler builds.
  3665. * It is called when a renderer is created, in `baseCreateRenderer` so that
  3666. * importing runtime-core is side-effects free.
  3667. *
  3668. * istanbul-ignore-next
  3669. */
  3670. function initFeatureFlags() {
  3671. const needWarn = [];
  3672. if (typeof __VUE_OPTIONS_API__ !== 'boolean') {
  3673. (process.env.NODE_ENV !== 'production') && needWarn.push(`__VUE_OPTIONS_API__`);
  3674. getGlobalThis().__VUE_OPTIONS_API__ = true;
  3675. }
  3676. if (typeof __VUE_PROD_DEVTOOLS__ !== 'boolean') {
  3677. (process.env.NODE_ENV !== 'production') && needWarn.push(`__VUE_PROD_DEVTOOLS__`);
  3678. getGlobalThis().__VUE_PROD_DEVTOOLS__ = false;
  3679. }
  3680. if ((process.env.NODE_ENV !== 'production') && needWarn.length) {
  3681. const multi = needWarn.length > 1;
  3682. console.warn(`Feature flag${multi ? `s` : ``} ${needWarn.join(', ')} ${multi ? `are` : `is`} not explicitly defined. You are running the esm-bundler build of Vue, ` +
  3683. `which expects these compile-time feature flags to be globally injected ` +
  3684. `via the bundler config in order to get better tree-shaking in the ` +
  3685. `production bundle.\n\n` +
  3686. `For more details, see https://link.vuejs.org/feature-flags.`);
  3687. }
  3688. }
  3689. const queuePostRenderEffect = queueEffectWithSuspense
  3690. ;
  3691. /**
  3692. * The createRenderer function accepts two generic arguments:
  3693. * HostNode and HostElement, corresponding to Node and Element types in the
  3694. * host environment. For example, for runtime-dom, HostNode would be the DOM
  3695. * `Node` interface and HostElement would be the DOM `Element` interface.
  3696. *
  3697. * Custom renderers can pass in the platform specific types like this:
  3698. *
  3699. * ``` js
  3700. * const { render, createApp } = createRenderer<Node, Element>({
  3701. * patchProp,
  3702. * ...nodeOps
  3703. * })
  3704. * ```
  3705. */
  3706. function createRenderer(options) {
  3707. return baseCreateRenderer(options);
  3708. }
  3709. // Separate API for creating hydration-enabled renderer.
  3710. // Hydration logic is only used when calling this function, making it
  3711. // tree-shakable.
  3712. function createHydrationRenderer(options) {
  3713. return baseCreateRenderer(options, createHydrationFunctions);
  3714. }
  3715. // implementation
  3716. function baseCreateRenderer(options, createHydrationFns) {
  3717. // compile-time feature flags check
  3718. {
  3719. initFeatureFlags();
  3720. }
  3721. const target = getGlobalThis();
  3722. target.__VUE__ = true;
  3723. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  3724. setDevtoolsHook(target.__VUE_DEVTOOLS_GLOBAL_HOOK__, target);
  3725. }
  3726. 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;
  3727. // Note: functions inside this closure should use `const xxx = () => {}`
  3728. // style in order to prevent being inlined by minifiers.
  3729. const patch = (n1, n2, container, anchor = null, parentComponent = null, parentSuspense = null, isSVG = false, slotScopeIds = null, optimized = (process.env.NODE_ENV !== 'production') && isHmrUpdating ? false : !!n2.dynamicChildren) => {
  3730. if (n1 === n2) {
  3731. return;
  3732. }
  3733. // patching & not same type, unmount old tree
  3734. if (n1 && !isSameVNodeType(n1, n2)) {
  3735. anchor = getNextHostNode(n1);
  3736. unmount(n1, parentComponent, parentSuspense, true);
  3737. n1 = null;
  3738. }
  3739. if (n2.patchFlag === -2 /* BAIL */) {
  3740. optimized = false;
  3741. n2.dynamicChildren = null;
  3742. }
  3743. const { type, ref, shapeFlag } = n2;
  3744. switch (type) {
  3745. case Text:
  3746. processText(n1, n2, container, anchor);
  3747. break;
  3748. case Comment:
  3749. processCommentNode(n1, n2, container, anchor);
  3750. break;
  3751. case Static:
  3752. if (n1 == null) {
  3753. mountStaticNode(n2, container, anchor, isSVG);
  3754. }
  3755. else if ((process.env.NODE_ENV !== 'production')) {
  3756. patchStaticNode(n1, n2, container, isSVG);
  3757. }
  3758. break;
  3759. case Fragment:
  3760. processFragment(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  3761. break;
  3762. default:
  3763. if (shapeFlag & 1 /* ELEMENT */) {
  3764. processElement(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  3765. }
  3766. else if (shapeFlag & 6 /* COMPONENT */) {
  3767. processComponent(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  3768. }
  3769. else if (shapeFlag & 64 /* TELEPORT */) {
  3770. type.process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, internals);
  3771. }
  3772. else if (shapeFlag & 128 /* SUSPENSE */) {
  3773. type.process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, internals);
  3774. }
  3775. else if ((process.env.NODE_ENV !== 'production')) {
  3776. warn('Invalid VNode type:', type, `(${typeof type})`);
  3777. }
  3778. }
  3779. // set ref
  3780. if (ref != null && parentComponent) {
  3781. setRef(ref, n1 && n1.ref, parentSuspense, n2 || n1, !n2);
  3782. }
  3783. };
  3784. const processText = (n1, n2, container, anchor) => {
  3785. if (n1 == null) {
  3786. hostInsert((n2.el = hostCreateText(n2.children)), container, anchor);
  3787. }
  3788. else {
  3789. const el = (n2.el = n1.el);
  3790. if (n2.children !== n1.children) {
  3791. hostSetText(el, n2.children);
  3792. }
  3793. }
  3794. };
  3795. const processCommentNode = (n1, n2, container, anchor) => {
  3796. if (n1 == null) {
  3797. hostInsert((n2.el = hostCreateComment(n2.children || '')), container, anchor);
  3798. }
  3799. else {
  3800. // there's no support for dynamic comments
  3801. n2.el = n1.el;
  3802. }
  3803. };
  3804. const mountStaticNode = (n2, container, anchor, isSVG) => {
  3805. [n2.el, n2.anchor] = hostInsertStaticContent(n2.children, container, anchor, isSVG);
  3806. };
  3807. /**
  3808. * Dev / HMR only
  3809. */
  3810. const patchStaticNode = (n1, n2, container, isSVG) => {
  3811. // static nodes are only patched during dev for HMR
  3812. if (n2.children !== n1.children) {
  3813. const anchor = hostNextSibling(n1.anchor);
  3814. // remove existing
  3815. removeStaticNode(n1);
  3816. [n2.el, n2.anchor] = hostInsertStaticContent(n2.children, container, anchor, isSVG);
  3817. }
  3818. else {
  3819. n2.el = n1.el;
  3820. n2.anchor = n1.anchor;
  3821. }
  3822. };
  3823. const moveStaticNode = ({ el, anchor }, container, nextSibling) => {
  3824. let next;
  3825. while (el && el !== anchor) {
  3826. next = hostNextSibling(el);
  3827. hostInsert(el, container, nextSibling);
  3828. el = next;
  3829. }
  3830. hostInsert(anchor, container, nextSibling);
  3831. };
  3832. const removeStaticNode = ({ el, anchor }) => {
  3833. let next;
  3834. while (el && el !== anchor) {
  3835. next = hostNextSibling(el);
  3836. hostRemove(el);
  3837. el = next;
  3838. }
  3839. hostRemove(anchor);
  3840. };
  3841. const processElement = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  3842. isSVG = isSVG || n2.type === 'svg';
  3843. if (n1 == null) {
  3844. mountElement(n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  3845. }
  3846. else {
  3847. patchElement(n1, n2, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  3848. }
  3849. };
  3850. const mountElement = (vnode, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  3851. let el;
  3852. let vnodeHook;
  3853. const { type, props, shapeFlag, transition, patchFlag, dirs } = vnode;
  3854. if (!(process.env.NODE_ENV !== 'production') &&
  3855. vnode.el &&
  3856. hostCloneNode !== undefined &&
  3857. patchFlag === -1 /* HOISTED */) {
  3858. // If a vnode has non-null el, it means it's being reused.
  3859. // Only static vnodes can be reused, so its mounted DOM nodes should be
  3860. // exactly the same, and we can simply do a clone here.
  3861. // only do this in production since cloned trees cannot be HMR updated.
  3862. el = vnode.el = hostCloneNode(vnode.el);
  3863. }
  3864. else {
  3865. el = vnode.el = hostCreateElement(vnode.type, isSVG, props && props.is, props);
  3866. // mount children first, since some props may rely on child content
  3867. // being already rendered, e.g. `<select value>`
  3868. if (shapeFlag & 8 /* TEXT_CHILDREN */) {
  3869. hostSetElementText(el, vnode.children);
  3870. }
  3871. else if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  3872. mountChildren(vnode.children, el, null, parentComponent, parentSuspense, isSVG && type !== 'foreignObject', slotScopeIds, optimized);
  3873. }
  3874. if (dirs) {
  3875. invokeDirectiveHook(vnode, null, parentComponent, 'created');
  3876. }
  3877. // props
  3878. if (props) {
  3879. for (const key in props) {
  3880. if (key !== 'value' && !isReservedProp(key)) {
  3881. hostPatchProp(el, key, null, props[key], isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  3882. }
  3883. }
  3884. /**
  3885. * Special case for setting value on DOM elements:
  3886. * - it can be order-sensitive (e.g. should be set *after* min/max, #2325, #4024)
  3887. * - it needs to be forced (#1471)
  3888. * #2353 proposes adding another renderer option to configure this, but
  3889. * the properties affects are so finite it is worth special casing it
  3890. * here to reduce the complexity. (Special casing it also should not
  3891. * affect non-DOM renderers)
  3892. */
  3893. if ('value' in props) {
  3894. hostPatchProp(el, 'value', null, props.value);
  3895. }
  3896. if ((vnodeHook = props.onVnodeBeforeMount)) {
  3897. invokeVNodeHook(vnodeHook, parentComponent, vnode);
  3898. }
  3899. }
  3900. // scopeId
  3901. setScopeId(el, vnode, vnode.scopeId, slotScopeIds, parentComponent);
  3902. }
  3903. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  3904. Object.defineProperty(el, '__vnode', {
  3905. value: vnode,
  3906. enumerable: false
  3907. });
  3908. Object.defineProperty(el, '__vueParentComponent', {
  3909. value: parentComponent,
  3910. enumerable: false
  3911. });
  3912. }
  3913. if (dirs) {
  3914. invokeDirectiveHook(vnode, null, parentComponent, 'beforeMount');
  3915. }
  3916. // #1583 For inside suspense + suspense not resolved case, enter hook should call when suspense resolved
  3917. // #1689 For inside suspense + suspense resolved case, just call it
  3918. const needCallTransitionHooks = (!parentSuspense || (parentSuspense && !parentSuspense.pendingBranch)) &&
  3919. transition &&
  3920. !transition.persisted;
  3921. if (needCallTransitionHooks) {
  3922. transition.beforeEnter(el);
  3923. }
  3924. hostInsert(el, container, anchor);
  3925. if ((vnodeHook = props && props.onVnodeMounted) ||
  3926. needCallTransitionHooks ||
  3927. dirs) {
  3928. queuePostRenderEffect(() => {
  3929. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, vnode);
  3930. needCallTransitionHooks && transition.enter(el);
  3931. dirs && invokeDirectiveHook(vnode, null, parentComponent, 'mounted');
  3932. }, parentSuspense);
  3933. }
  3934. };
  3935. const setScopeId = (el, vnode, scopeId, slotScopeIds, parentComponent) => {
  3936. if (scopeId) {
  3937. hostSetScopeId(el, scopeId);
  3938. }
  3939. if (slotScopeIds) {
  3940. for (let i = 0; i < slotScopeIds.length; i++) {
  3941. hostSetScopeId(el, slotScopeIds[i]);
  3942. }
  3943. }
  3944. if (parentComponent) {
  3945. let subTree = parentComponent.subTree;
  3946. if ((process.env.NODE_ENV !== 'production') &&
  3947. subTree.patchFlag > 0 &&
  3948. subTree.patchFlag & 2048 /* DEV_ROOT_FRAGMENT */) {
  3949. subTree =
  3950. filterSingleRoot(subTree.children) || subTree;
  3951. }
  3952. if (vnode === subTree) {
  3953. const parentVNode = parentComponent.vnode;
  3954. setScopeId(el, parentVNode, parentVNode.scopeId, parentVNode.slotScopeIds, parentComponent.parent);
  3955. }
  3956. }
  3957. };
  3958. const mountChildren = (children, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, start = 0) => {
  3959. for (let i = start; i < children.length; i++) {
  3960. const child = (children[i] = optimized
  3961. ? cloneIfMounted(children[i])
  3962. : normalizeVNode(children[i]));
  3963. patch(null, child, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  3964. }
  3965. };
  3966. const patchElement = (n1, n2, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  3967. const el = (n2.el = n1.el);
  3968. let { patchFlag, dynamicChildren, dirs } = n2;
  3969. // #1426 take the old vnode's patch flag into account since user may clone a
  3970. // compiler-generated vnode, which de-opts to FULL_PROPS
  3971. patchFlag |= n1.patchFlag & 16 /* FULL_PROPS */;
  3972. const oldProps = n1.props || EMPTY_OBJ;
  3973. const newProps = n2.props || EMPTY_OBJ;
  3974. let vnodeHook;
  3975. // disable recurse in beforeUpdate hooks
  3976. parentComponent && toggleRecurse(parentComponent, false);
  3977. if ((vnodeHook = newProps.onVnodeBeforeUpdate)) {
  3978. invokeVNodeHook(vnodeHook, parentComponent, n2, n1);
  3979. }
  3980. if (dirs) {
  3981. invokeDirectiveHook(n2, n1, parentComponent, 'beforeUpdate');
  3982. }
  3983. parentComponent && toggleRecurse(parentComponent, true);
  3984. if ((process.env.NODE_ENV !== 'production') && isHmrUpdating) {
  3985. // HMR updated, force full diff
  3986. patchFlag = 0;
  3987. optimized = false;
  3988. dynamicChildren = null;
  3989. }
  3990. const areChildrenSVG = isSVG && n2.type !== 'foreignObject';
  3991. if (dynamicChildren) {
  3992. patchBlockChildren(n1.dynamicChildren, dynamicChildren, el, parentComponent, parentSuspense, areChildrenSVG, slotScopeIds);
  3993. if ((process.env.NODE_ENV !== 'production') && parentComponent && parentComponent.type.__hmrId) {
  3994. traverseStaticChildren(n1, n2);
  3995. }
  3996. }
  3997. else if (!optimized) {
  3998. // full diff
  3999. patchChildren(n1, n2, el, null, parentComponent, parentSuspense, areChildrenSVG, slotScopeIds, false);
  4000. }
  4001. if (patchFlag > 0) {
  4002. // the presence of a patchFlag means this element's render code was
  4003. // generated by the compiler and can take the fast path.
  4004. // in this path old node and new node are guaranteed to have the same shape
  4005. // (i.e. at the exact same position in the source template)
  4006. if (patchFlag & 16 /* FULL_PROPS */) {
  4007. // element props contain dynamic keys, full diff needed
  4008. patchProps(el, n2, oldProps, newProps, parentComponent, parentSuspense, isSVG);
  4009. }
  4010. else {
  4011. // class
  4012. // this flag is matched when the element has dynamic class bindings.
  4013. if (patchFlag & 2 /* CLASS */) {
  4014. if (oldProps.class !== newProps.class) {
  4015. hostPatchProp(el, 'class', null, newProps.class, isSVG);
  4016. }
  4017. }
  4018. // style
  4019. // this flag is matched when the element has dynamic style bindings
  4020. if (patchFlag & 4 /* STYLE */) {
  4021. hostPatchProp(el, 'style', oldProps.style, newProps.style, isSVG);
  4022. }
  4023. // props
  4024. // This flag is matched when the element has dynamic prop/attr bindings
  4025. // other than class and style. The keys of dynamic prop/attrs are saved for
  4026. // faster iteration.
  4027. // Note dynamic keys like :[foo]="bar" will cause this optimization to
  4028. // bail out and go through a full diff because we need to unset the old key
  4029. if (patchFlag & 8 /* PROPS */) {
  4030. // if the flag is present then dynamicProps must be non-null
  4031. const propsToUpdate = n2.dynamicProps;
  4032. for (let i = 0; i < propsToUpdate.length; i++) {
  4033. const key = propsToUpdate[i];
  4034. const prev = oldProps[key];
  4035. const next = newProps[key];
  4036. // #1471 force patch value
  4037. if (next !== prev || key === 'value') {
  4038. hostPatchProp(el, key, prev, next, isSVG, n1.children, parentComponent, parentSuspense, unmountChildren);
  4039. }
  4040. }
  4041. }
  4042. }
  4043. // text
  4044. // This flag is matched when the element has only dynamic text children.
  4045. if (patchFlag & 1 /* TEXT */) {
  4046. if (n1.children !== n2.children) {
  4047. hostSetElementText(el, n2.children);
  4048. }
  4049. }
  4050. }
  4051. else if (!optimized && dynamicChildren == null) {
  4052. // unoptimized, full diff
  4053. patchProps(el, n2, oldProps, newProps, parentComponent, parentSuspense, isSVG);
  4054. }
  4055. if ((vnodeHook = newProps.onVnodeUpdated) || dirs) {
  4056. queuePostRenderEffect(() => {
  4057. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, n2, n1);
  4058. dirs && invokeDirectiveHook(n2, n1, parentComponent, 'updated');
  4059. }, parentSuspense);
  4060. }
  4061. };
  4062. // The fast path for blocks.
  4063. const patchBlockChildren = (oldChildren, newChildren, fallbackContainer, parentComponent, parentSuspense, isSVG, slotScopeIds) => {
  4064. for (let i = 0; i < newChildren.length; i++) {
  4065. const oldVNode = oldChildren[i];
  4066. const newVNode = newChildren[i];
  4067. // Determine the container (parent element) for the patch.
  4068. const container =
  4069. // oldVNode may be an errored async setup() component inside Suspense
  4070. // which will not have a mounted element
  4071. oldVNode.el &&
  4072. // - In the case of a Fragment, we need to provide the actual parent
  4073. // of the Fragment itself so it can move its children.
  4074. (oldVNode.type === Fragment ||
  4075. // - In the case of different nodes, there is going to be a replacement
  4076. // which also requires the correct parent container
  4077. !isSameVNodeType(oldVNode, newVNode) ||
  4078. // - In the case of a component, it could contain anything.
  4079. oldVNode.shapeFlag & (6 /* COMPONENT */ | 64 /* TELEPORT */))
  4080. ? hostParentNode(oldVNode.el)
  4081. : // In other cases, the parent container is not actually used so we
  4082. // just pass the block element here to avoid a DOM parentNode call.
  4083. fallbackContainer;
  4084. patch(oldVNode, newVNode, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, true);
  4085. }
  4086. };
  4087. const patchProps = (el, vnode, oldProps, newProps, parentComponent, parentSuspense, isSVG) => {
  4088. if (oldProps !== newProps) {
  4089. for (const key in newProps) {
  4090. // empty string is not valid prop
  4091. if (isReservedProp(key))
  4092. continue;
  4093. const next = newProps[key];
  4094. const prev = oldProps[key];
  4095. // defer patching value
  4096. if (next !== prev && key !== 'value') {
  4097. hostPatchProp(el, key, prev, next, isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  4098. }
  4099. }
  4100. if (oldProps !== EMPTY_OBJ) {
  4101. for (const key in oldProps) {
  4102. if (!isReservedProp(key) && !(key in newProps)) {
  4103. hostPatchProp(el, key, oldProps[key], null, isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  4104. }
  4105. }
  4106. }
  4107. if ('value' in newProps) {
  4108. hostPatchProp(el, 'value', oldProps.value, newProps.value);
  4109. }
  4110. }
  4111. };
  4112. const processFragment = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  4113. const fragmentStartAnchor = (n2.el = n1 ? n1.el : hostCreateText(''));
  4114. const fragmentEndAnchor = (n2.anchor = n1 ? n1.anchor : hostCreateText(''));
  4115. let { patchFlag, dynamicChildren, slotScopeIds: fragmentSlotScopeIds } = n2;
  4116. if ((process.env.NODE_ENV !== 'production') && isHmrUpdating) {
  4117. // HMR updated, force full diff
  4118. patchFlag = 0;
  4119. optimized = false;
  4120. dynamicChildren = null;
  4121. }
  4122. // check if this is a slot fragment with :slotted scope ids
  4123. if (fragmentSlotScopeIds) {
  4124. slotScopeIds = slotScopeIds
  4125. ? slotScopeIds.concat(fragmentSlotScopeIds)
  4126. : fragmentSlotScopeIds;
  4127. }
  4128. if (n1 == null) {
  4129. hostInsert(fragmentStartAnchor, container, anchor);
  4130. hostInsert(fragmentEndAnchor, container, anchor);
  4131. // a fragment can only have array children
  4132. // since they are either generated by the compiler, or implicitly created
  4133. // from arrays.
  4134. mountChildren(n2.children, container, fragmentEndAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  4135. }
  4136. else {
  4137. if (patchFlag > 0 &&
  4138. patchFlag & 64 /* STABLE_FRAGMENT */ &&
  4139. dynamicChildren &&
  4140. // #2715 the previous fragment could've been a BAILed one as a result
  4141. // of renderSlot() with no valid children
  4142. n1.dynamicChildren) {
  4143. // a stable fragment (template root or <template v-for>) doesn't need to
  4144. // patch children order, but it may contain dynamicChildren.
  4145. patchBlockChildren(n1.dynamicChildren, dynamicChildren, container, parentComponent, parentSuspense, isSVG, slotScopeIds);
  4146. if ((process.env.NODE_ENV !== 'production') && parentComponent && parentComponent.type.__hmrId) {
  4147. traverseStaticChildren(n1, n2);
  4148. }
  4149. else if (
  4150. // #2080 if the stable fragment has a key, it's a <template v-for> that may
  4151. // get moved around. Make sure all root level vnodes inherit el.
  4152. // #2134 or if it's a component root, it may also get moved around
  4153. // as the component is being moved.
  4154. n2.key != null ||
  4155. (parentComponent && n2 === parentComponent.subTree)) {
  4156. traverseStaticChildren(n1, n2, true /* shallow */);
  4157. }
  4158. }
  4159. else {
  4160. // keyed / unkeyed, or manual fragments.
  4161. // for keyed & unkeyed, since they are compiler generated from v-for,
  4162. // each child is guaranteed to be a block so the fragment will never
  4163. // have dynamicChildren.
  4164. patchChildren(n1, n2, container, fragmentEndAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  4165. }
  4166. }
  4167. };
  4168. const processComponent = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  4169. n2.slotScopeIds = slotScopeIds;
  4170. if (n1 == null) {
  4171. if (n2.shapeFlag & 512 /* COMPONENT_KEPT_ALIVE */) {
  4172. parentComponent.ctx.activate(n2, container, anchor, isSVG, optimized);
  4173. }
  4174. else {
  4175. mountComponent(n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  4176. }
  4177. }
  4178. else {
  4179. updateComponent(n1, n2, optimized);
  4180. }
  4181. };
  4182. const mountComponent = (initialVNode, container, anchor, parentComponent, parentSuspense, isSVG, optimized) => {
  4183. const instance = (initialVNode.component = createComponentInstance(initialVNode, parentComponent, parentSuspense));
  4184. if ((process.env.NODE_ENV !== 'production') && instance.type.__hmrId) {
  4185. registerHMR(instance);
  4186. }
  4187. if ((process.env.NODE_ENV !== 'production')) {
  4188. pushWarningContext(initialVNode);
  4189. startMeasure(instance, `mount`);
  4190. }
  4191. // inject renderer internals for keepAlive
  4192. if (isKeepAlive(initialVNode)) {
  4193. instance.ctx.renderer = internals;
  4194. }
  4195. // resolve props and slots for setup context
  4196. {
  4197. if ((process.env.NODE_ENV !== 'production')) {
  4198. startMeasure(instance, `init`);
  4199. }
  4200. setupComponent(instance);
  4201. if ((process.env.NODE_ENV !== 'production')) {
  4202. endMeasure(instance, `init`);
  4203. }
  4204. }
  4205. // setup() is async. This component relies on async logic to be resolved
  4206. // before proceeding
  4207. if (instance.asyncDep) {
  4208. parentSuspense && parentSuspense.registerDep(instance, setupRenderEffect);
  4209. // Give it a placeholder if this is not hydration
  4210. // TODO handle self-defined fallback
  4211. if (!initialVNode.el) {
  4212. const placeholder = (instance.subTree = createVNode(Comment));
  4213. processCommentNode(null, placeholder, container, anchor);
  4214. }
  4215. return;
  4216. }
  4217. setupRenderEffect(instance, initialVNode, container, anchor, parentSuspense, isSVG, optimized);
  4218. if ((process.env.NODE_ENV !== 'production')) {
  4219. popWarningContext();
  4220. endMeasure(instance, `mount`);
  4221. }
  4222. };
  4223. const updateComponent = (n1, n2, optimized) => {
  4224. const instance = (n2.component = n1.component);
  4225. if (shouldUpdateComponent(n1, n2, optimized)) {
  4226. if (instance.asyncDep &&
  4227. !instance.asyncResolved) {
  4228. // async & still pending - just update props and slots
  4229. // since the component's reactive effect for render isn't set-up yet
  4230. if ((process.env.NODE_ENV !== 'production')) {
  4231. pushWarningContext(n2);
  4232. }
  4233. updateComponentPreRender(instance, n2, optimized);
  4234. if ((process.env.NODE_ENV !== 'production')) {
  4235. popWarningContext();
  4236. }
  4237. return;
  4238. }
  4239. else {
  4240. // normal update
  4241. instance.next = n2;
  4242. // in case the child component is also queued, remove it to avoid
  4243. // double updating the same child component in the same flush.
  4244. invalidateJob(instance.update);
  4245. // instance.update is the reactive effect.
  4246. instance.update();
  4247. }
  4248. }
  4249. else {
  4250. // no update needed. just copy over properties
  4251. n2.component = n1.component;
  4252. n2.el = n1.el;
  4253. instance.vnode = n2;
  4254. }
  4255. };
  4256. const setupRenderEffect = (instance, initialVNode, container, anchor, parentSuspense, isSVG, optimized) => {
  4257. const componentUpdateFn = () => {
  4258. if (!instance.isMounted) {
  4259. let vnodeHook;
  4260. const { el, props } = initialVNode;
  4261. const { bm, m, parent } = instance;
  4262. const isAsyncWrapperVNode = isAsyncWrapper(initialVNode);
  4263. toggleRecurse(instance, false);
  4264. // beforeMount hook
  4265. if (bm) {
  4266. invokeArrayFns(bm);
  4267. }
  4268. // onVnodeBeforeMount
  4269. if (!isAsyncWrapperVNode &&
  4270. (vnodeHook = props && props.onVnodeBeforeMount)) {
  4271. invokeVNodeHook(vnodeHook, parent, initialVNode);
  4272. }
  4273. toggleRecurse(instance, true);
  4274. if (el && hydrateNode) {
  4275. // vnode has adopted host node - perform hydration instead of mount.
  4276. const hydrateSubTree = () => {
  4277. if ((process.env.NODE_ENV !== 'production')) {
  4278. startMeasure(instance, `render`);
  4279. }
  4280. instance.subTree = renderComponentRoot(instance);
  4281. if ((process.env.NODE_ENV !== 'production')) {
  4282. endMeasure(instance, `render`);
  4283. }
  4284. if ((process.env.NODE_ENV !== 'production')) {
  4285. startMeasure(instance, `hydrate`);
  4286. }
  4287. hydrateNode(el, instance.subTree, instance, parentSuspense, null);
  4288. if ((process.env.NODE_ENV !== 'production')) {
  4289. endMeasure(instance, `hydrate`);
  4290. }
  4291. };
  4292. if (isAsyncWrapperVNode) {
  4293. initialVNode.type.__asyncLoader().then(
  4294. // note: we are moving the render call into an async callback,
  4295. // which means it won't track dependencies - but it's ok because
  4296. // a server-rendered async wrapper is already in resolved state
  4297. // and it will never need to change.
  4298. () => !instance.isUnmounted && hydrateSubTree());
  4299. }
  4300. else {
  4301. hydrateSubTree();
  4302. }
  4303. }
  4304. else {
  4305. if ((process.env.NODE_ENV !== 'production')) {
  4306. startMeasure(instance, `render`);
  4307. }
  4308. const subTree = (instance.subTree = renderComponentRoot(instance));
  4309. if ((process.env.NODE_ENV !== 'production')) {
  4310. endMeasure(instance, `render`);
  4311. }
  4312. if ((process.env.NODE_ENV !== 'production')) {
  4313. startMeasure(instance, `patch`);
  4314. }
  4315. patch(null, subTree, container, anchor, instance, parentSuspense, isSVG);
  4316. if ((process.env.NODE_ENV !== 'production')) {
  4317. endMeasure(instance, `patch`);
  4318. }
  4319. initialVNode.el = subTree.el;
  4320. }
  4321. // mounted hook
  4322. if (m) {
  4323. queuePostRenderEffect(m, parentSuspense);
  4324. }
  4325. // onVnodeMounted
  4326. if (!isAsyncWrapperVNode &&
  4327. (vnodeHook = props && props.onVnodeMounted)) {
  4328. const scopedInitialVNode = initialVNode;
  4329. queuePostRenderEffect(() => invokeVNodeHook(vnodeHook, parent, scopedInitialVNode), parentSuspense);
  4330. }
  4331. // activated hook for keep-alive roots.
  4332. // #1742 activated hook must be accessed after first render
  4333. // since the hook may be injected by a child keep-alive
  4334. if (initialVNode.shapeFlag & 256 /* COMPONENT_SHOULD_KEEP_ALIVE */) {
  4335. instance.a && queuePostRenderEffect(instance.a, parentSuspense);
  4336. }
  4337. instance.isMounted = true;
  4338. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  4339. devtoolsComponentAdded(instance);
  4340. }
  4341. // #2458: deference mount-only object parameters to prevent memleaks
  4342. initialVNode = container = anchor = null;
  4343. }
  4344. else {
  4345. // updateComponent
  4346. // This is triggered by mutation of component's own state (next: null)
  4347. // OR parent calling processComponent (next: VNode)
  4348. let { next, bu, u, parent, vnode } = instance;
  4349. let originNext = next;
  4350. let vnodeHook;
  4351. if ((process.env.NODE_ENV !== 'production')) {
  4352. pushWarningContext(next || instance.vnode);
  4353. }
  4354. // Disallow component effect recursion during pre-lifecycle hooks.
  4355. toggleRecurse(instance, false);
  4356. if (next) {
  4357. next.el = vnode.el;
  4358. updateComponentPreRender(instance, next, optimized);
  4359. }
  4360. else {
  4361. next = vnode;
  4362. }
  4363. // beforeUpdate hook
  4364. if (bu) {
  4365. invokeArrayFns(bu);
  4366. }
  4367. // onVnodeBeforeUpdate
  4368. if ((vnodeHook = next.props && next.props.onVnodeBeforeUpdate)) {
  4369. invokeVNodeHook(vnodeHook, parent, next, vnode);
  4370. }
  4371. toggleRecurse(instance, true);
  4372. // render
  4373. if ((process.env.NODE_ENV !== 'production')) {
  4374. startMeasure(instance, `render`);
  4375. }
  4376. const nextTree = renderComponentRoot(instance);
  4377. if ((process.env.NODE_ENV !== 'production')) {
  4378. endMeasure(instance, `render`);
  4379. }
  4380. const prevTree = instance.subTree;
  4381. instance.subTree = nextTree;
  4382. if ((process.env.NODE_ENV !== 'production')) {
  4383. startMeasure(instance, `patch`);
  4384. }
  4385. patch(prevTree, nextTree,
  4386. // parent may have changed if it's in a teleport
  4387. hostParentNode(prevTree.el),
  4388. // anchor may have changed if it's in a fragment
  4389. getNextHostNode(prevTree), instance, parentSuspense, isSVG);
  4390. if ((process.env.NODE_ENV !== 'production')) {
  4391. endMeasure(instance, `patch`);
  4392. }
  4393. next.el = nextTree.el;
  4394. if (originNext === null) {
  4395. // self-triggered update. In case of HOC, update parent component
  4396. // vnode el. HOC is indicated by parent instance's subTree pointing
  4397. // to child component's vnode
  4398. updateHOCHostEl(instance, nextTree.el);
  4399. }
  4400. // updated hook
  4401. if (u) {
  4402. queuePostRenderEffect(u, parentSuspense);
  4403. }
  4404. // onVnodeUpdated
  4405. if ((vnodeHook = next.props && next.props.onVnodeUpdated)) {
  4406. queuePostRenderEffect(() => invokeVNodeHook(vnodeHook, parent, next, vnode), parentSuspense);
  4407. }
  4408. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  4409. devtoolsComponentUpdated(instance);
  4410. }
  4411. if ((process.env.NODE_ENV !== 'production')) {
  4412. popWarningContext();
  4413. }
  4414. }
  4415. };
  4416. // create reactive effect for rendering
  4417. const effect = (instance.effect = new ReactiveEffect(componentUpdateFn, () => queueJob(instance.update), instance.scope // track it in component's effect scope
  4418. ));
  4419. const update = (instance.update = effect.run.bind(effect));
  4420. update.id = instance.uid;
  4421. // allowRecurse
  4422. // #1801, #2043 component render effects should allow recursive updates
  4423. toggleRecurse(instance, true);
  4424. if ((process.env.NODE_ENV !== 'production')) {
  4425. effect.onTrack = instance.rtc
  4426. ? e => invokeArrayFns(instance.rtc, e)
  4427. : void 0;
  4428. effect.onTrigger = instance.rtg
  4429. ? e => invokeArrayFns(instance.rtg, e)
  4430. : void 0;
  4431. // @ts-ignore (for scheduler)
  4432. update.ownerInstance = instance;
  4433. }
  4434. update();
  4435. };
  4436. const updateComponentPreRender = (instance, nextVNode, optimized) => {
  4437. nextVNode.component = instance;
  4438. const prevProps = instance.vnode.props;
  4439. instance.vnode = nextVNode;
  4440. instance.next = null;
  4441. updateProps(instance, nextVNode.props, prevProps, optimized);
  4442. updateSlots(instance, nextVNode.children, optimized);
  4443. pauseTracking();
  4444. // props update may have triggered pre-flush watchers.
  4445. // flush them before the render update.
  4446. flushPreFlushCbs(undefined, instance.update);
  4447. resetTracking();
  4448. };
  4449. const patchChildren = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized = false) => {
  4450. const c1 = n1 && n1.children;
  4451. const prevShapeFlag = n1 ? n1.shapeFlag : 0;
  4452. const c2 = n2.children;
  4453. const { patchFlag, shapeFlag } = n2;
  4454. // fast path
  4455. if (patchFlag > 0) {
  4456. if (patchFlag & 128 /* KEYED_FRAGMENT */) {
  4457. // this could be either fully-keyed or mixed (some keyed some not)
  4458. // presence of patchFlag means children are guaranteed to be arrays
  4459. patchKeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  4460. return;
  4461. }
  4462. else if (patchFlag & 256 /* UNKEYED_FRAGMENT */) {
  4463. // unkeyed
  4464. patchUnkeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  4465. return;
  4466. }
  4467. }
  4468. // children has 3 possibilities: text, array or no children.
  4469. if (shapeFlag & 8 /* TEXT_CHILDREN */) {
  4470. // text children fast path
  4471. if (prevShapeFlag & 16 /* ARRAY_CHILDREN */) {
  4472. unmountChildren(c1, parentComponent, parentSuspense);
  4473. }
  4474. if (c2 !== c1) {
  4475. hostSetElementText(container, c2);
  4476. }
  4477. }
  4478. else {
  4479. if (prevShapeFlag & 16 /* ARRAY_CHILDREN */) {
  4480. // prev children was array
  4481. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  4482. // two arrays, cannot assume anything, do full diff
  4483. patchKeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  4484. }
  4485. else {
  4486. // no new children, just unmount old
  4487. unmountChildren(c1, parentComponent, parentSuspense, true);
  4488. }
  4489. }
  4490. else {
  4491. // prev children was text OR null
  4492. // new children is array OR null
  4493. if (prevShapeFlag & 8 /* TEXT_CHILDREN */) {
  4494. hostSetElementText(container, '');
  4495. }
  4496. // mount new if array
  4497. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  4498. mountChildren(c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  4499. }
  4500. }
  4501. }
  4502. };
  4503. const patchUnkeyedChildren = (c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  4504. c1 = c1 || EMPTY_ARR;
  4505. c2 = c2 || EMPTY_ARR;
  4506. const oldLength = c1.length;
  4507. const newLength = c2.length;
  4508. const commonLength = Math.min(oldLength, newLength);
  4509. let i;
  4510. for (i = 0; i < commonLength; i++) {
  4511. const nextChild = (c2[i] = optimized
  4512. ? cloneIfMounted(c2[i])
  4513. : normalizeVNode(c2[i]));
  4514. patch(c1[i], nextChild, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  4515. }
  4516. if (oldLength > newLength) {
  4517. // remove old
  4518. unmountChildren(c1, parentComponent, parentSuspense, true, false, commonLength);
  4519. }
  4520. else {
  4521. // mount new
  4522. mountChildren(c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, commonLength);
  4523. }
  4524. };
  4525. // can be all-keyed or mixed
  4526. const patchKeyedChildren = (c1, c2, container, parentAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  4527. let i = 0;
  4528. const l2 = c2.length;
  4529. let e1 = c1.length - 1; // prev ending index
  4530. let e2 = l2 - 1; // next ending index
  4531. // 1. sync from start
  4532. // (a b) c
  4533. // (a b) d e
  4534. while (i <= e1 && i <= e2) {
  4535. const n1 = c1[i];
  4536. const n2 = (c2[i] = optimized
  4537. ? cloneIfMounted(c2[i])
  4538. : normalizeVNode(c2[i]));
  4539. if (isSameVNodeType(n1, n2)) {
  4540. patch(n1, n2, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  4541. }
  4542. else {
  4543. break;
  4544. }
  4545. i++;
  4546. }
  4547. // 2. sync from end
  4548. // a (b c)
  4549. // d e (b c)
  4550. while (i <= e1 && i <= e2) {
  4551. const n1 = c1[e1];
  4552. const n2 = (c2[e2] = optimized
  4553. ? cloneIfMounted(c2[e2])
  4554. : normalizeVNode(c2[e2]));
  4555. if (isSameVNodeType(n1, n2)) {
  4556. patch(n1, n2, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  4557. }
  4558. else {
  4559. break;
  4560. }
  4561. e1--;
  4562. e2--;
  4563. }
  4564. // 3. common sequence + mount
  4565. // (a b)
  4566. // (a b) c
  4567. // i = 2, e1 = 1, e2 = 2
  4568. // (a b)
  4569. // c (a b)
  4570. // i = 0, e1 = -1, e2 = 0
  4571. if (i > e1) {
  4572. if (i <= e2) {
  4573. const nextPos = e2 + 1;
  4574. const anchor = nextPos < l2 ? c2[nextPos].el : parentAnchor;
  4575. while (i <= e2) {
  4576. patch(null, (c2[i] = optimized
  4577. ? cloneIfMounted(c2[i])
  4578. : normalizeVNode(c2[i])), container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  4579. i++;
  4580. }
  4581. }
  4582. }
  4583. // 4. common sequence + unmount
  4584. // (a b) c
  4585. // (a b)
  4586. // i = 2, e1 = 2, e2 = 1
  4587. // a (b c)
  4588. // (b c)
  4589. // i = 0, e1 = 0, e2 = -1
  4590. else if (i > e2) {
  4591. while (i <= e1) {
  4592. unmount(c1[i], parentComponent, parentSuspense, true);
  4593. i++;
  4594. }
  4595. }
  4596. // 5. unknown sequence
  4597. // [i ... e1 + 1]: a b [c d e] f g
  4598. // [i ... e2 + 1]: a b [e d c h] f g
  4599. // i = 2, e1 = 4, e2 = 5
  4600. else {
  4601. const s1 = i; // prev starting index
  4602. const s2 = i; // next starting index
  4603. // 5.1 build key:index map for newChildren
  4604. const keyToNewIndexMap = new Map();
  4605. for (i = s2; i <= e2; i++) {
  4606. const nextChild = (c2[i] = optimized
  4607. ? cloneIfMounted(c2[i])
  4608. : normalizeVNode(c2[i]));
  4609. if (nextChild.key != null) {
  4610. if ((process.env.NODE_ENV !== 'production') && keyToNewIndexMap.has(nextChild.key)) {
  4611. warn(`Duplicate keys found during update:`, JSON.stringify(nextChild.key), `Make sure keys are unique.`);
  4612. }
  4613. keyToNewIndexMap.set(nextChild.key, i);
  4614. }
  4615. }
  4616. // 5.2 loop through old children left to be patched and try to patch
  4617. // matching nodes & remove nodes that are no longer present
  4618. let j;
  4619. let patched = 0;
  4620. const toBePatched = e2 - s2 + 1;
  4621. let moved = false;
  4622. // used to track whether any node has moved
  4623. let maxNewIndexSoFar = 0;
  4624. // works as Map<newIndex, oldIndex>
  4625. // Note that oldIndex is offset by +1
  4626. // and oldIndex = 0 is a special value indicating the new node has
  4627. // no corresponding old node.
  4628. // used for determining longest stable subsequence
  4629. const newIndexToOldIndexMap = new Array(toBePatched);
  4630. for (i = 0; i < toBePatched; i++)
  4631. newIndexToOldIndexMap[i] = 0;
  4632. for (i = s1; i <= e1; i++) {
  4633. const prevChild = c1[i];
  4634. if (patched >= toBePatched) {
  4635. // all new children have been patched so this can only be a removal
  4636. unmount(prevChild, parentComponent, parentSuspense, true);
  4637. continue;
  4638. }
  4639. let newIndex;
  4640. if (prevChild.key != null) {
  4641. newIndex = keyToNewIndexMap.get(prevChild.key);
  4642. }
  4643. else {
  4644. // key-less node, try to locate a key-less node of the same type
  4645. for (j = s2; j <= e2; j++) {
  4646. if (newIndexToOldIndexMap[j - s2] === 0 &&
  4647. isSameVNodeType(prevChild, c2[j])) {
  4648. newIndex = j;
  4649. break;
  4650. }
  4651. }
  4652. }
  4653. if (newIndex === undefined) {
  4654. unmount(prevChild, parentComponent, parentSuspense, true);
  4655. }
  4656. else {
  4657. newIndexToOldIndexMap[newIndex - s2] = i + 1;
  4658. if (newIndex >= maxNewIndexSoFar) {
  4659. maxNewIndexSoFar = newIndex;
  4660. }
  4661. else {
  4662. moved = true;
  4663. }
  4664. patch(prevChild, c2[newIndex], container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  4665. patched++;
  4666. }
  4667. }
  4668. // 5.3 move and mount
  4669. // generate longest stable subsequence only when nodes have moved
  4670. const increasingNewIndexSequence = moved
  4671. ? getSequence(newIndexToOldIndexMap)
  4672. : EMPTY_ARR;
  4673. j = increasingNewIndexSequence.length - 1;
  4674. // looping backwards so that we can use last patched node as anchor
  4675. for (i = toBePatched - 1; i >= 0; i--) {
  4676. const nextIndex = s2 + i;
  4677. const nextChild = c2[nextIndex];
  4678. const anchor = nextIndex + 1 < l2 ? c2[nextIndex + 1].el : parentAnchor;
  4679. if (newIndexToOldIndexMap[i] === 0) {
  4680. // mount new
  4681. patch(null, nextChild, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  4682. }
  4683. else if (moved) {
  4684. // move if:
  4685. // There is no stable subsequence (e.g. a reverse)
  4686. // OR current node is not among the stable sequence
  4687. if (j < 0 || i !== increasingNewIndexSequence[j]) {
  4688. move(nextChild, container, anchor, 2 /* REORDER */);
  4689. }
  4690. else {
  4691. j--;
  4692. }
  4693. }
  4694. }
  4695. }
  4696. };
  4697. const move = (vnode, container, anchor, moveType, parentSuspense = null) => {
  4698. const { el, type, transition, children, shapeFlag } = vnode;
  4699. if (shapeFlag & 6 /* COMPONENT */) {
  4700. move(vnode.component.subTree, container, anchor, moveType);
  4701. return;
  4702. }
  4703. if (shapeFlag & 128 /* SUSPENSE */) {
  4704. vnode.suspense.move(container, anchor, moveType);
  4705. return;
  4706. }
  4707. if (shapeFlag & 64 /* TELEPORT */) {
  4708. type.move(vnode, container, anchor, internals);
  4709. return;
  4710. }
  4711. if (type === Fragment) {
  4712. hostInsert(el, container, anchor);
  4713. for (let i = 0; i < children.length; i++) {
  4714. move(children[i], container, anchor, moveType);
  4715. }
  4716. hostInsert(vnode.anchor, container, anchor);
  4717. return;
  4718. }
  4719. if (type === Static) {
  4720. moveStaticNode(vnode, container, anchor);
  4721. return;
  4722. }
  4723. // single nodes
  4724. const needTransition = moveType !== 2 /* REORDER */ &&
  4725. shapeFlag & 1 /* ELEMENT */ &&
  4726. transition;
  4727. if (needTransition) {
  4728. if (moveType === 0 /* ENTER */) {
  4729. transition.beforeEnter(el);
  4730. hostInsert(el, container, anchor);
  4731. queuePostRenderEffect(() => transition.enter(el), parentSuspense);
  4732. }
  4733. else {
  4734. const { leave, delayLeave, afterLeave } = transition;
  4735. const remove = () => hostInsert(el, container, anchor);
  4736. const performLeave = () => {
  4737. leave(el, () => {
  4738. remove();
  4739. afterLeave && afterLeave();
  4740. });
  4741. };
  4742. if (delayLeave) {
  4743. delayLeave(el, remove, performLeave);
  4744. }
  4745. else {
  4746. performLeave();
  4747. }
  4748. }
  4749. }
  4750. else {
  4751. hostInsert(el, container, anchor);
  4752. }
  4753. };
  4754. const unmount = (vnode, parentComponent, parentSuspense, doRemove = false, optimized = false) => {
  4755. const { type, props, ref, children, dynamicChildren, shapeFlag, patchFlag, dirs } = vnode;
  4756. // unset ref
  4757. if (ref != null) {
  4758. setRef(ref, null, parentSuspense, vnode, true);
  4759. }
  4760. if (shapeFlag & 256 /* COMPONENT_SHOULD_KEEP_ALIVE */) {
  4761. parentComponent.ctx.deactivate(vnode);
  4762. return;
  4763. }
  4764. const shouldInvokeDirs = shapeFlag & 1 /* ELEMENT */ && dirs;
  4765. const shouldInvokeVnodeHook = !isAsyncWrapper(vnode);
  4766. let vnodeHook;
  4767. if (shouldInvokeVnodeHook &&
  4768. (vnodeHook = props && props.onVnodeBeforeUnmount)) {
  4769. invokeVNodeHook(vnodeHook, parentComponent, vnode);
  4770. }
  4771. if (shapeFlag & 6 /* COMPONENT */) {
  4772. unmountComponent(vnode.component, parentSuspense, doRemove);
  4773. }
  4774. else {
  4775. if (shapeFlag & 128 /* SUSPENSE */) {
  4776. vnode.suspense.unmount(parentSuspense, doRemove);
  4777. return;
  4778. }
  4779. if (shouldInvokeDirs) {
  4780. invokeDirectiveHook(vnode, null, parentComponent, 'beforeUnmount');
  4781. }
  4782. if (shapeFlag & 64 /* TELEPORT */) {
  4783. vnode.type.remove(vnode, parentComponent, parentSuspense, optimized, internals, doRemove);
  4784. }
  4785. else if (dynamicChildren &&
  4786. // #1153: fast path should not be taken for non-stable (v-for) fragments
  4787. (type !== Fragment ||
  4788. (patchFlag > 0 && patchFlag & 64 /* STABLE_FRAGMENT */))) {
  4789. // fast path for block nodes: only need to unmount dynamic children.
  4790. unmountChildren(dynamicChildren, parentComponent, parentSuspense, false, true);
  4791. }
  4792. else if ((type === Fragment &&
  4793. patchFlag &
  4794. (128 /* KEYED_FRAGMENT */ | 256 /* UNKEYED_FRAGMENT */)) ||
  4795. (!optimized && shapeFlag & 16 /* ARRAY_CHILDREN */)) {
  4796. unmountChildren(children, parentComponent, parentSuspense);
  4797. }
  4798. if (doRemove) {
  4799. remove(vnode);
  4800. }
  4801. }
  4802. if ((shouldInvokeVnodeHook &&
  4803. (vnodeHook = props && props.onVnodeUnmounted)) ||
  4804. shouldInvokeDirs) {
  4805. queuePostRenderEffect(() => {
  4806. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, vnode);
  4807. shouldInvokeDirs &&
  4808. invokeDirectiveHook(vnode, null, parentComponent, 'unmounted');
  4809. }, parentSuspense);
  4810. }
  4811. };
  4812. const remove = vnode => {
  4813. const { type, el, anchor, transition } = vnode;
  4814. if (type === Fragment) {
  4815. removeFragment(el, anchor);
  4816. return;
  4817. }
  4818. if (type === Static) {
  4819. removeStaticNode(vnode);
  4820. return;
  4821. }
  4822. const performRemove = () => {
  4823. hostRemove(el);
  4824. if (transition && !transition.persisted && transition.afterLeave) {
  4825. transition.afterLeave();
  4826. }
  4827. };
  4828. if (vnode.shapeFlag & 1 /* ELEMENT */ &&
  4829. transition &&
  4830. !transition.persisted) {
  4831. const { leave, delayLeave } = transition;
  4832. const performLeave = () => leave(el, performRemove);
  4833. if (delayLeave) {
  4834. delayLeave(vnode.el, performRemove, performLeave);
  4835. }
  4836. else {
  4837. performLeave();
  4838. }
  4839. }
  4840. else {
  4841. performRemove();
  4842. }
  4843. };
  4844. const removeFragment = (cur, end) => {
  4845. // For fragments, directly remove all contained DOM nodes.
  4846. // (fragment child nodes cannot have transition)
  4847. let next;
  4848. while (cur !== end) {
  4849. next = hostNextSibling(cur);
  4850. hostRemove(cur);
  4851. cur = next;
  4852. }
  4853. hostRemove(end);
  4854. };
  4855. const unmountComponent = (instance, parentSuspense, doRemove) => {
  4856. if ((process.env.NODE_ENV !== 'production') && instance.type.__hmrId) {
  4857. unregisterHMR(instance);
  4858. }
  4859. const { bum, scope, update, subTree, um } = instance;
  4860. // beforeUnmount hook
  4861. if (bum) {
  4862. invokeArrayFns(bum);
  4863. }
  4864. // stop effects in component scope
  4865. scope.stop();
  4866. // update may be null if a component is unmounted before its async
  4867. // setup has resolved.
  4868. if (update) {
  4869. // so that scheduler will no longer invoke it
  4870. update.active = false;
  4871. unmount(subTree, instance, parentSuspense, doRemove);
  4872. }
  4873. // unmounted hook
  4874. if (um) {
  4875. queuePostRenderEffect(um, parentSuspense);
  4876. }
  4877. queuePostRenderEffect(() => {
  4878. instance.isUnmounted = true;
  4879. }, parentSuspense);
  4880. // A component with async dep inside a pending suspense is unmounted before
  4881. // its async dep resolves. This should remove the dep from the suspense, and
  4882. // cause the suspense to resolve immediately if that was the last dep.
  4883. if (parentSuspense &&
  4884. parentSuspense.pendingBranch &&
  4885. !parentSuspense.isUnmounted &&
  4886. instance.asyncDep &&
  4887. !instance.asyncResolved &&
  4888. instance.suspenseId === parentSuspense.pendingId) {
  4889. parentSuspense.deps--;
  4890. if (parentSuspense.deps === 0) {
  4891. parentSuspense.resolve();
  4892. }
  4893. }
  4894. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  4895. devtoolsComponentRemoved(instance);
  4896. }
  4897. };
  4898. const unmountChildren = (children, parentComponent, parentSuspense, doRemove = false, optimized = false, start = 0) => {
  4899. for (let i = start; i < children.length; i++) {
  4900. unmount(children[i], parentComponent, parentSuspense, doRemove, optimized);
  4901. }
  4902. };
  4903. const getNextHostNode = vnode => {
  4904. if (vnode.shapeFlag & 6 /* COMPONENT */) {
  4905. return getNextHostNode(vnode.component.subTree);
  4906. }
  4907. if (vnode.shapeFlag & 128 /* SUSPENSE */) {
  4908. return vnode.suspense.next();
  4909. }
  4910. return hostNextSibling((vnode.anchor || vnode.el));
  4911. };
  4912. const render = (vnode, container, isSVG) => {
  4913. if (vnode == null) {
  4914. if (container._vnode) {
  4915. unmount(container._vnode, null, null, true);
  4916. }
  4917. }
  4918. else {
  4919. patch(container._vnode || null, vnode, container, null, null, null, isSVG);
  4920. }
  4921. flushPostFlushCbs();
  4922. container._vnode = vnode;
  4923. };
  4924. const internals = {
  4925. p: patch,
  4926. um: unmount,
  4927. m: move,
  4928. r: remove,
  4929. mt: mountComponent,
  4930. mc: mountChildren,
  4931. pc: patchChildren,
  4932. pbc: patchBlockChildren,
  4933. n: getNextHostNode,
  4934. o: options
  4935. };
  4936. let hydrate;
  4937. let hydrateNode;
  4938. if (createHydrationFns) {
  4939. [hydrate, hydrateNode] = createHydrationFns(internals);
  4940. }
  4941. return {
  4942. render,
  4943. hydrate,
  4944. createApp: createAppAPI(render, hydrate)
  4945. };
  4946. }
  4947. function toggleRecurse({ effect, update }, allowed) {
  4948. effect.allowRecurse = update.allowRecurse = allowed;
  4949. }
  4950. /**
  4951. * #1156
  4952. * When a component is HMR-enabled, we need to make sure that all static nodes
  4953. * inside a block also inherit the DOM element from the previous tree so that
  4954. * HMR updates (which are full updates) can retrieve the element for patching.
  4955. *
  4956. * #2080
  4957. * Inside keyed `template` fragment static children, if a fragment is moved,
  4958. * the children will always be moved. Therefore, in order to ensure correct move
  4959. * position, el should be inherited from previous nodes.
  4960. */
  4961. function traverseStaticChildren(n1, n2, shallow = false) {
  4962. const ch1 = n1.children;
  4963. const ch2 = n2.children;
  4964. if (isArray(ch1) && isArray(ch2)) {
  4965. for (let i = 0; i < ch1.length; i++) {
  4966. // this is only called in the optimized path so array children are
  4967. // guaranteed to be vnodes
  4968. const c1 = ch1[i];
  4969. let c2 = ch2[i];
  4970. if (c2.shapeFlag & 1 /* ELEMENT */ && !c2.dynamicChildren) {
  4971. if (c2.patchFlag <= 0 || c2.patchFlag === 32 /* HYDRATE_EVENTS */) {
  4972. c2 = ch2[i] = cloneIfMounted(ch2[i]);
  4973. c2.el = c1.el;
  4974. }
  4975. if (!shallow)
  4976. traverseStaticChildren(c1, c2);
  4977. }
  4978. // also inherit for comment nodes, but not placeholders (e.g. v-if which
  4979. // would have received .el during block patch)
  4980. if ((process.env.NODE_ENV !== 'production') && c2.type === Comment && !c2.el) {
  4981. c2.el = c1.el;
  4982. }
  4983. }
  4984. }
  4985. }
  4986. // https://en.wikipedia.org/wiki/Longest_increasing_subsequence
  4987. function getSequence(arr) {
  4988. const p = arr.slice();
  4989. const result = [0];
  4990. let i, j, u, v, c;
  4991. const len = arr.length;
  4992. for (i = 0; i < len; i++) {
  4993. const arrI = arr[i];
  4994. if (arrI !== 0) {
  4995. j = result[result.length - 1];
  4996. if (arr[j] < arrI) {
  4997. p[i] = j;
  4998. result.push(i);
  4999. continue;
  5000. }
  5001. u = 0;
  5002. v = result.length - 1;
  5003. while (u < v) {
  5004. c = (u + v) >> 1;
  5005. if (arr[result[c]] < arrI) {
  5006. u = c + 1;
  5007. }
  5008. else {
  5009. v = c;
  5010. }
  5011. }
  5012. if (arrI < arr[result[u]]) {
  5013. if (u > 0) {
  5014. p[i] = result[u - 1];
  5015. }
  5016. result[u] = i;
  5017. }
  5018. }
  5019. }
  5020. u = result.length;
  5021. v = result[u - 1];
  5022. while (u-- > 0) {
  5023. result[u] = v;
  5024. v = p[v];
  5025. }
  5026. return result;
  5027. }
  5028. const isTeleport = (type) => type.__isTeleport;
  5029. const isTeleportDisabled = (props) => props && (props.disabled || props.disabled === '');
  5030. const isTargetSVG = (target) => typeof SVGElement !== 'undefined' && target instanceof SVGElement;
  5031. const resolveTarget = (props, select) => {
  5032. const targetSelector = props && props.to;
  5033. if (isString(targetSelector)) {
  5034. if (!select) {
  5035. (process.env.NODE_ENV !== 'production') &&
  5036. warn(`Current renderer does not support string target for Teleports. ` +
  5037. `(missing querySelector renderer option)`);
  5038. return null;
  5039. }
  5040. else {
  5041. const target = select(targetSelector);
  5042. if (!target) {
  5043. (process.env.NODE_ENV !== 'production') &&
  5044. warn(`Failed to locate Teleport target with selector "${targetSelector}". ` +
  5045. `Note the target element must exist before the component is mounted - ` +
  5046. `i.e. the target cannot be rendered by the component itself, and ` +
  5047. `ideally should be outside of the entire Vue component tree.`);
  5048. }
  5049. return target;
  5050. }
  5051. }
  5052. else {
  5053. if ((process.env.NODE_ENV !== 'production') && !targetSelector && !isTeleportDisabled(props)) {
  5054. warn(`Invalid Teleport target: ${targetSelector}`);
  5055. }
  5056. return targetSelector;
  5057. }
  5058. };
  5059. const TeleportImpl = {
  5060. __isTeleport: true,
  5061. process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, internals) {
  5062. const { mc: mountChildren, pc: patchChildren, pbc: patchBlockChildren, o: { insert, querySelector, createText, createComment } } = internals;
  5063. const disabled = isTeleportDisabled(n2.props);
  5064. let { shapeFlag, children, dynamicChildren } = n2;
  5065. // #3302
  5066. // HMR updated, force full diff
  5067. if ((process.env.NODE_ENV !== 'production') && isHmrUpdating) {
  5068. optimized = false;
  5069. dynamicChildren = null;
  5070. }
  5071. if (n1 == null) {
  5072. // insert anchors in the main view
  5073. const placeholder = (n2.el = (process.env.NODE_ENV !== 'production')
  5074. ? createComment('teleport start')
  5075. : createText(''));
  5076. const mainAnchor = (n2.anchor = (process.env.NODE_ENV !== 'production')
  5077. ? createComment('teleport end')
  5078. : createText(''));
  5079. insert(placeholder, container, anchor);
  5080. insert(mainAnchor, container, anchor);
  5081. const target = (n2.target = resolveTarget(n2.props, querySelector));
  5082. const targetAnchor = (n2.targetAnchor = createText(''));
  5083. if (target) {
  5084. insert(targetAnchor, target);
  5085. // #2652 we could be teleporting from a non-SVG tree into an SVG tree
  5086. isSVG = isSVG || isTargetSVG(target);
  5087. }
  5088. else if ((process.env.NODE_ENV !== 'production') && !disabled) {
  5089. warn('Invalid Teleport target on mount:', target, `(${typeof target})`);
  5090. }
  5091. const mount = (container, anchor) => {
  5092. // Teleport *always* has Array children. This is enforced in both the
  5093. // compiler and vnode children normalization.
  5094. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  5095. mountChildren(children, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5096. }
  5097. };
  5098. if (disabled) {
  5099. mount(container, mainAnchor);
  5100. }
  5101. else if (target) {
  5102. mount(target, targetAnchor);
  5103. }
  5104. }
  5105. else {
  5106. // update content
  5107. n2.el = n1.el;
  5108. const mainAnchor = (n2.anchor = n1.anchor);
  5109. const target = (n2.target = n1.target);
  5110. const targetAnchor = (n2.targetAnchor = n1.targetAnchor);
  5111. const wasDisabled = isTeleportDisabled(n1.props);
  5112. const currentContainer = wasDisabled ? container : target;
  5113. const currentAnchor = wasDisabled ? mainAnchor : targetAnchor;
  5114. isSVG = isSVG || isTargetSVG(target);
  5115. if (dynamicChildren) {
  5116. // fast path when the teleport happens to be a block root
  5117. patchBlockChildren(n1.dynamicChildren, dynamicChildren, currentContainer, parentComponent, parentSuspense, isSVG, slotScopeIds);
  5118. // even in block tree mode we need to make sure all root-level nodes
  5119. // in the teleport inherit previous DOM references so that they can
  5120. // be moved in future patches.
  5121. traverseStaticChildren(n1, n2, true);
  5122. }
  5123. else if (!optimized) {
  5124. patchChildren(n1, n2, currentContainer, currentAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, false);
  5125. }
  5126. if (disabled) {
  5127. if (!wasDisabled) {
  5128. // enabled -> disabled
  5129. // move into main container
  5130. moveTeleport(n2, container, mainAnchor, internals, 1 /* TOGGLE */);
  5131. }
  5132. }
  5133. else {
  5134. // target changed
  5135. if ((n2.props && n2.props.to) !== (n1.props && n1.props.to)) {
  5136. const nextTarget = (n2.target = resolveTarget(n2.props, querySelector));
  5137. if (nextTarget) {
  5138. moveTeleport(n2, nextTarget, null, internals, 0 /* TARGET_CHANGE */);
  5139. }
  5140. else if ((process.env.NODE_ENV !== 'production')) {
  5141. warn('Invalid Teleport target on update:', target, `(${typeof target})`);
  5142. }
  5143. }
  5144. else if (wasDisabled) {
  5145. // disabled -> enabled
  5146. // move into teleport target
  5147. moveTeleport(n2, target, targetAnchor, internals, 1 /* TOGGLE */);
  5148. }
  5149. }
  5150. }
  5151. },
  5152. remove(vnode, parentComponent, parentSuspense, optimized, { um: unmount, o: { remove: hostRemove } }, doRemove) {
  5153. const { shapeFlag, children, anchor, targetAnchor, target, props } = vnode;
  5154. if (target) {
  5155. hostRemove(targetAnchor);
  5156. }
  5157. // an unmounted teleport should always remove its children if not disabled
  5158. if (doRemove || !isTeleportDisabled(props)) {
  5159. hostRemove(anchor);
  5160. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  5161. for (let i = 0; i < children.length; i++) {
  5162. const child = children[i];
  5163. unmount(child, parentComponent, parentSuspense, true, !!child.dynamicChildren);
  5164. }
  5165. }
  5166. }
  5167. },
  5168. move: moveTeleport,
  5169. hydrate: hydrateTeleport
  5170. };
  5171. function moveTeleport(vnode, container, parentAnchor, { o: { insert }, m: move }, moveType = 2 /* REORDER */) {
  5172. // move target anchor if this is a target change.
  5173. if (moveType === 0 /* TARGET_CHANGE */) {
  5174. insert(vnode.targetAnchor, container, parentAnchor);
  5175. }
  5176. const { el, anchor, shapeFlag, children, props } = vnode;
  5177. const isReorder = moveType === 2 /* REORDER */;
  5178. // move main view anchor if this is a re-order.
  5179. if (isReorder) {
  5180. insert(el, container, parentAnchor);
  5181. }
  5182. // if this is a re-order and teleport is enabled (content is in target)
  5183. // do not move children. So the opposite is: only move children if this
  5184. // is not a reorder, or the teleport is disabled
  5185. if (!isReorder || isTeleportDisabled(props)) {
  5186. // Teleport has either Array children or no children.
  5187. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  5188. for (let i = 0; i < children.length; i++) {
  5189. move(children[i], container, parentAnchor, 2 /* REORDER */);
  5190. }
  5191. }
  5192. }
  5193. // move main view anchor if this is a re-order.
  5194. if (isReorder) {
  5195. insert(anchor, container, parentAnchor);
  5196. }
  5197. }
  5198. function hydrateTeleport(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized, { o: { nextSibling, parentNode, querySelector } }, hydrateChildren) {
  5199. const target = (vnode.target = resolveTarget(vnode.props, querySelector));
  5200. if (target) {
  5201. // if multiple teleports rendered to the same target element, we need to
  5202. // pick up from where the last teleport finished instead of the first node
  5203. const targetNode = target._lpa || target.firstChild;
  5204. if (vnode.shapeFlag & 16 /* ARRAY_CHILDREN */) {
  5205. if (isTeleportDisabled(vnode.props)) {
  5206. vnode.anchor = hydrateChildren(nextSibling(node), vnode, parentNode(node), parentComponent, parentSuspense, slotScopeIds, optimized);
  5207. vnode.targetAnchor = targetNode;
  5208. }
  5209. else {
  5210. vnode.anchor = nextSibling(node);
  5211. vnode.targetAnchor = hydrateChildren(targetNode, vnode, target, parentComponent, parentSuspense, slotScopeIds, optimized);
  5212. }
  5213. target._lpa =
  5214. vnode.targetAnchor && nextSibling(vnode.targetAnchor);
  5215. }
  5216. }
  5217. return vnode.anchor && nextSibling(vnode.anchor);
  5218. }
  5219. // Force-casted public typing for h and TSX props inference
  5220. const Teleport = TeleportImpl;
  5221. const COMPONENTS = 'components';
  5222. const DIRECTIVES = 'directives';
  5223. /**
  5224. * @private
  5225. */
  5226. function resolveComponent(name, maybeSelfReference) {
  5227. return resolveAsset(COMPONENTS, name, true, maybeSelfReference) || name;
  5228. }
  5229. const NULL_DYNAMIC_COMPONENT = Symbol();
  5230. /**
  5231. * @private
  5232. */
  5233. function resolveDynamicComponent(component) {
  5234. if (isString(component)) {
  5235. return resolveAsset(COMPONENTS, component, false) || component;
  5236. }
  5237. else {
  5238. // invalid types will fallthrough to createVNode and raise warning
  5239. return (component || NULL_DYNAMIC_COMPONENT);
  5240. }
  5241. }
  5242. /**
  5243. * @private
  5244. */
  5245. function resolveDirective(name) {
  5246. return resolveAsset(DIRECTIVES, name);
  5247. }
  5248. // implementation
  5249. function resolveAsset(type, name, warnMissing = true, maybeSelfReference = false) {
  5250. const instance = currentRenderingInstance || currentInstance;
  5251. if (instance) {
  5252. const Component = instance.type;
  5253. // explicit self name has highest priority
  5254. if (type === COMPONENTS) {
  5255. const selfName = getComponentName(Component);
  5256. if (selfName &&
  5257. (selfName === name ||
  5258. selfName === camelize(name) ||
  5259. selfName === capitalize(camelize(name)))) {
  5260. return Component;
  5261. }
  5262. }
  5263. const res =
  5264. // local registration
  5265. // check instance[type] first which is resolved for options API
  5266. resolve(instance[type] || Component[type], name) ||
  5267. // global registration
  5268. resolve(instance.appContext[type], name);
  5269. if (!res && maybeSelfReference) {
  5270. // fallback to implicit self-reference
  5271. return Component;
  5272. }
  5273. if ((process.env.NODE_ENV !== 'production') && warnMissing && !res) {
  5274. const extra = type === COMPONENTS
  5275. ? `\nIf this is a native custom element, make sure to exclude it from ` +
  5276. `component resolution via compilerOptions.isCustomElement.`
  5277. : ``;
  5278. warn(`Failed to resolve ${type.slice(0, -1)}: ${name}${extra}`);
  5279. }
  5280. return res;
  5281. }
  5282. else if ((process.env.NODE_ENV !== 'production')) {
  5283. warn(`resolve${capitalize(type.slice(0, -1))} ` +
  5284. `can only be used in render() or setup().`);
  5285. }
  5286. }
  5287. function resolve(registry, name) {
  5288. return (registry &&
  5289. (registry[name] ||
  5290. registry[camelize(name)] ||
  5291. registry[capitalize(camelize(name))]));
  5292. }
  5293. const Fragment = Symbol((process.env.NODE_ENV !== 'production') ? 'Fragment' : undefined);
  5294. const Text = Symbol((process.env.NODE_ENV !== 'production') ? 'Text' : undefined);
  5295. const Comment = Symbol((process.env.NODE_ENV !== 'production') ? 'Comment' : undefined);
  5296. const Static = Symbol((process.env.NODE_ENV !== 'production') ? 'Static' : undefined);
  5297. // Since v-if and v-for are the two possible ways node structure can dynamically
  5298. // change, once we consider v-if branches and each v-for fragment a block, we
  5299. // can divide a template into nested blocks, and within each block the node
  5300. // structure would be stable. This allows us to skip most children diffing
  5301. // and only worry about the dynamic nodes (indicated by patch flags).
  5302. const blockStack = [];
  5303. let currentBlock = null;
  5304. /**
  5305. * Open a block.
  5306. * This must be called before `createBlock`. It cannot be part of `createBlock`
  5307. * because the children of the block are evaluated before `createBlock` itself
  5308. * is called. The generated code typically looks like this:
  5309. *
  5310. * ```js
  5311. * function render() {
  5312. * return (openBlock(),createBlock('div', null, [...]))
  5313. * }
  5314. * ```
  5315. * disableTracking is true when creating a v-for fragment block, since a v-for
  5316. * fragment always diffs its children.
  5317. *
  5318. * @private
  5319. */
  5320. function openBlock(disableTracking = false) {
  5321. blockStack.push((currentBlock = disableTracking ? null : []));
  5322. }
  5323. function closeBlock() {
  5324. blockStack.pop();
  5325. currentBlock = blockStack[blockStack.length - 1] || null;
  5326. }
  5327. // Whether we should be tracking dynamic child nodes inside a block.
  5328. // Only tracks when this value is > 0
  5329. // We are not using a simple boolean because this value may need to be
  5330. // incremented/decremented by nested usage of v-once (see below)
  5331. let isBlockTreeEnabled = 1;
  5332. /**
  5333. * Block tracking sometimes needs to be disabled, for example during the
  5334. * creation of a tree that needs to be cached by v-once. The compiler generates
  5335. * code like this:
  5336. *
  5337. * ``` js
  5338. * _cache[1] || (
  5339. * setBlockTracking(-1),
  5340. * _cache[1] = createVNode(...),
  5341. * setBlockTracking(1),
  5342. * _cache[1]
  5343. * )
  5344. * ```
  5345. *
  5346. * @private
  5347. */
  5348. function setBlockTracking(value) {
  5349. isBlockTreeEnabled += value;
  5350. }
  5351. function setupBlock(vnode) {
  5352. // save current block children on the block vnode
  5353. vnode.dynamicChildren =
  5354. isBlockTreeEnabled > 0 ? currentBlock || EMPTY_ARR : null;
  5355. // close block
  5356. closeBlock();
  5357. // a block is always going to be patched, so track it as a child of its
  5358. // parent block
  5359. if (isBlockTreeEnabled > 0 && currentBlock) {
  5360. currentBlock.push(vnode);
  5361. }
  5362. return vnode;
  5363. }
  5364. /**
  5365. * @private
  5366. */
  5367. function createElementBlock(type, props, children, patchFlag, dynamicProps, shapeFlag) {
  5368. return setupBlock(createBaseVNode(type, props, children, patchFlag, dynamicProps, shapeFlag, true /* isBlock */));
  5369. }
  5370. /**
  5371. * Create a block root vnode. Takes the same exact arguments as `createVNode`.
  5372. * A block root keeps track of dynamic nodes within the block in the
  5373. * `dynamicChildren` array.
  5374. *
  5375. * @private
  5376. */
  5377. function createBlock(type, props, children, patchFlag, dynamicProps) {
  5378. return setupBlock(createVNode(type, props, children, patchFlag, dynamicProps, true /* isBlock: prevent a block from tracking itself */));
  5379. }
  5380. function isVNode(value) {
  5381. return value ? value.__v_isVNode === true : false;
  5382. }
  5383. function isSameVNodeType(n1, n2) {
  5384. if ((process.env.NODE_ENV !== 'production') &&
  5385. n2.shapeFlag & 6 /* COMPONENT */ &&
  5386. hmrDirtyComponents.has(n2.type)) {
  5387. // HMR only: if the component has been hot-updated, force a reload.
  5388. return false;
  5389. }
  5390. return n1.type === n2.type && n1.key === n2.key;
  5391. }
  5392. let vnodeArgsTransformer;
  5393. /**
  5394. * Internal API for registering an arguments transform for createVNode
  5395. * used for creating stubs in the test-utils
  5396. * It is *internal* but needs to be exposed for test-utils to pick up proper
  5397. * typings
  5398. */
  5399. function transformVNodeArgs(transformer) {
  5400. vnodeArgsTransformer = transformer;
  5401. }
  5402. const createVNodeWithArgsTransform = (...args) => {
  5403. return _createVNode(...(vnodeArgsTransformer
  5404. ? vnodeArgsTransformer(args, currentRenderingInstance)
  5405. : args));
  5406. };
  5407. const InternalObjectKey = `__vInternal`;
  5408. const normalizeKey = ({ key }) => key != null ? key : null;
  5409. const normalizeRef = ({ ref, ref_key, ref_for }) => {
  5410. return (ref != null
  5411. ? isString(ref) || isRef(ref) || isFunction(ref)
  5412. ? { i: currentRenderingInstance, r: ref, k: ref_key, f: !!ref_for }
  5413. : ref
  5414. : null);
  5415. };
  5416. function createBaseVNode(type, props = null, children = null, patchFlag = 0, dynamicProps = null, shapeFlag = type === Fragment ? 0 : 1 /* ELEMENT */, isBlockNode = false, needFullChildrenNormalization = false) {
  5417. const vnode = {
  5418. __v_isVNode: true,
  5419. __v_skip: true,
  5420. type,
  5421. props,
  5422. key: props && normalizeKey(props),
  5423. ref: props && normalizeRef(props),
  5424. scopeId: currentScopeId,
  5425. slotScopeIds: null,
  5426. children,
  5427. component: null,
  5428. suspense: null,
  5429. ssContent: null,
  5430. ssFallback: null,
  5431. dirs: null,
  5432. transition: null,
  5433. el: null,
  5434. anchor: null,
  5435. target: null,
  5436. targetAnchor: null,
  5437. staticCount: 0,
  5438. shapeFlag,
  5439. patchFlag,
  5440. dynamicProps,
  5441. dynamicChildren: null,
  5442. appContext: null
  5443. };
  5444. if (needFullChildrenNormalization) {
  5445. normalizeChildren(vnode, children);
  5446. // normalize suspense children
  5447. if (shapeFlag & 128 /* SUSPENSE */) {
  5448. type.normalize(vnode);
  5449. }
  5450. }
  5451. else if (children) {
  5452. // compiled element vnode - if children is passed, only possible types are
  5453. // string or Array.
  5454. vnode.shapeFlag |= isString(children)
  5455. ? 8 /* TEXT_CHILDREN */
  5456. : 16 /* ARRAY_CHILDREN */;
  5457. }
  5458. // validate key
  5459. if ((process.env.NODE_ENV !== 'production') && vnode.key !== vnode.key) {
  5460. warn(`VNode created with invalid key (NaN). VNode type:`, vnode.type);
  5461. }
  5462. // track vnode for block tree
  5463. if (isBlockTreeEnabled > 0 &&
  5464. // avoid a block node from tracking itself
  5465. !isBlockNode &&
  5466. // has current parent block
  5467. currentBlock &&
  5468. // presence of a patch flag indicates this node needs patching on updates.
  5469. // component nodes also should always be patched, because even if the
  5470. // component doesn't need to update, it needs to persist the instance on to
  5471. // the next vnode so that it can be properly unmounted later.
  5472. (vnode.patchFlag > 0 || shapeFlag & 6 /* COMPONENT */) &&
  5473. // the EVENTS flag is only for hydration and if it is the only flag, the
  5474. // vnode should not be considered dynamic due to handler caching.
  5475. vnode.patchFlag !== 32 /* HYDRATE_EVENTS */) {
  5476. currentBlock.push(vnode);
  5477. }
  5478. return vnode;
  5479. }
  5480. const createVNode = ((process.env.NODE_ENV !== 'production') ? createVNodeWithArgsTransform : _createVNode);
  5481. function _createVNode(type, props = null, children = null, patchFlag = 0, dynamicProps = null, isBlockNode = false) {
  5482. if (!type || type === NULL_DYNAMIC_COMPONENT) {
  5483. if ((process.env.NODE_ENV !== 'production') && !type) {
  5484. warn(`Invalid vnode type when creating vnode: ${type}.`);
  5485. }
  5486. type = Comment;
  5487. }
  5488. if (isVNode(type)) {
  5489. // createVNode receiving an existing vnode. This happens in cases like
  5490. // <component :is="vnode"/>
  5491. // #2078 make sure to merge refs during the clone instead of overwriting it
  5492. const cloned = cloneVNode(type, props, true /* mergeRef: true */);
  5493. if (children) {
  5494. normalizeChildren(cloned, children);
  5495. }
  5496. return cloned;
  5497. }
  5498. // class component normalization.
  5499. if (isClassComponent(type)) {
  5500. type = type.__vccOpts;
  5501. }
  5502. // class & style normalization.
  5503. if (props) {
  5504. // for reactive or proxy objects, we need to clone it to enable mutation.
  5505. props = guardReactiveProps(props);
  5506. let { class: klass, style } = props;
  5507. if (klass && !isString(klass)) {
  5508. props.class = normalizeClass(klass);
  5509. }
  5510. if (isObject(style)) {
  5511. // reactive state objects need to be cloned since they are likely to be
  5512. // mutated
  5513. if (isProxy(style) && !isArray(style)) {
  5514. style = extend({}, style);
  5515. }
  5516. props.style = normalizeStyle(style);
  5517. }
  5518. }
  5519. // encode the vnode type information into a bitmap
  5520. const shapeFlag = isString(type)
  5521. ? 1 /* ELEMENT */
  5522. : isSuspense(type)
  5523. ? 128 /* SUSPENSE */
  5524. : isTeleport(type)
  5525. ? 64 /* TELEPORT */
  5526. : isObject(type)
  5527. ? 4 /* STATEFUL_COMPONENT */
  5528. : isFunction(type)
  5529. ? 2 /* FUNCTIONAL_COMPONENT */
  5530. : 0;
  5531. if ((process.env.NODE_ENV !== 'production') && shapeFlag & 4 /* STATEFUL_COMPONENT */ && isProxy(type)) {
  5532. type = toRaw(type);
  5533. warn(`Vue received a Component which was made a reactive object. This can ` +
  5534. `lead to unnecessary performance overhead, and should be avoided by ` +
  5535. `marking the component with \`markRaw\` or using \`shallowRef\` ` +
  5536. `instead of \`ref\`.`, `\nComponent that was made reactive: `, type);
  5537. }
  5538. return createBaseVNode(type, props, children, patchFlag, dynamicProps, shapeFlag, isBlockNode, true);
  5539. }
  5540. function guardReactiveProps(props) {
  5541. if (!props)
  5542. return null;
  5543. return isProxy(props) || InternalObjectKey in props
  5544. ? extend({}, props)
  5545. : props;
  5546. }
  5547. function cloneVNode(vnode, extraProps, mergeRef = false) {
  5548. // This is intentionally NOT using spread or extend to avoid the runtime
  5549. // key enumeration cost.
  5550. const { props, ref, patchFlag, children } = vnode;
  5551. const mergedProps = extraProps ? mergeProps(props || {}, extraProps) : props;
  5552. const cloned = {
  5553. __v_isVNode: true,
  5554. __v_skip: true,
  5555. type: vnode.type,
  5556. props: mergedProps,
  5557. key: mergedProps && normalizeKey(mergedProps),
  5558. ref: extraProps && extraProps.ref
  5559. ? // #2078 in the case of <component :is="vnode" ref="extra"/>
  5560. // if the vnode itself already has a ref, cloneVNode will need to merge
  5561. // the refs so the single vnode can be set on multiple refs
  5562. mergeRef && ref
  5563. ? isArray(ref)
  5564. ? ref.concat(normalizeRef(extraProps))
  5565. : [ref, normalizeRef(extraProps)]
  5566. : normalizeRef(extraProps)
  5567. : ref,
  5568. scopeId: vnode.scopeId,
  5569. slotScopeIds: vnode.slotScopeIds,
  5570. children: (process.env.NODE_ENV !== 'production') && patchFlag === -1 /* HOISTED */ && isArray(children)
  5571. ? children.map(deepCloneVNode)
  5572. : children,
  5573. target: vnode.target,
  5574. targetAnchor: vnode.targetAnchor,
  5575. staticCount: vnode.staticCount,
  5576. shapeFlag: vnode.shapeFlag,
  5577. // if the vnode is cloned with extra props, we can no longer assume its
  5578. // existing patch flag to be reliable and need to add the FULL_PROPS flag.
  5579. // note: perserve flag for fragments since they use the flag for children
  5580. // fast paths only.
  5581. patchFlag: extraProps && vnode.type !== Fragment
  5582. ? patchFlag === -1 // hoisted node
  5583. ? 16 /* FULL_PROPS */
  5584. : patchFlag | 16 /* FULL_PROPS */
  5585. : patchFlag,
  5586. dynamicProps: vnode.dynamicProps,
  5587. dynamicChildren: vnode.dynamicChildren,
  5588. appContext: vnode.appContext,
  5589. dirs: vnode.dirs,
  5590. transition: vnode.transition,
  5591. // These should technically only be non-null on mounted VNodes. However,
  5592. // they *should* be copied for kept-alive vnodes. So we just always copy
  5593. // them since them being non-null during a mount doesn't affect the logic as
  5594. // they will simply be overwritten.
  5595. component: vnode.component,
  5596. suspense: vnode.suspense,
  5597. ssContent: vnode.ssContent && cloneVNode(vnode.ssContent),
  5598. ssFallback: vnode.ssFallback && cloneVNode(vnode.ssFallback),
  5599. el: vnode.el,
  5600. anchor: vnode.anchor
  5601. };
  5602. return cloned;
  5603. }
  5604. /**
  5605. * Dev only, for HMR of hoisted vnodes reused in v-for
  5606. * https://github.com/vitejs/vite/issues/2022
  5607. */
  5608. function deepCloneVNode(vnode) {
  5609. const cloned = cloneVNode(vnode);
  5610. if (isArray(vnode.children)) {
  5611. cloned.children = vnode.children.map(deepCloneVNode);
  5612. }
  5613. return cloned;
  5614. }
  5615. /**
  5616. * @private
  5617. */
  5618. function createTextVNode(text = ' ', flag = 0) {
  5619. return createVNode(Text, null, text, flag);
  5620. }
  5621. /**
  5622. * @private
  5623. */
  5624. function createStaticVNode(content, numberOfNodes) {
  5625. // A static vnode can contain multiple stringified elements, and the number
  5626. // of elements is necessary for hydration.
  5627. const vnode = createVNode(Static, null, content);
  5628. vnode.staticCount = numberOfNodes;
  5629. return vnode;
  5630. }
  5631. /**
  5632. * @private
  5633. */
  5634. function createCommentVNode(text = '',
  5635. // when used as the v-else branch, the comment node must be created as a
  5636. // block to ensure correct updates.
  5637. asBlock = false) {
  5638. return asBlock
  5639. ? (openBlock(), createBlock(Comment, null, text))
  5640. : createVNode(Comment, null, text);
  5641. }
  5642. function normalizeVNode(child) {
  5643. if (child == null || typeof child === 'boolean') {
  5644. // empty placeholder
  5645. return createVNode(Comment);
  5646. }
  5647. else if (isArray(child)) {
  5648. // fragment
  5649. return createVNode(Fragment, null,
  5650. // #3666, avoid reference pollution when reusing vnode
  5651. child.slice());
  5652. }
  5653. else if (typeof child === 'object') {
  5654. // already vnode, this should be the most common since compiled templates
  5655. // always produce all-vnode children arrays
  5656. return cloneIfMounted(child);
  5657. }
  5658. else {
  5659. // strings and numbers
  5660. return createVNode(Text, null, String(child));
  5661. }
  5662. }
  5663. // optimized normalization for template-compiled render fns
  5664. function cloneIfMounted(child) {
  5665. return child.el === null || child.memo ? child : cloneVNode(child);
  5666. }
  5667. function normalizeChildren(vnode, children) {
  5668. let type = 0;
  5669. const { shapeFlag } = vnode;
  5670. if (children == null) {
  5671. children = null;
  5672. }
  5673. else if (isArray(children)) {
  5674. type = 16 /* ARRAY_CHILDREN */;
  5675. }
  5676. else if (typeof children === 'object') {
  5677. if (shapeFlag & (1 /* ELEMENT */ | 64 /* TELEPORT */)) {
  5678. // Normalize slot to plain children for plain element and Teleport
  5679. const slot = children.default;
  5680. if (slot) {
  5681. // _c marker is added by withCtx() indicating this is a compiled slot
  5682. slot._c && (slot._d = false);
  5683. normalizeChildren(vnode, slot());
  5684. slot._c && (slot._d = true);
  5685. }
  5686. return;
  5687. }
  5688. else {
  5689. type = 32 /* SLOTS_CHILDREN */;
  5690. const slotFlag = children._;
  5691. if (!slotFlag && !(InternalObjectKey in children)) {
  5692. children._ctx = currentRenderingInstance;
  5693. }
  5694. else if (slotFlag === 3 /* FORWARDED */ && currentRenderingInstance) {
  5695. // a child component receives forwarded slots from the parent.
  5696. // its slot type is determined by its parent's slot type.
  5697. if (currentRenderingInstance.slots._ === 1 /* STABLE */) {
  5698. children._ = 1 /* STABLE */;
  5699. }
  5700. else {
  5701. children._ = 2 /* DYNAMIC */;
  5702. vnode.patchFlag |= 1024 /* DYNAMIC_SLOTS */;
  5703. }
  5704. }
  5705. }
  5706. }
  5707. else if (isFunction(children)) {
  5708. children = { default: children, _ctx: currentRenderingInstance };
  5709. type = 32 /* SLOTS_CHILDREN */;
  5710. }
  5711. else {
  5712. children = String(children);
  5713. // force teleport children to array so it can be moved around
  5714. if (shapeFlag & 64 /* TELEPORT */) {
  5715. type = 16 /* ARRAY_CHILDREN */;
  5716. children = [createTextVNode(children)];
  5717. }
  5718. else {
  5719. type = 8 /* TEXT_CHILDREN */;
  5720. }
  5721. }
  5722. vnode.children = children;
  5723. vnode.shapeFlag |= type;
  5724. }
  5725. function mergeProps(...args) {
  5726. const ret = {};
  5727. for (let i = 0; i < args.length; i++) {
  5728. const toMerge = args[i];
  5729. for (const key in toMerge) {
  5730. if (key === 'class') {
  5731. if (ret.class !== toMerge.class) {
  5732. ret.class = normalizeClass([ret.class, toMerge.class]);
  5733. }
  5734. }
  5735. else if (key === 'style') {
  5736. ret.style = normalizeStyle([ret.style, toMerge.style]);
  5737. }
  5738. else if (isOn(key)) {
  5739. const existing = ret[key];
  5740. const incoming = toMerge[key];
  5741. if (existing !== incoming &&
  5742. !(isArray(existing) && existing.includes(incoming))) {
  5743. ret[key] = existing
  5744. ? [].concat(existing, incoming)
  5745. : incoming;
  5746. }
  5747. }
  5748. else if (key !== '') {
  5749. ret[key] = toMerge[key];
  5750. }
  5751. }
  5752. }
  5753. return ret;
  5754. }
  5755. function invokeVNodeHook(hook, instance, vnode, prevVNode = null) {
  5756. callWithAsyncErrorHandling(hook, instance, 7 /* VNODE_HOOK */, [
  5757. vnode,
  5758. prevVNode
  5759. ]);
  5760. }
  5761. /**
  5762. * Actual implementation
  5763. */
  5764. function renderList(source, renderItem, cache, index) {
  5765. let ret;
  5766. const cached = (cache && cache[index]);
  5767. if (isArray(source) || isString(source)) {
  5768. ret = new Array(source.length);
  5769. for (let i = 0, l = source.length; i < l; i++) {
  5770. ret[i] = renderItem(source[i], i, undefined, cached && cached[i]);
  5771. }
  5772. }
  5773. else if (typeof source === 'number') {
  5774. if ((process.env.NODE_ENV !== 'production') && !Number.isInteger(source)) {
  5775. warn(`The v-for range expect an integer value but got ${source}.`);
  5776. return [];
  5777. }
  5778. ret = new Array(source);
  5779. for (let i = 0; i < source; i++) {
  5780. ret[i] = renderItem(i + 1, i, undefined, cached && cached[i]);
  5781. }
  5782. }
  5783. else if (isObject(source)) {
  5784. if (source[Symbol.iterator]) {
  5785. ret = Array.from(source, (item, i) => renderItem(item, i, undefined, cached && cached[i]));
  5786. }
  5787. else {
  5788. const keys = Object.keys(source);
  5789. ret = new Array(keys.length);
  5790. for (let i = 0, l = keys.length; i < l; i++) {
  5791. const key = keys[i];
  5792. ret[i] = renderItem(source[key], key, i, cached && cached[i]);
  5793. }
  5794. }
  5795. }
  5796. else {
  5797. ret = [];
  5798. }
  5799. if (cache) {
  5800. cache[index] = ret;
  5801. }
  5802. return ret;
  5803. }
  5804. /**
  5805. * Compiler runtime helper for creating dynamic slots object
  5806. * @private
  5807. */
  5808. function createSlots(slots, dynamicSlots) {
  5809. for (let i = 0; i < dynamicSlots.length; i++) {
  5810. const slot = dynamicSlots[i];
  5811. // array of dynamic slot generated by <template v-for="..." #[...]>
  5812. if (isArray(slot)) {
  5813. for (let j = 0; j < slot.length; j++) {
  5814. slots[slot[j].name] = slot[j].fn;
  5815. }
  5816. }
  5817. else if (slot) {
  5818. // conditional single slot generated by <template v-if="..." #foo>
  5819. slots[slot.name] = slot.fn;
  5820. }
  5821. }
  5822. return slots;
  5823. }
  5824. /**
  5825. * Compiler runtime helper for rendering `<slot/>`
  5826. * @private
  5827. */
  5828. function renderSlot(slots, name, props = {},
  5829. // this is not a user-facing function, so the fallback is always generated by
  5830. // the compiler and guaranteed to be a function returning an array
  5831. fallback, noSlotted) {
  5832. if (currentRenderingInstance.isCE) {
  5833. return createVNode('slot', name === 'default' ? null : { name }, fallback && fallback());
  5834. }
  5835. let slot = slots[name];
  5836. if ((process.env.NODE_ENV !== 'production') && slot && slot.length > 1) {
  5837. warn(`SSR-optimized slot function detected in a non-SSR-optimized render ` +
  5838. `function. You need to mark this component with $dynamic-slots in the ` +
  5839. `parent template.`);
  5840. slot = () => [];
  5841. }
  5842. // a compiled slot disables block tracking by default to avoid manual
  5843. // invocation interfering with template-based block tracking, but in
  5844. // `renderSlot` we can be sure that it's template-based so we can force
  5845. // enable it.
  5846. if (slot && slot._c) {
  5847. slot._d = false;
  5848. }
  5849. openBlock();
  5850. const validSlotContent = slot && ensureValidVNode(slot(props));
  5851. const rendered = createBlock(Fragment, { key: props.key || `_${name}` }, validSlotContent || (fallback ? fallback() : []), validSlotContent && slots._ === 1 /* STABLE */
  5852. ? 64 /* STABLE_FRAGMENT */
  5853. : -2 /* BAIL */);
  5854. if (!noSlotted && rendered.scopeId) {
  5855. rendered.slotScopeIds = [rendered.scopeId + '-s'];
  5856. }
  5857. if (slot && slot._c) {
  5858. slot._d = true;
  5859. }
  5860. return rendered;
  5861. }
  5862. function ensureValidVNode(vnodes) {
  5863. return vnodes.some(child => {
  5864. if (!isVNode(child))
  5865. return true;
  5866. if (child.type === Comment)
  5867. return false;
  5868. if (child.type === Fragment &&
  5869. !ensureValidVNode(child.children))
  5870. return false;
  5871. return true;
  5872. })
  5873. ? vnodes
  5874. : null;
  5875. }
  5876. /**
  5877. * For prefixing keys in v-on="obj" with "on"
  5878. * @private
  5879. */
  5880. function toHandlers(obj) {
  5881. const ret = {};
  5882. if ((process.env.NODE_ENV !== 'production') && !isObject(obj)) {
  5883. warn(`v-on with no argument expects an object value.`);
  5884. return ret;
  5885. }
  5886. for (const key in obj) {
  5887. ret[toHandlerKey(key)] = obj[key];
  5888. }
  5889. return ret;
  5890. }
  5891. /**
  5892. * #2437 In Vue 3, functional components do not have a public instance proxy but
  5893. * they exist in the internal parent chain. For code that relies on traversing
  5894. * public $parent chains, skip functional ones and go to the parent instead.
  5895. */
  5896. const getPublicInstance = (i) => {
  5897. if (!i)
  5898. return null;
  5899. if (isStatefulComponent(i))
  5900. return getExposeProxy(i) || i.proxy;
  5901. return getPublicInstance(i.parent);
  5902. };
  5903. const publicPropertiesMap = extend(Object.create(null), {
  5904. $: i => i,
  5905. $el: i => i.vnode.el,
  5906. $data: i => i.data,
  5907. $props: i => ((process.env.NODE_ENV !== 'production') ? shallowReadonly(i.props) : i.props),
  5908. $attrs: i => ((process.env.NODE_ENV !== 'production') ? shallowReadonly(i.attrs) : i.attrs),
  5909. $slots: i => ((process.env.NODE_ENV !== 'production') ? shallowReadonly(i.slots) : i.slots),
  5910. $refs: i => ((process.env.NODE_ENV !== 'production') ? shallowReadonly(i.refs) : i.refs),
  5911. $parent: i => getPublicInstance(i.parent),
  5912. $root: i => getPublicInstance(i.root),
  5913. $emit: i => i.emit,
  5914. $options: i => (__VUE_OPTIONS_API__ ? resolveMergedOptions(i) : i.type),
  5915. $forceUpdate: i => () => queueJob(i.update),
  5916. $nextTick: i => nextTick.bind(i.proxy),
  5917. $watch: i => (__VUE_OPTIONS_API__ ? instanceWatch.bind(i) : NOOP)
  5918. });
  5919. const PublicInstanceProxyHandlers = {
  5920. get({ _: instance }, key) {
  5921. const { ctx, setupState, data, props, accessCache, type, appContext } = instance;
  5922. // for internal formatters to know that this is a Vue instance
  5923. if ((process.env.NODE_ENV !== 'production') && key === '__isVue') {
  5924. return true;
  5925. }
  5926. // prioritize <script setup> bindings during dev.
  5927. // this allows even properties that start with _ or $ to be used - so that
  5928. // it aligns with the production behavior where the render fn is inlined and
  5929. // indeed has access to all declared variables.
  5930. if ((process.env.NODE_ENV !== 'production') &&
  5931. setupState !== EMPTY_OBJ &&
  5932. setupState.__isScriptSetup &&
  5933. hasOwn(setupState, key)) {
  5934. return setupState[key];
  5935. }
  5936. // data / props / ctx
  5937. // This getter gets called for every property access on the render context
  5938. // during render and is a major hotspot. The most expensive part of this
  5939. // is the multiple hasOwn() calls. It's much faster to do a simple property
  5940. // access on a plain object, so we use an accessCache object (with null
  5941. // prototype) to memoize what access type a key corresponds to.
  5942. let normalizedProps;
  5943. if (key[0] !== '$') {
  5944. const n = accessCache[key];
  5945. if (n !== undefined) {
  5946. switch (n) {
  5947. case 1 /* SETUP */:
  5948. return setupState[key];
  5949. case 2 /* DATA */:
  5950. return data[key];
  5951. case 4 /* CONTEXT */:
  5952. return ctx[key];
  5953. case 3 /* PROPS */:
  5954. return props[key];
  5955. // default: just fallthrough
  5956. }
  5957. }
  5958. else if (setupState !== EMPTY_OBJ && hasOwn(setupState, key)) {
  5959. accessCache[key] = 1 /* SETUP */;
  5960. return setupState[key];
  5961. }
  5962. else if (data !== EMPTY_OBJ && hasOwn(data, key)) {
  5963. accessCache[key] = 2 /* DATA */;
  5964. return data[key];
  5965. }
  5966. else if (
  5967. // only cache other properties when instance has declared (thus stable)
  5968. // props
  5969. (normalizedProps = instance.propsOptions[0]) &&
  5970. hasOwn(normalizedProps, key)) {
  5971. accessCache[key] = 3 /* PROPS */;
  5972. return props[key];
  5973. }
  5974. else if (ctx !== EMPTY_OBJ && hasOwn(ctx, key)) {
  5975. accessCache[key] = 4 /* CONTEXT */;
  5976. return ctx[key];
  5977. }
  5978. else if (!__VUE_OPTIONS_API__ || shouldCacheAccess) {
  5979. accessCache[key] = 0 /* OTHER */;
  5980. }
  5981. }
  5982. const publicGetter = publicPropertiesMap[key];
  5983. let cssModule, globalProperties;
  5984. // public $xxx properties
  5985. if (publicGetter) {
  5986. if (key === '$attrs') {
  5987. track(instance, "get" /* GET */, key);
  5988. (process.env.NODE_ENV !== 'production') && markAttrsAccessed();
  5989. }
  5990. return publicGetter(instance);
  5991. }
  5992. else if (
  5993. // css module (injected by vue-loader)
  5994. (cssModule = type.__cssModules) &&
  5995. (cssModule = cssModule[key])) {
  5996. return cssModule;
  5997. }
  5998. else if (ctx !== EMPTY_OBJ && hasOwn(ctx, key)) {
  5999. // user may set custom properties to `this` that start with `$`
  6000. accessCache[key] = 4 /* CONTEXT */;
  6001. return ctx[key];
  6002. }
  6003. else if (
  6004. // global properties
  6005. ((globalProperties = appContext.config.globalProperties),
  6006. hasOwn(globalProperties, key))) {
  6007. {
  6008. return globalProperties[key];
  6009. }
  6010. }
  6011. else if ((process.env.NODE_ENV !== 'production') &&
  6012. currentRenderingInstance &&
  6013. (!isString(key) ||
  6014. // #1091 avoid internal isRef/isVNode checks on component instance leading
  6015. // to infinite warning loop
  6016. key.indexOf('__v') !== 0)) {
  6017. if (data !== EMPTY_OBJ &&
  6018. (key[0] === '$' || key[0] === '_') &&
  6019. hasOwn(data, key)) {
  6020. warn(`Property ${JSON.stringify(key)} must be accessed via $data because it starts with a reserved ` +
  6021. `character ("$" or "_") and is not proxied on the render context.`);
  6022. }
  6023. else if (instance === currentRenderingInstance) {
  6024. warn(`Property ${JSON.stringify(key)} was accessed during render ` +
  6025. `but is not defined on instance.`);
  6026. }
  6027. }
  6028. },
  6029. set({ _: instance }, key, value) {
  6030. const { data, setupState, ctx } = instance;
  6031. if (setupState !== EMPTY_OBJ && hasOwn(setupState, key)) {
  6032. setupState[key] = value;
  6033. }
  6034. else if (data !== EMPTY_OBJ && hasOwn(data, key)) {
  6035. data[key] = value;
  6036. }
  6037. else if (hasOwn(instance.props, key)) {
  6038. (process.env.NODE_ENV !== 'production') &&
  6039. warn(`Attempting to mutate prop "${key}". Props are readonly.`, instance);
  6040. return false;
  6041. }
  6042. if (key[0] === '$' && key.slice(1) in instance) {
  6043. (process.env.NODE_ENV !== 'production') &&
  6044. warn(`Attempting to mutate public property "${key}". ` +
  6045. `Properties starting with $ are reserved and readonly.`, instance);
  6046. return false;
  6047. }
  6048. else {
  6049. if ((process.env.NODE_ENV !== 'production') && key in instance.appContext.config.globalProperties) {
  6050. Object.defineProperty(ctx, key, {
  6051. enumerable: true,
  6052. configurable: true,
  6053. value
  6054. });
  6055. }
  6056. else {
  6057. ctx[key] = value;
  6058. }
  6059. }
  6060. return true;
  6061. },
  6062. has({ _: { data, setupState, accessCache, ctx, appContext, propsOptions } }, key) {
  6063. let normalizedProps;
  6064. return (!!accessCache[key] ||
  6065. (data !== EMPTY_OBJ && hasOwn(data, key)) ||
  6066. (setupState !== EMPTY_OBJ && hasOwn(setupState, key)) ||
  6067. ((normalizedProps = propsOptions[0]) && hasOwn(normalizedProps, key)) ||
  6068. hasOwn(ctx, key) ||
  6069. hasOwn(publicPropertiesMap, key) ||
  6070. hasOwn(appContext.config.globalProperties, key));
  6071. }
  6072. };
  6073. if ((process.env.NODE_ENV !== 'production') && !false) {
  6074. PublicInstanceProxyHandlers.ownKeys = (target) => {
  6075. warn(`Avoid app logic that relies on enumerating keys on a component instance. ` +
  6076. `The keys will be empty in production mode to avoid performance overhead.`);
  6077. return Reflect.ownKeys(target);
  6078. };
  6079. }
  6080. const RuntimeCompiledPublicInstanceProxyHandlers = /*#__PURE__*/ extend({}, PublicInstanceProxyHandlers, {
  6081. get(target, key) {
  6082. // fast path for unscopables when using `with` block
  6083. if (key === Symbol.unscopables) {
  6084. return;
  6085. }
  6086. return PublicInstanceProxyHandlers.get(target, key, target);
  6087. },
  6088. has(_, key) {
  6089. const has = key[0] !== '_' && !isGloballyWhitelisted(key);
  6090. if ((process.env.NODE_ENV !== 'production') && !has && PublicInstanceProxyHandlers.has(_, key)) {
  6091. warn(`Property ${JSON.stringify(key)} should not start with _ which is a reserved prefix for Vue internals.`);
  6092. }
  6093. return has;
  6094. }
  6095. });
  6096. // dev only
  6097. // In dev mode, the proxy target exposes the same properties as seen on `this`
  6098. // for easier console inspection. In prod mode it will be an empty object so
  6099. // these properties definitions can be skipped.
  6100. function createDevRenderContext(instance) {
  6101. const target = {};
  6102. // expose internal instance for proxy handlers
  6103. Object.defineProperty(target, `_`, {
  6104. configurable: true,
  6105. enumerable: false,
  6106. get: () => instance
  6107. });
  6108. // expose public properties
  6109. Object.keys(publicPropertiesMap).forEach(key => {
  6110. Object.defineProperty(target, key, {
  6111. configurable: true,
  6112. enumerable: false,
  6113. get: () => publicPropertiesMap[key](instance),
  6114. // intercepted by the proxy so no need for implementation,
  6115. // but needed to prevent set errors
  6116. set: NOOP
  6117. });
  6118. });
  6119. return target;
  6120. }
  6121. // dev only
  6122. function exposePropsOnRenderContext(instance) {
  6123. const { ctx, propsOptions: [propsOptions] } = instance;
  6124. if (propsOptions) {
  6125. Object.keys(propsOptions).forEach(key => {
  6126. Object.defineProperty(ctx, key, {
  6127. enumerable: true,
  6128. configurable: true,
  6129. get: () => instance.props[key],
  6130. set: NOOP
  6131. });
  6132. });
  6133. }
  6134. }
  6135. // dev only
  6136. function exposeSetupStateOnRenderContext(instance) {
  6137. const { ctx, setupState } = instance;
  6138. Object.keys(toRaw(setupState)).forEach(key => {
  6139. if (!setupState.__isScriptSetup) {
  6140. if (key[0] === '$' || key[0] === '_') {
  6141. warn(`setup() return property ${JSON.stringify(key)} should not start with "$" or "_" ` +
  6142. `which are reserved prefixes for Vue internals.`);
  6143. return;
  6144. }
  6145. Object.defineProperty(ctx, key, {
  6146. enumerable: true,
  6147. configurable: true,
  6148. get: () => setupState[key],
  6149. set: NOOP
  6150. });
  6151. }
  6152. });
  6153. }
  6154. const emptyAppContext = createAppContext();
  6155. let uid$1 = 0;
  6156. function createComponentInstance(vnode, parent, suspense) {
  6157. const type = vnode.type;
  6158. // inherit parent app context - or - if root, adopt from root vnode
  6159. const appContext = (parent ? parent.appContext : vnode.appContext) || emptyAppContext;
  6160. const instance = {
  6161. uid: uid$1++,
  6162. vnode,
  6163. type,
  6164. parent,
  6165. appContext,
  6166. root: null,
  6167. next: null,
  6168. subTree: null,
  6169. effect: null,
  6170. update: null,
  6171. scope: new EffectScope(true /* detached */),
  6172. render: null,
  6173. proxy: null,
  6174. exposed: null,
  6175. exposeProxy: null,
  6176. withProxy: null,
  6177. provides: parent ? parent.provides : Object.create(appContext.provides),
  6178. accessCache: null,
  6179. renderCache: [],
  6180. // local resovled assets
  6181. components: null,
  6182. directives: null,
  6183. // resolved props and emits options
  6184. propsOptions: normalizePropsOptions(type, appContext),
  6185. emitsOptions: normalizeEmitsOptions(type, appContext),
  6186. // emit
  6187. emit: null,
  6188. emitted: null,
  6189. // props default value
  6190. propsDefaults: EMPTY_OBJ,
  6191. // inheritAttrs
  6192. inheritAttrs: type.inheritAttrs,
  6193. // state
  6194. ctx: EMPTY_OBJ,
  6195. data: EMPTY_OBJ,
  6196. props: EMPTY_OBJ,
  6197. attrs: EMPTY_OBJ,
  6198. slots: EMPTY_OBJ,
  6199. refs: EMPTY_OBJ,
  6200. setupState: EMPTY_OBJ,
  6201. setupContext: null,
  6202. // suspense related
  6203. suspense,
  6204. suspenseId: suspense ? suspense.pendingId : 0,
  6205. asyncDep: null,
  6206. asyncResolved: false,
  6207. // lifecycle hooks
  6208. // not using enums here because it results in computed properties
  6209. isMounted: false,
  6210. isUnmounted: false,
  6211. isDeactivated: false,
  6212. bc: null,
  6213. c: null,
  6214. bm: null,
  6215. m: null,
  6216. bu: null,
  6217. u: null,
  6218. um: null,
  6219. bum: null,
  6220. da: null,
  6221. a: null,
  6222. rtg: null,
  6223. rtc: null,
  6224. ec: null,
  6225. sp: null
  6226. };
  6227. if ((process.env.NODE_ENV !== 'production')) {
  6228. instance.ctx = createDevRenderContext(instance);
  6229. }
  6230. else {
  6231. instance.ctx = { _: instance };
  6232. }
  6233. instance.root = parent ? parent.root : instance;
  6234. instance.emit = emit$1.bind(null, instance);
  6235. // apply custom element special handling
  6236. if (vnode.ce) {
  6237. vnode.ce(instance);
  6238. }
  6239. return instance;
  6240. }
  6241. let currentInstance = null;
  6242. const getCurrentInstance = () => currentInstance || currentRenderingInstance;
  6243. const setCurrentInstance = (instance) => {
  6244. currentInstance = instance;
  6245. instance.scope.on();
  6246. };
  6247. const unsetCurrentInstance = () => {
  6248. currentInstance && currentInstance.scope.off();
  6249. currentInstance = null;
  6250. };
  6251. const isBuiltInTag = /*#__PURE__*/ makeMap('slot,component');
  6252. function validateComponentName(name, config) {
  6253. const appIsNativeTag = config.isNativeTag || NO;
  6254. if (isBuiltInTag(name) || appIsNativeTag(name)) {
  6255. warn('Do not use built-in or reserved HTML elements as component id: ' + name);
  6256. }
  6257. }
  6258. function isStatefulComponent(instance) {
  6259. return instance.vnode.shapeFlag & 4 /* STATEFUL_COMPONENT */;
  6260. }
  6261. let isInSSRComponentSetup = false;
  6262. function setupComponent(instance, isSSR = false) {
  6263. isInSSRComponentSetup = isSSR;
  6264. const { props, children } = instance.vnode;
  6265. const isStateful = isStatefulComponent(instance);
  6266. initProps(instance, props, isStateful, isSSR);
  6267. initSlots(instance, children);
  6268. const setupResult = isStateful
  6269. ? setupStatefulComponent(instance, isSSR)
  6270. : undefined;
  6271. isInSSRComponentSetup = false;
  6272. return setupResult;
  6273. }
  6274. function setupStatefulComponent(instance, isSSR) {
  6275. const Component = instance.type;
  6276. if ((process.env.NODE_ENV !== 'production')) {
  6277. if (Component.name) {
  6278. validateComponentName(Component.name, instance.appContext.config);
  6279. }
  6280. if (Component.components) {
  6281. const names = Object.keys(Component.components);
  6282. for (let i = 0; i < names.length; i++) {
  6283. validateComponentName(names[i], instance.appContext.config);
  6284. }
  6285. }
  6286. if (Component.directives) {
  6287. const names = Object.keys(Component.directives);
  6288. for (let i = 0; i < names.length; i++) {
  6289. validateDirectiveName(names[i]);
  6290. }
  6291. }
  6292. if (Component.compilerOptions && isRuntimeOnly()) {
  6293. warn(`"compilerOptions" is only supported when using a build of Vue that ` +
  6294. `includes the runtime compiler. Since you are using a runtime-only ` +
  6295. `build, the options should be passed via your build tool config instead.`);
  6296. }
  6297. }
  6298. // 0. create render proxy property access cache
  6299. instance.accessCache = Object.create(null);
  6300. // 1. create public instance / render proxy
  6301. // also mark it raw so it's never observed
  6302. instance.proxy = markRaw(new Proxy(instance.ctx, PublicInstanceProxyHandlers));
  6303. if ((process.env.NODE_ENV !== 'production')) {
  6304. exposePropsOnRenderContext(instance);
  6305. }
  6306. // 2. call setup()
  6307. const { setup } = Component;
  6308. if (setup) {
  6309. const setupContext = (instance.setupContext =
  6310. setup.length > 1 ? createSetupContext(instance) : null);
  6311. setCurrentInstance(instance);
  6312. pauseTracking();
  6313. const setupResult = callWithErrorHandling(setup, instance, 0 /* SETUP_FUNCTION */, [(process.env.NODE_ENV !== 'production') ? shallowReadonly(instance.props) : instance.props, setupContext]);
  6314. resetTracking();
  6315. unsetCurrentInstance();
  6316. if (isPromise(setupResult)) {
  6317. setupResult.then(unsetCurrentInstance, unsetCurrentInstance);
  6318. if (isSSR) {
  6319. // return the promise so server-renderer can wait on it
  6320. return setupResult
  6321. .then((resolvedResult) => {
  6322. handleSetupResult(instance, resolvedResult, isSSR);
  6323. })
  6324. .catch(e => {
  6325. handleError(e, instance, 0 /* SETUP_FUNCTION */);
  6326. });
  6327. }
  6328. else {
  6329. // async setup returned Promise.
  6330. // bail here and wait for re-entry.
  6331. instance.asyncDep = setupResult;
  6332. }
  6333. }
  6334. else {
  6335. handleSetupResult(instance, setupResult, isSSR);
  6336. }
  6337. }
  6338. else {
  6339. finishComponentSetup(instance, isSSR);
  6340. }
  6341. }
  6342. function handleSetupResult(instance, setupResult, isSSR) {
  6343. if (isFunction(setupResult)) {
  6344. // setup returned an inline render function
  6345. if (instance.type.__ssrInlineRender) {
  6346. // when the function's name is `ssrRender` (compiled by SFC inline mode),
  6347. // set it as ssrRender instead.
  6348. instance.ssrRender = setupResult;
  6349. }
  6350. else {
  6351. instance.render = setupResult;
  6352. }
  6353. }
  6354. else if (isObject(setupResult)) {
  6355. if ((process.env.NODE_ENV !== 'production') && isVNode(setupResult)) {
  6356. warn(`setup() should not return VNodes directly - ` +
  6357. `return a render function instead.`);
  6358. }
  6359. // setup returned bindings.
  6360. // assuming a render function compiled from template is present.
  6361. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  6362. instance.devtoolsRawSetupState = setupResult;
  6363. }
  6364. instance.setupState = proxyRefs(setupResult);
  6365. if ((process.env.NODE_ENV !== 'production')) {
  6366. exposeSetupStateOnRenderContext(instance);
  6367. }
  6368. }
  6369. else if ((process.env.NODE_ENV !== 'production') && setupResult !== undefined) {
  6370. warn(`setup() should return an object. Received: ${setupResult === null ? 'null' : typeof setupResult}`);
  6371. }
  6372. finishComponentSetup(instance, isSSR);
  6373. }
  6374. let compile;
  6375. let installWithProxy;
  6376. /**
  6377. * For runtime-dom to register the compiler.
  6378. * Note the exported method uses any to avoid d.ts relying on the compiler types.
  6379. */
  6380. function registerRuntimeCompiler(_compile) {
  6381. compile = _compile;
  6382. installWithProxy = i => {
  6383. if (i.render._rc) {
  6384. i.withProxy = new Proxy(i.ctx, RuntimeCompiledPublicInstanceProxyHandlers);
  6385. }
  6386. };
  6387. }
  6388. // dev only
  6389. const isRuntimeOnly = () => !compile;
  6390. function finishComponentSetup(instance, isSSR, skipOptions) {
  6391. const Component = instance.type;
  6392. // template / render function normalization
  6393. // could be already set when returned from setup()
  6394. if (!instance.render) {
  6395. // only do on-the-fly compile if not in SSR - SSR on-the-fly compliation
  6396. // is done by server-renderer
  6397. if (!isSSR && compile && !Component.render) {
  6398. const template = Component.template;
  6399. if (template) {
  6400. if ((process.env.NODE_ENV !== 'production')) {
  6401. startMeasure(instance, `compile`);
  6402. }
  6403. const { isCustomElement, compilerOptions } = instance.appContext.config;
  6404. const { delimiters, compilerOptions: componentCompilerOptions } = Component;
  6405. const finalCompilerOptions = extend(extend({
  6406. isCustomElement,
  6407. delimiters
  6408. }, compilerOptions), componentCompilerOptions);
  6409. Component.render = compile(template, finalCompilerOptions);
  6410. if ((process.env.NODE_ENV !== 'production')) {
  6411. endMeasure(instance, `compile`);
  6412. }
  6413. }
  6414. }
  6415. instance.render = (Component.render || NOOP);
  6416. // for runtime-compiled render functions using `with` blocks, the render
  6417. // proxy used needs a different `has` handler which is more performant and
  6418. // also only allows a whitelist of globals to fallthrough.
  6419. if (installWithProxy) {
  6420. installWithProxy(instance);
  6421. }
  6422. }
  6423. // support for 2.x options
  6424. if (__VUE_OPTIONS_API__ && !(false )) {
  6425. setCurrentInstance(instance);
  6426. pauseTracking();
  6427. applyOptions(instance);
  6428. resetTracking();
  6429. unsetCurrentInstance();
  6430. }
  6431. // warn missing template/render
  6432. // the runtime compilation of template in SSR is done by server-render
  6433. if ((process.env.NODE_ENV !== 'production') && !Component.render && instance.render === NOOP && !isSSR) {
  6434. /* istanbul ignore if */
  6435. if (!compile && Component.template) {
  6436. warn(`Component provided template option but ` +
  6437. `runtime compilation is not supported in this build of Vue.` +
  6438. (` Configure your bundler to alias "vue" to "vue/dist/vue.esm-bundler.js".`
  6439. ) /* should not happen */);
  6440. }
  6441. else {
  6442. warn(`Component is missing template or render function.`);
  6443. }
  6444. }
  6445. }
  6446. function createAttrsProxy(instance) {
  6447. return new Proxy(instance.attrs, (process.env.NODE_ENV !== 'production')
  6448. ? {
  6449. get(target, key) {
  6450. markAttrsAccessed();
  6451. track(instance, "get" /* GET */, '$attrs');
  6452. return target[key];
  6453. },
  6454. set() {
  6455. warn(`setupContext.attrs is readonly.`);
  6456. return false;
  6457. },
  6458. deleteProperty() {
  6459. warn(`setupContext.attrs is readonly.`);
  6460. return false;
  6461. }
  6462. }
  6463. : {
  6464. get(target, key) {
  6465. track(instance, "get" /* GET */, '$attrs');
  6466. return target[key];
  6467. }
  6468. });
  6469. }
  6470. function createSetupContext(instance) {
  6471. const expose = exposed => {
  6472. if ((process.env.NODE_ENV !== 'production') && instance.exposed) {
  6473. warn(`expose() should be called only once per setup().`);
  6474. }
  6475. instance.exposed = exposed || {};
  6476. };
  6477. let attrs;
  6478. if ((process.env.NODE_ENV !== 'production')) {
  6479. // We use getters in dev in case libs like test-utils overwrite instance
  6480. // properties (overwrites should not be done in prod)
  6481. return Object.freeze({
  6482. get attrs() {
  6483. return attrs || (attrs = createAttrsProxy(instance));
  6484. },
  6485. get slots() {
  6486. return shallowReadonly(instance.slots);
  6487. },
  6488. get emit() {
  6489. return (event, ...args) => instance.emit(event, ...args);
  6490. },
  6491. expose
  6492. });
  6493. }
  6494. else {
  6495. return {
  6496. get attrs() {
  6497. return attrs || (attrs = createAttrsProxy(instance));
  6498. },
  6499. slots: instance.slots,
  6500. emit: instance.emit,
  6501. expose
  6502. };
  6503. }
  6504. }
  6505. function getExposeProxy(instance) {
  6506. if (instance.exposed) {
  6507. return (instance.exposeProxy ||
  6508. (instance.exposeProxy = new Proxy(proxyRefs(markRaw(instance.exposed)), {
  6509. get(target, key) {
  6510. if (key in target) {
  6511. return target[key];
  6512. }
  6513. else if (key in publicPropertiesMap) {
  6514. return publicPropertiesMap[key](instance);
  6515. }
  6516. }
  6517. })));
  6518. }
  6519. }
  6520. const classifyRE = /(?:^|[-_])(\w)/g;
  6521. const classify = (str) => str.replace(classifyRE, c => c.toUpperCase()).replace(/[-_]/g, '');
  6522. function getComponentName(Component) {
  6523. return isFunction(Component)
  6524. ? Component.displayName || Component.name
  6525. : Component.name;
  6526. }
  6527. /* istanbul ignore next */
  6528. function formatComponentName(instance, Component, isRoot = false) {
  6529. let name = getComponentName(Component);
  6530. if (!name && Component.__file) {
  6531. const match = Component.__file.match(/([^/\\]+)\.\w+$/);
  6532. if (match) {
  6533. name = match[1];
  6534. }
  6535. }
  6536. if (!name && instance && instance.parent) {
  6537. // try to infer the name based on reverse resolution
  6538. const inferFromRegistry = (registry) => {
  6539. for (const key in registry) {
  6540. if (registry[key] === Component) {
  6541. return key;
  6542. }
  6543. }
  6544. };
  6545. name =
  6546. inferFromRegistry(instance.components ||
  6547. instance.parent.type.components) || inferFromRegistry(instance.appContext.components);
  6548. }
  6549. return name ? classify(name) : isRoot ? `App` : `Anonymous`;
  6550. }
  6551. function isClassComponent(value) {
  6552. return isFunction(value) && '__vccOpts' in value;
  6553. }
  6554. const stack = [];
  6555. function pushWarningContext(vnode) {
  6556. stack.push(vnode);
  6557. }
  6558. function popWarningContext() {
  6559. stack.pop();
  6560. }
  6561. function warn(msg, ...args) {
  6562. // avoid props formatting or warn handler tracking deps that might be mutated
  6563. // during patch, leading to infinite recursion.
  6564. pauseTracking();
  6565. const instance = stack.length ? stack[stack.length - 1].component : null;
  6566. const appWarnHandler = instance && instance.appContext.config.warnHandler;
  6567. const trace = getComponentTrace();
  6568. if (appWarnHandler) {
  6569. callWithErrorHandling(appWarnHandler, instance, 11 /* APP_WARN_HANDLER */, [
  6570. msg + args.join(''),
  6571. instance && instance.proxy,
  6572. trace
  6573. .map(({ vnode }) => `at <${formatComponentName(instance, vnode.type)}>`)
  6574. .join('\n'),
  6575. trace
  6576. ]);
  6577. }
  6578. else {
  6579. const warnArgs = [`[Vue warn]: ${msg}`, ...args];
  6580. /* istanbul ignore if */
  6581. if (trace.length &&
  6582. // avoid spamming console during tests
  6583. !false) {
  6584. warnArgs.push(`\n`, ...formatTrace(trace));
  6585. }
  6586. console.warn(...warnArgs);
  6587. }
  6588. resetTracking();
  6589. }
  6590. function getComponentTrace() {
  6591. let currentVNode = stack[stack.length - 1];
  6592. if (!currentVNode) {
  6593. return [];
  6594. }
  6595. // we can't just use the stack because it will be incomplete during updates
  6596. // that did not start from the root. Re-construct the parent chain using
  6597. // instance parent pointers.
  6598. const normalizedStack = [];
  6599. while (currentVNode) {
  6600. const last = normalizedStack[0];
  6601. if (last && last.vnode === currentVNode) {
  6602. last.recurseCount++;
  6603. }
  6604. else {
  6605. normalizedStack.push({
  6606. vnode: currentVNode,
  6607. recurseCount: 0
  6608. });
  6609. }
  6610. const parentInstance = currentVNode.component && currentVNode.component.parent;
  6611. currentVNode = parentInstance && parentInstance.vnode;
  6612. }
  6613. return normalizedStack;
  6614. }
  6615. /* istanbul ignore next */
  6616. function formatTrace(trace) {
  6617. const logs = [];
  6618. trace.forEach((entry, i) => {
  6619. logs.push(...(i === 0 ? [] : [`\n`]), ...formatTraceEntry(entry));
  6620. });
  6621. return logs;
  6622. }
  6623. function formatTraceEntry({ vnode, recurseCount }) {
  6624. const postfix = recurseCount > 0 ? `... (${recurseCount} recursive calls)` : ``;
  6625. const isRoot = vnode.component ? vnode.component.parent == null : false;
  6626. const open = ` at <${formatComponentName(vnode.component, vnode.type, isRoot)}`;
  6627. const close = `>` + postfix;
  6628. return vnode.props
  6629. ? [open, ...formatProps(vnode.props), close]
  6630. : [open + close];
  6631. }
  6632. /* istanbul ignore next */
  6633. function formatProps(props) {
  6634. const res = [];
  6635. const keys = Object.keys(props);
  6636. keys.slice(0, 3).forEach(key => {
  6637. res.push(...formatProp(key, props[key]));
  6638. });
  6639. if (keys.length > 3) {
  6640. res.push(` ...`);
  6641. }
  6642. return res;
  6643. }
  6644. /* istanbul ignore next */
  6645. function formatProp(key, value, raw) {
  6646. if (isString(value)) {
  6647. value = JSON.stringify(value);
  6648. return raw ? value : [`${key}=${value}`];
  6649. }
  6650. else if (typeof value === 'number' ||
  6651. typeof value === 'boolean' ||
  6652. value == null) {
  6653. return raw ? value : [`${key}=${value}`];
  6654. }
  6655. else if (isRef(value)) {
  6656. value = formatProp(key, toRaw(value.value), true);
  6657. return raw ? value : [`${key}=Ref<`, value, `>`];
  6658. }
  6659. else if (isFunction(value)) {
  6660. return [`${key}=fn${value.name ? `<${value.name}>` : ``}`];
  6661. }
  6662. else {
  6663. value = toRaw(value);
  6664. return raw ? value : [`${key}=`, value];
  6665. }
  6666. }
  6667. const ErrorTypeStrings = {
  6668. ["sp" /* SERVER_PREFETCH */]: 'serverPrefetch hook',
  6669. ["bc" /* BEFORE_CREATE */]: 'beforeCreate hook',
  6670. ["c" /* CREATED */]: 'created hook',
  6671. ["bm" /* BEFORE_MOUNT */]: 'beforeMount hook',
  6672. ["m" /* MOUNTED */]: 'mounted hook',
  6673. ["bu" /* BEFORE_UPDATE */]: 'beforeUpdate hook',
  6674. ["u" /* UPDATED */]: 'updated',
  6675. ["bum" /* BEFORE_UNMOUNT */]: 'beforeUnmount hook',
  6676. ["um" /* UNMOUNTED */]: 'unmounted hook',
  6677. ["a" /* ACTIVATED */]: 'activated hook',
  6678. ["da" /* DEACTIVATED */]: 'deactivated hook',
  6679. ["ec" /* ERROR_CAPTURED */]: 'errorCaptured hook',
  6680. ["rtc" /* RENDER_TRACKED */]: 'renderTracked hook',
  6681. ["rtg" /* RENDER_TRIGGERED */]: 'renderTriggered hook',
  6682. [0 /* SETUP_FUNCTION */]: 'setup function',
  6683. [1 /* RENDER_FUNCTION */]: 'render function',
  6684. [2 /* WATCH_GETTER */]: 'watcher getter',
  6685. [3 /* WATCH_CALLBACK */]: 'watcher callback',
  6686. [4 /* WATCH_CLEANUP */]: 'watcher cleanup function',
  6687. [5 /* NATIVE_EVENT_HANDLER */]: 'native event handler',
  6688. [6 /* COMPONENT_EVENT_HANDLER */]: 'component event handler',
  6689. [7 /* VNODE_HOOK */]: 'vnode hook',
  6690. [8 /* DIRECTIVE_HOOK */]: 'directive hook',
  6691. [9 /* TRANSITION_HOOK */]: 'transition hook',
  6692. [10 /* APP_ERROR_HANDLER */]: 'app errorHandler',
  6693. [11 /* APP_WARN_HANDLER */]: 'app warnHandler',
  6694. [12 /* FUNCTION_REF */]: 'ref function',
  6695. [13 /* ASYNC_COMPONENT_LOADER */]: 'async component loader',
  6696. [14 /* SCHEDULER */]: 'scheduler flush. This is likely a Vue internals bug. ' +
  6697. 'Please open an issue at https://new-issue.vuejs.org/?repo=vuejs/vue-next'
  6698. };
  6699. function callWithErrorHandling(fn, instance, type, args) {
  6700. let res;
  6701. try {
  6702. res = args ? fn(...args) : fn();
  6703. }
  6704. catch (err) {
  6705. handleError(err, instance, type);
  6706. }
  6707. return res;
  6708. }
  6709. function callWithAsyncErrorHandling(fn, instance, type, args) {
  6710. if (isFunction(fn)) {
  6711. const res = callWithErrorHandling(fn, instance, type, args);
  6712. if (res && isPromise(res)) {
  6713. res.catch(err => {
  6714. handleError(err, instance, type);
  6715. });
  6716. }
  6717. return res;
  6718. }
  6719. const values = [];
  6720. for (let i = 0; i < fn.length; i++) {
  6721. values.push(callWithAsyncErrorHandling(fn[i], instance, type, args));
  6722. }
  6723. return values;
  6724. }
  6725. function handleError(err, instance, type, throwInDev = true) {
  6726. const contextVNode = instance ? instance.vnode : null;
  6727. if (instance) {
  6728. let cur = instance.parent;
  6729. // the exposed instance is the render proxy to keep it consistent with 2.x
  6730. const exposedInstance = instance.proxy;
  6731. // in production the hook receives only the error code
  6732. const errorInfo = (process.env.NODE_ENV !== 'production') ? ErrorTypeStrings[type] : type;
  6733. while (cur) {
  6734. const errorCapturedHooks = cur.ec;
  6735. if (errorCapturedHooks) {
  6736. for (let i = 0; i < errorCapturedHooks.length; i++) {
  6737. if (errorCapturedHooks[i](err, exposedInstance, errorInfo) === false) {
  6738. return;
  6739. }
  6740. }
  6741. }
  6742. cur = cur.parent;
  6743. }
  6744. // app-level handling
  6745. const appErrorHandler = instance.appContext.config.errorHandler;
  6746. if (appErrorHandler) {
  6747. callWithErrorHandling(appErrorHandler, null, 10 /* APP_ERROR_HANDLER */, [err, exposedInstance, errorInfo]);
  6748. return;
  6749. }
  6750. }
  6751. logError(err, type, contextVNode, throwInDev);
  6752. }
  6753. function logError(err, type, contextVNode, throwInDev = true) {
  6754. if ((process.env.NODE_ENV !== 'production')) {
  6755. const info = ErrorTypeStrings[type];
  6756. if (contextVNode) {
  6757. pushWarningContext(contextVNode);
  6758. }
  6759. warn(`Unhandled error${info ? ` during execution of ${info}` : ``}`);
  6760. if (contextVNode) {
  6761. popWarningContext();
  6762. }
  6763. // crash in dev by default so it's more noticeable
  6764. if (throwInDev) {
  6765. throw err;
  6766. }
  6767. else {
  6768. console.error(err);
  6769. }
  6770. }
  6771. else {
  6772. // recover in prod to reduce the impact on end-user
  6773. console.error(err);
  6774. }
  6775. }
  6776. let isFlushing = false;
  6777. let isFlushPending = false;
  6778. const queue = [];
  6779. let flushIndex = 0;
  6780. const pendingPreFlushCbs = [];
  6781. let activePreFlushCbs = null;
  6782. let preFlushIndex = 0;
  6783. const pendingPostFlushCbs = [];
  6784. let activePostFlushCbs = null;
  6785. let postFlushIndex = 0;
  6786. const resolvedPromise = Promise.resolve();
  6787. let currentFlushPromise = null;
  6788. let currentPreFlushParentJob = null;
  6789. const RECURSION_LIMIT = 100;
  6790. function nextTick(fn) {
  6791. const p = currentFlushPromise || resolvedPromise;
  6792. return fn ? p.then(this ? fn.bind(this) : fn) : p;
  6793. }
  6794. // #2768
  6795. // Use binary-search to find a suitable position in the queue,
  6796. // so that the queue maintains the increasing order of job's id,
  6797. // which can prevent the job from being skipped and also can avoid repeated patching.
  6798. function findInsertionIndex(id) {
  6799. // the start index should be `flushIndex + 1`
  6800. let start = flushIndex + 1;
  6801. let end = queue.length;
  6802. while (start < end) {
  6803. const middle = (start + end) >>> 1;
  6804. const middleJobId = getId(queue[middle]);
  6805. middleJobId < id ? (start = middle + 1) : (end = middle);
  6806. }
  6807. return start;
  6808. }
  6809. function queueJob(job) {
  6810. // the dedupe search uses the startIndex argument of Array.includes()
  6811. // by default the search index includes the current job that is being run
  6812. // so it cannot recursively trigger itself again.
  6813. // if the job is a watch() callback, the search will start with a +1 index to
  6814. // allow it recursively trigger itself - it is the user's responsibility to
  6815. // ensure it doesn't end up in an infinite loop.
  6816. if ((!queue.length ||
  6817. !queue.includes(job, isFlushing && job.allowRecurse ? flushIndex + 1 : flushIndex)) &&
  6818. job !== currentPreFlushParentJob) {
  6819. if (job.id == null) {
  6820. queue.push(job);
  6821. }
  6822. else {
  6823. queue.splice(findInsertionIndex(job.id), 0, job);
  6824. }
  6825. queueFlush();
  6826. }
  6827. }
  6828. function queueFlush() {
  6829. if (!isFlushing && !isFlushPending) {
  6830. isFlushPending = true;
  6831. currentFlushPromise = resolvedPromise.then(flushJobs);
  6832. }
  6833. }
  6834. function invalidateJob(job) {
  6835. const i = queue.indexOf(job);
  6836. if (i > flushIndex) {
  6837. queue.splice(i, 1);
  6838. }
  6839. }
  6840. function queueCb(cb, activeQueue, pendingQueue, index) {
  6841. if (!isArray(cb)) {
  6842. if (!activeQueue ||
  6843. !activeQueue.includes(cb, cb.allowRecurse ? index + 1 : index)) {
  6844. pendingQueue.push(cb);
  6845. }
  6846. }
  6847. else {
  6848. // if cb is an array, it is a component lifecycle hook which can only be
  6849. // triggered by a job, which is already deduped in the main queue, so
  6850. // we can skip duplicate check here to improve perf
  6851. pendingQueue.push(...cb);
  6852. }
  6853. queueFlush();
  6854. }
  6855. function queuePreFlushCb(cb) {
  6856. queueCb(cb, activePreFlushCbs, pendingPreFlushCbs, preFlushIndex);
  6857. }
  6858. function queuePostFlushCb(cb) {
  6859. queueCb(cb, activePostFlushCbs, pendingPostFlushCbs, postFlushIndex);
  6860. }
  6861. function flushPreFlushCbs(seen, parentJob = null) {
  6862. if (pendingPreFlushCbs.length) {
  6863. currentPreFlushParentJob = parentJob;
  6864. activePreFlushCbs = [...new Set(pendingPreFlushCbs)];
  6865. pendingPreFlushCbs.length = 0;
  6866. if ((process.env.NODE_ENV !== 'production')) {
  6867. seen = seen || new Map();
  6868. }
  6869. for (preFlushIndex = 0; preFlushIndex < activePreFlushCbs.length; preFlushIndex++) {
  6870. if ((process.env.NODE_ENV !== 'production') &&
  6871. checkRecursiveUpdates(seen, activePreFlushCbs[preFlushIndex])) {
  6872. continue;
  6873. }
  6874. activePreFlushCbs[preFlushIndex]();
  6875. }
  6876. activePreFlushCbs = null;
  6877. preFlushIndex = 0;
  6878. currentPreFlushParentJob = null;
  6879. // recursively flush until it drains
  6880. flushPreFlushCbs(seen, parentJob);
  6881. }
  6882. }
  6883. function flushPostFlushCbs(seen) {
  6884. if (pendingPostFlushCbs.length) {
  6885. const deduped = [...new Set(pendingPostFlushCbs)];
  6886. pendingPostFlushCbs.length = 0;
  6887. // #1947 already has active queue, nested flushPostFlushCbs call
  6888. if (activePostFlushCbs) {
  6889. activePostFlushCbs.push(...deduped);
  6890. return;
  6891. }
  6892. activePostFlushCbs = deduped;
  6893. if ((process.env.NODE_ENV !== 'production')) {
  6894. seen = seen || new Map();
  6895. }
  6896. activePostFlushCbs.sort((a, b) => getId(a) - getId(b));
  6897. for (postFlushIndex = 0; postFlushIndex < activePostFlushCbs.length; postFlushIndex++) {
  6898. if ((process.env.NODE_ENV !== 'production') &&
  6899. checkRecursiveUpdates(seen, activePostFlushCbs[postFlushIndex])) {
  6900. continue;
  6901. }
  6902. activePostFlushCbs[postFlushIndex]();
  6903. }
  6904. activePostFlushCbs = null;
  6905. postFlushIndex = 0;
  6906. }
  6907. }
  6908. const getId = (job) => job.id == null ? Infinity : job.id;
  6909. function flushJobs(seen) {
  6910. isFlushPending = false;
  6911. isFlushing = true;
  6912. if ((process.env.NODE_ENV !== 'production')) {
  6913. seen = seen || new Map();
  6914. }
  6915. flushPreFlushCbs(seen);
  6916. // Sort queue before flush.
  6917. // This ensures that:
  6918. // 1. Components are updated from parent to child. (because parent is always
  6919. // created before the child so its render effect will have smaller
  6920. // priority number)
  6921. // 2. If a component is unmounted during a parent component's update,
  6922. // its update can be skipped.
  6923. queue.sort((a, b) => getId(a) - getId(b));
  6924. // conditional usage of checkRecursiveUpdate must be determined out of
  6925. // try ... catch block since Rollup by default de-optimizes treeshaking
  6926. // inside try-catch. This can leave all warning code unshaked. Although
  6927. // they would get eventually shaken by a minifier like terser, some minifiers
  6928. // would fail to do that (e.g. https://github.com/evanw/esbuild/issues/1610)
  6929. const check = (process.env.NODE_ENV !== 'production')
  6930. ? (job) => checkRecursiveUpdates(seen, job)
  6931. : NOOP;
  6932. try {
  6933. for (flushIndex = 0; flushIndex < queue.length; flushIndex++) {
  6934. const job = queue[flushIndex];
  6935. if (job && job.active !== false) {
  6936. if ((process.env.NODE_ENV !== 'production') && check(job)) {
  6937. continue;
  6938. }
  6939. // console.log(`running:`, job.id)
  6940. callWithErrorHandling(job, null, 14 /* SCHEDULER */);
  6941. }
  6942. }
  6943. }
  6944. finally {
  6945. flushIndex = 0;
  6946. queue.length = 0;
  6947. flushPostFlushCbs(seen);
  6948. isFlushing = false;
  6949. currentFlushPromise = null;
  6950. // some postFlushCb queued jobs!
  6951. // keep flushing until it drains.
  6952. if (queue.length ||
  6953. pendingPreFlushCbs.length ||
  6954. pendingPostFlushCbs.length) {
  6955. flushJobs(seen);
  6956. }
  6957. }
  6958. }
  6959. function checkRecursiveUpdates(seen, fn) {
  6960. if (!seen.has(fn)) {
  6961. seen.set(fn, 1);
  6962. }
  6963. else {
  6964. const count = seen.get(fn);
  6965. if (count > RECURSION_LIMIT) {
  6966. const instance = fn.ownerInstance;
  6967. const componentName = instance && getComponentName(instance.type);
  6968. warn(`Maximum recursive updates exceeded${componentName ? ` in component <${componentName}>` : ``}. ` +
  6969. `This means you have a reactive effect that is mutating its own ` +
  6970. `dependencies and thus recursively triggering itself. Possible sources ` +
  6971. `include component template, render function, updated hook or ` +
  6972. `watcher source function.`);
  6973. return true;
  6974. }
  6975. else {
  6976. seen.set(fn, count + 1);
  6977. }
  6978. }
  6979. }
  6980. // Simple effect.
  6981. function watchEffect(effect, options) {
  6982. return doWatch(effect, null, options);
  6983. }
  6984. function watchPostEffect(effect, options) {
  6985. return doWatch(effect, null, ((process.env.NODE_ENV !== 'production')
  6986. ? Object.assign(options || {}, { flush: 'post' })
  6987. : { flush: 'post' }));
  6988. }
  6989. function watchSyncEffect(effect, options) {
  6990. return doWatch(effect, null, ((process.env.NODE_ENV !== 'production')
  6991. ? Object.assign(options || {}, { flush: 'sync' })
  6992. : { flush: 'sync' }));
  6993. }
  6994. // initial value for watchers to trigger on undefined initial values
  6995. const INITIAL_WATCHER_VALUE = {};
  6996. // implementation
  6997. function watch(source, cb, options) {
  6998. if ((process.env.NODE_ENV !== 'production') && !isFunction(cb)) {
  6999. warn(`\`watch(fn, options?)\` signature has been moved to a separate API. ` +
  7000. `Use \`watchEffect(fn, options?)\` instead. \`watch\` now only ` +
  7001. `supports \`watch(source, cb, options?) signature.`);
  7002. }
  7003. return doWatch(source, cb, options);
  7004. }
  7005. function doWatch(source, cb, { immediate, deep, flush, onTrack, onTrigger } = EMPTY_OBJ) {
  7006. if ((process.env.NODE_ENV !== 'production') && !cb) {
  7007. if (immediate !== undefined) {
  7008. warn(`watch() "immediate" option is only respected when using the ` +
  7009. `watch(source, callback, options?) signature.`);
  7010. }
  7011. if (deep !== undefined) {
  7012. warn(`watch() "deep" option is only respected when using the ` +
  7013. `watch(source, callback, options?) signature.`);
  7014. }
  7015. }
  7016. const warnInvalidSource = (s) => {
  7017. warn(`Invalid watch source: `, s, `A watch source can only be a getter/effect function, a ref, ` +
  7018. `a reactive object, or an array of these types.`);
  7019. };
  7020. const instance = currentInstance;
  7021. let getter;
  7022. let forceTrigger = false;
  7023. let isMultiSource = false;
  7024. if (isRef(source)) {
  7025. getter = () => source.value;
  7026. forceTrigger = !!source._shallow;
  7027. }
  7028. else if (isReactive(source)) {
  7029. getter = () => source;
  7030. deep = true;
  7031. }
  7032. else if (isArray(source)) {
  7033. isMultiSource = true;
  7034. forceTrigger = source.some(isReactive);
  7035. getter = () => source.map(s => {
  7036. if (isRef(s)) {
  7037. return s.value;
  7038. }
  7039. else if (isReactive(s)) {
  7040. return traverse(s);
  7041. }
  7042. else if (isFunction(s)) {
  7043. return callWithErrorHandling(s, instance, 2 /* WATCH_GETTER */);
  7044. }
  7045. else {
  7046. (process.env.NODE_ENV !== 'production') && warnInvalidSource(s);
  7047. }
  7048. });
  7049. }
  7050. else if (isFunction(source)) {
  7051. if (cb) {
  7052. // getter with cb
  7053. getter = () => callWithErrorHandling(source, instance, 2 /* WATCH_GETTER */);
  7054. }
  7055. else {
  7056. // no cb -> simple effect
  7057. getter = () => {
  7058. if (instance && instance.isUnmounted) {
  7059. return;
  7060. }
  7061. if (cleanup) {
  7062. cleanup();
  7063. }
  7064. return callWithAsyncErrorHandling(source, instance, 3 /* WATCH_CALLBACK */, [onInvalidate]);
  7065. };
  7066. }
  7067. }
  7068. else {
  7069. getter = NOOP;
  7070. (process.env.NODE_ENV !== 'production') && warnInvalidSource(source);
  7071. }
  7072. if (cb && deep) {
  7073. const baseGetter = getter;
  7074. getter = () => traverse(baseGetter());
  7075. }
  7076. let cleanup;
  7077. let onInvalidate = (fn) => {
  7078. cleanup = effect.onStop = () => {
  7079. callWithErrorHandling(fn, instance, 4 /* WATCH_CLEANUP */);
  7080. };
  7081. };
  7082. // in SSR there is no need to setup an actual effect, and it should be noop
  7083. // unless it's eager
  7084. if (isInSSRComponentSetup) {
  7085. // we will also not call the invalidate callback (+ runner is not set up)
  7086. onInvalidate = NOOP;
  7087. if (!cb) {
  7088. getter();
  7089. }
  7090. else if (immediate) {
  7091. callWithAsyncErrorHandling(cb, instance, 3 /* WATCH_CALLBACK */, [
  7092. getter(),
  7093. isMultiSource ? [] : undefined,
  7094. onInvalidate
  7095. ]);
  7096. }
  7097. return NOOP;
  7098. }
  7099. let oldValue = isMultiSource ? [] : INITIAL_WATCHER_VALUE;
  7100. const job = () => {
  7101. if (!effect.active) {
  7102. return;
  7103. }
  7104. if (cb) {
  7105. // watch(source, cb)
  7106. const newValue = effect.run();
  7107. if (deep ||
  7108. forceTrigger ||
  7109. (isMultiSource
  7110. ? newValue.some((v, i) => hasChanged(v, oldValue[i]))
  7111. : hasChanged(newValue, oldValue)) ||
  7112. (false )) {
  7113. // cleanup before running cb again
  7114. if (cleanup) {
  7115. cleanup();
  7116. }
  7117. callWithAsyncErrorHandling(cb, instance, 3 /* WATCH_CALLBACK */, [
  7118. newValue,
  7119. // pass undefined as the old value when it's changed for the first time
  7120. oldValue === INITIAL_WATCHER_VALUE ? undefined : oldValue,
  7121. onInvalidate
  7122. ]);
  7123. oldValue = newValue;
  7124. }
  7125. }
  7126. else {
  7127. // watchEffect
  7128. effect.run();
  7129. }
  7130. };
  7131. // important: mark the job as a watcher callback so that scheduler knows
  7132. // it is allowed to self-trigger (#1727)
  7133. job.allowRecurse = !!cb;
  7134. let scheduler;
  7135. if (flush === 'sync') {
  7136. scheduler = job; // the scheduler function gets called directly
  7137. }
  7138. else if (flush === 'post') {
  7139. scheduler = () => queuePostRenderEffect(job, instance && instance.suspense);
  7140. }
  7141. else {
  7142. // default: 'pre'
  7143. scheduler = () => {
  7144. if (!instance || instance.isMounted) {
  7145. queuePreFlushCb(job);
  7146. }
  7147. else {
  7148. // with 'pre' option, the first call must happen before
  7149. // the component is mounted so it is called synchronously.
  7150. job();
  7151. }
  7152. };
  7153. }
  7154. const effect = new ReactiveEffect(getter, scheduler);
  7155. if ((process.env.NODE_ENV !== 'production')) {
  7156. effect.onTrack = onTrack;
  7157. effect.onTrigger = onTrigger;
  7158. }
  7159. // initial run
  7160. if (cb) {
  7161. if (immediate) {
  7162. job();
  7163. }
  7164. else {
  7165. oldValue = effect.run();
  7166. }
  7167. }
  7168. else if (flush === 'post') {
  7169. queuePostRenderEffect(effect.run.bind(effect), instance && instance.suspense);
  7170. }
  7171. else {
  7172. effect.run();
  7173. }
  7174. return () => {
  7175. effect.stop();
  7176. if (instance && instance.scope) {
  7177. remove(instance.scope.effects, effect);
  7178. }
  7179. };
  7180. }
  7181. // this.$watch
  7182. function instanceWatch(source, value, options) {
  7183. const publicThis = this.proxy;
  7184. const getter = isString(source)
  7185. ? source.includes('.')
  7186. ? createPathGetter(publicThis, source)
  7187. : () => publicThis[source]
  7188. : source.bind(publicThis, publicThis);
  7189. let cb;
  7190. if (isFunction(value)) {
  7191. cb = value;
  7192. }
  7193. else {
  7194. cb = value.handler;
  7195. options = value;
  7196. }
  7197. const cur = currentInstance;
  7198. setCurrentInstance(this);
  7199. const res = doWatch(getter, cb.bind(publicThis), options);
  7200. if (cur) {
  7201. setCurrentInstance(cur);
  7202. }
  7203. else {
  7204. unsetCurrentInstance();
  7205. }
  7206. return res;
  7207. }
  7208. function createPathGetter(ctx, path) {
  7209. const segments = path.split('.');
  7210. return () => {
  7211. let cur = ctx;
  7212. for (let i = 0; i < segments.length && cur; i++) {
  7213. cur = cur[segments[i]];
  7214. }
  7215. return cur;
  7216. };
  7217. }
  7218. function traverse(value, seen) {
  7219. if (!isObject(value) || value["__v_skip" /* SKIP */]) {
  7220. return value;
  7221. }
  7222. seen = seen || new Set();
  7223. if (seen.has(value)) {
  7224. return value;
  7225. }
  7226. seen.add(value);
  7227. if (isRef(value)) {
  7228. traverse(value.value, seen);
  7229. }
  7230. else if (isArray(value)) {
  7231. for (let i = 0; i < value.length; i++) {
  7232. traverse(value[i], seen);
  7233. }
  7234. }
  7235. else if (isSet(value) || isMap(value)) {
  7236. value.forEach((v) => {
  7237. traverse(v, seen);
  7238. });
  7239. }
  7240. else if (isPlainObject(value)) {
  7241. for (const key in value) {
  7242. traverse(value[key], seen);
  7243. }
  7244. }
  7245. return value;
  7246. }
  7247. // dev only
  7248. const warnRuntimeUsage = (method) => warn(`${method}() is a compiler-hint helper that is only usable inside ` +
  7249. `<script setup> of a single file component. Its arguments should be ` +
  7250. `compiled away and passing it at runtime has no effect.`);
  7251. // implementation
  7252. function defineProps() {
  7253. if ((process.env.NODE_ENV !== 'production')) {
  7254. warnRuntimeUsage(`defineProps`);
  7255. }
  7256. return null;
  7257. }
  7258. // implementation
  7259. function defineEmits() {
  7260. if ((process.env.NODE_ENV !== 'production')) {
  7261. warnRuntimeUsage(`defineEmits`);
  7262. }
  7263. return null;
  7264. }
  7265. /**
  7266. * Vue `<script setup>` compiler macro for declaring a component's exposed
  7267. * instance properties when it is accessed by a parent component via template
  7268. * refs.
  7269. *
  7270. * `<script setup>` components are closed by default - i.e. varaibles inside
  7271. * the `<script setup>` scope is not exposed to parent unless explicitly exposed
  7272. * via `defineExpose`.
  7273. *
  7274. * This is only usable inside `<script setup>`, is compiled away in the
  7275. * output and should **not** be actually called at runtime.
  7276. */
  7277. function defineExpose(exposed) {
  7278. if ((process.env.NODE_ENV !== 'production')) {
  7279. warnRuntimeUsage(`defineExpose`);
  7280. }
  7281. }
  7282. /**
  7283. * Vue `<script setup>` compiler macro for providing props default values when
  7284. * using type-based `defineProps` declaration.
  7285. *
  7286. * Example usage:
  7287. * ```ts
  7288. * withDefaults(defineProps<{
  7289. * size?: number
  7290. * labels?: string[]
  7291. * }>(), {
  7292. * size: 3,
  7293. * labels: () => ['default label']
  7294. * })
  7295. * ```
  7296. *
  7297. * This is only usable inside `<script setup>`, is compiled away in the output
  7298. * and should **not** be actually called at runtime.
  7299. */
  7300. function withDefaults(props, defaults) {
  7301. if ((process.env.NODE_ENV !== 'production')) {
  7302. warnRuntimeUsage(`withDefaults`);
  7303. }
  7304. return null;
  7305. }
  7306. function useSlots() {
  7307. return getContext().slots;
  7308. }
  7309. function useAttrs() {
  7310. return getContext().attrs;
  7311. }
  7312. function getContext() {
  7313. const i = getCurrentInstance();
  7314. if ((process.env.NODE_ENV !== 'production') && !i) {
  7315. warn(`useContext() called without active instance.`);
  7316. }
  7317. return i.setupContext || (i.setupContext = createSetupContext(i));
  7318. }
  7319. /**
  7320. * Runtime helper for merging default declarations. Imported by compiled code
  7321. * only.
  7322. * @internal
  7323. */
  7324. function mergeDefaults(raw, defaults) {
  7325. const props = isArray(raw)
  7326. ? raw.reduce((normalized, p) => ((normalized[p] = {}), normalized), {})
  7327. : raw;
  7328. for (const key in defaults) {
  7329. const opt = props[key];
  7330. if (opt) {
  7331. if (isArray(opt) || isFunction(opt)) {
  7332. props[key] = { type: opt, default: defaults[key] };
  7333. }
  7334. else {
  7335. opt.default = defaults[key];
  7336. }
  7337. }
  7338. else if (opt === null) {
  7339. props[key] = { default: defaults[key] };
  7340. }
  7341. else if ((process.env.NODE_ENV !== 'production')) {
  7342. warn(`props default key "${key}" has no corresponding declaration.`);
  7343. }
  7344. }
  7345. return props;
  7346. }
  7347. /**
  7348. * Used to create a proxy for the rest element when destructuring props with
  7349. * defineProps().
  7350. * @internal
  7351. */
  7352. function createPropsRestProxy(props, excludedKeys) {
  7353. const ret = {};
  7354. for (const key in props) {
  7355. if (!excludedKeys.includes(key)) {
  7356. Object.defineProperty(ret, key, {
  7357. enumerable: true,
  7358. get: () => props[key]
  7359. });
  7360. }
  7361. }
  7362. return ret;
  7363. }
  7364. /**
  7365. * `<script setup>` helper for persisting the current instance context over
  7366. * async/await flows.
  7367. *
  7368. * `@vue/compiler-sfc` converts the following:
  7369. *
  7370. * ```ts
  7371. * const x = await foo()
  7372. * ```
  7373. *
  7374. * into:
  7375. *
  7376. * ```ts
  7377. * let __temp, __restore
  7378. * const x = (([__temp, __restore] = withAsyncContext(() => foo())),__temp=await __temp,__restore(),__temp)
  7379. * ```
  7380. * @internal
  7381. */
  7382. function withAsyncContext(getAwaitable) {
  7383. const ctx = getCurrentInstance();
  7384. if ((process.env.NODE_ENV !== 'production') && !ctx) {
  7385. warn(`withAsyncContext called without active current instance. ` +
  7386. `This is likely a bug.`);
  7387. }
  7388. let awaitable = getAwaitable();
  7389. unsetCurrentInstance();
  7390. if (isPromise(awaitable)) {
  7391. awaitable = awaitable.catch(e => {
  7392. setCurrentInstance(ctx);
  7393. throw e;
  7394. });
  7395. }
  7396. return [awaitable, () => setCurrentInstance(ctx)];
  7397. }
  7398. // Actual implementation
  7399. function h(type, propsOrChildren, children) {
  7400. const l = arguments.length;
  7401. if (l === 2) {
  7402. if (isObject(propsOrChildren) && !isArray(propsOrChildren)) {
  7403. // single vnode without props
  7404. if (isVNode(propsOrChildren)) {
  7405. return createVNode(type, null, [propsOrChildren]);
  7406. }
  7407. // props without children
  7408. return createVNode(type, propsOrChildren);
  7409. }
  7410. else {
  7411. // omit props
  7412. return createVNode(type, null, propsOrChildren);
  7413. }
  7414. }
  7415. else {
  7416. if (l > 3) {
  7417. children = Array.prototype.slice.call(arguments, 2);
  7418. }
  7419. else if (l === 3 && isVNode(children)) {
  7420. children = [children];
  7421. }
  7422. return createVNode(type, propsOrChildren, children);
  7423. }
  7424. }
  7425. const ssrContextKey = Symbol((process.env.NODE_ENV !== 'production') ? `ssrContext` : ``);
  7426. const useSSRContext = () => {
  7427. {
  7428. const ctx = inject(ssrContextKey);
  7429. if (!ctx) {
  7430. warn(`Server rendering context not provided. Make sure to only call ` +
  7431. `useSSRContext() conditionally in the server build.`);
  7432. }
  7433. return ctx;
  7434. }
  7435. };
  7436. function initCustomFormatter() {
  7437. /* eslint-disable no-restricted-globals */
  7438. if (!(process.env.NODE_ENV !== 'production') || typeof window === 'undefined') {
  7439. return;
  7440. }
  7441. const vueStyle = { style: 'color:#3ba776' };
  7442. const numberStyle = { style: 'color:#0b1bc9' };
  7443. const stringStyle = { style: 'color:#b62e24' };
  7444. const keywordStyle = { style: 'color:#9d288c' };
  7445. // custom formatter for Chrome
  7446. // https://www.mattzeunert.com/2016/02/19/custom-chrome-devtools-object-formatters.html
  7447. const formatter = {
  7448. header(obj) {
  7449. // TODO also format ComponentPublicInstance & ctx.slots/attrs in setup
  7450. if (!isObject(obj)) {
  7451. return null;
  7452. }
  7453. if (obj.__isVue) {
  7454. return ['div', vueStyle, `VueInstance`];
  7455. }
  7456. else if (isRef(obj)) {
  7457. return [
  7458. 'div',
  7459. {},
  7460. ['span', vueStyle, genRefFlag(obj)],
  7461. '<',
  7462. formatValue(obj.value),
  7463. `>`
  7464. ];
  7465. }
  7466. else if (isReactive(obj)) {
  7467. return [
  7468. 'div',
  7469. {},
  7470. ['span', vueStyle, 'Reactive'],
  7471. '<',
  7472. formatValue(obj),
  7473. `>${isReadonly(obj) ? ` (readonly)` : ``}`
  7474. ];
  7475. }
  7476. else if (isReadonly(obj)) {
  7477. return [
  7478. 'div',
  7479. {},
  7480. ['span', vueStyle, 'Readonly'],
  7481. '<',
  7482. formatValue(obj),
  7483. '>'
  7484. ];
  7485. }
  7486. return null;
  7487. },
  7488. hasBody(obj) {
  7489. return obj && obj.__isVue;
  7490. },
  7491. body(obj) {
  7492. if (obj && obj.__isVue) {
  7493. return [
  7494. 'div',
  7495. {},
  7496. ...formatInstance(obj.$)
  7497. ];
  7498. }
  7499. }
  7500. };
  7501. function formatInstance(instance) {
  7502. const blocks = [];
  7503. if (instance.type.props && instance.props) {
  7504. blocks.push(createInstanceBlock('props', toRaw(instance.props)));
  7505. }
  7506. if (instance.setupState !== EMPTY_OBJ) {
  7507. blocks.push(createInstanceBlock('setup', instance.setupState));
  7508. }
  7509. if (instance.data !== EMPTY_OBJ) {
  7510. blocks.push(createInstanceBlock('data', toRaw(instance.data)));
  7511. }
  7512. const computed = extractKeys(instance, 'computed');
  7513. if (computed) {
  7514. blocks.push(createInstanceBlock('computed', computed));
  7515. }
  7516. const injected = extractKeys(instance, 'inject');
  7517. if (injected) {
  7518. blocks.push(createInstanceBlock('injected', injected));
  7519. }
  7520. blocks.push([
  7521. 'div',
  7522. {},
  7523. [
  7524. 'span',
  7525. {
  7526. style: keywordStyle.style + ';opacity:0.66'
  7527. },
  7528. '$ (internal): '
  7529. ],
  7530. ['object', { object: instance }]
  7531. ]);
  7532. return blocks;
  7533. }
  7534. function createInstanceBlock(type, target) {
  7535. target = extend({}, target);
  7536. if (!Object.keys(target).length) {
  7537. return ['span', {}];
  7538. }
  7539. return [
  7540. 'div',
  7541. { style: 'line-height:1.25em;margin-bottom:0.6em' },
  7542. [
  7543. 'div',
  7544. {
  7545. style: 'color:#476582'
  7546. },
  7547. type
  7548. ],
  7549. [
  7550. 'div',
  7551. {
  7552. style: 'padding-left:1.25em'
  7553. },
  7554. ...Object.keys(target).map(key => {
  7555. return [
  7556. 'div',
  7557. {},
  7558. ['span', keywordStyle, key + ': '],
  7559. formatValue(target[key], false)
  7560. ];
  7561. })
  7562. ]
  7563. ];
  7564. }
  7565. function formatValue(v, asRaw = true) {
  7566. if (typeof v === 'number') {
  7567. return ['span', numberStyle, v];
  7568. }
  7569. else if (typeof v === 'string') {
  7570. return ['span', stringStyle, JSON.stringify(v)];
  7571. }
  7572. else if (typeof v === 'boolean') {
  7573. return ['span', keywordStyle, v];
  7574. }
  7575. else if (isObject(v)) {
  7576. return ['object', { object: asRaw ? toRaw(v) : v }];
  7577. }
  7578. else {
  7579. return ['span', stringStyle, String(v)];
  7580. }
  7581. }
  7582. function extractKeys(instance, type) {
  7583. const Comp = instance.type;
  7584. if (isFunction(Comp)) {
  7585. return;
  7586. }
  7587. const extracted = {};
  7588. for (const key in instance.ctx) {
  7589. if (isKeyOfType(Comp, key, type)) {
  7590. extracted[key] = instance.ctx[key];
  7591. }
  7592. }
  7593. return extracted;
  7594. }
  7595. function isKeyOfType(Comp, key, type) {
  7596. const opts = Comp[type];
  7597. if ((isArray(opts) && opts.includes(key)) ||
  7598. (isObject(opts) && key in opts)) {
  7599. return true;
  7600. }
  7601. if (Comp.extends && isKeyOfType(Comp.extends, key, type)) {
  7602. return true;
  7603. }
  7604. if (Comp.mixins && Comp.mixins.some(m => isKeyOfType(m, key, type))) {
  7605. return true;
  7606. }
  7607. }
  7608. function genRefFlag(v) {
  7609. if (v._shallow) {
  7610. return `ShallowRef`;
  7611. }
  7612. if (v.effect) {
  7613. return `ComputedRef`;
  7614. }
  7615. return `Ref`;
  7616. }
  7617. if (window.devtoolsFormatters) {
  7618. window.devtoolsFormatters.push(formatter);
  7619. }
  7620. else {
  7621. window.devtoolsFormatters = [formatter];
  7622. }
  7623. }
  7624. function withMemo(memo, render, cache, index) {
  7625. const cached = cache[index];
  7626. if (cached && isMemoSame(cached, memo)) {
  7627. return cached;
  7628. }
  7629. const ret = render();
  7630. // shallow clone
  7631. ret.memo = memo.slice();
  7632. return (cache[index] = ret);
  7633. }
  7634. function isMemoSame(cached, memo) {
  7635. const prev = cached.memo;
  7636. if (prev.length != memo.length) {
  7637. return false;
  7638. }
  7639. for (let i = 0; i < prev.length; i++) {
  7640. if (prev[i] !== memo[i]) {
  7641. return false;
  7642. }
  7643. }
  7644. // make sure to let parent block track it when returning cached
  7645. if (isBlockTreeEnabled > 0 && currentBlock) {
  7646. currentBlock.push(cached);
  7647. }
  7648. return true;
  7649. }
  7650. // Core API ------------------------------------------------------------------
  7651. const version = "3.2.25";
  7652. const _ssrUtils = {
  7653. createComponentInstance,
  7654. setupComponent,
  7655. renderComponentRoot,
  7656. setCurrentRenderingInstance,
  7657. isVNode,
  7658. normalizeVNode
  7659. };
  7660. /**
  7661. * SSR utils for \@vue/server-renderer. Only exposed in cjs builds.
  7662. * @internal
  7663. */
  7664. const ssrUtils = (_ssrUtils );
  7665. /**
  7666. * @internal only exposed in compat builds
  7667. */
  7668. const resolveFilter = null;
  7669. /**
  7670. * @internal only exposed in compat builds.
  7671. */
  7672. const compatUtils = (null);
  7673. export { BaseTransition, Comment, Fragment, KeepAlive, Static, Suspense, Teleport, Text, callWithAsyncErrorHandling, callWithErrorHandling, cloneVNode, compatUtils, createBlock, createCommentVNode, createElementBlock, createBaseVNode as createElementVNode, createHydrationRenderer, createPropsRestProxy, createRenderer, createSlots, createStaticVNode, createTextVNode, createVNode, defineAsyncComponent, defineComponent, defineEmits, defineExpose, defineProps, devtools, getCurrentInstance, getTransitionRawChildren, guardReactiveProps, h, handleError, initCustomFormatter, inject, isMemoSame, isRuntimeOnly, isVNode, mergeDefaults, mergeProps, nextTick, onActivated, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onServerPrefetch, onUnmounted, onUpdated, openBlock, popScopeId, provide, pushScopeId, queuePostFlushCb, registerRuntimeCompiler, renderList, renderSlot, resolveComponent, resolveDirective, resolveDynamicComponent, resolveFilter, resolveTransitionHooks, setBlockTracking, setDevtoolsHook, setTransitionHooks, ssrContextKey, ssrUtils, toHandlers, transformVNodeArgs, useAttrs, useSSRContext, useSlots, useTransitionState, version, warn, watch, watchEffect, watchPostEffect, watchSyncEffect, withAsyncContext, withCtx, withDefaults, withDirectives, withMemo, withScopeId };