runtime-core.cjs.prod.js 238 KB

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