runtime-dom.esm-browser.js 399 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015
  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,BigInt';
  19. const isGloballyWhitelisted = /*#__PURE__*/ makeMap(GLOBALS_WHITE_LISTED);
  20. function normalizeStyle(value) {
  21. if (isArray(value)) {
  22. const res = {};
  23. for (let i = 0; i < value.length; i++) {
  24. const item = value[i];
  25. const normalized = isString(item)
  26. ? parseStringStyle(item)
  27. : normalizeStyle(item);
  28. if (normalized) {
  29. for (const key in normalized) {
  30. res[key] = normalized[key];
  31. }
  32. }
  33. }
  34. return res;
  35. }
  36. else if (isString(value)) {
  37. return value;
  38. }
  39. else if (isObject(value)) {
  40. return value;
  41. }
  42. }
  43. const listDelimiterRE = /;(?![^(]*\))/g;
  44. const propertyDelimiterRE = /:([^]+)/;
  45. const styleCommentRE = /\/\*.*?\*\//gs;
  46. function parseStringStyle(cssText) {
  47. const ret = {};
  48. cssText
  49. .replace(styleCommentRE, '')
  50. .split(listDelimiterRE)
  51. .forEach(item => {
  52. if (item) {
  53. const tmp = item.split(propertyDelimiterRE);
  54. tmp.length > 1 && (ret[tmp[0].trim()] = tmp[1].trim());
  55. }
  56. });
  57. return ret;
  58. }
  59. function normalizeClass(value) {
  60. let res = '';
  61. if (isString(value)) {
  62. res = value;
  63. }
  64. else if (isArray(value)) {
  65. for (let i = 0; i < value.length; i++) {
  66. const normalized = normalizeClass(value[i]);
  67. if (normalized) {
  68. res += normalized + ' ';
  69. }
  70. }
  71. }
  72. else if (isObject(value)) {
  73. for (const name in value) {
  74. if (value[name]) {
  75. res += name + ' ';
  76. }
  77. }
  78. }
  79. return res.trim();
  80. }
  81. function normalizeProps(props) {
  82. if (!props)
  83. return null;
  84. let { class: klass, style } = props;
  85. if (klass && !isString(klass)) {
  86. props.class = normalizeClass(klass);
  87. }
  88. if (style) {
  89. props.style = normalizeStyle(style);
  90. }
  91. return props;
  92. }
  93. // These tag configs are shared between compiler-dom and runtime-dom, so they
  94. // https://developer.mozilla.org/en-US/docs/Web/HTML/Element
  95. const HTML_TAGS = 'html,body,base,head,link,meta,style,title,address,article,aside,footer,' +
  96. 'header,hgroup,h1,h2,h3,h4,h5,h6,nav,section,div,dd,dl,dt,figcaption,' +
  97. 'figure,picture,hr,img,li,main,ol,p,pre,ul,a,b,abbr,bdi,bdo,br,cite,code,' +
  98. 'data,dfn,em,i,kbd,mark,q,rp,rt,ruby,s,samp,small,span,strong,sub,sup,' +
  99. 'time,u,var,wbr,area,audio,map,track,video,embed,object,param,source,' +
  100. 'canvas,script,noscript,del,ins,caption,col,colgroup,table,thead,tbody,td,' +
  101. 'th,tr,button,datalist,fieldset,form,input,label,legend,meter,optgroup,' +
  102. 'option,output,progress,select,textarea,details,dialog,menu,' +
  103. 'summary,template,blockquote,iframe,tfoot';
  104. // https://developer.mozilla.org/en-US/docs/Web/SVG/Element
  105. const SVG_TAGS = 'svg,animate,animateMotion,animateTransform,circle,clipPath,color-profile,' +
  106. 'defs,desc,discard,ellipse,feBlend,feColorMatrix,feComponentTransfer,' +
  107. 'feComposite,feConvolveMatrix,feDiffuseLighting,feDisplacementMap,' +
  108. 'feDistantLight,feDropShadow,feFlood,feFuncA,feFuncB,feFuncG,feFuncR,' +
  109. 'feGaussianBlur,feImage,feMerge,feMergeNode,feMorphology,feOffset,' +
  110. 'fePointLight,feSpecularLighting,feSpotLight,feTile,feTurbulence,filter,' +
  111. 'foreignObject,g,hatch,hatchpath,image,line,linearGradient,marker,mask,' +
  112. 'mesh,meshgradient,meshpatch,meshrow,metadata,mpath,path,pattern,' +
  113. 'polygon,polyline,radialGradient,rect,set,solidcolor,stop,switch,symbol,' +
  114. 'text,textPath,title,tspan,unknown,use,view';
  115. /**
  116. * Compiler only.
  117. * Do NOT use in runtime code paths unless behind `true` flag.
  118. */
  119. const isHTMLTag = /*#__PURE__*/ makeMap(HTML_TAGS);
  120. /**
  121. * Compiler only.
  122. * Do NOT use in runtime code paths unless behind `true` flag.
  123. */
  124. const isSVGTag = /*#__PURE__*/ makeMap(SVG_TAGS);
  125. /**
  126. * On the client we only need to offer special cases for boolean attributes that
  127. * have different names from their corresponding dom properties:
  128. * - itemscope -> N/A
  129. * - allowfullscreen -> allowFullscreen
  130. * - formnovalidate -> formNoValidate
  131. * - ismap -> isMap
  132. * - nomodule -> noModule
  133. * - novalidate -> noValidate
  134. * - readonly -> readOnly
  135. */
  136. const specialBooleanAttrs = `itemscope,allowfullscreen,formnovalidate,ismap,nomodule,novalidate,readonly`;
  137. const isSpecialBooleanAttr = /*#__PURE__*/ makeMap(specialBooleanAttrs);
  138. /**
  139. * Boolean attributes should be included if the value is truthy or ''.
  140. * e.g. `<select multiple>` compiles to `{ multiple: '' }`
  141. */
  142. function includeBooleanAttr(value) {
  143. return !!value || value === '';
  144. }
  145. function looseCompareArrays(a, b) {
  146. if (a.length !== b.length)
  147. return false;
  148. let equal = true;
  149. for (let i = 0; equal && i < a.length; i++) {
  150. equal = looseEqual(a[i], b[i]);
  151. }
  152. return equal;
  153. }
  154. function looseEqual(a, b) {
  155. if (a === b)
  156. return true;
  157. let aValidType = isDate(a);
  158. let bValidType = isDate(b);
  159. if (aValidType || bValidType) {
  160. return aValidType && bValidType ? a.getTime() === b.getTime() : false;
  161. }
  162. aValidType = isSymbol(a);
  163. bValidType = isSymbol(b);
  164. if (aValidType || bValidType) {
  165. return a === b;
  166. }
  167. aValidType = isArray(a);
  168. bValidType = isArray(b);
  169. if (aValidType || bValidType) {
  170. return aValidType && bValidType ? looseCompareArrays(a, b) : false;
  171. }
  172. aValidType = isObject(a);
  173. bValidType = isObject(b);
  174. if (aValidType || bValidType) {
  175. /* istanbul ignore if: this if will probably never be called */
  176. if (!aValidType || !bValidType) {
  177. return false;
  178. }
  179. const aKeysCount = Object.keys(a).length;
  180. const bKeysCount = Object.keys(b).length;
  181. if (aKeysCount !== bKeysCount) {
  182. return false;
  183. }
  184. for (const key in a) {
  185. const aHasKey = a.hasOwnProperty(key);
  186. const bHasKey = b.hasOwnProperty(key);
  187. if ((aHasKey && !bHasKey) ||
  188. (!aHasKey && bHasKey) ||
  189. !looseEqual(a[key], b[key])) {
  190. return false;
  191. }
  192. }
  193. }
  194. return String(a) === String(b);
  195. }
  196. function looseIndexOf(arr, val) {
  197. return arr.findIndex(item => looseEqual(item, val));
  198. }
  199. /**
  200. * For converting {{ interpolation }} values to displayed strings.
  201. * @private
  202. */
  203. const toDisplayString = (val) => {
  204. return isString(val)
  205. ? val
  206. : val == null
  207. ? ''
  208. : isArray(val) ||
  209. (isObject(val) &&
  210. (val.toString === objectToString || !isFunction(val.toString)))
  211. ? JSON.stringify(val, replacer, 2)
  212. : String(val);
  213. };
  214. const replacer = (_key, val) => {
  215. // can't use isRef here since @vue/shared has no deps
  216. if (val && val.__v_isRef) {
  217. return replacer(_key, val.value);
  218. }
  219. else if (isMap(val)) {
  220. return {
  221. [`Map(${val.size})`]: [...val.entries()].reduce((entries, [key, val]) => {
  222. entries[`${key} =>`] = val;
  223. return entries;
  224. }, {})
  225. };
  226. }
  227. else if (isSet(val)) {
  228. return {
  229. [`Set(${val.size})`]: [...val.values()]
  230. };
  231. }
  232. else if (isObject(val) && !isArray(val) && !isPlainObject(val)) {
  233. return String(val);
  234. }
  235. return val;
  236. };
  237. const EMPTY_OBJ = Object.freeze({})
  238. ;
  239. const EMPTY_ARR = Object.freeze([]) ;
  240. const NOOP = () => { };
  241. /**
  242. * Always return false.
  243. */
  244. const NO = () => false;
  245. const onRE = /^on[^a-z]/;
  246. const isOn = (key) => onRE.test(key);
  247. const isModelListener = (key) => key.startsWith('onUpdate:');
  248. const extend = Object.assign;
  249. const remove = (arr, el) => {
  250. const i = arr.indexOf(el);
  251. if (i > -1) {
  252. arr.splice(i, 1);
  253. }
  254. };
  255. const hasOwnProperty$1 = Object.prototype.hasOwnProperty;
  256. const hasOwn = (val, key) => hasOwnProperty$1.call(val, key);
  257. const isArray = Array.isArray;
  258. const isMap = (val) => toTypeString(val) === '[object Map]';
  259. const isSet = (val) => toTypeString(val) === '[object Set]';
  260. const isDate = (val) => toTypeString(val) === '[object Date]';
  261. const isRegExp = (val) => toTypeString(val) === '[object RegExp]';
  262. const isFunction = (val) => typeof val === 'function';
  263. const isString = (val) => typeof val === 'string';
  264. const isSymbol = (val) => typeof val === 'symbol';
  265. const isObject = (val) => val !== null && typeof val === 'object';
  266. const isPromise = (val) => {
  267. return isObject(val) && isFunction(val.then) && isFunction(val.catch);
  268. };
  269. const objectToString = Object.prototype.toString;
  270. const toTypeString = (value) => objectToString.call(value);
  271. const toRawType = (value) => {
  272. // extract "RawType" from strings like "[object RawType]"
  273. return toTypeString(value).slice(8, -1);
  274. };
  275. const isPlainObject = (val) => toTypeString(val) === '[object Object]';
  276. const isIntegerKey = (key) => isString(key) &&
  277. key !== 'NaN' &&
  278. key[0] !== '-' &&
  279. '' + parseInt(key, 10) === key;
  280. const isReservedProp = /*#__PURE__*/ makeMap(
  281. // the leading comma is intentional so empty string "" is also included
  282. ',key,ref,ref_for,ref_key,' +
  283. 'onVnodeBeforeMount,onVnodeMounted,' +
  284. 'onVnodeBeforeUpdate,onVnodeUpdated,' +
  285. 'onVnodeBeforeUnmount,onVnodeUnmounted');
  286. const isBuiltInDirective = /*#__PURE__*/ makeMap('bind,cloak,else-if,else,for,html,if,model,on,once,pre,show,slot,text,memo');
  287. const cacheStringFunction = (fn) => {
  288. const cache = Object.create(null);
  289. return ((str) => {
  290. const hit = cache[str];
  291. return hit || (cache[str] = fn(str));
  292. });
  293. };
  294. const camelizeRE = /-(\w)/g;
  295. /**
  296. * @private
  297. */
  298. const camelize = cacheStringFunction((str) => {
  299. return str.replace(camelizeRE, (_, c) => (c ? c.toUpperCase() : ''));
  300. });
  301. const hyphenateRE = /\B([A-Z])/g;
  302. /**
  303. * @private
  304. */
  305. const hyphenate = cacheStringFunction((str) => str.replace(hyphenateRE, '-$1').toLowerCase());
  306. /**
  307. * @private
  308. */
  309. const capitalize = cacheStringFunction((str) => str.charAt(0).toUpperCase() + str.slice(1));
  310. /**
  311. * @private
  312. */
  313. const toHandlerKey = cacheStringFunction((str) => str ? `on${capitalize(str)}` : ``);
  314. // compare whether a value has changed, accounting for NaN.
  315. const hasChanged = (value, oldValue) => !Object.is(value, oldValue);
  316. const invokeArrayFns = (fns, arg) => {
  317. for (let i = 0; i < fns.length; i++) {
  318. fns[i](arg);
  319. }
  320. };
  321. const def = (obj, key, value) => {
  322. Object.defineProperty(obj, key, {
  323. configurable: true,
  324. enumerable: false,
  325. value
  326. });
  327. };
  328. /**
  329. * "123-foo" will be parsed to 123
  330. * This is used for the .number modifier in v-model
  331. */
  332. const looseToNumber = (val) => {
  333. const n = parseFloat(val);
  334. return isNaN(n) ? val : n;
  335. };
  336. /**
  337. * Only conerces number-like strings
  338. * "123-foo" will be returned as-is
  339. */
  340. const toNumber = (val) => {
  341. const n = isString(val) ? Number(val) : NaN;
  342. return isNaN(n) ? val : n;
  343. };
  344. let _globalThis;
  345. const getGlobalThis = () => {
  346. return (_globalThis ||
  347. (_globalThis =
  348. typeof globalThis !== 'undefined'
  349. ? globalThis
  350. : typeof self !== 'undefined'
  351. ? self
  352. : typeof window !== 'undefined'
  353. ? window
  354. : typeof global !== 'undefined'
  355. ? global
  356. : {}));
  357. };
  358. function warn$1(msg, ...args) {
  359. console.warn(`[Vue warn] ${msg}`, ...args);
  360. }
  361. let activeEffectScope;
  362. class EffectScope {
  363. constructor(detached = false) {
  364. this.detached = detached;
  365. /**
  366. * @internal
  367. */
  368. this._active = true;
  369. /**
  370. * @internal
  371. */
  372. this.effects = [];
  373. /**
  374. * @internal
  375. */
  376. this.cleanups = [];
  377. this.parent = activeEffectScope;
  378. if (!detached && activeEffectScope) {
  379. this.index =
  380. (activeEffectScope.scopes || (activeEffectScope.scopes = [])).push(this) - 1;
  381. }
  382. }
  383. get active() {
  384. return this._active;
  385. }
  386. run(fn) {
  387. if (this._active) {
  388. const currentEffectScope = activeEffectScope;
  389. try {
  390. activeEffectScope = this;
  391. return fn();
  392. }
  393. finally {
  394. activeEffectScope = currentEffectScope;
  395. }
  396. }
  397. else {
  398. warn$1(`cannot run an inactive effect scope.`);
  399. }
  400. }
  401. /**
  402. * This should only be called on non-detached scopes
  403. * @internal
  404. */
  405. on() {
  406. activeEffectScope = this;
  407. }
  408. /**
  409. * This should only be called on non-detached scopes
  410. * @internal
  411. */
  412. off() {
  413. activeEffectScope = this.parent;
  414. }
  415. stop(fromParent) {
  416. if (this._active) {
  417. let i, l;
  418. for (i = 0, l = this.effects.length; i < l; i++) {
  419. this.effects[i].stop();
  420. }
  421. for (i = 0, l = this.cleanups.length; i < l; i++) {
  422. this.cleanups[i]();
  423. }
  424. if (this.scopes) {
  425. for (i = 0, l = this.scopes.length; i < l; i++) {
  426. this.scopes[i].stop(true);
  427. }
  428. }
  429. // nested scope, dereference from parent to avoid memory leaks
  430. if (!this.detached && this.parent && !fromParent) {
  431. // optimized O(1) removal
  432. const last = this.parent.scopes.pop();
  433. if (last && last !== this) {
  434. this.parent.scopes[this.index] = last;
  435. last.index = this.index;
  436. }
  437. }
  438. this.parent = undefined;
  439. this._active = false;
  440. }
  441. }
  442. }
  443. function effectScope(detached) {
  444. return new EffectScope(detached);
  445. }
  446. function recordEffectScope(effect, scope = activeEffectScope) {
  447. if (scope && scope.active) {
  448. scope.effects.push(effect);
  449. }
  450. }
  451. function getCurrentScope() {
  452. return activeEffectScope;
  453. }
  454. function onScopeDispose(fn) {
  455. if (activeEffectScope) {
  456. activeEffectScope.cleanups.push(fn);
  457. }
  458. else {
  459. warn$1(`onScopeDispose() is called when there is no active effect scope` +
  460. ` to be associated with.`);
  461. }
  462. }
  463. const createDep = (effects) => {
  464. const dep = new Set(effects);
  465. dep.w = 0;
  466. dep.n = 0;
  467. return dep;
  468. };
  469. const wasTracked = (dep) => (dep.w & trackOpBit) > 0;
  470. const newTracked = (dep) => (dep.n & trackOpBit) > 0;
  471. const initDepMarkers = ({ deps }) => {
  472. if (deps.length) {
  473. for (let i = 0; i < deps.length; i++) {
  474. deps[i].w |= trackOpBit; // set was tracked
  475. }
  476. }
  477. };
  478. const finalizeDepMarkers = (effect) => {
  479. const { deps } = effect;
  480. if (deps.length) {
  481. let ptr = 0;
  482. for (let i = 0; i < deps.length; i++) {
  483. const dep = deps[i];
  484. if (wasTracked(dep) && !newTracked(dep)) {
  485. dep.delete(effect);
  486. }
  487. else {
  488. deps[ptr++] = dep;
  489. }
  490. // clear bits
  491. dep.w &= ~trackOpBit;
  492. dep.n &= ~trackOpBit;
  493. }
  494. deps.length = ptr;
  495. }
  496. };
  497. const targetMap = new WeakMap();
  498. // The number of effects currently being tracked recursively.
  499. let effectTrackDepth = 0;
  500. let trackOpBit = 1;
  501. /**
  502. * The bitwise track markers support at most 30 levels of recursion.
  503. * This value is chosen to enable modern JS engines to use a SMI on all platforms.
  504. * When recursion depth is greater, fall back to using a full cleanup.
  505. */
  506. const maxMarkerBits = 30;
  507. let activeEffect;
  508. const ITERATE_KEY = Symbol('iterate' );
  509. const MAP_KEY_ITERATE_KEY = Symbol('Map key iterate' );
  510. class ReactiveEffect {
  511. constructor(fn, scheduler = null, scope) {
  512. this.fn = fn;
  513. this.scheduler = scheduler;
  514. this.active = true;
  515. this.deps = [];
  516. this.parent = undefined;
  517. recordEffectScope(this, scope);
  518. }
  519. run() {
  520. if (!this.active) {
  521. return this.fn();
  522. }
  523. let parent = activeEffect;
  524. let lastShouldTrack = shouldTrack;
  525. while (parent) {
  526. if (parent === this) {
  527. return;
  528. }
  529. parent = parent.parent;
  530. }
  531. try {
  532. this.parent = activeEffect;
  533. activeEffect = this;
  534. shouldTrack = true;
  535. trackOpBit = 1 << ++effectTrackDepth;
  536. if (effectTrackDepth <= maxMarkerBits) {
  537. initDepMarkers(this);
  538. }
  539. else {
  540. cleanupEffect(this);
  541. }
  542. return this.fn();
  543. }
  544. finally {
  545. if (effectTrackDepth <= maxMarkerBits) {
  546. finalizeDepMarkers(this);
  547. }
  548. trackOpBit = 1 << --effectTrackDepth;
  549. activeEffect = this.parent;
  550. shouldTrack = lastShouldTrack;
  551. this.parent = undefined;
  552. if (this.deferStop) {
  553. this.stop();
  554. }
  555. }
  556. }
  557. stop() {
  558. // stopped while running itself - defer the cleanup
  559. if (activeEffect === this) {
  560. this.deferStop = true;
  561. }
  562. else if (this.active) {
  563. cleanupEffect(this);
  564. if (this.onStop) {
  565. this.onStop();
  566. }
  567. this.active = false;
  568. }
  569. }
  570. }
  571. function cleanupEffect(effect) {
  572. const { deps } = effect;
  573. if (deps.length) {
  574. for (let i = 0; i < deps.length; i++) {
  575. deps[i].delete(effect);
  576. }
  577. deps.length = 0;
  578. }
  579. }
  580. function effect(fn, options) {
  581. if (fn.effect) {
  582. fn = fn.effect.fn;
  583. }
  584. const _effect = new ReactiveEffect(fn);
  585. if (options) {
  586. extend(_effect, options);
  587. if (options.scope)
  588. recordEffectScope(_effect, options.scope);
  589. }
  590. if (!options || !options.lazy) {
  591. _effect.run();
  592. }
  593. const runner = _effect.run.bind(_effect);
  594. runner.effect = _effect;
  595. return runner;
  596. }
  597. function stop(runner) {
  598. runner.effect.stop();
  599. }
  600. let shouldTrack = true;
  601. const trackStack = [];
  602. function pauseTracking() {
  603. trackStack.push(shouldTrack);
  604. shouldTrack = false;
  605. }
  606. function resetTracking() {
  607. const last = trackStack.pop();
  608. shouldTrack = last === undefined ? true : last;
  609. }
  610. function track(target, type, key) {
  611. if (shouldTrack && activeEffect) {
  612. let depsMap = targetMap.get(target);
  613. if (!depsMap) {
  614. targetMap.set(target, (depsMap = new Map()));
  615. }
  616. let dep = depsMap.get(key);
  617. if (!dep) {
  618. depsMap.set(key, (dep = createDep()));
  619. }
  620. const eventInfo = { effect: activeEffect, target, type, key }
  621. ;
  622. trackEffects(dep, eventInfo);
  623. }
  624. }
  625. function trackEffects(dep, debuggerEventExtraInfo) {
  626. let shouldTrack = false;
  627. if (effectTrackDepth <= maxMarkerBits) {
  628. if (!newTracked(dep)) {
  629. dep.n |= trackOpBit; // set newly tracked
  630. shouldTrack = !wasTracked(dep);
  631. }
  632. }
  633. else {
  634. // Full cleanup mode.
  635. shouldTrack = !dep.has(activeEffect);
  636. }
  637. if (shouldTrack) {
  638. dep.add(activeEffect);
  639. activeEffect.deps.push(dep);
  640. if (activeEffect.onTrack) {
  641. activeEffect.onTrack(Object.assign({ effect: activeEffect }, debuggerEventExtraInfo));
  642. }
  643. }
  644. }
  645. function trigger(target, type, key, newValue, oldValue, oldTarget) {
  646. const depsMap = targetMap.get(target);
  647. if (!depsMap) {
  648. // never been tracked
  649. return;
  650. }
  651. let deps = [];
  652. if (type === "clear" /* TriggerOpTypes.CLEAR */) {
  653. // collection being cleared
  654. // trigger all effects for target
  655. deps = [...depsMap.values()];
  656. }
  657. else if (key === 'length' && isArray(target)) {
  658. const newLength = Number(newValue);
  659. depsMap.forEach((dep, key) => {
  660. if (key === 'length' || key >= newLength) {
  661. deps.push(dep);
  662. }
  663. });
  664. }
  665. else {
  666. // schedule runs for SET | ADD | DELETE
  667. if (key !== void 0) {
  668. deps.push(depsMap.get(key));
  669. }
  670. // also run for iteration key on ADD | DELETE | Map.SET
  671. switch (type) {
  672. case "add" /* TriggerOpTypes.ADD */:
  673. if (!isArray(target)) {
  674. deps.push(depsMap.get(ITERATE_KEY));
  675. if (isMap(target)) {
  676. deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
  677. }
  678. }
  679. else if (isIntegerKey(key)) {
  680. // new index added to array -> length changes
  681. deps.push(depsMap.get('length'));
  682. }
  683. break;
  684. case "delete" /* TriggerOpTypes.DELETE */:
  685. if (!isArray(target)) {
  686. deps.push(depsMap.get(ITERATE_KEY));
  687. if (isMap(target)) {
  688. deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
  689. }
  690. }
  691. break;
  692. case "set" /* TriggerOpTypes.SET */:
  693. if (isMap(target)) {
  694. deps.push(depsMap.get(ITERATE_KEY));
  695. }
  696. break;
  697. }
  698. }
  699. const eventInfo = { target, type, key, newValue, oldValue, oldTarget }
  700. ;
  701. if (deps.length === 1) {
  702. if (deps[0]) {
  703. {
  704. triggerEffects(deps[0], eventInfo);
  705. }
  706. }
  707. }
  708. else {
  709. const effects = [];
  710. for (const dep of deps) {
  711. if (dep) {
  712. effects.push(...dep);
  713. }
  714. }
  715. {
  716. triggerEffects(createDep(effects), eventInfo);
  717. }
  718. }
  719. }
  720. function triggerEffects(dep, debuggerEventExtraInfo) {
  721. // spread into array for stabilization
  722. const effects = isArray(dep) ? dep : [...dep];
  723. for (const effect of effects) {
  724. if (effect.computed) {
  725. triggerEffect(effect, debuggerEventExtraInfo);
  726. }
  727. }
  728. for (const effect of effects) {
  729. if (!effect.computed) {
  730. triggerEffect(effect, debuggerEventExtraInfo);
  731. }
  732. }
  733. }
  734. function triggerEffect(effect, debuggerEventExtraInfo) {
  735. if (effect !== activeEffect || effect.allowRecurse) {
  736. if (effect.onTrigger) {
  737. effect.onTrigger(extend({ effect }, debuggerEventExtraInfo));
  738. }
  739. if (effect.scheduler) {
  740. effect.scheduler();
  741. }
  742. else {
  743. effect.run();
  744. }
  745. }
  746. }
  747. function getDepFromReactive(object, key) {
  748. var _a;
  749. return (_a = targetMap.get(object)) === null || _a === void 0 ? void 0 : _a.get(key);
  750. }
  751. const isNonTrackableKeys = /*#__PURE__*/ makeMap(`__proto__,__v_isRef,__isVue`);
  752. const builtInSymbols = new Set(
  753. /*#__PURE__*/
  754. Object.getOwnPropertyNames(Symbol)
  755. // ios10.x Object.getOwnPropertyNames(Symbol) can enumerate 'arguments' and 'caller'
  756. // but accessing them on Symbol leads to TypeError because Symbol is a strict mode
  757. // function
  758. .filter(key => key !== 'arguments' && key !== 'caller')
  759. .map(key => Symbol[key])
  760. .filter(isSymbol));
  761. const get$1 = /*#__PURE__*/ createGetter();
  762. const shallowGet = /*#__PURE__*/ createGetter(false, true);
  763. const readonlyGet = /*#__PURE__*/ createGetter(true);
  764. const shallowReadonlyGet = /*#__PURE__*/ createGetter(true, true);
  765. const arrayInstrumentations = /*#__PURE__*/ createArrayInstrumentations();
  766. function createArrayInstrumentations() {
  767. const instrumentations = {};
  768. ['includes', 'indexOf', 'lastIndexOf'].forEach(key => {
  769. instrumentations[key] = function (...args) {
  770. const arr = toRaw(this);
  771. for (let i = 0, l = this.length; i < l; i++) {
  772. track(arr, "get" /* TrackOpTypes.GET */, i + '');
  773. }
  774. // we run the method using the original args first (which may be reactive)
  775. const res = arr[key](...args);
  776. if (res === -1 || res === false) {
  777. // if that didn't work, run it again using raw values.
  778. return arr[key](...args.map(toRaw));
  779. }
  780. else {
  781. return res;
  782. }
  783. };
  784. });
  785. ['push', 'pop', 'shift', 'unshift', 'splice'].forEach(key => {
  786. instrumentations[key] = function (...args) {
  787. pauseTracking();
  788. const res = toRaw(this)[key].apply(this, args);
  789. resetTracking();
  790. return res;
  791. };
  792. });
  793. return instrumentations;
  794. }
  795. function hasOwnProperty(key) {
  796. const obj = toRaw(this);
  797. track(obj, "has" /* TrackOpTypes.HAS */, key);
  798. return obj.hasOwnProperty(key);
  799. }
  800. function createGetter(isReadonly = false, shallow = false) {
  801. return function get(target, key, receiver) {
  802. if (key === "__v_isReactive" /* ReactiveFlags.IS_REACTIVE */) {
  803. return !isReadonly;
  804. }
  805. else if (key === "__v_isReadonly" /* ReactiveFlags.IS_READONLY */) {
  806. return isReadonly;
  807. }
  808. else if (key === "__v_isShallow" /* ReactiveFlags.IS_SHALLOW */) {
  809. return shallow;
  810. }
  811. else if (key === "__v_raw" /* ReactiveFlags.RAW */ &&
  812. receiver ===
  813. (isReadonly
  814. ? shallow
  815. ? shallowReadonlyMap
  816. : readonlyMap
  817. : shallow
  818. ? shallowReactiveMap
  819. : reactiveMap).get(target)) {
  820. return target;
  821. }
  822. const targetIsArray = isArray(target);
  823. if (!isReadonly) {
  824. if (targetIsArray && hasOwn(arrayInstrumentations, key)) {
  825. return Reflect.get(arrayInstrumentations, key, receiver);
  826. }
  827. if (key === 'hasOwnProperty') {
  828. return hasOwnProperty;
  829. }
  830. }
  831. const res = Reflect.get(target, key, receiver);
  832. if (isSymbol(key) ? builtInSymbols.has(key) : isNonTrackableKeys(key)) {
  833. return res;
  834. }
  835. if (!isReadonly) {
  836. track(target, "get" /* TrackOpTypes.GET */, key);
  837. }
  838. if (shallow) {
  839. return res;
  840. }
  841. if (isRef(res)) {
  842. // ref unwrapping - skip unwrap for Array + integer key.
  843. return targetIsArray && isIntegerKey(key) ? res : res.value;
  844. }
  845. if (isObject(res)) {
  846. // Convert returned value into a proxy as well. we do the isObject check
  847. // here to avoid invalid value warning. Also need to lazy access readonly
  848. // and reactive here to avoid circular dependency.
  849. return isReadonly ? readonly(res) : reactive(res);
  850. }
  851. return res;
  852. };
  853. }
  854. const set$1 = /*#__PURE__*/ createSetter();
  855. const shallowSet = /*#__PURE__*/ createSetter(true);
  856. function createSetter(shallow = false) {
  857. return function set(target, key, value, receiver) {
  858. let oldValue = target[key];
  859. if (isReadonly(oldValue) && isRef(oldValue) && !isRef(value)) {
  860. return false;
  861. }
  862. if (!shallow) {
  863. if (!isShallow(value) && !isReadonly(value)) {
  864. oldValue = toRaw(oldValue);
  865. value = toRaw(value);
  866. }
  867. if (!isArray(target) && isRef(oldValue) && !isRef(value)) {
  868. oldValue.value = value;
  869. return true;
  870. }
  871. }
  872. const hadKey = isArray(target) && isIntegerKey(key)
  873. ? Number(key) < target.length
  874. : hasOwn(target, key);
  875. const result = Reflect.set(target, key, value, receiver);
  876. // don't trigger if target is something up in the prototype chain of original
  877. if (target === toRaw(receiver)) {
  878. if (!hadKey) {
  879. trigger(target, "add" /* TriggerOpTypes.ADD */, key, value);
  880. }
  881. else if (hasChanged(value, oldValue)) {
  882. trigger(target, "set" /* TriggerOpTypes.SET */, key, value, oldValue);
  883. }
  884. }
  885. return result;
  886. };
  887. }
  888. function deleteProperty(target, key) {
  889. const hadKey = hasOwn(target, key);
  890. const oldValue = target[key];
  891. const result = Reflect.deleteProperty(target, key);
  892. if (result && hadKey) {
  893. trigger(target, "delete" /* TriggerOpTypes.DELETE */, key, undefined, oldValue);
  894. }
  895. return result;
  896. }
  897. function has$1(target, key) {
  898. const result = Reflect.has(target, key);
  899. if (!isSymbol(key) || !builtInSymbols.has(key)) {
  900. track(target, "has" /* TrackOpTypes.HAS */, key);
  901. }
  902. return result;
  903. }
  904. function ownKeys(target) {
  905. track(target, "iterate" /* TrackOpTypes.ITERATE */, isArray(target) ? 'length' : ITERATE_KEY);
  906. return Reflect.ownKeys(target);
  907. }
  908. const mutableHandlers = {
  909. get: get$1,
  910. set: set$1,
  911. deleteProperty,
  912. has: has$1,
  913. ownKeys
  914. };
  915. const readonlyHandlers = {
  916. get: readonlyGet,
  917. set(target, key) {
  918. {
  919. warn$1(`Set operation on key "${String(key)}" failed: target is readonly.`, target);
  920. }
  921. return true;
  922. },
  923. deleteProperty(target, key) {
  924. {
  925. warn$1(`Delete operation on key "${String(key)}" failed: target is readonly.`, target);
  926. }
  927. return true;
  928. }
  929. };
  930. const shallowReactiveHandlers = /*#__PURE__*/ extend({}, mutableHandlers, {
  931. get: shallowGet,
  932. set: shallowSet
  933. });
  934. // Props handlers are special in the sense that it should not unwrap top-level
  935. // refs (in order to allow refs to be explicitly passed down), but should
  936. // retain the reactivity of the normal readonly object.
  937. const shallowReadonlyHandlers = /*#__PURE__*/ extend({}, readonlyHandlers, {
  938. get: shallowReadonlyGet
  939. });
  940. const toShallow = (value) => value;
  941. const getProto = (v) => Reflect.getPrototypeOf(v);
  942. function get(target, key, isReadonly = false, isShallow = false) {
  943. // #1772: readonly(reactive(Map)) should return readonly + reactive version
  944. // of the value
  945. target = target["__v_raw" /* ReactiveFlags.RAW */];
  946. const rawTarget = toRaw(target);
  947. const rawKey = toRaw(key);
  948. if (!isReadonly) {
  949. if (key !== rawKey) {
  950. track(rawTarget, "get" /* TrackOpTypes.GET */, key);
  951. }
  952. track(rawTarget, "get" /* TrackOpTypes.GET */, rawKey);
  953. }
  954. const { has } = getProto(rawTarget);
  955. const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
  956. if (has.call(rawTarget, key)) {
  957. return wrap(target.get(key));
  958. }
  959. else if (has.call(rawTarget, rawKey)) {
  960. return wrap(target.get(rawKey));
  961. }
  962. else if (target !== rawTarget) {
  963. // #3602 readonly(reactive(Map))
  964. // ensure that the nested reactive `Map` can do tracking for itself
  965. target.get(key);
  966. }
  967. }
  968. function has(key, isReadonly = false) {
  969. const target = this["__v_raw" /* ReactiveFlags.RAW */];
  970. const rawTarget = toRaw(target);
  971. const rawKey = toRaw(key);
  972. if (!isReadonly) {
  973. if (key !== rawKey) {
  974. track(rawTarget, "has" /* TrackOpTypes.HAS */, key);
  975. }
  976. track(rawTarget, "has" /* TrackOpTypes.HAS */, rawKey);
  977. }
  978. return key === rawKey
  979. ? target.has(key)
  980. : target.has(key) || target.has(rawKey);
  981. }
  982. function size(target, isReadonly = false) {
  983. target = target["__v_raw" /* ReactiveFlags.RAW */];
  984. !isReadonly && track(toRaw(target), "iterate" /* TrackOpTypes.ITERATE */, ITERATE_KEY);
  985. return Reflect.get(target, 'size', target);
  986. }
  987. function add(value) {
  988. value = toRaw(value);
  989. const target = toRaw(this);
  990. const proto = getProto(target);
  991. const hadKey = proto.has.call(target, value);
  992. if (!hadKey) {
  993. target.add(value);
  994. trigger(target, "add" /* TriggerOpTypes.ADD */, value, value);
  995. }
  996. return this;
  997. }
  998. function set(key, value) {
  999. value = toRaw(value);
  1000. const target = toRaw(this);
  1001. const { has, get } = getProto(target);
  1002. let hadKey = has.call(target, key);
  1003. if (!hadKey) {
  1004. key = toRaw(key);
  1005. hadKey = has.call(target, key);
  1006. }
  1007. else {
  1008. checkIdentityKeys(target, has, key);
  1009. }
  1010. const oldValue = get.call(target, key);
  1011. target.set(key, value);
  1012. if (!hadKey) {
  1013. trigger(target, "add" /* TriggerOpTypes.ADD */, key, value);
  1014. }
  1015. else if (hasChanged(value, oldValue)) {
  1016. trigger(target, "set" /* TriggerOpTypes.SET */, key, value, oldValue);
  1017. }
  1018. return this;
  1019. }
  1020. function deleteEntry(key) {
  1021. const target = toRaw(this);
  1022. const { has, get } = getProto(target);
  1023. let hadKey = has.call(target, key);
  1024. if (!hadKey) {
  1025. key = toRaw(key);
  1026. hadKey = has.call(target, key);
  1027. }
  1028. else {
  1029. checkIdentityKeys(target, has, key);
  1030. }
  1031. const oldValue = get ? get.call(target, key) : undefined;
  1032. // forward the operation before queueing reactions
  1033. const result = target.delete(key);
  1034. if (hadKey) {
  1035. trigger(target, "delete" /* TriggerOpTypes.DELETE */, key, undefined, oldValue);
  1036. }
  1037. return result;
  1038. }
  1039. function clear() {
  1040. const target = toRaw(this);
  1041. const hadItems = target.size !== 0;
  1042. const oldTarget = isMap(target)
  1043. ? new Map(target)
  1044. : new Set(target)
  1045. ;
  1046. // forward the operation before queueing reactions
  1047. const result = target.clear();
  1048. if (hadItems) {
  1049. trigger(target, "clear" /* TriggerOpTypes.CLEAR */, undefined, undefined, oldTarget);
  1050. }
  1051. return result;
  1052. }
  1053. function createForEach(isReadonly, isShallow) {
  1054. return function forEach(callback, thisArg) {
  1055. const observed = this;
  1056. const target = observed["__v_raw" /* ReactiveFlags.RAW */];
  1057. const rawTarget = toRaw(target);
  1058. const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
  1059. !isReadonly && track(rawTarget, "iterate" /* TrackOpTypes.ITERATE */, ITERATE_KEY);
  1060. return target.forEach((value, key) => {
  1061. // important: make sure the callback is
  1062. // 1. invoked with the reactive map as `this` and 3rd arg
  1063. // 2. the value received should be a corresponding reactive/readonly.
  1064. return callback.call(thisArg, wrap(value), wrap(key), observed);
  1065. });
  1066. };
  1067. }
  1068. function createIterableMethod(method, isReadonly, isShallow) {
  1069. return function (...args) {
  1070. const target = this["__v_raw" /* ReactiveFlags.RAW */];
  1071. const rawTarget = toRaw(target);
  1072. const targetIsMap = isMap(rawTarget);
  1073. const isPair = method === 'entries' || (method === Symbol.iterator && targetIsMap);
  1074. const isKeyOnly = method === 'keys' && targetIsMap;
  1075. const innerIterator = target[method](...args);
  1076. const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
  1077. !isReadonly &&
  1078. track(rawTarget, "iterate" /* TrackOpTypes.ITERATE */, isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY);
  1079. // return a wrapped iterator which returns observed versions of the
  1080. // values emitted from the real iterator
  1081. return {
  1082. // iterator protocol
  1083. next() {
  1084. const { value, done } = innerIterator.next();
  1085. return done
  1086. ? { value, done }
  1087. : {
  1088. value: isPair ? [wrap(value[0]), wrap(value[1])] : wrap(value),
  1089. done
  1090. };
  1091. },
  1092. // iterable protocol
  1093. [Symbol.iterator]() {
  1094. return this;
  1095. }
  1096. };
  1097. };
  1098. }
  1099. function createReadonlyMethod(type) {
  1100. return function (...args) {
  1101. {
  1102. const key = args[0] ? `on key "${args[0]}" ` : ``;
  1103. console.warn(`${capitalize(type)} operation ${key}failed: target is readonly.`, toRaw(this));
  1104. }
  1105. return type === "delete" /* TriggerOpTypes.DELETE */ ? false : this;
  1106. };
  1107. }
  1108. function createInstrumentations() {
  1109. const mutableInstrumentations = {
  1110. get(key) {
  1111. return get(this, key);
  1112. },
  1113. get size() {
  1114. return size(this);
  1115. },
  1116. has,
  1117. add,
  1118. set,
  1119. delete: deleteEntry,
  1120. clear,
  1121. forEach: createForEach(false, false)
  1122. };
  1123. const shallowInstrumentations = {
  1124. get(key) {
  1125. return get(this, key, false, true);
  1126. },
  1127. get size() {
  1128. return size(this);
  1129. },
  1130. has,
  1131. add,
  1132. set,
  1133. delete: deleteEntry,
  1134. clear,
  1135. forEach: createForEach(false, true)
  1136. };
  1137. const readonlyInstrumentations = {
  1138. get(key) {
  1139. return get(this, key, true);
  1140. },
  1141. get size() {
  1142. return size(this, true);
  1143. },
  1144. has(key) {
  1145. return has.call(this, key, true);
  1146. },
  1147. add: createReadonlyMethod("add" /* TriggerOpTypes.ADD */),
  1148. set: createReadonlyMethod("set" /* TriggerOpTypes.SET */),
  1149. delete: createReadonlyMethod("delete" /* TriggerOpTypes.DELETE */),
  1150. clear: createReadonlyMethod("clear" /* TriggerOpTypes.CLEAR */),
  1151. forEach: createForEach(true, false)
  1152. };
  1153. const shallowReadonlyInstrumentations = {
  1154. get(key) {
  1155. return get(this, key, true, true);
  1156. },
  1157. get size() {
  1158. return size(this, true);
  1159. },
  1160. has(key) {
  1161. return has.call(this, key, true);
  1162. },
  1163. add: createReadonlyMethod("add" /* TriggerOpTypes.ADD */),
  1164. set: createReadonlyMethod("set" /* TriggerOpTypes.SET */),
  1165. delete: createReadonlyMethod("delete" /* TriggerOpTypes.DELETE */),
  1166. clear: createReadonlyMethod("clear" /* TriggerOpTypes.CLEAR */),
  1167. forEach: createForEach(true, true)
  1168. };
  1169. const iteratorMethods = ['keys', 'values', 'entries', Symbol.iterator];
  1170. iteratorMethods.forEach(method => {
  1171. mutableInstrumentations[method] = createIterableMethod(method, false, false);
  1172. readonlyInstrumentations[method] = createIterableMethod(method, true, false);
  1173. shallowInstrumentations[method] = createIterableMethod(method, false, true);
  1174. shallowReadonlyInstrumentations[method] = createIterableMethod(method, true, true);
  1175. });
  1176. return [
  1177. mutableInstrumentations,
  1178. readonlyInstrumentations,
  1179. shallowInstrumentations,
  1180. shallowReadonlyInstrumentations
  1181. ];
  1182. }
  1183. const [mutableInstrumentations, readonlyInstrumentations, shallowInstrumentations, shallowReadonlyInstrumentations] = /* #__PURE__*/ createInstrumentations();
  1184. function createInstrumentationGetter(isReadonly, shallow) {
  1185. const instrumentations = shallow
  1186. ? isReadonly
  1187. ? shallowReadonlyInstrumentations
  1188. : shallowInstrumentations
  1189. : isReadonly
  1190. ? readonlyInstrumentations
  1191. : mutableInstrumentations;
  1192. return (target, key, receiver) => {
  1193. if (key === "__v_isReactive" /* ReactiveFlags.IS_REACTIVE */) {
  1194. return !isReadonly;
  1195. }
  1196. else if (key === "__v_isReadonly" /* ReactiveFlags.IS_READONLY */) {
  1197. return isReadonly;
  1198. }
  1199. else if (key === "__v_raw" /* ReactiveFlags.RAW */) {
  1200. return target;
  1201. }
  1202. return Reflect.get(hasOwn(instrumentations, key) && key in target
  1203. ? instrumentations
  1204. : target, key, receiver);
  1205. };
  1206. }
  1207. const mutableCollectionHandlers = {
  1208. get: /*#__PURE__*/ createInstrumentationGetter(false, false)
  1209. };
  1210. const shallowCollectionHandlers = {
  1211. get: /*#__PURE__*/ createInstrumentationGetter(false, true)
  1212. };
  1213. const readonlyCollectionHandlers = {
  1214. get: /*#__PURE__*/ createInstrumentationGetter(true, false)
  1215. };
  1216. const shallowReadonlyCollectionHandlers = {
  1217. get: /*#__PURE__*/ createInstrumentationGetter(true, true)
  1218. };
  1219. function checkIdentityKeys(target, has, key) {
  1220. const rawKey = toRaw(key);
  1221. if (rawKey !== key && has.call(target, rawKey)) {
  1222. const type = toRawType(target);
  1223. console.warn(`Reactive ${type} contains both the raw and reactive ` +
  1224. `versions of the same object${type === `Map` ? ` as keys` : ``}, ` +
  1225. `which can lead to inconsistencies. ` +
  1226. `Avoid differentiating between the raw and reactive versions ` +
  1227. `of an object and only use the reactive version if possible.`);
  1228. }
  1229. }
  1230. const reactiveMap = new WeakMap();
  1231. const shallowReactiveMap = new WeakMap();
  1232. const readonlyMap = new WeakMap();
  1233. const shallowReadonlyMap = new WeakMap();
  1234. function targetTypeMap(rawType) {
  1235. switch (rawType) {
  1236. case 'Object':
  1237. case 'Array':
  1238. return 1 /* TargetType.COMMON */;
  1239. case 'Map':
  1240. case 'Set':
  1241. case 'WeakMap':
  1242. case 'WeakSet':
  1243. return 2 /* TargetType.COLLECTION */;
  1244. default:
  1245. return 0 /* TargetType.INVALID */;
  1246. }
  1247. }
  1248. function getTargetType(value) {
  1249. return value["__v_skip" /* ReactiveFlags.SKIP */] || !Object.isExtensible(value)
  1250. ? 0 /* TargetType.INVALID */
  1251. : targetTypeMap(toRawType(value));
  1252. }
  1253. function reactive(target) {
  1254. // if trying to observe a readonly proxy, return the readonly version.
  1255. if (isReadonly(target)) {
  1256. return target;
  1257. }
  1258. return createReactiveObject(target, false, mutableHandlers, mutableCollectionHandlers, reactiveMap);
  1259. }
  1260. /**
  1261. * Return a shallowly-reactive copy of the original object, where only the root
  1262. * level properties are reactive. It also does not auto-unwrap refs (even at the
  1263. * root level).
  1264. */
  1265. function shallowReactive(target) {
  1266. return createReactiveObject(target, false, shallowReactiveHandlers, shallowCollectionHandlers, shallowReactiveMap);
  1267. }
  1268. /**
  1269. * Creates a readonly copy of the original object. Note the returned copy is not
  1270. * made reactive, but `readonly` can be called on an already reactive object.
  1271. */
  1272. function readonly(target) {
  1273. return createReactiveObject(target, true, readonlyHandlers, readonlyCollectionHandlers, readonlyMap);
  1274. }
  1275. /**
  1276. * Returns a reactive-copy of the original object, where only the root level
  1277. * properties are readonly, and does NOT unwrap refs nor recursively convert
  1278. * returned properties.
  1279. * This is used for creating the props proxy object for stateful components.
  1280. */
  1281. function shallowReadonly(target) {
  1282. return createReactiveObject(target, true, shallowReadonlyHandlers, shallowReadonlyCollectionHandlers, shallowReadonlyMap);
  1283. }
  1284. function createReactiveObject(target, isReadonly, baseHandlers, collectionHandlers, proxyMap) {
  1285. if (!isObject(target)) {
  1286. {
  1287. console.warn(`value cannot be made reactive: ${String(target)}`);
  1288. }
  1289. return target;
  1290. }
  1291. // target is already a Proxy, return it.
  1292. // exception: calling readonly() on a reactive object
  1293. if (target["__v_raw" /* ReactiveFlags.RAW */] &&
  1294. !(isReadonly && target["__v_isReactive" /* ReactiveFlags.IS_REACTIVE */])) {
  1295. return target;
  1296. }
  1297. // target already has corresponding Proxy
  1298. const existingProxy = proxyMap.get(target);
  1299. if (existingProxy) {
  1300. return existingProxy;
  1301. }
  1302. // only specific value types can be observed.
  1303. const targetType = getTargetType(target);
  1304. if (targetType === 0 /* TargetType.INVALID */) {
  1305. return target;
  1306. }
  1307. const proxy = new Proxy(target, targetType === 2 /* TargetType.COLLECTION */ ? collectionHandlers : baseHandlers);
  1308. proxyMap.set(target, proxy);
  1309. return proxy;
  1310. }
  1311. function isReactive(value) {
  1312. if (isReadonly(value)) {
  1313. return isReactive(value["__v_raw" /* ReactiveFlags.RAW */]);
  1314. }
  1315. return !!(value && value["__v_isReactive" /* ReactiveFlags.IS_REACTIVE */]);
  1316. }
  1317. function isReadonly(value) {
  1318. return !!(value && value["__v_isReadonly" /* ReactiveFlags.IS_READONLY */]);
  1319. }
  1320. function isShallow(value) {
  1321. return !!(value && value["__v_isShallow" /* ReactiveFlags.IS_SHALLOW */]);
  1322. }
  1323. function isProxy(value) {
  1324. return isReactive(value) || isReadonly(value);
  1325. }
  1326. function toRaw(observed) {
  1327. const raw = observed && observed["__v_raw" /* ReactiveFlags.RAW */];
  1328. return raw ? toRaw(raw) : observed;
  1329. }
  1330. function markRaw(value) {
  1331. def(value, "__v_skip" /* ReactiveFlags.SKIP */, true);
  1332. return value;
  1333. }
  1334. const toReactive = (value) => isObject(value) ? reactive(value) : value;
  1335. const toReadonly = (value) => isObject(value) ? readonly(value) : value;
  1336. function trackRefValue(ref) {
  1337. if (shouldTrack && activeEffect) {
  1338. ref = toRaw(ref);
  1339. {
  1340. trackEffects(ref.dep || (ref.dep = createDep()), {
  1341. target: ref,
  1342. type: "get" /* TrackOpTypes.GET */,
  1343. key: 'value'
  1344. });
  1345. }
  1346. }
  1347. }
  1348. function triggerRefValue(ref, newVal) {
  1349. ref = toRaw(ref);
  1350. const dep = ref.dep;
  1351. if (dep) {
  1352. {
  1353. triggerEffects(dep, {
  1354. target: ref,
  1355. type: "set" /* TriggerOpTypes.SET */,
  1356. key: 'value',
  1357. newValue: newVal
  1358. });
  1359. }
  1360. }
  1361. }
  1362. function isRef(r) {
  1363. return !!(r && r.__v_isRef === true);
  1364. }
  1365. function ref(value) {
  1366. return createRef(value, false);
  1367. }
  1368. function shallowRef(value) {
  1369. return createRef(value, true);
  1370. }
  1371. function createRef(rawValue, shallow) {
  1372. if (isRef(rawValue)) {
  1373. return rawValue;
  1374. }
  1375. return new RefImpl(rawValue, shallow);
  1376. }
  1377. class RefImpl {
  1378. constructor(value, __v_isShallow) {
  1379. this.__v_isShallow = __v_isShallow;
  1380. this.dep = undefined;
  1381. this.__v_isRef = true;
  1382. this._rawValue = __v_isShallow ? value : toRaw(value);
  1383. this._value = __v_isShallow ? value : toReactive(value);
  1384. }
  1385. get value() {
  1386. trackRefValue(this);
  1387. return this._value;
  1388. }
  1389. set value(newVal) {
  1390. const useDirectValue = this.__v_isShallow || isShallow(newVal) || isReadonly(newVal);
  1391. newVal = useDirectValue ? newVal : toRaw(newVal);
  1392. if (hasChanged(newVal, this._rawValue)) {
  1393. this._rawValue = newVal;
  1394. this._value = useDirectValue ? newVal : toReactive(newVal);
  1395. triggerRefValue(this, newVal);
  1396. }
  1397. }
  1398. }
  1399. function triggerRef(ref) {
  1400. triggerRefValue(ref, ref.value );
  1401. }
  1402. function unref(ref) {
  1403. return isRef(ref) ? ref.value : ref;
  1404. }
  1405. const shallowUnwrapHandlers = {
  1406. get: (target, key, receiver) => unref(Reflect.get(target, key, receiver)),
  1407. set: (target, key, value, receiver) => {
  1408. const oldValue = target[key];
  1409. if (isRef(oldValue) && !isRef(value)) {
  1410. oldValue.value = value;
  1411. return true;
  1412. }
  1413. else {
  1414. return Reflect.set(target, key, value, receiver);
  1415. }
  1416. }
  1417. };
  1418. function proxyRefs(objectWithRefs) {
  1419. return isReactive(objectWithRefs)
  1420. ? objectWithRefs
  1421. : new Proxy(objectWithRefs, shallowUnwrapHandlers);
  1422. }
  1423. class CustomRefImpl {
  1424. constructor(factory) {
  1425. this.dep = undefined;
  1426. this.__v_isRef = true;
  1427. const { get, set } = factory(() => trackRefValue(this), () => triggerRefValue(this));
  1428. this._get = get;
  1429. this._set = set;
  1430. }
  1431. get value() {
  1432. return this._get();
  1433. }
  1434. set value(newVal) {
  1435. this._set(newVal);
  1436. }
  1437. }
  1438. function customRef(factory) {
  1439. return new CustomRefImpl(factory);
  1440. }
  1441. function toRefs(object) {
  1442. if (!isProxy(object)) {
  1443. console.warn(`toRefs() expects a reactive object but received a plain one.`);
  1444. }
  1445. const ret = isArray(object) ? new Array(object.length) : {};
  1446. for (const key in object) {
  1447. ret[key] = toRef(object, key);
  1448. }
  1449. return ret;
  1450. }
  1451. class ObjectRefImpl {
  1452. constructor(_object, _key, _defaultValue) {
  1453. this._object = _object;
  1454. this._key = _key;
  1455. this._defaultValue = _defaultValue;
  1456. this.__v_isRef = true;
  1457. }
  1458. get value() {
  1459. const val = this._object[this._key];
  1460. return val === undefined ? this._defaultValue : val;
  1461. }
  1462. set value(newVal) {
  1463. this._object[this._key] = newVal;
  1464. }
  1465. get dep() {
  1466. return getDepFromReactive(toRaw(this._object), this._key);
  1467. }
  1468. }
  1469. function toRef(object, key, defaultValue) {
  1470. const val = object[key];
  1471. return isRef(val)
  1472. ? val
  1473. : new ObjectRefImpl(object, key, defaultValue);
  1474. }
  1475. var _a;
  1476. class ComputedRefImpl {
  1477. constructor(getter, _setter, isReadonly, isSSR) {
  1478. this._setter = _setter;
  1479. this.dep = undefined;
  1480. this.__v_isRef = true;
  1481. this[_a] = false;
  1482. this._dirty = true;
  1483. this.effect = new ReactiveEffect(getter, () => {
  1484. if (!this._dirty) {
  1485. this._dirty = true;
  1486. triggerRefValue(this);
  1487. }
  1488. });
  1489. this.effect.computed = this;
  1490. this.effect.active = this._cacheable = !isSSR;
  1491. this["__v_isReadonly" /* ReactiveFlags.IS_READONLY */] = isReadonly;
  1492. }
  1493. get value() {
  1494. // the computed ref may get wrapped by other proxies e.g. readonly() #3376
  1495. const self = toRaw(this);
  1496. trackRefValue(self);
  1497. if (self._dirty || !self._cacheable) {
  1498. self._dirty = false;
  1499. self._value = self.effect.run();
  1500. }
  1501. return self._value;
  1502. }
  1503. set value(newValue) {
  1504. this._setter(newValue);
  1505. }
  1506. }
  1507. _a = "__v_isReadonly" /* ReactiveFlags.IS_READONLY */;
  1508. function computed$1(getterOrOptions, debugOptions, isSSR = false) {
  1509. let getter;
  1510. let setter;
  1511. const onlyGetter = isFunction(getterOrOptions);
  1512. if (onlyGetter) {
  1513. getter = getterOrOptions;
  1514. setter = () => {
  1515. console.warn('Write operation failed: computed value is readonly');
  1516. }
  1517. ;
  1518. }
  1519. else {
  1520. getter = getterOrOptions.get;
  1521. setter = getterOrOptions.set;
  1522. }
  1523. const cRef = new ComputedRefImpl(getter, setter, onlyGetter || !setter, isSSR);
  1524. if (debugOptions && !isSSR) {
  1525. cRef.effect.onTrack = debugOptions.onTrack;
  1526. cRef.effect.onTrigger = debugOptions.onTrigger;
  1527. }
  1528. return cRef;
  1529. }
  1530. const stack = [];
  1531. function pushWarningContext(vnode) {
  1532. stack.push(vnode);
  1533. }
  1534. function popWarningContext() {
  1535. stack.pop();
  1536. }
  1537. function warn(msg, ...args) {
  1538. // avoid props formatting or warn handler tracking deps that might be mutated
  1539. // during patch, leading to infinite recursion.
  1540. pauseTracking();
  1541. const instance = stack.length ? stack[stack.length - 1].component : null;
  1542. const appWarnHandler = instance && instance.appContext.config.warnHandler;
  1543. const trace = getComponentTrace();
  1544. if (appWarnHandler) {
  1545. callWithErrorHandling(appWarnHandler, instance, 11 /* ErrorCodes.APP_WARN_HANDLER */, [
  1546. msg + args.join(''),
  1547. instance && instance.proxy,
  1548. trace
  1549. .map(({ vnode }) => `at <${formatComponentName(instance, vnode.type)}>`)
  1550. .join('\n'),
  1551. trace
  1552. ]);
  1553. }
  1554. else {
  1555. const warnArgs = [`[Vue warn]: ${msg}`, ...args];
  1556. /* istanbul ignore if */
  1557. if (trace.length &&
  1558. // avoid spamming console during tests
  1559. !false) {
  1560. warnArgs.push(`\n`, ...formatTrace(trace));
  1561. }
  1562. console.warn(...warnArgs);
  1563. }
  1564. resetTracking();
  1565. }
  1566. function getComponentTrace() {
  1567. let currentVNode = stack[stack.length - 1];
  1568. if (!currentVNode) {
  1569. return [];
  1570. }
  1571. // we can't just use the stack because it will be incomplete during updates
  1572. // that did not start from the root. Re-construct the parent chain using
  1573. // instance parent pointers.
  1574. const normalizedStack = [];
  1575. while (currentVNode) {
  1576. const last = normalizedStack[0];
  1577. if (last && last.vnode === currentVNode) {
  1578. last.recurseCount++;
  1579. }
  1580. else {
  1581. normalizedStack.push({
  1582. vnode: currentVNode,
  1583. recurseCount: 0
  1584. });
  1585. }
  1586. const parentInstance = currentVNode.component && currentVNode.component.parent;
  1587. currentVNode = parentInstance && parentInstance.vnode;
  1588. }
  1589. return normalizedStack;
  1590. }
  1591. /* istanbul ignore next */
  1592. function formatTrace(trace) {
  1593. const logs = [];
  1594. trace.forEach((entry, i) => {
  1595. logs.push(...(i === 0 ? [] : [`\n`]), ...formatTraceEntry(entry));
  1596. });
  1597. return logs;
  1598. }
  1599. function formatTraceEntry({ vnode, recurseCount }) {
  1600. const postfix = recurseCount > 0 ? `... (${recurseCount} recursive calls)` : ``;
  1601. const isRoot = vnode.component ? vnode.component.parent == null : false;
  1602. const open = ` at <${formatComponentName(vnode.component, vnode.type, isRoot)}`;
  1603. const close = `>` + postfix;
  1604. return vnode.props
  1605. ? [open, ...formatProps(vnode.props), close]
  1606. : [open + close];
  1607. }
  1608. /* istanbul ignore next */
  1609. function formatProps(props) {
  1610. const res = [];
  1611. const keys = Object.keys(props);
  1612. keys.slice(0, 3).forEach(key => {
  1613. res.push(...formatProp(key, props[key]));
  1614. });
  1615. if (keys.length > 3) {
  1616. res.push(` ...`);
  1617. }
  1618. return res;
  1619. }
  1620. /* istanbul ignore next */
  1621. function formatProp(key, value, raw) {
  1622. if (isString(value)) {
  1623. value = JSON.stringify(value);
  1624. return raw ? value : [`${key}=${value}`];
  1625. }
  1626. else if (typeof value === 'number' ||
  1627. typeof value === 'boolean' ||
  1628. value == null) {
  1629. return raw ? value : [`${key}=${value}`];
  1630. }
  1631. else if (isRef(value)) {
  1632. value = formatProp(key, toRaw(value.value), true);
  1633. return raw ? value : [`${key}=Ref<`, value, `>`];
  1634. }
  1635. else if (isFunction(value)) {
  1636. return [`${key}=fn${value.name ? `<${value.name}>` : ``}`];
  1637. }
  1638. else {
  1639. value = toRaw(value);
  1640. return raw ? value : [`${key}=`, value];
  1641. }
  1642. }
  1643. /**
  1644. * @internal
  1645. */
  1646. function assertNumber(val, type) {
  1647. if (val === undefined) {
  1648. return;
  1649. }
  1650. else if (typeof val !== 'number') {
  1651. warn(`${type} is not a valid number - ` + `got ${JSON.stringify(val)}.`);
  1652. }
  1653. else if (isNaN(val)) {
  1654. warn(`${type} is NaN - ` + 'the duration expression might be incorrect.');
  1655. }
  1656. }
  1657. const ErrorTypeStrings = {
  1658. ["sp" /* LifecycleHooks.SERVER_PREFETCH */]: 'serverPrefetch hook',
  1659. ["bc" /* LifecycleHooks.BEFORE_CREATE */]: 'beforeCreate hook',
  1660. ["c" /* LifecycleHooks.CREATED */]: 'created hook',
  1661. ["bm" /* LifecycleHooks.BEFORE_MOUNT */]: 'beforeMount hook',
  1662. ["m" /* LifecycleHooks.MOUNTED */]: 'mounted hook',
  1663. ["bu" /* LifecycleHooks.BEFORE_UPDATE */]: 'beforeUpdate hook',
  1664. ["u" /* LifecycleHooks.UPDATED */]: 'updated',
  1665. ["bum" /* LifecycleHooks.BEFORE_UNMOUNT */]: 'beforeUnmount hook',
  1666. ["um" /* LifecycleHooks.UNMOUNTED */]: 'unmounted hook',
  1667. ["a" /* LifecycleHooks.ACTIVATED */]: 'activated hook',
  1668. ["da" /* LifecycleHooks.DEACTIVATED */]: 'deactivated hook',
  1669. ["ec" /* LifecycleHooks.ERROR_CAPTURED */]: 'errorCaptured hook',
  1670. ["rtc" /* LifecycleHooks.RENDER_TRACKED */]: 'renderTracked hook',
  1671. ["rtg" /* LifecycleHooks.RENDER_TRIGGERED */]: 'renderTriggered hook',
  1672. [0 /* ErrorCodes.SETUP_FUNCTION */]: 'setup function',
  1673. [1 /* ErrorCodes.RENDER_FUNCTION */]: 'render function',
  1674. [2 /* ErrorCodes.WATCH_GETTER */]: 'watcher getter',
  1675. [3 /* ErrorCodes.WATCH_CALLBACK */]: 'watcher callback',
  1676. [4 /* ErrorCodes.WATCH_CLEANUP */]: 'watcher cleanup function',
  1677. [5 /* ErrorCodes.NATIVE_EVENT_HANDLER */]: 'native event handler',
  1678. [6 /* ErrorCodes.COMPONENT_EVENT_HANDLER */]: 'component event handler',
  1679. [7 /* ErrorCodes.VNODE_HOOK */]: 'vnode hook',
  1680. [8 /* ErrorCodes.DIRECTIVE_HOOK */]: 'directive hook',
  1681. [9 /* ErrorCodes.TRANSITION_HOOK */]: 'transition hook',
  1682. [10 /* ErrorCodes.APP_ERROR_HANDLER */]: 'app errorHandler',
  1683. [11 /* ErrorCodes.APP_WARN_HANDLER */]: 'app warnHandler',
  1684. [12 /* ErrorCodes.FUNCTION_REF */]: 'ref function',
  1685. [13 /* ErrorCodes.ASYNC_COMPONENT_LOADER */]: 'async component loader',
  1686. [14 /* ErrorCodes.SCHEDULER */]: 'scheduler flush. This is likely a Vue internals bug. ' +
  1687. 'Please open an issue at https://new-issue.vuejs.org/?repo=vuejs/core'
  1688. };
  1689. function callWithErrorHandling(fn, instance, type, args) {
  1690. let res;
  1691. try {
  1692. res = args ? fn(...args) : fn();
  1693. }
  1694. catch (err) {
  1695. handleError(err, instance, type);
  1696. }
  1697. return res;
  1698. }
  1699. function callWithAsyncErrorHandling(fn, instance, type, args) {
  1700. if (isFunction(fn)) {
  1701. const res = callWithErrorHandling(fn, instance, type, args);
  1702. if (res && isPromise(res)) {
  1703. res.catch(err => {
  1704. handleError(err, instance, type);
  1705. });
  1706. }
  1707. return res;
  1708. }
  1709. const values = [];
  1710. for (let i = 0; i < fn.length; i++) {
  1711. values.push(callWithAsyncErrorHandling(fn[i], instance, type, args));
  1712. }
  1713. return values;
  1714. }
  1715. function handleError(err, instance, type, throwInDev = true) {
  1716. const contextVNode = instance ? instance.vnode : null;
  1717. if (instance) {
  1718. let cur = instance.parent;
  1719. // the exposed instance is the render proxy to keep it consistent with 2.x
  1720. const exposedInstance = instance.proxy;
  1721. // in production the hook receives only the error code
  1722. const errorInfo = ErrorTypeStrings[type] ;
  1723. while (cur) {
  1724. const errorCapturedHooks = cur.ec;
  1725. if (errorCapturedHooks) {
  1726. for (let i = 0; i < errorCapturedHooks.length; i++) {
  1727. if (errorCapturedHooks[i](err, exposedInstance, errorInfo) === false) {
  1728. return;
  1729. }
  1730. }
  1731. }
  1732. cur = cur.parent;
  1733. }
  1734. // app-level handling
  1735. const appErrorHandler = instance.appContext.config.errorHandler;
  1736. if (appErrorHandler) {
  1737. callWithErrorHandling(appErrorHandler, null, 10 /* ErrorCodes.APP_ERROR_HANDLER */, [err, exposedInstance, errorInfo]);
  1738. return;
  1739. }
  1740. }
  1741. logError(err, type, contextVNode, throwInDev);
  1742. }
  1743. function logError(err, type, contextVNode, throwInDev = true) {
  1744. {
  1745. const info = ErrorTypeStrings[type];
  1746. if (contextVNode) {
  1747. pushWarningContext(contextVNode);
  1748. }
  1749. warn(`Unhandled error${info ? ` during execution of ${info}` : ``}`);
  1750. if (contextVNode) {
  1751. popWarningContext();
  1752. }
  1753. // crash in dev by default so it's more noticeable
  1754. if (throwInDev) {
  1755. throw err;
  1756. }
  1757. else {
  1758. console.error(err);
  1759. }
  1760. }
  1761. }
  1762. let isFlushing = false;
  1763. let isFlushPending = false;
  1764. const queue = [];
  1765. let flushIndex = 0;
  1766. const pendingPostFlushCbs = [];
  1767. let activePostFlushCbs = null;
  1768. let postFlushIndex = 0;
  1769. const resolvedPromise = /*#__PURE__*/ Promise.resolve();
  1770. let currentFlushPromise = null;
  1771. const RECURSION_LIMIT = 100;
  1772. function nextTick(fn) {
  1773. const p = currentFlushPromise || resolvedPromise;
  1774. return fn ? p.then(this ? fn.bind(this) : fn) : p;
  1775. }
  1776. // #2768
  1777. // Use binary-search to find a suitable position in the queue,
  1778. // so that the queue maintains the increasing order of job's id,
  1779. // which can prevent the job from being skipped and also can avoid repeated patching.
  1780. function findInsertionIndex(id) {
  1781. // the start index should be `flushIndex + 1`
  1782. let start = flushIndex + 1;
  1783. let end = queue.length;
  1784. while (start < end) {
  1785. const middle = (start + end) >>> 1;
  1786. const middleJobId = getId(queue[middle]);
  1787. middleJobId < id ? (start = middle + 1) : (end = middle);
  1788. }
  1789. return start;
  1790. }
  1791. function queueJob(job) {
  1792. // the dedupe search uses the startIndex argument of Array.includes()
  1793. // by default the search index includes the current job that is being run
  1794. // so it cannot recursively trigger itself again.
  1795. // if the job is a watch() callback, the search will start with a +1 index to
  1796. // allow it recursively trigger itself - it is the user's responsibility to
  1797. // ensure it doesn't end up in an infinite loop.
  1798. if (!queue.length ||
  1799. !queue.includes(job, isFlushing && job.allowRecurse ? flushIndex + 1 : flushIndex)) {
  1800. if (job.id == null) {
  1801. queue.push(job);
  1802. }
  1803. else {
  1804. queue.splice(findInsertionIndex(job.id), 0, job);
  1805. }
  1806. queueFlush();
  1807. }
  1808. }
  1809. function queueFlush() {
  1810. if (!isFlushing && !isFlushPending) {
  1811. isFlushPending = true;
  1812. currentFlushPromise = resolvedPromise.then(flushJobs);
  1813. }
  1814. }
  1815. function invalidateJob(job) {
  1816. const i = queue.indexOf(job);
  1817. if (i > flushIndex) {
  1818. queue.splice(i, 1);
  1819. }
  1820. }
  1821. function queuePostFlushCb(cb) {
  1822. if (!isArray(cb)) {
  1823. if (!activePostFlushCbs ||
  1824. !activePostFlushCbs.includes(cb, cb.allowRecurse ? postFlushIndex + 1 : postFlushIndex)) {
  1825. pendingPostFlushCbs.push(cb);
  1826. }
  1827. }
  1828. else {
  1829. // if cb is an array, it is a component lifecycle hook which can only be
  1830. // triggered by a job, which is already deduped in the main queue, so
  1831. // we can skip duplicate check here to improve perf
  1832. pendingPostFlushCbs.push(...cb);
  1833. }
  1834. queueFlush();
  1835. }
  1836. function flushPreFlushCbs(seen,
  1837. // if currently flushing, skip the current job itself
  1838. i = isFlushing ? flushIndex + 1 : 0) {
  1839. {
  1840. seen = seen || new Map();
  1841. }
  1842. for (; i < queue.length; i++) {
  1843. const cb = queue[i];
  1844. if (cb && cb.pre) {
  1845. if (checkRecursiveUpdates(seen, cb)) {
  1846. continue;
  1847. }
  1848. queue.splice(i, 1);
  1849. i--;
  1850. cb();
  1851. }
  1852. }
  1853. }
  1854. function flushPostFlushCbs(seen) {
  1855. if (pendingPostFlushCbs.length) {
  1856. const deduped = [...new Set(pendingPostFlushCbs)];
  1857. pendingPostFlushCbs.length = 0;
  1858. // #1947 already has active queue, nested flushPostFlushCbs call
  1859. if (activePostFlushCbs) {
  1860. activePostFlushCbs.push(...deduped);
  1861. return;
  1862. }
  1863. activePostFlushCbs = deduped;
  1864. {
  1865. seen = seen || new Map();
  1866. }
  1867. activePostFlushCbs.sort((a, b) => getId(a) - getId(b));
  1868. for (postFlushIndex = 0; postFlushIndex < activePostFlushCbs.length; postFlushIndex++) {
  1869. if (checkRecursiveUpdates(seen, activePostFlushCbs[postFlushIndex])) {
  1870. continue;
  1871. }
  1872. activePostFlushCbs[postFlushIndex]();
  1873. }
  1874. activePostFlushCbs = null;
  1875. postFlushIndex = 0;
  1876. }
  1877. }
  1878. const getId = (job) => job.id == null ? Infinity : job.id;
  1879. const comparator = (a, b) => {
  1880. const diff = getId(a) - getId(b);
  1881. if (diff === 0) {
  1882. if (a.pre && !b.pre)
  1883. return -1;
  1884. if (b.pre && !a.pre)
  1885. return 1;
  1886. }
  1887. return diff;
  1888. };
  1889. function flushJobs(seen) {
  1890. isFlushPending = false;
  1891. isFlushing = true;
  1892. {
  1893. seen = seen || new Map();
  1894. }
  1895. // Sort queue before flush.
  1896. // This ensures that:
  1897. // 1. Components are updated from parent to child. (because parent is always
  1898. // created before the child so its render effect will have smaller
  1899. // priority number)
  1900. // 2. If a component is unmounted during a parent component's update,
  1901. // its update can be skipped.
  1902. queue.sort(comparator);
  1903. // conditional usage of checkRecursiveUpdate must be determined out of
  1904. // try ... catch block since Rollup by default de-optimizes treeshaking
  1905. // inside try-catch. This can leave all warning code unshaked. Although
  1906. // they would get eventually shaken by a minifier like terser, some minifiers
  1907. // would fail to do that (e.g. https://github.com/evanw/esbuild/issues/1610)
  1908. const check = (job) => checkRecursiveUpdates(seen, job)
  1909. ;
  1910. try {
  1911. for (flushIndex = 0; flushIndex < queue.length; flushIndex++) {
  1912. const job = queue[flushIndex];
  1913. if (job && job.active !== false) {
  1914. if (true && check(job)) {
  1915. continue;
  1916. }
  1917. // console.log(`running:`, job.id)
  1918. callWithErrorHandling(job, null, 14 /* ErrorCodes.SCHEDULER */);
  1919. }
  1920. }
  1921. }
  1922. finally {
  1923. flushIndex = 0;
  1924. queue.length = 0;
  1925. flushPostFlushCbs(seen);
  1926. isFlushing = false;
  1927. currentFlushPromise = null;
  1928. // some postFlushCb queued jobs!
  1929. // keep flushing until it drains.
  1930. if (queue.length || pendingPostFlushCbs.length) {
  1931. flushJobs(seen);
  1932. }
  1933. }
  1934. }
  1935. function checkRecursiveUpdates(seen, fn) {
  1936. if (!seen.has(fn)) {
  1937. seen.set(fn, 1);
  1938. }
  1939. else {
  1940. const count = seen.get(fn);
  1941. if (count > RECURSION_LIMIT) {
  1942. const instance = fn.ownerInstance;
  1943. const componentName = instance && getComponentName(instance.type);
  1944. warn(`Maximum recursive updates exceeded${componentName ? ` in component <${componentName}>` : ``}. ` +
  1945. `This means you have a reactive effect that is mutating its own ` +
  1946. `dependencies and thus recursively triggering itself. Possible sources ` +
  1947. `include component template, render function, updated hook or ` +
  1948. `watcher source function.`);
  1949. return true;
  1950. }
  1951. else {
  1952. seen.set(fn, count + 1);
  1953. }
  1954. }
  1955. }
  1956. /* eslint-disable no-restricted-globals */
  1957. let isHmrUpdating = false;
  1958. const hmrDirtyComponents = new Set();
  1959. // Expose the HMR runtime on the global object
  1960. // This makes it entirely tree-shakable without polluting the exports and makes
  1961. // it easier to be used in toolings like vue-loader
  1962. // Note: for a component to be eligible for HMR it also needs the __hmrId option
  1963. // to be set so that its instances can be registered / removed.
  1964. {
  1965. getGlobalThis().__VUE_HMR_RUNTIME__ = {
  1966. createRecord: tryWrap(createRecord),
  1967. rerender: tryWrap(rerender),
  1968. reload: tryWrap(reload)
  1969. };
  1970. }
  1971. const map = new Map();
  1972. function registerHMR(instance) {
  1973. const id = instance.type.__hmrId;
  1974. let record = map.get(id);
  1975. if (!record) {
  1976. createRecord(id, instance.type);
  1977. record = map.get(id);
  1978. }
  1979. record.instances.add(instance);
  1980. }
  1981. function unregisterHMR(instance) {
  1982. map.get(instance.type.__hmrId).instances.delete(instance);
  1983. }
  1984. function createRecord(id, initialDef) {
  1985. if (map.has(id)) {
  1986. return false;
  1987. }
  1988. map.set(id, {
  1989. initialDef: normalizeClassComponent(initialDef),
  1990. instances: new Set()
  1991. });
  1992. return true;
  1993. }
  1994. function normalizeClassComponent(component) {
  1995. return isClassComponent(component) ? component.__vccOpts : component;
  1996. }
  1997. function rerender(id, newRender) {
  1998. const record = map.get(id);
  1999. if (!record) {
  2000. return;
  2001. }
  2002. // update initial record (for not-yet-rendered component)
  2003. record.initialDef.render = newRender;
  2004. [...record.instances].forEach(instance => {
  2005. if (newRender) {
  2006. instance.render = newRender;
  2007. normalizeClassComponent(instance.type).render = newRender;
  2008. }
  2009. instance.renderCache = [];
  2010. // this flag forces child components with slot content to update
  2011. isHmrUpdating = true;
  2012. instance.update();
  2013. isHmrUpdating = false;
  2014. });
  2015. }
  2016. function reload(id, newComp) {
  2017. const record = map.get(id);
  2018. if (!record)
  2019. return;
  2020. newComp = normalizeClassComponent(newComp);
  2021. // update initial def (for not-yet-rendered components)
  2022. updateComponentDef(record.initialDef, newComp);
  2023. // create a snapshot which avoids the set being mutated during updates
  2024. const instances = [...record.instances];
  2025. for (const instance of instances) {
  2026. const oldComp = normalizeClassComponent(instance.type);
  2027. if (!hmrDirtyComponents.has(oldComp)) {
  2028. // 1. Update existing comp definition to match new one
  2029. if (oldComp !== record.initialDef) {
  2030. updateComponentDef(oldComp, newComp);
  2031. }
  2032. // 2. mark definition dirty. This forces the renderer to replace the
  2033. // component on patch.
  2034. hmrDirtyComponents.add(oldComp);
  2035. }
  2036. // 3. invalidate options resolution cache
  2037. instance.appContext.optionsCache.delete(instance.type);
  2038. // 4. actually update
  2039. if (instance.ceReload) {
  2040. // custom element
  2041. hmrDirtyComponents.add(oldComp);
  2042. instance.ceReload(newComp.styles);
  2043. hmrDirtyComponents.delete(oldComp);
  2044. }
  2045. else if (instance.parent) {
  2046. // 4. Force the parent instance to re-render. This will cause all updated
  2047. // components to be unmounted and re-mounted. Queue the update so that we
  2048. // don't end up forcing the same parent to re-render multiple times.
  2049. queueJob(instance.parent.update);
  2050. }
  2051. else if (instance.appContext.reload) {
  2052. // root instance mounted via createApp() has a reload method
  2053. instance.appContext.reload();
  2054. }
  2055. else if (typeof window !== 'undefined') {
  2056. // root instance inside tree created via raw render(). Force reload.
  2057. window.location.reload();
  2058. }
  2059. else {
  2060. console.warn('[HMR] Root or manually mounted instance modified. Full reload required.');
  2061. }
  2062. }
  2063. // 5. make sure to cleanup dirty hmr components after update
  2064. queuePostFlushCb(() => {
  2065. for (const instance of instances) {
  2066. hmrDirtyComponents.delete(normalizeClassComponent(instance.type));
  2067. }
  2068. });
  2069. }
  2070. function updateComponentDef(oldComp, newComp) {
  2071. extend(oldComp, newComp);
  2072. for (const key in oldComp) {
  2073. if (key !== '__file' && !(key in newComp)) {
  2074. delete oldComp[key];
  2075. }
  2076. }
  2077. }
  2078. function tryWrap(fn) {
  2079. return (id, arg) => {
  2080. try {
  2081. return fn(id, arg);
  2082. }
  2083. catch (e) {
  2084. console.error(e);
  2085. console.warn(`[HMR] Something went wrong during Vue component hot-reload. ` +
  2086. `Full reload required.`);
  2087. }
  2088. };
  2089. }
  2090. let devtools;
  2091. let buffer = [];
  2092. let devtoolsNotInstalled = false;
  2093. function emit$1(event, ...args) {
  2094. if (devtools) {
  2095. devtools.emit(event, ...args);
  2096. }
  2097. else if (!devtoolsNotInstalled) {
  2098. buffer.push({ event, args });
  2099. }
  2100. }
  2101. function setDevtoolsHook(hook, target) {
  2102. var _a, _b;
  2103. devtools = hook;
  2104. if (devtools) {
  2105. devtools.enabled = true;
  2106. buffer.forEach(({ event, args }) => devtools.emit(event, ...args));
  2107. buffer = [];
  2108. }
  2109. else if (
  2110. // handle late devtools injection - only do this if we are in an actual
  2111. // browser environment to avoid the timer handle stalling test runner exit
  2112. // (#4815)
  2113. typeof window !== 'undefined' &&
  2114. // some envs mock window but not fully
  2115. window.HTMLElement &&
  2116. // also exclude jsdom
  2117. !((_b = (_a = window.navigator) === null || _a === void 0 ? void 0 : _a.userAgent) === null || _b === void 0 ? void 0 : _b.includes('jsdom'))) {
  2118. const replay = (target.__VUE_DEVTOOLS_HOOK_REPLAY__ =
  2119. target.__VUE_DEVTOOLS_HOOK_REPLAY__ || []);
  2120. replay.push((newHook) => {
  2121. setDevtoolsHook(newHook, target);
  2122. });
  2123. // clear buffer after 3s - the user probably doesn't have devtools installed
  2124. // at all, and keeping the buffer will cause memory leaks (#4738)
  2125. setTimeout(() => {
  2126. if (!devtools) {
  2127. target.__VUE_DEVTOOLS_HOOK_REPLAY__ = null;
  2128. devtoolsNotInstalled = true;
  2129. buffer = [];
  2130. }
  2131. }, 3000);
  2132. }
  2133. else {
  2134. // non-browser env, assume not installed
  2135. devtoolsNotInstalled = true;
  2136. buffer = [];
  2137. }
  2138. }
  2139. function devtoolsInitApp(app, version) {
  2140. emit$1("app:init" /* DevtoolsHooks.APP_INIT */, app, version, {
  2141. Fragment,
  2142. Text,
  2143. Comment,
  2144. Static
  2145. });
  2146. }
  2147. function devtoolsUnmountApp(app) {
  2148. emit$1("app:unmount" /* DevtoolsHooks.APP_UNMOUNT */, app);
  2149. }
  2150. const devtoolsComponentAdded = /*#__PURE__*/ createDevtoolsComponentHook("component:added" /* DevtoolsHooks.COMPONENT_ADDED */);
  2151. const devtoolsComponentUpdated =
  2152. /*#__PURE__*/ createDevtoolsComponentHook("component:updated" /* DevtoolsHooks.COMPONENT_UPDATED */);
  2153. const _devtoolsComponentRemoved = /*#__PURE__*/ createDevtoolsComponentHook("component:removed" /* DevtoolsHooks.COMPONENT_REMOVED */);
  2154. const devtoolsComponentRemoved = (component) => {
  2155. if (devtools &&
  2156. typeof devtools.cleanupBuffer === 'function' &&
  2157. // remove the component if it wasn't buffered
  2158. !devtools.cleanupBuffer(component)) {
  2159. _devtoolsComponentRemoved(component);
  2160. }
  2161. };
  2162. function createDevtoolsComponentHook(hook) {
  2163. return (component) => {
  2164. emit$1(hook, component.appContext.app, component.uid, component.parent ? component.parent.uid : undefined, component);
  2165. };
  2166. }
  2167. const devtoolsPerfStart = /*#__PURE__*/ createDevtoolsPerformanceHook("perf:start" /* DevtoolsHooks.PERFORMANCE_START */);
  2168. const devtoolsPerfEnd = /*#__PURE__*/ createDevtoolsPerformanceHook("perf:end" /* DevtoolsHooks.PERFORMANCE_END */);
  2169. function createDevtoolsPerformanceHook(hook) {
  2170. return (component, type, time) => {
  2171. emit$1(hook, component.appContext.app, component.uid, component, type, time);
  2172. };
  2173. }
  2174. function devtoolsComponentEmit(component, event, params) {
  2175. emit$1("component:emit" /* DevtoolsHooks.COMPONENT_EMIT */, component.appContext.app, component, event, params);
  2176. }
  2177. function emit(instance, event, ...rawArgs) {
  2178. if (instance.isUnmounted)
  2179. return;
  2180. const props = instance.vnode.props || EMPTY_OBJ;
  2181. {
  2182. const { emitsOptions, propsOptions: [propsOptions] } = instance;
  2183. if (emitsOptions) {
  2184. if (!(event in emitsOptions) &&
  2185. !(false )) {
  2186. if (!propsOptions || !(toHandlerKey(event) in propsOptions)) {
  2187. warn(`Component emitted event "${event}" but it is neither declared in ` +
  2188. `the emits option nor as an "${toHandlerKey(event)}" prop.`);
  2189. }
  2190. }
  2191. else {
  2192. const validator = emitsOptions[event];
  2193. if (isFunction(validator)) {
  2194. const isValid = validator(...rawArgs);
  2195. if (!isValid) {
  2196. warn(`Invalid event arguments: event validation failed for event "${event}".`);
  2197. }
  2198. }
  2199. }
  2200. }
  2201. }
  2202. let args = rawArgs;
  2203. const isModelListener = event.startsWith('update:');
  2204. // for v-model update:xxx events, apply modifiers on args
  2205. const modelArg = isModelListener && event.slice(7);
  2206. if (modelArg && modelArg in props) {
  2207. const modifiersKey = `${modelArg === 'modelValue' ? 'model' : modelArg}Modifiers`;
  2208. const { number, trim } = props[modifiersKey] || EMPTY_OBJ;
  2209. if (trim) {
  2210. args = rawArgs.map(a => (isString(a) ? a.trim() : a));
  2211. }
  2212. if (number) {
  2213. args = rawArgs.map(looseToNumber);
  2214. }
  2215. }
  2216. {
  2217. devtoolsComponentEmit(instance, event, args);
  2218. }
  2219. {
  2220. const lowerCaseEvent = event.toLowerCase();
  2221. if (lowerCaseEvent !== event && props[toHandlerKey(lowerCaseEvent)]) {
  2222. warn(`Event "${lowerCaseEvent}" is emitted in component ` +
  2223. `${formatComponentName(instance, instance.type)} but the handler is registered for "${event}". ` +
  2224. `Note that HTML attributes are case-insensitive and you cannot use ` +
  2225. `v-on to listen to camelCase events when using in-DOM templates. ` +
  2226. `You should probably use "${hyphenate(event)}" instead of "${event}".`);
  2227. }
  2228. }
  2229. let handlerName;
  2230. let handler = props[(handlerName = toHandlerKey(event))] ||
  2231. // also try camelCase event handler (#2249)
  2232. props[(handlerName = toHandlerKey(camelize(event)))];
  2233. // for v-model update:xxx events, also trigger kebab-case equivalent
  2234. // for props passed via kebab-case
  2235. if (!handler && isModelListener) {
  2236. handler = props[(handlerName = toHandlerKey(hyphenate(event)))];
  2237. }
  2238. if (handler) {
  2239. callWithAsyncErrorHandling(handler, instance, 6 /* ErrorCodes.COMPONENT_EVENT_HANDLER */, args);
  2240. }
  2241. const onceHandler = props[handlerName + `Once`];
  2242. if (onceHandler) {
  2243. if (!instance.emitted) {
  2244. instance.emitted = {};
  2245. }
  2246. else if (instance.emitted[handlerName]) {
  2247. return;
  2248. }
  2249. instance.emitted[handlerName] = true;
  2250. callWithAsyncErrorHandling(onceHandler, instance, 6 /* ErrorCodes.COMPONENT_EVENT_HANDLER */, args);
  2251. }
  2252. }
  2253. function normalizeEmitsOptions(comp, appContext, asMixin = false) {
  2254. const cache = appContext.emitsCache;
  2255. const cached = cache.get(comp);
  2256. if (cached !== undefined) {
  2257. return cached;
  2258. }
  2259. const raw = comp.emits;
  2260. let normalized = {};
  2261. // apply mixin/extends props
  2262. let hasExtends = false;
  2263. if (!isFunction(comp)) {
  2264. const extendEmits = (raw) => {
  2265. const normalizedFromExtend = normalizeEmitsOptions(raw, appContext, true);
  2266. if (normalizedFromExtend) {
  2267. hasExtends = true;
  2268. extend(normalized, normalizedFromExtend);
  2269. }
  2270. };
  2271. if (!asMixin && appContext.mixins.length) {
  2272. appContext.mixins.forEach(extendEmits);
  2273. }
  2274. if (comp.extends) {
  2275. extendEmits(comp.extends);
  2276. }
  2277. if (comp.mixins) {
  2278. comp.mixins.forEach(extendEmits);
  2279. }
  2280. }
  2281. if (!raw && !hasExtends) {
  2282. if (isObject(comp)) {
  2283. cache.set(comp, null);
  2284. }
  2285. return null;
  2286. }
  2287. if (isArray(raw)) {
  2288. raw.forEach(key => (normalized[key] = null));
  2289. }
  2290. else {
  2291. extend(normalized, raw);
  2292. }
  2293. if (isObject(comp)) {
  2294. cache.set(comp, normalized);
  2295. }
  2296. return normalized;
  2297. }
  2298. // Check if an incoming prop key is a declared emit event listener.
  2299. // e.g. With `emits: { click: null }`, props named `onClick` and `onclick` are
  2300. // both considered matched listeners.
  2301. function isEmitListener(options, key) {
  2302. if (!options || !isOn(key)) {
  2303. return false;
  2304. }
  2305. key = key.slice(2).replace(/Once$/, '');
  2306. return (hasOwn(options, key[0].toLowerCase() + key.slice(1)) ||
  2307. hasOwn(options, hyphenate(key)) ||
  2308. hasOwn(options, key));
  2309. }
  2310. /**
  2311. * mark the current rendering instance for asset resolution (e.g.
  2312. * resolveComponent, resolveDirective) during render
  2313. */
  2314. let currentRenderingInstance = null;
  2315. let currentScopeId = null;
  2316. /**
  2317. * Note: rendering calls maybe nested. The function returns the parent rendering
  2318. * instance if present, which should be restored after the render is done:
  2319. *
  2320. * ```js
  2321. * const prev = setCurrentRenderingInstance(i)
  2322. * // ...render
  2323. * setCurrentRenderingInstance(prev)
  2324. * ```
  2325. */
  2326. function setCurrentRenderingInstance(instance) {
  2327. const prev = currentRenderingInstance;
  2328. currentRenderingInstance = instance;
  2329. currentScopeId = (instance && instance.type.__scopeId) || null;
  2330. return prev;
  2331. }
  2332. /**
  2333. * Set scope id when creating hoisted vnodes.
  2334. * @private compiler helper
  2335. */
  2336. function pushScopeId(id) {
  2337. currentScopeId = id;
  2338. }
  2339. /**
  2340. * Technically we no longer need this after 3.0.8 but we need to keep the same
  2341. * API for backwards compat w/ code generated by compilers.
  2342. * @private
  2343. */
  2344. function popScopeId() {
  2345. currentScopeId = null;
  2346. }
  2347. /**
  2348. * Only for backwards compat
  2349. * @private
  2350. */
  2351. const withScopeId = (_id) => withCtx;
  2352. /**
  2353. * Wrap a slot function to memoize current rendering instance
  2354. * @private compiler helper
  2355. */
  2356. function withCtx(fn, ctx = currentRenderingInstance, isNonScopedSlot // false only
  2357. ) {
  2358. if (!ctx)
  2359. return fn;
  2360. // already normalized
  2361. if (fn._n) {
  2362. return fn;
  2363. }
  2364. const renderFnWithContext = (...args) => {
  2365. // If a user calls a compiled slot inside a template expression (#1745), it
  2366. // can mess up block tracking, so by default we disable block tracking and
  2367. // force bail out when invoking a compiled slot (indicated by the ._d flag).
  2368. // This isn't necessary if rendering a compiled `<slot>`, so we flip the
  2369. // ._d flag off when invoking the wrapped fn inside `renderSlot`.
  2370. if (renderFnWithContext._d) {
  2371. setBlockTracking(-1);
  2372. }
  2373. const prevInstance = setCurrentRenderingInstance(ctx);
  2374. let res;
  2375. try {
  2376. res = fn(...args);
  2377. }
  2378. finally {
  2379. setCurrentRenderingInstance(prevInstance);
  2380. if (renderFnWithContext._d) {
  2381. setBlockTracking(1);
  2382. }
  2383. }
  2384. {
  2385. devtoolsComponentUpdated(ctx);
  2386. }
  2387. return res;
  2388. };
  2389. // mark normalized to avoid duplicated wrapping
  2390. renderFnWithContext._n = true;
  2391. // mark this as compiled by default
  2392. // this is used in vnode.ts -> normalizeChildren() to set the slot
  2393. // rendering flag.
  2394. renderFnWithContext._c = true;
  2395. // disable block tracking by default
  2396. renderFnWithContext._d = true;
  2397. return renderFnWithContext;
  2398. }
  2399. /**
  2400. * dev only flag to track whether $attrs was used during render.
  2401. * If $attrs was used during render then the warning for failed attrs
  2402. * fallthrough can be suppressed.
  2403. */
  2404. let accessedAttrs = false;
  2405. function markAttrsAccessed() {
  2406. accessedAttrs = true;
  2407. }
  2408. function renderComponentRoot(instance) {
  2409. const { type: Component, vnode, proxy, withProxy, props, propsOptions: [propsOptions], slots, attrs, emit, render, renderCache, data, setupState, ctx, inheritAttrs } = instance;
  2410. let result;
  2411. let fallthroughAttrs;
  2412. const prev = setCurrentRenderingInstance(instance);
  2413. {
  2414. accessedAttrs = false;
  2415. }
  2416. try {
  2417. if (vnode.shapeFlag & 4 /* ShapeFlags.STATEFUL_COMPONENT */) {
  2418. // withProxy is a proxy with a different `has` trap only for
  2419. // runtime-compiled render functions using `with` block.
  2420. const proxyToUse = withProxy || proxy;
  2421. result = normalizeVNode(render.call(proxyToUse, proxyToUse, renderCache, props, setupState, data, ctx));
  2422. fallthroughAttrs = attrs;
  2423. }
  2424. else {
  2425. // functional
  2426. const render = Component;
  2427. // in dev, mark attrs accessed if optional props (attrs === props)
  2428. if (true && attrs === props) {
  2429. markAttrsAccessed();
  2430. }
  2431. result = normalizeVNode(render.length > 1
  2432. ? render(props, true
  2433. ? {
  2434. get attrs() {
  2435. markAttrsAccessed();
  2436. return attrs;
  2437. },
  2438. slots,
  2439. emit
  2440. }
  2441. : { attrs, slots, emit })
  2442. : render(props, null /* we know it doesn't need it */));
  2443. fallthroughAttrs = Component.props
  2444. ? attrs
  2445. : getFunctionalFallthrough(attrs);
  2446. }
  2447. }
  2448. catch (err) {
  2449. blockStack.length = 0;
  2450. handleError(err, instance, 1 /* ErrorCodes.RENDER_FUNCTION */);
  2451. result = createVNode(Comment);
  2452. }
  2453. // attr merging
  2454. // in dev mode, comments are preserved, and it's possible for a template
  2455. // to have comments along side the root element which makes it a fragment
  2456. let root = result;
  2457. let setRoot = undefined;
  2458. if (result.patchFlag > 0 &&
  2459. result.patchFlag & 2048 /* PatchFlags.DEV_ROOT_FRAGMENT */) {
  2460. [root, setRoot] = getChildRoot(result);
  2461. }
  2462. if (fallthroughAttrs && inheritAttrs !== false) {
  2463. const keys = Object.keys(fallthroughAttrs);
  2464. const { shapeFlag } = root;
  2465. if (keys.length) {
  2466. if (shapeFlag & (1 /* ShapeFlags.ELEMENT */ | 6 /* ShapeFlags.COMPONENT */)) {
  2467. if (propsOptions && keys.some(isModelListener)) {
  2468. // If a v-model listener (onUpdate:xxx) has a corresponding declared
  2469. // prop, it indicates this component expects to handle v-model and
  2470. // it should not fallthrough.
  2471. // related: #1543, #1643, #1989
  2472. fallthroughAttrs = filterModelListeners(fallthroughAttrs, propsOptions);
  2473. }
  2474. root = cloneVNode(root, fallthroughAttrs);
  2475. }
  2476. else if (!accessedAttrs && root.type !== Comment) {
  2477. const allAttrs = Object.keys(attrs);
  2478. const eventAttrs = [];
  2479. const extraAttrs = [];
  2480. for (let i = 0, l = allAttrs.length; i < l; i++) {
  2481. const key = allAttrs[i];
  2482. if (isOn(key)) {
  2483. // ignore v-model handlers when they fail to fallthrough
  2484. if (!isModelListener(key)) {
  2485. // remove `on`, lowercase first letter to reflect event casing
  2486. // accurately
  2487. eventAttrs.push(key[2].toLowerCase() + key.slice(3));
  2488. }
  2489. }
  2490. else {
  2491. extraAttrs.push(key);
  2492. }
  2493. }
  2494. if (extraAttrs.length) {
  2495. warn(`Extraneous non-props attributes (` +
  2496. `${extraAttrs.join(', ')}) ` +
  2497. `were passed to component but could not be automatically inherited ` +
  2498. `because component renders fragment or text root nodes.`);
  2499. }
  2500. if (eventAttrs.length) {
  2501. warn(`Extraneous non-emits event listeners (` +
  2502. `${eventAttrs.join(', ')}) ` +
  2503. `were passed to component but could not be automatically inherited ` +
  2504. `because component renders fragment or text root nodes. ` +
  2505. `If the listener is intended to be a component custom event listener only, ` +
  2506. `declare it using the "emits" option.`);
  2507. }
  2508. }
  2509. }
  2510. }
  2511. // inherit directives
  2512. if (vnode.dirs) {
  2513. if (!isElementRoot(root)) {
  2514. warn(`Runtime directive used on component with non-element root node. ` +
  2515. `The directives will not function as intended.`);
  2516. }
  2517. // clone before mutating since the root may be a hoisted vnode
  2518. root = cloneVNode(root);
  2519. root.dirs = root.dirs ? root.dirs.concat(vnode.dirs) : vnode.dirs;
  2520. }
  2521. // inherit transition data
  2522. if (vnode.transition) {
  2523. if (!isElementRoot(root)) {
  2524. warn(`Component inside <Transition> renders non-element root node ` +
  2525. `that cannot be animated.`);
  2526. }
  2527. root.transition = vnode.transition;
  2528. }
  2529. if (setRoot) {
  2530. setRoot(root);
  2531. }
  2532. else {
  2533. result = root;
  2534. }
  2535. setCurrentRenderingInstance(prev);
  2536. return result;
  2537. }
  2538. /**
  2539. * dev only
  2540. * In dev mode, template root level comments are rendered, which turns the
  2541. * template into a fragment root, but we need to locate the single element
  2542. * root for attrs and scope id processing.
  2543. */
  2544. const getChildRoot = (vnode) => {
  2545. const rawChildren = vnode.children;
  2546. const dynamicChildren = vnode.dynamicChildren;
  2547. const childRoot = filterSingleRoot(rawChildren);
  2548. if (!childRoot) {
  2549. return [vnode, undefined];
  2550. }
  2551. const index = rawChildren.indexOf(childRoot);
  2552. const dynamicIndex = dynamicChildren ? dynamicChildren.indexOf(childRoot) : -1;
  2553. const setRoot = (updatedRoot) => {
  2554. rawChildren[index] = updatedRoot;
  2555. if (dynamicChildren) {
  2556. if (dynamicIndex > -1) {
  2557. dynamicChildren[dynamicIndex] = updatedRoot;
  2558. }
  2559. else if (updatedRoot.patchFlag > 0) {
  2560. vnode.dynamicChildren = [...dynamicChildren, updatedRoot];
  2561. }
  2562. }
  2563. };
  2564. return [normalizeVNode(childRoot), setRoot];
  2565. };
  2566. function filterSingleRoot(children) {
  2567. let singleRoot;
  2568. for (let i = 0; i < children.length; i++) {
  2569. const child = children[i];
  2570. if (isVNode(child)) {
  2571. // ignore user comment
  2572. if (child.type !== Comment || child.children === 'v-if') {
  2573. if (singleRoot) {
  2574. // has more than 1 non-comment child, return now
  2575. return;
  2576. }
  2577. else {
  2578. singleRoot = child;
  2579. }
  2580. }
  2581. }
  2582. else {
  2583. return;
  2584. }
  2585. }
  2586. return singleRoot;
  2587. }
  2588. const getFunctionalFallthrough = (attrs) => {
  2589. let res;
  2590. for (const key in attrs) {
  2591. if (key === 'class' || key === 'style' || isOn(key)) {
  2592. (res || (res = {}))[key] = attrs[key];
  2593. }
  2594. }
  2595. return res;
  2596. };
  2597. const filterModelListeners = (attrs, props) => {
  2598. const res = {};
  2599. for (const key in attrs) {
  2600. if (!isModelListener(key) || !(key.slice(9) in props)) {
  2601. res[key] = attrs[key];
  2602. }
  2603. }
  2604. return res;
  2605. };
  2606. const isElementRoot = (vnode) => {
  2607. return (vnode.shapeFlag & (6 /* ShapeFlags.COMPONENT */ | 1 /* ShapeFlags.ELEMENT */) ||
  2608. vnode.type === Comment // potential v-if branch switch
  2609. );
  2610. };
  2611. function shouldUpdateComponent(prevVNode, nextVNode, optimized) {
  2612. const { props: prevProps, children: prevChildren, component } = prevVNode;
  2613. const { props: nextProps, children: nextChildren, patchFlag } = nextVNode;
  2614. const emits = component.emitsOptions;
  2615. // Parent component's render function was hot-updated. Since this may have
  2616. // caused the child component's slots content to have changed, we need to
  2617. // force the child to update as well.
  2618. if ((prevChildren || nextChildren) && isHmrUpdating) {
  2619. return true;
  2620. }
  2621. // force child update for runtime directive or transition on component vnode.
  2622. if (nextVNode.dirs || nextVNode.transition) {
  2623. return true;
  2624. }
  2625. if (optimized && patchFlag >= 0) {
  2626. if (patchFlag & 1024 /* PatchFlags.DYNAMIC_SLOTS */) {
  2627. // slot content that references values that might have changed,
  2628. // e.g. in a v-for
  2629. return true;
  2630. }
  2631. if (patchFlag & 16 /* PatchFlags.FULL_PROPS */) {
  2632. if (!prevProps) {
  2633. return !!nextProps;
  2634. }
  2635. // presence of this flag indicates props are always non-null
  2636. return hasPropsChanged(prevProps, nextProps, emits);
  2637. }
  2638. else if (patchFlag & 8 /* PatchFlags.PROPS */) {
  2639. const dynamicProps = nextVNode.dynamicProps;
  2640. for (let i = 0; i < dynamicProps.length; i++) {
  2641. const key = dynamicProps[i];
  2642. if (nextProps[key] !== prevProps[key] &&
  2643. !isEmitListener(emits, key)) {
  2644. return true;
  2645. }
  2646. }
  2647. }
  2648. }
  2649. else {
  2650. // this path is only taken by manually written render functions
  2651. // so presence of any children leads to a forced update
  2652. if (prevChildren || nextChildren) {
  2653. if (!nextChildren || !nextChildren.$stable) {
  2654. return true;
  2655. }
  2656. }
  2657. if (prevProps === nextProps) {
  2658. return false;
  2659. }
  2660. if (!prevProps) {
  2661. return !!nextProps;
  2662. }
  2663. if (!nextProps) {
  2664. return true;
  2665. }
  2666. return hasPropsChanged(prevProps, nextProps, emits);
  2667. }
  2668. return false;
  2669. }
  2670. function hasPropsChanged(prevProps, nextProps, emitsOptions) {
  2671. const nextKeys = Object.keys(nextProps);
  2672. if (nextKeys.length !== Object.keys(prevProps).length) {
  2673. return true;
  2674. }
  2675. for (let i = 0; i < nextKeys.length; i++) {
  2676. const key = nextKeys[i];
  2677. if (nextProps[key] !== prevProps[key] &&
  2678. !isEmitListener(emitsOptions, key)) {
  2679. return true;
  2680. }
  2681. }
  2682. return false;
  2683. }
  2684. function updateHOCHostEl({ vnode, parent }, el // HostNode
  2685. ) {
  2686. while (parent && parent.subTree === vnode) {
  2687. (vnode = parent.vnode).el = el;
  2688. parent = parent.parent;
  2689. }
  2690. }
  2691. const isSuspense = (type) => type.__isSuspense;
  2692. // Suspense exposes a component-like API, and is treated like a component
  2693. // in the compiler, but internally it's a special built-in type that hooks
  2694. // directly into the renderer.
  2695. const SuspenseImpl = {
  2696. name: 'Suspense',
  2697. // In order to make Suspense tree-shakable, we need to avoid importing it
  2698. // directly in the renderer. The renderer checks for the __isSuspense flag
  2699. // on a vnode's type and calls the `process` method, passing in renderer
  2700. // internals.
  2701. __isSuspense: true,
  2702. process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized,
  2703. // platform-specific impl passed from renderer
  2704. rendererInternals) {
  2705. if (n1 == null) {
  2706. mountSuspense(n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, rendererInternals);
  2707. }
  2708. else {
  2709. patchSuspense(n1, n2, container, anchor, parentComponent, isSVG, slotScopeIds, optimized, rendererInternals);
  2710. }
  2711. },
  2712. hydrate: hydrateSuspense,
  2713. create: createSuspenseBoundary,
  2714. normalize: normalizeSuspenseChildren
  2715. };
  2716. // Force-casted public typing for h and TSX props inference
  2717. const Suspense = (SuspenseImpl
  2718. );
  2719. function triggerEvent(vnode, name) {
  2720. const eventListener = vnode.props && vnode.props[name];
  2721. if (isFunction(eventListener)) {
  2722. eventListener();
  2723. }
  2724. }
  2725. function mountSuspense(vnode, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, rendererInternals) {
  2726. const { p: patch, o: { createElement } } = rendererInternals;
  2727. const hiddenContainer = createElement('div');
  2728. const suspense = (vnode.suspense = createSuspenseBoundary(vnode, parentSuspense, parentComponent, container, hiddenContainer, anchor, isSVG, slotScopeIds, optimized, rendererInternals));
  2729. // start mounting the content subtree in an off-dom container
  2730. patch(null, (suspense.pendingBranch = vnode.ssContent), hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds);
  2731. // now check if we have encountered any async deps
  2732. if (suspense.deps > 0) {
  2733. // has async
  2734. // invoke @fallback event
  2735. triggerEvent(vnode, 'onPending');
  2736. triggerEvent(vnode, 'onFallback');
  2737. // mount the fallback tree
  2738. patch(null, vnode.ssFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2739. isSVG, slotScopeIds);
  2740. setActiveBranch(suspense, vnode.ssFallback);
  2741. }
  2742. else {
  2743. // Suspense has no async deps. Just resolve.
  2744. suspense.resolve();
  2745. }
  2746. }
  2747. function patchSuspense(n1, n2, container, anchor, parentComponent, isSVG, slotScopeIds, optimized, { p: patch, um: unmount, o: { createElement } }) {
  2748. const suspense = (n2.suspense = n1.suspense);
  2749. suspense.vnode = n2;
  2750. n2.el = n1.el;
  2751. const newBranch = n2.ssContent;
  2752. const newFallback = n2.ssFallback;
  2753. const { activeBranch, pendingBranch, isInFallback, isHydrating } = suspense;
  2754. if (pendingBranch) {
  2755. suspense.pendingBranch = newBranch;
  2756. if (isSameVNodeType(newBranch, pendingBranch)) {
  2757. // same root type but content may have changed.
  2758. patch(pendingBranch, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2759. if (suspense.deps <= 0) {
  2760. suspense.resolve();
  2761. }
  2762. else if (isInFallback) {
  2763. patch(activeBranch, newFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2764. isSVG, slotScopeIds, optimized);
  2765. setActiveBranch(suspense, newFallback);
  2766. }
  2767. }
  2768. else {
  2769. // toggled before pending tree is resolved
  2770. suspense.pendingId++;
  2771. if (isHydrating) {
  2772. // if toggled before hydration is finished, the current DOM tree is
  2773. // no longer valid. set it as the active branch so it will be unmounted
  2774. // when resolved
  2775. suspense.isHydrating = false;
  2776. suspense.activeBranch = pendingBranch;
  2777. }
  2778. else {
  2779. unmount(pendingBranch, parentComponent, suspense);
  2780. }
  2781. // increment pending ID. this is used to invalidate async callbacks
  2782. // reset suspense state
  2783. suspense.deps = 0;
  2784. // discard effects from pending branch
  2785. suspense.effects.length = 0;
  2786. // discard previous container
  2787. suspense.hiddenContainer = createElement('div');
  2788. if (isInFallback) {
  2789. // already in fallback state
  2790. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2791. if (suspense.deps <= 0) {
  2792. suspense.resolve();
  2793. }
  2794. else {
  2795. patch(activeBranch, newFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2796. isSVG, slotScopeIds, optimized);
  2797. setActiveBranch(suspense, newFallback);
  2798. }
  2799. }
  2800. else if (activeBranch && isSameVNodeType(newBranch, activeBranch)) {
  2801. // toggled "back" to current active branch
  2802. patch(activeBranch, newBranch, container, anchor, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2803. // force resolve
  2804. suspense.resolve(true);
  2805. }
  2806. else {
  2807. // switched to a 3rd branch
  2808. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2809. if (suspense.deps <= 0) {
  2810. suspense.resolve();
  2811. }
  2812. }
  2813. }
  2814. }
  2815. else {
  2816. if (activeBranch && isSameVNodeType(newBranch, activeBranch)) {
  2817. // root did not change, just normal patch
  2818. patch(activeBranch, newBranch, container, anchor, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2819. setActiveBranch(suspense, newBranch);
  2820. }
  2821. else {
  2822. // root node toggled
  2823. // invoke @pending event
  2824. triggerEvent(n2, 'onPending');
  2825. // mount pending branch in off-dom container
  2826. suspense.pendingBranch = newBranch;
  2827. suspense.pendingId++;
  2828. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2829. if (suspense.deps <= 0) {
  2830. // incoming branch has no async deps, resolve now.
  2831. suspense.resolve();
  2832. }
  2833. else {
  2834. const { timeout, pendingId } = suspense;
  2835. if (timeout > 0) {
  2836. setTimeout(() => {
  2837. if (suspense.pendingId === pendingId) {
  2838. suspense.fallback(newFallback);
  2839. }
  2840. }, timeout);
  2841. }
  2842. else if (timeout === 0) {
  2843. suspense.fallback(newFallback);
  2844. }
  2845. }
  2846. }
  2847. }
  2848. }
  2849. let hasWarned = false;
  2850. function createSuspenseBoundary(vnode, parent, parentComponent, container, hiddenContainer, anchor, isSVG, slotScopeIds, optimized, rendererInternals, isHydrating = false) {
  2851. /* istanbul ignore if */
  2852. if (!hasWarned) {
  2853. hasWarned = true;
  2854. // @ts-ignore `console.info` cannot be null error
  2855. console[console.info ? 'info' : 'log'](`<Suspense> is an experimental feature and its API will likely change.`);
  2856. }
  2857. const { p: patch, m: move, um: unmount, n: next, o: { parentNode, remove } } = rendererInternals;
  2858. const timeout = vnode.props ? toNumber(vnode.props.timeout) : undefined;
  2859. {
  2860. assertNumber(timeout, `Suspense timeout`);
  2861. }
  2862. const suspense = {
  2863. vnode,
  2864. parent,
  2865. parentComponent,
  2866. isSVG,
  2867. container,
  2868. hiddenContainer,
  2869. anchor,
  2870. deps: 0,
  2871. pendingId: 0,
  2872. timeout: typeof timeout === 'number' ? timeout : -1,
  2873. activeBranch: null,
  2874. pendingBranch: null,
  2875. isInFallback: true,
  2876. isHydrating,
  2877. isUnmounted: false,
  2878. effects: [],
  2879. resolve(resume = false) {
  2880. {
  2881. if (!resume && !suspense.pendingBranch) {
  2882. throw new Error(`suspense.resolve() is called without a pending branch.`);
  2883. }
  2884. if (suspense.isUnmounted) {
  2885. throw new Error(`suspense.resolve() is called on an already unmounted suspense boundary.`);
  2886. }
  2887. }
  2888. const { vnode, activeBranch, pendingBranch, pendingId, effects, parentComponent, container } = suspense;
  2889. if (suspense.isHydrating) {
  2890. suspense.isHydrating = false;
  2891. }
  2892. else if (!resume) {
  2893. const delayEnter = activeBranch &&
  2894. pendingBranch.transition &&
  2895. pendingBranch.transition.mode === 'out-in';
  2896. if (delayEnter) {
  2897. activeBranch.transition.afterLeave = () => {
  2898. if (pendingId === suspense.pendingId) {
  2899. move(pendingBranch, container, anchor, 0 /* MoveType.ENTER */);
  2900. }
  2901. };
  2902. }
  2903. // this is initial anchor on mount
  2904. let { anchor } = suspense;
  2905. // unmount current active tree
  2906. if (activeBranch) {
  2907. // if the fallback tree was mounted, it may have been moved
  2908. // as part of a parent suspense. get the latest anchor for insertion
  2909. anchor = next(activeBranch);
  2910. unmount(activeBranch, parentComponent, suspense, true);
  2911. }
  2912. if (!delayEnter) {
  2913. // move content from off-dom container to actual container
  2914. move(pendingBranch, container, anchor, 0 /* MoveType.ENTER */);
  2915. }
  2916. }
  2917. setActiveBranch(suspense, pendingBranch);
  2918. suspense.pendingBranch = null;
  2919. suspense.isInFallback = false;
  2920. // flush buffered effects
  2921. // check if there is a pending parent suspense
  2922. let parent = suspense.parent;
  2923. let hasUnresolvedAncestor = false;
  2924. while (parent) {
  2925. if (parent.pendingBranch) {
  2926. // found a pending parent suspense, merge buffered post jobs
  2927. // into that parent
  2928. parent.effects.push(...effects);
  2929. hasUnresolvedAncestor = true;
  2930. break;
  2931. }
  2932. parent = parent.parent;
  2933. }
  2934. // no pending parent suspense, flush all jobs
  2935. if (!hasUnresolvedAncestor) {
  2936. queuePostFlushCb(effects);
  2937. }
  2938. suspense.effects = [];
  2939. // invoke @resolve event
  2940. triggerEvent(vnode, 'onResolve');
  2941. },
  2942. fallback(fallbackVNode) {
  2943. if (!suspense.pendingBranch) {
  2944. return;
  2945. }
  2946. const { vnode, activeBranch, parentComponent, container, isSVG } = suspense;
  2947. // invoke @fallback event
  2948. triggerEvent(vnode, 'onFallback');
  2949. const anchor = next(activeBranch);
  2950. const mountFallback = () => {
  2951. if (!suspense.isInFallback) {
  2952. return;
  2953. }
  2954. // mount the fallback tree
  2955. patch(null, fallbackVNode, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2956. isSVG, slotScopeIds, optimized);
  2957. setActiveBranch(suspense, fallbackVNode);
  2958. };
  2959. const delayEnter = fallbackVNode.transition && fallbackVNode.transition.mode === 'out-in';
  2960. if (delayEnter) {
  2961. activeBranch.transition.afterLeave = mountFallback;
  2962. }
  2963. suspense.isInFallback = true;
  2964. // unmount current active branch
  2965. unmount(activeBranch, parentComponent, null, // no suspense so unmount hooks fire now
  2966. true // shouldRemove
  2967. );
  2968. if (!delayEnter) {
  2969. mountFallback();
  2970. }
  2971. },
  2972. move(container, anchor, type) {
  2973. suspense.activeBranch &&
  2974. move(suspense.activeBranch, container, anchor, type);
  2975. suspense.container = container;
  2976. },
  2977. next() {
  2978. return suspense.activeBranch && next(suspense.activeBranch);
  2979. },
  2980. registerDep(instance, setupRenderEffect) {
  2981. const isInPendingSuspense = !!suspense.pendingBranch;
  2982. if (isInPendingSuspense) {
  2983. suspense.deps++;
  2984. }
  2985. const hydratedEl = instance.vnode.el;
  2986. instance
  2987. .asyncDep.catch(err => {
  2988. handleError(err, instance, 0 /* ErrorCodes.SETUP_FUNCTION */);
  2989. })
  2990. .then(asyncSetupResult => {
  2991. // retry when the setup() promise resolves.
  2992. // component may have been unmounted before resolve.
  2993. if (instance.isUnmounted ||
  2994. suspense.isUnmounted ||
  2995. suspense.pendingId !== instance.suspenseId) {
  2996. return;
  2997. }
  2998. // retry from this component
  2999. instance.asyncResolved = true;
  3000. const { vnode } = instance;
  3001. {
  3002. pushWarningContext(vnode);
  3003. }
  3004. handleSetupResult(instance, asyncSetupResult, false);
  3005. if (hydratedEl) {
  3006. // vnode may have been replaced if an update happened before the
  3007. // async dep is resolved.
  3008. vnode.el = hydratedEl;
  3009. }
  3010. const placeholder = !hydratedEl && instance.subTree.el;
  3011. setupRenderEffect(instance, vnode,
  3012. // component may have been moved before resolve.
  3013. // if this is not a hydration, instance.subTree will be the comment
  3014. // placeholder.
  3015. parentNode(hydratedEl || instance.subTree.el),
  3016. // anchor will not be used if this is hydration, so only need to
  3017. // consider the comment placeholder case.
  3018. hydratedEl ? null : next(instance.subTree), suspense, isSVG, optimized);
  3019. if (placeholder) {
  3020. remove(placeholder);
  3021. }
  3022. updateHOCHostEl(instance, vnode.el);
  3023. {
  3024. popWarningContext();
  3025. }
  3026. // only decrease deps count if suspense is not already resolved
  3027. if (isInPendingSuspense && --suspense.deps === 0) {
  3028. suspense.resolve();
  3029. }
  3030. });
  3031. },
  3032. unmount(parentSuspense, doRemove) {
  3033. suspense.isUnmounted = true;
  3034. if (suspense.activeBranch) {
  3035. unmount(suspense.activeBranch, parentComponent, parentSuspense, doRemove);
  3036. }
  3037. if (suspense.pendingBranch) {
  3038. unmount(suspense.pendingBranch, parentComponent, parentSuspense, doRemove);
  3039. }
  3040. }
  3041. };
  3042. return suspense;
  3043. }
  3044. function hydrateSuspense(node, vnode, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, rendererInternals, hydrateNode) {
  3045. /* eslint-disable no-restricted-globals */
  3046. const suspense = (vnode.suspense = createSuspenseBoundary(vnode, parentSuspense, parentComponent, node.parentNode, document.createElement('div'), null, isSVG, slotScopeIds, optimized, rendererInternals, true /* hydrating */));
  3047. // there are two possible scenarios for server-rendered suspense:
  3048. // - success: ssr content should be fully resolved
  3049. // - failure: ssr content should be the fallback branch.
  3050. // however, on the client we don't really know if it has failed or not
  3051. // attempt to hydrate the DOM assuming it has succeeded, but we still
  3052. // need to construct a suspense boundary first
  3053. const result = hydrateNode(node, (suspense.pendingBranch = vnode.ssContent), parentComponent, suspense, slotScopeIds, optimized);
  3054. if (suspense.deps === 0) {
  3055. suspense.resolve();
  3056. }
  3057. return result;
  3058. /* eslint-enable no-restricted-globals */
  3059. }
  3060. function normalizeSuspenseChildren(vnode) {
  3061. const { shapeFlag, children } = vnode;
  3062. const isSlotChildren = shapeFlag & 32 /* ShapeFlags.SLOTS_CHILDREN */;
  3063. vnode.ssContent = normalizeSuspenseSlot(isSlotChildren ? children.default : children);
  3064. vnode.ssFallback = isSlotChildren
  3065. ? normalizeSuspenseSlot(children.fallback)
  3066. : createVNode(Comment);
  3067. }
  3068. function normalizeSuspenseSlot(s) {
  3069. let block;
  3070. if (isFunction(s)) {
  3071. const trackBlock = isBlockTreeEnabled && s._c;
  3072. if (trackBlock) {
  3073. // disableTracking: false
  3074. // allow block tracking for compiled slots
  3075. // (see ./componentRenderContext.ts)
  3076. s._d = false;
  3077. openBlock();
  3078. }
  3079. s = s();
  3080. if (trackBlock) {
  3081. s._d = true;
  3082. block = currentBlock;
  3083. closeBlock();
  3084. }
  3085. }
  3086. if (isArray(s)) {
  3087. const singleChild = filterSingleRoot(s);
  3088. if (!singleChild) {
  3089. warn(`<Suspense> slots expect a single root node.`);
  3090. }
  3091. s = singleChild;
  3092. }
  3093. s = normalizeVNode(s);
  3094. if (block && !s.dynamicChildren) {
  3095. s.dynamicChildren = block.filter(c => c !== s);
  3096. }
  3097. return s;
  3098. }
  3099. function queueEffectWithSuspense(fn, suspense) {
  3100. if (suspense && suspense.pendingBranch) {
  3101. if (isArray(fn)) {
  3102. suspense.effects.push(...fn);
  3103. }
  3104. else {
  3105. suspense.effects.push(fn);
  3106. }
  3107. }
  3108. else {
  3109. queuePostFlushCb(fn);
  3110. }
  3111. }
  3112. function setActiveBranch(suspense, branch) {
  3113. suspense.activeBranch = branch;
  3114. const { vnode, parentComponent } = suspense;
  3115. const el = (vnode.el = branch.el);
  3116. // in case suspense is the root node of a component,
  3117. // recursively update the HOC el
  3118. if (parentComponent && parentComponent.subTree === vnode) {
  3119. parentComponent.vnode.el = el;
  3120. updateHOCHostEl(parentComponent, el);
  3121. }
  3122. }
  3123. function provide(key, value) {
  3124. if (!currentInstance) {
  3125. {
  3126. warn(`provide() can only be used inside setup().`);
  3127. }
  3128. }
  3129. else {
  3130. let provides = currentInstance.provides;
  3131. // by default an instance inherits its parent's provides object
  3132. // but when it needs to provide values of its own, it creates its
  3133. // own provides object using parent provides object as prototype.
  3134. // this way in `inject` we can simply look up injections from direct
  3135. // parent and let the prototype chain do the work.
  3136. const parentProvides = currentInstance.parent && currentInstance.parent.provides;
  3137. if (parentProvides === provides) {
  3138. provides = currentInstance.provides = Object.create(parentProvides);
  3139. }
  3140. // TS doesn't allow symbol as index type
  3141. provides[key] = value;
  3142. }
  3143. }
  3144. function inject(key, defaultValue, treatDefaultAsFactory = false) {
  3145. // fallback to `currentRenderingInstance` so that this can be called in
  3146. // a functional component
  3147. const instance = currentInstance || currentRenderingInstance;
  3148. if (instance) {
  3149. // #2400
  3150. // to support `app.use` plugins,
  3151. // fallback to appContext's `provides` if the instance is at root
  3152. const provides = instance.parent == null
  3153. ? instance.vnode.appContext && instance.vnode.appContext.provides
  3154. : instance.parent.provides;
  3155. if (provides && key in provides) {
  3156. // TS doesn't allow symbol as index type
  3157. return provides[key];
  3158. }
  3159. else if (arguments.length > 1) {
  3160. return treatDefaultAsFactory && isFunction(defaultValue)
  3161. ? defaultValue.call(instance.proxy)
  3162. : defaultValue;
  3163. }
  3164. else {
  3165. warn(`injection "${String(key)}" not found.`);
  3166. }
  3167. }
  3168. else {
  3169. warn(`inject() can only be used inside setup() or functional components.`);
  3170. }
  3171. }
  3172. // Simple effect.
  3173. function watchEffect(effect, options) {
  3174. return doWatch(effect, null, options);
  3175. }
  3176. function watchPostEffect(effect, options) {
  3177. return doWatch(effect, null, Object.assign(Object.assign({}, options), { flush: 'post' }) );
  3178. }
  3179. function watchSyncEffect(effect, options) {
  3180. return doWatch(effect, null, Object.assign(Object.assign({}, options), { flush: 'sync' }) );
  3181. }
  3182. // initial value for watchers to trigger on undefined initial values
  3183. const INITIAL_WATCHER_VALUE = {};
  3184. // implementation
  3185. function watch(source, cb, options) {
  3186. if (!isFunction(cb)) {
  3187. warn(`\`watch(fn, options?)\` signature has been moved to a separate API. ` +
  3188. `Use \`watchEffect(fn, options?)\` instead. \`watch\` now only ` +
  3189. `supports \`watch(source, cb, options?) signature.`);
  3190. }
  3191. return doWatch(source, cb, options);
  3192. }
  3193. function doWatch(source, cb, { immediate, deep, flush, onTrack, onTrigger } = EMPTY_OBJ) {
  3194. if (!cb) {
  3195. if (immediate !== undefined) {
  3196. warn(`watch() "immediate" option is only respected when using the ` +
  3197. `watch(source, callback, options?) signature.`);
  3198. }
  3199. if (deep !== undefined) {
  3200. warn(`watch() "deep" option is only respected when using the ` +
  3201. `watch(source, callback, options?) signature.`);
  3202. }
  3203. }
  3204. const warnInvalidSource = (s) => {
  3205. warn(`Invalid watch source: `, s, `A watch source can only be a getter/effect function, a ref, ` +
  3206. `a reactive object, or an array of these types.`);
  3207. };
  3208. const instance = getCurrentScope() === (currentInstance === null || currentInstance === void 0 ? void 0 : currentInstance.scope) ? currentInstance : null;
  3209. // const instance = currentInstance
  3210. let getter;
  3211. let forceTrigger = false;
  3212. let isMultiSource = false;
  3213. if (isRef(source)) {
  3214. getter = () => source.value;
  3215. forceTrigger = isShallow(source);
  3216. }
  3217. else if (isReactive(source)) {
  3218. getter = () => source;
  3219. deep = true;
  3220. }
  3221. else if (isArray(source)) {
  3222. isMultiSource = true;
  3223. forceTrigger = source.some(s => isReactive(s) || isShallow(s));
  3224. getter = () => source.map(s => {
  3225. if (isRef(s)) {
  3226. return s.value;
  3227. }
  3228. else if (isReactive(s)) {
  3229. return traverse(s);
  3230. }
  3231. else if (isFunction(s)) {
  3232. return callWithErrorHandling(s, instance, 2 /* ErrorCodes.WATCH_GETTER */);
  3233. }
  3234. else {
  3235. warnInvalidSource(s);
  3236. }
  3237. });
  3238. }
  3239. else if (isFunction(source)) {
  3240. if (cb) {
  3241. // getter with cb
  3242. getter = () => callWithErrorHandling(source, instance, 2 /* ErrorCodes.WATCH_GETTER */);
  3243. }
  3244. else {
  3245. // no cb -> simple effect
  3246. getter = () => {
  3247. if (instance && instance.isUnmounted) {
  3248. return;
  3249. }
  3250. if (cleanup) {
  3251. cleanup();
  3252. }
  3253. return callWithAsyncErrorHandling(source, instance, 3 /* ErrorCodes.WATCH_CALLBACK */, [onCleanup]);
  3254. };
  3255. }
  3256. }
  3257. else {
  3258. getter = NOOP;
  3259. warnInvalidSource(source);
  3260. }
  3261. if (cb && deep) {
  3262. const baseGetter = getter;
  3263. getter = () => traverse(baseGetter());
  3264. }
  3265. let cleanup;
  3266. let onCleanup = (fn) => {
  3267. cleanup = effect.onStop = () => {
  3268. callWithErrorHandling(fn, instance, 4 /* ErrorCodes.WATCH_CLEANUP */);
  3269. };
  3270. };
  3271. let oldValue = isMultiSource
  3272. ? new Array(source.length).fill(INITIAL_WATCHER_VALUE)
  3273. : INITIAL_WATCHER_VALUE;
  3274. const job = () => {
  3275. if (!effect.active) {
  3276. return;
  3277. }
  3278. if (cb) {
  3279. // watch(source, cb)
  3280. const newValue = effect.run();
  3281. if (deep ||
  3282. forceTrigger ||
  3283. (isMultiSource
  3284. ? newValue.some((v, i) => hasChanged(v, oldValue[i]))
  3285. : hasChanged(newValue, oldValue)) ||
  3286. (false )) {
  3287. // cleanup before running cb again
  3288. if (cleanup) {
  3289. cleanup();
  3290. }
  3291. callWithAsyncErrorHandling(cb, instance, 3 /* ErrorCodes.WATCH_CALLBACK */, [
  3292. newValue,
  3293. // pass undefined as the old value when it's changed for the first time
  3294. oldValue === INITIAL_WATCHER_VALUE
  3295. ? undefined
  3296. : isMultiSource && oldValue[0] === INITIAL_WATCHER_VALUE
  3297. ? []
  3298. : oldValue,
  3299. onCleanup
  3300. ]);
  3301. oldValue = newValue;
  3302. }
  3303. }
  3304. else {
  3305. // watchEffect
  3306. effect.run();
  3307. }
  3308. };
  3309. // important: mark the job as a watcher callback so that scheduler knows
  3310. // it is allowed to self-trigger (#1727)
  3311. job.allowRecurse = !!cb;
  3312. let scheduler;
  3313. if (flush === 'sync') {
  3314. scheduler = job; // the scheduler function gets called directly
  3315. }
  3316. else if (flush === 'post') {
  3317. scheduler = () => queuePostRenderEffect(job, instance && instance.suspense);
  3318. }
  3319. else {
  3320. // default: 'pre'
  3321. job.pre = true;
  3322. if (instance)
  3323. job.id = instance.uid;
  3324. scheduler = () => queueJob(job);
  3325. }
  3326. const effect = new ReactiveEffect(getter, scheduler);
  3327. {
  3328. effect.onTrack = onTrack;
  3329. effect.onTrigger = onTrigger;
  3330. }
  3331. // initial run
  3332. if (cb) {
  3333. if (immediate) {
  3334. job();
  3335. }
  3336. else {
  3337. oldValue = effect.run();
  3338. }
  3339. }
  3340. else if (flush === 'post') {
  3341. queuePostRenderEffect(effect.run.bind(effect), instance && instance.suspense);
  3342. }
  3343. else {
  3344. effect.run();
  3345. }
  3346. const unwatch = () => {
  3347. effect.stop();
  3348. if (instance && instance.scope) {
  3349. remove(instance.scope.effects, effect);
  3350. }
  3351. };
  3352. return unwatch;
  3353. }
  3354. // this.$watch
  3355. function instanceWatch(source, value, options) {
  3356. const publicThis = this.proxy;
  3357. const getter = isString(source)
  3358. ? source.includes('.')
  3359. ? createPathGetter(publicThis, source)
  3360. : () => publicThis[source]
  3361. : source.bind(publicThis, publicThis);
  3362. let cb;
  3363. if (isFunction(value)) {
  3364. cb = value;
  3365. }
  3366. else {
  3367. cb = value.handler;
  3368. options = value;
  3369. }
  3370. const cur = currentInstance;
  3371. setCurrentInstance(this);
  3372. const res = doWatch(getter, cb.bind(publicThis), options);
  3373. if (cur) {
  3374. setCurrentInstance(cur);
  3375. }
  3376. else {
  3377. unsetCurrentInstance();
  3378. }
  3379. return res;
  3380. }
  3381. function createPathGetter(ctx, path) {
  3382. const segments = path.split('.');
  3383. return () => {
  3384. let cur = ctx;
  3385. for (let i = 0; i < segments.length && cur; i++) {
  3386. cur = cur[segments[i]];
  3387. }
  3388. return cur;
  3389. };
  3390. }
  3391. function traverse(value, seen) {
  3392. if (!isObject(value) || value["__v_skip" /* ReactiveFlags.SKIP */]) {
  3393. return value;
  3394. }
  3395. seen = seen || new Set();
  3396. if (seen.has(value)) {
  3397. return value;
  3398. }
  3399. seen.add(value);
  3400. if (isRef(value)) {
  3401. traverse(value.value, seen);
  3402. }
  3403. else if (isArray(value)) {
  3404. for (let i = 0; i < value.length; i++) {
  3405. traverse(value[i], seen);
  3406. }
  3407. }
  3408. else if (isSet(value) || isMap(value)) {
  3409. value.forEach((v) => {
  3410. traverse(v, seen);
  3411. });
  3412. }
  3413. else if (isPlainObject(value)) {
  3414. for (const key in value) {
  3415. traverse(value[key], seen);
  3416. }
  3417. }
  3418. return value;
  3419. }
  3420. function useTransitionState() {
  3421. const state = {
  3422. isMounted: false,
  3423. isLeaving: false,
  3424. isUnmounting: false,
  3425. leavingVNodes: new Map()
  3426. };
  3427. onMounted(() => {
  3428. state.isMounted = true;
  3429. });
  3430. onBeforeUnmount(() => {
  3431. state.isUnmounting = true;
  3432. });
  3433. return state;
  3434. }
  3435. const TransitionHookValidator = [Function, Array];
  3436. const BaseTransitionImpl = {
  3437. name: `BaseTransition`,
  3438. props: {
  3439. mode: String,
  3440. appear: Boolean,
  3441. persisted: Boolean,
  3442. // enter
  3443. onBeforeEnter: TransitionHookValidator,
  3444. onEnter: TransitionHookValidator,
  3445. onAfterEnter: TransitionHookValidator,
  3446. onEnterCancelled: TransitionHookValidator,
  3447. // leave
  3448. onBeforeLeave: TransitionHookValidator,
  3449. onLeave: TransitionHookValidator,
  3450. onAfterLeave: TransitionHookValidator,
  3451. onLeaveCancelled: TransitionHookValidator,
  3452. // appear
  3453. onBeforeAppear: TransitionHookValidator,
  3454. onAppear: TransitionHookValidator,
  3455. onAfterAppear: TransitionHookValidator,
  3456. onAppearCancelled: TransitionHookValidator
  3457. },
  3458. setup(props, { slots }) {
  3459. const instance = getCurrentInstance();
  3460. const state = useTransitionState();
  3461. let prevTransitionKey;
  3462. return () => {
  3463. const children = slots.default && getTransitionRawChildren(slots.default(), true);
  3464. if (!children || !children.length) {
  3465. return;
  3466. }
  3467. let child = children[0];
  3468. if (children.length > 1) {
  3469. let hasFound = false;
  3470. // locate first non-comment child
  3471. for (const c of children) {
  3472. if (c.type !== Comment) {
  3473. if (hasFound) {
  3474. // warn more than one non-comment child
  3475. warn('<transition> can only be used on a single element or component. ' +
  3476. 'Use <transition-group> for lists.');
  3477. break;
  3478. }
  3479. child = c;
  3480. hasFound = true;
  3481. }
  3482. }
  3483. }
  3484. // there's no need to track reactivity for these props so use the raw
  3485. // props for a bit better perf
  3486. const rawProps = toRaw(props);
  3487. const { mode } = rawProps;
  3488. // check mode
  3489. if (mode &&
  3490. mode !== 'in-out' &&
  3491. mode !== 'out-in' &&
  3492. mode !== 'default') {
  3493. warn(`invalid <transition> mode: ${mode}`);
  3494. }
  3495. if (state.isLeaving) {
  3496. return emptyPlaceholder(child);
  3497. }
  3498. // in the case of <transition><keep-alive/></transition>, we need to
  3499. // compare the type of the kept-alive children.
  3500. const innerChild = getKeepAliveChild(child);
  3501. if (!innerChild) {
  3502. return emptyPlaceholder(child);
  3503. }
  3504. const enterHooks = resolveTransitionHooks(innerChild, rawProps, state, instance);
  3505. setTransitionHooks(innerChild, enterHooks);
  3506. const oldChild = instance.subTree;
  3507. const oldInnerChild = oldChild && getKeepAliveChild(oldChild);
  3508. let transitionKeyChanged = false;
  3509. const { getTransitionKey } = innerChild.type;
  3510. if (getTransitionKey) {
  3511. const key = getTransitionKey();
  3512. if (prevTransitionKey === undefined) {
  3513. prevTransitionKey = key;
  3514. }
  3515. else if (key !== prevTransitionKey) {
  3516. prevTransitionKey = key;
  3517. transitionKeyChanged = true;
  3518. }
  3519. }
  3520. // handle mode
  3521. if (oldInnerChild &&
  3522. oldInnerChild.type !== Comment &&
  3523. (!isSameVNodeType(innerChild, oldInnerChild) || transitionKeyChanged)) {
  3524. const leavingHooks = resolveTransitionHooks(oldInnerChild, rawProps, state, instance);
  3525. // update old tree's hooks in case of dynamic transition
  3526. setTransitionHooks(oldInnerChild, leavingHooks);
  3527. // switching between different views
  3528. if (mode === 'out-in') {
  3529. state.isLeaving = true;
  3530. // return placeholder node and queue update when leave finishes
  3531. leavingHooks.afterLeave = () => {
  3532. state.isLeaving = false;
  3533. // #6835
  3534. // it also needs to be updated when active is undefined
  3535. if (instance.update.active !== false) {
  3536. instance.update();
  3537. }
  3538. };
  3539. return emptyPlaceholder(child);
  3540. }
  3541. else if (mode === 'in-out' && innerChild.type !== Comment) {
  3542. leavingHooks.delayLeave = (el, earlyRemove, delayedLeave) => {
  3543. const leavingVNodesCache = getLeavingNodesForType(state, oldInnerChild);
  3544. leavingVNodesCache[String(oldInnerChild.key)] = oldInnerChild;
  3545. // early removal callback
  3546. el._leaveCb = () => {
  3547. earlyRemove();
  3548. el._leaveCb = undefined;
  3549. delete enterHooks.delayedLeave;
  3550. };
  3551. enterHooks.delayedLeave = delayedLeave;
  3552. };
  3553. }
  3554. }
  3555. return child;
  3556. };
  3557. }
  3558. };
  3559. // export the public type for h/tsx inference
  3560. // also to avoid inline import() in generated d.ts files
  3561. const BaseTransition = BaseTransitionImpl;
  3562. function getLeavingNodesForType(state, vnode) {
  3563. const { leavingVNodes } = state;
  3564. let leavingVNodesCache = leavingVNodes.get(vnode.type);
  3565. if (!leavingVNodesCache) {
  3566. leavingVNodesCache = Object.create(null);
  3567. leavingVNodes.set(vnode.type, leavingVNodesCache);
  3568. }
  3569. return leavingVNodesCache;
  3570. }
  3571. // The transition hooks are attached to the vnode as vnode.transition
  3572. // and will be called at appropriate timing in the renderer.
  3573. function resolveTransitionHooks(vnode, props, state, instance) {
  3574. const { appear, mode, persisted = false, onBeforeEnter, onEnter, onAfterEnter, onEnterCancelled, onBeforeLeave, onLeave, onAfterLeave, onLeaveCancelled, onBeforeAppear, onAppear, onAfterAppear, onAppearCancelled } = props;
  3575. const key = String(vnode.key);
  3576. const leavingVNodesCache = getLeavingNodesForType(state, vnode);
  3577. const callHook = (hook, args) => {
  3578. hook &&
  3579. callWithAsyncErrorHandling(hook, instance, 9 /* ErrorCodes.TRANSITION_HOOK */, args);
  3580. };
  3581. const callAsyncHook = (hook, args) => {
  3582. const done = args[1];
  3583. callHook(hook, args);
  3584. if (isArray(hook)) {
  3585. if (hook.every(hook => hook.length <= 1))
  3586. done();
  3587. }
  3588. else if (hook.length <= 1) {
  3589. done();
  3590. }
  3591. };
  3592. const hooks = {
  3593. mode,
  3594. persisted,
  3595. beforeEnter(el) {
  3596. let hook = onBeforeEnter;
  3597. if (!state.isMounted) {
  3598. if (appear) {
  3599. hook = onBeforeAppear || onBeforeEnter;
  3600. }
  3601. else {
  3602. return;
  3603. }
  3604. }
  3605. // for same element (v-show)
  3606. if (el._leaveCb) {
  3607. el._leaveCb(true /* cancelled */);
  3608. }
  3609. // for toggled element with same key (v-if)
  3610. const leavingVNode = leavingVNodesCache[key];
  3611. if (leavingVNode &&
  3612. isSameVNodeType(vnode, leavingVNode) &&
  3613. leavingVNode.el._leaveCb) {
  3614. // force early removal (not cancelled)
  3615. leavingVNode.el._leaveCb();
  3616. }
  3617. callHook(hook, [el]);
  3618. },
  3619. enter(el) {
  3620. let hook = onEnter;
  3621. let afterHook = onAfterEnter;
  3622. let cancelHook = onEnterCancelled;
  3623. if (!state.isMounted) {
  3624. if (appear) {
  3625. hook = onAppear || onEnter;
  3626. afterHook = onAfterAppear || onAfterEnter;
  3627. cancelHook = onAppearCancelled || onEnterCancelled;
  3628. }
  3629. else {
  3630. return;
  3631. }
  3632. }
  3633. let called = false;
  3634. const done = (el._enterCb = (cancelled) => {
  3635. if (called)
  3636. return;
  3637. called = true;
  3638. if (cancelled) {
  3639. callHook(cancelHook, [el]);
  3640. }
  3641. else {
  3642. callHook(afterHook, [el]);
  3643. }
  3644. if (hooks.delayedLeave) {
  3645. hooks.delayedLeave();
  3646. }
  3647. el._enterCb = undefined;
  3648. });
  3649. if (hook) {
  3650. callAsyncHook(hook, [el, done]);
  3651. }
  3652. else {
  3653. done();
  3654. }
  3655. },
  3656. leave(el, remove) {
  3657. const key = String(vnode.key);
  3658. if (el._enterCb) {
  3659. el._enterCb(true /* cancelled */);
  3660. }
  3661. if (state.isUnmounting) {
  3662. return remove();
  3663. }
  3664. callHook(onBeforeLeave, [el]);
  3665. let called = false;
  3666. const done = (el._leaveCb = (cancelled) => {
  3667. if (called)
  3668. return;
  3669. called = true;
  3670. remove();
  3671. if (cancelled) {
  3672. callHook(onLeaveCancelled, [el]);
  3673. }
  3674. else {
  3675. callHook(onAfterLeave, [el]);
  3676. }
  3677. el._leaveCb = undefined;
  3678. if (leavingVNodesCache[key] === vnode) {
  3679. delete leavingVNodesCache[key];
  3680. }
  3681. });
  3682. leavingVNodesCache[key] = vnode;
  3683. if (onLeave) {
  3684. callAsyncHook(onLeave, [el, done]);
  3685. }
  3686. else {
  3687. done();
  3688. }
  3689. },
  3690. clone(vnode) {
  3691. return resolveTransitionHooks(vnode, props, state, instance);
  3692. }
  3693. };
  3694. return hooks;
  3695. }
  3696. // the placeholder really only handles one special case: KeepAlive
  3697. // in the case of a KeepAlive in a leave phase we need to return a KeepAlive
  3698. // placeholder with empty content to avoid the KeepAlive instance from being
  3699. // unmounted.
  3700. function emptyPlaceholder(vnode) {
  3701. if (isKeepAlive(vnode)) {
  3702. vnode = cloneVNode(vnode);
  3703. vnode.children = null;
  3704. return vnode;
  3705. }
  3706. }
  3707. function getKeepAliveChild(vnode) {
  3708. return isKeepAlive(vnode)
  3709. ? vnode.children
  3710. ? vnode.children[0]
  3711. : undefined
  3712. : vnode;
  3713. }
  3714. function setTransitionHooks(vnode, hooks) {
  3715. if (vnode.shapeFlag & 6 /* ShapeFlags.COMPONENT */ && vnode.component) {
  3716. setTransitionHooks(vnode.component.subTree, hooks);
  3717. }
  3718. else if (vnode.shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
  3719. vnode.ssContent.transition = hooks.clone(vnode.ssContent);
  3720. vnode.ssFallback.transition = hooks.clone(vnode.ssFallback);
  3721. }
  3722. else {
  3723. vnode.transition = hooks;
  3724. }
  3725. }
  3726. function getTransitionRawChildren(children, keepComment = false, parentKey) {
  3727. let ret = [];
  3728. let keyedFragmentCount = 0;
  3729. for (let i = 0; i < children.length; i++) {
  3730. let child = children[i];
  3731. // #5360 inherit parent key in case of <template v-for>
  3732. const key = parentKey == null
  3733. ? child.key
  3734. : String(parentKey) + String(child.key != null ? child.key : i);
  3735. // handle fragment children case, e.g. v-for
  3736. if (child.type === Fragment) {
  3737. if (child.patchFlag & 128 /* PatchFlags.KEYED_FRAGMENT */)
  3738. keyedFragmentCount++;
  3739. ret = ret.concat(getTransitionRawChildren(child.children, keepComment, key));
  3740. }
  3741. // comment placeholders should be skipped, e.g. v-if
  3742. else if (keepComment || child.type !== Comment) {
  3743. ret.push(key != null ? cloneVNode(child, { key }) : child);
  3744. }
  3745. }
  3746. // #1126 if a transition children list contains multiple sub fragments, these
  3747. // fragments will be merged into a flat children array. Since each v-for
  3748. // fragment may contain different static bindings inside, we need to de-op
  3749. // these children to force full diffs to ensure correct behavior.
  3750. if (keyedFragmentCount > 1) {
  3751. for (let i = 0; i < ret.length; i++) {
  3752. ret[i].patchFlag = -2 /* PatchFlags.BAIL */;
  3753. }
  3754. }
  3755. return ret;
  3756. }
  3757. // implementation, close to no-op
  3758. function defineComponent(options) {
  3759. return isFunction(options) ? { setup: options, name: options.name } : options;
  3760. }
  3761. const isAsyncWrapper = (i) => !!i.type.__asyncLoader;
  3762. function defineAsyncComponent(source) {
  3763. if (isFunction(source)) {
  3764. source = { loader: source };
  3765. }
  3766. const { loader, loadingComponent, errorComponent, delay = 200, timeout, // undefined = never times out
  3767. suspensible = true, onError: userOnError } = source;
  3768. let pendingRequest = null;
  3769. let resolvedComp;
  3770. let retries = 0;
  3771. const retry = () => {
  3772. retries++;
  3773. pendingRequest = null;
  3774. return load();
  3775. };
  3776. const load = () => {
  3777. let thisRequest;
  3778. return (pendingRequest ||
  3779. (thisRequest = pendingRequest =
  3780. loader()
  3781. .catch(err => {
  3782. err = err instanceof Error ? err : new Error(String(err));
  3783. if (userOnError) {
  3784. return new Promise((resolve, reject) => {
  3785. const userRetry = () => resolve(retry());
  3786. const userFail = () => reject(err);
  3787. userOnError(err, userRetry, userFail, retries + 1);
  3788. });
  3789. }
  3790. else {
  3791. throw err;
  3792. }
  3793. })
  3794. .then((comp) => {
  3795. if (thisRequest !== pendingRequest && pendingRequest) {
  3796. return pendingRequest;
  3797. }
  3798. if (!comp) {
  3799. warn(`Async component loader resolved to undefined. ` +
  3800. `If you are using retry(), make sure to return its return value.`);
  3801. }
  3802. // interop module default
  3803. if (comp &&
  3804. (comp.__esModule || comp[Symbol.toStringTag] === 'Module')) {
  3805. comp = comp.default;
  3806. }
  3807. if (comp && !isObject(comp) && !isFunction(comp)) {
  3808. throw new Error(`Invalid async component load result: ${comp}`);
  3809. }
  3810. resolvedComp = comp;
  3811. return comp;
  3812. })));
  3813. };
  3814. return defineComponent({
  3815. name: 'AsyncComponentWrapper',
  3816. __asyncLoader: load,
  3817. get __asyncResolved() {
  3818. return resolvedComp;
  3819. },
  3820. setup() {
  3821. const instance = currentInstance;
  3822. // already resolved
  3823. if (resolvedComp) {
  3824. return () => createInnerComp(resolvedComp, instance);
  3825. }
  3826. const onError = (err) => {
  3827. pendingRequest = null;
  3828. handleError(err, instance, 13 /* ErrorCodes.ASYNC_COMPONENT_LOADER */, !errorComponent /* do not throw in dev if user provided error component */);
  3829. };
  3830. // suspense-controlled or SSR.
  3831. if ((suspensible && instance.suspense) ||
  3832. (false )) {
  3833. return load()
  3834. .then(comp => {
  3835. return () => createInnerComp(comp, instance);
  3836. })
  3837. .catch(err => {
  3838. onError(err);
  3839. return () => errorComponent
  3840. ? createVNode(errorComponent, {
  3841. error: err
  3842. })
  3843. : null;
  3844. });
  3845. }
  3846. const loaded = ref(false);
  3847. const error = ref();
  3848. const delayed = ref(!!delay);
  3849. if (delay) {
  3850. setTimeout(() => {
  3851. delayed.value = false;
  3852. }, delay);
  3853. }
  3854. if (timeout != null) {
  3855. setTimeout(() => {
  3856. if (!loaded.value && !error.value) {
  3857. const err = new Error(`Async component timed out after ${timeout}ms.`);
  3858. onError(err);
  3859. error.value = err;
  3860. }
  3861. }, timeout);
  3862. }
  3863. load()
  3864. .then(() => {
  3865. loaded.value = true;
  3866. if (instance.parent && isKeepAlive(instance.parent.vnode)) {
  3867. // parent is keep-alive, force update so the loaded component's
  3868. // name is taken into account
  3869. queueJob(instance.parent.update);
  3870. }
  3871. })
  3872. .catch(err => {
  3873. onError(err);
  3874. error.value = err;
  3875. });
  3876. return () => {
  3877. if (loaded.value && resolvedComp) {
  3878. return createInnerComp(resolvedComp, instance);
  3879. }
  3880. else if (error.value && errorComponent) {
  3881. return createVNode(errorComponent, {
  3882. error: error.value
  3883. });
  3884. }
  3885. else if (loadingComponent && !delayed.value) {
  3886. return createVNode(loadingComponent);
  3887. }
  3888. };
  3889. }
  3890. });
  3891. }
  3892. function createInnerComp(comp, parent) {
  3893. const { ref, props, children, ce } = parent.vnode;
  3894. const vnode = createVNode(comp, props, children);
  3895. // ensure inner component inherits the async wrapper's ref owner
  3896. vnode.ref = ref;
  3897. // pass the custom element callback on to the inner comp
  3898. // and remove it from the async wrapper
  3899. vnode.ce = ce;
  3900. delete parent.vnode.ce;
  3901. return vnode;
  3902. }
  3903. const isKeepAlive = (vnode) => vnode.type.__isKeepAlive;
  3904. const KeepAliveImpl = {
  3905. name: `KeepAlive`,
  3906. // Marker for special handling inside the renderer. We are not using a ===
  3907. // check directly on KeepAlive in the renderer, because importing it directly
  3908. // would prevent it from being tree-shaken.
  3909. __isKeepAlive: true,
  3910. props: {
  3911. include: [String, RegExp, Array],
  3912. exclude: [String, RegExp, Array],
  3913. max: [String, Number]
  3914. },
  3915. setup(props, { slots }) {
  3916. const instance = getCurrentInstance();
  3917. // KeepAlive communicates with the instantiated renderer via the
  3918. // ctx where the renderer passes in its internals,
  3919. // and the KeepAlive instance exposes activate/deactivate implementations.
  3920. // The whole point of this is to avoid importing KeepAlive directly in the
  3921. // renderer to facilitate tree-shaking.
  3922. const sharedContext = instance.ctx;
  3923. const cache = new Map();
  3924. const keys = new Set();
  3925. let current = null;
  3926. {
  3927. instance.__v_cache = cache;
  3928. }
  3929. const parentSuspense = instance.suspense;
  3930. const { renderer: { p: patch, m: move, um: _unmount, o: { createElement } } } = sharedContext;
  3931. const storageContainer = createElement('div');
  3932. sharedContext.activate = (vnode, container, anchor, isSVG, optimized) => {
  3933. const instance = vnode.component;
  3934. move(vnode, container, anchor, 0 /* MoveType.ENTER */, parentSuspense);
  3935. // in case props have changed
  3936. patch(instance.vnode, vnode, container, anchor, instance, parentSuspense, isSVG, vnode.slotScopeIds, optimized);
  3937. queuePostRenderEffect(() => {
  3938. instance.isDeactivated = false;
  3939. if (instance.a) {
  3940. invokeArrayFns(instance.a);
  3941. }
  3942. const vnodeHook = vnode.props && vnode.props.onVnodeMounted;
  3943. if (vnodeHook) {
  3944. invokeVNodeHook(vnodeHook, instance.parent, vnode);
  3945. }
  3946. }, parentSuspense);
  3947. {
  3948. // Update components tree
  3949. devtoolsComponentAdded(instance);
  3950. }
  3951. };
  3952. sharedContext.deactivate = (vnode) => {
  3953. const instance = vnode.component;
  3954. move(vnode, storageContainer, null, 1 /* MoveType.LEAVE */, parentSuspense);
  3955. queuePostRenderEffect(() => {
  3956. if (instance.da) {
  3957. invokeArrayFns(instance.da);
  3958. }
  3959. const vnodeHook = vnode.props && vnode.props.onVnodeUnmounted;
  3960. if (vnodeHook) {
  3961. invokeVNodeHook(vnodeHook, instance.parent, vnode);
  3962. }
  3963. instance.isDeactivated = true;
  3964. }, parentSuspense);
  3965. {
  3966. // Update components tree
  3967. devtoolsComponentAdded(instance);
  3968. }
  3969. };
  3970. function unmount(vnode) {
  3971. // reset the shapeFlag so it can be properly unmounted
  3972. resetShapeFlag(vnode);
  3973. _unmount(vnode, instance, parentSuspense, true);
  3974. }
  3975. function pruneCache(filter) {
  3976. cache.forEach((vnode, key) => {
  3977. const name = getComponentName(vnode.type);
  3978. if (name && (!filter || !filter(name))) {
  3979. pruneCacheEntry(key);
  3980. }
  3981. });
  3982. }
  3983. function pruneCacheEntry(key) {
  3984. const cached = cache.get(key);
  3985. if (!current || !isSameVNodeType(cached, current)) {
  3986. unmount(cached);
  3987. }
  3988. else if (current) {
  3989. // current active instance should no longer be kept-alive.
  3990. // we can't unmount it now but it might be later, so reset its flag now.
  3991. resetShapeFlag(current);
  3992. }
  3993. cache.delete(key);
  3994. keys.delete(key);
  3995. }
  3996. // prune cache on include/exclude prop change
  3997. watch(() => [props.include, props.exclude], ([include, exclude]) => {
  3998. include && pruneCache(name => matches(include, name));
  3999. exclude && pruneCache(name => !matches(exclude, name));
  4000. },
  4001. // prune post-render after `current` has been updated
  4002. { flush: 'post', deep: true });
  4003. // cache sub tree after render
  4004. let pendingCacheKey = null;
  4005. const cacheSubtree = () => {
  4006. // fix #1621, the pendingCacheKey could be 0
  4007. if (pendingCacheKey != null) {
  4008. cache.set(pendingCacheKey, getInnerChild(instance.subTree));
  4009. }
  4010. };
  4011. onMounted(cacheSubtree);
  4012. onUpdated(cacheSubtree);
  4013. onBeforeUnmount(() => {
  4014. cache.forEach(cached => {
  4015. const { subTree, suspense } = instance;
  4016. const vnode = getInnerChild(subTree);
  4017. if (cached.type === vnode.type && cached.key === vnode.key) {
  4018. // current instance will be unmounted as part of keep-alive's unmount
  4019. resetShapeFlag(vnode);
  4020. // but invoke its deactivated hook here
  4021. const da = vnode.component.da;
  4022. da && queuePostRenderEffect(da, suspense);
  4023. return;
  4024. }
  4025. unmount(cached);
  4026. });
  4027. });
  4028. return () => {
  4029. pendingCacheKey = null;
  4030. if (!slots.default) {
  4031. return null;
  4032. }
  4033. const children = slots.default();
  4034. const rawVNode = children[0];
  4035. if (children.length > 1) {
  4036. {
  4037. warn(`KeepAlive should contain exactly one component child.`);
  4038. }
  4039. current = null;
  4040. return children;
  4041. }
  4042. else if (!isVNode(rawVNode) ||
  4043. (!(rawVNode.shapeFlag & 4 /* ShapeFlags.STATEFUL_COMPONENT */) &&
  4044. !(rawVNode.shapeFlag & 128 /* ShapeFlags.SUSPENSE */))) {
  4045. current = null;
  4046. return rawVNode;
  4047. }
  4048. let vnode = getInnerChild(rawVNode);
  4049. const comp = vnode.type;
  4050. // for async components, name check should be based in its loaded
  4051. // inner component if available
  4052. const name = getComponentName(isAsyncWrapper(vnode)
  4053. ? vnode.type.__asyncResolved || {}
  4054. : comp);
  4055. const { include, exclude, max } = props;
  4056. if ((include && (!name || !matches(include, name))) ||
  4057. (exclude && name && matches(exclude, name))) {
  4058. current = vnode;
  4059. return rawVNode;
  4060. }
  4061. const key = vnode.key == null ? comp : vnode.key;
  4062. const cachedVNode = cache.get(key);
  4063. // clone vnode if it's reused because we are going to mutate it
  4064. if (vnode.el) {
  4065. vnode = cloneVNode(vnode);
  4066. if (rawVNode.shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
  4067. rawVNode.ssContent = vnode;
  4068. }
  4069. }
  4070. // #1513 it's possible for the returned vnode to be cloned due to attr
  4071. // fallthrough or scopeId, so the vnode here may not be the final vnode
  4072. // that is mounted. Instead of caching it directly, we store the pending
  4073. // key and cache `instance.subTree` (the normalized vnode) in
  4074. // beforeMount/beforeUpdate hooks.
  4075. pendingCacheKey = key;
  4076. if (cachedVNode) {
  4077. // copy over mounted state
  4078. vnode.el = cachedVNode.el;
  4079. vnode.component = cachedVNode.component;
  4080. if (vnode.transition) {
  4081. // recursively update transition hooks on subTree
  4082. setTransitionHooks(vnode, vnode.transition);
  4083. }
  4084. // avoid vnode being mounted as fresh
  4085. vnode.shapeFlag |= 512 /* ShapeFlags.COMPONENT_KEPT_ALIVE */;
  4086. // make this key the freshest
  4087. keys.delete(key);
  4088. keys.add(key);
  4089. }
  4090. else {
  4091. keys.add(key);
  4092. // prune oldest entry
  4093. if (max && keys.size > parseInt(max, 10)) {
  4094. pruneCacheEntry(keys.values().next().value);
  4095. }
  4096. }
  4097. // avoid vnode being unmounted
  4098. vnode.shapeFlag |= 256 /* ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE */;
  4099. current = vnode;
  4100. return isSuspense(rawVNode.type) ? rawVNode : vnode;
  4101. };
  4102. }
  4103. };
  4104. // export the public type for h/tsx inference
  4105. // also to avoid inline import() in generated d.ts files
  4106. const KeepAlive = KeepAliveImpl;
  4107. function matches(pattern, name) {
  4108. if (isArray(pattern)) {
  4109. return pattern.some((p) => matches(p, name));
  4110. }
  4111. else if (isString(pattern)) {
  4112. return pattern.split(',').includes(name);
  4113. }
  4114. else if (isRegExp(pattern)) {
  4115. return pattern.test(name);
  4116. }
  4117. /* istanbul ignore next */
  4118. return false;
  4119. }
  4120. function onActivated(hook, target) {
  4121. registerKeepAliveHook(hook, "a" /* LifecycleHooks.ACTIVATED */, target);
  4122. }
  4123. function onDeactivated(hook, target) {
  4124. registerKeepAliveHook(hook, "da" /* LifecycleHooks.DEACTIVATED */, target);
  4125. }
  4126. function registerKeepAliveHook(hook, type, target = currentInstance) {
  4127. // cache the deactivate branch check wrapper for injected hooks so the same
  4128. // hook can be properly deduped by the scheduler. "__wdc" stands for "with
  4129. // deactivation check".
  4130. const wrappedHook = hook.__wdc ||
  4131. (hook.__wdc = () => {
  4132. // only fire the hook if the target instance is NOT in a deactivated branch.
  4133. let current = target;
  4134. while (current) {
  4135. if (current.isDeactivated) {
  4136. return;
  4137. }
  4138. current = current.parent;
  4139. }
  4140. return hook();
  4141. });
  4142. injectHook(type, wrappedHook, target);
  4143. // In addition to registering it on the target instance, we walk up the parent
  4144. // chain and register it on all ancestor instances that are keep-alive roots.
  4145. // This avoids the need to walk the entire component tree when invoking these
  4146. // hooks, and more importantly, avoids the need to track child components in
  4147. // arrays.
  4148. if (target) {
  4149. let current = target.parent;
  4150. while (current && current.parent) {
  4151. if (isKeepAlive(current.parent.vnode)) {
  4152. injectToKeepAliveRoot(wrappedHook, type, target, current);
  4153. }
  4154. current = current.parent;
  4155. }
  4156. }
  4157. }
  4158. function injectToKeepAliveRoot(hook, type, target, keepAliveRoot) {
  4159. // injectHook wraps the original for error handling, so make sure to remove
  4160. // the wrapped version.
  4161. const injected = injectHook(type, hook, keepAliveRoot, true /* prepend */);
  4162. onUnmounted(() => {
  4163. remove(keepAliveRoot[type], injected);
  4164. }, target);
  4165. }
  4166. function resetShapeFlag(vnode) {
  4167. // bitwise operations to remove keep alive flags
  4168. vnode.shapeFlag &= ~256 /* ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE */;
  4169. vnode.shapeFlag &= ~512 /* ShapeFlags.COMPONENT_KEPT_ALIVE */;
  4170. }
  4171. function getInnerChild(vnode) {
  4172. return vnode.shapeFlag & 128 /* ShapeFlags.SUSPENSE */ ? vnode.ssContent : vnode;
  4173. }
  4174. function injectHook(type, hook, target = currentInstance, prepend = false) {
  4175. if (target) {
  4176. const hooks = target[type] || (target[type] = []);
  4177. // cache the error handling wrapper for injected hooks so the same hook
  4178. // can be properly deduped by the scheduler. "__weh" stands for "with error
  4179. // handling".
  4180. const wrappedHook = hook.__weh ||
  4181. (hook.__weh = (...args) => {
  4182. if (target.isUnmounted) {
  4183. return;
  4184. }
  4185. // disable tracking inside all lifecycle hooks
  4186. // since they can potentially be called inside effects.
  4187. pauseTracking();
  4188. // Set currentInstance during hook invocation.
  4189. // This assumes the hook does not synchronously trigger other hooks, which
  4190. // can only be false when the user does something really funky.
  4191. setCurrentInstance(target);
  4192. const res = callWithAsyncErrorHandling(hook, target, type, args);
  4193. unsetCurrentInstance();
  4194. resetTracking();
  4195. return res;
  4196. });
  4197. if (prepend) {
  4198. hooks.unshift(wrappedHook);
  4199. }
  4200. else {
  4201. hooks.push(wrappedHook);
  4202. }
  4203. return wrappedHook;
  4204. }
  4205. else {
  4206. const apiName = toHandlerKey(ErrorTypeStrings[type].replace(/ hook$/, ''));
  4207. warn(`${apiName} is called when there is no active component instance to be ` +
  4208. `associated with. ` +
  4209. `Lifecycle injection APIs can only be used during execution of setup().` +
  4210. (` If you are using async setup(), make sure to register lifecycle ` +
  4211. `hooks before the first await statement.`
  4212. ));
  4213. }
  4214. }
  4215. const createHook = (lifecycle) => (hook, target = currentInstance) =>
  4216. // post-create lifecycle registrations are noops during SSR (except for serverPrefetch)
  4217. (!isInSSRComponentSetup || lifecycle === "sp" /* LifecycleHooks.SERVER_PREFETCH */) &&
  4218. injectHook(lifecycle, (...args) => hook(...args), target);
  4219. const onBeforeMount = createHook("bm" /* LifecycleHooks.BEFORE_MOUNT */);
  4220. const onMounted = createHook("m" /* LifecycleHooks.MOUNTED */);
  4221. const onBeforeUpdate = createHook("bu" /* LifecycleHooks.BEFORE_UPDATE */);
  4222. const onUpdated = createHook("u" /* LifecycleHooks.UPDATED */);
  4223. const onBeforeUnmount = createHook("bum" /* LifecycleHooks.BEFORE_UNMOUNT */);
  4224. const onUnmounted = createHook("um" /* LifecycleHooks.UNMOUNTED */);
  4225. const onServerPrefetch = createHook("sp" /* LifecycleHooks.SERVER_PREFETCH */);
  4226. const onRenderTriggered = createHook("rtg" /* LifecycleHooks.RENDER_TRIGGERED */);
  4227. const onRenderTracked = createHook("rtc" /* LifecycleHooks.RENDER_TRACKED */);
  4228. function onErrorCaptured(hook, target = currentInstance) {
  4229. injectHook("ec" /* LifecycleHooks.ERROR_CAPTURED */, hook, target);
  4230. }
  4231. /**
  4232. Runtime helper for applying directives to a vnode. Example usage:
  4233. const comp = resolveComponent('comp')
  4234. const foo = resolveDirective('foo')
  4235. const bar = resolveDirective('bar')
  4236. return withDirectives(h(comp), [
  4237. [foo, this.x],
  4238. [bar, this.y]
  4239. ])
  4240. */
  4241. function validateDirectiveName(name) {
  4242. if (isBuiltInDirective(name)) {
  4243. warn('Do not use built-in directive ids as custom directive id: ' + name);
  4244. }
  4245. }
  4246. /**
  4247. * Adds directives to a VNode.
  4248. */
  4249. function withDirectives(vnode, directives) {
  4250. const internalInstance = currentRenderingInstance;
  4251. if (internalInstance === null) {
  4252. warn(`withDirectives can only be used inside render functions.`);
  4253. return vnode;
  4254. }
  4255. const instance = getExposeProxy(internalInstance) ||
  4256. internalInstance.proxy;
  4257. const bindings = vnode.dirs || (vnode.dirs = []);
  4258. for (let i = 0; i < directives.length; i++) {
  4259. let [dir, value, arg, modifiers = EMPTY_OBJ] = directives[i];
  4260. if (dir) {
  4261. if (isFunction(dir)) {
  4262. dir = {
  4263. mounted: dir,
  4264. updated: dir
  4265. };
  4266. }
  4267. if (dir.deep) {
  4268. traverse(value);
  4269. }
  4270. bindings.push({
  4271. dir,
  4272. instance,
  4273. value,
  4274. oldValue: void 0,
  4275. arg,
  4276. modifiers
  4277. });
  4278. }
  4279. }
  4280. return vnode;
  4281. }
  4282. function invokeDirectiveHook(vnode, prevVNode, instance, name) {
  4283. const bindings = vnode.dirs;
  4284. const oldBindings = prevVNode && prevVNode.dirs;
  4285. for (let i = 0; i < bindings.length; i++) {
  4286. const binding = bindings[i];
  4287. if (oldBindings) {
  4288. binding.oldValue = oldBindings[i].value;
  4289. }
  4290. let hook = binding.dir[name];
  4291. if (hook) {
  4292. // disable tracking inside all lifecycle hooks
  4293. // since they can potentially be called inside effects.
  4294. pauseTracking();
  4295. callWithAsyncErrorHandling(hook, instance, 8 /* ErrorCodes.DIRECTIVE_HOOK */, [
  4296. vnode.el,
  4297. binding,
  4298. vnode,
  4299. prevVNode
  4300. ]);
  4301. resetTracking();
  4302. }
  4303. }
  4304. }
  4305. const COMPONENTS = 'components';
  4306. const DIRECTIVES = 'directives';
  4307. /**
  4308. * @private
  4309. */
  4310. function resolveComponent(name, maybeSelfReference) {
  4311. return resolveAsset(COMPONENTS, name, true, maybeSelfReference) || name;
  4312. }
  4313. const NULL_DYNAMIC_COMPONENT = Symbol();
  4314. /**
  4315. * @private
  4316. */
  4317. function resolveDynamicComponent(component) {
  4318. if (isString(component)) {
  4319. return resolveAsset(COMPONENTS, component, false) || component;
  4320. }
  4321. else {
  4322. // invalid types will fallthrough to createVNode and raise warning
  4323. return (component || NULL_DYNAMIC_COMPONENT);
  4324. }
  4325. }
  4326. /**
  4327. * @private
  4328. */
  4329. function resolveDirective(name) {
  4330. return resolveAsset(DIRECTIVES, name);
  4331. }
  4332. // implementation
  4333. function resolveAsset(type, name, warnMissing = true, maybeSelfReference = false) {
  4334. const instance = currentRenderingInstance || currentInstance;
  4335. if (instance) {
  4336. const Component = instance.type;
  4337. // explicit self name has highest priority
  4338. if (type === COMPONENTS) {
  4339. const selfName = getComponentName(Component, false /* do not include inferred name to avoid breaking existing code */);
  4340. if (selfName &&
  4341. (selfName === name ||
  4342. selfName === camelize(name) ||
  4343. selfName === capitalize(camelize(name)))) {
  4344. return Component;
  4345. }
  4346. }
  4347. const res =
  4348. // local registration
  4349. // check instance[type] first which is resolved for options API
  4350. resolve(instance[type] || Component[type], name) ||
  4351. // global registration
  4352. resolve(instance.appContext[type], name);
  4353. if (!res && maybeSelfReference) {
  4354. // fallback to implicit self-reference
  4355. return Component;
  4356. }
  4357. if (warnMissing && !res) {
  4358. const extra = type === COMPONENTS
  4359. ? `\nIf this is a native custom element, make sure to exclude it from ` +
  4360. `component resolution via compilerOptions.isCustomElement.`
  4361. : ``;
  4362. warn(`Failed to resolve ${type.slice(0, -1)}: ${name}${extra}`);
  4363. }
  4364. return res;
  4365. }
  4366. else {
  4367. warn(`resolve${capitalize(type.slice(0, -1))} ` +
  4368. `can only be used in render() or setup().`);
  4369. }
  4370. }
  4371. function resolve(registry, name) {
  4372. return (registry &&
  4373. (registry[name] ||
  4374. registry[camelize(name)] ||
  4375. registry[capitalize(camelize(name))]));
  4376. }
  4377. /**
  4378. * Actual implementation
  4379. */
  4380. function renderList(source, renderItem, cache, index) {
  4381. let ret;
  4382. const cached = (cache && cache[index]);
  4383. if (isArray(source) || isString(source)) {
  4384. ret = new Array(source.length);
  4385. for (let i = 0, l = source.length; i < l; i++) {
  4386. ret[i] = renderItem(source[i], i, undefined, cached && cached[i]);
  4387. }
  4388. }
  4389. else if (typeof source === 'number') {
  4390. if (!Number.isInteger(source)) {
  4391. warn(`The v-for range expect an integer value but got ${source}.`);
  4392. }
  4393. ret = new Array(source);
  4394. for (let i = 0; i < source; i++) {
  4395. ret[i] = renderItem(i + 1, i, undefined, cached && cached[i]);
  4396. }
  4397. }
  4398. else if (isObject(source)) {
  4399. if (source[Symbol.iterator]) {
  4400. ret = Array.from(source, (item, i) => renderItem(item, i, undefined, cached && cached[i]));
  4401. }
  4402. else {
  4403. const keys = Object.keys(source);
  4404. ret = new Array(keys.length);
  4405. for (let i = 0, l = keys.length; i < l; i++) {
  4406. const key = keys[i];
  4407. ret[i] = renderItem(source[key], key, i, cached && cached[i]);
  4408. }
  4409. }
  4410. }
  4411. else {
  4412. ret = [];
  4413. }
  4414. if (cache) {
  4415. cache[index] = ret;
  4416. }
  4417. return ret;
  4418. }
  4419. /**
  4420. * Compiler runtime helper for creating dynamic slots object
  4421. * @private
  4422. */
  4423. function createSlots(slots, dynamicSlots) {
  4424. for (let i = 0; i < dynamicSlots.length; i++) {
  4425. const slot = dynamicSlots[i];
  4426. // array of dynamic slot generated by <template v-for="..." #[...]>
  4427. if (isArray(slot)) {
  4428. for (let j = 0; j < slot.length; j++) {
  4429. slots[slot[j].name] = slot[j].fn;
  4430. }
  4431. }
  4432. else if (slot) {
  4433. // conditional single slot generated by <template v-if="..." #foo>
  4434. slots[slot.name] = slot.key
  4435. ? (...args) => {
  4436. const res = slot.fn(...args);
  4437. // attach branch key so each conditional branch is considered a
  4438. // different fragment
  4439. if (res)
  4440. res.key = slot.key;
  4441. return res;
  4442. }
  4443. : slot.fn;
  4444. }
  4445. }
  4446. return slots;
  4447. }
  4448. /**
  4449. * Compiler runtime helper for rendering `<slot/>`
  4450. * @private
  4451. */
  4452. function renderSlot(slots, name, props = {},
  4453. // this is not a user-facing function, so the fallback is always generated by
  4454. // the compiler and guaranteed to be a function returning an array
  4455. fallback, noSlotted) {
  4456. if (currentRenderingInstance.isCE ||
  4457. (currentRenderingInstance.parent &&
  4458. isAsyncWrapper(currentRenderingInstance.parent) &&
  4459. currentRenderingInstance.parent.isCE)) {
  4460. if (name !== 'default')
  4461. props.name = name;
  4462. return createVNode('slot', props, fallback && fallback());
  4463. }
  4464. let slot = slots[name];
  4465. if (slot && slot.length > 1) {
  4466. warn(`SSR-optimized slot function detected in a non-SSR-optimized render ` +
  4467. `function. You need to mark this component with $dynamic-slots in the ` +
  4468. `parent template.`);
  4469. slot = () => [];
  4470. }
  4471. // a compiled slot disables block tracking by default to avoid manual
  4472. // invocation interfering with template-based block tracking, but in
  4473. // `renderSlot` we can be sure that it's template-based so we can force
  4474. // enable it.
  4475. if (slot && slot._c) {
  4476. slot._d = false;
  4477. }
  4478. openBlock();
  4479. const validSlotContent = slot && ensureValidVNode(slot(props));
  4480. const rendered = createBlock(Fragment, {
  4481. key: props.key ||
  4482. // slot content array of a dynamic conditional slot may have a branch
  4483. // key attached in the `createSlots` helper, respect that
  4484. (validSlotContent && validSlotContent.key) ||
  4485. `_${name}`
  4486. }, validSlotContent || (fallback ? fallback() : []), validSlotContent && slots._ === 1 /* SlotFlags.STABLE */
  4487. ? 64 /* PatchFlags.STABLE_FRAGMENT */
  4488. : -2 /* PatchFlags.BAIL */);
  4489. if (!noSlotted && rendered.scopeId) {
  4490. rendered.slotScopeIds = [rendered.scopeId + '-s'];
  4491. }
  4492. if (slot && slot._c) {
  4493. slot._d = true;
  4494. }
  4495. return rendered;
  4496. }
  4497. function ensureValidVNode(vnodes) {
  4498. return vnodes.some(child => {
  4499. if (!isVNode(child))
  4500. return true;
  4501. if (child.type === Comment)
  4502. return false;
  4503. if (child.type === Fragment &&
  4504. !ensureValidVNode(child.children))
  4505. return false;
  4506. return true;
  4507. })
  4508. ? vnodes
  4509. : null;
  4510. }
  4511. /**
  4512. * For prefixing keys in v-on="obj" with "on"
  4513. * @private
  4514. */
  4515. function toHandlers(obj, preserveCaseIfNecessary) {
  4516. const ret = {};
  4517. if (!isObject(obj)) {
  4518. warn(`v-on with no argument expects an object value.`);
  4519. return ret;
  4520. }
  4521. for (const key in obj) {
  4522. ret[preserveCaseIfNecessary && /[A-Z]/.test(key)
  4523. ? `on:${key}`
  4524. : toHandlerKey(key)] = obj[key];
  4525. }
  4526. return ret;
  4527. }
  4528. /**
  4529. * #2437 In Vue 3, functional components do not have a public instance proxy but
  4530. * they exist in the internal parent chain. For code that relies on traversing
  4531. * public $parent chains, skip functional ones and go to the parent instead.
  4532. */
  4533. const getPublicInstance = (i) => {
  4534. if (!i)
  4535. return null;
  4536. if (isStatefulComponent(i))
  4537. return getExposeProxy(i) || i.proxy;
  4538. return getPublicInstance(i.parent);
  4539. };
  4540. const publicPropertiesMap =
  4541. // Move PURE marker to new line to workaround compiler discarding it
  4542. // due to type annotation
  4543. /*#__PURE__*/ extend(Object.create(null), {
  4544. $: i => i,
  4545. $el: i => i.vnode.el,
  4546. $data: i => i.data,
  4547. $props: i => (shallowReadonly(i.props) ),
  4548. $attrs: i => (shallowReadonly(i.attrs) ),
  4549. $slots: i => (shallowReadonly(i.slots) ),
  4550. $refs: i => (shallowReadonly(i.refs) ),
  4551. $parent: i => getPublicInstance(i.parent),
  4552. $root: i => getPublicInstance(i.root),
  4553. $emit: i => i.emit,
  4554. $options: i => (resolveMergedOptions(i) ),
  4555. $forceUpdate: i => i.f || (i.f = () => queueJob(i.update)),
  4556. $nextTick: i => i.n || (i.n = nextTick.bind(i.proxy)),
  4557. $watch: i => (instanceWatch.bind(i) )
  4558. });
  4559. const isReservedPrefix = (key) => key === '_' || key === '$';
  4560. const hasSetupBinding = (state, key) => state !== EMPTY_OBJ && !state.__isScriptSetup && hasOwn(state, key);
  4561. const PublicInstanceProxyHandlers = {
  4562. get({ _: instance }, key) {
  4563. const { ctx, setupState, data, props, accessCache, type, appContext } = instance;
  4564. // for internal formatters to know that this is a Vue instance
  4565. if (key === '__isVue') {
  4566. return true;
  4567. }
  4568. // data / props / ctx
  4569. // This getter gets called for every property access on the render context
  4570. // during render and is a major hotspot. The most expensive part of this
  4571. // is the multiple hasOwn() calls. It's much faster to do a simple property
  4572. // access on a plain object, so we use an accessCache object (with null
  4573. // prototype) to memoize what access type a key corresponds to.
  4574. let normalizedProps;
  4575. if (key[0] !== '$') {
  4576. const n = accessCache[key];
  4577. if (n !== undefined) {
  4578. switch (n) {
  4579. case 1 /* AccessTypes.SETUP */:
  4580. return setupState[key];
  4581. case 2 /* AccessTypes.DATA */:
  4582. return data[key];
  4583. case 4 /* AccessTypes.CONTEXT */:
  4584. return ctx[key];
  4585. case 3 /* AccessTypes.PROPS */:
  4586. return props[key];
  4587. // default: just fallthrough
  4588. }
  4589. }
  4590. else if (hasSetupBinding(setupState, key)) {
  4591. accessCache[key] = 1 /* AccessTypes.SETUP */;
  4592. return setupState[key];
  4593. }
  4594. else if (data !== EMPTY_OBJ && hasOwn(data, key)) {
  4595. accessCache[key] = 2 /* AccessTypes.DATA */;
  4596. return data[key];
  4597. }
  4598. else if (
  4599. // only cache other properties when instance has declared (thus stable)
  4600. // props
  4601. (normalizedProps = instance.propsOptions[0]) &&
  4602. hasOwn(normalizedProps, key)) {
  4603. accessCache[key] = 3 /* AccessTypes.PROPS */;
  4604. return props[key];
  4605. }
  4606. else if (ctx !== EMPTY_OBJ && hasOwn(ctx, key)) {
  4607. accessCache[key] = 4 /* AccessTypes.CONTEXT */;
  4608. return ctx[key];
  4609. }
  4610. else if (shouldCacheAccess) {
  4611. accessCache[key] = 0 /* AccessTypes.OTHER */;
  4612. }
  4613. }
  4614. const publicGetter = publicPropertiesMap[key];
  4615. let cssModule, globalProperties;
  4616. // public $xxx properties
  4617. if (publicGetter) {
  4618. if (key === '$attrs') {
  4619. track(instance, "get" /* TrackOpTypes.GET */, key);
  4620. markAttrsAccessed();
  4621. }
  4622. return publicGetter(instance);
  4623. }
  4624. else if (
  4625. // css module (injected by vue-loader)
  4626. (cssModule = type.__cssModules) &&
  4627. (cssModule = cssModule[key])) {
  4628. return cssModule;
  4629. }
  4630. else if (ctx !== EMPTY_OBJ && hasOwn(ctx, key)) {
  4631. // user may set custom properties to `this` that start with `$`
  4632. accessCache[key] = 4 /* AccessTypes.CONTEXT */;
  4633. return ctx[key];
  4634. }
  4635. else if (
  4636. // global properties
  4637. ((globalProperties = appContext.config.globalProperties),
  4638. hasOwn(globalProperties, key))) {
  4639. {
  4640. return globalProperties[key];
  4641. }
  4642. }
  4643. else if (currentRenderingInstance &&
  4644. (!isString(key) ||
  4645. // #1091 avoid internal isRef/isVNode checks on component instance leading
  4646. // to infinite warning loop
  4647. key.indexOf('__v') !== 0)) {
  4648. if (data !== EMPTY_OBJ && isReservedPrefix(key[0]) && hasOwn(data, key)) {
  4649. warn(`Property ${JSON.stringify(key)} must be accessed via $data because it starts with a reserved ` +
  4650. `character ("$" or "_") and is not proxied on the render context.`);
  4651. }
  4652. else if (instance === currentRenderingInstance) {
  4653. warn(`Property ${JSON.stringify(key)} was accessed during render ` +
  4654. `but is not defined on instance.`);
  4655. }
  4656. }
  4657. },
  4658. set({ _: instance }, key, value) {
  4659. const { data, setupState, ctx } = instance;
  4660. if (hasSetupBinding(setupState, key)) {
  4661. setupState[key] = value;
  4662. return true;
  4663. }
  4664. else if (setupState.__isScriptSetup &&
  4665. hasOwn(setupState, key)) {
  4666. warn(`Cannot mutate <script setup> binding "${key}" from Options API.`);
  4667. return false;
  4668. }
  4669. else if (data !== EMPTY_OBJ && hasOwn(data, key)) {
  4670. data[key] = value;
  4671. return true;
  4672. }
  4673. else if (hasOwn(instance.props, key)) {
  4674. warn(`Attempting to mutate prop "${key}". Props are readonly.`);
  4675. return false;
  4676. }
  4677. if (key[0] === '$' && key.slice(1) in instance) {
  4678. warn(`Attempting to mutate public property "${key}". ` +
  4679. `Properties starting with $ are reserved and readonly.`);
  4680. return false;
  4681. }
  4682. else {
  4683. if (key in instance.appContext.config.globalProperties) {
  4684. Object.defineProperty(ctx, key, {
  4685. enumerable: true,
  4686. configurable: true,
  4687. value
  4688. });
  4689. }
  4690. else {
  4691. ctx[key] = value;
  4692. }
  4693. }
  4694. return true;
  4695. },
  4696. has({ _: { data, setupState, accessCache, ctx, appContext, propsOptions } }, key) {
  4697. let normalizedProps;
  4698. return (!!accessCache[key] ||
  4699. (data !== EMPTY_OBJ && hasOwn(data, key)) ||
  4700. hasSetupBinding(setupState, key) ||
  4701. ((normalizedProps = propsOptions[0]) && hasOwn(normalizedProps, key)) ||
  4702. hasOwn(ctx, key) ||
  4703. hasOwn(publicPropertiesMap, key) ||
  4704. hasOwn(appContext.config.globalProperties, key));
  4705. },
  4706. defineProperty(target, key, descriptor) {
  4707. if (descriptor.get != null) {
  4708. // invalidate key cache of a getter based property #5417
  4709. target._.accessCache[key] = 0;
  4710. }
  4711. else if (hasOwn(descriptor, 'value')) {
  4712. this.set(target, key, descriptor.value, null);
  4713. }
  4714. return Reflect.defineProperty(target, key, descriptor);
  4715. }
  4716. };
  4717. {
  4718. PublicInstanceProxyHandlers.ownKeys = (target) => {
  4719. warn(`Avoid app logic that relies on enumerating keys on a component instance. ` +
  4720. `The keys will be empty in production mode to avoid performance overhead.`);
  4721. return Reflect.ownKeys(target);
  4722. };
  4723. }
  4724. const RuntimeCompiledPublicInstanceProxyHandlers = /*#__PURE__*/ extend({}, PublicInstanceProxyHandlers, {
  4725. get(target, key) {
  4726. // fast path for unscopables when using `with` block
  4727. if (key === Symbol.unscopables) {
  4728. return;
  4729. }
  4730. return PublicInstanceProxyHandlers.get(target, key, target);
  4731. },
  4732. has(_, key) {
  4733. const has = key[0] !== '_' && !isGloballyWhitelisted(key);
  4734. if (!has && PublicInstanceProxyHandlers.has(_, key)) {
  4735. warn(`Property ${JSON.stringify(key)} should not start with _ which is a reserved prefix for Vue internals.`);
  4736. }
  4737. return has;
  4738. }
  4739. });
  4740. // dev only
  4741. // In dev mode, the proxy target exposes the same properties as seen on `this`
  4742. // for easier console inspection. In prod mode it will be an empty object so
  4743. // these properties definitions can be skipped.
  4744. function createDevRenderContext(instance) {
  4745. const target = {};
  4746. // expose internal instance for proxy handlers
  4747. Object.defineProperty(target, `_`, {
  4748. configurable: true,
  4749. enumerable: false,
  4750. get: () => instance
  4751. });
  4752. // expose public properties
  4753. Object.keys(publicPropertiesMap).forEach(key => {
  4754. Object.defineProperty(target, key, {
  4755. configurable: true,
  4756. enumerable: false,
  4757. get: () => publicPropertiesMap[key](instance),
  4758. // intercepted by the proxy so no need for implementation,
  4759. // but needed to prevent set errors
  4760. set: NOOP
  4761. });
  4762. });
  4763. return target;
  4764. }
  4765. // dev only
  4766. function exposePropsOnRenderContext(instance) {
  4767. const { ctx, propsOptions: [propsOptions] } = instance;
  4768. if (propsOptions) {
  4769. Object.keys(propsOptions).forEach(key => {
  4770. Object.defineProperty(ctx, key, {
  4771. enumerable: true,
  4772. configurable: true,
  4773. get: () => instance.props[key],
  4774. set: NOOP
  4775. });
  4776. });
  4777. }
  4778. }
  4779. // dev only
  4780. function exposeSetupStateOnRenderContext(instance) {
  4781. const { ctx, setupState } = instance;
  4782. Object.keys(toRaw(setupState)).forEach(key => {
  4783. if (!setupState.__isScriptSetup) {
  4784. if (isReservedPrefix(key[0])) {
  4785. warn(`setup() return property ${JSON.stringify(key)} should not start with "$" or "_" ` +
  4786. `which are reserved prefixes for Vue internals.`);
  4787. return;
  4788. }
  4789. Object.defineProperty(ctx, key, {
  4790. enumerable: true,
  4791. configurable: true,
  4792. get: () => setupState[key],
  4793. set: NOOP
  4794. });
  4795. }
  4796. });
  4797. }
  4798. function createDuplicateChecker() {
  4799. const cache = Object.create(null);
  4800. return (type, key) => {
  4801. if (cache[key]) {
  4802. warn(`${type} property "${key}" is already defined in ${cache[key]}.`);
  4803. }
  4804. else {
  4805. cache[key] = type;
  4806. }
  4807. };
  4808. }
  4809. let shouldCacheAccess = true;
  4810. function applyOptions(instance) {
  4811. const options = resolveMergedOptions(instance);
  4812. const publicThis = instance.proxy;
  4813. const ctx = instance.ctx;
  4814. // do not cache property access on public proxy during state initialization
  4815. shouldCacheAccess = false;
  4816. // call beforeCreate first before accessing other options since
  4817. // the hook may mutate resolved options (#2791)
  4818. if (options.beforeCreate) {
  4819. callHook$1(options.beforeCreate, instance, "bc" /* LifecycleHooks.BEFORE_CREATE */);
  4820. }
  4821. const {
  4822. // state
  4823. data: dataOptions, computed: computedOptions, methods, watch: watchOptions, provide: provideOptions, inject: injectOptions,
  4824. // lifecycle
  4825. created, beforeMount, mounted, beforeUpdate, updated, activated, deactivated, beforeDestroy, beforeUnmount, destroyed, unmounted, render, renderTracked, renderTriggered, errorCaptured, serverPrefetch,
  4826. // public API
  4827. expose, inheritAttrs,
  4828. // assets
  4829. components, directives, filters } = options;
  4830. const checkDuplicateProperties = createDuplicateChecker() ;
  4831. {
  4832. const [propsOptions] = instance.propsOptions;
  4833. if (propsOptions) {
  4834. for (const key in propsOptions) {
  4835. checkDuplicateProperties("Props" /* OptionTypes.PROPS */, key);
  4836. }
  4837. }
  4838. }
  4839. // options initialization order (to be consistent with Vue 2):
  4840. // - props (already done outside of this function)
  4841. // - inject
  4842. // - methods
  4843. // - data (deferred since it relies on `this` access)
  4844. // - computed
  4845. // - watch (deferred since it relies on `this` access)
  4846. if (injectOptions) {
  4847. resolveInjections(injectOptions, ctx, checkDuplicateProperties, instance.appContext.config.unwrapInjectedRef);
  4848. }
  4849. if (methods) {
  4850. for (const key in methods) {
  4851. const methodHandler = methods[key];
  4852. if (isFunction(methodHandler)) {
  4853. // In dev mode, we use the `createRenderContext` function to define
  4854. // methods to the proxy target, and those are read-only but
  4855. // reconfigurable, so it needs to be redefined here
  4856. {
  4857. Object.defineProperty(ctx, key, {
  4858. value: methodHandler.bind(publicThis),
  4859. configurable: true,
  4860. enumerable: true,
  4861. writable: true
  4862. });
  4863. }
  4864. {
  4865. checkDuplicateProperties("Methods" /* OptionTypes.METHODS */, key);
  4866. }
  4867. }
  4868. else {
  4869. warn(`Method "${key}" has type "${typeof methodHandler}" in the component definition. ` +
  4870. `Did you reference the function correctly?`);
  4871. }
  4872. }
  4873. }
  4874. if (dataOptions) {
  4875. if (!isFunction(dataOptions)) {
  4876. warn(`The data option must be a function. ` +
  4877. `Plain object usage is no longer supported.`);
  4878. }
  4879. const data = dataOptions.call(publicThis, publicThis);
  4880. if (isPromise(data)) {
  4881. warn(`data() returned a Promise - note data() cannot be async; If you ` +
  4882. `intend to perform data fetching before component renders, use ` +
  4883. `async setup() + <Suspense>.`);
  4884. }
  4885. if (!isObject(data)) {
  4886. warn(`data() should return an object.`);
  4887. }
  4888. else {
  4889. instance.data = reactive(data);
  4890. {
  4891. for (const key in data) {
  4892. checkDuplicateProperties("Data" /* OptionTypes.DATA */, key);
  4893. // expose data on ctx during dev
  4894. if (!isReservedPrefix(key[0])) {
  4895. Object.defineProperty(ctx, key, {
  4896. configurable: true,
  4897. enumerable: true,
  4898. get: () => data[key],
  4899. set: NOOP
  4900. });
  4901. }
  4902. }
  4903. }
  4904. }
  4905. }
  4906. // state initialization complete at this point - start caching access
  4907. shouldCacheAccess = true;
  4908. if (computedOptions) {
  4909. for (const key in computedOptions) {
  4910. const opt = computedOptions[key];
  4911. const get = isFunction(opt)
  4912. ? opt.bind(publicThis, publicThis)
  4913. : isFunction(opt.get)
  4914. ? opt.get.bind(publicThis, publicThis)
  4915. : NOOP;
  4916. if (get === NOOP) {
  4917. warn(`Computed property "${key}" has no getter.`);
  4918. }
  4919. const set = !isFunction(opt) && isFunction(opt.set)
  4920. ? opt.set.bind(publicThis)
  4921. : () => {
  4922. warn(`Write operation failed: computed property "${key}" is readonly.`);
  4923. }
  4924. ;
  4925. const c = computed({
  4926. get,
  4927. set
  4928. });
  4929. Object.defineProperty(ctx, key, {
  4930. enumerable: true,
  4931. configurable: true,
  4932. get: () => c.value,
  4933. set: v => (c.value = v)
  4934. });
  4935. {
  4936. checkDuplicateProperties("Computed" /* OptionTypes.COMPUTED */, key);
  4937. }
  4938. }
  4939. }
  4940. if (watchOptions) {
  4941. for (const key in watchOptions) {
  4942. createWatcher(watchOptions[key], ctx, publicThis, key);
  4943. }
  4944. }
  4945. if (provideOptions) {
  4946. const provides = isFunction(provideOptions)
  4947. ? provideOptions.call(publicThis)
  4948. : provideOptions;
  4949. Reflect.ownKeys(provides).forEach(key => {
  4950. provide(key, provides[key]);
  4951. });
  4952. }
  4953. if (created) {
  4954. callHook$1(created, instance, "c" /* LifecycleHooks.CREATED */);
  4955. }
  4956. function registerLifecycleHook(register, hook) {
  4957. if (isArray(hook)) {
  4958. hook.forEach(_hook => register(_hook.bind(publicThis)));
  4959. }
  4960. else if (hook) {
  4961. register(hook.bind(publicThis));
  4962. }
  4963. }
  4964. registerLifecycleHook(onBeforeMount, beforeMount);
  4965. registerLifecycleHook(onMounted, mounted);
  4966. registerLifecycleHook(onBeforeUpdate, beforeUpdate);
  4967. registerLifecycleHook(onUpdated, updated);
  4968. registerLifecycleHook(onActivated, activated);
  4969. registerLifecycleHook(onDeactivated, deactivated);
  4970. registerLifecycleHook(onErrorCaptured, errorCaptured);
  4971. registerLifecycleHook(onRenderTracked, renderTracked);
  4972. registerLifecycleHook(onRenderTriggered, renderTriggered);
  4973. registerLifecycleHook(onBeforeUnmount, beforeUnmount);
  4974. registerLifecycleHook(onUnmounted, unmounted);
  4975. registerLifecycleHook(onServerPrefetch, serverPrefetch);
  4976. if (isArray(expose)) {
  4977. if (expose.length) {
  4978. const exposed = instance.exposed || (instance.exposed = {});
  4979. expose.forEach(key => {
  4980. Object.defineProperty(exposed, key, {
  4981. get: () => publicThis[key],
  4982. set: val => (publicThis[key] = val)
  4983. });
  4984. });
  4985. }
  4986. else if (!instance.exposed) {
  4987. instance.exposed = {};
  4988. }
  4989. }
  4990. // options that are handled when creating the instance but also need to be
  4991. // applied from mixins
  4992. if (render && instance.render === NOOP) {
  4993. instance.render = render;
  4994. }
  4995. if (inheritAttrs != null) {
  4996. instance.inheritAttrs = inheritAttrs;
  4997. }
  4998. // asset options.
  4999. if (components)
  5000. instance.components = components;
  5001. if (directives)
  5002. instance.directives = directives;
  5003. }
  5004. function resolveInjections(injectOptions, ctx, checkDuplicateProperties = NOOP, unwrapRef = false) {
  5005. if (isArray(injectOptions)) {
  5006. injectOptions = normalizeInject(injectOptions);
  5007. }
  5008. for (const key in injectOptions) {
  5009. const opt = injectOptions[key];
  5010. let injected;
  5011. if (isObject(opt)) {
  5012. if ('default' in opt) {
  5013. injected = inject(opt.from || key, opt.default, true /* treat default function as factory */);
  5014. }
  5015. else {
  5016. injected = inject(opt.from || key);
  5017. }
  5018. }
  5019. else {
  5020. injected = inject(opt);
  5021. }
  5022. if (isRef(injected)) {
  5023. // TODO remove the check in 3.3
  5024. if (unwrapRef) {
  5025. Object.defineProperty(ctx, key, {
  5026. enumerable: true,
  5027. configurable: true,
  5028. get: () => injected.value,
  5029. set: v => (injected.value = v)
  5030. });
  5031. }
  5032. else {
  5033. {
  5034. warn(`injected property "${key}" is a ref and will be auto-unwrapped ` +
  5035. `and no longer needs \`.value\` in the next minor release. ` +
  5036. `To opt-in to the new behavior now, ` +
  5037. `set \`app.config.unwrapInjectedRef = true\` (this config is ` +
  5038. `temporary and will not be needed in the future.)`);
  5039. }
  5040. ctx[key] = injected;
  5041. }
  5042. }
  5043. else {
  5044. ctx[key] = injected;
  5045. }
  5046. {
  5047. checkDuplicateProperties("Inject" /* OptionTypes.INJECT */, key);
  5048. }
  5049. }
  5050. }
  5051. function callHook$1(hook, instance, type) {
  5052. callWithAsyncErrorHandling(isArray(hook)
  5053. ? hook.map(h => h.bind(instance.proxy))
  5054. : hook.bind(instance.proxy), instance, type);
  5055. }
  5056. function createWatcher(raw, ctx, publicThis, key) {
  5057. const getter = key.includes('.')
  5058. ? createPathGetter(publicThis, key)
  5059. : () => publicThis[key];
  5060. if (isString(raw)) {
  5061. const handler = ctx[raw];
  5062. if (isFunction(handler)) {
  5063. watch(getter, handler);
  5064. }
  5065. else {
  5066. warn(`Invalid watch handler specified by key "${raw}"`, handler);
  5067. }
  5068. }
  5069. else if (isFunction(raw)) {
  5070. watch(getter, raw.bind(publicThis));
  5071. }
  5072. else if (isObject(raw)) {
  5073. if (isArray(raw)) {
  5074. raw.forEach(r => createWatcher(r, ctx, publicThis, key));
  5075. }
  5076. else {
  5077. const handler = isFunction(raw.handler)
  5078. ? raw.handler.bind(publicThis)
  5079. : ctx[raw.handler];
  5080. if (isFunction(handler)) {
  5081. watch(getter, handler, raw);
  5082. }
  5083. else {
  5084. warn(`Invalid watch handler specified by key "${raw.handler}"`, handler);
  5085. }
  5086. }
  5087. }
  5088. else {
  5089. warn(`Invalid watch option: "${key}"`, raw);
  5090. }
  5091. }
  5092. /**
  5093. * Resolve merged options and cache it on the component.
  5094. * This is done only once per-component since the merging does not involve
  5095. * instances.
  5096. */
  5097. function resolveMergedOptions(instance) {
  5098. const base = instance.type;
  5099. const { mixins, extends: extendsOptions } = base;
  5100. const { mixins: globalMixins, optionsCache: cache, config: { optionMergeStrategies } } = instance.appContext;
  5101. const cached = cache.get(base);
  5102. let resolved;
  5103. if (cached) {
  5104. resolved = cached;
  5105. }
  5106. else if (!globalMixins.length && !mixins && !extendsOptions) {
  5107. {
  5108. resolved = base;
  5109. }
  5110. }
  5111. else {
  5112. resolved = {};
  5113. if (globalMixins.length) {
  5114. globalMixins.forEach(m => mergeOptions(resolved, m, optionMergeStrategies, true));
  5115. }
  5116. mergeOptions(resolved, base, optionMergeStrategies);
  5117. }
  5118. if (isObject(base)) {
  5119. cache.set(base, resolved);
  5120. }
  5121. return resolved;
  5122. }
  5123. function mergeOptions(to, from, strats, asMixin = false) {
  5124. const { mixins, extends: extendsOptions } = from;
  5125. if (extendsOptions) {
  5126. mergeOptions(to, extendsOptions, strats, true);
  5127. }
  5128. if (mixins) {
  5129. mixins.forEach((m) => mergeOptions(to, m, strats, true));
  5130. }
  5131. for (const key in from) {
  5132. if (asMixin && key === 'expose') {
  5133. warn(`"expose" option is ignored when declared in mixins or extends. ` +
  5134. `It should only be declared in the base component itself.`);
  5135. }
  5136. else {
  5137. const strat = internalOptionMergeStrats[key] || (strats && strats[key]);
  5138. to[key] = strat ? strat(to[key], from[key]) : from[key];
  5139. }
  5140. }
  5141. return to;
  5142. }
  5143. const internalOptionMergeStrats = {
  5144. data: mergeDataFn,
  5145. props: mergeObjectOptions,
  5146. emits: mergeObjectOptions,
  5147. // objects
  5148. methods: mergeObjectOptions,
  5149. computed: mergeObjectOptions,
  5150. // lifecycle
  5151. beforeCreate: mergeAsArray,
  5152. created: mergeAsArray,
  5153. beforeMount: mergeAsArray,
  5154. mounted: mergeAsArray,
  5155. beforeUpdate: mergeAsArray,
  5156. updated: mergeAsArray,
  5157. beforeDestroy: mergeAsArray,
  5158. beforeUnmount: mergeAsArray,
  5159. destroyed: mergeAsArray,
  5160. unmounted: mergeAsArray,
  5161. activated: mergeAsArray,
  5162. deactivated: mergeAsArray,
  5163. errorCaptured: mergeAsArray,
  5164. serverPrefetch: mergeAsArray,
  5165. // assets
  5166. components: mergeObjectOptions,
  5167. directives: mergeObjectOptions,
  5168. // watch
  5169. watch: mergeWatchOptions,
  5170. // provide / inject
  5171. provide: mergeDataFn,
  5172. inject: mergeInject
  5173. };
  5174. function mergeDataFn(to, from) {
  5175. if (!from) {
  5176. return to;
  5177. }
  5178. if (!to) {
  5179. return from;
  5180. }
  5181. return function mergedDataFn() {
  5182. return (extend)(isFunction(to) ? to.call(this, this) : to, isFunction(from) ? from.call(this, this) : from);
  5183. };
  5184. }
  5185. function mergeInject(to, from) {
  5186. return mergeObjectOptions(normalizeInject(to), normalizeInject(from));
  5187. }
  5188. function normalizeInject(raw) {
  5189. if (isArray(raw)) {
  5190. const res = {};
  5191. for (let i = 0; i < raw.length; i++) {
  5192. res[raw[i]] = raw[i];
  5193. }
  5194. return res;
  5195. }
  5196. return raw;
  5197. }
  5198. function mergeAsArray(to, from) {
  5199. return to ? [...new Set([].concat(to, from))] : from;
  5200. }
  5201. function mergeObjectOptions(to, from) {
  5202. return to ? extend(extend(Object.create(null), to), from) : from;
  5203. }
  5204. function mergeWatchOptions(to, from) {
  5205. if (!to)
  5206. return from;
  5207. if (!from)
  5208. return to;
  5209. const merged = extend(Object.create(null), to);
  5210. for (const key in from) {
  5211. merged[key] = mergeAsArray(to[key], from[key]);
  5212. }
  5213. return merged;
  5214. }
  5215. function initProps(instance, rawProps, isStateful, // result of bitwise flag comparison
  5216. isSSR = false) {
  5217. const props = {};
  5218. const attrs = {};
  5219. def(attrs, InternalObjectKey, 1);
  5220. instance.propsDefaults = Object.create(null);
  5221. setFullProps(instance, rawProps, props, attrs);
  5222. // ensure all declared prop keys are present
  5223. for (const key in instance.propsOptions[0]) {
  5224. if (!(key in props)) {
  5225. props[key] = undefined;
  5226. }
  5227. }
  5228. // validation
  5229. {
  5230. validateProps(rawProps || {}, props, instance);
  5231. }
  5232. if (isStateful) {
  5233. // stateful
  5234. instance.props = isSSR ? props : shallowReactive(props);
  5235. }
  5236. else {
  5237. if (!instance.type.props) {
  5238. // functional w/ optional props, props === attrs
  5239. instance.props = attrs;
  5240. }
  5241. else {
  5242. // functional w/ declared props
  5243. instance.props = props;
  5244. }
  5245. }
  5246. instance.attrs = attrs;
  5247. }
  5248. function isInHmrContext(instance) {
  5249. while (instance) {
  5250. if (instance.type.__hmrId)
  5251. return true;
  5252. instance = instance.parent;
  5253. }
  5254. }
  5255. function updateProps(instance, rawProps, rawPrevProps, optimized) {
  5256. const { props, attrs, vnode: { patchFlag } } = instance;
  5257. const rawCurrentProps = toRaw(props);
  5258. const [options] = instance.propsOptions;
  5259. let hasAttrsChanged = false;
  5260. if (
  5261. // always force full diff in dev
  5262. // - #1942 if hmr is enabled with sfc component
  5263. // - vite#872 non-sfc component used by sfc component
  5264. !(isInHmrContext(instance)) &&
  5265. (optimized || patchFlag > 0) &&
  5266. !(patchFlag & 16 /* PatchFlags.FULL_PROPS */)) {
  5267. if (patchFlag & 8 /* PatchFlags.PROPS */) {
  5268. // Compiler-generated props & no keys change, just set the updated
  5269. // the props.
  5270. const propsToUpdate = instance.vnode.dynamicProps;
  5271. for (let i = 0; i < propsToUpdate.length; i++) {
  5272. let key = propsToUpdate[i];
  5273. // skip if the prop key is a declared emit event listener
  5274. if (isEmitListener(instance.emitsOptions, key)) {
  5275. continue;
  5276. }
  5277. // PROPS flag guarantees rawProps to be non-null
  5278. const value = rawProps[key];
  5279. if (options) {
  5280. // attr / props separation was done on init and will be consistent
  5281. // in this code path, so just check if attrs have it.
  5282. if (hasOwn(attrs, key)) {
  5283. if (value !== attrs[key]) {
  5284. attrs[key] = value;
  5285. hasAttrsChanged = true;
  5286. }
  5287. }
  5288. else {
  5289. const camelizedKey = camelize(key);
  5290. props[camelizedKey] = resolvePropValue(options, rawCurrentProps, camelizedKey, value, instance, false /* isAbsent */);
  5291. }
  5292. }
  5293. else {
  5294. if (value !== attrs[key]) {
  5295. attrs[key] = value;
  5296. hasAttrsChanged = true;
  5297. }
  5298. }
  5299. }
  5300. }
  5301. }
  5302. else {
  5303. // full props update.
  5304. if (setFullProps(instance, rawProps, props, attrs)) {
  5305. hasAttrsChanged = true;
  5306. }
  5307. // in case of dynamic props, check if we need to delete keys from
  5308. // the props object
  5309. let kebabKey;
  5310. for (const key in rawCurrentProps) {
  5311. if (!rawProps ||
  5312. // for camelCase
  5313. (!hasOwn(rawProps, key) &&
  5314. // it's possible the original props was passed in as kebab-case
  5315. // and converted to camelCase (#955)
  5316. ((kebabKey = hyphenate(key)) === key || !hasOwn(rawProps, kebabKey)))) {
  5317. if (options) {
  5318. if (rawPrevProps &&
  5319. // for camelCase
  5320. (rawPrevProps[key] !== undefined ||
  5321. // for kebab-case
  5322. rawPrevProps[kebabKey] !== undefined)) {
  5323. props[key] = resolvePropValue(options, rawCurrentProps, key, undefined, instance, true /* isAbsent */);
  5324. }
  5325. }
  5326. else {
  5327. delete props[key];
  5328. }
  5329. }
  5330. }
  5331. // in the case of functional component w/o props declaration, props and
  5332. // attrs point to the same object so it should already have been updated.
  5333. if (attrs !== rawCurrentProps) {
  5334. for (const key in attrs) {
  5335. if (!rawProps ||
  5336. (!hasOwn(rawProps, key) &&
  5337. (!false ))) {
  5338. delete attrs[key];
  5339. hasAttrsChanged = true;
  5340. }
  5341. }
  5342. }
  5343. }
  5344. // trigger updates for $attrs in case it's used in component slots
  5345. if (hasAttrsChanged) {
  5346. trigger(instance, "set" /* TriggerOpTypes.SET */, '$attrs');
  5347. }
  5348. {
  5349. validateProps(rawProps || {}, props, instance);
  5350. }
  5351. }
  5352. function setFullProps(instance, rawProps, props, attrs) {
  5353. const [options, needCastKeys] = instance.propsOptions;
  5354. let hasAttrsChanged = false;
  5355. let rawCastValues;
  5356. if (rawProps) {
  5357. for (let key in rawProps) {
  5358. // key, ref are reserved and never passed down
  5359. if (isReservedProp(key)) {
  5360. continue;
  5361. }
  5362. const value = rawProps[key];
  5363. // prop option names are camelized during normalization, so to support
  5364. // kebab -> camel conversion here we need to camelize the key.
  5365. let camelKey;
  5366. if (options && hasOwn(options, (camelKey = camelize(key)))) {
  5367. if (!needCastKeys || !needCastKeys.includes(camelKey)) {
  5368. props[camelKey] = value;
  5369. }
  5370. else {
  5371. (rawCastValues || (rawCastValues = {}))[camelKey] = value;
  5372. }
  5373. }
  5374. else if (!isEmitListener(instance.emitsOptions, key)) {
  5375. if (!(key in attrs) || value !== attrs[key]) {
  5376. attrs[key] = value;
  5377. hasAttrsChanged = true;
  5378. }
  5379. }
  5380. }
  5381. }
  5382. if (needCastKeys) {
  5383. const rawCurrentProps = toRaw(props);
  5384. const castValues = rawCastValues || EMPTY_OBJ;
  5385. for (let i = 0; i < needCastKeys.length; i++) {
  5386. const key = needCastKeys[i];
  5387. props[key] = resolvePropValue(options, rawCurrentProps, key, castValues[key], instance, !hasOwn(castValues, key));
  5388. }
  5389. }
  5390. return hasAttrsChanged;
  5391. }
  5392. function resolvePropValue(options, props, key, value, instance, isAbsent) {
  5393. const opt = options[key];
  5394. if (opt != null) {
  5395. const hasDefault = hasOwn(opt, 'default');
  5396. // default values
  5397. if (hasDefault && value === undefined) {
  5398. const defaultValue = opt.default;
  5399. if (opt.type !== Function && isFunction(defaultValue)) {
  5400. const { propsDefaults } = instance;
  5401. if (key in propsDefaults) {
  5402. value = propsDefaults[key];
  5403. }
  5404. else {
  5405. setCurrentInstance(instance);
  5406. value = propsDefaults[key] = defaultValue.call(null, props);
  5407. unsetCurrentInstance();
  5408. }
  5409. }
  5410. else {
  5411. value = defaultValue;
  5412. }
  5413. }
  5414. // boolean casting
  5415. if (opt[0 /* BooleanFlags.shouldCast */]) {
  5416. if (isAbsent && !hasDefault) {
  5417. value = false;
  5418. }
  5419. else if (opt[1 /* BooleanFlags.shouldCastTrue */] &&
  5420. (value === '' || value === hyphenate(key))) {
  5421. value = true;
  5422. }
  5423. }
  5424. }
  5425. return value;
  5426. }
  5427. function normalizePropsOptions(comp, appContext, asMixin = false) {
  5428. const cache = appContext.propsCache;
  5429. const cached = cache.get(comp);
  5430. if (cached) {
  5431. return cached;
  5432. }
  5433. const raw = comp.props;
  5434. const normalized = {};
  5435. const needCastKeys = [];
  5436. // apply mixin/extends props
  5437. let hasExtends = false;
  5438. if (!isFunction(comp)) {
  5439. const extendProps = (raw) => {
  5440. hasExtends = true;
  5441. const [props, keys] = normalizePropsOptions(raw, appContext, true);
  5442. extend(normalized, props);
  5443. if (keys)
  5444. needCastKeys.push(...keys);
  5445. };
  5446. if (!asMixin && appContext.mixins.length) {
  5447. appContext.mixins.forEach(extendProps);
  5448. }
  5449. if (comp.extends) {
  5450. extendProps(comp.extends);
  5451. }
  5452. if (comp.mixins) {
  5453. comp.mixins.forEach(extendProps);
  5454. }
  5455. }
  5456. if (!raw && !hasExtends) {
  5457. if (isObject(comp)) {
  5458. cache.set(comp, EMPTY_ARR);
  5459. }
  5460. return EMPTY_ARR;
  5461. }
  5462. if (isArray(raw)) {
  5463. for (let i = 0; i < raw.length; i++) {
  5464. if (!isString(raw[i])) {
  5465. warn(`props must be strings when using array syntax.`, raw[i]);
  5466. }
  5467. const normalizedKey = camelize(raw[i]);
  5468. if (validatePropName(normalizedKey)) {
  5469. normalized[normalizedKey] = EMPTY_OBJ;
  5470. }
  5471. }
  5472. }
  5473. else if (raw) {
  5474. if (!isObject(raw)) {
  5475. warn(`invalid props options`, raw);
  5476. }
  5477. for (const key in raw) {
  5478. const normalizedKey = camelize(key);
  5479. if (validatePropName(normalizedKey)) {
  5480. const opt = raw[key];
  5481. const prop = (normalized[normalizedKey] =
  5482. isArray(opt) || isFunction(opt) ? { type: opt } : Object.assign({}, opt));
  5483. if (prop) {
  5484. const booleanIndex = getTypeIndex(Boolean, prop.type);
  5485. const stringIndex = getTypeIndex(String, prop.type);
  5486. prop[0 /* BooleanFlags.shouldCast */] = booleanIndex > -1;
  5487. prop[1 /* BooleanFlags.shouldCastTrue */] =
  5488. stringIndex < 0 || booleanIndex < stringIndex;
  5489. // if the prop needs boolean casting or default value
  5490. if (booleanIndex > -1 || hasOwn(prop, 'default')) {
  5491. needCastKeys.push(normalizedKey);
  5492. }
  5493. }
  5494. }
  5495. }
  5496. }
  5497. const res = [normalized, needCastKeys];
  5498. if (isObject(comp)) {
  5499. cache.set(comp, res);
  5500. }
  5501. return res;
  5502. }
  5503. function validatePropName(key) {
  5504. if (key[0] !== '$') {
  5505. return true;
  5506. }
  5507. else {
  5508. warn(`Invalid prop name: "${key}" is a reserved property.`);
  5509. }
  5510. return false;
  5511. }
  5512. // use function string name to check type constructors
  5513. // so that it works across vms / iframes.
  5514. function getType(ctor) {
  5515. const match = ctor && ctor.toString().match(/^\s*(function|class) (\w+)/);
  5516. return match ? match[2] : ctor === null ? 'null' : '';
  5517. }
  5518. function isSameType(a, b) {
  5519. return getType(a) === getType(b);
  5520. }
  5521. function getTypeIndex(type, expectedTypes) {
  5522. if (isArray(expectedTypes)) {
  5523. return expectedTypes.findIndex(t => isSameType(t, type));
  5524. }
  5525. else if (isFunction(expectedTypes)) {
  5526. return isSameType(expectedTypes, type) ? 0 : -1;
  5527. }
  5528. return -1;
  5529. }
  5530. /**
  5531. * dev only
  5532. */
  5533. function validateProps(rawProps, props, instance) {
  5534. const resolvedValues = toRaw(props);
  5535. const options = instance.propsOptions[0];
  5536. for (const key in options) {
  5537. let opt = options[key];
  5538. if (opt == null)
  5539. continue;
  5540. validateProp(key, resolvedValues[key], opt, !hasOwn(rawProps, key) && !hasOwn(rawProps, hyphenate(key)));
  5541. }
  5542. }
  5543. /**
  5544. * dev only
  5545. */
  5546. function validateProp(name, value, prop, isAbsent) {
  5547. const { type, required, validator } = prop;
  5548. // required!
  5549. if (required && isAbsent) {
  5550. warn('Missing required prop: "' + name + '"');
  5551. return;
  5552. }
  5553. // missing but optional
  5554. if (value == null && !prop.required) {
  5555. return;
  5556. }
  5557. // type check
  5558. if (type != null && type !== true) {
  5559. let isValid = false;
  5560. const types = isArray(type) ? type : [type];
  5561. const expectedTypes = [];
  5562. // value is valid as long as one of the specified types match
  5563. for (let i = 0; i < types.length && !isValid; i++) {
  5564. const { valid, expectedType } = assertType(value, types[i]);
  5565. expectedTypes.push(expectedType || '');
  5566. isValid = valid;
  5567. }
  5568. if (!isValid) {
  5569. warn(getInvalidTypeMessage(name, value, expectedTypes));
  5570. return;
  5571. }
  5572. }
  5573. // custom validator
  5574. if (validator && !validator(value)) {
  5575. warn('Invalid prop: custom validator check failed for prop "' + name + '".');
  5576. }
  5577. }
  5578. const isSimpleType = /*#__PURE__*/ makeMap('String,Number,Boolean,Function,Symbol,BigInt');
  5579. /**
  5580. * dev only
  5581. */
  5582. function assertType(value, type) {
  5583. let valid;
  5584. const expectedType = getType(type);
  5585. if (isSimpleType(expectedType)) {
  5586. const t = typeof value;
  5587. valid = t === expectedType.toLowerCase();
  5588. // for primitive wrapper objects
  5589. if (!valid && t === 'object') {
  5590. valid = value instanceof type;
  5591. }
  5592. }
  5593. else if (expectedType === 'Object') {
  5594. valid = isObject(value);
  5595. }
  5596. else if (expectedType === 'Array') {
  5597. valid = isArray(value);
  5598. }
  5599. else if (expectedType === 'null') {
  5600. valid = value === null;
  5601. }
  5602. else {
  5603. valid = value instanceof type;
  5604. }
  5605. return {
  5606. valid,
  5607. expectedType
  5608. };
  5609. }
  5610. /**
  5611. * dev only
  5612. */
  5613. function getInvalidTypeMessage(name, value, expectedTypes) {
  5614. let message = `Invalid prop: type check failed for prop "${name}".` +
  5615. ` Expected ${expectedTypes.map(capitalize).join(' | ')}`;
  5616. const expectedType = expectedTypes[0];
  5617. const receivedType = toRawType(value);
  5618. const expectedValue = styleValue(value, expectedType);
  5619. const receivedValue = styleValue(value, receivedType);
  5620. // check if we need to specify expected value
  5621. if (expectedTypes.length === 1 &&
  5622. isExplicable(expectedType) &&
  5623. !isBoolean(expectedType, receivedType)) {
  5624. message += ` with value ${expectedValue}`;
  5625. }
  5626. message += `, got ${receivedType} `;
  5627. // check if we need to specify received value
  5628. if (isExplicable(receivedType)) {
  5629. message += `with value ${receivedValue}.`;
  5630. }
  5631. return message;
  5632. }
  5633. /**
  5634. * dev only
  5635. */
  5636. function styleValue(value, type) {
  5637. if (type === 'String') {
  5638. return `"${value}"`;
  5639. }
  5640. else if (type === 'Number') {
  5641. return `${Number(value)}`;
  5642. }
  5643. else {
  5644. return `${value}`;
  5645. }
  5646. }
  5647. /**
  5648. * dev only
  5649. */
  5650. function isExplicable(type) {
  5651. const explicitTypes = ['string', 'number', 'boolean'];
  5652. return explicitTypes.some(elem => type.toLowerCase() === elem);
  5653. }
  5654. /**
  5655. * dev only
  5656. */
  5657. function isBoolean(...args) {
  5658. return args.some(elem => elem.toLowerCase() === 'boolean');
  5659. }
  5660. const isInternalKey = (key) => key[0] === '_' || key === '$stable';
  5661. const normalizeSlotValue = (value) => isArray(value)
  5662. ? value.map(normalizeVNode)
  5663. : [normalizeVNode(value)];
  5664. const normalizeSlot = (key, rawSlot, ctx) => {
  5665. if (rawSlot._n) {
  5666. // already normalized - #5353
  5667. return rawSlot;
  5668. }
  5669. const normalized = withCtx((...args) => {
  5670. if (true && currentInstance) {
  5671. warn(`Slot "${key}" invoked outside of the render function: ` +
  5672. `this will not track dependencies used in the slot. ` +
  5673. `Invoke the slot function inside the render function instead.`);
  5674. }
  5675. return normalizeSlotValue(rawSlot(...args));
  5676. }, ctx);
  5677. normalized._c = false;
  5678. return normalized;
  5679. };
  5680. const normalizeObjectSlots = (rawSlots, slots, instance) => {
  5681. const ctx = rawSlots._ctx;
  5682. for (const key in rawSlots) {
  5683. if (isInternalKey(key))
  5684. continue;
  5685. const value = rawSlots[key];
  5686. if (isFunction(value)) {
  5687. slots[key] = normalizeSlot(key, value, ctx);
  5688. }
  5689. else if (value != null) {
  5690. {
  5691. warn(`Non-function value encountered for slot "${key}". ` +
  5692. `Prefer function slots for better performance.`);
  5693. }
  5694. const normalized = normalizeSlotValue(value);
  5695. slots[key] = () => normalized;
  5696. }
  5697. }
  5698. };
  5699. const normalizeVNodeSlots = (instance, children) => {
  5700. if (!isKeepAlive(instance.vnode) &&
  5701. !(false )) {
  5702. warn(`Non-function value encountered for default slot. ` +
  5703. `Prefer function slots for better performance.`);
  5704. }
  5705. const normalized = normalizeSlotValue(children);
  5706. instance.slots.default = () => normalized;
  5707. };
  5708. const initSlots = (instance, children) => {
  5709. if (instance.vnode.shapeFlag & 32 /* ShapeFlags.SLOTS_CHILDREN */) {
  5710. const type = children._;
  5711. if (type) {
  5712. // users can get the shallow readonly version of the slots object through `this.$slots`,
  5713. // we should avoid the proxy object polluting the slots of the internal instance
  5714. instance.slots = toRaw(children);
  5715. // make compiler marker non-enumerable
  5716. def(children, '_', type);
  5717. }
  5718. else {
  5719. normalizeObjectSlots(children, (instance.slots = {}));
  5720. }
  5721. }
  5722. else {
  5723. instance.slots = {};
  5724. if (children) {
  5725. normalizeVNodeSlots(instance, children);
  5726. }
  5727. }
  5728. def(instance.slots, InternalObjectKey, 1);
  5729. };
  5730. const updateSlots = (instance, children, optimized) => {
  5731. const { vnode, slots } = instance;
  5732. let needDeletionCheck = true;
  5733. let deletionComparisonTarget = EMPTY_OBJ;
  5734. if (vnode.shapeFlag & 32 /* ShapeFlags.SLOTS_CHILDREN */) {
  5735. const type = children._;
  5736. if (type) {
  5737. // compiled slots.
  5738. if (isHmrUpdating) {
  5739. // Parent was HMR updated so slot content may have changed.
  5740. // force update slots and mark instance for hmr as well
  5741. extend(slots, children);
  5742. }
  5743. else if (optimized && type === 1 /* SlotFlags.STABLE */) {
  5744. // compiled AND stable.
  5745. // no need to update, and skip stale slots removal.
  5746. needDeletionCheck = false;
  5747. }
  5748. else {
  5749. // compiled but dynamic (v-if/v-for on slots) - update slots, but skip
  5750. // normalization.
  5751. extend(slots, children);
  5752. // #2893
  5753. // when rendering the optimized slots by manually written render function,
  5754. // we need to delete the `slots._` flag if necessary to make subsequent updates reliable,
  5755. // i.e. let the `renderSlot` create the bailed Fragment
  5756. if (!optimized && type === 1 /* SlotFlags.STABLE */) {
  5757. delete slots._;
  5758. }
  5759. }
  5760. }
  5761. else {
  5762. needDeletionCheck = !children.$stable;
  5763. normalizeObjectSlots(children, slots);
  5764. }
  5765. deletionComparisonTarget = children;
  5766. }
  5767. else if (children) {
  5768. // non slot object children (direct value) passed to a component
  5769. normalizeVNodeSlots(instance, children);
  5770. deletionComparisonTarget = { default: 1 };
  5771. }
  5772. // delete stale slots
  5773. if (needDeletionCheck) {
  5774. for (const key in slots) {
  5775. if (!isInternalKey(key) && !(key in deletionComparisonTarget)) {
  5776. delete slots[key];
  5777. }
  5778. }
  5779. }
  5780. };
  5781. function createAppContext() {
  5782. return {
  5783. app: null,
  5784. config: {
  5785. isNativeTag: NO,
  5786. performance: false,
  5787. globalProperties: {},
  5788. optionMergeStrategies: {},
  5789. errorHandler: undefined,
  5790. warnHandler: undefined,
  5791. compilerOptions: {}
  5792. },
  5793. mixins: [],
  5794. components: {},
  5795. directives: {},
  5796. provides: Object.create(null),
  5797. optionsCache: new WeakMap(),
  5798. propsCache: new WeakMap(),
  5799. emitsCache: new WeakMap()
  5800. };
  5801. }
  5802. let uid$1 = 0;
  5803. function createAppAPI(render, hydrate) {
  5804. return function createApp(rootComponent, rootProps = null) {
  5805. if (!isFunction(rootComponent)) {
  5806. rootComponent = Object.assign({}, rootComponent);
  5807. }
  5808. if (rootProps != null && !isObject(rootProps)) {
  5809. warn(`root props passed to app.mount() must be an object.`);
  5810. rootProps = null;
  5811. }
  5812. const context = createAppContext();
  5813. const installedPlugins = new Set();
  5814. let isMounted = false;
  5815. const app = (context.app = {
  5816. _uid: uid$1++,
  5817. _component: rootComponent,
  5818. _props: rootProps,
  5819. _container: null,
  5820. _context: context,
  5821. _instance: null,
  5822. version,
  5823. get config() {
  5824. return context.config;
  5825. },
  5826. set config(v) {
  5827. {
  5828. warn(`app.config cannot be replaced. Modify individual options instead.`);
  5829. }
  5830. },
  5831. use(plugin, ...options) {
  5832. if (installedPlugins.has(plugin)) {
  5833. warn(`Plugin has already been applied to target app.`);
  5834. }
  5835. else if (plugin && isFunction(plugin.install)) {
  5836. installedPlugins.add(plugin);
  5837. plugin.install(app, ...options);
  5838. }
  5839. else if (isFunction(plugin)) {
  5840. installedPlugins.add(plugin);
  5841. plugin(app, ...options);
  5842. }
  5843. else {
  5844. warn(`A plugin must either be a function or an object with an "install" ` +
  5845. `function.`);
  5846. }
  5847. return app;
  5848. },
  5849. mixin(mixin) {
  5850. {
  5851. if (!context.mixins.includes(mixin)) {
  5852. context.mixins.push(mixin);
  5853. }
  5854. else {
  5855. warn('Mixin has already been applied to target app' +
  5856. (mixin.name ? `: ${mixin.name}` : ''));
  5857. }
  5858. }
  5859. return app;
  5860. },
  5861. component(name, component) {
  5862. {
  5863. validateComponentName(name, context.config);
  5864. }
  5865. if (!component) {
  5866. return context.components[name];
  5867. }
  5868. if (context.components[name]) {
  5869. warn(`Component "${name}" has already been registered in target app.`);
  5870. }
  5871. context.components[name] = component;
  5872. return app;
  5873. },
  5874. directive(name, directive) {
  5875. {
  5876. validateDirectiveName(name);
  5877. }
  5878. if (!directive) {
  5879. return context.directives[name];
  5880. }
  5881. if (context.directives[name]) {
  5882. warn(`Directive "${name}" has already been registered in target app.`);
  5883. }
  5884. context.directives[name] = directive;
  5885. return app;
  5886. },
  5887. mount(rootContainer, isHydrate, isSVG) {
  5888. if (!isMounted) {
  5889. // #5571
  5890. if (rootContainer.__vue_app__) {
  5891. warn(`There is already an app instance mounted on the host container.\n` +
  5892. ` If you want to mount another app on the same host container,` +
  5893. ` you need to unmount the previous app by calling \`app.unmount()\` first.`);
  5894. }
  5895. const vnode = createVNode(rootComponent, rootProps);
  5896. // store app context on the root VNode.
  5897. // this will be set on the root instance on initial mount.
  5898. vnode.appContext = context;
  5899. // HMR root reload
  5900. {
  5901. context.reload = () => {
  5902. render(cloneVNode(vnode), rootContainer, isSVG);
  5903. };
  5904. }
  5905. if (isHydrate && hydrate) {
  5906. hydrate(vnode, rootContainer);
  5907. }
  5908. else {
  5909. render(vnode, rootContainer, isSVG);
  5910. }
  5911. isMounted = true;
  5912. app._container = rootContainer;
  5913. rootContainer.__vue_app__ = app;
  5914. {
  5915. app._instance = vnode.component;
  5916. devtoolsInitApp(app, version);
  5917. }
  5918. return getExposeProxy(vnode.component) || vnode.component.proxy;
  5919. }
  5920. else {
  5921. warn(`App has already been mounted.\n` +
  5922. `If you want to remount the same app, move your app creation logic ` +
  5923. `into a factory function and create fresh app instances for each ` +
  5924. `mount - e.g. \`const createMyApp = () => createApp(App)\``);
  5925. }
  5926. },
  5927. unmount() {
  5928. if (isMounted) {
  5929. render(null, app._container);
  5930. {
  5931. app._instance = null;
  5932. devtoolsUnmountApp(app);
  5933. }
  5934. delete app._container.__vue_app__;
  5935. }
  5936. else {
  5937. warn(`Cannot unmount an app that is not mounted.`);
  5938. }
  5939. },
  5940. provide(key, value) {
  5941. if (key in context.provides) {
  5942. warn(`App already provides property with key "${String(key)}". ` +
  5943. `It will be overwritten with the new value.`);
  5944. }
  5945. context.provides[key] = value;
  5946. return app;
  5947. }
  5948. });
  5949. return app;
  5950. };
  5951. }
  5952. /**
  5953. * Function for handling a template ref
  5954. */
  5955. function setRef(rawRef, oldRawRef, parentSuspense, vnode, isUnmount = false) {
  5956. if (isArray(rawRef)) {
  5957. rawRef.forEach((r, i) => setRef(r, oldRawRef && (isArray(oldRawRef) ? oldRawRef[i] : oldRawRef), parentSuspense, vnode, isUnmount));
  5958. return;
  5959. }
  5960. if (isAsyncWrapper(vnode) && !isUnmount) {
  5961. // when mounting async components, nothing needs to be done,
  5962. // because the template ref is forwarded to inner component
  5963. return;
  5964. }
  5965. const refValue = vnode.shapeFlag & 4 /* ShapeFlags.STATEFUL_COMPONENT */
  5966. ? getExposeProxy(vnode.component) || vnode.component.proxy
  5967. : vnode.el;
  5968. const value = isUnmount ? null : refValue;
  5969. const { i: owner, r: ref } = rawRef;
  5970. if (!owner) {
  5971. warn(`Missing ref owner context. ref cannot be used on hoisted vnodes. ` +
  5972. `A vnode with ref must be created inside the render function.`);
  5973. return;
  5974. }
  5975. const oldRef = oldRawRef && oldRawRef.r;
  5976. const refs = owner.refs === EMPTY_OBJ ? (owner.refs = {}) : owner.refs;
  5977. const setupState = owner.setupState;
  5978. // dynamic ref changed. unset old ref
  5979. if (oldRef != null && oldRef !== ref) {
  5980. if (isString(oldRef)) {
  5981. refs[oldRef] = null;
  5982. if (hasOwn(setupState, oldRef)) {
  5983. setupState[oldRef] = null;
  5984. }
  5985. }
  5986. else if (isRef(oldRef)) {
  5987. oldRef.value = null;
  5988. }
  5989. }
  5990. if (isFunction(ref)) {
  5991. callWithErrorHandling(ref, owner, 12 /* ErrorCodes.FUNCTION_REF */, [value, refs]);
  5992. }
  5993. else {
  5994. const _isString = isString(ref);
  5995. const _isRef = isRef(ref);
  5996. if (_isString || _isRef) {
  5997. const doSet = () => {
  5998. if (rawRef.f) {
  5999. const existing = _isString
  6000. ? hasOwn(setupState, ref)
  6001. ? setupState[ref]
  6002. : refs[ref]
  6003. : ref.value;
  6004. if (isUnmount) {
  6005. isArray(existing) && remove(existing, refValue);
  6006. }
  6007. else {
  6008. if (!isArray(existing)) {
  6009. if (_isString) {
  6010. refs[ref] = [refValue];
  6011. if (hasOwn(setupState, ref)) {
  6012. setupState[ref] = refs[ref];
  6013. }
  6014. }
  6015. else {
  6016. ref.value = [refValue];
  6017. if (rawRef.k)
  6018. refs[rawRef.k] = ref.value;
  6019. }
  6020. }
  6021. else if (!existing.includes(refValue)) {
  6022. existing.push(refValue);
  6023. }
  6024. }
  6025. }
  6026. else if (_isString) {
  6027. refs[ref] = value;
  6028. if (hasOwn(setupState, ref)) {
  6029. setupState[ref] = value;
  6030. }
  6031. }
  6032. else if (_isRef) {
  6033. ref.value = value;
  6034. if (rawRef.k)
  6035. refs[rawRef.k] = value;
  6036. }
  6037. else {
  6038. warn('Invalid template ref type:', ref, `(${typeof ref})`);
  6039. }
  6040. };
  6041. if (value) {
  6042. doSet.id = -1;
  6043. queuePostRenderEffect(doSet, parentSuspense);
  6044. }
  6045. else {
  6046. doSet();
  6047. }
  6048. }
  6049. else {
  6050. warn('Invalid template ref type:', ref, `(${typeof ref})`);
  6051. }
  6052. }
  6053. }
  6054. let hasMismatch = false;
  6055. const isSVGContainer = (container) => /svg/.test(container.namespaceURI) && container.tagName !== 'foreignObject';
  6056. const isComment = (node) => node.nodeType === 8 /* DOMNodeTypes.COMMENT */;
  6057. // Note: hydration is DOM-specific
  6058. // But we have to place it in core due to tight coupling with core - splitting
  6059. // it out creates a ton of unnecessary complexity.
  6060. // Hydration also depends on some renderer internal logic which needs to be
  6061. // passed in via arguments.
  6062. function createHydrationFunctions(rendererInternals) {
  6063. const { mt: mountComponent, p: patch, o: { patchProp, createText, nextSibling, parentNode, remove, insert, createComment } } = rendererInternals;
  6064. const hydrate = (vnode, container) => {
  6065. if (!container.hasChildNodes()) {
  6066. warn(`Attempting to hydrate existing markup but container is empty. ` +
  6067. `Performing full mount instead.`);
  6068. patch(null, vnode, container);
  6069. flushPostFlushCbs();
  6070. container._vnode = vnode;
  6071. return;
  6072. }
  6073. hasMismatch = false;
  6074. hydrateNode(container.firstChild, vnode, null, null, null);
  6075. flushPostFlushCbs();
  6076. container._vnode = vnode;
  6077. if (hasMismatch && !false) {
  6078. // this error should show up in production
  6079. console.error(`Hydration completed but contains mismatches.`);
  6080. }
  6081. };
  6082. const hydrateNode = (node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized = false) => {
  6083. const isFragmentStart = isComment(node) && node.data === '[';
  6084. const onMismatch = () => handleMismatch(node, vnode, parentComponent, parentSuspense, slotScopeIds, isFragmentStart);
  6085. const { type, ref, shapeFlag, patchFlag } = vnode;
  6086. let domType = node.nodeType;
  6087. vnode.el = node;
  6088. if (patchFlag === -2 /* PatchFlags.BAIL */) {
  6089. optimized = false;
  6090. vnode.dynamicChildren = null;
  6091. }
  6092. let nextNode = null;
  6093. switch (type) {
  6094. case Text:
  6095. if (domType !== 3 /* DOMNodeTypes.TEXT */) {
  6096. // #5728 empty text node inside a slot can cause hydration failure
  6097. // because the server rendered HTML won't contain a text node
  6098. if (vnode.children === '') {
  6099. insert((vnode.el = createText('')), parentNode(node), node);
  6100. nextNode = node;
  6101. }
  6102. else {
  6103. nextNode = onMismatch();
  6104. }
  6105. }
  6106. else {
  6107. if (node.data !== vnode.children) {
  6108. hasMismatch = true;
  6109. warn(`Hydration text mismatch:` +
  6110. `\n- Client: ${JSON.stringify(node.data)}` +
  6111. `\n- Server: ${JSON.stringify(vnode.children)}`);
  6112. node.data = vnode.children;
  6113. }
  6114. nextNode = nextSibling(node);
  6115. }
  6116. break;
  6117. case Comment:
  6118. if (domType !== 8 /* DOMNodeTypes.COMMENT */ || isFragmentStart) {
  6119. nextNode = onMismatch();
  6120. }
  6121. else {
  6122. nextNode = nextSibling(node);
  6123. }
  6124. break;
  6125. case Static:
  6126. if (isFragmentStart) {
  6127. // entire template is static but SSRed as a fragment
  6128. node = nextSibling(node);
  6129. domType = node.nodeType;
  6130. }
  6131. if (domType === 1 /* DOMNodeTypes.ELEMENT */ || domType === 3 /* DOMNodeTypes.TEXT */) {
  6132. // determine anchor, adopt content
  6133. nextNode = node;
  6134. // if the static vnode has its content stripped during build,
  6135. // adopt it from the server-rendered HTML.
  6136. const needToAdoptContent = !vnode.children.length;
  6137. for (let i = 0; i < vnode.staticCount; i++) {
  6138. if (needToAdoptContent)
  6139. vnode.children +=
  6140. nextNode.nodeType === 1 /* DOMNodeTypes.ELEMENT */
  6141. ? nextNode.outerHTML
  6142. : nextNode.data;
  6143. if (i === vnode.staticCount - 1) {
  6144. vnode.anchor = nextNode;
  6145. }
  6146. nextNode = nextSibling(nextNode);
  6147. }
  6148. return isFragmentStart ? nextSibling(nextNode) : nextNode;
  6149. }
  6150. else {
  6151. onMismatch();
  6152. }
  6153. break;
  6154. case Fragment:
  6155. if (!isFragmentStart) {
  6156. nextNode = onMismatch();
  6157. }
  6158. else {
  6159. nextNode = hydrateFragment(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized);
  6160. }
  6161. break;
  6162. default:
  6163. if (shapeFlag & 1 /* ShapeFlags.ELEMENT */) {
  6164. if (domType !== 1 /* DOMNodeTypes.ELEMENT */ ||
  6165. vnode.type.toLowerCase() !==
  6166. node.tagName.toLowerCase()) {
  6167. nextNode = onMismatch();
  6168. }
  6169. else {
  6170. nextNode = hydrateElement(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized);
  6171. }
  6172. }
  6173. else if (shapeFlag & 6 /* ShapeFlags.COMPONENT */) {
  6174. // when setting up the render effect, if the initial vnode already
  6175. // has .el set, the component will perform hydration instead of mount
  6176. // on its sub-tree.
  6177. vnode.slotScopeIds = slotScopeIds;
  6178. const container = parentNode(node);
  6179. mountComponent(vnode, container, null, parentComponent, parentSuspense, isSVGContainer(container), optimized);
  6180. // component may be async, so in the case of fragments we cannot rely
  6181. // on component's rendered output to determine the end of the fragment
  6182. // instead, we do a lookahead to find the end anchor node.
  6183. nextNode = isFragmentStart
  6184. ? locateClosingAsyncAnchor(node)
  6185. : nextSibling(node);
  6186. // #4293 teleport as component root
  6187. if (nextNode &&
  6188. isComment(nextNode) &&
  6189. nextNode.data === 'teleport end') {
  6190. nextNode = nextSibling(nextNode);
  6191. }
  6192. // #3787
  6193. // if component is async, it may get moved / unmounted before its
  6194. // inner component is loaded, so we need to give it a placeholder
  6195. // vnode that matches its adopted DOM.
  6196. if (isAsyncWrapper(vnode)) {
  6197. let subTree;
  6198. if (isFragmentStart) {
  6199. subTree = createVNode(Fragment);
  6200. subTree.anchor = nextNode
  6201. ? nextNode.previousSibling
  6202. : container.lastChild;
  6203. }
  6204. else {
  6205. subTree =
  6206. node.nodeType === 3 ? createTextVNode('') : createVNode('div');
  6207. }
  6208. subTree.el = node;
  6209. vnode.component.subTree = subTree;
  6210. }
  6211. }
  6212. else if (shapeFlag & 64 /* ShapeFlags.TELEPORT */) {
  6213. if (domType !== 8 /* DOMNodeTypes.COMMENT */) {
  6214. nextNode = onMismatch();
  6215. }
  6216. else {
  6217. nextNode = vnode.type.hydrate(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized, rendererInternals, hydrateChildren);
  6218. }
  6219. }
  6220. else if (shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
  6221. nextNode = vnode.type.hydrate(node, vnode, parentComponent, parentSuspense, isSVGContainer(parentNode(node)), slotScopeIds, optimized, rendererInternals, hydrateNode);
  6222. }
  6223. else {
  6224. warn('Invalid HostVNode type:', type, `(${typeof type})`);
  6225. }
  6226. }
  6227. if (ref != null) {
  6228. setRef(ref, null, parentSuspense, vnode);
  6229. }
  6230. return nextNode;
  6231. };
  6232. const hydrateElement = (el, vnode, parentComponent, parentSuspense, slotScopeIds, optimized) => {
  6233. optimized = optimized || !!vnode.dynamicChildren;
  6234. const { type, props, patchFlag, shapeFlag, dirs } = vnode;
  6235. // #4006 for form elements with non-string v-model value bindings
  6236. // e.g. <option :value="obj">, <input type="checkbox" :true-value="1">
  6237. const forcePatchValue = (type === 'input' && dirs) || type === 'option';
  6238. // skip props & children if this is hoisted static nodes
  6239. // #5405 in dev, always hydrate children for HMR
  6240. {
  6241. if (dirs) {
  6242. invokeDirectiveHook(vnode, null, parentComponent, 'created');
  6243. }
  6244. // props
  6245. if (props) {
  6246. if (forcePatchValue ||
  6247. !optimized ||
  6248. patchFlag & (16 /* PatchFlags.FULL_PROPS */ | 32 /* PatchFlags.HYDRATE_EVENTS */)) {
  6249. for (const key in props) {
  6250. if ((forcePatchValue && key.endsWith('value')) ||
  6251. (isOn(key) && !isReservedProp(key))) {
  6252. patchProp(el, key, null, props[key], false, undefined, parentComponent);
  6253. }
  6254. }
  6255. }
  6256. else if (props.onClick) {
  6257. // Fast path for click listeners (which is most often) to avoid
  6258. // iterating through props.
  6259. patchProp(el, 'onClick', null, props.onClick, false, undefined, parentComponent);
  6260. }
  6261. }
  6262. // vnode / directive hooks
  6263. let vnodeHooks;
  6264. if ((vnodeHooks = props && props.onVnodeBeforeMount)) {
  6265. invokeVNodeHook(vnodeHooks, parentComponent, vnode);
  6266. }
  6267. if (dirs) {
  6268. invokeDirectiveHook(vnode, null, parentComponent, 'beforeMount');
  6269. }
  6270. if ((vnodeHooks = props && props.onVnodeMounted) || dirs) {
  6271. queueEffectWithSuspense(() => {
  6272. vnodeHooks && invokeVNodeHook(vnodeHooks, parentComponent, vnode);
  6273. dirs && invokeDirectiveHook(vnode, null, parentComponent, 'mounted');
  6274. }, parentSuspense);
  6275. }
  6276. // children
  6277. if (shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */ &&
  6278. // skip if element has innerHTML / textContent
  6279. !(props && (props.innerHTML || props.textContent))) {
  6280. let next = hydrateChildren(el.firstChild, vnode, el, parentComponent, parentSuspense, slotScopeIds, optimized);
  6281. let hasWarned = false;
  6282. while (next) {
  6283. hasMismatch = true;
  6284. if (!hasWarned) {
  6285. warn(`Hydration children mismatch in <${vnode.type}>: ` +
  6286. `server rendered element contains more child nodes than client vdom.`);
  6287. hasWarned = true;
  6288. }
  6289. // The SSRed DOM contains more nodes than it should. Remove them.
  6290. const cur = next;
  6291. next = next.nextSibling;
  6292. remove(cur);
  6293. }
  6294. }
  6295. else if (shapeFlag & 8 /* ShapeFlags.TEXT_CHILDREN */) {
  6296. if (el.textContent !== vnode.children) {
  6297. hasMismatch = true;
  6298. warn(`Hydration text content mismatch in <${vnode.type}>:\n` +
  6299. `- Client: ${el.textContent}\n` +
  6300. `- Server: ${vnode.children}`);
  6301. el.textContent = vnode.children;
  6302. }
  6303. }
  6304. }
  6305. return el.nextSibling;
  6306. };
  6307. const hydrateChildren = (node, parentVNode, container, parentComponent, parentSuspense, slotScopeIds, optimized) => {
  6308. optimized = optimized || !!parentVNode.dynamicChildren;
  6309. const children = parentVNode.children;
  6310. const l = children.length;
  6311. let hasWarned = false;
  6312. for (let i = 0; i < l; i++) {
  6313. const vnode = optimized
  6314. ? children[i]
  6315. : (children[i] = normalizeVNode(children[i]));
  6316. if (node) {
  6317. node = hydrateNode(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized);
  6318. }
  6319. else if (vnode.type === Text && !vnode.children) {
  6320. continue;
  6321. }
  6322. else {
  6323. hasMismatch = true;
  6324. if (!hasWarned) {
  6325. warn(`Hydration children mismatch in <${container.tagName.toLowerCase()}>: ` +
  6326. `server rendered element contains fewer child nodes than client vdom.`);
  6327. hasWarned = true;
  6328. }
  6329. // the SSRed DOM didn't contain enough nodes. Mount the missing ones.
  6330. patch(null, vnode, container, null, parentComponent, parentSuspense, isSVGContainer(container), slotScopeIds);
  6331. }
  6332. }
  6333. return node;
  6334. };
  6335. const hydrateFragment = (node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized) => {
  6336. const { slotScopeIds: fragmentSlotScopeIds } = vnode;
  6337. if (fragmentSlotScopeIds) {
  6338. slotScopeIds = slotScopeIds
  6339. ? slotScopeIds.concat(fragmentSlotScopeIds)
  6340. : fragmentSlotScopeIds;
  6341. }
  6342. const container = parentNode(node);
  6343. const next = hydrateChildren(nextSibling(node), vnode, container, parentComponent, parentSuspense, slotScopeIds, optimized);
  6344. if (next && isComment(next) && next.data === ']') {
  6345. return nextSibling((vnode.anchor = next));
  6346. }
  6347. else {
  6348. // fragment didn't hydrate successfully, since we didn't get a end anchor
  6349. // back. This should have led to node/children mismatch warnings.
  6350. hasMismatch = true;
  6351. // since the anchor is missing, we need to create one and insert it
  6352. insert((vnode.anchor = createComment(`]`)), container, next);
  6353. return next;
  6354. }
  6355. };
  6356. const handleMismatch = (node, vnode, parentComponent, parentSuspense, slotScopeIds, isFragment) => {
  6357. hasMismatch = true;
  6358. warn(`Hydration node mismatch:\n- Client vnode:`, vnode.type, `\n- Server rendered DOM:`, node, node.nodeType === 3 /* DOMNodeTypes.TEXT */
  6359. ? `(text)`
  6360. : isComment(node) && node.data === '['
  6361. ? `(start of fragment)`
  6362. : ``);
  6363. vnode.el = null;
  6364. if (isFragment) {
  6365. // remove excessive fragment nodes
  6366. const end = locateClosingAsyncAnchor(node);
  6367. while (true) {
  6368. const next = nextSibling(node);
  6369. if (next && next !== end) {
  6370. remove(next);
  6371. }
  6372. else {
  6373. break;
  6374. }
  6375. }
  6376. }
  6377. const next = nextSibling(node);
  6378. const container = parentNode(node);
  6379. remove(node);
  6380. patch(null, vnode, container, next, parentComponent, parentSuspense, isSVGContainer(container), slotScopeIds);
  6381. return next;
  6382. };
  6383. const locateClosingAsyncAnchor = (node) => {
  6384. let match = 0;
  6385. while (node) {
  6386. node = nextSibling(node);
  6387. if (node && isComment(node)) {
  6388. if (node.data === '[')
  6389. match++;
  6390. if (node.data === ']') {
  6391. if (match === 0) {
  6392. return nextSibling(node);
  6393. }
  6394. else {
  6395. match--;
  6396. }
  6397. }
  6398. }
  6399. }
  6400. return node;
  6401. };
  6402. return [hydrate, hydrateNode];
  6403. }
  6404. /* eslint-disable no-restricted-globals */
  6405. let supported;
  6406. let perf;
  6407. function startMeasure(instance, type) {
  6408. if (instance.appContext.config.performance && isSupported()) {
  6409. perf.mark(`vue-${type}-${instance.uid}`);
  6410. }
  6411. {
  6412. devtoolsPerfStart(instance, type, isSupported() ? perf.now() : Date.now());
  6413. }
  6414. }
  6415. function endMeasure(instance, type) {
  6416. if (instance.appContext.config.performance && isSupported()) {
  6417. const startTag = `vue-${type}-${instance.uid}`;
  6418. const endTag = startTag + `:end`;
  6419. perf.mark(endTag);
  6420. perf.measure(`<${formatComponentName(instance, instance.type)}> ${type}`, startTag, endTag);
  6421. perf.clearMarks(startTag);
  6422. perf.clearMarks(endTag);
  6423. }
  6424. {
  6425. devtoolsPerfEnd(instance, type, isSupported() ? perf.now() : Date.now());
  6426. }
  6427. }
  6428. function isSupported() {
  6429. if (supported !== undefined) {
  6430. return supported;
  6431. }
  6432. if (typeof window !== 'undefined' && window.performance) {
  6433. supported = true;
  6434. perf = window.performance;
  6435. }
  6436. else {
  6437. supported = false;
  6438. }
  6439. return supported;
  6440. }
  6441. const queuePostRenderEffect = queueEffectWithSuspense
  6442. ;
  6443. /**
  6444. * The createRenderer function accepts two generic arguments:
  6445. * HostNode and HostElement, corresponding to Node and Element types in the
  6446. * host environment. For example, for runtime-dom, HostNode would be the DOM
  6447. * `Node` interface and HostElement would be the DOM `Element` interface.
  6448. *
  6449. * Custom renderers can pass in the platform specific types like this:
  6450. *
  6451. * ``` js
  6452. * const { render, createApp } = createRenderer<Node, Element>({
  6453. * patchProp,
  6454. * ...nodeOps
  6455. * })
  6456. * ```
  6457. */
  6458. function createRenderer(options) {
  6459. return baseCreateRenderer(options);
  6460. }
  6461. // Separate API for creating hydration-enabled renderer.
  6462. // Hydration logic is only used when calling this function, making it
  6463. // tree-shakable.
  6464. function createHydrationRenderer(options) {
  6465. return baseCreateRenderer(options, createHydrationFunctions);
  6466. }
  6467. // implementation
  6468. function baseCreateRenderer(options, createHydrationFns) {
  6469. const target = getGlobalThis();
  6470. target.__VUE__ = true;
  6471. {
  6472. setDevtoolsHook(target.__VUE_DEVTOOLS_GLOBAL_HOOK__, target);
  6473. }
  6474. const { insert: hostInsert, remove: hostRemove, patchProp: hostPatchProp, createElement: hostCreateElement, createText: hostCreateText, createComment: hostCreateComment, setText: hostSetText, setElementText: hostSetElementText, parentNode: hostParentNode, nextSibling: hostNextSibling, setScopeId: hostSetScopeId = NOOP, insertStaticContent: hostInsertStaticContent } = options;
  6475. // Note: functions inside this closure should use `const xxx = () => {}`
  6476. // style in order to prevent being inlined by minifiers.
  6477. const patch = (n1, n2, container, anchor = null, parentComponent = null, parentSuspense = null, isSVG = false, slotScopeIds = null, optimized = isHmrUpdating ? false : !!n2.dynamicChildren) => {
  6478. if (n1 === n2) {
  6479. return;
  6480. }
  6481. // patching & not same type, unmount old tree
  6482. if (n1 && !isSameVNodeType(n1, n2)) {
  6483. anchor = getNextHostNode(n1);
  6484. unmount(n1, parentComponent, parentSuspense, true);
  6485. n1 = null;
  6486. }
  6487. if (n2.patchFlag === -2 /* PatchFlags.BAIL */) {
  6488. optimized = false;
  6489. n2.dynamicChildren = null;
  6490. }
  6491. const { type, ref, shapeFlag } = n2;
  6492. switch (type) {
  6493. case Text:
  6494. processText(n1, n2, container, anchor);
  6495. break;
  6496. case Comment:
  6497. processCommentNode(n1, n2, container, anchor);
  6498. break;
  6499. case Static:
  6500. if (n1 == null) {
  6501. mountStaticNode(n2, container, anchor, isSVG);
  6502. }
  6503. else {
  6504. patchStaticNode(n1, n2, container, isSVG);
  6505. }
  6506. break;
  6507. case Fragment:
  6508. processFragment(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6509. break;
  6510. default:
  6511. if (shapeFlag & 1 /* ShapeFlags.ELEMENT */) {
  6512. processElement(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6513. }
  6514. else if (shapeFlag & 6 /* ShapeFlags.COMPONENT */) {
  6515. processComponent(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6516. }
  6517. else if (shapeFlag & 64 /* ShapeFlags.TELEPORT */) {
  6518. type.process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, internals);
  6519. }
  6520. else if (shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
  6521. type.process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, internals);
  6522. }
  6523. else {
  6524. warn('Invalid VNode type:', type, `(${typeof type})`);
  6525. }
  6526. }
  6527. // set ref
  6528. if (ref != null && parentComponent) {
  6529. setRef(ref, n1 && n1.ref, parentSuspense, n2 || n1, !n2);
  6530. }
  6531. };
  6532. const processText = (n1, n2, container, anchor) => {
  6533. if (n1 == null) {
  6534. hostInsert((n2.el = hostCreateText(n2.children)), container, anchor);
  6535. }
  6536. else {
  6537. const el = (n2.el = n1.el);
  6538. if (n2.children !== n1.children) {
  6539. hostSetText(el, n2.children);
  6540. }
  6541. }
  6542. };
  6543. const processCommentNode = (n1, n2, container, anchor) => {
  6544. if (n1 == null) {
  6545. hostInsert((n2.el = hostCreateComment(n2.children || '')), container, anchor);
  6546. }
  6547. else {
  6548. // there's no support for dynamic comments
  6549. n2.el = n1.el;
  6550. }
  6551. };
  6552. const mountStaticNode = (n2, container, anchor, isSVG) => {
  6553. [n2.el, n2.anchor] = hostInsertStaticContent(n2.children, container, anchor, isSVG, n2.el, n2.anchor);
  6554. };
  6555. /**
  6556. * Dev / HMR only
  6557. */
  6558. const patchStaticNode = (n1, n2, container, isSVG) => {
  6559. // static nodes are only patched during dev for HMR
  6560. if (n2.children !== n1.children) {
  6561. const anchor = hostNextSibling(n1.anchor);
  6562. // remove existing
  6563. removeStaticNode(n1);
  6564. [n2.el, n2.anchor] = hostInsertStaticContent(n2.children, container, anchor, isSVG);
  6565. }
  6566. else {
  6567. n2.el = n1.el;
  6568. n2.anchor = n1.anchor;
  6569. }
  6570. };
  6571. const moveStaticNode = ({ el, anchor }, container, nextSibling) => {
  6572. let next;
  6573. while (el && el !== anchor) {
  6574. next = hostNextSibling(el);
  6575. hostInsert(el, container, nextSibling);
  6576. el = next;
  6577. }
  6578. hostInsert(anchor, container, nextSibling);
  6579. };
  6580. const removeStaticNode = ({ el, anchor }) => {
  6581. let next;
  6582. while (el && el !== anchor) {
  6583. next = hostNextSibling(el);
  6584. hostRemove(el);
  6585. el = next;
  6586. }
  6587. hostRemove(anchor);
  6588. };
  6589. const processElement = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6590. isSVG = isSVG || n2.type === 'svg';
  6591. if (n1 == null) {
  6592. mountElement(n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6593. }
  6594. else {
  6595. patchElement(n1, n2, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6596. }
  6597. };
  6598. const mountElement = (vnode, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6599. let el;
  6600. let vnodeHook;
  6601. const { type, props, shapeFlag, transition, dirs } = vnode;
  6602. el = vnode.el = hostCreateElement(vnode.type, isSVG, props && props.is, props);
  6603. // mount children first, since some props may rely on child content
  6604. // being already rendered, e.g. `<select value>`
  6605. if (shapeFlag & 8 /* ShapeFlags.TEXT_CHILDREN */) {
  6606. hostSetElementText(el, vnode.children);
  6607. }
  6608. else if (shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  6609. mountChildren(vnode.children, el, null, parentComponent, parentSuspense, isSVG && type !== 'foreignObject', slotScopeIds, optimized);
  6610. }
  6611. if (dirs) {
  6612. invokeDirectiveHook(vnode, null, parentComponent, 'created');
  6613. }
  6614. // scopeId
  6615. setScopeId(el, vnode, vnode.scopeId, slotScopeIds, parentComponent);
  6616. // props
  6617. if (props) {
  6618. for (const key in props) {
  6619. if (key !== 'value' && !isReservedProp(key)) {
  6620. hostPatchProp(el, key, null, props[key], isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  6621. }
  6622. }
  6623. /**
  6624. * Special case for setting value on DOM elements:
  6625. * - it can be order-sensitive (e.g. should be set *after* min/max, #2325, #4024)
  6626. * - it needs to be forced (#1471)
  6627. * #2353 proposes adding another renderer option to configure this, but
  6628. * the properties affects are so finite it is worth special casing it
  6629. * here to reduce the complexity. (Special casing it also should not
  6630. * affect non-DOM renderers)
  6631. */
  6632. if ('value' in props) {
  6633. hostPatchProp(el, 'value', null, props.value);
  6634. }
  6635. if ((vnodeHook = props.onVnodeBeforeMount)) {
  6636. invokeVNodeHook(vnodeHook, parentComponent, vnode);
  6637. }
  6638. }
  6639. {
  6640. Object.defineProperty(el, '__vnode', {
  6641. value: vnode,
  6642. enumerable: false
  6643. });
  6644. Object.defineProperty(el, '__vueParentComponent', {
  6645. value: parentComponent,
  6646. enumerable: false
  6647. });
  6648. }
  6649. if (dirs) {
  6650. invokeDirectiveHook(vnode, null, parentComponent, 'beforeMount');
  6651. }
  6652. // #1583 For inside suspense + suspense not resolved case, enter hook should call when suspense resolved
  6653. // #1689 For inside suspense + suspense resolved case, just call it
  6654. const needCallTransitionHooks = (!parentSuspense || (parentSuspense && !parentSuspense.pendingBranch)) &&
  6655. transition &&
  6656. !transition.persisted;
  6657. if (needCallTransitionHooks) {
  6658. transition.beforeEnter(el);
  6659. }
  6660. hostInsert(el, container, anchor);
  6661. if ((vnodeHook = props && props.onVnodeMounted) ||
  6662. needCallTransitionHooks ||
  6663. dirs) {
  6664. queuePostRenderEffect(() => {
  6665. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, vnode);
  6666. needCallTransitionHooks && transition.enter(el);
  6667. dirs && invokeDirectiveHook(vnode, null, parentComponent, 'mounted');
  6668. }, parentSuspense);
  6669. }
  6670. };
  6671. const setScopeId = (el, vnode, scopeId, slotScopeIds, parentComponent) => {
  6672. if (scopeId) {
  6673. hostSetScopeId(el, scopeId);
  6674. }
  6675. if (slotScopeIds) {
  6676. for (let i = 0; i < slotScopeIds.length; i++) {
  6677. hostSetScopeId(el, slotScopeIds[i]);
  6678. }
  6679. }
  6680. if (parentComponent) {
  6681. let subTree = parentComponent.subTree;
  6682. if (subTree.patchFlag > 0 &&
  6683. subTree.patchFlag & 2048 /* PatchFlags.DEV_ROOT_FRAGMENT */) {
  6684. subTree =
  6685. filterSingleRoot(subTree.children) || subTree;
  6686. }
  6687. if (vnode === subTree) {
  6688. const parentVNode = parentComponent.vnode;
  6689. setScopeId(el, parentVNode, parentVNode.scopeId, parentVNode.slotScopeIds, parentComponent.parent);
  6690. }
  6691. }
  6692. };
  6693. const mountChildren = (children, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, start = 0) => {
  6694. for (let i = start; i < children.length; i++) {
  6695. const child = (children[i] = optimized
  6696. ? cloneIfMounted(children[i])
  6697. : normalizeVNode(children[i]));
  6698. patch(null, child, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6699. }
  6700. };
  6701. const patchElement = (n1, n2, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6702. const el = (n2.el = n1.el);
  6703. let { patchFlag, dynamicChildren, dirs } = n2;
  6704. // #1426 take the old vnode's patch flag into account since user may clone a
  6705. // compiler-generated vnode, which de-opts to FULL_PROPS
  6706. patchFlag |= n1.patchFlag & 16 /* PatchFlags.FULL_PROPS */;
  6707. const oldProps = n1.props || EMPTY_OBJ;
  6708. const newProps = n2.props || EMPTY_OBJ;
  6709. let vnodeHook;
  6710. // disable recurse in beforeUpdate hooks
  6711. parentComponent && toggleRecurse(parentComponent, false);
  6712. if ((vnodeHook = newProps.onVnodeBeforeUpdate)) {
  6713. invokeVNodeHook(vnodeHook, parentComponent, n2, n1);
  6714. }
  6715. if (dirs) {
  6716. invokeDirectiveHook(n2, n1, parentComponent, 'beforeUpdate');
  6717. }
  6718. parentComponent && toggleRecurse(parentComponent, true);
  6719. if (isHmrUpdating) {
  6720. // HMR updated, force full diff
  6721. patchFlag = 0;
  6722. optimized = false;
  6723. dynamicChildren = null;
  6724. }
  6725. const areChildrenSVG = isSVG && n2.type !== 'foreignObject';
  6726. if (dynamicChildren) {
  6727. patchBlockChildren(n1.dynamicChildren, dynamicChildren, el, parentComponent, parentSuspense, areChildrenSVG, slotScopeIds);
  6728. if (parentComponent && parentComponent.type.__hmrId) {
  6729. traverseStaticChildren(n1, n2);
  6730. }
  6731. }
  6732. else if (!optimized) {
  6733. // full diff
  6734. patchChildren(n1, n2, el, null, parentComponent, parentSuspense, areChildrenSVG, slotScopeIds, false);
  6735. }
  6736. if (patchFlag > 0) {
  6737. // the presence of a patchFlag means this element's render code was
  6738. // generated by the compiler and can take the fast path.
  6739. // in this path old node and new node are guaranteed to have the same shape
  6740. // (i.e. at the exact same position in the source template)
  6741. if (patchFlag & 16 /* PatchFlags.FULL_PROPS */) {
  6742. // element props contain dynamic keys, full diff needed
  6743. patchProps(el, n2, oldProps, newProps, parentComponent, parentSuspense, isSVG);
  6744. }
  6745. else {
  6746. // class
  6747. // this flag is matched when the element has dynamic class bindings.
  6748. if (patchFlag & 2 /* PatchFlags.CLASS */) {
  6749. if (oldProps.class !== newProps.class) {
  6750. hostPatchProp(el, 'class', null, newProps.class, isSVG);
  6751. }
  6752. }
  6753. // style
  6754. // this flag is matched when the element has dynamic style bindings
  6755. if (patchFlag & 4 /* PatchFlags.STYLE */) {
  6756. hostPatchProp(el, 'style', oldProps.style, newProps.style, isSVG);
  6757. }
  6758. // props
  6759. // This flag is matched when the element has dynamic prop/attr bindings
  6760. // other than class and style. The keys of dynamic prop/attrs are saved for
  6761. // faster iteration.
  6762. // Note dynamic keys like :[foo]="bar" will cause this optimization to
  6763. // bail out and go through a full diff because we need to unset the old key
  6764. if (patchFlag & 8 /* PatchFlags.PROPS */) {
  6765. // if the flag is present then dynamicProps must be non-null
  6766. const propsToUpdate = n2.dynamicProps;
  6767. for (let i = 0; i < propsToUpdate.length; i++) {
  6768. const key = propsToUpdate[i];
  6769. const prev = oldProps[key];
  6770. const next = newProps[key];
  6771. // #1471 force patch value
  6772. if (next !== prev || key === 'value') {
  6773. hostPatchProp(el, key, prev, next, isSVG, n1.children, parentComponent, parentSuspense, unmountChildren);
  6774. }
  6775. }
  6776. }
  6777. }
  6778. // text
  6779. // This flag is matched when the element has only dynamic text children.
  6780. if (patchFlag & 1 /* PatchFlags.TEXT */) {
  6781. if (n1.children !== n2.children) {
  6782. hostSetElementText(el, n2.children);
  6783. }
  6784. }
  6785. }
  6786. else if (!optimized && dynamicChildren == null) {
  6787. // unoptimized, full diff
  6788. patchProps(el, n2, oldProps, newProps, parentComponent, parentSuspense, isSVG);
  6789. }
  6790. if ((vnodeHook = newProps.onVnodeUpdated) || dirs) {
  6791. queuePostRenderEffect(() => {
  6792. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, n2, n1);
  6793. dirs && invokeDirectiveHook(n2, n1, parentComponent, 'updated');
  6794. }, parentSuspense);
  6795. }
  6796. };
  6797. // The fast path for blocks.
  6798. const patchBlockChildren = (oldChildren, newChildren, fallbackContainer, parentComponent, parentSuspense, isSVG, slotScopeIds) => {
  6799. for (let i = 0; i < newChildren.length; i++) {
  6800. const oldVNode = oldChildren[i];
  6801. const newVNode = newChildren[i];
  6802. // Determine the container (parent element) for the patch.
  6803. const container =
  6804. // oldVNode may be an errored async setup() component inside Suspense
  6805. // which will not have a mounted element
  6806. oldVNode.el &&
  6807. // - In the case of a Fragment, we need to provide the actual parent
  6808. // of the Fragment itself so it can move its children.
  6809. (oldVNode.type === Fragment ||
  6810. // - In the case of different nodes, there is going to be a replacement
  6811. // which also requires the correct parent container
  6812. !isSameVNodeType(oldVNode, newVNode) ||
  6813. // - In the case of a component, it could contain anything.
  6814. oldVNode.shapeFlag & (6 /* ShapeFlags.COMPONENT */ | 64 /* ShapeFlags.TELEPORT */))
  6815. ? hostParentNode(oldVNode.el)
  6816. : // In other cases, the parent container is not actually used so we
  6817. // just pass the block element here to avoid a DOM parentNode call.
  6818. fallbackContainer;
  6819. patch(oldVNode, newVNode, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, true);
  6820. }
  6821. };
  6822. const patchProps = (el, vnode, oldProps, newProps, parentComponent, parentSuspense, isSVG) => {
  6823. if (oldProps !== newProps) {
  6824. if (oldProps !== EMPTY_OBJ) {
  6825. for (const key in oldProps) {
  6826. if (!isReservedProp(key) && !(key in newProps)) {
  6827. hostPatchProp(el, key, oldProps[key], null, isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  6828. }
  6829. }
  6830. }
  6831. for (const key in newProps) {
  6832. // empty string is not valid prop
  6833. if (isReservedProp(key))
  6834. continue;
  6835. const next = newProps[key];
  6836. const prev = oldProps[key];
  6837. // defer patching value
  6838. if (next !== prev && key !== 'value') {
  6839. hostPatchProp(el, key, prev, next, isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  6840. }
  6841. }
  6842. if ('value' in newProps) {
  6843. hostPatchProp(el, 'value', oldProps.value, newProps.value);
  6844. }
  6845. }
  6846. };
  6847. const processFragment = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6848. const fragmentStartAnchor = (n2.el = n1 ? n1.el : hostCreateText(''));
  6849. const fragmentEndAnchor = (n2.anchor = n1 ? n1.anchor : hostCreateText(''));
  6850. let { patchFlag, dynamicChildren, slotScopeIds: fragmentSlotScopeIds } = n2;
  6851. if (// #5523 dev root fragment may inherit directives
  6852. (isHmrUpdating || patchFlag & 2048 /* PatchFlags.DEV_ROOT_FRAGMENT */)) {
  6853. // HMR updated / Dev root fragment (w/ comments), force full diff
  6854. patchFlag = 0;
  6855. optimized = false;
  6856. dynamicChildren = null;
  6857. }
  6858. // check if this is a slot fragment with :slotted scope ids
  6859. if (fragmentSlotScopeIds) {
  6860. slotScopeIds = slotScopeIds
  6861. ? slotScopeIds.concat(fragmentSlotScopeIds)
  6862. : fragmentSlotScopeIds;
  6863. }
  6864. if (n1 == null) {
  6865. hostInsert(fragmentStartAnchor, container, anchor);
  6866. hostInsert(fragmentEndAnchor, container, anchor);
  6867. // a fragment can only have array children
  6868. // since they are either generated by the compiler, or implicitly created
  6869. // from arrays.
  6870. mountChildren(n2.children, container, fragmentEndAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6871. }
  6872. else {
  6873. if (patchFlag > 0 &&
  6874. patchFlag & 64 /* PatchFlags.STABLE_FRAGMENT */ &&
  6875. dynamicChildren &&
  6876. // #2715 the previous fragment could've been a BAILed one as a result
  6877. // of renderSlot() with no valid children
  6878. n1.dynamicChildren) {
  6879. // a stable fragment (template root or <template v-for>) doesn't need to
  6880. // patch children order, but it may contain dynamicChildren.
  6881. patchBlockChildren(n1.dynamicChildren, dynamicChildren, container, parentComponent, parentSuspense, isSVG, slotScopeIds);
  6882. if (parentComponent && parentComponent.type.__hmrId) {
  6883. traverseStaticChildren(n1, n2);
  6884. }
  6885. else if (
  6886. // #2080 if the stable fragment has a key, it's a <template v-for> that may
  6887. // get moved around. Make sure all root level vnodes inherit el.
  6888. // #2134 or if it's a component root, it may also get moved around
  6889. // as the component is being moved.
  6890. n2.key != null ||
  6891. (parentComponent && n2 === parentComponent.subTree)) {
  6892. traverseStaticChildren(n1, n2, true /* shallow */);
  6893. }
  6894. }
  6895. else {
  6896. // keyed / unkeyed, or manual fragments.
  6897. // for keyed & unkeyed, since they are compiler generated from v-for,
  6898. // each child is guaranteed to be a block so the fragment will never
  6899. // have dynamicChildren.
  6900. patchChildren(n1, n2, container, fragmentEndAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6901. }
  6902. }
  6903. };
  6904. const processComponent = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6905. n2.slotScopeIds = slotScopeIds;
  6906. if (n1 == null) {
  6907. if (n2.shapeFlag & 512 /* ShapeFlags.COMPONENT_KEPT_ALIVE */) {
  6908. parentComponent.ctx.activate(n2, container, anchor, isSVG, optimized);
  6909. }
  6910. else {
  6911. mountComponent(n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  6912. }
  6913. }
  6914. else {
  6915. updateComponent(n1, n2, optimized);
  6916. }
  6917. };
  6918. const mountComponent = (initialVNode, container, anchor, parentComponent, parentSuspense, isSVG, optimized) => {
  6919. const instance = (initialVNode.component = createComponentInstance(initialVNode, parentComponent, parentSuspense));
  6920. if (instance.type.__hmrId) {
  6921. registerHMR(instance);
  6922. }
  6923. {
  6924. pushWarningContext(initialVNode);
  6925. startMeasure(instance, `mount`);
  6926. }
  6927. // inject renderer internals for keepAlive
  6928. if (isKeepAlive(initialVNode)) {
  6929. instance.ctx.renderer = internals;
  6930. }
  6931. // resolve props and slots for setup context
  6932. {
  6933. {
  6934. startMeasure(instance, `init`);
  6935. }
  6936. setupComponent(instance);
  6937. {
  6938. endMeasure(instance, `init`);
  6939. }
  6940. }
  6941. // setup() is async. This component relies on async logic to be resolved
  6942. // before proceeding
  6943. if (instance.asyncDep) {
  6944. parentSuspense && parentSuspense.registerDep(instance, setupRenderEffect);
  6945. // Give it a placeholder if this is not hydration
  6946. // TODO handle self-defined fallback
  6947. if (!initialVNode.el) {
  6948. const placeholder = (instance.subTree = createVNode(Comment));
  6949. processCommentNode(null, placeholder, container, anchor);
  6950. }
  6951. return;
  6952. }
  6953. setupRenderEffect(instance, initialVNode, container, anchor, parentSuspense, isSVG, optimized);
  6954. {
  6955. popWarningContext();
  6956. endMeasure(instance, `mount`);
  6957. }
  6958. };
  6959. const updateComponent = (n1, n2, optimized) => {
  6960. const instance = (n2.component = n1.component);
  6961. if (shouldUpdateComponent(n1, n2, optimized)) {
  6962. if (instance.asyncDep &&
  6963. !instance.asyncResolved) {
  6964. // async & still pending - just update props and slots
  6965. // since the component's reactive effect for render isn't set-up yet
  6966. {
  6967. pushWarningContext(n2);
  6968. }
  6969. updateComponentPreRender(instance, n2, optimized);
  6970. {
  6971. popWarningContext();
  6972. }
  6973. return;
  6974. }
  6975. else {
  6976. // normal update
  6977. instance.next = n2;
  6978. // in case the child component is also queued, remove it to avoid
  6979. // double updating the same child component in the same flush.
  6980. invalidateJob(instance.update);
  6981. // instance.update is the reactive effect.
  6982. instance.update();
  6983. }
  6984. }
  6985. else {
  6986. // no update needed. just copy over properties
  6987. n2.el = n1.el;
  6988. instance.vnode = n2;
  6989. }
  6990. };
  6991. const setupRenderEffect = (instance, initialVNode, container, anchor, parentSuspense, isSVG, optimized) => {
  6992. const componentUpdateFn = () => {
  6993. if (!instance.isMounted) {
  6994. let vnodeHook;
  6995. const { el, props } = initialVNode;
  6996. const { bm, m, parent } = instance;
  6997. const isAsyncWrapperVNode = isAsyncWrapper(initialVNode);
  6998. toggleRecurse(instance, false);
  6999. // beforeMount hook
  7000. if (bm) {
  7001. invokeArrayFns(bm);
  7002. }
  7003. // onVnodeBeforeMount
  7004. if (!isAsyncWrapperVNode &&
  7005. (vnodeHook = props && props.onVnodeBeforeMount)) {
  7006. invokeVNodeHook(vnodeHook, parent, initialVNode);
  7007. }
  7008. toggleRecurse(instance, true);
  7009. if (el && hydrateNode) {
  7010. // vnode has adopted host node - perform hydration instead of mount.
  7011. const hydrateSubTree = () => {
  7012. {
  7013. startMeasure(instance, `render`);
  7014. }
  7015. instance.subTree = renderComponentRoot(instance);
  7016. {
  7017. endMeasure(instance, `render`);
  7018. }
  7019. {
  7020. startMeasure(instance, `hydrate`);
  7021. }
  7022. hydrateNode(el, instance.subTree, instance, parentSuspense, null);
  7023. {
  7024. endMeasure(instance, `hydrate`);
  7025. }
  7026. };
  7027. if (isAsyncWrapperVNode) {
  7028. initialVNode.type.__asyncLoader().then(
  7029. // note: we are moving the render call into an async callback,
  7030. // which means it won't track dependencies - but it's ok because
  7031. // a server-rendered async wrapper is already in resolved state
  7032. // and it will never need to change.
  7033. () => !instance.isUnmounted && hydrateSubTree());
  7034. }
  7035. else {
  7036. hydrateSubTree();
  7037. }
  7038. }
  7039. else {
  7040. {
  7041. startMeasure(instance, `render`);
  7042. }
  7043. const subTree = (instance.subTree = renderComponentRoot(instance));
  7044. {
  7045. endMeasure(instance, `render`);
  7046. }
  7047. {
  7048. startMeasure(instance, `patch`);
  7049. }
  7050. patch(null, subTree, container, anchor, instance, parentSuspense, isSVG);
  7051. {
  7052. endMeasure(instance, `patch`);
  7053. }
  7054. initialVNode.el = subTree.el;
  7055. }
  7056. // mounted hook
  7057. if (m) {
  7058. queuePostRenderEffect(m, parentSuspense);
  7059. }
  7060. // onVnodeMounted
  7061. if (!isAsyncWrapperVNode &&
  7062. (vnodeHook = props && props.onVnodeMounted)) {
  7063. const scopedInitialVNode = initialVNode;
  7064. queuePostRenderEffect(() => invokeVNodeHook(vnodeHook, parent, scopedInitialVNode), parentSuspense);
  7065. }
  7066. // activated hook for keep-alive roots.
  7067. // #1742 activated hook must be accessed after first render
  7068. // since the hook may be injected by a child keep-alive
  7069. if (initialVNode.shapeFlag & 256 /* ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE */ ||
  7070. (parent &&
  7071. isAsyncWrapper(parent.vnode) &&
  7072. parent.vnode.shapeFlag & 256 /* ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE */)) {
  7073. instance.a && queuePostRenderEffect(instance.a, parentSuspense);
  7074. }
  7075. instance.isMounted = true;
  7076. {
  7077. devtoolsComponentAdded(instance);
  7078. }
  7079. // #2458: deference mount-only object parameters to prevent memleaks
  7080. initialVNode = container = anchor = null;
  7081. }
  7082. else {
  7083. // updateComponent
  7084. // This is triggered by mutation of component's own state (next: null)
  7085. // OR parent calling processComponent (next: VNode)
  7086. let { next, bu, u, parent, vnode } = instance;
  7087. let originNext = next;
  7088. let vnodeHook;
  7089. {
  7090. pushWarningContext(next || instance.vnode);
  7091. }
  7092. // Disallow component effect recursion during pre-lifecycle hooks.
  7093. toggleRecurse(instance, false);
  7094. if (next) {
  7095. next.el = vnode.el;
  7096. updateComponentPreRender(instance, next, optimized);
  7097. }
  7098. else {
  7099. next = vnode;
  7100. }
  7101. // beforeUpdate hook
  7102. if (bu) {
  7103. invokeArrayFns(bu);
  7104. }
  7105. // onVnodeBeforeUpdate
  7106. if ((vnodeHook = next.props && next.props.onVnodeBeforeUpdate)) {
  7107. invokeVNodeHook(vnodeHook, parent, next, vnode);
  7108. }
  7109. toggleRecurse(instance, true);
  7110. // render
  7111. {
  7112. startMeasure(instance, `render`);
  7113. }
  7114. const nextTree = renderComponentRoot(instance);
  7115. {
  7116. endMeasure(instance, `render`);
  7117. }
  7118. const prevTree = instance.subTree;
  7119. instance.subTree = nextTree;
  7120. {
  7121. startMeasure(instance, `patch`);
  7122. }
  7123. patch(prevTree, nextTree,
  7124. // parent may have changed if it's in a teleport
  7125. hostParentNode(prevTree.el),
  7126. // anchor may have changed if it's in a fragment
  7127. getNextHostNode(prevTree), instance, parentSuspense, isSVG);
  7128. {
  7129. endMeasure(instance, `patch`);
  7130. }
  7131. next.el = nextTree.el;
  7132. if (originNext === null) {
  7133. // self-triggered update. In case of HOC, update parent component
  7134. // vnode el. HOC is indicated by parent instance's subTree pointing
  7135. // to child component's vnode
  7136. updateHOCHostEl(instance, nextTree.el);
  7137. }
  7138. // updated hook
  7139. if (u) {
  7140. queuePostRenderEffect(u, parentSuspense);
  7141. }
  7142. // onVnodeUpdated
  7143. if ((vnodeHook = next.props && next.props.onVnodeUpdated)) {
  7144. queuePostRenderEffect(() => invokeVNodeHook(vnodeHook, parent, next, vnode), parentSuspense);
  7145. }
  7146. {
  7147. devtoolsComponentUpdated(instance);
  7148. }
  7149. {
  7150. popWarningContext();
  7151. }
  7152. }
  7153. };
  7154. // create reactive effect for rendering
  7155. const effect = (instance.effect = new ReactiveEffect(componentUpdateFn, () => queueJob(update), instance.scope // track it in component's effect scope
  7156. ));
  7157. const update = (instance.update = () => effect.run());
  7158. update.id = instance.uid;
  7159. // allowRecurse
  7160. // #1801, #2043 component render effects should allow recursive updates
  7161. toggleRecurse(instance, true);
  7162. {
  7163. effect.onTrack = instance.rtc
  7164. ? e => invokeArrayFns(instance.rtc, e)
  7165. : void 0;
  7166. effect.onTrigger = instance.rtg
  7167. ? e => invokeArrayFns(instance.rtg, e)
  7168. : void 0;
  7169. update.ownerInstance = instance;
  7170. }
  7171. update();
  7172. };
  7173. const updateComponentPreRender = (instance, nextVNode, optimized) => {
  7174. nextVNode.component = instance;
  7175. const prevProps = instance.vnode.props;
  7176. instance.vnode = nextVNode;
  7177. instance.next = null;
  7178. updateProps(instance, nextVNode.props, prevProps, optimized);
  7179. updateSlots(instance, nextVNode.children, optimized);
  7180. pauseTracking();
  7181. // props update may have triggered pre-flush watchers.
  7182. // flush them before the render update.
  7183. flushPreFlushCbs();
  7184. resetTracking();
  7185. };
  7186. const patchChildren = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized = false) => {
  7187. const c1 = n1 && n1.children;
  7188. const prevShapeFlag = n1 ? n1.shapeFlag : 0;
  7189. const c2 = n2.children;
  7190. const { patchFlag, shapeFlag } = n2;
  7191. // fast path
  7192. if (patchFlag > 0) {
  7193. if (patchFlag & 128 /* PatchFlags.KEYED_FRAGMENT */) {
  7194. // this could be either fully-keyed or mixed (some keyed some not)
  7195. // presence of patchFlag means children are guaranteed to be arrays
  7196. patchKeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7197. return;
  7198. }
  7199. else if (patchFlag & 256 /* PatchFlags.UNKEYED_FRAGMENT */) {
  7200. // unkeyed
  7201. patchUnkeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7202. return;
  7203. }
  7204. }
  7205. // children has 3 possibilities: text, array or no children.
  7206. if (shapeFlag & 8 /* ShapeFlags.TEXT_CHILDREN */) {
  7207. // text children fast path
  7208. if (prevShapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  7209. unmountChildren(c1, parentComponent, parentSuspense);
  7210. }
  7211. if (c2 !== c1) {
  7212. hostSetElementText(container, c2);
  7213. }
  7214. }
  7215. else {
  7216. if (prevShapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  7217. // prev children was array
  7218. if (shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  7219. // two arrays, cannot assume anything, do full diff
  7220. patchKeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7221. }
  7222. else {
  7223. // no new children, just unmount old
  7224. unmountChildren(c1, parentComponent, parentSuspense, true);
  7225. }
  7226. }
  7227. else {
  7228. // prev children was text OR null
  7229. // new children is array OR null
  7230. if (prevShapeFlag & 8 /* ShapeFlags.TEXT_CHILDREN */) {
  7231. hostSetElementText(container, '');
  7232. }
  7233. // mount new if array
  7234. if (shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  7235. mountChildren(c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7236. }
  7237. }
  7238. }
  7239. };
  7240. const patchUnkeyedChildren = (c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  7241. c1 = c1 || EMPTY_ARR;
  7242. c2 = c2 || EMPTY_ARR;
  7243. const oldLength = c1.length;
  7244. const newLength = c2.length;
  7245. const commonLength = Math.min(oldLength, newLength);
  7246. let i;
  7247. for (i = 0; i < commonLength; i++) {
  7248. const nextChild = (c2[i] = optimized
  7249. ? cloneIfMounted(c2[i])
  7250. : normalizeVNode(c2[i]));
  7251. patch(c1[i], nextChild, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7252. }
  7253. if (oldLength > newLength) {
  7254. // remove old
  7255. unmountChildren(c1, parentComponent, parentSuspense, true, false, commonLength);
  7256. }
  7257. else {
  7258. // mount new
  7259. mountChildren(c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, commonLength);
  7260. }
  7261. };
  7262. // can be all-keyed or mixed
  7263. const patchKeyedChildren = (c1, c2, container, parentAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  7264. let i = 0;
  7265. const l2 = c2.length;
  7266. let e1 = c1.length - 1; // prev ending index
  7267. let e2 = l2 - 1; // next ending index
  7268. // 1. sync from start
  7269. // (a b) c
  7270. // (a b) d e
  7271. while (i <= e1 && i <= e2) {
  7272. const n1 = c1[i];
  7273. const n2 = (c2[i] = optimized
  7274. ? cloneIfMounted(c2[i])
  7275. : normalizeVNode(c2[i]));
  7276. if (isSameVNodeType(n1, n2)) {
  7277. patch(n1, n2, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7278. }
  7279. else {
  7280. break;
  7281. }
  7282. i++;
  7283. }
  7284. // 2. sync from end
  7285. // a (b c)
  7286. // d e (b c)
  7287. while (i <= e1 && i <= e2) {
  7288. const n1 = c1[e1];
  7289. const n2 = (c2[e2] = optimized
  7290. ? cloneIfMounted(c2[e2])
  7291. : normalizeVNode(c2[e2]));
  7292. if (isSameVNodeType(n1, n2)) {
  7293. patch(n1, n2, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7294. }
  7295. else {
  7296. break;
  7297. }
  7298. e1--;
  7299. e2--;
  7300. }
  7301. // 3. common sequence + mount
  7302. // (a b)
  7303. // (a b) c
  7304. // i = 2, e1 = 1, e2 = 2
  7305. // (a b)
  7306. // c (a b)
  7307. // i = 0, e1 = -1, e2 = 0
  7308. if (i > e1) {
  7309. if (i <= e2) {
  7310. const nextPos = e2 + 1;
  7311. const anchor = nextPos < l2 ? c2[nextPos].el : parentAnchor;
  7312. while (i <= e2) {
  7313. patch(null, (c2[i] = optimized
  7314. ? cloneIfMounted(c2[i])
  7315. : normalizeVNode(c2[i])), container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7316. i++;
  7317. }
  7318. }
  7319. }
  7320. // 4. common sequence + unmount
  7321. // (a b) c
  7322. // (a b)
  7323. // i = 2, e1 = 2, e2 = 1
  7324. // a (b c)
  7325. // (b c)
  7326. // i = 0, e1 = 0, e2 = -1
  7327. else if (i > e2) {
  7328. while (i <= e1) {
  7329. unmount(c1[i], parentComponent, parentSuspense, true);
  7330. i++;
  7331. }
  7332. }
  7333. // 5. unknown sequence
  7334. // [i ... e1 + 1]: a b [c d e] f g
  7335. // [i ... e2 + 1]: a b [e d c h] f g
  7336. // i = 2, e1 = 4, e2 = 5
  7337. else {
  7338. const s1 = i; // prev starting index
  7339. const s2 = i; // next starting index
  7340. // 5.1 build key:index map for newChildren
  7341. const keyToNewIndexMap = new Map();
  7342. for (i = s2; i <= e2; i++) {
  7343. const nextChild = (c2[i] = optimized
  7344. ? cloneIfMounted(c2[i])
  7345. : normalizeVNode(c2[i]));
  7346. if (nextChild.key != null) {
  7347. if (keyToNewIndexMap.has(nextChild.key)) {
  7348. warn(`Duplicate keys found during update:`, JSON.stringify(nextChild.key), `Make sure keys are unique.`);
  7349. }
  7350. keyToNewIndexMap.set(nextChild.key, i);
  7351. }
  7352. }
  7353. // 5.2 loop through old children left to be patched and try to patch
  7354. // matching nodes & remove nodes that are no longer present
  7355. let j;
  7356. let patched = 0;
  7357. const toBePatched = e2 - s2 + 1;
  7358. let moved = false;
  7359. // used to track whether any node has moved
  7360. let maxNewIndexSoFar = 0;
  7361. // works as Map<newIndex, oldIndex>
  7362. // Note that oldIndex is offset by +1
  7363. // and oldIndex = 0 is a special value indicating the new node has
  7364. // no corresponding old node.
  7365. // used for determining longest stable subsequence
  7366. const newIndexToOldIndexMap = new Array(toBePatched);
  7367. for (i = 0; i < toBePatched; i++)
  7368. newIndexToOldIndexMap[i] = 0;
  7369. for (i = s1; i <= e1; i++) {
  7370. const prevChild = c1[i];
  7371. if (patched >= toBePatched) {
  7372. // all new children have been patched so this can only be a removal
  7373. unmount(prevChild, parentComponent, parentSuspense, true);
  7374. continue;
  7375. }
  7376. let newIndex;
  7377. if (prevChild.key != null) {
  7378. newIndex = keyToNewIndexMap.get(prevChild.key);
  7379. }
  7380. else {
  7381. // key-less node, try to locate a key-less node of the same type
  7382. for (j = s2; j <= e2; j++) {
  7383. if (newIndexToOldIndexMap[j - s2] === 0 &&
  7384. isSameVNodeType(prevChild, c2[j])) {
  7385. newIndex = j;
  7386. break;
  7387. }
  7388. }
  7389. }
  7390. if (newIndex === undefined) {
  7391. unmount(prevChild, parentComponent, parentSuspense, true);
  7392. }
  7393. else {
  7394. newIndexToOldIndexMap[newIndex - s2] = i + 1;
  7395. if (newIndex >= maxNewIndexSoFar) {
  7396. maxNewIndexSoFar = newIndex;
  7397. }
  7398. else {
  7399. moved = true;
  7400. }
  7401. patch(prevChild, c2[newIndex], container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7402. patched++;
  7403. }
  7404. }
  7405. // 5.3 move and mount
  7406. // generate longest stable subsequence only when nodes have moved
  7407. const increasingNewIndexSequence = moved
  7408. ? getSequence(newIndexToOldIndexMap)
  7409. : EMPTY_ARR;
  7410. j = increasingNewIndexSequence.length - 1;
  7411. // looping backwards so that we can use last patched node as anchor
  7412. for (i = toBePatched - 1; i >= 0; i--) {
  7413. const nextIndex = s2 + i;
  7414. const nextChild = c2[nextIndex];
  7415. const anchor = nextIndex + 1 < l2 ? c2[nextIndex + 1].el : parentAnchor;
  7416. if (newIndexToOldIndexMap[i] === 0) {
  7417. // mount new
  7418. patch(null, nextChild, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7419. }
  7420. else if (moved) {
  7421. // move if:
  7422. // There is no stable subsequence (e.g. a reverse)
  7423. // OR current node is not among the stable sequence
  7424. if (j < 0 || i !== increasingNewIndexSequence[j]) {
  7425. move(nextChild, container, anchor, 2 /* MoveType.REORDER */);
  7426. }
  7427. else {
  7428. j--;
  7429. }
  7430. }
  7431. }
  7432. }
  7433. };
  7434. const move = (vnode, container, anchor, moveType, parentSuspense = null) => {
  7435. const { el, type, transition, children, shapeFlag } = vnode;
  7436. if (shapeFlag & 6 /* ShapeFlags.COMPONENT */) {
  7437. move(vnode.component.subTree, container, anchor, moveType);
  7438. return;
  7439. }
  7440. if (shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
  7441. vnode.suspense.move(container, anchor, moveType);
  7442. return;
  7443. }
  7444. if (shapeFlag & 64 /* ShapeFlags.TELEPORT */) {
  7445. type.move(vnode, container, anchor, internals);
  7446. return;
  7447. }
  7448. if (type === Fragment) {
  7449. hostInsert(el, container, anchor);
  7450. for (let i = 0; i < children.length; i++) {
  7451. move(children[i], container, anchor, moveType);
  7452. }
  7453. hostInsert(vnode.anchor, container, anchor);
  7454. return;
  7455. }
  7456. if (type === Static) {
  7457. moveStaticNode(vnode, container, anchor);
  7458. return;
  7459. }
  7460. // single nodes
  7461. const needTransition = moveType !== 2 /* MoveType.REORDER */ &&
  7462. shapeFlag & 1 /* ShapeFlags.ELEMENT */ &&
  7463. transition;
  7464. if (needTransition) {
  7465. if (moveType === 0 /* MoveType.ENTER */) {
  7466. transition.beforeEnter(el);
  7467. hostInsert(el, container, anchor);
  7468. queuePostRenderEffect(() => transition.enter(el), parentSuspense);
  7469. }
  7470. else {
  7471. const { leave, delayLeave, afterLeave } = transition;
  7472. const remove = () => hostInsert(el, container, anchor);
  7473. const performLeave = () => {
  7474. leave(el, () => {
  7475. remove();
  7476. afterLeave && afterLeave();
  7477. });
  7478. };
  7479. if (delayLeave) {
  7480. delayLeave(el, remove, performLeave);
  7481. }
  7482. else {
  7483. performLeave();
  7484. }
  7485. }
  7486. }
  7487. else {
  7488. hostInsert(el, container, anchor);
  7489. }
  7490. };
  7491. const unmount = (vnode, parentComponent, parentSuspense, doRemove = false, optimized = false) => {
  7492. const { type, props, ref, children, dynamicChildren, shapeFlag, patchFlag, dirs } = vnode;
  7493. // unset ref
  7494. if (ref != null) {
  7495. setRef(ref, null, parentSuspense, vnode, true);
  7496. }
  7497. if (shapeFlag & 256 /* ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE */) {
  7498. parentComponent.ctx.deactivate(vnode);
  7499. return;
  7500. }
  7501. const shouldInvokeDirs = shapeFlag & 1 /* ShapeFlags.ELEMENT */ && dirs;
  7502. const shouldInvokeVnodeHook = !isAsyncWrapper(vnode);
  7503. let vnodeHook;
  7504. if (shouldInvokeVnodeHook &&
  7505. (vnodeHook = props && props.onVnodeBeforeUnmount)) {
  7506. invokeVNodeHook(vnodeHook, parentComponent, vnode);
  7507. }
  7508. if (shapeFlag & 6 /* ShapeFlags.COMPONENT */) {
  7509. unmountComponent(vnode.component, parentSuspense, doRemove);
  7510. }
  7511. else {
  7512. if (shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
  7513. vnode.suspense.unmount(parentSuspense, doRemove);
  7514. return;
  7515. }
  7516. if (shouldInvokeDirs) {
  7517. invokeDirectiveHook(vnode, null, parentComponent, 'beforeUnmount');
  7518. }
  7519. if (shapeFlag & 64 /* ShapeFlags.TELEPORT */) {
  7520. vnode.type.remove(vnode, parentComponent, parentSuspense, optimized, internals, doRemove);
  7521. }
  7522. else if (dynamicChildren &&
  7523. // #1153: fast path should not be taken for non-stable (v-for) fragments
  7524. (type !== Fragment ||
  7525. (patchFlag > 0 && patchFlag & 64 /* PatchFlags.STABLE_FRAGMENT */))) {
  7526. // fast path for block nodes: only need to unmount dynamic children.
  7527. unmountChildren(dynamicChildren, parentComponent, parentSuspense, false, true);
  7528. }
  7529. else if ((type === Fragment &&
  7530. patchFlag &
  7531. (128 /* PatchFlags.KEYED_FRAGMENT */ | 256 /* PatchFlags.UNKEYED_FRAGMENT */)) ||
  7532. (!optimized && shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */)) {
  7533. unmountChildren(children, parentComponent, parentSuspense);
  7534. }
  7535. if (doRemove) {
  7536. remove(vnode);
  7537. }
  7538. }
  7539. if ((shouldInvokeVnodeHook &&
  7540. (vnodeHook = props && props.onVnodeUnmounted)) ||
  7541. shouldInvokeDirs) {
  7542. queuePostRenderEffect(() => {
  7543. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, vnode);
  7544. shouldInvokeDirs &&
  7545. invokeDirectiveHook(vnode, null, parentComponent, 'unmounted');
  7546. }, parentSuspense);
  7547. }
  7548. };
  7549. const remove = vnode => {
  7550. const { type, el, anchor, transition } = vnode;
  7551. if (type === Fragment) {
  7552. if (vnode.patchFlag > 0 &&
  7553. vnode.patchFlag & 2048 /* PatchFlags.DEV_ROOT_FRAGMENT */ &&
  7554. transition &&
  7555. !transition.persisted) {
  7556. vnode.children.forEach(child => {
  7557. if (child.type === Comment) {
  7558. hostRemove(child.el);
  7559. }
  7560. else {
  7561. remove(child);
  7562. }
  7563. });
  7564. }
  7565. else {
  7566. removeFragment(el, anchor);
  7567. }
  7568. return;
  7569. }
  7570. if (type === Static) {
  7571. removeStaticNode(vnode);
  7572. return;
  7573. }
  7574. const performRemove = () => {
  7575. hostRemove(el);
  7576. if (transition && !transition.persisted && transition.afterLeave) {
  7577. transition.afterLeave();
  7578. }
  7579. };
  7580. if (vnode.shapeFlag & 1 /* ShapeFlags.ELEMENT */ &&
  7581. transition &&
  7582. !transition.persisted) {
  7583. const { leave, delayLeave } = transition;
  7584. const performLeave = () => leave(el, performRemove);
  7585. if (delayLeave) {
  7586. delayLeave(vnode.el, performRemove, performLeave);
  7587. }
  7588. else {
  7589. performLeave();
  7590. }
  7591. }
  7592. else {
  7593. performRemove();
  7594. }
  7595. };
  7596. const removeFragment = (cur, end) => {
  7597. // For fragments, directly remove all contained DOM nodes.
  7598. // (fragment child nodes cannot have transition)
  7599. let next;
  7600. while (cur !== end) {
  7601. next = hostNextSibling(cur);
  7602. hostRemove(cur);
  7603. cur = next;
  7604. }
  7605. hostRemove(end);
  7606. };
  7607. const unmountComponent = (instance, parentSuspense, doRemove) => {
  7608. if (instance.type.__hmrId) {
  7609. unregisterHMR(instance);
  7610. }
  7611. const { bum, scope, update, subTree, um } = instance;
  7612. // beforeUnmount hook
  7613. if (bum) {
  7614. invokeArrayFns(bum);
  7615. }
  7616. // stop effects in component scope
  7617. scope.stop();
  7618. // update may be null if a component is unmounted before its async
  7619. // setup has resolved.
  7620. if (update) {
  7621. // so that scheduler will no longer invoke it
  7622. update.active = false;
  7623. unmount(subTree, instance, parentSuspense, doRemove);
  7624. }
  7625. // unmounted hook
  7626. if (um) {
  7627. queuePostRenderEffect(um, parentSuspense);
  7628. }
  7629. queuePostRenderEffect(() => {
  7630. instance.isUnmounted = true;
  7631. }, parentSuspense);
  7632. // A component with async dep inside a pending suspense is unmounted before
  7633. // its async dep resolves. This should remove the dep from the suspense, and
  7634. // cause the suspense to resolve immediately if that was the last dep.
  7635. if (parentSuspense &&
  7636. parentSuspense.pendingBranch &&
  7637. !parentSuspense.isUnmounted &&
  7638. instance.asyncDep &&
  7639. !instance.asyncResolved &&
  7640. instance.suspenseId === parentSuspense.pendingId) {
  7641. parentSuspense.deps--;
  7642. if (parentSuspense.deps === 0) {
  7643. parentSuspense.resolve();
  7644. }
  7645. }
  7646. {
  7647. devtoolsComponentRemoved(instance);
  7648. }
  7649. };
  7650. const unmountChildren = (children, parentComponent, parentSuspense, doRemove = false, optimized = false, start = 0) => {
  7651. for (let i = start; i < children.length; i++) {
  7652. unmount(children[i], parentComponent, parentSuspense, doRemove, optimized);
  7653. }
  7654. };
  7655. const getNextHostNode = vnode => {
  7656. if (vnode.shapeFlag & 6 /* ShapeFlags.COMPONENT */) {
  7657. return getNextHostNode(vnode.component.subTree);
  7658. }
  7659. if (vnode.shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
  7660. return vnode.suspense.next();
  7661. }
  7662. return hostNextSibling((vnode.anchor || vnode.el));
  7663. };
  7664. const render = (vnode, container, isSVG) => {
  7665. if (vnode == null) {
  7666. if (container._vnode) {
  7667. unmount(container._vnode, null, null, true);
  7668. }
  7669. }
  7670. else {
  7671. patch(container._vnode || null, vnode, container, null, null, null, isSVG);
  7672. }
  7673. flushPreFlushCbs();
  7674. flushPostFlushCbs();
  7675. container._vnode = vnode;
  7676. };
  7677. const internals = {
  7678. p: patch,
  7679. um: unmount,
  7680. m: move,
  7681. r: remove,
  7682. mt: mountComponent,
  7683. mc: mountChildren,
  7684. pc: patchChildren,
  7685. pbc: patchBlockChildren,
  7686. n: getNextHostNode,
  7687. o: options
  7688. };
  7689. let hydrate;
  7690. let hydrateNode;
  7691. if (createHydrationFns) {
  7692. [hydrate, hydrateNode] = createHydrationFns(internals);
  7693. }
  7694. return {
  7695. render,
  7696. hydrate,
  7697. createApp: createAppAPI(render, hydrate)
  7698. };
  7699. }
  7700. function toggleRecurse({ effect, update }, allowed) {
  7701. effect.allowRecurse = update.allowRecurse = allowed;
  7702. }
  7703. /**
  7704. * #1156
  7705. * When a component is HMR-enabled, we need to make sure that all static nodes
  7706. * inside a block also inherit the DOM element from the previous tree so that
  7707. * HMR updates (which are full updates) can retrieve the element for patching.
  7708. *
  7709. * #2080
  7710. * Inside keyed `template` fragment static children, if a fragment is moved,
  7711. * the children will always be moved. Therefore, in order to ensure correct move
  7712. * position, el should be inherited from previous nodes.
  7713. */
  7714. function traverseStaticChildren(n1, n2, shallow = false) {
  7715. const ch1 = n1.children;
  7716. const ch2 = n2.children;
  7717. if (isArray(ch1) && isArray(ch2)) {
  7718. for (let i = 0; i < ch1.length; i++) {
  7719. // this is only called in the optimized path so array children are
  7720. // guaranteed to be vnodes
  7721. const c1 = ch1[i];
  7722. let c2 = ch2[i];
  7723. if (c2.shapeFlag & 1 /* ShapeFlags.ELEMENT */ && !c2.dynamicChildren) {
  7724. if (c2.patchFlag <= 0 || c2.patchFlag === 32 /* PatchFlags.HYDRATE_EVENTS */) {
  7725. c2 = ch2[i] = cloneIfMounted(ch2[i]);
  7726. c2.el = c1.el;
  7727. }
  7728. if (!shallow)
  7729. traverseStaticChildren(c1, c2);
  7730. }
  7731. // #6852 also inherit for text nodes
  7732. if (c2.type === Text) {
  7733. c2.el = c1.el;
  7734. }
  7735. // also inherit for comment nodes, but not placeholders (e.g. v-if which
  7736. // would have received .el during block patch)
  7737. if (c2.type === Comment && !c2.el) {
  7738. c2.el = c1.el;
  7739. }
  7740. }
  7741. }
  7742. }
  7743. // https://en.wikipedia.org/wiki/Longest_increasing_subsequence
  7744. function getSequence(arr) {
  7745. const p = arr.slice();
  7746. const result = [0];
  7747. let i, j, u, v, c;
  7748. const len = arr.length;
  7749. for (i = 0; i < len; i++) {
  7750. const arrI = arr[i];
  7751. if (arrI !== 0) {
  7752. j = result[result.length - 1];
  7753. if (arr[j] < arrI) {
  7754. p[i] = j;
  7755. result.push(i);
  7756. continue;
  7757. }
  7758. u = 0;
  7759. v = result.length - 1;
  7760. while (u < v) {
  7761. c = (u + v) >> 1;
  7762. if (arr[result[c]] < arrI) {
  7763. u = c + 1;
  7764. }
  7765. else {
  7766. v = c;
  7767. }
  7768. }
  7769. if (arrI < arr[result[u]]) {
  7770. if (u > 0) {
  7771. p[i] = result[u - 1];
  7772. }
  7773. result[u] = i;
  7774. }
  7775. }
  7776. }
  7777. u = result.length;
  7778. v = result[u - 1];
  7779. while (u-- > 0) {
  7780. result[u] = v;
  7781. v = p[v];
  7782. }
  7783. return result;
  7784. }
  7785. const isTeleport = (type) => type.__isTeleport;
  7786. const isTeleportDisabled = (props) => props && (props.disabled || props.disabled === '');
  7787. const isTargetSVG = (target) => typeof SVGElement !== 'undefined' && target instanceof SVGElement;
  7788. const resolveTarget = (props, select) => {
  7789. const targetSelector = props && props.to;
  7790. if (isString(targetSelector)) {
  7791. if (!select) {
  7792. warn(`Current renderer does not support string target for Teleports. ` +
  7793. `(missing querySelector renderer option)`);
  7794. return null;
  7795. }
  7796. else {
  7797. const target = select(targetSelector);
  7798. if (!target) {
  7799. warn(`Failed to locate Teleport target with selector "${targetSelector}". ` +
  7800. `Note the target element must exist before the component is mounted - ` +
  7801. `i.e. the target cannot be rendered by the component itself, and ` +
  7802. `ideally should be outside of the entire Vue component tree.`);
  7803. }
  7804. return target;
  7805. }
  7806. }
  7807. else {
  7808. if (!targetSelector && !isTeleportDisabled(props)) {
  7809. warn(`Invalid Teleport target: ${targetSelector}`);
  7810. }
  7811. return targetSelector;
  7812. }
  7813. };
  7814. const TeleportImpl = {
  7815. __isTeleport: true,
  7816. process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, internals) {
  7817. const { mc: mountChildren, pc: patchChildren, pbc: patchBlockChildren, o: { insert, querySelector, createText, createComment } } = internals;
  7818. const disabled = isTeleportDisabled(n2.props);
  7819. let { shapeFlag, children, dynamicChildren } = n2;
  7820. // #3302
  7821. // HMR updated, force full diff
  7822. if (isHmrUpdating) {
  7823. optimized = false;
  7824. dynamicChildren = null;
  7825. }
  7826. if (n1 == null) {
  7827. // insert anchors in the main view
  7828. const placeholder = (n2.el = createComment('teleport start')
  7829. );
  7830. const mainAnchor = (n2.anchor = createComment('teleport end')
  7831. );
  7832. insert(placeholder, container, anchor);
  7833. insert(mainAnchor, container, anchor);
  7834. const target = (n2.target = resolveTarget(n2.props, querySelector));
  7835. const targetAnchor = (n2.targetAnchor = createText(''));
  7836. if (target) {
  7837. insert(targetAnchor, target);
  7838. // #2652 we could be teleporting from a non-SVG tree into an SVG tree
  7839. isSVG = isSVG || isTargetSVG(target);
  7840. }
  7841. else if (!disabled) {
  7842. warn('Invalid Teleport target on mount:', target, `(${typeof target})`);
  7843. }
  7844. const mount = (container, anchor) => {
  7845. // Teleport *always* has Array children. This is enforced in both the
  7846. // compiler and vnode children normalization.
  7847. if (shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  7848. mountChildren(children, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7849. }
  7850. };
  7851. if (disabled) {
  7852. mount(container, mainAnchor);
  7853. }
  7854. else if (target) {
  7855. mount(target, targetAnchor);
  7856. }
  7857. }
  7858. else {
  7859. // update content
  7860. n2.el = n1.el;
  7861. const mainAnchor = (n2.anchor = n1.anchor);
  7862. const target = (n2.target = n1.target);
  7863. const targetAnchor = (n2.targetAnchor = n1.targetAnchor);
  7864. const wasDisabled = isTeleportDisabled(n1.props);
  7865. const currentContainer = wasDisabled ? container : target;
  7866. const currentAnchor = wasDisabled ? mainAnchor : targetAnchor;
  7867. isSVG = isSVG || isTargetSVG(target);
  7868. if (dynamicChildren) {
  7869. // fast path when the teleport happens to be a block root
  7870. patchBlockChildren(n1.dynamicChildren, dynamicChildren, currentContainer, parentComponent, parentSuspense, isSVG, slotScopeIds);
  7871. // even in block tree mode we need to make sure all root-level nodes
  7872. // in the teleport inherit previous DOM references so that they can
  7873. // be moved in future patches.
  7874. traverseStaticChildren(n1, n2, true);
  7875. }
  7876. else if (!optimized) {
  7877. patchChildren(n1, n2, currentContainer, currentAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, false);
  7878. }
  7879. if (disabled) {
  7880. if (!wasDisabled) {
  7881. // enabled -> disabled
  7882. // move into main container
  7883. moveTeleport(n2, container, mainAnchor, internals, 1 /* TeleportMoveTypes.TOGGLE */);
  7884. }
  7885. }
  7886. else {
  7887. // target changed
  7888. if ((n2.props && n2.props.to) !== (n1.props && n1.props.to)) {
  7889. const nextTarget = (n2.target = resolveTarget(n2.props, querySelector));
  7890. if (nextTarget) {
  7891. moveTeleport(n2, nextTarget, null, internals, 0 /* TeleportMoveTypes.TARGET_CHANGE */);
  7892. }
  7893. else {
  7894. warn('Invalid Teleport target on update:', target, `(${typeof target})`);
  7895. }
  7896. }
  7897. else if (wasDisabled) {
  7898. // disabled -> enabled
  7899. // move into teleport target
  7900. moveTeleport(n2, target, targetAnchor, internals, 1 /* TeleportMoveTypes.TOGGLE */);
  7901. }
  7902. }
  7903. }
  7904. updateCssVars(n2);
  7905. },
  7906. remove(vnode, parentComponent, parentSuspense, optimized, { um: unmount, o: { remove: hostRemove } }, doRemove) {
  7907. const { shapeFlag, children, anchor, targetAnchor, target, props } = vnode;
  7908. if (target) {
  7909. hostRemove(targetAnchor);
  7910. }
  7911. // an unmounted teleport should always remove its children if not disabled
  7912. if (doRemove || !isTeleportDisabled(props)) {
  7913. hostRemove(anchor);
  7914. if (shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  7915. for (let i = 0; i < children.length; i++) {
  7916. const child = children[i];
  7917. unmount(child, parentComponent, parentSuspense, true, !!child.dynamicChildren);
  7918. }
  7919. }
  7920. }
  7921. },
  7922. move: moveTeleport,
  7923. hydrate: hydrateTeleport
  7924. };
  7925. function moveTeleport(vnode, container, parentAnchor, { o: { insert }, m: move }, moveType = 2 /* TeleportMoveTypes.REORDER */) {
  7926. // move target anchor if this is a target change.
  7927. if (moveType === 0 /* TeleportMoveTypes.TARGET_CHANGE */) {
  7928. insert(vnode.targetAnchor, container, parentAnchor);
  7929. }
  7930. const { el, anchor, shapeFlag, children, props } = vnode;
  7931. const isReorder = moveType === 2 /* TeleportMoveTypes.REORDER */;
  7932. // move main view anchor if this is a re-order.
  7933. if (isReorder) {
  7934. insert(el, container, parentAnchor);
  7935. }
  7936. // if this is a re-order and teleport is enabled (content is in target)
  7937. // do not move children. So the opposite is: only move children if this
  7938. // is not a reorder, or the teleport is disabled
  7939. if (!isReorder || isTeleportDisabled(props)) {
  7940. // Teleport has either Array children or no children.
  7941. if (shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  7942. for (let i = 0; i < children.length; i++) {
  7943. move(children[i], container, parentAnchor, 2 /* MoveType.REORDER */);
  7944. }
  7945. }
  7946. }
  7947. // move main view anchor if this is a re-order.
  7948. if (isReorder) {
  7949. insert(anchor, container, parentAnchor);
  7950. }
  7951. }
  7952. function hydrateTeleport(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized, { o: { nextSibling, parentNode, querySelector } }, hydrateChildren) {
  7953. const target = (vnode.target = resolveTarget(vnode.props, querySelector));
  7954. if (target) {
  7955. // if multiple teleports rendered to the same target element, we need to
  7956. // pick up from where the last teleport finished instead of the first node
  7957. const targetNode = target._lpa || target.firstChild;
  7958. if (vnode.shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  7959. if (isTeleportDisabled(vnode.props)) {
  7960. vnode.anchor = hydrateChildren(nextSibling(node), vnode, parentNode(node), parentComponent, parentSuspense, slotScopeIds, optimized);
  7961. vnode.targetAnchor = targetNode;
  7962. }
  7963. else {
  7964. vnode.anchor = nextSibling(node);
  7965. // lookahead until we find the target anchor
  7966. // we cannot rely on return value of hydrateChildren() because there
  7967. // could be nested teleports
  7968. let targetAnchor = targetNode;
  7969. while (targetAnchor) {
  7970. targetAnchor = nextSibling(targetAnchor);
  7971. if (targetAnchor &&
  7972. targetAnchor.nodeType === 8 &&
  7973. targetAnchor.data === 'teleport anchor') {
  7974. vnode.targetAnchor = targetAnchor;
  7975. target._lpa =
  7976. vnode.targetAnchor && nextSibling(vnode.targetAnchor);
  7977. break;
  7978. }
  7979. }
  7980. hydrateChildren(targetNode, vnode, target, parentComponent, parentSuspense, slotScopeIds, optimized);
  7981. }
  7982. }
  7983. updateCssVars(vnode);
  7984. }
  7985. return vnode.anchor && nextSibling(vnode.anchor);
  7986. }
  7987. // Force-casted public typing for h and TSX props inference
  7988. const Teleport = TeleportImpl;
  7989. function updateCssVars(vnode) {
  7990. // presence of .ut method indicates owner component uses css vars.
  7991. // code path here can assume browser environment.
  7992. const ctx = vnode.ctx;
  7993. if (ctx && ctx.ut) {
  7994. let node = vnode.children[0].el;
  7995. while (node !== vnode.targetAnchor) {
  7996. if (node.nodeType === 1)
  7997. node.setAttribute('data-v-owner', ctx.uid);
  7998. node = node.nextSibling;
  7999. }
  8000. ctx.ut();
  8001. }
  8002. }
  8003. const Fragment = Symbol('Fragment' );
  8004. const Text = Symbol('Text' );
  8005. const Comment = Symbol('Comment' );
  8006. const Static = Symbol('Static' );
  8007. // Since v-if and v-for are the two possible ways node structure can dynamically
  8008. // change, once we consider v-if branches and each v-for fragment a block, we
  8009. // can divide a template into nested blocks, and within each block the node
  8010. // structure would be stable. This allows us to skip most children diffing
  8011. // and only worry about the dynamic nodes (indicated by patch flags).
  8012. const blockStack = [];
  8013. let currentBlock = null;
  8014. /**
  8015. * Open a block.
  8016. * This must be called before `createBlock`. It cannot be part of `createBlock`
  8017. * because the children of the block are evaluated before `createBlock` itself
  8018. * is called. The generated code typically looks like this:
  8019. *
  8020. * ```js
  8021. * function render() {
  8022. * return (openBlock(),createBlock('div', null, [...]))
  8023. * }
  8024. * ```
  8025. * disableTracking is true when creating a v-for fragment block, since a v-for
  8026. * fragment always diffs its children.
  8027. *
  8028. * @private
  8029. */
  8030. function openBlock(disableTracking = false) {
  8031. blockStack.push((currentBlock = disableTracking ? null : []));
  8032. }
  8033. function closeBlock() {
  8034. blockStack.pop();
  8035. currentBlock = blockStack[blockStack.length - 1] || null;
  8036. }
  8037. // Whether we should be tracking dynamic child nodes inside a block.
  8038. // Only tracks when this value is > 0
  8039. // We are not using a simple boolean because this value may need to be
  8040. // incremented/decremented by nested usage of v-once (see below)
  8041. let isBlockTreeEnabled = 1;
  8042. /**
  8043. * Block tracking sometimes needs to be disabled, for example during the
  8044. * creation of a tree that needs to be cached by v-once. The compiler generates
  8045. * code like this:
  8046. *
  8047. * ``` js
  8048. * _cache[1] || (
  8049. * setBlockTracking(-1),
  8050. * _cache[1] = createVNode(...),
  8051. * setBlockTracking(1),
  8052. * _cache[1]
  8053. * )
  8054. * ```
  8055. *
  8056. * @private
  8057. */
  8058. function setBlockTracking(value) {
  8059. isBlockTreeEnabled += value;
  8060. }
  8061. function setupBlock(vnode) {
  8062. // save current block children on the block vnode
  8063. vnode.dynamicChildren =
  8064. isBlockTreeEnabled > 0 ? currentBlock || EMPTY_ARR : null;
  8065. // close block
  8066. closeBlock();
  8067. // a block is always going to be patched, so track it as a child of its
  8068. // parent block
  8069. if (isBlockTreeEnabled > 0 && currentBlock) {
  8070. currentBlock.push(vnode);
  8071. }
  8072. return vnode;
  8073. }
  8074. /**
  8075. * @private
  8076. */
  8077. function createElementBlock(type, props, children, patchFlag, dynamicProps, shapeFlag) {
  8078. return setupBlock(createBaseVNode(type, props, children, patchFlag, dynamicProps, shapeFlag, true /* isBlock */));
  8079. }
  8080. /**
  8081. * Create a block root vnode. Takes the same exact arguments as `createVNode`.
  8082. * A block root keeps track of dynamic nodes within the block in the
  8083. * `dynamicChildren` array.
  8084. *
  8085. * @private
  8086. */
  8087. function createBlock(type, props, children, patchFlag, dynamicProps) {
  8088. return setupBlock(createVNode(type, props, children, patchFlag, dynamicProps, true /* isBlock: prevent a block from tracking itself */));
  8089. }
  8090. function isVNode(value) {
  8091. return value ? value.__v_isVNode === true : false;
  8092. }
  8093. function isSameVNodeType(n1, n2) {
  8094. if (n2.shapeFlag & 6 /* ShapeFlags.COMPONENT */ &&
  8095. hmrDirtyComponents.has(n2.type)) {
  8096. // #7042, ensure the vnode being unmounted during HMR
  8097. // bitwise operations to remove keep alive flags
  8098. n1.shapeFlag &= ~256 /* ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE */;
  8099. n2.shapeFlag &= ~512 /* ShapeFlags.COMPONENT_KEPT_ALIVE */;
  8100. // HMR only: if the component has been hot-updated, force a reload.
  8101. return false;
  8102. }
  8103. return n1.type === n2.type && n1.key === n2.key;
  8104. }
  8105. let vnodeArgsTransformer;
  8106. /**
  8107. * Internal API for registering an arguments transform for createVNode
  8108. * used for creating stubs in the test-utils
  8109. * It is *internal* but needs to be exposed for test-utils to pick up proper
  8110. * typings
  8111. */
  8112. function transformVNodeArgs(transformer) {
  8113. vnodeArgsTransformer = transformer;
  8114. }
  8115. const createVNodeWithArgsTransform = (...args) => {
  8116. return _createVNode(...(vnodeArgsTransformer
  8117. ? vnodeArgsTransformer(args, currentRenderingInstance)
  8118. : args));
  8119. };
  8120. const InternalObjectKey = `__vInternal`;
  8121. const normalizeKey = ({ key }) => key != null ? key : null;
  8122. const normalizeRef = ({ ref, ref_key, ref_for }) => {
  8123. return (ref != null
  8124. ? isString(ref) || isRef(ref) || isFunction(ref)
  8125. ? { i: currentRenderingInstance, r: ref, k: ref_key, f: !!ref_for }
  8126. : ref
  8127. : null);
  8128. };
  8129. function createBaseVNode(type, props = null, children = null, patchFlag = 0, dynamicProps = null, shapeFlag = type === Fragment ? 0 : 1 /* ShapeFlags.ELEMENT */, isBlockNode = false, needFullChildrenNormalization = false) {
  8130. const vnode = {
  8131. __v_isVNode: true,
  8132. __v_skip: true,
  8133. type,
  8134. props,
  8135. key: props && normalizeKey(props),
  8136. ref: props && normalizeRef(props),
  8137. scopeId: currentScopeId,
  8138. slotScopeIds: null,
  8139. children,
  8140. component: null,
  8141. suspense: null,
  8142. ssContent: null,
  8143. ssFallback: null,
  8144. dirs: null,
  8145. transition: null,
  8146. el: null,
  8147. anchor: null,
  8148. target: null,
  8149. targetAnchor: null,
  8150. staticCount: 0,
  8151. shapeFlag,
  8152. patchFlag,
  8153. dynamicProps,
  8154. dynamicChildren: null,
  8155. appContext: null,
  8156. ctx: currentRenderingInstance
  8157. };
  8158. if (needFullChildrenNormalization) {
  8159. normalizeChildren(vnode, children);
  8160. // normalize suspense children
  8161. if (shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
  8162. type.normalize(vnode);
  8163. }
  8164. }
  8165. else if (children) {
  8166. // compiled element vnode - if children is passed, only possible types are
  8167. // string or Array.
  8168. vnode.shapeFlag |= isString(children)
  8169. ? 8 /* ShapeFlags.TEXT_CHILDREN */
  8170. : 16 /* ShapeFlags.ARRAY_CHILDREN */;
  8171. }
  8172. // validate key
  8173. if (vnode.key !== vnode.key) {
  8174. warn(`VNode created with invalid key (NaN). VNode type:`, vnode.type);
  8175. }
  8176. // track vnode for block tree
  8177. if (isBlockTreeEnabled > 0 &&
  8178. // avoid a block node from tracking itself
  8179. !isBlockNode &&
  8180. // has current parent block
  8181. currentBlock &&
  8182. // presence of a patch flag indicates this node needs patching on updates.
  8183. // component nodes also should always be patched, because even if the
  8184. // component doesn't need to update, it needs to persist the instance on to
  8185. // the next vnode so that it can be properly unmounted later.
  8186. (vnode.patchFlag > 0 || shapeFlag & 6 /* ShapeFlags.COMPONENT */) &&
  8187. // the EVENTS flag is only for hydration and if it is the only flag, the
  8188. // vnode should not be considered dynamic due to handler caching.
  8189. vnode.patchFlag !== 32 /* PatchFlags.HYDRATE_EVENTS */) {
  8190. currentBlock.push(vnode);
  8191. }
  8192. return vnode;
  8193. }
  8194. const createVNode = (createVNodeWithArgsTransform );
  8195. function _createVNode(type, props = null, children = null, patchFlag = 0, dynamicProps = null, isBlockNode = false) {
  8196. if (!type || type === NULL_DYNAMIC_COMPONENT) {
  8197. if (!type) {
  8198. warn(`Invalid vnode type when creating vnode: ${type}.`);
  8199. }
  8200. type = Comment;
  8201. }
  8202. if (isVNode(type)) {
  8203. // createVNode receiving an existing vnode. This happens in cases like
  8204. // <component :is="vnode"/>
  8205. // #2078 make sure to merge refs during the clone instead of overwriting it
  8206. const cloned = cloneVNode(type, props, true /* mergeRef: true */);
  8207. if (children) {
  8208. normalizeChildren(cloned, children);
  8209. }
  8210. if (isBlockTreeEnabled > 0 && !isBlockNode && currentBlock) {
  8211. if (cloned.shapeFlag & 6 /* ShapeFlags.COMPONENT */) {
  8212. currentBlock[currentBlock.indexOf(type)] = cloned;
  8213. }
  8214. else {
  8215. currentBlock.push(cloned);
  8216. }
  8217. }
  8218. cloned.patchFlag |= -2 /* PatchFlags.BAIL */;
  8219. return cloned;
  8220. }
  8221. // class component normalization.
  8222. if (isClassComponent(type)) {
  8223. type = type.__vccOpts;
  8224. }
  8225. // class & style normalization.
  8226. if (props) {
  8227. // for reactive or proxy objects, we need to clone it to enable mutation.
  8228. props = guardReactiveProps(props);
  8229. let { class: klass, style } = props;
  8230. if (klass && !isString(klass)) {
  8231. props.class = normalizeClass(klass);
  8232. }
  8233. if (isObject(style)) {
  8234. // reactive state objects need to be cloned since they are likely to be
  8235. // mutated
  8236. if (isProxy(style) && !isArray(style)) {
  8237. style = extend({}, style);
  8238. }
  8239. props.style = normalizeStyle(style);
  8240. }
  8241. }
  8242. // encode the vnode type information into a bitmap
  8243. const shapeFlag = isString(type)
  8244. ? 1 /* ShapeFlags.ELEMENT */
  8245. : isSuspense(type)
  8246. ? 128 /* ShapeFlags.SUSPENSE */
  8247. : isTeleport(type)
  8248. ? 64 /* ShapeFlags.TELEPORT */
  8249. : isObject(type)
  8250. ? 4 /* ShapeFlags.STATEFUL_COMPONENT */
  8251. : isFunction(type)
  8252. ? 2 /* ShapeFlags.FUNCTIONAL_COMPONENT */
  8253. : 0;
  8254. if (shapeFlag & 4 /* ShapeFlags.STATEFUL_COMPONENT */ && isProxy(type)) {
  8255. type = toRaw(type);
  8256. warn(`Vue received a Component which was made a reactive object. This can ` +
  8257. `lead to unnecessary performance overhead, and should be avoided by ` +
  8258. `marking the component with \`markRaw\` or using \`shallowRef\` ` +
  8259. `instead of \`ref\`.`, `\nComponent that was made reactive: `, type);
  8260. }
  8261. return createBaseVNode(type, props, children, patchFlag, dynamicProps, shapeFlag, isBlockNode, true);
  8262. }
  8263. function guardReactiveProps(props) {
  8264. if (!props)
  8265. return null;
  8266. return isProxy(props) || InternalObjectKey in props
  8267. ? extend({}, props)
  8268. : props;
  8269. }
  8270. function cloneVNode(vnode, extraProps, mergeRef = false) {
  8271. // This is intentionally NOT using spread or extend to avoid the runtime
  8272. // key enumeration cost.
  8273. const { props, ref, patchFlag, children } = vnode;
  8274. const mergedProps = extraProps ? mergeProps(props || {}, extraProps) : props;
  8275. const cloned = {
  8276. __v_isVNode: true,
  8277. __v_skip: true,
  8278. type: vnode.type,
  8279. props: mergedProps,
  8280. key: mergedProps && normalizeKey(mergedProps),
  8281. ref: extraProps && extraProps.ref
  8282. ? // #2078 in the case of <component :is="vnode" ref="extra"/>
  8283. // if the vnode itself already has a ref, cloneVNode will need to merge
  8284. // the refs so the single vnode can be set on multiple refs
  8285. mergeRef && ref
  8286. ? isArray(ref)
  8287. ? ref.concat(normalizeRef(extraProps))
  8288. : [ref, normalizeRef(extraProps)]
  8289. : normalizeRef(extraProps)
  8290. : ref,
  8291. scopeId: vnode.scopeId,
  8292. slotScopeIds: vnode.slotScopeIds,
  8293. children: patchFlag === -1 /* PatchFlags.HOISTED */ && isArray(children)
  8294. ? children.map(deepCloneVNode)
  8295. : children,
  8296. target: vnode.target,
  8297. targetAnchor: vnode.targetAnchor,
  8298. staticCount: vnode.staticCount,
  8299. shapeFlag: vnode.shapeFlag,
  8300. // if the vnode is cloned with extra props, we can no longer assume its
  8301. // existing patch flag to be reliable and need to add the FULL_PROPS flag.
  8302. // note: preserve flag for fragments since they use the flag for children
  8303. // fast paths only.
  8304. patchFlag: extraProps && vnode.type !== Fragment
  8305. ? patchFlag === -1 // hoisted node
  8306. ? 16 /* PatchFlags.FULL_PROPS */
  8307. : patchFlag | 16 /* PatchFlags.FULL_PROPS */
  8308. : patchFlag,
  8309. dynamicProps: vnode.dynamicProps,
  8310. dynamicChildren: vnode.dynamicChildren,
  8311. appContext: vnode.appContext,
  8312. dirs: vnode.dirs,
  8313. transition: vnode.transition,
  8314. // These should technically only be non-null on mounted VNodes. However,
  8315. // they *should* be copied for kept-alive vnodes. So we just always copy
  8316. // them since them being non-null during a mount doesn't affect the logic as
  8317. // they will simply be overwritten.
  8318. component: vnode.component,
  8319. suspense: vnode.suspense,
  8320. ssContent: vnode.ssContent && cloneVNode(vnode.ssContent),
  8321. ssFallback: vnode.ssFallback && cloneVNode(vnode.ssFallback),
  8322. el: vnode.el,
  8323. anchor: vnode.anchor,
  8324. ctx: vnode.ctx,
  8325. ce: vnode.ce
  8326. };
  8327. return cloned;
  8328. }
  8329. /**
  8330. * Dev only, for HMR of hoisted vnodes reused in v-for
  8331. * https://github.com/vitejs/vite/issues/2022
  8332. */
  8333. function deepCloneVNode(vnode) {
  8334. const cloned = cloneVNode(vnode);
  8335. if (isArray(vnode.children)) {
  8336. cloned.children = vnode.children.map(deepCloneVNode);
  8337. }
  8338. return cloned;
  8339. }
  8340. /**
  8341. * @private
  8342. */
  8343. function createTextVNode(text = ' ', flag = 0) {
  8344. return createVNode(Text, null, text, flag);
  8345. }
  8346. /**
  8347. * @private
  8348. */
  8349. function createStaticVNode(content, numberOfNodes) {
  8350. // A static vnode can contain multiple stringified elements, and the number
  8351. // of elements is necessary for hydration.
  8352. const vnode = createVNode(Static, null, content);
  8353. vnode.staticCount = numberOfNodes;
  8354. return vnode;
  8355. }
  8356. /**
  8357. * @private
  8358. */
  8359. function createCommentVNode(text = '',
  8360. // when used as the v-else branch, the comment node must be created as a
  8361. // block to ensure correct updates.
  8362. asBlock = false) {
  8363. return asBlock
  8364. ? (openBlock(), createBlock(Comment, null, text))
  8365. : createVNode(Comment, null, text);
  8366. }
  8367. function normalizeVNode(child) {
  8368. if (child == null || typeof child === 'boolean') {
  8369. // empty placeholder
  8370. return createVNode(Comment);
  8371. }
  8372. else if (isArray(child)) {
  8373. // fragment
  8374. return createVNode(Fragment, null,
  8375. // #3666, avoid reference pollution when reusing vnode
  8376. child.slice());
  8377. }
  8378. else if (typeof child === 'object') {
  8379. // already vnode, this should be the most common since compiled templates
  8380. // always produce all-vnode children arrays
  8381. return cloneIfMounted(child);
  8382. }
  8383. else {
  8384. // strings and numbers
  8385. return createVNode(Text, null, String(child));
  8386. }
  8387. }
  8388. // optimized normalization for template-compiled render fns
  8389. function cloneIfMounted(child) {
  8390. return (child.el === null && child.patchFlag !== -1 /* PatchFlags.HOISTED */) ||
  8391. child.memo
  8392. ? child
  8393. : cloneVNode(child);
  8394. }
  8395. function normalizeChildren(vnode, children) {
  8396. let type = 0;
  8397. const { shapeFlag } = vnode;
  8398. if (children == null) {
  8399. children = null;
  8400. }
  8401. else if (isArray(children)) {
  8402. type = 16 /* ShapeFlags.ARRAY_CHILDREN */;
  8403. }
  8404. else if (typeof children === 'object') {
  8405. if (shapeFlag & (1 /* ShapeFlags.ELEMENT */ | 64 /* ShapeFlags.TELEPORT */)) {
  8406. // Normalize slot to plain children for plain element and Teleport
  8407. const slot = children.default;
  8408. if (slot) {
  8409. // _c marker is added by withCtx() indicating this is a compiled slot
  8410. slot._c && (slot._d = false);
  8411. normalizeChildren(vnode, slot());
  8412. slot._c && (slot._d = true);
  8413. }
  8414. return;
  8415. }
  8416. else {
  8417. type = 32 /* ShapeFlags.SLOTS_CHILDREN */;
  8418. const slotFlag = children._;
  8419. if (!slotFlag && !(InternalObjectKey in children)) {
  8420. children._ctx = currentRenderingInstance;
  8421. }
  8422. else if (slotFlag === 3 /* SlotFlags.FORWARDED */ && currentRenderingInstance) {
  8423. // a child component receives forwarded slots from the parent.
  8424. // its slot type is determined by its parent's slot type.
  8425. if (currentRenderingInstance.slots._ === 1 /* SlotFlags.STABLE */) {
  8426. children._ = 1 /* SlotFlags.STABLE */;
  8427. }
  8428. else {
  8429. children._ = 2 /* SlotFlags.DYNAMIC */;
  8430. vnode.patchFlag |= 1024 /* PatchFlags.DYNAMIC_SLOTS */;
  8431. }
  8432. }
  8433. }
  8434. }
  8435. else if (isFunction(children)) {
  8436. children = { default: children, _ctx: currentRenderingInstance };
  8437. type = 32 /* ShapeFlags.SLOTS_CHILDREN */;
  8438. }
  8439. else {
  8440. children = String(children);
  8441. // force teleport children to array so it can be moved around
  8442. if (shapeFlag & 64 /* ShapeFlags.TELEPORT */) {
  8443. type = 16 /* ShapeFlags.ARRAY_CHILDREN */;
  8444. children = [createTextVNode(children)];
  8445. }
  8446. else {
  8447. type = 8 /* ShapeFlags.TEXT_CHILDREN */;
  8448. }
  8449. }
  8450. vnode.children = children;
  8451. vnode.shapeFlag |= type;
  8452. }
  8453. function mergeProps(...args) {
  8454. const ret = {};
  8455. for (let i = 0; i < args.length; i++) {
  8456. const toMerge = args[i];
  8457. for (const key in toMerge) {
  8458. if (key === 'class') {
  8459. if (ret.class !== toMerge.class) {
  8460. ret.class = normalizeClass([ret.class, toMerge.class]);
  8461. }
  8462. }
  8463. else if (key === 'style') {
  8464. ret.style = normalizeStyle([ret.style, toMerge.style]);
  8465. }
  8466. else if (isOn(key)) {
  8467. const existing = ret[key];
  8468. const incoming = toMerge[key];
  8469. if (incoming &&
  8470. existing !== incoming &&
  8471. !(isArray(existing) && existing.includes(incoming))) {
  8472. ret[key] = existing
  8473. ? [].concat(existing, incoming)
  8474. : incoming;
  8475. }
  8476. }
  8477. else if (key !== '') {
  8478. ret[key] = toMerge[key];
  8479. }
  8480. }
  8481. }
  8482. return ret;
  8483. }
  8484. function invokeVNodeHook(hook, instance, vnode, prevVNode = null) {
  8485. callWithAsyncErrorHandling(hook, instance, 7 /* ErrorCodes.VNODE_HOOK */, [
  8486. vnode,
  8487. prevVNode
  8488. ]);
  8489. }
  8490. const emptyAppContext = createAppContext();
  8491. let uid = 0;
  8492. function createComponentInstance(vnode, parent, suspense) {
  8493. const type = vnode.type;
  8494. // inherit parent app context - or - if root, adopt from root vnode
  8495. const appContext = (parent ? parent.appContext : vnode.appContext) || emptyAppContext;
  8496. const instance = {
  8497. uid: uid++,
  8498. vnode,
  8499. type,
  8500. parent,
  8501. appContext,
  8502. root: null,
  8503. next: null,
  8504. subTree: null,
  8505. effect: null,
  8506. update: null,
  8507. scope: new EffectScope(true /* detached */),
  8508. render: null,
  8509. proxy: null,
  8510. exposed: null,
  8511. exposeProxy: null,
  8512. withProxy: null,
  8513. provides: parent ? parent.provides : Object.create(appContext.provides),
  8514. accessCache: null,
  8515. renderCache: [],
  8516. // local resolved assets
  8517. components: null,
  8518. directives: null,
  8519. // resolved props and emits options
  8520. propsOptions: normalizePropsOptions(type, appContext),
  8521. emitsOptions: normalizeEmitsOptions(type, appContext),
  8522. // emit
  8523. emit: null,
  8524. emitted: null,
  8525. // props default value
  8526. propsDefaults: EMPTY_OBJ,
  8527. // inheritAttrs
  8528. inheritAttrs: type.inheritAttrs,
  8529. // state
  8530. ctx: EMPTY_OBJ,
  8531. data: EMPTY_OBJ,
  8532. props: EMPTY_OBJ,
  8533. attrs: EMPTY_OBJ,
  8534. slots: EMPTY_OBJ,
  8535. refs: EMPTY_OBJ,
  8536. setupState: EMPTY_OBJ,
  8537. setupContext: null,
  8538. // suspense related
  8539. suspense,
  8540. suspenseId: suspense ? suspense.pendingId : 0,
  8541. asyncDep: null,
  8542. asyncResolved: false,
  8543. // lifecycle hooks
  8544. // not using enums here because it results in computed properties
  8545. isMounted: false,
  8546. isUnmounted: false,
  8547. isDeactivated: false,
  8548. bc: null,
  8549. c: null,
  8550. bm: null,
  8551. m: null,
  8552. bu: null,
  8553. u: null,
  8554. um: null,
  8555. bum: null,
  8556. da: null,
  8557. a: null,
  8558. rtg: null,
  8559. rtc: null,
  8560. ec: null,
  8561. sp: null
  8562. };
  8563. {
  8564. instance.ctx = createDevRenderContext(instance);
  8565. }
  8566. instance.root = parent ? parent.root : instance;
  8567. instance.emit = emit.bind(null, instance);
  8568. // apply custom element special handling
  8569. if (vnode.ce) {
  8570. vnode.ce(instance);
  8571. }
  8572. return instance;
  8573. }
  8574. let currentInstance = null;
  8575. const getCurrentInstance = () => currentInstance || currentRenderingInstance;
  8576. const setCurrentInstance = (instance) => {
  8577. currentInstance = instance;
  8578. instance.scope.on();
  8579. };
  8580. const unsetCurrentInstance = () => {
  8581. currentInstance && currentInstance.scope.off();
  8582. currentInstance = null;
  8583. };
  8584. const isBuiltInTag = /*#__PURE__*/ makeMap('slot,component');
  8585. function validateComponentName(name, config) {
  8586. const appIsNativeTag = config.isNativeTag || NO;
  8587. if (isBuiltInTag(name) || appIsNativeTag(name)) {
  8588. warn('Do not use built-in or reserved HTML elements as component id: ' + name);
  8589. }
  8590. }
  8591. function isStatefulComponent(instance) {
  8592. return instance.vnode.shapeFlag & 4 /* ShapeFlags.STATEFUL_COMPONENT */;
  8593. }
  8594. let isInSSRComponentSetup = false;
  8595. function setupComponent(instance, isSSR = false) {
  8596. isInSSRComponentSetup = isSSR;
  8597. const { props, children } = instance.vnode;
  8598. const isStateful = isStatefulComponent(instance);
  8599. initProps(instance, props, isStateful, isSSR);
  8600. initSlots(instance, children);
  8601. const setupResult = isStateful
  8602. ? setupStatefulComponent(instance, isSSR)
  8603. : undefined;
  8604. isInSSRComponentSetup = false;
  8605. return setupResult;
  8606. }
  8607. function setupStatefulComponent(instance, isSSR) {
  8608. var _a;
  8609. const Component = instance.type;
  8610. {
  8611. if (Component.name) {
  8612. validateComponentName(Component.name, instance.appContext.config);
  8613. }
  8614. if (Component.components) {
  8615. const names = Object.keys(Component.components);
  8616. for (let i = 0; i < names.length; i++) {
  8617. validateComponentName(names[i], instance.appContext.config);
  8618. }
  8619. }
  8620. if (Component.directives) {
  8621. const names = Object.keys(Component.directives);
  8622. for (let i = 0; i < names.length; i++) {
  8623. validateDirectiveName(names[i]);
  8624. }
  8625. }
  8626. if (Component.compilerOptions && isRuntimeOnly()) {
  8627. warn(`"compilerOptions" is only supported when using a build of Vue that ` +
  8628. `includes the runtime compiler. Since you are using a runtime-only ` +
  8629. `build, the options should be passed via your build tool config instead.`);
  8630. }
  8631. }
  8632. // 0. create render proxy property access cache
  8633. instance.accessCache = Object.create(null);
  8634. // 1. create public instance / render proxy
  8635. // also mark it raw so it's never observed
  8636. instance.proxy = markRaw(new Proxy(instance.ctx, PublicInstanceProxyHandlers));
  8637. {
  8638. exposePropsOnRenderContext(instance);
  8639. }
  8640. // 2. call setup()
  8641. const { setup } = Component;
  8642. if (setup) {
  8643. const setupContext = (instance.setupContext =
  8644. setup.length > 1 ? createSetupContext(instance) : null);
  8645. setCurrentInstance(instance);
  8646. pauseTracking();
  8647. const setupResult = callWithErrorHandling(setup, instance, 0 /* ErrorCodes.SETUP_FUNCTION */, [shallowReadonly(instance.props) , setupContext]);
  8648. resetTracking();
  8649. unsetCurrentInstance();
  8650. if (isPromise(setupResult)) {
  8651. setupResult.then(unsetCurrentInstance, unsetCurrentInstance);
  8652. if (isSSR) {
  8653. // return the promise so server-renderer can wait on it
  8654. return setupResult
  8655. .then((resolvedResult) => {
  8656. handleSetupResult(instance, resolvedResult, isSSR);
  8657. })
  8658. .catch(e => {
  8659. handleError(e, instance, 0 /* ErrorCodes.SETUP_FUNCTION */);
  8660. });
  8661. }
  8662. else {
  8663. // async setup returned Promise.
  8664. // bail here and wait for re-entry.
  8665. instance.asyncDep = setupResult;
  8666. if (!instance.suspense) {
  8667. const name = (_a = Component.name) !== null && _a !== void 0 ? _a : 'Anonymous';
  8668. warn(`Component <${name}>: setup function returned a promise, but no ` +
  8669. `<Suspense> boundary was found in the parent component tree. ` +
  8670. `A component with async setup() must be nested in a <Suspense> ` +
  8671. `in order to be rendered.`);
  8672. }
  8673. }
  8674. }
  8675. else {
  8676. handleSetupResult(instance, setupResult, isSSR);
  8677. }
  8678. }
  8679. else {
  8680. finishComponentSetup(instance, isSSR);
  8681. }
  8682. }
  8683. function handleSetupResult(instance, setupResult, isSSR) {
  8684. if (isFunction(setupResult)) {
  8685. // setup returned an inline render function
  8686. {
  8687. instance.render = setupResult;
  8688. }
  8689. }
  8690. else if (isObject(setupResult)) {
  8691. if (isVNode(setupResult)) {
  8692. warn(`setup() should not return VNodes directly - ` +
  8693. `return a render function instead.`);
  8694. }
  8695. // setup returned bindings.
  8696. // assuming a render function compiled from template is present.
  8697. {
  8698. instance.devtoolsRawSetupState = setupResult;
  8699. }
  8700. instance.setupState = proxyRefs(setupResult);
  8701. {
  8702. exposeSetupStateOnRenderContext(instance);
  8703. }
  8704. }
  8705. else if (setupResult !== undefined) {
  8706. warn(`setup() should return an object. Received: ${setupResult === null ? 'null' : typeof setupResult}`);
  8707. }
  8708. finishComponentSetup(instance, isSSR);
  8709. }
  8710. let compile;
  8711. let installWithProxy;
  8712. /**
  8713. * For runtime-dom to register the compiler.
  8714. * Note the exported method uses any to avoid d.ts relying on the compiler types.
  8715. */
  8716. function registerRuntimeCompiler(_compile) {
  8717. compile = _compile;
  8718. installWithProxy = i => {
  8719. if (i.render._rc) {
  8720. i.withProxy = new Proxy(i.ctx, RuntimeCompiledPublicInstanceProxyHandlers);
  8721. }
  8722. };
  8723. }
  8724. // dev only
  8725. const isRuntimeOnly = () => !compile;
  8726. function finishComponentSetup(instance, isSSR, skipOptions) {
  8727. const Component = instance.type;
  8728. // template / render function normalization
  8729. // could be already set when returned from setup()
  8730. if (!instance.render) {
  8731. // only do on-the-fly compile if not in SSR - SSR on-the-fly compilation
  8732. // is done by server-renderer
  8733. if (!isSSR && compile && !Component.render) {
  8734. const template = Component.template ||
  8735. resolveMergedOptions(instance).template;
  8736. if (template) {
  8737. {
  8738. startMeasure(instance, `compile`);
  8739. }
  8740. const { isCustomElement, compilerOptions } = instance.appContext.config;
  8741. const { delimiters, compilerOptions: componentCompilerOptions } = Component;
  8742. const finalCompilerOptions = extend(extend({
  8743. isCustomElement,
  8744. delimiters
  8745. }, compilerOptions), componentCompilerOptions);
  8746. Component.render = compile(template, finalCompilerOptions);
  8747. {
  8748. endMeasure(instance, `compile`);
  8749. }
  8750. }
  8751. }
  8752. instance.render = (Component.render || NOOP);
  8753. // for runtime-compiled render functions using `with` blocks, the render
  8754. // proxy used needs a different `has` handler which is more performant and
  8755. // also only allows a whitelist of globals to fallthrough.
  8756. if (installWithProxy) {
  8757. installWithProxy(instance);
  8758. }
  8759. }
  8760. // support for 2.x options
  8761. {
  8762. setCurrentInstance(instance);
  8763. pauseTracking();
  8764. applyOptions(instance);
  8765. resetTracking();
  8766. unsetCurrentInstance();
  8767. }
  8768. // warn missing template/render
  8769. // the runtime compilation of template in SSR is done by server-render
  8770. if (!Component.render && instance.render === NOOP && !isSSR) {
  8771. /* istanbul ignore if */
  8772. if (!compile && Component.template) {
  8773. warn(`Component provided template option but ` +
  8774. `runtime compilation is not supported in this build of Vue.` +
  8775. (` Use "vue.esm-browser.js" instead.`
  8776. ) /* should not happen */);
  8777. }
  8778. else {
  8779. warn(`Component is missing template or render function.`);
  8780. }
  8781. }
  8782. }
  8783. function createAttrsProxy(instance) {
  8784. return new Proxy(instance.attrs, {
  8785. get(target, key) {
  8786. markAttrsAccessed();
  8787. track(instance, "get" /* TrackOpTypes.GET */, '$attrs');
  8788. return target[key];
  8789. },
  8790. set() {
  8791. warn(`setupContext.attrs is readonly.`);
  8792. return false;
  8793. },
  8794. deleteProperty() {
  8795. warn(`setupContext.attrs is readonly.`);
  8796. return false;
  8797. }
  8798. }
  8799. );
  8800. }
  8801. function createSetupContext(instance) {
  8802. const expose = exposed => {
  8803. {
  8804. if (instance.exposed) {
  8805. warn(`expose() should be called only once per setup().`);
  8806. }
  8807. if (exposed != null) {
  8808. let exposedType = typeof exposed;
  8809. if (exposedType === 'object') {
  8810. if (isArray(exposed)) {
  8811. exposedType = 'array';
  8812. }
  8813. else if (isRef(exposed)) {
  8814. exposedType = 'ref';
  8815. }
  8816. }
  8817. if (exposedType !== 'object') {
  8818. warn(`expose() should be passed a plain object, received ${exposedType}.`);
  8819. }
  8820. }
  8821. }
  8822. instance.exposed = exposed || {};
  8823. };
  8824. let attrs;
  8825. {
  8826. // We use getters in dev in case libs like test-utils overwrite instance
  8827. // properties (overwrites should not be done in prod)
  8828. return Object.freeze({
  8829. get attrs() {
  8830. return attrs || (attrs = createAttrsProxy(instance));
  8831. },
  8832. get slots() {
  8833. return shallowReadonly(instance.slots);
  8834. },
  8835. get emit() {
  8836. return (event, ...args) => instance.emit(event, ...args);
  8837. },
  8838. expose
  8839. });
  8840. }
  8841. }
  8842. function getExposeProxy(instance) {
  8843. if (instance.exposed) {
  8844. return (instance.exposeProxy ||
  8845. (instance.exposeProxy = new Proxy(proxyRefs(markRaw(instance.exposed)), {
  8846. get(target, key) {
  8847. if (key in target) {
  8848. return target[key];
  8849. }
  8850. else if (key in publicPropertiesMap) {
  8851. return publicPropertiesMap[key](instance);
  8852. }
  8853. },
  8854. has(target, key) {
  8855. return key in target || key in publicPropertiesMap;
  8856. }
  8857. })));
  8858. }
  8859. }
  8860. const classifyRE = /(?:^|[-_])(\w)/g;
  8861. const classify = (str) => str.replace(classifyRE, c => c.toUpperCase()).replace(/[-_]/g, '');
  8862. function getComponentName(Component, includeInferred = true) {
  8863. return isFunction(Component)
  8864. ? Component.displayName || Component.name
  8865. : Component.name || (includeInferred && Component.__name);
  8866. }
  8867. /* istanbul ignore next */
  8868. function formatComponentName(instance, Component, isRoot = false) {
  8869. let name = getComponentName(Component);
  8870. if (!name && Component.__file) {
  8871. const match = Component.__file.match(/([^/\\]+)\.\w+$/);
  8872. if (match) {
  8873. name = match[1];
  8874. }
  8875. }
  8876. if (!name && instance && instance.parent) {
  8877. // try to infer the name based on reverse resolution
  8878. const inferFromRegistry = (registry) => {
  8879. for (const key in registry) {
  8880. if (registry[key] === Component) {
  8881. return key;
  8882. }
  8883. }
  8884. };
  8885. name =
  8886. inferFromRegistry(instance.components ||
  8887. instance.parent.type.components) || inferFromRegistry(instance.appContext.components);
  8888. }
  8889. return name ? classify(name) : isRoot ? `App` : `Anonymous`;
  8890. }
  8891. function isClassComponent(value) {
  8892. return isFunction(value) && '__vccOpts' in value;
  8893. }
  8894. const computed = ((getterOrOptions, debugOptions) => {
  8895. // @ts-ignore
  8896. return computed$1(getterOrOptions, debugOptions, isInSSRComponentSetup);
  8897. });
  8898. // dev only
  8899. const warnRuntimeUsage = (method) => warn(`${method}() is a compiler-hint helper that is only usable inside ` +
  8900. `<script setup> of a single file component. Its arguments should be ` +
  8901. `compiled away and passing it at runtime has no effect.`);
  8902. // implementation
  8903. function defineProps() {
  8904. {
  8905. warnRuntimeUsage(`defineProps`);
  8906. }
  8907. return null;
  8908. }
  8909. // implementation
  8910. function defineEmits() {
  8911. {
  8912. warnRuntimeUsage(`defineEmits`);
  8913. }
  8914. return null;
  8915. }
  8916. /**
  8917. * Vue `<script setup>` compiler macro for declaring a component's exposed
  8918. * instance properties when it is accessed by a parent component via template
  8919. * refs.
  8920. *
  8921. * `<script setup>` components are closed by default - i.e. variables inside
  8922. * the `<script setup>` scope is not exposed to parent unless explicitly exposed
  8923. * via `defineExpose`.
  8924. *
  8925. * This is only usable inside `<script setup>`, is compiled away in the
  8926. * output and should **not** be actually called at runtime.
  8927. */
  8928. function defineExpose(exposed) {
  8929. {
  8930. warnRuntimeUsage(`defineExpose`);
  8931. }
  8932. }
  8933. /**
  8934. * Vue `<script setup>` compiler macro for providing props default values when
  8935. * using type-based `defineProps` declaration.
  8936. *
  8937. * Example usage:
  8938. * ```ts
  8939. * withDefaults(defineProps<{
  8940. * size?: number
  8941. * labels?: string[]
  8942. * }>(), {
  8943. * size: 3,
  8944. * labels: () => ['default label']
  8945. * })
  8946. * ```
  8947. *
  8948. * This is only usable inside `<script setup>`, is compiled away in the output
  8949. * and should **not** be actually called at runtime.
  8950. */
  8951. function withDefaults(props, defaults) {
  8952. {
  8953. warnRuntimeUsage(`withDefaults`);
  8954. }
  8955. return null;
  8956. }
  8957. function useSlots() {
  8958. return getContext().slots;
  8959. }
  8960. function useAttrs() {
  8961. return getContext().attrs;
  8962. }
  8963. function getContext() {
  8964. const i = getCurrentInstance();
  8965. if (!i) {
  8966. warn(`useContext() called without active instance.`);
  8967. }
  8968. return i.setupContext || (i.setupContext = createSetupContext(i));
  8969. }
  8970. /**
  8971. * Runtime helper for merging default declarations. Imported by compiled code
  8972. * only.
  8973. * @internal
  8974. */
  8975. function mergeDefaults(raw, defaults) {
  8976. const props = isArray(raw)
  8977. ? raw.reduce((normalized, p) => ((normalized[p] = {}), normalized), {})
  8978. : raw;
  8979. for (const key in defaults) {
  8980. const opt = props[key];
  8981. if (opt) {
  8982. if (isArray(opt) || isFunction(opt)) {
  8983. props[key] = { type: opt, default: defaults[key] };
  8984. }
  8985. else {
  8986. opt.default = defaults[key];
  8987. }
  8988. }
  8989. else if (opt === null) {
  8990. props[key] = { default: defaults[key] };
  8991. }
  8992. else {
  8993. warn(`props default key "${key}" has no corresponding declaration.`);
  8994. }
  8995. }
  8996. return props;
  8997. }
  8998. /**
  8999. * Used to create a proxy for the rest element when destructuring props with
  9000. * defineProps().
  9001. * @internal
  9002. */
  9003. function createPropsRestProxy(props, excludedKeys) {
  9004. const ret = {};
  9005. for (const key in props) {
  9006. if (!excludedKeys.includes(key)) {
  9007. Object.defineProperty(ret, key, {
  9008. enumerable: true,
  9009. get: () => props[key]
  9010. });
  9011. }
  9012. }
  9013. return ret;
  9014. }
  9015. /**
  9016. * `<script setup>` helper for persisting the current instance context over
  9017. * async/await flows.
  9018. *
  9019. * `@vue/compiler-sfc` converts the following:
  9020. *
  9021. * ```ts
  9022. * const x = await foo()
  9023. * ```
  9024. *
  9025. * into:
  9026. *
  9027. * ```ts
  9028. * let __temp, __restore
  9029. * const x = (([__temp, __restore] = withAsyncContext(() => foo())),__temp=await __temp,__restore(),__temp)
  9030. * ```
  9031. * @internal
  9032. */
  9033. function withAsyncContext(getAwaitable) {
  9034. const ctx = getCurrentInstance();
  9035. if (!ctx) {
  9036. warn(`withAsyncContext called without active current instance. ` +
  9037. `This is likely a bug.`);
  9038. }
  9039. let awaitable = getAwaitable();
  9040. unsetCurrentInstance();
  9041. if (isPromise(awaitable)) {
  9042. awaitable = awaitable.catch(e => {
  9043. setCurrentInstance(ctx);
  9044. throw e;
  9045. });
  9046. }
  9047. return [awaitable, () => setCurrentInstance(ctx)];
  9048. }
  9049. // Actual implementation
  9050. function h(type, propsOrChildren, children) {
  9051. const l = arguments.length;
  9052. if (l === 2) {
  9053. if (isObject(propsOrChildren) && !isArray(propsOrChildren)) {
  9054. // single vnode without props
  9055. if (isVNode(propsOrChildren)) {
  9056. return createVNode(type, null, [propsOrChildren]);
  9057. }
  9058. // props without children
  9059. return createVNode(type, propsOrChildren);
  9060. }
  9061. else {
  9062. // omit props
  9063. return createVNode(type, null, propsOrChildren);
  9064. }
  9065. }
  9066. else {
  9067. if (l > 3) {
  9068. children = Array.prototype.slice.call(arguments, 2);
  9069. }
  9070. else if (l === 3 && isVNode(children)) {
  9071. children = [children];
  9072. }
  9073. return createVNode(type, propsOrChildren, children);
  9074. }
  9075. }
  9076. const ssrContextKey = Symbol(`ssrContext` );
  9077. const useSSRContext = () => {
  9078. {
  9079. const ctx = inject(ssrContextKey);
  9080. if (!ctx) {
  9081. warn(`Server rendering context not provided. Make sure to only call ` +
  9082. `useSSRContext() conditionally in the server build.`);
  9083. }
  9084. return ctx;
  9085. }
  9086. };
  9087. function initCustomFormatter() {
  9088. /* eslint-disable no-restricted-globals */
  9089. if (typeof window === 'undefined') {
  9090. return;
  9091. }
  9092. const vueStyle = { style: 'color:#3ba776' };
  9093. const numberStyle = { style: 'color:#0b1bc9' };
  9094. const stringStyle = { style: 'color:#b62e24' };
  9095. const keywordStyle = { style: 'color:#9d288c' };
  9096. // custom formatter for Chrome
  9097. // https://www.mattzeunert.com/2016/02/19/custom-chrome-devtools-object-formatters.html
  9098. const formatter = {
  9099. header(obj) {
  9100. // TODO also format ComponentPublicInstance & ctx.slots/attrs in setup
  9101. if (!isObject(obj)) {
  9102. return null;
  9103. }
  9104. if (obj.__isVue) {
  9105. return ['div', vueStyle, `VueInstance`];
  9106. }
  9107. else if (isRef(obj)) {
  9108. return [
  9109. 'div',
  9110. {},
  9111. ['span', vueStyle, genRefFlag(obj)],
  9112. '<',
  9113. formatValue(obj.value),
  9114. `>`
  9115. ];
  9116. }
  9117. else if (isReactive(obj)) {
  9118. return [
  9119. 'div',
  9120. {},
  9121. ['span', vueStyle, isShallow(obj) ? 'ShallowReactive' : 'Reactive'],
  9122. '<',
  9123. formatValue(obj),
  9124. `>${isReadonly(obj) ? ` (readonly)` : ``}`
  9125. ];
  9126. }
  9127. else if (isReadonly(obj)) {
  9128. return [
  9129. 'div',
  9130. {},
  9131. ['span', vueStyle, isShallow(obj) ? 'ShallowReadonly' : 'Readonly'],
  9132. '<',
  9133. formatValue(obj),
  9134. '>'
  9135. ];
  9136. }
  9137. return null;
  9138. },
  9139. hasBody(obj) {
  9140. return obj && obj.__isVue;
  9141. },
  9142. body(obj) {
  9143. if (obj && obj.__isVue) {
  9144. return [
  9145. 'div',
  9146. {},
  9147. ...formatInstance(obj.$)
  9148. ];
  9149. }
  9150. }
  9151. };
  9152. function formatInstance(instance) {
  9153. const blocks = [];
  9154. if (instance.type.props && instance.props) {
  9155. blocks.push(createInstanceBlock('props', toRaw(instance.props)));
  9156. }
  9157. if (instance.setupState !== EMPTY_OBJ) {
  9158. blocks.push(createInstanceBlock('setup', instance.setupState));
  9159. }
  9160. if (instance.data !== EMPTY_OBJ) {
  9161. blocks.push(createInstanceBlock('data', toRaw(instance.data)));
  9162. }
  9163. const computed = extractKeys(instance, 'computed');
  9164. if (computed) {
  9165. blocks.push(createInstanceBlock('computed', computed));
  9166. }
  9167. const injected = extractKeys(instance, 'inject');
  9168. if (injected) {
  9169. blocks.push(createInstanceBlock('injected', injected));
  9170. }
  9171. blocks.push([
  9172. 'div',
  9173. {},
  9174. [
  9175. 'span',
  9176. {
  9177. style: keywordStyle.style + ';opacity:0.66'
  9178. },
  9179. '$ (internal): '
  9180. ],
  9181. ['object', { object: instance }]
  9182. ]);
  9183. return blocks;
  9184. }
  9185. function createInstanceBlock(type, target) {
  9186. target = extend({}, target);
  9187. if (!Object.keys(target).length) {
  9188. return ['span', {}];
  9189. }
  9190. return [
  9191. 'div',
  9192. { style: 'line-height:1.25em;margin-bottom:0.6em' },
  9193. [
  9194. 'div',
  9195. {
  9196. style: 'color:#476582'
  9197. },
  9198. type
  9199. ],
  9200. [
  9201. 'div',
  9202. {
  9203. style: 'padding-left:1.25em'
  9204. },
  9205. ...Object.keys(target).map(key => {
  9206. return [
  9207. 'div',
  9208. {},
  9209. ['span', keywordStyle, key + ': '],
  9210. formatValue(target[key], false)
  9211. ];
  9212. })
  9213. ]
  9214. ];
  9215. }
  9216. function formatValue(v, asRaw = true) {
  9217. if (typeof v === 'number') {
  9218. return ['span', numberStyle, v];
  9219. }
  9220. else if (typeof v === 'string') {
  9221. return ['span', stringStyle, JSON.stringify(v)];
  9222. }
  9223. else if (typeof v === 'boolean') {
  9224. return ['span', keywordStyle, v];
  9225. }
  9226. else if (isObject(v)) {
  9227. return ['object', { object: asRaw ? toRaw(v) : v }];
  9228. }
  9229. else {
  9230. return ['span', stringStyle, String(v)];
  9231. }
  9232. }
  9233. function extractKeys(instance, type) {
  9234. const Comp = instance.type;
  9235. if (isFunction(Comp)) {
  9236. return;
  9237. }
  9238. const extracted = {};
  9239. for (const key in instance.ctx) {
  9240. if (isKeyOfType(Comp, key, type)) {
  9241. extracted[key] = instance.ctx[key];
  9242. }
  9243. }
  9244. return extracted;
  9245. }
  9246. function isKeyOfType(Comp, key, type) {
  9247. const opts = Comp[type];
  9248. if ((isArray(opts) && opts.includes(key)) ||
  9249. (isObject(opts) && key in opts)) {
  9250. return true;
  9251. }
  9252. if (Comp.extends && isKeyOfType(Comp.extends, key, type)) {
  9253. return true;
  9254. }
  9255. if (Comp.mixins && Comp.mixins.some(m => isKeyOfType(m, key, type))) {
  9256. return true;
  9257. }
  9258. }
  9259. function genRefFlag(v) {
  9260. if (isShallow(v)) {
  9261. return `ShallowRef`;
  9262. }
  9263. if (v.effect) {
  9264. return `ComputedRef`;
  9265. }
  9266. return `Ref`;
  9267. }
  9268. if (window.devtoolsFormatters) {
  9269. window.devtoolsFormatters.push(formatter);
  9270. }
  9271. else {
  9272. window.devtoolsFormatters = [formatter];
  9273. }
  9274. }
  9275. function withMemo(memo, render, cache, index) {
  9276. const cached = cache[index];
  9277. if (cached && isMemoSame(cached, memo)) {
  9278. return cached;
  9279. }
  9280. const ret = render();
  9281. // shallow clone
  9282. ret.memo = memo.slice();
  9283. return (cache[index] = ret);
  9284. }
  9285. function isMemoSame(cached, memo) {
  9286. const prev = cached.memo;
  9287. if (prev.length != memo.length) {
  9288. return false;
  9289. }
  9290. for (let i = 0; i < prev.length; i++) {
  9291. if (hasChanged(prev[i], memo[i])) {
  9292. return false;
  9293. }
  9294. }
  9295. // make sure to let parent block track it when returning cached
  9296. if (isBlockTreeEnabled > 0 && currentBlock) {
  9297. currentBlock.push(cached);
  9298. }
  9299. return true;
  9300. }
  9301. // Core API ------------------------------------------------------------------
  9302. const version = "3.2.47";
  9303. /**
  9304. * SSR utils for \@vue/server-renderer. Only exposed in ssr-possible builds.
  9305. * @internal
  9306. */
  9307. const ssrUtils = (null);
  9308. /**
  9309. * @internal only exposed in compat builds
  9310. */
  9311. const resolveFilter = null;
  9312. /**
  9313. * @internal only exposed in compat builds.
  9314. */
  9315. const compatUtils = (null);
  9316. const svgNS = 'http://www.w3.org/2000/svg';
  9317. const doc = (typeof document !== 'undefined' ? document : null);
  9318. const templateContainer = doc && /*#__PURE__*/ doc.createElement('template');
  9319. const nodeOps = {
  9320. insert: (child, parent, anchor) => {
  9321. parent.insertBefore(child, anchor || null);
  9322. },
  9323. remove: child => {
  9324. const parent = child.parentNode;
  9325. if (parent) {
  9326. parent.removeChild(child);
  9327. }
  9328. },
  9329. createElement: (tag, isSVG, is, props) => {
  9330. const el = isSVG
  9331. ? doc.createElementNS(svgNS, tag)
  9332. : doc.createElement(tag, is ? { is } : undefined);
  9333. if (tag === 'select' && props && props.multiple != null) {
  9334. el.setAttribute('multiple', props.multiple);
  9335. }
  9336. return el;
  9337. },
  9338. createText: text => doc.createTextNode(text),
  9339. createComment: text => doc.createComment(text),
  9340. setText: (node, text) => {
  9341. node.nodeValue = text;
  9342. },
  9343. setElementText: (el, text) => {
  9344. el.textContent = text;
  9345. },
  9346. parentNode: node => node.parentNode,
  9347. nextSibling: node => node.nextSibling,
  9348. querySelector: selector => doc.querySelector(selector),
  9349. setScopeId(el, id) {
  9350. el.setAttribute(id, '');
  9351. },
  9352. // __UNSAFE__
  9353. // Reason: innerHTML.
  9354. // Static content here can only come from compiled templates.
  9355. // As long as the user only uses trusted templates, this is safe.
  9356. insertStaticContent(content, parent, anchor, isSVG, start, end) {
  9357. // <parent> before | first ... last | anchor </parent>
  9358. const before = anchor ? anchor.previousSibling : parent.lastChild;
  9359. // #5308 can only take cached path if:
  9360. // - has a single root node
  9361. // - nextSibling info is still available
  9362. if (start && (start === end || start.nextSibling)) {
  9363. // cached
  9364. while (true) {
  9365. parent.insertBefore(start.cloneNode(true), anchor);
  9366. if (start === end || !(start = start.nextSibling))
  9367. break;
  9368. }
  9369. }
  9370. else {
  9371. // fresh insert
  9372. templateContainer.innerHTML = isSVG ? `<svg>${content}</svg>` : content;
  9373. const template = templateContainer.content;
  9374. if (isSVG) {
  9375. // remove outer svg wrapper
  9376. const wrapper = template.firstChild;
  9377. while (wrapper.firstChild) {
  9378. template.appendChild(wrapper.firstChild);
  9379. }
  9380. template.removeChild(wrapper);
  9381. }
  9382. parent.insertBefore(template, anchor);
  9383. }
  9384. return [
  9385. // first
  9386. before ? before.nextSibling : parent.firstChild,
  9387. // last
  9388. anchor ? anchor.previousSibling : parent.lastChild
  9389. ];
  9390. }
  9391. };
  9392. // compiler should normalize class + :class bindings on the same element
  9393. // into a single binding ['staticClass', dynamic]
  9394. function patchClass(el, value, isSVG) {
  9395. // directly setting className should be faster than setAttribute in theory
  9396. // if this is an element during a transition, take the temporary transition
  9397. // classes into account.
  9398. const transitionClasses = el._vtc;
  9399. if (transitionClasses) {
  9400. value = (value ? [value, ...transitionClasses] : [...transitionClasses]).join(' ');
  9401. }
  9402. if (value == null) {
  9403. el.removeAttribute('class');
  9404. }
  9405. else if (isSVG) {
  9406. el.setAttribute('class', value);
  9407. }
  9408. else {
  9409. el.className = value;
  9410. }
  9411. }
  9412. function patchStyle(el, prev, next) {
  9413. const style = el.style;
  9414. const isCssString = isString(next);
  9415. if (next && !isCssString) {
  9416. if (prev && !isString(prev)) {
  9417. for (const key in prev) {
  9418. if (next[key] == null) {
  9419. setStyle(style, key, '');
  9420. }
  9421. }
  9422. }
  9423. for (const key in next) {
  9424. setStyle(style, key, next[key]);
  9425. }
  9426. }
  9427. else {
  9428. const currentDisplay = style.display;
  9429. if (isCssString) {
  9430. if (prev !== next) {
  9431. style.cssText = next;
  9432. }
  9433. }
  9434. else if (prev) {
  9435. el.removeAttribute('style');
  9436. }
  9437. // indicates that the `display` of the element is controlled by `v-show`,
  9438. // so we always keep the current `display` value regardless of the `style`
  9439. // value, thus handing over control to `v-show`.
  9440. if ('_vod' in el) {
  9441. style.display = currentDisplay;
  9442. }
  9443. }
  9444. }
  9445. const semicolonRE = /[^\\];\s*$/;
  9446. const importantRE = /\s*!important$/;
  9447. function setStyle(style, name, val) {
  9448. if (isArray(val)) {
  9449. val.forEach(v => setStyle(style, name, v));
  9450. }
  9451. else {
  9452. if (val == null)
  9453. val = '';
  9454. {
  9455. if (semicolonRE.test(val)) {
  9456. warn(`Unexpected semicolon at the end of '${name}' style value: '${val}'`);
  9457. }
  9458. }
  9459. if (name.startsWith('--')) {
  9460. // custom property definition
  9461. style.setProperty(name, val);
  9462. }
  9463. else {
  9464. const prefixed = autoPrefix(style, name);
  9465. if (importantRE.test(val)) {
  9466. // !important
  9467. style.setProperty(hyphenate(prefixed), val.replace(importantRE, ''), 'important');
  9468. }
  9469. else {
  9470. style[prefixed] = val;
  9471. }
  9472. }
  9473. }
  9474. }
  9475. const prefixes = ['Webkit', 'Moz', 'ms'];
  9476. const prefixCache = {};
  9477. function autoPrefix(style, rawName) {
  9478. const cached = prefixCache[rawName];
  9479. if (cached) {
  9480. return cached;
  9481. }
  9482. let name = camelize(rawName);
  9483. if (name !== 'filter' && name in style) {
  9484. return (prefixCache[rawName] = name);
  9485. }
  9486. name = capitalize(name);
  9487. for (let i = 0; i < prefixes.length; i++) {
  9488. const prefixed = prefixes[i] + name;
  9489. if (prefixed in style) {
  9490. return (prefixCache[rawName] = prefixed);
  9491. }
  9492. }
  9493. return rawName;
  9494. }
  9495. const xlinkNS = 'http://www.w3.org/1999/xlink';
  9496. function patchAttr(el, key, value, isSVG, instance) {
  9497. if (isSVG && key.startsWith('xlink:')) {
  9498. if (value == null) {
  9499. el.removeAttributeNS(xlinkNS, key.slice(6, key.length));
  9500. }
  9501. else {
  9502. el.setAttributeNS(xlinkNS, key, value);
  9503. }
  9504. }
  9505. else {
  9506. // note we are only checking boolean attributes that don't have a
  9507. // corresponding dom prop of the same name here.
  9508. const isBoolean = isSpecialBooleanAttr(key);
  9509. if (value == null || (isBoolean && !includeBooleanAttr(value))) {
  9510. el.removeAttribute(key);
  9511. }
  9512. else {
  9513. el.setAttribute(key, isBoolean ? '' : value);
  9514. }
  9515. }
  9516. }
  9517. // __UNSAFE__
  9518. // functions. The user is responsible for using them with only trusted content.
  9519. function patchDOMProp(el, key, value,
  9520. // the following args are passed only due to potential innerHTML/textContent
  9521. // overriding existing VNodes, in which case the old tree must be properly
  9522. // unmounted.
  9523. prevChildren, parentComponent, parentSuspense, unmountChildren) {
  9524. if (key === 'innerHTML' || key === 'textContent') {
  9525. if (prevChildren) {
  9526. unmountChildren(prevChildren, parentComponent, parentSuspense);
  9527. }
  9528. el[key] = value == null ? '' : value;
  9529. return;
  9530. }
  9531. if (key === 'value' &&
  9532. el.tagName !== 'PROGRESS' &&
  9533. // custom elements may use _value internally
  9534. !el.tagName.includes('-')) {
  9535. // store value as _value as well since
  9536. // non-string values will be stringified.
  9537. el._value = value;
  9538. const newValue = value == null ? '' : value;
  9539. if (el.value !== newValue ||
  9540. // #4956: always set for OPTION elements because its value falls back to
  9541. // textContent if no value attribute is present. And setting .value for
  9542. // OPTION has no side effect
  9543. el.tagName === 'OPTION') {
  9544. el.value = newValue;
  9545. }
  9546. if (value == null) {
  9547. el.removeAttribute(key);
  9548. }
  9549. return;
  9550. }
  9551. let needRemove = false;
  9552. if (value === '' || value == null) {
  9553. const type = typeof el[key];
  9554. if (type === 'boolean') {
  9555. // e.g. <select multiple> compiles to { multiple: '' }
  9556. value = includeBooleanAttr(value);
  9557. }
  9558. else if (value == null && type === 'string') {
  9559. // e.g. <div :id="null">
  9560. value = '';
  9561. needRemove = true;
  9562. }
  9563. else if (type === 'number') {
  9564. // e.g. <img :width="null">
  9565. value = 0;
  9566. needRemove = true;
  9567. }
  9568. }
  9569. // some properties perform value validation and throw,
  9570. // some properties has getter, no setter, will error in 'use strict'
  9571. // eg. <select :type="null"></select> <select :willValidate="null"></select>
  9572. try {
  9573. el[key] = value;
  9574. }
  9575. catch (e) {
  9576. // do not warn if value is auto-coerced from nullish values
  9577. if (!needRemove) {
  9578. warn(`Failed setting prop "${key}" on <${el.tagName.toLowerCase()}>: ` +
  9579. `value ${value} is invalid.`, e);
  9580. }
  9581. }
  9582. needRemove && el.removeAttribute(key);
  9583. }
  9584. function addEventListener(el, event, handler, options) {
  9585. el.addEventListener(event, handler, options);
  9586. }
  9587. function removeEventListener(el, event, handler, options) {
  9588. el.removeEventListener(event, handler, options);
  9589. }
  9590. function patchEvent(el, rawName, prevValue, nextValue, instance = null) {
  9591. // vei = vue event invokers
  9592. const invokers = el._vei || (el._vei = {});
  9593. const existingInvoker = invokers[rawName];
  9594. if (nextValue && existingInvoker) {
  9595. // patch
  9596. existingInvoker.value = nextValue;
  9597. }
  9598. else {
  9599. const [name, options] = parseName(rawName);
  9600. if (nextValue) {
  9601. // add
  9602. const invoker = (invokers[rawName] = createInvoker(nextValue, instance));
  9603. addEventListener(el, name, invoker, options);
  9604. }
  9605. else if (existingInvoker) {
  9606. // remove
  9607. removeEventListener(el, name, existingInvoker, options);
  9608. invokers[rawName] = undefined;
  9609. }
  9610. }
  9611. }
  9612. const optionsModifierRE = /(?:Once|Passive|Capture)$/;
  9613. function parseName(name) {
  9614. let options;
  9615. if (optionsModifierRE.test(name)) {
  9616. options = {};
  9617. let m;
  9618. while ((m = name.match(optionsModifierRE))) {
  9619. name = name.slice(0, name.length - m[0].length);
  9620. options[m[0].toLowerCase()] = true;
  9621. }
  9622. }
  9623. const event = name[2] === ':' ? name.slice(3) : hyphenate(name.slice(2));
  9624. return [event, options];
  9625. }
  9626. // To avoid the overhead of repeatedly calling Date.now(), we cache
  9627. // and use the same timestamp for all event listeners attached in the same tick.
  9628. let cachedNow = 0;
  9629. const p = /*#__PURE__*/ Promise.resolve();
  9630. const getNow = () => cachedNow || (p.then(() => (cachedNow = 0)), (cachedNow = Date.now()));
  9631. function createInvoker(initialValue, instance) {
  9632. const invoker = (e) => {
  9633. // async edge case vuejs/vue#6566
  9634. // inner click event triggers patch, event handler
  9635. // attached to outer element during patch, and triggered again. This
  9636. // happens because browsers fire microtask ticks between event propagation.
  9637. // this no longer happens for templates in Vue 3, but could still be
  9638. // theoretically possible for hand-written render functions.
  9639. // the solution: we save the timestamp when a handler is attached,
  9640. // and also attach the timestamp to any event that was handled by vue
  9641. // for the first time (to avoid inconsistent event timestamp implementations
  9642. // or events fired from iframes, e.g. #2513)
  9643. // The handler would only fire if the event passed to it was fired
  9644. // AFTER it was attached.
  9645. if (!e._vts) {
  9646. e._vts = Date.now();
  9647. }
  9648. else if (e._vts <= invoker.attached) {
  9649. return;
  9650. }
  9651. callWithAsyncErrorHandling(patchStopImmediatePropagation(e, invoker.value), instance, 5 /* ErrorCodes.NATIVE_EVENT_HANDLER */, [e]);
  9652. };
  9653. invoker.value = initialValue;
  9654. invoker.attached = getNow();
  9655. return invoker;
  9656. }
  9657. function patchStopImmediatePropagation(e, value) {
  9658. if (isArray(value)) {
  9659. const originalStop = e.stopImmediatePropagation;
  9660. e.stopImmediatePropagation = () => {
  9661. originalStop.call(e);
  9662. e._stopped = true;
  9663. };
  9664. return value.map(fn => (e) => !e._stopped && fn && fn(e));
  9665. }
  9666. else {
  9667. return value;
  9668. }
  9669. }
  9670. const nativeOnRE = /^on[a-z]/;
  9671. const patchProp = (el, key, prevValue, nextValue, isSVG = false, prevChildren, parentComponent, parentSuspense, unmountChildren) => {
  9672. if (key === 'class') {
  9673. patchClass(el, nextValue, isSVG);
  9674. }
  9675. else if (key === 'style') {
  9676. patchStyle(el, prevValue, nextValue);
  9677. }
  9678. else if (isOn(key)) {
  9679. // ignore v-model listeners
  9680. if (!isModelListener(key)) {
  9681. patchEvent(el, key, prevValue, nextValue, parentComponent);
  9682. }
  9683. }
  9684. else if (key[0] === '.'
  9685. ? ((key = key.slice(1)), true)
  9686. : key[0] === '^'
  9687. ? ((key = key.slice(1)), false)
  9688. : shouldSetAsProp(el, key, nextValue, isSVG)) {
  9689. patchDOMProp(el, key, nextValue, prevChildren, parentComponent, parentSuspense, unmountChildren);
  9690. }
  9691. else {
  9692. // special case for <input v-model type="checkbox"> with
  9693. // :true-value & :false-value
  9694. // store value as dom properties since non-string values will be
  9695. // stringified.
  9696. if (key === 'true-value') {
  9697. el._trueValue = nextValue;
  9698. }
  9699. else if (key === 'false-value') {
  9700. el._falseValue = nextValue;
  9701. }
  9702. patchAttr(el, key, nextValue, isSVG);
  9703. }
  9704. };
  9705. function shouldSetAsProp(el, key, value, isSVG) {
  9706. if (isSVG) {
  9707. // most keys must be set as attribute on svg elements to work
  9708. // ...except innerHTML & textContent
  9709. if (key === 'innerHTML' || key === 'textContent') {
  9710. return true;
  9711. }
  9712. // or native onclick with function values
  9713. if (key in el && nativeOnRE.test(key) && isFunction(value)) {
  9714. return true;
  9715. }
  9716. return false;
  9717. }
  9718. // these are enumerated attrs, however their corresponding DOM properties
  9719. // are actually booleans - this leads to setting it with a string "false"
  9720. // value leading it to be coerced to `true`, so we need to always treat
  9721. // them as attributes.
  9722. // Note that `contentEditable` doesn't have this problem: its DOM
  9723. // property is also enumerated string values.
  9724. if (key === 'spellcheck' || key === 'draggable' || key === 'translate') {
  9725. return false;
  9726. }
  9727. // #1787, #2840 form property on form elements is readonly and must be set as
  9728. // attribute.
  9729. if (key === 'form') {
  9730. return false;
  9731. }
  9732. // #1526 <input list> must be set as attribute
  9733. if (key === 'list' && el.tagName === 'INPUT') {
  9734. return false;
  9735. }
  9736. // #2766 <textarea type> must be set as attribute
  9737. if (key === 'type' && el.tagName === 'TEXTAREA') {
  9738. return false;
  9739. }
  9740. // native onclick with string value, must be set as attribute
  9741. if (nativeOnRE.test(key) && isString(value)) {
  9742. return false;
  9743. }
  9744. return key in el;
  9745. }
  9746. function defineCustomElement(options, hydrate) {
  9747. const Comp = defineComponent(options);
  9748. class VueCustomElement extends VueElement {
  9749. constructor(initialProps) {
  9750. super(Comp, initialProps, hydrate);
  9751. }
  9752. }
  9753. VueCustomElement.def = Comp;
  9754. return VueCustomElement;
  9755. }
  9756. const defineSSRCustomElement = ((options) => {
  9757. // @ts-ignore
  9758. return defineCustomElement(options, hydrate);
  9759. });
  9760. const BaseClass = (typeof HTMLElement !== 'undefined' ? HTMLElement : class {
  9761. });
  9762. class VueElement extends BaseClass {
  9763. constructor(_def, _props = {}, hydrate) {
  9764. super();
  9765. this._def = _def;
  9766. this._props = _props;
  9767. /**
  9768. * @internal
  9769. */
  9770. this._instance = null;
  9771. this._connected = false;
  9772. this._resolved = false;
  9773. this._numberProps = null;
  9774. if (this.shadowRoot && hydrate) {
  9775. hydrate(this._createVNode(), this.shadowRoot);
  9776. }
  9777. else {
  9778. if (this.shadowRoot) {
  9779. warn(`Custom element has pre-rendered declarative shadow root but is not ` +
  9780. `defined as hydratable. Use \`defineSSRCustomElement\`.`);
  9781. }
  9782. this.attachShadow({ mode: 'open' });
  9783. if (!this._def.__asyncLoader) {
  9784. // for sync component defs we can immediately resolve props
  9785. this._resolveProps(this._def);
  9786. }
  9787. }
  9788. }
  9789. connectedCallback() {
  9790. this._connected = true;
  9791. if (!this._instance) {
  9792. if (this._resolved) {
  9793. this._update();
  9794. }
  9795. else {
  9796. this._resolveDef();
  9797. }
  9798. }
  9799. }
  9800. disconnectedCallback() {
  9801. this._connected = false;
  9802. nextTick(() => {
  9803. if (!this._connected) {
  9804. render(null, this.shadowRoot);
  9805. this._instance = null;
  9806. }
  9807. });
  9808. }
  9809. /**
  9810. * resolve inner component definition (handle possible async component)
  9811. */
  9812. _resolveDef() {
  9813. this._resolved = true;
  9814. // set initial attrs
  9815. for (let i = 0; i < this.attributes.length; i++) {
  9816. this._setAttr(this.attributes[i].name);
  9817. }
  9818. // watch future attr changes
  9819. new MutationObserver(mutations => {
  9820. for (const m of mutations) {
  9821. this._setAttr(m.attributeName);
  9822. }
  9823. }).observe(this, { attributes: true });
  9824. const resolve = (def, isAsync = false) => {
  9825. const { props, styles } = def;
  9826. // cast Number-type props set before resolve
  9827. let numberProps;
  9828. if (props && !isArray(props)) {
  9829. for (const key in props) {
  9830. const opt = props[key];
  9831. if (opt === Number || (opt && opt.type === Number)) {
  9832. if (key in this._props) {
  9833. this._props[key] = toNumber(this._props[key]);
  9834. }
  9835. (numberProps || (numberProps = Object.create(null)))[camelize(key)] = true;
  9836. }
  9837. }
  9838. }
  9839. this._numberProps = numberProps;
  9840. if (isAsync) {
  9841. // defining getter/setters on prototype
  9842. // for sync defs, this already happened in the constructor
  9843. this._resolveProps(def);
  9844. }
  9845. // apply CSS
  9846. this._applyStyles(styles);
  9847. // initial render
  9848. this._update();
  9849. };
  9850. const asyncDef = this._def.__asyncLoader;
  9851. if (asyncDef) {
  9852. asyncDef().then(def => resolve(def, true));
  9853. }
  9854. else {
  9855. resolve(this._def);
  9856. }
  9857. }
  9858. _resolveProps(def) {
  9859. const { props } = def;
  9860. const declaredPropKeys = isArray(props) ? props : Object.keys(props || {});
  9861. // check if there are props set pre-upgrade or connect
  9862. for (const key of Object.keys(this)) {
  9863. if (key[0] !== '_' && declaredPropKeys.includes(key)) {
  9864. this._setProp(key, this[key], true, false);
  9865. }
  9866. }
  9867. // defining getter/setters on prototype
  9868. for (const key of declaredPropKeys.map(camelize)) {
  9869. Object.defineProperty(this, key, {
  9870. get() {
  9871. return this._getProp(key);
  9872. },
  9873. set(val) {
  9874. this._setProp(key, val);
  9875. }
  9876. });
  9877. }
  9878. }
  9879. _setAttr(key) {
  9880. let value = this.getAttribute(key);
  9881. const camelKey = camelize(key);
  9882. if (this._numberProps && this._numberProps[camelKey]) {
  9883. value = toNumber(value);
  9884. }
  9885. this._setProp(camelKey, value, false);
  9886. }
  9887. /**
  9888. * @internal
  9889. */
  9890. _getProp(key) {
  9891. return this._props[key];
  9892. }
  9893. /**
  9894. * @internal
  9895. */
  9896. _setProp(key, val, shouldReflect = true, shouldUpdate = true) {
  9897. if (val !== this._props[key]) {
  9898. this._props[key] = val;
  9899. if (shouldUpdate && this._instance) {
  9900. this._update();
  9901. }
  9902. // reflect
  9903. if (shouldReflect) {
  9904. if (val === true) {
  9905. this.setAttribute(hyphenate(key), '');
  9906. }
  9907. else if (typeof val === 'string' || typeof val === 'number') {
  9908. this.setAttribute(hyphenate(key), val + '');
  9909. }
  9910. else if (!val) {
  9911. this.removeAttribute(hyphenate(key));
  9912. }
  9913. }
  9914. }
  9915. }
  9916. _update() {
  9917. render(this._createVNode(), this.shadowRoot);
  9918. }
  9919. _createVNode() {
  9920. const vnode = createVNode(this._def, extend({}, this._props));
  9921. if (!this._instance) {
  9922. vnode.ce = instance => {
  9923. this._instance = instance;
  9924. instance.isCE = true;
  9925. // HMR
  9926. {
  9927. instance.ceReload = newStyles => {
  9928. // always reset styles
  9929. if (this._styles) {
  9930. this._styles.forEach(s => this.shadowRoot.removeChild(s));
  9931. this._styles.length = 0;
  9932. }
  9933. this._applyStyles(newStyles);
  9934. this._instance = null;
  9935. this._update();
  9936. };
  9937. }
  9938. const dispatch = (event, args) => {
  9939. this.dispatchEvent(new CustomEvent(event, {
  9940. detail: args
  9941. }));
  9942. };
  9943. // intercept emit
  9944. instance.emit = (event, ...args) => {
  9945. // dispatch both the raw and hyphenated versions of an event
  9946. // to match Vue behavior
  9947. dispatch(event, args);
  9948. if (hyphenate(event) !== event) {
  9949. dispatch(hyphenate(event), args);
  9950. }
  9951. };
  9952. // locate nearest Vue custom element parent for provide/inject
  9953. let parent = this;
  9954. while ((parent =
  9955. parent && (parent.parentNode || parent.host))) {
  9956. if (parent instanceof VueElement) {
  9957. instance.parent = parent._instance;
  9958. instance.provides = parent._instance.provides;
  9959. break;
  9960. }
  9961. }
  9962. };
  9963. }
  9964. return vnode;
  9965. }
  9966. _applyStyles(styles) {
  9967. if (styles) {
  9968. styles.forEach(css => {
  9969. const s = document.createElement('style');
  9970. s.textContent = css;
  9971. this.shadowRoot.appendChild(s);
  9972. // record for HMR
  9973. {
  9974. (this._styles || (this._styles = [])).push(s);
  9975. }
  9976. });
  9977. }
  9978. }
  9979. }
  9980. function useCssModule(name = '$style') {
  9981. /* istanbul ignore else */
  9982. {
  9983. const instance = getCurrentInstance();
  9984. if (!instance) {
  9985. warn(`useCssModule must be called inside setup()`);
  9986. return EMPTY_OBJ;
  9987. }
  9988. const modules = instance.type.__cssModules;
  9989. if (!modules) {
  9990. warn(`Current instance does not have CSS modules injected.`);
  9991. return EMPTY_OBJ;
  9992. }
  9993. const mod = modules[name];
  9994. if (!mod) {
  9995. warn(`Current instance does not have CSS module named "${name}".`);
  9996. return EMPTY_OBJ;
  9997. }
  9998. return mod;
  9999. }
  10000. }
  10001. /**
  10002. * Runtime helper for SFC's CSS variable injection feature.
  10003. * @private
  10004. */
  10005. function useCssVars(getter) {
  10006. const instance = getCurrentInstance();
  10007. /* istanbul ignore next */
  10008. if (!instance) {
  10009. warn(`useCssVars is called without current active component instance.`);
  10010. return;
  10011. }
  10012. const updateTeleports = (instance.ut = (vars = getter(instance.proxy)) => {
  10013. Array.from(document.querySelectorAll(`[data-v-owner="${instance.uid}"]`)).forEach(node => setVarsOnNode(node, vars));
  10014. });
  10015. const setVars = () => {
  10016. const vars = getter(instance.proxy);
  10017. setVarsOnVNode(instance.subTree, vars);
  10018. updateTeleports(vars);
  10019. };
  10020. watchPostEffect(setVars);
  10021. onMounted(() => {
  10022. const ob = new MutationObserver(setVars);
  10023. ob.observe(instance.subTree.el.parentNode, { childList: true });
  10024. onUnmounted(() => ob.disconnect());
  10025. });
  10026. }
  10027. function setVarsOnVNode(vnode, vars) {
  10028. if (vnode.shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
  10029. const suspense = vnode.suspense;
  10030. vnode = suspense.activeBranch;
  10031. if (suspense.pendingBranch && !suspense.isHydrating) {
  10032. suspense.effects.push(() => {
  10033. setVarsOnVNode(suspense.activeBranch, vars);
  10034. });
  10035. }
  10036. }
  10037. // drill down HOCs until it's a non-component vnode
  10038. while (vnode.component) {
  10039. vnode = vnode.component.subTree;
  10040. }
  10041. if (vnode.shapeFlag & 1 /* ShapeFlags.ELEMENT */ && vnode.el) {
  10042. setVarsOnNode(vnode.el, vars);
  10043. }
  10044. else if (vnode.type === Fragment) {
  10045. vnode.children.forEach(c => setVarsOnVNode(c, vars));
  10046. }
  10047. else if (vnode.type === Static) {
  10048. let { el, anchor } = vnode;
  10049. while (el) {
  10050. setVarsOnNode(el, vars);
  10051. if (el === anchor)
  10052. break;
  10053. el = el.nextSibling;
  10054. }
  10055. }
  10056. }
  10057. function setVarsOnNode(el, vars) {
  10058. if (el.nodeType === 1) {
  10059. const style = el.style;
  10060. for (const key in vars) {
  10061. style.setProperty(`--${key}`, vars[key]);
  10062. }
  10063. }
  10064. }
  10065. const TRANSITION = 'transition';
  10066. const ANIMATION = 'animation';
  10067. // DOM Transition is a higher-order-component based on the platform-agnostic
  10068. // base Transition component, with DOM-specific logic.
  10069. const Transition = (props, { slots }) => h(BaseTransition, resolveTransitionProps(props), slots);
  10070. Transition.displayName = 'Transition';
  10071. const DOMTransitionPropsValidators = {
  10072. name: String,
  10073. type: String,
  10074. css: {
  10075. type: Boolean,
  10076. default: true
  10077. },
  10078. duration: [String, Number, Object],
  10079. enterFromClass: String,
  10080. enterActiveClass: String,
  10081. enterToClass: String,
  10082. appearFromClass: String,
  10083. appearActiveClass: String,
  10084. appearToClass: String,
  10085. leaveFromClass: String,
  10086. leaveActiveClass: String,
  10087. leaveToClass: String
  10088. };
  10089. const TransitionPropsValidators = (Transition.props =
  10090. /*#__PURE__*/ extend({}, BaseTransition.props, DOMTransitionPropsValidators));
  10091. /**
  10092. * #3227 Incoming hooks may be merged into arrays when wrapping Transition
  10093. * with custom HOCs.
  10094. */
  10095. const callHook = (hook, args = []) => {
  10096. if (isArray(hook)) {
  10097. hook.forEach(h => h(...args));
  10098. }
  10099. else if (hook) {
  10100. hook(...args);
  10101. }
  10102. };
  10103. /**
  10104. * Check if a hook expects a callback (2nd arg), which means the user
  10105. * intends to explicitly control the end of the transition.
  10106. */
  10107. const hasExplicitCallback = (hook) => {
  10108. return hook
  10109. ? isArray(hook)
  10110. ? hook.some(h => h.length > 1)
  10111. : hook.length > 1
  10112. : false;
  10113. };
  10114. function resolveTransitionProps(rawProps) {
  10115. const baseProps = {};
  10116. for (const key in rawProps) {
  10117. if (!(key in DOMTransitionPropsValidators)) {
  10118. baseProps[key] = rawProps[key];
  10119. }
  10120. }
  10121. if (rawProps.css === false) {
  10122. return baseProps;
  10123. }
  10124. const { name = 'v', type, 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;
  10125. const durations = normalizeDuration(duration);
  10126. const enterDuration = durations && durations[0];
  10127. const leaveDuration = durations && durations[1];
  10128. const { onBeforeEnter, onEnter, onEnterCancelled, onLeave, onLeaveCancelled, onBeforeAppear = onBeforeEnter, onAppear = onEnter, onAppearCancelled = onEnterCancelled } = baseProps;
  10129. const finishEnter = (el, isAppear, done) => {
  10130. removeTransitionClass(el, isAppear ? appearToClass : enterToClass);
  10131. removeTransitionClass(el, isAppear ? appearActiveClass : enterActiveClass);
  10132. done && done();
  10133. };
  10134. const finishLeave = (el, done) => {
  10135. el._isLeaving = false;
  10136. removeTransitionClass(el, leaveFromClass);
  10137. removeTransitionClass(el, leaveToClass);
  10138. removeTransitionClass(el, leaveActiveClass);
  10139. done && done();
  10140. };
  10141. const makeEnterHook = (isAppear) => {
  10142. return (el, done) => {
  10143. const hook = isAppear ? onAppear : onEnter;
  10144. const resolve = () => finishEnter(el, isAppear, done);
  10145. callHook(hook, [el, resolve]);
  10146. nextFrame(() => {
  10147. removeTransitionClass(el, isAppear ? appearFromClass : enterFromClass);
  10148. addTransitionClass(el, isAppear ? appearToClass : enterToClass);
  10149. if (!hasExplicitCallback(hook)) {
  10150. whenTransitionEnds(el, type, enterDuration, resolve);
  10151. }
  10152. });
  10153. };
  10154. };
  10155. return extend(baseProps, {
  10156. onBeforeEnter(el) {
  10157. callHook(onBeforeEnter, [el]);
  10158. addTransitionClass(el, enterFromClass);
  10159. addTransitionClass(el, enterActiveClass);
  10160. },
  10161. onBeforeAppear(el) {
  10162. callHook(onBeforeAppear, [el]);
  10163. addTransitionClass(el, appearFromClass);
  10164. addTransitionClass(el, appearActiveClass);
  10165. },
  10166. onEnter: makeEnterHook(false),
  10167. onAppear: makeEnterHook(true),
  10168. onLeave(el, done) {
  10169. el._isLeaving = true;
  10170. const resolve = () => finishLeave(el, done);
  10171. addTransitionClass(el, leaveFromClass);
  10172. // force reflow so *-leave-from classes immediately take effect (#2593)
  10173. forceReflow();
  10174. addTransitionClass(el, leaveActiveClass);
  10175. nextFrame(() => {
  10176. if (!el._isLeaving) {
  10177. // cancelled
  10178. return;
  10179. }
  10180. removeTransitionClass(el, leaveFromClass);
  10181. addTransitionClass(el, leaveToClass);
  10182. if (!hasExplicitCallback(onLeave)) {
  10183. whenTransitionEnds(el, type, leaveDuration, resolve);
  10184. }
  10185. });
  10186. callHook(onLeave, [el, resolve]);
  10187. },
  10188. onEnterCancelled(el) {
  10189. finishEnter(el, false);
  10190. callHook(onEnterCancelled, [el]);
  10191. },
  10192. onAppearCancelled(el) {
  10193. finishEnter(el, true);
  10194. callHook(onAppearCancelled, [el]);
  10195. },
  10196. onLeaveCancelled(el) {
  10197. finishLeave(el);
  10198. callHook(onLeaveCancelled, [el]);
  10199. }
  10200. });
  10201. }
  10202. function normalizeDuration(duration) {
  10203. if (duration == null) {
  10204. return null;
  10205. }
  10206. else if (isObject(duration)) {
  10207. return [NumberOf(duration.enter), NumberOf(duration.leave)];
  10208. }
  10209. else {
  10210. const n = NumberOf(duration);
  10211. return [n, n];
  10212. }
  10213. }
  10214. function NumberOf(val) {
  10215. const res = toNumber(val);
  10216. {
  10217. assertNumber(res, '<transition> explicit duration');
  10218. }
  10219. return res;
  10220. }
  10221. function addTransitionClass(el, cls) {
  10222. cls.split(/\s+/).forEach(c => c && el.classList.add(c));
  10223. (el._vtc ||
  10224. (el._vtc = new Set())).add(cls);
  10225. }
  10226. function removeTransitionClass(el, cls) {
  10227. cls.split(/\s+/).forEach(c => c && el.classList.remove(c));
  10228. const { _vtc } = el;
  10229. if (_vtc) {
  10230. _vtc.delete(cls);
  10231. if (!_vtc.size) {
  10232. el._vtc = undefined;
  10233. }
  10234. }
  10235. }
  10236. function nextFrame(cb) {
  10237. requestAnimationFrame(() => {
  10238. requestAnimationFrame(cb);
  10239. });
  10240. }
  10241. let endId = 0;
  10242. function whenTransitionEnds(el, expectedType, explicitTimeout, resolve) {
  10243. const id = (el._endId = ++endId);
  10244. const resolveIfNotStale = () => {
  10245. if (id === el._endId) {
  10246. resolve();
  10247. }
  10248. };
  10249. if (explicitTimeout) {
  10250. return setTimeout(resolveIfNotStale, explicitTimeout);
  10251. }
  10252. const { type, timeout, propCount } = getTransitionInfo(el, expectedType);
  10253. if (!type) {
  10254. return resolve();
  10255. }
  10256. const endEvent = type + 'end';
  10257. let ended = 0;
  10258. const end = () => {
  10259. el.removeEventListener(endEvent, onEnd);
  10260. resolveIfNotStale();
  10261. };
  10262. const onEnd = (e) => {
  10263. if (e.target === el && ++ended >= propCount) {
  10264. end();
  10265. }
  10266. };
  10267. setTimeout(() => {
  10268. if (ended < propCount) {
  10269. end();
  10270. }
  10271. }, timeout + 1);
  10272. el.addEventListener(endEvent, onEnd);
  10273. }
  10274. function getTransitionInfo(el, expectedType) {
  10275. const styles = window.getComputedStyle(el);
  10276. // JSDOM may return undefined for transition properties
  10277. const getStyleProperties = (key) => (styles[key] || '').split(', ');
  10278. const transitionDelays = getStyleProperties(`${TRANSITION}Delay`);
  10279. const transitionDurations = getStyleProperties(`${TRANSITION}Duration`);
  10280. const transitionTimeout = getTimeout(transitionDelays, transitionDurations);
  10281. const animationDelays = getStyleProperties(`${ANIMATION}Delay`);
  10282. const animationDurations = getStyleProperties(`${ANIMATION}Duration`);
  10283. const animationTimeout = getTimeout(animationDelays, animationDurations);
  10284. let type = null;
  10285. let timeout = 0;
  10286. let propCount = 0;
  10287. /* istanbul ignore if */
  10288. if (expectedType === TRANSITION) {
  10289. if (transitionTimeout > 0) {
  10290. type = TRANSITION;
  10291. timeout = transitionTimeout;
  10292. propCount = transitionDurations.length;
  10293. }
  10294. }
  10295. else if (expectedType === ANIMATION) {
  10296. if (animationTimeout > 0) {
  10297. type = ANIMATION;
  10298. timeout = animationTimeout;
  10299. propCount = animationDurations.length;
  10300. }
  10301. }
  10302. else {
  10303. timeout = Math.max(transitionTimeout, animationTimeout);
  10304. type =
  10305. timeout > 0
  10306. ? transitionTimeout > animationTimeout
  10307. ? TRANSITION
  10308. : ANIMATION
  10309. : null;
  10310. propCount = type
  10311. ? type === TRANSITION
  10312. ? transitionDurations.length
  10313. : animationDurations.length
  10314. : 0;
  10315. }
  10316. const hasTransform = type === TRANSITION &&
  10317. /\b(transform|all)(,|$)/.test(getStyleProperties(`${TRANSITION}Property`).toString());
  10318. return {
  10319. type,
  10320. timeout,
  10321. propCount,
  10322. hasTransform
  10323. };
  10324. }
  10325. function getTimeout(delays, durations) {
  10326. while (delays.length < durations.length) {
  10327. delays = delays.concat(delays);
  10328. }
  10329. return Math.max(...durations.map((d, i) => toMs(d) + toMs(delays[i])));
  10330. }
  10331. // Old versions of Chromium (below 61.0.3163.100) formats floating pointer
  10332. // numbers in a locale-dependent way, using a comma instead of a dot.
  10333. // If comma is not replaced with a dot, the input will be rounded down
  10334. // (i.e. acting as a floor function) causing unexpected behaviors
  10335. function toMs(s) {
  10336. return Number(s.slice(0, -1).replace(',', '.')) * 1000;
  10337. }
  10338. // synchronously force layout to put elements into a certain state
  10339. function forceReflow() {
  10340. return document.body.offsetHeight;
  10341. }
  10342. const positionMap = new WeakMap();
  10343. const newPositionMap = new WeakMap();
  10344. const TransitionGroupImpl = {
  10345. name: 'TransitionGroup',
  10346. props: /*#__PURE__*/ extend({}, TransitionPropsValidators, {
  10347. tag: String,
  10348. moveClass: String
  10349. }),
  10350. setup(props, { slots }) {
  10351. const instance = getCurrentInstance();
  10352. const state = useTransitionState();
  10353. let prevChildren;
  10354. let children;
  10355. onUpdated(() => {
  10356. // children is guaranteed to exist after initial render
  10357. if (!prevChildren.length) {
  10358. return;
  10359. }
  10360. const moveClass = props.moveClass || `${props.name || 'v'}-move`;
  10361. if (!hasCSSTransform(prevChildren[0].el, instance.vnode.el, moveClass)) {
  10362. return;
  10363. }
  10364. // we divide the work into three loops to avoid mixing DOM reads and writes
  10365. // in each iteration - which helps prevent layout thrashing.
  10366. prevChildren.forEach(callPendingCbs);
  10367. prevChildren.forEach(recordPosition);
  10368. const movedChildren = prevChildren.filter(applyTranslation);
  10369. // force reflow to put everything in position
  10370. forceReflow();
  10371. movedChildren.forEach(c => {
  10372. const el = c.el;
  10373. const style = el.style;
  10374. addTransitionClass(el, moveClass);
  10375. style.transform = style.webkitTransform = style.transitionDuration = '';
  10376. const cb = (el._moveCb = (e) => {
  10377. if (e && e.target !== el) {
  10378. return;
  10379. }
  10380. if (!e || /transform$/.test(e.propertyName)) {
  10381. el.removeEventListener('transitionend', cb);
  10382. el._moveCb = null;
  10383. removeTransitionClass(el, moveClass);
  10384. }
  10385. });
  10386. el.addEventListener('transitionend', cb);
  10387. });
  10388. });
  10389. return () => {
  10390. const rawProps = toRaw(props);
  10391. const cssTransitionProps = resolveTransitionProps(rawProps);
  10392. let tag = rawProps.tag || Fragment;
  10393. prevChildren = children;
  10394. children = slots.default ? getTransitionRawChildren(slots.default()) : [];
  10395. for (let i = 0; i < children.length; i++) {
  10396. const child = children[i];
  10397. if (child.key != null) {
  10398. setTransitionHooks(child, resolveTransitionHooks(child, cssTransitionProps, state, instance));
  10399. }
  10400. else {
  10401. warn(`<TransitionGroup> children must be keyed.`);
  10402. }
  10403. }
  10404. if (prevChildren) {
  10405. for (let i = 0; i < prevChildren.length; i++) {
  10406. const child = prevChildren[i];
  10407. setTransitionHooks(child, resolveTransitionHooks(child, cssTransitionProps, state, instance));
  10408. positionMap.set(child, child.el.getBoundingClientRect());
  10409. }
  10410. }
  10411. return createVNode(tag, null, children);
  10412. };
  10413. }
  10414. };
  10415. /**
  10416. * TransitionGroup does not support "mode" so we need to remove it from the
  10417. * props declarations, but direct delete operation is considered a side effect
  10418. * and will make the entire transition feature non-tree-shakeable, so we do it
  10419. * in a function and mark the function's invocation as pure.
  10420. */
  10421. const removeMode = (props) => delete props.mode;
  10422. /*#__PURE__*/ removeMode(TransitionGroupImpl.props);
  10423. const TransitionGroup = TransitionGroupImpl;
  10424. function callPendingCbs(c) {
  10425. const el = c.el;
  10426. if (el._moveCb) {
  10427. el._moveCb();
  10428. }
  10429. if (el._enterCb) {
  10430. el._enterCb();
  10431. }
  10432. }
  10433. function recordPosition(c) {
  10434. newPositionMap.set(c, c.el.getBoundingClientRect());
  10435. }
  10436. function applyTranslation(c) {
  10437. const oldPos = positionMap.get(c);
  10438. const newPos = newPositionMap.get(c);
  10439. const dx = oldPos.left - newPos.left;
  10440. const dy = oldPos.top - newPos.top;
  10441. if (dx || dy) {
  10442. const s = c.el.style;
  10443. s.transform = s.webkitTransform = `translate(${dx}px,${dy}px)`;
  10444. s.transitionDuration = '0s';
  10445. return c;
  10446. }
  10447. }
  10448. function hasCSSTransform(el, root, moveClass) {
  10449. // Detect whether an element with the move class applied has
  10450. // CSS transitions. Since the element may be inside an entering
  10451. // transition at this very moment, we make a clone of it and remove
  10452. // all other transition classes applied to ensure only the move class
  10453. // is applied.
  10454. const clone = el.cloneNode();
  10455. if (el._vtc) {
  10456. el._vtc.forEach(cls => {
  10457. cls.split(/\s+/).forEach(c => c && clone.classList.remove(c));
  10458. });
  10459. }
  10460. moveClass.split(/\s+/).forEach(c => c && clone.classList.add(c));
  10461. clone.style.display = 'none';
  10462. const container = (root.nodeType === 1 ? root : root.parentNode);
  10463. container.appendChild(clone);
  10464. const { hasTransform } = getTransitionInfo(clone);
  10465. container.removeChild(clone);
  10466. return hasTransform;
  10467. }
  10468. const getModelAssigner = (vnode) => {
  10469. const fn = vnode.props['onUpdate:modelValue'] ||
  10470. (false );
  10471. return isArray(fn) ? value => invokeArrayFns(fn, value) : fn;
  10472. };
  10473. function onCompositionStart(e) {
  10474. e.target.composing = true;
  10475. }
  10476. function onCompositionEnd(e) {
  10477. const target = e.target;
  10478. if (target.composing) {
  10479. target.composing = false;
  10480. target.dispatchEvent(new Event('input'));
  10481. }
  10482. }
  10483. // We are exporting the v-model runtime directly as vnode hooks so that it can
  10484. // be tree-shaken in case v-model is never used.
  10485. const vModelText = {
  10486. created(el, { modifiers: { lazy, trim, number } }, vnode) {
  10487. el._assign = getModelAssigner(vnode);
  10488. const castToNumber = number || (vnode.props && vnode.props.type === 'number');
  10489. addEventListener(el, lazy ? 'change' : 'input', e => {
  10490. if (e.target.composing)
  10491. return;
  10492. let domValue = el.value;
  10493. if (trim) {
  10494. domValue = domValue.trim();
  10495. }
  10496. if (castToNumber) {
  10497. domValue = looseToNumber(domValue);
  10498. }
  10499. el._assign(domValue);
  10500. });
  10501. if (trim) {
  10502. addEventListener(el, 'change', () => {
  10503. el.value = el.value.trim();
  10504. });
  10505. }
  10506. if (!lazy) {
  10507. addEventListener(el, 'compositionstart', onCompositionStart);
  10508. addEventListener(el, 'compositionend', onCompositionEnd);
  10509. // Safari < 10.2 & UIWebView doesn't fire compositionend when
  10510. // switching focus before confirming composition choice
  10511. // this also fixes the issue where some browsers e.g. iOS Chrome
  10512. // fires "change" instead of "input" on autocomplete.
  10513. addEventListener(el, 'change', onCompositionEnd);
  10514. }
  10515. },
  10516. // set value on mounted so it's after min/max for type="range"
  10517. mounted(el, { value }) {
  10518. el.value = value == null ? '' : value;
  10519. },
  10520. beforeUpdate(el, { value, modifiers: { lazy, trim, number } }, vnode) {
  10521. el._assign = getModelAssigner(vnode);
  10522. // avoid clearing unresolved text. #2302
  10523. if (el.composing)
  10524. return;
  10525. if (document.activeElement === el && el.type !== 'range') {
  10526. if (lazy) {
  10527. return;
  10528. }
  10529. if (trim && el.value.trim() === value) {
  10530. return;
  10531. }
  10532. if ((number || el.type === 'number') &&
  10533. looseToNumber(el.value) === value) {
  10534. return;
  10535. }
  10536. }
  10537. const newValue = value == null ? '' : value;
  10538. if (el.value !== newValue) {
  10539. el.value = newValue;
  10540. }
  10541. }
  10542. };
  10543. const vModelCheckbox = {
  10544. // #4096 array checkboxes need to be deep traversed
  10545. deep: true,
  10546. created(el, _, vnode) {
  10547. el._assign = getModelAssigner(vnode);
  10548. addEventListener(el, 'change', () => {
  10549. const modelValue = el._modelValue;
  10550. const elementValue = getValue(el);
  10551. const checked = el.checked;
  10552. const assign = el._assign;
  10553. if (isArray(modelValue)) {
  10554. const index = looseIndexOf(modelValue, elementValue);
  10555. const found = index !== -1;
  10556. if (checked && !found) {
  10557. assign(modelValue.concat(elementValue));
  10558. }
  10559. else if (!checked && found) {
  10560. const filtered = [...modelValue];
  10561. filtered.splice(index, 1);
  10562. assign(filtered);
  10563. }
  10564. }
  10565. else if (isSet(modelValue)) {
  10566. const cloned = new Set(modelValue);
  10567. if (checked) {
  10568. cloned.add(elementValue);
  10569. }
  10570. else {
  10571. cloned.delete(elementValue);
  10572. }
  10573. assign(cloned);
  10574. }
  10575. else {
  10576. assign(getCheckboxValue(el, checked));
  10577. }
  10578. });
  10579. },
  10580. // set initial checked on mount to wait for true-value/false-value
  10581. mounted: setChecked,
  10582. beforeUpdate(el, binding, vnode) {
  10583. el._assign = getModelAssigner(vnode);
  10584. setChecked(el, binding, vnode);
  10585. }
  10586. };
  10587. function setChecked(el, { value, oldValue }, vnode) {
  10588. el._modelValue = value;
  10589. if (isArray(value)) {
  10590. el.checked = looseIndexOf(value, vnode.props.value) > -1;
  10591. }
  10592. else if (isSet(value)) {
  10593. el.checked = value.has(vnode.props.value);
  10594. }
  10595. else if (value !== oldValue) {
  10596. el.checked = looseEqual(value, getCheckboxValue(el, true));
  10597. }
  10598. }
  10599. const vModelRadio = {
  10600. created(el, { value }, vnode) {
  10601. el.checked = looseEqual(value, vnode.props.value);
  10602. el._assign = getModelAssigner(vnode);
  10603. addEventListener(el, 'change', () => {
  10604. el._assign(getValue(el));
  10605. });
  10606. },
  10607. beforeUpdate(el, { value, oldValue }, vnode) {
  10608. el._assign = getModelAssigner(vnode);
  10609. if (value !== oldValue) {
  10610. el.checked = looseEqual(value, vnode.props.value);
  10611. }
  10612. }
  10613. };
  10614. const vModelSelect = {
  10615. // <select multiple> value need to be deep traversed
  10616. deep: true,
  10617. created(el, { value, modifiers: { number } }, vnode) {
  10618. const isSetModel = isSet(value);
  10619. addEventListener(el, 'change', () => {
  10620. const selectedVal = Array.prototype.filter
  10621. .call(el.options, (o) => o.selected)
  10622. .map((o) => number ? looseToNumber(getValue(o)) : getValue(o));
  10623. el._assign(el.multiple
  10624. ? isSetModel
  10625. ? new Set(selectedVal)
  10626. : selectedVal
  10627. : selectedVal[0]);
  10628. });
  10629. el._assign = getModelAssigner(vnode);
  10630. },
  10631. // set value in mounted & updated because <select> relies on its children
  10632. // <option>s.
  10633. mounted(el, { value }) {
  10634. setSelected(el, value);
  10635. },
  10636. beforeUpdate(el, _binding, vnode) {
  10637. el._assign = getModelAssigner(vnode);
  10638. },
  10639. updated(el, { value }) {
  10640. setSelected(el, value);
  10641. }
  10642. };
  10643. function setSelected(el, value) {
  10644. const isMultiple = el.multiple;
  10645. if (isMultiple && !isArray(value) && !isSet(value)) {
  10646. warn(`<select multiple v-model> expects an Array or Set value for its binding, ` +
  10647. `but got ${Object.prototype.toString.call(value).slice(8, -1)}.`);
  10648. return;
  10649. }
  10650. for (let i = 0, l = el.options.length; i < l; i++) {
  10651. const option = el.options[i];
  10652. const optionValue = getValue(option);
  10653. if (isMultiple) {
  10654. if (isArray(value)) {
  10655. option.selected = looseIndexOf(value, optionValue) > -1;
  10656. }
  10657. else {
  10658. option.selected = value.has(optionValue);
  10659. }
  10660. }
  10661. else {
  10662. if (looseEqual(getValue(option), value)) {
  10663. if (el.selectedIndex !== i)
  10664. el.selectedIndex = i;
  10665. return;
  10666. }
  10667. }
  10668. }
  10669. if (!isMultiple && el.selectedIndex !== -1) {
  10670. el.selectedIndex = -1;
  10671. }
  10672. }
  10673. // retrieve raw value set via :value bindings
  10674. function getValue(el) {
  10675. return '_value' in el ? el._value : el.value;
  10676. }
  10677. // retrieve raw value for true-value and false-value set via :true-value or :false-value bindings
  10678. function getCheckboxValue(el, checked) {
  10679. const key = checked ? '_trueValue' : '_falseValue';
  10680. return key in el ? el[key] : checked;
  10681. }
  10682. const vModelDynamic = {
  10683. created(el, binding, vnode) {
  10684. callModelHook(el, binding, vnode, null, 'created');
  10685. },
  10686. mounted(el, binding, vnode) {
  10687. callModelHook(el, binding, vnode, null, 'mounted');
  10688. },
  10689. beforeUpdate(el, binding, vnode, prevVNode) {
  10690. callModelHook(el, binding, vnode, prevVNode, 'beforeUpdate');
  10691. },
  10692. updated(el, binding, vnode, prevVNode) {
  10693. callModelHook(el, binding, vnode, prevVNode, 'updated');
  10694. }
  10695. };
  10696. function resolveDynamicModel(tagName, type) {
  10697. switch (tagName) {
  10698. case 'SELECT':
  10699. return vModelSelect;
  10700. case 'TEXTAREA':
  10701. return vModelText;
  10702. default:
  10703. switch (type) {
  10704. case 'checkbox':
  10705. return vModelCheckbox;
  10706. case 'radio':
  10707. return vModelRadio;
  10708. default:
  10709. return vModelText;
  10710. }
  10711. }
  10712. }
  10713. function callModelHook(el, binding, vnode, prevVNode, hook) {
  10714. const modelToUse = resolveDynamicModel(el.tagName, vnode.props && vnode.props.type);
  10715. const fn = modelToUse[hook];
  10716. fn && fn(el, binding, vnode, prevVNode);
  10717. }
  10718. const systemModifiers = ['ctrl', 'shift', 'alt', 'meta'];
  10719. const modifierGuards = {
  10720. stop: e => e.stopPropagation(),
  10721. prevent: e => e.preventDefault(),
  10722. self: e => e.target !== e.currentTarget,
  10723. ctrl: e => !e.ctrlKey,
  10724. shift: e => !e.shiftKey,
  10725. alt: e => !e.altKey,
  10726. meta: e => !e.metaKey,
  10727. left: e => 'button' in e && e.button !== 0,
  10728. middle: e => 'button' in e && e.button !== 1,
  10729. right: e => 'button' in e && e.button !== 2,
  10730. exact: (e, modifiers) => systemModifiers.some(m => e[`${m}Key`] && !modifiers.includes(m))
  10731. };
  10732. /**
  10733. * @private
  10734. */
  10735. const withModifiers = (fn, modifiers) => {
  10736. return (event, ...args) => {
  10737. for (let i = 0; i < modifiers.length; i++) {
  10738. const guard = modifierGuards[modifiers[i]];
  10739. if (guard && guard(event, modifiers))
  10740. return;
  10741. }
  10742. return fn(event, ...args);
  10743. };
  10744. };
  10745. // Kept for 2.x compat.
  10746. // Note: IE11 compat for `spacebar` and `del` is removed for now.
  10747. const keyNames = {
  10748. esc: 'escape',
  10749. space: ' ',
  10750. up: 'arrow-up',
  10751. left: 'arrow-left',
  10752. right: 'arrow-right',
  10753. down: 'arrow-down',
  10754. delete: 'backspace'
  10755. };
  10756. /**
  10757. * @private
  10758. */
  10759. const withKeys = (fn, modifiers) => {
  10760. return (event) => {
  10761. if (!('key' in event)) {
  10762. return;
  10763. }
  10764. const eventKey = hyphenate(event.key);
  10765. if (modifiers.some(k => k === eventKey || keyNames[k] === eventKey)) {
  10766. return fn(event);
  10767. }
  10768. };
  10769. };
  10770. const vShow = {
  10771. beforeMount(el, { value }, { transition }) {
  10772. el._vod = el.style.display === 'none' ? '' : el.style.display;
  10773. if (transition && value) {
  10774. transition.beforeEnter(el);
  10775. }
  10776. else {
  10777. setDisplay(el, value);
  10778. }
  10779. },
  10780. mounted(el, { value }, { transition }) {
  10781. if (transition && value) {
  10782. transition.enter(el);
  10783. }
  10784. },
  10785. updated(el, { value, oldValue }, { transition }) {
  10786. if (!value === !oldValue)
  10787. return;
  10788. if (transition) {
  10789. if (value) {
  10790. transition.beforeEnter(el);
  10791. setDisplay(el, true);
  10792. transition.enter(el);
  10793. }
  10794. else {
  10795. transition.leave(el, () => {
  10796. setDisplay(el, false);
  10797. });
  10798. }
  10799. }
  10800. else {
  10801. setDisplay(el, value);
  10802. }
  10803. },
  10804. beforeUnmount(el, { value }) {
  10805. setDisplay(el, value);
  10806. }
  10807. };
  10808. function setDisplay(el, value) {
  10809. el.style.display = value ? el._vod : 'none';
  10810. }
  10811. const rendererOptions = /*#__PURE__*/ extend({ patchProp }, nodeOps);
  10812. // lazy create the renderer - this makes core renderer logic tree-shakable
  10813. // in case the user only imports reactivity utilities from Vue.
  10814. let renderer;
  10815. let enabledHydration = false;
  10816. function ensureRenderer() {
  10817. return (renderer ||
  10818. (renderer = createRenderer(rendererOptions)));
  10819. }
  10820. function ensureHydrationRenderer() {
  10821. renderer = enabledHydration
  10822. ? renderer
  10823. : createHydrationRenderer(rendererOptions);
  10824. enabledHydration = true;
  10825. return renderer;
  10826. }
  10827. // use explicit type casts here to avoid import() calls in rolled-up d.ts
  10828. const render = ((...args) => {
  10829. ensureRenderer().render(...args);
  10830. });
  10831. const hydrate = ((...args) => {
  10832. ensureHydrationRenderer().hydrate(...args);
  10833. });
  10834. const createApp = ((...args) => {
  10835. const app = ensureRenderer().createApp(...args);
  10836. {
  10837. injectNativeTagCheck(app);
  10838. injectCompilerOptionsCheck(app);
  10839. }
  10840. const { mount } = app;
  10841. app.mount = (containerOrSelector) => {
  10842. const container = normalizeContainer(containerOrSelector);
  10843. if (!container)
  10844. return;
  10845. const component = app._component;
  10846. if (!isFunction(component) && !component.render && !component.template) {
  10847. // __UNSAFE__
  10848. // Reason: potential execution of JS expressions in in-DOM template.
  10849. // The user must make sure the in-DOM template is trusted. If it's
  10850. // rendered by the server, the template should not contain any user data.
  10851. component.template = container.innerHTML;
  10852. }
  10853. // clear content before mounting
  10854. container.innerHTML = '';
  10855. const proxy = mount(container, false, container instanceof SVGElement);
  10856. if (container instanceof Element) {
  10857. container.removeAttribute('v-cloak');
  10858. container.setAttribute('data-v-app', '');
  10859. }
  10860. return proxy;
  10861. };
  10862. return app;
  10863. });
  10864. const createSSRApp = ((...args) => {
  10865. const app = ensureHydrationRenderer().createApp(...args);
  10866. {
  10867. injectNativeTagCheck(app);
  10868. injectCompilerOptionsCheck(app);
  10869. }
  10870. const { mount } = app;
  10871. app.mount = (containerOrSelector) => {
  10872. const container = normalizeContainer(containerOrSelector);
  10873. if (container) {
  10874. return mount(container, true, container instanceof SVGElement);
  10875. }
  10876. };
  10877. return app;
  10878. });
  10879. function injectNativeTagCheck(app) {
  10880. // Inject `isNativeTag`
  10881. // this is used for component name validation (dev only)
  10882. Object.defineProperty(app.config, 'isNativeTag', {
  10883. value: (tag) => isHTMLTag(tag) || isSVGTag(tag),
  10884. writable: false
  10885. });
  10886. }
  10887. // dev only
  10888. function injectCompilerOptionsCheck(app) {
  10889. if (isRuntimeOnly()) {
  10890. const isCustomElement = app.config.isCustomElement;
  10891. Object.defineProperty(app.config, 'isCustomElement', {
  10892. get() {
  10893. return isCustomElement;
  10894. },
  10895. set() {
  10896. warn(`The \`isCustomElement\` config option is deprecated. Use ` +
  10897. `\`compilerOptions.isCustomElement\` instead.`);
  10898. }
  10899. });
  10900. const compilerOptions = app.config.compilerOptions;
  10901. const msg = `The \`compilerOptions\` config option is only respected when using ` +
  10902. `a build of Vue.js that includes the runtime compiler (aka "full build"). ` +
  10903. `Since you are using the runtime-only build, \`compilerOptions\` ` +
  10904. `must be passed to \`@vue/compiler-dom\` in the build setup instead.\n` +
  10905. `- For vue-loader: pass it via vue-loader's \`compilerOptions\` loader option.\n` +
  10906. `- For vue-cli: see https://cli.vuejs.org/guide/webpack.html#modifying-options-of-a-loader\n` +
  10907. `- For vite: pass it via @vitejs/plugin-vue options. See https://github.com/vitejs/vite/tree/main/packages/plugin-vue#example-for-passing-options-to-vuecompiler-dom`;
  10908. Object.defineProperty(app.config, 'compilerOptions', {
  10909. get() {
  10910. warn(msg);
  10911. return compilerOptions;
  10912. },
  10913. set() {
  10914. warn(msg);
  10915. }
  10916. });
  10917. }
  10918. }
  10919. function normalizeContainer(container) {
  10920. if (isString(container)) {
  10921. const res = document.querySelector(container);
  10922. if (!res) {
  10923. warn(`Failed to mount app: mount target selector "${container}" returned null.`);
  10924. }
  10925. return res;
  10926. }
  10927. if (window.ShadowRoot &&
  10928. container instanceof window.ShadowRoot &&
  10929. container.mode === 'closed') {
  10930. warn(`mounting on a ShadowRoot with \`{mode: "closed"}\` may lead to unpredictable bugs`);
  10931. }
  10932. return container;
  10933. }
  10934. /**
  10935. * @internal
  10936. */
  10937. const initDirectivesForSSR = NOOP;
  10938. export { BaseTransition, Comment, EffectScope, Fragment, KeepAlive, ReactiveEffect, Static, Suspense, Teleport, Text, Transition, TransitionGroup, VueElement, assertNumber, callWithAsyncErrorHandling, callWithErrorHandling, camelize, capitalize, cloneVNode, compatUtils, computed, createApp, createBlock, createCommentVNode, createElementBlock, createBaseVNode as createElementVNode, createHydrationRenderer, createPropsRestProxy, createRenderer, createSSRApp, createSlots, createStaticVNode, createTextVNode, createVNode, customRef, defineAsyncComponent, defineComponent, defineCustomElement, defineEmits, defineExpose, defineProps, defineSSRCustomElement, devtools, effect, effectScope, getCurrentInstance, getCurrentScope, getTransitionRawChildren, guardReactiveProps, h, handleError, hydrate, initCustomFormatter, initDirectivesForSSR, inject, isMemoSame, isProxy, isReactive, isReadonly, isRef, isRuntimeOnly, isShallow, isVNode, markRaw, mergeDefaults, mergeProps, nextTick, normalizeClass, normalizeProps, normalizeStyle, onActivated, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onScopeDispose, onServerPrefetch, onUnmounted, onUpdated, openBlock, popScopeId, provide, proxyRefs, pushScopeId, queuePostFlushCb, reactive, readonly, ref, registerRuntimeCompiler, render, renderList, renderSlot, resolveComponent, resolveDirective, resolveDynamicComponent, resolveFilter, resolveTransitionHooks, setBlockTracking, setDevtoolsHook, setTransitionHooks, shallowReactive, shallowReadonly, shallowRef, ssrContextKey, ssrUtils, stop, toDisplayString, toHandlerKey, toHandlers, toRaw, toRef, toRefs, transformVNodeArgs, triggerRef, unref, useAttrs, useCssModule, useCssVars, useSSRContext, useSlots, useTransitionState, vModelCheckbox, vModelDynamic, vModelRadio, vModelSelect, vModelText, vShow, version, warn, watch, watchEffect, watchPostEffect, watchSyncEffect, withAsyncContext, withCtx, withDefaults, withDirectives, withKeys, withMemo, withModifiers, withScopeId };