runtime-dom.global.js 347 KB

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