runtime-core.cjs.prod.js 237 KB

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