vue.runtime.cjs.js 407 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var shared = require('@vue/shared');
  4. var uniShared = require('@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 {
  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 {
  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('iterate' );
  156. const MAP_KEY_ITERATE_KEY = Symbol('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. shared.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 = { effect: activeEffect, target, type, key }
  268. ;
  269. trackEffects(dep, eventInfo);
  270. }
  271. }
  272. function trackEffects(dep, debuggerEventExtraInfo) {
  273. let shouldTrack = false;
  274. if (effectTrackDepth <= maxMarkerBits) {
  275. if (!newTracked(dep)) {
  276. dep.n |= trackOpBit; // set newly tracked
  277. shouldTrack = !wasTracked(dep);
  278. }
  279. }
  280. else {
  281. // Full cleanup mode.
  282. shouldTrack = !dep.has(activeEffect);
  283. }
  284. if (shouldTrack) {
  285. dep.add(activeEffect);
  286. activeEffect.deps.push(dep);
  287. if (activeEffect.onTrack) {
  288. activeEffect.onTrack({
  289. effect: activeEffect,
  290. ...debuggerEventExtraInfo
  291. });
  292. }
  293. }
  294. }
  295. function trigger(target, type, key, newValue, oldValue, oldTarget) {
  296. const depsMap = targetMap.get(target);
  297. if (!depsMap) {
  298. // never been tracked
  299. return;
  300. }
  301. let deps = [];
  302. if (type === "clear" /* TriggerOpTypes.CLEAR */) {
  303. // collection being cleared
  304. // trigger all effects for target
  305. deps = [...depsMap.values()];
  306. }
  307. else if (key === 'length' && shared.isArray(target)) {
  308. const newLength = Number(newValue);
  309. depsMap.forEach((dep, key) => {
  310. if (key === 'length' || key >= newLength) {
  311. deps.push(dep);
  312. }
  313. });
  314. }
  315. else {
  316. // schedule runs for SET | ADD | DELETE
  317. if (key !== void 0) {
  318. deps.push(depsMap.get(key));
  319. }
  320. // also run for iteration key on ADD | DELETE | Map.SET
  321. switch (type) {
  322. case "add" /* TriggerOpTypes.ADD */:
  323. if (!shared.isArray(target)) {
  324. deps.push(depsMap.get(ITERATE_KEY));
  325. if (shared.isMap(target)) {
  326. deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
  327. }
  328. }
  329. else if (shared.isIntegerKey(key)) {
  330. // new index added to array -> length changes
  331. deps.push(depsMap.get('length'));
  332. }
  333. break;
  334. case "delete" /* TriggerOpTypes.DELETE */:
  335. if (!shared.isArray(target)) {
  336. deps.push(depsMap.get(ITERATE_KEY));
  337. if (shared.isMap(target)) {
  338. deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
  339. }
  340. }
  341. break;
  342. case "set" /* TriggerOpTypes.SET */:
  343. if (shared.isMap(target)) {
  344. deps.push(depsMap.get(ITERATE_KEY));
  345. }
  346. break;
  347. }
  348. }
  349. const eventInfo = { target, type, key, newValue, oldValue, oldTarget }
  350. ;
  351. if (deps.length === 1) {
  352. if (deps[0]) {
  353. {
  354. triggerEffects(deps[0], eventInfo);
  355. }
  356. }
  357. }
  358. else {
  359. const effects = [];
  360. for (const dep of deps) {
  361. if (dep) {
  362. effects.push(...dep);
  363. }
  364. }
  365. {
  366. triggerEffects(createDep(effects), eventInfo);
  367. }
  368. }
  369. }
  370. function triggerEffects(dep, debuggerEventExtraInfo) {
  371. // spread into array for stabilization
  372. const effects = shared.isArray(dep) ? dep : [...dep];
  373. for (const effect of effects) {
  374. if (effect.computed) {
  375. triggerEffect(effect, debuggerEventExtraInfo);
  376. }
  377. }
  378. for (const effect of effects) {
  379. if (!effect.computed) {
  380. triggerEffect(effect, debuggerEventExtraInfo);
  381. }
  382. }
  383. }
  384. function triggerEffect(effect, debuggerEventExtraInfo) {
  385. if (effect !== activeEffect || effect.allowRecurse) {
  386. if (effect.onTrigger) {
  387. effect.onTrigger(shared.extend({ effect }, debuggerEventExtraInfo));
  388. }
  389. if (effect.scheduler) {
  390. effect.scheduler();
  391. }
  392. else {
  393. effect.run();
  394. }
  395. }
  396. }
  397. function getDepFromReactive(object, key) {
  398. var _a;
  399. return (_a = targetMap.get(object)) === null || _a === void 0 ? void 0 : _a.get(key);
  400. }
  401. const isNonTrackableKeys = /*#__PURE__*/ shared.makeMap(`__proto__,__v_isRef,__isVue`);
  402. const builtInSymbols = new Set(
  403. /*#__PURE__*/
  404. Object.getOwnPropertyNames(Symbol)
  405. // ios10.x Object.getOwnPropertyNames(Symbol) can enumerate 'arguments' and 'caller'
  406. // but accessing them on Symbol leads to TypeError because Symbol is a strict mode
  407. // function
  408. .filter(key => key !== 'arguments' && key !== 'caller')
  409. .map(key => Symbol[key])
  410. .filter(shared.isSymbol));
  411. const get$1 = /*#__PURE__*/ createGetter();
  412. const shallowGet = /*#__PURE__*/ createGetter(false, true);
  413. const readonlyGet = /*#__PURE__*/ createGetter(true);
  414. const shallowReadonlyGet = /*#__PURE__*/ createGetter(true, true);
  415. const arrayInstrumentations = /*#__PURE__*/ createArrayInstrumentations();
  416. function createArrayInstrumentations() {
  417. const instrumentations = {};
  418. ['includes', 'indexOf', 'lastIndexOf'].forEach(key => {
  419. instrumentations[key] = function (...args) {
  420. const arr = toRaw(this);
  421. for (let i = 0, l = this.length; i < l; i++) {
  422. track(arr, "get" /* TrackOpTypes.GET */, i + '');
  423. }
  424. // we run the method using the original args first (which may be reactive)
  425. const res = arr[key](...args);
  426. if (res === -1 || res === false) {
  427. // if that didn't work, run it again using raw values.
  428. return arr[key](...args.map(toRaw));
  429. }
  430. else {
  431. return res;
  432. }
  433. };
  434. });
  435. ['push', 'pop', 'shift', 'unshift', 'splice'].forEach(key => {
  436. instrumentations[key] = function (...args) {
  437. pauseTracking();
  438. const res = toRaw(this)[key].apply(this, args);
  439. resetTracking();
  440. return res;
  441. };
  442. });
  443. return instrumentations;
  444. }
  445. function hasOwnProperty(key) {
  446. const obj = toRaw(this);
  447. track(obj, "has" /* TrackOpTypes.HAS */, key);
  448. return obj.hasOwnProperty(key);
  449. }
  450. function createGetter(isReadonly = false, shallow = false) {
  451. return function get(target, key, receiver) {
  452. if (key === "__v_isReactive" /* ReactiveFlags.IS_REACTIVE */) {
  453. return !isReadonly;
  454. }
  455. else if (key === "__v_isReadonly" /* ReactiveFlags.IS_READONLY */) {
  456. return isReadonly;
  457. }
  458. else if (key === "__v_isShallow" /* ReactiveFlags.IS_SHALLOW */) {
  459. return shallow;
  460. }
  461. else if (key === "__v_raw" /* ReactiveFlags.RAW */ &&
  462. receiver ===
  463. (isReadonly
  464. ? shallow
  465. ? shallowReadonlyMap
  466. : readonlyMap
  467. : shallow
  468. ? shallowReactiveMap
  469. : reactiveMap).get(target)) {
  470. return target;
  471. }
  472. const targetIsArray = shared.isArray(target);
  473. if (!isReadonly) {
  474. if (targetIsArray && shared.hasOwn(arrayInstrumentations, key)) {
  475. return Reflect.get(arrayInstrumentations, key, receiver);
  476. }
  477. if (key === 'hasOwnProperty') {
  478. return hasOwnProperty;
  479. }
  480. }
  481. const res = Reflect.get(target, key, receiver);
  482. if (shared.isSymbol(key) ? builtInSymbols.has(key) : isNonTrackableKeys(key)) {
  483. return res;
  484. }
  485. if (!isReadonly) {
  486. track(target, "get" /* TrackOpTypes.GET */, key);
  487. }
  488. if (shallow) {
  489. return res;
  490. }
  491. if (isRef(res)) {
  492. // ref unwrapping - skip unwrap for Array + integer key.
  493. return targetIsArray && shared.isIntegerKey(key) ? res : res.value;
  494. }
  495. if (shared.isObject(res)) {
  496. // Convert returned value into a proxy as well. we do the isObject check
  497. // here to avoid invalid value warning. Also need to lazy access readonly
  498. // and reactive here to avoid circular dependency.
  499. return isReadonly ? readonly(res) : reactive(res);
  500. }
  501. return res;
  502. };
  503. }
  504. const set$1 = /*#__PURE__*/ createSetter();
  505. const shallowSet = /*#__PURE__*/ createSetter(true);
  506. function createSetter(shallow = false) {
  507. return function set(target, key, value, receiver) {
  508. let oldValue = target[key];
  509. if (isReadonly(oldValue) && isRef(oldValue) && !isRef(value)) {
  510. return false;
  511. }
  512. if (!shallow) {
  513. if (!isShallow(value) && !isReadonly(value)) {
  514. oldValue = toRaw(oldValue);
  515. value = toRaw(value);
  516. }
  517. if (!shared.isArray(target) && isRef(oldValue) && !isRef(value)) {
  518. oldValue.value = value;
  519. return true;
  520. }
  521. }
  522. const hadKey = shared.isArray(target) && shared.isIntegerKey(key)
  523. ? Number(key) < target.length
  524. : shared.hasOwn(target, key);
  525. const result = Reflect.set(target, key, value, receiver);
  526. // don't trigger if target is something up in the prototype chain of original
  527. if (target === toRaw(receiver)) {
  528. if (!hadKey) {
  529. trigger(target, "add" /* TriggerOpTypes.ADD */, key, value);
  530. }
  531. else if (shared.hasChanged(value, oldValue)) {
  532. trigger(target, "set" /* TriggerOpTypes.SET */, key, value, oldValue);
  533. }
  534. }
  535. return result;
  536. };
  537. }
  538. function deleteProperty(target, key) {
  539. const hadKey = shared.hasOwn(target, key);
  540. const oldValue = target[key];
  541. const result = Reflect.deleteProperty(target, key);
  542. if (result && hadKey) {
  543. trigger(target, "delete" /* TriggerOpTypes.DELETE */, key, undefined, oldValue);
  544. }
  545. return result;
  546. }
  547. function has$1(target, key) {
  548. const result = Reflect.has(target, key);
  549. if (!shared.isSymbol(key) || !builtInSymbols.has(key)) {
  550. track(target, "has" /* TrackOpTypes.HAS */, key);
  551. }
  552. return result;
  553. }
  554. function ownKeys(target) {
  555. track(target, "iterate" /* TrackOpTypes.ITERATE */, shared.isArray(target) ? 'length' : ITERATE_KEY);
  556. return Reflect.ownKeys(target);
  557. }
  558. const mutableHandlers = {
  559. get: get$1,
  560. set: set$1,
  561. deleteProperty,
  562. has: has$1,
  563. ownKeys
  564. };
  565. const readonlyHandlers = {
  566. get: readonlyGet,
  567. set(target, key) {
  568. {
  569. warn$1(`Set operation on key "${String(key)}" failed: target is readonly.`, target);
  570. }
  571. return true;
  572. },
  573. deleteProperty(target, key) {
  574. {
  575. warn$1(`Delete operation on key "${String(key)}" failed: target is readonly.`, target);
  576. }
  577. return true;
  578. }
  579. };
  580. const shallowReactiveHandlers = /*#__PURE__*/ shared.extend({}, mutableHandlers, {
  581. get: shallowGet,
  582. set: shallowSet
  583. });
  584. // Props handlers are special in the sense that it should not unwrap top-level
  585. // refs (in order to allow refs to be explicitly passed down), but should
  586. // retain the reactivity of the normal readonly object.
  587. const shallowReadonlyHandlers = /*#__PURE__*/ shared.extend({}, readonlyHandlers, {
  588. get: shallowReadonlyGet
  589. });
  590. const toShallow = (value) => value;
  591. const getProto = (v) => Reflect.getPrototypeOf(v);
  592. function get(target, key, isReadonly = false, isShallow = false) {
  593. // #1772: readonly(reactive(Map)) should return readonly + reactive version
  594. // of the value
  595. target = target["__v_raw" /* ReactiveFlags.RAW */];
  596. const rawTarget = toRaw(target);
  597. const rawKey = toRaw(key);
  598. if (!isReadonly) {
  599. if (key !== rawKey) {
  600. track(rawTarget, "get" /* TrackOpTypes.GET */, key);
  601. }
  602. track(rawTarget, "get" /* TrackOpTypes.GET */, rawKey);
  603. }
  604. const { has } = getProto(rawTarget);
  605. const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
  606. if (has.call(rawTarget, key)) {
  607. return wrap(target.get(key));
  608. }
  609. else if (has.call(rawTarget, rawKey)) {
  610. return wrap(target.get(rawKey));
  611. }
  612. else if (target !== rawTarget) {
  613. // #3602 readonly(reactive(Map))
  614. // ensure that the nested reactive `Map` can do tracking for itself
  615. target.get(key);
  616. }
  617. }
  618. function has(key, isReadonly = false) {
  619. const target = this["__v_raw" /* ReactiveFlags.RAW */];
  620. const rawTarget = toRaw(target);
  621. const rawKey = toRaw(key);
  622. if (!isReadonly) {
  623. if (key !== rawKey) {
  624. track(rawTarget, "has" /* TrackOpTypes.HAS */, key);
  625. }
  626. track(rawTarget, "has" /* TrackOpTypes.HAS */, rawKey);
  627. }
  628. return key === rawKey
  629. ? target.has(key)
  630. : target.has(key) || target.has(rawKey);
  631. }
  632. function size(target, isReadonly = false) {
  633. target = target["__v_raw" /* ReactiveFlags.RAW */];
  634. !isReadonly && track(toRaw(target), "iterate" /* TrackOpTypes.ITERATE */, ITERATE_KEY);
  635. return Reflect.get(target, 'size', target);
  636. }
  637. function add(value) {
  638. value = toRaw(value);
  639. const target = toRaw(this);
  640. const proto = getProto(target);
  641. const hadKey = proto.has.call(target, value);
  642. if (!hadKey) {
  643. target.add(value);
  644. trigger(target, "add" /* TriggerOpTypes.ADD */, value, value);
  645. }
  646. return this;
  647. }
  648. function set(key, value) {
  649. value = toRaw(value);
  650. const target = toRaw(this);
  651. const { has, get } = getProto(target);
  652. let hadKey = has.call(target, key);
  653. if (!hadKey) {
  654. key = toRaw(key);
  655. hadKey = has.call(target, key);
  656. }
  657. else {
  658. checkIdentityKeys(target, has, key);
  659. }
  660. const oldValue = get.call(target, key);
  661. target.set(key, value);
  662. if (!hadKey) {
  663. trigger(target, "add" /* TriggerOpTypes.ADD */, key, value);
  664. }
  665. else if (shared.hasChanged(value, oldValue)) {
  666. trigger(target, "set" /* TriggerOpTypes.SET */, key, value, oldValue);
  667. }
  668. return this;
  669. }
  670. function deleteEntry(key) {
  671. const target = toRaw(this);
  672. const { has, get } = getProto(target);
  673. let hadKey = has.call(target, key);
  674. if (!hadKey) {
  675. key = toRaw(key);
  676. hadKey = has.call(target, key);
  677. }
  678. else {
  679. checkIdentityKeys(target, has, key);
  680. }
  681. const oldValue = get ? get.call(target, key) : undefined;
  682. // forward the operation before queueing reactions
  683. const result = target.delete(key);
  684. if (hadKey) {
  685. trigger(target, "delete" /* TriggerOpTypes.DELETE */, key, undefined, oldValue);
  686. }
  687. return result;
  688. }
  689. function clear() {
  690. const target = toRaw(this);
  691. const hadItems = target.size !== 0;
  692. const oldTarget = shared.isMap(target)
  693. ? new Map(target)
  694. : new Set(target)
  695. ;
  696. // forward the operation before queueing reactions
  697. const result = target.clear();
  698. if (hadItems) {
  699. trigger(target, "clear" /* TriggerOpTypes.CLEAR */, undefined, undefined, oldTarget);
  700. }
  701. return result;
  702. }
  703. function createForEach(isReadonly, isShallow) {
  704. return function forEach(callback, thisArg) {
  705. const observed = this;
  706. const target = observed["__v_raw" /* ReactiveFlags.RAW */];
  707. const rawTarget = toRaw(target);
  708. const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
  709. !isReadonly && track(rawTarget, "iterate" /* TrackOpTypes.ITERATE */, ITERATE_KEY);
  710. return target.forEach((value, key) => {
  711. // important: make sure the callback is
  712. // 1. invoked with the reactive map as `this` and 3rd arg
  713. // 2. the value received should be a corresponding reactive/readonly.
  714. return callback.call(thisArg, wrap(value), wrap(key), observed);
  715. });
  716. };
  717. }
  718. function createIterableMethod(method, isReadonly, isShallow) {
  719. return function (...args) {
  720. const target = this["__v_raw" /* ReactiveFlags.RAW */];
  721. const rawTarget = toRaw(target);
  722. const targetIsMap = shared.isMap(rawTarget);
  723. const isPair = method === 'entries' || (method === Symbol.iterator && targetIsMap);
  724. const isKeyOnly = method === 'keys' && targetIsMap;
  725. const innerIterator = target[method](...args);
  726. const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
  727. !isReadonly &&
  728. track(rawTarget, "iterate" /* TrackOpTypes.ITERATE */, isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY);
  729. // return a wrapped iterator which returns observed versions of the
  730. // values emitted from the real iterator
  731. return {
  732. // iterator protocol
  733. next() {
  734. const { value, done } = innerIterator.next();
  735. return done
  736. ? { value, done }
  737. : {
  738. value: isPair ? [wrap(value[0]), wrap(value[1])] : wrap(value),
  739. done
  740. };
  741. },
  742. // iterable protocol
  743. [Symbol.iterator]() {
  744. return this;
  745. }
  746. };
  747. };
  748. }
  749. function createReadonlyMethod(type) {
  750. return function (...args) {
  751. {
  752. const key = args[0] ? `on key "${args[0]}" ` : ``;
  753. console.warn(`${shared.capitalize(type)} operation ${key}failed: target is readonly.`, toRaw(this));
  754. }
  755. return type === "delete" /* TriggerOpTypes.DELETE */ ? false : this;
  756. };
  757. }
  758. function createInstrumentations() {
  759. const mutableInstrumentations = {
  760. get(key) {
  761. return get(this, key);
  762. },
  763. get size() {
  764. return size(this);
  765. },
  766. has,
  767. add,
  768. set,
  769. delete: deleteEntry,
  770. clear,
  771. forEach: createForEach(false, false)
  772. };
  773. const shallowInstrumentations = {
  774. get(key) {
  775. return get(this, key, false, true);
  776. },
  777. get size() {
  778. return size(this);
  779. },
  780. has,
  781. add,
  782. set,
  783. delete: deleteEntry,
  784. clear,
  785. forEach: createForEach(false, true)
  786. };
  787. const readonlyInstrumentations = {
  788. get(key) {
  789. return get(this, key, true);
  790. },
  791. get size() {
  792. return size(this, true);
  793. },
  794. has(key) {
  795. return has.call(this, key, true);
  796. },
  797. add: createReadonlyMethod("add" /* TriggerOpTypes.ADD */),
  798. set: createReadonlyMethod("set" /* TriggerOpTypes.SET */),
  799. delete: createReadonlyMethod("delete" /* TriggerOpTypes.DELETE */),
  800. clear: createReadonlyMethod("clear" /* TriggerOpTypes.CLEAR */),
  801. forEach: createForEach(true, false)
  802. };
  803. const shallowReadonlyInstrumentations = {
  804. get(key) {
  805. return get(this, key, true, true);
  806. },
  807. get size() {
  808. return size(this, true);
  809. },
  810. has(key) {
  811. return has.call(this, key, true);
  812. },
  813. add: createReadonlyMethod("add" /* TriggerOpTypes.ADD */),
  814. set: createReadonlyMethod("set" /* TriggerOpTypes.SET */),
  815. delete: createReadonlyMethod("delete" /* TriggerOpTypes.DELETE */),
  816. clear: createReadonlyMethod("clear" /* TriggerOpTypes.CLEAR */),
  817. forEach: createForEach(true, true)
  818. };
  819. const iteratorMethods = ['keys', 'values', 'entries', Symbol.iterator];
  820. iteratorMethods.forEach(method => {
  821. mutableInstrumentations[method] = createIterableMethod(method, false, false);
  822. readonlyInstrumentations[method] = createIterableMethod(method, true, false);
  823. shallowInstrumentations[method] = createIterableMethod(method, false, true);
  824. shallowReadonlyInstrumentations[method] = createIterableMethod(method, true, true);
  825. });
  826. return [
  827. mutableInstrumentations,
  828. readonlyInstrumentations,
  829. shallowInstrumentations,
  830. shallowReadonlyInstrumentations
  831. ];
  832. }
  833. const [mutableInstrumentations, readonlyInstrumentations, shallowInstrumentations, shallowReadonlyInstrumentations] = /* #__PURE__*/ createInstrumentations();
  834. function createInstrumentationGetter(isReadonly, shallow) {
  835. const instrumentations = shallow
  836. ? isReadonly
  837. ? shallowReadonlyInstrumentations
  838. : shallowInstrumentations
  839. : isReadonly
  840. ? readonlyInstrumentations
  841. : mutableInstrumentations;
  842. return (target, key, receiver) => {
  843. if (key === "__v_isReactive" /* ReactiveFlags.IS_REACTIVE */) {
  844. return !isReadonly;
  845. }
  846. else if (key === "__v_isReadonly" /* ReactiveFlags.IS_READONLY */) {
  847. return isReadonly;
  848. }
  849. else if (key === "__v_raw" /* ReactiveFlags.RAW */) {
  850. return target;
  851. }
  852. return Reflect.get(shared.hasOwn(instrumentations, key) && key in target
  853. ? instrumentations
  854. : target, key, receiver);
  855. };
  856. }
  857. const mutableCollectionHandlers = {
  858. get: /*#__PURE__*/ createInstrumentationGetter(false, false)
  859. };
  860. const shallowCollectionHandlers = {
  861. get: /*#__PURE__*/ createInstrumentationGetter(false, true)
  862. };
  863. const readonlyCollectionHandlers = {
  864. get: /*#__PURE__*/ createInstrumentationGetter(true, false)
  865. };
  866. const shallowReadonlyCollectionHandlers = {
  867. get: /*#__PURE__*/ createInstrumentationGetter(true, true)
  868. };
  869. function checkIdentityKeys(target, has, key) {
  870. const rawKey = toRaw(key);
  871. if (rawKey !== key && has.call(target, rawKey)) {
  872. const type = shared.toRawType(target);
  873. console.warn(`Reactive ${type} contains both the raw and reactive ` +
  874. `versions of the same object${type === `Map` ? ` as keys` : ``}, ` +
  875. `which can lead to inconsistencies. ` +
  876. `Avoid differentiating between the raw and reactive versions ` +
  877. `of an object and only use the reactive version if possible.`);
  878. }
  879. }
  880. const reactiveMap = new WeakMap();
  881. const shallowReactiveMap = new WeakMap();
  882. const readonlyMap = new WeakMap();
  883. const shallowReadonlyMap = new WeakMap();
  884. function targetTypeMap(rawType) {
  885. switch (rawType) {
  886. case 'Object':
  887. case 'Array':
  888. return 1 /* TargetType.COMMON */;
  889. case 'Map':
  890. case 'Set':
  891. case 'WeakMap':
  892. case 'WeakSet':
  893. return 2 /* TargetType.COLLECTION */;
  894. default:
  895. return 0 /* TargetType.INVALID */;
  896. }
  897. }
  898. function getTargetType(value) {
  899. return value["__v_skip" /* ReactiveFlags.SKIP */] || !Object.isExtensible(value)
  900. ? 0 /* TargetType.INVALID */
  901. : targetTypeMap(shared.toRawType(value));
  902. }
  903. function reactive(target) {
  904. // if trying to observe a readonly proxy, return the readonly version.
  905. if (isReadonly(target)) {
  906. return target;
  907. }
  908. return createReactiveObject(target, false, mutableHandlers, mutableCollectionHandlers, reactiveMap);
  909. }
  910. /**
  911. * Return a shallowly-reactive copy of the original object, where only the root
  912. * level properties are reactive. It also does not auto-unwrap refs (even at the
  913. * root level).
  914. */
  915. function shallowReactive(target) {
  916. return createReactiveObject(target, false, shallowReactiveHandlers, shallowCollectionHandlers, shallowReactiveMap);
  917. }
  918. /**
  919. * Creates a readonly copy of the original object. Note the returned copy is not
  920. * made reactive, but `readonly` can be called on an already reactive object.
  921. */
  922. function readonly(target) {
  923. return createReactiveObject(target, true, readonlyHandlers, readonlyCollectionHandlers, readonlyMap);
  924. }
  925. /**
  926. * Returns a reactive-copy of the original object, where only the root level
  927. * properties are readonly, and does NOT unwrap refs nor recursively convert
  928. * returned properties.
  929. * This is used for creating the props proxy object for stateful components.
  930. */
  931. function shallowReadonly(target) {
  932. return createReactiveObject(target, true, shallowReadonlyHandlers, shallowReadonlyCollectionHandlers, shallowReadonlyMap);
  933. }
  934. function createReactiveObject(target, isReadonly, baseHandlers, collectionHandlers, proxyMap) {
  935. if (!shared.isObject(target)) {
  936. {
  937. console.warn(`value cannot be made reactive: ${String(target)}`);
  938. }
  939. return target;
  940. }
  941. // target is already a Proxy, return it.
  942. // exception: calling readonly() on a reactive object
  943. if (target["__v_raw" /* ReactiveFlags.RAW */] &&
  944. !(isReadonly && target["__v_isReactive" /* ReactiveFlags.IS_REACTIVE */])) {
  945. return target;
  946. }
  947. // target already has corresponding Proxy
  948. const existingProxy = proxyMap.get(target);
  949. if (existingProxy) {
  950. return existingProxy;
  951. }
  952. // only specific value types can be observed.
  953. const targetType = getTargetType(target);
  954. if (targetType === 0 /* TargetType.INVALID */) {
  955. return target;
  956. }
  957. const proxy = new Proxy(target, targetType === 2 /* TargetType.COLLECTION */ ? collectionHandlers : baseHandlers);
  958. proxyMap.set(target, proxy);
  959. return proxy;
  960. }
  961. function isReactive(value) {
  962. if (isReadonly(value)) {
  963. return isReactive(value["__v_raw" /* ReactiveFlags.RAW */]);
  964. }
  965. return !!(value && value["__v_isReactive" /* ReactiveFlags.IS_REACTIVE */]);
  966. }
  967. function isReadonly(value) {
  968. return !!(value && value["__v_isReadonly" /* ReactiveFlags.IS_READONLY */]);
  969. }
  970. function isShallow(value) {
  971. return !!(value && value["__v_isShallow" /* ReactiveFlags.IS_SHALLOW */]);
  972. }
  973. function isProxy(value) {
  974. return isReactive(value) || isReadonly(value);
  975. }
  976. function toRaw(observed) {
  977. const raw = observed && observed["__v_raw" /* ReactiveFlags.RAW */];
  978. return raw ? toRaw(raw) : observed;
  979. }
  980. function markRaw(value) {
  981. shared.def(value, "__v_skip" /* ReactiveFlags.SKIP */, true);
  982. return value;
  983. }
  984. const toReactive = (value) => shared.isObject(value) ? reactive(value) : value;
  985. const toReadonly = (value) => shared.isObject(value) ? readonly(value) : value;
  986. function trackRefValue(ref) {
  987. if (shouldTrack && activeEffect) {
  988. ref = toRaw(ref);
  989. {
  990. trackEffects(ref.dep || (ref.dep = createDep()), {
  991. target: ref,
  992. type: "get" /* TrackOpTypes.GET */,
  993. key: 'value'
  994. });
  995. }
  996. }
  997. }
  998. function triggerRefValue(ref, newVal) {
  999. ref = toRaw(ref);
  1000. const dep = ref.dep;
  1001. if (dep) {
  1002. {
  1003. triggerEffects(dep, {
  1004. target: ref,
  1005. type: "set" /* TriggerOpTypes.SET */,
  1006. key: 'value',
  1007. newValue: newVal
  1008. });
  1009. }
  1010. }
  1011. }
  1012. function isRef(r) {
  1013. return !!(r && r.__v_isRef === true);
  1014. }
  1015. function ref(value) {
  1016. return createRef(value, false);
  1017. }
  1018. function shallowRef(value) {
  1019. return createRef(value, true);
  1020. }
  1021. function createRef(rawValue, shallow) {
  1022. if (isRef(rawValue)) {
  1023. return rawValue;
  1024. }
  1025. return new RefImpl(rawValue, shallow);
  1026. }
  1027. class RefImpl {
  1028. constructor(value, __v_isShallow) {
  1029. this.__v_isShallow = __v_isShallow;
  1030. this.dep = undefined;
  1031. this.__v_isRef = true;
  1032. this._rawValue = __v_isShallow ? value : toRaw(value);
  1033. this._value = __v_isShallow ? value : toReactive(value);
  1034. }
  1035. get value() {
  1036. trackRefValue(this);
  1037. return this._value;
  1038. }
  1039. set value(newVal) {
  1040. const useDirectValue = this.__v_isShallow || isShallow(newVal) || isReadonly(newVal);
  1041. newVal = useDirectValue ? newVal : toRaw(newVal);
  1042. if (shared.hasChanged(newVal, this._rawValue)) {
  1043. this._rawValue = newVal;
  1044. this._value = useDirectValue ? newVal : toReactive(newVal);
  1045. triggerRefValue(this, newVal);
  1046. }
  1047. }
  1048. }
  1049. function triggerRef(ref) {
  1050. triggerRefValue(ref, ref.value );
  1051. }
  1052. function unref(ref) {
  1053. return isRef(ref) ? ref.value : ref;
  1054. }
  1055. const shallowUnwrapHandlers = {
  1056. get: (target, key, receiver) => unref(Reflect.get(target, key, receiver)),
  1057. set: (target, key, value, receiver) => {
  1058. const oldValue = target[key];
  1059. if (isRef(oldValue) && !isRef(value)) {
  1060. oldValue.value = value;
  1061. return true;
  1062. }
  1063. else {
  1064. return Reflect.set(target, key, value, receiver);
  1065. }
  1066. }
  1067. };
  1068. function proxyRefs(objectWithRefs) {
  1069. return isReactive(objectWithRefs)
  1070. ? objectWithRefs
  1071. : new Proxy(objectWithRefs, shallowUnwrapHandlers);
  1072. }
  1073. class CustomRefImpl {
  1074. constructor(factory) {
  1075. this.dep = undefined;
  1076. this.__v_isRef = true;
  1077. const { get, set } = factory(() => trackRefValue(this), () => triggerRefValue(this));
  1078. this._get = get;
  1079. this._set = set;
  1080. }
  1081. get value() {
  1082. return this._get();
  1083. }
  1084. set value(newVal) {
  1085. this._set(newVal);
  1086. }
  1087. }
  1088. function customRef(factory) {
  1089. return new CustomRefImpl(factory);
  1090. }
  1091. function toRefs(object) {
  1092. if (!isProxy(object)) {
  1093. console.warn(`toRefs() expects a reactive object but received a plain one.`);
  1094. }
  1095. const ret = shared.isArray(object) ? new Array(object.length) : {};
  1096. for (const key in object) {
  1097. ret[key] = toRef(object, key);
  1098. }
  1099. return ret;
  1100. }
  1101. class ObjectRefImpl {
  1102. constructor(_object, _key, _defaultValue) {
  1103. this._object = _object;
  1104. this._key = _key;
  1105. this._defaultValue = _defaultValue;
  1106. this.__v_isRef = true;
  1107. }
  1108. get value() {
  1109. const val = this._object[this._key];
  1110. return val === undefined ? this._defaultValue : val;
  1111. }
  1112. set value(newVal) {
  1113. this._object[this._key] = newVal;
  1114. }
  1115. get dep() {
  1116. return getDepFromReactive(toRaw(this._object), this._key);
  1117. }
  1118. }
  1119. function toRef(object, key, defaultValue) {
  1120. const val = object[key];
  1121. return isRef(val)
  1122. ? val
  1123. : new ObjectRefImpl(object, key, defaultValue);
  1124. }
  1125. var _a;
  1126. class ComputedRefImpl {
  1127. constructor(getter, _setter, isReadonly, isSSR) {
  1128. this._setter = _setter;
  1129. this.dep = undefined;
  1130. this.__v_isRef = true;
  1131. this[_a] = false;
  1132. this._dirty = true;
  1133. this.effect = new ReactiveEffect(getter, () => {
  1134. if (!this._dirty) {
  1135. this._dirty = true;
  1136. triggerRefValue(this);
  1137. }
  1138. });
  1139. this.effect.computed = this;
  1140. this.effect.active = this._cacheable = !isSSR;
  1141. this["__v_isReadonly" /* ReactiveFlags.IS_READONLY */] = isReadonly;
  1142. }
  1143. get value() {
  1144. // the computed ref may get wrapped by other proxies e.g. readonly() #3376
  1145. const self = toRaw(this);
  1146. trackRefValue(self);
  1147. if (self._dirty || !self._cacheable) {
  1148. self._dirty = false;
  1149. self._value = self.effect.run();
  1150. }
  1151. return self._value;
  1152. }
  1153. set value(newValue) {
  1154. this._setter(newValue);
  1155. }
  1156. }
  1157. _a = "__v_isReadonly" /* ReactiveFlags.IS_READONLY */;
  1158. function computed$1(getterOrOptions, debugOptions, isSSR = false) {
  1159. let getter;
  1160. let setter;
  1161. const onlyGetter = shared.isFunction(getterOrOptions);
  1162. if (onlyGetter) {
  1163. getter = getterOrOptions;
  1164. setter = () => {
  1165. console.warn('Write operation failed: computed value is readonly');
  1166. }
  1167. ;
  1168. }
  1169. else {
  1170. getter = getterOrOptions.get;
  1171. setter = getterOrOptions.set;
  1172. }
  1173. const cRef = new ComputedRefImpl(getter, setter, onlyGetter || !setter, isSSR);
  1174. if (debugOptions && !isSSR) {
  1175. cRef.effect.onTrack = debugOptions.onTrack;
  1176. cRef.effect.onTrigger = debugOptions.onTrigger;
  1177. }
  1178. return cRef;
  1179. }
  1180. const stack = [];
  1181. function pushWarningContext(vnode) {
  1182. stack.push(vnode);
  1183. }
  1184. function popWarningContext() {
  1185. stack.pop();
  1186. }
  1187. function warn(msg, ...args) {
  1188. // avoid props formatting or warn handler tracking deps that might be mutated
  1189. // during patch, leading to infinite recursion.
  1190. pauseTracking();
  1191. const instance = stack.length ? stack[stack.length - 1].component : null;
  1192. const appWarnHandler = instance && instance.appContext.config.warnHandler;
  1193. const trace = getComponentTrace();
  1194. if (appWarnHandler) {
  1195. // fixed by xxxxxx Cannot convert a Symbol value to a string
  1196. if (args.length) {
  1197. args[0] = String(args[0]);
  1198. }
  1199. callWithErrorHandling(appWarnHandler, instance, 11 /* ErrorCodes.APP_WARN_HANDLER */, [
  1200. msg + args.join(''),
  1201. instance && instance.proxy,
  1202. trace
  1203. .map(({ vnode }) => `at <${formatComponentName(instance, vnode.type)}>`)
  1204. .join('\n'),
  1205. trace
  1206. ]);
  1207. }
  1208. else {
  1209. const warnArgs = [`[Vue warn]: ${msg}`, ...args];
  1210. /* istanbul ignore if */
  1211. if (trace.length &&
  1212. // avoid spamming console during tests
  1213. !false) {
  1214. warnArgs.push(`\n`, ...formatTrace(trace));
  1215. }
  1216. console.warn(...warnArgs);
  1217. }
  1218. resetTracking();
  1219. }
  1220. function getComponentTrace() {
  1221. let currentVNode = stack[stack.length - 1];
  1222. if (!currentVNode) {
  1223. return [];
  1224. }
  1225. // we can't just use the stack because it will be incomplete during updates
  1226. // that did not start from the root. Re-construct the parent chain using
  1227. // instance parent pointers.
  1228. const normalizedStack = [];
  1229. while (currentVNode) {
  1230. const last = normalizedStack[0];
  1231. if (last && last.vnode === currentVNode) {
  1232. last.recurseCount++;
  1233. }
  1234. else {
  1235. normalizedStack.push({
  1236. vnode: currentVNode,
  1237. recurseCount: 0
  1238. });
  1239. }
  1240. const parentInstance = currentVNode.component && currentVNode.component.parent;
  1241. currentVNode = parentInstance && parentInstance.vnode;
  1242. }
  1243. return normalizedStack;
  1244. }
  1245. /* istanbul ignore next */
  1246. function formatTrace(trace) {
  1247. const logs = [];
  1248. trace.forEach((entry, i) => {
  1249. logs.push(...(i === 0 ? [] : [`\n`]), ...formatTraceEntry(entry));
  1250. });
  1251. return logs;
  1252. }
  1253. function formatTraceEntry({ vnode, recurseCount }) {
  1254. const postfix = recurseCount > 0 ? `... (${recurseCount} recursive calls)` : ``;
  1255. const isRoot = vnode.component ? vnode.component.parent == null : false;
  1256. const open = ` at <${formatComponentName(vnode.component, vnode.type, isRoot)}`;
  1257. const close = `>` + postfix;
  1258. return vnode.props
  1259. ? [open, ...formatProps(vnode.props), close]
  1260. : [open + close];
  1261. }
  1262. /* istanbul ignore next */
  1263. function formatProps(props) {
  1264. const res = [];
  1265. const keys = Object.keys(props);
  1266. keys.slice(0, 3).forEach(key => {
  1267. res.push(...formatProp(key, props[key]));
  1268. });
  1269. if (keys.length > 3) {
  1270. res.push(` ...`);
  1271. }
  1272. return res;
  1273. }
  1274. /* istanbul ignore next */
  1275. function formatProp(key, value, raw) {
  1276. if (shared.isString(value)) {
  1277. value = JSON.stringify(value);
  1278. return raw ? value : [`${key}=${value}`];
  1279. }
  1280. else if (typeof value === 'number' ||
  1281. typeof value === 'boolean' ||
  1282. value == null) {
  1283. return raw ? value : [`${key}=${value}`];
  1284. }
  1285. else if (isRef(value)) {
  1286. value = formatProp(key, toRaw(value.value), true);
  1287. return raw ? value : [`${key}=Ref<`, value, `>`];
  1288. }
  1289. else if (shared.isFunction(value)) {
  1290. return [`${key}=fn${value.name ? `<${value.name}>` : ``}`];
  1291. }
  1292. else {
  1293. value = toRaw(value);
  1294. return raw ? value : [`${key}=`, value];
  1295. }
  1296. }
  1297. /**
  1298. * @internal
  1299. */
  1300. function assertNumber(val, type) {
  1301. if (val === undefined) {
  1302. return;
  1303. }
  1304. else if (typeof val !== 'number') {
  1305. warn(`${type} is not a valid number - ` + `got ${JSON.stringify(val)}.`);
  1306. }
  1307. else if (isNaN(val)) {
  1308. warn(`${type} is NaN - ` + 'the duration expression might be incorrect.');
  1309. }
  1310. }
  1311. const ErrorTypeStrings = {
  1312. ["sp" /* LifecycleHooks.SERVER_PREFETCH */]: 'serverPrefetch hook',
  1313. ["bc" /* LifecycleHooks.BEFORE_CREATE */]: 'beforeCreate hook',
  1314. ["c" /* LifecycleHooks.CREATED */]: 'created hook',
  1315. ["bm" /* LifecycleHooks.BEFORE_MOUNT */]: 'beforeMount hook',
  1316. ["m" /* LifecycleHooks.MOUNTED */]: 'mounted hook',
  1317. ["bu" /* LifecycleHooks.BEFORE_UPDATE */]: 'beforeUpdate hook',
  1318. ["u" /* LifecycleHooks.UPDATED */]: 'updated',
  1319. ["bum" /* LifecycleHooks.BEFORE_UNMOUNT */]: 'beforeUnmount hook',
  1320. ["um" /* LifecycleHooks.UNMOUNTED */]: 'unmounted hook',
  1321. ["ba" /* LifecycleHooks.BEFORE_ACTIVATE */]: 'beforeActivate hook',
  1322. ["a" /* LifecycleHooks.ACTIVATED */]: 'activated hook',
  1323. ["bda" /* LifecycleHooks.BEFORE_DEACTIVATE */]: 'beforeDeactivate hook',
  1324. ["da" /* LifecycleHooks.DEACTIVATED */]: 'deactivated hook',
  1325. ["ec" /* LifecycleHooks.ERROR_CAPTURED */]: 'errorCaptured hook',
  1326. ["rtc" /* LifecycleHooks.RENDER_TRACKED */]: 'renderTracked hook',
  1327. ["rtg" /* LifecycleHooks.RENDER_TRIGGERED */]: 'renderTriggered hook',
  1328. [0 /* ErrorCodes.SETUP_FUNCTION */]: 'setup function',
  1329. [1 /* ErrorCodes.RENDER_FUNCTION */]: 'render function',
  1330. [2 /* ErrorCodes.WATCH_GETTER */]: 'watcher getter',
  1331. [3 /* ErrorCodes.WATCH_CALLBACK */]: 'watcher callback',
  1332. [4 /* ErrorCodes.WATCH_CLEANUP */]: 'watcher cleanup function',
  1333. [5 /* ErrorCodes.NATIVE_EVENT_HANDLER */]: 'native event handler',
  1334. [6 /* ErrorCodes.COMPONENT_EVENT_HANDLER */]: 'component event handler',
  1335. [7 /* ErrorCodes.VNODE_HOOK */]: 'vnode hook',
  1336. [8 /* ErrorCodes.DIRECTIVE_HOOK */]: 'directive hook',
  1337. [9 /* ErrorCodes.TRANSITION_HOOK */]: 'transition hook',
  1338. [10 /* ErrorCodes.APP_ERROR_HANDLER */]: 'app errorHandler',
  1339. [11 /* ErrorCodes.APP_WARN_HANDLER */]: 'app warnHandler',
  1340. [12 /* ErrorCodes.FUNCTION_REF */]: 'ref function',
  1341. [13 /* ErrorCodes.ASYNC_COMPONENT_LOADER */]: 'async component loader',
  1342. [14 /* ErrorCodes.SCHEDULER */]: 'scheduler flush. This is likely a Vue internals bug. ' +
  1343. 'Please open an issue at https://new-issue.vuejs.org/?repo=vuejs/core'
  1344. };
  1345. function callWithErrorHandling(fn, instance, type, args) {
  1346. let res;
  1347. try {
  1348. res = args ? fn(...args) : fn();
  1349. }
  1350. catch (err) {
  1351. handleError(err, instance, type);
  1352. }
  1353. return res;
  1354. }
  1355. function callWithAsyncErrorHandling(fn, instance, type, args) {
  1356. if (shared.isFunction(fn)) {
  1357. const res = callWithErrorHandling(fn, instance, type, args);
  1358. if (res && shared.isPromise(res)) {
  1359. res.catch(err => {
  1360. handleError(err, instance, type);
  1361. });
  1362. }
  1363. return res;
  1364. }
  1365. const values = [];
  1366. for (let i = 0; i < fn.length; i++) {
  1367. values.push(callWithAsyncErrorHandling(fn[i], instance, type, args));
  1368. }
  1369. return values;
  1370. }
  1371. function handleError(err, instance, type, throwInDev = true) {
  1372. const contextVNode = instance ? instance.vnode : null;
  1373. if (instance) {
  1374. let cur = instance.parent;
  1375. // the exposed instance is the render proxy to keep it consistent with 2.x
  1376. const exposedInstance = instance.proxy;
  1377. // in production the hook receives only the error code
  1378. // fixed by xxxxxx
  1379. const errorInfo = ErrorTypeStrings[type] || type ;
  1380. while (cur) {
  1381. const errorCapturedHooks = cur.ec;
  1382. if (errorCapturedHooks) {
  1383. for (let i = 0; i < errorCapturedHooks.length; i++) {
  1384. if (errorCapturedHooks[i](err, exposedInstance, errorInfo) === false) {
  1385. return;
  1386. }
  1387. }
  1388. }
  1389. cur = cur.parent;
  1390. }
  1391. // app-level handling
  1392. const appErrorHandler = instance.appContext.config.errorHandler;
  1393. if (appErrorHandler) {
  1394. callWithErrorHandling(appErrorHandler, null, 10 /* ErrorCodes.APP_ERROR_HANDLER */, [err, exposedInstance, errorInfo]);
  1395. return;
  1396. }
  1397. }
  1398. logError(err, type, contextVNode, throwInDev);
  1399. }
  1400. function logError(err, type, contextVNode, throwInDev = true) {
  1401. {
  1402. const info = ErrorTypeStrings[type] || type; // fixed by xxxxxx
  1403. if (contextVNode) {
  1404. pushWarningContext(contextVNode);
  1405. }
  1406. warn(`Unhandled error${info ? ` during execution of ${info}` : ``}`);
  1407. if (contextVNode) {
  1408. popWarningContext();
  1409. }
  1410. // crash in dev by default so it's more noticeable
  1411. // 不要 crash,经常会导致整个App运行失败,比如路由跳转失败,不能返回了
  1412. /* if (throwInDev) {
  1413. throw err
  1414. } else */ {
  1415. console.error(err);
  1416. }
  1417. }
  1418. }
  1419. let isFlushing = false;
  1420. let isFlushPending = false;
  1421. const queue = [];
  1422. let flushIndex = 0;
  1423. const pendingPostFlushCbs = [];
  1424. let activePostFlushCbs = null;
  1425. let postFlushIndex = 0;
  1426. const resolvedPromise = /*#__PURE__*/ Promise.resolve();
  1427. let currentFlushPromise = null;
  1428. const RECURSION_LIMIT = 100;
  1429. function nextTick(fn) {
  1430. const p = currentFlushPromise || resolvedPromise;
  1431. return fn ? p.then(this ? fn.bind(this) : fn) : p;
  1432. }
  1433. // #2768
  1434. // Use binary-search to find a suitable position in the queue,
  1435. // so that the queue maintains the increasing order of job's id,
  1436. // which can prevent the job from being skipped and also can avoid repeated patching.
  1437. function findInsertionIndex(id) {
  1438. // the start index should be `flushIndex + 1`
  1439. let start = flushIndex + 1;
  1440. let end = queue.length;
  1441. while (start < end) {
  1442. const middle = (start + end) >>> 1;
  1443. const middleJobId = getId(queue[middle]);
  1444. middleJobId < id ? (start = middle + 1) : (end = middle);
  1445. }
  1446. return start;
  1447. }
  1448. function queueJob(job) {
  1449. // the dedupe search uses the startIndex argument of Array.includes()
  1450. // by default the search index includes the current job that is being run
  1451. // so it cannot recursively trigger itself again.
  1452. // if the job is a watch() callback, the search will start with a +1 index to
  1453. // allow it recursively trigger itself - it is the user's responsibility to
  1454. // ensure it doesn't end up in an infinite loop.
  1455. if (!queue.length ||
  1456. !queue.includes(job, isFlushing && job.allowRecurse ? flushIndex + 1 : flushIndex)) {
  1457. if (job.id == null) {
  1458. queue.push(job);
  1459. }
  1460. else {
  1461. queue.splice(findInsertionIndex(job.id), 0, job);
  1462. }
  1463. queueFlush();
  1464. }
  1465. }
  1466. function queueFlush() {
  1467. if (!isFlushing && !isFlushPending) {
  1468. isFlushPending = true;
  1469. currentFlushPromise = resolvedPromise.then(flushJobs);
  1470. }
  1471. }
  1472. function invalidateJob(job) {
  1473. const i = queue.indexOf(job);
  1474. if (i > flushIndex) {
  1475. queue.splice(i, 1);
  1476. }
  1477. }
  1478. function queuePostFlushCb(cb) {
  1479. if (!shared.isArray(cb)) {
  1480. if (!activePostFlushCbs ||
  1481. !activePostFlushCbs.includes(cb, cb.allowRecurse ? postFlushIndex + 1 : postFlushIndex)) {
  1482. pendingPostFlushCbs.push(cb);
  1483. }
  1484. }
  1485. else {
  1486. // if cb is an array, it is a component lifecycle hook which can only be
  1487. // triggered by a job, which is already deduped in the main queue, so
  1488. // we can skip duplicate check here to improve perf
  1489. pendingPostFlushCbs.push(...cb);
  1490. }
  1491. queueFlush();
  1492. }
  1493. function flushPreFlushCbs(seen,
  1494. // if currently flushing, skip the current job itself
  1495. i = isFlushing ? flushIndex + 1 : 0) {
  1496. {
  1497. seen = seen || new Map();
  1498. }
  1499. for (; i < queue.length; i++) {
  1500. const cb = queue[i];
  1501. if (cb && cb.pre) {
  1502. if (checkRecursiveUpdates(seen, cb)) {
  1503. continue;
  1504. }
  1505. queue.splice(i, 1);
  1506. i--;
  1507. cb();
  1508. }
  1509. }
  1510. }
  1511. function flushPostFlushCbs(seen) {
  1512. if (pendingPostFlushCbs.length) {
  1513. const deduped = [...new Set(pendingPostFlushCbs)];
  1514. pendingPostFlushCbs.length = 0;
  1515. // #1947 already has active queue, nested flushPostFlushCbs call
  1516. if (activePostFlushCbs) {
  1517. activePostFlushCbs.push(...deduped);
  1518. return;
  1519. }
  1520. activePostFlushCbs = deduped;
  1521. {
  1522. seen = seen || new Map();
  1523. }
  1524. activePostFlushCbs.sort((a, b) => getId(a) - getId(b));
  1525. for (postFlushIndex = 0; postFlushIndex < activePostFlushCbs.length; postFlushIndex++) {
  1526. if (checkRecursiveUpdates(seen, activePostFlushCbs[postFlushIndex])) {
  1527. continue;
  1528. }
  1529. activePostFlushCbs[postFlushIndex]();
  1530. }
  1531. activePostFlushCbs = null;
  1532. postFlushIndex = 0;
  1533. }
  1534. }
  1535. const getId = (job) => job.id == null ? Infinity : job.id;
  1536. const comparator = (a, b) => {
  1537. const diff = getId(a) - getId(b);
  1538. if (diff === 0) {
  1539. if (a.pre && !b.pre)
  1540. return -1;
  1541. if (b.pre && !a.pre)
  1542. return 1;
  1543. }
  1544. return diff;
  1545. };
  1546. function flushJobs(seen) {
  1547. isFlushPending = false;
  1548. isFlushing = true;
  1549. {
  1550. seen = seen || new Map();
  1551. }
  1552. // Sort queue before flush.
  1553. // This ensures that:
  1554. // 1. Components are updated from parent to child. (because parent is always
  1555. // created before the child so its render effect will have smaller
  1556. // priority number)
  1557. // 2. If a component is unmounted during a parent component's update,
  1558. // its update can be skipped.
  1559. queue.sort(comparator);
  1560. // conditional usage of checkRecursiveUpdate must be determined out of
  1561. // try ... catch block since Rollup by default de-optimizes treeshaking
  1562. // inside try-catch. This can leave all warning code unshaked. Although
  1563. // they would get eventually shaken by a minifier like terser, some minifiers
  1564. // would fail to do that (e.g. https://github.com/evanw/esbuild/issues/1610)
  1565. const check = (job) => checkRecursiveUpdates(seen, job)
  1566. ;
  1567. try {
  1568. for (flushIndex = 0; flushIndex < queue.length; flushIndex++) {
  1569. const job = queue[flushIndex];
  1570. if (job && job.active !== false) {
  1571. if (true && check(job)) {
  1572. continue;
  1573. }
  1574. // console.log(`running:`, job.id)
  1575. callWithErrorHandling(job, null, 14 /* ErrorCodes.SCHEDULER */);
  1576. }
  1577. }
  1578. }
  1579. finally {
  1580. flushIndex = 0;
  1581. queue.length = 0;
  1582. flushPostFlushCbs(seen);
  1583. isFlushing = false;
  1584. currentFlushPromise = null;
  1585. // some postFlushCb queued jobs!
  1586. // keep flushing until it drains.
  1587. if (queue.length || pendingPostFlushCbs.length) {
  1588. flushJobs(seen);
  1589. }
  1590. }
  1591. }
  1592. function checkRecursiveUpdates(seen, fn) {
  1593. if (!seen.has(fn)) {
  1594. seen.set(fn, 1);
  1595. }
  1596. else {
  1597. const count = seen.get(fn);
  1598. if (count > RECURSION_LIMIT) {
  1599. const instance = fn.ownerInstance;
  1600. const componentName = instance && getComponentName(instance.type);
  1601. warn(`Maximum recursive updates exceeded${componentName ? ` in component <${componentName}>` : ``}. ` +
  1602. `This means you have a reactive effect that is mutating its own ` +
  1603. `dependencies and thus recursively triggering itself. Possible sources ` +
  1604. `include component template, render function, updated hook or ` +
  1605. `watcher source function.`);
  1606. return true;
  1607. }
  1608. else {
  1609. seen.set(fn, count + 1);
  1610. }
  1611. }
  1612. }
  1613. /* eslint-disable no-restricted-globals */
  1614. let isHmrUpdating = false;
  1615. const hmrDirtyComponents = new Set();
  1616. // Expose the HMR runtime on the global object
  1617. // This makes it entirely tree-shakable without polluting the exports and makes
  1618. // it easier to be used in toolings like vue-loader
  1619. // Note: for a component to be eligible for HMR it also needs the __hmrId option
  1620. // to be set so that its instances can be registered / removed.
  1621. {
  1622. shared.getGlobalThis().__VUE_HMR_RUNTIME__ = {
  1623. createRecord: tryWrap(createRecord),
  1624. rerender: tryWrap(rerender),
  1625. reload: tryWrap(reload)
  1626. };
  1627. }
  1628. const map = new Map();
  1629. function registerHMR(instance) {
  1630. const id = instance.type.__hmrId;
  1631. let record = map.get(id);
  1632. if (!record) {
  1633. createRecord(id, instance.type);
  1634. record = map.get(id);
  1635. }
  1636. record.instances.add(instance);
  1637. }
  1638. function unregisterHMR(instance) {
  1639. map.get(instance.type.__hmrId).instances.delete(instance);
  1640. }
  1641. function createRecord(id, initialDef) {
  1642. if (map.has(id)) {
  1643. return false;
  1644. }
  1645. map.set(id, {
  1646. initialDef: normalizeClassComponent(initialDef),
  1647. instances: new Set()
  1648. });
  1649. return true;
  1650. }
  1651. function normalizeClassComponent(component) {
  1652. return isClassComponent(component) ? component.__vccOpts : component;
  1653. }
  1654. function rerender(id, newRender) {
  1655. const record = map.get(id);
  1656. if (!record) {
  1657. return;
  1658. }
  1659. // update initial record (for not-yet-rendered component)
  1660. record.initialDef.render = newRender;
  1661. [...record.instances].forEach(instance => {
  1662. if (newRender) {
  1663. instance.render = newRender;
  1664. normalizeClassComponent(instance.type).render = newRender;
  1665. }
  1666. instance.renderCache = [];
  1667. // this flag forces child components with slot content to update
  1668. isHmrUpdating = true;
  1669. instance.update();
  1670. isHmrUpdating = false;
  1671. });
  1672. }
  1673. function reload(id, newComp) {
  1674. const record = map.get(id);
  1675. if (!record)
  1676. return;
  1677. // fixed by xxxxxx 解决页面刷新 setupPage
  1678. if (typeof window !== 'undefined' &&
  1679. window.__setupPage &&
  1680. record.initialDef.__mpType === 'page') {
  1681. newComp = window.__setupPage(newComp);
  1682. }
  1683. newComp = normalizeClassComponent(newComp);
  1684. // update initial def (for not-yet-rendered components)
  1685. updateComponentDef(record.initialDef, newComp);
  1686. // create a snapshot which avoids the set being mutated during updates
  1687. const instances = [...record.instances];
  1688. for (const instance of instances) {
  1689. const oldComp = normalizeClassComponent(instance.type);
  1690. if (!hmrDirtyComponents.has(oldComp)) {
  1691. // 1. Update existing comp definition to match new one
  1692. if (oldComp !== record.initialDef) {
  1693. updateComponentDef(oldComp, newComp);
  1694. }
  1695. // 2. mark definition dirty. This forces the renderer to replace the
  1696. // component on patch.
  1697. hmrDirtyComponents.add(oldComp);
  1698. }
  1699. // 3. invalidate options resolution cache
  1700. instance.appContext.optionsCache.delete(instance.type);
  1701. // 4. actually update
  1702. if (instance.ceReload) {
  1703. // custom element
  1704. hmrDirtyComponents.add(oldComp);
  1705. instance.ceReload(newComp.styles);
  1706. hmrDirtyComponents.delete(oldComp);
  1707. }
  1708. else if (instance.parent) {
  1709. // 4. Force the parent instance to re-render. This will cause all updated
  1710. // components to be unmounted and re-mounted. Queue the update so that we
  1711. // don't end up forcing the same parent to re-render multiple times.
  1712. queueJob(instance.parent.update);
  1713. }
  1714. else if (instance.appContext.reload) {
  1715. // root instance mounted via createApp() has a reload method
  1716. instance.appContext.reload();
  1717. }
  1718. else if (typeof window !== 'undefined') {
  1719. // root instance inside tree created via raw render(). Force reload.
  1720. window.location.reload();
  1721. }
  1722. else {
  1723. console.warn('[HMR] Root or manually mounted instance modified. Full reload required.');
  1724. }
  1725. }
  1726. // 5. make sure to cleanup dirty hmr components after update
  1727. queuePostFlushCb(() => {
  1728. for (const instance of instances) {
  1729. hmrDirtyComponents.delete(normalizeClassComponent(instance.type));
  1730. }
  1731. });
  1732. }
  1733. function updateComponentDef(oldComp, newComp) {
  1734. shared.extend(oldComp, newComp);
  1735. for (const key in oldComp) {
  1736. if (key !== '__file' && !(key in newComp)) {
  1737. delete oldComp[key];
  1738. }
  1739. }
  1740. }
  1741. function tryWrap(fn) {
  1742. return (id, arg) => {
  1743. try {
  1744. return fn(id, arg);
  1745. }
  1746. catch (e) {
  1747. console.error(e);
  1748. console.warn(`[HMR] Something went wrong during Vue component hot-reload. ` +
  1749. `Full reload required.`);
  1750. }
  1751. };
  1752. }
  1753. exports.devtools = void 0;
  1754. let buffer = [];
  1755. let devtoolsNotInstalled = false;
  1756. function emit$1(event, ...args) {
  1757. if (exports.devtools) {
  1758. exports.devtools.emit(event, ...args);
  1759. }
  1760. else if (!devtoolsNotInstalled) {
  1761. buffer.push({ event, args });
  1762. }
  1763. }
  1764. function setDevtoolsHook(hook, target) {
  1765. var _a, _b;
  1766. exports.devtools = hook;
  1767. if (exports.devtools) {
  1768. exports.devtools.enabled = true;
  1769. buffer.forEach(({ event, args }) => exports.devtools.emit(event, ...args));
  1770. buffer = [];
  1771. }
  1772. else if (
  1773. // handle late devtools injection - only do this if we are in an actual
  1774. // browser environment to avoid the timer handle stalling test runner exit
  1775. // (#4815)
  1776. typeof window !== 'undefined' &&
  1777. // some envs mock window but not fully
  1778. // eslint-disable-next-line no-restricted-globals
  1779. window.HTMLElement &&
  1780. // also exclude jsdom
  1781. // eslint-disable-next-line no-restricted-globals
  1782. !((_b = (_a = window.navigator) === null || _a === void 0 ? void 0 : _a.userAgent) === null || _b === void 0 ? void 0 : _b.includes('jsdom'))) {
  1783. const replay = (target.__VUE_DEVTOOLS_HOOK_REPLAY__ =
  1784. target.__VUE_DEVTOOLS_HOOK_REPLAY__ || []);
  1785. replay.push((newHook) => {
  1786. setDevtoolsHook(newHook, target);
  1787. });
  1788. // clear buffer after 3s - the user probably doesn't have devtools installed
  1789. // at all, and keeping the buffer will cause memory leaks (#4738)
  1790. setTimeout(() => {
  1791. if (!exports.devtools) {
  1792. target.__VUE_DEVTOOLS_HOOK_REPLAY__ = null;
  1793. devtoolsNotInstalled = true;
  1794. buffer = [];
  1795. }
  1796. }, 3000);
  1797. }
  1798. else {
  1799. // non-browser env, assume not installed
  1800. devtoolsNotInstalled = true;
  1801. buffer = [];
  1802. }
  1803. }
  1804. function devtoolsInitApp(app, version) {
  1805. emit$1("app:init" /* DevtoolsHooks.APP_INIT */, app, version, {
  1806. Fragment,
  1807. Text,
  1808. Comment,
  1809. Static
  1810. });
  1811. }
  1812. function devtoolsUnmountApp(app) {
  1813. emit$1("app:unmount" /* DevtoolsHooks.APP_UNMOUNT */, app);
  1814. }
  1815. const devtoolsComponentAdded = /*#__PURE__*/ createDevtoolsComponentHook("component:added" /* DevtoolsHooks.COMPONENT_ADDED */);
  1816. const devtoolsComponentUpdated =
  1817. /*#__PURE__*/ createDevtoolsComponentHook("component:updated" /* DevtoolsHooks.COMPONENT_UPDATED */);
  1818. const _devtoolsComponentRemoved = /*#__PURE__*/ createDevtoolsComponentHook("component:removed" /* DevtoolsHooks.COMPONENT_REMOVED */);
  1819. const devtoolsComponentRemoved = (component) => {
  1820. if (exports.devtools &&
  1821. typeof exports.devtools.cleanupBuffer === 'function' &&
  1822. // remove the component if it wasn't buffered
  1823. !exports.devtools.cleanupBuffer(component)) {
  1824. _devtoolsComponentRemoved(component);
  1825. }
  1826. };
  1827. function createDevtoolsComponentHook(hook) {
  1828. return (component) => {
  1829. emit$1(hook, component.appContext.app, component.uid, component.parent ? component.parent.uid : undefined, component);
  1830. };
  1831. }
  1832. const devtoolsPerfStart = /*#__PURE__*/ createDevtoolsPerformanceHook("perf:start" /* DevtoolsHooks.PERFORMANCE_START */);
  1833. const devtoolsPerfEnd = /*#__PURE__*/ createDevtoolsPerformanceHook("perf:end" /* DevtoolsHooks.PERFORMANCE_END */);
  1834. function createDevtoolsPerformanceHook(hook) {
  1835. return (component, type, time) => {
  1836. emit$1(hook, component.appContext.app, component.uid, component, type, time);
  1837. };
  1838. }
  1839. function devtoolsComponentEmit(component, event, params) {
  1840. emit$1("component:emit" /* DevtoolsHooks.COMPONENT_EMIT */, component.appContext.app, component, event, params);
  1841. }
  1842. function emit(instance, event, ...rawArgs) {
  1843. if (instance.isUnmounted)
  1844. return;
  1845. const props = instance.vnode.props || shared.EMPTY_OBJ;
  1846. {
  1847. const { emitsOptions, propsOptions: [propsOptions] } = instance;
  1848. if (emitsOptions) {
  1849. if (!(event in emitsOptions) &&
  1850. !(false )) {
  1851. if (!propsOptions || !(shared.toHandlerKey(event) in propsOptions)) {
  1852. warn(`Component emitted event "${event}" but it is neither declared in ` +
  1853. `the emits option nor as an "${shared.toHandlerKey(event)}" prop.`);
  1854. }
  1855. }
  1856. else {
  1857. const validator = emitsOptions[event];
  1858. if (shared.isFunction(validator)) {
  1859. const isValid = validator(...rawArgs);
  1860. if (!isValid) {
  1861. warn(`Invalid event arguments: event validation failed for event "${event}".`);
  1862. }
  1863. }
  1864. }
  1865. }
  1866. }
  1867. let args = rawArgs;
  1868. const isModelListener = event.startsWith('update:');
  1869. // for v-model update:xxx events, apply modifiers on args
  1870. const modelArg = isModelListener && event.slice(7);
  1871. if (modelArg && modelArg in props) {
  1872. const modifiersKey = `${modelArg === 'modelValue' ? 'model' : modelArg}Modifiers`;
  1873. const { number, trim } = props[modifiersKey] || shared.EMPTY_OBJ;
  1874. if (trim) {
  1875. args = rawArgs.map(a => (shared.isString(a) ? a.trim() : a));
  1876. }
  1877. if (number) {
  1878. args = rawArgs.map(shared.looseToNumber);
  1879. }
  1880. }
  1881. {
  1882. devtoolsComponentEmit(instance, event, args);
  1883. }
  1884. {
  1885. const lowerCaseEvent = event.toLowerCase();
  1886. if (lowerCaseEvent !== event && props[shared.toHandlerKey(lowerCaseEvent)]) {
  1887. warn(`Event "${lowerCaseEvent}" is emitted in component ` +
  1888. `${formatComponentName(instance, instance.type)} but the handler is registered for "${event}". ` +
  1889. `Note that HTML attributes are case-insensitive and you cannot use ` +
  1890. `v-on to listen to camelCase events when using in-DOM templates. ` +
  1891. `You should probably use "${shared.hyphenate(event)}" instead of "${event}".`);
  1892. }
  1893. }
  1894. let handlerName;
  1895. let handler = props[(handlerName = shared.toHandlerKey(event))] ||
  1896. // also try camelCase event handler (#2249)
  1897. props[(handlerName = shared.toHandlerKey(shared.camelize(event)))];
  1898. // for v-model update:xxx events, also trigger kebab-case equivalent
  1899. // for props passed via kebab-case
  1900. if (!handler && isModelListener) {
  1901. handler = props[(handlerName = shared.toHandlerKey(shared.hyphenate(event)))];
  1902. }
  1903. if (handler) {
  1904. callWithAsyncErrorHandling(handler, instance, 6 /* ErrorCodes.COMPONENT_EVENT_HANDLER */,
  1905. // fixed by xxxxxx
  1906. normalizeWxsEventArgs(instance, handler, args));
  1907. }
  1908. const onceHandler = props[handlerName + `Once`];
  1909. if (onceHandler) {
  1910. if (!instance.emitted) {
  1911. instance.emitted = {};
  1912. }
  1913. else if (instance.emitted[handlerName]) {
  1914. return;
  1915. }
  1916. instance.emitted[handlerName] = true;
  1917. callWithAsyncErrorHandling(onceHandler, instance, 6 /* ErrorCodes.COMPONENT_EVENT_HANDLER */,
  1918. // fixed by xxxxxx
  1919. normalizeWxsEventArgs(instance, onceHandler, args));
  1920. }
  1921. }
  1922. /**
  1923. * 补充 wxs 事件参数
  1924. * @param instance
  1925. * @param handler
  1926. * @param args
  1927. * @returns
  1928. */
  1929. function normalizeWxsEventArgs(instance, handler, args) {
  1930. // 系统组件事件参数长度一定是 1
  1931. if (args.length !== 1) {
  1932. return args;
  1933. }
  1934. // 判断是否可能需要补充 ownerInstance 参数
  1935. if (shared.isFunction(handler)) {
  1936. // 单函数,且参数小于 2 的直接返回
  1937. if (handler.length < 2) {
  1938. return args;
  1939. }
  1940. }
  1941. else {
  1942. // 多函数,且参数没有大于等于 2 的直接返回
  1943. if (!handler.find(item => item.length >= 2)) {
  1944. return args;
  1945. }
  1946. }
  1947. // 系统组件事件对象
  1948. const $sysEvent = args[0];
  1949. if ($sysEvent &&
  1950. shared.hasOwn($sysEvent, 'type') &&
  1951. shared.hasOwn($sysEvent, 'timeStamp') &&
  1952. shared.hasOwn($sysEvent, 'target') &&
  1953. shared.hasOwn($sysEvent, 'currentTarget') &&
  1954. shared.hasOwn($sysEvent, 'detail')) {
  1955. const proxy = instance.proxy;
  1956. const $ownerInstance = proxy.$gcd(proxy, true);
  1957. if ($ownerInstance) {
  1958. args.push($ownerInstance);
  1959. }
  1960. }
  1961. return args;
  1962. }
  1963. function normalizeEmitsOptions(comp, appContext, asMixin = false) {
  1964. const cache = appContext.emitsCache;
  1965. const cached = cache.get(comp);
  1966. if (cached !== undefined) {
  1967. return cached;
  1968. }
  1969. const raw = comp.emits;
  1970. let normalized = {};
  1971. // apply mixin/extends props
  1972. let hasExtends = false;
  1973. if (!shared.isFunction(comp)) {
  1974. const extendEmits = (raw) => {
  1975. const normalizedFromExtend = normalizeEmitsOptions(raw, appContext, true);
  1976. if (normalizedFromExtend) {
  1977. hasExtends = true;
  1978. shared.extend(normalized, normalizedFromExtend);
  1979. }
  1980. };
  1981. if (!asMixin && appContext.mixins.length) {
  1982. appContext.mixins.forEach(extendEmits);
  1983. }
  1984. if (comp.extends) {
  1985. extendEmits(comp.extends);
  1986. }
  1987. if (comp.mixins) {
  1988. comp.mixins.forEach(extendEmits);
  1989. }
  1990. }
  1991. if (!raw && !hasExtends) {
  1992. if (shared.isObject(comp)) {
  1993. cache.set(comp, null);
  1994. }
  1995. return null;
  1996. }
  1997. if (shared.isArray(raw)) {
  1998. raw.forEach(key => (normalized[key] = null));
  1999. }
  2000. else {
  2001. shared.extend(normalized, raw);
  2002. }
  2003. if (shared.isObject(comp)) {
  2004. cache.set(comp, normalized);
  2005. }
  2006. return normalized;
  2007. }
  2008. // Check if an incoming prop key is a declared emit event listener.
  2009. // e.g. With `emits: { click: null }`, props named `onClick` and `onclick` are
  2010. // both considered matched listeners.
  2011. function isEmitListener(options, key) {
  2012. if (!options || !shared.isOn(key)) {
  2013. return false;
  2014. }
  2015. key = key.slice(2).replace(/Once$/, '');
  2016. return (shared.hasOwn(options, key[0].toLowerCase() + key.slice(1)) ||
  2017. shared.hasOwn(options, shared.hyphenate(key)) ||
  2018. shared.hasOwn(options, key));
  2019. }
  2020. /**
  2021. * mark the current rendering instance for asset resolution (e.g.
  2022. * resolveComponent, resolveDirective) during render
  2023. */
  2024. let currentRenderingInstance = null;
  2025. let currentScopeId = null;
  2026. /**
  2027. * Note: rendering calls maybe nested. The function returns the parent rendering
  2028. * instance if present, which should be restored after the render is done:
  2029. *
  2030. * ```js
  2031. * const prev = setCurrentRenderingInstance(i)
  2032. * // ...render
  2033. * setCurrentRenderingInstance(prev)
  2034. * ```
  2035. */
  2036. function setCurrentRenderingInstance(instance) {
  2037. const prev = currentRenderingInstance;
  2038. currentRenderingInstance = instance;
  2039. currentScopeId = (instance && instance.type.__scopeId) || null;
  2040. return prev;
  2041. }
  2042. /**
  2043. * Set scope id when creating hoisted vnodes.
  2044. * @private compiler helper
  2045. */
  2046. function pushScopeId(id) {
  2047. currentScopeId = id;
  2048. }
  2049. /**
  2050. * Technically we no longer need this after 3.0.8 but we need to keep the same
  2051. * API for backwards compat w/ code generated by compilers.
  2052. * @private
  2053. */
  2054. function popScopeId() {
  2055. currentScopeId = null;
  2056. }
  2057. /**
  2058. * Only for backwards compat
  2059. * @private
  2060. */
  2061. const withScopeId = (_id) => withCtx;
  2062. /**
  2063. * Wrap a slot function to memoize current rendering instance
  2064. * @private compiler helper
  2065. */
  2066. function withCtx(fn, ctx = currentRenderingInstance, isNonScopedSlot // false only
  2067. ) {
  2068. if (!ctx)
  2069. return fn;
  2070. // already normalized
  2071. if (fn._n) {
  2072. return fn;
  2073. }
  2074. const renderFnWithContext = (...args) => {
  2075. // If a user calls a compiled slot inside a template expression (#1745), it
  2076. // can mess up block tracking, so by default we disable block tracking and
  2077. // force bail out when invoking a compiled slot (indicated by the ._d flag).
  2078. // This isn't necessary if rendering a compiled `<slot>`, so we flip the
  2079. // ._d flag off when invoking the wrapped fn inside `renderSlot`.
  2080. if (renderFnWithContext._d) {
  2081. setBlockTracking(-1);
  2082. }
  2083. const prevInstance = setCurrentRenderingInstance(ctx);
  2084. let res;
  2085. try {
  2086. res = fn(...args);
  2087. }
  2088. finally {
  2089. setCurrentRenderingInstance(prevInstance);
  2090. if (renderFnWithContext._d) {
  2091. setBlockTracking(1);
  2092. }
  2093. }
  2094. {
  2095. devtoolsComponentUpdated(ctx);
  2096. }
  2097. return res;
  2098. };
  2099. // mark normalized to avoid duplicated wrapping
  2100. renderFnWithContext._n = true;
  2101. // mark this as compiled by default
  2102. // this is used in vnode.ts -> normalizeChildren() to set the slot
  2103. // rendering flag.
  2104. renderFnWithContext._c = true;
  2105. // disable block tracking by default
  2106. renderFnWithContext._d = true;
  2107. return renderFnWithContext;
  2108. }
  2109. /**
  2110. * dev only flag to track whether $attrs was used during render.
  2111. * If $attrs was used during render then the warning for failed attrs
  2112. * fallthrough can be suppressed.
  2113. */
  2114. let accessedAttrs = false;
  2115. function markAttrsAccessed() {
  2116. accessedAttrs = true;
  2117. }
  2118. function renderComponentRoot(instance) {
  2119. const { type: Component, vnode, proxy, withProxy, props, propsOptions: [propsOptions], slots, attrs, emit, render, renderCache, data, setupState, ctx, inheritAttrs } = instance;
  2120. let result;
  2121. let fallthroughAttrs;
  2122. const prev = setCurrentRenderingInstance(instance);
  2123. {
  2124. accessedAttrs = false;
  2125. }
  2126. try {
  2127. if (vnode.shapeFlag & 4 /* ShapeFlags.STATEFUL_COMPONENT */) {
  2128. // withProxy is a proxy with a different `has` trap only for
  2129. // runtime-compiled render functions using `with` block.
  2130. const proxyToUse = withProxy || proxy;
  2131. result = normalizeVNode(render.call(proxyToUse, proxyToUse, renderCache, props, setupState, data, ctx));
  2132. fallthroughAttrs = attrs;
  2133. }
  2134. else {
  2135. // functional
  2136. const render = Component;
  2137. // in dev, mark attrs accessed if optional props (attrs === props)
  2138. if (true && attrs === props) {
  2139. markAttrsAccessed();
  2140. }
  2141. result = normalizeVNode(render.length > 1
  2142. ? render(props, true
  2143. ? {
  2144. get attrs() {
  2145. markAttrsAccessed();
  2146. return attrs;
  2147. },
  2148. slots,
  2149. emit
  2150. }
  2151. : { attrs, slots, emit })
  2152. : render(props, null /* we know it doesn't need it */));
  2153. fallthroughAttrs = Component.props
  2154. ? attrs
  2155. : getFunctionalFallthrough(attrs);
  2156. }
  2157. }
  2158. catch (err) {
  2159. blockStack.length = 0;
  2160. handleError(err, instance, 1 /* ErrorCodes.RENDER_FUNCTION */);
  2161. result = createVNode(Comment);
  2162. }
  2163. // attr merging
  2164. // in dev mode, comments are preserved, and it's possible for a template
  2165. // to have comments along side the root element which makes it a fragment
  2166. let root = result;
  2167. let setRoot = undefined;
  2168. if (result.patchFlag > 0 &&
  2169. result.patchFlag & 2048 /* PatchFlags.DEV_ROOT_FRAGMENT */) {
  2170. [root, setRoot] = getChildRoot(result);
  2171. }
  2172. if (fallthroughAttrs && inheritAttrs !== false) {
  2173. const keys = Object.keys(fallthroughAttrs);
  2174. const { shapeFlag } = root;
  2175. if (keys.length) {
  2176. if (shapeFlag & (1 /* ShapeFlags.ELEMENT */ | 6 /* ShapeFlags.COMPONENT */)) {
  2177. if (propsOptions && keys.some(shared.isModelListener)) {
  2178. // If a v-model listener (onUpdate:xxx) has a corresponding declared
  2179. // prop, it indicates this component expects to handle v-model and
  2180. // it should not fallthrough.
  2181. // related: #1543, #1643, #1989
  2182. fallthroughAttrs = filterModelListeners(fallthroughAttrs, propsOptions);
  2183. }
  2184. root = cloneVNode(root, fallthroughAttrs);
  2185. }
  2186. else if (!accessedAttrs && root.type !== Comment) {
  2187. const allAttrs = Object.keys(attrs);
  2188. const eventAttrs = [];
  2189. const extraAttrs = [];
  2190. for (let i = 0, l = allAttrs.length; i < l; i++) {
  2191. const key = allAttrs[i];
  2192. if (shared.isOn(key)) {
  2193. // ignore v-model handlers when they fail to fallthrough
  2194. if (!shared.isModelListener(key)) {
  2195. // remove `on`, lowercase first letter to reflect event casing
  2196. // accurately
  2197. eventAttrs.push(key[2].toLowerCase() + key.slice(3));
  2198. }
  2199. }
  2200. else {
  2201. extraAttrs.push(key);
  2202. }
  2203. }
  2204. if (extraAttrs.length) {
  2205. warn(`Extraneous non-props attributes (` +
  2206. `${extraAttrs.join(', ')}) ` +
  2207. `were passed to component but could not be automatically inherited ` +
  2208. `because component renders fragment or text root nodes.`);
  2209. }
  2210. if (eventAttrs.length) {
  2211. warn(`Extraneous non-emits event listeners (` +
  2212. `${eventAttrs.join(', ')}) ` +
  2213. `were passed to component but could not be automatically inherited ` +
  2214. `because component renders fragment or text root nodes. ` +
  2215. `If the listener is intended to be a component custom event listener only, ` +
  2216. `declare it using the "emits" option.`);
  2217. }
  2218. }
  2219. }
  2220. }
  2221. // inherit directives
  2222. if (vnode.dirs) {
  2223. if (!isElementRoot(root)) {
  2224. warn(`Runtime directive used on component with non-element root node. ` +
  2225. `The directives will not function as intended.`);
  2226. }
  2227. // clone before mutating since the root may be a hoisted vnode
  2228. root = cloneVNode(root);
  2229. root.dirs = root.dirs ? root.dirs.concat(vnode.dirs) : vnode.dirs;
  2230. }
  2231. // inherit transition data
  2232. if (vnode.transition) {
  2233. if (!isElementRoot(root)) {
  2234. warn(`Component inside <Transition> renders non-element root node ` +
  2235. `that cannot be animated.`);
  2236. }
  2237. root.transition = vnode.transition;
  2238. }
  2239. if (setRoot) {
  2240. setRoot(root);
  2241. }
  2242. else {
  2243. result = root;
  2244. }
  2245. setCurrentRenderingInstance(prev);
  2246. return result;
  2247. }
  2248. /**
  2249. * dev only
  2250. * In dev mode, template root level comments are rendered, which turns the
  2251. * template into a fragment root, but we need to locate the single element
  2252. * root for attrs and scope id processing.
  2253. */
  2254. const getChildRoot = (vnode) => {
  2255. const rawChildren = vnode.children;
  2256. const dynamicChildren = vnode.dynamicChildren;
  2257. const childRoot = filterSingleRoot(rawChildren);
  2258. if (!childRoot) {
  2259. return [vnode, undefined];
  2260. }
  2261. const index = rawChildren.indexOf(childRoot);
  2262. const dynamicIndex = dynamicChildren ? dynamicChildren.indexOf(childRoot) : -1;
  2263. const setRoot = (updatedRoot) => {
  2264. rawChildren[index] = updatedRoot;
  2265. if (dynamicChildren) {
  2266. if (dynamicIndex > -1) {
  2267. dynamicChildren[dynamicIndex] = updatedRoot;
  2268. }
  2269. else if (updatedRoot.patchFlag > 0) {
  2270. vnode.dynamicChildren = [...dynamicChildren, updatedRoot];
  2271. }
  2272. }
  2273. };
  2274. return [normalizeVNode(childRoot), setRoot];
  2275. };
  2276. function filterSingleRoot(children) {
  2277. let singleRoot;
  2278. for (let i = 0; i < children.length; i++) {
  2279. const child = children[i];
  2280. if (isVNode(child)) {
  2281. // ignore user comment
  2282. if (child.type !== Comment || child.children === 'v-if') {
  2283. if (singleRoot) {
  2284. // has more than 1 non-comment child, return now
  2285. return;
  2286. }
  2287. else {
  2288. singleRoot = child;
  2289. }
  2290. }
  2291. }
  2292. else {
  2293. return;
  2294. }
  2295. }
  2296. return singleRoot;
  2297. }
  2298. const getFunctionalFallthrough = (attrs) => {
  2299. let res;
  2300. for (const key in attrs) {
  2301. if (key === 'class' || key === 'style' || shared.isOn(key)) {
  2302. (res || (res = {}))[key] = attrs[key];
  2303. }
  2304. }
  2305. return res;
  2306. };
  2307. const filterModelListeners = (attrs, props) => {
  2308. const res = {};
  2309. for (const key in attrs) {
  2310. if (!shared.isModelListener(key) || !(key.slice(9) in props)) {
  2311. res[key] = attrs[key];
  2312. }
  2313. }
  2314. return res;
  2315. };
  2316. const isElementRoot = (vnode) => {
  2317. return (vnode.shapeFlag & (6 /* ShapeFlags.COMPONENT */ | 1 /* ShapeFlags.ELEMENT */) ||
  2318. vnode.type === Comment // potential v-if branch switch
  2319. );
  2320. };
  2321. function shouldUpdateComponent(prevVNode, nextVNode, optimized) {
  2322. const { props: prevProps, children: prevChildren, component } = prevVNode;
  2323. const { props: nextProps, children: nextChildren, patchFlag } = nextVNode;
  2324. const emits = component.emitsOptions;
  2325. // Parent component's render function was hot-updated. Since this may have
  2326. // caused the child component's slots content to have changed, we need to
  2327. // force the child to update as well.
  2328. if ((prevChildren || nextChildren) && isHmrUpdating) {
  2329. return true;
  2330. }
  2331. // force child update for runtime directive or transition on component vnode.
  2332. if (nextVNode.dirs || nextVNode.transition) {
  2333. return true;
  2334. }
  2335. if (optimized && patchFlag >= 0) {
  2336. if (patchFlag & 1024 /* PatchFlags.DYNAMIC_SLOTS */) {
  2337. // slot content that references values that might have changed,
  2338. // e.g. in a v-for
  2339. return true;
  2340. }
  2341. if (patchFlag & 16 /* PatchFlags.FULL_PROPS */) {
  2342. if (!prevProps) {
  2343. return !!nextProps;
  2344. }
  2345. // presence of this flag indicates props are always non-null
  2346. return hasPropsChanged(prevProps, nextProps, emits);
  2347. }
  2348. else if (patchFlag & 8 /* PatchFlags.PROPS */) {
  2349. const dynamicProps = nextVNode.dynamicProps;
  2350. for (let i = 0; i < dynamicProps.length; i++) {
  2351. const key = dynamicProps[i];
  2352. if (nextProps[key] !== prevProps[key] &&
  2353. !isEmitListener(emits, key)) {
  2354. return true;
  2355. }
  2356. }
  2357. }
  2358. }
  2359. else {
  2360. // this path is only taken by manually written render functions
  2361. // so presence of any children leads to a forced update
  2362. if (prevChildren || nextChildren) {
  2363. if (!nextChildren || !nextChildren.$stable) {
  2364. return true;
  2365. }
  2366. }
  2367. if (prevProps === nextProps) {
  2368. return false;
  2369. }
  2370. if (!prevProps) {
  2371. return !!nextProps;
  2372. }
  2373. if (!nextProps) {
  2374. return true;
  2375. }
  2376. return hasPropsChanged(prevProps, nextProps, emits);
  2377. }
  2378. return false;
  2379. }
  2380. function hasPropsChanged(prevProps, nextProps, emitsOptions) {
  2381. const nextKeys = Object.keys(nextProps);
  2382. if (nextKeys.length !== Object.keys(prevProps).length) {
  2383. return true;
  2384. }
  2385. for (let i = 0; i < nextKeys.length; i++) {
  2386. const key = nextKeys[i];
  2387. if (nextProps[key] !== prevProps[key] &&
  2388. !isEmitListener(emitsOptions, key)) {
  2389. return true;
  2390. }
  2391. }
  2392. return false;
  2393. }
  2394. function updateHOCHostEl({ vnode, parent }, el // HostNode
  2395. ) {
  2396. while (parent && parent.subTree === vnode) {
  2397. (vnode = parent.vnode).el = el;
  2398. parent = parent.parent;
  2399. }
  2400. }
  2401. const isSuspense = (type) => type.__isSuspense;
  2402. // Suspense exposes a component-like API, and is treated like a component
  2403. // in the compiler, but internally it's a special built-in type that hooks
  2404. // directly into the renderer.
  2405. const SuspenseImpl = {
  2406. name: 'Suspense',
  2407. // In order to make Suspense tree-shakable, we need to avoid importing it
  2408. // directly in the renderer. The renderer checks for the __isSuspense flag
  2409. // on a vnode's type and calls the `process` method, passing in renderer
  2410. // internals.
  2411. __isSuspense: true,
  2412. process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized,
  2413. // platform-specific impl passed from renderer
  2414. rendererInternals) {
  2415. if (n1 == null) {
  2416. mountSuspense(n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, rendererInternals);
  2417. }
  2418. else {
  2419. patchSuspense(n1, n2, container, anchor, parentComponent, isSVG, slotScopeIds, optimized, rendererInternals);
  2420. }
  2421. },
  2422. hydrate: hydrateSuspense,
  2423. create: createSuspenseBoundary,
  2424. normalize: normalizeSuspenseChildren
  2425. };
  2426. // Force-casted public typing for h and TSX props inference
  2427. const Suspense = (SuspenseImpl
  2428. );
  2429. function triggerEvent(vnode, name) {
  2430. const eventListener = vnode.props && vnode.props[name];
  2431. if (shared.isFunction(eventListener)) {
  2432. eventListener();
  2433. }
  2434. }
  2435. function mountSuspense(vnode, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, rendererInternals) {
  2436. const { p: patch, o: { createElement } } = rendererInternals;
  2437. const hiddenContainer = createElement('div');
  2438. const suspense = (vnode.suspense = createSuspenseBoundary(vnode, parentSuspense, parentComponent, container, hiddenContainer, anchor, isSVG, slotScopeIds, optimized, rendererInternals));
  2439. // start mounting the content subtree in an off-dom container
  2440. patch(null, (suspense.pendingBranch = vnode.ssContent), hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds);
  2441. // now check if we have encountered any async deps
  2442. if (suspense.deps > 0) {
  2443. // has async
  2444. // invoke @fallback event
  2445. triggerEvent(vnode, 'onPending');
  2446. triggerEvent(vnode, 'onFallback');
  2447. // mount the fallback tree
  2448. patch(null, vnode.ssFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2449. isSVG, slotScopeIds);
  2450. setActiveBranch(suspense, vnode.ssFallback);
  2451. }
  2452. else {
  2453. // Suspense has no async deps. Just resolve.
  2454. suspense.resolve();
  2455. }
  2456. }
  2457. function patchSuspense(n1, n2, container, anchor, parentComponent, isSVG, slotScopeIds, optimized, { p: patch, um: unmount, o: { createElement } }) {
  2458. const suspense = (n2.suspense = n1.suspense);
  2459. suspense.vnode = n2;
  2460. n2.el = n1.el;
  2461. const newBranch = n2.ssContent;
  2462. const newFallback = n2.ssFallback;
  2463. const { activeBranch, pendingBranch, isInFallback, isHydrating } = suspense;
  2464. if (pendingBranch) {
  2465. suspense.pendingBranch = newBranch;
  2466. if (isSameVNodeType(newBranch, pendingBranch)) {
  2467. // same root type but content may have changed.
  2468. patch(pendingBranch, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2469. if (suspense.deps <= 0) {
  2470. suspense.resolve();
  2471. }
  2472. else if (isInFallback) {
  2473. patch(activeBranch, newFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2474. isSVG, slotScopeIds, optimized);
  2475. setActiveBranch(suspense, newFallback);
  2476. }
  2477. }
  2478. else {
  2479. // toggled before pending tree is resolved
  2480. suspense.pendingId++;
  2481. if (isHydrating) {
  2482. // if toggled before hydration is finished, the current DOM tree is
  2483. // no longer valid. set it as the active branch so it will be unmounted
  2484. // when resolved
  2485. suspense.isHydrating = false;
  2486. suspense.activeBranch = pendingBranch;
  2487. }
  2488. else {
  2489. unmount(pendingBranch, parentComponent, suspense);
  2490. }
  2491. // increment pending ID. this is used to invalidate async callbacks
  2492. // reset suspense state
  2493. suspense.deps = 0;
  2494. // discard effects from pending branch
  2495. suspense.effects.length = 0;
  2496. // discard previous container
  2497. suspense.hiddenContainer = createElement('div');
  2498. if (isInFallback) {
  2499. // already in fallback state
  2500. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2501. if (suspense.deps <= 0) {
  2502. suspense.resolve();
  2503. }
  2504. else {
  2505. patch(activeBranch, newFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2506. isSVG, slotScopeIds, optimized);
  2507. setActiveBranch(suspense, newFallback);
  2508. }
  2509. }
  2510. else if (activeBranch && isSameVNodeType(newBranch, activeBranch)) {
  2511. // toggled "back" to current active branch
  2512. patch(activeBranch, newBranch, container, anchor, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2513. // force resolve
  2514. suspense.resolve(true);
  2515. }
  2516. else {
  2517. // switched to a 3rd branch
  2518. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2519. if (suspense.deps <= 0) {
  2520. suspense.resolve();
  2521. }
  2522. }
  2523. }
  2524. }
  2525. else {
  2526. if (activeBranch && isSameVNodeType(newBranch, activeBranch)) {
  2527. // root did not change, just normal patch
  2528. patch(activeBranch, newBranch, container, anchor, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2529. setActiveBranch(suspense, newBranch);
  2530. }
  2531. else {
  2532. // root node toggled
  2533. // invoke @pending event
  2534. triggerEvent(n2, 'onPending');
  2535. // mount pending branch in off-dom container
  2536. suspense.pendingBranch = newBranch;
  2537. suspense.pendingId++;
  2538. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2539. if (suspense.deps <= 0) {
  2540. // incoming branch has no async deps, resolve now.
  2541. suspense.resolve();
  2542. }
  2543. else {
  2544. const { timeout, pendingId } = suspense;
  2545. if (timeout > 0) {
  2546. setTimeout(() => {
  2547. if (suspense.pendingId === pendingId) {
  2548. suspense.fallback(newFallback);
  2549. }
  2550. }, timeout);
  2551. }
  2552. else if (timeout === 0) {
  2553. suspense.fallback(newFallback);
  2554. }
  2555. }
  2556. }
  2557. }
  2558. }
  2559. let hasWarned = false;
  2560. function createSuspenseBoundary(vnode, parent, parentComponent, container, hiddenContainer, anchor, isSVG, slotScopeIds, optimized, rendererInternals, isHydrating = false) {
  2561. /* istanbul ignore if */
  2562. if (!hasWarned) {
  2563. hasWarned = true;
  2564. // @ts-ignore `console.info` cannot be null error
  2565. console[console.info ? 'info' : 'log'](`<Suspense> is an experimental feature and its API will likely change.`);
  2566. }
  2567. const { p: patch, m: move, um: unmount, n: next, o: { parentNode, remove } } = rendererInternals;
  2568. const timeout = vnode.props ? shared.toNumber(vnode.props.timeout) : undefined;
  2569. {
  2570. assertNumber(timeout, `Suspense timeout`);
  2571. }
  2572. const suspense = {
  2573. vnode,
  2574. parent,
  2575. parentComponent,
  2576. isSVG,
  2577. container,
  2578. hiddenContainer,
  2579. anchor,
  2580. deps: 0,
  2581. pendingId: 0,
  2582. timeout: typeof timeout === 'number' ? timeout : -1,
  2583. activeBranch: null,
  2584. pendingBranch: null,
  2585. isInFallback: true,
  2586. isHydrating,
  2587. isUnmounted: false,
  2588. effects: [],
  2589. resolve(resume = false) {
  2590. {
  2591. if (!resume && !suspense.pendingBranch) {
  2592. throw new Error(`suspense.resolve() is called without a pending branch.`);
  2593. }
  2594. if (suspense.isUnmounted) {
  2595. throw new Error(`suspense.resolve() is called on an already unmounted suspense boundary.`);
  2596. }
  2597. }
  2598. const { vnode, activeBranch, pendingBranch, pendingId, effects, parentComponent, container } = suspense;
  2599. if (suspense.isHydrating) {
  2600. suspense.isHydrating = false;
  2601. }
  2602. else if (!resume) {
  2603. const delayEnter = activeBranch &&
  2604. pendingBranch.transition &&
  2605. pendingBranch.transition.mode === 'out-in';
  2606. if (delayEnter) {
  2607. activeBranch.transition.afterLeave = () => {
  2608. if (pendingId === suspense.pendingId) {
  2609. move(pendingBranch, container, anchor, 0 /* MoveType.ENTER */);
  2610. }
  2611. };
  2612. }
  2613. // this is initial anchor on mount
  2614. let { anchor } = suspense;
  2615. // unmount current active tree
  2616. if (activeBranch) {
  2617. // if the fallback tree was mounted, it may have been moved
  2618. // as part of a parent suspense. get the latest anchor for insertion
  2619. anchor = next(activeBranch);
  2620. unmount(activeBranch, parentComponent, suspense, true);
  2621. }
  2622. if (!delayEnter) {
  2623. // move content from off-dom container to actual container
  2624. move(pendingBranch, container, anchor, 0 /* MoveType.ENTER */);
  2625. }
  2626. }
  2627. setActiveBranch(suspense, pendingBranch);
  2628. suspense.pendingBranch = null;
  2629. suspense.isInFallback = false;
  2630. // flush buffered effects
  2631. // check if there is a pending parent suspense
  2632. let parent = suspense.parent;
  2633. let hasUnresolvedAncestor = false;
  2634. while (parent) {
  2635. if (parent.pendingBranch) {
  2636. // found a pending parent suspense, merge buffered post jobs
  2637. // into that parent
  2638. parent.effects.push(...effects);
  2639. hasUnresolvedAncestor = true;
  2640. break;
  2641. }
  2642. parent = parent.parent;
  2643. }
  2644. // no pending parent suspense, flush all jobs
  2645. if (!hasUnresolvedAncestor) {
  2646. queuePostFlushCb(effects);
  2647. }
  2648. suspense.effects = [];
  2649. // invoke @resolve event
  2650. triggerEvent(vnode, 'onResolve');
  2651. },
  2652. fallback(fallbackVNode) {
  2653. if (!suspense.pendingBranch) {
  2654. return;
  2655. }
  2656. const { vnode, activeBranch, parentComponent, container, isSVG } = suspense;
  2657. // invoke @fallback event
  2658. triggerEvent(vnode, 'onFallback');
  2659. const anchor = next(activeBranch);
  2660. const mountFallback = () => {
  2661. if (!suspense.isInFallback) {
  2662. return;
  2663. }
  2664. // mount the fallback tree
  2665. patch(null, fallbackVNode, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2666. isSVG, slotScopeIds, optimized);
  2667. setActiveBranch(suspense, fallbackVNode);
  2668. };
  2669. const delayEnter = fallbackVNode.transition && fallbackVNode.transition.mode === 'out-in';
  2670. if (delayEnter) {
  2671. activeBranch.transition.afterLeave = mountFallback;
  2672. }
  2673. suspense.isInFallback = true;
  2674. // unmount current active branch
  2675. unmount(activeBranch, parentComponent, null, // no suspense so unmount hooks fire now
  2676. true // shouldRemove
  2677. );
  2678. if (!delayEnter) {
  2679. mountFallback();
  2680. }
  2681. },
  2682. move(container, anchor, type) {
  2683. suspense.activeBranch &&
  2684. move(suspense.activeBranch, container, anchor, type);
  2685. suspense.container = container;
  2686. },
  2687. next() {
  2688. return suspense.activeBranch && next(suspense.activeBranch);
  2689. },
  2690. registerDep(instance, setupRenderEffect) {
  2691. const isInPendingSuspense = !!suspense.pendingBranch;
  2692. if (isInPendingSuspense) {
  2693. suspense.deps++;
  2694. }
  2695. const hydratedEl = instance.vnode.el;
  2696. instance
  2697. .asyncDep.catch(err => {
  2698. handleError(err, instance, 0 /* ErrorCodes.SETUP_FUNCTION */);
  2699. })
  2700. .then(asyncSetupResult => {
  2701. // retry when the setup() promise resolves.
  2702. // component may have been unmounted before resolve.
  2703. if (instance.isUnmounted ||
  2704. suspense.isUnmounted ||
  2705. suspense.pendingId !== instance.suspenseId) {
  2706. return;
  2707. }
  2708. // retry from this component
  2709. instance.asyncResolved = true;
  2710. const { vnode } = instance;
  2711. {
  2712. pushWarningContext(vnode);
  2713. }
  2714. handleSetupResult(instance, asyncSetupResult, false);
  2715. if (hydratedEl) {
  2716. // vnode may have been replaced if an update happened before the
  2717. // async dep is resolved.
  2718. vnode.el = hydratedEl;
  2719. }
  2720. const placeholder = !hydratedEl && instance.subTree.el;
  2721. setupRenderEffect(instance, vnode,
  2722. // component may have been moved before resolve.
  2723. // if this is not a hydration, instance.subTree will be the comment
  2724. // placeholder.
  2725. parentNode(hydratedEl || instance.subTree.el),
  2726. // anchor will not be used if this is hydration, so only need to
  2727. // consider the comment placeholder case.
  2728. hydratedEl ? null : next(instance.subTree), suspense, isSVG, optimized);
  2729. if (placeholder) {
  2730. remove(placeholder);
  2731. }
  2732. updateHOCHostEl(instance, vnode.el);
  2733. {
  2734. popWarningContext();
  2735. }
  2736. // only decrease deps count if suspense is not already resolved
  2737. if (isInPendingSuspense && --suspense.deps === 0) {
  2738. suspense.resolve();
  2739. }
  2740. });
  2741. },
  2742. unmount(parentSuspense, doRemove) {
  2743. suspense.isUnmounted = true;
  2744. if (suspense.activeBranch) {
  2745. unmount(suspense.activeBranch, parentComponent, parentSuspense, doRemove);
  2746. }
  2747. if (suspense.pendingBranch) {
  2748. unmount(suspense.pendingBranch, parentComponent, parentSuspense, doRemove);
  2749. }
  2750. }
  2751. };
  2752. return suspense;
  2753. }
  2754. function hydrateSuspense(node, vnode, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, rendererInternals, hydrateNode) {
  2755. /* eslint-disable no-restricted-globals */
  2756. const suspense = (vnode.suspense = createSuspenseBoundary(vnode, parentSuspense, parentComponent, node.parentNode, document.createElement('div'), null, isSVG, slotScopeIds, optimized, rendererInternals, true /* hydrating */));
  2757. // there are two possible scenarios for server-rendered suspense:
  2758. // - success: ssr content should be fully resolved
  2759. // - failure: ssr content should be the fallback branch.
  2760. // however, on the client we don't really know if it has failed or not
  2761. // attempt to hydrate the DOM assuming it has succeeded, but we still
  2762. // need to construct a suspense boundary first
  2763. const result = hydrateNode(node, (suspense.pendingBranch = vnode.ssContent), parentComponent, suspense, slotScopeIds, optimized);
  2764. if (suspense.deps === 0) {
  2765. suspense.resolve();
  2766. }
  2767. return result;
  2768. /* eslint-enable no-restricted-globals */
  2769. }
  2770. function normalizeSuspenseChildren(vnode) {
  2771. const { shapeFlag, children } = vnode;
  2772. const isSlotChildren = shapeFlag & 32 /* ShapeFlags.SLOTS_CHILDREN */;
  2773. vnode.ssContent = normalizeSuspenseSlot(isSlotChildren ? children.default : children);
  2774. vnode.ssFallback = isSlotChildren
  2775. ? normalizeSuspenseSlot(children.fallback)
  2776. : createVNode(Comment);
  2777. }
  2778. function normalizeSuspenseSlot(s) {
  2779. let block;
  2780. if (shared.isFunction(s)) {
  2781. const trackBlock = isBlockTreeEnabled && s._c;
  2782. if (trackBlock) {
  2783. // disableTracking: false
  2784. // allow block tracking for compiled slots
  2785. // (see ./componentRenderContext.ts)
  2786. s._d = false;
  2787. openBlock();
  2788. }
  2789. s = s();
  2790. if (trackBlock) {
  2791. s._d = true;
  2792. block = currentBlock;
  2793. closeBlock();
  2794. }
  2795. }
  2796. if (shared.isArray(s)) {
  2797. const singleChild = filterSingleRoot(s);
  2798. if (!singleChild) {
  2799. warn(`<Suspense> slots expect a single root node.`);
  2800. }
  2801. s = singleChild;
  2802. }
  2803. s = normalizeVNode(s);
  2804. if (block && !s.dynamicChildren) {
  2805. s.dynamicChildren = block.filter(c => c !== s);
  2806. }
  2807. return s;
  2808. }
  2809. function queueEffectWithSuspense(fn, suspense) {
  2810. if (suspense && suspense.pendingBranch) {
  2811. if (shared.isArray(fn)) {
  2812. suspense.effects.push(...fn);
  2813. }
  2814. else {
  2815. suspense.effects.push(fn);
  2816. }
  2817. }
  2818. else {
  2819. queuePostFlushCb(fn);
  2820. }
  2821. }
  2822. function setActiveBranch(suspense, branch) {
  2823. suspense.activeBranch = branch;
  2824. const { vnode, parentComponent } = suspense;
  2825. const el = (vnode.el = branch.el);
  2826. // in case suspense is the root node of a component,
  2827. // recursively update the HOC el
  2828. if (parentComponent && parentComponent.subTree === vnode) {
  2829. parentComponent.vnode.el = el;
  2830. updateHOCHostEl(parentComponent, el);
  2831. }
  2832. }
  2833. function provide(key, value) {
  2834. if (!currentInstance) {
  2835. {
  2836. warn(`provide() can only be used inside setup().`);
  2837. }
  2838. }
  2839. else {
  2840. let provides = currentInstance.provides;
  2841. // by default an instance inherits its parent's provides object
  2842. // but when it needs to provide values of its own, it creates its
  2843. // own provides object using parent provides object as prototype.
  2844. // this way in `inject` we can simply look up injections from direct
  2845. // parent and let the prototype chain do the work.
  2846. const parentProvides = currentInstance.parent && currentInstance.parent.provides;
  2847. if (parentProvides === provides) {
  2848. provides = currentInstance.provides = Object.create(parentProvides);
  2849. }
  2850. // TS doesn't allow symbol as index type
  2851. provides[key] = value;
  2852. // 当实例为 App 时,同步到全局 provide
  2853. if (currentInstance.type.mpType === 'app') {
  2854. currentInstance.appContext.app.provide(key, value);
  2855. }
  2856. }
  2857. }
  2858. function inject(key, defaultValue, treatDefaultAsFactory = false) {
  2859. // fallback to `currentRenderingInstance` so that this can be called in
  2860. // a functional component
  2861. const instance = currentInstance || currentRenderingInstance;
  2862. if (instance) {
  2863. // #2400
  2864. // to support `app.use` plugins,
  2865. // fallback to appContext's `provides` if the instance is at root
  2866. const provides = instance.parent == null
  2867. ? instance.vnode.appContext && instance.vnode.appContext.provides
  2868. : instance.parent.provides;
  2869. if (provides && key in provides) {
  2870. // TS doesn't allow symbol as index type
  2871. return provides[key];
  2872. }
  2873. else if (arguments.length > 1) {
  2874. return treatDefaultAsFactory && shared.isFunction(defaultValue)
  2875. ? defaultValue.call(instance.proxy)
  2876. : defaultValue;
  2877. }
  2878. else {
  2879. warn(`injection "${String(key)}" not found.`);
  2880. }
  2881. }
  2882. else {
  2883. warn(`inject() can only be used inside setup() or functional components.`);
  2884. }
  2885. }
  2886. // Simple effect.
  2887. function watchEffect(effect, options) {
  2888. return doWatch(effect, null, options);
  2889. }
  2890. function watchPostEffect(effect, options) {
  2891. return doWatch(effect, null, { ...options, flush: 'post' } );
  2892. }
  2893. function watchSyncEffect(effect, options) {
  2894. return doWatch(effect, null, { ...options, flush: 'sync' } );
  2895. }
  2896. // initial value for watchers to trigger on undefined initial values
  2897. const INITIAL_WATCHER_VALUE = {};
  2898. // implementation
  2899. function watch(source, cb, options) {
  2900. if (!shared.isFunction(cb)) {
  2901. warn(`\`watch(fn, options?)\` signature has been moved to a separate API. ` +
  2902. `Use \`watchEffect(fn, options?)\` instead. \`watch\` now only ` +
  2903. `supports \`watch(source, cb, options?) signature.`);
  2904. }
  2905. return doWatch(source, cb, options);
  2906. }
  2907. function doWatch(source, cb, { immediate, deep, flush, onTrack, onTrigger } = shared.EMPTY_OBJ) {
  2908. if (!cb) {
  2909. if (immediate !== undefined) {
  2910. warn(`watch() "immediate" option is only respected when using the ` +
  2911. `watch(source, callback, options?) signature.`);
  2912. }
  2913. if (deep !== undefined) {
  2914. warn(`watch() "deep" option is only respected when using the ` +
  2915. `watch(source, callback, options?) signature.`);
  2916. }
  2917. }
  2918. const warnInvalidSource = (s) => {
  2919. warn(`Invalid watch source: `, s, `A watch source can only be a getter/effect function, a ref, ` +
  2920. `a reactive object, or an array of these types.`);
  2921. };
  2922. const instance = getCurrentScope() === (currentInstance === null || currentInstance === void 0 ? void 0 : currentInstance.scope) ? currentInstance : null;
  2923. // const instance = currentInstance
  2924. let getter;
  2925. let forceTrigger = false;
  2926. let isMultiSource = false;
  2927. if (isRef(source)) {
  2928. getter = () => source.value;
  2929. forceTrigger = isShallow(source);
  2930. }
  2931. else if (isReactive(source)) {
  2932. getter = () => source;
  2933. deep = true;
  2934. }
  2935. else if (shared.isArray(source)) {
  2936. isMultiSource = true;
  2937. forceTrigger = source.some(s => isReactive(s) || isShallow(s));
  2938. getter = () => source.map(s => {
  2939. if (isRef(s)) {
  2940. return s.value;
  2941. }
  2942. else if (isReactive(s)) {
  2943. return traverse(s);
  2944. }
  2945. else if (shared.isFunction(s)) {
  2946. return callWithErrorHandling(s, instance, 2 /* ErrorCodes.WATCH_GETTER */);
  2947. }
  2948. else {
  2949. warnInvalidSource(s);
  2950. }
  2951. });
  2952. }
  2953. else if (shared.isFunction(source)) {
  2954. if (cb) {
  2955. // getter with cb
  2956. getter = () => callWithErrorHandling(source, instance, 2 /* ErrorCodes.WATCH_GETTER */);
  2957. }
  2958. else {
  2959. // no cb -> simple effect
  2960. getter = () => {
  2961. if (instance && instance.isUnmounted) {
  2962. return;
  2963. }
  2964. if (cleanup) {
  2965. cleanup();
  2966. }
  2967. return callWithAsyncErrorHandling(source, instance, 3 /* ErrorCodes.WATCH_CALLBACK */, [onCleanup]);
  2968. };
  2969. }
  2970. }
  2971. else {
  2972. getter = shared.NOOP;
  2973. warnInvalidSource(source);
  2974. }
  2975. if (cb && deep) {
  2976. const baseGetter = getter;
  2977. getter = () => traverse(baseGetter());
  2978. }
  2979. let cleanup;
  2980. let onCleanup = (fn) => {
  2981. cleanup = effect.onStop = () => {
  2982. callWithErrorHandling(fn, instance, 4 /* ErrorCodes.WATCH_CLEANUP */);
  2983. };
  2984. };
  2985. // in SSR there is no need to setup an actual effect, and it should be noop
  2986. // unless it's eager or sync flush
  2987. let ssrCleanup;
  2988. if (exports.isInSSRComponentSetup) {
  2989. // we will also not call the invalidate callback (+ runner is not set up)
  2990. onCleanup = shared.NOOP;
  2991. if (!cb) {
  2992. getter();
  2993. }
  2994. else if (immediate) {
  2995. callWithAsyncErrorHandling(cb, instance, 3 /* ErrorCodes.WATCH_CALLBACK */, [
  2996. getter(),
  2997. isMultiSource ? [] : undefined,
  2998. onCleanup
  2999. ]);
  3000. }
  3001. if (flush === 'sync') {
  3002. const ctx = useSSRContext();
  3003. ssrCleanup = ctx.__watcherHandles || (ctx.__watcherHandles = []);
  3004. }
  3005. else {
  3006. return shared.NOOP;
  3007. }
  3008. }
  3009. let oldValue = isMultiSource
  3010. ? new Array(source.length).fill(INITIAL_WATCHER_VALUE)
  3011. : INITIAL_WATCHER_VALUE;
  3012. const job = () => {
  3013. if (!effect.active) {
  3014. return;
  3015. }
  3016. if (cb) {
  3017. // watch(source, cb)
  3018. const newValue = effect.run();
  3019. if (deep ||
  3020. forceTrigger ||
  3021. (isMultiSource
  3022. ? newValue.some((v, i) => shared.hasChanged(v, oldValue[i]))
  3023. : shared.hasChanged(newValue, oldValue)) ||
  3024. (false )) {
  3025. // cleanup before running cb again
  3026. if (cleanup) {
  3027. cleanup();
  3028. }
  3029. callWithAsyncErrorHandling(cb, instance, 3 /* ErrorCodes.WATCH_CALLBACK */, [
  3030. newValue,
  3031. // pass undefined as the old value when it's changed for the first time
  3032. oldValue === INITIAL_WATCHER_VALUE
  3033. ? undefined
  3034. : isMultiSource && oldValue[0] === INITIAL_WATCHER_VALUE
  3035. ? []
  3036. : oldValue,
  3037. onCleanup
  3038. ]);
  3039. oldValue = newValue;
  3040. }
  3041. }
  3042. else {
  3043. // watchEffect
  3044. effect.run();
  3045. }
  3046. };
  3047. // important: mark the job as a watcher callback so that scheduler knows
  3048. // it is allowed to self-trigger (#1727)
  3049. job.allowRecurse = !!cb;
  3050. let scheduler;
  3051. if (flush === 'sync') {
  3052. scheduler = job; // the scheduler function gets called directly
  3053. }
  3054. else if (flush === 'post') {
  3055. scheduler = () => queuePostRenderEffect(job, instance && instance.suspense);
  3056. }
  3057. else {
  3058. // default: 'pre'
  3059. job.pre = true;
  3060. if (instance)
  3061. job.id = instance.uid;
  3062. scheduler = () => queueJob(job);
  3063. }
  3064. const effect = new ReactiveEffect(getter, scheduler);
  3065. {
  3066. effect.onTrack = onTrack;
  3067. effect.onTrigger = onTrigger;
  3068. }
  3069. // initial run
  3070. if (cb) {
  3071. if (immediate) {
  3072. job();
  3073. }
  3074. else {
  3075. oldValue = effect.run();
  3076. }
  3077. }
  3078. else if (flush === 'post') {
  3079. queuePostRenderEffect(effect.run.bind(effect), instance && instance.suspense);
  3080. }
  3081. else {
  3082. effect.run();
  3083. }
  3084. const unwatch = () => {
  3085. effect.stop();
  3086. if (instance && instance.scope) {
  3087. shared.remove(instance.scope.effects, effect);
  3088. }
  3089. };
  3090. if (ssrCleanup)
  3091. ssrCleanup.push(unwatch);
  3092. return unwatch;
  3093. }
  3094. // this.$watch
  3095. function instanceWatch(source, value, options) {
  3096. const publicThis = this.proxy;
  3097. const getter = shared.isString(source)
  3098. ? source.includes('.')
  3099. ? createPathGetter(publicThis, source)
  3100. : () => publicThis[source]
  3101. : source.bind(publicThis, publicThis);
  3102. let cb;
  3103. if (shared.isFunction(value)) {
  3104. cb = value;
  3105. }
  3106. else {
  3107. cb = value.handler;
  3108. options = value;
  3109. }
  3110. const cur = currentInstance;
  3111. setCurrentInstance(this);
  3112. const res = doWatch(getter, cb.bind(publicThis), options);
  3113. if (cur) {
  3114. setCurrentInstance(cur);
  3115. }
  3116. else {
  3117. unsetCurrentInstance();
  3118. }
  3119. return res;
  3120. }
  3121. function createPathGetter(ctx, path) {
  3122. const segments = path.split('.');
  3123. return () => {
  3124. let cur = ctx;
  3125. for (let i = 0; i < segments.length && cur; i++) {
  3126. cur = cur[segments[i]];
  3127. }
  3128. return cur;
  3129. };
  3130. }
  3131. function traverse(value, seen) {
  3132. if (!shared.isObject(value) || value["__v_skip" /* ReactiveFlags.SKIP */]) {
  3133. return value;
  3134. }
  3135. seen = seen || new Set();
  3136. if (seen.has(value)) {
  3137. return value;
  3138. }
  3139. seen.add(value);
  3140. if (isRef(value)) {
  3141. traverse(value.value, seen);
  3142. }
  3143. else if (shared.isArray(value)) {
  3144. for (let i = 0; i < value.length; i++) {
  3145. traverse(value[i], seen);
  3146. }
  3147. }
  3148. else if (shared.isSet(value) || shared.isMap(value)) {
  3149. value.forEach((v) => {
  3150. traverse(v, seen);
  3151. });
  3152. }
  3153. else if (shared.isPlainObject(value)) {
  3154. for (const key in value) {
  3155. traverse(value[key], seen);
  3156. }
  3157. }
  3158. return value;
  3159. }
  3160. function useTransitionState() {
  3161. const state = {
  3162. isMounted: false,
  3163. isLeaving: false,
  3164. isUnmounting: false,
  3165. leavingVNodes: new Map()
  3166. };
  3167. onMounted(() => {
  3168. state.isMounted = true;
  3169. });
  3170. onBeforeUnmount(() => {
  3171. state.isUnmounting = true;
  3172. });
  3173. return state;
  3174. }
  3175. const TransitionHookValidator = [Function, Array];
  3176. const BaseTransitionPropsValidators = {
  3177. mode: String,
  3178. appear: Boolean,
  3179. persisted: Boolean,
  3180. // enter
  3181. onBeforeEnter: TransitionHookValidator,
  3182. onEnter: TransitionHookValidator,
  3183. onAfterEnter: TransitionHookValidator,
  3184. onEnterCancelled: TransitionHookValidator,
  3185. // leave
  3186. onBeforeLeave: TransitionHookValidator,
  3187. onLeave: TransitionHookValidator,
  3188. onAfterLeave: TransitionHookValidator,
  3189. onLeaveCancelled: TransitionHookValidator,
  3190. // appear
  3191. onBeforeAppear: TransitionHookValidator,
  3192. onAppear: TransitionHookValidator,
  3193. onAfterAppear: TransitionHookValidator,
  3194. onAppearCancelled: TransitionHookValidator
  3195. };
  3196. const BaseTransitionImpl = {
  3197. name: `BaseTransition`,
  3198. props: BaseTransitionPropsValidators,
  3199. setup(props, { slots }) {
  3200. const instance = getCurrentInstance();
  3201. const state = useTransitionState();
  3202. let prevTransitionKey;
  3203. return () => {
  3204. const children = slots.default && getTransitionRawChildren(slots.default(), true);
  3205. if (!children || !children.length) {
  3206. return;
  3207. }
  3208. let child = children[0];
  3209. if (children.length > 1) {
  3210. let hasFound = false;
  3211. // locate first non-comment child
  3212. for (const c of children) {
  3213. if (c.type !== Comment) {
  3214. if (hasFound) {
  3215. // warn more than one non-comment child
  3216. warn('<transition> can only be used on a single element or component. ' +
  3217. 'Use <transition-group> for lists.');
  3218. break;
  3219. }
  3220. child = c;
  3221. hasFound = true;
  3222. }
  3223. }
  3224. }
  3225. // there's no need to track reactivity for these props so use the raw
  3226. // props for a bit better perf
  3227. const rawProps = toRaw(props);
  3228. const { mode } = rawProps;
  3229. // check mode
  3230. if (mode &&
  3231. mode !== 'in-out' &&
  3232. mode !== 'out-in' &&
  3233. mode !== 'default') {
  3234. warn(`invalid <transition> mode: ${mode}`);
  3235. }
  3236. if (state.isLeaving) {
  3237. return emptyPlaceholder(child);
  3238. }
  3239. // in the case of <transition><keep-alive/></transition>, we need to
  3240. // compare the type of the kept-alive children.
  3241. const innerChild = getKeepAliveChild(child);
  3242. if (!innerChild) {
  3243. return emptyPlaceholder(child);
  3244. }
  3245. const enterHooks = resolveTransitionHooks(innerChild, rawProps, state, instance);
  3246. setTransitionHooks(innerChild, enterHooks);
  3247. const oldChild = instance.subTree;
  3248. const oldInnerChild = oldChild && getKeepAliveChild(oldChild);
  3249. let transitionKeyChanged = false;
  3250. const { getTransitionKey } = innerChild.type;
  3251. if (getTransitionKey) {
  3252. const key = getTransitionKey();
  3253. if (prevTransitionKey === undefined) {
  3254. prevTransitionKey = key;
  3255. }
  3256. else if (key !== prevTransitionKey) {
  3257. prevTransitionKey = key;
  3258. transitionKeyChanged = true;
  3259. }
  3260. }
  3261. // handle mode
  3262. if (oldInnerChild &&
  3263. oldInnerChild.type !== Comment &&
  3264. (!isSameVNodeType(innerChild, oldInnerChild) || transitionKeyChanged)) {
  3265. const leavingHooks = resolveTransitionHooks(oldInnerChild, rawProps, state, instance);
  3266. // update old tree's hooks in case of dynamic transition
  3267. setTransitionHooks(oldInnerChild, leavingHooks);
  3268. // switching between different views
  3269. if (mode === 'out-in') {
  3270. state.isLeaving = true;
  3271. // return placeholder node and queue update when leave finishes
  3272. leavingHooks.afterLeave = () => {
  3273. state.isLeaving = false;
  3274. // #6835
  3275. // it also needs to be updated when active is undefined
  3276. if (instance.update.active !== false) {
  3277. instance.update();
  3278. }
  3279. };
  3280. return emptyPlaceholder(child);
  3281. }
  3282. else if (mode === 'in-out' && innerChild.type !== Comment) {
  3283. leavingHooks.delayLeave = (el, earlyRemove, delayedLeave) => {
  3284. const leavingVNodesCache = getLeavingNodesForType(state, oldInnerChild);
  3285. leavingVNodesCache[String(oldInnerChild.key)] = oldInnerChild;
  3286. // early removal callback
  3287. el._leaveCb = () => {
  3288. earlyRemove();
  3289. el._leaveCb = undefined;
  3290. delete enterHooks.delayedLeave;
  3291. };
  3292. enterHooks.delayedLeave = delayedLeave;
  3293. };
  3294. }
  3295. }
  3296. return child;
  3297. };
  3298. }
  3299. };
  3300. // export the public type for h/tsx inference
  3301. // also to avoid inline import() in generated d.ts files
  3302. const BaseTransition = BaseTransitionImpl;
  3303. function getLeavingNodesForType(state, vnode) {
  3304. const { leavingVNodes } = state;
  3305. let leavingVNodesCache = leavingVNodes.get(vnode.type);
  3306. if (!leavingVNodesCache) {
  3307. leavingVNodesCache = Object.create(null);
  3308. leavingVNodes.set(vnode.type, leavingVNodesCache);
  3309. }
  3310. return leavingVNodesCache;
  3311. }
  3312. // The transition hooks are attached to the vnode as vnode.transition
  3313. // and will be called at appropriate timing in the renderer.
  3314. function resolveTransitionHooks(vnode, props, state, instance) {
  3315. const { appear, mode, persisted = false, onBeforeEnter, onEnter, onAfterEnter, onEnterCancelled, onBeforeLeave, onLeave, onAfterLeave, onLeaveCancelled, onBeforeAppear, onAppear, onAfterAppear, onAppearCancelled } = props;
  3316. const key = String(vnode.key);
  3317. const leavingVNodesCache = getLeavingNodesForType(state, vnode);
  3318. const callHook = (hook, args) => {
  3319. hook &&
  3320. callWithAsyncErrorHandling(hook, instance, 9 /* ErrorCodes.TRANSITION_HOOK */, args);
  3321. };
  3322. const callAsyncHook = (hook, args) => {
  3323. const done = args[1];
  3324. callHook(hook, args);
  3325. if (shared.isArray(hook)) {
  3326. if (hook.every(hook => hook.length <= 1))
  3327. done();
  3328. }
  3329. else if (hook.length <= 1) {
  3330. done();
  3331. }
  3332. };
  3333. const hooks = {
  3334. mode,
  3335. persisted,
  3336. beforeEnter(el) {
  3337. let hook = onBeforeEnter;
  3338. if (!state.isMounted) {
  3339. if (appear) {
  3340. hook = onBeforeAppear || onBeforeEnter;
  3341. }
  3342. else {
  3343. return;
  3344. }
  3345. }
  3346. // for same element (v-show)
  3347. if (el._leaveCb) {
  3348. el._leaveCb(true /* cancelled */);
  3349. }
  3350. // for toggled element with same key (v-if)
  3351. const leavingVNode = leavingVNodesCache[key];
  3352. if (leavingVNode &&
  3353. isSameVNodeType(vnode, leavingVNode) &&
  3354. leavingVNode.el._leaveCb) {
  3355. // force early removal (not cancelled)
  3356. leavingVNode.el._leaveCb();
  3357. }
  3358. callHook(hook, [el]);
  3359. },
  3360. enter(el) {
  3361. let hook = onEnter;
  3362. let afterHook = onAfterEnter;
  3363. let cancelHook = onEnterCancelled;
  3364. if (!state.isMounted) {
  3365. if (appear) {
  3366. hook = onAppear || onEnter;
  3367. afterHook = onAfterAppear || onAfterEnter;
  3368. cancelHook = onAppearCancelled || onEnterCancelled;
  3369. }
  3370. else {
  3371. return;
  3372. }
  3373. }
  3374. let called = false;
  3375. const done = (el._enterCb = (cancelled) => {
  3376. if (called)
  3377. return;
  3378. called = true;
  3379. if (cancelled) {
  3380. callHook(cancelHook, [el]);
  3381. }
  3382. else {
  3383. callHook(afterHook, [el]);
  3384. }
  3385. if (hooks.delayedLeave) {
  3386. hooks.delayedLeave();
  3387. }
  3388. el._enterCb = undefined;
  3389. });
  3390. if (hook) {
  3391. callAsyncHook(hook, [el, done]);
  3392. }
  3393. else {
  3394. done();
  3395. }
  3396. },
  3397. leave(el, remove) {
  3398. const key = String(vnode.key);
  3399. if (el._enterCb) {
  3400. el._enterCb(true /* cancelled */);
  3401. }
  3402. if (state.isUnmounting) {
  3403. return remove();
  3404. }
  3405. callHook(onBeforeLeave, [el]);
  3406. let called = false;
  3407. const done = (el._leaveCb = (cancelled) => {
  3408. if (called)
  3409. return;
  3410. called = true;
  3411. remove();
  3412. if (cancelled) {
  3413. callHook(onLeaveCancelled, [el]);
  3414. }
  3415. else {
  3416. callHook(onAfterLeave, [el]);
  3417. }
  3418. el._leaveCb = undefined;
  3419. if (leavingVNodesCache[key] === vnode) {
  3420. delete leavingVNodesCache[key];
  3421. }
  3422. });
  3423. leavingVNodesCache[key] = vnode;
  3424. if (onLeave) {
  3425. callAsyncHook(onLeave, [el, done]);
  3426. }
  3427. else {
  3428. done();
  3429. }
  3430. },
  3431. clone(vnode) {
  3432. return resolveTransitionHooks(vnode, props, state, instance);
  3433. }
  3434. };
  3435. return hooks;
  3436. }
  3437. // the placeholder really only handles one special case: KeepAlive
  3438. // in the case of a KeepAlive in a leave phase we need to return a KeepAlive
  3439. // placeholder with empty content to avoid the KeepAlive instance from being
  3440. // unmounted.
  3441. function emptyPlaceholder(vnode) {
  3442. if (isKeepAlive(vnode)) {
  3443. vnode = cloneVNode(vnode);
  3444. vnode.children = null;
  3445. return vnode;
  3446. }
  3447. }
  3448. function getKeepAliveChild(vnode) {
  3449. return isKeepAlive(vnode)
  3450. ? vnode.children
  3451. ? vnode.children[0]
  3452. : undefined
  3453. : vnode;
  3454. }
  3455. function setTransitionHooks(vnode, hooks) {
  3456. if (vnode.shapeFlag & 6 /* ShapeFlags.COMPONENT */ && vnode.component) {
  3457. setTransitionHooks(vnode.component.subTree, hooks);
  3458. }
  3459. else if (vnode.shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
  3460. vnode.ssContent.transition = hooks.clone(vnode.ssContent);
  3461. vnode.ssFallback.transition = hooks.clone(vnode.ssFallback);
  3462. }
  3463. else {
  3464. vnode.transition = hooks;
  3465. }
  3466. }
  3467. function getTransitionRawChildren(children, keepComment = false, parentKey) {
  3468. let ret = [];
  3469. let keyedFragmentCount = 0;
  3470. for (let i = 0; i < children.length; i++) {
  3471. let child = children[i];
  3472. // #5360 inherit parent key in case of <template v-for>
  3473. const key = parentKey == null
  3474. ? child.key
  3475. : String(parentKey) + String(child.key != null ? child.key : i);
  3476. // handle fragment children case, e.g. v-for
  3477. if (child.type === Fragment) {
  3478. if (child.patchFlag & 128 /* PatchFlags.KEYED_FRAGMENT */)
  3479. keyedFragmentCount++;
  3480. ret = ret.concat(getTransitionRawChildren(child.children, keepComment, key));
  3481. }
  3482. // comment placeholders should be skipped, e.g. v-if
  3483. else if (keepComment || child.type !== Comment) {
  3484. ret.push(key != null ? cloneVNode(child, { key }) : child);
  3485. }
  3486. }
  3487. // #1126 if a transition children list contains multiple sub fragments, these
  3488. // fragments will be merged into a flat children array. Since each v-for
  3489. // fragment may contain different static bindings inside, we need to de-op
  3490. // these children to force full diffs to ensure correct behavior.
  3491. if (keyedFragmentCount > 1) {
  3492. for (let i = 0; i < ret.length; i++) {
  3493. ret[i].patchFlag = -2 /* PatchFlags.BAIL */;
  3494. }
  3495. }
  3496. return ret;
  3497. }
  3498. // implementation, close to no-op
  3499. function defineComponent(options) {
  3500. return shared.isFunction(options) ? { setup: options, name: options.name } : options;
  3501. }
  3502. const isAsyncWrapper = (i) => !!i.type.__asyncLoader;
  3503. function defineAsyncComponent(source) {
  3504. if (shared.isFunction(source)) {
  3505. source = { loader: source };
  3506. }
  3507. const { loader, loadingComponent, errorComponent, delay = 200, timeout, // undefined = never times out
  3508. suspensible = true, onError: userOnError } = source;
  3509. let pendingRequest = null;
  3510. let resolvedComp;
  3511. let retries = 0;
  3512. const retry = () => {
  3513. retries++;
  3514. pendingRequest = null;
  3515. return load();
  3516. };
  3517. const load = () => {
  3518. let thisRequest;
  3519. return (pendingRequest ||
  3520. (thisRequest = pendingRequest =
  3521. loader()
  3522. .catch(err => {
  3523. err = err instanceof Error ? err : new Error(String(err));
  3524. if (userOnError) {
  3525. return new Promise((resolve, reject) => {
  3526. const userRetry = () => resolve(retry());
  3527. const userFail = () => reject(err);
  3528. userOnError(err, userRetry, userFail, retries + 1);
  3529. });
  3530. }
  3531. else {
  3532. throw err;
  3533. }
  3534. })
  3535. .then((comp) => {
  3536. if (thisRequest !== pendingRequest && pendingRequest) {
  3537. return pendingRequest;
  3538. }
  3539. if (!comp) {
  3540. warn(`Async component loader resolved to undefined. ` +
  3541. `If you are using retry(), make sure to return its return value.`);
  3542. }
  3543. // interop module default
  3544. if (comp &&
  3545. (comp.__esModule || comp[Symbol.toStringTag] === 'Module')) {
  3546. comp = comp.default;
  3547. }
  3548. if (comp && !shared.isObject(comp) && !shared.isFunction(comp)) {
  3549. throw new Error(`Invalid async component load result: ${comp}`);
  3550. }
  3551. resolvedComp = comp;
  3552. return comp;
  3553. })));
  3554. };
  3555. return defineComponent({
  3556. name: 'AsyncComponentWrapper',
  3557. __asyncLoader: load,
  3558. get __asyncResolved() {
  3559. return resolvedComp;
  3560. },
  3561. setup() {
  3562. const instance = currentInstance;
  3563. // already resolved
  3564. if (resolvedComp) {
  3565. return () => createInnerComp(resolvedComp, instance);
  3566. }
  3567. const onError = (err) => {
  3568. pendingRequest = null;
  3569. handleError(err, instance, 13 /* ErrorCodes.ASYNC_COMPONENT_LOADER */, !errorComponent /* do not throw in dev if user provided error component */);
  3570. };
  3571. // suspense-controlled or SSR.
  3572. if ((suspensible && instance.suspense) ||
  3573. (exports.isInSSRComponentSetup)) {
  3574. return load()
  3575. .then(comp => {
  3576. return () => createInnerComp(comp, instance);
  3577. })
  3578. .catch(err => {
  3579. onError(err);
  3580. return () => errorComponent
  3581. ? createVNode(errorComponent, {
  3582. error: err
  3583. })
  3584. : null;
  3585. });
  3586. }
  3587. const loaded = ref(false);
  3588. const error = ref();
  3589. const delayed = ref(!!delay);
  3590. if (delay) {
  3591. setTimeout(() => {
  3592. delayed.value = false;
  3593. }, delay);
  3594. }
  3595. if (timeout != null) {
  3596. setTimeout(() => {
  3597. if (!loaded.value && !error.value) {
  3598. const err = new Error(`Async component timed out after ${timeout}ms.`);
  3599. onError(err);
  3600. error.value = err;
  3601. }
  3602. }, timeout);
  3603. }
  3604. load()
  3605. .then(() => {
  3606. loaded.value = true;
  3607. if (instance.parent && isKeepAlive(instance.parent.vnode)) {
  3608. // parent is keep-alive, force update so the loaded component's
  3609. // name is taken into account
  3610. queueJob(instance.parent.update);
  3611. }
  3612. })
  3613. .catch(err => {
  3614. onError(err);
  3615. error.value = err;
  3616. });
  3617. return () => {
  3618. if (loaded.value && resolvedComp) {
  3619. return createInnerComp(resolvedComp, instance);
  3620. }
  3621. else if (error.value && errorComponent) {
  3622. return createVNode(errorComponent, {
  3623. error: error.value
  3624. });
  3625. }
  3626. else if (loadingComponent && !delayed.value) {
  3627. return createVNode(loadingComponent);
  3628. }
  3629. };
  3630. }
  3631. });
  3632. }
  3633. function createInnerComp(comp, parent) {
  3634. const { ref, props, children, ce } = parent.vnode;
  3635. const vnode = createVNode(comp, props, children);
  3636. // ensure inner component inherits the async wrapper's ref owner
  3637. vnode.ref = ref;
  3638. // pass the custom element callback on to the inner comp
  3639. // and remove it from the async wrapper
  3640. vnode.ce = ce;
  3641. delete parent.vnode.ce;
  3642. return vnode;
  3643. }
  3644. const isKeepAlive = (vnode) => vnode.type.__isKeepAlive;
  3645. class Cache {
  3646. constructor(max) {
  3647. this.max = max;
  3648. this._cache = new Map();
  3649. this._keys = new Set();
  3650. this._max = parseInt(max, 10);
  3651. }
  3652. get(key) {
  3653. const { _cache, _keys, _max } = this;
  3654. const cached = _cache.get(key);
  3655. if (cached) {
  3656. // make this key the freshest
  3657. _keys.delete(key);
  3658. _keys.add(key);
  3659. }
  3660. else {
  3661. _keys.add(key);
  3662. // prune oldest entry
  3663. if (_max && _keys.size > _max) {
  3664. const staleKey = _keys.values().next().value;
  3665. this.pruneCacheEntry(_cache.get(staleKey));
  3666. this.delete(staleKey);
  3667. }
  3668. }
  3669. return cached;
  3670. }
  3671. set(key, value) {
  3672. this._cache.set(key, value);
  3673. }
  3674. delete(key) {
  3675. this._cache.delete(key);
  3676. this._keys.delete(key);
  3677. }
  3678. forEach(fn, thisArg) {
  3679. this._cache.forEach(fn.bind(thisArg));
  3680. }
  3681. }
  3682. const KeepAliveImpl = {
  3683. name: `KeepAlive`,
  3684. // Marker for special handling inside the renderer. We are not using a ===
  3685. // check directly on KeepAlive in the renderer, because importing it directly
  3686. // would prevent it from being tree-shaken.
  3687. __isKeepAlive: true,
  3688. props: {
  3689. include: [String, RegExp, Array],
  3690. exclude: [String, RegExp, Array],
  3691. max: [String, Number],
  3692. matchBy: {
  3693. type: String,
  3694. default: 'name'
  3695. },
  3696. cache: Object
  3697. },
  3698. setup(props, { slots }) {
  3699. const instance = getCurrentInstance();
  3700. // KeepAlive communicates with the instantiated renderer via the
  3701. // ctx where the renderer passes in its internals,
  3702. // and the KeepAlive instance exposes activate/deactivate implementations.
  3703. // The whole point of this is to avoid importing KeepAlive directly in the
  3704. // renderer to facilitate tree-shaking.
  3705. const sharedContext = instance.ctx;
  3706. // if the internal renderer is not registered, it indicates that this is server-side rendering,
  3707. // for KeepAlive, we just need to render its children
  3708. if (!sharedContext.renderer) {
  3709. return () => {
  3710. const children = slots.default && slots.default();
  3711. return children && children.length === 1 ? children[0] : children;
  3712. };
  3713. }
  3714. if (props.cache && props.max) {
  3715. // fixed by xxxxxx
  3716. warn('The `max` prop will be ignored if you provide a custom caching strategy');
  3717. }
  3718. const cache = props.cache || new Cache(props.max);
  3719. cache.pruneCacheEntry = pruneCacheEntry;
  3720. let current = null;
  3721. function pruneCacheEntry(cached) {
  3722. if (!current ||
  3723. !isSameVNodeType(cached, current) ||
  3724. (props.matchBy === 'key' && cached.key !== current.key)) {
  3725. unmount(cached);
  3726. }
  3727. else if (current) {
  3728. // current active instance should no longer be kept-alive.
  3729. // we can't unmount it now but it might be later, so reset its flag now.
  3730. resetShapeFlag(current);
  3731. }
  3732. }
  3733. const parentSuspense = instance.suspense;
  3734. const { renderer: { p: patch, m: move, um: _unmount, o: { createElement } } } = sharedContext;
  3735. const storageContainer = createElement('div');
  3736. sharedContext.activate = (vnode, container, anchor, isSVG, optimized) => {
  3737. const instance = vnode.component;
  3738. if (instance.ba) {
  3739. const currentState = instance.isDeactivated;
  3740. instance.isDeactivated = false;
  3741. shared.invokeArrayFns(instance.ba);
  3742. instance.isDeactivated = currentState;
  3743. }
  3744. move(vnode, container, anchor, 0 /* MoveType.ENTER */, parentSuspense);
  3745. // in case props have changed
  3746. patch(instance.vnode, vnode, container, anchor, instance, parentSuspense, isSVG, vnode.slotScopeIds, optimized);
  3747. queuePostRenderEffect(() => {
  3748. instance.isDeactivated = false;
  3749. if (instance.a) {
  3750. shared.invokeArrayFns(instance.a);
  3751. }
  3752. const vnodeHook = vnode.props && vnode.props.onVnodeMounted;
  3753. if (vnodeHook) {
  3754. invokeVNodeHook(vnodeHook, instance.parent, vnode);
  3755. }
  3756. }, parentSuspense);
  3757. {
  3758. // Update components tree
  3759. devtoolsComponentAdded(instance);
  3760. }
  3761. };
  3762. sharedContext.deactivate = (vnode) => {
  3763. const instance = vnode.component;
  3764. if (instance.bda) {
  3765. invokeKeepAliveHooks(instance.bda);
  3766. }
  3767. move(vnode, storageContainer, null, 1 /* MoveType.LEAVE */, parentSuspense);
  3768. queuePostRenderEffect(() => {
  3769. if (instance.bda) {
  3770. resetHookState(instance.bda);
  3771. }
  3772. if (instance.da) {
  3773. shared.invokeArrayFns(instance.da);
  3774. }
  3775. const vnodeHook = vnode.props && vnode.props.onVnodeUnmounted;
  3776. if (vnodeHook) {
  3777. invokeVNodeHook(vnodeHook, instance.parent, vnode);
  3778. }
  3779. instance.isDeactivated = true;
  3780. }, parentSuspense);
  3781. {
  3782. // Update components tree
  3783. devtoolsComponentAdded(instance);
  3784. }
  3785. };
  3786. function unmount(vnode) {
  3787. // reset the shapeFlag so it can be properly unmounted
  3788. resetShapeFlag(vnode);
  3789. _unmount(vnode, instance, parentSuspense, true);
  3790. }
  3791. function pruneCache(filter) {
  3792. cache.forEach((vnode, key) => {
  3793. const name = getMatchingName(vnode, props.matchBy);
  3794. if (name && (!filter || !filter(name))) {
  3795. cache.delete(key);
  3796. pruneCacheEntry(vnode);
  3797. }
  3798. });
  3799. }
  3800. // prune cache on include/exclude prop change
  3801. watch(() => [props.include, props.exclude, props.matchBy], ([include, exclude]) => {
  3802. include && pruneCache(name => matches(include, name));
  3803. exclude && pruneCache(name => !matches(exclude, name));
  3804. },
  3805. // prune post-render after `current` has been updated
  3806. { flush: 'post', deep: true });
  3807. // cache sub tree after render
  3808. let pendingCacheKey = null;
  3809. const cacheSubtree = () => {
  3810. // fix #1621, the pendingCacheKey could be 0
  3811. if (pendingCacheKey != null) {
  3812. cache.set(pendingCacheKey, getInnerChild(instance.subTree));
  3813. }
  3814. };
  3815. onMounted(cacheSubtree);
  3816. onUpdated(cacheSubtree);
  3817. onBeforeUnmount(() => {
  3818. cache.forEach((cached, key) => {
  3819. cache.delete(key);
  3820. pruneCacheEntry(cached);
  3821. const { subTree, suspense } = instance;
  3822. const vnode = getInnerChild(subTree);
  3823. if (cached.type === vnode.type &&
  3824. (props.matchBy !== 'key' || cached.key === vnode.key)) {
  3825. // invoke its beforeDeactivate hook here
  3826. if (vnode.component.bda) {
  3827. shared.invokeArrayFns(vnode.component.bda);
  3828. }
  3829. // current instance will be unmounted as part of keep-alive's unmount
  3830. resetShapeFlag(vnode);
  3831. // but invoke its deactivated hook here
  3832. const da = vnode.component.da;
  3833. da && queuePostRenderEffect(da, suspense);
  3834. return;
  3835. }
  3836. });
  3837. });
  3838. return () => {
  3839. pendingCacheKey = null;
  3840. if (!slots.default) {
  3841. return null;
  3842. }
  3843. const children = slots.default();
  3844. const rawVNode = children[0];
  3845. if (children.length > 1) {
  3846. {
  3847. warn(`KeepAlive should contain exactly one component child.`);
  3848. }
  3849. current = null;
  3850. return children;
  3851. }
  3852. else if (!isVNode(rawVNode) ||
  3853. (!(rawVNode.shapeFlag & 4 /* ShapeFlags.STATEFUL_COMPONENT */) &&
  3854. !isSuspense(rawVNode.type))) {
  3855. current = null;
  3856. return rawVNode;
  3857. }
  3858. let vnode = getInnerChild(rawVNode);
  3859. const comp = vnode.type;
  3860. const name = getMatchingName(vnode, props.matchBy);
  3861. const { include, exclude } = props;
  3862. if ((include && (!name || !matches(include, name))) ||
  3863. (exclude && name && matches(exclude, name))) {
  3864. current = vnode;
  3865. return rawVNode;
  3866. }
  3867. const key = vnode.key == null ? comp : vnode.key;
  3868. const cachedVNode = cache.get(key);
  3869. // clone vnode if it's reused because we are going to mutate it
  3870. if (vnode.el) {
  3871. vnode = cloneVNode(vnode);
  3872. if (isSuspense(rawVNode.type)) {
  3873. rawVNode.ssContent = vnode;
  3874. }
  3875. }
  3876. // #1513 it's possible for the returned vnode to be cloned due to attr
  3877. // fallthrough or scopeId, so the vnode here may not be the final vnode
  3878. // that is mounted. Instead of caching it directly, we store the pending
  3879. // key and cache `instance.subTree` (the normalized vnode) in
  3880. // beforeMount/beforeUpdate hooks.
  3881. pendingCacheKey = key;
  3882. if (cachedVNode) {
  3883. // copy over mounted state
  3884. vnode.el = cachedVNode.el;
  3885. vnode.component = cachedVNode.component;
  3886. if (vnode.transition) {
  3887. // recursively update transition hooks on subTree
  3888. setTransitionHooks(vnode, vnode.transition);
  3889. }
  3890. // avoid vnode being mounted as fresh
  3891. vnode.shapeFlag |= 512 /* ShapeFlags.COMPONENT_KEPT_ALIVE */;
  3892. }
  3893. // avoid vnode being unmounted
  3894. vnode.shapeFlag |= 256 /* ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE */;
  3895. current = vnode;
  3896. return isSuspense(rawVNode.type) ? rawVNode : vnode;
  3897. };
  3898. }
  3899. };
  3900. // export the public type for h/tsx inference
  3901. // also to avoid inline import() in generated d.ts files
  3902. const KeepAlive = KeepAliveImpl;
  3903. function matches(pattern, name) {
  3904. if (shared.isArray(pattern)) {
  3905. return pattern.some((p) => matches(p, name));
  3906. }
  3907. else if (shared.isString(pattern)) {
  3908. return pattern.split(',').includes(name);
  3909. }
  3910. else if (pattern.test) {
  3911. return pattern.test(name);
  3912. }
  3913. /* istanbul ignore next */
  3914. return false;
  3915. }
  3916. function onBeforeActivate(hook, target) {
  3917. registerKeepAliveHook(hook, "ba" /* LifecycleHooks.BEFORE_ACTIVATE */, target);
  3918. }
  3919. function onActivated(hook, target) {
  3920. registerKeepAliveHook(hook, "a" /* LifecycleHooks.ACTIVATED */, target);
  3921. }
  3922. function onBeforeDeactivate(hook, target) {
  3923. registerKeepAliveHook(hook, "bda" /* LifecycleHooks.BEFORE_DEACTIVATE */, target);
  3924. }
  3925. function onDeactivated(hook, target) {
  3926. registerKeepAliveHook(hook, "da" /* LifecycleHooks.DEACTIVATED */, target);
  3927. }
  3928. function registerKeepAliveHook(hook, type, target = currentInstance) {
  3929. // cache the deactivate branch check wrapper for injected hooks so the same
  3930. // hook can be properly deduped by the scheduler. "__wdc" stands for "with
  3931. // deactivation check".
  3932. const wrappedHook = hook.__wdc ||
  3933. (hook.__wdc = () => {
  3934. // only fire the hook if the target instance is NOT in a deactivated branch.
  3935. let current = target;
  3936. while (current) {
  3937. if (current.isDeactivated) {
  3938. return;
  3939. }
  3940. current = current.parent;
  3941. }
  3942. return hook();
  3943. });
  3944. wrappedHook.__called = false;
  3945. injectHook(type, wrappedHook, target);
  3946. // In addition to registering it on the target instance, we walk up the parent
  3947. // chain and register it on all ancestor instances that are keep-alive roots.
  3948. // This avoids the need to walk the entire component tree when invoking these
  3949. // hooks, and more importantly, avoids the need to track child components in
  3950. // arrays.
  3951. if (target) {
  3952. let current = target.parent;
  3953. while (current && current.parent) {
  3954. if (isKeepAlive(current.parent.vnode)) {
  3955. injectToKeepAliveRoot(wrappedHook, type, target, current);
  3956. }
  3957. current = current.parent;
  3958. }
  3959. }
  3960. }
  3961. function injectToKeepAliveRoot(hook, type, target, keepAliveRoot) {
  3962. // injectHook wraps the original for error handling, so make sure to remove
  3963. // the wrapped version.
  3964. const injected = injectHook(type, hook, keepAliveRoot, true /* prepend */);
  3965. onUnmounted(() => {
  3966. shared.remove(keepAliveRoot[type], injected);
  3967. }, target);
  3968. }
  3969. function resetShapeFlag(vnode) {
  3970. // bitwise operations to remove keep alive flags
  3971. vnode.shapeFlag &= ~256 /* ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE */;
  3972. vnode.shapeFlag &= ~512 /* ShapeFlags.COMPONENT_KEPT_ALIVE */;
  3973. }
  3974. function getInnerChild(vnode) {
  3975. return isSuspense(vnode.type) ? vnode.ssContent : vnode;
  3976. }
  3977. function getMatchingName(vnode, matchBy) {
  3978. if (matchBy === 'name') {
  3979. const comp = vnode.type;
  3980. return getComponentName(isAsyncWrapper(vnode)
  3981. ? comp.__asyncResolved || {}
  3982. : comp);
  3983. }
  3984. return String(vnode.key);
  3985. }
  3986. function invokeKeepAliveHooks(hooks) {
  3987. for (let i = 0; i < hooks.length; i++) {
  3988. const hook = hooks[i];
  3989. if (!hook.__called) {
  3990. hook();
  3991. hook.__called = true;
  3992. }
  3993. }
  3994. }
  3995. function resetHookState(hooks) {
  3996. hooks.forEach((hook) => (hook.__called = false));
  3997. }
  3998. function injectHook(type, hook, target = currentInstance, prepend = false) {
  3999. if (target) {
  4000. // fixed by xxxxxx
  4001. if (uniShared.isRootHook(type) && target.$pageInstance) {
  4002. // 系统保留组件,如 view,app 等
  4003. if (target.type.__reserved) {
  4004. return;
  4005. }
  4006. if (target !== target.$pageInstance) {
  4007. target = target.$pageInstance;
  4008. if (uniShared.isRootImmediateHook(type)) {
  4009. // 作用域应该是组件还是页面?目前绑定的是页面
  4010. const proxy = target.proxy;
  4011. callWithAsyncErrorHandling(hook.bind(proxy), target, type, uniShared.ON_LOAD === type ? [proxy.$page.options] : []);
  4012. }
  4013. }
  4014. }
  4015. const hooks = target[type] || (target[type] = []);
  4016. // cache the error handling wrapper for injected hooks so the same hook
  4017. // can be properly deduped by the scheduler. "__weh" stands for "with error
  4018. // handling".
  4019. const wrappedHook = hook.__weh ||
  4020. (hook.__weh = (...args) => {
  4021. if (target.isUnmounted) {
  4022. // fixed by xxxxxx
  4023. return;
  4024. }
  4025. // disable tracking inside all lifecycle hooks
  4026. // since they can potentially be called inside effects.
  4027. pauseTracking();
  4028. // Set currentInstance during hook invocation.
  4029. // This assumes the hook does not synchronously trigger other hooks, which
  4030. // can only be false when the user does something really funky.
  4031. setCurrentInstance(target); // fixed by xxxxxx
  4032. const res = callWithAsyncErrorHandling(hook, target, type, args);
  4033. unsetCurrentInstance();
  4034. resetTracking();
  4035. return res;
  4036. });
  4037. if (prepend) {
  4038. hooks.unshift(wrappedHook);
  4039. }
  4040. else {
  4041. hooks.push(wrappedHook);
  4042. }
  4043. return wrappedHook;
  4044. }
  4045. else {
  4046. const apiName = shared.toHandlerKey((ErrorTypeStrings[type] || type.replace(/^on/, '')).replace(/ hook$/, '')); // fixed by xxxxxx
  4047. warn(`${apiName} is called when there is no active component instance to be ` +
  4048. `associated with. ` +
  4049. `Lifecycle injection APIs can only be used during execution of setup().` +
  4050. (` If you are using async setup(), make sure to register lifecycle ` +
  4051. `hooks before the first await statement.`
  4052. ));
  4053. }
  4054. }
  4055. const createHook = (lifecycle) => (hook, target = currentInstance) =>
  4056. // post-create lifecycle registrations are noops during SSR (except for serverPrefetch)
  4057. (!exports.isInSSRComponentSetup || lifecycle === "sp" /* LifecycleHooks.SERVER_PREFETCH */) &&
  4058. injectHook(lifecycle, (...args) => hook(...args), target);
  4059. const onBeforeMount = createHook("bm" /* LifecycleHooks.BEFORE_MOUNT */);
  4060. const onMounted = createHook("m" /* LifecycleHooks.MOUNTED */);
  4061. const onBeforeUpdate = createHook("bu" /* LifecycleHooks.BEFORE_UPDATE */);
  4062. const onUpdated = createHook("u" /* LifecycleHooks.UPDATED */);
  4063. const onBeforeUnmount = createHook("bum" /* LifecycleHooks.BEFORE_UNMOUNT */);
  4064. const onUnmounted = createHook("um" /* LifecycleHooks.UNMOUNTED */);
  4065. const onServerPrefetch = createHook("sp" /* LifecycleHooks.SERVER_PREFETCH */);
  4066. const onRenderTriggered = createHook("rtg" /* LifecycleHooks.RENDER_TRIGGERED */);
  4067. const onRenderTracked = createHook("rtc" /* LifecycleHooks.RENDER_TRACKED */);
  4068. function onErrorCaptured(hook, target = currentInstance) {
  4069. injectHook("ec" /* LifecycleHooks.ERROR_CAPTURED */, hook, target);
  4070. }
  4071. /**
  4072. Runtime helper for applying directives to a vnode. Example usage:
  4073. const comp = resolveComponent('comp')
  4074. const foo = resolveDirective('foo')
  4075. const bar = resolveDirective('bar')
  4076. return withDirectives(h(comp), [
  4077. [foo, this.x],
  4078. [bar, this.y]
  4079. ])
  4080. */
  4081. function validateDirectiveName(name) {
  4082. if (shared.isBuiltInDirective(name)) {
  4083. warn('Do not use built-in directive ids as custom directive id: ' + name);
  4084. }
  4085. }
  4086. /**
  4087. * Adds directives to a VNode.
  4088. */
  4089. function withDirectives(vnode, directives) {
  4090. const internalInstance = currentRenderingInstance;
  4091. if (internalInstance === null) {
  4092. warn(`withDirectives can only be used inside render functions.`);
  4093. return vnode;
  4094. }
  4095. const instance = getExposeProxy(internalInstance) ||
  4096. internalInstance.proxy;
  4097. const bindings = vnode.dirs || (vnode.dirs = []);
  4098. for (let i = 0; i < directives.length; i++) {
  4099. let [dir, value, arg, modifiers = shared.EMPTY_OBJ] = directives[i];
  4100. if (dir) {
  4101. if (shared.isFunction(dir)) {
  4102. dir = {
  4103. mounted: dir,
  4104. updated: dir
  4105. };
  4106. }
  4107. if (dir.deep) {
  4108. traverse(value);
  4109. }
  4110. bindings.push({
  4111. dir,
  4112. instance,
  4113. value,
  4114. oldValue: void 0,
  4115. arg,
  4116. modifiers
  4117. });
  4118. }
  4119. }
  4120. return vnode;
  4121. }
  4122. function invokeDirectiveHook(vnode, prevVNode, instance, name) {
  4123. const bindings = vnode.dirs;
  4124. const oldBindings = prevVNode && prevVNode.dirs;
  4125. for (let i = 0; i < bindings.length; i++) {
  4126. const binding = bindings[i];
  4127. if (oldBindings) {
  4128. binding.oldValue = oldBindings[i].value;
  4129. }
  4130. let hook = binding.dir[name];
  4131. if (hook) {
  4132. // disable tracking inside all lifecycle hooks
  4133. // since they can potentially be called inside effects.
  4134. pauseTracking();
  4135. callWithAsyncErrorHandling(hook, instance, 8 /* ErrorCodes.DIRECTIVE_HOOK */, [
  4136. vnode.el,
  4137. binding,
  4138. vnode,
  4139. prevVNode
  4140. ]);
  4141. resetTracking();
  4142. }
  4143. }
  4144. }
  4145. const COMPONENTS = 'components';
  4146. const DIRECTIVES = 'directives';
  4147. /**
  4148. * @private
  4149. */
  4150. function resolveComponent(name, maybeSelfReference) {
  4151. return resolveAsset(COMPONENTS, name, true, maybeSelfReference) || name;
  4152. }
  4153. const NULL_DYNAMIC_COMPONENT = Symbol();
  4154. /**
  4155. * @private
  4156. */
  4157. function resolveDynamicComponent(component) {
  4158. if (shared.isString(component)) {
  4159. return resolveAsset(COMPONENTS, component, false) || component;
  4160. }
  4161. else {
  4162. // invalid types will fallthrough to createVNode and raise warning
  4163. return (component || NULL_DYNAMIC_COMPONENT);
  4164. }
  4165. }
  4166. /**
  4167. * @private
  4168. */
  4169. function resolveDirective(name) {
  4170. return resolveAsset(DIRECTIVES, name);
  4171. }
  4172. // implementation
  4173. function resolveAsset(type, name, warnMissing = true, maybeSelfReference = false) {
  4174. const instance = currentRenderingInstance || currentInstance;
  4175. if (instance) {
  4176. const Component = instance.type;
  4177. // explicit self name has highest priority
  4178. if (type === COMPONENTS) {
  4179. const selfName = getComponentName(Component, false /* do not include inferred name to avoid breaking existing code */);
  4180. if (selfName &&
  4181. (selfName === name ||
  4182. selfName === shared.camelize(name) ||
  4183. selfName === shared.capitalize(shared.camelize(name)))) {
  4184. return Component;
  4185. }
  4186. }
  4187. const res =
  4188. // local registration
  4189. // check instance[type] first which is resolved for options API
  4190. resolve(instance[type] || Component[type], name) ||
  4191. // global registration
  4192. resolve(instance.appContext[type], name);
  4193. if (!res && maybeSelfReference) {
  4194. // fallback to implicit self-reference
  4195. return Component;
  4196. }
  4197. if (warnMissing && !res) {
  4198. const extra = type === COMPONENTS
  4199. ? `\nIf this is a native custom element, make sure to exclude it from ` +
  4200. `component resolution via compilerOptions.isCustomElement.`
  4201. : ``;
  4202. warn(`Failed to resolve ${type.slice(0, -1)}: ${name}${extra}`);
  4203. }
  4204. return res;
  4205. }
  4206. else {
  4207. warn(`resolve${shared.capitalize(type.slice(0, -1))} ` +
  4208. `can only be used in render() or setup().`);
  4209. }
  4210. }
  4211. function resolve(registry, name) {
  4212. return (registry &&
  4213. (registry[name] ||
  4214. registry[shared.camelize(name)] ||
  4215. registry[shared.capitalize(shared.camelize(name))]));
  4216. }
  4217. /**
  4218. * Actual implementation
  4219. */
  4220. function renderList(source, renderItem, cache, index) {
  4221. let ret;
  4222. const cached = (cache && cache[index]);
  4223. if (shared.isArray(source) || shared.isString(source)) {
  4224. ret = new Array(source.length);
  4225. for (let i = 0, l = source.length; i < l; i++) {
  4226. ret[i] = renderItem(source[i], i, undefined, cached && cached[i]);
  4227. }
  4228. }
  4229. else if (typeof source === 'number') {
  4230. if (!Number.isInteger(source)) {
  4231. warn(`The v-for range expect an integer value but got ${source}.`);
  4232. }
  4233. ret = new Array(source);
  4234. for (let i = 0; i < source; i++) {
  4235. ret[i] = renderItem(i + 1, i, undefined, cached && cached[i]);
  4236. }
  4237. }
  4238. else if (shared.isObject(source)) {
  4239. if (source[Symbol.iterator]) {
  4240. ret = Array.from(source, (item, i) => renderItem(item, i, undefined, cached && cached[i]));
  4241. }
  4242. else {
  4243. const keys = Object.keys(source);
  4244. ret = new Array(keys.length);
  4245. for (let i = 0, l = keys.length; i < l; i++) {
  4246. const key = keys[i];
  4247. ret[i] = renderItem(source[key], key, i, cached && cached[i]);
  4248. }
  4249. }
  4250. }
  4251. else {
  4252. ret = [];
  4253. }
  4254. if (cache) {
  4255. cache[index] = ret;
  4256. }
  4257. return ret;
  4258. }
  4259. /**
  4260. * Compiler runtime helper for creating dynamic slots object
  4261. * @private
  4262. */
  4263. function createSlots(slots, dynamicSlots) {
  4264. for (let i = 0; i < dynamicSlots.length; i++) {
  4265. const slot = dynamicSlots[i];
  4266. // array of dynamic slot generated by <template v-for="..." #[...]>
  4267. if (shared.isArray(slot)) {
  4268. for (let j = 0; j < slot.length; j++) {
  4269. slots[slot[j].name] = slot[j].fn;
  4270. }
  4271. }
  4272. else if (slot) {
  4273. // conditional single slot generated by <template v-if="..." #foo>
  4274. slots[slot.name] = slot.key
  4275. ? (...args) => {
  4276. const res = slot.fn(...args);
  4277. // attach branch key so each conditional branch is considered a
  4278. // different fragment
  4279. if (res)
  4280. res.key = slot.key;
  4281. return res;
  4282. }
  4283. : slot.fn;
  4284. }
  4285. }
  4286. return slots;
  4287. }
  4288. /**
  4289. * Compiler runtime helper for rendering `<slot/>`
  4290. * @private
  4291. */
  4292. function renderSlot(slots, name, props = {},
  4293. // this is not a user-facing function, so the fallback is always generated by
  4294. // the compiler and guaranteed to be a function returning an array
  4295. fallback, noSlotted) {
  4296. if (currentRenderingInstance.isCE ||
  4297. (currentRenderingInstance.parent &&
  4298. isAsyncWrapper(currentRenderingInstance.parent) &&
  4299. currentRenderingInstance.parent.isCE)) {
  4300. if (name !== 'default')
  4301. props.name = name;
  4302. return createVNode('slot', props, fallback && fallback());
  4303. }
  4304. let slot = slots[name];
  4305. if (slot && slot.length > 1) {
  4306. warn(`SSR-optimized slot function detected in a non-SSR-optimized render ` +
  4307. `function. You need to mark this component with $dynamic-slots in the ` +
  4308. `parent template.`);
  4309. slot = () => [];
  4310. }
  4311. // a compiled slot disables block tracking by default to avoid manual
  4312. // invocation interfering with template-based block tracking, but in
  4313. // `renderSlot` we can be sure that it's template-based so we can force
  4314. // enable it.
  4315. if (slot && slot._c) {
  4316. slot._d = false;
  4317. }
  4318. openBlock();
  4319. const validSlotContent = slot && ensureValidVNode(slot(props));
  4320. const rendered = createBlock(Fragment, {
  4321. key: props.key ||
  4322. // slot content array of a dynamic conditional slot may have a branch
  4323. // key attached in the `createSlots` helper, respect that
  4324. (validSlotContent && validSlotContent.key) ||
  4325. `_${name}`
  4326. }, validSlotContent || (fallback ? fallback() : []), validSlotContent && slots._ === 1 /* SlotFlags.STABLE */
  4327. ? 64 /* PatchFlags.STABLE_FRAGMENT */
  4328. : -2 /* PatchFlags.BAIL */);
  4329. if (!noSlotted && rendered.scopeId) {
  4330. rendered.slotScopeIds = [rendered.scopeId + '-s'];
  4331. }
  4332. if (slot && slot._c) {
  4333. slot._d = true;
  4334. }
  4335. return rendered;
  4336. }
  4337. function ensureValidVNode(vnodes) {
  4338. return vnodes.some(child => {
  4339. if (!isVNode(child))
  4340. return true;
  4341. if (child.type === Comment)
  4342. return false;
  4343. if (child.type === Fragment &&
  4344. !ensureValidVNode(child.children))
  4345. return false;
  4346. return true;
  4347. })
  4348. ? vnodes
  4349. : null;
  4350. }
  4351. /**
  4352. * For prefixing keys in v-on="obj" with "on"
  4353. * @private
  4354. */
  4355. function toHandlers(obj, preserveCaseIfNecessary) {
  4356. const ret = {};
  4357. if (!shared.isObject(obj)) {
  4358. warn(`v-on with no argument expects an object value.`);
  4359. return ret;
  4360. }
  4361. for (const key in obj) {
  4362. ret[preserveCaseIfNecessary && /[A-Z]/.test(key)
  4363. ? `on:${key}`
  4364. : shared.toHandlerKey(key)] = obj[key];
  4365. }
  4366. return ret;
  4367. }
  4368. function isUniBuiltInComponentInstance(p) {
  4369. return p && p.$options && (p.$options.__reserved || p.$options.rootElement);
  4370. }
  4371. /**
  4372. * #2437 In Vue 3, functional components do not have a public instance proxy but
  4373. * they exist in the internal parent chain. For code that relies on traversing
  4374. * public $parent chains, skip functional ones and go to the parent instead.
  4375. */
  4376. const getPublicInstance = (i) => {
  4377. if (!i)
  4378. return null;
  4379. if (isStatefulComponent(i)) {
  4380. const p = getExposeProxy(i) || i.proxy;
  4381. if (isUniBuiltInComponentInstance(p)) {
  4382. return getPublicInstance(i.parent);
  4383. }
  4384. return p;
  4385. }
  4386. return getPublicInstance(i.parent);
  4387. };
  4388. const publicPropertiesMap =
  4389. // Move PURE marker to new line to workaround compiler discarding it
  4390. // due to type annotation
  4391. /*#__PURE__*/ shared.extend(Object.create(null), {
  4392. $: i => i,
  4393. $el: i => i.vnode.el,
  4394. $data: i => i.data,
  4395. $props: i => (shallowReadonly(i.props) ),
  4396. $attrs: i => (shallowReadonly(i.attrs) ),
  4397. $slots: i => (shallowReadonly(i.slots) ),
  4398. $refs: i => (shallowReadonly(i.refs) ),
  4399. $parent: i => getPublicInstance(i.parent),
  4400. $root: i => getPublicInstance(i.root),
  4401. $emit: i => i.emit,
  4402. $options: i => (resolveMergedOptions(i) ),
  4403. $forceUpdate: i => i.f ||
  4404. (i.f = () => {
  4405. queueJob(i.update);
  4406. const subTree = i.subTree;
  4407. if (subTree.shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  4408. const vnodes = subTree.children;
  4409. vnodes.forEach(vnode => {
  4410. if (!vnode.component) {
  4411. return;
  4412. }
  4413. const p = getExposeProxy(vnode.component) || vnode.component.proxy;
  4414. if (isUniBuiltInComponentInstance(p)) {
  4415. p.$forceUpdate();
  4416. }
  4417. });
  4418. }
  4419. else if (subTree.component) {
  4420. const p = getExposeProxy(subTree.component) || subTree.component.proxy;
  4421. if (isUniBuiltInComponentInstance(p)) {
  4422. p.$forceUpdate();
  4423. }
  4424. }
  4425. }),
  4426. $nextTick: i => i.n || (i.n = nextTick.bind(i.proxy)),
  4427. $watch: i => (instanceWatch.bind(i) )
  4428. });
  4429. const isReservedPrefix = (key) => key === '_' || key === '$';
  4430. const hasSetupBinding = (state, key) => state !== shared.EMPTY_OBJ && !state.__isScriptSetup && shared.hasOwn(state, key);
  4431. const PublicInstanceProxyHandlers = {
  4432. get({ _: instance }, key) {
  4433. const { ctx, setupState, data, props, accessCache, type, appContext } = instance;
  4434. // for internal formatters to know that this is a Vue instance
  4435. if (key === '__isVue') {
  4436. return true;
  4437. }
  4438. // data / props / ctx
  4439. // This getter gets called for every property access on the render context
  4440. // during render and is a major hotspot. The most expensive part of this
  4441. // is the multiple hasOwn() calls. It's much faster to do a simple property
  4442. // access on a plain object, so we use an accessCache object (with null
  4443. // prototype) to memoize what access type a key corresponds to.
  4444. let normalizedProps;
  4445. if (key[0] !== '$') {
  4446. const n = accessCache[key];
  4447. if (n !== undefined) {
  4448. switch (n) {
  4449. case 1 /* AccessTypes.SETUP */:
  4450. return setupState[key];
  4451. case 2 /* AccessTypes.DATA */:
  4452. return data[key];
  4453. case 4 /* AccessTypes.CONTEXT */:
  4454. return ctx[key];
  4455. case 3 /* AccessTypes.PROPS */:
  4456. return props[key];
  4457. // default: just fallthrough
  4458. }
  4459. }
  4460. else if (hasSetupBinding(setupState, key)) {
  4461. accessCache[key] = 1 /* AccessTypes.SETUP */;
  4462. return setupState[key];
  4463. }
  4464. else if (data !== shared.EMPTY_OBJ && shared.hasOwn(data, key)) {
  4465. accessCache[key] = 2 /* AccessTypes.DATA */;
  4466. return data[key];
  4467. }
  4468. else if (
  4469. // only cache other properties when instance has declared (thus stable)
  4470. // props
  4471. (normalizedProps = instance.propsOptions[0]) &&
  4472. shared.hasOwn(normalizedProps, key)) {
  4473. accessCache[key] = 3 /* AccessTypes.PROPS */;
  4474. return props[key];
  4475. }
  4476. else if (ctx !== shared.EMPTY_OBJ && shared.hasOwn(ctx, key)) {
  4477. accessCache[key] = 4 /* AccessTypes.CONTEXT */;
  4478. return ctx[key];
  4479. }
  4480. else if (shouldCacheAccess) {
  4481. accessCache[key] = 0 /* AccessTypes.OTHER */;
  4482. }
  4483. }
  4484. const publicGetter = publicPropertiesMap[key];
  4485. let cssModule, globalProperties;
  4486. // public $xxx properties
  4487. if (publicGetter) {
  4488. if (key === '$attrs') {
  4489. track(instance, "get" /* TrackOpTypes.GET */, key);
  4490. markAttrsAccessed();
  4491. }
  4492. return publicGetter(instance);
  4493. }
  4494. else if (
  4495. // css module (injected by vue-loader)
  4496. (cssModule = type.__cssModules) &&
  4497. (cssModule = cssModule[key])) {
  4498. return cssModule;
  4499. }
  4500. else if (ctx !== shared.EMPTY_OBJ && shared.hasOwn(ctx, key)) {
  4501. // user may set custom properties to `this` that start with `$`
  4502. accessCache[key] = 4 /* AccessTypes.CONTEXT */;
  4503. return ctx[key];
  4504. }
  4505. else if (
  4506. // global properties
  4507. ((globalProperties = appContext.config.globalProperties),
  4508. shared.hasOwn(globalProperties, key))) {
  4509. {
  4510. return globalProperties[key];
  4511. }
  4512. }
  4513. else if (currentRenderingInstance &&
  4514. (!shared.isString(key) ||
  4515. // #1091 avoid internal isRef/isVNode checks on component instance leading
  4516. // to infinite warning loop
  4517. key.indexOf('__v') !== 0)) {
  4518. if (data !== shared.EMPTY_OBJ && isReservedPrefix(key[0]) && shared.hasOwn(data, key)) {
  4519. warn(`Property ${JSON.stringify(key)} must be accessed via $data because it starts with a reserved ` +
  4520. `character ("$" or "_") and is not proxied on the render context.`);
  4521. }
  4522. else if (instance === currentRenderingInstance) {
  4523. warn(`Property ${JSON.stringify(key)} was accessed during render ` +
  4524. `but is not defined on instance.`);
  4525. }
  4526. }
  4527. },
  4528. set({ _: instance }, key, value) {
  4529. const { data, setupState, ctx } = instance;
  4530. if (hasSetupBinding(setupState, key)) {
  4531. setupState[key] = value;
  4532. return true;
  4533. }
  4534. else if (setupState.__isScriptSetup &&
  4535. shared.hasOwn(setupState, key)) {
  4536. warn(`Cannot mutate <script setup> binding "${key}" from Options API.`);
  4537. return false;
  4538. }
  4539. else if (data !== shared.EMPTY_OBJ && shared.hasOwn(data, key)) {
  4540. data[key] = value;
  4541. return true;
  4542. }
  4543. else if (shared.hasOwn(instance.props, key)) {
  4544. warn(`Attempting to mutate prop "${key}". Props are readonly.`);
  4545. return false;
  4546. }
  4547. if (key[0] === '$' && key.slice(1) in instance) {
  4548. warn(`Attempting to mutate public property "${key}". ` +
  4549. `Properties starting with $ are reserved and readonly.`);
  4550. return false;
  4551. }
  4552. else {
  4553. if (key in instance.appContext.config.globalProperties) {
  4554. Object.defineProperty(ctx, key, {
  4555. enumerable: true,
  4556. configurable: true,
  4557. value
  4558. });
  4559. }
  4560. else {
  4561. ctx[key] = value;
  4562. }
  4563. }
  4564. return true;
  4565. },
  4566. has({ _: { data, setupState, accessCache, ctx, appContext, propsOptions } }, key) {
  4567. let normalizedProps;
  4568. return (!!accessCache[key] ||
  4569. (data !== shared.EMPTY_OBJ && shared.hasOwn(data, key)) ||
  4570. hasSetupBinding(setupState, key) ||
  4571. ((normalizedProps = propsOptions[0]) && shared.hasOwn(normalizedProps, key)) ||
  4572. shared.hasOwn(ctx, key) ||
  4573. shared.hasOwn(publicPropertiesMap, key) ||
  4574. shared.hasOwn(appContext.config.globalProperties, key));
  4575. },
  4576. defineProperty(target, key, descriptor) {
  4577. if (descriptor.get != null) {
  4578. // invalidate key cache of a getter based property #5417
  4579. target._.accessCache[key] = 0;
  4580. }
  4581. else if (shared.hasOwn(descriptor, 'value')) {
  4582. this.set(target, key, descriptor.value, null);
  4583. }
  4584. return Reflect.defineProperty(target, key, descriptor);
  4585. }
  4586. };
  4587. {
  4588. PublicInstanceProxyHandlers.ownKeys = (target) => {
  4589. warn(`Avoid app logic that relies on enumerating keys on a component instance. ` +
  4590. `The keys will be empty in production mode to avoid performance overhead.`);
  4591. return Reflect.ownKeys(target);
  4592. };
  4593. }
  4594. const RuntimeCompiledPublicInstanceProxyHandlers = /*#__PURE__*/ shared.extend({}, PublicInstanceProxyHandlers, {
  4595. get(target, key) {
  4596. // fast path for unscopables when using `with` block
  4597. if (key === Symbol.unscopables) {
  4598. return;
  4599. }
  4600. return PublicInstanceProxyHandlers.get(target, key, target);
  4601. },
  4602. has(_, key) {
  4603. const has = key[0] !== '_' && !shared.isGloballyWhitelisted(key);
  4604. if (!has && PublicInstanceProxyHandlers.has(_, key)) {
  4605. warn(`Property ${JSON.stringify(key)} should not start with _ which is a reserved prefix for Vue internals.`);
  4606. }
  4607. return has;
  4608. }
  4609. });
  4610. // dev only
  4611. // In dev mode, the proxy target exposes the same properties as seen on `this`
  4612. // for easier console inspection. In prod mode it will be an empty object so
  4613. // these properties definitions can be skipped.
  4614. function createDevRenderContext(instance) {
  4615. const target = {};
  4616. // expose internal instance for proxy handlers
  4617. Object.defineProperty(target, `_`, {
  4618. configurable: true,
  4619. enumerable: false,
  4620. get: () => instance
  4621. });
  4622. // expose public properties
  4623. Object.keys(publicPropertiesMap).forEach(key => {
  4624. Object.defineProperty(target, key, {
  4625. configurable: true,
  4626. enumerable: false,
  4627. get: () => publicPropertiesMap[key](instance),
  4628. // intercepted by the proxy so no need for implementation,
  4629. // but needed to prevent set errors
  4630. set: shared.NOOP
  4631. });
  4632. });
  4633. return target;
  4634. }
  4635. // dev only
  4636. function exposePropsOnRenderContext(instance) {
  4637. const { ctx, propsOptions: [propsOptions] } = instance;
  4638. if (propsOptions) {
  4639. Object.keys(propsOptions).forEach(key => {
  4640. Object.defineProperty(ctx, key, {
  4641. enumerable: true,
  4642. configurable: true,
  4643. get: () => instance.props[key],
  4644. set: shared.NOOP
  4645. });
  4646. });
  4647. }
  4648. }
  4649. // dev only
  4650. function exposeSetupStateOnRenderContext(instance) {
  4651. const { ctx, setupState } = instance;
  4652. Object.keys(toRaw(setupState)).forEach(key => {
  4653. if (!setupState.__isScriptSetup) {
  4654. if (isReservedPrefix(key[0])) {
  4655. warn(`setup() return property ${JSON.stringify(key)} should not start with "$" or "_" ` +
  4656. `which are reserved prefixes for Vue internals.`);
  4657. return;
  4658. }
  4659. Object.defineProperty(ctx, key, {
  4660. enumerable: true,
  4661. configurable: true,
  4662. get: () => setupState[key],
  4663. set: shared.NOOP
  4664. });
  4665. }
  4666. });
  4667. }
  4668. function createDuplicateChecker() {
  4669. const cache = Object.create(null);
  4670. return (type, key) => {
  4671. if (cache[key]) {
  4672. warn(`${type} property "${key}" is already defined in ${cache[key]}.`);
  4673. }
  4674. else {
  4675. cache[key] = type;
  4676. }
  4677. };
  4678. }
  4679. let shouldCacheAccess = true;
  4680. function applyOptions(instance) {
  4681. const options = resolveMergedOptions(instance);
  4682. const publicThis = instance.proxy;
  4683. const ctx = instance.ctx;
  4684. // do not cache property access on public proxy during state initialization
  4685. shouldCacheAccess = false;
  4686. // call beforeCreate first before accessing other options since
  4687. // the hook may mutate resolved options (#2791)
  4688. if (options.beforeCreate) {
  4689. callHook$1(options.beforeCreate, instance, "bc" /* LifecycleHooks.BEFORE_CREATE */);
  4690. }
  4691. const {
  4692. // state
  4693. data: dataOptions, computed: computedOptions, methods, watch: watchOptions, provide: provideOptions, inject: injectOptions,
  4694. // lifecycle
  4695. created, beforeMount, mounted, beforeUpdate, updated, activated, deactivated, beforeDestroy, beforeUnmount, destroyed, unmounted, render, renderTracked, renderTriggered, errorCaptured, serverPrefetch,
  4696. // public API
  4697. expose, inheritAttrs,
  4698. // assets
  4699. components, directives, filters } = options;
  4700. const checkDuplicateProperties = createDuplicateChecker() ;
  4701. {
  4702. const [propsOptions] = instance.propsOptions;
  4703. if (propsOptions) {
  4704. for (const key in propsOptions) {
  4705. checkDuplicateProperties("Props" /* OptionTypes.PROPS */, key);
  4706. }
  4707. }
  4708. }
  4709. // options initialization order (to be consistent with Vue 2):
  4710. // - props (already done outside of this function)
  4711. // - inject
  4712. // - methods
  4713. // - data (deferred since it relies on `this` access)
  4714. // - computed
  4715. // - watch (deferred since it relies on `this` access)
  4716. if (injectOptions) {
  4717. resolveInjections(injectOptions, ctx, checkDuplicateProperties, instance.appContext.config.unwrapInjectedRef);
  4718. }
  4719. if (methods) {
  4720. for (const key in methods) {
  4721. const methodHandler = methods[key];
  4722. if (shared.isFunction(methodHandler)) {
  4723. // In dev mode, we use the `createRenderContext` function to define
  4724. // methods to the proxy target, and those are read-only but
  4725. // reconfigurable, so it needs to be redefined here
  4726. {
  4727. Object.defineProperty(ctx, key, {
  4728. value: methodHandler.bind(publicThis),
  4729. configurable: true,
  4730. enumerable: true,
  4731. writable: true
  4732. });
  4733. }
  4734. {
  4735. checkDuplicateProperties("Methods" /* OptionTypes.METHODS */, key);
  4736. }
  4737. }
  4738. else {
  4739. warn(`Method "${key}" has type "${typeof methodHandler}" in the component definition. ` +
  4740. `Did you reference the function correctly?`);
  4741. }
  4742. }
  4743. }
  4744. if (dataOptions) {
  4745. if (!shared.isFunction(dataOptions)) {
  4746. warn(`The data option must be a function. ` +
  4747. `Plain object usage is no longer supported.`);
  4748. }
  4749. const data = dataOptions.call(publicThis, publicThis);
  4750. if (shared.isPromise(data)) {
  4751. warn(`data() returned a Promise - note data() cannot be async; If you ` +
  4752. `intend to perform data fetching before component renders, use ` +
  4753. `async setup() + <Suspense>.`);
  4754. }
  4755. if (!shared.isObject(data)) {
  4756. warn(`data() should return an object.`);
  4757. }
  4758. else {
  4759. instance.data = reactive(data);
  4760. {
  4761. for (const key in data) {
  4762. checkDuplicateProperties("Data" /* OptionTypes.DATA */, key);
  4763. // expose data on ctx during dev
  4764. if (!isReservedPrefix(key[0])) {
  4765. Object.defineProperty(ctx, key, {
  4766. configurable: true,
  4767. enumerable: true,
  4768. get: () => data[key],
  4769. set: shared.NOOP
  4770. });
  4771. }
  4772. }
  4773. }
  4774. }
  4775. }
  4776. // state initialization complete at this point - start caching access
  4777. shouldCacheAccess = true;
  4778. if (computedOptions) {
  4779. for (const key in computedOptions) {
  4780. const opt = computedOptions[key];
  4781. const get = shared.isFunction(opt)
  4782. ? opt.bind(publicThis, publicThis)
  4783. : shared.isFunction(opt.get)
  4784. ? opt.get.bind(publicThis, publicThis)
  4785. : shared.NOOP;
  4786. if (get === shared.NOOP) {
  4787. warn(`Computed property "${key}" has no getter.`);
  4788. }
  4789. const set = !shared.isFunction(opt) && shared.isFunction(opt.set)
  4790. ? opt.set.bind(publicThis)
  4791. : () => {
  4792. warn(`Write operation failed: computed property "${key}" is readonly.`);
  4793. }
  4794. ;
  4795. const c = computed({
  4796. get,
  4797. set
  4798. });
  4799. Object.defineProperty(ctx, key, {
  4800. enumerable: true,
  4801. configurable: true,
  4802. get: () => c.value,
  4803. set: v => (c.value = v)
  4804. });
  4805. {
  4806. checkDuplicateProperties("Computed" /* OptionTypes.COMPUTED */, key);
  4807. }
  4808. }
  4809. }
  4810. if (watchOptions) {
  4811. for (const key in watchOptions) {
  4812. createWatcher(watchOptions[key], ctx, publicThis, key);
  4813. }
  4814. }
  4815. if (provideOptions) {
  4816. const provides = shared.isFunction(provideOptions)
  4817. ? provideOptions.call(publicThis)
  4818. : provideOptions;
  4819. Reflect.ownKeys(provides).forEach(key => {
  4820. provide(key, provides[key]);
  4821. });
  4822. }
  4823. if (created) {
  4824. callHook$1(created, instance, "c" /* LifecycleHooks.CREATED */);
  4825. }
  4826. function registerLifecycleHook(register, hook) {
  4827. if (shared.isArray(hook)) {
  4828. hook.forEach(_hook => register(_hook.bind(publicThis)));
  4829. }
  4830. else if (hook) {
  4831. register(hook.bind(publicThis));
  4832. }
  4833. }
  4834. registerLifecycleHook(onBeforeMount, beforeMount);
  4835. registerLifecycleHook(onMounted, mounted);
  4836. registerLifecycleHook(onBeforeUpdate, beforeUpdate);
  4837. registerLifecycleHook(onUpdated, updated);
  4838. registerLifecycleHook(onActivated, activated);
  4839. registerLifecycleHook(onDeactivated, deactivated);
  4840. registerLifecycleHook(onErrorCaptured, errorCaptured);
  4841. registerLifecycleHook(onRenderTracked, renderTracked);
  4842. registerLifecycleHook(onRenderTriggered, renderTriggered);
  4843. registerLifecycleHook(onBeforeUnmount, beforeUnmount);
  4844. registerLifecycleHook(onUnmounted, unmounted);
  4845. registerLifecycleHook(onServerPrefetch, serverPrefetch);
  4846. if (shared.isArray(expose)) {
  4847. if (expose.length) {
  4848. const exposed = instance.exposed || (instance.exposed = {});
  4849. expose.forEach(key => {
  4850. Object.defineProperty(exposed, key, {
  4851. get: () => publicThis[key],
  4852. set: val => (publicThis[key] = val)
  4853. });
  4854. });
  4855. }
  4856. else if (!instance.exposed) {
  4857. instance.exposed = {};
  4858. }
  4859. }
  4860. // options that are handled when creating the instance but also need to be
  4861. // applied from mixins
  4862. if (render && instance.render === shared.NOOP) {
  4863. instance.render = render;
  4864. }
  4865. if (inheritAttrs != null) {
  4866. instance.inheritAttrs = inheritAttrs;
  4867. }
  4868. // asset options.
  4869. if (components)
  4870. instance.components = components;
  4871. if (directives)
  4872. instance.directives = directives;
  4873. // fixed by xxxxxx
  4874. const customApplyOptions = instance.appContext.config.globalProperties
  4875. .$applyOptions;
  4876. if (customApplyOptions) {
  4877. customApplyOptions(options, instance, publicThis);
  4878. }
  4879. }
  4880. function resolveInjections(injectOptions, ctx, checkDuplicateProperties = shared.NOOP, unwrapRef = false) {
  4881. if (shared.isArray(injectOptions)) {
  4882. injectOptions = normalizeInject(injectOptions);
  4883. }
  4884. for (const key in injectOptions) {
  4885. const opt = injectOptions[key];
  4886. let injected;
  4887. if (shared.isObject(opt)) {
  4888. if ('default' in opt) {
  4889. injected = inject(opt.from || key, opt.default, true /* treat default function as factory */);
  4890. }
  4891. else {
  4892. injected = inject(opt.from || key);
  4893. }
  4894. }
  4895. else {
  4896. injected = inject(opt);
  4897. }
  4898. if (isRef(injected)) {
  4899. // TODO remove the check in 3.3
  4900. if (unwrapRef) {
  4901. Object.defineProperty(ctx, key, {
  4902. enumerable: true,
  4903. configurable: true,
  4904. get: () => injected.value,
  4905. set: v => (injected.value = v)
  4906. });
  4907. }
  4908. else {
  4909. {
  4910. warn(`injected property "${key}" is a ref and will be auto-unwrapped ` +
  4911. `and no longer needs \`.value\` in the next minor release. ` +
  4912. `To opt-in to the new behavior now, ` +
  4913. `set \`app.config.unwrapInjectedRef = true\` (this config is ` +
  4914. `temporary and will not be needed in the future.)`);
  4915. }
  4916. ctx[key] = injected;
  4917. }
  4918. }
  4919. else {
  4920. ctx[key] = injected;
  4921. }
  4922. {
  4923. checkDuplicateProperties("Inject" /* OptionTypes.INJECT */, key);
  4924. }
  4925. }
  4926. }
  4927. function callHook$1(hook, instance, type) {
  4928. callWithAsyncErrorHandling(shared.isArray(hook)
  4929. ? hook.map(h => h.bind(instance.proxy))
  4930. : hook.bind(instance.proxy), instance, type);
  4931. }
  4932. function createWatcher(raw, ctx, publicThis, key) {
  4933. const getter = key.includes('.')
  4934. ? createPathGetter(publicThis, key)
  4935. : () => publicThis[key];
  4936. if (shared.isString(raw)) {
  4937. const handler = ctx[raw];
  4938. if (shared.isFunction(handler)) {
  4939. watch(getter, handler);
  4940. }
  4941. else {
  4942. warn(`Invalid watch handler specified by key "${raw}"`, handler);
  4943. }
  4944. }
  4945. else if (shared.isFunction(raw)) {
  4946. watch(getter, raw.bind(publicThis));
  4947. }
  4948. else if (shared.isObject(raw)) {
  4949. if (shared.isArray(raw)) {
  4950. raw.forEach(r => createWatcher(r, ctx, publicThis, key));
  4951. }
  4952. else {
  4953. const handler = shared.isFunction(raw.handler)
  4954. ? raw.handler.bind(publicThis)
  4955. : ctx[raw.handler];
  4956. if (shared.isFunction(handler)) {
  4957. watch(getter, handler, raw);
  4958. }
  4959. else {
  4960. warn(`Invalid watch handler specified by key "${raw.handler}"`, handler);
  4961. }
  4962. }
  4963. }
  4964. else {
  4965. warn(`Invalid watch option: "${key}"`, raw);
  4966. }
  4967. }
  4968. /**
  4969. * Resolve merged options and cache it on the component.
  4970. * This is done only once per-component since the merging does not involve
  4971. * instances.
  4972. */
  4973. function resolveMergedOptions(instance) {
  4974. const base = instance.type;
  4975. const { mixins, extends: extendsOptions } = base;
  4976. const { mixins: globalMixins, optionsCache: cache, config: { optionMergeStrategies } } = instance.appContext;
  4977. const cached = cache.get(base);
  4978. let resolved;
  4979. if (cached) {
  4980. resolved = cached;
  4981. }
  4982. else if (!globalMixins.length && !mixins && !extendsOptions) {
  4983. {
  4984. resolved = base;
  4985. }
  4986. }
  4987. else {
  4988. resolved = {};
  4989. if (globalMixins.length) {
  4990. globalMixins.forEach(m => mergeOptions(resolved, m, optionMergeStrategies, true));
  4991. }
  4992. mergeOptions(resolved, base, optionMergeStrategies);
  4993. }
  4994. if (shared.isObject(base)) {
  4995. cache.set(base, resolved);
  4996. }
  4997. return resolved;
  4998. }
  4999. function mergeOptions(to, from, strats, asMixin = false) {
  5000. const { mixins, extends: extendsOptions } = from;
  5001. if (extendsOptions) {
  5002. mergeOptions(to, extendsOptions, strats, true);
  5003. }
  5004. if (mixins) {
  5005. mixins.forEach((m) => mergeOptions(to, m, strats, true));
  5006. }
  5007. for (const key in from) {
  5008. if (asMixin && key === 'expose') {
  5009. warn(`"expose" option is ignored when declared in mixins or extends. ` +
  5010. `It should only be declared in the base component itself.`);
  5011. }
  5012. else {
  5013. const strat = internalOptionMergeStrats[key] || (strats && strats[key]);
  5014. to[key] = strat ? strat(to[key], from[key]) : from[key];
  5015. }
  5016. }
  5017. return to;
  5018. }
  5019. const internalOptionMergeStrats = {
  5020. data: mergeDataFn,
  5021. props: mergeObjectOptions,
  5022. emits: mergeObjectOptions,
  5023. // objects
  5024. methods: mergeObjectOptions,
  5025. computed: mergeObjectOptions,
  5026. // lifecycle
  5027. beforeCreate: mergeAsArray,
  5028. created: mergeAsArray,
  5029. beforeMount: mergeAsArray,
  5030. mounted: mergeAsArray,
  5031. beforeUpdate: mergeAsArray,
  5032. updated: mergeAsArray,
  5033. beforeDestroy: mergeAsArray,
  5034. beforeUnmount: mergeAsArray,
  5035. destroyed: mergeAsArray,
  5036. unmounted: mergeAsArray,
  5037. activated: mergeAsArray,
  5038. deactivated: mergeAsArray,
  5039. errorCaptured: mergeAsArray,
  5040. serverPrefetch: mergeAsArray,
  5041. // assets
  5042. components: mergeObjectOptions,
  5043. directives: mergeObjectOptions,
  5044. // watch
  5045. watch: mergeWatchOptions,
  5046. // provide / inject
  5047. provide: mergeDataFn,
  5048. inject: mergeInject
  5049. };
  5050. function mergeDataFn(to, from) {
  5051. if (!from) {
  5052. return to;
  5053. }
  5054. if (!to) {
  5055. return from;
  5056. }
  5057. return function mergedDataFn() {
  5058. return (shared.extend)(shared.isFunction(to) ? to.call(this, this) : to, shared.isFunction(from) ? from.call(this, this) : from);
  5059. };
  5060. }
  5061. function mergeInject(to, from) {
  5062. return mergeObjectOptions(normalizeInject(to), normalizeInject(from));
  5063. }
  5064. function normalizeInject(raw) {
  5065. if (shared.isArray(raw)) {
  5066. const res = {};
  5067. for (let i = 0; i < raw.length; i++) {
  5068. res[raw[i]] = raw[i];
  5069. }
  5070. return res;
  5071. }
  5072. return raw;
  5073. }
  5074. function mergeAsArray(to, from) {
  5075. return to ? [...new Set([].concat(to, from))] : from;
  5076. }
  5077. function mergeObjectOptions(to, from) {
  5078. return to ? shared.extend(shared.extend(Object.create(null), to), from) : from;
  5079. }
  5080. function mergeWatchOptions(to, from) {
  5081. if (!to)
  5082. return from;
  5083. if (!from)
  5084. return to;
  5085. const merged = shared.extend(Object.create(null), to);
  5086. for (const key in from) {
  5087. merged[key] = mergeAsArray(to[key], from[key]);
  5088. }
  5089. return merged;
  5090. }
  5091. function initProps(instance, rawProps, isStateful, // result of bitwise flag comparison
  5092. isSSR = false) {
  5093. const props = {};
  5094. const attrs = {};
  5095. shared.def(attrs, InternalObjectKey, 1);
  5096. instance.propsDefaults = Object.create(null);
  5097. setFullProps(instance, rawProps, props, attrs);
  5098. // ensure all declared prop keys are present
  5099. for (const key in instance.propsOptions[0]) {
  5100. if (!(key in props)) {
  5101. props[key] = undefined;
  5102. }
  5103. }
  5104. // validation
  5105. {
  5106. validateProps(rawProps || {}, props, instance);
  5107. }
  5108. if (isStateful) {
  5109. // stateful
  5110. instance.props = isSSR ? props : shallowReactive(props);
  5111. }
  5112. else {
  5113. if (!instance.type.props) {
  5114. // functional w/ optional props, props === attrs
  5115. instance.props = attrs;
  5116. }
  5117. else {
  5118. // functional w/ declared props
  5119. instance.props = props;
  5120. }
  5121. }
  5122. instance.attrs = attrs;
  5123. }
  5124. function isInHmrContext(instance) {
  5125. while (instance) {
  5126. if (instance.type.__hmrId)
  5127. return true;
  5128. instance = instance.parent;
  5129. }
  5130. }
  5131. function updateProps(instance, rawProps, rawPrevProps, optimized) {
  5132. const { props, attrs, vnode: { patchFlag } } = instance;
  5133. const rawCurrentProps = toRaw(props);
  5134. const [options] = instance.propsOptions;
  5135. let hasAttrsChanged = false;
  5136. if (
  5137. // always force full diff in dev
  5138. // - #1942 if hmr is enabled with sfc component
  5139. // - vite#872 non-sfc component used by sfc component
  5140. !(isInHmrContext(instance)) &&
  5141. (optimized || patchFlag > 0) &&
  5142. !(patchFlag & 16 /* PatchFlags.FULL_PROPS */)) {
  5143. if (patchFlag & 8 /* PatchFlags.PROPS */) {
  5144. // Compiler-generated props & no keys change, just set the updated
  5145. // the props.
  5146. const propsToUpdate = instance.vnode.dynamicProps;
  5147. for (let i = 0; i < propsToUpdate.length; i++) {
  5148. let key = propsToUpdate[i];
  5149. // skip if the prop key is a declared emit event listener
  5150. if (isEmitListener(instance.emitsOptions, key)) {
  5151. continue;
  5152. }
  5153. // PROPS flag guarantees rawProps to be non-null
  5154. const value = rawProps[key];
  5155. if (options) {
  5156. // attr / props separation was done on init and will be consistent
  5157. // in this code path, so just check if attrs have it.
  5158. if (shared.hasOwn(attrs, key)) {
  5159. if (value !== attrs[key]) {
  5160. attrs[key] = value;
  5161. hasAttrsChanged = true;
  5162. }
  5163. }
  5164. else {
  5165. const camelizedKey = shared.camelize(key);
  5166. props[camelizedKey] = resolvePropValue(options, rawCurrentProps, camelizedKey, value, instance, false /* isAbsent */);
  5167. }
  5168. }
  5169. else {
  5170. if (value !== attrs[key]) {
  5171. attrs[key] = value;
  5172. hasAttrsChanged = true;
  5173. }
  5174. }
  5175. }
  5176. }
  5177. }
  5178. else {
  5179. // full props update.
  5180. if (setFullProps(instance, rawProps, props, attrs)) {
  5181. hasAttrsChanged = true;
  5182. }
  5183. // in case of dynamic props, check if we need to delete keys from
  5184. // the props object
  5185. let kebabKey;
  5186. for (const key in rawCurrentProps) {
  5187. if (!rawProps ||
  5188. // for camelCase
  5189. (!shared.hasOwn(rawProps, key) &&
  5190. // it's possible the original props was passed in as kebab-case
  5191. // and converted to camelCase (#955)
  5192. ((kebabKey = shared.hyphenate(key)) === key || !shared.hasOwn(rawProps, kebabKey)))) {
  5193. if (options) {
  5194. if (rawPrevProps &&
  5195. // for camelCase
  5196. (rawPrevProps[key] !== undefined ||
  5197. // for kebab-case
  5198. rawPrevProps[kebabKey] !== undefined)) {
  5199. props[key] = resolvePropValue(options, rawCurrentProps, key, undefined, instance, true /* isAbsent */);
  5200. }
  5201. }
  5202. else {
  5203. delete props[key];
  5204. }
  5205. }
  5206. }
  5207. // in the case of functional component w/o props declaration, props and
  5208. // attrs point to the same object so it should already have been updated.
  5209. if (attrs !== rawCurrentProps) {
  5210. for (const key in attrs) {
  5211. if (!rawProps ||
  5212. (!shared.hasOwn(rawProps, key) &&
  5213. (!false ))) {
  5214. delete attrs[key];
  5215. hasAttrsChanged = true;
  5216. }
  5217. }
  5218. }
  5219. }
  5220. // trigger updates for $attrs in case it's used in component slots
  5221. if (hasAttrsChanged) {
  5222. trigger(instance, "set" /* TriggerOpTypes.SET */, '$attrs');
  5223. }
  5224. {
  5225. validateProps(rawProps || {}, props, instance);
  5226. }
  5227. }
  5228. function setFullProps(instance, rawProps, props, attrs) {
  5229. const [options, needCastKeys] = instance.propsOptions;
  5230. let hasAttrsChanged = false;
  5231. let rawCastValues;
  5232. if (rawProps) {
  5233. for (let key in rawProps) {
  5234. // key, ref are reserved and never passed down
  5235. if (shared.isReservedProp(key)) {
  5236. continue;
  5237. }
  5238. const value = rawProps[key];
  5239. // prop option names are camelized during normalization, so to support
  5240. // kebab -> camel conversion here we need to camelize the key.
  5241. let camelKey;
  5242. if (options && shared.hasOwn(options, (camelKey = shared.camelize(key)))) {
  5243. if (!needCastKeys || !needCastKeys.includes(camelKey)) {
  5244. props[camelKey] = value;
  5245. }
  5246. else {
  5247. (rawCastValues || (rawCastValues = {}))[camelKey] = value;
  5248. }
  5249. }
  5250. else if (!isEmitListener(instance.emitsOptions, key)) {
  5251. if (!(key in attrs) || value !== attrs[key]) {
  5252. attrs[key] = value;
  5253. hasAttrsChanged = true;
  5254. }
  5255. }
  5256. }
  5257. }
  5258. if (needCastKeys) {
  5259. const rawCurrentProps = toRaw(props);
  5260. const castValues = rawCastValues || shared.EMPTY_OBJ;
  5261. for (let i = 0; i < needCastKeys.length; i++) {
  5262. const key = needCastKeys[i];
  5263. props[key] = resolvePropValue(options, rawCurrentProps, key, castValues[key], instance, !shared.hasOwn(castValues, key));
  5264. }
  5265. }
  5266. return hasAttrsChanged;
  5267. }
  5268. function resolvePropValue(options, props, key, value, instance, isAbsent) {
  5269. const opt = options[key];
  5270. if (opt != null) {
  5271. const hasDefault = shared.hasOwn(opt, 'default');
  5272. // default values
  5273. if (hasDefault && value === undefined) {
  5274. const defaultValue = opt.default;
  5275. if (opt.type !== Function && shared.isFunction(defaultValue)) {
  5276. const { propsDefaults } = instance;
  5277. if (key in propsDefaults) {
  5278. value = propsDefaults[key];
  5279. }
  5280. else {
  5281. setCurrentInstance(instance);
  5282. value = propsDefaults[key] = defaultValue.call(null, props);
  5283. unsetCurrentInstance();
  5284. }
  5285. }
  5286. else {
  5287. value = defaultValue;
  5288. }
  5289. }
  5290. // boolean casting
  5291. if (opt[0 /* BooleanFlags.shouldCast */]) {
  5292. if (isAbsent && !hasDefault) {
  5293. value = false;
  5294. }
  5295. else if (opt[1 /* BooleanFlags.shouldCastTrue */] &&
  5296. (value === '' || value === shared.hyphenate(key))) {
  5297. value = true;
  5298. }
  5299. }
  5300. }
  5301. return value;
  5302. }
  5303. function normalizePropsOptions(comp, appContext, asMixin = false) {
  5304. const cache = appContext.propsCache;
  5305. const cached = cache.get(comp);
  5306. if (cached) {
  5307. return cached;
  5308. }
  5309. const raw = comp.props;
  5310. const normalized = {};
  5311. const needCastKeys = [];
  5312. // apply mixin/extends props
  5313. let hasExtends = false;
  5314. if (!shared.isFunction(comp)) {
  5315. const extendProps = (raw) => {
  5316. hasExtends = true;
  5317. const [props, keys] = normalizePropsOptions(raw, appContext, true);
  5318. shared.extend(normalized, props);
  5319. if (keys)
  5320. needCastKeys.push(...keys);
  5321. };
  5322. if (!asMixin && appContext.mixins.length) {
  5323. appContext.mixins.forEach(extendProps);
  5324. }
  5325. if (comp.extends) {
  5326. extendProps(comp.extends);
  5327. }
  5328. if (comp.mixins) {
  5329. comp.mixins.forEach(extendProps);
  5330. }
  5331. }
  5332. if (!raw && !hasExtends) {
  5333. if (shared.isObject(comp)) {
  5334. cache.set(comp, shared.EMPTY_ARR);
  5335. }
  5336. return shared.EMPTY_ARR;
  5337. }
  5338. if (shared.isArray(raw)) {
  5339. for (let i = 0; i < raw.length; i++) {
  5340. if (!shared.isString(raw[i])) {
  5341. warn(`props must be strings when using array syntax.`, raw[i]);
  5342. }
  5343. const normalizedKey = shared.camelize(raw[i]);
  5344. if (validatePropName(normalizedKey)) {
  5345. normalized[normalizedKey] = shared.EMPTY_OBJ;
  5346. }
  5347. }
  5348. }
  5349. else if (raw) {
  5350. if (!shared.isObject(raw)) {
  5351. warn(`invalid props options`, raw);
  5352. }
  5353. for (const key in raw) {
  5354. const normalizedKey = shared.camelize(key);
  5355. if (validatePropName(normalizedKey)) {
  5356. const opt = raw[key];
  5357. const prop = (normalized[normalizedKey] =
  5358. shared.isArray(opt) || shared.isFunction(opt) ? { type: opt } : { ...opt });
  5359. if (prop) {
  5360. const booleanIndex = getTypeIndex(Boolean, prop.type);
  5361. const stringIndex = getTypeIndex(String, prop.type);
  5362. prop[0 /* BooleanFlags.shouldCast */] = booleanIndex > -1;
  5363. prop[1 /* BooleanFlags.shouldCastTrue */] =
  5364. stringIndex < 0 || booleanIndex < stringIndex;
  5365. // if the prop needs boolean casting or default value
  5366. if (booleanIndex > -1 || shared.hasOwn(prop, 'default')) {
  5367. needCastKeys.push(normalizedKey);
  5368. }
  5369. }
  5370. }
  5371. }
  5372. }
  5373. const res = [normalized, needCastKeys];
  5374. if (shared.isObject(comp)) {
  5375. cache.set(comp, res);
  5376. }
  5377. return res;
  5378. }
  5379. function validatePropName(key) {
  5380. if (key[0] !== '$') {
  5381. return true;
  5382. }
  5383. else {
  5384. warn(`Invalid prop name: "${key}" is a reserved property.`);
  5385. }
  5386. return false;
  5387. }
  5388. // use function string name to check type constructors
  5389. // so that it works across vms / iframes.
  5390. function getType(ctor) {
  5391. const match = ctor && ctor.toString().match(/^\s*(function|class) (\w+)/);
  5392. return match ? match[2] : ctor === null ? 'null' : '';
  5393. }
  5394. function isSameType(a, b) {
  5395. return getType(a) === getType(b);
  5396. }
  5397. function getTypeIndex(type, expectedTypes) {
  5398. if (shared.isArray(expectedTypes)) {
  5399. return expectedTypes.findIndex(t => isSameType(t, type));
  5400. }
  5401. else if (shared.isFunction(expectedTypes)) {
  5402. return isSameType(expectedTypes, type) ? 0 : -1;
  5403. }
  5404. return -1;
  5405. }
  5406. /**
  5407. * dev only
  5408. */
  5409. function validateProps(rawProps, props, instance) {
  5410. const resolvedValues = toRaw(props);
  5411. const options = instance.propsOptions[0];
  5412. for (const key in options) {
  5413. let opt = options[key];
  5414. if (opt == null)
  5415. continue;
  5416. validateProp(key, resolvedValues[key], opt, !shared.hasOwn(rawProps, key) && !shared.hasOwn(rawProps, shared.hyphenate(key)));
  5417. }
  5418. }
  5419. /**
  5420. * dev only
  5421. */
  5422. function validateProp(name, value, prop, isAbsent) {
  5423. const { type, required, validator } = prop;
  5424. // required!
  5425. if (required && isAbsent) {
  5426. warn('Missing required prop: "' + name + '"');
  5427. return;
  5428. }
  5429. // missing but optional
  5430. if (value == null && !prop.required) {
  5431. return;
  5432. }
  5433. // type check
  5434. if (type != null && type !== true) {
  5435. let isValid = false;
  5436. const types = shared.isArray(type) ? type : [type];
  5437. const expectedTypes = [];
  5438. // value is valid as long as one of the specified types match
  5439. for (let i = 0; i < types.length && !isValid; i++) {
  5440. const { valid, expectedType } = assertType(value, types[i]);
  5441. expectedTypes.push(expectedType || '');
  5442. isValid = valid;
  5443. }
  5444. if (!isValid) {
  5445. warn(getInvalidTypeMessage(name, value, expectedTypes));
  5446. return;
  5447. }
  5448. }
  5449. // custom validator
  5450. if (validator && !validator(value)) {
  5451. warn('Invalid prop: custom validator check failed for prop "' + name + '".');
  5452. }
  5453. }
  5454. const isSimpleType = /*#__PURE__*/ shared.makeMap('String,Number,Boolean,Function,Symbol,BigInt');
  5455. /**
  5456. * dev only
  5457. */
  5458. function assertType(value, type) {
  5459. let valid;
  5460. const expectedType = getType(type);
  5461. if (isSimpleType(expectedType)) {
  5462. const t = typeof value;
  5463. valid = t === expectedType.toLowerCase();
  5464. // for primitive wrapper objects
  5465. if (!valid && t === 'object') {
  5466. valid = value instanceof type;
  5467. }
  5468. }
  5469. else if (expectedType === 'Object') {
  5470. valid = shared.isObject(value);
  5471. }
  5472. else if (expectedType === 'Array') {
  5473. valid = shared.isArray(value);
  5474. }
  5475. else if (expectedType === 'null') {
  5476. valid = value === null;
  5477. }
  5478. else {
  5479. valid = value instanceof type;
  5480. }
  5481. return {
  5482. valid,
  5483. expectedType
  5484. };
  5485. }
  5486. /**
  5487. * dev only
  5488. */
  5489. function getInvalidTypeMessage(name, value, expectedTypes) {
  5490. let message = `Invalid prop: type check failed for prop "${name}".` +
  5491. ` Expected ${expectedTypes.map(shared.capitalize).join(' | ')}`;
  5492. const expectedType = expectedTypes[0];
  5493. const receivedType = shared.toRawType(value);
  5494. const expectedValue = styleValue(value, expectedType);
  5495. const receivedValue = styleValue(value, receivedType);
  5496. // check if we need to specify expected value
  5497. if (expectedTypes.length === 1 &&
  5498. isExplicable(expectedType) &&
  5499. !isBoolean(expectedType, receivedType)) {
  5500. message += ` with value ${expectedValue}`;
  5501. }
  5502. message += `, got ${receivedType} `;
  5503. // check if we need to specify received value
  5504. if (isExplicable(receivedType)) {
  5505. message += `with value ${receivedValue}.`;
  5506. }
  5507. return message;
  5508. }
  5509. /**
  5510. * dev only
  5511. */
  5512. function styleValue(value, type) {
  5513. if (type === 'String') {
  5514. return `"${value}"`;
  5515. }
  5516. else if (type === 'Number') {
  5517. return `${Number(value)}`;
  5518. }
  5519. else {
  5520. return `${value}`;
  5521. }
  5522. }
  5523. /**
  5524. * dev only
  5525. */
  5526. function isExplicable(type) {
  5527. const explicitTypes = ['string', 'number', 'boolean'];
  5528. return explicitTypes.some(elem => type.toLowerCase() === elem);
  5529. }
  5530. /**
  5531. * dev only
  5532. */
  5533. function isBoolean(...args) {
  5534. return args.some(elem => elem.toLowerCase() === 'boolean');
  5535. }
  5536. const isInternalKey = (key) => key[0] === '_' || key === '$stable';
  5537. const normalizeSlotValue = (value) => shared.isArray(value)
  5538. ? value.map(normalizeVNode)
  5539. : [normalizeVNode(value)];
  5540. const normalizeSlot = (key, rawSlot, ctx) => {
  5541. if (rawSlot._n) {
  5542. // already normalized - #5353
  5543. return rawSlot;
  5544. }
  5545. const normalized = withCtx((...args) => {
  5546. if (true && currentInstance) {
  5547. warn(`Slot "${key}" invoked outside of the render function: ` +
  5548. `this will not track dependencies used in the slot. ` +
  5549. `Invoke the slot function inside the render function instead.`);
  5550. }
  5551. return normalizeSlotValue(rawSlot(...args));
  5552. }, ctx);
  5553. normalized._c = false;
  5554. return normalized;
  5555. };
  5556. const normalizeObjectSlots = (rawSlots, slots, instance) => {
  5557. const ctx = rawSlots._ctx;
  5558. for (const key in rawSlots) {
  5559. if (isInternalKey(key))
  5560. continue;
  5561. const value = rawSlots[key];
  5562. if (shared.isFunction(value)) {
  5563. slots[key] = normalizeSlot(key, value, ctx);
  5564. }
  5565. else if (value != null) {
  5566. {
  5567. warn(`Non-function value encountered for slot "${key}". ` +
  5568. `Prefer function slots for better performance.`);
  5569. }
  5570. const normalized = normalizeSlotValue(value);
  5571. slots[key] = () => normalized;
  5572. }
  5573. }
  5574. };
  5575. const normalizeVNodeSlots = (instance, children) => {
  5576. if (!isKeepAlive(instance.vnode) &&
  5577. !(false )) {
  5578. warn(`Non-function value encountered for default slot. ` +
  5579. `Prefer function slots for better performance.`);
  5580. }
  5581. const normalized = normalizeSlotValue(children);
  5582. instance.slots.default = () => normalized;
  5583. };
  5584. const initSlots = (instance, children) => {
  5585. if (instance.vnode.shapeFlag & 32 /* ShapeFlags.SLOTS_CHILDREN */) {
  5586. const type = children._;
  5587. if (type) {
  5588. // users can get the shallow readonly version of the slots object through `this.$slots`,
  5589. // we should avoid the proxy object polluting the slots of the internal instance
  5590. instance.slots = toRaw(children);
  5591. // make compiler marker non-enumerable
  5592. shared.def(children, '_', type);
  5593. }
  5594. else {
  5595. normalizeObjectSlots(children, (instance.slots = {}));
  5596. }
  5597. }
  5598. else {
  5599. instance.slots = {};
  5600. if (children) {
  5601. normalizeVNodeSlots(instance, children);
  5602. }
  5603. }
  5604. shared.def(instance.slots, InternalObjectKey, 1);
  5605. };
  5606. const updateSlots = (instance, children, optimized) => {
  5607. const { vnode, slots } = instance;
  5608. let needDeletionCheck = true;
  5609. let deletionComparisonTarget = shared.EMPTY_OBJ;
  5610. if (vnode.shapeFlag & 32 /* ShapeFlags.SLOTS_CHILDREN */) {
  5611. const type = children._;
  5612. if (type) {
  5613. // compiled slots.
  5614. if (isHmrUpdating) {
  5615. // Parent was HMR updated so slot content may have changed.
  5616. // force update slots and mark instance for hmr as well
  5617. shared.extend(slots, children);
  5618. }
  5619. else if (optimized && type === 1 /* SlotFlags.STABLE */) {
  5620. // compiled AND stable.
  5621. // no need to update, and skip stale slots removal.
  5622. needDeletionCheck = false;
  5623. }
  5624. else {
  5625. // compiled but dynamic (v-if/v-for on slots) - update slots, but skip
  5626. // normalization.
  5627. shared.extend(slots, children);
  5628. // #2893
  5629. // when rendering the optimized slots by manually written render function,
  5630. // we need to delete the `slots._` flag if necessary to make subsequent updates reliable,
  5631. // i.e. let the `renderSlot` create the bailed Fragment
  5632. if (!optimized && type === 1 /* SlotFlags.STABLE */) {
  5633. delete slots._;
  5634. }
  5635. }
  5636. }
  5637. else {
  5638. needDeletionCheck = !children.$stable;
  5639. normalizeObjectSlots(children, slots);
  5640. }
  5641. deletionComparisonTarget = children;
  5642. }
  5643. else if (children) {
  5644. // non slot object children (direct value) passed to a component
  5645. normalizeVNodeSlots(instance, children);
  5646. deletionComparisonTarget = { default: 1 };
  5647. }
  5648. // delete stale slots
  5649. if (needDeletionCheck) {
  5650. for (const key in slots) {
  5651. if (!isInternalKey(key) && !(key in deletionComparisonTarget)) {
  5652. delete slots[key];
  5653. }
  5654. }
  5655. }
  5656. };
  5657. function createAppContext() {
  5658. return {
  5659. app: null,
  5660. config: {
  5661. isNativeTag: shared.NO,
  5662. performance: false,
  5663. globalProperties: {},
  5664. optionMergeStrategies: {},
  5665. errorHandler: undefined,
  5666. warnHandler: undefined,
  5667. compilerOptions: {}
  5668. },
  5669. mixins: [],
  5670. components: {},
  5671. directives: {},
  5672. provides: Object.create(null),
  5673. optionsCache: new WeakMap(),
  5674. propsCache: new WeakMap(),
  5675. emitsCache: new WeakMap()
  5676. };
  5677. }
  5678. let uid$1 = 0;
  5679. function createAppAPI(render, hydrate) {
  5680. return function createApp(rootComponent, rootProps = null) {
  5681. if (!shared.isFunction(rootComponent)) {
  5682. rootComponent = { ...rootComponent };
  5683. }
  5684. if (rootProps != null && !shared.isObject(rootProps)) {
  5685. warn(`root props passed to app.mount() must be an object.`);
  5686. rootProps = null;
  5687. }
  5688. const context = createAppContext();
  5689. const installedPlugins = new Set();
  5690. let isMounted = false;
  5691. const app = (context.app = {
  5692. _uid: uid$1++,
  5693. _component: rootComponent,
  5694. _props: rootProps,
  5695. _container: null,
  5696. _context: context,
  5697. _instance: null,
  5698. version,
  5699. get config() {
  5700. return context.config;
  5701. },
  5702. set config(v) {
  5703. {
  5704. warn(`app.config cannot be replaced. Modify individual options instead.`);
  5705. }
  5706. },
  5707. use(plugin, ...options) {
  5708. if (installedPlugins.has(plugin)) {
  5709. warn(`Plugin has already been applied to target app.`);
  5710. }
  5711. else if (plugin && shared.isFunction(plugin.install)) {
  5712. installedPlugins.add(plugin);
  5713. plugin.install(app, ...options);
  5714. }
  5715. else if (shared.isFunction(plugin)) {
  5716. installedPlugins.add(plugin);
  5717. plugin(app, ...options);
  5718. }
  5719. else {
  5720. warn(`A plugin must either be a function or an object with an "install" ` +
  5721. `function.`);
  5722. }
  5723. return app;
  5724. },
  5725. mixin(mixin) {
  5726. {
  5727. if (!context.mixins.includes(mixin)) {
  5728. context.mixins.push(mixin);
  5729. }
  5730. else {
  5731. warn('Mixin has already been applied to target app' +
  5732. (mixin.name ? `: ${mixin.name}` : ''));
  5733. }
  5734. }
  5735. return app;
  5736. },
  5737. component(name, component) {
  5738. {
  5739. validateComponentName(name, context.config);
  5740. }
  5741. if (!component) {
  5742. return context.components[name];
  5743. }
  5744. if (context.components[name]) {
  5745. warn(`Component "${name}" has already been registered in target app.`);
  5746. }
  5747. context.components[name] = component;
  5748. return app;
  5749. },
  5750. directive(name, directive) {
  5751. {
  5752. validateDirectiveName(name);
  5753. }
  5754. if (!directive) {
  5755. return context.directives[name];
  5756. }
  5757. if (context.directives[name]) {
  5758. warn(`Directive "${name}" has already been registered in target app.`);
  5759. }
  5760. context.directives[name] = directive;
  5761. return app;
  5762. },
  5763. mount(rootContainer, isHydrate, isSVG) {
  5764. if (!isMounted) {
  5765. // #5571
  5766. if (rootContainer.__vue_app__) {
  5767. warn(`There is already an app instance mounted on the host container.\n` +
  5768. ` If you want to mount another app on the same host container,` +
  5769. ` you need to unmount the previous app by calling \`app.unmount()\` first.`);
  5770. }
  5771. const vnode = createVNode(rootComponent, rootProps);
  5772. // store app context on the root VNode.
  5773. // this will be set on the root instance on initial mount.
  5774. vnode.appContext = context;
  5775. // HMR root reload
  5776. {
  5777. context.reload = () => {
  5778. render(cloneVNode(vnode), rootContainer, isSVG);
  5779. };
  5780. }
  5781. if (isHydrate && hydrate) {
  5782. hydrate(vnode, rootContainer);
  5783. }
  5784. else {
  5785. render(vnode, rootContainer, isSVG);
  5786. }
  5787. isMounted = true;
  5788. app._container = rootContainer;
  5789. rootContainer.__vue_app__ = app;
  5790. // fixed by xxxxxx (始终暴露,因为 onError 要访问)
  5791. app._instance = vnode.component;
  5792. {
  5793. devtoolsInitApp(app, version);
  5794. }
  5795. return getExposeProxy(vnode.component) || vnode.component.proxy;
  5796. }
  5797. else {
  5798. warn(`App has already been mounted.\n` +
  5799. `If you want to remount the same app, move your app creation logic ` +
  5800. `into a factory function and create fresh app instances for each ` +
  5801. `mount - e.g. \`const createMyApp = () => createApp(App)\``);
  5802. }
  5803. },
  5804. unmount() {
  5805. if (isMounted) {
  5806. render(null, app._container);
  5807. {
  5808. app._instance = null;
  5809. devtoolsUnmountApp(app);
  5810. }
  5811. delete app._container.__vue_app__;
  5812. }
  5813. else {
  5814. warn(`Cannot unmount an app that is not mounted.`);
  5815. }
  5816. },
  5817. provide(key, value) {
  5818. if (key in context.provides) {
  5819. warn(`App already provides property with key "${String(key)}". ` +
  5820. `It will be overwritten with the new value.`);
  5821. }
  5822. context.provides[key] = value;
  5823. return app;
  5824. }
  5825. });
  5826. return app;
  5827. };
  5828. }
  5829. /**
  5830. * Function for handling a template ref
  5831. */
  5832. function setRef(rawRef, oldRawRef, parentSuspense, vnode, isUnmount = false) {
  5833. if (shared.isArray(rawRef)) {
  5834. rawRef.forEach((r, i) => setRef(r, oldRawRef && (shared.isArray(oldRawRef) ? oldRawRef[i] : oldRawRef), parentSuspense, vnode, isUnmount));
  5835. return;
  5836. }
  5837. if (isAsyncWrapper(vnode) && !isUnmount) {
  5838. // when mounting async components, nothing needs to be done,
  5839. // because the template ref is forwarded to inner component
  5840. return;
  5841. }
  5842. const refValue = vnode.shapeFlag & 4 /* ShapeFlags.STATEFUL_COMPONENT */ &&
  5843. !(vnode.component.type.rootElement) // fixed by xxxxxx 非 x 项目或者非内置组件
  5844. ? getExposeProxy(vnode.component) || vnode.component.proxy
  5845. : vnode.el;
  5846. const value = isUnmount ? null : refValue;
  5847. const { i: owner, r: ref } = rawRef;
  5848. if (!owner) {
  5849. warn(`Missing ref owner context. ref cannot be used on hoisted vnodes. ` +
  5850. `A vnode with ref must be created inside the render function.`);
  5851. return;
  5852. }
  5853. const oldRef = oldRawRef && oldRawRef.r;
  5854. const refs = owner.refs === shared.EMPTY_OBJ ? (owner.refs = {}) : owner.refs;
  5855. const setupState = owner.setupState;
  5856. // dynamic ref changed. unset old ref
  5857. if (oldRef != null && oldRef !== ref) {
  5858. if (shared.isString(oldRef)) {
  5859. refs[oldRef] = null;
  5860. if (shared.hasOwn(setupState, oldRef)) {
  5861. setupState[oldRef] = null;
  5862. }
  5863. }
  5864. else if (isRef(oldRef)) {
  5865. oldRef.value = null;
  5866. }
  5867. }
  5868. if (shared.isFunction(ref)) {
  5869. callWithErrorHandling(ref, owner, 12 /* ErrorCodes.FUNCTION_REF */, [value, refs]);
  5870. }
  5871. else {
  5872. const _isString = shared.isString(ref);
  5873. const _isRef = isRef(ref);
  5874. if (_isString || _isRef) {
  5875. const doSet = () => {
  5876. if (rawRef.f) {
  5877. const existing = _isString
  5878. ? shared.hasOwn(setupState, ref)
  5879. ? setupState[ref]
  5880. : refs[ref]
  5881. : ref.value;
  5882. if (isUnmount) {
  5883. shared.isArray(existing) && shared.remove(existing, refValue);
  5884. }
  5885. else {
  5886. if (!shared.isArray(existing)) {
  5887. if (_isString) {
  5888. refs[ref] = [refValue];
  5889. if (shared.hasOwn(setupState, ref)) {
  5890. setupState[ref] = refs[ref];
  5891. }
  5892. }
  5893. else {
  5894. ref.value = [refValue];
  5895. if (rawRef.k)
  5896. refs[rawRef.k] = ref.value;
  5897. }
  5898. }
  5899. else if (!existing.includes(refValue)) {
  5900. existing.push(refValue);
  5901. }
  5902. }
  5903. }
  5904. else if (_isString) {
  5905. refs[ref] = value;
  5906. if (shared.hasOwn(setupState, ref)) {
  5907. setupState[ref] = value;
  5908. }
  5909. }
  5910. else if (_isRef) {
  5911. ref.value = value;
  5912. if (rawRef.k)
  5913. refs[rawRef.k] = value;
  5914. }
  5915. else {
  5916. warn('Invalid template ref type:', ref, `(${typeof ref})`);
  5917. }
  5918. };
  5919. if (value) {
  5920. doSet.id = -1;
  5921. queuePostRenderEffect(doSet, parentSuspense);
  5922. }
  5923. else {
  5924. doSet();
  5925. }
  5926. }
  5927. else {
  5928. warn('Invalid template ref type:', ref, `(${typeof ref})`);
  5929. }
  5930. }
  5931. }
  5932. let hasMismatch = false;
  5933. const isSVGContainer = (container) => /svg/.test(container.namespaceURI) && container.tagName !== 'foreignObject';
  5934. const isComment = (node) => node.nodeType === 8 /* DOMNodeTypes.COMMENT */;
  5935. // Note: hydration is DOM-specific
  5936. // But we have to place it in core due to tight coupling with core - splitting
  5937. // it out creates a ton of unnecessary complexity.
  5938. // Hydration also depends on some renderer internal logic which needs to be
  5939. // passed in via arguments.
  5940. function createHydrationFunctions(rendererInternals) {
  5941. const { mt: mountComponent, p: patch, o: { patchProp, createText, nextSibling, parentNode, remove, insert, createComment } } = rendererInternals;
  5942. const hydrate = (vnode, container) => {
  5943. if (!container.hasChildNodes()) {
  5944. warn(`Attempting to hydrate existing markup but container is empty. ` +
  5945. `Performing full mount instead.`);
  5946. patch(null, vnode, container);
  5947. flushPostFlushCbs();
  5948. container._vnode = vnode;
  5949. return;
  5950. }
  5951. hasMismatch = false;
  5952. hydrateNode(container.firstChild, vnode, null, null, null);
  5953. flushPostFlushCbs();
  5954. container._vnode = vnode;
  5955. if (hasMismatch && !false) {
  5956. // this error should show up in production
  5957. console.error(`Hydration completed but contains mismatches.`);
  5958. }
  5959. };
  5960. const hydrateNode = (node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized = false) => {
  5961. const isFragmentStart = isComment(node) && node.data === '[';
  5962. const onMismatch = () => handleMismatch(node, vnode, parentComponent, parentSuspense, slotScopeIds, isFragmentStart);
  5963. const { type, ref, shapeFlag, patchFlag } = vnode;
  5964. let domType = node.nodeType;
  5965. vnode.el = node;
  5966. if (patchFlag === -2 /* PatchFlags.BAIL */) {
  5967. optimized = false;
  5968. vnode.dynamicChildren = null;
  5969. }
  5970. let nextNode = null;
  5971. switch (type) {
  5972. case Text:
  5973. if (domType !== 3 /* DOMNodeTypes.TEXT */) {
  5974. // #5728 empty text node inside a slot can cause hydration failure
  5975. // because the server rendered HTML won't contain a text node
  5976. if (vnode.children === '') {
  5977. insert((vnode.el = createText('')), parentNode(node), node);
  5978. nextNode = node;
  5979. }
  5980. else {
  5981. nextNode = onMismatch();
  5982. }
  5983. }
  5984. else {
  5985. if (node.data !== vnode.children) {
  5986. hasMismatch = true;
  5987. warn(`Hydration text mismatch:` +
  5988. `\n- Client: ${JSON.stringify(node.data)}` +
  5989. `\n- Server: ${JSON.stringify(vnode.children)}`);
  5990. node.data = vnode.children;
  5991. }
  5992. nextNode = nextSibling(node);
  5993. }
  5994. break;
  5995. case Comment:
  5996. if (domType !== 8 /* DOMNodeTypes.COMMENT */ || isFragmentStart) {
  5997. nextNode = onMismatch();
  5998. }
  5999. else {
  6000. nextNode = nextSibling(node);
  6001. }
  6002. break;
  6003. case Static:
  6004. if (isFragmentStart) {
  6005. // entire template is static but SSRed as a fragment
  6006. node = nextSibling(node);
  6007. domType = node.nodeType;
  6008. }
  6009. if (domType === 1 /* DOMNodeTypes.ELEMENT */ || domType === 3 /* DOMNodeTypes.TEXT */) {
  6010. // determine anchor, adopt content
  6011. nextNode = node;
  6012. // if the static vnode has its content stripped during build,
  6013. // adopt it from the server-rendered HTML.
  6014. const needToAdoptContent = !vnode.children.length;
  6015. for (let i = 0; i < vnode.staticCount; i++) {
  6016. if (needToAdoptContent)
  6017. vnode.children +=
  6018. nextNode.nodeType === 1 /* DOMNodeTypes.ELEMENT */
  6019. ? nextNode.outerHTML
  6020. : nextNode.data;
  6021. if (i === vnode.staticCount - 1) {
  6022. vnode.anchor = nextNode;
  6023. }
  6024. nextNode = nextSibling(nextNode);
  6025. }
  6026. return isFragmentStart ? nextSibling(nextNode) : nextNode;
  6027. }
  6028. else {
  6029. onMismatch();
  6030. }
  6031. break;
  6032. case Fragment:
  6033. if (!isFragmentStart) {
  6034. nextNode = onMismatch();
  6035. }
  6036. else {
  6037. nextNode = hydrateFragment(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized);
  6038. }
  6039. break;
  6040. default:
  6041. if (shapeFlag & 1 /* ShapeFlags.ELEMENT */) {
  6042. if (domType !== 1 /* DOMNodeTypes.ELEMENT */ ||
  6043. vnode.type.toLowerCase() !==
  6044. node.tagName.toLowerCase()) {
  6045. nextNode = onMismatch();
  6046. }
  6047. else {
  6048. nextNode = hydrateElement(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized);
  6049. }
  6050. }
  6051. else if (shapeFlag & 6 /* ShapeFlags.COMPONENT */) {
  6052. // when setting up the render effect, if the initial vnode already
  6053. // has .el set, the component will perform hydration instead of mount
  6054. // on its sub-tree.
  6055. vnode.slotScopeIds = slotScopeIds;
  6056. const container = parentNode(node);
  6057. mountComponent(vnode, container, null, parentComponent, parentSuspense, isSVGContainer(container), optimized);
  6058. // component may be async, so in the case of fragments we cannot rely
  6059. // on component's rendered output to determine the end of the fragment
  6060. // instead, we do a lookahead to find the end anchor node.
  6061. nextNode = isFragmentStart
  6062. ? locateClosingAsyncAnchor(node)
  6063. : nextSibling(node);
  6064. // #4293 teleport as component root
  6065. if (nextNode &&
  6066. isComment(nextNode) &&
  6067. nextNode.data === 'teleport end') {
  6068. nextNode = nextSibling(nextNode);
  6069. }
  6070. // #3787
  6071. // if component is async, it may get moved / unmounted before its
  6072. // inner component is loaded, so we need to give it a placeholder
  6073. // vnode that matches its adopted DOM.
  6074. if (isAsyncWrapper(vnode)) {
  6075. let subTree;
  6076. if (isFragmentStart) {
  6077. subTree = createVNode(Fragment);
  6078. subTree.anchor = nextNode
  6079. ? nextNode.previousSibling
  6080. : container.lastChild;
  6081. }
  6082. else {
  6083. subTree =
  6084. node.nodeType === 3 ? createTextVNode('') : createVNode('div');
  6085. }
  6086. subTree.el = node;
  6087. vnode.component.subTree = subTree;
  6088. }
  6089. }
  6090. else if (shapeFlag & 64 /* ShapeFlags.TELEPORT */) {
  6091. if (domType !== 8 /* DOMNodeTypes.COMMENT */) {
  6092. nextNode = onMismatch();
  6093. }
  6094. else {
  6095. nextNode = vnode.type.hydrate(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized, rendererInternals, hydrateChildren);
  6096. }
  6097. }
  6098. else if (shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
  6099. nextNode = vnode.type.hydrate(node, vnode, parentComponent, parentSuspense, isSVGContainer(parentNode(node)), slotScopeIds, optimized, rendererInternals, hydrateNode);
  6100. }
  6101. else {
  6102. warn('Invalid HostVNode type:', type, `(${typeof type})`);
  6103. }
  6104. }
  6105. if (ref != null) {
  6106. setRef(ref, null, parentSuspense, vnode);
  6107. }
  6108. return nextNode;
  6109. };
  6110. const hydrateElement = (el, vnode, parentComponent, parentSuspense, slotScopeIds, optimized) => {
  6111. optimized = optimized || !!vnode.dynamicChildren;
  6112. const { type, props, patchFlag, shapeFlag, dirs } = vnode;
  6113. // #4006 for form elements with non-string v-model value bindings
  6114. // e.g. <option :value="obj">, <input type="checkbox" :true-value="1">
  6115. const forcePatchValue = (type === 'input' && dirs) || type === 'option';
  6116. // skip props & children if this is hoisted static nodes
  6117. // #5405 in dev, always hydrate children for HMR
  6118. {
  6119. if (dirs) {
  6120. invokeDirectiveHook(vnode, null, parentComponent, 'created');
  6121. }
  6122. // props
  6123. if (props) {
  6124. if (forcePatchValue ||
  6125. !optimized ||
  6126. patchFlag & (16 /* PatchFlags.FULL_PROPS */ | 32 /* PatchFlags.HYDRATE_EVENTS */)) {
  6127. for (const key in props) {
  6128. if ((forcePatchValue && key.endsWith('value')) ||
  6129. (shared.isOn(key) && !shared.isReservedProp(key))) {
  6130. patchProp(el, key, null, props[key], false, undefined, parentComponent);
  6131. }
  6132. }
  6133. }
  6134. else if (props.onClick) {
  6135. // Fast path for click listeners (which is most often) to avoid
  6136. // iterating through props.
  6137. patchProp(el, 'onClick', null, props.onClick, false, undefined, parentComponent);
  6138. }
  6139. }
  6140. // vnode / directive hooks
  6141. let vnodeHooks;
  6142. if ((vnodeHooks = props && props.onVnodeBeforeMount)) {
  6143. invokeVNodeHook(vnodeHooks, parentComponent, vnode);
  6144. }
  6145. if (dirs) {
  6146. invokeDirectiveHook(vnode, null, parentComponent, 'beforeMount');
  6147. }
  6148. if ((vnodeHooks = props && props.onVnodeMounted) || dirs) {
  6149. queueEffectWithSuspense(() => {
  6150. vnodeHooks && invokeVNodeHook(vnodeHooks, parentComponent, vnode);
  6151. dirs && invokeDirectiveHook(vnode, null, parentComponent, 'mounted');
  6152. }, parentSuspense);
  6153. }
  6154. // children
  6155. if (shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */ &&
  6156. // skip if element has innerHTML / textContent
  6157. !(props && (props.innerHTML || props.textContent))) {
  6158. let next = hydrateChildren(el.firstChild, vnode, el, parentComponent, parentSuspense, slotScopeIds, optimized);
  6159. let hasWarned = false;
  6160. while (next) {
  6161. hasMismatch = true;
  6162. if (!hasWarned) {
  6163. warn(`Hydration children mismatch in <${vnode.type}>: ` +
  6164. `server rendered element contains more child nodes than client vdom.`);
  6165. hasWarned = true;
  6166. }
  6167. // The SSRed DOM contains more nodes than it should. Remove them.
  6168. const cur = next;
  6169. next = next.nextSibling;
  6170. remove(cur);
  6171. }
  6172. }
  6173. else if (shapeFlag & 8 /* ShapeFlags.TEXT_CHILDREN */) {
  6174. if (el.textContent !== vnode.children) {
  6175. hasMismatch = true;
  6176. warn(`Hydration text content mismatch in <${vnode.type}>:\n` +
  6177. `- Client: ${el.textContent}\n` +
  6178. `- Server: ${vnode.children}`);
  6179. el.textContent = vnode.children;
  6180. }
  6181. }
  6182. }
  6183. return el.nextSibling;
  6184. };
  6185. const hydrateChildren = (node, parentVNode, container, parentComponent, parentSuspense, slotScopeIds, optimized) => {
  6186. optimized = optimized || !!parentVNode.dynamicChildren;
  6187. const children = parentVNode.children;
  6188. const l = children.length;
  6189. let hasWarned = false;
  6190. for (let i = 0; i < l; i++) {
  6191. const vnode = optimized
  6192. ? children[i]
  6193. : (children[i] = normalizeVNode(children[i]));
  6194. if (node) {
  6195. node = hydrateNode(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized);
  6196. }
  6197. else if (vnode.type === Text && !vnode.children) {
  6198. continue;
  6199. }
  6200. else {
  6201. hasMismatch = true;
  6202. if (!hasWarned) {
  6203. warn(`Hydration children mismatch in <${container.tagName.toLowerCase()}>: ` +
  6204. `server rendered element contains fewer child nodes than client vdom.`);
  6205. hasWarned = true;
  6206. }
  6207. // the SSRed DOM didn't contain enough nodes. Mount the missing ones.
  6208. patch(null, vnode, container, null, parentComponent, parentSuspense, isSVGContainer(container), slotScopeIds);
  6209. }
  6210. }
  6211. return node;
  6212. };
  6213. const hydrateFragment = (node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized) => {
  6214. const { slotScopeIds: fragmentSlotScopeIds } = vnode;
  6215. if (fragmentSlotScopeIds) {
  6216. slotScopeIds = slotScopeIds
  6217. ? slotScopeIds.concat(fragmentSlotScopeIds)
  6218. : fragmentSlotScopeIds;
  6219. }
  6220. const container = parentNode(node);
  6221. const next = hydrateChildren(nextSibling(node), vnode, container, parentComponent, parentSuspense, slotScopeIds, optimized);
  6222. if (next && isComment(next) && next.data === ']') {
  6223. return nextSibling((vnode.anchor = next));
  6224. }
  6225. else {
  6226. // fragment didn't hydrate successfully, since we didn't get a end anchor
  6227. // back. This should have led to node/children mismatch warnings.
  6228. hasMismatch = true;
  6229. // since the anchor is missing, we need to create one and insert it
  6230. insert((vnode.anchor = createComment(`]`)), container, next);
  6231. return next;
  6232. }
  6233. };
  6234. const handleMismatch = (node, vnode, parentComponent, parentSuspense, slotScopeIds, isFragment) => {
  6235. hasMismatch = true;
  6236. warn(`Hydration node mismatch:\n- Client vnode:`, vnode.type, `\n- Server rendered DOM:`, node, node.nodeType === 3 /* DOMNodeTypes.TEXT */
  6237. ? `(text)`
  6238. : isComment(node) && node.data === '['
  6239. ? `(start of fragment)`
  6240. : ``);
  6241. vnode.el = null;
  6242. if (isFragment) {
  6243. // remove excessive fragment nodes
  6244. const end = locateClosingAsyncAnchor(node);
  6245. while (true) {
  6246. const next = nextSibling(node);
  6247. if (next && next !== end) {
  6248. remove(next);
  6249. }
  6250. else {
  6251. break;
  6252. }
  6253. }
  6254. }
  6255. const next = nextSibling(node);
  6256. const container = parentNode(node);
  6257. remove(node);
  6258. patch(null, vnode, container, next, parentComponent, parentSuspense, isSVGContainer(container), slotScopeIds);
  6259. return next;
  6260. };
  6261. const locateClosingAsyncAnchor = (node) => {
  6262. let match = 0;
  6263. while (node) {
  6264. node = nextSibling(node);
  6265. if (node && isComment(node)) {
  6266. if (node.data === '[')
  6267. match++;
  6268. if (node.data === ']') {
  6269. if (match === 0) {
  6270. return nextSibling(node);
  6271. }
  6272. else {
  6273. match--;
  6274. }
  6275. }
  6276. }
  6277. }
  6278. return node;
  6279. };
  6280. return [hydrate, hydrateNode];
  6281. }
  6282. /* eslint-disable no-restricted-globals */
  6283. let supported;
  6284. let perf;
  6285. function startMeasure(instance, type) {
  6286. if (instance.appContext.config.performance && isSupported()) {
  6287. perf.mark(`vue-${type}-${instance.uid}`);
  6288. }
  6289. {
  6290. devtoolsPerfStart(instance, type, isSupported() ? perf.now() : Date.now());
  6291. }
  6292. }
  6293. function endMeasure(instance, type) {
  6294. if (instance.appContext.config.performance && isSupported()) {
  6295. const startTag = `vue-${type}-${instance.uid}`;
  6296. const endTag = startTag + `:end`;
  6297. perf.mark(endTag);
  6298. perf.measure(`<${formatComponentName(instance, instance.type)}> ${type}`, startTag, endTag);
  6299. perf.clearMarks(startTag);
  6300. perf.clearMarks(endTag);
  6301. }
  6302. {
  6303. devtoolsPerfEnd(instance, type, isSupported() ? perf.now() : Date.now());
  6304. }
  6305. }
  6306. function isSupported() {
  6307. if (supported !== undefined) {
  6308. return supported;
  6309. }
  6310. if (typeof window !== 'undefined' && window.performance) {
  6311. supported = true;
  6312. perf = window.performance;
  6313. }
  6314. else {
  6315. supported = false;
  6316. }
  6317. return supported;
  6318. }
  6319. const queuePostRenderEffect = queueEffectWithSuspense
  6320. ;
  6321. /**
  6322. * The createRenderer function accepts two generic arguments:
  6323. * HostNode and HostElement, corresponding to Node and Element types in the
  6324. * host environment. For example, for runtime-dom, HostNode would be the DOM
  6325. * `Node` interface and HostElement would be the DOM `Element` interface.
  6326. *
  6327. * Custom renderers can pass in the platform specific types like this:
  6328. *
  6329. * ``` js
  6330. * const { render, createApp } = createRenderer<Node, Element>({
  6331. * patchProp,
  6332. * ...nodeOps
  6333. * })
  6334. * ```
  6335. */
  6336. function createRenderer(options) {
  6337. return baseCreateRenderer(options);
  6338. }
  6339. // Separate API for creating hydration-enabled renderer.
  6340. // Hydration logic is only used when calling this function, making it
  6341. // tree-shakable.
  6342. function createHydrationRenderer(options) {
  6343. return baseCreateRenderer(options, createHydrationFunctions);
  6344. }
  6345. // implementation
  6346. function baseCreateRenderer(options, createHydrationFns) {
  6347. const target = shared.getGlobalThis();
  6348. target.__VUE__ = true;
  6349. {
  6350. setDevtoolsHook(target.__VUE_DEVTOOLS_GLOBAL_HOOK__, target);
  6351. }
  6352. const { insert: hostInsert, remove: hostRemove, patchProp: hostPatchProp, forcePatchProp: hostForcePatchProp, // fixed by xxxxxx
  6353. createElement: hostCreateElement, createText: hostCreateText, createComment: hostCreateComment, setText: hostSetText, setElementText: hostSetElementText, parentNode: hostParentNode, nextSibling: hostNextSibling, setScopeId: hostSetScopeId = shared.NOOP, insertStaticContent: hostInsertStaticContent } = options;
  6354. // Note: functions inside this closure should use `const xxx = () => {}`
  6355. // style in order to prevent being inlined by minifiers.
  6356. const patch = (n1, n2, container, anchor = null, parentComponent = null, parentSuspense = null, isSVG = false, slotScopeIds = null, optimized = isHmrUpdating ? false : !!n2.dynamicChildren) => {
  6357. if (n1 === n2) {
  6358. return;
  6359. }
  6360. // patching & not same type, unmount old tree
  6361. if (n1 && !isSameVNodeType(n1, n2)) {
  6362. anchor = getNextHostNode(n1);
  6363. unmount(n1, parentComponent, parentSuspense, true);
  6364. n1 = null;
  6365. }
  6366. if (n2.patchFlag === -2 /* PatchFlags.BAIL */) {
  6367. optimized = false;
  6368. n2.dynamicChildren = null;
  6369. }
  6370. const { type, ref, shapeFlag } = n2;
  6371. switch (type) {
  6372. case Text:
  6373. processText(n1, n2, container, anchor);
  6374. break;
  6375. case Comment:
  6376. processCommentNode(n1, n2, container, anchor);
  6377. break;
  6378. case Static:
  6379. if (n1 == null) {
  6380. mountStaticNode(n2, container, anchor, isSVG);
  6381. }
  6382. else {
  6383. patchStaticNode(n1, n2, container, isSVG);
  6384. }
  6385. break;
  6386. case Fragment:
  6387. processFragment(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6388. break;
  6389. default:
  6390. if (shapeFlag & 1 /* ShapeFlags.ELEMENT */) {
  6391. processElement(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6392. }
  6393. else if (shapeFlag & 6 /* ShapeFlags.COMPONENT */) {
  6394. processComponent(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6395. }
  6396. else if (shapeFlag & 64 /* ShapeFlags.TELEPORT */) {
  6397. type.process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, internals);
  6398. }
  6399. else if (shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
  6400. type.process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, internals);
  6401. }
  6402. else {
  6403. warn('Invalid VNode type:', type, `(${typeof type})`);
  6404. }
  6405. }
  6406. // set ref
  6407. if (ref != null && parentComponent) {
  6408. setRef(ref, n1 && n1.ref, parentSuspense, n2 || n1, !n2);
  6409. }
  6410. };
  6411. const processText = (n1, n2, container, anchor) => {
  6412. if (n1 == null) {
  6413. hostInsert((n2.el = hostCreateText(n2.children)), container, anchor);
  6414. }
  6415. else {
  6416. const el = (n2.el = n1.el);
  6417. if (n2.children !== n1.children) {
  6418. hostSetText(el, n2.children);
  6419. }
  6420. }
  6421. };
  6422. const processCommentNode = (n1, n2, container, anchor) => {
  6423. if (n1 == null) {
  6424. hostInsert((n2.el = hostCreateComment(n2.children || '')), container, anchor);
  6425. }
  6426. else {
  6427. // there's no support for dynamic comments
  6428. n2.el = n1.el;
  6429. }
  6430. };
  6431. const mountStaticNode = (n2, container, anchor, isSVG) => {
  6432. [n2.el, n2.anchor] = hostInsertStaticContent(n2.children, container, anchor, isSVG, n2.el, n2.anchor);
  6433. };
  6434. /**
  6435. * Dev / HMR only
  6436. */
  6437. const patchStaticNode = (n1, n2, container, isSVG) => {
  6438. // static nodes are only patched during dev for HMR
  6439. if (n2.children !== n1.children) {
  6440. const anchor = hostNextSibling(n1.anchor);
  6441. // remove existing
  6442. removeStaticNode(n1);
  6443. [n2.el, n2.anchor] = hostInsertStaticContent(n2.children, container, anchor, isSVG);
  6444. }
  6445. else {
  6446. n2.el = n1.el;
  6447. n2.anchor = n1.anchor;
  6448. }
  6449. };
  6450. const moveStaticNode = ({ el, anchor }, container, nextSibling) => {
  6451. let next;
  6452. while (el && el !== anchor) {
  6453. next = hostNextSibling(el);
  6454. hostInsert(el, container, nextSibling);
  6455. el = next;
  6456. }
  6457. hostInsert(anchor, container, nextSibling);
  6458. };
  6459. const removeStaticNode = ({ el, anchor }) => {
  6460. let next;
  6461. while (el && el !== anchor) {
  6462. next = hostNextSibling(el);
  6463. hostRemove(el);
  6464. el = next;
  6465. }
  6466. hostRemove(anchor);
  6467. };
  6468. const processElement = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6469. isSVG = isSVG || n2.type === 'svg';
  6470. if (n1 == null) {
  6471. mountElement(n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6472. }
  6473. else {
  6474. patchElement(n1, n2, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6475. }
  6476. };
  6477. const mountElement = (vnode, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6478. let el;
  6479. let vnodeHook;
  6480. const { type, props, shapeFlag, transition, dirs } = vnode;
  6481. el = vnode.el = hostCreateElement(vnode.type, isSVG, props && props.is, props);
  6482. // mount children first, since some props may rely on child content
  6483. // being already rendered, e.g. `<select value>`
  6484. if (shapeFlag & 8 /* ShapeFlags.TEXT_CHILDREN */) {
  6485. hostSetElementText(el, vnode.children);
  6486. }
  6487. else if (shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  6488. mountChildren(vnode.children, el, null, parentComponent, parentSuspense, isSVG && type !== 'foreignObject', slotScopeIds, optimized);
  6489. }
  6490. if (dirs) {
  6491. invokeDirectiveHook(vnode, null, parentComponent, 'created');
  6492. }
  6493. // scopeId
  6494. setScopeId(el, vnode, vnode.scopeId, slotScopeIds, parentComponent);
  6495. // props
  6496. if (props) {
  6497. for (const key in props) {
  6498. if (key !== 'value' && !shared.isReservedProp(key)) {
  6499. hostPatchProp(el, key, null, props[key], isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  6500. }
  6501. }
  6502. /**
  6503. * Special case for setting value on DOM elements:
  6504. * - it can be order-sensitive (e.g. should be set *after* min/max, #2325, #4024)
  6505. * - it needs to be forced (#1471)
  6506. * #2353 proposes adding another renderer option to configure this, but
  6507. * the properties affects are so finite it is worth special casing it
  6508. * here to reduce the complexity. (Special casing it also should not
  6509. * affect non-DOM renderers)
  6510. */
  6511. if ('value' in props) {
  6512. hostPatchProp(el, 'value', null, props.value);
  6513. }
  6514. if ((vnodeHook = props.onVnodeBeforeMount)) {
  6515. invokeVNodeHook(vnodeHook, parentComponent, vnode);
  6516. }
  6517. }
  6518. {
  6519. Object.defineProperty(el, '__vnode', {
  6520. value: vnode,
  6521. enumerable: false
  6522. });
  6523. }
  6524. // fixed by xxxxxx
  6525. Object.defineProperty(el, '__vueParentComponent', {
  6526. value: parentComponent,
  6527. enumerable: false
  6528. });
  6529. if (dirs) {
  6530. invokeDirectiveHook(vnode, null, parentComponent, 'beforeMount');
  6531. }
  6532. // #1583 For inside suspense + suspense not resolved case, enter hook should call when suspense resolved
  6533. // #1689 For inside suspense + suspense resolved case, just call it
  6534. const needCallTransitionHooks = (!parentSuspense || (parentSuspense && !parentSuspense.pendingBranch)) &&
  6535. transition &&
  6536. !transition.persisted;
  6537. if (needCallTransitionHooks) {
  6538. transition.beforeEnter(el);
  6539. }
  6540. hostInsert(el, container, anchor);
  6541. if ((vnodeHook = props && props.onVnodeMounted) ||
  6542. needCallTransitionHooks ||
  6543. dirs) {
  6544. queuePostRenderEffect(() => {
  6545. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, vnode);
  6546. needCallTransitionHooks && transition.enter(el);
  6547. dirs && invokeDirectiveHook(vnode, null, parentComponent, 'mounted');
  6548. }, parentSuspense);
  6549. }
  6550. };
  6551. const setScopeId = (el, vnode, scopeId, slotScopeIds, parentComponent) => {
  6552. if (scopeId) {
  6553. hostSetScopeId(el, scopeId);
  6554. }
  6555. if (slotScopeIds) {
  6556. for (let i = 0; i < slotScopeIds.length; i++) {
  6557. hostSetScopeId(el, slotScopeIds[i]);
  6558. }
  6559. }
  6560. if (parentComponent) {
  6561. let subTree = parentComponent.subTree;
  6562. if (subTree.patchFlag > 0 &&
  6563. subTree.patchFlag & 2048 /* PatchFlags.DEV_ROOT_FRAGMENT */) {
  6564. subTree =
  6565. filterSingleRoot(subTree.children) || subTree;
  6566. }
  6567. if (vnode === subTree) {
  6568. const parentVNode = parentComponent.vnode;
  6569. setScopeId(el, parentVNode, parentVNode.scopeId, parentVNode.slotScopeIds, parentComponent.parent);
  6570. }
  6571. }
  6572. };
  6573. const mountChildren = (children, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, start = 0) => {
  6574. for (let i = start; i < children.length; i++) {
  6575. const child = (children[i] = optimized
  6576. ? cloneIfMounted(children[i])
  6577. : normalizeVNode(children[i]));
  6578. patch(null, child, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6579. }
  6580. };
  6581. const patchElement = (n1, n2, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6582. const el = (n2.el = n1.el);
  6583. let { patchFlag, dynamicChildren, dirs } = n2;
  6584. // #1426 take the old vnode's patch flag into account since user may clone a
  6585. // compiler-generated vnode, which de-opts to FULL_PROPS
  6586. patchFlag |= n1.patchFlag & 16 /* PatchFlags.FULL_PROPS */;
  6587. const oldProps = n1.props || shared.EMPTY_OBJ;
  6588. const newProps = n2.props || shared.EMPTY_OBJ;
  6589. let vnodeHook;
  6590. // disable recurse in beforeUpdate hooks
  6591. parentComponent && toggleRecurse(parentComponent, false);
  6592. if ((vnodeHook = newProps.onVnodeBeforeUpdate)) {
  6593. invokeVNodeHook(vnodeHook, parentComponent, n2, n1);
  6594. }
  6595. if (dirs) {
  6596. invokeDirectiveHook(n2, n1, parentComponent, 'beforeUpdate');
  6597. }
  6598. parentComponent && toggleRecurse(parentComponent, true);
  6599. if (isHmrUpdating) {
  6600. // HMR updated, force full diff
  6601. patchFlag = 0;
  6602. optimized = false;
  6603. dynamicChildren = null;
  6604. }
  6605. const areChildrenSVG = isSVG && n2.type !== 'foreignObject';
  6606. if (dynamicChildren) {
  6607. patchBlockChildren(n1.dynamicChildren, dynamicChildren, el, parentComponent, parentSuspense, areChildrenSVG, slotScopeIds);
  6608. if (parentComponent && parentComponent.type.__hmrId) {
  6609. traverseStaticChildren(n1, n2);
  6610. }
  6611. }
  6612. else if (!optimized) {
  6613. // full diff
  6614. patchChildren(n1, n2, el, null, parentComponent, parentSuspense, areChildrenSVG, slotScopeIds, false);
  6615. }
  6616. if (patchFlag > 0) {
  6617. // the presence of a patchFlag means this element's render code was
  6618. // generated by the compiler and can take the fast path.
  6619. // in this path old node and new node are guaranteed to have the same shape
  6620. // (i.e. at the exact same position in the source template)
  6621. if (patchFlag & 16 /* PatchFlags.FULL_PROPS */) {
  6622. // element props contain dynamic keys, full diff needed
  6623. patchProps(el, n2, oldProps, newProps, parentComponent, parentSuspense, isSVG);
  6624. }
  6625. else {
  6626. // class
  6627. // this flag is matched when the element has dynamic class bindings.
  6628. if (patchFlag & 2 /* PatchFlags.CLASS */) {
  6629. if (oldProps.class !== newProps.class) {
  6630. hostPatchProp(el, 'class', null, newProps.class, isSVG);
  6631. }
  6632. }
  6633. // style
  6634. // this flag is matched when the element has dynamic style bindings
  6635. if (patchFlag & 4 /* PatchFlags.STYLE */) {
  6636. hostPatchProp(el, 'style', oldProps.style, newProps.style, isSVG);
  6637. }
  6638. // props
  6639. // This flag is matched when the element has dynamic prop/attr bindings
  6640. // other than class and style. The keys of dynamic prop/attrs are saved for
  6641. // faster iteration.
  6642. // Note dynamic keys like :[foo]="bar" will cause this optimization to
  6643. // bail out and go through a full diff because we need to unset the old key
  6644. if (patchFlag & 8 /* PatchFlags.PROPS */) {
  6645. // if the flag is present then dynamicProps must be non-null
  6646. const propsToUpdate = n2.dynamicProps;
  6647. for (let i = 0; i < propsToUpdate.length; i++) {
  6648. const key = propsToUpdate[i];
  6649. const prev = oldProps[key];
  6650. const next = newProps[key];
  6651. // #1471 force patch value
  6652. if (next !== prev ||
  6653. key === 'value' ||
  6654. (hostForcePatchProp && hostForcePatchProp(el, key)) // fixed by xxxxxx
  6655. ) {
  6656. hostPatchProp(el, key, prev, next, isSVG, n1.children, parentComponent, parentSuspense, unmountChildren);
  6657. }
  6658. }
  6659. }
  6660. }
  6661. // text
  6662. // This flag is matched when the element has only dynamic text children.
  6663. if (patchFlag & 1 /* PatchFlags.TEXT */) {
  6664. if (n1.children !== n2.children) {
  6665. hostSetElementText(el, n2.children);
  6666. }
  6667. }
  6668. }
  6669. else if (!optimized && dynamicChildren == null) {
  6670. // unoptimized, full diff
  6671. patchProps(el, n2, oldProps, newProps, parentComponent, parentSuspense, isSVG);
  6672. }
  6673. if ((vnodeHook = newProps.onVnodeUpdated) || dirs) {
  6674. queuePostRenderEffect(() => {
  6675. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, n2, n1);
  6676. dirs && invokeDirectiveHook(n2, n1, parentComponent, 'updated');
  6677. }, parentSuspense);
  6678. }
  6679. };
  6680. // The fast path for blocks.
  6681. const patchBlockChildren = (oldChildren, newChildren, fallbackContainer, parentComponent, parentSuspense, isSVG, slotScopeIds) => {
  6682. for (let i = 0; i < newChildren.length; i++) {
  6683. const oldVNode = oldChildren[i];
  6684. const newVNode = newChildren[i];
  6685. // Determine the container (parent element) for the patch.
  6686. const container =
  6687. // oldVNode may be an errored async setup() component inside Suspense
  6688. // which will not have a mounted element
  6689. oldVNode.el &&
  6690. // - In the case of a Fragment, we need to provide the actual parent
  6691. // of the Fragment itself so it can move its children.
  6692. (oldVNode.type === Fragment ||
  6693. // - In the case of different nodes, there is going to be a replacement
  6694. // which also requires the correct parent container
  6695. !isSameVNodeType(oldVNode, newVNode) ||
  6696. // - In the case of a component, it could contain anything.
  6697. oldVNode.shapeFlag & (6 /* ShapeFlags.COMPONENT */ | 64 /* ShapeFlags.TELEPORT */))
  6698. ? hostParentNode(oldVNode.el)
  6699. : // In other cases, the parent container is not actually used so we
  6700. // just pass the block element here to avoid a DOM parentNode call.
  6701. fallbackContainer;
  6702. patch(oldVNode, newVNode, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, true);
  6703. }
  6704. };
  6705. const patchProps = (el, vnode, oldProps, newProps, parentComponent, parentSuspense, isSVG) => {
  6706. if (oldProps !== newProps) {
  6707. if (oldProps !== shared.EMPTY_OBJ) {
  6708. for (const key in oldProps) {
  6709. if (!shared.isReservedProp(key) && !(key in newProps)) {
  6710. hostPatchProp(el, key, oldProps[key], null, isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  6711. }
  6712. }
  6713. }
  6714. for (const key in newProps) {
  6715. // empty string is not valid prop
  6716. if (shared.isReservedProp(key))
  6717. continue;
  6718. const next = newProps[key];
  6719. const prev = oldProps[key];
  6720. // defer patching value
  6721. if ((next !== prev && key !== 'value') ||
  6722. (hostForcePatchProp && hostForcePatchProp(el, key)) // fixed by xxxxxx
  6723. ) {
  6724. hostPatchProp(el, key, prev, next, isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  6725. }
  6726. }
  6727. if ('value' in newProps) {
  6728. hostPatchProp(el, 'value', oldProps.value, newProps.value);
  6729. }
  6730. }
  6731. };
  6732. const processFragment = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6733. const fragmentStartAnchor = (n2.el = n1 ? n1.el : hostCreateText(''));
  6734. const fragmentEndAnchor = (n2.anchor = n1 ? n1.anchor : hostCreateText(''));
  6735. let { patchFlag, dynamicChildren, slotScopeIds: fragmentSlotScopeIds } = n2;
  6736. if (// #5523 dev root fragment may inherit directives
  6737. (isHmrUpdating || patchFlag & 2048 /* PatchFlags.DEV_ROOT_FRAGMENT */)) {
  6738. // HMR updated / Dev root fragment (w/ comments), force full diff
  6739. patchFlag = 0;
  6740. optimized = false;
  6741. dynamicChildren = null;
  6742. }
  6743. // check if this is a slot fragment with :slotted scope ids
  6744. if (fragmentSlotScopeIds) {
  6745. slotScopeIds = slotScopeIds
  6746. ? slotScopeIds.concat(fragmentSlotScopeIds)
  6747. : fragmentSlotScopeIds;
  6748. }
  6749. if (n1 == null) {
  6750. hostInsert(fragmentStartAnchor, container, anchor);
  6751. hostInsert(fragmentEndAnchor, container, anchor);
  6752. // a fragment can only have array children
  6753. // since they are either generated by the compiler, or implicitly created
  6754. // from arrays.
  6755. mountChildren(
  6756. // #10007
  6757. // such fragment like `<></>` will be compiled into
  6758. // a fragment which doesn't have a children.
  6759. // In this case fallback to an empty array
  6760. (n2.children || []), container, fragmentEndAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6761. }
  6762. else {
  6763. if (patchFlag > 0 &&
  6764. patchFlag & 64 /* PatchFlags.STABLE_FRAGMENT */ &&
  6765. dynamicChildren &&
  6766. // #2715 the previous fragment could've been a BAILed one as a result
  6767. // of renderSlot() with no valid children
  6768. n1.dynamicChildren) {
  6769. // a stable fragment (template root or <template v-for>) doesn't need to
  6770. // patch children order, but it may contain dynamicChildren.
  6771. patchBlockChildren(n1.dynamicChildren, dynamicChildren, container, parentComponent, parentSuspense, isSVG, slotScopeIds);
  6772. if (parentComponent && parentComponent.type.__hmrId) {
  6773. traverseStaticChildren(n1, n2);
  6774. }
  6775. else if (
  6776. // #2080 if the stable fragment has a key, it's a <template v-for> that may
  6777. // get moved around. Make sure all root level vnodes inherit el.
  6778. // #2134 or if it's a component root, it may also get moved around
  6779. // as the component is being moved.
  6780. n2.key != null ||
  6781. (parentComponent && n2 === parentComponent.subTree)) {
  6782. traverseStaticChildren(n1, n2, true /* shallow */);
  6783. }
  6784. }
  6785. else {
  6786. // keyed / unkeyed, or manual fragments.
  6787. // for keyed & unkeyed, since they are compiler generated from v-for,
  6788. // each child is guaranteed to be a block so the fragment will never
  6789. // have dynamicChildren.
  6790. patchChildren(n1, n2, container, fragmentEndAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6791. }
  6792. }
  6793. };
  6794. const processComponent = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6795. n2.slotScopeIds = slotScopeIds;
  6796. if (n1 == null) {
  6797. if (n2.shapeFlag & 512 /* ShapeFlags.COMPONENT_KEPT_ALIVE */) {
  6798. parentComponent.ctx.activate(n2, container, anchor, isSVG, optimized);
  6799. }
  6800. else {
  6801. mountComponent(n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  6802. }
  6803. }
  6804. else {
  6805. updateComponent(n1, n2, optimized);
  6806. }
  6807. };
  6808. const mountComponent = (initialVNode, container, anchor, parentComponent, parentSuspense, isSVG, optimized) => {
  6809. const instance = (initialVNode.component = createComponentInstance(initialVNode, parentComponent, parentSuspense));
  6810. if (instance.type.__hmrId) {
  6811. registerHMR(instance);
  6812. }
  6813. {
  6814. pushWarningContext(initialVNode);
  6815. startMeasure(instance, `mount`);
  6816. }
  6817. // inject renderer internals for keepAlive
  6818. if (isKeepAlive(initialVNode)) {
  6819. instance.ctx.renderer = internals;
  6820. }
  6821. // resolve props and slots for setup context
  6822. {
  6823. {
  6824. startMeasure(instance, `init`);
  6825. }
  6826. setupComponent(instance);
  6827. {
  6828. endMeasure(instance, `init`);
  6829. }
  6830. }
  6831. // setup() is async. This component relies on async logic to be resolved
  6832. // before proceeding
  6833. if (instance.asyncDep) {
  6834. parentSuspense && parentSuspense.registerDep(instance, setupRenderEffect);
  6835. // Give it a placeholder if this is not hydration
  6836. // TODO handle self-defined fallback
  6837. if (!initialVNode.el) {
  6838. const placeholder = (instance.subTree = createVNode(Comment));
  6839. processCommentNode(null, placeholder, container, anchor);
  6840. }
  6841. return;
  6842. }
  6843. setupRenderEffect(instance, initialVNode, container, anchor, parentSuspense, isSVG, optimized);
  6844. {
  6845. popWarningContext();
  6846. endMeasure(instance, `mount`);
  6847. }
  6848. };
  6849. const updateComponent = (n1, n2, optimized) => {
  6850. const instance = (n2.component = n1.component);
  6851. if (shouldUpdateComponent(n1, n2, optimized)) {
  6852. if (instance.asyncDep &&
  6853. !instance.asyncResolved) {
  6854. // async & still pending - just update props and slots
  6855. // since the component's reactive effect for render isn't set-up yet
  6856. {
  6857. pushWarningContext(n2);
  6858. }
  6859. updateComponentPreRender(instance, n2, optimized);
  6860. {
  6861. popWarningContext();
  6862. }
  6863. return;
  6864. }
  6865. else {
  6866. // normal update
  6867. instance.next = n2;
  6868. // in case the child component is also queued, remove it to avoid
  6869. // double updating the same child component in the same flush.
  6870. invalidateJob(instance.update);
  6871. // instance.update is the reactive effect.
  6872. instance.update();
  6873. }
  6874. }
  6875. else {
  6876. // no update needed. just copy over properties
  6877. n2.el = n1.el;
  6878. instance.vnode = n2;
  6879. }
  6880. };
  6881. const setupRenderEffect = (instance, initialVNode, container, anchor, parentSuspense, isSVG, optimized) => {
  6882. const componentUpdateFn = () => {
  6883. if (!instance.isMounted) {
  6884. let vnodeHook;
  6885. const { el, props } = initialVNode;
  6886. const { bm, m, parent } = instance;
  6887. const isAsyncWrapperVNode = isAsyncWrapper(initialVNode);
  6888. toggleRecurse(instance, false);
  6889. // beforeMount hook
  6890. if (bm) {
  6891. shared.invokeArrayFns(bm);
  6892. }
  6893. // onVnodeBeforeMount
  6894. if (!isAsyncWrapperVNode &&
  6895. (vnodeHook = props && props.onVnodeBeforeMount)) {
  6896. invokeVNodeHook(vnodeHook, parent, initialVNode);
  6897. }
  6898. toggleRecurse(instance, true);
  6899. if (el && hydrateNode) {
  6900. // vnode has adopted host node - perform hydration instead of mount.
  6901. const hydrateSubTree = () => {
  6902. {
  6903. startMeasure(instance, `render`);
  6904. }
  6905. instance.subTree = renderComponentRoot(instance);
  6906. {
  6907. endMeasure(instance, `render`);
  6908. }
  6909. {
  6910. startMeasure(instance, `hydrate`);
  6911. }
  6912. hydrateNode(el, instance.subTree, instance, parentSuspense, null);
  6913. {
  6914. endMeasure(instance, `hydrate`);
  6915. }
  6916. };
  6917. if (isAsyncWrapperVNode) {
  6918. initialVNode.type.__asyncLoader().then(
  6919. // note: we are moving the render call into an async callback,
  6920. // which means it won't track dependencies - but it's ok because
  6921. // a server-rendered async wrapper is already in resolved state
  6922. // and it will never need to change.
  6923. () => !instance.isUnmounted && hydrateSubTree());
  6924. }
  6925. else {
  6926. hydrateSubTree();
  6927. }
  6928. }
  6929. else {
  6930. {
  6931. startMeasure(instance, `render`);
  6932. }
  6933. const subTree = (instance.subTree = renderComponentRoot(instance));
  6934. {
  6935. endMeasure(instance, `render`);
  6936. }
  6937. {
  6938. startMeasure(instance, `patch`);
  6939. }
  6940. patch(null, subTree, container, anchor, instance, parentSuspense, isSVG);
  6941. {
  6942. endMeasure(instance, `patch`);
  6943. }
  6944. initialVNode.el = subTree.el;
  6945. }
  6946. // mounted hook
  6947. if (m) {
  6948. queuePostRenderEffect(m, parentSuspense);
  6949. }
  6950. // onVnodeMounted
  6951. if (!isAsyncWrapperVNode &&
  6952. (vnodeHook = props && props.onVnodeMounted)) {
  6953. const scopedInitialVNode = initialVNode;
  6954. queuePostRenderEffect(() => invokeVNodeHook(vnodeHook, parent, scopedInitialVNode), parentSuspense);
  6955. }
  6956. // fixed by xxxxxx
  6957. // activated hook for keep-alive roots.
  6958. // #1742 beforeActivate/activated hook must be accessed after first render
  6959. // since the hook may be injected by a child keep-alive
  6960. const { ba, a } = instance;
  6961. if (initialVNode.shapeFlag & 256 /* ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE */ ||
  6962. (parent &&
  6963. isAsyncWrapper(parent.vnode) &&
  6964. parent.vnode.shapeFlag & 256 /* ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE */)) {
  6965. ba && invokeKeepAliveHooks(ba);
  6966. a && queuePostRenderEffect(a, parentSuspense);
  6967. // reset hook state
  6968. ba && queuePostRenderEffect(() => resetHookState(ba), parentSuspense);
  6969. }
  6970. instance.isMounted = true;
  6971. {
  6972. devtoolsComponentAdded(instance);
  6973. }
  6974. // #2458: deference mount-only object parameters to prevent memleaks
  6975. initialVNode = container = anchor = null;
  6976. }
  6977. else {
  6978. // updateComponent
  6979. // This is triggered by mutation of component's own state (next: null)
  6980. // OR parent calling processComponent (next: VNode)
  6981. let { next, bu, u, parent, vnode } = instance;
  6982. let originNext = next;
  6983. let vnodeHook;
  6984. {
  6985. pushWarningContext(next || instance.vnode);
  6986. }
  6987. // Disallow component effect recursion during pre-lifecycle hooks.
  6988. toggleRecurse(instance, false);
  6989. if (next) {
  6990. next.el = vnode.el;
  6991. updateComponentPreRender(instance, next, optimized);
  6992. }
  6993. else {
  6994. next = vnode;
  6995. }
  6996. // beforeUpdate hook
  6997. if (bu) {
  6998. shared.invokeArrayFns(bu);
  6999. }
  7000. // onVnodeBeforeUpdate
  7001. if ((vnodeHook = next.props && next.props.onVnodeBeforeUpdate)) {
  7002. invokeVNodeHook(vnodeHook, parent, next, vnode);
  7003. }
  7004. toggleRecurse(instance, true);
  7005. // render
  7006. {
  7007. startMeasure(instance, `render`);
  7008. }
  7009. const nextTree = renderComponentRoot(instance);
  7010. {
  7011. endMeasure(instance, `render`);
  7012. }
  7013. const prevTree = instance.subTree;
  7014. instance.subTree = nextTree;
  7015. {
  7016. startMeasure(instance, `patch`);
  7017. }
  7018. patch(prevTree, nextTree,
  7019. // parent may have changed if it's in a teleport
  7020. hostParentNode(prevTree.el),
  7021. // anchor may have changed if it's in a fragment
  7022. getNextHostNode(prevTree), instance, parentSuspense, isSVG);
  7023. {
  7024. endMeasure(instance, `patch`);
  7025. }
  7026. next.el = nextTree.el;
  7027. if (originNext === null) {
  7028. // self-triggered update. In case of HOC, update parent component
  7029. // vnode el. HOC is indicated by parent instance's subTree pointing
  7030. // to child component's vnode
  7031. updateHOCHostEl(instance, nextTree.el);
  7032. }
  7033. // updated hook
  7034. if (u) {
  7035. queuePostRenderEffect(u, parentSuspense);
  7036. }
  7037. // onVnodeUpdated
  7038. if ((vnodeHook = next.props && next.props.onVnodeUpdated)) {
  7039. queuePostRenderEffect(() => invokeVNodeHook(vnodeHook, parent, next, vnode), parentSuspense);
  7040. }
  7041. {
  7042. devtoolsComponentUpdated(instance);
  7043. }
  7044. {
  7045. popWarningContext();
  7046. }
  7047. }
  7048. };
  7049. // create reactive effect for rendering
  7050. const effect = (instance.effect = new ReactiveEffect(componentUpdateFn, () => queueJob(update), instance.scope // track it in component's effect scope
  7051. ));
  7052. const update = (instance.update = () => effect.run());
  7053. update.id = instance.uid;
  7054. // allowRecurse
  7055. // #1801, #2043 component render effects should allow recursive updates
  7056. toggleRecurse(instance, true);
  7057. {
  7058. effect.onTrack = instance.rtc
  7059. ? e => shared.invokeArrayFns(instance.rtc, e)
  7060. : void 0;
  7061. effect.onTrigger = instance.rtg
  7062. ? e => shared.invokeArrayFns(instance.rtg, e)
  7063. : void 0;
  7064. update.ownerInstance = instance;
  7065. }
  7066. update();
  7067. };
  7068. const updateComponentPreRender = (instance, nextVNode, optimized) => {
  7069. nextVNode.component = instance;
  7070. const prevProps = instance.vnode.props;
  7071. instance.vnode = nextVNode;
  7072. instance.next = null;
  7073. updateProps(instance, nextVNode.props, prevProps, optimized);
  7074. updateSlots(instance, nextVNode.children, optimized);
  7075. pauseTracking();
  7076. // props update may have triggered pre-flush watchers.
  7077. // flush them before the render update.
  7078. flushPreFlushCbs();
  7079. resetTracking();
  7080. };
  7081. const patchChildren = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized = false) => {
  7082. const c1 = n1 && n1.children;
  7083. const prevShapeFlag = n1 ? n1.shapeFlag : 0;
  7084. const c2 = n2.children;
  7085. const { patchFlag, shapeFlag } = n2;
  7086. // fast path
  7087. if (patchFlag > 0) {
  7088. if (patchFlag & 128 /* PatchFlags.KEYED_FRAGMENT */) {
  7089. // this could be either fully-keyed or mixed (some keyed some not)
  7090. // presence of patchFlag means children are guaranteed to be arrays
  7091. patchKeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7092. return;
  7093. }
  7094. else if (patchFlag & 256 /* PatchFlags.UNKEYED_FRAGMENT */) {
  7095. // unkeyed
  7096. patchUnkeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7097. return;
  7098. }
  7099. }
  7100. // children has 3 possibilities: text, array or no children.
  7101. if (shapeFlag & 8 /* ShapeFlags.TEXT_CHILDREN */) {
  7102. // text children fast path
  7103. if (prevShapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  7104. unmountChildren(c1, parentComponent, parentSuspense);
  7105. }
  7106. if (c2 !== c1) {
  7107. hostSetElementText(container, c2);
  7108. }
  7109. }
  7110. else {
  7111. if (prevShapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  7112. // prev children was array
  7113. if (shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  7114. // two arrays, cannot assume anything, do full diff
  7115. patchKeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7116. }
  7117. else {
  7118. // no new children, just unmount old
  7119. unmountChildren(c1, parentComponent, parentSuspense, true);
  7120. }
  7121. }
  7122. else {
  7123. // prev children was text OR null
  7124. // new children is array OR null
  7125. if (prevShapeFlag & 8 /* ShapeFlags.TEXT_CHILDREN */) {
  7126. hostSetElementText(container, '');
  7127. }
  7128. // mount new if array
  7129. if (shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  7130. mountChildren(c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7131. }
  7132. }
  7133. }
  7134. };
  7135. const patchUnkeyedChildren = (c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  7136. c1 = c1 || shared.EMPTY_ARR;
  7137. c2 = c2 || shared.EMPTY_ARR;
  7138. const oldLength = c1.length;
  7139. const newLength = c2.length;
  7140. const commonLength = Math.min(oldLength, newLength);
  7141. let i;
  7142. for (i = 0; i < commonLength; i++) {
  7143. const nextChild = (c2[i] = optimized
  7144. ? cloneIfMounted(c2[i])
  7145. : normalizeVNode(c2[i]));
  7146. patch(c1[i], nextChild, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7147. }
  7148. if (oldLength > newLength) {
  7149. // remove old
  7150. unmountChildren(c1, parentComponent, parentSuspense, true, false, commonLength);
  7151. }
  7152. else {
  7153. // mount new
  7154. mountChildren(c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, commonLength);
  7155. }
  7156. };
  7157. // can be all-keyed or mixed
  7158. const patchKeyedChildren = (c1, c2, container, parentAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  7159. let i = 0;
  7160. const l2 = c2.length;
  7161. let e1 = c1.length - 1; // prev ending index
  7162. let e2 = l2 - 1; // next ending index
  7163. // 1. sync from start
  7164. // (a b) c
  7165. // (a b) d e
  7166. while (i <= e1 && i <= e2) {
  7167. const n1 = c1[i];
  7168. const n2 = (c2[i] = optimized
  7169. ? cloneIfMounted(c2[i])
  7170. : normalizeVNode(c2[i]));
  7171. if (isSameVNodeType(n1, n2)) {
  7172. patch(n1, n2, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7173. }
  7174. else {
  7175. break;
  7176. }
  7177. i++;
  7178. }
  7179. // 2. sync from end
  7180. // a (b c)
  7181. // d e (b c)
  7182. while (i <= e1 && i <= e2) {
  7183. const n1 = c1[e1];
  7184. const n2 = (c2[e2] = optimized
  7185. ? cloneIfMounted(c2[e2])
  7186. : normalizeVNode(c2[e2]));
  7187. if (isSameVNodeType(n1, n2)) {
  7188. patch(n1, n2, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7189. }
  7190. else {
  7191. break;
  7192. }
  7193. e1--;
  7194. e2--;
  7195. }
  7196. // 3. common sequence + mount
  7197. // (a b)
  7198. // (a b) c
  7199. // i = 2, e1 = 1, e2 = 2
  7200. // (a b)
  7201. // c (a b)
  7202. // i = 0, e1 = -1, e2 = 0
  7203. if (i > e1) {
  7204. if (i <= e2) {
  7205. const nextPos = e2 + 1;
  7206. const anchor = nextPos < l2 ? c2[nextPos].el : parentAnchor;
  7207. while (i <= e2) {
  7208. patch(null, (c2[i] = optimized
  7209. ? cloneIfMounted(c2[i])
  7210. : normalizeVNode(c2[i])), container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7211. i++;
  7212. }
  7213. }
  7214. }
  7215. // 4. common sequence + unmount
  7216. // (a b) c
  7217. // (a b)
  7218. // i = 2, e1 = 2, e2 = 1
  7219. // a (b c)
  7220. // (b c)
  7221. // i = 0, e1 = 0, e2 = -1
  7222. else if (i > e2) {
  7223. while (i <= e1) {
  7224. unmount(c1[i], parentComponent, parentSuspense, true);
  7225. i++;
  7226. }
  7227. }
  7228. // 5. unknown sequence
  7229. // [i ... e1 + 1]: a b [c d e] f g
  7230. // [i ... e2 + 1]: a b [e d c h] f g
  7231. // i = 2, e1 = 4, e2 = 5
  7232. else {
  7233. const s1 = i; // prev starting index
  7234. const s2 = i; // next starting index
  7235. // 5.1 build key:index map for newChildren
  7236. const keyToNewIndexMap = new Map();
  7237. for (i = s2; i <= e2; i++) {
  7238. const nextChild = (c2[i] = optimized
  7239. ? cloneIfMounted(c2[i])
  7240. : normalizeVNode(c2[i]));
  7241. if (nextChild.key != null) {
  7242. if (keyToNewIndexMap.has(nextChild.key)) {
  7243. warn(`Duplicate keys found during update:`, JSON.stringify(nextChild.key), `Make sure keys are unique.`);
  7244. }
  7245. keyToNewIndexMap.set(nextChild.key, i);
  7246. }
  7247. }
  7248. // 5.2 loop through old children left to be patched and try to patch
  7249. // matching nodes & remove nodes that are no longer present
  7250. let j;
  7251. let patched = 0;
  7252. const toBePatched = e2 - s2 + 1;
  7253. let moved = false;
  7254. // used to track whether any node has moved
  7255. let maxNewIndexSoFar = 0;
  7256. // works as Map<newIndex, oldIndex>
  7257. // Note that oldIndex is offset by +1
  7258. // and oldIndex = 0 is a special value indicating the new node has
  7259. // no corresponding old node.
  7260. // used for determining longest stable subsequence
  7261. const newIndexToOldIndexMap = new Array(toBePatched);
  7262. for (i = 0; i < toBePatched; i++)
  7263. newIndexToOldIndexMap[i] = 0;
  7264. for (i = s1; i <= e1; i++) {
  7265. const prevChild = c1[i];
  7266. if (patched >= toBePatched) {
  7267. // all new children have been patched so this can only be a removal
  7268. unmount(prevChild, parentComponent, parentSuspense, true);
  7269. continue;
  7270. }
  7271. let newIndex;
  7272. if (prevChild.key != null) {
  7273. newIndex = keyToNewIndexMap.get(prevChild.key);
  7274. }
  7275. else {
  7276. // key-less node, try to locate a key-less node of the same type
  7277. for (j = s2; j <= e2; j++) {
  7278. if (newIndexToOldIndexMap[j - s2] === 0 &&
  7279. isSameVNodeType(prevChild, c2[j])) {
  7280. newIndex = j;
  7281. break;
  7282. }
  7283. }
  7284. }
  7285. if (newIndex === undefined) {
  7286. unmount(prevChild, parentComponent, parentSuspense, true);
  7287. }
  7288. else {
  7289. newIndexToOldIndexMap[newIndex - s2] = i + 1;
  7290. if (newIndex >= maxNewIndexSoFar) {
  7291. maxNewIndexSoFar = newIndex;
  7292. }
  7293. else {
  7294. moved = true;
  7295. }
  7296. patch(prevChild, c2[newIndex], container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7297. patched++;
  7298. }
  7299. }
  7300. // 5.3 move and mount
  7301. // generate longest stable subsequence only when nodes have moved
  7302. const increasingNewIndexSequence = moved
  7303. ? getSequence(newIndexToOldIndexMap)
  7304. : shared.EMPTY_ARR;
  7305. j = increasingNewIndexSequence.length - 1;
  7306. // looping backwards so that we can use last patched node as anchor
  7307. for (i = toBePatched - 1; i >= 0; i--) {
  7308. const nextIndex = s2 + i;
  7309. const nextChild = c2[nextIndex];
  7310. const anchor = nextIndex + 1 < l2 ? c2[nextIndex + 1].el : parentAnchor;
  7311. if (newIndexToOldIndexMap[i] === 0) {
  7312. // mount new
  7313. patch(null, nextChild, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7314. }
  7315. else if (moved) {
  7316. // move if:
  7317. // There is no stable subsequence (e.g. a reverse)
  7318. // OR current node is not among the stable sequence
  7319. if (j < 0 || i !== increasingNewIndexSequence[j]) {
  7320. move(nextChild, container, anchor, 2 /* MoveType.REORDER */);
  7321. }
  7322. else {
  7323. j--;
  7324. }
  7325. }
  7326. }
  7327. }
  7328. };
  7329. const move = (vnode, container, anchor, moveType, parentSuspense = null) => {
  7330. const { el, type, transition, children, shapeFlag } = vnode;
  7331. if (shapeFlag & 6 /* ShapeFlags.COMPONENT */) {
  7332. move(vnode.component.subTree, container, anchor, moveType);
  7333. return;
  7334. }
  7335. if (shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
  7336. vnode.suspense.move(container, anchor, moveType);
  7337. return;
  7338. }
  7339. if (shapeFlag & 64 /* ShapeFlags.TELEPORT */) {
  7340. type.move(vnode, container, anchor, internals);
  7341. return;
  7342. }
  7343. if (type === Fragment) {
  7344. hostInsert(el, container, anchor);
  7345. for (let i = 0; i < children.length; i++) {
  7346. move(children[i], container, anchor, moveType);
  7347. }
  7348. hostInsert(vnode.anchor, container, anchor);
  7349. return;
  7350. }
  7351. if (type === Static) {
  7352. moveStaticNode(vnode, container, anchor);
  7353. return;
  7354. }
  7355. // single nodes
  7356. const needTransition = moveType !== 2 /* MoveType.REORDER */ &&
  7357. shapeFlag & 1 /* ShapeFlags.ELEMENT */ &&
  7358. transition;
  7359. if (needTransition) {
  7360. if (moveType === 0 /* MoveType.ENTER */) {
  7361. transition.beforeEnter(el);
  7362. hostInsert(el, container, anchor);
  7363. queuePostRenderEffect(() => transition.enter(el), parentSuspense);
  7364. }
  7365. else {
  7366. const { leave, delayLeave, afterLeave } = transition;
  7367. const remove = () => hostInsert(el, container, anchor);
  7368. const performLeave = () => {
  7369. leave(el, () => {
  7370. remove();
  7371. afterLeave && afterLeave();
  7372. });
  7373. };
  7374. if (delayLeave) {
  7375. delayLeave(el, remove, performLeave);
  7376. }
  7377. else {
  7378. performLeave();
  7379. }
  7380. }
  7381. }
  7382. else {
  7383. hostInsert(el, container, anchor);
  7384. }
  7385. };
  7386. const unmount = (vnode, parentComponent, parentSuspense, doRemove = false, optimized = false) => {
  7387. const { type, props, ref, children, dynamicChildren, shapeFlag, patchFlag, dirs } = vnode;
  7388. // unset ref
  7389. if (ref != null) {
  7390. setRef(ref, null, parentSuspense, vnode, true);
  7391. }
  7392. if (shapeFlag & 256 /* ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE */) {
  7393. parentComponent.ctx.deactivate(vnode);
  7394. return;
  7395. }
  7396. const shouldInvokeDirs = shapeFlag & 1 /* ShapeFlags.ELEMENT */ && dirs;
  7397. const shouldInvokeVnodeHook = !isAsyncWrapper(vnode);
  7398. let vnodeHook;
  7399. if (shouldInvokeVnodeHook &&
  7400. (vnodeHook = props && props.onVnodeBeforeUnmount)) {
  7401. invokeVNodeHook(vnodeHook, parentComponent, vnode);
  7402. }
  7403. if (shapeFlag & 6 /* ShapeFlags.COMPONENT */) {
  7404. unmountComponent(vnode.component, parentSuspense, doRemove);
  7405. }
  7406. else {
  7407. if (shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
  7408. vnode.suspense.unmount(parentSuspense, doRemove);
  7409. return;
  7410. }
  7411. if (shouldInvokeDirs) {
  7412. invokeDirectiveHook(vnode, null, parentComponent, 'beforeUnmount');
  7413. }
  7414. if (shapeFlag & 64 /* ShapeFlags.TELEPORT */) {
  7415. vnode.type.remove(vnode, parentComponent, parentSuspense, optimized, internals, doRemove);
  7416. }
  7417. else if (dynamicChildren &&
  7418. // #1153: fast path should not be taken for non-stable (v-for) fragments
  7419. (type !== Fragment ||
  7420. (patchFlag > 0 && patchFlag & 64 /* PatchFlags.STABLE_FRAGMENT */))) {
  7421. // fast path for block nodes: only need to unmount dynamic children.
  7422. unmountChildren(dynamicChildren, parentComponent, parentSuspense, false, true);
  7423. }
  7424. else if ((type === Fragment &&
  7425. patchFlag &
  7426. (128 /* PatchFlags.KEYED_FRAGMENT */ | 256 /* PatchFlags.UNKEYED_FRAGMENT */)) ||
  7427. (!optimized && shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */)) {
  7428. unmountChildren(children, parentComponent, parentSuspense);
  7429. }
  7430. if (doRemove) {
  7431. remove(vnode);
  7432. }
  7433. }
  7434. if ((shouldInvokeVnodeHook &&
  7435. (vnodeHook = props && props.onVnodeUnmounted)) ||
  7436. shouldInvokeDirs) {
  7437. queuePostRenderEffect(() => {
  7438. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, vnode);
  7439. shouldInvokeDirs &&
  7440. invokeDirectiveHook(vnode, null, parentComponent, 'unmounted');
  7441. }, parentSuspense);
  7442. }
  7443. };
  7444. const remove = vnode => {
  7445. const { type, el, anchor, transition } = vnode;
  7446. if (type === Fragment) {
  7447. if (vnode.patchFlag > 0 &&
  7448. vnode.patchFlag & 2048 /* PatchFlags.DEV_ROOT_FRAGMENT */ &&
  7449. transition &&
  7450. !transition.persisted) {
  7451. vnode.children.forEach(child => {
  7452. if (child.type === Comment) {
  7453. hostRemove(child.el);
  7454. }
  7455. else {
  7456. remove(child);
  7457. }
  7458. });
  7459. }
  7460. else {
  7461. removeFragment(el, anchor);
  7462. }
  7463. return;
  7464. }
  7465. if (type === Static) {
  7466. removeStaticNode(vnode);
  7467. return;
  7468. }
  7469. const performRemove = () => {
  7470. hostRemove(el);
  7471. if (transition && !transition.persisted && transition.afterLeave) {
  7472. transition.afterLeave();
  7473. }
  7474. };
  7475. if (vnode.shapeFlag & 1 /* ShapeFlags.ELEMENT */ &&
  7476. transition &&
  7477. !transition.persisted) {
  7478. const { leave, delayLeave } = transition;
  7479. const performLeave = () => leave(el, performRemove);
  7480. if (delayLeave) {
  7481. delayLeave(vnode.el, performRemove, performLeave);
  7482. }
  7483. else {
  7484. performLeave();
  7485. }
  7486. }
  7487. else {
  7488. performRemove();
  7489. }
  7490. };
  7491. const removeFragment = (cur, end) => {
  7492. // For fragments, directly remove all contained DOM nodes.
  7493. // (fragment child nodes cannot have transition)
  7494. let next;
  7495. while (cur !== end) {
  7496. next = hostNextSibling(cur);
  7497. hostRemove(cur);
  7498. cur = next;
  7499. }
  7500. hostRemove(end);
  7501. };
  7502. const unmountComponent = (instance, parentSuspense, doRemove) => {
  7503. if (instance.type.__hmrId) {
  7504. unregisterHMR(instance);
  7505. }
  7506. const { bum, scope, update, subTree, um } = instance;
  7507. // beforeUnmount hook
  7508. if (bum) {
  7509. shared.invokeArrayFns(bum);
  7510. }
  7511. // stop effects in component scope
  7512. scope.stop();
  7513. // update may be null if a component is unmounted before its async
  7514. // setup has resolved.
  7515. if (update) {
  7516. // so that scheduler will no longer invoke it
  7517. update.active = false;
  7518. unmount(subTree, instance, parentSuspense, doRemove);
  7519. }
  7520. // unmounted hook
  7521. if (um) {
  7522. queuePostRenderEffect(um, parentSuspense);
  7523. }
  7524. queuePostRenderEffect(() => {
  7525. instance.isUnmounted = true;
  7526. }, parentSuspense);
  7527. // A component with async dep inside a pending suspense is unmounted before
  7528. // its async dep resolves. This should remove the dep from the suspense, and
  7529. // cause the suspense to resolve immediately if that was the last dep.
  7530. if (parentSuspense &&
  7531. parentSuspense.pendingBranch &&
  7532. !parentSuspense.isUnmounted &&
  7533. instance.asyncDep &&
  7534. !instance.asyncResolved &&
  7535. instance.suspenseId === parentSuspense.pendingId) {
  7536. parentSuspense.deps--;
  7537. if (parentSuspense.deps === 0) {
  7538. parentSuspense.resolve();
  7539. }
  7540. }
  7541. {
  7542. devtoolsComponentRemoved(instance);
  7543. }
  7544. };
  7545. const unmountChildren = (children, parentComponent, parentSuspense, doRemove = false, optimized = false, start = 0) => {
  7546. for (let i = start; i < children.length; i++) {
  7547. unmount(children[i], parentComponent, parentSuspense, doRemove, optimized);
  7548. }
  7549. };
  7550. const getNextHostNode = vnode => {
  7551. if (vnode.shapeFlag & 6 /* ShapeFlags.COMPONENT */) {
  7552. return getNextHostNode(vnode.component.subTree);
  7553. }
  7554. if (vnode.shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
  7555. return vnode.suspense.next();
  7556. }
  7557. return hostNextSibling((vnode.anchor || vnode.el));
  7558. };
  7559. const render = (vnode, container, isSVG) => {
  7560. if (vnode == null) {
  7561. if (container._vnode) {
  7562. unmount(container._vnode, null, null, true);
  7563. }
  7564. }
  7565. else {
  7566. patch(container._vnode || null, vnode, container, null, null, null, isSVG);
  7567. }
  7568. flushPreFlushCbs();
  7569. flushPostFlushCbs();
  7570. container._vnode = vnode;
  7571. };
  7572. const internals = {
  7573. p: patch,
  7574. um: unmount,
  7575. m: move,
  7576. r: remove,
  7577. mt: mountComponent,
  7578. mc: mountChildren,
  7579. pc: patchChildren,
  7580. pbc: patchBlockChildren,
  7581. n: getNextHostNode,
  7582. o: options
  7583. };
  7584. let hydrate;
  7585. let hydrateNode;
  7586. if (createHydrationFns) {
  7587. [hydrate, hydrateNode] = createHydrationFns(internals);
  7588. }
  7589. return {
  7590. render,
  7591. hydrate,
  7592. createApp: createAppAPI(render, hydrate)
  7593. };
  7594. }
  7595. function toggleRecurse({ effect, update }, allowed) {
  7596. effect.allowRecurse = update.allowRecurse = allowed;
  7597. }
  7598. /**
  7599. * #1156
  7600. * When a component is HMR-enabled, we need to make sure that all static nodes
  7601. * inside a block also inherit the DOM element from the previous tree so that
  7602. * HMR updates (which are full updates) can retrieve the element for patching.
  7603. *
  7604. * #2080
  7605. * Inside keyed `template` fragment static children, if a fragment is moved,
  7606. * the children will always be moved. Therefore, in order to ensure correct move
  7607. * position, el should be inherited from previous nodes.
  7608. */
  7609. function traverseStaticChildren(n1, n2, shallow = false) {
  7610. const ch1 = n1.children;
  7611. const ch2 = n2.children;
  7612. if (shared.isArray(ch1) && shared.isArray(ch2)) {
  7613. for (let i = 0; i < ch1.length; i++) {
  7614. // this is only called in the optimized path so array children are
  7615. // guaranteed to be vnodes
  7616. const c1 = ch1[i];
  7617. let c2 = ch2[i];
  7618. if (c2.shapeFlag & 1 /* ShapeFlags.ELEMENT */ && !c2.dynamicChildren) {
  7619. if (c2.patchFlag <= 0 || c2.patchFlag === 32 /* PatchFlags.HYDRATE_EVENTS */) {
  7620. c2 = ch2[i] = cloneIfMounted(ch2[i]);
  7621. c2.el = c1.el;
  7622. }
  7623. if (!shallow)
  7624. traverseStaticChildren(c1, c2);
  7625. }
  7626. // #6852 also inherit for text nodes
  7627. if (c2.type === Text) {
  7628. c2.el = c1.el;
  7629. }
  7630. // also inherit for comment nodes, but not placeholders (e.g. v-if which
  7631. // would have received .el during block patch)
  7632. if (c2.type === Comment && !c2.el) {
  7633. c2.el = c1.el;
  7634. }
  7635. }
  7636. }
  7637. }
  7638. // https://en.wikipedia.org/wiki/Longest_increasing_subsequence
  7639. function getSequence(arr) {
  7640. const p = arr.slice();
  7641. const result = [0];
  7642. let i, j, u, v, c;
  7643. const len = arr.length;
  7644. for (i = 0; i < len; i++) {
  7645. const arrI = arr[i];
  7646. if (arrI !== 0) {
  7647. j = result[result.length - 1];
  7648. if (arr[j] < arrI) {
  7649. p[i] = j;
  7650. result.push(i);
  7651. continue;
  7652. }
  7653. u = 0;
  7654. v = result.length - 1;
  7655. while (u < v) {
  7656. c = (u + v) >> 1;
  7657. if (arr[result[c]] < arrI) {
  7658. u = c + 1;
  7659. }
  7660. else {
  7661. v = c;
  7662. }
  7663. }
  7664. if (arrI < arr[result[u]]) {
  7665. if (u > 0) {
  7666. p[i] = result[u - 1];
  7667. }
  7668. result[u] = i;
  7669. }
  7670. }
  7671. }
  7672. u = result.length;
  7673. v = result[u - 1];
  7674. while (u-- > 0) {
  7675. result[u] = v;
  7676. v = p[v];
  7677. }
  7678. return result;
  7679. }
  7680. const isTeleport = (type) => type.__isTeleport;
  7681. const isTeleportDisabled = (props) => props && (props.disabled || props.disabled === '');
  7682. const isTargetSVG = (target) => typeof SVGElement !== 'undefined' && target instanceof SVGElement;
  7683. const resolveTarget = (props, select) => {
  7684. const targetSelector = props && props.to;
  7685. if (shared.isString(targetSelector)) {
  7686. if (!select) {
  7687. warn(`Current renderer does not support string target for Teleports. ` +
  7688. `(missing querySelector renderer option)`);
  7689. return null;
  7690. }
  7691. else {
  7692. const target = select(targetSelector);
  7693. if (!target) {
  7694. warn(`Failed to locate Teleport target with selector "${targetSelector}". ` +
  7695. `Note the target element must exist before the component is mounted - ` +
  7696. `i.e. the target cannot be rendered by the component itself, and ` +
  7697. `ideally should be outside of the entire Vue component tree.`);
  7698. }
  7699. return target;
  7700. }
  7701. }
  7702. else {
  7703. if (!targetSelector && !isTeleportDisabled(props)) {
  7704. warn(`Invalid Teleport target: ${targetSelector}`);
  7705. }
  7706. return targetSelector;
  7707. }
  7708. };
  7709. const TeleportImpl = {
  7710. __isTeleport: true,
  7711. process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, internals) {
  7712. const { mc: mountChildren, pc: patchChildren, pbc: patchBlockChildren, o: { insert, querySelector, createText, createComment } } = internals;
  7713. const disabled = isTeleportDisabled(n2.props);
  7714. let { shapeFlag, children, dynamicChildren } = n2;
  7715. // #3302
  7716. // HMR updated, force full diff
  7717. if (isHmrUpdating) {
  7718. optimized = false;
  7719. dynamicChildren = null;
  7720. }
  7721. if (n1 == null) {
  7722. // insert anchors in the main view
  7723. const placeholder = (n2.el = createComment('teleport start')
  7724. );
  7725. const mainAnchor = (n2.anchor = createComment('teleport end')
  7726. );
  7727. insert(placeholder, container, anchor);
  7728. insert(mainAnchor, container, anchor);
  7729. const target = (n2.target = resolveTarget(n2.props, querySelector));
  7730. const targetAnchor = (n2.targetAnchor = createText(''));
  7731. if (target) {
  7732. insert(targetAnchor, target);
  7733. // #2652 we could be teleporting from a non-SVG tree into an SVG tree
  7734. isSVG = isSVG || isTargetSVG(target);
  7735. }
  7736. else if (!disabled) {
  7737. warn('Invalid Teleport target on mount:', target, `(${typeof target})`);
  7738. }
  7739. const mount = (container, anchor) => {
  7740. // Teleport *always* has Array children. This is enforced in both the
  7741. // compiler and vnode children normalization.
  7742. if (shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  7743. mountChildren(children, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7744. }
  7745. };
  7746. if (disabled) {
  7747. mount(container, mainAnchor);
  7748. }
  7749. else if (target) {
  7750. mount(target, targetAnchor);
  7751. }
  7752. }
  7753. else {
  7754. // update content
  7755. n2.el = n1.el;
  7756. const mainAnchor = (n2.anchor = n1.anchor);
  7757. const target = (n2.target = n1.target);
  7758. const targetAnchor = (n2.targetAnchor = n1.targetAnchor);
  7759. const wasDisabled = isTeleportDisabled(n1.props);
  7760. const currentContainer = wasDisabled ? container : target;
  7761. const currentAnchor = wasDisabled ? mainAnchor : targetAnchor;
  7762. isSVG = isSVG || isTargetSVG(target);
  7763. if (dynamicChildren) {
  7764. // fast path when the teleport happens to be a block root
  7765. patchBlockChildren(n1.dynamicChildren, dynamicChildren, currentContainer, parentComponent, parentSuspense, isSVG, slotScopeIds);
  7766. // even in block tree mode we need to make sure all root-level nodes
  7767. // in the teleport inherit previous DOM references so that they can
  7768. // be moved in future patches.
  7769. traverseStaticChildren(n1, n2, true);
  7770. }
  7771. else if (!optimized) {
  7772. patchChildren(n1, n2, currentContainer, currentAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, false);
  7773. }
  7774. if (disabled) {
  7775. if (!wasDisabled) {
  7776. // enabled -> disabled
  7777. // move into main container
  7778. moveTeleport(n2, container, mainAnchor, internals, 1 /* TeleportMoveTypes.TOGGLE */);
  7779. }
  7780. }
  7781. else {
  7782. // target changed
  7783. if ((n2.props && n2.props.to) !== (n1.props && n1.props.to)) {
  7784. const nextTarget = (n2.target = resolveTarget(n2.props, querySelector));
  7785. if (nextTarget) {
  7786. moveTeleport(n2, nextTarget, null, internals, 0 /* TeleportMoveTypes.TARGET_CHANGE */);
  7787. }
  7788. else {
  7789. warn('Invalid Teleport target on update:', target, `(${typeof target})`);
  7790. }
  7791. }
  7792. else if (wasDisabled) {
  7793. // disabled -> enabled
  7794. // move into teleport target
  7795. moveTeleport(n2, target, targetAnchor, internals, 1 /* TeleportMoveTypes.TOGGLE */);
  7796. }
  7797. }
  7798. }
  7799. updateCssVars(n2);
  7800. },
  7801. remove(vnode, parentComponent, parentSuspense, optimized, { um: unmount, o: { remove: hostRemove } }, doRemove) {
  7802. const { shapeFlag, children, anchor, targetAnchor, target, props } = vnode;
  7803. if (target) {
  7804. hostRemove(targetAnchor);
  7805. }
  7806. // an unmounted teleport should always remove its children if not disabled
  7807. if (doRemove || !isTeleportDisabled(props)) {
  7808. hostRemove(anchor);
  7809. if (shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  7810. for (let i = 0; i < children.length; i++) {
  7811. const child = children[i];
  7812. unmount(child, parentComponent, parentSuspense, true, !!child.dynamicChildren);
  7813. }
  7814. }
  7815. }
  7816. },
  7817. move: moveTeleport,
  7818. hydrate: hydrateTeleport
  7819. };
  7820. function moveTeleport(vnode, container, parentAnchor, { o: { insert }, m: move }, moveType = 2 /* TeleportMoveTypes.REORDER */) {
  7821. // move target anchor if this is a target change.
  7822. if (moveType === 0 /* TeleportMoveTypes.TARGET_CHANGE */) {
  7823. insert(vnode.targetAnchor, container, parentAnchor);
  7824. }
  7825. const { el, anchor, shapeFlag, children, props } = vnode;
  7826. const isReorder = moveType === 2 /* TeleportMoveTypes.REORDER */;
  7827. // move main view anchor if this is a re-order.
  7828. if (isReorder) {
  7829. insert(el, container, parentAnchor);
  7830. }
  7831. // if this is a re-order and teleport is enabled (content is in target)
  7832. // do not move children. So the opposite is: only move children if this
  7833. // is not a reorder, or the teleport is disabled
  7834. if (!isReorder || isTeleportDisabled(props)) {
  7835. // Teleport has either Array children or no children.
  7836. if (shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  7837. for (let i = 0; i < children.length; i++) {
  7838. move(children[i], container, parentAnchor, 2 /* MoveType.REORDER */);
  7839. }
  7840. }
  7841. }
  7842. // move main view anchor if this is a re-order.
  7843. if (isReorder) {
  7844. insert(anchor, container, parentAnchor);
  7845. }
  7846. }
  7847. function hydrateTeleport(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized, { o: { nextSibling, parentNode, querySelector } }, hydrateChildren) {
  7848. const target = (vnode.target = resolveTarget(vnode.props, querySelector));
  7849. if (target) {
  7850. // if multiple teleports rendered to the same target element, we need to
  7851. // pick up from where the last teleport finished instead of the first node
  7852. const targetNode = target._lpa || target.firstChild;
  7853. if (vnode.shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  7854. if (isTeleportDisabled(vnode.props)) {
  7855. vnode.anchor = hydrateChildren(nextSibling(node), vnode, parentNode(node), parentComponent, parentSuspense, slotScopeIds, optimized);
  7856. vnode.targetAnchor = targetNode;
  7857. }
  7858. else {
  7859. vnode.anchor = nextSibling(node);
  7860. // lookahead until we find the target anchor
  7861. // we cannot rely on return value of hydrateChildren() because there
  7862. // could be nested teleports
  7863. let targetAnchor = targetNode;
  7864. while (targetAnchor) {
  7865. targetAnchor = nextSibling(targetAnchor);
  7866. if (targetAnchor &&
  7867. targetAnchor.nodeType === 8 &&
  7868. targetAnchor.data === 'teleport anchor') {
  7869. vnode.targetAnchor = targetAnchor;
  7870. target._lpa =
  7871. vnode.targetAnchor && nextSibling(vnode.targetAnchor);
  7872. break;
  7873. }
  7874. }
  7875. hydrateChildren(targetNode, vnode, target, parentComponent, parentSuspense, slotScopeIds, optimized);
  7876. }
  7877. }
  7878. updateCssVars(vnode);
  7879. }
  7880. return vnode.anchor && nextSibling(vnode.anchor);
  7881. }
  7882. // Force-casted public typing for h and TSX props inference
  7883. const Teleport = TeleportImpl;
  7884. function updateCssVars(vnode) {
  7885. // presence of .ut method indicates owner component uses css vars.
  7886. // code path here can assume browser environment.
  7887. const ctx = vnode.ctx;
  7888. if (ctx && ctx.ut) {
  7889. let node = vnode.children[0].el;
  7890. while (node !== vnode.targetAnchor) {
  7891. if (node.nodeType === 1)
  7892. node.setAttribute('data-v-owner', ctx.uid);
  7893. node = node.nextSibling;
  7894. }
  7895. ctx.ut();
  7896. }
  7897. }
  7898. const Fragment = Symbol('Fragment' );
  7899. const Text = Symbol('Text' );
  7900. const Comment = Symbol('Comment' );
  7901. const Static = Symbol('Static' );
  7902. // Since v-if and v-for are the two possible ways node structure can dynamically
  7903. // change, once we consider v-if branches and each v-for fragment a block, we
  7904. // can divide a template into nested blocks, and within each block the node
  7905. // structure would be stable. This allows us to skip most children diffing
  7906. // and only worry about the dynamic nodes (indicated by patch flags).
  7907. const blockStack = [];
  7908. let currentBlock = null;
  7909. /**
  7910. * Open a block.
  7911. * This must be called before `createBlock`. It cannot be part of `createBlock`
  7912. * because the children of the block are evaluated before `createBlock` itself
  7913. * is called. The generated code typically looks like this:
  7914. *
  7915. * ```js
  7916. * function render() {
  7917. * return (openBlock(),createBlock('div', null, [...]))
  7918. * }
  7919. * ```
  7920. * disableTracking is true when creating a v-for fragment block, since a v-for
  7921. * fragment always diffs its children.
  7922. *
  7923. * @private
  7924. */
  7925. function openBlock(disableTracking = false) {
  7926. blockStack.push((currentBlock = disableTracking ? null : []));
  7927. }
  7928. function closeBlock() {
  7929. blockStack.pop();
  7930. currentBlock = blockStack[blockStack.length - 1] || null;
  7931. }
  7932. // Whether we should be tracking dynamic child nodes inside a block.
  7933. // Only tracks when this value is > 0
  7934. // We are not using a simple boolean because this value may need to be
  7935. // incremented/decremented by nested usage of v-once (see below)
  7936. let isBlockTreeEnabled = 1;
  7937. /**
  7938. * Block tracking sometimes needs to be disabled, for example during the
  7939. * creation of a tree that needs to be cached by v-once. The compiler generates
  7940. * code like this:
  7941. *
  7942. * ``` js
  7943. * _cache[1] || (
  7944. * setBlockTracking(-1),
  7945. * _cache[1] = createVNode(...),
  7946. * setBlockTracking(1),
  7947. * _cache[1]
  7948. * )
  7949. * ```
  7950. *
  7951. * @private
  7952. */
  7953. function setBlockTracking(value) {
  7954. isBlockTreeEnabled += value;
  7955. }
  7956. function setupBlock(vnode) {
  7957. // save current block children on the block vnode
  7958. vnode.dynamicChildren =
  7959. isBlockTreeEnabled > 0 ? currentBlock || shared.EMPTY_ARR : null;
  7960. // close block
  7961. closeBlock();
  7962. // a block is always going to be patched, so track it as a child of its
  7963. // parent block
  7964. if (isBlockTreeEnabled > 0 && currentBlock) {
  7965. currentBlock.push(vnode);
  7966. }
  7967. return vnode;
  7968. }
  7969. /**
  7970. * @private
  7971. */
  7972. function createElementBlock(type, props, children, patchFlag, dynamicProps, shapeFlag) {
  7973. return setupBlock(createBaseVNode(type, props, children, patchFlag, dynamicProps, shapeFlag, true /* isBlock */));
  7974. }
  7975. /**
  7976. * Create a block root vnode. Takes the same exact arguments as `createVNode`.
  7977. * A block root keeps track of dynamic nodes within the block in the
  7978. * `dynamicChildren` array.
  7979. *
  7980. * @private
  7981. */
  7982. function createBlock(type, props, children, patchFlag, dynamicProps) {
  7983. return setupBlock(createVNode(type, props, children, patchFlag, dynamicProps, true /* isBlock: prevent a block from tracking itself */));
  7984. }
  7985. function isVNode(value) {
  7986. return value ? value.__v_isVNode === true : false;
  7987. }
  7988. function isSameVNodeType(n1, n2) {
  7989. if (n2.shapeFlag & 6 /* ShapeFlags.COMPONENT */ &&
  7990. hmrDirtyComponents.has(n2.type)) {
  7991. // #7042, ensure the vnode being unmounted during HMR
  7992. // bitwise operations to remove keep alive flags
  7993. n1.shapeFlag &= ~256 /* ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE */;
  7994. n2.shapeFlag &= ~512 /* ShapeFlags.COMPONENT_KEPT_ALIVE */;
  7995. // HMR only: if the component has been hot-updated, force a reload.
  7996. return false;
  7997. }
  7998. return n1.type === n2.type && n1.key === n2.key;
  7999. }
  8000. let vnodeArgsTransformer;
  8001. /**
  8002. * Internal API for registering an arguments transform for createVNode
  8003. * used for creating stubs in the test-utils
  8004. * It is *internal* but needs to be exposed for test-utils to pick up proper
  8005. * typings
  8006. */
  8007. function transformVNodeArgs(transformer) {
  8008. vnodeArgsTransformer = transformer;
  8009. }
  8010. const createVNodeWithArgsTransform = (...args) => {
  8011. return _createVNode(...(vnodeArgsTransformer
  8012. ? vnodeArgsTransformer(args, currentRenderingInstance)
  8013. : args));
  8014. };
  8015. const InternalObjectKey = `__vInternal`;
  8016. const normalizeKey = ({ key }) => key != null ? key : null;
  8017. const normalizeRef = ({ ref, ref_key, ref_for }) => {
  8018. return (ref != null
  8019. ? shared.isString(ref) || isRef(ref) || shared.isFunction(ref)
  8020. ? { i: currentRenderingInstance, r: ref, k: ref_key, f: !!ref_for }
  8021. : ref
  8022. : null);
  8023. };
  8024. function createBaseVNode(type, props = null, children = null, patchFlag = 0, dynamicProps = null, shapeFlag = type === Fragment ? 0 : 1 /* ShapeFlags.ELEMENT */, isBlockNode = false, needFullChildrenNormalization = false) {
  8025. const vnode = {
  8026. __v_isVNode: true,
  8027. __v_skip: true,
  8028. type,
  8029. props,
  8030. key: props && normalizeKey(props),
  8031. ref: props && normalizeRef(props),
  8032. scopeId: currentScopeId,
  8033. slotScopeIds: null,
  8034. children,
  8035. component: null,
  8036. suspense: null,
  8037. ssContent: null,
  8038. ssFallback: null,
  8039. dirs: null,
  8040. transition: null,
  8041. el: null,
  8042. anchor: null,
  8043. target: null,
  8044. targetAnchor: null,
  8045. staticCount: 0,
  8046. shapeFlag,
  8047. patchFlag,
  8048. dynamicProps,
  8049. dynamicChildren: null,
  8050. appContext: null,
  8051. ctx: currentRenderingInstance
  8052. };
  8053. if (needFullChildrenNormalization) {
  8054. normalizeChildren(vnode, children);
  8055. // normalize suspense children
  8056. if (shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
  8057. type.normalize(vnode);
  8058. }
  8059. }
  8060. else if (children) {
  8061. // compiled element vnode - if children is passed, only possible types are
  8062. // string or Array.
  8063. vnode.shapeFlag |= shared.isString(children)
  8064. ? 8 /* ShapeFlags.TEXT_CHILDREN */
  8065. : 16 /* ShapeFlags.ARRAY_CHILDREN */;
  8066. }
  8067. // validate key
  8068. if (vnode.key !== vnode.key) {
  8069. warn(`VNode created with invalid key (NaN). VNode type:`, vnode.type);
  8070. }
  8071. // track vnode for block tree
  8072. if (isBlockTreeEnabled > 0 &&
  8073. // avoid a block node from tracking itself
  8074. !isBlockNode &&
  8075. // has current parent block
  8076. currentBlock &&
  8077. // presence of a patch flag indicates this node needs patching on updates.
  8078. // component nodes also should always be patched, because even if the
  8079. // component doesn't need to update, it needs to persist the instance on to
  8080. // the next vnode so that it can be properly unmounted later.
  8081. (vnode.patchFlag > 0 || shapeFlag & 6 /* ShapeFlags.COMPONENT */) &&
  8082. // the EVENTS flag is only for hydration and if it is the only flag, the
  8083. // vnode should not be considered dynamic due to handler caching.
  8084. vnode.patchFlag !== 32 /* PatchFlags.HYDRATE_EVENTS */) {
  8085. currentBlock.push(vnode);
  8086. }
  8087. return vnode;
  8088. }
  8089. const createVNode = (createVNodeWithArgsTransform );
  8090. function _createVNode(type, props = null, children = null, patchFlag = 0, dynamicProps = null, isBlockNode = false) {
  8091. if (!type || type === NULL_DYNAMIC_COMPONENT) {
  8092. if (!type) {
  8093. warn(`Invalid vnode type when creating vnode: ${type}.`);
  8094. }
  8095. type = Comment;
  8096. }
  8097. if (isVNode(type)) {
  8098. // createVNode receiving an existing vnode. This happens in cases like
  8099. // <component :is="vnode"/>
  8100. // #2078 make sure to merge refs during the clone instead of overwriting it
  8101. const cloned = cloneVNode(type, props, true /* mergeRef: true */);
  8102. if (children) {
  8103. normalizeChildren(cloned, children);
  8104. }
  8105. if (isBlockTreeEnabled > 0 && !isBlockNode && currentBlock) {
  8106. if (cloned.shapeFlag & 6 /* ShapeFlags.COMPONENT */) {
  8107. currentBlock[currentBlock.indexOf(type)] = cloned;
  8108. }
  8109. else {
  8110. currentBlock.push(cloned);
  8111. }
  8112. }
  8113. cloned.patchFlag |= -2 /* PatchFlags.BAIL */;
  8114. return cloned;
  8115. }
  8116. // class component normalization.
  8117. if (isClassComponent(type)) {
  8118. type = type.__vccOpts;
  8119. }
  8120. // class & style normalization.
  8121. if (props) {
  8122. // for reactive or proxy objects, we need to clone it to enable mutation.
  8123. props = guardReactiveProps(props);
  8124. let { class: klass, style } = props;
  8125. if (klass && !shared.isString(klass)) {
  8126. props.class = uniShared.normalizeClass(klass);
  8127. }
  8128. if (shared.isObject(style)) {
  8129. // reactive state objects need to be cloned since they are likely to be
  8130. // mutated
  8131. if (isProxy(style) && !shared.isArray(style)) {
  8132. style = shared.extend({}, style);
  8133. }
  8134. props.style = uniShared.normalizeStyle(style);
  8135. }
  8136. }
  8137. // encode the vnode type information into a bitmap
  8138. const shapeFlag = shared.isString(type)
  8139. ? 1 /* ShapeFlags.ELEMENT */
  8140. : isSuspense(type)
  8141. ? 128 /* ShapeFlags.SUSPENSE */
  8142. : isTeleport(type)
  8143. ? 64 /* ShapeFlags.TELEPORT */
  8144. : shared.isObject(type)
  8145. ? 4 /* ShapeFlags.STATEFUL_COMPONENT */
  8146. : shared.isFunction(type)
  8147. ? 2 /* ShapeFlags.FUNCTIONAL_COMPONENT */
  8148. : 0;
  8149. if (shapeFlag & 4 /* ShapeFlags.STATEFUL_COMPONENT */ && isProxy(type)) {
  8150. type = toRaw(type);
  8151. warn(`Vue received a Component which was made a reactive object. This can ` +
  8152. `lead to unnecessary performance overhead, and should be avoided by ` +
  8153. `marking the component with \`markRaw\` or using \`shallowRef\` ` +
  8154. `instead of \`ref\`.`, `\nComponent that was made reactive: `, type);
  8155. }
  8156. return createBaseVNode(type, props, children, patchFlag, dynamicProps, shapeFlag, isBlockNode, true);
  8157. }
  8158. function guardReactiveProps(props) {
  8159. if (!props)
  8160. return null;
  8161. return isProxy(props) || InternalObjectKey in props
  8162. ? shared.extend({}, props)
  8163. : props;
  8164. }
  8165. function cloneVNode(vnode, extraProps, mergeRef = false) {
  8166. // This is intentionally NOT using spread or extend to avoid the runtime
  8167. // key enumeration cost.
  8168. const { props, ref, patchFlag, children } = vnode;
  8169. const mergedProps = extraProps ? mergeProps(props || {}, extraProps) : props;
  8170. const cloned = {
  8171. __v_isVNode: true,
  8172. __v_skip: true,
  8173. type: vnode.type,
  8174. props: mergedProps,
  8175. key: mergedProps && normalizeKey(mergedProps),
  8176. ref: extraProps && extraProps.ref
  8177. ? // #2078 in the case of <component :is="vnode" ref="extra"/>
  8178. // if the vnode itself already has a ref, cloneVNode will need to merge
  8179. // the refs so the single vnode can be set on multiple refs
  8180. mergeRef && ref
  8181. ? shared.isArray(ref)
  8182. ? ref.concat(normalizeRef(extraProps))
  8183. : [ref, normalizeRef(extraProps)]
  8184. : normalizeRef(extraProps)
  8185. : ref,
  8186. scopeId: vnode.scopeId,
  8187. slotScopeIds: vnode.slotScopeIds,
  8188. children: patchFlag === -1 /* PatchFlags.HOISTED */ && shared.isArray(children)
  8189. ? children.map(deepCloneVNode)
  8190. : children,
  8191. target: vnode.target,
  8192. targetAnchor: vnode.targetAnchor,
  8193. staticCount: vnode.staticCount,
  8194. shapeFlag: vnode.shapeFlag,
  8195. // if the vnode is cloned with extra props, we can no longer assume its
  8196. // existing patch flag to be reliable and need to add the FULL_PROPS flag.
  8197. // note: preserve flag for fragments since they use the flag for children
  8198. // fast paths only.
  8199. patchFlag: extraProps && vnode.type !== Fragment
  8200. ? patchFlag === -1 // hoisted node
  8201. ? 16 /* PatchFlags.FULL_PROPS */
  8202. : patchFlag | 16 /* PatchFlags.FULL_PROPS */
  8203. : patchFlag,
  8204. dynamicProps: vnode.dynamicProps,
  8205. dynamicChildren: vnode.dynamicChildren,
  8206. appContext: vnode.appContext,
  8207. dirs: vnode.dirs,
  8208. transition: vnode.transition,
  8209. // These should technically only be non-null on mounted VNodes. However,
  8210. // they *should* be copied for kept-alive vnodes. So we just always copy
  8211. // them since them being non-null during a mount doesn't affect the logic as
  8212. // they will simply be overwritten.
  8213. component: vnode.component,
  8214. suspense: vnode.suspense,
  8215. ssContent: vnode.ssContent && cloneVNode(vnode.ssContent),
  8216. ssFallback: vnode.ssFallback && cloneVNode(vnode.ssFallback),
  8217. el: vnode.el,
  8218. anchor: vnode.anchor,
  8219. ctx: vnode.ctx,
  8220. ce: vnode.ce
  8221. };
  8222. return cloned;
  8223. }
  8224. /**
  8225. * Dev only, for HMR of hoisted vnodes reused in v-for
  8226. * https://github.com/vitejs/vite/issues/2022
  8227. */
  8228. function deepCloneVNode(vnode) {
  8229. const cloned = cloneVNode(vnode);
  8230. if (shared.isArray(vnode.children)) {
  8231. cloned.children = vnode.children.map(deepCloneVNode);
  8232. }
  8233. return cloned;
  8234. }
  8235. /**
  8236. * @private
  8237. */
  8238. function createTextVNode(text = ' ', flag = 0) {
  8239. return createVNode(Text, null, text, flag);
  8240. }
  8241. /**
  8242. * @private
  8243. */
  8244. function createStaticVNode(content, numberOfNodes) {
  8245. // A static vnode can contain multiple stringified elements, and the number
  8246. // of elements is necessary for hydration.
  8247. const vnode = createVNode(Static, null, content);
  8248. vnode.staticCount = numberOfNodes;
  8249. return vnode;
  8250. }
  8251. /**
  8252. * @private
  8253. */
  8254. function createCommentVNode(text = '',
  8255. // when used as the v-else branch, the comment node must be created as a
  8256. // block to ensure correct updates.
  8257. asBlock = false) {
  8258. return asBlock
  8259. ? (openBlock(), createBlock(Comment, null, text))
  8260. : createVNode(Comment, null, text);
  8261. }
  8262. function normalizeVNode(child) {
  8263. if (child == null || typeof child === 'boolean') {
  8264. // empty placeholder
  8265. return createVNode(Comment);
  8266. }
  8267. else if (shared.isArray(child)) {
  8268. // fragment
  8269. return createVNode(Fragment, null,
  8270. // #3666, avoid reference pollution when reusing vnode
  8271. child.slice());
  8272. }
  8273. else if (typeof child === 'object') {
  8274. // already vnode, this should be the most common since compiled templates
  8275. // always produce all-vnode children arrays
  8276. return cloneIfMounted(child);
  8277. }
  8278. else {
  8279. // strings and numbers
  8280. return createVNode(Text, null, String(child));
  8281. }
  8282. }
  8283. // optimized normalization for template-compiled render fns
  8284. function cloneIfMounted(child) {
  8285. return (child.el === null && child.patchFlag !== -1 /* PatchFlags.HOISTED */) ||
  8286. child.memo
  8287. ? child
  8288. : cloneVNode(child);
  8289. }
  8290. function normalizeChildren(vnode, children) {
  8291. let type = 0;
  8292. const { shapeFlag } = vnode;
  8293. if (children == null) {
  8294. children = null;
  8295. }
  8296. else if (shared.isArray(children)) {
  8297. type = 16 /* ShapeFlags.ARRAY_CHILDREN */;
  8298. }
  8299. else if (typeof children === 'object') {
  8300. if (shapeFlag & (1 /* ShapeFlags.ELEMENT */ | 64 /* ShapeFlags.TELEPORT */)) {
  8301. // Normalize slot to plain children for plain element and Teleport
  8302. const slot = children.default;
  8303. if (slot) {
  8304. // _c marker is added by withCtx() indicating this is a compiled slot
  8305. slot._c && (slot._d = false);
  8306. normalizeChildren(vnode, slot());
  8307. slot._c && (slot._d = true);
  8308. }
  8309. return;
  8310. }
  8311. else {
  8312. type = 32 /* ShapeFlags.SLOTS_CHILDREN */;
  8313. const slotFlag = children._;
  8314. if (!slotFlag && !(InternalObjectKey in children)) {
  8315. children._ctx = currentRenderingInstance;
  8316. }
  8317. else if (slotFlag === 3 /* SlotFlags.FORWARDED */ && currentRenderingInstance) {
  8318. // a child component receives forwarded slots from the parent.
  8319. // its slot type is determined by its parent's slot type.
  8320. if (currentRenderingInstance.slots._ === 1 /* SlotFlags.STABLE */) {
  8321. children._ = 1 /* SlotFlags.STABLE */;
  8322. }
  8323. else {
  8324. children._ = 2 /* SlotFlags.DYNAMIC */;
  8325. vnode.patchFlag |= 1024 /* PatchFlags.DYNAMIC_SLOTS */;
  8326. }
  8327. }
  8328. }
  8329. }
  8330. else if (shared.isFunction(children)) {
  8331. children = { default: children, _ctx: currentRenderingInstance };
  8332. type = 32 /* ShapeFlags.SLOTS_CHILDREN */;
  8333. }
  8334. else {
  8335. children = String(children);
  8336. // force teleport children to array so it can be moved around
  8337. if (shapeFlag & 64 /* ShapeFlags.TELEPORT */) {
  8338. type = 16 /* ShapeFlags.ARRAY_CHILDREN */;
  8339. children = [createTextVNode(children)];
  8340. }
  8341. else {
  8342. type = 8 /* ShapeFlags.TEXT_CHILDREN */;
  8343. }
  8344. }
  8345. vnode.children = children;
  8346. vnode.shapeFlag |= type;
  8347. }
  8348. function mergeProps(...args) {
  8349. const ret = {};
  8350. for (let i = 0; i < args.length; i++) {
  8351. const toMerge = args[i];
  8352. for (const key in toMerge) {
  8353. if (key === 'class') {
  8354. if (ret.class !== toMerge.class) {
  8355. ret.class = uniShared.normalizeClass([ret.class, toMerge.class]);
  8356. }
  8357. }
  8358. else if (key === 'style') {
  8359. ret.style = uniShared.normalizeStyle([ret.style, toMerge.style]);
  8360. }
  8361. else if (shared.isOn(key)) {
  8362. const existing = ret[key];
  8363. const incoming = toMerge[key];
  8364. if (incoming &&
  8365. existing !== incoming &&
  8366. !(shared.isArray(existing) && existing.includes(incoming))) {
  8367. ret[key] = existing
  8368. ? [].concat(existing, incoming)
  8369. : incoming;
  8370. }
  8371. }
  8372. else if (key !== '') {
  8373. ret[key] = toMerge[key];
  8374. }
  8375. }
  8376. }
  8377. return ret;
  8378. }
  8379. function invokeVNodeHook(hook, instance, vnode, prevVNode = null) {
  8380. callWithAsyncErrorHandling(hook, instance, 7 /* ErrorCodes.VNODE_HOOK */, [
  8381. vnode,
  8382. prevVNode
  8383. ]);
  8384. }
  8385. const emptyAppContext = createAppContext();
  8386. let uid = 0;
  8387. function createComponentInstance(vnode, parent, suspense) {
  8388. const type = vnode.type;
  8389. // inherit parent app context - or - if root, adopt from root vnode
  8390. const appContext = (parent ? parent.appContext : vnode.appContext) || emptyAppContext;
  8391. const instance = {
  8392. uid: uid++,
  8393. vnode,
  8394. type,
  8395. parent,
  8396. appContext,
  8397. root: null,
  8398. next: null,
  8399. subTree: null,
  8400. effect: null,
  8401. update: null,
  8402. scope: new EffectScope(true /* detached */),
  8403. render: null,
  8404. proxy: null,
  8405. exposed: null,
  8406. exposeProxy: null,
  8407. withProxy: null,
  8408. provides: parent ? parent.provides : Object.create(appContext.provides),
  8409. accessCache: null,
  8410. renderCache: [],
  8411. // local resolved assets
  8412. components: null,
  8413. directives: null,
  8414. // resolved props and emits options
  8415. propsOptions: normalizePropsOptions(type, appContext),
  8416. emitsOptions: normalizeEmitsOptions(type, appContext),
  8417. // emit
  8418. emit: null,
  8419. emitted: null,
  8420. // props default value
  8421. propsDefaults: shared.EMPTY_OBJ,
  8422. // inheritAttrs
  8423. inheritAttrs: type.inheritAttrs,
  8424. // state
  8425. ctx: shared.EMPTY_OBJ,
  8426. data: shared.EMPTY_OBJ,
  8427. props: shared.EMPTY_OBJ,
  8428. attrs: shared.EMPTY_OBJ,
  8429. slots: shared.EMPTY_OBJ,
  8430. refs: shared.EMPTY_OBJ,
  8431. setupState: shared.EMPTY_OBJ,
  8432. setupContext: null,
  8433. // suspense related
  8434. suspense,
  8435. suspenseId: suspense ? suspense.pendingId : 0,
  8436. asyncDep: null,
  8437. asyncResolved: false,
  8438. // lifecycle hooks
  8439. // not using enums here because it results in computed properties
  8440. isMounted: false,
  8441. isUnmounted: false,
  8442. isDeactivated: false,
  8443. bc: null,
  8444. c: null,
  8445. bm: null,
  8446. m: null,
  8447. bu: null,
  8448. u: null,
  8449. um: null,
  8450. bum: null,
  8451. bda: null,
  8452. da: null,
  8453. ba: null,
  8454. a: null,
  8455. rtg: null,
  8456. rtc: null,
  8457. ec: null,
  8458. sp: null
  8459. };
  8460. {
  8461. instance.ctx = createDevRenderContext(instance);
  8462. }
  8463. instance.root = parent ? parent.root : instance;
  8464. instance.emit = emit.bind(null, instance);
  8465. instance.$pageInstance = parent && parent.$pageInstance;
  8466. // apply custom element special handling
  8467. if (vnode.ce) {
  8468. vnode.ce(instance);
  8469. }
  8470. return instance;
  8471. }
  8472. let currentInstance = null;
  8473. const getCurrentInstance = () => currentInstance || currentRenderingInstance;
  8474. const setCurrentInstance = (instance) => {
  8475. currentInstance = instance;
  8476. instance.scope.on();
  8477. };
  8478. const unsetCurrentInstance = () => {
  8479. currentInstance && currentInstance.scope.off();
  8480. currentInstance = null;
  8481. };
  8482. const isBuiltInTag = /*#__PURE__*/ shared.makeMap('slot,component');
  8483. function validateComponentName(name, config) {
  8484. const appIsNativeTag = config.isNativeTag || shared.NO;
  8485. if (isBuiltInTag(name) || appIsNativeTag(name)) {
  8486. warn('Do not use built-in or reserved HTML elements as component id: ' + name);
  8487. }
  8488. }
  8489. function isStatefulComponent(instance) {
  8490. return instance.vnode.shapeFlag & 4 /* ShapeFlags.STATEFUL_COMPONENT */;
  8491. }
  8492. exports.isInSSRComponentSetup = false;
  8493. function setupComponent(instance, isSSR = false) {
  8494. exports.isInSSRComponentSetup = isSSR;
  8495. const { props, children } = instance.vnode;
  8496. const isStateful = isStatefulComponent(instance);
  8497. initProps(instance, props, isStateful, isSSR);
  8498. initSlots(instance, children);
  8499. const setupResult = isStateful
  8500. ? setupStatefulComponent(instance, isSSR)
  8501. : undefined;
  8502. exports.isInSSRComponentSetup = false;
  8503. return setupResult;
  8504. }
  8505. function setupStatefulComponent(instance, isSSR) {
  8506. var _a;
  8507. const Component = instance.type;
  8508. {
  8509. if (Component.name) {
  8510. validateComponentName(Component.name, instance.appContext.config);
  8511. }
  8512. if (Component.components) {
  8513. const names = Object.keys(Component.components);
  8514. for (let i = 0; i < names.length; i++) {
  8515. validateComponentName(names[i], instance.appContext.config);
  8516. }
  8517. }
  8518. if (Component.directives) {
  8519. const names = Object.keys(Component.directives);
  8520. for (let i = 0; i < names.length; i++) {
  8521. validateDirectiveName(names[i]);
  8522. }
  8523. }
  8524. if (Component.compilerOptions && isRuntimeOnly()) {
  8525. warn(`"compilerOptions" is only supported when using a build of Vue that ` +
  8526. `includes the runtime compiler. Since you are using a runtime-only ` +
  8527. `build, the options should be passed via your build tool config instead.`);
  8528. }
  8529. }
  8530. // 0. create render proxy property access cache
  8531. instance.accessCache = Object.create(null);
  8532. // 1. create public instance / render proxy
  8533. // also mark it raw so it's never observed
  8534. instance.proxy = markRaw(new Proxy(instance.ctx, PublicInstanceProxyHandlers));
  8535. {
  8536. exposePropsOnRenderContext(instance);
  8537. }
  8538. // 2. call setup()
  8539. const { setup } = Component;
  8540. if (setup) {
  8541. const setupContext = (instance.setupContext =
  8542. setup.length > 1 ? createSetupContext(instance) : null);
  8543. setCurrentInstance(instance);
  8544. pauseTracking();
  8545. const setupResult = callWithErrorHandling(setup, instance, 0 /* ErrorCodes.SETUP_FUNCTION */, [shallowReadonly(instance.props) , setupContext]);
  8546. resetTracking();
  8547. unsetCurrentInstance();
  8548. if (shared.isPromise(setupResult)) {
  8549. setupResult.then(unsetCurrentInstance, unsetCurrentInstance);
  8550. if (isSSR) {
  8551. // return the promise so server-renderer can wait on it
  8552. return setupResult
  8553. .then((resolvedResult) => {
  8554. handleSetupResult(instance, resolvedResult, isSSR);
  8555. })
  8556. .catch(e => {
  8557. handleError(e, instance, 0 /* ErrorCodes.SETUP_FUNCTION */);
  8558. });
  8559. }
  8560. else {
  8561. // async setup returned Promise.
  8562. // bail here and wait for re-entry.
  8563. instance.asyncDep = setupResult;
  8564. if (!instance.suspense) {
  8565. const name = (_a = Component.name) !== null && _a !== void 0 ? _a : 'Anonymous';
  8566. warn(`Component <${name}>: setup function returned a promise, but no ` +
  8567. `<Suspense> boundary was found in the parent component tree. ` +
  8568. `A component with async setup() must be nested in a <Suspense> ` +
  8569. `in order to be rendered.`);
  8570. }
  8571. }
  8572. }
  8573. else {
  8574. handleSetupResult(instance, setupResult, isSSR);
  8575. }
  8576. }
  8577. else {
  8578. finishComponentSetup(instance, isSSR);
  8579. }
  8580. }
  8581. function handleSetupResult(instance, setupResult, isSSR) {
  8582. if (shared.isFunction(setupResult)) {
  8583. // setup returned an inline render function
  8584. if (instance.type.__ssrInlineRender) {
  8585. // when the function's name is `ssrRender` (compiled by SFC inline mode),
  8586. // set it as ssrRender instead.
  8587. instance.ssrRender = setupResult;
  8588. }
  8589. else {
  8590. instance.render = setupResult;
  8591. }
  8592. }
  8593. else if (shared.isObject(setupResult)) {
  8594. if (isVNode(setupResult)) {
  8595. warn(`setup() should not return VNodes directly - ` +
  8596. `return a render function instead.`);
  8597. }
  8598. // setup returned bindings.
  8599. // assuming a render function compiled from template is present.
  8600. {
  8601. instance.devtoolsRawSetupState = setupResult;
  8602. }
  8603. instance.setupState = proxyRefs(setupResult);
  8604. {
  8605. exposeSetupStateOnRenderContext(instance);
  8606. }
  8607. }
  8608. else if (setupResult !== undefined) {
  8609. warn(`setup() should return an object. Received: ${setupResult === null ? 'null' : typeof setupResult}`);
  8610. }
  8611. finishComponentSetup(instance, isSSR);
  8612. }
  8613. let compile$1;
  8614. let installWithProxy;
  8615. /**
  8616. * For runtime-dom to register the compiler.
  8617. * Note the exported method uses any to avoid d.ts relying on the compiler types.
  8618. */
  8619. function registerRuntimeCompiler(_compile) {
  8620. compile$1 = _compile;
  8621. installWithProxy = i => {
  8622. if (i.render._rc) {
  8623. i.withProxy = new Proxy(i.ctx, RuntimeCompiledPublicInstanceProxyHandlers);
  8624. }
  8625. };
  8626. }
  8627. // dev only
  8628. const isRuntimeOnly = () => !compile$1;
  8629. function finishComponentSetup(instance, isSSR, skipOptions) {
  8630. const Component = instance.type;
  8631. // template / render function normalization
  8632. // could be already set when returned from setup()
  8633. if (!instance.render) {
  8634. // only do on-the-fly compile if not in SSR - SSR on-the-fly compilation
  8635. // is done by server-renderer
  8636. if (!isSSR && compile$1 && !Component.render) {
  8637. const template = Component.template ||
  8638. resolveMergedOptions(instance).template;
  8639. if (template) {
  8640. {
  8641. startMeasure(instance, `compile`);
  8642. }
  8643. const { isCustomElement, compilerOptions } = instance.appContext.config;
  8644. const { delimiters, compilerOptions: componentCompilerOptions } = Component;
  8645. const finalCompilerOptions = shared.extend(shared.extend({
  8646. isCustomElement,
  8647. delimiters
  8648. }, compilerOptions), componentCompilerOptions);
  8649. Component.render = compile$1(template, finalCompilerOptions);
  8650. {
  8651. endMeasure(instance, `compile`);
  8652. }
  8653. }
  8654. }
  8655. instance.render = (Component.render || shared.NOOP);
  8656. // for runtime-compiled render functions using `with` blocks, the render
  8657. // proxy used needs a different `has` handler which is more performant and
  8658. // also only allows a whitelist of globals to fallthrough.
  8659. if (installWithProxy) {
  8660. installWithProxy(instance);
  8661. }
  8662. }
  8663. // support for 2.x options
  8664. {
  8665. setCurrentInstance(instance);
  8666. pauseTracking();
  8667. applyOptions(instance);
  8668. resetTracking();
  8669. unsetCurrentInstance();
  8670. }
  8671. // warn missing template/render
  8672. // the runtime compilation of template in SSR is done by server-render
  8673. if (!Component.render && instance.render === shared.NOOP && !isSSR) {
  8674. /* istanbul ignore if */
  8675. if (!compile$1 && Component.template) {
  8676. warn(`Component provided template option but ` +
  8677. `runtime compilation is not supported in this build of Vue.` +
  8678. (``) /* should not happen */);
  8679. }
  8680. else {
  8681. warn(`Component is missing template or render function.`);
  8682. }
  8683. }
  8684. }
  8685. function createAttrsProxy(instance) {
  8686. return new Proxy(instance.attrs, {
  8687. get(target, key) {
  8688. markAttrsAccessed();
  8689. track(instance, "get" /* TrackOpTypes.GET */, '$attrs');
  8690. return target[key];
  8691. },
  8692. set() {
  8693. warn(`setupContext.attrs is readonly.`);
  8694. return false;
  8695. },
  8696. deleteProperty() {
  8697. warn(`setupContext.attrs is readonly.`);
  8698. return false;
  8699. }
  8700. }
  8701. );
  8702. }
  8703. function createSetupContext(instance) {
  8704. const expose = exposed => {
  8705. {
  8706. if (instance.exposed) {
  8707. warn(`expose() should be called only once per setup().`);
  8708. }
  8709. if (exposed != null) {
  8710. let exposedType = typeof exposed;
  8711. if (exposedType === 'object') {
  8712. if (shared.isArray(exposed)) {
  8713. exposedType = 'array';
  8714. }
  8715. else if (isRef(exposed)) {
  8716. exposedType = 'ref';
  8717. }
  8718. }
  8719. if (exposedType !== 'object') {
  8720. warn(`expose() should be passed a plain object, received ${exposedType}.`);
  8721. }
  8722. }
  8723. }
  8724. instance.exposed = exposed || {};
  8725. };
  8726. let attrs;
  8727. {
  8728. // We use getters in dev in case libs like test-utils overwrite instance
  8729. // properties (overwrites should not be done in prod)
  8730. return Object.freeze({
  8731. get attrs() {
  8732. return attrs || (attrs = createAttrsProxy(instance));
  8733. },
  8734. get slots() {
  8735. return shallowReadonly(instance.slots);
  8736. },
  8737. get emit() {
  8738. return (event, ...args) => instance.emit(event, ...args);
  8739. },
  8740. expose
  8741. });
  8742. }
  8743. }
  8744. function getExposeProxy(instance) {
  8745. if (instance.exposed) {
  8746. return (instance.exposeProxy ||
  8747. (instance.exposeProxy = new Proxy(proxyRefs(markRaw(instance.exposed)), {
  8748. get(target, key) {
  8749. if (key in target) {
  8750. return target[key];
  8751. }
  8752. else if (key in publicPropertiesMap) {
  8753. return publicPropertiesMap[key](instance);
  8754. }
  8755. },
  8756. has(target, key) {
  8757. return key in target || key in publicPropertiesMap;
  8758. }
  8759. })));
  8760. }
  8761. }
  8762. const classifyRE = /(?:^|[-_])(\w)/g;
  8763. const classify = (str) => str.replace(classifyRE, c => c.toUpperCase()).replace(/[-_]/g, '');
  8764. function getComponentName(Component, includeInferred = true) {
  8765. return shared.isFunction(Component)
  8766. ? Component.displayName || Component.name
  8767. : Component.name || (includeInferred && Component.__name);
  8768. }
  8769. /* istanbul ignore next */
  8770. function formatComponentName(instance, Component, isRoot = false) {
  8771. let name = getComponentName(Component);
  8772. if (!name && Component.__file) {
  8773. const match = Component.__file.match(/([^/\\]+)\.\w+$/);
  8774. if (match) {
  8775. name = match[1];
  8776. }
  8777. }
  8778. if (!name && instance && instance.parent) {
  8779. // try to infer the name based on reverse resolution
  8780. const inferFromRegistry = (registry) => {
  8781. for (const key in registry) {
  8782. if (registry[key] === Component) {
  8783. return key;
  8784. }
  8785. }
  8786. };
  8787. name =
  8788. inferFromRegistry(instance.components ||
  8789. instance.parent.type.components) || inferFromRegistry(instance.appContext.components);
  8790. }
  8791. return name ? classify(name) : isRoot ? `App` : `Anonymous`;
  8792. }
  8793. function isClassComponent(value) {
  8794. return shared.isFunction(value) && '__vccOpts' in value;
  8795. }
  8796. const computed = ((getterOrOptions, debugOptions) => {
  8797. // @ts-ignore
  8798. return computed$1(getterOrOptions, debugOptions, exports.isInSSRComponentSetup);
  8799. });
  8800. // dev only
  8801. const warnRuntimeUsage = (method) => warn(`${method}() is a compiler-hint helper that is only usable inside ` +
  8802. `<script setup> of a single file component. Its arguments should be ` +
  8803. `compiled away and passing it at runtime has no effect.`);
  8804. // implementation
  8805. function defineProps() {
  8806. {
  8807. warnRuntimeUsage(`defineProps`);
  8808. }
  8809. return null;
  8810. }
  8811. // implementation
  8812. function defineEmits() {
  8813. {
  8814. warnRuntimeUsage(`defineEmits`);
  8815. }
  8816. return null;
  8817. }
  8818. /**
  8819. * Vue `<script setup>` compiler macro for declaring a component's exposed
  8820. * instance properties when it is accessed by a parent component via template
  8821. * refs.
  8822. *
  8823. * `<script setup>` components are closed by default - i.e. variables inside
  8824. * the `<script setup>` scope is not exposed to parent unless explicitly exposed
  8825. * via `defineExpose`.
  8826. *
  8827. * This is only usable inside `<script setup>`, is compiled away in the
  8828. * output and should **not** be actually called at runtime.
  8829. */
  8830. function defineExpose(exposed) {
  8831. {
  8832. warnRuntimeUsage(`defineExpose`);
  8833. }
  8834. }
  8835. /**
  8836. * Vue `<script setup>` compiler macro for providing props default values when
  8837. * using type-based `defineProps` declaration.
  8838. *
  8839. * Example usage:
  8840. * ```ts
  8841. * withDefaults(defineProps<{
  8842. * size?: number
  8843. * labels?: string[]
  8844. * }>(), {
  8845. * size: 3,
  8846. * labels: () => ['default label']
  8847. * })
  8848. * ```
  8849. *
  8850. * This is only usable inside `<script setup>`, is compiled away in the output
  8851. * and should **not** be actually called at runtime.
  8852. */
  8853. function withDefaults(props, defaults) {
  8854. {
  8855. warnRuntimeUsage(`withDefaults`);
  8856. }
  8857. return null;
  8858. }
  8859. function useSlots() {
  8860. return getContext().slots;
  8861. }
  8862. function useAttrs() {
  8863. return getContext().attrs;
  8864. }
  8865. function getContext() {
  8866. const i = getCurrentInstance();
  8867. if (!i) {
  8868. warn(`useContext() called without active instance.`);
  8869. }
  8870. return i.setupContext || (i.setupContext = createSetupContext(i));
  8871. }
  8872. /**
  8873. * Runtime helper for merging default declarations. Imported by compiled code
  8874. * only.
  8875. * @internal
  8876. */
  8877. function mergeDefaults(raw, defaults) {
  8878. const props = shared.isArray(raw)
  8879. ? raw.reduce((normalized, p) => ((normalized[p] = {}), normalized), {})
  8880. : raw;
  8881. for (const key in defaults) {
  8882. const opt = props[key];
  8883. if (opt) {
  8884. if (shared.isArray(opt) || shared.isFunction(opt)) {
  8885. props[key] = { type: opt, default: defaults[key] };
  8886. }
  8887. else {
  8888. opt.default = defaults[key];
  8889. }
  8890. }
  8891. else if (opt === null) {
  8892. props[key] = { default: defaults[key] };
  8893. }
  8894. else {
  8895. warn(`props default key "${key}" has no corresponding declaration.`);
  8896. }
  8897. }
  8898. return props;
  8899. }
  8900. /**
  8901. * Used to create a proxy for the rest element when destructuring props with
  8902. * defineProps().
  8903. * @internal
  8904. */
  8905. function createPropsRestProxy(props, excludedKeys) {
  8906. const ret = {};
  8907. for (const key in props) {
  8908. if (!excludedKeys.includes(key)) {
  8909. Object.defineProperty(ret, key, {
  8910. enumerable: true,
  8911. get: () => props[key]
  8912. });
  8913. }
  8914. }
  8915. return ret;
  8916. }
  8917. /**
  8918. * `<script setup>` helper for persisting the current instance context over
  8919. * async/await flows.
  8920. *
  8921. * `@vue/compiler-sfc` converts the following:
  8922. *
  8923. * ```ts
  8924. * const x = await foo()
  8925. * ```
  8926. *
  8927. * into:
  8928. *
  8929. * ```ts
  8930. * let __temp, __restore
  8931. * const x = (([__temp, __restore] = withAsyncContext(() => foo())),__temp=await __temp,__restore(),__temp)
  8932. * ```
  8933. * @internal
  8934. */
  8935. function withAsyncContext(getAwaitable) {
  8936. const ctx = getCurrentInstance();
  8937. if (!ctx) {
  8938. warn(`withAsyncContext called without active current instance. ` +
  8939. `This is likely a bug.`);
  8940. }
  8941. let awaitable = getAwaitable();
  8942. unsetCurrentInstance();
  8943. if (shared.isPromise(awaitable)) {
  8944. awaitable = awaitable.catch(e => {
  8945. setCurrentInstance(ctx);
  8946. throw e;
  8947. });
  8948. }
  8949. return [awaitable, () => setCurrentInstance(ctx)];
  8950. }
  8951. // Actual implementation
  8952. function h(type, propsOrChildren, children) {
  8953. const l = arguments.length;
  8954. if (l === 2) {
  8955. if (shared.isObject(propsOrChildren) && !shared.isArray(propsOrChildren)) {
  8956. // single vnode without props
  8957. if (isVNode(propsOrChildren)) {
  8958. return createVNode(type, null, [propsOrChildren]);
  8959. }
  8960. // props without children
  8961. return createVNode(type, propsOrChildren);
  8962. }
  8963. else {
  8964. // omit props
  8965. return createVNode(type, null, propsOrChildren);
  8966. }
  8967. }
  8968. else {
  8969. if (l > 3) {
  8970. children = Array.prototype.slice.call(arguments, 2);
  8971. }
  8972. else if (l === 3 && isVNode(children)) {
  8973. children = [children];
  8974. }
  8975. return createVNode(type, propsOrChildren, children);
  8976. }
  8977. }
  8978. const ssrContextKey = Symbol(`ssrContext` );
  8979. const useSSRContext = () => {
  8980. {
  8981. const ctx = inject(ssrContextKey);
  8982. if (!ctx) {
  8983. warn(`Server rendering context not provided. Make sure to only call ` +
  8984. `useSSRContext() conditionally in the server build.`);
  8985. }
  8986. return ctx;
  8987. }
  8988. };
  8989. function initCustomFormatter() {
  8990. /* eslint-disable no-restricted-globals */
  8991. if (typeof window === 'undefined') {
  8992. return;
  8993. }
  8994. const vueStyle = { style: 'color:#3ba776' };
  8995. const numberStyle = { style: 'color:#0b1bc9' };
  8996. const stringStyle = { style: 'color:#b62e24' };
  8997. const keywordStyle = { style: 'color:#9d288c' };
  8998. // custom formatter for Chrome
  8999. // https://www.mattzeunert.com/2016/02/19/custom-chrome-devtools-object-formatters.html
  9000. const formatter = {
  9001. header(obj) {
  9002. // TODO also format ComponentPublicInstance & ctx.slots/attrs in setup
  9003. if (!shared.isObject(obj)) {
  9004. return null;
  9005. }
  9006. if (obj.__isVue) {
  9007. return ['div', vueStyle, `VueInstance`];
  9008. }
  9009. else if (isRef(obj)) {
  9010. return [
  9011. 'div',
  9012. {},
  9013. ['span', vueStyle, genRefFlag(obj)],
  9014. '<',
  9015. formatValue(obj.value),
  9016. `>`
  9017. ];
  9018. }
  9019. else if (isReactive(obj)) {
  9020. return [
  9021. 'div',
  9022. {},
  9023. ['span', vueStyle, isShallow(obj) ? 'ShallowReactive' : 'Reactive'],
  9024. '<',
  9025. formatValue(obj),
  9026. `>${isReadonly(obj) ? ` (readonly)` : ``}`
  9027. ];
  9028. }
  9029. else if (isReadonly(obj)) {
  9030. return [
  9031. 'div',
  9032. {},
  9033. ['span', vueStyle, isShallow(obj) ? 'ShallowReadonly' : 'Readonly'],
  9034. '<',
  9035. formatValue(obj),
  9036. '>'
  9037. ];
  9038. }
  9039. return null;
  9040. },
  9041. hasBody(obj) {
  9042. return obj && obj.__isVue;
  9043. },
  9044. body(obj) {
  9045. if (obj && obj.__isVue) {
  9046. return [
  9047. 'div',
  9048. {},
  9049. ...formatInstance(obj.$)
  9050. ];
  9051. }
  9052. }
  9053. };
  9054. function formatInstance(instance) {
  9055. const blocks = [];
  9056. if (instance.type.props && instance.props) {
  9057. blocks.push(createInstanceBlock('props', toRaw(instance.props)));
  9058. }
  9059. if (instance.setupState !== shared.EMPTY_OBJ) {
  9060. blocks.push(createInstanceBlock('setup', instance.setupState));
  9061. }
  9062. if (instance.data !== shared.EMPTY_OBJ) {
  9063. blocks.push(createInstanceBlock('data', toRaw(instance.data)));
  9064. }
  9065. const computed = extractKeys(instance, 'computed');
  9066. if (computed) {
  9067. blocks.push(createInstanceBlock('computed', computed));
  9068. }
  9069. const injected = extractKeys(instance, 'inject');
  9070. if (injected) {
  9071. blocks.push(createInstanceBlock('injected', injected));
  9072. }
  9073. blocks.push([
  9074. 'div',
  9075. {},
  9076. [
  9077. 'span',
  9078. {
  9079. style: keywordStyle.style + ';opacity:0.66'
  9080. },
  9081. '$ (internal): '
  9082. ],
  9083. ['object', { object: instance }]
  9084. ]);
  9085. return blocks;
  9086. }
  9087. function createInstanceBlock(type, target) {
  9088. target = shared.extend({}, target);
  9089. if (!Object.keys(target).length) {
  9090. return ['span', {}];
  9091. }
  9092. return [
  9093. 'div',
  9094. { style: 'line-height:1.25em;margin-bottom:0.6em' },
  9095. [
  9096. 'div',
  9097. {
  9098. style: 'color:#476582'
  9099. },
  9100. type
  9101. ],
  9102. [
  9103. 'div',
  9104. {
  9105. style: 'padding-left:1.25em'
  9106. },
  9107. ...Object.keys(target).map(key => {
  9108. return [
  9109. 'div',
  9110. {},
  9111. ['span', keywordStyle, key + ': '],
  9112. formatValue(target[key], false)
  9113. ];
  9114. })
  9115. ]
  9116. ];
  9117. }
  9118. function formatValue(v, asRaw = true) {
  9119. if (typeof v === 'number') {
  9120. return ['span', numberStyle, v];
  9121. }
  9122. else if (typeof v === 'string') {
  9123. return ['span', stringStyle, JSON.stringify(v)];
  9124. }
  9125. else if (typeof v === 'boolean') {
  9126. return ['span', keywordStyle, v];
  9127. }
  9128. else if (shared.isObject(v)) {
  9129. return ['object', { object: asRaw ? toRaw(v) : v }];
  9130. }
  9131. else {
  9132. return ['span', stringStyle, String(v)];
  9133. }
  9134. }
  9135. function extractKeys(instance, type) {
  9136. const Comp = instance.type;
  9137. if (shared.isFunction(Comp)) {
  9138. return;
  9139. }
  9140. const extracted = {};
  9141. for (const key in instance.ctx) {
  9142. if (isKeyOfType(Comp, key, type)) {
  9143. extracted[key] = instance.ctx[key];
  9144. }
  9145. }
  9146. return extracted;
  9147. }
  9148. function isKeyOfType(Comp, key, type) {
  9149. const opts = Comp[type];
  9150. if ((shared.isArray(opts) && opts.includes(key)) ||
  9151. (shared.isObject(opts) && key in opts)) {
  9152. return true;
  9153. }
  9154. if (Comp.extends && isKeyOfType(Comp.extends, key, type)) {
  9155. return true;
  9156. }
  9157. if (Comp.mixins && Comp.mixins.some(m => isKeyOfType(m, key, type))) {
  9158. return true;
  9159. }
  9160. }
  9161. function genRefFlag(v) {
  9162. if (isShallow(v)) {
  9163. return `ShallowRef`;
  9164. }
  9165. if (v.effect) {
  9166. return `ComputedRef`;
  9167. }
  9168. return `Ref`;
  9169. }
  9170. if (window.devtoolsFormatters) {
  9171. window.devtoolsFormatters.push(formatter);
  9172. }
  9173. else {
  9174. window.devtoolsFormatters = [formatter];
  9175. }
  9176. }
  9177. function withMemo(memo, render, cache, index) {
  9178. const cached = cache[index];
  9179. if (cached && isMemoSame(cached, memo)) {
  9180. return cached;
  9181. }
  9182. const ret = render();
  9183. // shallow clone
  9184. ret.memo = memo.slice();
  9185. return (cache[index] = ret);
  9186. }
  9187. function isMemoSame(cached, memo) {
  9188. const prev = cached.memo;
  9189. if (prev.length != memo.length) {
  9190. return false;
  9191. }
  9192. for (let i = 0; i < prev.length; i++) {
  9193. if (shared.hasChanged(prev[i], memo[i])) {
  9194. return false;
  9195. }
  9196. }
  9197. // make sure to let parent block track it when returning cached
  9198. if (isBlockTreeEnabled > 0 && currentBlock) {
  9199. currentBlock.push(cached);
  9200. }
  9201. return true;
  9202. }
  9203. // Core API ------------------------------------------------------------------
  9204. const version = "3.2.47";
  9205. const _ssrUtils = {
  9206. createComponentInstance,
  9207. setupComponent,
  9208. renderComponentRoot,
  9209. setCurrentRenderingInstance,
  9210. isVNode,
  9211. normalizeVNode
  9212. };
  9213. /**
  9214. * SSR utils for \@vue/server-renderer. Only exposed in ssr-possible builds.
  9215. * @internal
  9216. */
  9217. const ssrUtils = (_ssrUtils );
  9218. /**
  9219. * @internal only exposed in compat builds
  9220. */
  9221. const resolveFilter = null;
  9222. /**
  9223. * @internal only exposed in compat builds.
  9224. */
  9225. const compatUtils = (null);
  9226. const svgNS = 'http://www.w3.org/2000/svg';
  9227. const doc = (typeof document !== 'undefined' ? document : null);
  9228. const templateContainer = doc && /*#__PURE__*/ doc.createElement('template');
  9229. const nodeOps = {
  9230. insert: (child, parent, anchor) => {
  9231. parent.insertBefore(child, anchor || null);
  9232. },
  9233. remove: child => {
  9234. const parent = child.parentNode;
  9235. if (parent) {
  9236. parent.removeChild(child);
  9237. }
  9238. },
  9239. createElement: (tag, isSVG, is, props) => {
  9240. /**
  9241. * fix chrome version 64
  9242. * document.createElement('uni-text', undefined) instanceof customElements.get('uni-text') // false
  9243. * document.createElement('uni-text') instanceof customElements.get('uni-text') // true
  9244. */
  9245. const el = isSVG
  9246. ? doc.createElementNS(svgNS, tag)
  9247. : is
  9248. ? doc.createElement(tag, { is })
  9249. : doc.createElement(tag);
  9250. if (tag === 'select' && props && props.multiple != null) {
  9251. el.setAttribute('multiple', props.multiple);
  9252. }
  9253. return el;
  9254. },
  9255. createText: text => doc.createTextNode(text),
  9256. createComment: text => doc.createComment(text),
  9257. setText: (node, text) => {
  9258. node.nodeValue = text;
  9259. },
  9260. setElementText: (el, text) => {
  9261. el.textContent = text;
  9262. },
  9263. parentNode: node => node.parentNode,
  9264. nextSibling: node => node.nextSibling,
  9265. querySelector: selector => doc.querySelector(selector),
  9266. setScopeId(el, id) {
  9267. el.setAttribute(id, '');
  9268. },
  9269. // __UNSAFE__
  9270. // Reason: innerHTML.
  9271. // Static content here can only come from compiled templates.
  9272. // As long as the user only uses trusted templates, this is safe.
  9273. insertStaticContent(content, parent, anchor, isSVG, start, end) {
  9274. // <parent> before | first ... last | anchor </parent>
  9275. const before = anchor ? anchor.previousSibling : parent.lastChild;
  9276. // #5308 can only take cached path if:
  9277. // - has a single root node
  9278. // - nextSibling info is still available
  9279. if (start && (start === end || start.nextSibling)) {
  9280. // cached
  9281. while (true) {
  9282. parent.insertBefore(start.cloneNode(true), anchor);
  9283. if (start === end || !(start = start.nextSibling))
  9284. break;
  9285. }
  9286. }
  9287. else {
  9288. // fresh insert
  9289. templateContainer.innerHTML = isSVG ? `<svg>${content}</svg>` : content;
  9290. const template = templateContainer.content;
  9291. if (isSVG) {
  9292. // remove outer svg wrapper
  9293. const wrapper = template.firstChild;
  9294. while (wrapper.firstChild) {
  9295. template.appendChild(wrapper.firstChild);
  9296. }
  9297. template.removeChild(wrapper);
  9298. }
  9299. parent.insertBefore(template, anchor);
  9300. }
  9301. return [
  9302. // first
  9303. before ? before.nextSibling : parent.firstChild,
  9304. // last
  9305. anchor ? anchor.previousSibling : parent.lastChild
  9306. ];
  9307. }
  9308. };
  9309. // compiler should normalize class + :class bindings on the same element
  9310. // into a single binding ['staticClass', dynamic]
  9311. function patchClass(el, value, isSVG) {
  9312. // directly setting className should be faster than setAttribute in theory
  9313. // if this is an element during a transition, take the temporary transition
  9314. // classes into account.
  9315. // fixed by xxxxxx wxs
  9316. const { __wxsAddClass, __wxsRemoveClass } = el;
  9317. if (__wxsRemoveClass && __wxsRemoveClass.length) {
  9318. value = (value || '')
  9319. .split(/\s+/)
  9320. .filter(v => __wxsRemoveClass.indexOf(v) === -1)
  9321. .join(' ');
  9322. __wxsRemoveClass.length = 0;
  9323. }
  9324. if (__wxsAddClass && __wxsAddClass.length) {
  9325. value = (value || '') + ' ' + __wxsAddClass.join(' ');
  9326. }
  9327. const transitionClasses = el._vtc;
  9328. if (transitionClasses) {
  9329. value = (value ? [value, ...transitionClasses] : [...transitionClasses]).join(' ');
  9330. }
  9331. if (value == null) {
  9332. el.removeAttribute('class');
  9333. }
  9334. else if (isSVG) {
  9335. el.setAttribute('class', value);
  9336. }
  9337. else {
  9338. el.className = value;
  9339. }
  9340. }
  9341. function patchStyle(el, prev, next) {
  9342. const style = el.style;
  9343. const isCssString = shared.isString(next);
  9344. if (next && !isCssString) {
  9345. if (prev && !shared.isString(prev)) {
  9346. for (const key in prev) {
  9347. if (next[key] == null) {
  9348. setStyle(style, key, '');
  9349. }
  9350. }
  9351. }
  9352. for (const key in next) {
  9353. setStyle(style, key, next[key]);
  9354. }
  9355. }
  9356. else {
  9357. const currentDisplay = style.display;
  9358. if (isCssString) {
  9359. if (prev !== next) {
  9360. style.cssText = next;
  9361. }
  9362. }
  9363. else if (prev) {
  9364. el.removeAttribute('style');
  9365. }
  9366. // indicates that the `display` of the element is controlled by `v-show`,
  9367. // so we always keep the current `display` value regardless of the `style`
  9368. // value, thus handing over control to `v-show`.
  9369. if ('_vod' in el) {
  9370. style.display = currentDisplay;
  9371. }
  9372. }
  9373. // fixed by xxxxxx
  9374. const { __wxsStyle } = el;
  9375. if (__wxsStyle) {
  9376. for (const key in __wxsStyle) {
  9377. setStyle(style, key, __wxsStyle[key]);
  9378. }
  9379. }
  9380. }
  9381. const semicolonRE = /[^\\];\s*$/;
  9382. const importantRE = /\s*!important$/;
  9383. function setStyle(style, name, val) {
  9384. if (shared.isArray(val)) {
  9385. val.forEach(v => setStyle(style, name, v));
  9386. }
  9387. else {
  9388. if (val == null)
  9389. val = '';
  9390. // fixed by xxxxxx
  9391. val = normalizeRpx(val);
  9392. {
  9393. if (semicolonRE.test(val)) {
  9394. warn(`Unexpected semicolon at the end of '${name}' style value: '${val}'`);
  9395. }
  9396. }
  9397. if (name.startsWith('--')) {
  9398. // custom property definition
  9399. style.setProperty(name, val);
  9400. }
  9401. else {
  9402. const prefixed = autoPrefix(style, name);
  9403. if (importantRE.test(val)) {
  9404. // !important
  9405. style.setProperty(shared.hyphenate(prefixed), val.replace(importantRE, ''), 'important');
  9406. }
  9407. else {
  9408. style[prefixed] = val;
  9409. }
  9410. }
  9411. }
  9412. }
  9413. const prefixes = ['Webkit', 'Moz', 'ms'];
  9414. const prefixCache = {};
  9415. function autoPrefix(style, rawName) {
  9416. const cached = prefixCache[rawName];
  9417. if (cached) {
  9418. return cached;
  9419. }
  9420. let name = shared.camelize(rawName);
  9421. if (name !== 'filter' && name in style) {
  9422. return (prefixCache[rawName] = name);
  9423. }
  9424. name = shared.capitalize(name);
  9425. for (let i = 0; i < prefixes.length; i++) {
  9426. const prefixed = prefixes[i] + name;
  9427. if (prefixed in style) {
  9428. return (prefixCache[rawName] = prefixed);
  9429. }
  9430. }
  9431. return rawName;
  9432. }
  9433. // fixed by xxxxxx
  9434. // upx,rpx
  9435. const { unit, unitRatio, unitPrecision } = uniShared.defaultRpx2Unit;
  9436. const rpx2Unit = uniShared.createRpx2Unit(unit, unitRatio, unitPrecision);
  9437. const normalizeRpx = (val) => {
  9438. if (shared.isString(val)) {
  9439. return rpx2Unit(val);
  9440. }
  9441. return val;
  9442. };
  9443. const xlinkNS = 'http://www.w3.org/1999/xlink';
  9444. function patchAttr(el, key, value, isSVG, instance) {
  9445. if (isSVG && key.startsWith('xlink:')) {
  9446. if (value == null) {
  9447. el.removeAttributeNS(xlinkNS, key.slice(6, key.length));
  9448. }
  9449. else {
  9450. el.setAttributeNS(xlinkNS, key, value);
  9451. }
  9452. }
  9453. else {
  9454. // note we are only checking boolean attributes that don't have a
  9455. // corresponding dom prop of the same name here.
  9456. const isBoolean = shared.isSpecialBooleanAttr(key);
  9457. if (value == null || (isBoolean && !shared.includeBooleanAttr(value))) {
  9458. el.removeAttribute(key);
  9459. }
  9460. else {
  9461. el.setAttribute(key, isBoolean ? '' : value);
  9462. }
  9463. }
  9464. }
  9465. // __UNSAFE__
  9466. // functions. The user is responsible for using them with only trusted content.
  9467. function patchDOMProp(el, key, value,
  9468. // the following args are passed only due to potential innerHTML/textContent
  9469. // overriding existing VNodes, in which case the old tree must be properly
  9470. // unmounted.
  9471. prevChildren, parentComponent, parentSuspense, unmountChildren) {
  9472. if (key === 'innerHTML' || key === 'textContent') {
  9473. if (prevChildren) {
  9474. unmountChildren(prevChildren, parentComponent, parentSuspense);
  9475. }
  9476. el[key] = value == null ? '' : value;
  9477. return;
  9478. }
  9479. if (key === 'value' &&
  9480. el.tagName !== 'PROGRESS' &&
  9481. // custom elements may use _value internally
  9482. !el.tagName.includes('-')) {
  9483. // store value as _value as well since
  9484. // non-string values will be stringified.
  9485. el._value = value;
  9486. const newValue = value == null ? '' : value;
  9487. if (el.value !== newValue ||
  9488. // #4956: always set for OPTION elements because its value falls back to
  9489. // textContent if no value attribute is present. And setting .value for
  9490. // OPTION has no side effect
  9491. el.tagName === 'OPTION') {
  9492. el.value = newValue;
  9493. }
  9494. if (value == null) {
  9495. el.removeAttribute(key);
  9496. }
  9497. return;
  9498. }
  9499. let needRemove = false;
  9500. if (value === '' || value == null) {
  9501. const type = typeof el[key];
  9502. if (type === 'boolean') {
  9503. // e.g. <select multiple> compiles to { multiple: '' }
  9504. value = shared.includeBooleanAttr(value);
  9505. }
  9506. else if (value == null && type === 'string') {
  9507. // e.g. <div :id="null">
  9508. value = '';
  9509. needRemove = true;
  9510. }
  9511. else if (type === 'number') {
  9512. // e.g. <img :width="null">
  9513. value = 0;
  9514. needRemove = true;
  9515. }
  9516. }
  9517. // some properties perform value validation and throw,
  9518. // some properties has getter, no setter, will error in 'use strict'
  9519. // eg. <select :type="null"></select> <select :willValidate="null"></select>
  9520. try {
  9521. el[key] = value;
  9522. }
  9523. catch (e) {
  9524. // do not warn if value is auto-coerced from nullish values
  9525. if (!needRemove) {
  9526. warn(`Failed setting prop "${key}" on <${el.tagName.toLowerCase()}>: ` +
  9527. `value ${value} is invalid.`, e);
  9528. }
  9529. }
  9530. needRemove && el.removeAttribute(key);
  9531. }
  9532. function addEventListener(el, event, handler, options) {
  9533. el.addEventListener(event, handler, options);
  9534. }
  9535. function removeEventListener(el, event, handler, options) {
  9536. el.removeEventListener(event, handler, options);
  9537. }
  9538. function patchEvent(el, rawName, prevValue, nextValue, instance = null) {
  9539. // vei = vue event invokers
  9540. const invokers = el._vei || (el._vei = {});
  9541. const existingInvoker = invokers[rawName];
  9542. if (nextValue && existingInvoker) {
  9543. // patch
  9544. existingInvoker.value = nextValue;
  9545. }
  9546. else {
  9547. const [name, options] = parseName(rawName);
  9548. if (nextValue) {
  9549. // add
  9550. const invoker = (invokers[rawName] = createInvoker(nextValue, instance));
  9551. addEventListener(el, name, invoker, options);
  9552. }
  9553. else if (existingInvoker) {
  9554. // remove
  9555. removeEventListener(el, name, existingInvoker, options);
  9556. invokers[rawName] = undefined;
  9557. }
  9558. }
  9559. }
  9560. const optionsModifierRE = /(?:Once|Passive|Capture)$/;
  9561. function parseName(name) {
  9562. let options;
  9563. if (optionsModifierRE.test(name)) {
  9564. options = {};
  9565. let m;
  9566. while ((m = name.match(optionsModifierRE))) {
  9567. name = name.slice(0, name.length - m[0].length);
  9568. options[m[0].toLowerCase()] = true;
  9569. }
  9570. }
  9571. const event = name[2] === ':' ? name.slice(3) : shared.hyphenate(name.slice(2));
  9572. return [event, options];
  9573. }
  9574. // To avoid the overhead of repeatedly calling Date.now(), we cache
  9575. // and use the same timestamp for all event listeners attached in the same tick.
  9576. let cachedNow = 0;
  9577. const p = /*#__PURE__*/ Promise.resolve();
  9578. const getNow = () => cachedNow || (p.then(() => (cachedNow = 0)), (cachedNow = Date.now()));
  9579. function createInvoker(initialValue, instance) {
  9580. const invoker = (e) => {
  9581. // async edge case vuejs/vue#6566
  9582. // inner click event triggers patch, event handler
  9583. // attached to outer element during patch, and triggered again. This
  9584. // happens because browsers fire microtask ticks between event propagation.
  9585. // this no longer happens for templates in Vue 3, but could still be
  9586. // theoretically possible for hand-written render functions.
  9587. // the solution: we save the timestamp when a handler is attached,
  9588. // and also attach the timestamp to any event that was handled by vue
  9589. // for the first time (to avoid inconsistent event timestamp implementations
  9590. // or events fired from iframes, e.g. #2513)
  9591. // The handler would only fire if the event passed to it was fired
  9592. // AFTER it was attached.
  9593. if (!e._vts) {
  9594. e._vts = Date.now();
  9595. }
  9596. else if (e._vts <= invoker.attached) {
  9597. return;
  9598. }
  9599. // fixed by xxxxxx
  9600. const proxy = instance && instance.proxy;
  9601. const normalizeNativeEvent = proxy && proxy.$nne;
  9602. const { value } = invoker;
  9603. if (normalizeNativeEvent && shared.isArray(value)) {
  9604. const fns = patchStopImmediatePropagation(e, value);
  9605. for (let i = 0; i < fns.length; i++) {
  9606. const fn = fns[i];
  9607. callWithAsyncErrorHandling(fn, instance, 5 /* ErrorCodes.NATIVE_EVENT_HANDLER */, !fn.__wwe ? normalizeNativeEvent(e) : [e]);
  9608. }
  9609. return;
  9610. }
  9611. callWithAsyncErrorHandling(patchStopImmediatePropagation(e, value), instance, 5 /* ErrorCodes.NATIVE_EVENT_HANDLER */,
  9612. // fixed by xxxxxx
  9613. normalizeNativeEvent && !value.__wwe
  9614. ? normalizeNativeEvent(e, value, instance)
  9615. : [e]);
  9616. };
  9617. invoker.value = initialValue;
  9618. invoker.attached = getNow();
  9619. return invoker;
  9620. }
  9621. function patchStopImmediatePropagation(e, value) {
  9622. if (shared.isArray(value)) {
  9623. const originalStop = e.stopImmediatePropagation;
  9624. e.stopImmediatePropagation = () => {
  9625. originalStop.call(e);
  9626. e._stopped = true;
  9627. };
  9628. return value.map(fn => {
  9629. const patchedFn = (e) => !e._stopped && fn && fn(e);
  9630. patchedFn.__wwe = fn.__wwe;
  9631. return patchedFn;
  9632. });
  9633. }
  9634. else {
  9635. return value;
  9636. }
  9637. }
  9638. function patchWxs(el, rawName, nextValue, instance = null) {
  9639. if (!nextValue || !instance) {
  9640. return;
  9641. }
  9642. const propName = rawName.replace('change:', '');
  9643. const { attrs } = instance;
  9644. const nextPropValue = attrs[propName];
  9645. const prevPropValue = (el.__wxsProps || (el.__wxsProps = {}))[propName];
  9646. if (prevPropValue === nextPropValue) {
  9647. return;
  9648. }
  9649. el.__wxsProps[propName] = nextPropValue;
  9650. const proxy = instance.proxy;
  9651. nextTick(() => {
  9652. nextValue(nextPropValue, prevPropValue, proxy.$gcd(proxy, true), proxy.$gcd(proxy, false));
  9653. });
  9654. }
  9655. const nativeOnRE = /^on[a-z]/;
  9656. // fixed by xxxxxx
  9657. const forcePatchProp = (el, key) => {
  9658. if (key.indexOf('change:') === 0) {
  9659. return true;
  9660. }
  9661. if (key === 'class' && el.__wxsClassChanged) {
  9662. el.__wxsClassChanged = false;
  9663. return true;
  9664. }
  9665. if (key === 'style' && el.__wxsStyleChanged) {
  9666. el.__wxsStyleChanged = false;
  9667. return true;
  9668. }
  9669. return false;
  9670. };
  9671. const patchProp = (el, key, prevValue, nextValue, isSVG = false, prevChildren, parentComponent, parentSuspense, unmountChildren) => {
  9672. // @ts-expect-error fixed by xxxxxx
  9673. if (__UNI_FEATURE_WXS__ && key.indexOf('change:') === 0) {
  9674. return patchWxs(el, key, nextValue, parentComponent);
  9675. }
  9676. if (key === 'class') {
  9677. patchClass(el, nextValue, isSVG);
  9678. }
  9679. else if (key === 'style') {
  9680. patchStyle(el, prevValue, nextValue);
  9681. }
  9682. else if (shared.isOn(key)) {
  9683. // ignore v-model listeners
  9684. if (!shared.isModelListener(key)) {
  9685. patchEvent(el, key, prevValue, nextValue, parentComponent);
  9686. }
  9687. }
  9688. else if (key[0] === '.'
  9689. ? ((key = key.slice(1)), true)
  9690. : key[0] === '^'
  9691. ? ((key = key.slice(1)), false)
  9692. : shouldSetAsProp(el, key, nextValue, isSVG)) {
  9693. patchDOMProp(el, key, nextValue, prevChildren, parentComponent, parentSuspense, unmountChildren);
  9694. }
  9695. else {
  9696. // special case for <input v-model type="checkbox"> with
  9697. // :true-value & :false-value
  9698. // store value as dom properties since non-string values will be
  9699. // stringified.
  9700. if (key === 'true-value') {
  9701. el._trueValue = nextValue;
  9702. }
  9703. else if (key === 'false-value') {
  9704. el._falseValue = nextValue;
  9705. }
  9706. patchAttr(el, key, nextValue, isSVG);
  9707. }
  9708. };
  9709. function shouldSetAsProp(el, key, value, isSVG) {
  9710. if (isSVG) {
  9711. // most keys must be set as attribute on svg elements to work
  9712. // ...except innerHTML & textContent
  9713. if (key === 'innerHTML' || key === 'textContent') {
  9714. return true;
  9715. }
  9716. // or native onclick with function values
  9717. if (key in el && nativeOnRE.test(key) && shared.isFunction(value)) {
  9718. return true;
  9719. }
  9720. return false;
  9721. }
  9722. // these are enumerated attrs, however their corresponding DOM properties
  9723. // are actually booleans - this leads to setting it with a string "false"
  9724. // value leading it to be coerced to `true`, so we need to always treat
  9725. // them as attributes.
  9726. // Note that `contentEditable` doesn't have this problem: its DOM
  9727. // property is also enumerated string values.
  9728. if (key === 'spellcheck' || key === 'draggable' || key === 'translate') {
  9729. return false;
  9730. }
  9731. // #1787, #2840 form property on form elements is readonly and must be set as
  9732. // attribute.
  9733. if (key === 'form') {
  9734. return false;
  9735. }
  9736. // #1526 <input list> must be set as attribute
  9737. if (key === 'list' && el.tagName === 'INPUT') {
  9738. return false;
  9739. }
  9740. // #2766 <textarea type> must be set as attribute
  9741. if (key === 'type' && el.tagName === 'TEXTAREA') {
  9742. return false;
  9743. }
  9744. // native onclick with string value, must be set as attribute
  9745. if (nativeOnRE.test(key) && shared.isString(value)) {
  9746. return false;
  9747. }
  9748. return key in el;
  9749. }
  9750. function defineCustomElement(options, hydrate) {
  9751. const Comp = defineComponent(options);
  9752. class VueCustomElement extends VueElement {
  9753. constructor(initialProps) {
  9754. super(Comp, initialProps, hydrate);
  9755. }
  9756. }
  9757. VueCustomElement.def = Comp;
  9758. return VueCustomElement;
  9759. }
  9760. const defineSSRCustomElement = ((options) => {
  9761. // @ts-ignore
  9762. return defineCustomElement(options, hydrate);
  9763. });
  9764. const BaseClass = (typeof HTMLElement !== 'undefined' ? HTMLElement : class {
  9765. });
  9766. class VueElement extends BaseClass {
  9767. constructor(_def, _props = {}, hydrate) {
  9768. super();
  9769. this._def = _def;
  9770. this._props = _props;
  9771. /**
  9772. * @internal
  9773. */
  9774. this._instance = null;
  9775. this._connected = false;
  9776. this._resolved = false;
  9777. this._numberProps = null;
  9778. if (this.shadowRoot && hydrate) {
  9779. hydrate(this._createVNode(), this.shadowRoot);
  9780. }
  9781. else {
  9782. if (this.shadowRoot) {
  9783. warn(`Custom element has pre-rendered declarative shadow root but is not ` +
  9784. `defined as hydratable. Use \`defineSSRCustomElement\`.`);
  9785. }
  9786. this.attachShadow({ mode: 'open' });
  9787. if (!this._def.__asyncLoader) {
  9788. // for sync component defs we can immediately resolve props
  9789. this._resolveProps(this._def);
  9790. }
  9791. }
  9792. }
  9793. connectedCallback() {
  9794. this._connected = true;
  9795. if (!this._instance) {
  9796. if (this._resolved) {
  9797. this._update();
  9798. }
  9799. else {
  9800. this._resolveDef();
  9801. }
  9802. }
  9803. }
  9804. disconnectedCallback() {
  9805. this._connected = false;
  9806. nextTick(() => {
  9807. if (!this._connected) {
  9808. render(null, this.shadowRoot);
  9809. this._instance = null;
  9810. }
  9811. });
  9812. }
  9813. /**
  9814. * resolve inner component definition (handle possible async component)
  9815. */
  9816. _resolveDef() {
  9817. this._resolved = true;
  9818. // set initial attrs
  9819. for (let i = 0; i < this.attributes.length; i++) {
  9820. this._setAttr(this.attributes[i].name);
  9821. }
  9822. // watch future attr changes
  9823. new MutationObserver(mutations => {
  9824. for (const m of mutations) {
  9825. this._setAttr(m.attributeName);
  9826. }
  9827. }).observe(this, { attributes: true });
  9828. const resolve = (def, isAsync = false) => {
  9829. const { props, styles } = def;
  9830. // cast Number-type props set before resolve
  9831. let numberProps;
  9832. if (props && !shared.isArray(props)) {
  9833. for (const key in props) {
  9834. const opt = props[key];
  9835. if (opt === Number || (opt && opt.type === Number)) {
  9836. if (key in this._props) {
  9837. this._props[key] = shared.toNumber(this._props[key]);
  9838. }
  9839. (numberProps || (numberProps = Object.create(null)))[shared.camelize(key)] = true;
  9840. }
  9841. }
  9842. }
  9843. this._numberProps = numberProps;
  9844. if (isAsync) {
  9845. // defining getter/setters on prototype
  9846. // for sync defs, this already happened in the constructor
  9847. this._resolveProps(def);
  9848. }
  9849. // apply CSS
  9850. this._applyStyles(styles);
  9851. // initial render
  9852. this._update();
  9853. };
  9854. const asyncDef = this._def.__asyncLoader;
  9855. if (asyncDef) {
  9856. asyncDef().then(def => resolve(def, true));
  9857. }
  9858. else {
  9859. resolve(this._def);
  9860. }
  9861. }
  9862. _resolveProps(def) {
  9863. const { props } = def;
  9864. const declaredPropKeys = shared.isArray(props) ? props : Object.keys(props || {});
  9865. // check if there are props set pre-upgrade or connect
  9866. for (const key of Object.keys(this)) {
  9867. if (key[0] !== '_' && declaredPropKeys.includes(key)) {
  9868. this._setProp(key, this[key], true, false);
  9869. }
  9870. }
  9871. // defining getter/setters on prototype
  9872. for (const key of declaredPropKeys.map(shared.camelize)) {
  9873. Object.defineProperty(this, key, {
  9874. get() {
  9875. return this._getProp(key);
  9876. },
  9877. set(val) {
  9878. this._setProp(key, val);
  9879. }
  9880. });
  9881. }
  9882. }
  9883. _setAttr(key) {
  9884. let value = this.getAttribute(key);
  9885. const camelKey = shared.camelize(key);
  9886. if (this._numberProps && this._numberProps[camelKey]) {
  9887. value = shared.toNumber(value);
  9888. }
  9889. this._setProp(camelKey, value, false);
  9890. }
  9891. /**
  9892. * @internal
  9893. */
  9894. _getProp(key) {
  9895. return this._props[key];
  9896. }
  9897. /**
  9898. * @internal
  9899. */
  9900. _setProp(key, val, shouldReflect = true, shouldUpdate = true) {
  9901. if (val !== this._props[key]) {
  9902. this._props[key] = val;
  9903. if (shouldUpdate && this._instance) {
  9904. this._update();
  9905. }
  9906. // reflect
  9907. if (shouldReflect) {
  9908. if (val === true) {
  9909. this.setAttribute(shared.hyphenate(key), '');
  9910. }
  9911. else if (typeof val === 'string' || typeof val === 'number') {
  9912. this.setAttribute(shared.hyphenate(key), val + '');
  9913. }
  9914. else if (!val) {
  9915. this.removeAttribute(shared.hyphenate(key));
  9916. }
  9917. }
  9918. }
  9919. }
  9920. _update() {
  9921. render(this._createVNode(), this.shadowRoot);
  9922. }
  9923. _createVNode() {
  9924. const vnode = createVNode(this._def, shared.extend({}, this._props));
  9925. if (!this._instance) {
  9926. vnode.ce = instance => {
  9927. this._instance = instance;
  9928. instance.isCE = true;
  9929. // HMR
  9930. {
  9931. instance.ceReload = newStyles => {
  9932. // always reset styles
  9933. if (this._styles) {
  9934. this._styles.forEach(s => this.shadowRoot.removeChild(s));
  9935. this._styles.length = 0;
  9936. }
  9937. this._applyStyles(newStyles);
  9938. this._instance = null;
  9939. this._update();
  9940. };
  9941. }
  9942. const dispatch = (event, args) => {
  9943. this.dispatchEvent(new CustomEvent(event, {
  9944. detail: args
  9945. }));
  9946. };
  9947. // intercept emit
  9948. instance.emit = (event, ...args) => {
  9949. // dispatch both the raw and hyphenated versions of an event
  9950. // to match Vue behavior
  9951. dispatch(event, args);
  9952. if (shared.hyphenate(event) !== event) {
  9953. dispatch(shared.hyphenate(event), args);
  9954. }
  9955. };
  9956. // locate nearest Vue custom element parent for provide/inject
  9957. let parent = this;
  9958. while ((parent =
  9959. parent && (parent.parentNode || parent.host))) {
  9960. if (parent instanceof VueElement) {
  9961. instance.parent = parent._instance;
  9962. instance.provides = parent._instance.provides;
  9963. break;
  9964. }
  9965. }
  9966. };
  9967. }
  9968. return vnode;
  9969. }
  9970. _applyStyles(styles) {
  9971. if (styles) {
  9972. styles.forEach(css => {
  9973. const s = document.createElement('style');
  9974. s.textContent = css;
  9975. this.shadowRoot.appendChild(s);
  9976. // record for HMR
  9977. {
  9978. (this._styles || (this._styles = [])).push(s);
  9979. }
  9980. });
  9981. }
  9982. }
  9983. }
  9984. function useCssModule(name = '$style') {
  9985. /* istanbul ignore else */
  9986. {
  9987. const instance = getCurrentInstance();
  9988. if (!instance) {
  9989. warn(`useCssModule must be called inside setup()`);
  9990. return shared.EMPTY_OBJ;
  9991. }
  9992. const modules = instance.type.__cssModules;
  9993. if (!modules) {
  9994. warn(`Current instance does not have CSS modules injected.`);
  9995. return shared.EMPTY_OBJ;
  9996. }
  9997. const mod = modules[name];
  9998. if (!mod) {
  9999. warn(`Current instance does not have CSS module named "${name}".`);
  10000. return shared.EMPTY_OBJ;
  10001. }
  10002. return mod;
  10003. }
  10004. }
  10005. /**
  10006. * Runtime helper for SFC's CSS variable injection feature.
  10007. * @private
  10008. */
  10009. function useCssVars(getter) {
  10010. return;
  10011. }
  10012. const TRANSITION = 'transition';
  10013. const ANIMATION = 'animation';
  10014. // DOM Transition is a higher-order-component based on the platform-agnostic
  10015. // base Transition component, with DOM-specific logic.
  10016. const Transition = (props, { slots }) => h(BaseTransition, resolveTransitionProps(props), slots);
  10017. Transition.displayName = 'Transition';
  10018. const DOMTransitionPropsValidators = {
  10019. name: String,
  10020. type: String,
  10021. css: {
  10022. type: Boolean,
  10023. default: true
  10024. },
  10025. duration: [String, Number, Object],
  10026. enterFromClass: String,
  10027. enterActiveClass: String,
  10028. enterToClass: String,
  10029. appearFromClass: String,
  10030. appearActiveClass: String,
  10031. appearToClass: String,
  10032. leaveFromClass: String,
  10033. leaveActiveClass: String,
  10034. leaveToClass: String
  10035. };
  10036. const TransitionPropsValidators = (Transition.props =
  10037. /*#__PURE__*/ shared.extend({}, BaseTransitionPropsValidators, DOMTransitionPropsValidators));
  10038. /**
  10039. * #3227 Incoming hooks may be merged into arrays when wrapping Transition
  10040. * with custom HOCs.
  10041. */
  10042. const callHook = (hook, args = []) => {
  10043. if (shared.isArray(hook)) {
  10044. hook.forEach(h => h(...args));
  10045. }
  10046. else if (hook) {
  10047. hook(...args);
  10048. }
  10049. };
  10050. /**
  10051. * Check if a hook expects a callback (2nd arg), which means the user
  10052. * intends to explicitly control the end of the transition.
  10053. */
  10054. const hasExplicitCallback = (hook) => {
  10055. return hook
  10056. ? shared.isArray(hook)
  10057. ? hook.some(h => h.length > 1)
  10058. : hook.length > 1
  10059. : false;
  10060. };
  10061. function resolveTransitionProps(rawProps) {
  10062. const baseProps = {};
  10063. for (const key in rawProps) {
  10064. if (!(key in DOMTransitionPropsValidators)) {
  10065. baseProps[key] = rawProps[key];
  10066. }
  10067. }
  10068. if (rawProps.css === false) {
  10069. return baseProps;
  10070. }
  10071. 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;
  10072. const durations = normalizeDuration(duration);
  10073. const enterDuration = durations && durations[0];
  10074. const leaveDuration = durations && durations[1];
  10075. const { onBeforeEnter, onEnter, onEnterCancelled, onLeave, onLeaveCancelled, onBeforeAppear = onBeforeEnter, onAppear = onEnter, onAppearCancelled = onEnterCancelled } = baseProps;
  10076. const finishEnter = (el, isAppear, done) => {
  10077. removeTransitionClass(el, isAppear ? appearToClass : enterToClass);
  10078. removeTransitionClass(el, isAppear ? appearActiveClass : enterActiveClass);
  10079. done && done();
  10080. };
  10081. const finishLeave = (el, done) => {
  10082. el._isLeaving = false;
  10083. removeTransitionClass(el, leaveFromClass);
  10084. removeTransitionClass(el, leaveToClass);
  10085. removeTransitionClass(el, leaveActiveClass);
  10086. done && done();
  10087. };
  10088. const makeEnterHook = (isAppear) => {
  10089. return (el, done) => {
  10090. const hook = isAppear ? onAppear : onEnter;
  10091. const resolve = () => finishEnter(el, isAppear, done);
  10092. callHook(hook, [el, resolve]);
  10093. nextFrame(() => {
  10094. removeTransitionClass(el, isAppear ? appearFromClass : enterFromClass);
  10095. addTransitionClass(el, isAppear ? appearToClass : enterToClass);
  10096. if (!hasExplicitCallback(hook)) {
  10097. whenTransitionEnds(el, type, enterDuration, resolve);
  10098. }
  10099. });
  10100. };
  10101. };
  10102. return shared.extend(baseProps, {
  10103. onBeforeEnter(el) {
  10104. callHook(onBeforeEnter, [el]);
  10105. addTransitionClass(el, enterFromClass);
  10106. addTransitionClass(el, enterActiveClass);
  10107. },
  10108. onBeforeAppear(el) {
  10109. callHook(onBeforeAppear, [el]);
  10110. addTransitionClass(el, appearFromClass);
  10111. addTransitionClass(el, appearActiveClass);
  10112. },
  10113. onEnter: makeEnterHook(false),
  10114. onAppear: makeEnterHook(true),
  10115. onLeave(el, done) {
  10116. el._isLeaving = true;
  10117. const resolve = () => finishLeave(el, done);
  10118. addTransitionClass(el, leaveFromClass);
  10119. // force reflow so *-leave-from classes immediately take effect (#2593)
  10120. forceReflow();
  10121. addTransitionClass(el, leaveActiveClass);
  10122. nextFrame(() => {
  10123. if (!el._isLeaving) {
  10124. // cancelled
  10125. return;
  10126. }
  10127. removeTransitionClass(el, leaveFromClass);
  10128. addTransitionClass(el, leaveToClass);
  10129. if (!hasExplicitCallback(onLeave)) {
  10130. whenTransitionEnds(el, type, leaveDuration, resolve);
  10131. }
  10132. });
  10133. callHook(onLeave, [el, resolve]);
  10134. },
  10135. onEnterCancelled(el) {
  10136. finishEnter(el, false);
  10137. callHook(onEnterCancelled, [el]);
  10138. },
  10139. onAppearCancelled(el) {
  10140. finishEnter(el, true);
  10141. callHook(onAppearCancelled, [el]);
  10142. },
  10143. onLeaveCancelled(el) {
  10144. finishLeave(el);
  10145. callHook(onLeaveCancelled, [el]);
  10146. }
  10147. });
  10148. }
  10149. function normalizeDuration(duration) {
  10150. if (duration == null) {
  10151. return null;
  10152. }
  10153. else if (shared.isObject(duration)) {
  10154. return [NumberOf(duration.enter), NumberOf(duration.leave)];
  10155. }
  10156. else {
  10157. const n = NumberOf(duration);
  10158. return [n, n];
  10159. }
  10160. }
  10161. function NumberOf(val) {
  10162. const res = shared.toNumber(val);
  10163. {
  10164. assertNumber(res, '<transition> explicit duration');
  10165. }
  10166. return res;
  10167. }
  10168. function addTransitionClass(el, cls) {
  10169. cls.split(/\s+/).forEach(c => c && el.classList.add(c));
  10170. (el._vtc ||
  10171. (el._vtc = new Set())).add(cls);
  10172. }
  10173. function removeTransitionClass(el, cls) {
  10174. cls.split(/\s+/).forEach(c => c && el.classList.remove(c));
  10175. const { _vtc } = el;
  10176. if (_vtc) {
  10177. _vtc.delete(cls);
  10178. if (!_vtc.size) {
  10179. el._vtc = undefined;
  10180. }
  10181. }
  10182. }
  10183. function nextFrame(cb) {
  10184. requestAnimationFrame(() => {
  10185. requestAnimationFrame(cb);
  10186. });
  10187. }
  10188. let endId = 0;
  10189. function whenTransitionEnds(el, expectedType, explicitTimeout, resolve) {
  10190. const id = (el._endId = ++endId);
  10191. const resolveIfNotStale = () => {
  10192. if (id === el._endId) {
  10193. resolve();
  10194. }
  10195. };
  10196. if (explicitTimeout) {
  10197. return setTimeout(resolveIfNotStale, explicitTimeout);
  10198. }
  10199. const { type, timeout, propCount } = getTransitionInfo(el, expectedType);
  10200. if (!type) {
  10201. return resolve();
  10202. }
  10203. const endEvent = type + 'end';
  10204. let ended = 0;
  10205. const end = () => {
  10206. el.removeEventListener(endEvent, onEnd);
  10207. resolveIfNotStale();
  10208. };
  10209. const onEnd = (e) => {
  10210. if (e.target === el && ++ended >= propCount) {
  10211. end();
  10212. }
  10213. };
  10214. setTimeout(() => {
  10215. if (ended < propCount) {
  10216. end();
  10217. }
  10218. }, timeout + 1);
  10219. el.addEventListener(endEvent, onEnd);
  10220. }
  10221. function getTransitionInfo(el, expectedType) {
  10222. const styles = window.getComputedStyle(el);
  10223. // JSDOM may return undefined for transition properties
  10224. const getStyleProperties = (key) => (styles[key] || '').split(', ');
  10225. const transitionDelays = getStyleProperties(`${TRANSITION}Delay`);
  10226. const transitionDurations = getStyleProperties(`${TRANSITION}Duration`);
  10227. const transitionTimeout = getTimeout(transitionDelays, transitionDurations);
  10228. const animationDelays = getStyleProperties(`${ANIMATION}Delay`);
  10229. const animationDurations = getStyleProperties(`${ANIMATION}Duration`);
  10230. const animationTimeout = getTimeout(animationDelays, animationDurations);
  10231. let type = null;
  10232. let timeout = 0;
  10233. let propCount = 0;
  10234. /* istanbul ignore if */
  10235. if (expectedType === TRANSITION) {
  10236. if (transitionTimeout > 0) {
  10237. type = TRANSITION;
  10238. timeout = transitionTimeout;
  10239. propCount = transitionDurations.length;
  10240. }
  10241. }
  10242. else if (expectedType === ANIMATION) {
  10243. if (animationTimeout > 0) {
  10244. type = ANIMATION;
  10245. timeout = animationTimeout;
  10246. propCount = animationDurations.length;
  10247. }
  10248. }
  10249. else {
  10250. timeout = Math.max(transitionTimeout, animationTimeout);
  10251. type =
  10252. timeout > 0
  10253. ? transitionTimeout > animationTimeout
  10254. ? TRANSITION
  10255. : ANIMATION
  10256. : null;
  10257. propCount = type
  10258. ? type === TRANSITION
  10259. ? transitionDurations.length
  10260. : animationDurations.length
  10261. : 0;
  10262. }
  10263. const hasTransform = type === TRANSITION &&
  10264. /\b(transform|all)(,|$)/.test(getStyleProperties(`${TRANSITION}Property`).toString());
  10265. return {
  10266. type,
  10267. timeout,
  10268. propCount,
  10269. hasTransform
  10270. };
  10271. }
  10272. function getTimeout(delays, durations) {
  10273. while (delays.length < durations.length) {
  10274. delays = delays.concat(delays);
  10275. }
  10276. return Math.max(...durations.map((d, i) => toMs(d) + toMs(delays[i])));
  10277. }
  10278. // Old versions of Chromium (below 61.0.3163.100) formats floating pointer
  10279. // numbers in a locale-dependent way, using a comma instead of a dot.
  10280. // If comma is not replaced with a dot, the input will be rounded down
  10281. // (i.e. acting as a floor function) causing unexpected behaviors
  10282. function toMs(s) {
  10283. return Number(s.slice(0, -1).replace(',', '.')) * 1000;
  10284. }
  10285. // synchronously force layout to put elements into a certain state
  10286. function forceReflow() {
  10287. return document.body.offsetHeight;
  10288. }
  10289. const positionMap = new WeakMap();
  10290. const newPositionMap = new WeakMap();
  10291. const TransitionGroupImpl = {
  10292. name: 'TransitionGroup',
  10293. props: /*#__PURE__*/ shared.extend({}, TransitionPropsValidators, {
  10294. tag: String,
  10295. moveClass: String
  10296. }),
  10297. setup(props, { slots }) {
  10298. const instance = getCurrentInstance();
  10299. const state = useTransitionState();
  10300. let prevChildren;
  10301. let children;
  10302. onUpdated(() => {
  10303. // children is guaranteed to exist after initial render
  10304. if (!prevChildren.length) {
  10305. return;
  10306. }
  10307. const moveClass = props.moveClass || `${props.name || 'v'}-move`;
  10308. if (!hasCSSTransform(prevChildren[0].el, instance.vnode.el, moveClass)) {
  10309. return;
  10310. }
  10311. // we divide the work into three loops to avoid mixing DOM reads and writes
  10312. // in each iteration - which helps prevent layout thrashing.
  10313. prevChildren.forEach(callPendingCbs);
  10314. prevChildren.forEach(recordPosition);
  10315. const movedChildren = prevChildren.filter(applyTranslation);
  10316. // force reflow to put everything in position
  10317. forceReflow();
  10318. movedChildren.forEach(c => {
  10319. const el = c.el;
  10320. const style = el.style;
  10321. addTransitionClass(el, moveClass);
  10322. style.transform = style.webkitTransform = style.transitionDuration = '';
  10323. const cb = (el._moveCb = (e) => {
  10324. if (e && e.target !== el) {
  10325. return;
  10326. }
  10327. if (!e || /transform$/.test(e.propertyName)) {
  10328. el.removeEventListener('transitionend', cb);
  10329. el._moveCb = null;
  10330. removeTransitionClass(el, moveClass);
  10331. }
  10332. });
  10333. el.addEventListener('transitionend', cb);
  10334. });
  10335. });
  10336. return () => {
  10337. const rawProps = toRaw(props);
  10338. const cssTransitionProps = resolveTransitionProps(rawProps);
  10339. let tag = rawProps.tag || Fragment;
  10340. prevChildren = children;
  10341. children = slots.default ? getTransitionRawChildren(slots.default()) : [];
  10342. for (let i = 0; i < children.length; i++) {
  10343. const child = children[i];
  10344. if (child.key != null) {
  10345. setTransitionHooks(child, resolveTransitionHooks(child, cssTransitionProps, state, instance));
  10346. }
  10347. else {
  10348. warn(`<TransitionGroup> children must be keyed.`);
  10349. }
  10350. }
  10351. if (prevChildren) {
  10352. for (let i = 0; i < prevChildren.length; i++) {
  10353. const child = prevChildren[i];
  10354. setTransitionHooks(child, resolveTransitionHooks(child, cssTransitionProps, state, instance));
  10355. positionMap.set(child, child.el.getBoundingClientRect());
  10356. }
  10357. }
  10358. return createVNode(tag, null, children);
  10359. };
  10360. }
  10361. };
  10362. /**
  10363. * TransitionGroup does not support "mode" so we need to remove it from the
  10364. * props declarations, but direct delete operation is considered a side effect
  10365. * and will make the entire transition feature non-tree-shakeable, so we do it
  10366. * in a function and mark the function's invocation as pure.
  10367. */
  10368. const removeMode = (props) => delete props.mode;
  10369. /*#__PURE__*/ removeMode(TransitionGroupImpl.props);
  10370. const TransitionGroup = TransitionGroupImpl;
  10371. function callPendingCbs(c) {
  10372. const el = c.el;
  10373. if (el._moveCb) {
  10374. el._moveCb();
  10375. }
  10376. if (el._enterCb) {
  10377. el._enterCb();
  10378. }
  10379. }
  10380. function recordPosition(c) {
  10381. newPositionMap.set(c, c.el.getBoundingClientRect());
  10382. }
  10383. function applyTranslation(c) {
  10384. const oldPos = positionMap.get(c);
  10385. const newPos = newPositionMap.get(c);
  10386. const dx = oldPos.left - newPos.left;
  10387. const dy = oldPos.top - newPos.top;
  10388. if (dx || dy) {
  10389. const s = c.el.style;
  10390. s.transform = s.webkitTransform = `translate(${dx}px,${dy}px)`;
  10391. s.transitionDuration = '0s';
  10392. return c;
  10393. }
  10394. }
  10395. function hasCSSTransform(el, root, moveClass) {
  10396. // Detect whether an element with the move class applied has
  10397. // CSS transitions. Since the element may be inside an entering
  10398. // transition at this very moment, we make a clone of it and remove
  10399. // all other transition classes applied to ensure only the move class
  10400. // is applied.
  10401. const clone = el.cloneNode();
  10402. if (el._vtc) {
  10403. el._vtc.forEach(cls => {
  10404. cls.split(/\s+/).forEach(c => c && clone.classList.remove(c));
  10405. });
  10406. }
  10407. moveClass.split(/\s+/).forEach(c => c && clone.classList.add(c));
  10408. clone.style.display = 'none';
  10409. const container = (root.nodeType === 1 ? root : root.parentNode);
  10410. container.appendChild(clone);
  10411. const { hasTransform } = getTransitionInfo(clone);
  10412. container.removeChild(clone);
  10413. return hasTransform;
  10414. }
  10415. const getModelAssigner = (vnode) => {
  10416. const fn = vnode.props['onUpdate:modelValue'] ||
  10417. (false );
  10418. return shared.isArray(fn) ? value => shared.invokeArrayFns(fn, value) : fn;
  10419. };
  10420. function onCompositionStart(e) {
  10421. e.target.composing = true;
  10422. }
  10423. function onCompositionEnd(e) {
  10424. const target = e.target;
  10425. if (target.composing) {
  10426. target.composing = false;
  10427. target.dispatchEvent(new Event('input'));
  10428. }
  10429. }
  10430. // We are exporting the v-model runtime directly as vnode hooks so that it can
  10431. // be tree-shaken in case v-model is never used.
  10432. const vModelText = {
  10433. created(el, { modifiers: { lazy, trim, number } }, vnode) {
  10434. el._assign = getModelAssigner(vnode);
  10435. const castToNumber = number || (vnode.props && vnode.props.type === 'number');
  10436. addEventListener(el, lazy ? 'change' : 'input', e => {
  10437. if (e.target.composing)
  10438. return;
  10439. let domValue = el.value;
  10440. if (trim) {
  10441. domValue = domValue.trim();
  10442. }
  10443. if (castToNumber) {
  10444. domValue = shared.looseToNumber(domValue);
  10445. }
  10446. el._assign(domValue);
  10447. });
  10448. if (trim) {
  10449. addEventListener(el, 'change', () => {
  10450. el.value = el.value.trim();
  10451. });
  10452. }
  10453. if (!lazy) {
  10454. addEventListener(el, 'compositionstart', onCompositionStart);
  10455. addEventListener(el, 'compositionend', onCompositionEnd);
  10456. // Safari < 10.2 & UIWebView doesn't fire compositionend when
  10457. // switching focus before confirming composition choice
  10458. // this also fixes the issue where some browsers e.g. iOS Chrome
  10459. // fires "change" instead of "input" on autocomplete.
  10460. addEventListener(el, 'change', onCompositionEnd);
  10461. }
  10462. },
  10463. // set value on mounted so it's after min/max for type="range"
  10464. mounted(el, { value }) {
  10465. el.value = value == null ? '' : value;
  10466. },
  10467. beforeUpdate(el, { value, modifiers: { lazy, trim, number } }, vnode) {
  10468. el._assign = getModelAssigner(vnode);
  10469. // avoid clearing unresolved text. #2302
  10470. if (el.composing)
  10471. return;
  10472. if (document.activeElement === el && el.type !== 'range') {
  10473. if (lazy) {
  10474. return;
  10475. }
  10476. if (trim && el.value.trim() === value) {
  10477. return;
  10478. }
  10479. if ((number || el.type === 'number') &&
  10480. shared.looseToNumber(el.value) === value) {
  10481. return;
  10482. }
  10483. }
  10484. const newValue = value == null ? '' : value;
  10485. if (el.value !== newValue) {
  10486. el.value = newValue;
  10487. }
  10488. }
  10489. };
  10490. const vModelCheckbox = {
  10491. // #4096 array checkboxes need to be deep traversed
  10492. deep: true,
  10493. created(el, _, vnode) {
  10494. el._assign = getModelAssigner(vnode);
  10495. addEventListener(el, 'change', () => {
  10496. const modelValue = el._modelValue;
  10497. const elementValue = getValue(el);
  10498. const checked = el.checked;
  10499. const assign = el._assign;
  10500. if (shared.isArray(modelValue)) {
  10501. const index = shared.looseIndexOf(modelValue, elementValue);
  10502. const found = index !== -1;
  10503. if (checked && !found) {
  10504. assign(modelValue.concat(elementValue));
  10505. }
  10506. else if (!checked && found) {
  10507. const filtered = [...modelValue];
  10508. filtered.splice(index, 1);
  10509. assign(filtered);
  10510. }
  10511. }
  10512. else if (shared.isSet(modelValue)) {
  10513. const cloned = new Set(modelValue);
  10514. if (checked) {
  10515. cloned.add(elementValue);
  10516. }
  10517. else {
  10518. cloned.delete(elementValue);
  10519. }
  10520. assign(cloned);
  10521. }
  10522. else {
  10523. assign(getCheckboxValue(el, checked));
  10524. }
  10525. });
  10526. },
  10527. // set initial checked on mount to wait for true-value/false-value
  10528. mounted: setChecked,
  10529. beforeUpdate(el, binding, vnode) {
  10530. el._assign = getModelAssigner(vnode);
  10531. setChecked(el, binding, vnode);
  10532. }
  10533. };
  10534. function setChecked(el, { value, oldValue }, vnode) {
  10535. el._modelValue = value;
  10536. if (shared.isArray(value)) {
  10537. el.checked = shared.looseIndexOf(value, vnode.props.value) > -1;
  10538. }
  10539. else if (shared.isSet(value)) {
  10540. el.checked = value.has(vnode.props.value);
  10541. }
  10542. else if (value !== oldValue) {
  10543. el.checked = shared.looseEqual(value, getCheckboxValue(el, true));
  10544. }
  10545. }
  10546. const vModelRadio = {
  10547. created(el, { value }, vnode) {
  10548. el.checked = shared.looseEqual(value, vnode.props.value);
  10549. el._assign = getModelAssigner(vnode);
  10550. addEventListener(el, 'change', () => {
  10551. el._assign(getValue(el));
  10552. });
  10553. },
  10554. beforeUpdate(el, { value, oldValue }, vnode) {
  10555. el._assign = getModelAssigner(vnode);
  10556. if (value !== oldValue) {
  10557. el.checked = shared.looseEqual(value, vnode.props.value);
  10558. }
  10559. }
  10560. };
  10561. const vModelSelect = {
  10562. // <select multiple> value need to be deep traversed
  10563. deep: true,
  10564. created(el, { value, modifiers: { number } }, vnode) {
  10565. const isSetModel = shared.isSet(value);
  10566. addEventListener(el, 'change', () => {
  10567. const selectedVal = Array.prototype.filter
  10568. .call(el.options, (o) => o.selected)
  10569. .map((o) => number ? shared.looseToNumber(getValue(o)) : getValue(o));
  10570. el._assign(el.multiple
  10571. ? isSetModel
  10572. ? new Set(selectedVal)
  10573. : selectedVal
  10574. : selectedVal[0]);
  10575. });
  10576. el._assign = getModelAssigner(vnode);
  10577. },
  10578. // set value in mounted & updated because <select> relies on its children
  10579. // <option>s.
  10580. mounted(el, { value }) {
  10581. setSelected(el, value);
  10582. },
  10583. beforeUpdate(el, _binding, vnode) {
  10584. el._assign = getModelAssigner(vnode);
  10585. },
  10586. updated(el, { value }) {
  10587. setSelected(el, value);
  10588. }
  10589. };
  10590. function setSelected(el, value) {
  10591. const isMultiple = el.multiple;
  10592. if (isMultiple && !shared.isArray(value) && !shared.isSet(value)) {
  10593. warn(`<select multiple v-model> expects an Array or Set value for its binding, ` +
  10594. `but got ${Object.prototype.toString.call(value).slice(8, -1)}.`);
  10595. return;
  10596. }
  10597. for (let i = 0, l = el.options.length; i < l; i++) {
  10598. const option = el.options[i];
  10599. const optionValue = getValue(option);
  10600. if (isMultiple) {
  10601. if (shared.isArray(value)) {
  10602. option.selected = shared.looseIndexOf(value, optionValue) > -1;
  10603. }
  10604. else {
  10605. option.selected = value.has(optionValue);
  10606. }
  10607. }
  10608. else {
  10609. if (shared.looseEqual(getValue(option), value)) {
  10610. if (el.selectedIndex !== i)
  10611. el.selectedIndex = i;
  10612. return;
  10613. }
  10614. }
  10615. }
  10616. if (!isMultiple && el.selectedIndex !== -1) {
  10617. el.selectedIndex = -1;
  10618. }
  10619. }
  10620. // retrieve raw value set via :value bindings
  10621. function getValue(el) {
  10622. return '_value' in el ? el._value : el.value;
  10623. }
  10624. // retrieve raw value for true-value and false-value set via :true-value or :false-value bindings
  10625. function getCheckboxValue(el, checked) {
  10626. const key = checked ? '_trueValue' : '_falseValue';
  10627. return key in el ? el[key] : checked;
  10628. }
  10629. const vModelDynamic = {
  10630. created(el, binding, vnode) {
  10631. callModelHook(el, binding, vnode, null, 'created');
  10632. },
  10633. mounted(el, binding, vnode) {
  10634. callModelHook(el, binding, vnode, null, 'mounted');
  10635. },
  10636. beforeUpdate(el, binding, vnode, prevVNode) {
  10637. callModelHook(el, binding, vnode, prevVNode, 'beforeUpdate');
  10638. },
  10639. updated(el, binding, vnode, prevVNode) {
  10640. callModelHook(el, binding, vnode, prevVNode, 'updated');
  10641. }
  10642. };
  10643. function resolveDynamicModel(tagName, type) {
  10644. switch (tagName) {
  10645. case 'SELECT':
  10646. return vModelSelect;
  10647. case 'TEXTAREA':
  10648. return vModelText;
  10649. default:
  10650. switch (type) {
  10651. case 'checkbox':
  10652. return vModelCheckbox;
  10653. case 'radio':
  10654. return vModelRadio;
  10655. default:
  10656. return vModelText;
  10657. }
  10658. }
  10659. }
  10660. function callModelHook(el, binding, vnode, prevVNode, hook) {
  10661. const modelToUse = resolveDynamicModel(el.tagName, vnode.props && vnode.props.type);
  10662. const fn = modelToUse[hook];
  10663. fn && fn(el, binding, vnode, prevVNode);
  10664. }
  10665. // SSR vnode transforms, only used when user includes client-oriented render
  10666. // function in SSR
  10667. function initVModelForSSR() {
  10668. vModelText.getSSRProps = ({ value }) => ({ value });
  10669. vModelRadio.getSSRProps = ({ value }, vnode) => {
  10670. if (vnode.props && shared.looseEqual(vnode.props.value, value)) {
  10671. return { checked: true };
  10672. }
  10673. };
  10674. vModelCheckbox.getSSRProps = ({ value }, vnode) => {
  10675. if (shared.isArray(value)) {
  10676. if (vnode.props && shared.looseIndexOf(value, vnode.props.value) > -1) {
  10677. return { checked: true };
  10678. }
  10679. }
  10680. else if (shared.isSet(value)) {
  10681. if (vnode.props && value.has(vnode.props.value)) {
  10682. return { checked: true };
  10683. }
  10684. }
  10685. else if (value) {
  10686. return { checked: true };
  10687. }
  10688. };
  10689. vModelDynamic.getSSRProps = (binding, vnode) => {
  10690. if (typeof vnode.type !== 'string') {
  10691. return;
  10692. }
  10693. const modelToUse = resolveDynamicModel(
  10694. // resolveDynamicModel expects an uppercase tag name, but vnode.type is lowercase
  10695. vnode.type.toUpperCase(), vnode.props && vnode.props.type);
  10696. if (modelToUse.getSSRProps) {
  10697. return modelToUse.getSSRProps(binding, vnode);
  10698. }
  10699. };
  10700. }
  10701. const systemModifiers = ['ctrl', 'shift', 'alt', 'meta'];
  10702. const modifierGuards = {
  10703. stop: e => e.stopPropagation(),
  10704. prevent: e => e.preventDefault(),
  10705. self: e => e.target !== e.currentTarget,
  10706. ctrl: e => !e.ctrlKey,
  10707. shift: e => !e.shiftKey,
  10708. alt: e => !e.altKey,
  10709. meta: e => !e.metaKey,
  10710. left: e => 'button' in e && e.button !== 0,
  10711. middle: e => 'button' in e && e.button !== 1,
  10712. right: e => 'button' in e && e.button !== 2,
  10713. exact: (e, modifiers) => systemModifiers.some(m => e[`${m}Key`] && !modifiers.includes(m))
  10714. };
  10715. /**
  10716. * @private
  10717. */
  10718. const withModifiers = (fn, modifiers) => {
  10719. return (event, ...args) => {
  10720. for (let i = 0; i < modifiers.length; i++) {
  10721. const guard = modifierGuards[modifiers[i]];
  10722. if (guard && guard(event, modifiers))
  10723. return;
  10724. }
  10725. return fn(event, ...args);
  10726. };
  10727. };
  10728. // Kept for 2.x compat.
  10729. // Note: IE11 compat for `spacebar` and `del` is removed for now.
  10730. const keyNames = {
  10731. esc: 'escape',
  10732. space: ' ',
  10733. up: 'arrow-up',
  10734. left: 'arrow-left',
  10735. right: 'arrow-right',
  10736. down: 'arrow-down',
  10737. delete: 'backspace'
  10738. };
  10739. /**
  10740. * @private
  10741. */
  10742. const withKeys = (fn, modifiers) => {
  10743. return (event) => {
  10744. if (!('key' in event)) {
  10745. return;
  10746. }
  10747. const eventKey = shared.hyphenate(event.key);
  10748. if (modifiers.some(k => k === eventKey || keyNames[k] === eventKey)) {
  10749. return fn(event);
  10750. }
  10751. };
  10752. };
  10753. const vShow = {
  10754. beforeMount(el, { value }, { transition }) {
  10755. el._vod = el.style.display === 'none' ? '' : el.style.display;
  10756. if (transition && value) {
  10757. transition.beforeEnter(el);
  10758. }
  10759. else {
  10760. setDisplay(el, value);
  10761. }
  10762. },
  10763. mounted(el, { value }, { transition }) {
  10764. if (transition && value) {
  10765. transition.enter(el);
  10766. }
  10767. },
  10768. updated(el, { value, oldValue }, { transition }) {
  10769. if (!value === !oldValue)
  10770. return;
  10771. if (transition) {
  10772. if (value) {
  10773. transition.beforeEnter(el);
  10774. setDisplay(el, true);
  10775. transition.enter(el);
  10776. }
  10777. else {
  10778. transition.leave(el, () => {
  10779. setDisplay(el, false);
  10780. });
  10781. }
  10782. }
  10783. else {
  10784. setDisplay(el, value);
  10785. }
  10786. },
  10787. beforeUnmount(el, { value }) {
  10788. setDisplay(el, value);
  10789. }
  10790. };
  10791. function setDisplay(el, value) {
  10792. el.style.display = value ? el._vod : 'none';
  10793. }
  10794. // SSR vnode transforms, only used when user includes client-oriented render
  10795. // function in SSR
  10796. function initVShowForSSR() {
  10797. vShow.getSSRProps = ({ value }) => {
  10798. if (!value) {
  10799. return { style: { display: 'none' } };
  10800. }
  10801. };
  10802. }
  10803. // fixed by xxxxxx
  10804. const rendererOptions = /*#__PURE__*/ shared.extend({ patchProp, forcePatchProp }, nodeOps);
  10805. // lazy create the renderer - this makes core renderer logic tree-shakable
  10806. // in case the user only imports reactivity utilities from Vue.
  10807. let renderer;
  10808. let enabledHydration = false;
  10809. function ensureRenderer() {
  10810. return (renderer ||
  10811. (renderer = createRenderer(rendererOptions)));
  10812. }
  10813. function ensureHydrationRenderer() {
  10814. renderer = enabledHydration
  10815. ? renderer
  10816. : createHydrationRenderer(rendererOptions);
  10817. enabledHydration = true;
  10818. return renderer;
  10819. }
  10820. // use explicit type casts here to avoid import() calls in rolled-up d.ts
  10821. const render = ((...args) => {
  10822. ensureRenderer().render(...args);
  10823. });
  10824. const hydrate = ((...args) => {
  10825. ensureHydrationRenderer().hydrate(...args);
  10826. });
  10827. const createApp = ((...args) => {
  10828. const app = ensureRenderer().createApp(...args);
  10829. {
  10830. injectNativeTagCheck(app);
  10831. injectCompilerOptionsCheck(app);
  10832. }
  10833. const { mount } = app;
  10834. app.mount = (containerOrSelector) => {
  10835. const container = normalizeContainer(containerOrSelector);
  10836. if (!container)
  10837. return;
  10838. const component = app._component;
  10839. if (!shared.isFunction(component) && !component.render && !component.template) {
  10840. // __UNSAFE__
  10841. // Reason: potential execution of JS expressions in in-DOM template.
  10842. // The user must make sure the in-DOM template is trusted. If it's
  10843. // rendered by the server, the template should not contain any user data.
  10844. component.template = container.innerHTML;
  10845. }
  10846. // clear content before mounting
  10847. container.innerHTML = '';
  10848. const proxy = mount(container, false, container instanceof SVGElement);
  10849. if (container instanceof Element) {
  10850. container.removeAttribute('v-cloak');
  10851. container.setAttribute('data-v-app', '');
  10852. }
  10853. return proxy;
  10854. };
  10855. return app;
  10856. });
  10857. const createSSRApp = ((...args) => {
  10858. const app = ensureHydrationRenderer().createApp(...args);
  10859. {
  10860. injectNativeTagCheck(app);
  10861. injectCompilerOptionsCheck(app);
  10862. }
  10863. const { mount } = app;
  10864. app.mount = (containerOrSelector) => {
  10865. const container = normalizeContainer(containerOrSelector);
  10866. if (container) {
  10867. return mount(container, true, container instanceof SVGElement);
  10868. }
  10869. };
  10870. return app;
  10871. });
  10872. function injectNativeTagCheck(app) {
  10873. // Inject `isNativeTag`
  10874. // this is used for component name validation (dev only)
  10875. Object.defineProperty(app.config, 'isNativeTag', {
  10876. value: (tag) => shared.isHTMLTag(tag) || shared.isSVGTag(tag),
  10877. writable: false
  10878. });
  10879. }
  10880. // dev only
  10881. function injectCompilerOptionsCheck(app) {
  10882. if (isRuntimeOnly()) {
  10883. const isCustomElement = app.config.isCustomElement;
  10884. Object.defineProperty(app.config, 'isCustomElement', {
  10885. get() {
  10886. return isCustomElement;
  10887. },
  10888. set() {
  10889. warn(`The \`isCustomElement\` config option is deprecated. Use ` +
  10890. `\`compilerOptions.isCustomElement\` instead.`);
  10891. }
  10892. });
  10893. const compilerOptions = app.config.compilerOptions;
  10894. const msg = `The \`compilerOptions\` config option is only respected when using ` +
  10895. `a build of Vue.js that includes the runtime compiler (aka "full build"). ` +
  10896. `Since you are using the runtime-only build, \`compilerOptions\` ` +
  10897. `must be passed to \`@vue/compiler-dom\` in the build setup instead.\n` +
  10898. `- For vue-loader: pass it via vue-loader's \`compilerOptions\` loader option.\n` +
  10899. `- For vue-cli: see https://cli.vuejs.org/guide/webpack.html#modifying-options-of-a-loader\n` +
  10900. `- 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`;
  10901. Object.defineProperty(app.config, 'compilerOptions', {
  10902. get() {
  10903. warn(msg);
  10904. return compilerOptions;
  10905. },
  10906. set() {
  10907. warn(msg);
  10908. }
  10909. });
  10910. }
  10911. }
  10912. function normalizeContainer(container) {
  10913. if (shared.isString(container)) {
  10914. const res = document.querySelector(container);
  10915. if (!res) {
  10916. warn(`Failed to mount app: mount target selector "${container}" returned null.`);
  10917. }
  10918. return res;
  10919. }
  10920. if (window.ShadowRoot &&
  10921. container instanceof window.ShadowRoot &&
  10922. container.mode === 'closed') {
  10923. warn(`mounting on a ShadowRoot with \`{mode: "closed"}\` may lead to unpredictable bugs`);
  10924. }
  10925. return container;
  10926. }
  10927. let ssrDirectiveInitialized = false;
  10928. /**
  10929. * @internal
  10930. */
  10931. const initDirectivesForSSR = () => {
  10932. if (!ssrDirectiveInitialized) {
  10933. ssrDirectiveInitialized = true;
  10934. initVModelForSSR();
  10935. initVShowForSSR();
  10936. }
  10937. }
  10938. ;
  10939. // This entry exports the runtime only, and is built as
  10940. const compile = () => {
  10941. {
  10942. warn(`Runtime compilation is not supported in this build of Vue.` +
  10943. (``) /* should not happen */);
  10944. }
  10945. };
  10946. exports.camelize = shared.camelize;
  10947. exports.capitalize = shared.capitalize;
  10948. exports.toDisplayString = shared.toDisplayString;
  10949. exports.toHandlerKey = shared.toHandlerKey;
  10950. exports.normalizeClass = uniShared.normalizeClass;
  10951. exports.normalizeProps = uniShared.normalizeProps;
  10952. exports.normalizeStyle = uniShared.normalizeStyle;
  10953. exports.BaseTransition = BaseTransition;
  10954. exports.BaseTransitionPropsValidators = BaseTransitionPropsValidators;
  10955. exports.Comment = Comment;
  10956. exports.EffectScope = EffectScope;
  10957. exports.Fragment = Fragment;
  10958. exports.KeepAlive = KeepAlive;
  10959. exports.ReactiveEffect = ReactiveEffect;
  10960. exports.Static = Static;
  10961. exports.Suspense = Suspense;
  10962. exports.Teleport = Teleport;
  10963. exports.Text = Text;
  10964. exports.Transition = Transition;
  10965. exports.TransitionGroup = TransitionGroup;
  10966. exports.VueElement = VueElement;
  10967. exports.assertNumber = assertNumber;
  10968. exports.callWithAsyncErrorHandling = callWithAsyncErrorHandling;
  10969. exports.callWithErrorHandling = callWithErrorHandling;
  10970. exports.cloneVNode = cloneVNode;
  10971. exports.compatUtils = compatUtils;
  10972. exports.compile = compile;
  10973. exports.computed = computed;
  10974. exports.createApp = createApp;
  10975. exports.createBlock = createBlock;
  10976. exports.createCommentVNode = createCommentVNode;
  10977. exports.createElementBlock = createElementBlock;
  10978. exports.createElementVNode = createBaseVNode;
  10979. exports.createHydrationRenderer = createHydrationRenderer;
  10980. exports.createPropsRestProxy = createPropsRestProxy;
  10981. exports.createRenderer = createRenderer;
  10982. exports.createSSRApp = createSSRApp;
  10983. exports.createSlots = createSlots;
  10984. exports.createStaticVNode = createStaticVNode;
  10985. exports.createTextVNode = createTextVNode;
  10986. exports.createVNode = createVNode;
  10987. exports.createVueApp = createApp;
  10988. exports.customRef = customRef;
  10989. exports.defineAsyncComponent = defineAsyncComponent;
  10990. exports.defineComponent = defineComponent;
  10991. exports.defineCustomElement = defineCustomElement;
  10992. exports.defineEmits = defineEmits;
  10993. exports.defineExpose = defineExpose;
  10994. exports.defineProps = defineProps;
  10995. exports.defineSSRCustomElement = defineSSRCustomElement;
  10996. exports.effect = effect;
  10997. exports.effectScope = effectScope;
  10998. exports.getCurrentInstance = getCurrentInstance;
  10999. exports.getCurrentScope = getCurrentScope;
  11000. exports.getTransitionRawChildren = getTransitionRawChildren;
  11001. exports.guardReactiveProps = guardReactiveProps;
  11002. exports.h = h;
  11003. exports.handleError = handleError;
  11004. exports.hydrate = hydrate;
  11005. exports.initCustomFormatter = initCustomFormatter;
  11006. exports.initDirectivesForSSR = initDirectivesForSSR;
  11007. exports.inject = inject;
  11008. exports.injectHook = injectHook;
  11009. exports.isMemoSame = isMemoSame;
  11010. exports.isProxy = isProxy;
  11011. exports.isReactive = isReactive;
  11012. exports.isReadonly = isReadonly;
  11013. exports.isRef = isRef;
  11014. exports.isRuntimeOnly = isRuntimeOnly;
  11015. exports.isShallow = isShallow;
  11016. exports.isVNode = isVNode;
  11017. exports.markRaw = markRaw;
  11018. exports.mergeDefaults = mergeDefaults;
  11019. exports.mergeProps = mergeProps;
  11020. exports.nextTick = nextTick;
  11021. exports.onActivated = onActivated;
  11022. exports.onBeforeActivate = onBeforeActivate;
  11023. exports.onBeforeDeactivate = onBeforeDeactivate;
  11024. exports.onBeforeMount = onBeforeMount;
  11025. exports.onBeforeUnmount = onBeforeUnmount;
  11026. exports.onBeforeUpdate = onBeforeUpdate;
  11027. exports.onDeactivated = onDeactivated;
  11028. exports.onErrorCaptured = onErrorCaptured;
  11029. exports.onMounted = onMounted;
  11030. exports.onRenderTracked = onRenderTracked;
  11031. exports.onRenderTriggered = onRenderTriggered;
  11032. exports.onScopeDispose = onScopeDispose;
  11033. exports.onServerPrefetch = onServerPrefetch;
  11034. exports.onUnmounted = onUnmounted;
  11035. exports.onUpdated = onUpdated;
  11036. exports.openBlock = openBlock;
  11037. exports.popScopeId = popScopeId;
  11038. exports.provide = provide;
  11039. exports.proxyRefs = proxyRefs;
  11040. exports.pushScopeId = pushScopeId;
  11041. exports.queuePostFlushCb = queuePostFlushCb;
  11042. exports.reactive = reactive;
  11043. exports.readonly = readonly;
  11044. exports.ref = ref;
  11045. exports.registerRuntimeCompiler = registerRuntimeCompiler;
  11046. exports.render = render;
  11047. exports.renderList = renderList;
  11048. exports.renderSlot = renderSlot;
  11049. exports.resolveComponent = resolveComponent;
  11050. exports.resolveDirective = resolveDirective;
  11051. exports.resolveDynamicComponent = resolveDynamicComponent;
  11052. exports.resolveFilter = resolveFilter;
  11053. exports.resolveTransitionHooks = resolveTransitionHooks;
  11054. exports.setBlockTracking = setBlockTracking;
  11055. exports.setDevtoolsHook = setDevtoolsHook;
  11056. exports.setTransitionHooks = setTransitionHooks;
  11057. exports.shallowReactive = shallowReactive;
  11058. exports.shallowReadonly = shallowReadonly;
  11059. exports.shallowRef = shallowRef;
  11060. exports.ssrContextKey = ssrContextKey;
  11061. exports.ssrUtils = ssrUtils;
  11062. exports.stop = stop;
  11063. exports.toHandlers = toHandlers;
  11064. exports.toRaw = toRaw;
  11065. exports.toRef = toRef;
  11066. exports.toRefs = toRefs;
  11067. exports.transformVNodeArgs = transformVNodeArgs;
  11068. exports.triggerRef = triggerRef;
  11069. exports.unref = unref;
  11070. exports.useAttrs = useAttrs;
  11071. exports.useCssModule = useCssModule;
  11072. exports.useCssVars = useCssVars;
  11073. exports.useSSRContext = useSSRContext;
  11074. exports.useSlots = useSlots;
  11075. exports.useTransitionState = useTransitionState;
  11076. exports.vModelCheckbox = vModelCheckbox;
  11077. exports.vModelDynamic = vModelDynamic;
  11078. exports.vModelRadio = vModelRadio;
  11079. exports.vModelSelect = vModelSelect;
  11080. exports.vModelText = vModelText;
  11081. exports.vShow = vShow;
  11082. exports.version = version;
  11083. exports.warn = warn;
  11084. exports.watch = watch;
  11085. exports.watchEffect = watchEffect;
  11086. exports.watchPostEffect = watchPostEffect;
  11087. exports.watchSyncEffect = watchSyncEffect;
  11088. exports.withAsyncContext = withAsyncContext;
  11089. exports.withCtx = withCtx;
  11090. exports.withDefaults = withDefaults;
  11091. exports.withDirectives = withDirectives;
  11092. exports.withKeys = withKeys;
  11093. exports.withMemo = withMemo;
  11094. exports.withModifiers = withModifiers;
  11095. exports.withScopeId = withScopeId;