vue.runtime.esm.js 417 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192
  1. import { extend, isArray, isMap, isIntegerKey, hasOwn, isSymbol, isObject, hasChanged, makeMap, capitalize, toRawType, def, isFunction, NOOP, isString, isPromise, getGlobalThis, EMPTY_OBJ, toHandlerKey, looseToNumber, hyphenate, camelize, isOn, isModelListener, toNumber, remove, isSet, isPlainObject, invokeArrayFns, isBuiltInDirective, isGloballyWhitelisted, isReservedProp, EMPTY_ARR, NO, isSpecialBooleanAttr, includeBooleanAttr, looseIndexOf, looseEqual, isHTMLTag, isSVGTag } from '@vue/shared';
  2. export { camelize, capitalize, toDisplayString, toHandlerKey } from '@vue/shared';
  3. import { isRootHook, isRootImmediateHook, ON_LOAD, normalizeClass, normalizeStyle, createRpx2Unit, defaultRpx2Unit } from '@dcloudio/uni-shared';
  4. export { normalizeClass, normalizeProps, normalizeStyle } from '@dcloudio/uni-shared';
  5. function warn$1(msg, ...args) {
  6. console.warn(`[Vue warn] ${msg}`, ...args);
  7. }
  8. let activeEffectScope;
  9. class EffectScope {
  10. constructor(detached = false) {
  11. this.detached = detached;
  12. /**
  13. * @internal
  14. */
  15. this._active = true;
  16. /**
  17. * @internal
  18. */
  19. this.effects = [];
  20. /**
  21. * @internal
  22. */
  23. this.cleanups = [];
  24. this.parent = activeEffectScope;
  25. if (!detached && activeEffectScope) {
  26. this.index =
  27. (activeEffectScope.scopes || (activeEffectScope.scopes = [])).push(this) - 1;
  28. }
  29. }
  30. get active() {
  31. return this._active;
  32. }
  33. run(fn) {
  34. if (this._active) {
  35. const currentEffectScope = activeEffectScope;
  36. try {
  37. activeEffectScope = this;
  38. return fn();
  39. }
  40. finally {
  41. activeEffectScope = currentEffectScope;
  42. }
  43. }
  44. else if ((process.env.NODE_ENV !== 'production')) {
  45. warn$1(`cannot run an inactive effect scope.`);
  46. }
  47. }
  48. /**
  49. * This should only be called on non-detached scopes
  50. * @internal
  51. */
  52. on() {
  53. activeEffectScope = this;
  54. }
  55. /**
  56. * This should only be called on non-detached scopes
  57. * @internal
  58. */
  59. off() {
  60. activeEffectScope = this.parent;
  61. }
  62. stop(fromParent) {
  63. if (this._active) {
  64. let i, l;
  65. for (i = 0, l = this.effects.length; i < l; i++) {
  66. this.effects[i].stop();
  67. }
  68. for (i = 0, l = this.cleanups.length; i < l; i++) {
  69. this.cleanups[i]();
  70. }
  71. if (this.scopes) {
  72. for (i = 0, l = this.scopes.length; i < l; i++) {
  73. this.scopes[i].stop(true);
  74. }
  75. }
  76. // nested scope, dereference from parent to avoid memory leaks
  77. if (!this.detached && this.parent && !fromParent) {
  78. // optimized O(1) removal
  79. const last = this.parent.scopes.pop();
  80. if (last && last !== this) {
  81. this.parent.scopes[this.index] = last;
  82. last.index = this.index;
  83. }
  84. }
  85. this.parent = undefined;
  86. this._active = false;
  87. }
  88. }
  89. }
  90. function effectScope(detached) {
  91. return new EffectScope(detached);
  92. }
  93. function recordEffectScope(effect, scope = activeEffectScope) {
  94. if (scope && scope.active) {
  95. scope.effects.push(effect);
  96. }
  97. }
  98. function getCurrentScope() {
  99. return activeEffectScope;
  100. }
  101. function onScopeDispose(fn) {
  102. if (activeEffectScope) {
  103. activeEffectScope.cleanups.push(fn);
  104. }
  105. else if ((process.env.NODE_ENV !== 'production')) {
  106. warn$1(`onScopeDispose() is called when there is no active effect scope` +
  107. ` to be associated with.`);
  108. }
  109. }
  110. const createDep = (effects) => {
  111. const dep = new Set(effects);
  112. dep.w = 0;
  113. dep.n = 0;
  114. return dep;
  115. };
  116. const wasTracked = (dep) => (dep.w & trackOpBit) > 0;
  117. const newTracked = (dep) => (dep.n & trackOpBit) > 0;
  118. const initDepMarkers = ({ deps }) => {
  119. if (deps.length) {
  120. for (let i = 0; i < deps.length; i++) {
  121. deps[i].w |= trackOpBit; // set was tracked
  122. }
  123. }
  124. };
  125. const finalizeDepMarkers = (effect) => {
  126. const { deps } = effect;
  127. if (deps.length) {
  128. let ptr = 0;
  129. for (let i = 0; i < deps.length; i++) {
  130. const dep = deps[i];
  131. if (wasTracked(dep) && !newTracked(dep)) {
  132. dep.delete(effect);
  133. }
  134. else {
  135. deps[ptr++] = dep;
  136. }
  137. // clear bits
  138. dep.w &= ~trackOpBit;
  139. dep.n &= ~trackOpBit;
  140. }
  141. deps.length = ptr;
  142. }
  143. };
  144. const targetMap = new WeakMap();
  145. // The number of effects currently being tracked recursively.
  146. let effectTrackDepth = 0;
  147. let trackOpBit = 1;
  148. /**
  149. * The bitwise track markers support at most 30 levels of recursion.
  150. * This value is chosen to enable modern JS engines to use a SMI on all platforms.
  151. * When recursion depth is greater, fall back to using a full cleanup.
  152. */
  153. const maxMarkerBits = 30;
  154. let activeEffect;
  155. const ITERATE_KEY = Symbol((process.env.NODE_ENV !== 'production') ? 'iterate' : '');
  156. const MAP_KEY_ITERATE_KEY = Symbol((process.env.NODE_ENV !== 'production') ? 'Map key iterate' : '');
  157. class ReactiveEffect {
  158. constructor(fn, scheduler = null, scope) {
  159. this.fn = fn;
  160. this.scheduler = scheduler;
  161. this.active = true;
  162. this.deps = [];
  163. this.parent = undefined;
  164. recordEffectScope(this, scope);
  165. }
  166. run() {
  167. if (!this.active) {
  168. return this.fn();
  169. }
  170. let parent = activeEffect;
  171. let lastShouldTrack = shouldTrack;
  172. while (parent) {
  173. if (parent === this) {
  174. return;
  175. }
  176. parent = parent.parent;
  177. }
  178. try {
  179. this.parent = activeEffect;
  180. activeEffect = this;
  181. shouldTrack = true;
  182. trackOpBit = 1 << ++effectTrackDepth;
  183. if (effectTrackDepth <= maxMarkerBits) {
  184. initDepMarkers(this);
  185. }
  186. else {
  187. cleanupEffect(this);
  188. }
  189. return this.fn();
  190. }
  191. finally {
  192. if (effectTrackDepth <= maxMarkerBits) {
  193. finalizeDepMarkers(this);
  194. }
  195. trackOpBit = 1 << --effectTrackDepth;
  196. activeEffect = this.parent;
  197. shouldTrack = lastShouldTrack;
  198. this.parent = undefined;
  199. if (this.deferStop) {
  200. this.stop();
  201. }
  202. }
  203. }
  204. stop() {
  205. // stopped while running itself - defer the cleanup
  206. if (activeEffect === this) {
  207. this.deferStop = true;
  208. }
  209. else if (this.active) {
  210. cleanupEffect(this);
  211. if (this.onStop) {
  212. this.onStop();
  213. }
  214. this.active = false;
  215. }
  216. }
  217. }
  218. function cleanupEffect(effect) {
  219. const { deps } = effect;
  220. if (deps.length) {
  221. for (let i = 0; i < deps.length; i++) {
  222. deps[i].delete(effect);
  223. }
  224. deps.length = 0;
  225. }
  226. }
  227. function effect(fn, options) {
  228. if (fn.effect) {
  229. fn = fn.effect.fn;
  230. }
  231. const _effect = new ReactiveEffect(fn);
  232. if (options) {
  233. extend(_effect, options);
  234. if (options.scope)
  235. recordEffectScope(_effect, options.scope);
  236. }
  237. if (!options || !options.lazy) {
  238. _effect.run();
  239. }
  240. const runner = _effect.run.bind(_effect);
  241. runner.effect = _effect;
  242. return runner;
  243. }
  244. function stop(runner) {
  245. runner.effect.stop();
  246. }
  247. let shouldTrack = true;
  248. const trackStack = [];
  249. function pauseTracking() {
  250. trackStack.push(shouldTrack);
  251. shouldTrack = false;
  252. }
  253. function resetTracking() {
  254. const last = trackStack.pop();
  255. shouldTrack = last === undefined ? true : last;
  256. }
  257. function track(target, type, key) {
  258. if (shouldTrack && activeEffect) {
  259. let depsMap = targetMap.get(target);
  260. if (!depsMap) {
  261. targetMap.set(target, (depsMap = new Map()));
  262. }
  263. let dep = depsMap.get(key);
  264. if (!dep) {
  265. depsMap.set(key, (dep = createDep()));
  266. }
  267. const eventInfo = (process.env.NODE_ENV !== 'production')
  268. ? { effect: activeEffect, target, type, key }
  269. : undefined;
  270. trackEffects(dep, eventInfo);
  271. }
  272. }
  273. function trackEffects(dep, debuggerEventExtraInfo) {
  274. let shouldTrack = false;
  275. if (effectTrackDepth <= maxMarkerBits) {
  276. if (!newTracked(dep)) {
  277. dep.n |= trackOpBit; // set newly tracked
  278. shouldTrack = !wasTracked(dep);
  279. }
  280. }
  281. else {
  282. // Full cleanup mode.
  283. shouldTrack = !dep.has(activeEffect);
  284. }
  285. if (shouldTrack) {
  286. dep.add(activeEffect);
  287. activeEffect.deps.push(dep);
  288. if ((process.env.NODE_ENV !== 'production') && activeEffect.onTrack) {
  289. activeEffect.onTrack(Object.assign({ effect: activeEffect }, debuggerEventExtraInfo));
  290. }
  291. }
  292. }
  293. function trigger(target, type, key, newValue, oldValue, oldTarget) {
  294. const depsMap = targetMap.get(target);
  295. if (!depsMap) {
  296. // never been tracked
  297. return;
  298. }
  299. let deps = [];
  300. if (type === "clear" /* TriggerOpTypes.CLEAR */) {
  301. // collection being cleared
  302. // trigger all effects for target
  303. deps = [...depsMap.values()];
  304. }
  305. else if (key === 'length' && isArray(target)) {
  306. const newLength = Number(newValue);
  307. depsMap.forEach((dep, key) => {
  308. if (key === 'length' || key >= newLength) {
  309. deps.push(dep);
  310. }
  311. });
  312. }
  313. else {
  314. // schedule runs for SET | ADD | DELETE
  315. if (key !== void 0) {
  316. deps.push(depsMap.get(key));
  317. }
  318. // also run for iteration key on ADD | DELETE | Map.SET
  319. switch (type) {
  320. case "add" /* TriggerOpTypes.ADD */:
  321. if (!isArray(target)) {
  322. deps.push(depsMap.get(ITERATE_KEY));
  323. if (isMap(target)) {
  324. deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
  325. }
  326. }
  327. else if (isIntegerKey(key)) {
  328. // new index added to array -> length changes
  329. deps.push(depsMap.get('length'));
  330. }
  331. break;
  332. case "delete" /* TriggerOpTypes.DELETE */:
  333. if (!isArray(target)) {
  334. deps.push(depsMap.get(ITERATE_KEY));
  335. if (isMap(target)) {
  336. deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
  337. }
  338. }
  339. break;
  340. case "set" /* TriggerOpTypes.SET */:
  341. if (isMap(target)) {
  342. deps.push(depsMap.get(ITERATE_KEY));
  343. }
  344. break;
  345. }
  346. }
  347. const eventInfo = (process.env.NODE_ENV !== 'production')
  348. ? { target, type, key, newValue, oldValue, oldTarget }
  349. : undefined;
  350. if (deps.length === 1) {
  351. if (deps[0]) {
  352. if ((process.env.NODE_ENV !== 'production')) {
  353. triggerEffects(deps[0], eventInfo);
  354. }
  355. else {
  356. triggerEffects(deps[0]);
  357. }
  358. }
  359. }
  360. else {
  361. const effects = [];
  362. for (const dep of deps) {
  363. if (dep) {
  364. effects.push(...dep);
  365. }
  366. }
  367. if ((process.env.NODE_ENV !== 'production')) {
  368. triggerEffects(createDep(effects), eventInfo);
  369. }
  370. else {
  371. triggerEffects(createDep(effects));
  372. }
  373. }
  374. }
  375. function triggerEffects(dep, debuggerEventExtraInfo) {
  376. // spread into array for stabilization
  377. const effects = isArray(dep) ? dep : [...dep];
  378. for (const effect of effects) {
  379. if (effect.computed) {
  380. triggerEffect(effect, debuggerEventExtraInfo);
  381. }
  382. }
  383. for (const effect of effects) {
  384. if (!effect.computed) {
  385. triggerEffect(effect, debuggerEventExtraInfo);
  386. }
  387. }
  388. }
  389. function triggerEffect(effect, debuggerEventExtraInfo) {
  390. if (effect !== activeEffect || effect.allowRecurse) {
  391. if ((process.env.NODE_ENV !== 'production') && effect.onTrigger) {
  392. effect.onTrigger(extend({ effect }, debuggerEventExtraInfo));
  393. }
  394. if (effect.scheduler) {
  395. effect.scheduler();
  396. }
  397. else {
  398. effect.run();
  399. }
  400. }
  401. }
  402. function getDepFromReactive(object, key) {
  403. var _a;
  404. return (_a = targetMap.get(object)) === null || _a === void 0 ? void 0 : _a.get(key);
  405. }
  406. const isNonTrackableKeys = /*#__PURE__*/ makeMap(`__proto__,__v_isRef,__isVue`);
  407. const builtInSymbols = new Set(
  408. /*#__PURE__*/
  409. Object.getOwnPropertyNames(Symbol)
  410. // ios10.x Object.getOwnPropertyNames(Symbol) can enumerate 'arguments' and 'caller'
  411. // but accessing them on Symbol leads to TypeError because Symbol is a strict mode
  412. // function
  413. .filter(key => key !== 'arguments' && key !== 'caller')
  414. .map(key => Symbol[key])
  415. .filter(isSymbol));
  416. const get$1 = /*#__PURE__*/ createGetter();
  417. const shallowGet = /*#__PURE__*/ createGetter(false, true);
  418. const readonlyGet = /*#__PURE__*/ createGetter(true);
  419. const shallowReadonlyGet = /*#__PURE__*/ createGetter(true, true);
  420. const arrayInstrumentations = /*#__PURE__*/ createArrayInstrumentations();
  421. function createArrayInstrumentations() {
  422. const instrumentations = {};
  423. ['includes', 'indexOf', 'lastIndexOf'].forEach(key => {
  424. instrumentations[key] = function (...args) {
  425. const arr = toRaw(this);
  426. for (let i = 0, l = this.length; i < l; i++) {
  427. track(arr, "get" /* TrackOpTypes.GET */, i + '');
  428. }
  429. // we run the method using the original args first (which may be reactive)
  430. const res = arr[key](...args);
  431. if (res === -1 || res === false) {
  432. // if that didn't work, run it again using raw values.
  433. return arr[key](...args.map(toRaw));
  434. }
  435. else {
  436. return res;
  437. }
  438. };
  439. });
  440. ['push', 'pop', 'shift', 'unshift', 'splice'].forEach(key => {
  441. instrumentations[key] = function (...args) {
  442. pauseTracking();
  443. const res = toRaw(this)[key].apply(this, args);
  444. resetTracking();
  445. return res;
  446. };
  447. });
  448. return instrumentations;
  449. }
  450. function hasOwnProperty(key) {
  451. const obj = toRaw(this);
  452. track(obj, "has" /* TrackOpTypes.HAS */, key);
  453. return obj.hasOwnProperty(key);
  454. }
  455. function createGetter(isReadonly = false, shallow = false) {
  456. return function get(target, key, receiver) {
  457. if (key === "__v_isReactive" /* ReactiveFlags.IS_REACTIVE */) {
  458. return !isReadonly;
  459. }
  460. else if (key === "__v_isReadonly" /* ReactiveFlags.IS_READONLY */) {
  461. return isReadonly;
  462. }
  463. else if (key === "__v_isShallow" /* ReactiveFlags.IS_SHALLOW */) {
  464. return shallow;
  465. }
  466. else if (key === "__v_raw" /* ReactiveFlags.RAW */ &&
  467. receiver ===
  468. (isReadonly
  469. ? shallow
  470. ? shallowReadonlyMap
  471. : readonlyMap
  472. : shallow
  473. ? shallowReactiveMap
  474. : reactiveMap).get(target)) {
  475. return target;
  476. }
  477. const targetIsArray = isArray(target);
  478. if (!isReadonly) {
  479. if (targetIsArray && hasOwn(arrayInstrumentations, key)) {
  480. return Reflect.get(arrayInstrumentations, key, receiver);
  481. }
  482. if (key === 'hasOwnProperty') {
  483. return hasOwnProperty;
  484. }
  485. }
  486. const res = Reflect.get(target, key, receiver);
  487. if (isSymbol(key) ? builtInSymbols.has(key) : isNonTrackableKeys(key)) {
  488. return res;
  489. }
  490. if (!isReadonly) {
  491. track(target, "get" /* TrackOpTypes.GET */, key);
  492. }
  493. if (shallow) {
  494. return res;
  495. }
  496. if (isRef(res)) {
  497. // ref unwrapping - skip unwrap for Array + integer key.
  498. return targetIsArray && isIntegerKey(key) ? res : res.value;
  499. }
  500. if (isObject(res)) {
  501. // Convert returned value into a proxy as well. we do the isObject check
  502. // here to avoid invalid value warning. Also need to lazy access readonly
  503. // and reactive here to avoid circular dependency.
  504. return isReadonly ? readonly(res) : reactive(res);
  505. }
  506. return res;
  507. };
  508. }
  509. const set$1 = /*#__PURE__*/ createSetter();
  510. const shallowSet = /*#__PURE__*/ createSetter(true);
  511. function createSetter(shallow = false) {
  512. return function set(target, key, value, receiver) {
  513. let oldValue = target[key];
  514. if (isReadonly(oldValue) && isRef(oldValue) && !isRef(value)) {
  515. return false;
  516. }
  517. if (!shallow) {
  518. if (!isShallow(value) && !isReadonly(value)) {
  519. oldValue = toRaw(oldValue);
  520. value = toRaw(value);
  521. }
  522. if (!isArray(target) && isRef(oldValue) && !isRef(value)) {
  523. oldValue.value = value;
  524. return true;
  525. }
  526. }
  527. const hadKey = isArray(target) && isIntegerKey(key)
  528. ? Number(key) < target.length
  529. : hasOwn(target, key);
  530. const result = Reflect.set(target, key, value, receiver);
  531. // don't trigger if target is something up in the prototype chain of original
  532. if (target === toRaw(receiver)) {
  533. if (!hadKey) {
  534. trigger(target, "add" /* TriggerOpTypes.ADD */, key, value);
  535. }
  536. else if (hasChanged(value, oldValue)) {
  537. trigger(target, "set" /* TriggerOpTypes.SET */, key, value, oldValue);
  538. }
  539. }
  540. return result;
  541. };
  542. }
  543. function deleteProperty(target, key) {
  544. const hadKey = hasOwn(target, key);
  545. const oldValue = target[key];
  546. const result = Reflect.deleteProperty(target, key);
  547. if (result && hadKey) {
  548. trigger(target, "delete" /* TriggerOpTypes.DELETE */, key, undefined, oldValue);
  549. }
  550. return result;
  551. }
  552. function has$1(target, key) {
  553. const result = Reflect.has(target, key);
  554. if (!isSymbol(key) || !builtInSymbols.has(key)) {
  555. track(target, "has" /* TrackOpTypes.HAS */, key);
  556. }
  557. return result;
  558. }
  559. function ownKeys(target) {
  560. track(target, "iterate" /* TrackOpTypes.ITERATE */, isArray(target) ? 'length' : ITERATE_KEY);
  561. return Reflect.ownKeys(target);
  562. }
  563. const mutableHandlers = {
  564. get: get$1,
  565. set: set$1,
  566. deleteProperty,
  567. has: has$1,
  568. ownKeys
  569. };
  570. const readonlyHandlers = {
  571. get: readonlyGet,
  572. set(target, key) {
  573. if ((process.env.NODE_ENV !== 'production')) {
  574. warn$1(`Set operation on key "${String(key)}" failed: target is readonly.`, target);
  575. }
  576. return true;
  577. },
  578. deleteProperty(target, key) {
  579. if ((process.env.NODE_ENV !== 'production')) {
  580. warn$1(`Delete operation on key "${String(key)}" failed: target is readonly.`, target);
  581. }
  582. return true;
  583. }
  584. };
  585. const shallowReactiveHandlers = /*#__PURE__*/ extend({}, mutableHandlers, {
  586. get: shallowGet,
  587. set: shallowSet
  588. });
  589. // Props handlers are special in the sense that it should not unwrap top-level
  590. // refs (in order to allow refs to be explicitly passed down), but should
  591. // retain the reactivity of the normal readonly object.
  592. const shallowReadonlyHandlers = /*#__PURE__*/ extend({}, readonlyHandlers, {
  593. get: shallowReadonlyGet
  594. });
  595. const toShallow = (value) => value;
  596. const getProto = (v) => Reflect.getPrototypeOf(v);
  597. function get(target, key, isReadonly = false, isShallow = false) {
  598. // #1772: readonly(reactive(Map)) should return readonly + reactive version
  599. // of the value
  600. target = target["__v_raw" /* ReactiveFlags.RAW */];
  601. const rawTarget = toRaw(target);
  602. const rawKey = toRaw(key);
  603. if (!isReadonly) {
  604. if (key !== rawKey) {
  605. track(rawTarget, "get" /* TrackOpTypes.GET */, key);
  606. }
  607. track(rawTarget, "get" /* TrackOpTypes.GET */, rawKey);
  608. }
  609. const { has } = getProto(rawTarget);
  610. const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
  611. if (has.call(rawTarget, key)) {
  612. return wrap(target.get(key));
  613. }
  614. else if (has.call(rawTarget, rawKey)) {
  615. return wrap(target.get(rawKey));
  616. }
  617. else if (target !== rawTarget) {
  618. // #3602 readonly(reactive(Map))
  619. // ensure that the nested reactive `Map` can do tracking for itself
  620. target.get(key);
  621. }
  622. }
  623. function has(key, isReadonly = false) {
  624. const target = this["__v_raw" /* ReactiveFlags.RAW */];
  625. const rawTarget = toRaw(target);
  626. const rawKey = toRaw(key);
  627. if (!isReadonly) {
  628. if (key !== rawKey) {
  629. track(rawTarget, "has" /* TrackOpTypes.HAS */, key);
  630. }
  631. track(rawTarget, "has" /* TrackOpTypes.HAS */, rawKey);
  632. }
  633. return key === rawKey
  634. ? target.has(key)
  635. : target.has(key) || target.has(rawKey);
  636. }
  637. function size(target, isReadonly = false) {
  638. target = target["__v_raw" /* ReactiveFlags.RAW */];
  639. !isReadonly && track(toRaw(target), "iterate" /* TrackOpTypes.ITERATE */, ITERATE_KEY);
  640. return Reflect.get(target, 'size', target);
  641. }
  642. function add(value) {
  643. value = toRaw(value);
  644. const target = toRaw(this);
  645. const proto = getProto(target);
  646. const hadKey = proto.has.call(target, value);
  647. if (!hadKey) {
  648. target.add(value);
  649. trigger(target, "add" /* TriggerOpTypes.ADD */, value, value);
  650. }
  651. return this;
  652. }
  653. function set(key, value) {
  654. value = toRaw(value);
  655. const target = toRaw(this);
  656. const { has, get } = getProto(target);
  657. let hadKey = has.call(target, key);
  658. if (!hadKey) {
  659. key = toRaw(key);
  660. hadKey = has.call(target, key);
  661. }
  662. else if ((process.env.NODE_ENV !== 'production')) {
  663. checkIdentityKeys(target, has, key);
  664. }
  665. const oldValue = get.call(target, key);
  666. target.set(key, value);
  667. if (!hadKey) {
  668. trigger(target, "add" /* TriggerOpTypes.ADD */, key, value);
  669. }
  670. else if (hasChanged(value, oldValue)) {
  671. trigger(target, "set" /* TriggerOpTypes.SET */, key, value, oldValue);
  672. }
  673. return this;
  674. }
  675. function deleteEntry(key) {
  676. const target = toRaw(this);
  677. const { has, get } = getProto(target);
  678. let hadKey = has.call(target, key);
  679. if (!hadKey) {
  680. key = toRaw(key);
  681. hadKey = has.call(target, key);
  682. }
  683. else if ((process.env.NODE_ENV !== 'production')) {
  684. checkIdentityKeys(target, has, key);
  685. }
  686. const oldValue = get ? get.call(target, key) : undefined;
  687. // forward the operation before queueing reactions
  688. const result = target.delete(key);
  689. if (hadKey) {
  690. trigger(target, "delete" /* TriggerOpTypes.DELETE */, key, undefined, oldValue);
  691. }
  692. return result;
  693. }
  694. function clear() {
  695. const target = toRaw(this);
  696. const hadItems = target.size !== 0;
  697. const oldTarget = (process.env.NODE_ENV !== 'production')
  698. ? isMap(target)
  699. ? new Map(target)
  700. : new Set(target)
  701. : undefined;
  702. // forward the operation before queueing reactions
  703. const result = target.clear();
  704. if (hadItems) {
  705. trigger(target, "clear" /* TriggerOpTypes.CLEAR */, undefined, undefined, oldTarget);
  706. }
  707. return result;
  708. }
  709. function createForEach(isReadonly, isShallow) {
  710. return function forEach(callback, thisArg) {
  711. const observed = this;
  712. const target = observed["__v_raw" /* ReactiveFlags.RAW */];
  713. const rawTarget = toRaw(target);
  714. const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
  715. !isReadonly && track(rawTarget, "iterate" /* TrackOpTypes.ITERATE */, ITERATE_KEY);
  716. return target.forEach((value, key) => {
  717. // important: make sure the callback is
  718. // 1. invoked with the reactive map as `this` and 3rd arg
  719. // 2. the value received should be a corresponding reactive/readonly.
  720. return callback.call(thisArg, wrap(value), wrap(key), observed);
  721. });
  722. };
  723. }
  724. function createIterableMethod(method, isReadonly, isShallow) {
  725. return function (...args) {
  726. const target = this["__v_raw" /* ReactiveFlags.RAW */];
  727. const rawTarget = toRaw(target);
  728. const targetIsMap = isMap(rawTarget);
  729. const isPair = method === 'entries' || (method === Symbol.iterator && targetIsMap);
  730. const isKeyOnly = method === 'keys' && targetIsMap;
  731. const innerIterator = target[method](...args);
  732. const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
  733. !isReadonly &&
  734. track(rawTarget, "iterate" /* TrackOpTypes.ITERATE */, isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY);
  735. // return a wrapped iterator which returns observed versions of the
  736. // values emitted from the real iterator
  737. return {
  738. // iterator protocol
  739. next() {
  740. const { value, done } = innerIterator.next();
  741. return done
  742. ? { value, done }
  743. : {
  744. value: isPair ? [wrap(value[0]), wrap(value[1])] : wrap(value),
  745. done
  746. };
  747. },
  748. // iterable protocol
  749. [Symbol.iterator]() {
  750. return this;
  751. }
  752. };
  753. };
  754. }
  755. function createReadonlyMethod(type) {
  756. return function (...args) {
  757. if ((process.env.NODE_ENV !== 'production')) {
  758. const key = args[0] ? `on key "${args[0]}" ` : ``;
  759. console.warn(`${capitalize(type)} operation ${key}failed: target is readonly.`, toRaw(this));
  760. }
  761. return type === "delete" /* TriggerOpTypes.DELETE */ ? false : this;
  762. };
  763. }
  764. function createInstrumentations() {
  765. const mutableInstrumentations = {
  766. get(key) {
  767. return get(this, key);
  768. },
  769. get size() {
  770. return size(this);
  771. },
  772. has,
  773. add,
  774. set,
  775. delete: deleteEntry,
  776. clear,
  777. forEach: createForEach(false, false)
  778. };
  779. const shallowInstrumentations = {
  780. get(key) {
  781. return get(this, key, false, true);
  782. },
  783. get size() {
  784. return size(this);
  785. },
  786. has,
  787. add,
  788. set,
  789. delete: deleteEntry,
  790. clear,
  791. forEach: createForEach(false, true)
  792. };
  793. const readonlyInstrumentations = {
  794. get(key) {
  795. return get(this, key, true);
  796. },
  797. get size() {
  798. return size(this, true);
  799. },
  800. has(key) {
  801. return has.call(this, key, true);
  802. },
  803. add: createReadonlyMethod("add" /* TriggerOpTypes.ADD */),
  804. set: createReadonlyMethod("set" /* TriggerOpTypes.SET */),
  805. delete: createReadonlyMethod("delete" /* TriggerOpTypes.DELETE */),
  806. clear: createReadonlyMethod("clear" /* TriggerOpTypes.CLEAR */),
  807. forEach: createForEach(true, false)
  808. };
  809. const shallowReadonlyInstrumentations = {
  810. get(key) {
  811. return get(this, key, true, true);
  812. },
  813. get size() {
  814. return size(this, true);
  815. },
  816. has(key) {
  817. return has.call(this, key, true);
  818. },
  819. add: createReadonlyMethod("add" /* TriggerOpTypes.ADD */),
  820. set: createReadonlyMethod("set" /* TriggerOpTypes.SET */),
  821. delete: createReadonlyMethod("delete" /* TriggerOpTypes.DELETE */),
  822. clear: createReadonlyMethod("clear" /* TriggerOpTypes.CLEAR */),
  823. forEach: createForEach(true, true)
  824. };
  825. const iteratorMethods = ['keys', 'values', 'entries', Symbol.iterator];
  826. iteratorMethods.forEach(method => {
  827. mutableInstrumentations[method] = createIterableMethod(method, false, false);
  828. readonlyInstrumentations[method] = createIterableMethod(method, true, false);
  829. shallowInstrumentations[method] = createIterableMethod(method, false, true);
  830. shallowReadonlyInstrumentations[method] = createIterableMethod(method, true, true);
  831. });
  832. return [
  833. mutableInstrumentations,
  834. readonlyInstrumentations,
  835. shallowInstrumentations,
  836. shallowReadonlyInstrumentations
  837. ];
  838. }
  839. const [mutableInstrumentations, readonlyInstrumentations, shallowInstrumentations, shallowReadonlyInstrumentations] = /* #__PURE__*/ createInstrumentations();
  840. function createInstrumentationGetter(isReadonly, shallow) {
  841. const instrumentations = shallow
  842. ? isReadonly
  843. ? shallowReadonlyInstrumentations
  844. : shallowInstrumentations
  845. : isReadonly
  846. ? readonlyInstrumentations
  847. : mutableInstrumentations;
  848. return (target, key, receiver) => {
  849. if (key === "__v_isReactive" /* ReactiveFlags.IS_REACTIVE */) {
  850. return !isReadonly;
  851. }
  852. else if (key === "__v_isReadonly" /* ReactiveFlags.IS_READONLY */) {
  853. return isReadonly;
  854. }
  855. else if (key === "__v_raw" /* ReactiveFlags.RAW */) {
  856. return target;
  857. }
  858. return Reflect.get(hasOwn(instrumentations, key) && key in target
  859. ? instrumentations
  860. : target, key, receiver);
  861. };
  862. }
  863. const mutableCollectionHandlers = {
  864. get: /*#__PURE__*/ createInstrumentationGetter(false, false)
  865. };
  866. const shallowCollectionHandlers = {
  867. get: /*#__PURE__*/ createInstrumentationGetter(false, true)
  868. };
  869. const readonlyCollectionHandlers = {
  870. get: /*#__PURE__*/ createInstrumentationGetter(true, false)
  871. };
  872. const shallowReadonlyCollectionHandlers = {
  873. get: /*#__PURE__*/ createInstrumentationGetter(true, true)
  874. };
  875. function checkIdentityKeys(target, has, key) {
  876. const rawKey = toRaw(key);
  877. if (rawKey !== key && has.call(target, rawKey)) {
  878. const type = toRawType(target);
  879. console.warn(`Reactive ${type} contains both the raw and reactive ` +
  880. `versions of the same object${type === `Map` ? ` as keys` : ``}, ` +
  881. `which can lead to inconsistencies. ` +
  882. `Avoid differentiating between the raw and reactive versions ` +
  883. `of an object and only use the reactive version if possible.`);
  884. }
  885. }
  886. const reactiveMap = new WeakMap();
  887. const shallowReactiveMap = new WeakMap();
  888. const readonlyMap = new WeakMap();
  889. const shallowReadonlyMap = new WeakMap();
  890. function targetTypeMap(rawType) {
  891. switch (rawType) {
  892. case 'Object':
  893. case 'Array':
  894. return 1 /* TargetType.COMMON */;
  895. case 'Map':
  896. case 'Set':
  897. case 'WeakMap':
  898. case 'WeakSet':
  899. return 2 /* TargetType.COLLECTION */;
  900. default:
  901. return 0 /* TargetType.INVALID */;
  902. }
  903. }
  904. function getTargetType(value) {
  905. return value["__v_skip" /* ReactiveFlags.SKIP */] || !Object.isExtensible(value)
  906. ? 0 /* TargetType.INVALID */
  907. : targetTypeMap(toRawType(value));
  908. }
  909. function reactive(target) {
  910. // if trying to observe a readonly proxy, return the readonly version.
  911. if (isReadonly(target)) {
  912. return target;
  913. }
  914. return createReactiveObject(target, false, mutableHandlers, mutableCollectionHandlers, reactiveMap);
  915. }
  916. /**
  917. * Return a shallowly-reactive copy of the original object, where only the root
  918. * level properties are reactive. It also does not auto-unwrap refs (even at the
  919. * root level).
  920. */
  921. function shallowReactive(target) {
  922. return createReactiveObject(target, false, shallowReactiveHandlers, shallowCollectionHandlers, shallowReactiveMap);
  923. }
  924. /**
  925. * Creates a readonly copy of the original object. Note the returned copy is not
  926. * made reactive, but `readonly` can be called on an already reactive object.
  927. */
  928. function readonly(target) {
  929. return createReactiveObject(target, true, readonlyHandlers, readonlyCollectionHandlers, readonlyMap);
  930. }
  931. /**
  932. * Returns a reactive-copy of the original object, where only the root level
  933. * properties are readonly, and does NOT unwrap refs nor recursively convert
  934. * returned properties.
  935. * This is used for creating the props proxy object for stateful components.
  936. */
  937. function shallowReadonly(target) {
  938. return createReactiveObject(target, true, shallowReadonlyHandlers, shallowReadonlyCollectionHandlers, shallowReadonlyMap);
  939. }
  940. function createReactiveObject(target, isReadonly, baseHandlers, collectionHandlers, proxyMap) {
  941. if (!isObject(target)) {
  942. if ((process.env.NODE_ENV !== 'production')) {
  943. console.warn(`value cannot be made reactive: ${String(target)}`);
  944. }
  945. return target;
  946. }
  947. // target is already a Proxy, return it.
  948. // exception: calling readonly() on a reactive object
  949. if (target["__v_raw" /* ReactiveFlags.RAW */] &&
  950. !(isReadonly && target["__v_isReactive" /* ReactiveFlags.IS_REACTIVE */])) {
  951. return target;
  952. }
  953. // target already has corresponding Proxy
  954. const existingProxy = proxyMap.get(target);
  955. if (existingProxy) {
  956. return existingProxy;
  957. }
  958. // only specific value types can be observed.
  959. const targetType = getTargetType(target);
  960. if (targetType === 0 /* TargetType.INVALID */) {
  961. return target;
  962. }
  963. const proxy = new Proxy(target, targetType === 2 /* TargetType.COLLECTION */ ? collectionHandlers : baseHandlers);
  964. proxyMap.set(target, proxy);
  965. return proxy;
  966. }
  967. function isReactive(value) {
  968. if (isReadonly(value)) {
  969. return isReactive(value["__v_raw" /* ReactiveFlags.RAW */]);
  970. }
  971. return !!(value && value["__v_isReactive" /* ReactiveFlags.IS_REACTIVE */]);
  972. }
  973. function isReadonly(value) {
  974. return !!(value && value["__v_isReadonly" /* ReactiveFlags.IS_READONLY */]);
  975. }
  976. function isShallow(value) {
  977. return !!(value && value["__v_isShallow" /* ReactiveFlags.IS_SHALLOW */]);
  978. }
  979. function isProxy(value) {
  980. return isReactive(value) || isReadonly(value);
  981. }
  982. function toRaw(observed) {
  983. const raw = observed && observed["__v_raw" /* ReactiveFlags.RAW */];
  984. return raw ? toRaw(raw) : observed;
  985. }
  986. function markRaw(value) {
  987. def(value, "__v_skip" /* ReactiveFlags.SKIP */, true);
  988. return value;
  989. }
  990. const toReactive = (value) => isObject(value) ? reactive(value) : value;
  991. const toReadonly = (value) => isObject(value) ? readonly(value) : value;
  992. function trackRefValue(ref) {
  993. if (shouldTrack && activeEffect) {
  994. ref = toRaw(ref);
  995. if ((process.env.NODE_ENV !== 'production')) {
  996. trackEffects(ref.dep || (ref.dep = createDep()), {
  997. target: ref,
  998. type: "get" /* TrackOpTypes.GET */,
  999. key: 'value'
  1000. });
  1001. }
  1002. else {
  1003. trackEffects(ref.dep || (ref.dep = createDep()));
  1004. }
  1005. }
  1006. }
  1007. function triggerRefValue(ref, newVal) {
  1008. ref = toRaw(ref);
  1009. const dep = ref.dep;
  1010. if (dep) {
  1011. if ((process.env.NODE_ENV !== 'production')) {
  1012. triggerEffects(dep, {
  1013. target: ref,
  1014. type: "set" /* TriggerOpTypes.SET */,
  1015. key: 'value',
  1016. newValue: newVal
  1017. });
  1018. }
  1019. else {
  1020. triggerEffects(dep);
  1021. }
  1022. }
  1023. }
  1024. function isRef(r) {
  1025. return !!(r && r.__v_isRef === true);
  1026. }
  1027. function ref(value) {
  1028. return createRef(value, false);
  1029. }
  1030. function shallowRef(value) {
  1031. return createRef(value, true);
  1032. }
  1033. function createRef(rawValue, shallow) {
  1034. if (isRef(rawValue)) {
  1035. return rawValue;
  1036. }
  1037. return new RefImpl(rawValue, shallow);
  1038. }
  1039. class RefImpl {
  1040. constructor(value, __v_isShallow) {
  1041. this.__v_isShallow = __v_isShallow;
  1042. this.dep = undefined;
  1043. this.__v_isRef = true;
  1044. this._rawValue = __v_isShallow ? value : toRaw(value);
  1045. this._value = __v_isShallow ? value : toReactive(value);
  1046. }
  1047. get value() {
  1048. trackRefValue(this);
  1049. return this._value;
  1050. }
  1051. set value(newVal) {
  1052. const useDirectValue = this.__v_isShallow || isShallow(newVal) || isReadonly(newVal);
  1053. newVal = useDirectValue ? newVal : toRaw(newVal);
  1054. if (hasChanged(newVal, this._rawValue)) {
  1055. this._rawValue = newVal;
  1056. this._value = useDirectValue ? newVal : toReactive(newVal);
  1057. triggerRefValue(this, newVal);
  1058. }
  1059. }
  1060. }
  1061. function triggerRef(ref) {
  1062. triggerRefValue(ref, (process.env.NODE_ENV !== 'production') ? ref.value : void 0);
  1063. }
  1064. function unref(ref) {
  1065. return isRef(ref) ? ref.value : ref;
  1066. }
  1067. const shallowUnwrapHandlers = {
  1068. get: (target, key, receiver) => unref(Reflect.get(target, key, receiver)),
  1069. set: (target, key, value, receiver) => {
  1070. const oldValue = target[key];
  1071. if (isRef(oldValue) && !isRef(value)) {
  1072. oldValue.value = value;
  1073. return true;
  1074. }
  1075. else {
  1076. return Reflect.set(target, key, value, receiver);
  1077. }
  1078. }
  1079. };
  1080. function proxyRefs(objectWithRefs) {
  1081. return isReactive(objectWithRefs)
  1082. ? objectWithRefs
  1083. : new Proxy(objectWithRefs, shallowUnwrapHandlers);
  1084. }
  1085. class CustomRefImpl {
  1086. constructor(factory) {
  1087. this.dep = undefined;
  1088. this.__v_isRef = true;
  1089. const { get, set } = factory(() => trackRefValue(this), () => triggerRefValue(this));
  1090. this._get = get;
  1091. this._set = set;
  1092. }
  1093. get value() {
  1094. return this._get();
  1095. }
  1096. set value(newVal) {
  1097. this._set(newVal);
  1098. }
  1099. }
  1100. function customRef(factory) {
  1101. return new CustomRefImpl(factory);
  1102. }
  1103. function toRefs(object) {
  1104. if ((process.env.NODE_ENV !== 'production') && !isProxy(object)) {
  1105. console.warn(`toRefs() expects a reactive object but received a plain one.`);
  1106. }
  1107. const ret = isArray(object) ? new Array(object.length) : {};
  1108. for (const key in object) {
  1109. ret[key] = toRef(object, key);
  1110. }
  1111. return ret;
  1112. }
  1113. class ObjectRefImpl {
  1114. constructor(_object, _key, _defaultValue) {
  1115. this._object = _object;
  1116. this._key = _key;
  1117. this._defaultValue = _defaultValue;
  1118. this.__v_isRef = true;
  1119. }
  1120. get value() {
  1121. const val = this._object[this._key];
  1122. return val === undefined ? this._defaultValue : val;
  1123. }
  1124. set value(newVal) {
  1125. this._object[this._key] = newVal;
  1126. }
  1127. get dep() {
  1128. return getDepFromReactive(toRaw(this._object), this._key);
  1129. }
  1130. }
  1131. function toRef(object, key, defaultValue) {
  1132. const val = object[key];
  1133. return isRef(val)
  1134. ? val
  1135. : new ObjectRefImpl(object, key, defaultValue);
  1136. }
  1137. var _a;
  1138. class ComputedRefImpl {
  1139. constructor(getter, _setter, isReadonly, isSSR) {
  1140. this._setter = _setter;
  1141. this.dep = undefined;
  1142. this.__v_isRef = true;
  1143. this[_a] = false;
  1144. this._dirty = true;
  1145. this.effect = new ReactiveEffect(getter, () => {
  1146. if (!this._dirty) {
  1147. this._dirty = true;
  1148. triggerRefValue(this);
  1149. }
  1150. });
  1151. this.effect.computed = this;
  1152. this.effect.active = this._cacheable = !isSSR;
  1153. this["__v_isReadonly" /* ReactiveFlags.IS_READONLY */] = isReadonly;
  1154. }
  1155. get value() {
  1156. // the computed ref may get wrapped by other proxies e.g. readonly() #3376
  1157. const self = toRaw(this);
  1158. trackRefValue(self);
  1159. if (self._dirty || !self._cacheable) {
  1160. self._dirty = false;
  1161. self._value = self.effect.run();
  1162. }
  1163. return self._value;
  1164. }
  1165. set value(newValue) {
  1166. this._setter(newValue);
  1167. }
  1168. }
  1169. _a = "__v_isReadonly" /* ReactiveFlags.IS_READONLY */;
  1170. function computed$1(getterOrOptions, debugOptions, isSSR = false) {
  1171. let getter;
  1172. let setter;
  1173. const onlyGetter = isFunction(getterOrOptions);
  1174. if (onlyGetter) {
  1175. getter = getterOrOptions;
  1176. setter = (process.env.NODE_ENV !== 'production')
  1177. ? () => {
  1178. console.warn('Write operation failed: computed value is readonly');
  1179. }
  1180. : NOOP;
  1181. }
  1182. else {
  1183. getter = getterOrOptions.get;
  1184. setter = getterOrOptions.set;
  1185. }
  1186. const cRef = new ComputedRefImpl(getter, setter, onlyGetter || !setter, isSSR);
  1187. if ((process.env.NODE_ENV !== 'production') && debugOptions && !isSSR) {
  1188. cRef.effect.onTrack = debugOptions.onTrack;
  1189. cRef.effect.onTrigger = debugOptions.onTrigger;
  1190. }
  1191. return cRef;
  1192. }
  1193. const stack = [];
  1194. function pushWarningContext(vnode) {
  1195. stack.push(vnode);
  1196. }
  1197. function popWarningContext() {
  1198. stack.pop();
  1199. }
  1200. function warn(msg, ...args) {
  1201. if (!(process.env.NODE_ENV !== 'production'))
  1202. return;
  1203. // avoid props formatting or warn handler tracking deps that might be mutated
  1204. // during patch, leading to infinite recursion.
  1205. pauseTracking();
  1206. const instance = stack.length ? stack[stack.length - 1].component : null;
  1207. const appWarnHandler = instance && instance.appContext.config.warnHandler;
  1208. const trace = getComponentTrace();
  1209. if (appWarnHandler) {
  1210. // fixed by xxxxxx Cannot convert a Symbol value to a string
  1211. if (args.length) {
  1212. args[0] = String(args[0]);
  1213. }
  1214. callWithErrorHandling(appWarnHandler, instance, 11 /* ErrorCodes.APP_WARN_HANDLER */, [
  1215. msg + args.join(''),
  1216. instance && instance.proxy,
  1217. trace
  1218. .map(({ vnode }) => `at <${formatComponentName(instance, vnode.type)}>`)
  1219. .join('\n'),
  1220. trace
  1221. ]);
  1222. }
  1223. else {
  1224. const warnArgs = [`[Vue warn]: ${msg}`, ...args];
  1225. /* istanbul ignore if */
  1226. if (trace.length &&
  1227. // avoid spamming console during tests
  1228. !false) {
  1229. warnArgs.push(`\n`, ...formatTrace(trace));
  1230. }
  1231. console.warn(...warnArgs);
  1232. }
  1233. resetTracking();
  1234. }
  1235. function getComponentTrace() {
  1236. let currentVNode = stack[stack.length - 1];
  1237. if (!currentVNode) {
  1238. return [];
  1239. }
  1240. // we can't just use the stack because it will be incomplete during updates
  1241. // that did not start from the root. Re-construct the parent chain using
  1242. // instance parent pointers.
  1243. const normalizedStack = [];
  1244. while (currentVNode) {
  1245. const last = normalizedStack[0];
  1246. if (last && last.vnode === currentVNode) {
  1247. last.recurseCount++;
  1248. }
  1249. else {
  1250. normalizedStack.push({
  1251. vnode: currentVNode,
  1252. recurseCount: 0
  1253. });
  1254. }
  1255. const parentInstance = currentVNode.component && currentVNode.component.parent;
  1256. currentVNode = parentInstance && parentInstance.vnode;
  1257. }
  1258. return normalizedStack;
  1259. }
  1260. /* istanbul ignore next */
  1261. function formatTrace(trace) {
  1262. const logs = [];
  1263. trace.forEach((entry, i) => {
  1264. logs.push(...(i === 0 ? [] : [`\n`]), ...formatTraceEntry(entry));
  1265. });
  1266. return logs;
  1267. }
  1268. function formatTraceEntry({ vnode, recurseCount }) {
  1269. const postfix = recurseCount > 0 ? `... (${recurseCount} recursive calls)` : ``;
  1270. const isRoot = vnode.component ? vnode.component.parent == null : false;
  1271. const open = ` at <${formatComponentName(vnode.component, vnode.type, isRoot)}`;
  1272. const close = `>` + postfix;
  1273. return vnode.props
  1274. ? [open, ...formatProps(vnode.props), close]
  1275. : [open + close];
  1276. }
  1277. /* istanbul ignore next */
  1278. function formatProps(props) {
  1279. const res = [];
  1280. const keys = Object.keys(props);
  1281. keys.slice(0, 3).forEach(key => {
  1282. res.push(...formatProp(key, props[key]));
  1283. });
  1284. if (keys.length > 3) {
  1285. res.push(` ...`);
  1286. }
  1287. return res;
  1288. }
  1289. /* istanbul ignore next */
  1290. function formatProp(key, value, raw) {
  1291. if (isString(value)) {
  1292. value = JSON.stringify(value);
  1293. return raw ? value : [`${key}=${value}`];
  1294. }
  1295. else if (typeof value === 'number' ||
  1296. typeof value === 'boolean' ||
  1297. value == null) {
  1298. return raw ? value : [`${key}=${value}`];
  1299. }
  1300. else if (isRef(value)) {
  1301. value = formatProp(key, toRaw(value.value), true);
  1302. return raw ? value : [`${key}=Ref<`, value, `>`];
  1303. }
  1304. else if (isFunction(value)) {
  1305. return [`${key}=fn${value.name ? `<${value.name}>` : ``}`];
  1306. }
  1307. else {
  1308. value = toRaw(value);
  1309. return raw ? value : [`${key}=`, value];
  1310. }
  1311. }
  1312. /**
  1313. * @internal
  1314. */
  1315. function assertNumber(val, type) {
  1316. if (!(process.env.NODE_ENV !== 'production'))
  1317. return;
  1318. if (val === undefined) {
  1319. return;
  1320. }
  1321. else if (typeof val !== 'number') {
  1322. warn(`${type} is not a valid number - ` + `got ${JSON.stringify(val)}.`);
  1323. }
  1324. else if (isNaN(val)) {
  1325. warn(`${type} is NaN - ` + 'the duration expression might be incorrect.');
  1326. }
  1327. }
  1328. const ErrorTypeStrings = {
  1329. ["sp" /* LifecycleHooks.SERVER_PREFETCH */]: 'serverPrefetch hook',
  1330. ["bc" /* LifecycleHooks.BEFORE_CREATE */]: 'beforeCreate hook',
  1331. ["c" /* LifecycleHooks.CREATED */]: 'created hook',
  1332. ["bm" /* LifecycleHooks.BEFORE_MOUNT */]: 'beforeMount hook',
  1333. ["m" /* LifecycleHooks.MOUNTED */]: 'mounted hook',
  1334. ["bu" /* LifecycleHooks.BEFORE_UPDATE */]: 'beforeUpdate hook',
  1335. ["u" /* LifecycleHooks.UPDATED */]: 'updated',
  1336. ["bum" /* LifecycleHooks.BEFORE_UNMOUNT */]: 'beforeUnmount hook',
  1337. ["um" /* LifecycleHooks.UNMOUNTED */]: 'unmounted hook',
  1338. ["ba" /* LifecycleHooks.BEFORE_ACTIVATE */]: 'beforeActivate hook',
  1339. ["a" /* LifecycleHooks.ACTIVATED */]: 'activated hook',
  1340. ["bda" /* LifecycleHooks.BEFORE_DEACTIVATE */]: 'beforeDeactivate hook',
  1341. ["da" /* LifecycleHooks.DEACTIVATED */]: 'deactivated hook',
  1342. ["ec" /* LifecycleHooks.ERROR_CAPTURED */]: 'errorCaptured hook',
  1343. ["rtc" /* LifecycleHooks.RENDER_TRACKED */]: 'renderTracked hook',
  1344. ["rtg" /* LifecycleHooks.RENDER_TRIGGERED */]: 'renderTriggered hook',
  1345. [0 /* ErrorCodes.SETUP_FUNCTION */]: 'setup function',
  1346. [1 /* ErrorCodes.RENDER_FUNCTION */]: 'render function',
  1347. [2 /* ErrorCodes.WATCH_GETTER */]: 'watcher getter',
  1348. [3 /* ErrorCodes.WATCH_CALLBACK */]: 'watcher callback',
  1349. [4 /* ErrorCodes.WATCH_CLEANUP */]: 'watcher cleanup function',
  1350. [5 /* ErrorCodes.NATIVE_EVENT_HANDLER */]: 'native event handler',
  1351. [6 /* ErrorCodes.COMPONENT_EVENT_HANDLER */]: 'component event handler',
  1352. [7 /* ErrorCodes.VNODE_HOOK */]: 'vnode hook',
  1353. [8 /* ErrorCodes.DIRECTIVE_HOOK */]: 'directive hook',
  1354. [9 /* ErrorCodes.TRANSITION_HOOK */]: 'transition hook',
  1355. [10 /* ErrorCodes.APP_ERROR_HANDLER */]: 'app errorHandler',
  1356. [11 /* ErrorCodes.APP_WARN_HANDLER */]: 'app warnHandler',
  1357. [12 /* ErrorCodes.FUNCTION_REF */]: 'ref function',
  1358. [13 /* ErrorCodes.ASYNC_COMPONENT_LOADER */]: 'async component loader',
  1359. [14 /* ErrorCodes.SCHEDULER */]: 'scheduler flush. This is likely a Vue internals bug. ' +
  1360. 'Please open an issue at https://new-issue.vuejs.org/?repo=vuejs/core'
  1361. };
  1362. function callWithErrorHandling(fn, instance, type, args) {
  1363. let res;
  1364. try {
  1365. res = args ? fn(...args) : fn();
  1366. }
  1367. catch (err) {
  1368. handleError(err, instance, type);
  1369. }
  1370. return res;
  1371. }
  1372. function callWithAsyncErrorHandling(fn, instance, type, args) {
  1373. if (isFunction(fn)) {
  1374. const res = callWithErrorHandling(fn, instance, type, args);
  1375. if (res && isPromise(res)) {
  1376. res.catch(err => {
  1377. handleError(err, instance, type);
  1378. });
  1379. }
  1380. return res;
  1381. }
  1382. const values = [];
  1383. for (let i = 0; i < fn.length; i++) {
  1384. values.push(callWithAsyncErrorHandling(fn[i], instance, type, args));
  1385. }
  1386. return values;
  1387. }
  1388. function handleError(err, instance, type, throwInDev = true) {
  1389. const contextVNode = instance ? instance.vnode : null;
  1390. if (instance) {
  1391. let cur = instance.parent;
  1392. // the exposed instance is the render proxy to keep it consistent with 2.x
  1393. const exposedInstance = instance.proxy;
  1394. // in production the hook receives only the error code
  1395. // fixed by xxxxxx
  1396. const errorInfo = (process.env.NODE_ENV !== 'production') ? ErrorTypeStrings[type] || type : type;
  1397. while (cur) {
  1398. const errorCapturedHooks = cur.ec;
  1399. if (errorCapturedHooks) {
  1400. for (let i = 0; i < errorCapturedHooks.length; i++) {
  1401. if (errorCapturedHooks[i](err, exposedInstance, errorInfo) === false) {
  1402. return;
  1403. }
  1404. }
  1405. }
  1406. cur = cur.parent;
  1407. }
  1408. // app-level handling
  1409. const appErrorHandler = instance.appContext.config.errorHandler;
  1410. if (appErrorHandler) {
  1411. callWithErrorHandling(appErrorHandler, null, 10 /* ErrorCodes.APP_ERROR_HANDLER */, [err, exposedInstance, errorInfo]);
  1412. return;
  1413. }
  1414. }
  1415. logError(err, type, contextVNode, throwInDev);
  1416. }
  1417. function logError(err, type, contextVNode, throwInDev = true) {
  1418. if ((process.env.NODE_ENV !== 'production')) {
  1419. const info = ErrorTypeStrings[type] || type; // fixed by xxxxxx
  1420. if (contextVNode) {
  1421. pushWarningContext(contextVNode);
  1422. }
  1423. warn(`Unhandled error${info ? ` during execution of ${info}` : ``}`);
  1424. if (contextVNode) {
  1425. popWarningContext();
  1426. }
  1427. // crash in dev by default so it's more noticeable
  1428. // 不要 crash,经常会导致整个App运行失败,比如路由跳转失败,不能返回了
  1429. /* if (throwInDev) {
  1430. throw err
  1431. } else */ {
  1432. console.error(err);
  1433. }
  1434. }
  1435. else {
  1436. // recover in prod to reduce the impact on end-user
  1437. console.error(err);
  1438. }
  1439. }
  1440. let isFlushing = false;
  1441. let isFlushPending = false;
  1442. const queue = [];
  1443. let flushIndex = 0;
  1444. const pendingPostFlushCbs = [];
  1445. let activePostFlushCbs = null;
  1446. let postFlushIndex = 0;
  1447. const resolvedPromise = /*#__PURE__*/ Promise.resolve();
  1448. let currentFlushPromise = null;
  1449. const RECURSION_LIMIT = 100;
  1450. function nextTick(fn) {
  1451. const p = currentFlushPromise || resolvedPromise;
  1452. return fn ? p.then(this ? fn.bind(this) : fn) : p;
  1453. }
  1454. // #2768
  1455. // Use binary-search to find a suitable position in the queue,
  1456. // so that the queue maintains the increasing order of job's id,
  1457. // which can prevent the job from being skipped and also can avoid repeated patching.
  1458. function findInsertionIndex(id) {
  1459. // the start index should be `flushIndex + 1`
  1460. let start = flushIndex + 1;
  1461. let end = queue.length;
  1462. while (start < end) {
  1463. const middle = (start + end) >>> 1;
  1464. const middleJobId = getId(queue[middle]);
  1465. middleJobId < id ? (start = middle + 1) : (end = middle);
  1466. }
  1467. return start;
  1468. }
  1469. function queueJob(job) {
  1470. // the dedupe search uses the startIndex argument of Array.includes()
  1471. // by default the search index includes the current job that is being run
  1472. // so it cannot recursively trigger itself again.
  1473. // if the job is a watch() callback, the search will start with a +1 index to
  1474. // allow it recursively trigger itself - it is the user's responsibility to
  1475. // ensure it doesn't end up in an infinite loop.
  1476. if (!queue.length ||
  1477. !queue.includes(job, isFlushing && job.allowRecurse ? flushIndex + 1 : flushIndex)) {
  1478. if (job.id == null) {
  1479. queue.push(job);
  1480. }
  1481. else {
  1482. queue.splice(findInsertionIndex(job.id), 0, job);
  1483. }
  1484. queueFlush();
  1485. }
  1486. }
  1487. function queueFlush() {
  1488. if (!isFlushing && !isFlushPending) {
  1489. isFlushPending = true;
  1490. currentFlushPromise = resolvedPromise.then(flushJobs);
  1491. }
  1492. }
  1493. function invalidateJob(job) {
  1494. const i = queue.indexOf(job);
  1495. if (i > flushIndex) {
  1496. queue.splice(i, 1);
  1497. }
  1498. }
  1499. function queuePostFlushCb(cb) {
  1500. if (!isArray(cb)) {
  1501. if (!activePostFlushCbs ||
  1502. !activePostFlushCbs.includes(cb, cb.allowRecurse ? postFlushIndex + 1 : postFlushIndex)) {
  1503. pendingPostFlushCbs.push(cb);
  1504. }
  1505. }
  1506. else {
  1507. // if cb is an array, it is a component lifecycle hook which can only be
  1508. // triggered by a job, which is already deduped in the main queue, so
  1509. // we can skip duplicate check here to improve perf
  1510. pendingPostFlushCbs.push(...cb);
  1511. }
  1512. queueFlush();
  1513. }
  1514. function flushPreFlushCbs(seen,
  1515. // if currently flushing, skip the current job itself
  1516. i = isFlushing ? flushIndex + 1 : 0) {
  1517. if ((process.env.NODE_ENV !== 'production')) {
  1518. seen = seen || new Map();
  1519. }
  1520. for (; i < queue.length; i++) {
  1521. const cb = queue[i];
  1522. if (cb && cb.pre) {
  1523. if ((process.env.NODE_ENV !== 'production') && checkRecursiveUpdates(seen, cb)) {
  1524. continue;
  1525. }
  1526. queue.splice(i, 1);
  1527. i--;
  1528. cb();
  1529. }
  1530. }
  1531. }
  1532. function flushPostFlushCbs(seen) {
  1533. if (pendingPostFlushCbs.length) {
  1534. const deduped = [...new Set(pendingPostFlushCbs)];
  1535. pendingPostFlushCbs.length = 0;
  1536. // #1947 already has active queue, nested flushPostFlushCbs call
  1537. if (activePostFlushCbs) {
  1538. activePostFlushCbs.push(...deduped);
  1539. return;
  1540. }
  1541. activePostFlushCbs = deduped;
  1542. if ((process.env.NODE_ENV !== 'production')) {
  1543. seen = seen || new Map();
  1544. }
  1545. activePostFlushCbs.sort((a, b) => getId(a) - getId(b));
  1546. for (postFlushIndex = 0; postFlushIndex < activePostFlushCbs.length; postFlushIndex++) {
  1547. if ((process.env.NODE_ENV !== 'production') &&
  1548. checkRecursiveUpdates(seen, activePostFlushCbs[postFlushIndex])) {
  1549. continue;
  1550. }
  1551. activePostFlushCbs[postFlushIndex]();
  1552. }
  1553. activePostFlushCbs = null;
  1554. postFlushIndex = 0;
  1555. }
  1556. }
  1557. const getId = (job) => job.id == null ? Infinity : job.id;
  1558. const comparator = (a, b) => {
  1559. const diff = getId(a) - getId(b);
  1560. if (diff === 0) {
  1561. if (a.pre && !b.pre)
  1562. return -1;
  1563. if (b.pre && !a.pre)
  1564. return 1;
  1565. }
  1566. return diff;
  1567. };
  1568. function flushJobs(seen) {
  1569. isFlushPending = false;
  1570. isFlushing = true;
  1571. if ((process.env.NODE_ENV !== 'production')) {
  1572. seen = seen || new Map();
  1573. }
  1574. // Sort queue before flush.
  1575. // This ensures that:
  1576. // 1. Components are updated from parent to child. (because parent is always
  1577. // created before the child so its render effect will have smaller
  1578. // priority number)
  1579. // 2. If a component is unmounted during a parent component's update,
  1580. // its update can be skipped.
  1581. queue.sort(comparator);
  1582. // conditional usage of checkRecursiveUpdate must be determined out of
  1583. // try ... catch block since Rollup by default de-optimizes treeshaking
  1584. // inside try-catch. This can leave all warning code unshaked. Although
  1585. // they would get eventually shaken by a minifier like terser, some minifiers
  1586. // would fail to do that (e.g. https://github.com/evanw/esbuild/issues/1610)
  1587. const check = (process.env.NODE_ENV !== 'production')
  1588. ? (job) => checkRecursiveUpdates(seen, job)
  1589. : NOOP;
  1590. try {
  1591. for (flushIndex = 0; flushIndex < queue.length; flushIndex++) {
  1592. const job = queue[flushIndex];
  1593. if (job && job.active !== false) {
  1594. if ((process.env.NODE_ENV !== 'production') && check(job)) {
  1595. continue;
  1596. }
  1597. // console.log(`running:`, job.id)
  1598. callWithErrorHandling(job, null, 14 /* ErrorCodes.SCHEDULER */);
  1599. }
  1600. }
  1601. }
  1602. finally {
  1603. flushIndex = 0;
  1604. queue.length = 0;
  1605. flushPostFlushCbs(seen);
  1606. isFlushing = false;
  1607. currentFlushPromise = null;
  1608. // some postFlushCb queued jobs!
  1609. // keep flushing until it drains.
  1610. if (queue.length || pendingPostFlushCbs.length) {
  1611. flushJobs(seen);
  1612. }
  1613. }
  1614. }
  1615. function checkRecursiveUpdates(seen, fn) {
  1616. if (!seen.has(fn)) {
  1617. seen.set(fn, 1);
  1618. }
  1619. else {
  1620. const count = seen.get(fn);
  1621. if (count > RECURSION_LIMIT) {
  1622. const instance = fn.ownerInstance;
  1623. const componentName = instance && getComponentName(instance.type);
  1624. warn(`Maximum recursive updates exceeded${componentName ? ` in component <${componentName}>` : ``}. ` +
  1625. `This means you have a reactive effect that is mutating its own ` +
  1626. `dependencies and thus recursively triggering itself. Possible sources ` +
  1627. `include component template, render function, updated hook or ` +
  1628. `watcher source function.`);
  1629. return true;
  1630. }
  1631. else {
  1632. seen.set(fn, count + 1);
  1633. }
  1634. }
  1635. }
  1636. /* eslint-disable no-restricted-globals */
  1637. let isHmrUpdating = false;
  1638. const hmrDirtyComponents = new Set();
  1639. // Expose the HMR runtime on the global object
  1640. // This makes it entirely tree-shakable without polluting the exports and makes
  1641. // it easier to be used in toolings like vue-loader
  1642. // Note: for a component to be eligible for HMR it also needs the __hmrId option
  1643. // to be set so that its instances can be registered / removed.
  1644. if ((process.env.NODE_ENV !== 'production')) {
  1645. getGlobalThis().__VUE_HMR_RUNTIME__ = {
  1646. createRecord: tryWrap(createRecord),
  1647. rerender: tryWrap(rerender),
  1648. reload: tryWrap(reload)
  1649. };
  1650. }
  1651. const map = new Map();
  1652. function registerHMR(instance) {
  1653. const id = instance.type.__hmrId;
  1654. let record = map.get(id);
  1655. if (!record) {
  1656. createRecord(id, instance.type);
  1657. record = map.get(id);
  1658. }
  1659. record.instances.add(instance);
  1660. }
  1661. function unregisterHMR(instance) {
  1662. map.get(instance.type.__hmrId).instances.delete(instance);
  1663. }
  1664. function createRecord(id, initialDef) {
  1665. if (map.has(id)) {
  1666. return false;
  1667. }
  1668. map.set(id, {
  1669. initialDef: normalizeClassComponent(initialDef),
  1670. instances: new Set()
  1671. });
  1672. return true;
  1673. }
  1674. function normalizeClassComponent(component) {
  1675. return isClassComponent(component) ? component.__vccOpts : component;
  1676. }
  1677. function rerender(id, newRender) {
  1678. const record = map.get(id);
  1679. if (!record) {
  1680. return;
  1681. }
  1682. // update initial record (for not-yet-rendered component)
  1683. record.initialDef.render = newRender;
  1684. [...record.instances].forEach(instance => {
  1685. if (newRender) {
  1686. instance.render = newRender;
  1687. normalizeClassComponent(instance.type).render = newRender;
  1688. }
  1689. instance.renderCache = [];
  1690. // this flag forces child components with slot content to update
  1691. isHmrUpdating = true;
  1692. instance.update();
  1693. isHmrUpdating = false;
  1694. });
  1695. }
  1696. function reload(id, newComp) {
  1697. const record = map.get(id);
  1698. if (!record)
  1699. return;
  1700. // fixed by xxxxxx 解决页面刷新 setupPage
  1701. if (typeof window !== 'undefined' &&
  1702. window.__setupPage &&
  1703. record.initialDef.__mpType === 'page') {
  1704. newComp = window.__setupPage(newComp);
  1705. }
  1706. newComp = normalizeClassComponent(newComp);
  1707. // update initial def (for not-yet-rendered components)
  1708. updateComponentDef(record.initialDef, newComp);
  1709. // create a snapshot which avoids the set being mutated during updates
  1710. const instances = [...record.instances];
  1711. for (const instance of instances) {
  1712. const oldComp = normalizeClassComponent(instance.type);
  1713. if (!hmrDirtyComponents.has(oldComp)) {
  1714. // 1. Update existing comp definition to match new one
  1715. if (oldComp !== record.initialDef) {
  1716. updateComponentDef(oldComp, newComp);
  1717. }
  1718. // 2. mark definition dirty. This forces the renderer to replace the
  1719. // component on patch.
  1720. hmrDirtyComponents.add(oldComp);
  1721. }
  1722. // 3. invalidate options resolution cache
  1723. instance.appContext.optionsCache.delete(instance.type);
  1724. // 4. actually update
  1725. if (instance.ceReload) {
  1726. // custom element
  1727. hmrDirtyComponents.add(oldComp);
  1728. instance.ceReload(newComp.styles);
  1729. hmrDirtyComponents.delete(oldComp);
  1730. }
  1731. else if (instance.parent) {
  1732. // 4. Force the parent instance to re-render. This will cause all updated
  1733. // components to be unmounted and re-mounted. Queue the update so that we
  1734. // don't end up forcing the same parent to re-render multiple times.
  1735. queueJob(instance.parent.update);
  1736. }
  1737. else if (instance.appContext.reload) {
  1738. // root instance mounted via createApp() has a reload method
  1739. instance.appContext.reload();
  1740. }
  1741. else if (typeof window !== 'undefined') {
  1742. // root instance inside tree created via raw render(). Force reload.
  1743. window.location.reload();
  1744. }
  1745. else {
  1746. console.warn('[HMR] Root or manually mounted instance modified. Full reload required.');
  1747. }
  1748. }
  1749. // 5. make sure to cleanup dirty hmr components after update
  1750. queuePostFlushCb(() => {
  1751. for (const instance of instances) {
  1752. hmrDirtyComponents.delete(normalizeClassComponent(instance.type));
  1753. }
  1754. });
  1755. }
  1756. function updateComponentDef(oldComp, newComp) {
  1757. extend(oldComp, newComp);
  1758. for (const key in oldComp) {
  1759. if (key !== '__file' && !(key in newComp)) {
  1760. delete oldComp[key];
  1761. }
  1762. }
  1763. }
  1764. function tryWrap(fn) {
  1765. return (id, arg) => {
  1766. try {
  1767. return fn(id, arg);
  1768. }
  1769. catch (e) {
  1770. console.error(e);
  1771. console.warn(`[HMR] Something went wrong during Vue component hot-reload. ` +
  1772. `Full reload required.`);
  1773. }
  1774. };
  1775. }
  1776. let devtools;
  1777. let buffer = [];
  1778. let devtoolsNotInstalled = false;
  1779. function emit$1(event, ...args) {
  1780. if (devtools) {
  1781. devtools.emit(event, ...args);
  1782. }
  1783. else if (!devtoolsNotInstalled) {
  1784. buffer.push({ event, args });
  1785. }
  1786. }
  1787. function setDevtoolsHook(hook, target) {
  1788. var _a, _b;
  1789. devtools = hook;
  1790. if (devtools) {
  1791. devtools.enabled = true;
  1792. buffer.forEach(({ event, args }) => devtools.emit(event, ...args));
  1793. buffer = [];
  1794. }
  1795. else if (
  1796. // handle late devtools injection - only do this if we are in an actual
  1797. // browser environment to avoid the timer handle stalling test runner exit
  1798. // (#4815)
  1799. typeof window !== 'undefined' &&
  1800. // some envs mock window but not fully
  1801. // eslint-disable-next-line no-restricted-globals
  1802. window.HTMLElement &&
  1803. // also exclude jsdom
  1804. // eslint-disable-next-line no-restricted-globals
  1805. !((_b = (_a = window.navigator) === null || _a === void 0 ? void 0 : _a.userAgent) === null || _b === void 0 ? void 0 : _b.includes('jsdom'))) {
  1806. const replay = (target.__VUE_DEVTOOLS_HOOK_REPLAY__ =
  1807. target.__VUE_DEVTOOLS_HOOK_REPLAY__ || []);
  1808. replay.push((newHook) => {
  1809. setDevtoolsHook(newHook, target);
  1810. });
  1811. // clear buffer after 3s - the user probably doesn't have devtools installed
  1812. // at all, and keeping the buffer will cause memory leaks (#4738)
  1813. setTimeout(() => {
  1814. if (!devtools) {
  1815. target.__VUE_DEVTOOLS_HOOK_REPLAY__ = null;
  1816. devtoolsNotInstalled = true;
  1817. buffer = [];
  1818. }
  1819. }, 3000);
  1820. }
  1821. else {
  1822. // non-browser env, assume not installed
  1823. devtoolsNotInstalled = true;
  1824. buffer = [];
  1825. }
  1826. }
  1827. function devtoolsInitApp(app, version) {
  1828. emit$1("app:init" /* DevtoolsHooks.APP_INIT */, app, version, {
  1829. Fragment,
  1830. Text,
  1831. Comment,
  1832. Static
  1833. });
  1834. }
  1835. function devtoolsUnmountApp(app) {
  1836. emit$1("app:unmount" /* DevtoolsHooks.APP_UNMOUNT */, app);
  1837. }
  1838. const devtoolsComponentAdded = /*#__PURE__*/ createDevtoolsComponentHook("component:added" /* DevtoolsHooks.COMPONENT_ADDED */);
  1839. const devtoolsComponentUpdated =
  1840. /*#__PURE__*/ createDevtoolsComponentHook("component:updated" /* DevtoolsHooks.COMPONENT_UPDATED */);
  1841. const _devtoolsComponentRemoved = /*#__PURE__*/ createDevtoolsComponentHook("component:removed" /* DevtoolsHooks.COMPONENT_REMOVED */);
  1842. const devtoolsComponentRemoved = (component) => {
  1843. if (devtools &&
  1844. typeof devtools.cleanupBuffer === 'function' &&
  1845. // remove the component if it wasn't buffered
  1846. !devtools.cleanupBuffer(component)) {
  1847. _devtoolsComponentRemoved(component);
  1848. }
  1849. };
  1850. function createDevtoolsComponentHook(hook) {
  1851. return (component) => {
  1852. emit$1(hook, component.appContext.app, component.uid, component.parent ? component.parent.uid : undefined, component);
  1853. };
  1854. }
  1855. const devtoolsPerfStart = /*#__PURE__*/ createDevtoolsPerformanceHook("perf:start" /* DevtoolsHooks.PERFORMANCE_START */);
  1856. const devtoolsPerfEnd = /*#__PURE__*/ createDevtoolsPerformanceHook("perf:end" /* DevtoolsHooks.PERFORMANCE_END */);
  1857. function createDevtoolsPerformanceHook(hook) {
  1858. return (component, type, time) => {
  1859. emit$1(hook, component.appContext.app, component.uid, component, type, time);
  1860. };
  1861. }
  1862. function devtoolsComponentEmit(component, event, params) {
  1863. emit$1("component:emit" /* DevtoolsHooks.COMPONENT_EMIT */, component.appContext.app, component, event, params);
  1864. }
  1865. function emit(instance, event, ...rawArgs) {
  1866. if (instance.isUnmounted)
  1867. return;
  1868. const props = instance.vnode.props || EMPTY_OBJ;
  1869. if ((process.env.NODE_ENV !== 'production')) {
  1870. const { emitsOptions, propsOptions: [propsOptions] } = instance;
  1871. if (emitsOptions) {
  1872. if (!(event in emitsOptions) &&
  1873. !(false )) {
  1874. if (!propsOptions || !(toHandlerKey(event) in propsOptions)) {
  1875. warn(`Component emitted event "${event}" but it is neither declared in ` +
  1876. `the emits option nor as an "${toHandlerKey(event)}" prop.`);
  1877. }
  1878. }
  1879. else {
  1880. const validator = emitsOptions[event];
  1881. if (isFunction(validator)) {
  1882. const isValid = validator(...rawArgs);
  1883. if (!isValid) {
  1884. warn(`Invalid event arguments: event validation failed for event "${event}".`);
  1885. }
  1886. }
  1887. }
  1888. }
  1889. }
  1890. let args = rawArgs;
  1891. const isModelListener = event.startsWith('update:');
  1892. // for v-model update:xxx events, apply modifiers on args
  1893. const modelArg = isModelListener && event.slice(7);
  1894. if (modelArg && modelArg in props) {
  1895. const modifiersKey = `${modelArg === 'modelValue' ? 'model' : modelArg}Modifiers`;
  1896. const { number, trim } = props[modifiersKey] || EMPTY_OBJ;
  1897. if (trim) {
  1898. args = rawArgs.map(a => (isString(a) ? a.trim() : a));
  1899. }
  1900. if (number) {
  1901. args = rawArgs.map(looseToNumber);
  1902. }
  1903. }
  1904. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  1905. devtoolsComponentEmit(instance, event, args);
  1906. }
  1907. if ((process.env.NODE_ENV !== 'production')) {
  1908. const lowerCaseEvent = event.toLowerCase();
  1909. if (lowerCaseEvent !== event && props[toHandlerKey(lowerCaseEvent)]) {
  1910. warn(`Event "${lowerCaseEvent}" is emitted in component ` +
  1911. `${formatComponentName(instance, instance.type)} but the handler is registered for "${event}". ` +
  1912. `Note that HTML attributes are case-insensitive and you cannot use ` +
  1913. `v-on to listen to camelCase events when using in-DOM templates. ` +
  1914. `You should probably use "${hyphenate(event)}" instead of "${event}".`);
  1915. }
  1916. }
  1917. let handlerName;
  1918. let handler = props[(handlerName = toHandlerKey(event))] ||
  1919. // also try camelCase event handler (#2249)
  1920. props[(handlerName = toHandlerKey(camelize(event)))];
  1921. // for v-model update:xxx events, also trigger kebab-case equivalent
  1922. // for props passed via kebab-case
  1923. if (!handler && isModelListener) {
  1924. handler = props[(handlerName = toHandlerKey(hyphenate(event)))];
  1925. }
  1926. if (handler) {
  1927. callWithAsyncErrorHandling(handler, instance, 6 /* ErrorCodes.COMPONENT_EVENT_HANDLER */,
  1928. // fixed by xxxxxx
  1929. normalizeWxsEventArgs(instance, handler, args));
  1930. }
  1931. const onceHandler = props[handlerName + `Once`];
  1932. if (onceHandler) {
  1933. if (!instance.emitted) {
  1934. instance.emitted = {};
  1935. }
  1936. else if (instance.emitted[handlerName]) {
  1937. return;
  1938. }
  1939. instance.emitted[handlerName] = true;
  1940. callWithAsyncErrorHandling(onceHandler, instance, 6 /* ErrorCodes.COMPONENT_EVENT_HANDLER */,
  1941. // fixed by xxxxxx
  1942. normalizeWxsEventArgs(instance, onceHandler, args));
  1943. }
  1944. }
  1945. /**
  1946. * 补充 wxs 事件参数
  1947. * @param instance
  1948. * @param handler
  1949. * @param args
  1950. * @returns
  1951. */
  1952. function normalizeWxsEventArgs(instance, handler, args) {
  1953. // 系统组件事件参数长度一定是 1
  1954. if (args.length !== 1) {
  1955. return args;
  1956. }
  1957. // 判断是否可能需要补充 ownerInstance 参数
  1958. if (isFunction(handler)) {
  1959. // 单函数,且参数小于 2 的直接返回
  1960. if (handler.length < 2) {
  1961. return args;
  1962. }
  1963. }
  1964. else {
  1965. // 多函数,且参数没有大于等于 2 的直接返回
  1966. if (!handler.find(item => item.length >= 2)) {
  1967. return args;
  1968. }
  1969. }
  1970. // 系统组件事件对象
  1971. const $sysEvent = args[0];
  1972. if ($sysEvent &&
  1973. hasOwn($sysEvent, 'type') &&
  1974. hasOwn($sysEvent, 'timeStamp') &&
  1975. hasOwn($sysEvent, 'target') &&
  1976. hasOwn($sysEvent, 'currentTarget') &&
  1977. hasOwn($sysEvent, 'detail')) {
  1978. const proxy = instance.proxy;
  1979. const $ownerInstance = proxy.$gcd(proxy, true);
  1980. if ($ownerInstance) {
  1981. args.push($ownerInstance);
  1982. }
  1983. }
  1984. return args;
  1985. }
  1986. function normalizeEmitsOptions(comp, appContext, asMixin = false) {
  1987. const cache = appContext.emitsCache;
  1988. const cached = cache.get(comp);
  1989. if (cached !== undefined) {
  1990. return cached;
  1991. }
  1992. const raw = comp.emits;
  1993. let normalized = {};
  1994. // apply mixin/extends props
  1995. let hasExtends = false;
  1996. if (__VUE_OPTIONS_API__ && !isFunction(comp)) {
  1997. const extendEmits = (raw) => {
  1998. const normalizedFromExtend = normalizeEmitsOptions(raw, appContext, true);
  1999. if (normalizedFromExtend) {
  2000. hasExtends = true;
  2001. extend(normalized, normalizedFromExtend);
  2002. }
  2003. };
  2004. if (!asMixin && appContext.mixins.length) {
  2005. appContext.mixins.forEach(extendEmits);
  2006. }
  2007. if (comp.extends) {
  2008. extendEmits(comp.extends);
  2009. }
  2010. if (comp.mixins) {
  2011. comp.mixins.forEach(extendEmits);
  2012. }
  2013. }
  2014. if (!raw && !hasExtends) {
  2015. if (isObject(comp)) {
  2016. cache.set(comp, null);
  2017. }
  2018. return null;
  2019. }
  2020. if (isArray(raw)) {
  2021. raw.forEach(key => (normalized[key] = null));
  2022. }
  2023. else {
  2024. extend(normalized, raw);
  2025. }
  2026. if (isObject(comp)) {
  2027. cache.set(comp, normalized);
  2028. }
  2029. return normalized;
  2030. }
  2031. // Check if an incoming prop key is a declared emit event listener.
  2032. // e.g. With `emits: { click: null }`, props named `onClick` and `onclick` are
  2033. // both considered matched listeners.
  2034. function isEmitListener(options, key) {
  2035. if (!options || !isOn(key)) {
  2036. return false;
  2037. }
  2038. key = key.slice(2).replace(/Once$/, '');
  2039. return (hasOwn(options, key[0].toLowerCase() + key.slice(1)) ||
  2040. hasOwn(options, hyphenate(key)) ||
  2041. hasOwn(options, key));
  2042. }
  2043. /**
  2044. * mark the current rendering instance for asset resolution (e.g.
  2045. * resolveComponent, resolveDirective) during render
  2046. */
  2047. let currentRenderingInstance = null;
  2048. let currentScopeId = null;
  2049. /**
  2050. * Note: rendering calls maybe nested. The function returns the parent rendering
  2051. * instance if present, which should be restored after the render is done:
  2052. *
  2053. * ```js
  2054. * const prev = setCurrentRenderingInstance(i)
  2055. * // ...render
  2056. * setCurrentRenderingInstance(prev)
  2057. * ```
  2058. */
  2059. function setCurrentRenderingInstance(instance) {
  2060. const prev = currentRenderingInstance;
  2061. currentRenderingInstance = instance;
  2062. currentScopeId = (instance && instance.type.__scopeId) || null;
  2063. return prev;
  2064. }
  2065. /**
  2066. * Set scope id when creating hoisted vnodes.
  2067. * @private compiler helper
  2068. */
  2069. function pushScopeId(id) {
  2070. currentScopeId = id;
  2071. }
  2072. /**
  2073. * Technically we no longer need this after 3.0.8 but we need to keep the same
  2074. * API for backwards compat w/ code generated by compilers.
  2075. * @private
  2076. */
  2077. function popScopeId() {
  2078. currentScopeId = null;
  2079. }
  2080. /**
  2081. * Only for backwards compat
  2082. * @private
  2083. */
  2084. const withScopeId = (_id) => withCtx;
  2085. /**
  2086. * Wrap a slot function to memoize current rendering instance
  2087. * @private compiler helper
  2088. */
  2089. function withCtx(fn, ctx = currentRenderingInstance, isNonScopedSlot // false only
  2090. ) {
  2091. if (!ctx)
  2092. return fn;
  2093. // already normalized
  2094. if (fn._n) {
  2095. return fn;
  2096. }
  2097. const renderFnWithContext = (...args) => {
  2098. // If a user calls a compiled slot inside a template expression (#1745), it
  2099. // can mess up block tracking, so by default we disable block tracking and
  2100. // force bail out when invoking a compiled slot (indicated by the ._d flag).
  2101. // This isn't necessary if rendering a compiled `<slot>`, so we flip the
  2102. // ._d flag off when invoking the wrapped fn inside `renderSlot`.
  2103. if (renderFnWithContext._d) {
  2104. setBlockTracking(-1);
  2105. }
  2106. const prevInstance = setCurrentRenderingInstance(ctx);
  2107. let res;
  2108. try {
  2109. res = fn(...args);
  2110. }
  2111. finally {
  2112. setCurrentRenderingInstance(prevInstance);
  2113. if (renderFnWithContext._d) {
  2114. setBlockTracking(1);
  2115. }
  2116. }
  2117. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  2118. devtoolsComponentUpdated(ctx);
  2119. }
  2120. return res;
  2121. };
  2122. // mark normalized to avoid duplicated wrapping
  2123. renderFnWithContext._n = true;
  2124. // mark this as compiled by default
  2125. // this is used in vnode.ts -> normalizeChildren() to set the slot
  2126. // rendering flag.
  2127. renderFnWithContext._c = true;
  2128. // disable block tracking by default
  2129. renderFnWithContext._d = true;
  2130. return renderFnWithContext;
  2131. }
  2132. /**
  2133. * dev only flag to track whether $attrs was used during render.
  2134. * If $attrs was used during render then the warning for failed attrs
  2135. * fallthrough can be suppressed.
  2136. */
  2137. let accessedAttrs = false;
  2138. function markAttrsAccessed() {
  2139. accessedAttrs = true;
  2140. }
  2141. function renderComponentRoot(instance) {
  2142. const { type: Component, vnode, proxy, withProxy, props, propsOptions: [propsOptions], slots, attrs, emit, render, renderCache, data, setupState, ctx, inheritAttrs } = instance;
  2143. let result;
  2144. let fallthroughAttrs;
  2145. const prev = setCurrentRenderingInstance(instance);
  2146. if ((process.env.NODE_ENV !== 'production')) {
  2147. accessedAttrs = false;
  2148. }
  2149. try {
  2150. if (vnode.shapeFlag & 4 /* ShapeFlags.STATEFUL_COMPONENT */) {
  2151. // withProxy is a proxy with a different `has` trap only for
  2152. // runtime-compiled render functions using `with` block.
  2153. const proxyToUse = withProxy || proxy;
  2154. result = normalizeVNode(render.call(proxyToUse, proxyToUse, renderCache, props, setupState, data, ctx));
  2155. fallthroughAttrs = attrs;
  2156. }
  2157. else {
  2158. // functional
  2159. const render = Component;
  2160. // in dev, mark attrs accessed if optional props (attrs === props)
  2161. if ((process.env.NODE_ENV !== 'production') && attrs === props) {
  2162. markAttrsAccessed();
  2163. }
  2164. result = normalizeVNode(render.length > 1
  2165. ? render(props, (process.env.NODE_ENV !== 'production')
  2166. ? {
  2167. get attrs() {
  2168. markAttrsAccessed();
  2169. return attrs;
  2170. },
  2171. slots,
  2172. emit
  2173. }
  2174. : { attrs, slots, emit })
  2175. : render(props, null /* we know it doesn't need it */));
  2176. fallthroughAttrs = Component.props
  2177. ? attrs
  2178. : getFunctionalFallthrough(attrs);
  2179. }
  2180. }
  2181. catch (err) {
  2182. blockStack.length = 0;
  2183. handleError(err, instance, 1 /* ErrorCodes.RENDER_FUNCTION */);
  2184. result = createVNode(Comment);
  2185. }
  2186. // attr merging
  2187. // in dev mode, comments are preserved, and it's possible for a template
  2188. // to have comments along side the root element which makes it a fragment
  2189. let root = result;
  2190. let setRoot = undefined;
  2191. if ((process.env.NODE_ENV !== 'production') &&
  2192. result.patchFlag > 0 &&
  2193. result.patchFlag & 2048 /* PatchFlags.DEV_ROOT_FRAGMENT */) {
  2194. [root, setRoot] = getChildRoot(result);
  2195. }
  2196. if (fallthroughAttrs && inheritAttrs !== false) {
  2197. const keys = Object.keys(fallthroughAttrs);
  2198. const { shapeFlag } = root;
  2199. if (keys.length) {
  2200. if (shapeFlag & (1 /* ShapeFlags.ELEMENT */ | 6 /* ShapeFlags.COMPONENT */)) {
  2201. if (propsOptions && keys.some(isModelListener)) {
  2202. // If a v-model listener (onUpdate:xxx) has a corresponding declared
  2203. // prop, it indicates this component expects to handle v-model and
  2204. // it should not fallthrough.
  2205. // related: #1543, #1643, #1989
  2206. fallthroughAttrs = filterModelListeners(fallthroughAttrs, propsOptions);
  2207. }
  2208. root = cloneVNode(root, fallthroughAttrs);
  2209. }
  2210. else if ((process.env.NODE_ENV !== 'production') && !accessedAttrs && root.type !== Comment) {
  2211. const allAttrs = Object.keys(attrs);
  2212. const eventAttrs = [];
  2213. const extraAttrs = [];
  2214. for (let i = 0, l = allAttrs.length; i < l; i++) {
  2215. const key = allAttrs[i];
  2216. if (isOn(key)) {
  2217. // ignore v-model handlers when they fail to fallthrough
  2218. if (!isModelListener(key)) {
  2219. // remove `on`, lowercase first letter to reflect event casing
  2220. // accurately
  2221. eventAttrs.push(key[2].toLowerCase() + key.slice(3));
  2222. }
  2223. }
  2224. else {
  2225. extraAttrs.push(key);
  2226. }
  2227. }
  2228. if (extraAttrs.length) {
  2229. warn(`Extraneous non-props attributes (` +
  2230. `${extraAttrs.join(', ')}) ` +
  2231. `were passed to component but could not be automatically inherited ` +
  2232. `because component renders fragment or text root nodes.`);
  2233. }
  2234. if (eventAttrs.length) {
  2235. warn(`Extraneous non-emits event listeners (` +
  2236. `${eventAttrs.join(', ')}) ` +
  2237. `were passed to component but could not be automatically inherited ` +
  2238. `because component renders fragment or text root nodes. ` +
  2239. `If the listener is intended to be a component custom event listener only, ` +
  2240. `declare it using the "emits" option.`);
  2241. }
  2242. }
  2243. }
  2244. }
  2245. // inherit directives
  2246. if (vnode.dirs) {
  2247. if ((process.env.NODE_ENV !== 'production') && !isElementRoot(root)) {
  2248. warn(`Runtime directive used on component with non-element root node. ` +
  2249. `The directives will not function as intended.`);
  2250. }
  2251. // clone before mutating since the root may be a hoisted vnode
  2252. root = cloneVNode(root);
  2253. root.dirs = root.dirs ? root.dirs.concat(vnode.dirs) : vnode.dirs;
  2254. }
  2255. // inherit transition data
  2256. if (vnode.transition) {
  2257. if ((process.env.NODE_ENV !== 'production') && !isElementRoot(root)) {
  2258. warn(`Component inside <Transition> renders non-element root node ` +
  2259. `that cannot be animated.`);
  2260. }
  2261. root.transition = vnode.transition;
  2262. }
  2263. if ((process.env.NODE_ENV !== 'production') && setRoot) {
  2264. setRoot(root);
  2265. }
  2266. else {
  2267. result = root;
  2268. }
  2269. setCurrentRenderingInstance(prev);
  2270. return result;
  2271. }
  2272. /**
  2273. * dev only
  2274. * In dev mode, template root level comments are rendered, which turns the
  2275. * template into a fragment root, but we need to locate the single element
  2276. * root for attrs and scope id processing.
  2277. */
  2278. const getChildRoot = (vnode) => {
  2279. const rawChildren = vnode.children;
  2280. const dynamicChildren = vnode.dynamicChildren;
  2281. const childRoot = filterSingleRoot(rawChildren);
  2282. if (!childRoot) {
  2283. return [vnode, undefined];
  2284. }
  2285. const index = rawChildren.indexOf(childRoot);
  2286. const dynamicIndex = dynamicChildren ? dynamicChildren.indexOf(childRoot) : -1;
  2287. const setRoot = (updatedRoot) => {
  2288. rawChildren[index] = updatedRoot;
  2289. if (dynamicChildren) {
  2290. if (dynamicIndex > -1) {
  2291. dynamicChildren[dynamicIndex] = updatedRoot;
  2292. }
  2293. else if (updatedRoot.patchFlag > 0) {
  2294. vnode.dynamicChildren = [...dynamicChildren, updatedRoot];
  2295. }
  2296. }
  2297. };
  2298. return [normalizeVNode(childRoot), setRoot];
  2299. };
  2300. function filterSingleRoot(children) {
  2301. let singleRoot;
  2302. for (let i = 0; i < children.length; i++) {
  2303. const child = children[i];
  2304. if (isVNode(child)) {
  2305. // ignore user comment
  2306. if (child.type !== Comment || child.children === 'v-if') {
  2307. if (singleRoot) {
  2308. // has more than 1 non-comment child, return now
  2309. return;
  2310. }
  2311. else {
  2312. singleRoot = child;
  2313. }
  2314. }
  2315. }
  2316. else {
  2317. return;
  2318. }
  2319. }
  2320. return singleRoot;
  2321. }
  2322. const getFunctionalFallthrough = (attrs) => {
  2323. let res;
  2324. for (const key in attrs) {
  2325. if (key === 'class' || key === 'style' || isOn(key)) {
  2326. (res || (res = {}))[key] = attrs[key];
  2327. }
  2328. }
  2329. return res;
  2330. };
  2331. const filterModelListeners = (attrs, props) => {
  2332. const res = {};
  2333. for (const key in attrs) {
  2334. if (!isModelListener(key) || !(key.slice(9) in props)) {
  2335. res[key] = attrs[key];
  2336. }
  2337. }
  2338. return res;
  2339. };
  2340. const isElementRoot = (vnode) => {
  2341. return (vnode.shapeFlag & (6 /* ShapeFlags.COMPONENT */ | 1 /* ShapeFlags.ELEMENT */) ||
  2342. vnode.type === Comment // potential v-if branch switch
  2343. );
  2344. };
  2345. function shouldUpdateComponent(prevVNode, nextVNode, optimized) {
  2346. const { props: prevProps, children: prevChildren, component } = prevVNode;
  2347. const { props: nextProps, children: nextChildren, patchFlag } = nextVNode;
  2348. const emits = component.emitsOptions;
  2349. // Parent component's render function was hot-updated. Since this may have
  2350. // caused the child component's slots content to have changed, we need to
  2351. // force the child to update as well.
  2352. if ((process.env.NODE_ENV !== 'production') && (prevChildren || nextChildren) && isHmrUpdating) {
  2353. return true;
  2354. }
  2355. // force child update for runtime directive or transition on component vnode.
  2356. if (nextVNode.dirs || nextVNode.transition) {
  2357. return true;
  2358. }
  2359. if (optimized && patchFlag >= 0) {
  2360. if (patchFlag & 1024 /* PatchFlags.DYNAMIC_SLOTS */) {
  2361. // slot content that references values that might have changed,
  2362. // e.g. in a v-for
  2363. return true;
  2364. }
  2365. if (patchFlag & 16 /* PatchFlags.FULL_PROPS */) {
  2366. if (!prevProps) {
  2367. return !!nextProps;
  2368. }
  2369. // presence of this flag indicates props are always non-null
  2370. return hasPropsChanged(prevProps, nextProps, emits);
  2371. }
  2372. else if (patchFlag & 8 /* PatchFlags.PROPS */) {
  2373. const dynamicProps = nextVNode.dynamicProps;
  2374. for (let i = 0; i < dynamicProps.length; i++) {
  2375. const key = dynamicProps[i];
  2376. if (nextProps[key] !== prevProps[key] &&
  2377. !isEmitListener(emits, key)) {
  2378. return true;
  2379. }
  2380. }
  2381. }
  2382. }
  2383. else {
  2384. // this path is only taken by manually written render functions
  2385. // so presence of any children leads to a forced update
  2386. if (prevChildren || nextChildren) {
  2387. if (!nextChildren || !nextChildren.$stable) {
  2388. return true;
  2389. }
  2390. }
  2391. if (prevProps === nextProps) {
  2392. return false;
  2393. }
  2394. if (!prevProps) {
  2395. return !!nextProps;
  2396. }
  2397. if (!nextProps) {
  2398. return true;
  2399. }
  2400. return hasPropsChanged(prevProps, nextProps, emits);
  2401. }
  2402. return false;
  2403. }
  2404. function hasPropsChanged(prevProps, nextProps, emitsOptions) {
  2405. const nextKeys = Object.keys(nextProps);
  2406. if (nextKeys.length !== Object.keys(prevProps).length) {
  2407. return true;
  2408. }
  2409. for (let i = 0; i < nextKeys.length; i++) {
  2410. const key = nextKeys[i];
  2411. if (nextProps[key] !== prevProps[key] &&
  2412. !isEmitListener(emitsOptions, key)) {
  2413. return true;
  2414. }
  2415. }
  2416. return false;
  2417. }
  2418. function updateHOCHostEl({ vnode, parent }, el // HostNode
  2419. ) {
  2420. while (parent && parent.subTree === vnode) {
  2421. (vnode = parent.vnode).el = el;
  2422. parent = parent.parent;
  2423. }
  2424. }
  2425. const isSuspense = (type) => type.__isSuspense;
  2426. // Suspense exposes a component-like API, and is treated like a component
  2427. // in the compiler, but internally it's a special built-in type that hooks
  2428. // directly into the renderer.
  2429. const SuspenseImpl = {
  2430. name: 'Suspense',
  2431. // In order to make Suspense tree-shakable, we need to avoid importing it
  2432. // directly in the renderer. The renderer checks for the __isSuspense flag
  2433. // on a vnode's type and calls the `process` method, passing in renderer
  2434. // internals.
  2435. __isSuspense: true,
  2436. process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized,
  2437. // platform-specific impl passed from renderer
  2438. rendererInternals) {
  2439. if (n1 == null) {
  2440. mountSuspense(n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, rendererInternals);
  2441. }
  2442. else {
  2443. patchSuspense(n1, n2, container, anchor, parentComponent, isSVG, slotScopeIds, optimized, rendererInternals);
  2444. }
  2445. },
  2446. hydrate: hydrateSuspense,
  2447. create: createSuspenseBoundary,
  2448. normalize: normalizeSuspenseChildren
  2449. };
  2450. // Force-casted public typing for h and TSX props inference
  2451. const Suspense = (SuspenseImpl
  2452. );
  2453. function triggerEvent(vnode, name) {
  2454. const eventListener = vnode.props && vnode.props[name];
  2455. if (isFunction(eventListener)) {
  2456. eventListener();
  2457. }
  2458. }
  2459. function mountSuspense(vnode, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, rendererInternals) {
  2460. const { p: patch, o: { createElement } } = rendererInternals;
  2461. const hiddenContainer = createElement('div');
  2462. const suspense = (vnode.suspense = createSuspenseBoundary(vnode, parentSuspense, parentComponent, container, hiddenContainer, anchor, isSVG, slotScopeIds, optimized, rendererInternals));
  2463. // start mounting the content subtree in an off-dom container
  2464. patch(null, (suspense.pendingBranch = vnode.ssContent), hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds);
  2465. // now check if we have encountered any async deps
  2466. if (suspense.deps > 0) {
  2467. // has async
  2468. // invoke @fallback event
  2469. triggerEvent(vnode, 'onPending');
  2470. triggerEvent(vnode, 'onFallback');
  2471. // mount the fallback tree
  2472. patch(null, vnode.ssFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2473. isSVG, slotScopeIds);
  2474. setActiveBranch(suspense, vnode.ssFallback);
  2475. }
  2476. else {
  2477. // Suspense has no async deps. Just resolve.
  2478. suspense.resolve();
  2479. }
  2480. }
  2481. function patchSuspense(n1, n2, container, anchor, parentComponent, isSVG, slotScopeIds, optimized, { p: patch, um: unmount, o: { createElement } }) {
  2482. const suspense = (n2.suspense = n1.suspense);
  2483. suspense.vnode = n2;
  2484. n2.el = n1.el;
  2485. const newBranch = n2.ssContent;
  2486. const newFallback = n2.ssFallback;
  2487. const { activeBranch, pendingBranch, isInFallback, isHydrating } = suspense;
  2488. if (pendingBranch) {
  2489. suspense.pendingBranch = newBranch;
  2490. if (isSameVNodeType(newBranch, pendingBranch)) {
  2491. // same root type but content may have changed.
  2492. patch(pendingBranch, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2493. if (suspense.deps <= 0) {
  2494. suspense.resolve();
  2495. }
  2496. else if (isInFallback) {
  2497. patch(activeBranch, newFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2498. isSVG, slotScopeIds, optimized);
  2499. setActiveBranch(suspense, newFallback);
  2500. }
  2501. }
  2502. else {
  2503. // toggled before pending tree is resolved
  2504. suspense.pendingId++;
  2505. if (isHydrating) {
  2506. // if toggled before hydration is finished, the current DOM tree is
  2507. // no longer valid. set it as the active branch so it will be unmounted
  2508. // when resolved
  2509. suspense.isHydrating = false;
  2510. suspense.activeBranch = pendingBranch;
  2511. }
  2512. else {
  2513. unmount(pendingBranch, parentComponent, suspense);
  2514. }
  2515. // increment pending ID. this is used to invalidate async callbacks
  2516. // reset suspense state
  2517. suspense.deps = 0;
  2518. // discard effects from pending branch
  2519. suspense.effects.length = 0;
  2520. // discard previous container
  2521. suspense.hiddenContainer = createElement('div');
  2522. if (isInFallback) {
  2523. // already in fallback state
  2524. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2525. if (suspense.deps <= 0) {
  2526. suspense.resolve();
  2527. }
  2528. else {
  2529. patch(activeBranch, newFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2530. isSVG, slotScopeIds, optimized);
  2531. setActiveBranch(suspense, newFallback);
  2532. }
  2533. }
  2534. else if (activeBranch && isSameVNodeType(newBranch, activeBranch)) {
  2535. // toggled "back" to current active branch
  2536. patch(activeBranch, newBranch, container, anchor, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2537. // force resolve
  2538. suspense.resolve(true);
  2539. }
  2540. else {
  2541. // switched to a 3rd branch
  2542. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2543. if (suspense.deps <= 0) {
  2544. suspense.resolve();
  2545. }
  2546. }
  2547. }
  2548. }
  2549. else {
  2550. if (activeBranch && isSameVNodeType(newBranch, activeBranch)) {
  2551. // root did not change, just normal patch
  2552. patch(activeBranch, newBranch, container, anchor, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2553. setActiveBranch(suspense, newBranch);
  2554. }
  2555. else {
  2556. // root node toggled
  2557. // invoke @pending event
  2558. triggerEvent(n2, 'onPending');
  2559. // mount pending branch in off-dom container
  2560. suspense.pendingBranch = newBranch;
  2561. suspense.pendingId++;
  2562. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2563. if (suspense.deps <= 0) {
  2564. // incoming branch has no async deps, resolve now.
  2565. suspense.resolve();
  2566. }
  2567. else {
  2568. const { timeout, pendingId } = suspense;
  2569. if (timeout > 0) {
  2570. setTimeout(() => {
  2571. if (suspense.pendingId === pendingId) {
  2572. suspense.fallback(newFallback);
  2573. }
  2574. }, timeout);
  2575. }
  2576. else if (timeout === 0) {
  2577. suspense.fallback(newFallback);
  2578. }
  2579. }
  2580. }
  2581. }
  2582. }
  2583. let hasWarned = false;
  2584. function createSuspenseBoundary(vnode, parent, parentComponent, container, hiddenContainer, anchor, isSVG, slotScopeIds, optimized, rendererInternals, isHydrating = false) {
  2585. /* istanbul ignore if */
  2586. if ((process.env.NODE_ENV !== 'production') && !false && !hasWarned) {
  2587. hasWarned = true;
  2588. // @ts-ignore `console.info` cannot be null error
  2589. console[console.info ? 'info' : 'log'](`<Suspense> is an experimental feature and its API will likely change.`);
  2590. }
  2591. const { p: patch, m: move, um: unmount, n: next, o: { parentNode, remove } } = rendererInternals;
  2592. const timeout = vnode.props ? toNumber(vnode.props.timeout) : undefined;
  2593. if ((process.env.NODE_ENV !== 'production')) {
  2594. assertNumber(timeout, `Suspense timeout`);
  2595. }
  2596. const suspense = {
  2597. vnode,
  2598. parent,
  2599. parentComponent,
  2600. isSVG,
  2601. container,
  2602. hiddenContainer,
  2603. anchor,
  2604. deps: 0,
  2605. pendingId: 0,
  2606. timeout: typeof timeout === 'number' ? timeout : -1,
  2607. activeBranch: null,
  2608. pendingBranch: null,
  2609. isInFallback: true,
  2610. isHydrating,
  2611. isUnmounted: false,
  2612. effects: [],
  2613. resolve(resume = false) {
  2614. if ((process.env.NODE_ENV !== 'production')) {
  2615. if (!resume && !suspense.pendingBranch) {
  2616. throw new Error(`suspense.resolve() is called without a pending branch.`);
  2617. }
  2618. if (suspense.isUnmounted) {
  2619. throw new Error(`suspense.resolve() is called on an already unmounted suspense boundary.`);
  2620. }
  2621. }
  2622. const { vnode, activeBranch, pendingBranch, pendingId, effects, parentComponent, container } = suspense;
  2623. if (suspense.isHydrating) {
  2624. suspense.isHydrating = false;
  2625. }
  2626. else if (!resume) {
  2627. const delayEnter = activeBranch &&
  2628. pendingBranch.transition &&
  2629. pendingBranch.transition.mode === 'out-in';
  2630. if (delayEnter) {
  2631. activeBranch.transition.afterLeave = () => {
  2632. if (pendingId === suspense.pendingId) {
  2633. move(pendingBranch, container, anchor, 0 /* MoveType.ENTER */);
  2634. }
  2635. };
  2636. }
  2637. // this is initial anchor on mount
  2638. let { anchor } = suspense;
  2639. // unmount current active tree
  2640. if (activeBranch) {
  2641. // if the fallback tree was mounted, it may have been moved
  2642. // as part of a parent suspense. get the latest anchor for insertion
  2643. anchor = next(activeBranch);
  2644. unmount(activeBranch, parentComponent, suspense, true);
  2645. }
  2646. if (!delayEnter) {
  2647. // move content from off-dom container to actual container
  2648. move(pendingBranch, container, anchor, 0 /* MoveType.ENTER */);
  2649. }
  2650. }
  2651. setActiveBranch(suspense, pendingBranch);
  2652. suspense.pendingBranch = null;
  2653. suspense.isInFallback = false;
  2654. // flush buffered effects
  2655. // check if there is a pending parent suspense
  2656. let parent = suspense.parent;
  2657. let hasUnresolvedAncestor = false;
  2658. while (parent) {
  2659. if (parent.pendingBranch) {
  2660. // found a pending parent suspense, merge buffered post jobs
  2661. // into that parent
  2662. parent.effects.push(...effects);
  2663. hasUnresolvedAncestor = true;
  2664. break;
  2665. }
  2666. parent = parent.parent;
  2667. }
  2668. // no pending parent suspense, flush all jobs
  2669. if (!hasUnresolvedAncestor) {
  2670. queuePostFlushCb(effects);
  2671. }
  2672. suspense.effects = [];
  2673. // invoke @resolve event
  2674. triggerEvent(vnode, 'onResolve');
  2675. },
  2676. fallback(fallbackVNode) {
  2677. if (!suspense.pendingBranch) {
  2678. return;
  2679. }
  2680. const { vnode, activeBranch, parentComponent, container, isSVG } = suspense;
  2681. // invoke @fallback event
  2682. triggerEvent(vnode, 'onFallback');
  2683. const anchor = next(activeBranch);
  2684. const mountFallback = () => {
  2685. if (!suspense.isInFallback) {
  2686. return;
  2687. }
  2688. // mount the fallback tree
  2689. patch(null, fallbackVNode, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2690. isSVG, slotScopeIds, optimized);
  2691. setActiveBranch(suspense, fallbackVNode);
  2692. };
  2693. const delayEnter = fallbackVNode.transition && fallbackVNode.transition.mode === 'out-in';
  2694. if (delayEnter) {
  2695. activeBranch.transition.afterLeave = mountFallback;
  2696. }
  2697. suspense.isInFallback = true;
  2698. // unmount current active branch
  2699. unmount(activeBranch, parentComponent, null, // no suspense so unmount hooks fire now
  2700. true // shouldRemove
  2701. );
  2702. if (!delayEnter) {
  2703. mountFallback();
  2704. }
  2705. },
  2706. move(container, anchor, type) {
  2707. suspense.activeBranch &&
  2708. move(suspense.activeBranch, container, anchor, type);
  2709. suspense.container = container;
  2710. },
  2711. next() {
  2712. return suspense.activeBranch && next(suspense.activeBranch);
  2713. },
  2714. registerDep(instance, setupRenderEffect) {
  2715. const isInPendingSuspense = !!suspense.pendingBranch;
  2716. if (isInPendingSuspense) {
  2717. suspense.deps++;
  2718. }
  2719. const hydratedEl = instance.vnode.el;
  2720. instance
  2721. .asyncDep.catch(err => {
  2722. handleError(err, instance, 0 /* ErrorCodes.SETUP_FUNCTION */);
  2723. })
  2724. .then(asyncSetupResult => {
  2725. // retry when the setup() promise resolves.
  2726. // component may have been unmounted before resolve.
  2727. if (instance.isUnmounted ||
  2728. suspense.isUnmounted ||
  2729. suspense.pendingId !== instance.suspenseId) {
  2730. return;
  2731. }
  2732. // retry from this component
  2733. instance.asyncResolved = true;
  2734. const { vnode } = instance;
  2735. if ((process.env.NODE_ENV !== 'production')) {
  2736. pushWarningContext(vnode);
  2737. }
  2738. handleSetupResult(instance, asyncSetupResult, false);
  2739. if (hydratedEl) {
  2740. // vnode may have been replaced if an update happened before the
  2741. // async dep is resolved.
  2742. vnode.el = hydratedEl;
  2743. }
  2744. const placeholder = !hydratedEl && instance.subTree.el;
  2745. setupRenderEffect(instance, vnode,
  2746. // component may have been moved before resolve.
  2747. // if this is not a hydration, instance.subTree will be the comment
  2748. // placeholder.
  2749. parentNode(hydratedEl || instance.subTree.el),
  2750. // anchor will not be used if this is hydration, so only need to
  2751. // consider the comment placeholder case.
  2752. hydratedEl ? null : next(instance.subTree), suspense, isSVG, optimized);
  2753. if (placeholder) {
  2754. remove(placeholder);
  2755. }
  2756. updateHOCHostEl(instance, vnode.el);
  2757. if ((process.env.NODE_ENV !== 'production')) {
  2758. popWarningContext();
  2759. }
  2760. // only decrease deps count if suspense is not already resolved
  2761. if (isInPendingSuspense && --suspense.deps === 0) {
  2762. suspense.resolve();
  2763. }
  2764. });
  2765. },
  2766. unmount(parentSuspense, doRemove) {
  2767. suspense.isUnmounted = true;
  2768. if (suspense.activeBranch) {
  2769. unmount(suspense.activeBranch, parentComponent, parentSuspense, doRemove);
  2770. }
  2771. if (suspense.pendingBranch) {
  2772. unmount(suspense.pendingBranch, parentComponent, parentSuspense, doRemove);
  2773. }
  2774. }
  2775. };
  2776. return suspense;
  2777. }
  2778. function hydrateSuspense(node, vnode, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, rendererInternals, hydrateNode) {
  2779. /* eslint-disable no-restricted-globals */
  2780. const suspense = (vnode.suspense = createSuspenseBoundary(vnode, parentSuspense, parentComponent, node.parentNode, document.createElement('div'), null, isSVG, slotScopeIds, optimized, rendererInternals, true /* hydrating */));
  2781. // there are two possible scenarios for server-rendered suspense:
  2782. // - success: ssr content should be fully resolved
  2783. // - failure: ssr content should be the fallback branch.
  2784. // however, on the client we don't really know if it has failed or not
  2785. // attempt to hydrate the DOM assuming it has succeeded, but we still
  2786. // need to construct a suspense boundary first
  2787. const result = hydrateNode(node, (suspense.pendingBranch = vnode.ssContent), parentComponent, suspense, slotScopeIds, optimized);
  2788. if (suspense.deps === 0) {
  2789. suspense.resolve();
  2790. }
  2791. return result;
  2792. /* eslint-enable no-restricted-globals */
  2793. }
  2794. function normalizeSuspenseChildren(vnode) {
  2795. const { shapeFlag, children } = vnode;
  2796. const isSlotChildren = shapeFlag & 32 /* ShapeFlags.SLOTS_CHILDREN */;
  2797. vnode.ssContent = normalizeSuspenseSlot(isSlotChildren ? children.default : children);
  2798. vnode.ssFallback = isSlotChildren
  2799. ? normalizeSuspenseSlot(children.fallback)
  2800. : createVNode(Comment);
  2801. }
  2802. function normalizeSuspenseSlot(s) {
  2803. let block;
  2804. if (isFunction(s)) {
  2805. const trackBlock = isBlockTreeEnabled && s._c;
  2806. if (trackBlock) {
  2807. // disableTracking: false
  2808. // allow block tracking for compiled slots
  2809. // (see ./componentRenderContext.ts)
  2810. s._d = false;
  2811. openBlock();
  2812. }
  2813. s = s();
  2814. if (trackBlock) {
  2815. s._d = true;
  2816. block = currentBlock;
  2817. closeBlock();
  2818. }
  2819. }
  2820. if (isArray(s)) {
  2821. const singleChild = filterSingleRoot(s);
  2822. if ((process.env.NODE_ENV !== 'production') && !singleChild) {
  2823. warn(`<Suspense> slots expect a single root node.`);
  2824. }
  2825. s = singleChild;
  2826. }
  2827. s = normalizeVNode(s);
  2828. if (block && !s.dynamicChildren) {
  2829. s.dynamicChildren = block.filter(c => c !== s);
  2830. }
  2831. return s;
  2832. }
  2833. function queueEffectWithSuspense(fn, suspense) {
  2834. if (suspense && suspense.pendingBranch) {
  2835. if (isArray(fn)) {
  2836. suspense.effects.push(...fn);
  2837. }
  2838. else {
  2839. suspense.effects.push(fn);
  2840. }
  2841. }
  2842. else {
  2843. queuePostFlushCb(fn);
  2844. }
  2845. }
  2846. function setActiveBranch(suspense, branch) {
  2847. suspense.activeBranch = branch;
  2848. const { vnode, parentComponent } = suspense;
  2849. const el = (vnode.el = branch.el);
  2850. // in case suspense is the root node of a component,
  2851. // recursively update the HOC el
  2852. if (parentComponent && parentComponent.subTree === vnode) {
  2853. parentComponent.vnode.el = el;
  2854. updateHOCHostEl(parentComponent, el);
  2855. }
  2856. }
  2857. function provide(key, value) {
  2858. if (!currentInstance) {
  2859. if ((process.env.NODE_ENV !== 'production')) {
  2860. warn(`provide() can only be used inside setup().`);
  2861. }
  2862. }
  2863. else {
  2864. let provides = currentInstance.provides;
  2865. // by default an instance inherits its parent's provides object
  2866. // but when it needs to provide values of its own, it creates its
  2867. // own provides object using parent provides object as prototype.
  2868. // this way in `inject` we can simply look up injections from direct
  2869. // parent and let the prototype chain do the work.
  2870. const parentProvides = currentInstance.parent && currentInstance.parent.provides;
  2871. if (parentProvides === provides) {
  2872. provides = currentInstance.provides = Object.create(parentProvides);
  2873. }
  2874. // TS doesn't allow symbol as index type
  2875. provides[key] = value;
  2876. // 当实例为 App 时,同步到全局 provide
  2877. if (currentInstance.type.mpType === 'app') {
  2878. currentInstance.appContext.app.provide(key, value);
  2879. }
  2880. }
  2881. }
  2882. function inject(key, defaultValue, treatDefaultAsFactory = false) {
  2883. // fallback to `currentRenderingInstance` so that this can be called in
  2884. // a functional component
  2885. const instance = currentInstance || currentRenderingInstance;
  2886. if (instance) {
  2887. // #2400
  2888. // to support `app.use` plugins,
  2889. // fallback to appContext's `provides` if the instance is at root
  2890. const provides = instance.parent == null
  2891. ? instance.vnode.appContext && instance.vnode.appContext.provides
  2892. : instance.parent.provides;
  2893. if (provides && key in provides) {
  2894. // TS doesn't allow symbol as index type
  2895. return provides[key];
  2896. }
  2897. else if (arguments.length > 1) {
  2898. return treatDefaultAsFactory && isFunction(defaultValue)
  2899. ? defaultValue.call(instance.proxy)
  2900. : defaultValue;
  2901. }
  2902. else if ((process.env.NODE_ENV !== 'production')) {
  2903. warn(`injection "${String(key)}" not found.`);
  2904. }
  2905. }
  2906. else if ((process.env.NODE_ENV !== 'production')) {
  2907. warn(`inject() can only be used inside setup() or functional components.`);
  2908. }
  2909. }
  2910. // Simple effect.
  2911. function watchEffect(effect, options) {
  2912. return doWatch(effect, null, options);
  2913. }
  2914. function watchPostEffect(effect, options) {
  2915. return doWatch(effect, null, (process.env.NODE_ENV !== 'production') ? Object.assign(Object.assign({}, options), { flush: 'post' }) : { flush: 'post' });
  2916. }
  2917. function watchSyncEffect(effect, options) {
  2918. return doWatch(effect, null, (process.env.NODE_ENV !== 'production') ? Object.assign(Object.assign({}, options), { flush: 'sync' }) : { flush: 'sync' });
  2919. }
  2920. // initial value for watchers to trigger on undefined initial values
  2921. const INITIAL_WATCHER_VALUE = {};
  2922. // implementation
  2923. function watch(source, cb, options) {
  2924. if ((process.env.NODE_ENV !== 'production') && !isFunction(cb)) {
  2925. warn(`\`watch(fn, options?)\` signature has been moved to a separate API. ` +
  2926. `Use \`watchEffect(fn, options?)\` instead. \`watch\` now only ` +
  2927. `supports \`watch(source, cb, options?) signature.`);
  2928. }
  2929. return doWatch(source, cb, options);
  2930. }
  2931. function doWatch(source, cb, { immediate, deep, flush, onTrack, onTrigger } = EMPTY_OBJ) {
  2932. if ((process.env.NODE_ENV !== 'production') && !cb) {
  2933. if (immediate !== undefined) {
  2934. warn(`watch() "immediate" option is only respected when using the ` +
  2935. `watch(source, callback, options?) signature.`);
  2936. }
  2937. if (deep !== undefined) {
  2938. warn(`watch() "deep" option is only respected when using the ` +
  2939. `watch(source, callback, options?) signature.`);
  2940. }
  2941. }
  2942. const warnInvalidSource = (s) => {
  2943. warn(`Invalid watch source: `, s, `A watch source can only be a getter/effect function, a ref, ` +
  2944. `a reactive object, or an array of these types.`);
  2945. };
  2946. const instance = getCurrentScope() === (currentInstance === null || currentInstance === void 0 ? void 0 : currentInstance.scope) ? currentInstance : null;
  2947. // const instance = currentInstance
  2948. let getter;
  2949. let forceTrigger = false;
  2950. let isMultiSource = false;
  2951. if (isRef(source)) {
  2952. getter = () => source.value;
  2953. forceTrigger = isShallow(source);
  2954. }
  2955. else if (isReactive(source)) {
  2956. getter = () => source;
  2957. deep = true;
  2958. }
  2959. else if (isArray(source)) {
  2960. isMultiSource = true;
  2961. forceTrigger = source.some(s => isReactive(s) || isShallow(s));
  2962. getter = () => source.map(s => {
  2963. if (isRef(s)) {
  2964. return s.value;
  2965. }
  2966. else if (isReactive(s)) {
  2967. return traverse(s);
  2968. }
  2969. else if (isFunction(s)) {
  2970. return callWithErrorHandling(s, instance, 2 /* ErrorCodes.WATCH_GETTER */);
  2971. }
  2972. else {
  2973. (process.env.NODE_ENV !== 'production') && warnInvalidSource(s);
  2974. }
  2975. });
  2976. }
  2977. else if (isFunction(source)) {
  2978. if (cb) {
  2979. // getter with cb
  2980. getter = () => callWithErrorHandling(source, instance, 2 /* ErrorCodes.WATCH_GETTER */);
  2981. }
  2982. else {
  2983. // no cb -> simple effect
  2984. getter = () => {
  2985. if (instance && instance.isUnmounted) {
  2986. return;
  2987. }
  2988. if (cleanup) {
  2989. cleanup();
  2990. }
  2991. return callWithAsyncErrorHandling(source, instance, 3 /* ErrorCodes.WATCH_CALLBACK */, [onCleanup]);
  2992. };
  2993. }
  2994. }
  2995. else {
  2996. getter = NOOP;
  2997. (process.env.NODE_ENV !== 'production') && warnInvalidSource(source);
  2998. }
  2999. if (cb && deep) {
  3000. const baseGetter = getter;
  3001. getter = () => traverse(baseGetter());
  3002. }
  3003. let cleanup;
  3004. let onCleanup = (fn) => {
  3005. cleanup = effect.onStop = () => {
  3006. callWithErrorHandling(fn, instance, 4 /* ErrorCodes.WATCH_CLEANUP */);
  3007. };
  3008. };
  3009. // in SSR there is no need to setup an actual effect, and it should be noop
  3010. // unless it's eager or sync flush
  3011. let ssrCleanup;
  3012. if (isInSSRComponentSetup) {
  3013. // we will also not call the invalidate callback (+ runner is not set up)
  3014. onCleanup = NOOP;
  3015. if (!cb) {
  3016. getter();
  3017. }
  3018. else if (immediate) {
  3019. callWithAsyncErrorHandling(cb, instance, 3 /* ErrorCodes.WATCH_CALLBACK */, [
  3020. getter(),
  3021. isMultiSource ? [] : undefined,
  3022. onCleanup
  3023. ]);
  3024. }
  3025. if (flush === 'sync') {
  3026. const ctx = useSSRContext();
  3027. ssrCleanup = ctx.__watcherHandles || (ctx.__watcherHandles = []);
  3028. }
  3029. else {
  3030. return NOOP;
  3031. }
  3032. }
  3033. let oldValue = isMultiSource
  3034. ? new Array(source.length).fill(INITIAL_WATCHER_VALUE)
  3035. : INITIAL_WATCHER_VALUE;
  3036. const job = () => {
  3037. if (!effect.active) {
  3038. return;
  3039. }
  3040. if (cb) {
  3041. // watch(source, cb)
  3042. const newValue = effect.run();
  3043. if (deep ||
  3044. forceTrigger ||
  3045. (isMultiSource
  3046. ? newValue.some((v, i) => hasChanged(v, oldValue[i]))
  3047. : hasChanged(newValue, oldValue)) ||
  3048. (false )) {
  3049. // cleanup before running cb again
  3050. if (cleanup) {
  3051. cleanup();
  3052. }
  3053. callWithAsyncErrorHandling(cb, instance, 3 /* ErrorCodes.WATCH_CALLBACK */, [
  3054. newValue,
  3055. // pass undefined as the old value when it's changed for the first time
  3056. oldValue === INITIAL_WATCHER_VALUE
  3057. ? undefined
  3058. : isMultiSource && oldValue[0] === INITIAL_WATCHER_VALUE
  3059. ? []
  3060. : oldValue,
  3061. onCleanup
  3062. ]);
  3063. oldValue = newValue;
  3064. }
  3065. }
  3066. else {
  3067. // watchEffect
  3068. effect.run();
  3069. }
  3070. };
  3071. // important: mark the job as a watcher callback so that scheduler knows
  3072. // it is allowed to self-trigger (#1727)
  3073. job.allowRecurse = !!cb;
  3074. let scheduler;
  3075. if (flush === 'sync') {
  3076. scheduler = job; // the scheduler function gets called directly
  3077. }
  3078. else if (flush === 'post') {
  3079. scheduler = () => queuePostRenderEffect(job, instance && instance.suspense);
  3080. }
  3081. else {
  3082. // default: 'pre'
  3083. job.pre = true;
  3084. if (instance)
  3085. job.id = instance.uid;
  3086. scheduler = () => queueJob(job);
  3087. }
  3088. const effect = new ReactiveEffect(getter, scheduler);
  3089. if ((process.env.NODE_ENV !== 'production')) {
  3090. effect.onTrack = onTrack;
  3091. effect.onTrigger = onTrigger;
  3092. }
  3093. // initial run
  3094. if (cb) {
  3095. if (immediate) {
  3096. job();
  3097. }
  3098. else {
  3099. oldValue = effect.run();
  3100. }
  3101. }
  3102. else if (flush === 'post') {
  3103. queuePostRenderEffect(effect.run.bind(effect), instance && instance.suspense);
  3104. }
  3105. else {
  3106. effect.run();
  3107. }
  3108. const unwatch = () => {
  3109. effect.stop();
  3110. if (instance && instance.scope) {
  3111. remove(instance.scope.effects, effect);
  3112. }
  3113. };
  3114. if (ssrCleanup)
  3115. ssrCleanup.push(unwatch);
  3116. return unwatch;
  3117. }
  3118. // this.$watch
  3119. function instanceWatch(source, value, options) {
  3120. const publicThis = this.proxy;
  3121. const getter = isString(source)
  3122. ? source.includes('.')
  3123. ? createPathGetter(publicThis, source)
  3124. : () => publicThis[source]
  3125. : source.bind(publicThis, publicThis);
  3126. let cb;
  3127. if (isFunction(value)) {
  3128. cb = value;
  3129. }
  3130. else {
  3131. cb = value.handler;
  3132. options = value;
  3133. }
  3134. const cur = currentInstance;
  3135. setCurrentInstance(this);
  3136. const res = doWatch(getter, cb.bind(publicThis), options);
  3137. if (cur) {
  3138. setCurrentInstance(cur);
  3139. }
  3140. else {
  3141. unsetCurrentInstance();
  3142. }
  3143. return res;
  3144. }
  3145. function createPathGetter(ctx, path) {
  3146. const segments = path.split('.');
  3147. return () => {
  3148. let cur = ctx;
  3149. for (let i = 0; i < segments.length && cur; i++) {
  3150. cur = cur[segments[i]];
  3151. }
  3152. return cur;
  3153. };
  3154. }
  3155. function traverse(value, seen) {
  3156. if (!isObject(value) || value["__v_skip" /* ReactiveFlags.SKIP */]) {
  3157. return value;
  3158. }
  3159. seen = seen || new Set();
  3160. if (seen.has(value)) {
  3161. return value;
  3162. }
  3163. seen.add(value);
  3164. if (isRef(value)) {
  3165. traverse(value.value, seen);
  3166. }
  3167. else if (isArray(value)) {
  3168. for (let i = 0; i < value.length; i++) {
  3169. traverse(value[i], seen);
  3170. }
  3171. }
  3172. else if (isSet(value) || isMap(value)) {
  3173. value.forEach((v) => {
  3174. traverse(v, seen);
  3175. });
  3176. }
  3177. else if (isPlainObject(value)) {
  3178. for (const key in value) {
  3179. traverse(value[key], seen);
  3180. }
  3181. }
  3182. return value;
  3183. }
  3184. function useTransitionState() {
  3185. const state = {
  3186. isMounted: false,
  3187. isLeaving: false,
  3188. isUnmounting: false,
  3189. leavingVNodes: new Map()
  3190. };
  3191. onMounted(() => {
  3192. state.isMounted = true;
  3193. });
  3194. onBeforeUnmount(() => {
  3195. state.isUnmounting = true;
  3196. });
  3197. return state;
  3198. }
  3199. const TransitionHookValidator = [Function, Array];
  3200. const BaseTransitionPropsValidators = {
  3201. mode: String,
  3202. appear: Boolean,
  3203. persisted: Boolean,
  3204. // enter
  3205. onBeforeEnter: TransitionHookValidator,
  3206. onEnter: TransitionHookValidator,
  3207. onAfterEnter: TransitionHookValidator,
  3208. onEnterCancelled: TransitionHookValidator,
  3209. // leave
  3210. onBeforeLeave: TransitionHookValidator,
  3211. onLeave: TransitionHookValidator,
  3212. onAfterLeave: TransitionHookValidator,
  3213. onLeaveCancelled: TransitionHookValidator,
  3214. // appear
  3215. onBeforeAppear: TransitionHookValidator,
  3216. onAppear: TransitionHookValidator,
  3217. onAfterAppear: TransitionHookValidator,
  3218. onAppearCancelled: TransitionHookValidator
  3219. };
  3220. const BaseTransitionImpl = {
  3221. name: `BaseTransition`,
  3222. props: BaseTransitionPropsValidators,
  3223. setup(props, { slots }) {
  3224. const instance = getCurrentInstance();
  3225. const state = useTransitionState();
  3226. let prevTransitionKey;
  3227. return () => {
  3228. const children = slots.default && getTransitionRawChildren(slots.default(), true);
  3229. if (!children || !children.length) {
  3230. return;
  3231. }
  3232. let child = children[0];
  3233. if (children.length > 1) {
  3234. let hasFound = false;
  3235. // locate first non-comment child
  3236. for (const c of children) {
  3237. if (c.type !== Comment) {
  3238. if ((process.env.NODE_ENV !== 'production') && hasFound) {
  3239. // warn more than one non-comment child
  3240. warn('<transition> can only be used on a single element or component. ' +
  3241. 'Use <transition-group> for lists.');
  3242. break;
  3243. }
  3244. child = c;
  3245. hasFound = true;
  3246. if (!(process.env.NODE_ENV !== 'production'))
  3247. break;
  3248. }
  3249. }
  3250. }
  3251. // there's no need to track reactivity for these props so use the raw
  3252. // props for a bit better perf
  3253. const rawProps = toRaw(props);
  3254. const { mode } = rawProps;
  3255. // check mode
  3256. if ((process.env.NODE_ENV !== 'production') &&
  3257. mode &&
  3258. mode !== 'in-out' &&
  3259. mode !== 'out-in' &&
  3260. mode !== 'default') {
  3261. warn(`invalid <transition> mode: ${mode}`);
  3262. }
  3263. if (state.isLeaving) {
  3264. return emptyPlaceholder(child);
  3265. }
  3266. // in the case of <transition><keep-alive/></transition>, we need to
  3267. // compare the type of the kept-alive children.
  3268. const innerChild = getKeepAliveChild(child);
  3269. if (!innerChild) {
  3270. return emptyPlaceholder(child);
  3271. }
  3272. const enterHooks = resolveTransitionHooks(innerChild, rawProps, state, instance);
  3273. setTransitionHooks(innerChild, enterHooks);
  3274. const oldChild = instance.subTree;
  3275. const oldInnerChild = oldChild && getKeepAliveChild(oldChild);
  3276. let transitionKeyChanged = false;
  3277. const { getTransitionKey } = innerChild.type;
  3278. if (getTransitionKey) {
  3279. const key = getTransitionKey();
  3280. if (prevTransitionKey === undefined) {
  3281. prevTransitionKey = key;
  3282. }
  3283. else if (key !== prevTransitionKey) {
  3284. prevTransitionKey = key;
  3285. transitionKeyChanged = true;
  3286. }
  3287. }
  3288. // handle mode
  3289. if (oldInnerChild &&
  3290. oldInnerChild.type !== Comment &&
  3291. (!isSameVNodeType(innerChild, oldInnerChild) || transitionKeyChanged)) {
  3292. const leavingHooks = resolveTransitionHooks(oldInnerChild, rawProps, state, instance);
  3293. // update old tree's hooks in case of dynamic transition
  3294. setTransitionHooks(oldInnerChild, leavingHooks);
  3295. // switching between different views
  3296. if (mode === 'out-in') {
  3297. state.isLeaving = true;
  3298. // return placeholder node and queue update when leave finishes
  3299. leavingHooks.afterLeave = () => {
  3300. state.isLeaving = false;
  3301. // #6835
  3302. // it also needs to be updated when active is undefined
  3303. if (instance.update.active !== false) {
  3304. instance.update();
  3305. }
  3306. };
  3307. return emptyPlaceholder(child);
  3308. }
  3309. else if (mode === 'in-out' && innerChild.type !== Comment) {
  3310. leavingHooks.delayLeave = (el, earlyRemove, delayedLeave) => {
  3311. const leavingVNodesCache = getLeavingNodesForType(state, oldInnerChild);
  3312. leavingVNodesCache[String(oldInnerChild.key)] = oldInnerChild;
  3313. // early removal callback
  3314. el._leaveCb = () => {
  3315. earlyRemove();
  3316. el._leaveCb = undefined;
  3317. delete enterHooks.delayedLeave;
  3318. };
  3319. enterHooks.delayedLeave = delayedLeave;
  3320. };
  3321. }
  3322. }
  3323. return child;
  3324. };
  3325. }
  3326. };
  3327. // export the public type for h/tsx inference
  3328. // also to avoid inline import() in generated d.ts files
  3329. const BaseTransition = BaseTransitionImpl;
  3330. function getLeavingNodesForType(state, vnode) {
  3331. const { leavingVNodes } = state;
  3332. let leavingVNodesCache = leavingVNodes.get(vnode.type);
  3333. if (!leavingVNodesCache) {
  3334. leavingVNodesCache = Object.create(null);
  3335. leavingVNodes.set(vnode.type, leavingVNodesCache);
  3336. }
  3337. return leavingVNodesCache;
  3338. }
  3339. // The transition hooks are attached to the vnode as vnode.transition
  3340. // and will be called at appropriate timing in the renderer.
  3341. function resolveTransitionHooks(vnode, props, state, instance) {
  3342. const { appear, mode, persisted = false, onBeforeEnter, onEnter, onAfterEnter, onEnterCancelled, onBeforeLeave, onLeave, onAfterLeave, onLeaveCancelled, onBeforeAppear, onAppear, onAfterAppear, onAppearCancelled } = props;
  3343. const key = String(vnode.key);
  3344. const leavingVNodesCache = getLeavingNodesForType(state, vnode);
  3345. const callHook = (hook, args) => {
  3346. hook &&
  3347. callWithAsyncErrorHandling(hook, instance, 9 /* ErrorCodes.TRANSITION_HOOK */, args);
  3348. };
  3349. const callAsyncHook = (hook, args) => {
  3350. const done = args[1];
  3351. callHook(hook, args);
  3352. if (isArray(hook)) {
  3353. if (hook.every(hook => hook.length <= 1))
  3354. done();
  3355. }
  3356. else if (hook.length <= 1) {
  3357. done();
  3358. }
  3359. };
  3360. const hooks = {
  3361. mode,
  3362. persisted,
  3363. beforeEnter(el) {
  3364. let hook = onBeforeEnter;
  3365. if (!state.isMounted) {
  3366. if (appear) {
  3367. hook = onBeforeAppear || onBeforeEnter;
  3368. }
  3369. else {
  3370. return;
  3371. }
  3372. }
  3373. // for same element (v-show)
  3374. if (el._leaveCb) {
  3375. el._leaveCb(true /* cancelled */);
  3376. }
  3377. // for toggled element with same key (v-if)
  3378. const leavingVNode = leavingVNodesCache[key];
  3379. if (leavingVNode &&
  3380. isSameVNodeType(vnode, leavingVNode) &&
  3381. leavingVNode.el._leaveCb) {
  3382. // force early removal (not cancelled)
  3383. leavingVNode.el._leaveCb();
  3384. }
  3385. callHook(hook, [el]);
  3386. },
  3387. enter(el) {
  3388. let hook = onEnter;
  3389. let afterHook = onAfterEnter;
  3390. let cancelHook = onEnterCancelled;
  3391. if (!state.isMounted) {
  3392. if (appear) {
  3393. hook = onAppear || onEnter;
  3394. afterHook = onAfterAppear || onAfterEnter;
  3395. cancelHook = onAppearCancelled || onEnterCancelled;
  3396. }
  3397. else {
  3398. return;
  3399. }
  3400. }
  3401. let called = false;
  3402. const done = (el._enterCb = (cancelled) => {
  3403. if (called)
  3404. return;
  3405. called = true;
  3406. if (cancelled) {
  3407. callHook(cancelHook, [el]);
  3408. }
  3409. else {
  3410. callHook(afterHook, [el]);
  3411. }
  3412. if (hooks.delayedLeave) {
  3413. hooks.delayedLeave();
  3414. }
  3415. el._enterCb = undefined;
  3416. });
  3417. if (hook) {
  3418. callAsyncHook(hook, [el, done]);
  3419. }
  3420. else {
  3421. done();
  3422. }
  3423. },
  3424. leave(el, remove) {
  3425. const key = String(vnode.key);
  3426. if (el._enterCb) {
  3427. el._enterCb(true /* cancelled */);
  3428. }
  3429. if (state.isUnmounting) {
  3430. return remove();
  3431. }
  3432. callHook(onBeforeLeave, [el]);
  3433. let called = false;
  3434. const done = (el._leaveCb = (cancelled) => {
  3435. if (called)
  3436. return;
  3437. called = true;
  3438. remove();
  3439. if (cancelled) {
  3440. callHook(onLeaveCancelled, [el]);
  3441. }
  3442. else {
  3443. callHook(onAfterLeave, [el]);
  3444. }
  3445. el._leaveCb = undefined;
  3446. if (leavingVNodesCache[key] === vnode) {
  3447. delete leavingVNodesCache[key];
  3448. }
  3449. });
  3450. leavingVNodesCache[key] = vnode;
  3451. if (onLeave) {
  3452. callAsyncHook(onLeave, [el, done]);
  3453. }
  3454. else {
  3455. done();
  3456. }
  3457. },
  3458. clone(vnode) {
  3459. return resolveTransitionHooks(vnode, props, state, instance);
  3460. }
  3461. };
  3462. return hooks;
  3463. }
  3464. // the placeholder really only handles one special case: KeepAlive
  3465. // in the case of a KeepAlive in a leave phase we need to return a KeepAlive
  3466. // placeholder with empty content to avoid the KeepAlive instance from being
  3467. // unmounted.
  3468. function emptyPlaceholder(vnode) {
  3469. if (isKeepAlive(vnode)) {
  3470. vnode = cloneVNode(vnode);
  3471. vnode.children = null;
  3472. return vnode;
  3473. }
  3474. }
  3475. function getKeepAliveChild(vnode) {
  3476. return isKeepAlive(vnode)
  3477. ? vnode.children
  3478. ? vnode.children[0]
  3479. : undefined
  3480. : vnode;
  3481. }
  3482. function setTransitionHooks(vnode, hooks) {
  3483. if (vnode.shapeFlag & 6 /* ShapeFlags.COMPONENT */ && vnode.component) {
  3484. setTransitionHooks(vnode.component.subTree, hooks);
  3485. }
  3486. else if (vnode.shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
  3487. vnode.ssContent.transition = hooks.clone(vnode.ssContent);
  3488. vnode.ssFallback.transition = hooks.clone(vnode.ssFallback);
  3489. }
  3490. else {
  3491. vnode.transition = hooks;
  3492. }
  3493. }
  3494. function getTransitionRawChildren(children, keepComment = false, parentKey) {
  3495. let ret = [];
  3496. let keyedFragmentCount = 0;
  3497. for (let i = 0; i < children.length; i++) {
  3498. let child = children[i];
  3499. // #5360 inherit parent key in case of <template v-for>
  3500. const key = parentKey == null
  3501. ? child.key
  3502. : String(parentKey) + String(child.key != null ? child.key : i);
  3503. // handle fragment children case, e.g. v-for
  3504. if (child.type === Fragment) {
  3505. if (child.patchFlag & 128 /* PatchFlags.KEYED_FRAGMENT */)
  3506. keyedFragmentCount++;
  3507. ret = ret.concat(getTransitionRawChildren(child.children, keepComment, key));
  3508. }
  3509. // comment placeholders should be skipped, e.g. v-if
  3510. else if (keepComment || child.type !== Comment) {
  3511. ret.push(key != null ? cloneVNode(child, { key }) : child);
  3512. }
  3513. }
  3514. // #1126 if a transition children list contains multiple sub fragments, these
  3515. // fragments will be merged into a flat children array. Since each v-for
  3516. // fragment may contain different static bindings inside, we need to de-op
  3517. // these children to force full diffs to ensure correct behavior.
  3518. if (keyedFragmentCount > 1) {
  3519. for (let i = 0; i < ret.length; i++) {
  3520. ret[i].patchFlag = -2 /* PatchFlags.BAIL */;
  3521. }
  3522. }
  3523. return ret;
  3524. }
  3525. // implementation, close to no-op
  3526. function defineComponent(options) {
  3527. return isFunction(options) ? { setup: options, name: options.name } : options;
  3528. }
  3529. const isAsyncWrapper = (i) => !!i.type.__asyncLoader;
  3530. function defineAsyncComponent(source) {
  3531. if (isFunction(source)) {
  3532. source = { loader: source };
  3533. }
  3534. const { loader, loadingComponent, errorComponent, delay = 200, timeout, // undefined = never times out
  3535. suspensible = true, onError: userOnError } = source;
  3536. let pendingRequest = null;
  3537. let resolvedComp;
  3538. let retries = 0;
  3539. const retry = () => {
  3540. retries++;
  3541. pendingRequest = null;
  3542. return load();
  3543. };
  3544. const load = () => {
  3545. let thisRequest;
  3546. return (pendingRequest ||
  3547. (thisRequest = pendingRequest =
  3548. loader()
  3549. .catch(err => {
  3550. err = err instanceof Error ? err : new Error(String(err));
  3551. if (userOnError) {
  3552. return new Promise((resolve, reject) => {
  3553. const userRetry = () => resolve(retry());
  3554. const userFail = () => reject(err);
  3555. userOnError(err, userRetry, userFail, retries + 1);
  3556. });
  3557. }
  3558. else {
  3559. throw err;
  3560. }
  3561. })
  3562. .then((comp) => {
  3563. if (thisRequest !== pendingRequest && pendingRequest) {
  3564. return pendingRequest;
  3565. }
  3566. if ((process.env.NODE_ENV !== 'production') && !comp) {
  3567. warn(`Async component loader resolved to undefined. ` +
  3568. `If you are using retry(), make sure to return its return value.`);
  3569. }
  3570. // interop module default
  3571. if (comp &&
  3572. (comp.__esModule || comp[Symbol.toStringTag] === 'Module')) {
  3573. comp = comp.default;
  3574. }
  3575. if ((process.env.NODE_ENV !== 'production') && comp && !isObject(comp) && !isFunction(comp)) {
  3576. throw new Error(`Invalid async component load result: ${comp}`);
  3577. }
  3578. resolvedComp = comp;
  3579. return comp;
  3580. })));
  3581. };
  3582. return defineComponent({
  3583. name: 'AsyncComponentWrapper',
  3584. __asyncLoader: load,
  3585. get __asyncResolved() {
  3586. return resolvedComp;
  3587. },
  3588. setup() {
  3589. const instance = currentInstance;
  3590. // already resolved
  3591. if (resolvedComp) {
  3592. return () => createInnerComp(resolvedComp, instance);
  3593. }
  3594. const onError = (err) => {
  3595. pendingRequest = null;
  3596. handleError(err, instance, 13 /* ErrorCodes.ASYNC_COMPONENT_LOADER */, !errorComponent /* do not throw in dev if user provided error component */);
  3597. };
  3598. // suspense-controlled or SSR.
  3599. if ((suspensible && instance.suspense) ||
  3600. (isInSSRComponentSetup)) {
  3601. return load()
  3602. .then(comp => {
  3603. return () => createInnerComp(comp, instance);
  3604. })
  3605. .catch(err => {
  3606. onError(err);
  3607. return () => errorComponent
  3608. ? createVNode(errorComponent, {
  3609. error: err
  3610. })
  3611. : null;
  3612. });
  3613. }
  3614. const loaded = ref(false);
  3615. const error = ref();
  3616. const delayed = ref(!!delay);
  3617. if (delay) {
  3618. setTimeout(() => {
  3619. delayed.value = false;
  3620. }, delay);
  3621. }
  3622. if (timeout != null) {
  3623. setTimeout(() => {
  3624. if (!loaded.value && !error.value) {
  3625. const err = new Error(`Async component timed out after ${timeout}ms.`);
  3626. onError(err);
  3627. error.value = err;
  3628. }
  3629. }, timeout);
  3630. }
  3631. load()
  3632. .then(() => {
  3633. loaded.value = true;
  3634. if (instance.parent && isKeepAlive(instance.parent.vnode)) {
  3635. // parent is keep-alive, force update so the loaded component's
  3636. // name is taken into account
  3637. queueJob(instance.parent.update);
  3638. }
  3639. })
  3640. .catch(err => {
  3641. onError(err);
  3642. error.value = err;
  3643. });
  3644. return () => {
  3645. if (loaded.value && resolvedComp) {
  3646. return createInnerComp(resolvedComp, instance);
  3647. }
  3648. else if (error.value && errorComponent) {
  3649. return createVNode(errorComponent, {
  3650. error: error.value
  3651. });
  3652. }
  3653. else if (loadingComponent && !delayed.value) {
  3654. return createVNode(loadingComponent);
  3655. }
  3656. };
  3657. }
  3658. });
  3659. }
  3660. function createInnerComp(comp, parent) {
  3661. const { ref, props, children, ce } = parent.vnode;
  3662. const vnode = createVNode(comp, props, children);
  3663. // ensure inner component inherits the async wrapper's ref owner
  3664. vnode.ref = ref;
  3665. // pass the custom element callback on to the inner comp
  3666. // and remove it from the async wrapper
  3667. vnode.ce = ce;
  3668. delete parent.vnode.ce;
  3669. return vnode;
  3670. }
  3671. const isKeepAlive = (vnode) => vnode.type.__isKeepAlive;
  3672. class Cache {
  3673. constructor(max) {
  3674. this.max = max;
  3675. this._cache = new Map();
  3676. this._keys = new Set();
  3677. this._max = parseInt(max, 10);
  3678. }
  3679. get(key) {
  3680. const { _cache, _keys, _max } = this;
  3681. const cached = _cache.get(key);
  3682. if (cached) {
  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 > _max) {
  3691. const staleKey = _keys.values().next().value;
  3692. this.pruneCacheEntry(_cache.get(staleKey));
  3693. this.delete(staleKey);
  3694. }
  3695. }
  3696. return cached;
  3697. }
  3698. set(key, value) {
  3699. this._cache.set(key, value);
  3700. }
  3701. delete(key) {
  3702. this._cache.delete(key);
  3703. this._keys.delete(key);
  3704. }
  3705. forEach(fn, thisArg) {
  3706. this._cache.forEach(fn.bind(thisArg));
  3707. }
  3708. }
  3709. const KeepAliveImpl = {
  3710. name: `KeepAlive`,
  3711. // Marker for special handling inside the renderer. We are not using a ===
  3712. // check directly on KeepAlive in the renderer, because importing it directly
  3713. // would prevent it from being tree-shaken.
  3714. __isKeepAlive: true,
  3715. props: {
  3716. include: [String, RegExp, Array],
  3717. exclude: [String, RegExp, Array],
  3718. max: [String, Number],
  3719. matchBy: {
  3720. type: String,
  3721. default: 'name'
  3722. },
  3723. cache: Object
  3724. },
  3725. setup(props, { slots }) {
  3726. const instance = getCurrentInstance();
  3727. // KeepAlive communicates with the instantiated renderer via the
  3728. // ctx where the renderer passes in its internals,
  3729. // and the KeepAlive instance exposes activate/deactivate implementations.
  3730. // The whole point of this is to avoid importing KeepAlive directly in the
  3731. // renderer to facilitate tree-shaking.
  3732. const sharedContext = instance.ctx;
  3733. // if the internal renderer is not registered, it indicates that this is server-side rendering,
  3734. // for KeepAlive, we just need to render its children
  3735. if (!sharedContext.renderer) {
  3736. return () => {
  3737. const children = slots.default && slots.default();
  3738. return children && children.length === 1 ? children[0] : children;
  3739. };
  3740. }
  3741. if ((process.env.NODE_ENV !== 'production') && props.cache && props.max) {
  3742. // fixed by xxxxxx
  3743. warn('The `max` prop will be ignored if you provide a custom caching strategy');
  3744. }
  3745. const cache = props.cache || new Cache(props.max);
  3746. cache.pruneCacheEntry = pruneCacheEntry;
  3747. let current = null;
  3748. function pruneCacheEntry(cached) {
  3749. if (!current ||
  3750. !isSameVNodeType(cached, current) ||
  3751. (props.matchBy === 'key' && cached.key !== current.key)) {
  3752. unmount(cached);
  3753. }
  3754. else if (current) {
  3755. // current active instance should no longer be kept-alive.
  3756. // we can't unmount it now but it might be later, so reset its flag now.
  3757. resetShapeFlag(current);
  3758. }
  3759. }
  3760. const parentSuspense = instance.suspense;
  3761. const { renderer: { p: patch, m: move, um: _unmount, o: { createElement } } } = sharedContext;
  3762. const storageContainer = createElement('div');
  3763. sharedContext.activate = (vnode, container, anchor, isSVG, optimized) => {
  3764. const instance = vnode.component;
  3765. if (instance.ba) {
  3766. const currentState = instance.isDeactivated;
  3767. instance.isDeactivated = false;
  3768. invokeArrayFns(instance.ba);
  3769. instance.isDeactivated = currentState;
  3770. }
  3771. move(vnode, container, anchor, 0 /* MoveType.ENTER */, parentSuspense);
  3772. // in case props have changed
  3773. patch(instance.vnode, vnode, container, anchor, instance, parentSuspense, isSVG, vnode.slotScopeIds, optimized);
  3774. queuePostRenderEffect(() => {
  3775. instance.isDeactivated = false;
  3776. if (instance.a) {
  3777. invokeArrayFns(instance.a);
  3778. }
  3779. const vnodeHook = vnode.props && vnode.props.onVnodeMounted;
  3780. if (vnodeHook) {
  3781. invokeVNodeHook(vnodeHook, instance.parent, vnode);
  3782. }
  3783. }, parentSuspense);
  3784. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  3785. // Update components tree
  3786. devtoolsComponentAdded(instance);
  3787. }
  3788. };
  3789. sharedContext.deactivate = (vnode) => {
  3790. const instance = vnode.component;
  3791. if (instance.bda) {
  3792. invokeKeepAliveHooks(instance.bda);
  3793. }
  3794. move(vnode, storageContainer, null, 1 /* MoveType.LEAVE */, parentSuspense);
  3795. queuePostRenderEffect(() => {
  3796. if (instance.bda) {
  3797. resetHookState(instance.bda);
  3798. }
  3799. if (instance.da) {
  3800. invokeArrayFns(instance.da);
  3801. }
  3802. const vnodeHook = vnode.props && vnode.props.onVnodeUnmounted;
  3803. if (vnodeHook) {
  3804. invokeVNodeHook(vnodeHook, instance.parent, vnode);
  3805. }
  3806. instance.isDeactivated = true;
  3807. }, parentSuspense);
  3808. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  3809. // Update components tree
  3810. devtoolsComponentAdded(instance);
  3811. }
  3812. };
  3813. function unmount(vnode) {
  3814. // reset the shapeFlag so it can be properly unmounted
  3815. resetShapeFlag(vnode);
  3816. _unmount(vnode, instance, parentSuspense, true);
  3817. }
  3818. function pruneCache(filter) {
  3819. cache.forEach((vnode, key) => {
  3820. const name = getMatchingName(vnode, props.matchBy);
  3821. if (name && (!filter || !filter(name))) {
  3822. cache.delete(key);
  3823. pruneCacheEntry(vnode);
  3824. }
  3825. });
  3826. }
  3827. // prune cache on include/exclude prop change
  3828. watch(() => [props.include, props.exclude, props.matchBy], ([include, exclude]) => {
  3829. include && pruneCache(name => matches(include, name));
  3830. exclude && pruneCache(name => !matches(exclude, name));
  3831. },
  3832. // prune post-render after `current` has been updated
  3833. { flush: 'post', deep: true });
  3834. // cache sub tree after render
  3835. let pendingCacheKey = null;
  3836. const cacheSubtree = () => {
  3837. // fix #1621, the pendingCacheKey could be 0
  3838. if (pendingCacheKey != null) {
  3839. cache.set(pendingCacheKey, getInnerChild(instance.subTree));
  3840. }
  3841. };
  3842. onMounted(cacheSubtree);
  3843. onUpdated(cacheSubtree);
  3844. onBeforeUnmount(() => {
  3845. cache.forEach((cached, key) => {
  3846. cache.delete(key);
  3847. pruneCacheEntry(cached);
  3848. const { subTree, suspense } = instance;
  3849. const vnode = getInnerChild(subTree);
  3850. if (cached.type === vnode.type &&
  3851. (props.matchBy !== 'key' || cached.key === vnode.key)) {
  3852. // invoke its beforeDeactivate hook here
  3853. if (vnode.component.bda) {
  3854. invokeArrayFns(vnode.component.bda);
  3855. }
  3856. // current instance will be unmounted as part of keep-alive's unmount
  3857. resetShapeFlag(vnode);
  3858. // but invoke its deactivated hook here
  3859. const da = vnode.component.da;
  3860. da && queuePostRenderEffect(da, suspense);
  3861. return;
  3862. }
  3863. });
  3864. });
  3865. return () => {
  3866. pendingCacheKey = null;
  3867. if (!slots.default) {
  3868. return null;
  3869. }
  3870. const children = slots.default();
  3871. const rawVNode = children[0];
  3872. if (children.length > 1) {
  3873. if ((process.env.NODE_ENV !== 'production')) {
  3874. warn(`KeepAlive should contain exactly one component child.`);
  3875. }
  3876. current = null;
  3877. return children;
  3878. }
  3879. else if (!isVNode(rawVNode) ||
  3880. (!(rawVNode.shapeFlag & 4 /* ShapeFlags.STATEFUL_COMPONENT */) &&
  3881. !isSuspense(rawVNode.type))) {
  3882. current = null;
  3883. return rawVNode;
  3884. }
  3885. let vnode = getInnerChild(rawVNode);
  3886. const comp = vnode.type;
  3887. const name = getMatchingName(vnode, props.matchBy);
  3888. const { include, exclude } = props;
  3889. if ((include && (!name || !matches(include, name))) ||
  3890. (exclude && name && matches(exclude, name))) {
  3891. current = vnode;
  3892. return rawVNode;
  3893. }
  3894. const key = vnode.key == null ? comp : vnode.key;
  3895. const cachedVNode = cache.get(key);
  3896. // clone vnode if it's reused because we are going to mutate it
  3897. if (vnode.el) {
  3898. vnode = cloneVNode(vnode);
  3899. if (isSuspense(rawVNode.type)) {
  3900. rawVNode.ssContent = vnode;
  3901. }
  3902. }
  3903. // #1513 it's possible for the returned vnode to be cloned due to attr
  3904. // fallthrough or scopeId, so the vnode here may not be the final vnode
  3905. // that is mounted. Instead of caching it directly, we store the pending
  3906. // key and cache `instance.subTree` (the normalized vnode) in
  3907. // beforeMount/beforeUpdate hooks.
  3908. pendingCacheKey = key;
  3909. if (cachedVNode) {
  3910. // copy over mounted state
  3911. vnode.el = cachedVNode.el;
  3912. vnode.component = cachedVNode.component;
  3913. if (vnode.transition) {
  3914. // recursively update transition hooks on subTree
  3915. setTransitionHooks(vnode, vnode.transition);
  3916. }
  3917. // avoid vnode being mounted as fresh
  3918. vnode.shapeFlag |= 512 /* ShapeFlags.COMPONENT_KEPT_ALIVE */;
  3919. }
  3920. // avoid vnode being unmounted
  3921. vnode.shapeFlag |= 256 /* ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE */;
  3922. current = vnode;
  3923. return isSuspense(rawVNode.type) ? rawVNode : vnode;
  3924. };
  3925. }
  3926. };
  3927. // export the public type for h/tsx inference
  3928. // also to avoid inline import() in generated d.ts files
  3929. const KeepAlive = KeepAliveImpl;
  3930. function matches(pattern, name) {
  3931. if (isArray(pattern)) {
  3932. return pattern.some((p) => matches(p, name));
  3933. }
  3934. else if (isString(pattern)) {
  3935. return pattern.split(',').includes(name);
  3936. }
  3937. else if (pattern.test) {
  3938. return pattern.test(name);
  3939. }
  3940. /* istanbul ignore next */
  3941. return false;
  3942. }
  3943. function onBeforeActivate(hook, target) {
  3944. registerKeepAliveHook(hook, "ba" /* LifecycleHooks.BEFORE_ACTIVATE */, target);
  3945. }
  3946. function onActivated(hook, target) {
  3947. registerKeepAliveHook(hook, "a" /* LifecycleHooks.ACTIVATED */, target);
  3948. }
  3949. function onBeforeDeactivate(hook, target) {
  3950. registerKeepAliveHook(hook, "bda" /* LifecycleHooks.BEFORE_DEACTIVATE */, target);
  3951. }
  3952. function onDeactivated(hook, target) {
  3953. registerKeepAliveHook(hook, "da" /* LifecycleHooks.DEACTIVATED */, target);
  3954. }
  3955. function registerKeepAliveHook(hook, type, target = currentInstance) {
  3956. // cache the deactivate branch check wrapper for injected hooks so the same
  3957. // hook can be properly deduped by the scheduler. "__wdc" stands for "with
  3958. // deactivation check".
  3959. const wrappedHook = hook.__wdc ||
  3960. (hook.__wdc = () => {
  3961. // only fire the hook if the target instance is NOT in a deactivated branch.
  3962. let current = target;
  3963. while (current) {
  3964. if (current.isDeactivated) {
  3965. return;
  3966. }
  3967. current = current.parent;
  3968. }
  3969. return hook();
  3970. });
  3971. wrappedHook.__called = false;
  3972. injectHook(type, wrappedHook, target);
  3973. // In addition to registering it on the target instance, we walk up the parent
  3974. // chain and register it on all ancestor instances that are keep-alive roots.
  3975. // This avoids the need to walk the entire component tree when invoking these
  3976. // hooks, and more importantly, avoids the need to track child components in
  3977. // arrays.
  3978. if (target) {
  3979. let current = target.parent;
  3980. while (current && current.parent) {
  3981. if (isKeepAlive(current.parent.vnode)) {
  3982. injectToKeepAliveRoot(wrappedHook, type, target, current);
  3983. }
  3984. current = current.parent;
  3985. }
  3986. }
  3987. }
  3988. function injectToKeepAliveRoot(hook, type, target, keepAliveRoot) {
  3989. // injectHook wraps the original for error handling, so make sure to remove
  3990. // the wrapped version.
  3991. const injected = injectHook(type, hook, keepAliveRoot, true /* prepend */);
  3992. onUnmounted(() => {
  3993. remove(keepAliveRoot[type], injected);
  3994. }, target);
  3995. }
  3996. function resetShapeFlag(vnode) {
  3997. // bitwise operations to remove keep alive flags
  3998. vnode.shapeFlag &= ~256 /* ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE */;
  3999. vnode.shapeFlag &= ~512 /* ShapeFlags.COMPONENT_KEPT_ALIVE */;
  4000. }
  4001. function getInnerChild(vnode) {
  4002. return isSuspense(vnode.type) ? vnode.ssContent : vnode;
  4003. }
  4004. function getMatchingName(vnode, matchBy) {
  4005. if (matchBy === 'name') {
  4006. const comp = vnode.type;
  4007. return getComponentName(isAsyncWrapper(vnode)
  4008. ? comp.__asyncResolved || {}
  4009. : comp);
  4010. }
  4011. return String(vnode.key);
  4012. }
  4013. function invokeKeepAliveHooks(hooks) {
  4014. for (let i = 0; i < hooks.length; i++) {
  4015. const hook = hooks[i];
  4016. if (!hook.__called) {
  4017. hook();
  4018. hook.__called = true;
  4019. }
  4020. }
  4021. }
  4022. function resetHookState(hooks) {
  4023. hooks.forEach((hook) => (hook.__called = false));
  4024. }
  4025. function injectHook(type, hook, target = currentInstance, prepend = false) {
  4026. if (target) {
  4027. // fixed by xxxxxx
  4028. if (isRootHook(type) && target.$pageInstance) {
  4029. // 系统保留组件,如 view,app 等
  4030. if (target.type.__reserved) {
  4031. return;
  4032. }
  4033. if (target !== target.$pageInstance) {
  4034. target = target.$pageInstance;
  4035. if (isRootImmediateHook(type)) {
  4036. // 作用域应该是组件还是页面?目前绑定的是页面
  4037. const proxy = target.proxy;
  4038. callWithAsyncErrorHandling(hook.bind(proxy), target, type, ON_LOAD === type ? [proxy.$page.options] : []);
  4039. }
  4040. }
  4041. }
  4042. const hooks = target[type] || (target[type] = []);
  4043. // cache the error handling wrapper for injected hooks so the same hook
  4044. // can be properly deduped by the scheduler. "__weh" stands for "with error
  4045. // handling".
  4046. const wrappedHook = hook.__weh ||
  4047. (hook.__weh = (...args) => {
  4048. if (target.isUnmounted) {
  4049. // fixed by xxxxxx
  4050. return;
  4051. }
  4052. // disable tracking inside all lifecycle hooks
  4053. // since they can potentially be called inside effects.
  4054. pauseTracking();
  4055. // Set currentInstance during hook invocation.
  4056. // This assumes the hook does not synchronously trigger other hooks, which
  4057. // can only be false when the user does something really funky.
  4058. setCurrentInstance(target); // fixed by xxxxxx
  4059. const res = callWithAsyncErrorHandling(hook, target, type, args);
  4060. unsetCurrentInstance();
  4061. resetTracking();
  4062. return res;
  4063. });
  4064. if (prepend) {
  4065. hooks.unshift(wrappedHook);
  4066. }
  4067. else {
  4068. hooks.push(wrappedHook);
  4069. }
  4070. return wrappedHook;
  4071. }
  4072. else if ((process.env.NODE_ENV !== 'production')) {
  4073. const apiName = toHandlerKey((ErrorTypeStrings[type] || type.replace(/^on/, '')).replace(/ hook$/, '')); // fixed by xxxxxx
  4074. warn(`${apiName} is called when there is no active component instance to be ` +
  4075. `associated with. ` +
  4076. `Lifecycle injection APIs can only be used during execution of setup().` +
  4077. (` If you are using async setup(), make sure to register lifecycle ` +
  4078. `hooks before the first await statement.`
  4079. ));
  4080. }
  4081. }
  4082. const createHook = (lifecycle) => (hook, target = currentInstance) =>
  4083. // post-create lifecycle registrations are noops during SSR (except for serverPrefetch)
  4084. (!isInSSRComponentSetup || lifecycle === "sp" /* LifecycleHooks.SERVER_PREFETCH */) &&
  4085. injectHook(lifecycle, (...args) => hook(...args), target);
  4086. const onBeforeMount = createHook("bm" /* LifecycleHooks.BEFORE_MOUNT */);
  4087. const onMounted = createHook("m" /* LifecycleHooks.MOUNTED */);
  4088. const onBeforeUpdate = createHook("bu" /* LifecycleHooks.BEFORE_UPDATE */);
  4089. const onUpdated = createHook("u" /* LifecycleHooks.UPDATED */);
  4090. const onBeforeUnmount = createHook("bum" /* LifecycleHooks.BEFORE_UNMOUNT */);
  4091. const onUnmounted = createHook("um" /* LifecycleHooks.UNMOUNTED */);
  4092. const onServerPrefetch = createHook("sp" /* LifecycleHooks.SERVER_PREFETCH */);
  4093. const onRenderTriggered = createHook("rtg" /* LifecycleHooks.RENDER_TRIGGERED */);
  4094. const onRenderTracked = createHook("rtc" /* LifecycleHooks.RENDER_TRACKED */);
  4095. function onErrorCaptured(hook, target = currentInstance) {
  4096. injectHook("ec" /* LifecycleHooks.ERROR_CAPTURED */, hook, target);
  4097. }
  4098. /**
  4099. Runtime helper for applying directives to a vnode. Example usage:
  4100. const comp = resolveComponent('comp')
  4101. const foo = resolveDirective('foo')
  4102. const bar = resolveDirective('bar')
  4103. return withDirectives(h(comp), [
  4104. [foo, this.x],
  4105. [bar, this.y]
  4106. ])
  4107. */
  4108. function validateDirectiveName(name) {
  4109. if (isBuiltInDirective(name)) {
  4110. warn('Do not use built-in directive ids as custom directive id: ' + name);
  4111. }
  4112. }
  4113. /**
  4114. * Adds directives to a VNode.
  4115. */
  4116. function withDirectives(vnode, directives) {
  4117. const internalInstance = currentRenderingInstance;
  4118. if (internalInstance === null) {
  4119. (process.env.NODE_ENV !== 'production') && warn(`withDirectives can only be used inside render functions.`);
  4120. return vnode;
  4121. }
  4122. const instance = getExposeProxy(internalInstance) ||
  4123. internalInstance.proxy;
  4124. const bindings = vnode.dirs || (vnode.dirs = []);
  4125. for (let i = 0; i < directives.length; i++) {
  4126. let [dir, value, arg, modifiers = EMPTY_OBJ] = directives[i];
  4127. if (dir) {
  4128. if (isFunction(dir)) {
  4129. dir = {
  4130. mounted: dir,
  4131. updated: dir
  4132. };
  4133. }
  4134. if (dir.deep) {
  4135. traverse(value);
  4136. }
  4137. bindings.push({
  4138. dir,
  4139. instance,
  4140. value,
  4141. oldValue: void 0,
  4142. arg,
  4143. modifiers
  4144. });
  4145. }
  4146. }
  4147. return vnode;
  4148. }
  4149. function invokeDirectiveHook(vnode, prevVNode, instance, name) {
  4150. const bindings = vnode.dirs;
  4151. const oldBindings = prevVNode && prevVNode.dirs;
  4152. for (let i = 0; i < bindings.length; i++) {
  4153. const binding = bindings[i];
  4154. if (oldBindings) {
  4155. binding.oldValue = oldBindings[i].value;
  4156. }
  4157. let hook = binding.dir[name];
  4158. if (hook) {
  4159. // disable tracking inside all lifecycle hooks
  4160. // since they can potentially be called inside effects.
  4161. pauseTracking();
  4162. callWithAsyncErrorHandling(hook, instance, 8 /* ErrorCodes.DIRECTIVE_HOOK */, [
  4163. vnode.el,
  4164. binding,
  4165. vnode,
  4166. prevVNode
  4167. ]);
  4168. resetTracking();
  4169. }
  4170. }
  4171. }
  4172. const COMPONENTS = 'components';
  4173. const DIRECTIVES = 'directives';
  4174. /**
  4175. * @private
  4176. */
  4177. function resolveComponent(name, maybeSelfReference) {
  4178. return resolveAsset(COMPONENTS, name, true, maybeSelfReference) || name;
  4179. }
  4180. const NULL_DYNAMIC_COMPONENT = Symbol();
  4181. /**
  4182. * @private
  4183. */
  4184. function resolveDynamicComponent(component) {
  4185. if (isString(component)) {
  4186. return resolveAsset(COMPONENTS, component, false) || component;
  4187. }
  4188. else {
  4189. // invalid types will fallthrough to createVNode and raise warning
  4190. return (component || NULL_DYNAMIC_COMPONENT);
  4191. }
  4192. }
  4193. /**
  4194. * @private
  4195. */
  4196. function resolveDirective(name) {
  4197. return resolveAsset(DIRECTIVES, name);
  4198. }
  4199. // implementation
  4200. function resolveAsset(type, name, warnMissing = true, maybeSelfReference = false) {
  4201. const instance = currentRenderingInstance || currentInstance;
  4202. if (instance) {
  4203. const Component = instance.type;
  4204. // explicit self name has highest priority
  4205. if (type === COMPONENTS) {
  4206. const selfName = getComponentName(Component, false /* do not include inferred name to avoid breaking existing code */);
  4207. if (selfName &&
  4208. (selfName === name ||
  4209. selfName === camelize(name) ||
  4210. selfName === capitalize(camelize(name)))) {
  4211. return Component;
  4212. }
  4213. }
  4214. const res =
  4215. // local registration
  4216. // check instance[type] first which is resolved for options API
  4217. resolve(instance[type] || Component[type], name) ||
  4218. // global registration
  4219. resolve(instance.appContext[type], name);
  4220. if (!res && maybeSelfReference) {
  4221. // fallback to implicit self-reference
  4222. return Component;
  4223. }
  4224. if ((process.env.NODE_ENV !== 'production') && warnMissing && !res) {
  4225. const extra = type === COMPONENTS
  4226. ? `\nIf this is a native custom element, make sure to exclude it from ` +
  4227. `component resolution via compilerOptions.isCustomElement.`
  4228. : ``;
  4229. warn(`Failed to resolve ${type.slice(0, -1)}: ${name}${extra}`);
  4230. }
  4231. return res;
  4232. }
  4233. else if ((process.env.NODE_ENV !== 'production')) {
  4234. warn(`resolve${capitalize(type.slice(0, -1))} ` +
  4235. `can only be used in render() or setup().`);
  4236. }
  4237. }
  4238. function resolve(registry, name) {
  4239. return (registry &&
  4240. (registry[name] ||
  4241. registry[camelize(name)] ||
  4242. registry[capitalize(camelize(name))]));
  4243. }
  4244. /**
  4245. * Actual implementation
  4246. */
  4247. function renderList(source, renderItem, cache, index) {
  4248. let ret;
  4249. const cached = (cache && cache[index]);
  4250. if (isArray(source) || isString(source)) {
  4251. ret = new Array(source.length);
  4252. for (let i = 0, l = source.length; i < l; i++) {
  4253. ret[i] = renderItem(source[i], i, undefined, cached && cached[i]);
  4254. }
  4255. }
  4256. else if (typeof source === 'number') {
  4257. if ((process.env.NODE_ENV !== 'production') && !Number.isInteger(source)) {
  4258. warn(`The v-for range expect an integer value but got ${source}.`);
  4259. }
  4260. ret = new Array(source);
  4261. for (let i = 0; i < source; i++) {
  4262. ret[i] = renderItem(i + 1, i, undefined, cached && cached[i]);
  4263. }
  4264. }
  4265. else if (isObject(source)) {
  4266. if (source[Symbol.iterator]) {
  4267. ret = Array.from(source, (item, i) => renderItem(item, i, undefined, cached && cached[i]));
  4268. }
  4269. else {
  4270. const keys = Object.keys(source);
  4271. ret = new Array(keys.length);
  4272. for (let i = 0, l = keys.length; i < l; i++) {
  4273. const key = keys[i];
  4274. ret[i] = renderItem(source[key], key, i, cached && cached[i]);
  4275. }
  4276. }
  4277. }
  4278. else {
  4279. ret = [];
  4280. }
  4281. if (cache) {
  4282. cache[index] = ret;
  4283. }
  4284. return ret;
  4285. }
  4286. /**
  4287. * Compiler runtime helper for creating dynamic slots object
  4288. * @private
  4289. */
  4290. function createSlots(slots, dynamicSlots) {
  4291. for (let i = 0; i < dynamicSlots.length; i++) {
  4292. const slot = dynamicSlots[i];
  4293. // array of dynamic slot generated by <template v-for="..." #[...]>
  4294. if (isArray(slot)) {
  4295. for (let j = 0; j < slot.length; j++) {
  4296. slots[slot[j].name] = slot[j].fn;
  4297. }
  4298. }
  4299. else if (slot) {
  4300. // conditional single slot generated by <template v-if="..." #foo>
  4301. slots[slot.name] = slot.key
  4302. ? (...args) => {
  4303. const res = slot.fn(...args);
  4304. // attach branch key so each conditional branch is considered a
  4305. // different fragment
  4306. if (res)
  4307. res.key = slot.key;
  4308. return res;
  4309. }
  4310. : slot.fn;
  4311. }
  4312. }
  4313. return slots;
  4314. }
  4315. /**
  4316. * Compiler runtime helper for rendering `<slot/>`
  4317. * @private
  4318. */
  4319. function renderSlot(slots, name, props = {},
  4320. // this is not a user-facing function, so the fallback is always generated by
  4321. // the compiler and guaranteed to be a function returning an array
  4322. fallback, noSlotted) {
  4323. if (currentRenderingInstance.isCE ||
  4324. (currentRenderingInstance.parent &&
  4325. isAsyncWrapper(currentRenderingInstance.parent) &&
  4326. currentRenderingInstance.parent.isCE)) {
  4327. if (name !== 'default')
  4328. props.name = name;
  4329. return createVNode('slot', props, fallback && fallback());
  4330. }
  4331. let slot = slots[name];
  4332. if ((process.env.NODE_ENV !== 'production') && slot && slot.length > 1) {
  4333. warn(`SSR-optimized slot function detected in a non-SSR-optimized render ` +
  4334. `function. You need to mark this component with $dynamic-slots in the ` +
  4335. `parent template.`);
  4336. slot = () => [];
  4337. }
  4338. // a compiled slot disables block tracking by default to avoid manual
  4339. // invocation interfering with template-based block tracking, but in
  4340. // `renderSlot` we can be sure that it's template-based so we can force
  4341. // enable it.
  4342. if (slot && slot._c) {
  4343. slot._d = false;
  4344. }
  4345. openBlock();
  4346. const validSlotContent = slot && ensureValidVNode(slot(props));
  4347. const rendered = createBlock(Fragment, {
  4348. key: props.key ||
  4349. // slot content array of a dynamic conditional slot may have a branch
  4350. // key attached in the `createSlots` helper, respect that
  4351. (validSlotContent && validSlotContent.key) ||
  4352. `_${name}`
  4353. }, validSlotContent || (fallback ? fallback() : []), validSlotContent && slots._ === 1 /* SlotFlags.STABLE */
  4354. ? 64 /* PatchFlags.STABLE_FRAGMENT */
  4355. : -2 /* PatchFlags.BAIL */);
  4356. if (!noSlotted && rendered.scopeId) {
  4357. rendered.slotScopeIds = [rendered.scopeId + '-s'];
  4358. }
  4359. if (slot && slot._c) {
  4360. slot._d = true;
  4361. }
  4362. return rendered;
  4363. }
  4364. function ensureValidVNode(vnodes) {
  4365. return vnodes.some(child => {
  4366. if (!isVNode(child))
  4367. return true;
  4368. if (child.type === Comment)
  4369. return false;
  4370. if (child.type === Fragment &&
  4371. !ensureValidVNode(child.children))
  4372. return false;
  4373. return true;
  4374. })
  4375. ? vnodes
  4376. : null;
  4377. }
  4378. /**
  4379. * For prefixing keys in v-on="obj" with "on"
  4380. * @private
  4381. */
  4382. function toHandlers(obj, preserveCaseIfNecessary) {
  4383. const ret = {};
  4384. if ((process.env.NODE_ENV !== 'production') && !isObject(obj)) {
  4385. warn(`v-on with no argument expects an object value.`);
  4386. return ret;
  4387. }
  4388. for (const key in obj) {
  4389. ret[preserveCaseIfNecessary && /[A-Z]/.test(key)
  4390. ? `on:${key}`
  4391. : toHandlerKey(key)] = obj[key];
  4392. }
  4393. return ret;
  4394. }
  4395. function isUniBuiltInComponentInstance(p) {
  4396. return p && p.$options && (p.$options.__reserved || p.$options.rootElement);
  4397. }
  4398. /**
  4399. * #2437 In Vue 3, functional components do not have a public instance proxy but
  4400. * they exist in the internal parent chain. For code that relies on traversing
  4401. * public $parent chains, skip functional ones and go to the parent instead.
  4402. */
  4403. const getPublicInstance = (i) => {
  4404. if (!i)
  4405. return null;
  4406. if (isStatefulComponent(i)) {
  4407. const p = getExposeProxy(i) || i.proxy;
  4408. if (isUniBuiltInComponentInstance(p)) {
  4409. return getPublicInstance(i.parent);
  4410. }
  4411. return p;
  4412. }
  4413. return getPublicInstance(i.parent);
  4414. };
  4415. const publicPropertiesMap =
  4416. // Move PURE marker to new line to workaround compiler discarding it
  4417. // due to type annotation
  4418. /*#__PURE__*/ extend(Object.create(null), {
  4419. $: i => i,
  4420. $el: i => i.vnode.el,
  4421. $data: i => i.data,
  4422. $props: i => ((process.env.NODE_ENV !== 'production') ? shallowReadonly(i.props) : i.props),
  4423. $attrs: i => ((process.env.NODE_ENV !== 'production') ? shallowReadonly(i.attrs) : i.attrs),
  4424. $slots: i => ((process.env.NODE_ENV !== 'production') ? shallowReadonly(i.slots) : i.slots),
  4425. $refs: i => ((process.env.NODE_ENV !== 'production') ? shallowReadonly(i.refs) : i.refs),
  4426. $parent: i => getPublicInstance(i.parent),
  4427. $root: i => getPublicInstance(i.root),
  4428. $emit: i => i.emit,
  4429. $options: i => (__VUE_OPTIONS_API__ ? resolveMergedOptions(i) : i.type),
  4430. $forceUpdate: i => i.f ||
  4431. (i.f = () => {
  4432. queueJob(i.update);
  4433. const subTree = i.subTree;
  4434. if (subTree.shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  4435. const vnodes = subTree.children;
  4436. vnodes.forEach(vnode => {
  4437. if (!vnode.component) {
  4438. return;
  4439. }
  4440. const p = getExposeProxy(vnode.component) || vnode.component.proxy;
  4441. if (isUniBuiltInComponentInstance(p)) {
  4442. p.$forceUpdate();
  4443. }
  4444. });
  4445. }
  4446. else if (subTree.component) {
  4447. const p = getExposeProxy(subTree.component) || subTree.component.proxy;
  4448. if (isUniBuiltInComponentInstance(p)) {
  4449. p.$forceUpdate();
  4450. }
  4451. }
  4452. }),
  4453. $nextTick: i => i.n || (i.n = nextTick.bind(i.proxy)),
  4454. $watch: i => (__VUE_OPTIONS_API__ ? instanceWatch.bind(i) : NOOP)
  4455. });
  4456. const isReservedPrefix = (key) => key === '_' || key === '$';
  4457. const hasSetupBinding = (state, key) => state !== EMPTY_OBJ && !state.__isScriptSetup && hasOwn(state, key);
  4458. const PublicInstanceProxyHandlers = {
  4459. get({ _: instance }, key) {
  4460. const { ctx, setupState, data, props, accessCache, type, appContext } = instance;
  4461. // for internal formatters to know that this is a Vue instance
  4462. if ((process.env.NODE_ENV !== 'production') && key === '__isVue') {
  4463. return true;
  4464. }
  4465. // data / props / ctx
  4466. // This getter gets called for every property access on the render context
  4467. // during render and is a major hotspot. The most expensive part of this
  4468. // is the multiple hasOwn() calls. It's much faster to do a simple property
  4469. // access on a plain object, so we use an accessCache object (with null
  4470. // prototype) to memoize what access type a key corresponds to.
  4471. let normalizedProps;
  4472. if (key[0] !== '$') {
  4473. const n = accessCache[key];
  4474. if (n !== undefined) {
  4475. switch (n) {
  4476. case 1 /* AccessTypes.SETUP */:
  4477. return setupState[key];
  4478. case 2 /* AccessTypes.DATA */:
  4479. return data[key];
  4480. case 4 /* AccessTypes.CONTEXT */:
  4481. return ctx[key];
  4482. case 3 /* AccessTypes.PROPS */:
  4483. return props[key];
  4484. // default: just fallthrough
  4485. }
  4486. }
  4487. else if (hasSetupBinding(setupState, key)) {
  4488. accessCache[key] = 1 /* AccessTypes.SETUP */;
  4489. return setupState[key];
  4490. }
  4491. else if (data !== EMPTY_OBJ && hasOwn(data, key)) {
  4492. accessCache[key] = 2 /* AccessTypes.DATA */;
  4493. return data[key];
  4494. }
  4495. else if (
  4496. // only cache other properties when instance has declared (thus stable)
  4497. // props
  4498. (normalizedProps = instance.propsOptions[0]) &&
  4499. hasOwn(normalizedProps, key)) {
  4500. accessCache[key] = 3 /* AccessTypes.PROPS */;
  4501. return props[key];
  4502. }
  4503. else if (ctx !== EMPTY_OBJ && hasOwn(ctx, key)) {
  4504. accessCache[key] = 4 /* AccessTypes.CONTEXT */;
  4505. return ctx[key];
  4506. }
  4507. else if (!__VUE_OPTIONS_API__ || shouldCacheAccess) {
  4508. accessCache[key] = 0 /* AccessTypes.OTHER */;
  4509. }
  4510. }
  4511. const publicGetter = publicPropertiesMap[key];
  4512. let cssModule, globalProperties;
  4513. // public $xxx properties
  4514. if (publicGetter) {
  4515. if (key === '$attrs') {
  4516. track(instance, "get" /* TrackOpTypes.GET */, key);
  4517. (process.env.NODE_ENV !== 'production') && markAttrsAccessed();
  4518. }
  4519. return publicGetter(instance);
  4520. }
  4521. else if (
  4522. // css module (injected by vue-loader)
  4523. (cssModule = type.__cssModules) &&
  4524. (cssModule = cssModule[key])) {
  4525. return cssModule;
  4526. }
  4527. else if (ctx !== EMPTY_OBJ && hasOwn(ctx, key)) {
  4528. // user may set custom properties to `this` that start with `$`
  4529. accessCache[key] = 4 /* AccessTypes.CONTEXT */;
  4530. return ctx[key];
  4531. }
  4532. else if (
  4533. // global properties
  4534. ((globalProperties = appContext.config.globalProperties),
  4535. hasOwn(globalProperties, key))) {
  4536. {
  4537. return globalProperties[key];
  4538. }
  4539. }
  4540. else if ((process.env.NODE_ENV !== 'production') &&
  4541. currentRenderingInstance &&
  4542. (!isString(key) ||
  4543. // #1091 avoid internal isRef/isVNode checks on component instance leading
  4544. // to infinite warning loop
  4545. key.indexOf('__v') !== 0)) {
  4546. if (data !== EMPTY_OBJ && isReservedPrefix(key[0]) && hasOwn(data, key)) {
  4547. warn(`Property ${JSON.stringify(key)} must be accessed via $data because it starts with a reserved ` +
  4548. `character ("$" or "_") and is not proxied on the render context.`);
  4549. }
  4550. else if (instance === currentRenderingInstance) {
  4551. warn(`Property ${JSON.stringify(key)} was accessed during render ` +
  4552. `but is not defined on instance.`);
  4553. }
  4554. }
  4555. },
  4556. set({ _: instance }, key, value) {
  4557. const { data, setupState, ctx } = instance;
  4558. if (hasSetupBinding(setupState, key)) {
  4559. setupState[key] = value;
  4560. return true;
  4561. }
  4562. else if ((process.env.NODE_ENV !== 'production') &&
  4563. setupState.__isScriptSetup &&
  4564. hasOwn(setupState, key)) {
  4565. warn(`Cannot mutate <script setup> binding "${key}" from Options API.`);
  4566. return false;
  4567. }
  4568. else if (data !== EMPTY_OBJ && hasOwn(data, key)) {
  4569. data[key] = value;
  4570. return true;
  4571. }
  4572. else if (hasOwn(instance.props, key)) {
  4573. (process.env.NODE_ENV !== 'production') && warn(`Attempting to mutate prop "${key}". Props are readonly.`);
  4574. return false;
  4575. }
  4576. if (key[0] === '$' && key.slice(1) in instance) {
  4577. (process.env.NODE_ENV !== 'production') &&
  4578. warn(`Attempting to mutate public property "${key}". ` +
  4579. `Properties starting with $ are reserved and readonly.`);
  4580. return false;
  4581. }
  4582. else {
  4583. if ((process.env.NODE_ENV !== 'production') && key in instance.appContext.config.globalProperties) {
  4584. Object.defineProperty(ctx, key, {
  4585. enumerable: true,
  4586. configurable: true,
  4587. value
  4588. });
  4589. }
  4590. else {
  4591. ctx[key] = value;
  4592. }
  4593. }
  4594. return true;
  4595. },
  4596. has({ _: { data, setupState, accessCache, ctx, appContext, propsOptions } }, key) {
  4597. let normalizedProps;
  4598. return (!!accessCache[key] ||
  4599. (data !== EMPTY_OBJ && hasOwn(data, key)) ||
  4600. hasSetupBinding(setupState, key) ||
  4601. ((normalizedProps = propsOptions[0]) && hasOwn(normalizedProps, key)) ||
  4602. hasOwn(ctx, key) ||
  4603. hasOwn(publicPropertiesMap, key) ||
  4604. hasOwn(appContext.config.globalProperties, key));
  4605. },
  4606. defineProperty(target, key, descriptor) {
  4607. if (descriptor.get != null) {
  4608. // invalidate key cache of a getter based property #5417
  4609. target._.accessCache[key] = 0;
  4610. }
  4611. else if (hasOwn(descriptor, 'value')) {
  4612. this.set(target, key, descriptor.value, null);
  4613. }
  4614. return Reflect.defineProperty(target, key, descriptor);
  4615. }
  4616. };
  4617. if ((process.env.NODE_ENV !== 'production') && !false) {
  4618. PublicInstanceProxyHandlers.ownKeys = (target) => {
  4619. warn(`Avoid app logic that relies on enumerating keys on a component instance. ` +
  4620. `The keys will be empty in production mode to avoid performance overhead.`);
  4621. return Reflect.ownKeys(target);
  4622. };
  4623. }
  4624. const RuntimeCompiledPublicInstanceProxyHandlers = /*#__PURE__*/ extend({}, PublicInstanceProxyHandlers, {
  4625. get(target, key) {
  4626. // fast path for unscopables when using `with` block
  4627. if (key === Symbol.unscopables) {
  4628. return;
  4629. }
  4630. return PublicInstanceProxyHandlers.get(target, key, target);
  4631. },
  4632. has(_, key) {
  4633. const has = key[0] !== '_' && !isGloballyWhitelisted(key);
  4634. if ((process.env.NODE_ENV !== 'production') && !has && PublicInstanceProxyHandlers.has(_, key)) {
  4635. warn(`Property ${JSON.stringify(key)} should not start with _ which is a reserved prefix for Vue internals.`);
  4636. }
  4637. return has;
  4638. }
  4639. });
  4640. // dev only
  4641. // In dev mode, the proxy target exposes the same properties as seen on `this`
  4642. // for easier console inspection. In prod mode it will be an empty object so
  4643. // these properties definitions can be skipped.
  4644. function createDevRenderContext(instance) {
  4645. const target = {};
  4646. // expose internal instance for proxy handlers
  4647. Object.defineProperty(target, `_`, {
  4648. configurable: true,
  4649. enumerable: false,
  4650. get: () => instance
  4651. });
  4652. // expose public properties
  4653. Object.keys(publicPropertiesMap).forEach(key => {
  4654. Object.defineProperty(target, key, {
  4655. configurable: true,
  4656. enumerable: false,
  4657. get: () => publicPropertiesMap[key](instance),
  4658. // intercepted by the proxy so no need for implementation,
  4659. // but needed to prevent set errors
  4660. set: NOOP
  4661. });
  4662. });
  4663. return target;
  4664. }
  4665. // dev only
  4666. function exposePropsOnRenderContext(instance) {
  4667. const { ctx, propsOptions: [propsOptions] } = instance;
  4668. if (propsOptions) {
  4669. Object.keys(propsOptions).forEach(key => {
  4670. Object.defineProperty(ctx, key, {
  4671. enumerable: true,
  4672. configurable: true,
  4673. get: () => instance.props[key],
  4674. set: NOOP
  4675. });
  4676. });
  4677. }
  4678. }
  4679. // dev only
  4680. function exposeSetupStateOnRenderContext(instance) {
  4681. const { ctx, setupState } = instance;
  4682. Object.keys(toRaw(setupState)).forEach(key => {
  4683. if (!setupState.__isScriptSetup) {
  4684. if (isReservedPrefix(key[0])) {
  4685. warn(`setup() return property ${JSON.stringify(key)} should not start with "$" or "_" ` +
  4686. `which are reserved prefixes for Vue internals.`);
  4687. return;
  4688. }
  4689. Object.defineProperty(ctx, key, {
  4690. enumerable: true,
  4691. configurable: true,
  4692. get: () => setupState[key],
  4693. set: NOOP
  4694. });
  4695. }
  4696. });
  4697. }
  4698. function createDuplicateChecker() {
  4699. const cache = Object.create(null);
  4700. return (type, key) => {
  4701. if (cache[key]) {
  4702. warn(`${type} property "${key}" is already defined in ${cache[key]}.`);
  4703. }
  4704. else {
  4705. cache[key] = type;
  4706. }
  4707. };
  4708. }
  4709. let shouldCacheAccess = true;
  4710. function applyOptions(instance) {
  4711. const options = resolveMergedOptions(instance);
  4712. const publicThis = instance.proxy;
  4713. const ctx = instance.ctx;
  4714. // do not cache property access on public proxy during state initialization
  4715. shouldCacheAccess = false;
  4716. // call beforeCreate first before accessing other options since
  4717. // the hook may mutate resolved options (#2791)
  4718. if (options.beforeCreate) {
  4719. callHook$1(options.beforeCreate, instance, "bc" /* LifecycleHooks.BEFORE_CREATE */);
  4720. }
  4721. const {
  4722. // state
  4723. data: dataOptions, computed: computedOptions, methods, watch: watchOptions, provide: provideOptions, inject: injectOptions,
  4724. // lifecycle
  4725. created, beforeMount, mounted, beforeUpdate, updated, activated, deactivated, beforeDestroy, beforeUnmount, destroyed, unmounted, render, renderTracked, renderTriggered, errorCaptured, serverPrefetch,
  4726. // public API
  4727. expose, inheritAttrs,
  4728. // assets
  4729. components, directives, filters } = options;
  4730. const checkDuplicateProperties = (process.env.NODE_ENV !== 'production') ? createDuplicateChecker() : null;
  4731. if ((process.env.NODE_ENV !== 'production')) {
  4732. const [propsOptions] = instance.propsOptions;
  4733. if (propsOptions) {
  4734. for (const key in propsOptions) {
  4735. checkDuplicateProperties("Props" /* OptionTypes.PROPS */, key);
  4736. }
  4737. }
  4738. }
  4739. // options initialization order (to be consistent with Vue 2):
  4740. // - props (already done outside of this function)
  4741. // - inject
  4742. // - methods
  4743. // - data (deferred since it relies on `this` access)
  4744. // - computed
  4745. // - watch (deferred since it relies on `this` access)
  4746. if (injectOptions) {
  4747. resolveInjections(injectOptions, ctx, checkDuplicateProperties, instance.appContext.config.unwrapInjectedRef);
  4748. }
  4749. if (methods) {
  4750. for (const key in methods) {
  4751. const methodHandler = methods[key];
  4752. if (isFunction(methodHandler)) {
  4753. // In dev mode, we use the `createRenderContext` function to define
  4754. // methods to the proxy target, and those are read-only but
  4755. // reconfigurable, so it needs to be redefined here
  4756. if ((process.env.NODE_ENV !== 'production')) {
  4757. Object.defineProperty(ctx, key, {
  4758. value: methodHandler.bind(publicThis),
  4759. configurable: true,
  4760. enumerable: true,
  4761. writable: true
  4762. });
  4763. }
  4764. else {
  4765. ctx[key] = methodHandler.bind(publicThis);
  4766. }
  4767. if ((process.env.NODE_ENV !== 'production')) {
  4768. checkDuplicateProperties("Methods" /* OptionTypes.METHODS */, key);
  4769. }
  4770. }
  4771. else if ((process.env.NODE_ENV !== 'production')) {
  4772. warn(`Method "${key}" has type "${typeof methodHandler}" in the component definition. ` +
  4773. `Did you reference the function correctly?`);
  4774. }
  4775. }
  4776. }
  4777. if (dataOptions) {
  4778. if ((process.env.NODE_ENV !== 'production') && !isFunction(dataOptions)) {
  4779. warn(`The data option must be a function. ` +
  4780. `Plain object usage is no longer supported.`);
  4781. }
  4782. const data = dataOptions.call(publicThis, publicThis);
  4783. if ((process.env.NODE_ENV !== 'production') && isPromise(data)) {
  4784. warn(`data() returned a Promise - note data() cannot be async; If you ` +
  4785. `intend to perform data fetching before component renders, use ` +
  4786. `async setup() + <Suspense>.`);
  4787. }
  4788. if (!isObject(data)) {
  4789. (process.env.NODE_ENV !== 'production') && warn(`data() should return an object.`);
  4790. }
  4791. else {
  4792. instance.data = reactive(data);
  4793. if ((process.env.NODE_ENV !== 'production')) {
  4794. for (const key in data) {
  4795. checkDuplicateProperties("Data" /* OptionTypes.DATA */, key);
  4796. // expose data on ctx during dev
  4797. if (!isReservedPrefix(key[0])) {
  4798. Object.defineProperty(ctx, key, {
  4799. configurable: true,
  4800. enumerable: true,
  4801. get: () => data[key],
  4802. set: NOOP
  4803. });
  4804. }
  4805. }
  4806. }
  4807. }
  4808. }
  4809. // state initialization complete at this point - start caching access
  4810. shouldCacheAccess = true;
  4811. if (computedOptions) {
  4812. for (const key in computedOptions) {
  4813. const opt = computedOptions[key];
  4814. const get = isFunction(opt)
  4815. ? opt.bind(publicThis, publicThis)
  4816. : isFunction(opt.get)
  4817. ? opt.get.bind(publicThis, publicThis)
  4818. : NOOP;
  4819. if ((process.env.NODE_ENV !== 'production') && get === NOOP) {
  4820. warn(`Computed property "${key}" has no getter.`);
  4821. }
  4822. const set = !isFunction(opt) && isFunction(opt.set)
  4823. ? opt.set.bind(publicThis)
  4824. : (process.env.NODE_ENV !== 'production')
  4825. ? () => {
  4826. warn(`Write operation failed: computed property "${key}" is readonly.`);
  4827. }
  4828. : NOOP;
  4829. const c = computed({
  4830. get,
  4831. set
  4832. });
  4833. Object.defineProperty(ctx, key, {
  4834. enumerable: true,
  4835. configurable: true,
  4836. get: () => c.value,
  4837. set: v => (c.value = v)
  4838. });
  4839. if ((process.env.NODE_ENV !== 'production')) {
  4840. checkDuplicateProperties("Computed" /* OptionTypes.COMPUTED */, key);
  4841. }
  4842. }
  4843. }
  4844. if (watchOptions) {
  4845. for (const key in watchOptions) {
  4846. createWatcher(watchOptions[key], ctx, publicThis, key);
  4847. }
  4848. }
  4849. if (provideOptions) {
  4850. const provides = isFunction(provideOptions)
  4851. ? provideOptions.call(publicThis)
  4852. : provideOptions;
  4853. Reflect.ownKeys(provides).forEach(key => {
  4854. provide(key, provides[key]);
  4855. });
  4856. }
  4857. if (created) {
  4858. callHook$1(created, instance, "c" /* LifecycleHooks.CREATED */);
  4859. }
  4860. function registerLifecycleHook(register, hook) {
  4861. if (isArray(hook)) {
  4862. hook.forEach(_hook => register(_hook.bind(publicThis)));
  4863. }
  4864. else if (hook) {
  4865. register(hook.bind(publicThis));
  4866. }
  4867. }
  4868. registerLifecycleHook(onBeforeMount, beforeMount);
  4869. registerLifecycleHook(onMounted, mounted);
  4870. registerLifecycleHook(onBeforeUpdate, beforeUpdate);
  4871. registerLifecycleHook(onUpdated, updated);
  4872. registerLifecycleHook(onActivated, activated);
  4873. registerLifecycleHook(onDeactivated, deactivated);
  4874. registerLifecycleHook(onErrorCaptured, errorCaptured);
  4875. registerLifecycleHook(onRenderTracked, renderTracked);
  4876. registerLifecycleHook(onRenderTriggered, renderTriggered);
  4877. registerLifecycleHook(onBeforeUnmount, beforeUnmount);
  4878. registerLifecycleHook(onUnmounted, unmounted);
  4879. registerLifecycleHook(onServerPrefetch, serverPrefetch);
  4880. if (isArray(expose)) {
  4881. if (expose.length) {
  4882. const exposed = instance.exposed || (instance.exposed = {});
  4883. expose.forEach(key => {
  4884. Object.defineProperty(exposed, key, {
  4885. get: () => publicThis[key],
  4886. set: val => (publicThis[key] = val)
  4887. });
  4888. });
  4889. }
  4890. else if (!instance.exposed) {
  4891. instance.exposed = {};
  4892. }
  4893. }
  4894. // options that are handled when creating the instance but also need to be
  4895. // applied from mixins
  4896. if (render && instance.render === NOOP) {
  4897. instance.render = render;
  4898. }
  4899. if (inheritAttrs != null) {
  4900. instance.inheritAttrs = inheritAttrs;
  4901. }
  4902. // asset options.
  4903. if (components)
  4904. instance.components = components;
  4905. if (directives)
  4906. instance.directives = directives;
  4907. // fixed by xxxxxx
  4908. const customApplyOptions = instance.appContext.config.globalProperties
  4909. .$applyOptions;
  4910. if (customApplyOptions) {
  4911. customApplyOptions(options, instance, publicThis);
  4912. }
  4913. }
  4914. function resolveInjections(injectOptions, ctx, checkDuplicateProperties = NOOP, unwrapRef = false) {
  4915. if (isArray(injectOptions)) {
  4916. injectOptions = normalizeInject(injectOptions);
  4917. }
  4918. for (const key in injectOptions) {
  4919. const opt = injectOptions[key];
  4920. let injected;
  4921. if (isObject(opt)) {
  4922. if ('default' in opt) {
  4923. injected = inject(opt.from || key, opt.default, true /* treat default function as factory */);
  4924. }
  4925. else {
  4926. injected = inject(opt.from || key);
  4927. }
  4928. }
  4929. else {
  4930. injected = inject(opt);
  4931. }
  4932. if (isRef(injected)) {
  4933. // TODO remove the check in 3.3
  4934. if (unwrapRef) {
  4935. Object.defineProperty(ctx, key, {
  4936. enumerable: true,
  4937. configurable: true,
  4938. get: () => injected.value,
  4939. set: v => (injected.value = v)
  4940. });
  4941. }
  4942. else {
  4943. if ((process.env.NODE_ENV !== 'production')) {
  4944. warn(`injected property "${key}" is a ref and will be auto-unwrapped ` +
  4945. `and no longer needs \`.value\` in the next minor release. ` +
  4946. `To opt-in to the new behavior now, ` +
  4947. `set \`app.config.unwrapInjectedRef = true\` (this config is ` +
  4948. `temporary and will not be needed in the future.)`);
  4949. }
  4950. ctx[key] = injected;
  4951. }
  4952. }
  4953. else {
  4954. ctx[key] = injected;
  4955. }
  4956. if ((process.env.NODE_ENV !== 'production')) {
  4957. checkDuplicateProperties("Inject" /* OptionTypes.INJECT */, key);
  4958. }
  4959. }
  4960. }
  4961. function callHook$1(hook, instance, type) {
  4962. callWithAsyncErrorHandling(isArray(hook)
  4963. ? hook.map(h => h.bind(instance.proxy))
  4964. : hook.bind(instance.proxy), instance, type);
  4965. }
  4966. function createWatcher(raw, ctx, publicThis, key) {
  4967. const getter = key.includes('.')
  4968. ? createPathGetter(publicThis, key)
  4969. : () => publicThis[key];
  4970. if (isString(raw)) {
  4971. const handler = ctx[raw];
  4972. if (isFunction(handler)) {
  4973. watch(getter, handler);
  4974. }
  4975. else if ((process.env.NODE_ENV !== 'production')) {
  4976. warn(`Invalid watch handler specified by key "${raw}"`, handler);
  4977. }
  4978. }
  4979. else if (isFunction(raw)) {
  4980. watch(getter, raw.bind(publicThis));
  4981. }
  4982. else if (isObject(raw)) {
  4983. if (isArray(raw)) {
  4984. raw.forEach(r => createWatcher(r, ctx, publicThis, key));
  4985. }
  4986. else {
  4987. const handler = isFunction(raw.handler)
  4988. ? raw.handler.bind(publicThis)
  4989. : ctx[raw.handler];
  4990. if (isFunction(handler)) {
  4991. watch(getter, handler, raw);
  4992. }
  4993. else if ((process.env.NODE_ENV !== 'production')) {
  4994. warn(`Invalid watch handler specified by key "${raw.handler}"`, handler);
  4995. }
  4996. }
  4997. }
  4998. else if ((process.env.NODE_ENV !== 'production')) {
  4999. warn(`Invalid watch option: "${key}"`, raw);
  5000. }
  5001. }
  5002. /**
  5003. * Resolve merged options and cache it on the component.
  5004. * This is done only once per-component since the merging does not involve
  5005. * instances.
  5006. */
  5007. function resolveMergedOptions(instance) {
  5008. const base = instance.type;
  5009. const { mixins, extends: extendsOptions } = base;
  5010. const { mixins: globalMixins, optionsCache: cache, config: { optionMergeStrategies } } = instance.appContext;
  5011. const cached = cache.get(base);
  5012. let resolved;
  5013. if (cached) {
  5014. resolved = cached;
  5015. }
  5016. else if (!globalMixins.length && !mixins && !extendsOptions) {
  5017. {
  5018. resolved = base;
  5019. }
  5020. }
  5021. else {
  5022. resolved = {};
  5023. if (globalMixins.length) {
  5024. globalMixins.forEach(m => mergeOptions(resolved, m, optionMergeStrategies, true));
  5025. }
  5026. mergeOptions(resolved, base, optionMergeStrategies);
  5027. }
  5028. if (isObject(base)) {
  5029. cache.set(base, resolved);
  5030. }
  5031. return resolved;
  5032. }
  5033. function mergeOptions(to, from, strats, asMixin = false) {
  5034. const { mixins, extends: extendsOptions } = from;
  5035. if (extendsOptions) {
  5036. mergeOptions(to, extendsOptions, strats, true);
  5037. }
  5038. if (mixins) {
  5039. mixins.forEach((m) => mergeOptions(to, m, strats, true));
  5040. }
  5041. for (const key in from) {
  5042. if (asMixin && key === 'expose') {
  5043. (process.env.NODE_ENV !== 'production') &&
  5044. warn(`"expose" option is ignored when declared in mixins or extends. ` +
  5045. `It should only be declared in the base component itself.`);
  5046. }
  5047. else {
  5048. const strat = internalOptionMergeStrats[key] || (strats && strats[key]);
  5049. to[key] = strat ? strat(to[key], from[key]) : from[key];
  5050. }
  5051. }
  5052. return to;
  5053. }
  5054. const internalOptionMergeStrats = {
  5055. data: mergeDataFn,
  5056. props: mergeObjectOptions,
  5057. emits: mergeObjectOptions,
  5058. // objects
  5059. methods: mergeObjectOptions,
  5060. computed: mergeObjectOptions,
  5061. // lifecycle
  5062. beforeCreate: mergeAsArray,
  5063. created: mergeAsArray,
  5064. beforeMount: mergeAsArray,
  5065. mounted: mergeAsArray,
  5066. beforeUpdate: mergeAsArray,
  5067. updated: mergeAsArray,
  5068. beforeDestroy: mergeAsArray,
  5069. beforeUnmount: mergeAsArray,
  5070. destroyed: mergeAsArray,
  5071. unmounted: mergeAsArray,
  5072. activated: mergeAsArray,
  5073. deactivated: mergeAsArray,
  5074. errorCaptured: mergeAsArray,
  5075. serverPrefetch: mergeAsArray,
  5076. // assets
  5077. components: mergeObjectOptions,
  5078. directives: mergeObjectOptions,
  5079. // watch
  5080. watch: mergeWatchOptions,
  5081. // provide / inject
  5082. provide: mergeDataFn,
  5083. inject: mergeInject
  5084. };
  5085. function mergeDataFn(to, from) {
  5086. if (!from) {
  5087. return to;
  5088. }
  5089. if (!to) {
  5090. return from;
  5091. }
  5092. return function mergedDataFn() {
  5093. return (extend)(isFunction(to) ? to.call(this, this) : to, isFunction(from) ? from.call(this, this) : from);
  5094. };
  5095. }
  5096. function mergeInject(to, from) {
  5097. return mergeObjectOptions(normalizeInject(to), normalizeInject(from));
  5098. }
  5099. function normalizeInject(raw) {
  5100. if (isArray(raw)) {
  5101. const res = {};
  5102. for (let i = 0; i < raw.length; i++) {
  5103. res[raw[i]] = raw[i];
  5104. }
  5105. return res;
  5106. }
  5107. return raw;
  5108. }
  5109. function mergeAsArray(to, from) {
  5110. return to ? [...new Set([].concat(to, from))] : from;
  5111. }
  5112. function mergeObjectOptions(to, from) {
  5113. return to ? extend(extend(Object.create(null), to), from) : from;
  5114. }
  5115. function mergeWatchOptions(to, from) {
  5116. if (!to)
  5117. return from;
  5118. if (!from)
  5119. return to;
  5120. const merged = extend(Object.create(null), to);
  5121. for (const key in from) {
  5122. merged[key] = mergeAsArray(to[key], from[key]);
  5123. }
  5124. return merged;
  5125. }
  5126. function initProps(instance, rawProps, isStateful, // result of bitwise flag comparison
  5127. isSSR = false) {
  5128. const props = {};
  5129. const attrs = {};
  5130. def(attrs, InternalObjectKey, 1);
  5131. instance.propsDefaults = Object.create(null);
  5132. setFullProps(instance, rawProps, props, attrs);
  5133. // ensure all declared prop keys are present
  5134. for (const key in instance.propsOptions[0]) {
  5135. if (!(key in props)) {
  5136. props[key] = undefined;
  5137. }
  5138. }
  5139. // validation
  5140. if ((process.env.NODE_ENV !== 'production')) {
  5141. validateProps(rawProps || {}, props, instance);
  5142. }
  5143. if (isStateful) {
  5144. // stateful
  5145. instance.props = isSSR ? props : shallowReactive(props);
  5146. }
  5147. else {
  5148. if (!instance.type.props) {
  5149. // functional w/ optional props, props === attrs
  5150. instance.props = attrs;
  5151. }
  5152. else {
  5153. // functional w/ declared props
  5154. instance.props = props;
  5155. }
  5156. }
  5157. instance.attrs = attrs;
  5158. }
  5159. function isInHmrContext(instance) {
  5160. while (instance) {
  5161. if (instance.type.__hmrId)
  5162. return true;
  5163. instance = instance.parent;
  5164. }
  5165. }
  5166. function updateProps(instance, rawProps, rawPrevProps, optimized) {
  5167. const { props, attrs, vnode: { patchFlag } } = instance;
  5168. const rawCurrentProps = toRaw(props);
  5169. const [options] = instance.propsOptions;
  5170. let hasAttrsChanged = false;
  5171. if (
  5172. // always force full diff in dev
  5173. // - #1942 if hmr is enabled with sfc component
  5174. // - vite#872 non-sfc component used by sfc component
  5175. !((process.env.NODE_ENV !== 'production') && isInHmrContext(instance)) &&
  5176. (optimized || patchFlag > 0) &&
  5177. !(patchFlag & 16 /* PatchFlags.FULL_PROPS */)) {
  5178. if (patchFlag & 8 /* PatchFlags.PROPS */) {
  5179. // Compiler-generated props & no keys change, just set the updated
  5180. // the props.
  5181. const propsToUpdate = instance.vnode.dynamicProps;
  5182. for (let i = 0; i < propsToUpdate.length; i++) {
  5183. let key = propsToUpdate[i];
  5184. // skip if the prop key is a declared emit event listener
  5185. if (isEmitListener(instance.emitsOptions, key)) {
  5186. continue;
  5187. }
  5188. // PROPS flag guarantees rawProps to be non-null
  5189. const value = rawProps[key];
  5190. if (options) {
  5191. // attr / props separation was done on init and will be consistent
  5192. // in this code path, so just check if attrs have it.
  5193. if (hasOwn(attrs, key)) {
  5194. if (value !== attrs[key]) {
  5195. attrs[key] = value;
  5196. hasAttrsChanged = true;
  5197. }
  5198. }
  5199. else {
  5200. const camelizedKey = camelize(key);
  5201. props[camelizedKey] = resolvePropValue(options, rawCurrentProps, camelizedKey, value, instance, false /* isAbsent */);
  5202. }
  5203. }
  5204. else {
  5205. if (value !== attrs[key]) {
  5206. attrs[key] = value;
  5207. hasAttrsChanged = true;
  5208. }
  5209. }
  5210. }
  5211. }
  5212. }
  5213. else {
  5214. // full props update.
  5215. if (setFullProps(instance, rawProps, props, attrs)) {
  5216. hasAttrsChanged = true;
  5217. }
  5218. // in case of dynamic props, check if we need to delete keys from
  5219. // the props object
  5220. let kebabKey;
  5221. for (const key in rawCurrentProps) {
  5222. if (!rawProps ||
  5223. // for camelCase
  5224. (!hasOwn(rawProps, key) &&
  5225. // it's possible the original props was passed in as kebab-case
  5226. // and converted to camelCase (#955)
  5227. ((kebabKey = hyphenate(key)) === key || !hasOwn(rawProps, kebabKey)))) {
  5228. if (options) {
  5229. if (rawPrevProps &&
  5230. // for camelCase
  5231. (rawPrevProps[key] !== undefined ||
  5232. // for kebab-case
  5233. rawPrevProps[kebabKey] !== undefined)) {
  5234. props[key] = resolvePropValue(options, rawCurrentProps, key, undefined, instance, true /* isAbsent */);
  5235. }
  5236. }
  5237. else {
  5238. delete props[key];
  5239. }
  5240. }
  5241. }
  5242. // in the case of functional component w/o props declaration, props and
  5243. // attrs point to the same object so it should already have been updated.
  5244. if (attrs !== rawCurrentProps) {
  5245. for (const key in attrs) {
  5246. if (!rawProps ||
  5247. (!hasOwn(rawProps, key) &&
  5248. (!false ))) {
  5249. delete attrs[key];
  5250. hasAttrsChanged = true;
  5251. }
  5252. }
  5253. }
  5254. }
  5255. // trigger updates for $attrs in case it's used in component slots
  5256. if (hasAttrsChanged) {
  5257. trigger(instance, "set" /* TriggerOpTypes.SET */, '$attrs');
  5258. }
  5259. if ((process.env.NODE_ENV !== 'production')) {
  5260. validateProps(rawProps || {}, props, instance);
  5261. }
  5262. }
  5263. function setFullProps(instance, rawProps, props, attrs) {
  5264. const [options, needCastKeys] = instance.propsOptions;
  5265. let hasAttrsChanged = false;
  5266. let rawCastValues;
  5267. if (rawProps) {
  5268. for (let key in rawProps) {
  5269. // key, ref are reserved and never passed down
  5270. if (isReservedProp(key)) {
  5271. continue;
  5272. }
  5273. const value = rawProps[key];
  5274. // prop option names are camelized during normalization, so to support
  5275. // kebab -> camel conversion here we need to camelize the key.
  5276. let camelKey;
  5277. if (options && hasOwn(options, (camelKey = camelize(key)))) {
  5278. if (!needCastKeys || !needCastKeys.includes(camelKey)) {
  5279. props[camelKey] = value;
  5280. }
  5281. else {
  5282. (rawCastValues || (rawCastValues = {}))[camelKey] = value;
  5283. }
  5284. }
  5285. else if (!isEmitListener(instance.emitsOptions, key)) {
  5286. if (!(key in attrs) || value !== attrs[key]) {
  5287. attrs[key] = value;
  5288. hasAttrsChanged = true;
  5289. }
  5290. }
  5291. }
  5292. }
  5293. if (needCastKeys) {
  5294. const rawCurrentProps = toRaw(props);
  5295. const castValues = rawCastValues || EMPTY_OBJ;
  5296. for (let i = 0; i < needCastKeys.length; i++) {
  5297. const key = needCastKeys[i];
  5298. props[key] = resolvePropValue(options, rawCurrentProps, key, castValues[key], instance, !hasOwn(castValues, key));
  5299. }
  5300. }
  5301. return hasAttrsChanged;
  5302. }
  5303. function resolvePropValue(options, props, key, value, instance, isAbsent) {
  5304. const opt = options[key];
  5305. if (opt != null) {
  5306. const hasDefault = hasOwn(opt, 'default');
  5307. // default values
  5308. if (hasDefault && value === undefined) {
  5309. const defaultValue = opt.default;
  5310. if (opt.type !== Function && isFunction(defaultValue)) {
  5311. const { propsDefaults } = instance;
  5312. if (key in propsDefaults) {
  5313. value = propsDefaults[key];
  5314. }
  5315. else {
  5316. setCurrentInstance(instance);
  5317. value = propsDefaults[key] = defaultValue.call(null, props);
  5318. unsetCurrentInstance();
  5319. }
  5320. }
  5321. else {
  5322. value = defaultValue;
  5323. }
  5324. }
  5325. // boolean casting
  5326. if (opt[0 /* BooleanFlags.shouldCast */]) {
  5327. if (isAbsent && !hasDefault) {
  5328. value = false;
  5329. }
  5330. else if (opt[1 /* BooleanFlags.shouldCastTrue */] &&
  5331. (value === '' || value === hyphenate(key))) {
  5332. value = true;
  5333. }
  5334. }
  5335. }
  5336. return value;
  5337. }
  5338. function normalizePropsOptions(comp, appContext, asMixin = false) {
  5339. const cache = appContext.propsCache;
  5340. const cached = cache.get(comp);
  5341. if (cached) {
  5342. return cached;
  5343. }
  5344. const raw = comp.props;
  5345. const normalized = {};
  5346. const needCastKeys = [];
  5347. // apply mixin/extends props
  5348. let hasExtends = false;
  5349. if (__VUE_OPTIONS_API__ && !isFunction(comp)) {
  5350. const extendProps = (raw) => {
  5351. hasExtends = true;
  5352. const [props, keys] = normalizePropsOptions(raw, appContext, true);
  5353. extend(normalized, props);
  5354. if (keys)
  5355. needCastKeys.push(...keys);
  5356. };
  5357. if (!asMixin && appContext.mixins.length) {
  5358. appContext.mixins.forEach(extendProps);
  5359. }
  5360. if (comp.extends) {
  5361. extendProps(comp.extends);
  5362. }
  5363. if (comp.mixins) {
  5364. comp.mixins.forEach(extendProps);
  5365. }
  5366. }
  5367. if (!raw && !hasExtends) {
  5368. if (isObject(comp)) {
  5369. cache.set(comp, EMPTY_ARR);
  5370. }
  5371. return EMPTY_ARR;
  5372. }
  5373. if (isArray(raw)) {
  5374. for (let i = 0; i < raw.length; i++) {
  5375. if ((process.env.NODE_ENV !== 'production') && !isString(raw[i])) {
  5376. warn(`props must be strings when using array syntax.`, raw[i]);
  5377. }
  5378. const normalizedKey = camelize(raw[i]);
  5379. if (validatePropName(normalizedKey)) {
  5380. normalized[normalizedKey] = EMPTY_OBJ;
  5381. }
  5382. }
  5383. }
  5384. else if (raw) {
  5385. if ((process.env.NODE_ENV !== 'production') && !isObject(raw)) {
  5386. warn(`invalid props options`, raw);
  5387. }
  5388. for (const key in raw) {
  5389. const normalizedKey = camelize(key);
  5390. if (validatePropName(normalizedKey)) {
  5391. const opt = raw[key];
  5392. const prop = (normalized[normalizedKey] =
  5393. isArray(opt) || isFunction(opt) ? { type: opt } : Object.assign({}, opt));
  5394. if (prop) {
  5395. const booleanIndex = getTypeIndex(Boolean, prop.type);
  5396. const stringIndex = getTypeIndex(String, prop.type);
  5397. prop[0 /* BooleanFlags.shouldCast */] = booleanIndex > -1;
  5398. prop[1 /* BooleanFlags.shouldCastTrue */] =
  5399. stringIndex < 0 || booleanIndex < stringIndex;
  5400. // if the prop needs boolean casting or default value
  5401. if (booleanIndex > -1 || hasOwn(prop, 'default')) {
  5402. needCastKeys.push(normalizedKey);
  5403. }
  5404. }
  5405. }
  5406. }
  5407. }
  5408. const res = [normalized, needCastKeys];
  5409. if (isObject(comp)) {
  5410. cache.set(comp, res);
  5411. }
  5412. return res;
  5413. }
  5414. function validatePropName(key) {
  5415. if (key[0] !== '$') {
  5416. return true;
  5417. }
  5418. else if ((process.env.NODE_ENV !== 'production')) {
  5419. warn(`Invalid prop name: "${key}" is a reserved property.`);
  5420. }
  5421. return false;
  5422. }
  5423. // use function string name to check type constructors
  5424. // so that it works across vms / iframes.
  5425. function getType(ctor) {
  5426. const match = ctor && ctor.toString().match(/^\s*(function|class) (\w+)/);
  5427. return match ? match[2] : ctor === null ? 'null' : '';
  5428. }
  5429. function isSameType(a, b) {
  5430. return getType(a) === getType(b);
  5431. }
  5432. function getTypeIndex(type, expectedTypes) {
  5433. if (isArray(expectedTypes)) {
  5434. return expectedTypes.findIndex(t => isSameType(t, type));
  5435. }
  5436. else if (isFunction(expectedTypes)) {
  5437. return isSameType(expectedTypes, type) ? 0 : -1;
  5438. }
  5439. return -1;
  5440. }
  5441. /**
  5442. * dev only
  5443. */
  5444. function validateProps(rawProps, props, instance) {
  5445. const resolvedValues = toRaw(props);
  5446. const options = instance.propsOptions[0];
  5447. for (const key in options) {
  5448. let opt = options[key];
  5449. if (opt == null)
  5450. continue;
  5451. validateProp(key, resolvedValues[key], opt, !hasOwn(rawProps, key) && !hasOwn(rawProps, hyphenate(key)));
  5452. }
  5453. }
  5454. /**
  5455. * dev only
  5456. */
  5457. function validateProp(name, value, prop, isAbsent) {
  5458. const { type, required, validator } = prop;
  5459. // required!
  5460. if (required && isAbsent) {
  5461. warn('Missing required prop: "' + name + '"');
  5462. return;
  5463. }
  5464. // missing but optional
  5465. if (value == null && !prop.required) {
  5466. return;
  5467. }
  5468. // type check
  5469. if (type != null && type !== true) {
  5470. let isValid = false;
  5471. const types = isArray(type) ? type : [type];
  5472. const expectedTypes = [];
  5473. // value is valid as long as one of the specified types match
  5474. for (let i = 0; i < types.length && !isValid; i++) {
  5475. const { valid, expectedType } = assertType(value, types[i]);
  5476. expectedTypes.push(expectedType || '');
  5477. isValid = valid;
  5478. }
  5479. if (!isValid) {
  5480. warn(getInvalidTypeMessage(name, value, expectedTypes));
  5481. return;
  5482. }
  5483. }
  5484. // custom validator
  5485. if (validator && !validator(value)) {
  5486. warn('Invalid prop: custom validator check failed for prop "' + name + '".');
  5487. }
  5488. }
  5489. const isSimpleType = /*#__PURE__*/ makeMap('String,Number,Boolean,Function,Symbol,BigInt');
  5490. /**
  5491. * dev only
  5492. */
  5493. function assertType(value, type) {
  5494. let valid;
  5495. const expectedType = getType(type);
  5496. if (isSimpleType(expectedType)) {
  5497. const t = typeof value;
  5498. valid = t === expectedType.toLowerCase();
  5499. // for primitive wrapper objects
  5500. if (!valid && t === 'object') {
  5501. valid = value instanceof type;
  5502. }
  5503. }
  5504. else if (expectedType === 'Object') {
  5505. valid = isObject(value);
  5506. }
  5507. else if (expectedType === 'Array') {
  5508. valid = isArray(value);
  5509. }
  5510. else if (expectedType === 'null') {
  5511. valid = value === null;
  5512. }
  5513. else {
  5514. valid = value instanceof type;
  5515. }
  5516. return {
  5517. valid,
  5518. expectedType
  5519. };
  5520. }
  5521. /**
  5522. * dev only
  5523. */
  5524. function getInvalidTypeMessage(name, value, expectedTypes) {
  5525. let message = `Invalid prop: type check failed for prop "${name}".` +
  5526. ` Expected ${expectedTypes.map(capitalize).join(' | ')}`;
  5527. const expectedType = expectedTypes[0];
  5528. const receivedType = toRawType(value);
  5529. const expectedValue = styleValue(value, expectedType);
  5530. const receivedValue = styleValue(value, receivedType);
  5531. // check if we need to specify expected value
  5532. if (expectedTypes.length === 1 &&
  5533. isExplicable(expectedType) &&
  5534. !isBoolean(expectedType, receivedType)) {
  5535. message += ` with value ${expectedValue}`;
  5536. }
  5537. message += `, got ${receivedType} `;
  5538. // check if we need to specify received value
  5539. if (isExplicable(receivedType)) {
  5540. message += `with value ${receivedValue}.`;
  5541. }
  5542. return message;
  5543. }
  5544. /**
  5545. * dev only
  5546. */
  5547. function styleValue(value, type) {
  5548. if (type === 'String') {
  5549. return `"${value}"`;
  5550. }
  5551. else if (type === 'Number') {
  5552. return `${Number(value)}`;
  5553. }
  5554. else {
  5555. return `${value}`;
  5556. }
  5557. }
  5558. /**
  5559. * dev only
  5560. */
  5561. function isExplicable(type) {
  5562. const explicitTypes = ['string', 'number', 'boolean'];
  5563. return explicitTypes.some(elem => type.toLowerCase() === elem);
  5564. }
  5565. /**
  5566. * dev only
  5567. */
  5568. function isBoolean(...args) {
  5569. return args.some(elem => elem.toLowerCase() === 'boolean');
  5570. }
  5571. const isInternalKey = (key) => key[0] === '_' || key === '$stable';
  5572. const normalizeSlotValue = (value) => isArray(value)
  5573. ? value.map(normalizeVNode)
  5574. : [normalizeVNode(value)];
  5575. const normalizeSlot = (key, rawSlot, ctx) => {
  5576. if (rawSlot._n) {
  5577. // already normalized - #5353
  5578. return rawSlot;
  5579. }
  5580. const normalized = withCtx((...args) => {
  5581. if ((process.env.NODE_ENV !== 'production') && currentInstance) {
  5582. warn(`Slot "${key}" invoked outside of the render function: ` +
  5583. `this will not track dependencies used in the slot. ` +
  5584. `Invoke the slot function inside the render function instead.`);
  5585. }
  5586. return normalizeSlotValue(rawSlot(...args));
  5587. }, ctx);
  5588. normalized._c = false;
  5589. return normalized;
  5590. };
  5591. const normalizeObjectSlots = (rawSlots, slots, instance) => {
  5592. const ctx = rawSlots._ctx;
  5593. for (const key in rawSlots) {
  5594. if (isInternalKey(key))
  5595. continue;
  5596. const value = rawSlots[key];
  5597. if (isFunction(value)) {
  5598. slots[key] = normalizeSlot(key, value, ctx);
  5599. }
  5600. else if (value != null) {
  5601. if ((process.env.NODE_ENV !== 'production') &&
  5602. !(false )) {
  5603. warn(`Non-function value encountered for slot "${key}". ` +
  5604. `Prefer function slots for better performance.`);
  5605. }
  5606. const normalized = normalizeSlotValue(value);
  5607. slots[key] = () => normalized;
  5608. }
  5609. }
  5610. };
  5611. const normalizeVNodeSlots = (instance, children) => {
  5612. if ((process.env.NODE_ENV !== 'production') &&
  5613. !isKeepAlive(instance.vnode) &&
  5614. !(false )) {
  5615. warn(`Non-function value encountered for default slot. ` +
  5616. `Prefer function slots for better performance.`);
  5617. }
  5618. const normalized = normalizeSlotValue(children);
  5619. instance.slots.default = () => normalized;
  5620. };
  5621. const initSlots = (instance, children) => {
  5622. if (instance.vnode.shapeFlag & 32 /* ShapeFlags.SLOTS_CHILDREN */) {
  5623. const type = children._;
  5624. if (type) {
  5625. // users can get the shallow readonly version of the slots object through `this.$slots`,
  5626. // we should avoid the proxy object polluting the slots of the internal instance
  5627. instance.slots = toRaw(children);
  5628. // make compiler marker non-enumerable
  5629. def(children, '_', type);
  5630. }
  5631. else {
  5632. normalizeObjectSlots(children, (instance.slots = {}));
  5633. }
  5634. }
  5635. else {
  5636. instance.slots = {};
  5637. if (children) {
  5638. normalizeVNodeSlots(instance, children);
  5639. }
  5640. }
  5641. def(instance.slots, InternalObjectKey, 1);
  5642. };
  5643. const updateSlots = (instance, children, optimized) => {
  5644. const { vnode, slots } = instance;
  5645. let needDeletionCheck = true;
  5646. let deletionComparisonTarget = EMPTY_OBJ;
  5647. if (vnode.shapeFlag & 32 /* ShapeFlags.SLOTS_CHILDREN */) {
  5648. const type = children._;
  5649. if (type) {
  5650. // compiled slots.
  5651. if ((process.env.NODE_ENV !== 'production') && isHmrUpdating) {
  5652. // Parent was HMR updated so slot content may have changed.
  5653. // force update slots and mark instance for hmr as well
  5654. extend(slots, children);
  5655. }
  5656. else if (optimized && type === 1 /* SlotFlags.STABLE */) {
  5657. // compiled AND stable.
  5658. // no need to update, and skip stale slots removal.
  5659. needDeletionCheck = false;
  5660. }
  5661. else {
  5662. // compiled but dynamic (v-if/v-for on slots) - update slots, but skip
  5663. // normalization.
  5664. extend(slots, children);
  5665. // #2893
  5666. // when rendering the optimized slots by manually written render function,
  5667. // we need to delete the `slots._` flag if necessary to make subsequent updates reliable,
  5668. // i.e. let the `renderSlot` create the bailed Fragment
  5669. if (!optimized && type === 1 /* SlotFlags.STABLE */) {
  5670. delete slots._;
  5671. }
  5672. }
  5673. }
  5674. else {
  5675. needDeletionCheck = !children.$stable;
  5676. normalizeObjectSlots(children, slots);
  5677. }
  5678. deletionComparisonTarget = children;
  5679. }
  5680. else if (children) {
  5681. // non slot object children (direct value) passed to a component
  5682. normalizeVNodeSlots(instance, children);
  5683. deletionComparisonTarget = { default: 1 };
  5684. }
  5685. // delete stale slots
  5686. if (needDeletionCheck) {
  5687. for (const key in slots) {
  5688. if (!isInternalKey(key) && !(key in deletionComparisonTarget)) {
  5689. delete slots[key];
  5690. }
  5691. }
  5692. }
  5693. };
  5694. function createAppContext() {
  5695. return {
  5696. app: null,
  5697. config: {
  5698. isNativeTag: NO,
  5699. performance: false,
  5700. globalProperties: {},
  5701. optionMergeStrategies: {},
  5702. errorHandler: undefined,
  5703. warnHandler: undefined,
  5704. compilerOptions: {}
  5705. },
  5706. mixins: [],
  5707. components: {},
  5708. directives: {},
  5709. provides: Object.create(null),
  5710. optionsCache: new WeakMap(),
  5711. propsCache: new WeakMap(),
  5712. emitsCache: new WeakMap()
  5713. };
  5714. }
  5715. let uid$1 = 0;
  5716. function createAppAPI(render, hydrate) {
  5717. return function createApp(rootComponent, rootProps = null) {
  5718. if (!isFunction(rootComponent)) {
  5719. rootComponent = Object.assign({}, rootComponent);
  5720. }
  5721. if (rootProps != null && !isObject(rootProps)) {
  5722. (process.env.NODE_ENV !== 'production') && warn(`root props passed to app.mount() must be an object.`);
  5723. rootProps = null;
  5724. }
  5725. const context = createAppContext();
  5726. const installedPlugins = new Set();
  5727. let isMounted = false;
  5728. const app = (context.app = {
  5729. _uid: uid$1++,
  5730. _component: rootComponent,
  5731. _props: rootProps,
  5732. _container: null,
  5733. _context: context,
  5734. _instance: null,
  5735. version,
  5736. get config() {
  5737. return context.config;
  5738. },
  5739. set config(v) {
  5740. if ((process.env.NODE_ENV !== 'production')) {
  5741. warn(`app.config cannot be replaced. Modify individual options instead.`);
  5742. }
  5743. },
  5744. use(plugin, ...options) {
  5745. if (installedPlugins.has(plugin)) {
  5746. (process.env.NODE_ENV !== 'production') && warn(`Plugin has already been applied to target app.`);
  5747. }
  5748. else if (plugin && isFunction(plugin.install)) {
  5749. installedPlugins.add(plugin);
  5750. plugin.install(app, ...options);
  5751. }
  5752. else if (isFunction(plugin)) {
  5753. installedPlugins.add(plugin);
  5754. plugin(app, ...options);
  5755. }
  5756. else if ((process.env.NODE_ENV !== 'production')) {
  5757. warn(`A plugin must either be a function or an object with an "install" ` +
  5758. `function.`);
  5759. }
  5760. return app;
  5761. },
  5762. mixin(mixin) {
  5763. if (__VUE_OPTIONS_API__) {
  5764. if (!context.mixins.includes(mixin)) {
  5765. context.mixins.push(mixin);
  5766. }
  5767. else if ((process.env.NODE_ENV !== 'production')) {
  5768. warn('Mixin has already been applied to target app' +
  5769. (mixin.name ? `: ${mixin.name}` : ''));
  5770. }
  5771. }
  5772. else if ((process.env.NODE_ENV !== 'production')) {
  5773. warn('Mixins are only available in builds supporting Options API');
  5774. }
  5775. return app;
  5776. },
  5777. component(name, component) {
  5778. if ((process.env.NODE_ENV !== 'production')) {
  5779. validateComponentName(name, context.config);
  5780. }
  5781. if (!component) {
  5782. return context.components[name];
  5783. }
  5784. if ((process.env.NODE_ENV !== 'production') && context.components[name]) {
  5785. warn(`Component "${name}" has already been registered in target app.`);
  5786. }
  5787. context.components[name] = component;
  5788. return app;
  5789. },
  5790. directive(name, directive) {
  5791. if ((process.env.NODE_ENV !== 'production')) {
  5792. validateDirectiveName(name);
  5793. }
  5794. if (!directive) {
  5795. return context.directives[name];
  5796. }
  5797. if ((process.env.NODE_ENV !== 'production') && context.directives[name]) {
  5798. warn(`Directive "${name}" has already been registered in target app.`);
  5799. }
  5800. context.directives[name] = directive;
  5801. return app;
  5802. },
  5803. mount(rootContainer, isHydrate, isSVG) {
  5804. if (!isMounted) {
  5805. // #5571
  5806. if ((process.env.NODE_ENV !== 'production') && rootContainer.__vue_app__) {
  5807. warn(`There is already an app instance mounted on the host container.\n` +
  5808. ` If you want to mount another app on the same host container,` +
  5809. ` you need to unmount the previous app by calling \`app.unmount()\` first.`);
  5810. }
  5811. const vnode = createVNode(rootComponent, rootProps);
  5812. // store app context on the root VNode.
  5813. // this will be set on the root instance on initial mount.
  5814. vnode.appContext = context;
  5815. // HMR root reload
  5816. if ((process.env.NODE_ENV !== 'production')) {
  5817. context.reload = () => {
  5818. render(cloneVNode(vnode), rootContainer, isSVG);
  5819. };
  5820. }
  5821. if (isHydrate && hydrate) {
  5822. hydrate(vnode, rootContainer);
  5823. }
  5824. else {
  5825. render(vnode, rootContainer, isSVG);
  5826. }
  5827. isMounted = true;
  5828. app._container = rootContainer;
  5829. rootContainer.__vue_app__ = app;
  5830. // fixed by xxxxxx (始终暴露,因为 onError 要访问)
  5831. app._instance = vnode.component;
  5832. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  5833. devtoolsInitApp(app, version);
  5834. }
  5835. return getExposeProxy(vnode.component) || vnode.component.proxy;
  5836. }
  5837. else if ((process.env.NODE_ENV !== 'production')) {
  5838. warn(`App has already been mounted.\n` +
  5839. `If you want to remount the same app, move your app creation logic ` +
  5840. `into a factory function and create fresh app instances for each ` +
  5841. `mount - e.g. \`const createMyApp = () => createApp(App)\``);
  5842. }
  5843. },
  5844. unmount() {
  5845. if (isMounted) {
  5846. render(null, app._container);
  5847. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  5848. app._instance = null;
  5849. devtoolsUnmountApp(app);
  5850. }
  5851. delete app._container.__vue_app__;
  5852. }
  5853. else if ((process.env.NODE_ENV !== 'production')) {
  5854. warn(`Cannot unmount an app that is not mounted.`);
  5855. }
  5856. },
  5857. provide(key, value) {
  5858. if ((process.env.NODE_ENV !== 'production') && key in context.provides) {
  5859. warn(`App already provides property with key "${String(key)}". ` +
  5860. `It will be overwritten with the new value.`);
  5861. }
  5862. context.provides[key] = value;
  5863. return app;
  5864. }
  5865. });
  5866. return app;
  5867. };
  5868. }
  5869. /**
  5870. * Function for handling a template ref
  5871. */
  5872. function setRef(rawRef, oldRawRef, parentSuspense, vnode, isUnmount = false) {
  5873. if (isArray(rawRef)) {
  5874. rawRef.forEach((r, i) => setRef(r, oldRawRef && (isArray(oldRawRef) ? oldRawRef[i] : oldRawRef), parentSuspense, vnode, isUnmount));
  5875. return;
  5876. }
  5877. if (isAsyncWrapper(vnode) && !isUnmount) {
  5878. // when mounting async components, nothing needs to be done,
  5879. // because the template ref is forwarded to inner component
  5880. return;
  5881. }
  5882. const refValue = vnode.shapeFlag & 4 /* ShapeFlags.STATEFUL_COMPONENT */ &&
  5883. !(vnode.component.type.rootElement) // fixed by xxxxxx 非 x 项目或者非内置组件
  5884. ? getExposeProxy(vnode.component) || vnode.component.proxy
  5885. : vnode.el;
  5886. const value = isUnmount ? null : refValue;
  5887. const { i: owner, r: ref } = rawRef;
  5888. if ((process.env.NODE_ENV !== 'production') && !owner) {
  5889. warn(`Missing ref owner context. ref cannot be used on hoisted vnodes. ` +
  5890. `A vnode with ref must be created inside the render function.`);
  5891. return;
  5892. }
  5893. const oldRef = oldRawRef && oldRawRef.r;
  5894. const refs = owner.refs === EMPTY_OBJ ? (owner.refs = {}) : owner.refs;
  5895. const setupState = owner.setupState;
  5896. // dynamic ref changed. unset old ref
  5897. if (oldRef != null && oldRef !== ref) {
  5898. if (isString(oldRef)) {
  5899. refs[oldRef] = null;
  5900. if (hasOwn(setupState, oldRef)) {
  5901. setupState[oldRef] = null;
  5902. }
  5903. }
  5904. else if (isRef(oldRef)) {
  5905. oldRef.value = null;
  5906. }
  5907. }
  5908. if (isFunction(ref)) {
  5909. callWithErrorHandling(ref, owner, 12 /* ErrorCodes.FUNCTION_REF */, [value, refs]);
  5910. }
  5911. else {
  5912. const _isString = isString(ref);
  5913. const _isRef = isRef(ref);
  5914. if (_isString || _isRef) {
  5915. const doSet = () => {
  5916. if (rawRef.f) {
  5917. const existing = _isString
  5918. ? hasOwn(setupState, ref)
  5919. ? setupState[ref]
  5920. : refs[ref]
  5921. : ref.value;
  5922. if (isUnmount) {
  5923. isArray(existing) && remove(existing, refValue);
  5924. }
  5925. else {
  5926. if (!isArray(existing)) {
  5927. if (_isString) {
  5928. refs[ref] = [refValue];
  5929. if (hasOwn(setupState, ref)) {
  5930. setupState[ref] = refs[ref];
  5931. }
  5932. }
  5933. else {
  5934. ref.value = [refValue];
  5935. if (rawRef.k)
  5936. refs[rawRef.k] = ref.value;
  5937. }
  5938. }
  5939. else if (!existing.includes(refValue)) {
  5940. existing.push(refValue);
  5941. }
  5942. }
  5943. }
  5944. else if (_isString) {
  5945. refs[ref] = value;
  5946. if (hasOwn(setupState, ref)) {
  5947. setupState[ref] = value;
  5948. }
  5949. }
  5950. else if (_isRef) {
  5951. ref.value = value;
  5952. if (rawRef.k)
  5953. refs[rawRef.k] = value;
  5954. }
  5955. else if ((process.env.NODE_ENV !== 'production')) {
  5956. warn('Invalid template ref type:', ref, `(${typeof ref})`);
  5957. }
  5958. };
  5959. if (value) {
  5960. doSet.id = -1;
  5961. queuePostRenderEffect(doSet, parentSuspense);
  5962. }
  5963. else {
  5964. doSet();
  5965. }
  5966. }
  5967. else if ((process.env.NODE_ENV !== 'production')) {
  5968. warn('Invalid template ref type:', ref, `(${typeof ref})`);
  5969. }
  5970. }
  5971. }
  5972. let hasMismatch = false;
  5973. const isSVGContainer = (container) => /svg/.test(container.namespaceURI) && container.tagName !== 'foreignObject';
  5974. const isComment = (node) => node.nodeType === 8 /* DOMNodeTypes.COMMENT */;
  5975. // Note: hydration is DOM-specific
  5976. // But we have to place it in core due to tight coupling with core - splitting
  5977. // it out creates a ton of unnecessary complexity.
  5978. // Hydration also depends on some renderer internal logic which needs to be
  5979. // passed in via arguments.
  5980. function createHydrationFunctions(rendererInternals) {
  5981. const { mt: mountComponent, p: patch, o: { patchProp, createText, nextSibling, parentNode, remove, insert, createComment } } = rendererInternals;
  5982. const hydrate = (vnode, container) => {
  5983. if (!container.hasChildNodes()) {
  5984. (process.env.NODE_ENV !== 'production') &&
  5985. warn(`Attempting to hydrate existing markup but container is empty. ` +
  5986. `Performing full mount instead.`);
  5987. patch(null, vnode, container);
  5988. flushPostFlushCbs();
  5989. container._vnode = vnode;
  5990. return;
  5991. }
  5992. hasMismatch = false;
  5993. hydrateNode(container.firstChild, vnode, null, null, null);
  5994. flushPostFlushCbs();
  5995. container._vnode = vnode;
  5996. if (hasMismatch && !false) {
  5997. // this error should show up in production
  5998. console.error(`Hydration completed but contains mismatches.`);
  5999. }
  6000. };
  6001. const hydrateNode = (node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized = false) => {
  6002. const isFragmentStart = isComment(node) && node.data === '[';
  6003. const onMismatch = () => handleMismatch(node, vnode, parentComponent, parentSuspense, slotScopeIds, isFragmentStart);
  6004. const { type, ref, shapeFlag, patchFlag } = vnode;
  6005. let domType = node.nodeType;
  6006. vnode.el = node;
  6007. if (patchFlag === -2 /* PatchFlags.BAIL */) {
  6008. optimized = false;
  6009. vnode.dynamicChildren = null;
  6010. }
  6011. let nextNode = null;
  6012. switch (type) {
  6013. case Text:
  6014. if (domType !== 3 /* DOMNodeTypes.TEXT */) {
  6015. // #5728 empty text node inside a slot can cause hydration failure
  6016. // because the server rendered HTML won't contain a text node
  6017. if (vnode.children === '') {
  6018. insert((vnode.el = createText('')), parentNode(node), node);
  6019. nextNode = node;
  6020. }
  6021. else {
  6022. nextNode = onMismatch();
  6023. }
  6024. }
  6025. else {
  6026. if (node.data !== vnode.children) {
  6027. hasMismatch = true;
  6028. (process.env.NODE_ENV !== 'production') &&
  6029. warn(`Hydration text mismatch:` +
  6030. `\n- Client: ${JSON.stringify(node.data)}` +
  6031. `\n- Server: ${JSON.stringify(vnode.children)}`);
  6032. node.data = vnode.children;
  6033. }
  6034. nextNode = nextSibling(node);
  6035. }
  6036. break;
  6037. case Comment:
  6038. if (domType !== 8 /* DOMNodeTypes.COMMENT */ || isFragmentStart) {
  6039. nextNode = onMismatch();
  6040. }
  6041. else {
  6042. nextNode = nextSibling(node);
  6043. }
  6044. break;
  6045. case Static:
  6046. if (isFragmentStart) {
  6047. // entire template is static but SSRed as a fragment
  6048. node = nextSibling(node);
  6049. domType = node.nodeType;
  6050. }
  6051. if (domType === 1 /* DOMNodeTypes.ELEMENT */ || domType === 3 /* DOMNodeTypes.TEXT */) {
  6052. // determine anchor, adopt content
  6053. nextNode = node;
  6054. // if the static vnode has its content stripped during build,
  6055. // adopt it from the server-rendered HTML.
  6056. const needToAdoptContent = !vnode.children.length;
  6057. for (let i = 0; i < vnode.staticCount; i++) {
  6058. if (needToAdoptContent)
  6059. vnode.children +=
  6060. nextNode.nodeType === 1 /* DOMNodeTypes.ELEMENT */
  6061. ? nextNode.outerHTML
  6062. : nextNode.data;
  6063. if (i === vnode.staticCount - 1) {
  6064. vnode.anchor = nextNode;
  6065. }
  6066. nextNode = nextSibling(nextNode);
  6067. }
  6068. return isFragmentStart ? nextSibling(nextNode) : nextNode;
  6069. }
  6070. else {
  6071. onMismatch();
  6072. }
  6073. break;
  6074. case Fragment:
  6075. if (!isFragmentStart) {
  6076. nextNode = onMismatch();
  6077. }
  6078. else {
  6079. nextNode = hydrateFragment(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized);
  6080. }
  6081. break;
  6082. default:
  6083. if (shapeFlag & 1 /* ShapeFlags.ELEMENT */) {
  6084. if (domType !== 1 /* DOMNodeTypes.ELEMENT */ ||
  6085. vnode.type.toLowerCase() !==
  6086. node.tagName.toLowerCase()) {
  6087. nextNode = onMismatch();
  6088. }
  6089. else {
  6090. nextNode = hydrateElement(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized);
  6091. }
  6092. }
  6093. else if (shapeFlag & 6 /* ShapeFlags.COMPONENT */) {
  6094. // when setting up the render effect, if the initial vnode already
  6095. // has .el set, the component will perform hydration instead of mount
  6096. // on its sub-tree.
  6097. vnode.slotScopeIds = slotScopeIds;
  6098. const container = parentNode(node);
  6099. mountComponent(vnode, container, null, parentComponent, parentSuspense, isSVGContainer(container), optimized);
  6100. // component may be async, so in the case of fragments we cannot rely
  6101. // on component's rendered output to determine the end of the fragment
  6102. // instead, we do a lookahead to find the end anchor node.
  6103. nextNode = isFragmentStart
  6104. ? locateClosingAsyncAnchor(node)
  6105. : nextSibling(node);
  6106. // #4293 teleport as component root
  6107. if (nextNode &&
  6108. isComment(nextNode) &&
  6109. nextNode.data === 'teleport end') {
  6110. nextNode = nextSibling(nextNode);
  6111. }
  6112. // #3787
  6113. // if component is async, it may get moved / unmounted before its
  6114. // inner component is loaded, so we need to give it a placeholder
  6115. // vnode that matches its adopted DOM.
  6116. if (isAsyncWrapper(vnode)) {
  6117. let subTree;
  6118. if (isFragmentStart) {
  6119. subTree = createVNode(Fragment);
  6120. subTree.anchor = nextNode
  6121. ? nextNode.previousSibling
  6122. : container.lastChild;
  6123. }
  6124. else {
  6125. subTree =
  6126. node.nodeType === 3 ? createTextVNode('') : createVNode('div');
  6127. }
  6128. subTree.el = node;
  6129. vnode.component.subTree = subTree;
  6130. }
  6131. }
  6132. else if (shapeFlag & 64 /* ShapeFlags.TELEPORT */) {
  6133. if (domType !== 8 /* DOMNodeTypes.COMMENT */) {
  6134. nextNode = onMismatch();
  6135. }
  6136. else {
  6137. nextNode = vnode.type.hydrate(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized, rendererInternals, hydrateChildren);
  6138. }
  6139. }
  6140. else if (shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
  6141. nextNode = vnode.type.hydrate(node, vnode, parentComponent, parentSuspense, isSVGContainer(parentNode(node)), slotScopeIds, optimized, rendererInternals, hydrateNode);
  6142. }
  6143. else if ((process.env.NODE_ENV !== 'production')) {
  6144. warn('Invalid HostVNode type:', type, `(${typeof type})`);
  6145. }
  6146. }
  6147. if (ref != null) {
  6148. setRef(ref, null, parentSuspense, vnode);
  6149. }
  6150. return nextNode;
  6151. };
  6152. const hydrateElement = (el, vnode, parentComponent, parentSuspense, slotScopeIds, optimized) => {
  6153. optimized = optimized || !!vnode.dynamicChildren;
  6154. const { type, props, patchFlag, shapeFlag, dirs } = vnode;
  6155. // #4006 for form elements with non-string v-model value bindings
  6156. // e.g. <option :value="obj">, <input type="checkbox" :true-value="1">
  6157. const forcePatchValue = (type === 'input' && dirs) || type === 'option';
  6158. // skip props & children if this is hoisted static nodes
  6159. // #5405 in dev, always hydrate children for HMR
  6160. if ((process.env.NODE_ENV !== 'production') || forcePatchValue || patchFlag !== -1 /* PatchFlags.HOISTED */) {
  6161. if (dirs) {
  6162. invokeDirectiveHook(vnode, null, parentComponent, 'created');
  6163. }
  6164. // props
  6165. if (props) {
  6166. if (forcePatchValue ||
  6167. !optimized ||
  6168. patchFlag & (16 /* PatchFlags.FULL_PROPS */ | 32 /* PatchFlags.HYDRATE_EVENTS */)) {
  6169. for (const key in props) {
  6170. if ((forcePatchValue && key.endsWith('value')) ||
  6171. (isOn(key) && !isReservedProp(key))) {
  6172. patchProp(el, key, null, props[key], false, undefined, parentComponent);
  6173. }
  6174. }
  6175. }
  6176. else if (props.onClick) {
  6177. // Fast path for click listeners (which is most often) to avoid
  6178. // iterating through props.
  6179. patchProp(el, 'onClick', null, props.onClick, false, undefined, parentComponent);
  6180. }
  6181. }
  6182. // vnode / directive hooks
  6183. let vnodeHooks;
  6184. if ((vnodeHooks = props && props.onVnodeBeforeMount)) {
  6185. invokeVNodeHook(vnodeHooks, parentComponent, vnode);
  6186. }
  6187. if (dirs) {
  6188. invokeDirectiveHook(vnode, null, parentComponent, 'beforeMount');
  6189. }
  6190. if ((vnodeHooks = props && props.onVnodeMounted) || dirs) {
  6191. queueEffectWithSuspense(() => {
  6192. vnodeHooks && invokeVNodeHook(vnodeHooks, parentComponent, vnode);
  6193. dirs && invokeDirectiveHook(vnode, null, parentComponent, 'mounted');
  6194. }, parentSuspense);
  6195. }
  6196. // children
  6197. if (shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */ &&
  6198. // skip if element has innerHTML / textContent
  6199. !(props && (props.innerHTML || props.textContent))) {
  6200. let next = hydrateChildren(el.firstChild, vnode, el, parentComponent, parentSuspense, slotScopeIds, optimized);
  6201. let hasWarned = false;
  6202. while (next) {
  6203. hasMismatch = true;
  6204. if ((process.env.NODE_ENV !== 'production') && !hasWarned) {
  6205. warn(`Hydration children mismatch in <${vnode.type}>: ` +
  6206. `server rendered element contains more child nodes than client vdom.`);
  6207. hasWarned = true;
  6208. }
  6209. // The SSRed DOM contains more nodes than it should. Remove them.
  6210. const cur = next;
  6211. next = next.nextSibling;
  6212. remove(cur);
  6213. }
  6214. }
  6215. else if (shapeFlag & 8 /* ShapeFlags.TEXT_CHILDREN */) {
  6216. if (el.textContent !== vnode.children) {
  6217. hasMismatch = true;
  6218. (process.env.NODE_ENV !== 'production') &&
  6219. warn(`Hydration text content mismatch in <${vnode.type}>:\n` +
  6220. `- Client: ${el.textContent}\n` +
  6221. `- Server: ${vnode.children}`);
  6222. el.textContent = vnode.children;
  6223. }
  6224. }
  6225. }
  6226. return el.nextSibling;
  6227. };
  6228. const hydrateChildren = (node, parentVNode, container, parentComponent, parentSuspense, slotScopeIds, optimized) => {
  6229. optimized = optimized || !!parentVNode.dynamicChildren;
  6230. const children = parentVNode.children;
  6231. const l = children.length;
  6232. let hasWarned = false;
  6233. for (let i = 0; i < l; i++) {
  6234. const vnode = optimized
  6235. ? children[i]
  6236. : (children[i] = normalizeVNode(children[i]));
  6237. if (node) {
  6238. node = hydrateNode(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized);
  6239. }
  6240. else if (vnode.type === Text && !vnode.children) {
  6241. continue;
  6242. }
  6243. else {
  6244. hasMismatch = true;
  6245. if ((process.env.NODE_ENV !== 'production') && !hasWarned) {
  6246. warn(`Hydration children mismatch in <${container.tagName.toLowerCase()}>: ` +
  6247. `server rendered element contains fewer child nodes than client vdom.`);
  6248. hasWarned = true;
  6249. }
  6250. // the SSRed DOM didn't contain enough nodes. Mount the missing ones.
  6251. patch(null, vnode, container, null, parentComponent, parentSuspense, isSVGContainer(container), slotScopeIds);
  6252. }
  6253. }
  6254. return node;
  6255. };
  6256. const hydrateFragment = (node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized) => {
  6257. const { slotScopeIds: fragmentSlotScopeIds } = vnode;
  6258. if (fragmentSlotScopeIds) {
  6259. slotScopeIds = slotScopeIds
  6260. ? slotScopeIds.concat(fragmentSlotScopeIds)
  6261. : fragmentSlotScopeIds;
  6262. }
  6263. const container = parentNode(node);
  6264. const next = hydrateChildren(nextSibling(node), vnode, container, parentComponent, parentSuspense, slotScopeIds, optimized);
  6265. if (next && isComment(next) && next.data === ']') {
  6266. return nextSibling((vnode.anchor = next));
  6267. }
  6268. else {
  6269. // fragment didn't hydrate successfully, since we didn't get a end anchor
  6270. // back. This should have led to node/children mismatch warnings.
  6271. hasMismatch = true;
  6272. // since the anchor is missing, we need to create one and insert it
  6273. insert((vnode.anchor = createComment(`]`)), container, next);
  6274. return next;
  6275. }
  6276. };
  6277. const handleMismatch = (node, vnode, parentComponent, parentSuspense, slotScopeIds, isFragment) => {
  6278. hasMismatch = true;
  6279. (process.env.NODE_ENV !== 'production') &&
  6280. warn(`Hydration node mismatch:\n- Client vnode:`, vnode.type, `\n- Server rendered DOM:`, node, node.nodeType === 3 /* DOMNodeTypes.TEXT */
  6281. ? `(text)`
  6282. : isComment(node) && node.data === '['
  6283. ? `(start of fragment)`
  6284. : ``);
  6285. vnode.el = null;
  6286. if (isFragment) {
  6287. // remove excessive fragment nodes
  6288. const end = locateClosingAsyncAnchor(node);
  6289. while (true) {
  6290. const next = nextSibling(node);
  6291. if (next && next !== end) {
  6292. remove(next);
  6293. }
  6294. else {
  6295. break;
  6296. }
  6297. }
  6298. }
  6299. const next = nextSibling(node);
  6300. const container = parentNode(node);
  6301. remove(node);
  6302. patch(null, vnode, container, next, parentComponent, parentSuspense, isSVGContainer(container), slotScopeIds);
  6303. return next;
  6304. };
  6305. const locateClosingAsyncAnchor = (node) => {
  6306. let match = 0;
  6307. while (node) {
  6308. node = nextSibling(node);
  6309. if (node && isComment(node)) {
  6310. if (node.data === '[')
  6311. match++;
  6312. if (node.data === ']') {
  6313. if (match === 0) {
  6314. return nextSibling(node);
  6315. }
  6316. else {
  6317. match--;
  6318. }
  6319. }
  6320. }
  6321. }
  6322. return node;
  6323. };
  6324. return [hydrate, hydrateNode];
  6325. }
  6326. /* eslint-disable no-restricted-globals */
  6327. let supported;
  6328. let perf;
  6329. function startMeasure(instance, type) {
  6330. if (instance.appContext.config.performance && isSupported()) {
  6331. perf.mark(`vue-${type}-${instance.uid}`);
  6332. }
  6333. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  6334. devtoolsPerfStart(instance, type, isSupported() ? perf.now() : Date.now());
  6335. }
  6336. }
  6337. function endMeasure(instance, type) {
  6338. if (instance.appContext.config.performance && isSupported()) {
  6339. const startTag = `vue-${type}-${instance.uid}`;
  6340. const endTag = startTag + `:end`;
  6341. perf.mark(endTag);
  6342. perf.measure(`<${formatComponentName(instance, instance.type)}> ${type}`, startTag, endTag);
  6343. perf.clearMarks(startTag);
  6344. perf.clearMarks(endTag);
  6345. }
  6346. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  6347. devtoolsPerfEnd(instance, type, isSupported() ? perf.now() : Date.now());
  6348. }
  6349. }
  6350. function isSupported() {
  6351. if (supported !== undefined) {
  6352. return supported;
  6353. }
  6354. if (typeof window !== 'undefined' && window.performance) {
  6355. supported = true;
  6356. perf = window.performance;
  6357. }
  6358. else {
  6359. supported = false;
  6360. }
  6361. return supported;
  6362. }
  6363. /**
  6364. * This is only called in esm-bundler builds.
  6365. * It is called when a renderer is created, in `baseCreateRenderer` so that
  6366. * importing runtime-core is side-effects free.
  6367. *
  6368. * istanbul-ignore-next
  6369. */
  6370. function initFeatureFlags() {
  6371. const needWarn = [];
  6372. if (typeof __VUE_OPTIONS_API__ !== 'boolean') {
  6373. (process.env.NODE_ENV !== 'production') && needWarn.push(`__VUE_OPTIONS_API__`);
  6374. getGlobalThis().__VUE_OPTIONS_API__ = true;
  6375. }
  6376. if (typeof __VUE_PROD_DEVTOOLS__ !== 'boolean') {
  6377. (process.env.NODE_ENV !== 'production') && needWarn.push(`__VUE_PROD_DEVTOOLS__`);
  6378. getGlobalThis().__VUE_PROD_DEVTOOLS__ = false;
  6379. }
  6380. if ((process.env.NODE_ENV !== 'production') && needWarn.length) {
  6381. const multi = needWarn.length > 1;
  6382. console.warn(`Feature flag${multi ? `s` : ``} ${needWarn.join(', ')} ${multi ? `are` : `is`} not explicitly defined. You are running the esm-bundler build of Vue, ` +
  6383. `which expects these compile-time feature flags to be globally injected ` +
  6384. `via the bundler config in order to get better tree-shaking in the ` +
  6385. `production bundle.\n\n` +
  6386. `For more details, see https://link.vuejs.org/feature-flags.`);
  6387. }
  6388. }
  6389. const queuePostRenderEffect = queueEffectWithSuspense
  6390. ;
  6391. /**
  6392. * The createRenderer function accepts two generic arguments:
  6393. * HostNode and HostElement, corresponding to Node and Element types in the
  6394. * host environment. For example, for runtime-dom, HostNode would be the DOM
  6395. * `Node` interface and HostElement would be the DOM `Element` interface.
  6396. *
  6397. * Custom renderers can pass in the platform specific types like this:
  6398. *
  6399. * ``` js
  6400. * const { render, createApp } = createRenderer<Node, Element>({
  6401. * patchProp,
  6402. * ...nodeOps
  6403. * })
  6404. * ```
  6405. */
  6406. function createRenderer(options) {
  6407. return baseCreateRenderer(options);
  6408. }
  6409. // Separate API for creating hydration-enabled renderer.
  6410. // Hydration logic is only used when calling this function, making it
  6411. // tree-shakable.
  6412. function createHydrationRenderer(options) {
  6413. return baseCreateRenderer(options, createHydrationFunctions);
  6414. }
  6415. // implementation
  6416. function baseCreateRenderer(options, createHydrationFns) {
  6417. // compile-time feature flags check
  6418. {
  6419. initFeatureFlags();
  6420. }
  6421. const target = getGlobalThis();
  6422. target.__VUE__ = true;
  6423. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  6424. setDevtoolsHook(target.__VUE_DEVTOOLS_GLOBAL_HOOK__, target);
  6425. }
  6426. const { insert: hostInsert, remove: hostRemove, patchProp: hostPatchProp, forcePatchProp: hostForcePatchProp, // fixed by xxxxxx
  6427. createElement: hostCreateElement, createText: hostCreateText, createComment: hostCreateComment, setText: hostSetText, setElementText: hostSetElementText, parentNode: hostParentNode, nextSibling: hostNextSibling, setScopeId: hostSetScopeId = NOOP, insertStaticContent: hostInsertStaticContent } = options;
  6428. // Note: functions inside this closure should use `const xxx = () => {}`
  6429. // style in order to prevent being inlined by minifiers.
  6430. const patch = (n1, n2, container, anchor = null, parentComponent = null, parentSuspense = null, isSVG = false, slotScopeIds = null, optimized = (process.env.NODE_ENV !== 'production') && isHmrUpdating ? false : !!n2.dynamicChildren) => {
  6431. if (n1 === n2) {
  6432. return;
  6433. }
  6434. // patching & not same type, unmount old tree
  6435. if (n1 && !isSameVNodeType(n1, n2)) {
  6436. anchor = getNextHostNode(n1);
  6437. unmount(n1, parentComponent, parentSuspense, true);
  6438. n1 = null;
  6439. }
  6440. if (n2.patchFlag === -2 /* PatchFlags.BAIL */) {
  6441. optimized = false;
  6442. n2.dynamicChildren = null;
  6443. }
  6444. const { type, ref, shapeFlag } = n2;
  6445. switch (type) {
  6446. case Text:
  6447. processText(n1, n2, container, anchor);
  6448. break;
  6449. case Comment:
  6450. processCommentNode(n1, n2, container, anchor);
  6451. break;
  6452. case Static:
  6453. if (n1 == null) {
  6454. mountStaticNode(n2, container, anchor, isSVG);
  6455. }
  6456. else if ((process.env.NODE_ENV !== 'production')) {
  6457. patchStaticNode(n1, n2, container, isSVG);
  6458. }
  6459. break;
  6460. case Fragment:
  6461. processFragment(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6462. break;
  6463. default:
  6464. if (shapeFlag & 1 /* ShapeFlags.ELEMENT */) {
  6465. processElement(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6466. }
  6467. else if (shapeFlag & 6 /* ShapeFlags.COMPONENT */) {
  6468. processComponent(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6469. }
  6470. else if (shapeFlag & 64 /* ShapeFlags.TELEPORT */) {
  6471. type.process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, internals);
  6472. }
  6473. else if (shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
  6474. type.process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, internals);
  6475. }
  6476. else if ((process.env.NODE_ENV !== 'production')) {
  6477. warn('Invalid VNode type:', type, `(${typeof type})`);
  6478. }
  6479. }
  6480. // set ref
  6481. if (ref != null && parentComponent) {
  6482. setRef(ref, n1 && n1.ref, parentSuspense, n2 || n1, !n2);
  6483. }
  6484. };
  6485. const processText = (n1, n2, container, anchor) => {
  6486. if (n1 == null) {
  6487. hostInsert((n2.el = hostCreateText(n2.children)), container, anchor);
  6488. }
  6489. else {
  6490. const el = (n2.el = n1.el);
  6491. if (n2.children !== n1.children) {
  6492. hostSetText(el, n2.children);
  6493. }
  6494. }
  6495. };
  6496. const processCommentNode = (n1, n2, container, anchor) => {
  6497. if (n1 == null) {
  6498. hostInsert((n2.el = hostCreateComment(n2.children || '')), container, anchor);
  6499. }
  6500. else {
  6501. // there's no support for dynamic comments
  6502. n2.el = n1.el;
  6503. }
  6504. };
  6505. const mountStaticNode = (n2, container, anchor, isSVG) => {
  6506. [n2.el, n2.anchor] = hostInsertStaticContent(n2.children, container, anchor, isSVG, n2.el, n2.anchor);
  6507. };
  6508. /**
  6509. * Dev / HMR only
  6510. */
  6511. const patchStaticNode = (n1, n2, container, isSVG) => {
  6512. // static nodes are only patched during dev for HMR
  6513. if (n2.children !== n1.children) {
  6514. const anchor = hostNextSibling(n1.anchor);
  6515. // remove existing
  6516. removeStaticNode(n1);
  6517. [n2.el, n2.anchor] = hostInsertStaticContent(n2.children, container, anchor, isSVG);
  6518. }
  6519. else {
  6520. n2.el = n1.el;
  6521. n2.anchor = n1.anchor;
  6522. }
  6523. };
  6524. const moveStaticNode = ({ el, anchor }, container, nextSibling) => {
  6525. let next;
  6526. while (el && el !== anchor) {
  6527. next = hostNextSibling(el);
  6528. hostInsert(el, container, nextSibling);
  6529. el = next;
  6530. }
  6531. hostInsert(anchor, container, nextSibling);
  6532. };
  6533. const removeStaticNode = ({ el, anchor }) => {
  6534. let next;
  6535. while (el && el !== anchor) {
  6536. next = hostNextSibling(el);
  6537. hostRemove(el);
  6538. el = next;
  6539. }
  6540. hostRemove(anchor);
  6541. };
  6542. const processElement = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6543. isSVG = isSVG || n2.type === 'svg';
  6544. if (n1 == null) {
  6545. mountElement(n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6546. }
  6547. else {
  6548. patchElement(n1, n2, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6549. }
  6550. };
  6551. const mountElement = (vnode, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6552. let el;
  6553. let vnodeHook;
  6554. const { type, props, shapeFlag, transition, dirs } = vnode;
  6555. el = vnode.el = hostCreateElement(vnode.type, isSVG, props && props.is, props);
  6556. // mount children first, since some props may rely on child content
  6557. // being already rendered, e.g. `<select value>`
  6558. if (shapeFlag & 8 /* ShapeFlags.TEXT_CHILDREN */) {
  6559. hostSetElementText(el, vnode.children);
  6560. }
  6561. else if (shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  6562. mountChildren(vnode.children, el, null, parentComponent, parentSuspense, isSVG && type !== 'foreignObject', slotScopeIds, optimized);
  6563. }
  6564. if (dirs) {
  6565. invokeDirectiveHook(vnode, null, parentComponent, 'created');
  6566. }
  6567. // scopeId
  6568. setScopeId(el, vnode, vnode.scopeId, slotScopeIds, parentComponent);
  6569. // props
  6570. if (props) {
  6571. for (const key in props) {
  6572. if (key !== 'value' && !isReservedProp(key)) {
  6573. hostPatchProp(el, key, null, props[key], isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  6574. }
  6575. }
  6576. /**
  6577. * Special case for setting value on DOM elements:
  6578. * - it can be order-sensitive (e.g. should be set *after* min/max, #2325, #4024)
  6579. * - it needs to be forced (#1471)
  6580. * #2353 proposes adding another renderer option to configure this, but
  6581. * the properties affects are so finite it is worth special casing it
  6582. * here to reduce the complexity. (Special casing it also should not
  6583. * affect non-DOM renderers)
  6584. */
  6585. if ('value' in props) {
  6586. hostPatchProp(el, 'value', null, props.value);
  6587. }
  6588. if ((vnodeHook = props.onVnodeBeforeMount)) {
  6589. invokeVNodeHook(vnodeHook, parentComponent, vnode);
  6590. }
  6591. }
  6592. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  6593. Object.defineProperty(el, '__vnode', {
  6594. value: vnode,
  6595. enumerable: false
  6596. });
  6597. }
  6598. // fixed by xxxxxx
  6599. Object.defineProperty(el, '__vueParentComponent', {
  6600. value: parentComponent,
  6601. enumerable: false
  6602. });
  6603. if (dirs) {
  6604. invokeDirectiveHook(vnode, null, parentComponent, 'beforeMount');
  6605. }
  6606. // #1583 For inside suspense + suspense not resolved case, enter hook should call when suspense resolved
  6607. // #1689 For inside suspense + suspense resolved case, just call it
  6608. const needCallTransitionHooks = (!parentSuspense || (parentSuspense && !parentSuspense.pendingBranch)) &&
  6609. transition &&
  6610. !transition.persisted;
  6611. if (needCallTransitionHooks) {
  6612. transition.beforeEnter(el);
  6613. }
  6614. hostInsert(el, container, anchor);
  6615. if ((vnodeHook = props && props.onVnodeMounted) ||
  6616. needCallTransitionHooks ||
  6617. dirs) {
  6618. queuePostRenderEffect(() => {
  6619. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, vnode);
  6620. needCallTransitionHooks && transition.enter(el);
  6621. dirs && invokeDirectiveHook(vnode, null, parentComponent, 'mounted');
  6622. }, parentSuspense);
  6623. }
  6624. };
  6625. const setScopeId = (el, vnode, scopeId, slotScopeIds, parentComponent) => {
  6626. if (scopeId) {
  6627. hostSetScopeId(el, scopeId);
  6628. }
  6629. if (slotScopeIds) {
  6630. for (let i = 0; i < slotScopeIds.length; i++) {
  6631. hostSetScopeId(el, slotScopeIds[i]);
  6632. }
  6633. }
  6634. if (parentComponent) {
  6635. let subTree = parentComponent.subTree;
  6636. if ((process.env.NODE_ENV !== 'production') &&
  6637. subTree.patchFlag > 0 &&
  6638. subTree.patchFlag & 2048 /* PatchFlags.DEV_ROOT_FRAGMENT */) {
  6639. subTree =
  6640. filterSingleRoot(subTree.children) || subTree;
  6641. }
  6642. if (vnode === subTree) {
  6643. const parentVNode = parentComponent.vnode;
  6644. setScopeId(el, parentVNode, parentVNode.scopeId, parentVNode.slotScopeIds, parentComponent.parent);
  6645. }
  6646. }
  6647. };
  6648. const mountChildren = (children, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, start = 0) => {
  6649. for (let i = start; i < children.length; i++) {
  6650. const child = (children[i] = optimized
  6651. ? cloneIfMounted(children[i])
  6652. : normalizeVNode(children[i]));
  6653. patch(null, child, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6654. }
  6655. };
  6656. const patchElement = (n1, n2, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6657. const el = (n2.el = n1.el);
  6658. let { patchFlag, dynamicChildren, dirs } = n2;
  6659. // #1426 take the old vnode's patch flag into account since user may clone a
  6660. // compiler-generated vnode, which de-opts to FULL_PROPS
  6661. patchFlag |= n1.patchFlag & 16 /* PatchFlags.FULL_PROPS */;
  6662. const oldProps = n1.props || EMPTY_OBJ;
  6663. const newProps = n2.props || EMPTY_OBJ;
  6664. let vnodeHook;
  6665. // disable recurse in beforeUpdate hooks
  6666. parentComponent && toggleRecurse(parentComponent, false);
  6667. if ((vnodeHook = newProps.onVnodeBeforeUpdate)) {
  6668. invokeVNodeHook(vnodeHook, parentComponent, n2, n1);
  6669. }
  6670. if (dirs) {
  6671. invokeDirectiveHook(n2, n1, parentComponent, 'beforeUpdate');
  6672. }
  6673. parentComponent && toggleRecurse(parentComponent, true);
  6674. if ((process.env.NODE_ENV !== 'production') && isHmrUpdating) {
  6675. // HMR updated, force full diff
  6676. patchFlag = 0;
  6677. optimized = false;
  6678. dynamicChildren = null;
  6679. }
  6680. const areChildrenSVG = isSVG && n2.type !== 'foreignObject';
  6681. if (dynamicChildren) {
  6682. patchBlockChildren(n1.dynamicChildren, dynamicChildren, el, parentComponent, parentSuspense, areChildrenSVG, slotScopeIds);
  6683. if ((process.env.NODE_ENV !== 'production') && parentComponent && parentComponent.type.__hmrId) {
  6684. traverseStaticChildren(n1, n2);
  6685. }
  6686. }
  6687. else if (!optimized) {
  6688. // full diff
  6689. patchChildren(n1, n2, el, null, parentComponent, parentSuspense, areChildrenSVG, slotScopeIds, false);
  6690. }
  6691. if (patchFlag > 0) {
  6692. // the presence of a patchFlag means this element's render code was
  6693. // generated by the compiler and can take the fast path.
  6694. // in this path old node and new node are guaranteed to have the same shape
  6695. // (i.e. at the exact same position in the source template)
  6696. if (patchFlag & 16 /* PatchFlags.FULL_PROPS */) {
  6697. // element props contain dynamic keys, full diff needed
  6698. patchProps(el, n2, oldProps, newProps, parentComponent, parentSuspense, isSVG);
  6699. }
  6700. else {
  6701. // class
  6702. // this flag is matched when the element has dynamic class bindings.
  6703. if (patchFlag & 2 /* PatchFlags.CLASS */) {
  6704. if (oldProps.class !== newProps.class) {
  6705. hostPatchProp(el, 'class', null, newProps.class, isSVG);
  6706. }
  6707. }
  6708. // style
  6709. // this flag is matched when the element has dynamic style bindings
  6710. if (patchFlag & 4 /* PatchFlags.STYLE */) {
  6711. hostPatchProp(el, 'style', oldProps.style, newProps.style, isSVG);
  6712. }
  6713. // props
  6714. // This flag is matched when the element has dynamic prop/attr bindings
  6715. // other than class and style. The keys of dynamic prop/attrs are saved for
  6716. // faster iteration.
  6717. // Note dynamic keys like :[foo]="bar" will cause this optimization to
  6718. // bail out and go through a full diff because we need to unset the old key
  6719. if (patchFlag & 8 /* PatchFlags.PROPS */) {
  6720. // if the flag is present then dynamicProps must be non-null
  6721. const propsToUpdate = n2.dynamicProps;
  6722. for (let i = 0; i < propsToUpdate.length; i++) {
  6723. const key = propsToUpdate[i];
  6724. const prev = oldProps[key];
  6725. const next = newProps[key];
  6726. // #1471 force patch value
  6727. if (next !== prev ||
  6728. key === 'value' ||
  6729. (hostForcePatchProp && hostForcePatchProp(el, key)) // fixed by xxxxxx
  6730. ) {
  6731. hostPatchProp(el, key, prev, next, isSVG, n1.children, parentComponent, parentSuspense, unmountChildren);
  6732. }
  6733. }
  6734. }
  6735. }
  6736. // text
  6737. // This flag is matched when the element has only dynamic text children.
  6738. if (patchFlag & 1 /* PatchFlags.TEXT */) {
  6739. if (n1.children !== n2.children) {
  6740. hostSetElementText(el, n2.children);
  6741. }
  6742. }
  6743. }
  6744. else if (!optimized && dynamicChildren == null) {
  6745. // unoptimized, full diff
  6746. patchProps(el, n2, oldProps, newProps, parentComponent, parentSuspense, isSVG);
  6747. }
  6748. if ((vnodeHook = newProps.onVnodeUpdated) || dirs) {
  6749. queuePostRenderEffect(() => {
  6750. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, n2, n1);
  6751. dirs && invokeDirectiveHook(n2, n1, parentComponent, 'updated');
  6752. }, parentSuspense);
  6753. }
  6754. };
  6755. // The fast path for blocks.
  6756. const patchBlockChildren = (oldChildren, newChildren, fallbackContainer, parentComponent, parentSuspense, isSVG, slotScopeIds) => {
  6757. for (let i = 0; i < newChildren.length; i++) {
  6758. const oldVNode = oldChildren[i];
  6759. const newVNode = newChildren[i];
  6760. // Determine the container (parent element) for the patch.
  6761. const container =
  6762. // oldVNode may be an errored async setup() component inside Suspense
  6763. // which will not have a mounted element
  6764. oldVNode.el &&
  6765. // - In the case of a Fragment, we need to provide the actual parent
  6766. // of the Fragment itself so it can move its children.
  6767. (oldVNode.type === Fragment ||
  6768. // - In the case of different nodes, there is going to be a replacement
  6769. // which also requires the correct parent container
  6770. !isSameVNodeType(oldVNode, newVNode) ||
  6771. // - In the case of a component, it could contain anything.
  6772. oldVNode.shapeFlag & (6 /* ShapeFlags.COMPONENT */ | 64 /* ShapeFlags.TELEPORT */))
  6773. ? hostParentNode(oldVNode.el)
  6774. : // In other cases, the parent container is not actually used so we
  6775. // just pass the block element here to avoid a DOM parentNode call.
  6776. fallbackContainer;
  6777. patch(oldVNode, newVNode, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, true);
  6778. }
  6779. };
  6780. const patchProps = (el, vnode, oldProps, newProps, parentComponent, parentSuspense, isSVG) => {
  6781. if (oldProps !== newProps) {
  6782. if (oldProps !== EMPTY_OBJ) {
  6783. for (const key in oldProps) {
  6784. if (!isReservedProp(key) && !(key in newProps)) {
  6785. hostPatchProp(el, key, oldProps[key], null, isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  6786. }
  6787. }
  6788. }
  6789. for (const key in newProps) {
  6790. // empty string is not valid prop
  6791. if (isReservedProp(key))
  6792. continue;
  6793. const next = newProps[key];
  6794. const prev = oldProps[key];
  6795. // defer patching value
  6796. if ((next !== prev && key !== 'value') ||
  6797. (hostForcePatchProp && hostForcePatchProp(el, key)) // fixed by xxxxxx
  6798. ) {
  6799. hostPatchProp(el, key, prev, next, isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  6800. }
  6801. }
  6802. if ('value' in newProps) {
  6803. hostPatchProp(el, 'value', oldProps.value, newProps.value);
  6804. }
  6805. }
  6806. };
  6807. const processFragment = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6808. const fragmentStartAnchor = (n2.el = n1 ? n1.el : hostCreateText(''));
  6809. const fragmentEndAnchor = (n2.anchor = n1 ? n1.anchor : hostCreateText(''));
  6810. let { patchFlag, dynamicChildren, slotScopeIds: fragmentSlotScopeIds } = n2;
  6811. if ((process.env.NODE_ENV !== 'production') &&
  6812. // #5523 dev root fragment may inherit directives
  6813. (isHmrUpdating || patchFlag & 2048 /* PatchFlags.DEV_ROOT_FRAGMENT */)) {
  6814. // HMR updated / Dev root fragment (w/ comments), force full diff
  6815. patchFlag = 0;
  6816. optimized = false;
  6817. dynamicChildren = null;
  6818. }
  6819. // check if this is a slot fragment with :slotted scope ids
  6820. if (fragmentSlotScopeIds) {
  6821. slotScopeIds = slotScopeIds
  6822. ? slotScopeIds.concat(fragmentSlotScopeIds)
  6823. : fragmentSlotScopeIds;
  6824. }
  6825. if (n1 == null) {
  6826. hostInsert(fragmentStartAnchor, container, anchor);
  6827. hostInsert(fragmentEndAnchor, container, anchor);
  6828. // a fragment can only have array children
  6829. // since they are either generated by the compiler, or implicitly created
  6830. // from arrays.
  6831. mountChildren(
  6832. // #10007
  6833. // such fragment like `<></>` will be compiled into
  6834. // a fragment which doesn't have a children.
  6835. // In this case fallback to an empty array
  6836. (n2.children || []), container, fragmentEndAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6837. }
  6838. else {
  6839. if (patchFlag > 0 &&
  6840. patchFlag & 64 /* PatchFlags.STABLE_FRAGMENT */ &&
  6841. dynamicChildren &&
  6842. // #2715 the previous fragment could've been a BAILed one as a result
  6843. // of renderSlot() with no valid children
  6844. n1.dynamicChildren) {
  6845. // a stable fragment (template root or <template v-for>) doesn't need to
  6846. // patch children order, but it may contain dynamicChildren.
  6847. patchBlockChildren(n1.dynamicChildren, dynamicChildren, container, parentComponent, parentSuspense, isSVG, slotScopeIds);
  6848. if ((process.env.NODE_ENV !== 'production') && parentComponent && parentComponent.type.__hmrId) {
  6849. traverseStaticChildren(n1, n2);
  6850. }
  6851. else if (
  6852. // #2080 if the stable fragment has a key, it's a <template v-for> that may
  6853. // get moved around. Make sure all root level vnodes inherit el.
  6854. // #2134 or if it's a component root, it may also get moved around
  6855. // as the component is being moved.
  6856. n2.key != null ||
  6857. (parentComponent && n2 === parentComponent.subTree)) {
  6858. traverseStaticChildren(n1, n2, true /* shallow */);
  6859. }
  6860. }
  6861. else {
  6862. // keyed / unkeyed, or manual fragments.
  6863. // for keyed & unkeyed, since they are compiler generated from v-for,
  6864. // each child is guaranteed to be a block so the fragment will never
  6865. // have dynamicChildren.
  6866. patchChildren(n1, n2, container, fragmentEndAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6867. }
  6868. }
  6869. };
  6870. const processComponent = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6871. n2.slotScopeIds = slotScopeIds;
  6872. if (n1 == null) {
  6873. if (n2.shapeFlag & 512 /* ShapeFlags.COMPONENT_KEPT_ALIVE */) {
  6874. parentComponent.ctx.activate(n2, container, anchor, isSVG, optimized);
  6875. }
  6876. else {
  6877. mountComponent(n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  6878. }
  6879. }
  6880. else {
  6881. updateComponent(n1, n2, optimized);
  6882. }
  6883. };
  6884. const mountComponent = (initialVNode, container, anchor, parentComponent, parentSuspense, isSVG, optimized) => {
  6885. const instance = (initialVNode.component = createComponentInstance(initialVNode, parentComponent, parentSuspense));
  6886. if ((process.env.NODE_ENV !== 'production') && instance.type.__hmrId) {
  6887. registerHMR(instance);
  6888. }
  6889. if ((process.env.NODE_ENV !== 'production')) {
  6890. pushWarningContext(initialVNode);
  6891. startMeasure(instance, `mount`);
  6892. }
  6893. // inject renderer internals for keepAlive
  6894. if (isKeepAlive(initialVNode)) {
  6895. instance.ctx.renderer = internals;
  6896. }
  6897. // resolve props and slots for setup context
  6898. {
  6899. if ((process.env.NODE_ENV !== 'production')) {
  6900. startMeasure(instance, `init`);
  6901. }
  6902. setupComponent(instance);
  6903. if ((process.env.NODE_ENV !== 'production')) {
  6904. endMeasure(instance, `init`);
  6905. }
  6906. }
  6907. // setup() is async. This component relies on async logic to be resolved
  6908. // before proceeding
  6909. if (instance.asyncDep) {
  6910. parentSuspense && parentSuspense.registerDep(instance, setupRenderEffect);
  6911. // Give it a placeholder if this is not hydration
  6912. // TODO handle self-defined fallback
  6913. if (!initialVNode.el) {
  6914. const placeholder = (instance.subTree = createVNode(Comment));
  6915. processCommentNode(null, placeholder, container, anchor);
  6916. }
  6917. return;
  6918. }
  6919. setupRenderEffect(instance, initialVNode, container, anchor, parentSuspense, isSVG, optimized);
  6920. if ((process.env.NODE_ENV !== 'production')) {
  6921. popWarningContext();
  6922. endMeasure(instance, `mount`);
  6923. }
  6924. };
  6925. const updateComponent = (n1, n2, optimized) => {
  6926. const instance = (n2.component = n1.component);
  6927. if (shouldUpdateComponent(n1, n2, optimized)) {
  6928. if (instance.asyncDep &&
  6929. !instance.asyncResolved) {
  6930. // async & still pending - just update props and slots
  6931. // since the component's reactive effect for render isn't set-up yet
  6932. if ((process.env.NODE_ENV !== 'production')) {
  6933. pushWarningContext(n2);
  6934. }
  6935. updateComponentPreRender(instance, n2, optimized);
  6936. if ((process.env.NODE_ENV !== 'production')) {
  6937. popWarningContext();
  6938. }
  6939. return;
  6940. }
  6941. else {
  6942. // normal update
  6943. instance.next = n2;
  6944. // in case the child component is also queued, remove it to avoid
  6945. // double updating the same child component in the same flush.
  6946. invalidateJob(instance.update);
  6947. // instance.update is the reactive effect.
  6948. instance.update();
  6949. }
  6950. }
  6951. else {
  6952. // no update needed. just copy over properties
  6953. n2.el = n1.el;
  6954. instance.vnode = n2;
  6955. }
  6956. };
  6957. const setupRenderEffect = (instance, initialVNode, container, anchor, parentSuspense, isSVG, optimized) => {
  6958. const componentUpdateFn = () => {
  6959. if (!instance.isMounted) {
  6960. let vnodeHook;
  6961. const { el, props } = initialVNode;
  6962. const { bm, m, parent } = instance;
  6963. const isAsyncWrapperVNode = isAsyncWrapper(initialVNode);
  6964. toggleRecurse(instance, false);
  6965. // beforeMount hook
  6966. if (bm) {
  6967. invokeArrayFns(bm);
  6968. }
  6969. // onVnodeBeforeMount
  6970. if (!isAsyncWrapperVNode &&
  6971. (vnodeHook = props && props.onVnodeBeforeMount)) {
  6972. invokeVNodeHook(vnodeHook, parent, initialVNode);
  6973. }
  6974. toggleRecurse(instance, true);
  6975. if (el && hydrateNode) {
  6976. // vnode has adopted host node - perform hydration instead of mount.
  6977. const hydrateSubTree = () => {
  6978. if ((process.env.NODE_ENV !== 'production')) {
  6979. startMeasure(instance, `render`);
  6980. }
  6981. instance.subTree = renderComponentRoot(instance);
  6982. if ((process.env.NODE_ENV !== 'production')) {
  6983. endMeasure(instance, `render`);
  6984. }
  6985. if ((process.env.NODE_ENV !== 'production')) {
  6986. startMeasure(instance, `hydrate`);
  6987. }
  6988. hydrateNode(el, instance.subTree, instance, parentSuspense, null);
  6989. if ((process.env.NODE_ENV !== 'production')) {
  6990. endMeasure(instance, `hydrate`);
  6991. }
  6992. };
  6993. if (isAsyncWrapperVNode) {
  6994. initialVNode.type.__asyncLoader().then(
  6995. // note: we are moving the render call into an async callback,
  6996. // which means it won't track dependencies - but it's ok because
  6997. // a server-rendered async wrapper is already in resolved state
  6998. // and it will never need to change.
  6999. () => !instance.isUnmounted && hydrateSubTree());
  7000. }
  7001. else {
  7002. hydrateSubTree();
  7003. }
  7004. }
  7005. else {
  7006. if ((process.env.NODE_ENV !== 'production')) {
  7007. startMeasure(instance, `render`);
  7008. }
  7009. const subTree = (instance.subTree = renderComponentRoot(instance));
  7010. if ((process.env.NODE_ENV !== 'production')) {
  7011. endMeasure(instance, `render`);
  7012. }
  7013. if ((process.env.NODE_ENV !== 'production')) {
  7014. startMeasure(instance, `patch`);
  7015. }
  7016. patch(null, subTree, container, anchor, instance, parentSuspense, isSVG);
  7017. if ((process.env.NODE_ENV !== 'production')) {
  7018. endMeasure(instance, `patch`);
  7019. }
  7020. initialVNode.el = subTree.el;
  7021. }
  7022. // mounted hook
  7023. if (m) {
  7024. queuePostRenderEffect(m, parentSuspense);
  7025. }
  7026. // onVnodeMounted
  7027. if (!isAsyncWrapperVNode &&
  7028. (vnodeHook = props && props.onVnodeMounted)) {
  7029. const scopedInitialVNode = initialVNode;
  7030. queuePostRenderEffect(() => invokeVNodeHook(vnodeHook, parent, scopedInitialVNode), parentSuspense);
  7031. }
  7032. // fixed by xxxxxx
  7033. // activated hook for keep-alive roots.
  7034. // #1742 beforeActivate/activated hook must be accessed after first render
  7035. // since the hook may be injected by a child keep-alive
  7036. const { ba, a } = instance;
  7037. if (initialVNode.shapeFlag & 256 /* ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE */ ||
  7038. (parent &&
  7039. isAsyncWrapper(parent.vnode) &&
  7040. parent.vnode.shapeFlag & 256 /* ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE */)) {
  7041. ba && invokeKeepAliveHooks(ba);
  7042. a && queuePostRenderEffect(a, parentSuspense);
  7043. // reset hook state
  7044. ba && queuePostRenderEffect(() => resetHookState(ba), parentSuspense);
  7045. }
  7046. instance.isMounted = true;
  7047. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  7048. devtoolsComponentAdded(instance);
  7049. }
  7050. // #2458: deference mount-only object parameters to prevent memleaks
  7051. initialVNode = container = anchor = null;
  7052. }
  7053. else {
  7054. // updateComponent
  7055. // This is triggered by mutation of component's own state (next: null)
  7056. // OR parent calling processComponent (next: VNode)
  7057. let { next, bu, u, parent, vnode } = instance;
  7058. let originNext = next;
  7059. let vnodeHook;
  7060. if ((process.env.NODE_ENV !== 'production')) {
  7061. pushWarningContext(next || instance.vnode);
  7062. }
  7063. // Disallow component effect recursion during pre-lifecycle hooks.
  7064. toggleRecurse(instance, false);
  7065. if (next) {
  7066. next.el = vnode.el;
  7067. updateComponentPreRender(instance, next, optimized);
  7068. }
  7069. else {
  7070. next = vnode;
  7071. }
  7072. // beforeUpdate hook
  7073. if (bu) {
  7074. invokeArrayFns(bu);
  7075. }
  7076. // onVnodeBeforeUpdate
  7077. if ((vnodeHook = next.props && next.props.onVnodeBeforeUpdate)) {
  7078. invokeVNodeHook(vnodeHook, parent, next, vnode);
  7079. }
  7080. toggleRecurse(instance, true);
  7081. // render
  7082. if ((process.env.NODE_ENV !== 'production')) {
  7083. startMeasure(instance, `render`);
  7084. }
  7085. const nextTree = renderComponentRoot(instance);
  7086. if ((process.env.NODE_ENV !== 'production')) {
  7087. endMeasure(instance, `render`);
  7088. }
  7089. const prevTree = instance.subTree;
  7090. instance.subTree = nextTree;
  7091. if ((process.env.NODE_ENV !== 'production')) {
  7092. startMeasure(instance, `patch`);
  7093. }
  7094. patch(prevTree, nextTree,
  7095. // parent may have changed if it's in a teleport
  7096. hostParentNode(prevTree.el),
  7097. // anchor may have changed if it's in a fragment
  7098. getNextHostNode(prevTree), instance, parentSuspense, isSVG);
  7099. if ((process.env.NODE_ENV !== 'production')) {
  7100. endMeasure(instance, `patch`);
  7101. }
  7102. next.el = nextTree.el;
  7103. if (originNext === null) {
  7104. // self-triggered update. In case of HOC, update parent component
  7105. // vnode el. HOC is indicated by parent instance's subTree pointing
  7106. // to child component's vnode
  7107. updateHOCHostEl(instance, nextTree.el);
  7108. }
  7109. // updated hook
  7110. if (u) {
  7111. queuePostRenderEffect(u, parentSuspense);
  7112. }
  7113. // onVnodeUpdated
  7114. if ((vnodeHook = next.props && next.props.onVnodeUpdated)) {
  7115. queuePostRenderEffect(() => invokeVNodeHook(vnodeHook, parent, next, vnode), parentSuspense);
  7116. }
  7117. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  7118. devtoolsComponentUpdated(instance);
  7119. }
  7120. if ((process.env.NODE_ENV !== 'production')) {
  7121. popWarningContext();
  7122. }
  7123. }
  7124. };
  7125. // create reactive effect for rendering
  7126. const effect = (instance.effect = new ReactiveEffect(componentUpdateFn, () => queueJob(update), instance.scope // track it in component's effect scope
  7127. ));
  7128. const update = (instance.update = () => effect.run());
  7129. update.id = instance.uid;
  7130. // allowRecurse
  7131. // #1801, #2043 component render effects should allow recursive updates
  7132. toggleRecurse(instance, true);
  7133. if ((process.env.NODE_ENV !== 'production')) {
  7134. effect.onTrack = instance.rtc
  7135. ? e => invokeArrayFns(instance.rtc, e)
  7136. : void 0;
  7137. effect.onTrigger = instance.rtg
  7138. ? e => invokeArrayFns(instance.rtg, e)
  7139. : void 0;
  7140. update.ownerInstance = instance;
  7141. }
  7142. update();
  7143. };
  7144. const updateComponentPreRender = (instance, nextVNode, optimized) => {
  7145. nextVNode.component = instance;
  7146. const prevProps = instance.vnode.props;
  7147. instance.vnode = nextVNode;
  7148. instance.next = null;
  7149. updateProps(instance, nextVNode.props, prevProps, optimized);
  7150. updateSlots(instance, nextVNode.children, optimized);
  7151. pauseTracking();
  7152. // props update may have triggered pre-flush watchers.
  7153. // flush them before the render update.
  7154. flushPreFlushCbs();
  7155. resetTracking();
  7156. };
  7157. const patchChildren = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized = false) => {
  7158. const c1 = n1 && n1.children;
  7159. const prevShapeFlag = n1 ? n1.shapeFlag : 0;
  7160. const c2 = n2.children;
  7161. const { patchFlag, shapeFlag } = n2;
  7162. // fast path
  7163. if (patchFlag > 0) {
  7164. if (patchFlag & 128 /* PatchFlags.KEYED_FRAGMENT */) {
  7165. // this could be either fully-keyed or mixed (some keyed some not)
  7166. // presence of patchFlag means children are guaranteed to be arrays
  7167. patchKeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7168. return;
  7169. }
  7170. else if (patchFlag & 256 /* PatchFlags.UNKEYED_FRAGMENT */) {
  7171. // unkeyed
  7172. patchUnkeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7173. return;
  7174. }
  7175. }
  7176. // children has 3 possibilities: text, array or no children.
  7177. if (shapeFlag & 8 /* ShapeFlags.TEXT_CHILDREN */) {
  7178. // text children fast path
  7179. if (prevShapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  7180. unmountChildren(c1, parentComponent, parentSuspense);
  7181. }
  7182. if (c2 !== c1) {
  7183. hostSetElementText(container, c2);
  7184. }
  7185. }
  7186. else {
  7187. if (prevShapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  7188. // prev children was array
  7189. if (shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  7190. // two arrays, cannot assume anything, do full diff
  7191. patchKeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7192. }
  7193. else {
  7194. // no new children, just unmount old
  7195. unmountChildren(c1, parentComponent, parentSuspense, true);
  7196. }
  7197. }
  7198. else {
  7199. // prev children was text OR null
  7200. // new children is array OR null
  7201. if (prevShapeFlag & 8 /* ShapeFlags.TEXT_CHILDREN */) {
  7202. hostSetElementText(container, '');
  7203. }
  7204. // mount new if array
  7205. if (shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  7206. mountChildren(c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7207. }
  7208. }
  7209. }
  7210. };
  7211. const patchUnkeyedChildren = (c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  7212. c1 = c1 || EMPTY_ARR;
  7213. c2 = c2 || EMPTY_ARR;
  7214. const oldLength = c1.length;
  7215. const newLength = c2.length;
  7216. const commonLength = Math.min(oldLength, newLength);
  7217. let i;
  7218. for (i = 0; i < commonLength; i++) {
  7219. const nextChild = (c2[i] = optimized
  7220. ? cloneIfMounted(c2[i])
  7221. : normalizeVNode(c2[i]));
  7222. patch(c1[i], nextChild, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7223. }
  7224. if (oldLength > newLength) {
  7225. // remove old
  7226. unmountChildren(c1, parentComponent, parentSuspense, true, false, commonLength);
  7227. }
  7228. else {
  7229. // mount new
  7230. mountChildren(c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, commonLength);
  7231. }
  7232. };
  7233. // can be all-keyed or mixed
  7234. const patchKeyedChildren = (c1, c2, container, parentAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  7235. let i = 0;
  7236. const l2 = c2.length;
  7237. let e1 = c1.length - 1; // prev ending index
  7238. let e2 = l2 - 1; // next ending index
  7239. // 1. sync from start
  7240. // (a b) c
  7241. // (a b) d e
  7242. while (i <= e1 && i <= e2) {
  7243. const n1 = c1[i];
  7244. const n2 = (c2[i] = optimized
  7245. ? cloneIfMounted(c2[i])
  7246. : normalizeVNode(c2[i]));
  7247. if (isSameVNodeType(n1, n2)) {
  7248. patch(n1, n2, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7249. }
  7250. else {
  7251. break;
  7252. }
  7253. i++;
  7254. }
  7255. // 2. sync from end
  7256. // a (b c)
  7257. // d e (b c)
  7258. while (i <= e1 && i <= e2) {
  7259. const n1 = c1[e1];
  7260. const n2 = (c2[e2] = optimized
  7261. ? cloneIfMounted(c2[e2])
  7262. : normalizeVNode(c2[e2]));
  7263. if (isSameVNodeType(n1, n2)) {
  7264. patch(n1, n2, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7265. }
  7266. else {
  7267. break;
  7268. }
  7269. e1--;
  7270. e2--;
  7271. }
  7272. // 3. common sequence + mount
  7273. // (a b)
  7274. // (a b) c
  7275. // i = 2, e1 = 1, e2 = 2
  7276. // (a b)
  7277. // c (a b)
  7278. // i = 0, e1 = -1, e2 = 0
  7279. if (i > e1) {
  7280. if (i <= e2) {
  7281. const nextPos = e2 + 1;
  7282. const anchor = nextPos < l2 ? c2[nextPos].el : parentAnchor;
  7283. while (i <= e2) {
  7284. patch(null, (c2[i] = optimized
  7285. ? cloneIfMounted(c2[i])
  7286. : normalizeVNode(c2[i])), container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7287. i++;
  7288. }
  7289. }
  7290. }
  7291. // 4. common sequence + unmount
  7292. // (a b) c
  7293. // (a b)
  7294. // i = 2, e1 = 2, e2 = 1
  7295. // a (b c)
  7296. // (b c)
  7297. // i = 0, e1 = 0, e2 = -1
  7298. else if (i > e2) {
  7299. while (i <= e1) {
  7300. unmount(c1[i], parentComponent, parentSuspense, true);
  7301. i++;
  7302. }
  7303. }
  7304. // 5. unknown sequence
  7305. // [i ... e1 + 1]: a b [c d e] f g
  7306. // [i ... e2 + 1]: a b [e d c h] f g
  7307. // i = 2, e1 = 4, e2 = 5
  7308. else {
  7309. const s1 = i; // prev starting index
  7310. const s2 = i; // next starting index
  7311. // 5.1 build key:index map for newChildren
  7312. const keyToNewIndexMap = new Map();
  7313. for (i = s2; i <= e2; i++) {
  7314. const nextChild = (c2[i] = optimized
  7315. ? cloneIfMounted(c2[i])
  7316. : normalizeVNode(c2[i]));
  7317. if (nextChild.key != null) {
  7318. if ((process.env.NODE_ENV !== 'production') && keyToNewIndexMap.has(nextChild.key)) {
  7319. warn(`Duplicate keys found during update:`, JSON.stringify(nextChild.key), `Make sure keys are unique.`);
  7320. }
  7321. keyToNewIndexMap.set(nextChild.key, i);
  7322. }
  7323. }
  7324. // 5.2 loop through old children left to be patched and try to patch
  7325. // matching nodes & remove nodes that are no longer present
  7326. let j;
  7327. let patched = 0;
  7328. const toBePatched = e2 - s2 + 1;
  7329. let moved = false;
  7330. // used to track whether any node has moved
  7331. let maxNewIndexSoFar = 0;
  7332. // works as Map<newIndex, oldIndex>
  7333. // Note that oldIndex is offset by +1
  7334. // and oldIndex = 0 is a special value indicating the new node has
  7335. // no corresponding old node.
  7336. // used for determining longest stable subsequence
  7337. const newIndexToOldIndexMap = new Array(toBePatched);
  7338. for (i = 0; i < toBePatched; i++)
  7339. newIndexToOldIndexMap[i] = 0;
  7340. for (i = s1; i <= e1; i++) {
  7341. const prevChild = c1[i];
  7342. if (patched >= toBePatched) {
  7343. // all new children have been patched so this can only be a removal
  7344. unmount(prevChild, parentComponent, parentSuspense, true);
  7345. continue;
  7346. }
  7347. let newIndex;
  7348. if (prevChild.key != null) {
  7349. newIndex = keyToNewIndexMap.get(prevChild.key);
  7350. }
  7351. else {
  7352. // key-less node, try to locate a key-less node of the same type
  7353. for (j = s2; j <= e2; j++) {
  7354. if (newIndexToOldIndexMap[j - s2] === 0 &&
  7355. isSameVNodeType(prevChild, c2[j])) {
  7356. newIndex = j;
  7357. break;
  7358. }
  7359. }
  7360. }
  7361. if (newIndex === undefined) {
  7362. unmount(prevChild, parentComponent, parentSuspense, true);
  7363. }
  7364. else {
  7365. newIndexToOldIndexMap[newIndex - s2] = i + 1;
  7366. if (newIndex >= maxNewIndexSoFar) {
  7367. maxNewIndexSoFar = newIndex;
  7368. }
  7369. else {
  7370. moved = true;
  7371. }
  7372. patch(prevChild, c2[newIndex], container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7373. patched++;
  7374. }
  7375. }
  7376. // 5.3 move and mount
  7377. // generate longest stable subsequence only when nodes have moved
  7378. const increasingNewIndexSequence = moved
  7379. ? getSequence(newIndexToOldIndexMap)
  7380. : EMPTY_ARR;
  7381. j = increasingNewIndexSequence.length - 1;
  7382. // looping backwards so that we can use last patched node as anchor
  7383. for (i = toBePatched - 1; i >= 0; i--) {
  7384. const nextIndex = s2 + i;
  7385. const nextChild = c2[nextIndex];
  7386. const anchor = nextIndex + 1 < l2 ? c2[nextIndex + 1].el : parentAnchor;
  7387. if (newIndexToOldIndexMap[i] === 0) {
  7388. // mount new
  7389. patch(null, nextChild, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7390. }
  7391. else if (moved) {
  7392. // move if:
  7393. // There is no stable subsequence (e.g. a reverse)
  7394. // OR current node is not among the stable sequence
  7395. if (j < 0 || i !== increasingNewIndexSequence[j]) {
  7396. move(nextChild, container, anchor, 2 /* MoveType.REORDER */);
  7397. }
  7398. else {
  7399. j--;
  7400. }
  7401. }
  7402. }
  7403. }
  7404. };
  7405. const move = (vnode, container, anchor, moveType, parentSuspense = null) => {
  7406. const { el, type, transition, children, shapeFlag } = vnode;
  7407. if (shapeFlag & 6 /* ShapeFlags.COMPONENT */) {
  7408. move(vnode.component.subTree, container, anchor, moveType);
  7409. return;
  7410. }
  7411. if (shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
  7412. vnode.suspense.move(container, anchor, moveType);
  7413. return;
  7414. }
  7415. if (shapeFlag & 64 /* ShapeFlags.TELEPORT */) {
  7416. type.move(vnode, container, anchor, internals);
  7417. return;
  7418. }
  7419. if (type === Fragment) {
  7420. hostInsert(el, container, anchor);
  7421. for (let i = 0; i < children.length; i++) {
  7422. move(children[i], container, anchor, moveType);
  7423. }
  7424. hostInsert(vnode.anchor, container, anchor);
  7425. return;
  7426. }
  7427. if (type === Static) {
  7428. moveStaticNode(vnode, container, anchor);
  7429. return;
  7430. }
  7431. // single nodes
  7432. const needTransition = moveType !== 2 /* MoveType.REORDER */ &&
  7433. shapeFlag & 1 /* ShapeFlags.ELEMENT */ &&
  7434. transition;
  7435. if (needTransition) {
  7436. if (moveType === 0 /* MoveType.ENTER */) {
  7437. transition.beforeEnter(el);
  7438. hostInsert(el, container, anchor);
  7439. queuePostRenderEffect(() => transition.enter(el), parentSuspense);
  7440. }
  7441. else {
  7442. const { leave, delayLeave, afterLeave } = transition;
  7443. const remove = () => hostInsert(el, container, anchor);
  7444. const performLeave = () => {
  7445. leave(el, () => {
  7446. remove();
  7447. afterLeave && afterLeave();
  7448. });
  7449. };
  7450. if (delayLeave) {
  7451. delayLeave(el, remove, performLeave);
  7452. }
  7453. else {
  7454. performLeave();
  7455. }
  7456. }
  7457. }
  7458. else {
  7459. hostInsert(el, container, anchor);
  7460. }
  7461. };
  7462. const unmount = (vnode, parentComponent, parentSuspense, doRemove = false, optimized = false) => {
  7463. const { type, props, ref, children, dynamicChildren, shapeFlag, patchFlag, dirs } = vnode;
  7464. // unset ref
  7465. if (ref != null) {
  7466. setRef(ref, null, parentSuspense, vnode, true);
  7467. }
  7468. if (shapeFlag & 256 /* ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE */) {
  7469. parentComponent.ctx.deactivate(vnode);
  7470. return;
  7471. }
  7472. const shouldInvokeDirs = shapeFlag & 1 /* ShapeFlags.ELEMENT */ && dirs;
  7473. const shouldInvokeVnodeHook = !isAsyncWrapper(vnode);
  7474. let vnodeHook;
  7475. if (shouldInvokeVnodeHook &&
  7476. (vnodeHook = props && props.onVnodeBeforeUnmount)) {
  7477. invokeVNodeHook(vnodeHook, parentComponent, vnode);
  7478. }
  7479. if (shapeFlag & 6 /* ShapeFlags.COMPONENT */) {
  7480. unmountComponent(vnode.component, parentSuspense, doRemove);
  7481. }
  7482. else {
  7483. if (shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
  7484. vnode.suspense.unmount(parentSuspense, doRemove);
  7485. return;
  7486. }
  7487. if (shouldInvokeDirs) {
  7488. invokeDirectiveHook(vnode, null, parentComponent, 'beforeUnmount');
  7489. }
  7490. if (shapeFlag & 64 /* ShapeFlags.TELEPORT */) {
  7491. vnode.type.remove(vnode, parentComponent, parentSuspense, optimized, internals, doRemove);
  7492. }
  7493. else if (dynamicChildren &&
  7494. // #1153: fast path should not be taken for non-stable (v-for) fragments
  7495. (type !== Fragment ||
  7496. (patchFlag > 0 && patchFlag & 64 /* PatchFlags.STABLE_FRAGMENT */))) {
  7497. // fast path for block nodes: only need to unmount dynamic children.
  7498. unmountChildren(dynamicChildren, parentComponent, parentSuspense, false, true);
  7499. }
  7500. else if ((type === Fragment &&
  7501. patchFlag &
  7502. (128 /* PatchFlags.KEYED_FRAGMENT */ | 256 /* PatchFlags.UNKEYED_FRAGMENT */)) ||
  7503. (!optimized && shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */)) {
  7504. unmountChildren(children, parentComponent, parentSuspense);
  7505. }
  7506. if (doRemove) {
  7507. remove(vnode);
  7508. }
  7509. }
  7510. if ((shouldInvokeVnodeHook &&
  7511. (vnodeHook = props && props.onVnodeUnmounted)) ||
  7512. shouldInvokeDirs) {
  7513. queuePostRenderEffect(() => {
  7514. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, vnode);
  7515. shouldInvokeDirs &&
  7516. invokeDirectiveHook(vnode, null, parentComponent, 'unmounted');
  7517. }, parentSuspense);
  7518. }
  7519. };
  7520. const remove = vnode => {
  7521. const { type, el, anchor, transition } = vnode;
  7522. if (type === Fragment) {
  7523. if ((process.env.NODE_ENV !== 'production') &&
  7524. vnode.patchFlag > 0 &&
  7525. vnode.patchFlag & 2048 /* PatchFlags.DEV_ROOT_FRAGMENT */ &&
  7526. transition &&
  7527. !transition.persisted) {
  7528. vnode.children.forEach(child => {
  7529. if (child.type === Comment) {
  7530. hostRemove(child.el);
  7531. }
  7532. else {
  7533. remove(child);
  7534. }
  7535. });
  7536. }
  7537. else {
  7538. removeFragment(el, anchor);
  7539. }
  7540. return;
  7541. }
  7542. if (type === Static) {
  7543. removeStaticNode(vnode);
  7544. return;
  7545. }
  7546. const performRemove = () => {
  7547. hostRemove(el);
  7548. if (transition && !transition.persisted && transition.afterLeave) {
  7549. transition.afterLeave();
  7550. }
  7551. };
  7552. if (vnode.shapeFlag & 1 /* ShapeFlags.ELEMENT */ &&
  7553. transition &&
  7554. !transition.persisted) {
  7555. const { leave, delayLeave } = transition;
  7556. const performLeave = () => leave(el, performRemove);
  7557. if (delayLeave) {
  7558. delayLeave(vnode.el, performRemove, performLeave);
  7559. }
  7560. else {
  7561. performLeave();
  7562. }
  7563. }
  7564. else {
  7565. performRemove();
  7566. }
  7567. };
  7568. const removeFragment = (cur, end) => {
  7569. // For fragments, directly remove all contained DOM nodes.
  7570. // (fragment child nodes cannot have transition)
  7571. let next;
  7572. while (cur !== end) {
  7573. next = hostNextSibling(cur);
  7574. hostRemove(cur);
  7575. cur = next;
  7576. }
  7577. hostRemove(end);
  7578. };
  7579. const unmountComponent = (instance, parentSuspense, doRemove) => {
  7580. if ((process.env.NODE_ENV !== 'production') && instance.type.__hmrId) {
  7581. unregisterHMR(instance);
  7582. }
  7583. const { bum, scope, update, subTree, um } = instance;
  7584. // beforeUnmount hook
  7585. if (bum) {
  7586. invokeArrayFns(bum);
  7587. }
  7588. // stop effects in component scope
  7589. scope.stop();
  7590. // update may be null if a component is unmounted before its async
  7591. // setup has resolved.
  7592. if (update) {
  7593. // so that scheduler will no longer invoke it
  7594. update.active = false;
  7595. unmount(subTree, instance, parentSuspense, doRemove);
  7596. }
  7597. // unmounted hook
  7598. if (um) {
  7599. queuePostRenderEffect(um, parentSuspense);
  7600. }
  7601. queuePostRenderEffect(() => {
  7602. instance.isUnmounted = true;
  7603. }, parentSuspense);
  7604. // A component with async dep inside a pending suspense is unmounted before
  7605. // its async dep resolves. This should remove the dep from the suspense, and
  7606. // cause the suspense to resolve immediately if that was the last dep.
  7607. if (parentSuspense &&
  7608. parentSuspense.pendingBranch &&
  7609. !parentSuspense.isUnmounted &&
  7610. instance.asyncDep &&
  7611. !instance.asyncResolved &&
  7612. instance.suspenseId === parentSuspense.pendingId) {
  7613. parentSuspense.deps--;
  7614. if (parentSuspense.deps === 0) {
  7615. parentSuspense.resolve();
  7616. }
  7617. }
  7618. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  7619. devtoolsComponentRemoved(instance);
  7620. }
  7621. };
  7622. const unmountChildren = (children, parentComponent, parentSuspense, doRemove = false, optimized = false, start = 0) => {
  7623. for (let i = start; i < children.length; i++) {
  7624. unmount(children[i], parentComponent, parentSuspense, doRemove, optimized);
  7625. }
  7626. };
  7627. const getNextHostNode = vnode => {
  7628. if (vnode.shapeFlag & 6 /* ShapeFlags.COMPONENT */) {
  7629. return getNextHostNode(vnode.component.subTree);
  7630. }
  7631. if (vnode.shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
  7632. return vnode.suspense.next();
  7633. }
  7634. return hostNextSibling((vnode.anchor || vnode.el));
  7635. };
  7636. const render = (vnode, container, isSVG) => {
  7637. if (vnode == null) {
  7638. if (container._vnode) {
  7639. unmount(container._vnode, null, null, true);
  7640. }
  7641. }
  7642. else {
  7643. patch(container._vnode || null, vnode, container, null, null, null, isSVG);
  7644. }
  7645. flushPreFlushCbs();
  7646. flushPostFlushCbs();
  7647. container._vnode = vnode;
  7648. };
  7649. const internals = {
  7650. p: patch,
  7651. um: unmount,
  7652. m: move,
  7653. r: remove,
  7654. mt: mountComponent,
  7655. mc: mountChildren,
  7656. pc: patchChildren,
  7657. pbc: patchBlockChildren,
  7658. n: getNextHostNode,
  7659. o: options
  7660. };
  7661. let hydrate;
  7662. let hydrateNode;
  7663. if (createHydrationFns) {
  7664. [hydrate, hydrateNode] = createHydrationFns(internals);
  7665. }
  7666. return {
  7667. render,
  7668. hydrate,
  7669. createApp: createAppAPI(render, hydrate)
  7670. };
  7671. }
  7672. function toggleRecurse({ effect, update }, allowed) {
  7673. effect.allowRecurse = update.allowRecurse = allowed;
  7674. }
  7675. /**
  7676. * #1156
  7677. * When a component is HMR-enabled, we need to make sure that all static nodes
  7678. * inside a block also inherit the DOM element from the previous tree so that
  7679. * HMR updates (which are full updates) can retrieve the element for patching.
  7680. *
  7681. * #2080
  7682. * Inside keyed `template` fragment static children, if a fragment is moved,
  7683. * the children will always be moved. Therefore, in order to ensure correct move
  7684. * position, el should be inherited from previous nodes.
  7685. */
  7686. function traverseStaticChildren(n1, n2, shallow = false) {
  7687. const ch1 = n1.children;
  7688. const ch2 = n2.children;
  7689. if (isArray(ch1) && isArray(ch2)) {
  7690. for (let i = 0; i < ch1.length; i++) {
  7691. // this is only called in the optimized path so array children are
  7692. // guaranteed to be vnodes
  7693. const c1 = ch1[i];
  7694. let c2 = ch2[i];
  7695. if (c2.shapeFlag & 1 /* ShapeFlags.ELEMENT */ && !c2.dynamicChildren) {
  7696. if (c2.patchFlag <= 0 || c2.patchFlag === 32 /* PatchFlags.HYDRATE_EVENTS */) {
  7697. c2 = ch2[i] = cloneIfMounted(ch2[i]);
  7698. c2.el = c1.el;
  7699. }
  7700. if (!shallow)
  7701. traverseStaticChildren(c1, c2);
  7702. }
  7703. // #6852 also inherit for text nodes
  7704. if (c2.type === Text) {
  7705. c2.el = c1.el;
  7706. }
  7707. // also inherit for comment nodes, but not placeholders (e.g. v-if which
  7708. // would have received .el during block patch)
  7709. if ((process.env.NODE_ENV !== 'production') && c2.type === Comment && !c2.el) {
  7710. c2.el = c1.el;
  7711. }
  7712. }
  7713. }
  7714. }
  7715. // https://en.wikipedia.org/wiki/Longest_increasing_subsequence
  7716. function getSequence(arr) {
  7717. const p = arr.slice();
  7718. const result = [0];
  7719. let i, j, u, v, c;
  7720. const len = arr.length;
  7721. for (i = 0; i < len; i++) {
  7722. const arrI = arr[i];
  7723. if (arrI !== 0) {
  7724. j = result[result.length - 1];
  7725. if (arr[j] < arrI) {
  7726. p[i] = j;
  7727. result.push(i);
  7728. continue;
  7729. }
  7730. u = 0;
  7731. v = result.length - 1;
  7732. while (u < v) {
  7733. c = (u + v) >> 1;
  7734. if (arr[result[c]] < arrI) {
  7735. u = c + 1;
  7736. }
  7737. else {
  7738. v = c;
  7739. }
  7740. }
  7741. if (arrI < arr[result[u]]) {
  7742. if (u > 0) {
  7743. p[i] = result[u - 1];
  7744. }
  7745. result[u] = i;
  7746. }
  7747. }
  7748. }
  7749. u = result.length;
  7750. v = result[u - 1];
  7751. while (u-- > 0) {
  7752. result[u] = v;
  7753. v = p[v];
  7754. }
  7755. return result;
  7756. }
  7757. const isTeleport = (type) => type.__isTeleport;
  7758. const isTeleportDisabled = (props) => props && (props.disabled || props.disabled === '');
  7759. const isTargetSVG = (target) => typeof SVGElement !== 'undefined' && target instanceof SVGElement;
  7760. const resolveTarget = (props, select) => {
  7761. const targetSelector = props && props.to;
  7762. if (isString(targetSelector)) {
  7763. if (!select) {
  7764. (process.env.NODE_ENV !== 'production') &&
  7765. warn(`Current renderer does not support string target for Teleports. ` +
  7766. `(missing querySelector renderer option)`);
  7767. return null;
  7768. }
  7769. else {
  7770. const target = select(targetSelector);
  7771. if (!target) {
  7772. (process.env.NODE_ENV !== 'production') &&
  7773. warn(`Failed to locate Teleport target with selector "${targetSelector}". ` +
  7774. `Note the target element must exist before the component is mounted - ` +
  7775. `i.e. the target cannot be rendered by the component itself, and ` +
  7776. `ideally should be outside of the entire Vue component tree.`);
  7777. }
  7778. return target;
  7779. }
  7780. }
  7781. else {
  7782. if ((process.env.NODE_ENV !== 'production') && !targetSelector && !isTeleportDisabled(props)) {
  7783. warn(`Invalid Teleport target: ${targetSelector}`);
  7784. }
  7785. return targetSelector;
  7786. }
  7787. };
  7788. const TeleportImpl = {
  7789. __isTeleport: true,
  7790. process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, internals) {
  7791. const { mc: mountChildren, pc: patchChildren, pbc: patchBlockChildren, o: { insert, querySelector, createText, createComment } } = internals;
  7792. const disabled = isTeleportDisabled(n2.props);
  7793. let { shapeFlag, children, dynamicChildren } = n2;
  7794. // #3302
  7795. // HMR updated, force full diff
  7796. if ((process.env.NODE_ENV !== 'production') && isHmrUpdating) {
  7797. optimized = false;
  7798. dynamicChildren = null;
  7799. }
  7800. if (n1 == null) {
  7801. // insert anchors in the main view
  7802. const placeholder = (n2.el = (process.env.NODE_ENV !== 'production')
  7803. ? createComment('teleport start')
  7804. : createText(''));
  7805. const mainAnchor = (n2.anchor = (process.env.NODE_ENV !== 'production')
  7806. ? createComment('teleport end')
  7807. : createText(''));
  7808. insert(placeholder, container, anchor);
  7809. insert(mainAnchor, container, anchor);
  7810. const target = (n2.target = resolveTarget(n2.props, querySelector));
  7811. const targetAnchor = (n2.targetAnchor = createText(''));
  7812. if (target) {
  7813. insert(targetAnchor, target);
  7814. // #2652 we could be teleporting from a non-SVG tree into an SVG tree
  7815. isSVG = isSVG || isTargetSVG(target);
  7816. }
  7817. else if ((process.env.NODE_ENV !== 'production') && !disabled) {
  7818. warn('Invalid Teleport target on mount:', target, `(${typeof target})`);
  7819. }
  7820. const mount = (container, anchor) => {
  7821. // Teleport *always* has Array children. This is enforced in both the
  7822. // compiler and vnode children normalization.
  7823. if (shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  7824. mountChildren(children, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7825. }
  7826. };
  7827. if (disabled) {
  7828. mount(container, mainAnchor);
  7829. }
  7830. else if (target) {
  7831. mount(target, targetAnchor);
  7832. }
  7833. }
  7834. else {
  7835. // update content
  7836. n2.el = n1.el;
  7837. const mainAnchor = (n2.anchor = n1.anchor);
  7838. const target = (n2.target = n1.target);
  7839. const targetAnchor = (n2.targetAnchor = n1.targetAnchor);
  7840. const wasDisabled = isTeleportDisabled(n1.props);
  7841. const currentContainer = wasDisabled ? container : target;
  7842. const currentAnchor = wasDisabled ? mainAnchor : targetAnchor;
  7843. isSVG = isSVG || isTargetSVG(target);
  7844. if (dynamicChildren) {
  7845. // fast path when the teleport happens to be a block root
  7846. patchBlockChildren(n1.dynamicChildren, dynamicChildren, currentContainer, parentComponent, parentSuspense, isSVG, slotScopeIds);
  7847. // even in block tree mode we need to make sure all root-level nodes
  7848. // in the teleport inherit previous DOM references so that they can
  7849. // be moved in future patches.
  7850. traverseStaticChildren(n1, n2, true);
  7851. }
  7852. else if (!optimized) {
  7853. patchChildren(n1, n2, currentContainer, currentAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, false);
  7854. }
  7855. if (disabled) {
  7856. if (!wasDisabled) {
  7857. // enabled -> disabled
  7858. // move into main container
  7859. moveTeleport(n2, container, mainAnchor, internals, 1 /* TeleportMoveTypes.TOGGLE */);
  7860. }
  7861. }
  7862. else {
  7863. // target changed
  7864. if ((n2.props && n2.props.to) !== (n1.props && n1.props.to)) {
  7865. const nextTarget = (n2.target = resolveTarget(n2.props, querySelector));
  7866. if (nextTarget) {
  7867. moveTeleport(n2, nextTarget, null, internals, 0 /* TeleportMoveTypes.TARGET_CHANGE */);
  7868. }
  7869. else if ((process.env.NODE_ENV !== 'production')) {
  7870. warn('Invalid Teleport target on update:', target, `(${typeof target})`);
  7871. }
  7872. }
  7873. else if (wasDisabled) {
  7874. // disabled -> enabled
  7875. // move into teleport target
  7876. moveTeleport(n2, target, targetAnchor, internals, 1 /* TeleportMoveTypes.TOGGLE */);
  7877. }
  7878. }
  7879. }
  7880. updateCssVars(n2);
  7881. },
  7882. remove(vnode, parentComponent, parentSuspense, optimized, { um: unmount, o: { remove: hostRemove } }, doRemove) {
  7883. const { shapeFlag, children, anchor, targetAnchor, target, props } = vnode;
  7884. if (target) {
  7885. hostRemove(targetAnchor);
  7886. }
  7887. // an unmounted teleport should always remove its children if not disabled
  7888. if (doRemove || !isTeleportDisabled(props)) {
  7889. hostRemove(anchor);
  7890. if (shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  7891. for (let i = 0; i < children.length; i++) {
  7892. const child = children[i];
  7893. unmount(child, parentComponent, parentSuspense, true, !!child.dynamicChildren);
  7894. }
  7895. }
  7896. }
  7897. },
  7898. move: moveTeleport,
  7899. hydrate: hydrateTeleport
  7900. };
  7901. function moveTeleport(vnode, container, parentAnchor, { o: { insert }, m: move }, moveType = 2 /* TeleportMoveTypes.REORDER */) {
  7902. // move target anchor if this is a target change.
  7903. if (moveType === 0 /* TeleportMoveTypes.TARGET_CHANGE */) {
  7904. insert(vnode.targetAnchor, container, parentAnchor);
  7905. }
  7906. const { el, anchor, shapeFlag, children, props } = vnode;
  7907. const isReorder = moveType === 2 /* TeleportMoveTypes.REORDER */;
  7908. // move main view anchor if this is a re-order.
  7909. if (isReorder) {
  7910. insert(el, container, parentAnchor);
  7911. }
  7912. // if this is a re-order and teleport is enabled (content is in target)
  7913. // do not move children. So the opposite is: only move children if this
  7914. // is not a reorder, or the teleport is disabled
  7915. if (!isReorder || isTeleportDisabled(props)) {
  7916. // Teleport has either Array children or no children.
  7917. if (shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  7918. for (let i = 0; i < children.length; i++) {
  7919. move(children[i], container, parentAnchor, 2 /* MoveType.REORDER */);
  7920. }
  7921. }
  7922. }
  7923. // move main view anchor if this is a re-order.
  7924. if (isReorder) {
  7925. insert(anchor, container, parentAnchor);
  7926. }
  7927. }
  7928. function hydrateTeleport(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized, { o: { nextSibling, parentNode, querySelector } }, hydrateChildren) {
  7929. const target = (vnode.target = resolveTarget(vnode.props, querySelector));
  7930. if (target) {
  7931. // if multiple teleports rendered to the same target element, we need to
  7932. // pick up from where the last teleport finished instead of the first node
  7933. const targetNode = target._lpa || target.firstChild;
  7934. if (vnode.shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  7935. if (isTeleportDisabled(vnode.props)) {
  7936. vnode.anchor = hydrateChildren(nextSibling(node), vnode, parentNode(node), parentComponent, parentSuspense, slotScopeIds, optimized);
  7937. vnode.targetAnchor = targetNode;
  7938. }
  7939. else {
  7940. vnode.anchor = nextSibling(node);
  7941. // lookahead until we find the target anchor
  7942. // we cannot rely on return value of hydrateChildren() because there
  7943. // could be nested teleports
  7944. let targetAnchor = targetNode;
  7945. while (targetAnchor) {
  7946. targetAnchor = nextSibling(targetAnchor);
  7947. if (targetAnchor &&
  7948. targetAnchor.nodeType === 8 &&
  7949. targetAnchor.data === 'teleport anchor') {
  7950. vnode.targetAnchor = targetAnchor;
  7951. target._lpa =
  7952. vnode.targetAnchor && nextSibling(vnode.targetAnchor);
  7953. break;
  7954. }
  7955. }
  7956. hydrateChildren(targetNode, vnode, target, parentComponent, parentSuspense, slotScopeIds, optimized);
  7957. }
  7958. }
  7959. updateCssVars(vnode);
  7960. }
  7961. return vnode.anchor && nextSibling(vnode.anchor);
  7962. }
  7963. // Force-casted public typing for h and TSX props inference
  7964. const Teleport = TeleportImpl;
  7965. function updateCssVars(vnode) {
  7966. // presence of .ut method indicates owner component uses css vars.
  7967. // code path here can assume browser environment.
  7968. const ctx = vnode.ctx;
  7969. if (ctx && ctx.ut) {
  7970. let node = vnode.children[0].el;
  7971. while (node !== vnode.targetAnchor) {
  7972. if (node.nodeType === 1)
  7973. node.setAttribute('data-v-owner', ctx.uid);
  7974. node = node.nextSibling;
  7975. }
  7976. ctx.ut();
  7977. }
  7978. }
  7979. const Fragment = Symbol((process.env.NODE_ENV !== 'production') ? 'Fragment' : undefined);
  7980. const Text = Symbol((process.env.NODE_ENV !== 'production') ? 'Text' : undefined);
  7981. const Comment = Symbol((process.env.NODE_ENV !== 'production') ? 'Comment' : undefined);
  7982. const Static = Symbol((process.env.NODE_ENV !== 'production') ? 'Static' : undefined);
  7983. // Since v-if and v-for are the two possible ways node structure can dynamically
  7984. // change, once we consider v-if branches and each v-for fragment a block, we
  7985. // can divide a template into nested blocks, and within each block the node
  7986. // structure would be stable. This allows us to skip most children diffing
  7987. // and only worry about the dynamic nodes (indicated by patch flags).
  7988. const blockStack = [];
  7989. let currentBlock = null;
  7990. /**
  7991. * Open a block.
  7992. * This must be called before `createBlock`. It cannot be part of `createBlock`
  7993. * because the children of the block are evaluated before `createBlock` itself
  7994. * is called. The generated code typically looks like this:
  7995. *
  7996. * ```js
  7997. * function render() {
  7998. * return (openBlock(),createBlock('div', null, [...]))
  7999. * }
  8000. * ```
  8001. * disableTracking is true when creating a v-for fragment block, since a v-for
  8002. * fragment always diffs its children.
  8003. *
  8004. * @private
  8005. */
  8006. function openBlock(disableTracking = false) {
  8007. blockStack.push((currentBlock = disableTracking ? null : []));
  8008. }
  8009. function closeBlock() {
  8010. blockStack.pop();
  8011. currentBlock = blockStack[blockStack.length - 1] || null;
  8012. }
  8013. // Whether we should be tracking dynamic child nodes inside a block.
  8014. // Only tracks when this value is > 0
  8015. // We are not using a simple boolean because this value may need to be
  8016. // incremented/decremented by nested usage of v-once (see below)
  8017. let isBlockTreeEnabled = 1;
  8018. /**
  8019. * Block tracking sometimes needs to be disabled, for example during the
  8020. * creation of a tree that needs to be cached by v-once. The compiler generates
  8021. * code like this:
  8022. *
  8023. * ``` js
  8024. * _cache[1] || (
  8025. * setBlockTracking(-1),
  8026. * _cache[1] = createVNode(...),
  8027. * setBlockTracking(1),
  8028. * _cache[1]
  8029. * )
  8030. * ```
  8031. *
  8032. * @private
  8033. */
  8034. function setBlockTracking(value) {
  8035. isBlockTreeEnabled += value;
  8036. }
  8037. function setupBlock(vnode) {
  8038. // save current block children on the block vnode
  8039. vnode.dynamicChildren =
  8040. isBlockTreeEnabled > 0 ? currentBlock || EMPTY_ARR : null;
  8041. // close block
  8042. closeBlock();
  8043. // a block is always going to be patched, so track it as a child of its
  8044. // parent block
  8045. if (isBlockTreeEnabled > 0 && currentBlock) {
  8046. currentBlock.push(vnode);
  8047. }
  8048. return vnode;
  8049. }
  8050. /**
  8051. * @private
  8052. */
  8053. function createElementBlock(type, props, children, patchFlag, dynamicProps, shapeFlag) {
  8054. return setupBlock(createBaseVNode(type, props, children, patchFlag, dynamicProps, shapeFlag, true /* isBlock */));
  8055. }
  8056. /**
  8057. * Create a block root vnode. Takes the same exact arguments as `createVNode`.
  8058. * A block root keeps track of dynamic nodes within the block in the
  8059. * `dynamicChildren` array.
  8060. *
  8061. * @private
  8062. */
  8063. function createBlock(type, props, children, patchFlag, dynamicProps) {
  8064. return setupBlock(createVNode(type, props, children, patchFlag, dynamicProps, true /* isBlock: prevent a block from tracking itself */));
  8065. }
  8066. function isVNode(value) {
  8067. return value ? value.__v_isVNode === true : false;
  8068. }
  8069. function isSameVNodeType(n1, n2) {
  8070. if ((process.env.NODE_ENV !== 'production') &&
  8071. n2.shapeFlag & 6 /* ShapeFlags.COMPONENT */ &&
  8072. hmrDirtyComponents.has(n2.type)) {
  8073. // #7042, ensure the vnode being unmounted during HMR
  8074. // bitwise operations to remove keep alive flags
  8075. n1.shapeFlag &= ~256 /* ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE */;
  8076. n2.shapeFlag &= ~512 /* ShapeFlags.COMPONENT_KEPT_ALIVE */;
  8077. // HMR only: if the component has been hot-updated, force a reload.
  8078. return false;
  8079. }
  8080. return n1.type === n2.type && n1.key === n2.key;
  8081. }
  8082. let vnodeArgsTransformer;
  8083. /**
  8084. * Internal API for registering an arguments transform for createVNode
  8085. * used for creating stubs in the test-utils
  8086. * It is *internal* but needs to be exposed for test-utils to pick up proper
  8087. * typings
  8088. */
  8089. function transformVNodeArgs(transformer) {
  8090. vnodeArgsTransformer = transformer;
  8091. }
  8092. const createVNodeWithArgsTransform = (...args) => {
  8093. return _createVNode(...(vnodeArgsTransformer
  8094. ? vnodeArgsTransformer(args, currentRenderingInstance)
  8095. : args));
  8096. };
  8097. const InternalObjectKey = `__vInternal`;
  8098. const normalizeKey = ({ key }) => key != null ? key : null;
  8099. const normalizeRef = ({ ref, ref_key, ref_for }) => {
  8100. return (ref != null
  8101. ? isString(ref) || isRef(ref) || isFunction(ref)
  8102. ? { i: currentRenderingInstance, r: ref, k: ref_key, f: !!ref_for }
  8103. : ref
  8104. : null);
  8105. };
  8106. function createBaseVNode(type, props = null, children = null, patchFlag = 0, dynamicProps = null, shapeFlag = type === Fragment ? 0 : 1 /* ShapeFlags.ELEMENT */, isBlockNode = false, needFullChildrenNormalization = false) {
  8107. const vnode = {
  8108. __v_isVNode: true,
  8109. __v_skip: true,
  8110. type,
  8111. props,
  8112. key: props && normalizeKey(props),
  8113. ref: props && normalizeRef(props),
  8114. scopeId: currentScopeId,
  8115. slotScopeIds: null,
  8116. children,
  8117. component: null,
  8118. suspense: null,
  8119. ssContent: null,
  8120. ssFallback: null,
  8121. dirs: null,
  8122. transition: null,
  8123. el: null,
  8124. anchor: null,
  8125. target: null,
  8126. targetAnchor: null,
  8127. staticCount: 0,
  8128. shapeFlag,
  8129. patchFlag,
  8130. dynamicProps,
  8131. dynamicChildren: null,
  8132. appContext: null,
  8133. ctx: currentRenderingInstance
  8134. };
  8135. if (needFullChildrenNormalization) {
  8136. normalizeChildren(vnode, children);
  8137. // normalize suspense children
  8138. if (shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
  8139. type.normalize(vnode);
  8140. }
  8141. }
  8142. else if (children) {
  8143. // compiled element vnode - if children is passed, only possible types are
  8144. // string or Array.
  8145. vnode.shapeFlag |= isString(children)
  8146. ? 8 /* ShapeFlags.TEXT_CHILDREN */
  8147. : 16 /* ShapeFlags.ARRAY_CHILDREN */;
  8148. }
  8149. // validate key
  8150. if ((process.env.NODE_ENV !== 'production') && vnode.key !== vnode.key) {
  8151. warn(`VNode created with invalid key (NaN). VNode type:`, vnode.type);
  8152. }
  8153. // track vnode for block tree
  8154. if (isBlockTreeEnabled > 0 &&
  8155. // avoid a block node from tracking itself
  8156. !isBlockNode &&
  8157. // has current parent block
  8158. currentBlock &&
  8159. // presence of a patch flag indicates this node needs patching on updates.
  8160. // component nodes also should always be patched, because even if the
  8161. // component doesn't need to update, it needs to persist the instance on to
  8162. // the next vnode so that it can be properly unmounted later.
  8163. (vnode.patchFlag > 0 || shapeFlag & 6 /* ShapeFlags.COMPONENT */) &&
  8164. // the EVENTS flag is only for hydration and if it is the only flag, the
  8165. // vnode should not be considered dynamic due to handler caching.
  8166. vnode.patchFlag !== 32 /* PatchFlags.HYDRATE_EVENTS */) {
  8167. currentBlock.push(vnode);
  8168. }
  8169. return vnode;
  8170. }
  8171. const createVNode = ((process.env.NODE_ENV !== 'production') ? createVNodeWithArgsTransform : _createVNode);
  8172. function _createVNode(type, props = null, children = null, patchFlag = 0, dynamicProps = null, isBlockNode = false) {
  8173. if (!type || type === NULL_DYNAMIC_COMPONENT) {
  8174. if ((process.env.NODE_ENV !== 'production') && !type) {
  8175. warn(`Invalid vnode type when creating vnode: ${type}.`);
  8176. }
  8177. type = Comment;
  8178. }
  8179. if (isVNode(type)) {
  8180. // createVNode receiving an existing vnode. This happens in cases like
  8181. // <component :is="vnode"/>
  8182. // #2078 make sure to merge refs during the clone instead of overwriting it
  8183. const cloned = cloneVNode(type, props, true /* mergeRef: true */);
  8184. if (children) {
  8185. normalizeChildren(cloned, children);
  8186. }
  8187. if (isBlockTreeEnabled > 0 && !isBlockNode && currentBlock) {
  8188. if (cloned.shapeFlag & 6 /* ShapeFlags.COMPONENT */) {
  8189. currentBlock[currentBlock.indexOf(type)] = cloned;
  8190. }
  8191. else {
  8192. currentBlock.push(cloned);
  8193. }
  8194. }
  8195. cloned.patchFlag |= -2 /* PatchFlags.BAIL */;
  8196. return cloned;
  8197. }
  8198. // class component normalization.
  8199. if (isClassComponent(type)) {
  8200. type = type.__vccOpts;
  8201. }
  8202. // class & style normalization.
  8203. if (props) {
  8204. // for reactive or proxy objects, we need to clone it to enable mutation.
  8205. props = guardReactiveProps(props);
  8206. let { class: klass, style } = props;
  8207. if (klass && !isString(klass)) {
  8208. props.class = normalizeClass(klass);
  8209. }
  8210. if (isObject(style)) {
  8211. // reactive state objects need to be cloned since they are likely to be
  8212. // mutated
  8213. if (isProxy(style) && !isArray(style)) {
  8214. style = extend({}, style);
  8215. }
  8216. props.style = normalizeStyle(style);
  8217. }
  8218. }
  8219. // encode the vnode type information into a bitmap
  8220. const shapeFlag = isString(type)
  8221. ? 1 /* ShapeFlags.ELEMENT */
  8222. : isSuspense(type)
  8223. ? 128 /* ShapeFlags.SUSPENSE */
  8224. : isTeleport(type)
  8225. ? 64 /* ShapeFlags.TELEPORT */
  8226. : isObject(type)
  8227. ? 4 /* ShapeFlags.STATEFUL_COMPONENT */
  8228. : isFunction(type)
  8229. ? 2 /* ShapeFlags.FUNCTIONAL_COMPONENT */
  8230. : 0;
  8231. if ((process.env.NODE_ENV !== 'production') && shapeFlag & 4 /* ShapeFlags.STATEFUL_COMPONENT */ && isProxy(type)) {
  8232. type = toRaw(type);
  8233. warn(`Vue received a Component which was made a reactive object. This can ` +
  8234. `lead to unnecessary performance overhead, and should be avoided by ` +
  8235. `marking the component with \`markRaw\` or using \`shallowRef\` ` +
  8236. `instead of \`ref\`.`, `\nComponent that was made reactive: `, type);
  8237. }
  8238. return createBaseVNode(type, props, children, patchFlag, dynamicProps, shapeFlag, isBlockNode, true);
  8239. }
  8240. function guardReactiveProps(props) {
  8241. if (!props)
  8242. return null;
  8243. return isProxy(props) || InternalObjectKey in props
  8244. ? extend({}, props)
  8245. : props;
  8246. }
  8247. function cloneVNode(vnode, extraProps, mergeRef = false) {
  8248. // This is intentionally NOT using spread or extend to avoid the runtime
  8249. // key enumeration cost.
  8250. const { props, ref, patchFlag, children } = vnode;
  8251. const mergedProps = extraProps ? mergeProps(props || {}, extraProps) : props;
  8252. const cloned = {
  8253. __v_isVNode: true,
  8254. __v_skip: true,
  8255. type: vnode.type,
  8256. props: mergedProps,
  8257. key: mergedProps && normalizeKey(mergedProps),
  8258. ref: extraProps && extraProps.ref
  8259. ? // #2078 in the case of <component :is="vnode" ref="extra"/>
  8260. // if the vnode itself already has a ref, cloneVNode will need to merge
  8261. // the refs so the single vnode can be set on multiple refs
  8262. mergeRef && ref
  8263. ? isArray(ref)
  8264. ? ref.concat(normalizeRef(extraProps))
  8265. : [ref, normalizeRef(extraProps)]
  8266. : normalizeRef(extraProps)
  8267. : ref,
  8268. scopeId: vnode.scopeId,
  8269. slotScopeIds: vnode.slotScopeIds,
  8270. children: (process.env.NODE_ENV !== 'production') && patchFlag === -1 /* PatchFlags.HOISTED */ && isArray(children)
  8271. ? children.map(deepCloneVNode)
  8272. : children,
  8273. target: vnode.target,
  8274. targetAnchor: vnode.targetAnchor,
  8275. staticCount: vnode.staticCount,
  8276. shapeFlag: vnode.shapeFlag,
  8277. // if the vnode is cloned with extra props, we can no longer assume its
  8278. // existing patch flag to be reliable and need to add the FULL_PROPS flag.
  8279. // note: preserve flag for fragments since they use the flag for children
  8280. // fast paths only.
  8281. patchFlag: extraProps && vnode.type !== Fragment
  8282. ? patchFlag === -1 // hoisted node
  8283. ? 16 /* PatchFlags.FULL_PROPS */
  8284. : patchFlag | 16 /* PatchFlags.FULL_PROPS */
  8285. : patchFlag,
  8286. dynamicProps: vnode.dynamicProps,
  8287. dynamicChildren: vnode.dynamicChildren,
  8288. appContext: vnode.appContext,
  8289. dirs: vnode.dirs,
  8290. transition: vnode.transition,
  8291. // These should technically only be non-null on mounted VNodes. However,
  8292. // they *should* be copied for kept-alive vnodes. So we just always copy
  8293. // them since them being non-null during a mount doesn't affect the logic as
  8294. // they will simply be overwritten.
  8295. component: vnode.component,
  8296. suspense: vnode.suspense,
  8297. ssContent: vnode.ssContent && cloneVNode(vnode.ssContent),
  8298. ssFallback: vnode.ssFallback && cloneVNode(vnode.ssFallback),
  8299. el: vnode.el,
  8300. anchor: vnode.anchor,
  8301. ctx: vnode.ctx,
  8302. ce: vnode.ce
  8303. };
  8304. return cloned;
  8305. }
  8306. /**
  8307. * Dev only, for HMR of hoisted vnodes reused in v-for
  8308. * https://github.com/vitejs/vite/issues/2022
  8309. */
  8310. function deepCloneVNode(vnode) {
  8311. const cloned = cloneVNode(vnode);
  8312. if (isArray(vnode.children)) {
  8313. cloned.children = vnode.children.map(deepCloneVNode);
  8314. }
  8315. return cloned;
  8316. }
  8317. /**
  8318. * @private
  8319. */
  8320. function createTextVNode(text = ' ', flag = 0) {
  8321. return createVNode(Text, null, text, flag);
  8322. }
  8323. /**
  8324. * @private
  8325. */
  8326. function createStaticVNode(content, numberOfNodes) {
  8327. // A static vnode can contain multiple stringified elements, and the number
  8328. // of elements is necessary for hydration.
  8329. const vnode = createVNode(Static, null, content);
  8330. vnode.staticCount = numberOfNodes;
  8331. return vnode;
  8332. }
  8333. /**
  8334. * @private
  8335. */
  8336. function createCommentVNode(text = '',
  8337. // when used as the v-else branch, the comment node must be created as a
  8338. // block to ensure correct updates.
  8339. asBlock = false) {
  8340. return asBlock
  8341. ? (openBlock(), createBlock(Comment, null, text))
  8342. : createVNode(Comment, null, text);
  8343. }
  8344. function normalizeVNode(child) {
  8345. if (child == null || typeof child === 'boolean') {
  8346. // empty placeholder
  8347. return createVNode(Comment);
  8348. }
  8349. else if (isArray(child)) {
  8350. // fragment
  8351. return createVNode(Fragment, null,
  8352. // #3666, avoid reference pollution when reusing vnode
  8353. child.slice());
  8354. }
  8355. else if (typeof child === 'object') {
  8356. // already vnode, this should be the most common since compiled templates
  8357. // always produce all-vnode children arrays
  8358. return cloneIfMounted(child);
  8359. }
  8360. else {
  8361. // strings and numbers
  8362. return createVNode(Text, null, String(child));
  8363. }
  8364. }
  8365. // optimized normalization for template-compiled render fns
  8366. function cloneIfMounted(child) {
  8367. return (child.el === null && child.patchFlag !== -1 /* PatchFlags.HOISTED */) ||
  8368. child.memo
  8369. ? child
  8370. : cloneVNode(child);
  8371. }
  8372. function normalizeChildren(vnode, children) {
  8373. let type = 0;
  8374. const { shapeFlag } = vnode;
  8375. if (children == null) {
  8376. children = null;
  8377. }
  8378. else if (isArray(children)) {
  8379. type = 16 /* ShapeFlags.ARRAY_CHILDREN */;
  8380. }
  8381. else if (typeof children === 'object') {
  8382. if (shapeFlag & (1 /* ShapeFlags.ELEMENT */ | 64 /* ShapeFlags.TELEPORT */)) {
  8383. // Normalize slot to plain children for plain element and Teleport
  8384. const slot = children.default;
  8385. if (slot) {
  8386. // _c marker is added by withCtx() indicating this is a compiled slot
  8387. slot._c && (slot._d = false);
  8388. normalizeChildren(vnode, slot());
  8389. slot._c && (slot._d = true);
  8390. }
  8391. return;
  8392. }
  8393. else {
  8394. type = 32 /* ShapeFlags.SLOTS_CHILDREN */;
  8395. const slotFlag = children._;
  8396. if (!slotFlag && !(InternalObjectKey in children)) {
  8397. children._ctx = currentRenderingInstance;
  8398. }
  8399. else if (slotFlag === 3 /* SlotFlags.FORWARDED */ && currentRenderingInstance) {
  8400. // a child component receives forwarded slots from the parent.
  8401. // its slot type is determined by its parent's slot type.
  8402. if (currentRenderingInstance.slots._ === 1 /* SlotFlags.STABLE */) {
  8403. children._ = 1 /* SlotFlags.STABLE */;
  8404. }
  8405. else {
  8406. children._ = 2 /* SlotFlags.DYNAMIC */;
  8407. vnode.patchFlag |= 1024 /* PatchFlags.DYNAMIC_SLOTS */;
  8408. }
  8409. }
  8410. }
  8411. }
  8412. else if (isFunction(children)) {
  8413. children = { default: children, _ctx: currentRenderingInstance };
  8414. type = 32 /* ShapeFlags.SLOTS_CHILDREN */;
  8415. }
  8416. else {
  8417. children = String(children);
  8418. // force teleport children to array so it can be moved around
  8419. if (shapeFlag & 64 /* ShapeFlags.TELEPORT */) {
  8420. type = 16 /* ShapeFlags.ARRAY_CHILDREN */;
  8421. children = [createTextVNode(children)];
  8422. }
  8423. else {
  8424. type = 8 /* ShapeFlags.TEXT_CHILDREN */;
  8425. }
  8426. }
  8427. vnode.children = children;
  8428. vnode.shapeFlag |= type;
  8429. }
  8430. function mergeProps(...args) {
  8431. const ret = {};
  8432. for (let i = 0; i < args.length; i++) {
  8433. const toMerge = args[i];
  8434. for (const key in toMerge) {
  8435. if (key === 'class') {
  8436. if (ret.class !== toMerge.class) {
  8437. ret.class = normalizeClass([ret.class, toMerge.class]);
  8438. }
  8439. }
  8440. else if (key === 'style') {
  8441. ret.style = normalizeStyle([ret.style, toMerge.style]);
  8442. }
  8443. else if (isOn(key)) {
  8444. const existing = ret[key];
  8445. const incoming = toMerge[key];
  8446. if (incoming &&
  8447. existing !== incoming &&
  8448. !(isArray(existing) && existing.includes(incoming))) {
  8449. ret[key] = existing
  8450. ? [].concat(existing, incoming)
  8451. : incoming;
  8452. }
  8453. }
  8454. else if (key !== '') {
  8455. ret[key] = toMerge[key];
  8456. }
  8457. }
  8458. }
  8459. return ret;
  8460. }
  8461. function invokeVNodeHook(hook, instance, vnode, prevVNode = null) {
  8462. callWithAsyncErrorHandling(hook, instance, 7 /* ErrorCodes.VNODE_HOOK */, [
  8463. vnode,
  8464. prevVNode
  8465. ]);
  8466. }
  8467. const emptyAppContext = createAppContext();
  8468. let uid = 0;
  8469. function createComponentInstance(vnode, parent, suspense) {
  8470. const type = vnode.type;
  8471. // inherit parent app context - or - if root, adopt from root vnode
  8472. const appContext = (parent ? parent.appContext : vnode.appContext) || emptyAppContext;
  8473. const instance = {
  8474. uid: uid++,
  8475. vnode,
  8476. type,
  8477. parent,
  8478. appContext,
  8479. root: null,
  8480. next: null,
  8481. subTree: null,
  8482. effect: null,
  8483. update: null,
  8484. scope: new EffectScope(true /* detached */),
  8485. render: null,
  8486. proxy: null,
  8487. exposed: null,
  8488. exposeProxy: null,
  8489. withProxy: null,
  8490. provides: parent ? parent.provides : Object.create(appContext.provides),
  8491. accessCache: null,
  8492. renderCache: [],
  8493. // local resolved assets
  8494. components: null,
  8495. directives: null,
  8496. // resolved props and emits options
  8497. propsOptions: normalizePropsOptions(type, appContext),
  8498. emitsOptions: normalizeEmitsOptions(type, appContext),
  8499. // emit
  8500. emit: null,
  8501. emitted: null,
  8502. // props default value
  8503. propsDefaults: EMPTY_OBJ,
  8504. // inheritAttrs
  8505. inheritAttrs: type.inheritAttrs,
  8506. // state
  8507. ctx: EMPTY_OBJ,
  8508. data: EMPTY_OBJ,
  8509. props: EMPTY_OBJ,
  8510. attrs: EMPTY_OBJ,
  8511. slots: EMPTY_OBJ,
  8512. refs: EMPTY_OBJ,
  8513. setupState: EMPTY_OBJ,
  8514. setupContext: null,
  8515. // suspense related
  8516. suspense,
  8517. suspenseId: suspense ? suspense.pendingId : 0,
  8518. asyncDep: null,
  8519. asyncResolved: false,
  8520. // lifecycle hooks
  8521. // not using enums here because it results in computed properties
  8522. isMounted: false,
  8523. isUnmounted: false,
  8524. isDeactivated: false,
  8525. bc: null,
  8526. c: null,
  8527. bm: null,
  8528. m: null,
  8529. bu: null,
  8530. u: null,
  8531. um: null,
  8532. bum: null,
  8533. bda: null,
  8534. da: null,
  8535. ba: null,
  8536. a: null,
  8537. rtg: null,
  8538. rtc: null,
  8539. ec: null,
  8540. sp: null
  8541. };
  8542. if ((process.env.NODE_ENV !== 'production')) {
  8543. instance.ctx = createDevRenderContext(instance);
  8544. }
  8545. else {
  8546. instance.ctx = { _: instance };
  8547. }
  8548. instance.root = parent ? parent.root : instance;
  8549. instance.emit = emit.bind(null, instance);
  8550. instance.$pageInstance = parent && parent.$pageInstance;
  8551. // apply custom element special handling
  8552. if (vnode.ce) {
  8553. vnode.ce(instance);
  8554. }
  8555. return instance;
  8556. }
  8557. let currentInstance = null;
  8558. const getCurrentInstance = () => currentInstance || currentRenderingInstance;
  8559. const setCurrentInstance = (instance) => {
  8560. currentInstance = instance;
  8561. instance.scope.on();
  8562. };
  8563. const unsetCurrentInstance = () => {
  8564. currentInstance && currentInstance.scope.off();
  8565. currentInstance = null;
  8566. };
  8567. const isBuiltInTag = /*#__PURE__*/ makeMap('slot,component');
  8568. function validateComponentName(name, config) {
  8569. const appIsNativeTag = config.isNativeTag || NO;
  8570. if (isBuiltInTag(name) || appIsNativeTag(name)) {
  8571. warn('Do not use built-in or reserved HTML elements as component id: ' + name);
  8572. }
  8573. }
  8574. function isStatefulComponent(instance) {
  8575. return instance.vnode.shapeFlag & 4 /* ShapeFlags.STATEFUL_COMPONENT */;
  8576. }
  8577. let isInSSRComponentSetup = false;
  8578. function setupComponent(instance, isSSR = false) {
  8579. isInSSRComponentSetup = isSSR;
  8580. const { props, children } = instance.vnode;
  8581. const isStateful = isStatefulComponent(instance);
  8582. initProps(instance, props, isStateful, isSSR);
  8583. initSlots(instance, children);
  8584. const setupResult = isStateful
  8585. ? setupStatefulComponent(instance, isSSR)
  8586. : undefined;
  8587. isInSSRComponentSetup = false;
  8588. return setupResult;
  8589. }
  8590. function setupStatefulComponent(instance, isSSR) {
  8591. var _a;
  8592. const Component = instance.type;
  8593. if ((process.env.NODE_ENV !== 'production')) {
  8594. if (Component.name) {
  8595. validateComponentName(Component.name, instance.appContext.config);
  8596. }
  8597. if (Component.components) {
  8598. const names = Object.keys(Component.components);
  8599. for (let i = 0; i < names.length; i++) {
  8600. validateComponentName(names[i], instance.appContext.config);
  8601. }
  8602. }
  8603. if (Component.directives) {
  8604. const names = Object.keys(Component.directives);
  8605. for (let i = 0; i < names.length; i++) {
  8606. validateDirectiveName(names[i]);
  8607. }
  8608. }
  8609. if (Component.compilerOptions && isRuntimeOnly()) {
  8610. warn(`"compilerOptions" is only supported when using a build of Vue that ` +
  8611. `includes the runtime compiler. Since you are using a runtime-only ` +
  8612. `build, the options should be passed via your build tool config instead.`);
  8613. }
  8614. }
  8615. // 0. create render proxy property access cache
  8616. instance.accessCache = Object.create(null);
  8617. // 1. create public instance / render proxy
  8618. // also mark it raw so it's never observed
  8619. instance.proxy = markRaw(new Proxy(instance.ctx, PublicInstanceProxyHandlers));
  8620. if ((process.env.NODE_ENV !== 'production')) {
  8621. exposePropsOnRenderContext(instance);
  8622. }
  8623. // 2. call setup()
  8624. const { setup } = Component;
  8625. if (setup) {
  8626. const setupContext = (instance.setupContext =
  8627. setup.length > 1 ? createSetupContext(instance) : null);
  8628. setCurrentInstance(instance);
  8629. pauseTracking();
  8630. const setupResult = callWithErrorHandling(setup, instance, 0 /* ErrorCodes.SETUP_FUNCTION */, [(process.env.NODE_ENV !== 'production') ? shallowReadonly(instance.props) : instance.props, setupContext]);
  8631. resetTracking();
  8632. unsetCurrentInstance();
  8633. if (isPromise(setupResult)) {
  8634. setupResult.then(unsetCurrentInstance, unsetCurrentInstance);
  8635. if (isSSR) {
  8636. // return the promise so server-renderer can wait on it
  8637. return setupResult
  8638. .then((resolvedResult) => {
  8639. handleSetupResult(instance, resolvedResult, isSSR);
  8640. })
  8641. .catch(e => {
  8642. handleError(e, instance, 0 /* ErrorCodes.SETUP_FUNCTION */);
  8643. });
  8644. }
  8645. else {
  8646. // async setup returned Promise.
  8647. // bail here and wait for re-entry.
  8648. instance.asyncDep = setupResult;
  8649. if ((process.env.NODE_ENV !== 'production') && !instance.suspense) {
  8650. const name = (_a = Component.name) !== null && _a !== void 0 ? _a : 'Anonymous';
  8651. warn(`Component <${name}>: setup function returned a promise, but no ` +
  8652. `<Suspense> boundary was found in the parent component tree. ` +
  8653. `A component with async setup() must be nested in a <Suspense> ` +
  8654. `in order to be rendered.`);
  8655. }
  8656. }
  8657. }
  8658. else {
  8659. handleSetupResult(instance, setupResult, isSSR);
  8660. }
  8661. }
  8662. else {
  8663. finishComponentSetup(instance, isSSR);
  8664. }
  8665. }
  8666. function handleSetupResult(instance, setupResult, isSSR) {
  8667. if (isFunction(setupResult)) {
  8668. // setup returned an inline render function
  8669. if (instance.type.__ssrInlineRender) {
  8670. // when the function's name is `ssrRender` (compiled by SFC inline mode),
  8671. // set it as ssrRender instead.
  8672. instance.ssrRender = setupResult;
  8673. }
  8674. else {
  8675. instance.render = setupResult;
  8676. }
  8677. }
  8678. else if (isObject(setupResult)) {
  8679. if ((process.env.NODE_ENV !== 'production') && isVNode(setupResult)) {
  8680. warn(`setup() should not return VNodes directly - ` +
  8681. `return a render function instead.`);
  8682. }
  8683. // setup returned bindings.
  8684. // assuming a render function compiled from template is present.
  8685. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  8686. instance.devtoolsRawSetupState = setupResult;
  8687. }
  8688. instance.setupState = proxyRefs(setupResult);
  8689. if ((process.env.NODE_ENV !== 'production')) {
  8690. exposeSetupStateOnRenderContext(instance);
  8691. }
  8692. }
  8693. else if ((process.env.NODE_ENV !== 'production') && setupResult !== undefined) {
  8694. warn(`setup() should return an object. Received: ${setupResult === null ? 'null' : typeof setupResult}`);
  8695. }
  8696. finishComponentSetup(instance, isSSR);
  8697. }
  8698. let compile$1;
  8699. let installWithProxy;
  8700. /**
  8701. * For runtime-dom to register the compiler.
  8702. * Note the exported method uses any to avoid d.ts relying on the compiler types.
  8703. */
  8704. function registerRuntimeCompiler(_compile) {
  8705. compile$1 = _compile;
  8706. installWithProxy = i => {
  8707. if (i.render._rc) {
  8708. i.withProxy = new Proxy(i.ctx, RuntimeCompiledPublicInstanceProxyHandlers);
  8709. }
  8710. };
  8711. }
  8712. // dev only
  8713. const isRuntimeOnly = () => !compile$1;
  8714. function finishComponentSetup(instance, isSSR, skipOptions) {
  8715. const Component = instance.type;
  8716. // template / render function normalization
  8717. // could be already set when returned from setup()
  8718. if (!instance.render) {
  8719. // only do on-the-fly compile if not in SSR - SSR on-the-fly compilation
  8720. // is done by server-renderer
  8721. if (!isSSR && compile$1 && !Component.render) {
  8722. const template = Component.template ||
  8723. resolveMergedOptions(instance).template;
  8724. if (template) {
  8725. if ((process.env.NODE_ENV !== 'production')) {
  8726. startMeasure(instance, `compile`);
  8727. }
  8728. const { isCustomElement, compilerOptions } = instance.appContext.config;
  8729. const { delimiters, compilerOptions: componentCompilerOptions } = Component;
  8730. const finalCompilerOptions = extend(extend({
  8731. isCustomElement,
  8732. delimiters
  8733. }, compilerOptions), componentCompilerOptions);
  8734. Component.render = compile$1(template, finalCompilerOptions);
  8735. if ((process.env.NODE_ENV !== 'production')) {
  8736. endMeasure(instance, `compile`);
  8737. }
  8738. }
  8739. }
  8740. instance.render = (Component.render || NOOP);
  8741. // for runtime-compiled render functions using `with` blocks, the render
  8742. // proxy used needs a different `has` handler which is more performant and
  8743. // also only allows a whitelist of globals to fallthrough.
  8744. if (installWithProxy) {
  8745. installWithProxy(instance);
  8746. }
  8747. }
  8748. // support for 2.x options
  8749. if (__VUE_OPTIONS_API__ && !(false )) {
  8750. setCurrentInstance(instance);
  8751. pauseTracking();
  8752. applyOptions(instance);
  8753. resetTracking();
  8754. unsetCurrentInstance();
  8755. }
  8756. // warn missing template/render
  8757. // the runtime compilation of template in SSR is done by server-render
  8758. if ((process.env.NODE_ENV !== 'production') && !Component.render && instance.render === NOOP && !isSSR) {
  8759. /* istanbul ignore if */
  8760. if (!compile$1 && Component.template) {
  8761. warn(`Component provided template option but ` +
  8762. `runtime compilation is not supported in this build of Vue.` +
  8763. (` Configure your bundler to alias "vue" to "vue/dist/vue.esm-bundler.js".`
  8764. ) /* should not happen */);
  8765. }
  8766. else {
  8767. warn(`Component is missing template or render function.`);
  8768. }
  8769. }
  8770. }
  8771. function createAttrsProxy(instance) {
  8772. return new Proxy(instance.attrs, (process.env.NODE_ENV !== 'production')
  8773. ? {
  8774. get(target, key) {
  8775. markAttrsAccessed();
  8776. track(instance, "get" /* TrackOpTypes.GET */, '$attrs');
  8777. return target[key];
  8778. },
  8779. set() {
  8780. warn(`setupContext.attrs is readonly.`);
  8781. return false;
  8782. },
  8783. deleteProperty() {
  8784. warn(`setupContext.attrs is readonly.`);
  8785. return false;
  8786. }
  8787. }
  8788. : {
  8789. get(target, key) {
  8790. track(instance, "get" /* TrackOpTypes.GET */, '$attrs');
  8791. return target[key];
  8792. }
  8793. });
  8794. }
  8795. function createSetupContext(instance) {
  8796. const expose = exposed => {
  8797. if ((process.env.NODE_ENV !== 'production')) {
  8798. if (instance.exposed) {
  8799. warn(`expose() should be called only once per setup().`);
  8800. }
  8801. if (exposed != null) {
  8802. let exposedType = typeof exposed;
  8803. if (exposedType === 'object') {
  8804. if (isArray(exposed)) {
  8805. exposedType = 'array';
  8806. }
  8807. else if (isRef(exposed)) {
  8808. exposedType = 'ref';
  8809. }
  8810. }
  8811. if (exposedType !== 'object') {
  8812. warn(`expose() should be passed a plain object, received ${exposedType}.`);
  8813. }
  8814. }
  8815. }
  8816. instance.exposed = exposed || {};
  8817. };
  8818. let attrs;
  8819. if ((process.env.NODE_ENV !== 'production')) {
  8820. // We use getters in dev in case libs like test-utils overwrite instance
  8821. // properties (overwrites should not be done in prod)
  8822. return Object.freeze({
  8823. get attrs() {
  8824. return attrs || (attrs = createAttrsProxy(instance));
  8825. },
  8826. get slots() {
  8827. return shallowReadonly(instance.slots);
  8828. },
  8829. get emit() {
  8830. return (event, ...args) => instance.emit(event, ...args);
  8831. },
  8832. expose
  8833. });
  8834. }
  8835. else {
  8836. return {
  8837. get attrs() {
  8838. return attrs || (attrs = createAttrsProxy(instance));
  8839. },
  8840. slots: instance.slots,
  8841. emit: instance.emit,
  8842. expose
  8843. };
  8844. }
  8845. }
  8846. function getExposeProxy(instance) {
  8847. if (instance.exposed) {
  8848. return (instance.exposeProxy ||
  8849. (instance.exposeProxy = new Proxy(proxyRefs(markRaw(instance.exposed)), {
  8850. get(target, key) {
  8851. if (key in target) {
  8852. return target[key];
  8853. }
  8854. else if (key in publicPropertiesMap) {
  8855. return publicPropertiesMap[key](instance);
  8856. }
  8857. },
  8858. has(target, key) {
  8859. return key in target || key in publicPropertiesMap;
  8860. }
  8861. })));
  8862. }
  8863. }
  8864. const classifyRE = /(?:^|[-_])(\w)/g;
  8865. const classify = (str) => str.replace(classifyRE, c => c.toUpperCase()).replace(/[-_]/g, '');
  8866. function getComponentName(Component, includeInferred = true) {
  8867. return isFunction(Component)
  8868. ? Component.displayName || Component.name
  8869. : Component.name || (includeInferred && Component.__name);
  8870. }
  8871. /* istanbul ignore next */
  8872. function formatComponentName(instance, Component, isRoot = false) {
  8873. let name = getComponentName(Component);
  8874. if (!name && Component.__file) {
  8875. const match = Component.__file.match(/([^/\\]+)\.\w+$/);
  8876. if (match) {
  8877. name = match[1];
  8878. }
  8879. }
  8880. if (!name && instance && instance.parent) {
  8881. // try to infer the name based on reverse resolution
  8882. const inferFromRegistry = (registry) => {
  8883. for (const key in registry) {
  8884. if (registry[key] === Component) {
  8885. return key;
  8886. }
  8887. }
  8888. };
  8889. name =
  8890. inferFromRegistry(instance.components ||
  8891. instance.parent.type.components) || inferFromRegistry(instance.appContext.components);
  8892. }
  8893. return name ? classify(name) : isRoot ? `App` : `Anonymous`;
  8894. }
  8895. function isClassComponent(value) {
  8896. return isFunction(value) && '__vccOpts' in value;
  8897. }
  8898. const computed = ((getterOrOptions, debugOptions) => {
  8899. // @ts-ignore
  8900. return computed$1(getterOrOptions, debugOptions, isInSSRComponentSetup);
  8901. });
  8902. // dev only
  8903. const warnRuntimeUsage = (method) => warn(`${method}() is a compiler-hint helper that is only usable inside ` +
  8904. `<script setup> of a single file component. Its arguments should be ` +
  8905. `compiled away and passing it at runtime has no effect.`);
  8906. // implementation
  8907. function defineProps() {
  8908. if ((process.env.NODE_ENV !== 'production')) {
  8909. warnRuntimeUsage(`defineProps`);
  8910. }
  8911. return null;
  8912. }
  8913. // implementation
  8914. function defineEmits() {
  8915. if ((process.env.NODE_ENV !== 'production')) {
  8916. warnRuntimeUsage(`defineEmits`);
  8917. }
  8918. return null;
  8919. }
  8920. /**
  8921. * Vue `<script setup>` compiler macro for declaring a component's exposed
  8922. * instance properties when it is accessed by a parent component via template
  8923. * refs.
  8924. *
  8925. * `<script setup>` components are closed by default - i.e. variables inside
  8926. * the `<script setup>` scope is not exposed to parent unless explicitly exposed
  8927. * via `defineExpose`.
  8928. *
  8929. * This is only usable inside `<script setup>`, is compiled away in the
  8930. * output and should **not** be actually called at runtime.
  8931. */
  8932. function defineExpose(exposed) {
  8933. if ((process.env.NODE_ENV !== 'production')) {
  8934. warnRuntimeUsage(`defineExpose`);
  8935. }
  8936. }
  8937. /**
  8938. * Vue `<script setup>` compiler macro for providing props default values when
  8939. * using type-based `defineProps` declaration.
  8940. *
  8941. * Example usage:
  8942. * ```ts
  8943. * withDefaults(defineProps<{
  8944. * size?: number
  8945. * labels?: string[]
  8946. * }>(), {
  8947. * size: 3,
  8948. * labels: () => ['default label']
  8949. * })
  8950. * ```
  8951. *
  8952. * This is only usable inside `<script setup>`, is compiled away in the output
  8953. * and should **not** be actually called at runtime.
  8954. */
  8955. function withDefaults(props, defaults) {
  8956. if ((process.env.NODE_ENV !== 'production')) {
  8957. warnRuntimeUsage(`withDefaults`);
  8958. }
  8959. return null;
  8960. }
  8961. function useSlots() {
  8962. return getContext().slots;
  8963. }
  8964. function useAttrs() {
  8965. return getContext().attrs;
  8966. }
  8967. function getContext() {
  8968. const i = getCurrentInstance();
  8969. if ((process.env.NODE_ENV !== 'production') && !i) {
  8970. warn(`useContext() called without active instance.`);
  8971. }
  8972. return i.setupContext || (i.setupContext = createSetupContext(i));
  8973. }
  8974. /**
  8975. * Runtime helper for merging default declarations. Imported by compiled code
  8976. * only.
  8977. * @internal
  8978. */
  8979. function mergeDefaults(raw, defaults) {
  8980. const props = isArray(raw)
  8981. ? raw.reduce((normalized, p) => ((normalized[p] = {}), normalized), {})
  8982. : raw;
  8983. for (const key in defaults) {
  8984. const opt = props[key];
  8985. if (opt) {
  8986. if (isArray(opt) || isFunction(opt)) {
  8987. props[key] = { type: opt, default: defaults[key] };
  8988. }
  8989. else {
  8990. opt.default = defaults[key];
  8991. }
  8992. }
  8993. else if (opt === null) {
  8994. props[key] = { default: defaults[key] };
  8995. }
  8996. else if ((process.env.NODE_ENV !== 'production')) {
  8997. warn(`props default key "${key}" has no corresponding declaration.`);
  8998. }
  8999. }
  9000. return props;
  9001. }
  9002. /**
  9003. * Used to create a proxy for the rest element when destructuring props with
  9004. * defineProps().
  9005. * @internal
  9006. */
  9007. function createPropsRestProxy(props, excludedKeys) {
  9008. const ret = {};
  9009. for (const key in props) {
  9010. if (!excludedKeys.includes(key)) {
  9011. Object.defineProperty(ret, key, {
  9012. enumerable: true,
  9013. get: () => props[key]
  9014. });
  9015. }
  9016. }
  9017. return ret;
  9018. }
  9019. /**
  9020. * `<script setup>` helper for persisting the current instance context over
  9021. * async/await flows.
  9022. *
  9023. * `@vue/compiler-sfc` converts the following:
  9024. *
  9025. * ```ts
  9026. * const x = await foo()
  9027. * ```
  9028. *
  9029. * into:
  9030. *
  9031. * ```ts
  9032. * let __temp, __restore
  9033. * const x = (([__temp, __restore] = withAsyncContext(() => foo())),__temp=await __temp,__restore(),__temp)
  9034. * ```
  9035. * @internal
  9036. */
  9037. function withAsyncContext(getAwaitable) {
  9038. const ctx = getCurrentInstance();
  9039. if ((process.env.NODE_ENV !== 'production') && !ctx) {
  9040. warn(`withAsyncContext called without active current instance. ` +
  9041. `This is likely a bug.`);
  9042. }
  9043. let awaitable = getAwaitable();
  9044. unsetCurrentInstance();
  9045. if (isPromise(awaitable)) {
  9046. awaitable = awaitable.catch(e => {
  9047. setCurrentInstance(ctx);
  9048. throw e;
  9049. });
  9050. }
  9051. return [awaitable, () => setCurrentInstance(ctx)];
  9052. }
  9053. // Actual implementation
  9054. function h(type, propsOrChildren, children) {
  9055. const l = arguments.length;
  9056. if (l === 2) {
  9057. if (isObject(propsOrChildren) && !isArray(propsOrChildren)) {
  9058. // single vnode without props
  9059. if (isVNode(propsOrChildren)) {
  9060. return createVNode(type, null, [propsOrChildren]);
  9061. }
  9062. // props without children
  9063. return createVNode(type, propsOrChildren);
  9064. }
  9065. else {
  9066. // omit props
  9067. return createVNode(type, null, propsOrChildren);
  9068. }
  9069. }
  9070. else {
  9071. if (l > 3) {
  9072. children = Array.prototype.slice.call(arguments, 2);
  9073. }
  9074. else if (l === 3 && isVNode(children)) {
  9075. children = [children];
  9076. }
  9077. return createVNode(type, propsOrChildren, children);
  9078. }
  9079. }
  9080. const ssrContextKey = Symbol((process.env.NODE_ENV !== 'production') ? `ssrContext` : ``);
  9081. const useSSRContext = () => {
  9082. {
  9083. const ctx = inject(ssrContextKey);
  9084. if (!ctx) {
  9085. (process.env.NODE_ENV !== 'production') &&
  9086. warn(`Server rendering context not provided. Make sure to only call ` +
  9087. `useSSRContext() conditionally in the server build.`);
  9088. }
  9089. return ctx;
  9090. }
  9091. };
  9092. function initCustomFormatter() {
  9093. /* eslint-disable no-restricted-globals */
  9094. if (!(process.env.NODE_ENV !== 'production') || typeof window === 'undefined') {
  9095. return;
  9096. }
  9097. const vueStyle = { style: 'color:#3ba776' };
  9098. const numberStyle = { style: 'color:#0b1bc9' };
  9099. const stringStyle = { style: 'color:#b62e24' };
  9100. const keywordStyle = { style: 'color:#9d288c' };
  9101. // custom formatter for Chrome
  9102. // https://www.mattzeunert.com/2016/02/19/custom-chrome-devtools-object-formatters.html
  9103. const formatter = {
  9104. header(obj) {
  9105. // TODO also format ComponentPublicInstance & ctx.slots/attrs in setup
  9106. if (!isObject(obj)) {
  9107. return null;
  9108. }
  9109. if (obj.__isVue) {
  9110. return ['div', vueStyle, `VueInstance`];
  9111. }
  9112. else if (isRef(obj)) {
  9113. return [
  9114. 'div',
  9115. {},
  9116. ['span', vueStyle, genRefFlag(obj)],
  9117. '<',
  9118. formatValue(obj.value),
  9119. `>`
  9120. ];
  9121. }
  9122. else if (isReactive(obj)) {
  9123. return [
  9124. 'div',
  9125. {},
  9126. ['span', vueStyle, isShallow(obj) ? 'ShallowReactive' : 'Reactive'],
  9127. '<',
  9128. formatValue(obj),
  9129. `>${isReadonly(obj) ? ` (readonly)` : ``}`
  9130. ];
  9131. }
  9132. else if (isReadonly(obj)) {
  9133. return [
  9134. 'div',
  9135. {},
  9136. ['span', vueStyle, isShallow(obj) ? 'ShallowReadonly' : 'Readonly'],
  9137. '<',
  9138. formatValue(obj),
  9139. '>'
  9140. ];
  9141. }
  9142. return null;
  9143. },
  9144. hasBody(obj) {
  9145. return obj && obj.__isVue;
  9146. },
  9147. body(obj) {
  9148. if (obj && obj.__isVue) {
  9149. return [
  9150. 'div',
  9151. {},
  9152. ...formatInstance(obj.$)
  9153. ];
  9154. }
  9155. }
  9156. };
  9157. function formatInstance(instance) {
  9158. const blocks = [];
  9159. if (instance.type.props && instance.props) {
  9160. blocks.push(createInstanceBlock('props', toRaw(instance.props)));
  9161. }
  9162. if (instance.setupState !== EMPTY_OBJ) {
  9163. blocks.push(createInstanceBlock('setup', instance.setupState));
  9164. }
  9165. if (instance.data !== EMPTY_OBJ) {
  9166. blocks.push(createInstanceBlock('data', toRaw(instance.data)));
  9167. }
  9168. const computed = extractKeys(instance, 'computed');
  9169. if (computed) {
  9170. blocks.push(createInstanceBlock('computed', computed));
  9171. }
  9172. const injected = extractKeys(instance, 'inject');
  9173. if (injected) {
  9174. blocks.push(createInstanceBlock('injected', injected));
  9175. }
  9176. blocks.push([
  9177. 'div',
  9178. {},
  9179. [
  9180. 'span',
  9181. {
  9182. style: keywordStyle.style + ';opacity:0.66'
  9183. },
  9184. '$ (internal): '
  9185. ],
  9186. ['object', { object: instance }]
  9187. ]);
  9188. return blocks;
  9189. }
  9190. function createInstanceBlock(type, target) {
  9191. target = extend({}, target);
  9192. if (!Object.keys(target).length) {
  9193. return ['span', {}];
  9194. }
  9195. return [
  9196. 'div',
  9197. { style: 'line-height:1.25em;margin-bottom:0.6em' },
  9198. [
  9199. 'div',
  9200. {
  9201. style: 'color:#476582'
  9202. },
  9203. type
  9204. ],
  9205. [
  9206. 'div',
  9207. {
  9208. style: 'padding-left:1.25em'
  9209. },
  9210. ...Object.keys(target).map(key => {
  9211. return [
  9212. 'div',
  9213. {},
  9214. ['span', keywordStyle, key + ': '],
  9215. formatValue(target[key], false)
  9216. ];
  9217. })
  9218. ]
  9219. ];
  9220. }
  9221. function formatValue(v, asRaw = true) {
  9222. if (typeof v === 'number') {
  9223. return ['span', numberStyle, v];
  9224. }
  9225. else if (typeof v === 'string') {
  9226. return ['span', stringStyle, JSON.stringify(v)];
  9227. }
  9228. else if (typeof v === 'boolean') {
  9229. return ['span', keywordStyle, v];
  9230. }
  9231. else if (isObject(v)) {
  9232. return ['object', { object: asRaw ? toRaw(v) : v }];
  9233. }
  9234. else {
  9235. return ['span', stringStyle, String(v)];
  9236. }
  9237. }
  9238. function extractKeys(instance, type) {
  9239. const Comp = instance.type;
  9240. if (isFunction(Comp)) {
  9241. return;
  9242. }
  9243. const extracted = {};
  9244. for (const key in instance.ctx) {
  9245. if (isKeyOfType(Comp, key, type)) {
  9246. extracted[key] = instance.ctx[key];
  9247. }
  9248. }
  9249. return extracted;
  9250. }
  9251. function isKeyOfType(Comp, key, type) {
  9252. const opts = Comp[type];
  9253. if ((isArray(opts) && opts.includes(key)) ||
  9254. (isObject(opts) && key in opts)) {
  9255. return true;
  9256. }
  9257. if (Comp.extends && isKeyOfType(Comp.extends, key, type)) {
  9258. return true;
  9259. }
  9260. if (Comp.mixins && Comp.mixins.some(m => isKeyOfType(m, key, type))) {
  9261. return true;
  9262. }
  9263. }
  9264. function genRefFlag(v) {
  9265. if (isShallow(v)) {
  9266. return `ShallowRef`;
  9267. }
  9268. if (v.effect) {
  9269. return `ComputedRef`;
  9270. }
  9271. return `Ref`;
  9272. }
  9273. if (window.devtoolsFormatters) {
  9274. window.devtoolsFormatters.push(formatter);
  9275. }
  9276. else {
  9277. window.devtoolsFormatters = [formatter];
  9278. }
  9279. }
  9280. function withMemo(memo, render, cache, index) {
  9281. const cached = cache[index];
  9282. if (cached && isMemoSame(cached, memo)) {
  9283. return cached;
  9284. }
  9285. const ret = render();
  9286. // shallow clone
  9287. ret.memo = memo.slice();
  9288. return (cache[index] = ret);
  9289. }
  9290. function isMemoSame(cached, memo) {
  9291. const prev = cached.memo;
  9292. if (prev.length != memo.length) {
  9293. return false;
  9294. }
  9295. for (let i = 0; i < prev.length; i++) {
  9296. if (hasChanged(prev[i], memo[i])) {
  9297. return false;
  9298. }
  9299. }
  9300. // make sure to let parent block track it when returning cached
  9301. if (isBlockTreeEnabled > 0 && currentBlock) {
  9302. currentBlock.push(cached);
  9303. }
  9304. return true;
  9305. }
  9306. // Core API ------------------------------------------------------------------
  9307. const version = "3.2.47";
  9308. const _ssrUtils = {
  9309. createComponentInstance,
  9310. setupComponent,
  9311. renderComponentRoot,
  9312. setCurrentRenderingInstance,
  9313. isVNode,
  9314. normalizeVNode
  9315. };
  9316. /**
  9317. * SSR utils for \@vue/server-renderer. Only exposed in ssr-possible builds.
  9318. * @internal
  9319. */
  9320. const ssrUtils = (_ssrUtils );
  9321. /**
  9322. * @internal only exposed in compat builds
  9323. */
  9324. const resolveFilter = null;
  9325. /**
  9326. * @internal only exposed in compat builds.
  9327. */
  9328. const compatUtils = (null);
  9329. const svgNS = 'http://www.w3.org/2000/svg';
  9330. const doc = (typeof document !== 'undefined' ? document : null);
  9331. const templateContainer = doc && /*#__PURE__*/ doc.createElement('template');
  9332. const nodeOps = {
  9333. insert: (child, parent, anchor) => {
  9334. parent.insertBefore(child, anchor || null);
  9335. },
  9336. remove: child => {
  9337. const parent = child.parentNode;
  9338. if (parent) {
  9339. parent.removeChild(child);
  9340. }
  9341. },
  9342. createElement: (tag, isSVG, is, props) => {
  9343. /**
  9344. * fix chrome version 64
  9345. * document.createElement('uni-text', undefined) instanceof customElements.get('uni-text') // false
  9346. * document.createElement('uni-text') instanceof customElements.get('uni-text') // true
  9347. */
  9348. const el = isSVG
  9349. ? doc.createElementNS(svgNS, tag)
  9350. : is
  9351. ? doc.createElement(tag, { is })
  9352. : doc.createElement(tag);
  9353. if (tag === 'select' && props && props.multiple != null) {
  9354. el.setAttribute('multiple', props.multiple);
  9355. }
  9356. return el;
  9357. },
  9358. createText: text => doc.createTextNode(text),
  9359. createComment: text => doc.createComment(text),
  9360. setText: (node, text) => {
  9361. node.nodeValue = text;
  9362. },
  9363. setElementText: (el, text) => {
  9364. el.textContent = text;
  9365. },
  9366. parentNode: node => node.parentNode,
  9367. nextSibling: node => node.nextSibling,
  9368. querySelector: selector => doc.querySelector(selector),
  9369. setScopeId(el, id) {
  9370. el.setAttribute(id, '');
  9371. },
  9372. // __UNSAFE__
  9373. // Reason: innerHTML.
  9374. // Static content here can only come from compiled templates.
  9375. // As long as the user only uses trusted templates, this is safe.
  9376. insertStaticContent(content, parent, anchor, isSVG, start, end) {
  9377. // <parent> before | first ... last | anchor </parent>
  9378. const before = anchor ? anchor.previousSibling : parent.lastChild;
  9379. // #5308 can only take cached path if:
  9380. // - has a single root node
  9381. // - nextSibling info is still available
  9382. if (start && (start === end || start.nextSibling)) {
  9383. // cached
  9384. while (true) {
  9385. parent.insertBefore(start.cloneNode(true), anchor);
  9386. if (start === end || !(start = start.nextSibling))
  9387. break;
  9388. }
  9389. }
  9390. else {
  9391. // fresh insert
  9392. templateContainer.innerHTML = isSVG ? `<svg>${content}</svg>` : content;
  9393. const template = templateContainer.content;
  9394. if (isSVG) {
  9395. // remove outer svg wrapper
  9396. const wrapper = template.firstChild;
  9397. while (wrapper.firstChild) {
  9398. template.appendChild(wrapper.firstChild);
  9399. }
  9400. template.removeChild(wrapper);
  9401. }
  9402. parent.insertBefore(template, anchor);
  9403. }
  9404. return [
  9405. // first
  9406. before ? before.nextSibling : parent.firstChild,
  9407. // last
  9408. anchor ? anchor.previousSibling : parent.lastChild
  9409. ];
  9410. }
  9411. };
  9412. // compiler should normalize class + :class bindings on the same element
  9413. // into a single binding ['staticClass', dynamic]
  9414. function patchClass(el, value, isSVG) {
  9415. // directly setting className should be faster than setAttribute in theory
  9416. // if this is an element during a transition, take the temporary transition
  9417. // classes into account.
  9418. // fixed by xxxxxx wxs
  9419. const { __wxsAddClass, __wxsRemoveClass } = el;
  9420. if (__wxsRemoveClass && __wxsRemoveClass.length) {
  9421. value = (value || '')
  9422. .split(/\s+/)
  9423. .filter(v => __wxsRemoveClass.indexOf(v) === -1)
  9424. .join(' ');
  9425. __wxsRemoveClass.length = 0;
  9426. }
  9427. if (__wxsAddClass && __wxsAddClass.length) {
  9428. value = (value || '') + ' ' + __wxsAddClass.join(' ');
  9429. }
  9430. const transitionClasses = el._vtc;
  9431. if (transitionClasses) {
  9432. value = (value ? [value, ...transitionClasses] : [...transitionClasses]).join(' ');
  9433. }
  9434. if (value == null) {
  9435. el.removeAttribute('class');
  9436. }
  9437. else if (isSVG) {
  9438. el.setAttribute('class', value);
  9439. }
  9440. else {
  9441. el.className = value;
  9442. }
  9443. }
  9444. function patchStyle(el, prev, next) {
  9445. const style = el.style;
  9446. const isCssString = isString(next);
  9447. if (next && !isCssString) {
  9448. if (prev && !isString(prev)) {
  9449. for (const key in prev) {
  9450. if (next[key] == null) {
  9451. setStyle(style, key, '');
  9452. }
  9453. }
  9454. }
  9455. for (const key in next) {
  9456. setStyle(style, key, next[key]);
  9457. }
  9458. }
  9459. else {
  9460. const currentDisplay = style.display;
  9461. if (isCssString) {
  9462. if (prev !== next) {
  9463. style.cssText = next;
  9464. }
  9465. }
  9466. else if (prev) {
  9467. el.removeAttribute('style');
  9468. }
  9469. // indicates that the `display` of the element is controlled by `v-show`,
  9470. // so we always keep the current `display` value regardless of the `style`
  9471. // value, thus handing over control to `v-show`.
  9472. if ('_vod' in el) {
  9473. style.display = currentDisplay;
  9474. }
  9475. }
  9476. // fixed by xxxxxx
  9477. const { __wxsStyle } = el;
  9478. if (__wxsStyle) {
  9479. for (const key in __wxsStyle) {
  9480. setStyle(style, key, __wxsStyle[key]);
  9481. }
  9482. }
  9483. }
  9484. const semicolonRE = /[^\\];\s*$/;
  9485. const importantRE = /\s*!important$/;
  9486. function setStyle(style, name, val) {
  9487. if (isArray(val)) {
  9488. val.forEach(v => setStyle(style, name, v));
  9489. }
  9490. else {
  9491. if (val == null)
  9492. val = '';
  9493. // fixed by xxxxxx
  9494. val = normalizeRpx(val);
  9495. if ((process.env.NODE_ENV !== 'production')) {
  9496. if (semicolonRE.test(val)) {
  9497. warn(`Unexpected semicolon at the end of '${name}' style value: '${val}'`);
  9498. }
  9499. }
  9500. if (name.startsWith('--')) {
  9501. // custom property definition
  9502. style.setProperty(name, val);
  9503. }
  9504. else {
  9505. const prefixed = autoPrefix(style, name);
  9506. if (importantRE.test(val)) {
  9507. // !important
  9508. style.setProperty(hyphenate(prefixed), val.replace(importantRE, ''), 'important');
  9509. }
  9510. else {
  9511. style[prefixed] = val;
  9512. }
  9513. }
  9514. }
  9515. }
  9516. const prefixes = ['Webkit', 'Moz', 'ms'];
  9517. const prefixCache = {};
  9518. function autoPrefix(style, rawName) {
  9519. const cached = prefixCache[rawName];
  9520. if (cached) {
  9521. return cached;
  9522. }
  9523. let name = camelize(rawName);
  9524. if (name !== 'filter' && name in style) {
  9525. return (prefixCache[rawName] = name);
  9526. }
  9527. name = capitalize(name);
  9528. for (let i = 0; i < prefixes.length; i++) {
  9529. const prefixed = prefixes[i] + name;
  9530. if (prefixed in style) {
  9531. return (prefixCache[rawName] = prefixed);
  9532. }
  9533. }
  9534. return rawName;
  9535. }
  9536. // fixed by xxxxxx
  9537. // upx,rpx
  9538. const { unit, unitRatio, unitPrecision } = defaultRpx2Unit;
  9539. const rpx2Unit = createRpx2Unit(unit, unitRatio, unitPrecision);
  9540. const normalizeRpx = (val) => {
  9541. if (isString(val)) {
  9542. return rpx2Unit(val);
  9543. }
  9544. return val;
  9545. };
  9546. const xlinkNS = 'http://www.w3.org/1999/xlink';
  9547. function patchAttr(el, key, value, isSVG, instance) {
  9548. if (isSVG && key.startsWith('xlink:')) {
  9549. if (value == null) {
  9550. el.removeAttributeNS(xlinkNS, key.slice(6, key.length));
  9551. }
  9552. else {
  9553. el.setAttributeNS(xlinkNS, key, value);
  9554. }
  9555. }
  9556. else {
  9557. // note we are only checking boolean attributes that don't have a
  9558. // corresponding dom prop of the same name here.
  9559. const isBoolean = isSpecialBooleanAttr(key);
  9560. if (value == null || (isBoolean && !includeBooleanAttr(value))) {
  9561. el.removeAttribute(key);
  9562. }
  9563. else {
  9564. el.setAttribute(key, isBoolean ? '' : value);
  9565. }
  9566. }
  9567. }
  9568. // __UNSAFE__
  9569. // functions. The user is responsible for using them with only trusted content.
  9570. function patchDOMProp(el, key, value,
  9571. // the following args are passed only due to potential innerHTML/textContent
  9572. // overriding existing VNodes, in which case the old tree must be properly
  9573. // unmounted.
  9574. prevChildren, parentComponent, parentSuspense, unmountChildren) {
  9575. if (key === 'innerHTML' || key === 'textContent') {
  9576. if (prevChildren) {
  9577. unmountChildren(prevChildren, parentComponent, parentSuspense);
  9578. }
  9579. el[key] = value == null ? '' : value;
  9580. return;
  9581. }
  9582. if (key === 'value' &&
  9583. el.tagName !== 'PROGRESS' &&
  9584. // custom elements may use _value internally
  9585. !el.tagName.includes('-')) {
  9586. // store value as _value as well since
  9587. // non-string values will be stringified.
  9588. el._value = value;
  9589. const newValue = value == null ? '' : value;
  9590. if (el.value !== newValue ||
  9591. // #4956: always set for OPTION elements because its value falls back to
  9592. // textContent if no value attribute is present. And setting .value for
  9593. // OPTION has no side effect
  9594. el.tagName === 'OPTION') {
  9595. el.value = newValue;
  9596. }
  9597. if (value == null) {
  9598. el.removeAttribute(key);
  9599. }
  9600. return;
  9601. }
  9602. let needRemove = false;
  9603. if (value === '' || value == null) {
  9604. const type = typeof el[key];
  9605. if (type === 'boolean') {
  9606. // e.g. <select multiple> compiles to { multiple: '' }
  9607. value = includeBooleanAttr(value);
  9608. }
  9609. else if (value == null && type === 'string') {
  9610. // e.g. <div :id="null">
  9611. value = '';
  9612. needRemove = true;
  9613. }
  9614. else if (type === 'number') {
  9615. // e.g. <img :width="null">
  9616. value = 0;
  9617. needRemove = true;
  9618. }
  9619. }
  9620. // some properties perform value validation and throw,
  9621. // some properties has getter, no setter, will error in 'use strict'
  9622. // eg. <select :type="null"></select> <select :willValidate="null"></select>
  9623. try {
  9624. el[key] = value;
  9625. }
  9626. catch (e) {
  9627. // do not warn if value is auto-coerced from nullish values
  9628. if ((process.env.NODE_ENV !== 'production') && !needRemove) {
  9629. warn(`Failed setting prop "${key}" on <${el.tagName.toLowerCase()}>: ` +
  9630. `value ${value} is invalid.`, e);
  9631. }
  9632. }
  9633. needRemove && el.removeAttribute(key);
  9634. }
  9635. function addEventListener(el, event, handler, options) {
  9636. el.addEventListener(event, handler, options);
  9637. }
  9638. function removeEventListener(el, event, handler, options) {
  9639. el.removeEventListener(event, handler, options);
  9640. }
  9641. function patchEvent(el, rawName, prevValue, nextValue, instance = null) {
  9642. // vei = vue event invokers
  9643. const invokers = el._vei || (el._vei = {});
  9644. const existingInvoker = invokers[rawName];
  9645. if (nextValue && existingInvoker) {
  9646. // patch
  9647. existingInvoker.value = nextValue;
  9648. }
  9649. else {
  9650. const [name, options] = parseName(rawName);
  9651. if (nextValue) {
  9652. // add
  9653. const invoker = (invokers[rawName] = createInvoker(nextValue, instance));
  9654. addEventListener(el, name, invoker, options);
  9655. }
  9656. else if (existingInvoker) {
  9657. // remove
  9658. removeEventListener(el, name, existingInvoker, options);
  9659. invokers[rawName] = undefined;
  9660. }
  9661. }
  9662. }
  9663. const optionsModifierRE = /(?:Once|Passive|Capture)$/;
  9664. function parseName(name) {
  9665. let options;
  9666. if (optionsModifierRE.test(name)) {
  9667. options = {};
  9668. let m;
  9669. while ((m = name.match(optionsModifierRE))) {
  9670. name = name.slice(0, name.length - m[0].length);
  9671. options[m[0].toLowerCase()] = true;
  9672. }
  9673. }
  9674. const event = name[2] === ':' ? name.slice(3) : hyphenate(name.slice(2));
  9675. return [event, options];
  9676. }
  9677. // To avoid the overhead of repeatedly calling Date.now(), we cache
  9678. // and use the same timestamp for all event listeners attached in the same tick.
  9679. let cachedNow = 0;
  9680. const p = /*#__PURE__*/ Promise.resolve();
  9681. const getNow = () => cachedNow || (p.then(() => (cachedNow = 0)), (cachedNow = Date.now()));
  9682. function createInvoker(initialValue, instance) {
  9683. const invoker = (e) => {
  9684. // async edge case vuejs/vue#6566
  9685. // inner click event triggers patch, event handler
  9686. // attached to outer element during patch, and triggered again. This
  9687. // happens because browsers fire microtask ticks between event propagation.
  9688. // this no longer happens for templates in Vue 3, but could still be
  9689. // theoretically possible for hand-written render functions.
  9690. // the solution: we save the timestamp when a handler is attached,
  9691. // and also attach the timestamp to any event that was handled by vue
  9692. // for the first time (to avoid inconsistent event timestamp implementations
  9693. // or events fired from iframes, e.g. #2513)
  9694. // The handler would only fire if the event passed to it was fired
  9695. // AFTER it was attached.
  9696. if (!e._vts) {
  9697. e._vts = Date.now();
  9698. }
  9699. else if (e._vts <= invoker.attached) {
  9700. return;
  9701. }
  9702. // fixed by xxxxxx
  9703. const proxy = instance && instance.proxy;
  9704. const normalizeNativeEvent = proxy && proxy.$nne;
  9705. const { value } = invoker;
  9706. if (normalizeNativeEvent && isArray(value)) {
  9707. const fns = patchStopImmediatePropagation(e, value);
  9708. for (let i = 0; i < fns.length; i++) {
  9709. const fn = fns[i];
  9710. callWithAsyncErrorHandling(fn, instance, 5 /* ErrorCodes.NATIVE_EVENT_HANDLER */, !fn.__wwe ? normalizeNativeEvent(e) : [e]);
  9711. }
  9712. return;
  9713. }
  9714. callWithAsyncErrorHandling(patchStopImmediatePropagation(e, value), instance, 5 /* ErrorCodes.NATIVE_EVENT_HANDLER */,
  9715. // fixed by xxxxxx
  9716. normalizeNativeEvent && !value.__wwe
  9717. ? normalizeNativeEvent(e, value, instance)
  9718. : [e]);
  9719. };
  9720. invoker.value = initialValue;
  9721. invoker.attached = getNow();
  9722. return invoker;
  9723. }
  9724. function patchStopImmediatePropagation(e, value) {
  9725. if (isArray(value)) {
  9726. const originalStop = e.stopImmediatePropagation;
  9727. e.stopImmediatePropagation = () => {
  9728. originalStop.call(e);
  9729. e._stopped = true;
  9730. };
  9731. return value.map(fn => {
  9732. const patchedFn = (e) => !e._stopped && fn && fn(e);
  9733. patchedFn.__wwe = fn.__wwe;
  9734. return patchedFn;
  9735. });
  9736. }
  9737. else {
  9738. return value;
  9739. }
  9740. }
  9741. function patchWxs(el, rawName, nextValue, instance = null) {
  9742. if (!nextValue || !instance) {
  9743. return;
  9744. }
  9745. const propName = rawName.replace('change:', '');
  9746. const { attrs } = instance;
  9747. const nextPropValue = attrs[propName];
  9748. const prevPropValue = (el.__wxsProps || (el.__wxsProps = {}))[propName];
  9749. if (prevPropValue === nextPropValue) {
  9750. return;
  9751. }
  9752. el.__wxsProps[propName] = nextPropValue;
  9753. const proxy = instance.proxy;
  9754. nextTick(() => {
  9755. nextValue(nextPropValue, prevPropValue, proxy.$gcd(proxy, true), proxy.$gcd(proxy, false));
  9756. });
  9757. }
  9758. const nativeOnRE = /^on[a-z]/;
  9759. // fixed by xxxxxx
  9760. const forcePatchProp = (el, key) => {
  9761. if (key.indexOf('change:') === 0) {
  9762. return true;
  9763. }
  9764. if (key === 'class' && el.__wxsClassChanged) {
  9765. el.__wxsClassChanged = false;
  9766. return true;
  9767. }
  9768. if (key === 'style' && el.__wxsStyleChanged) {
  9769. el.__wxsStyleChanged = false;
  9770. return true;
  9771. }
  9772. return false;
  9773. };
  9774. const patchProp = (el, key, prevValue, nextValue, isSVG = false, prevChildren, parentComponent, parentSuspense, unmountChildren) => {
  9775. // @ts-expect-error fixed by xxxxxx
  9776. if (__UNI_FEATURE_WXS__ && key.indexOf('change:') === 0) {
  9777. return patchWxs(el, key, nextValue, parentComponent);
  9778. }
  9779. if (key === 'class') {
  9780. patchClass(el, nextValue, isSVG);
  9781. }
  9782. else if (key === 'style') {
  9783. patchStyle(el, prevValue, nextValue);
  9784. }
  9785. else if (isOn(key)) {
  9786. // ignore v-model listeners
  9787. if (!isModelListener(key)) {
  9788. patchEvent(el, key, prevValue, nextValue, parentComponent);
  9789. }
  9790. }
  9791. else if (key[0] === '.'
  9792. ? ((key = key.slice(1)), true)
  9793. : key[0] === '^'
  9794. ? ((key = key.slice(1)), false)
  9795. : shouldSetAsProp(el, key, nextValue, isSVG)) {
  9796. patchDOMProp(el, key, nextValue, prevChildren, parentComponent, parentSuspense, unmountChildren);
  9797. }
  9798. else {
  9799. // special case for <input v-model type="checkbox"> with
  9800. // :true-value & :false-value
  9801. // store value as dom properties since non-string values will be
  9802. // stringified.
  9803. if (key === 'true-value') {
  9804. el._trueValue = nextValue;
  9805. }
  9806. else if (key === 'false-value') {
  9807. el._falseValue = nextValue;
  9808. }
  9809. patchAttr(el, key, nextValue, isSVG);
  9810. }
  9811. };
  9812. function shouldSetAsProp(el, key, value, isSVG) {
  9813. if (isSVG) {
  9814. // most keys must be set as attribute on svg elements to work
  9815. // ...except innerHTML & textContent
  9816. if (key === 'innerHTML' || key === 'textContent') {
  9817. return true;
  9818. }
  9819. // or native onclick with function values
  9820. if (key in el && nativeOnRE.test(key) && isFunction(value)) {
  9821. return true;
  9822. }
  9823. return false;
  9824. }
  9825. // these are enumerated attrs, however their corresponding DOM properties
  9826. // are actually booleans - this leads to setting it with a string "false"
  9827. // value leading it to be coerced to `true`, so we need to always treat
  9828. // them as attributes.
  9829. // Note that `contentEditable` doesn't have this problem: its DOM
  9830. // property is also enumerated string values.
  9831. if (key === 'spellcheck' || key === 'draggable' || key === 'translate') {
  9832. return false;
  9833. }
  9834. // #1787, #2840 form property on form elements is readonly and must be set as
  9835. // attribute.
  9836. if (key === 'form') {
  9837. return false;
  9838. }
  9839. // #1526 <input list> must be set as attribute
  9840. if (key === 'list' && el.tagName === 'INPUT') {
  9841. return false;
  9842. }
  9843. // #2766 <textarea type> must be set as attribute
  9844. if (key === 'type' && el.tagName === 'TEXTAREA') {
  9845. return false;
  9846. }
  9847. // native onclick with string value, must be set as attribute
  9848. if (nativeOnRE.test(key) && isString(value)) {
  9849. return false;
  9850. }
  9851. return key in el;
  9852. }
  9853. function defineCustomElement(options, hydrate) {
  9854. const Comp = defineComponent(options);
  9855. class VueCustomElement extends VueElement {
  9856. constructor(initialProps) {
  9857. super(Comp, initialProps, hydrate);
  9858. }
  9859. }
  9860. VueCustomElement.def = Comp;
  9861. return VueCustomElement;
  9862. }
  9863. const defineSSRCustomElement = ((options) => {
  9864. // @ts-ignore
  9865. return defineCustomElement(options, hydrate);
  9866. });
  9867. const BaseClass = (typeof HTMLElement !== 'undefined' ? HTMLElement : class {
  9868. });
  9869. class VueElement extends BaseClass {
  9870. constructor(_def, _props = {}, hydrate) {
  9871. super();
  9872. this._def = _def;
  9873. this._props = _props;
  9874. /**
  9875. * @internal
  9876. */
  9877. this._instance = null;
  9878. this._connected = false;
  9879. this._resolved = false;
  9880. this._numberProps = null;
  9881. if (this.shadowRoot && hydrate) {
  9882. hydrate(this._createVNode(), this.shadowRoot);
  9883. }
  9884. else {
  9885. if ((process.env.NODE_ENV !== 'production') && this.shadowRoot) {
  9886. warn(`Custom element has pre-rendered declarative shadow root but is not ` +
  9887. `defined as hydratable. Use \`defineSSRCustomElement\`.`);
  9888. }
  9889. this.attachShadow({ mode: 'open' });
  9890. if (!this._def.__asyncLoader) {
  9891. // for sync component defs we can immediately resolve props
  9892. this._resolveProps(this._def);
  9893. }
  9894. }
  9895. }
  9896. connectedCallback() {
  9897. this._connected = true;
  9898. if (!this._instance) {
  9899. if (this._resolved) {
  9900. this._update();
  9901. }
  9902. else {
  9903. this._resolveDef();
  9904. }
  9905. }
  9906. }
  9907. disconnectedCallback() {
  9908. this._connected = false;
  9909. nextTick(() => {
  9910. if (!this._connected) {
  9911. render(null, this.shadowRoot);
  9912. this._instance = null;
  9913. }
  9914. });
  9915. }
  9916. /**
  9917. * resolve inner component definition (handle possible async component)
  9918. */
  9919. _resolveDef() {
  9920. this._resolved = true;
  9921. // set initial attrs
  9922. for (let i = 0; i < this.attributes.length; i++) {
  9923. this._setAttr(this.attributes[i].name);
  9924. }
  9925. // watch future attr changes
  9926. new MutationObserver(mutations => {
  9927. for (const m of mutations) {
  9928. this._setAttr(m.attributeName);
  9929. }
  9930. }).observe(this, { attributes: true });
  9931. const resolve = (def, isAsync = false) => {
  9932. const { props, styles } = def;
  9933. // cast Number-type props set before resolve
  9934. let numberProps;
  9935. if (props && !isArray(props)) {
  9936. for (const key in props) {
  9937. const opt = props[key];
  9938. if (opt === Number || (opt && opt.type === Number)) {
  9939. if (key in this._props) {
  9940. this._props[key] = toNumber(this._props[key]);
  9941. }
  9942. (numberProps || (numberProps = Object.create(null)))[camelize(key)] = true;
  9943. }
  9944. }
  9945. }
  9946. this._numberProps = numberProps;
  9947. if (isAsync) {
  9948. // defining getter/setters on prototype
  9949. // for sync defs, this already happened in the constructor
  9950. this._resolveProps(def);
  9951. }
  9952. // apply CSS
  9953. this._applyStyles(styles);
  9954. // initial render
  9955. this._update();
  9956. };
  9957. const asyncDef = this._def.__asyncLoader;
  9958. if (asyncDef) {
  9959. asyncDef().then(def => resolve(def, true));
  9960. }
  9961. else {
  9962. resolve(this._def);
  9963. }
  9964. }
  9965. _resolveProps(def) {
  9966. const { props } = def;
  9967. const declaredPropKeys = isArray(props) ? props : Object.keys(props || {});
  9968. // check if there are props set pre-upgrade or connect
  9969. for (const key of Object.keys(this)) {
  9970. if (key[0] !== '_' && declaredPropKeys.includes(key)) {
  9971. this._setProp(key, this[key], true, false);
  9972. }
  9973. }
  9974. // defining getter/setters on prototype
  9975. for (const key of declaredPropKeys.map(camelize)) {
  9976. Object.defineProperty(this, key, {
  9977. get() {
  9978. return this._getProp(key);
  9979. },
  9980. set(val) {
  9981. this._setProp(key, val);
  9982. }
  9983. });
  9984. }
  9985. }
  9986. _setAttr(key) {
  9987. let value = this.getAttribute(key);
  9988. const camelKey = camelize(key);
  9989. if (this._numberProps && this._numberProps[camelKey]) {
  9990. value = toNumber(value);
  9991. }
  9992. this._setProp(camelKey, value, false);
  9993. }
  9994. /**
  9995. * @internal
  9996. */
  9997. _getProp(key) {
  9998. return this._props[key];
  9999. }
  10000. /**
  10001. * @internal
  10002. */
  10003. _setProp(key, val, shouldReflect = true, shouldUpdate = true) {
  10004. if (val !== this._props[key]) {
  10005. this._props[key] = val;
  10006. if (shouldUpdate && this._instance) {
  10007. this._update();
  10008. }
  10009. // reflect
  10010. if (shouldReflect) {
  10011. if (val === true) {
  10012. this.setAttribute(hyphenate(key), '');
  10013. }
  10014. else if (typeof val === 'string' || typeof val === 'number') {
  10015. this.setAttribute(hyphenate(key), val + '');
  10016. }
  10017. else if (!val) {
  10018. this.removeAttribute(hyphenate(key));
  10019. }
  10020. }
  10021. }
  10022. }
  10023. _update() {
  10024. render(this._createVNode(), this.shadowRoot);
  10025. }
  10026. _createVNode() {
  10027. const vnode = createVNode(this._def, extend({}, this._props));
  10028. if (!this._instance) {
  10029. vnode.ce = instance => {
  10030. this._instance = instance;
  10031. instance.isCE = true;
  10032. // HMR
  10033. if ((process.env.NODE_ENV !== 'production')) {
  10034. instance.ceReload = newStyles => {
  10035. // always reset styles
  10036. if (this._styles) {
  10037. this._styles.forEach(s => this.shadowRoot.removeChild(s));
  10038. this._styles.length = 0;
  10039. }
  10040. this._applyStyles(newStyles);
  10041. this._instance = null;
  10042. this._update();
  10043. };
  10044. }
  10045. const dispatch = (event, args) => {
  10046. this.dispatchEvent(new CustomEvent(event, {
  10047. detail: args
  10048. }));
  10049. };
  10050. // intercept emit
  10051. instance.emit = (event, ...args) => {
  10052. // dispatch both the raw and hyphenated versions of an event
  10053. // to match Vue behavior
  10054. dispatch(event, args);
  10055. if (hyphenate(event) !== event) {
  10056. dispatch(hyphenate(event), args);
  10057. }
  10058. };
  10059. // locate nearest Vue custom element parent for provide/inject
  10060. let parent = this;
  10061. while ((parent =
  10062. parent && (parent.parentNode || parent.host))) {
  10063. if (parent instanceof VueElement) {
  10064. instance.parent = parent._instance;
  10065. instance.provides = parent._instance.provides;
  10066. break;
  10067. }
  10068. }
  10069. };
  10070. }
  10071. return vnode;
  10072. }
  10073. _applyStyles(styles) {
  10074. if (styles) {
  10075. styles.forEach(css => {
  10076. const s = document.createElement('style');
  10077. s.textContent = css;
  10078. this.shadowRoot.appendChild(s);
  10079. // record for HMR
  10080. if ((process.env.NODE_ENV !== 'production')) {
  10081. (this._styles || (this._styles = [])).push(s);
  10082. }
  10083. });
  10084. }
  10085. }
  10086. }
  10087. function useCssModule(name = '$style') {
  10088. /* istanbul ignore else */
  10089. {
  10090. const instance = getCurrentInstance();
  10091. if (!instance) {
  10092. (process.env.NODE_ENV !== 'production') && warn(`useCssModule must be called inside setup()`);
  10093. return EMPTY_OBJ;
  10094. }
  10095. const modules = instance.type.__cssModules;
  10096. if (!modules) {
  10097. (process.env.NODE_ENV !== 'production') && warn(`Current instance does not have CSS modules injected.`);
  10098. return EMPTY_OBJ;
  10099. }
  10100. const mod = modules[name];
  10101. if (!mod) {
  10102. (process.env.NODE_ENV !== 'production') &&
  10103. warn(`Current instance does not have CSS module named "${name}".`);
  10104. return EMPTY_OBJ;
  10105. }
  10106. return mod;
  10107. }
  10108. }
  10109. /**
  10110. * Runtime helper for SFC's CSS variable injection feature.
  10111. * @private
  10112. */
  10113. function useCssVars(getter) {
  10114. const instance = getCurrentInstance();
  10115. /* istanbul ignore next */
  10116. if (!instance) {
  10117. (process.env.NODE_ENV !== 'production') &&
  10118. warn(`useCssVars is called without current active component instance.`);
  10119. return;
  10120. }
  10121. const updateTeleports = (instance.ut = (vars = getter(instance.proxy)) => {
  10122. Array.from(document.querySelectorAll(`[data-v-owner="${instance.uid}"]`)).forEach(node => setVarsOnNode(node, vars));
  10123. });
  10124. const setVars = () => {
  10125. const vars = getter(instance.proxy);
  10126. setVarsOnVNode(instance.subTree, vars);
  10127. updateTeleports(vars);
  10128. };
  10129. watchPostEffect(setVars);
  10130. onMounted(() => {
  10131. const ob = new MutationObserver(setVars);
  10132. ob.observe(instance.subTree.el.parentNode, { childList: true });
  10133. onUnmounted(() => ob.disconnect());
  10134. });
  10135. }
  10136. function setVarsOnVNode(vnode, vars) {
  10137. if (vnode.shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
  10138. const suspense = vnode.suspense;
  10139. vnode = suspense.activeBranch;
  10140. if (suspense.pendingBranch && !suspense.isHydrating) {
  10141. suspense.effects.push(() => {
  10142. setVarsOnVNode(suspense.activeBranch, vars);
  10143. });
  10144. }
  10145. }
  10146. // drill down HOCs until it's a non-component vnode
  10147. while (vnode.component) {
  10148. vnode = vnode.component.subTree;
  10149. }
  10150. if (vnode.shapeFlag & 1 /* ShapeFlags.ELEMENT */ && vnode.el) {
  10151. setVarsOnNode(vnode.el, vars);
  10152. }
  10153. else if (vnode.type === Fragment) {
  10154. vnode.children.forEach(c => setVarsOnVNode(c, vars));
  10155. }
  10156. else if (vnode.type === Static) {
  10157. let { el, anchor } = vnode;
  10158. while (el) {
  10159. setVarsOnNode(el, vars);
  10160. if (el === anchor)
  10161. break;
  10162. el = el.nextSibling;
  10163. }
  10164. }
  10165. }
  10166. function setVarsOnNode(el, vars) {
  10167. if (el.nodeType === 1) {
  10168. const style = el.style;
  10169. for (const key in vars) {
  10170. style.setProperty(`--${key}`, normalizeRpx(vars[key]));
  10171. }
  10172. }
  10173. }
  10174. const TRANSITION = 'transition';
  10175. const ANIMATION = 'animation';
  10176. // DOM Transition is a higher-order-component based on the platform-agnostic
  10177. // base Transition component, with DOM-specific logic.
  10178. const Transition = (props, { slots }) => h(BaseTransition, resolveTransitionProps(props), slots);
  10179. Transition.displayName = 'Transition';
  10180. const DOMTransitionPropsValidators = {
  10181. name: String,
  10182. type: String,
  10183. css: {
  10184. type: Boolean,
  10185. default: true
  10186. },
  10187. duration: [String, Number, Object],
  10188. enterFromClass: String,
  10189. enterActiveClass: String,
  10190. enterToClass: String,
  10191. appearFromClass: String,
  10192. appearActiveClass: String,
  10193. appearToClass: String,
  10194. leaveFromClass: String,
  10195. leaveActiveClass: String,
  10196. leaveToClass: String
  10197. };
  10198. const TransitionPropsValidators = (Transition.props =
  10199. /*#__PURE__*/ extend({}, BaseTransitionPropsValidators, DOMTransitionPropsValidators));
  10200. /**
  10201. * #3227 Incoming hooks may be merged into arrays when wrapping Transition
  10202. * with custom HOCs.
  10203. */
  10204. const callHook = (hook, args = []) => {
  10205. if (isArray(hook)) {
  10206. hook.forEach(h => h(...args));
  10207. }
  10208. else if (hook) {
  10209. hook(...args);
  10210. }
  10211. };
  10212. /**
  10213. * Check if a hook expects a callback (2nd arg), which means the user
  10214. * intends to explicitly control the end of the transition.
  10215. */
  10216. const hasExplicitCallback = (hook) => {
  10217. return hook
  10218. ? isArray(hook)
  10219. ? hook.some(h => h.length > 1)
  10220. : hook.length > 1
  10221. : false;
  10222. };
  10223. function resolveTransitionProps(rawProps) {
  10224. const baseProps = {};
  10225. for (const key in rawProps) {
  10226. if (!(key in DOMTransitionPropsValidators)) {
  10227. baseProps[key] = rawProps[key];
  10228. }
  10229. }
  10230. if (rawProps.css === false) {
  10231. return baseProps;
  10232. }
  10233. const { name = 'v', type, duration, enterFromClass = `${name}-enter-from`, enterActiveClass = `${name}-enter-active`, enterToClass = `${name}-enter-to`, appearFromClass = enterFromClass, appearActiveClass = enterActiveClass, appearToClass = enterToClass, leaveFromClass = `${name}-leave-from`, leaveActiveClass = `${name}-leave-active`, leaveToClass = `${name}-leave-to` } = rawProps;
  10234. const durations = normalizeDuration(duration);
  10235. const enterDuration = durations && durations[0];
  10236. const leaveDuration = durations && durations[1];
  10237. const { onBeforeEnter, onEnter, onEnterCancelled, onLeave, onLeaveCancelled, onBeforeAppear = onBeforeEnter, onAppear = onEnter, onAppearCancelled = onEnterCancelled } = baseProps;
  10238. const finishEnter = (el, isAppear, done) => {
  10239. removeTransitionClass(el, isAppear ? appearToClass : enterToClass);
  10240. removeTransitionClass(el, isAppear ? appearActiveClass : enterActiveClass);
  10241. done && done();
  10242. };
  10243. const finishLeave = (el, done) => {
  10244. el._isLeaving = false;
  10245. removeTransitionClass(el, leaveFromClass);
  10246. removeTransitionClass(el, leaveToClass);
  10247. removeTransitionClass(el, leaveActiveClass);
  10248. done && done();
  10249. };
  10250. const makeEnterHook = (isAppear) => {
  10251. return (el, done) => {
  10252. const hook = isAppear ? onAppear : onEnter;
  10253. const resolve = () => finishEnter(el, isAppear, done);
  10254. callHook(hook, [el, resolve]);
  10255. nextFrame(() => {
  10256. removeTransitionClass(el, isAppear ? appearFromClass : enterFromClass);
  10257. addTransitionClass(el, isAppear ? appearToClass : enterToClass);
  10258. if (!hasExplicitCallback(hook)) {
  10259. whenTransitionEnds(el, type, enterDuration, resolve);
  10260. }
  10261. });
  10262. };
  10263. };
  10264. return extend(baseProps, {
  10265. onBeforeEnter(el) {
  10266. callHook(onBeforeEnter, [el]);
  10267. addTransitionClass(el, enterFromClass);
  10268. addTransitionClass(el, enterActiveClass);
  10269. },
  10270. onBeforeAppear(el) {
  10271. callHook(onBeforeAppear, [el]);
  10272. addTransitionClass(el, appearFromClass);
  10273. addTransitionClass(el, appearActiveClass);
  10274. },
  10275. onEnter: makeEnterHook(false),
  10276. onAppear: makeEnterHook(true),
  10277. onLeave(el, done) {
  10278. el._isLeaving = true;
  10279. const resolve = () => finishLeave(el, done);
  10280. addTransitionClass(el, leaveFromClass);
  10281. // force reflow so *-leave-from classes immediately take effect (#2593)
  10282. forceReflow();
  10283. addTransitionClass(el, leaveActiveClass);
  10284. nextFrame(() => {
  10285. if (!el._isLeaving) {
  10286. // cancelled
  10287. return;
  10288. }
  10289. removeTransitionClass(el, leaveFromClass);
  10290. addTransitionClass(el, leaveToClass);
  10291. if (!hasExplicitCallback(onLeave)) {
  10292. whenTransitionEnds(el, type, leaveDuration, resolve);
  10293. }
  10294. });
  10295. callHook(onLeave, [el, resolve]);
  10296. },
  10297. onEnterCancelled(el) {
  10298. finishEnter(el, false);
  10299. callHook(onEnterCancelled, [el]);
  10300. },
  10301. onAppearCancelled(el) {
  10302. finishEnter(el, true);
  10303. callHook(onAppearCancelled, [el]);
  10304. },
  10305. onLeaveCancelled(el) {
  10306. finishLeave(el);
  10307. callHook(onLeaveCancelled, [el]);
  10308. }
  10309. });
  10310. }
  10311. function normalizeDuration(duration) {
  10312. if (duration == null) {
  10313. return null;
  10314. }
  10315. else if (isObject(duration)) {
  10316. return [NumberOf(duration.enter), NumberOf(duration.leave)];
  10317. }
  10318. else {
  10319. const n = NumberOf(duration);
  10320. return [n, n];
  10321. }
  10322. }
  10323. function NumberOf(val) {
  10324. const res = toNumber(val);
  10325. if ((process.env.NODE_ENV !== 'production')) {
  10326. assertNumber(res, '<transition> explicit duration');
  10327. }
  10328. return res;
  10329. }
  10330. function addTransitionClass(el, cls) {
  10331. cls.split(/\s+/).forEach(c => c && el.classList.add(c));
  10332. (el._vtc ||
  10333. (el._vtc = new Set())).add(cls);
  10334. }
  10335. function removeTransitionClass(el, cls) {
  10336. cls.split(/\s+/).forEach(c => c && el.classList.remove(c));
  10337. const { _vtc } = el;
  10338. if (_vtc) {
  10339. _vtc.delete(cls);
  10340. if (!_vtc.size) {
  10341. el._vtc = undefined;
  10342. }
  10343. }
  10344. }
  10345. function nextFrame(cb) {
  10346. requestAnimationFrame(() => {
  10347. requestAnimationFrame(cb);
  10348. });
  10349. }
  10350. let endId = 0;
  10351. function whenTransitionEnds(el, expectedType, explicitTimeout, resolve) {
  10352. const id = (el._endId = ++endId);
  10353. const resolveIfNotStale = () => {
  10354. if (id === el._endId) {
  10355. resolve();
  10356. }
  10357. };
  10358. if (explicitTimeout) {
  10359. return setTimeout(resolveIfNotStale, explicitTimeout);
  10360. }
  10361. const { type, timeout, propCount } = getTransitionInfo(el, expectedType);
  10362. if (!type) {
  10363. return resolve();
  10364. }
  10365. const endEvent = type + 'end';
  10366. let ended = 0;
  10367. const end = () => {
  10368. el.removeEventListener(endEvent, onEnd);
  10369. resolveIfNotStale();
  10370. };
  10371. const onEnd = (e) => {
  10372. if (e.target === el && ++ended >= propCount) {
  10373. end();
  10374. }
  10375. };
  10376. setTimeout(() => {
  10377. if (ended < propCount) {
  10378. end();
  10379. }
  10380. }, timeout + 1);
  10381. el.addEventListener(endEvent, onEnd);
  10382. }
  10383. function getTransitionInfo(el, expectedType) {
  10384. const styles = window.getComputedStyle(el);
  10385. // JSDOM may return undefined for transition properties
  10386. const getStyleProperties = (key) => (styles[key] || '').split(', ');
  10387. const transitionDelays = getStyleProperties(`${TRANSITION}Delay`);
  10388. const transitionDurations = getStyleProperties(`${TRANSITION}Duration`);
  10389. const transitionTimeout = getTimeout(transitionDelays, transitionDurations);
  10390. const animationDelays = getStyleProperties(`${ANIMATION}Delay`);
  10391. const animationDurations = getStyleProperties(`${ANIMATION}Duration`);
  10392. const animationTimeout = getTimeout(animationDelays, animationDurations);
  10393. let type = null;
  10394. let timeout = 0;
  10395. let propCount = 0;
  10396. /* istanbul ignore if */
  10397. if (expectedType === TRANSITION) {
  10398. if (transitionTimeout > 0) {
  10399. type = TRANSITION;
  10400. timeout = transitionTimeout;
  10401. propCount = transitionDurations.length;
  10402. }
  10403. }
  10404. else if (expectedType === ANIMATION) {
  10405. if (animationTimeout > 0) {
  10406. type = ANIMATION;
  10407. timeout = animationTimeout;
  10408. propCount = animationDurations.length;
  10409. }
  10410. }
  10411. else {
  10412. timeout = Math.max(transitionTimeout, animationTimeout);
  10413. type =
  10414. timeout > 0
  10415. ? transitionTimeout > animationTimeout
  10416. ? TRANSITION
  10417. : ANIMATION
  10418. : null;
  10419. propCount = type
  10420. ? type === TRANSITION
  10421. ? transitionDurations.length
  10422. : animationDurations.length
  10423. : 0;
  10424. }
  10425. const hasTransform = type === TRANSITION &&
  10426. /\b(transform|all)(,|$)/.test(getStyleProperties(`${TRANSITION}Property`).toString());
  10427. return {
  10428. type,
  10429. timeout,
  10430. propCount,
  10431. hasTransform
  10432. };
  10433. }
  10434. function getTimeout(delays, durations) {
  10435. while (delays.length < durations.length) {
  10436. delays = delays.concat(delays);
  10437. }
  10438. return Math.max(...durations.map((d, i) => toMs(d) + toMs(delays[i])));
  10439. }
  10440. // Old versions of Chromium (below 61.0.3163.100) formats floating pointer
  10441. // numbers in a locale-dependent way, using a comma instead of a dot.
  10442. // If comma is not replaced with a dot, the input will be rounded down
  10443. // (i.e. acting as a floor function) causing unexpected behaviors
  10444. function toMs(s) {
  10445. return Number(s.slice(0, -1).replace(',', '.')) * 1000;
  10446. }
  10447. // synchronously force layout to put elements into a certain state
  10448. function forceReflow() {
  10449. return document.body.offsetHeight;
  10450. }
  10451. const positionMap = new WeakMap();
  10452. const newPositionMap = new WeakMap();
  10453. const TransitionGroupImpl = {
  10454. name: 'TransitionGroup',
  10455. props: /*#__PURE__*/ extend({}, TransitionPropsValidators, {
  10456. tag: String,
  10457. moveClass: String
  10458. }),
  10459. setup(props, { slots }) {
  10460. const instance = getCurrentInstance();
  10461. const state = useTransitionState();
  10462. let prevChildren;
  10463. let children;
  10464. onUpdated(() => {
  10465. // children is guaranteed to exist after initial render
  10466. if (!prevChildren.length) {
  10467. return;
  10468. }
  10469. const moveClass = props.moveClass || `${props.name || 'v'}-move`;
  10470. if (!hasCSSTransform(prevChildren[0].el, instance.vnode.el, moveClass)) {
  10471. return;
  10472. }
  10473. // we divide the work into three loops to avoid mixing DOM reads and writes
  10474. // in each iteration - which helps prevent layout thrashing.
  10475. prevChildren.forEach(callPendingCbs);
  10476. prevChildren.forEach(recordPosition);
  10477. const movedChildren = prevChildren.filter(applyTranslation);
  10478. // force reflow to put everything in position
  10479. forceReflow();
  10480. movedChildren.forEach(c => {
  10481. const el = c.el;
  10482. const style = el.style;
  10483. addTransitionClass(el, moveClass);
  10484. style.transform = style.webkitTransform = style.transitionDuration = '';
  10485. const cb = (el._moveCb = (e) => {
  10486. if (e && e.target !== el) {
  10487. return;
  10488. }
  10489. if (!e || /transform$/.test(e.propertyName)) {
  10490. el.removeEventListener('transitionend', cb);
  10491. el._moveCb = null;
  10492. removeTransitionClass(el, moveClass);
  10493. }
  10494. });
  10495. el.addEventListener('transitionend', cb);
  10496. });
  10497. });
  10498. return () => {
  10499. const rawProps = toRaw(props);
  10500. const cssTransitionProps = resolveTransitionProps(rawProps);
  10501. let tag = rawProps.tag || Fragment;
  10502. prevChildren = children;
  10503. children = slots.default ? getTransitionRawChildren(slots.default()) : [];
  10504. for (let i = 0; i < children.length; i++) {
  10505. const child = children[i];
  10506. if (child.key != null) {
  10507. setTransitionHooks(child, resolveTransitionHooks(child, cssTransitionProps, state, instance));
  10508. }
  10509. else if ((process.env.NODE_ENV !== 'production')) {
  10510. warn(`<TransitionGroup> children must be keyed.`);
  10511. }
  10512. }
  10513. if (prevChildren) {
  10514. for (let i = 0; i < prevChildren.length; i++) {
  10515. const child = prevChildren[i];
  10516. setTransitionHooks(child, resolveTransitionHooks(child, cssTransitionProps, state, instance));
  10517. positionMap.set(child, child.el.getBoundingClientRect());
  10518. }
  10519. }
  10520. return createVNode(tag, null, children);
  10521. };
  10522. }
  10523. };
  10524. /**
  10525. * TransitionGroup does not support "mode" so we need to remove it from the
  10526. * props declarations, but direct delete operation is considered a side effect
  10527. * and will make the entire transition feature non-tree-shakeable, so we do it
  10528. * in a function and mark the function's invocation as pure.
  10529. */
  10530. const removeMode = (props) => delete props.mode;
  10531. /*#__PURE__*/ removeMode(TransitionGroupImpl.props);
  10532. const TransitionGroup = TransitionGroupImpl;
  10533. function callPendingCbs(c) {
  10534. const el = c.el;
  10535. if (el._moveCb) {
  10536. el._moveCb();
  10537. }
  10538. if (el._enterCb) {
  10539. el._enterCb();
  10540. }
  10541. }
  10542. function recordPosition(c) {
  10543. newPositionMap.set(c, c.el.getBoundingClientRect());
  10544. }
  10545. function applyTranslation(c) {
  10546. const oldPos = positionMap.get(c);
  10547. const newPos = newPositionMap.get(c);
  10548. const dx = oldPos.left - newPos.left;
  10549. const dy = oldPos.top - newPos.top;
  10550. if (dx || dy) {
  10551. const s = c.el.style;
  10552. s.transform = s.webkitTransform = `translate(${dx}px,${dy}px)`;
  10553. s.transitionDuration = '0s';
  10554. return c;
  10555. }
  10556. }
  10557. function hasCSSTransform(el, root, moveClass) {
  10558. // Detect whether an element with the move class applied has
  10559. // CSS transitions. Since the element may be inside an entering
  10560. // transition at this very moment, we make a clone of it and remove
  10561. // all other transition classes applied to ensure only the move class
  10562. // is applied.
  10563. const clone = el.cloneNode();
  10564. if (el._vtc) {
  10565. el._vtc.forEach(cls => {
  10566. cls.split(/\s+/).forEach(c => c && clone.classList.remove(c));
  10567. });
  10568. }
  10569. moveClass.split(/\s+/).forEach(c => c && clone.classList.add(c));
  10570. clone.style.display = 'none';
  10571. const container = (root.nodeType === 1 ? root : root.parentNode);
  10572. container.appendChild(clone);
  10573. const { hasTransform } = getTransitionInfo(clone);
  10574. container.removeChild(clone);
  10575. return hasTransform;
  10576. }
  10577. const getModelAssigner = (vnode) => {
  10578. const fn = vnode.props['onUpdate:modelValue'] ||
  10579. (false );
  10580. return isArray(fn) ? value => invokeArrayFns(fn, value) : fn;
  10581. };
  10582. function onCompositionStart(e) {
  10583. e.target.composing = true;
  10584. }
  10585. function onCompositionEnd(e) {
  10586. const target = e.target;
  10587. if (target.composing) {
  10588. target.composing = false;
  10589. target.dispatchEvent(new Event('input'));
  10590. }
  10591. }
  10592. // We are exporting the v-model runtime directly as vnode hooks so that it can
  10593. // be tree-shaken in case v-model is never used.
  10594. const vModelText = {
  10595. created(el, { modifiers: { lazy, trim, number } }, vnode) {
  10596. el._assign = getModelAssigner(vnode);
  10597. const castToNumber = number || (vnode.props && vnode.props.type === 'number');
  10598. addEventListener(el, lazy ? 'change' : 'input', e => {
  10599. if (e.target.composing)
  10600. return;
  10601. let domValue = el.value;
  10602. if (trim) {
  10603. domValue = domValue.trim();
  10604. }
  10605. if (castToNumber) {
  10606. domValue = looseToNumber(domValue);
  10607. }
  10608. el._assign(domValue);
  10609. });
  10610. if (trim) {
  10611. addEventListener(el, 'change', () => {
  10612. el.value = el.value.trim();
  10613. });
  10614. }
  10615. if (!lazy) {
  10616. addEventListener(el, 'compositionstart', onCompositionStart);
  10617. addEventListener(el, 'compositionend', onCompositionEnd);
  10618. // Safari < 10.2 & UIWebView doesn't fire compositionend when
  10619. // switching focus before confirming composition choice
  10620. // this also fixes the issue where some browsers e.g. iOS Chrome
  10621. // fires "change" instead of "input" on autocomplete.
  10622. addEventListener(el, 'change', onCompositionEnd);
  10623. }
  10624. },
  10625. // set value on mounted so it's after min/max for type="range"
  10626. mounted(el, { value }) {
  10627. el.value = value == null ? '' : value;
  10628. },
  10629. beforeUpdate(el, { value, modifiers: { lazy, trim, number } }, vnode) {
  10630. el._assign = getModelAssigner(vnode);
  10631. // avoid clearing unresolved text. #2302
  10632. if (el.composing)
  10633. return;
  10634. if (document.activeElement === el && el.type !== 'range') {
  10635. if (lazy) {
  10636. return;
  10637. }
  10638. if (trim && el.value.trim() === value) {
  10639. return;
  10640. }
  10641. if ((number || el.type === 'number') &&
  10642. looseToNumber(el.value) === value) {
  10643. return;
  10644. }
  10645. }
  10646. const newValue = value == null ? '' : value;
  10647. if (el.value !== newValue) {
  10648. el.value = newValue;
  10649. }
  10650. }
  10651. };
  10652. const vModelCheckbox = {
  10653. // #4096 array checkboxes need to be deep traversed
  10654. deep: true,
  10655. created(el, _, vnode) {
  10656. el._assign = getModelAssigner(vnode);
  10657. addEventListener(el, 'change', () => {
  10658. const modelValue = el._modelValue;
  10659. const elementValue = getValue(el);
  10660. const checked = el.checked;
  10661. const assign = el._assign;
  10662. if (isArray(modelValue)) {
  10663. const index = looseIndexOf(modelValue, elementValue);
  10664. const found = index !== -1;
  10665. if (checked && !found) {
  10666. assign(modelValue.concat(elementValue));
  10667. }
  10668. else if (!checked && found) {
  10669. const filtered = [...modelValue];
  10670. filtered.splice(index, 1);
  10671. assign(filtered);
  10672. }
  10673. }
  10674. else if (isSet(modelValue)) {
  10675. const cloned = new Set(modelValue);
  10676. if (checked) {
  10677. cloned.add(elementValue);
  10678. }
  10679. else {
  10680. cloned.delete(elementValue);
  10681. }
  10682. assign(cloned);
  10683. }
  10684. else {
  10685. assign(getCheckboxValue(el, checked));
  10686. }
  10687. });
  10688. },
  10689. // set initial checked on mount to wait for true-value/false-value
  10690. mounted: setChecked,
  10691. beforeUpdate(el, binding, vnode) {
  10692. el._assign = getModelAssigner(vnode);
  10693. setChecked(el, binding, vnode);
  10694. }
  10695. };
  10696. function setChecked(el, { value, oldValue }, vnode) {
  10697. el._modelValue = value;
  10698. if (isArray(value)) {
  10699. el.checked = looseIndexOf(value, vnode.props.value) > -1;
  10700. }
  10701. else if (isSet(value)) {
  10702. el.checked = value.has(vnode.props.value);
  10703. }
  10704. else if (value !== oldValue) {
  10705. el.checked = looseEqual(value, getCheckboxValue(el, true));
  10706. }
  10707. }
  10708. const vModelRadio = {
  10709. created(el, { value }, vnode) {
  10710. el.checked = looseEqual(value, vnode.props.value);
  10711. el._assign = getModelAssigner(vnode);
  10712. addEventListener(el, 'change', () => {
  10713. el._assign(getValue(el));
  10714. });
  10715. },
  10716. beforeUpdate(el, { value, oldValue }, vnode) {
  10717. el._assign = getModelAssigner(vnode);
  10718. if (value !== oldValue) {
  10719. el.checked = looseEqual(value, vnode.props.value);
  10720. }
  10721. }
  10722. };
  10723. const vModelSelect = {
  10724. // <select multiple> value need to be deep traversed
  10725. deep: true,
  10726. created(el, { value, modifiers: { number } }, vnode) {
  10727. const isSetModel = isSet(value);
  10728. addEventListener(el, 'change', () => {
  10729. const selectedVal = Array.prototype.filter
  10730. .call(el.options, (o) => o.selected)
  10731. .map((o) => number ? looseToNumber(getValue(o)) : getValue(o));
  10732. el._assign(el.multiple
  10733. ? isSetModel
  10734. ? new Set(selectedVal)
  10735. : selectedVal
  10736. : selectedVal[0]);
  10737. });
  10738. el._assign = getModelAssigner(vnode);
  10739. },
  10740. // set value in mounted & updated because <select> relies on its children
  10741. // <option>s.
  10742. mounted(el, { value }) {
  10743. setSelected(el, value);
  10744. },
  10745. beforeUpdate(el, _binding, vnode) {
  10746. el._assign = getModelAssigner(vnode);
  10747. },
  10748. updated(el, { value }) {
  10749. setSelected(el, value);
  10750. }
  10751. };
  10752. function setSelected(el, value) {
  10753. const isMultiple = el.multiple;
  10754. if (isMultiple && !isArray(value) && !isSet(value)) {
  10755. (process.env.NODE_ENV !== 'production') &&
  10756. warn(`<select multiple v-model> expects an Array or Set value for its binding, ` +
  10757. `but got ${Object.prototype.toString.call(value).slice(8, -1)}.`);
  10758. return;
  10759. }
  10760. for (let i = 0, l = el.options.length; i < l; i++) {
  10761. const option = el.options[i];
  10762. const optionValue = getValue(option);
  10763. if (isMultiple) {
  10764. if (isArray(value)) {
  10765. option.selected = looseIndexOf(value, optionValue) > -1;
  10766. }
  10767. else {
  10768. option.selected = value.has(optionValue);
  10769. }
  10770. }
  10771. else {
  10772. if (looseEqual(getValue(option), value)) {
  10773. if (el.selectedIndex !== i)
  10774. el.selectedIndex = i;
  10775. return;
  10776. }
  10777. }
  10778. }
  10779. if (!isMultiple && el.selectedIndex !== -1) {
  10780. el.selectedIndex = -1;
  10781. }
  10782. }
  10783. // retrieve raw value set via :value bindings
  10784. function getValue(el) {
  10785. return '_value' in el ? el._value : el.value;
  10786. }
  10787. // retrieve raw value for true-value and false-value set via :true-value or :false-value bindings
  10788. function getCheckboxValue(el, checked) {
  10789. const key = checked ? '_trueValue' : '_falseValue';
  10790. return key in el ? el[key] : checked;
  10791. }
  10792. const vModelDynamic = {
  10793. created(el, binding, vnode) {
  10794. callModelHook(el, binding, vnode, null, 'created');
  10795. },
  10796. mounted(el, binding, vnode) {
  10797. callModelHook(el, binding, vnode, null, 'mounted');
  10798. },
  10799. beforeUpdate(el, binding, vnode, prevVNode) {
  10800. callModelHook(el, binding, vnode, prevVNode, 'beforeUpdate');
  10801. },
  10802. updated(el, binding, vnode, prevVNode) {
  10803. callModelHook(el, binding, vnode, prevVNode, 'updated');
  10804. }
  10805. };
  10806. function resolveDynamicModel(tagName, type) {
  10807. switch (tagName) {
  10808. case 'SELECT':
  10809. return vModelSelect;
  10810. case 'TEXTAREA':
  10811. return vModelText;
  10812. default:
  10813. switch (type) {
  10814. case 'checkbox':
  10815. return vModelCheckbox;
  10816. case 'radio':
  10817. return vModelRadio;
  10818. default:
  10819. return vModelText;
  10820. }
  10821. }
  10822. }
  10823. function callModelHook(el, binding, vnode, prevVNode, hook) {
  10824. const modelToUse = resolveDynamicModel(el.tagName, vnode.props && vnode.props.type);
  10825. const fn = modelToUse[hook];
  10826. fn && fn(el, binding, vnode, prevVNode);
  10827. }
  10828. // SSR vnode transforms, only used when user includes client-oriented render
  10829. // function in SSR
  10830. function initVModelForSSR() {
  10831. vModelText.getSSRProps = ({ value }) => ({ value });
  10832. vModelRadio.getSSRProps = ({ value }, vnode) => {
  10833. if (vnode.props && looseEqual(vnode.props.value, value)) {
  10834. return { checked: true };
  10835. }
  10836. };
  10837. vModelCheckbox.getSSRProps = ({ value }, vnode) => {
  10838. if (isArray(value)) {
  10839. if (vnode.props && looseIndexOf(value, vnode.props.value) > -1) {
  10840. return { checked: true };
  10841. }
  10842. }
  10843. else if (isSet(value)) {
  10844. if (vnode.props && value.has(vnode.props.value)) {
  10845. return { checked: true };
  10846. }
  10847. }
  10848. else if (value) {
  10849. return { checked: true };
  10850. }
  10851. };
  10852. vModelDynamic.getSSRProps = (binding, vnode) => {
  10853. if (typeof vnode.type !== 'string') {
  10854. return;
  10855. }
  10856. const modelToUse = resolveDynamicModel(
  10857. // resolveDynamicModel expects an uppercase tag name, but vnode.type is lowercase
  10858. vnode.type.toUpperCase(), vnode.props && vnode.props.type);
  10859. if (modelToUse.getSSRProps) {
  10860. return modelToUse.getSSRProps(binding, vnode);
  10861. }
  10862. };
  10863. }
  10864. const systemModifiers = ['ctrl', 'shift', 'alt', 'meta'];
  10865. const modifierGuards = {
  10866. stop: e => e.stopPropagation(),
  10867. prevent: e => e.preventDefault(),
  10868. self: e => e.target !== e.currentTarget,
  10869. ctrl: e => !e.ctrlKey,
  10870. shift: e => !e.shiftKey,
  10871. alt: e => !e.altKey,
  10872. meta: e => !e.metaKey,
  10873. left: e => 'button' in e && e.button !== 0,
  10874. middle: e => 'button' in e && e.button !== 1,
  10875. right: e => 'button' in e && e.button !== 2,
  10876. exact: (e, modifiers) => systemModifiers.some(m => e[`${m}Key`] && !modifiers.includes(m))
  10877. };
  10878. /**
  10879. * @private
  10880. */
  10881. const withModifiers = (fn, modifiers) => {
  10882. return (event, ...args) => {
  10883. for (let i = 0; i < modifiers.length; i++) {
  10884. const guard = modifierGuards[modifiers[i]];
  10885. if (guard && guard(event, modifiers))
  10886. return;
  10887. }
  10888. return fn(event, ...args);
  10889. };
  10890. };
  10891. // Kept for 2.x compat.
  10892. // Note: IE11 compat for `spacebar` and `del` is removed for now.
  10893. const keyNames = {
  10894. esc: 'escape',
  10895. space: ' ',
  10896. up: 'arrow-up',
  10897. left: 'arrow-left',
  10898. right: 'arrow-right',
  10899. down: 'arrow-down',
  10900. delete: 'backspace'
  10901. };
  10902. /**
  10903. * @private
  10904. */
  10905. const withKeys = (fn, modifiers) => {
  10906. return (event) => {
  10907. if (!('key' in event)) {
  10908. return;
  10909. }
  10910. const eventKey = hyphenate(event.key);
  10911. if (modifiers.some(k => k === eventKey || keyNames[k] === eventKey)) {
  10912. return fn(event);
  10913. }
  10914. };
  10915. };
  10916. const vShow = {
  10917. beforeMount(el, { value }, { transition }) {
  10918. el._vod = el.style.display === 'none' ? '' : el.style.display;
  10919. if (transition && value) {
  10920. transition.beforeEnter(el);
  10921. }
  10922. else {
  10923. setDisplay(el, value);
  10924. }
  10925. },
  10926. mounted(el, { value }, { transition }) {
  10927. if (transition && value) {
  10928. transition.enter(el);
  10929. }
  10930. },
  10931. updated(el, { value, oldValue }, { transition }) {
  10932. if (!value === !oldValue)
  10933. return;
  10934. if (transition) {
  10935. if (value) {
  10936. transition.beforeEnter(el);
  10937. setDisplay(el, true);
  10938. transition.enter(el);
  10939. }
  10940. else {
  10941. transition.leave(el, () => {
  10942. setDisplay(el, false);
  10943. });
  10944. }
  10945. }
  10946. else {
  10947. setDisplay(el, value);
  10948. }
  10949. },
  10950. beforeUnmount(el, { value }) {
  10951. setDisplay(el, value);
  10952. }
  10953. };
  10954. function setDisplay(el, value) {
  10955. el.style.display = value ? el._vod : 'none';
  10956. }
  10957. // SSR vnode transforms, only used when user includes client-oriented render
  10958. // function in SSR
  10959. function initVShowForSSR() {
  10960. vShow.getSSRProps = ({ value }) => {
  10961. if (!value) {
  10962. return { style: { display: 'none' } };
  10963. }
  10964. };
  10965. }
  10966. // fixed by xxxxxx
  10967. const rendererOptions = /*#__PURE__*/ extend({ patchProp, forcePatchProp }, nodeOps);
  10968. // lazy create the renderer - this makes core renderer logic tree-shakable
  10969. // in case the user only imports reactivity utilities from Vue.
  10970. let renderer;
  10971. let enabledHydration = false;
  10972. function ensureRenderer() {
  10973. return (renderer ||
  10974. (renderer = createRenderer(rendererOptions)));
  10975. }
  10976. function ensureHydrationRenderer() {
  10977. renderer = enabledHydration
  10978. ? renderer
  10979. : createHydrationRenderer(rendererOptions);
  10980. enabledHydration = true;
  10981. return renderer;
  10982. }
  10983. // use explicit type casts here to avoid import() calls in rolled-up d.ts
  10984. const render = ((...args) => {
  10985. ensureRenderer().render(...args);
  10986. });
  10987. const hydrate = ((...args) => {
  10988. ensureHydrationRenderer().hydrate(...args);
  10989. });
  10990. const createApp = ((...args) => {
  10991. const app = ensureRenderer().createApp(...args);
  10992. if ((process.env.NODE_ENV !== 'production')) {
  10993. injectNativeTagCheck(app);
  10994. injectCompilerOptionsCheck(app);
  10995. }
  10996. const { mount } = app;
  10997. app.mount = (containerOrSelector) => {
  10998. const container = normalizeContainer(containerOrSelector);
  10999. if (!container)
  11000. return;
  11001. const component = app._component;
  11002. if (!isFunction(component) && !component.render && !component.template) {
  11003. // __UNSAFE__
  11004. // Reason: potential execution of JS expressions in in-DOM template.
  11005. // The user must make sure the in-DOM template is trusted. If it's
  11006. // rendered by the server, the template should not contain any user data.
  11007. component.template = container.innerHTML;
  11008. }
  11009. // clear content before mounting
  11010. container.innerHTML = '';
  11011. const proxy = mount(container, false, container instanceof SVGElement);
  11012. if (container instanceof Element) {
  11013. container.removeAttribute('v-cloak');
  11014. container.setAttribute('data-v-app', '');
  11015. }
  11016. return proxy;
  11017. };
  11018. return app;
  11019. });
  11020. const createSSRApp = ((...args) => {
  11021. const app = ensureHydrationRenderer().createApp(...args);
  11022. if ((process.env.NODE_ENV !== 'production')) {
  11023. injectNativeTagCheck(app);
  11024. injectCompilerOptionsCheck(app);
  11025. }
  11026. const { mount } = app;
  11027. app.mount = (containerOrSelector) => {
  11028. const container = normalizeContainer(containerOrSelector);
  11029. if (container) {
  11030. return mount(container, true, container instanceof SVGElement);
  11031. }
  11032. };
  11033. return app;
  11034. });
  11035. function injectNativeTagCheck(app) {
  11036. // Inject `isNativeTag`
  11037. // this is used for component name validation (dev only)
  11038. Object.defineProperty(app.config, 'isNativeTag', {
  11039. value: (tag) => isHTMLTag(tag) || isSVGTag(tag),
  11040. writable: false
  11041. });
  11042. }
  11043. // dev only
  11044. function injectCompilerOptionsCheck(app) {
  11045. if (isRuntimeOnly()) {
  11046. const isCustomElement = app.config.isCustomElement;
  11047. Object.defineProperty(app.config, 'isCustomElement', {
  11048. get() {
  11049. return isCustomElement;
  11050. },
  11051. set() {
  11052. warn(`The \`isCustomElement\` config option is deprecated. Use ` +
  11053. `\`compilerOptions.isCustomElement\` instead.`);
  11054. }
  11055. });
  11056. const compilerOptions = app.config.compilerOptions;
  11057. const msg = `The \`compilerOptions\` config option is only respected when using ` +
  11058. `a build of Vue.js that includes the runtime compiler (aka "full build"). ` +
  11059. `Since you are using the runtime-only build, \`compilerOptions\` ` +
  11060. `must be passed to \`@vue/compiler-dom\` in the build setup instead.\n` +
  11061. `- For vue-loader: pass it via vue-loader's \`compilerOptions\` loader option.\n` +
  11062. `- For vue-cli: see https://cli.vuejs.org/guide/webpack.html#modifying-options-of-a-loader\n` +
  11063. `- For vite: pass it via @vitejs/plugin-vue options. See https://github.com/vitejs/vite/tree/main/packages/plugin-vue#example-for-passing-options-to-vuecompiler-dom`;
  11064. Object.defineProperty(app.config, 'compilerOptions', {
  11065. get() {
  11066. warn(msg);
  11067. return compilerOptions;
  11068. },
  11069. set() {
  11070. warn(msg);
  11071. }
  11072. });
  11073. }
  11074. }
  11075. function normalizeContainer(container) {
  11076. if (isString(container)) {
  11077. const res = document.querySelector(container);
  11078. if ((process.env.NODE_ENV !== 'production') && !res) {
  11079. warn(`Failed to mount app: mount target selector "${container}" returned null.`);
  11080. }
  11081. return res;
  11082. }
  11083. if ((process.env.NODE_ENV !== 'production') &&
  11084. window.ShadowRoot &&
  11085. container instanceof window.ShadowRoot &&
  11086. container.mode === 'closed') {
  11087. warn(`mounting on a ShadowRoot with \`{mode: "closed"}\` may lead to unpredictable bugs`);
  11088. }
  11089. return container;
  11090. }
  11091. let ssrDirectiveInitialized = false;
  11092. /**
  11093. * @internal
  11094. */
  11095. const initDirectivesForSSR = () => {
  11096. if (!ssrDirectiveInitialized) {
  11097. ssrDirectiveInitialized = true;
  11098. initVModelForSSR();
  11099. initVShowForSSR();
  11100. }
  11101. }
  11102. ;
  11103. function initDev() {
  11104. {
  11105. initCustomFormatter();
  11106. }
  11107. }
  11108. // This entry exports the runtime only, and is built as
  11109. if ((process.env.NODE_ENV !== 'production')) {
  11110. initDev();
  11111. }
  11112. const compile = () => {
  11113. if ((process.env.NODE_ENV !== 'production')) {
  11114. warn(`Runtime compilation is not supported in this build of Vue.` +
  11115. (` Configure your bundler to alias "vue" to "vue/dist/vue.esm-bundler.js".`
  11116. ) /* should not happen */);
  11117. }
  11118. };
  11119. export { BaseTransition, BaseTransitionPropsValidators, Comment, EffectScope, Fragment, KeepAlive, ReactiveEffect, Static, Suspense, Teleport, Text, Transition, TransitionGroup, VueElement, assertNumber, callWithAsyncErrorHandling, callWithErrorHandling, cloneVNode, compatUtils, compile, computed, createApp, createBlock, createCommentVNode, createElementBlock, createBaseVNode as createElementVNode, createHydrationRenderer, createPropsRestProxy, createRenderer, createSSRApp, createSlots, createStaticVNode, createTextVNode, createVNode, createApp as createVueApp, customRef, defineAsyncComponent, defineComponent, defineCustomElement, defineEmits, defineExpose, defineProps, defineSSRCustomElement, devtools, effect, effectScope, getCurrentInstance, getCurrentScope, getTransitionRawChildren, guardReactiveProps, h, handleError, hydrate, initCustomFormatter, initDirectivesForSSR, inject, injectHook, isInSSRComponentSetup, isMemoSame, isProxy, isReactive, isReadonly, isRef, isRuntimeOnly, isShallow, isVNode, markRaw, mergeDefaults, mergeProps, nextTick, onActivated, onBeforeActivate, onBeforeDeactivate, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onScopeDispose, onServerPrefetch, onUnmounted, onUpdated, openBlock, popScopeId, provide, proxyRefs, pushScopeId, queuePostFlushCb, reactive, readonly, ref, registerRuntimeCompiler, render, renderList, renderSlot, resolveComponent, resolveDirective, resolveDynamicComponent, resolveFilter, resolveTransitionHooks, setBlockTracking, setDevtoolsHook, setTransitionHooks, shallowReactive, shallowReadonly, shallowRef, ssrContextKey, ssrUtils, stop, toHandlers, toRaw, toRef, toRefs, transformVNodeArgs, triggerRef, unref, useAttrs, useCssModule, useCssVars, useSSRContext, useSlots, useTransitionState, vModelCheckbox, vModelDynamic, vModelRadio, vModelSelect, vModelText, vShow, version, warn, watch, watchEffect, watchPostEffect, watchSyncEffect, withAsyncContext, withCtx, withDefaults, withDirectives, withKeys, withMemo, withModifiers, withScopeId };