runtime-core.cjs.js 302 KB

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