vue.runtime.esm-browser.js 328 KB

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