runtime-core.cjs.js 301 KB

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