vue.runtime.esm.js 208 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988
  1. import { isRootHook, getValueByDataPath, isUniLifecycleHook, ON_ERROR, UniLifecycleHooks, invokeCreateErrorHandler, dynamicSlotName } from '@dcloudio/uni-shared';
  2. import { extend, isObject, def, hasChanged, isArray, isString, isFunction, isPromise, EMPTY_OBJ, remove, toHandlerKey, camelize, capitalize, hasOwn, hyphenate, isReservedProp, toRawType, normalizeClass, normalizeStyle, isOn, toTypeString, NOOP, isMap, isIntegerKey, isSet, isPlainObject, makeMap, invokeArrayFns, NO, isSymbol, looseToNumber, isBuiltInDirective, EMPTY_ARR, isModelListener, toNumber, toDisplayString } from '@vue/shared';
  3. export { EMPTY_OBJ, camelize, normalizeClass, normalizeProps, normalizeStyle, toDisplayString, toHandlerKey } from '@vue/shared';
  4. function warn$1(msg, ...args) {
  5. console.warn(`[Vue warn] ${msg}`, ...args);
  6. }
  7. let activeEffectScope;
  8. class EffectScope {
  9. constructor(detached = false) {
  10. this.detached = detached;
  11. /**
  12. * @internal
  13. */
  14. this._active = true;
  15. /**
  16. * @internal
  17. */
  18. this.effects = [];
  19. /**
  20. * @internal
  21. */
  22. this.cleanups = [];
  23. this.parent = activeEffectScope;
  24. if (!detached && activeEffectScope) {
  25. this.index =
  26. (activeEffectScope.scopes || (activeEffectScope.scopes = [])).push(this) - 1;
  27. }
  28. }
  29. get active() {
  30. return this._active;
  31. }
  32. run(fn) {
  33. if (this._active) {
  34. const currentEffectScope = activeEffectScope;
  35. try {
  36. activeEffectScope = this;
  37. return fn();
  38. }
  39. finally {
  40. activeEffectScope = currentEffectScope;
  41. }
  42. }
  43. else if ((process.env.NODE_ENV !== 'production')) {
  44. warn$1(`cannot run an inactive effect scope.`);
  45. }
  46. }
  47. /**
  48. * This should only be called on non-detached scopes
  49. * @internal
  50. */
  51. on() {
  52. activeEffectScope = this;
  53. }
  54. /**
  55. * This should only be called on non-detached scopes
  56. * @internal
  57. */
  58. off() {
  59. activeEffectScope = this.parent;
  60. }
  61. stop(fromParent) {
  62. if (this._active) {
  63. let i, l;
  64. for (i = 0, l = this.effects.length; i < l; i++) {
  65. this.effects[i].stop();
  66. }
  67. for (i = 0, l = this.cleanups.length; i < l; i++) {
  68. this.cleanups[i]();
  69. }
  70. if (this.scopes) {
  71. for (i = 0, l = this.scopes.length; i < l; i++) {
  72. this.scopes[i].stop(true);
  73. }
  74. }
  75. // nested scope, dereference from parent to avoid memory leaks
  76. if (!this.detached && this.parent && !fromParent) {
  77. // optimized O(1) removal
  78. const last = this.parent.scopes.pop();
  79. if (last && last !== this) {
  80. this.parent.scopes[this.index] = last;
  81. last.index = this.index;
  82. }
  83. }
  84. this.parent = undefined;
  85. this._active = false;
  86. }
  87. }
  88. }
  89. function effectScope(detached) {
  90. return new EffectScope(detached);
  91. }
  92. function recordEffectScope(effect, scope = activeEffectScope) {
  93. if (scope && scope.active) {
  94. scope.effects.push(effect);
  95. }
  96. }
  97. function getCurrentScope() {
  98. return activeEffectScope;
  99. }
  100. function onScopeDispose(fn) {
  101. if (activeEffectScope) {
  102. activeEffectScope.cleanups.push(fn);
  103. }
  104. else if ((process.env.NODE_ENV !== 'production')) {
  105. warn$1(`onScopeDispose() is called when there is no active effect scope` +
  106. ` to be associated with.`);
  107. }
  108. }
  109. const createDep = (effects) => {
  110. const dep = new Set(effects);
  111. dep.w = 0;
  112. dep.n = 0;
  113. return dep;
  114. };
  115. const wasTracked = (dep) => (dep.w & trackOpBit) > 0;
  116. const newTracked = (dep) => (dep.n & trackOpBit) > 0;
  117. const initDepMarkers = ({ deps }) => {
  118. if (deps.length) {
  119. for (let i = 0; i < deps.length; i++) {
  120. deps[i].w |= trackOpBit; // set was tracked
  121. }
  122. }
  123. };
  124. const finalizeDepMarkers = (effect) => {
  125. const { deps } = effect;
  126. if (deps.length) {
  127. let ptr = 0;
  128. for (let i = 0; i < deps.length; i++) {
  129. const dep = deps[i];
  130. if (wasTracked(dep) && !newTracked(dep)) {
  131. dep.delete(effect);
  132. }
  133. else {
  134. deps[ptr++] = dep;
  135. }
  136. // clear bits
  137. dep.w &= ~trackOpBit;
  138. dep.n &= ~trackOpBit;
  139. }
  140. deps.length = ptr;
  141. }
  142. };
  143. const targetMap = new WeakMap();
  144. // The number of effects currently being tracked recursively.
  145. let effectTrackDepth = 0;
  146. let trackOpBit = 1;
  147. /**
  148. * The bitwise track markers support at most 30 levels of recursion.
  149. * This value is chosen to enable modern JS engines to use a SMI on all platforms.
  150. * When recursion depth is greater, fall back to using a full cleanup.
  151. */
  152. const maxMarkerBits = 30;
  153. let activeEffect;
  154. const ITERATE_KEY = Symbol((process.env.NODE_ENV !== 'production') ? 'iterate' : '');
  155. const MAP_KEY_ITERATE_KEY = Symbol((process.env.NODE_ENV !== 'production') ? 'Map key iterate' : '');
  156. class ReactiveEffect {
  157. constructor(fn, scheduler = null, scope) {
  158. this.fn = fn;
  159. this.scheduler = scheduler;
  160. this.active = true;
  161. this.deps = [];
  162. this.parent = undefined;
  163. recordEffectScope(this, scope);
  164. }
  165. run() {
  166. if (!this.active) {
  167. return this.fn();
  168. }
  169. let parent = activeEffect;
  170. let lastShouldTrack = shouldTrack;
  171. while (parent) {
  172. if (parent === this) {
  173. return;
  174. }
  175. parent = parent.parent;
  176. }
  177. try {
  178. this.parent = activeEffect;
  179. activeEffect = this;
  180. shouldTrack = true;
  181. trackOpBit = 1 << ++effectTrackDepth;
  182. if (effectTrackDepth <= maxMarkerBits) {
  183. initDepMarkers(this);
  184. }
  185. else {
  186. cleanupEffect(this);
  187. }
  188. return this.fn();
  189. }
  190. finally {
  191. if (effectTrackDepth <= maxMarkerBits) {
  192. finalizeDepMarkers(this);
  193. }
  194. trackOpBit = 1 << --effectTrackDepth;
  195. activeEffect = this.parent;
  196. shouldTrack = lastShouldTrack;
  197. this.parent = undefined;
  198. if (this.deferStop) {
  199. this.stop();
  200. }
  201. }
  202. }
  203. stop() {
  204. // stopped while running itself - defer the cleanup
  205. if (activeEffect === this) {
  206. this.deferStop = true;
  207. }
  208. else if (this.active) {
  209. cleanupEffect(this);
  210. if (this.onStop) {
  211. this.onStop();
  212. }
  213. this.active = false;
  214. }
  215. }
  216. }
  217. function cleanupEffect(effect) {
  218. const { deps } = effect;
  219. if (deps.length) {
  220. for (let i = 0; i < deps.length; i++) {
  221. deps[i].delete(effect);
  222. }
  223. deps.length = 0;
  224. }
  225. }
  226. function effect(fn, options) {
  227. if (fn.effect) {
  228. fn = fn.effect.fn;
  229. }
  230. const _effect = new ReactiveEffect(fn);
  231. if (options) {
  232. extend(_effect, options);
  233. if (options.scope)
  234. recordEffectScope(_effect, options.scope);
  235. }
  236. if (!options || !options.lazy) {
  237. _effect.run();
  238. }
  239. const runner = _effect.run.bind(_effect);
  240. runner.effect = _effect;
  241. return runner;
  242. }
  243. function stop(runner) {
  244. runner.effect.stop();
  245. }
  246. let shouldTrack = true;
  247. const trackStack = [];
  248. function pauseTracking() {
  249. trackStack.push(shouldTrack);
  250. shouldTrack = false;
  251. }
  252. function resetTracking() {
  253. const last = trackStack.pop();
  254. shouldTrack = last === undefined ? true : last;
  255. }
  256. function track(target, type, key) {
  257. if (shouldTrack && activeEffect) {
  258. let depsMap = targetMap.get(target);
  259. if (!depsMap) {
  260. targetMap.set(target, (depsMap = new Map()));
  261. }
  262. let dep = depsMap.get(key);
  263. if (!dep) {
  264. depsMap.set(key, (dep = createDep()));
  265. }
  266. const eventInfo = (process.env.NODE_ENV !== 'production')
  267. ? { effect: activeEffect, target, type, key }
  268. : undefined;
  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 ((process.env.NODE_ENV !== 'production') && activeEffect.onTrack) {
  288. activeEffect.onTrack(Object.assign({ effect: activeEffect }, debuggerEventExtraInfo));
  289. }
  290. }
  291. }
  292. function trigger(target, type, key, newValue, oldValue, oldTarget) {
  293. const depsMap = targetMap.get(target);
  294. if (!depsMap) {
  295. // never been tracked
  296. return;
  297. }
  298. let deps = [];
  299. if (type === "clear" /* TriggerOpTypes.CLEAR */) {
  300. // collection being cleared
  301. // trigger all effects for target
  302. deps = [...depsMap.values()];
  303. }
  304. else if (key === 'length' && isArray(target)) {
  305. const newLength = Number(newValue);
  306. depsMap.forEach((dep, key) => {
  307. if (key === 'length' || key >= newLength) {
  308. deps.push(dep);
  309. }
  310. });
  311. }
  312. else {
  313. // schedule runs for SET | ADD | DELETE
  314. if (key !== void 0) {
  315. deps.push(depsMap.get(key));
  316. }
  317. // also run for iteration key on ADD | DELETE | Map.SET
  318. switch (type) {
  319. case "add" /* TriggerOpTypes.ADD */:
  320. if (!isArray(target)) {
  321. deps.push(depsMap.get(ITERATE_KEY));
  322. if (isMap(target)) {
  323. deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
  324. }
  325. }
  326. else if (isIntegerKey(key)) {
  327. // new index added to array -> length changes
  328. deps.push(depsMap.get('length'));
  329. }
  330. break;
  331. case "delete" /* TriggerOpTypes.DELETE */:
  332. if (!isArray(target)) {
  333. deps.push(depsMap.get(ITERATE_KEY));
  334. if (isMap(target)) {
  335. deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
  336. }
  337. }
  338. break;
  339. case "set" /* TriggerOpTypes.SET */:
  340. if (isMap(target)) {
  341. deps.push(depsMap.get(ITERATE_KEY));
  342. }
  343. break;
  344. }
  345. }
  346. const eventInfo = (process.env.NODE_ENV !== 'production')
  347. ? { target, type, key, newValue, oldValue, oldTarget }
  348. : undefined;
  349. if (deps.length === 1) {
  350. if (deps[0]) {
  351. if ((process.env.NODE_ENV !== 'production')) {
  352. triggerEffects(deps[0], eventInfo);
  353. }
  354. else {
  355. triggerEffects(deps[0]);
  356. }
  357. }
  358. }
  359. else {
  360. const effects = [];
  361. for (const dep of deps) {
  362. if (dep) {
  363. effects.push(...dep);
  364. }
  365. }
  366. if ((process.env.NODE_ENV !== 'production')) {
  367. triggerEffects(createDep(effects), eventInfo);
  368. }
  369. else {
  370. triggerEffects(createDep(effects));
  371. }
  372. }
  373. }
  374. function triggerEffects(dep, debuggerEventExtraInfo) {
  375. // spread into array for stabilization
  376. const effects = isArray(dep) ? dep : [...dep];
  377. for (const effect of effects) {
  378. if (effect.computed) {
  379. triggerEffect(effect, debuggerEventExtraInfo);
  380. }
  381. }
  382. for (const effect of effects) {
  383. if (!effect.computed) {
  384. triggerEffect(effect, debuggerEventExtraInfo);
  385. }
  386. }
  387. }
  388. function triggerEffect(effect, debuggerEventExtraInfo) {
  389. if (effect !== activeEffect || effect.allowRecurse) {
  390. if ((process.env.NODE_ENV !== 'production') && effect.onTrigger) {
  391. effect.onTrigger(extend({ effect }, debuggerEventExtraInfo));
  392. }
  393. if (effect.scheduler) {
  394. effect.scheduler();
  395. }
  396. else {
  397. effect.run();
  398. }
  399. }
  400. }
  401. function getDepFromReactive(object, key) {
  402. var _a;
  403. return (_a = targetMap.get(object)) === null || _a === void 0 ? void 0 : _a.get(key);
  404. }
  405. const isNonTrackableKeys = /*#__PURE__*/ makeMap(`__proto__,__v_isRef,__isVue`);
  406. const builtInSymbols = new Set(
  407. /*#__PURE__*/
  408. Object.getOwnPropertyNames(Symbol)
  409. // ios10.x Object.getOwnPropertyNames(Symbol) can enumerate 'arguments' and 'caller'
  410. // but accessing them on Symbol leads to TypeError because Symbol is a strict mode
  411. // function
  412. .filter(key => key !== 'arguments' && key !== 'caller')
  413. .map(key => Symbol[key])
  414. .filter(isSymbol));
  415. const get$1 = /*#__PURE__*/ createGetter();
  416. const shallowGet = /*#__PURE__*/ createGetter(false, true);
  417. const readonlyGet = /*#__PURE__*/ createGetter(true);
  418. const shallowReadonlyGet = /*#__PURE__*/ createGetter(true, true);
  419. const arrayInstrumentations = /*#__PURE__*/ createArrayInstrumentations();
  420. function createArrayInstrumentations() {
  421. const instrumentations = {};
  422. ['includes', 'indexOf', 'lastIndexOf'].forEach(key => {
  423. instrumentations[key] = function (...args) {
  424. const arr = toRaw(this);
  425. for (let i = 0, l = this.length; i < l; i++) {
  426. track(arr, "get" /* TrackOpTypes.GET */, i + '');
  427. }
  428. // we run the method using the original args first (which may be reactive)
  429. const res = arr[key](...args);
  430. if (res === -1 || res === false) {
  431. // if that didn't work, run it again using raw values.
  432. return arr[key](...args.map(toRaw));
  433. }
  434. else {
  435. return res;
  436. }
  437. };
  438. });
  439. ['push', 'pop', 'shift', 'unshift', 'splice'].forEach(key => {
  440. instrumentations[key] = function (...args) {
  441. pauseTracking();
  442. const res = toRaw(this)[key].apply(this, args);
  443. resetTracking();
  444. return res;
  445. };
  446. });
  447. return instrumentations;
  448. }
  449. function hasOwnProperty(key) {
  450. const obj = toRaw(this);
  451. track(obj, "has" /* TrackOpTypes.HAS */, key);
  452. return obj.hasOwnProperty(key);
  453. }
  454. function createGetter(isReadonly = false, shallow = false) {
  455. return function get(target, key, receiver) {
  456. if (key === "__v_isReactive" /* ReactiveFlags.IS_REACTIVE */) {
  457. return !isReadonly;
  458. }
  459. else if (key === "__v_isReadonly" /* ReactiveFlags.IS_READONLY */) {
  460. return isReadonly;
  461. }
  462. else if (key === "__v_isShallow" /* ReactiveFlags.IS_SHALLOW */) {
  463. return shallow;
  464. }
  465. else if (key === "__v_raw" /* ReactiveFlags.RAW */ &&
  466. receiver ===
  467. (isReadonly
  468. ? shallow
  469. ? shallowReadonlyMap
  470. : readonlyMap
  471. : shallow
  472. ? shallowReactiveMap
  473. : reactiveMap).get(target)) {
  474. return target;
  475. }
  476. const targetIsArray = isArray(target);
  477. if (!isReadonly) {
  478. if (targetIsArray && hasOwn(arrayInstrumentations, key)) {
  479. return Reflect.get(arrayInstrumentations, key, receiver);
  480. }
  481. if (key === 'hasOwnProperty') {
  482. return hasOwnProperty;
  483. }
  484. }
  485. const res = Reflect.get(target, key, receiver);
  486. if (isSymbol(key) ? builtInSymbols.has(key) : isNonTrackableKeys(key)) {
  487. return res;
  488. }
  489. if (!isReadonly) {
  490. track(target, "get" /* TrackOpTypes.GET */, key);
  491. }
  492. if (shallow) {
  493. return res;
  494. }
  495. if (isRef(res)) {
  496. // ref unwrapping - skip unwrap for Array + integer key.
  497. return targetIsArray && isIntegerKey(key) ? res : res.value;
  498. }
  499. if (isObject(res)) {
  500. // Convert returned value into a proxy as well. we do the isObject check
  501. // here to avoid invalid value warning. Also need to lazy access readonly
  502. // and reactive here to avoid circular dependency.
  503. return isReadonly ? readonly(res) : reactive(res);
  504. }
  505. return res;
  506. };
  507. }
  508. const set$1 = /*#__PURE__*/ createSetter();
  509. const shallowSet = /*#__PURE__*/ createSetter(true);
  510. function createSetter(shallow = false) {
  511. return function set(target, key, value, receiver) {
  512. let oldValue = target[key];
  513. if (isReadonly(oldValue) && isRef(oldValue) && !isRef(value)) {
  514. return false;
  515. }
  516. if (!shallow) {
  517. if (!isShallow(value) && !isReadonly(value)) {
  518. oldValue = toRaw(oldValue);
  519. value = toRaw(value);
  520. }
  521. if (!isArray(target) && isRef(oldValue) && !isRef(value)) {
  522. oldValue.value = value;
  523. return true;
  524. }
  525. }
  526. const hadKey = isArray(target) && isIntegerKey(key)
  527. ? Number(key) < target.length
  528. : hasOwn(target, key);
  529. const result = Reflect.set(target, key, value, receiver);
  530. // don't trigger if target is something up in the prototype chain of original
  531. if (target === toRaw(receiver)) {
  532. if (!hadKey) {
  533. trigger(target, "add" /* TriggerOpTypes.ADD */, key, value);
  534. }
  535. else if (hasChanged(value, oldValue)) {
  536. trigger(target, "set" /* TriggerOpTypes.SET */, key, value, oldValue);
  537. }
  538. }
  539. return result;
  540. };
  541. }
  542. function deleteProperty(target, key) {
  543. const hadKey = hasOwn(target, key);
  544. const oldValue = target[key];
  545. const result = Reflect.deleteProperty(target, key);
  546. if (result && hadKey) {
  547. trigger(target, "delete" /* TriggerOpTypes.DELETE */, key, undefined, oldValue);
  548. }
  549. return result;
  550. }
  551. function has$1(target, key) {
  552. const result = Reflect.has(target, key);
  553. if (!isSymbol(key) || !builtInSymbols.has(key)) {
  554. track(target, "has" /* TrackOpTypes.HAS */, key);
  555. }
  556. return result;
  557. }
  558. function ownKeys(target) {
  559. track(target, "iterate" /* TrackOpTypes.ITERATE */, isArray(target) ? 'length' : ITERATE_KEY);
  560. return Reflect.ownKeys(target);
  561. }
  562. const mutableHandlers = {
  563. get: get$1,
  564. set: set$1,
  565. deleteProperty,
  566. has: has$1,
  567. ownKeys
  568. };
  569. const readonlyHandlers = {
  570. get: readonlyGet,
  571. set(target, key) {
  572. if ((process.env.NODE_ENV !== 'production')) {
  573. warn$1(`Set operation on key "${String(key)}" failed: target is readonly.`, target);
  574. }
  575. return true;
  576. },
  577. deleteProperty(target, key) {
  578. if ((process.env.NODE_ENV !== 'production')) {
  579. warn$1(`Delete operation on key "${String(key)}" failed: target is readonly.`, target);
  580. }
  581. return true;
  582. }
  583. };
  584. const shallowReactiveHandlers = /*#__PURE__*/ extend({}, mutableHandlers, {
  585. get: shallowGet,
  586. set: shallowSet
  587. });
  588. // Props handlers are special in the sense that it should not unwrap top-level
  589. // refs (in order to allow refs to be explicitly passed down), but should
  590. // retain the reactivity of the normal readonly object.
  591. const shallowReadonlyHandlers = /*#__PURE__*/ extend({}, readonlyHandlers, {
  592. get: shallowReadonlyGet
  593. });
  594. const toShallow = (value) => value;
  595. const getProto = (v) => Reflect.getPrototypeOf(v);
  596. function get(target, key, isReadonly = false, isShallow = false) {
  597. // #1772: readonly(reactive(Map)) should return readonly + reactive version
  598. // of the value
  599. target = target["__v_raw" /* ReactiveFlags.RAW */];
  600. const rawTarget = toRaw(target);
  601. const rawKey = toRaw(key);
  602. if (!isReadonly) {
  603. if (key !== rawKey) {
  604. track(rawTarget, "get" /* TrackOpTypes.GET */, key);
  605. }
  606. track(rawTarget, "get" /* TrackOpTypes.GET */, rawKey);
  607. }
  608. const { has } = getProto(rawTarget);
  609. const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
  610. if (has.call(rawTarget, key)) {
  611. return wrap(target.get(key));
  612. }
  613. else if (has.call(rawTarget, rawKey)) {
  614. return wrap(target.get(rawKey));
  615. }
  616. else if (target !== rawTarget) {
  617. // #3602 readonly(reactive(Map))
  618. // ensure that the nested reactive `Map` can do tracking for itself
  619. target.get(key);
  620. }
  621. }
  622. function has(key, isReadonly = false) {
  623. const target = this["__v_raw" /* ReactiveFlags.RAW */];
  624. const rawTarget = toRaw(target);
  625. const rawKey = toRaw(key);
  626. if (!isReadonly) {
  627. if (key !== rawKey) {
  628. track(rawTarget, "has" /* TrackOpTypes.HAS */, key);
  629. }
  630. track(rawTarget, "has" /* TrackOpTypes.HAS */, rawKey);
  631. }
  632. return key === rawKey
  633. ? target.has(key)
  634. : target.has(key) || target.has(rawKey);
  635. }
  636. function size(target, isReadonly = false) {
  637. target = target["__v_raw" /* ReactiveFlags.RAW */];
  638. !isReadonly && track(toRaw(target), "iterate" /* TrackOpTypes.ITERATE */, ITERATE_KEY);
  639. return Reflect.get(target, 'size', target);
  640. }
  641. function add(value) {
  642. value = toRaw(value);
  643. const target = toRaw(this);
  644. const proto = getProto(target);
  645. const hadKey = proto.has.call(target, value);
  646. if (!hadKey) {
  647. target.add(value);
  648. trigger(target, "add" /* TriggerOpTypes.ADD */, value, value);
  649. }
  650. return this;
  651. }
  652. function set$2(key, value) {
  653. value = toRaw(value);
  654. const target = toRaw(this);
  655. const { has, get } = getProto(target);
  656. let hadKey = has.call(target, key);
  657. if (!hadKey) {
  658. key = toRaw(key);
  659. hadKey = has.call(target, key);
  660. }
  661. else if ((process.env.NODE_ENV !== 'production')) {
  662. checkIdentityKeys(target, has, key);
  663. }
  664. const oldValue = get.call(target, key);
  665. target.set(key, value);
  666. if (!hadKey) {
  667. trigger(target, "add" /* TriggerOpTypes.ADD */, key, value);
  668. }
  669. else if (hasChanged(value, oldValue)) {
  670. trigger(target, "set" /* TriggerOpTypes.SET */, key, value, oldValue);
  671. }
  672. return this;
  673. }
  674. function deleteEntry(key) {
  675. const target = toRaw(this);
  676. const { has, get } = getProto(target);
  677. let hadKey = has.call(target, key);
  678. if (!hadKey) {
  679. key = toRaw(key);
  680. hadKey = has.call(target, key);
  681. }
  682. else if ((process.env.NODE_ENV !== 'production')) {
  683. checkIdentityKeys(target, has, key);
  684. }
  685. const oldValue = get ? get.call(target, key) : undefined;
  686. // forward the operation before queueing reactions
  687. const result = target.delete(key);
  688. if (hadKey) {
  689. trigger(target, "delete" /* TriggerOpTypes.DELETE */, key, undefined, oldValue);
  690. }
  691. return result;
  692. }
  693. function clear() {
  694. const target = toRaw(this);
  695. const hadItems = target.size !== 0;
  696. const oldTarget = (process.env.NODE_ENV !== 'production')
  697. ? isMap(target)
  698. ? new Map(target)
  699. : new Set(target)
  700. : undefined;
  701. // forward the operation before queueing reactions
  702. const result = target.clear();
  703. if (hadItems) {
  704. trigger(target, "clear" /* TriggerOpTypes.CLEAR */, undefined, undefined, oldTarget);
  705. }
  706. return result;
  707. }
  708. function createForEach(isReadonly, isShallow) {
  709. return function forEach(callback, thisArg) {
  710. const observed = this;
  711. const target = observed["__v_raw" /* ReactiveFlags.RAW */];
  712. const rawTarget = toRaw(target);
  713. const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
  714. !isReadonly && track(rawTarget, "iterate" /* TrackOpTypes.ITERATE */, ITERATE_KEY);
  715. return target.forEach((value, key) => {
  716. // important: make sure the callback is
  717. // 1. invoked with the reactive map as `this` and 3rd arg
  718. // 2. the value received should be a corresponding reactive/readonly.
  719. return callback.call(thisArg, wrap(value), wrap(key), observed);
  720. });
  721. };
  722. }
  723. function createIterableMethod(method, isReadonly, isShallow) {
  724. return function (...args) {
  725. const target = this["__v_raw" /* ReactiveFlags.RAW */];
  726. const rawTarget = toRaw(target);
  727. const targetIsMap = isMap(rawTarget);
  728. const isPair = method === 'entries' || (method === Symbol.iterator && targetIsMap);
  729. const isKeyOnly = method === 'keys' && targetIsMap;
  730. const innerIterator = target[method](...args);
  731. const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
  732. !isReadonly &&
  733. track(rawTarget, "iterate" /* TrackOpTypes.ITERATE */, isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY);
  734. // return a wrapped iterator which returns observed versions of the
  735. // values emitted from the real iterator
  736. return {
  737. // iterator protocol
  738. next() {
  739. const { value, done } = innerIterator.next();
  740. return done
  741. ? { value, done }
  742. : {
  743. value: isPair ? [wrap(value[0]), wrap(value[1])] : wrap(value),
  744. done
  745. };
  746. },
  747. // iterable protocol
  748. [Symbol.iterator]() {
  749. return this;
  750. }
  751. };
  752. };
  753. }
  754. function createReadonlyMethod(type) {
  755. return function (...args) {
  756. if ((process.env.NODE_ENV !== 'production')) {
  757. const key = args[0] ? `on key "${args[0]}" ` : ``;
  758. console.warn(`${capitalize(type)} operation ${key}failed: target is readonly.`, toRaw(this));
  759. }
  760. return type === "delete" /* TriggerOpTypes.DELETE */ ? false : this;
  761. };
  762. }
  763. function createInstrumentations() {
  764. const mutableInstrumentations = {
  765. get(key) {
  766. return get(this, key);
  767. },
  768. get size() {
  769. return size(this);
  770. },
  771. has,
  772. add,
  773. set: set$2,
  774. delete: deleteEntry,
  775. clear,
  776. forEach: createForEach(false, false)
  777. };
  778. const shallowInstrumentations = {
  779. get(key) {
  780. return get(this, key, false, true);
  781. },
  782. get size() {
  783. return size(this);
  784. },
  785. has,
  786. add,
  787. set: set$2,
  788. delete: deleteEntry,
  789. clear,
  790. forEach: createForEach(false, true)
  791. };
  792. const readonlyInstrumentations = {
  793. get(key) {
  794. return get(this, key, true);
  795. },
  796. get size() {
  797. return size(this, true);
  798. },
  799. has(key) {
  800. return has.call(this, key, true);
  801. },
  802. add: createReadonlyMethod("add" /* TriggerOpTypes.ADD */),
  803. set: createReadonlyMethod("set" /* TriggerOpTypes.SET */),
  804. delete: createReadonlyMethod("delete" /* TriggerOpTypes.DELETE */),
  805. clear: createReadonlyMethod("clear" /* TriggerOpTypes.CLEAR */),
  806. forEach: createForEach(true, false)
  807. };
  808. const shallowReadonlyInstrumentations = {
  809. get(key) {
  810. return get(this, key, true, true);
  811. },
  812. get size() {
  813. return size(this, true);
  814. },
  815. has(key) {
  816. return has.call(this, key, true);
  817. },
  818. add: createReadonlyMethod("add" /* TriggerOpTypes.ADD */),
  819. set: createReadonlyMethod("set" /* TriggerOpTypes.SET */),
  820. delete: createReadonlyMethod("delete" /* TriggerOpTypes.DELETE */),
  821. clear: createReadonlyMethod("clear" /* TriggerOpTypes.CLEAR */),
  822. forEach: createForEach(true, true)
  823. };
  824. const iteratorMethods = ['keys', 'values', 'entries', Symbol.iterator];
  825. iteratorMethods.forEach(method => {
  826. mutableInstrumentations[method] = createIterableMethod(method, false, false);
  827. readonlyInstrumentations[method] = createIterableMethod(method, true, false);
  828. shallowInstrumentations[method] = createIterableMethod(method, false, true);
  829. shallowReadonlyInstrumentations[method] = createIterableMethod(method, true, true);
  830. });
  831. return [
  832. mutableInstrumentations,
  833. readonlyInstrumentations,
  834. shallowInstrumentations,
  835. shallowReadonlyInstrumentations
  836. ];
  837. }
  838. const [mutableInstrumentations, readonlyInstrumentations, shallowInstrumentations, shallowReadonlyInstrumentations] = /* #__PURE__*/ createInstrumentations();
  839. function createInstrumentationGetter(isReadonly, shallow) {
  840. const instrumentations = shallow
  841. ? isReadonly
  842. ? shallowReadonlyInstrumentations
  843. : shallowInstrumentations
  844. : isReadonly
  845. ? readonlyInstrumentations
  846. : mutableInstrumentations;
  847. return (target, key, receiver) => {
  848. if (key === "__v_isReactive" /* ReactiveFlags.IS_REACTIVE */) {
  849. return !isReadonly;
  850. }
  851. else if (key === "__v_isReadonly" /* ReactiveFlags.IS_READONLY */) {
  852. return isReadonly;
  853. }
  854. else if (key === "__v_raw" /* ReactiveFlags.RAW */) {
  855. return target;
  856. }
  857. return Reflect.get(hasOwn(instrumentations, key) && key in target
  858. ? instrumentations
  859. : target, key, receiver);
  860. };
  861. }
  862. const mutableCollectionHandlers = {
  863. get: /*#__PURE__*/ createInstrumentationGetter(false, false)
  864. };
  865. const shallowCollectionHandlers = {
  866. get: /*#__PURE__*/ createInstrumentationGetter(false, true)
  867. };
  868. const readonlyCollectionHandlers = {
  869. get: /*#__PURE__*/ createInstrumentationGetter(true, false)
  870. };
  871. const shallowReadonlyCollectionHandlers = {
  872. get: /*#__PURE__*/ createInstrumentationGetter(true, true)
  873. };
  874. function checkIdentityKeys(target, has, key) {
  875. const rawKey = toRaw(key);
  876. if (rawKey !== key && has.call(target, rawKey)) {
  877. const type = toRawType(target);
  878. console.warn(`Reactive ${type} contains both the raw and reactive ` +
  879. `versions of the same object${type === `Map` ? ` as keys` : ``}, ` +
  880. `which can lead to inconsistencies. ` +
  881. `Avoid differentiating between the raw and reactive versions ` +
  882. `of an object and only use the reactive version if possible.`);
  883. }
  884. }
  885. const reactiveMap = new WeakMap();
  886. const shallowReactiveMap = new WeakMap();
  887. const readonlyMap = new WeakMap();
  888. const shallowReadonlyMap = new WeakMap();
  889. function targetTypeMap(rawType) {
  890. switch (rawType) {
  891. case 'Object':
  892. case 'Array':
  893. return 1 /* TargetType.COMMON */;
  894. case 'Map':
  895. case 'Set':
  896. case 'WeakMap':
  897. case 'WeakSet':
  898. return 2 /* TargetType.COLLECTION */;
  899. default:
  900. return 0 /* TargetType.INVALID */;
  901. }
  902. }
  903. function getTargetType(value) {
  904. return value["__v_skip" /* ReactiveFlags.SKIP */] || !Object.isExtensible(value)
  905. ? 0 /* TargetType.INVALID */
  906. : targetTypeMap(toRawType(value));
  907. }
  908. function reactive(target) {
  909. // if trying to observe a readonly proxy, return the readonly version.
  910. if (isReadonly(target)) {
  911. return target;
  912. }
  913. return createReactiveObject(target, false, mutableHandlers, mutableCollectionHandlers, reactiveMap);
  914. }
  915. /**
  916. * Return a shallowly-reactive copy of the original object, where only the root
  917. * level properties are reactive. It also does not auto-unwrap refs (even at the
  918. * root level).
  919. */
  920. function shallowReactive(target) {
  921. return createReactiveObject(target, false, shallowReactiveHandlers, shallowCollectionHandlers, shallowReactiveMap);
  922. }
  923. /**
  924. * Creates a readonly copy of the original object. Note the returned copy is not
  925. * made reactive, but `readonly` can be called on an already reactive object.
  926. */
  927. function readonly(target) {
  928. return createReactiveObject(target, true, readonlyHandlers, readonlyCollectionHandlers, readonlyMap);
  929. }
  930. /**
  931. * Returns a reactive-copy of the original object, where only the root level
  932. * properties are readonly, and does NOT unwrap refs nor recursively convert
  933. * returned properties.
  934. * This is used for creating the props proxy object for stateful components.
  935. */
  936. function shallowReadonly(target) {
  937. return createReactiveObject(target, true, shallowReadonlyHandlers, shallowReadonlyCollectionHandlers, shallowReadonlyMap);
  938. }
  939. function createReactiveObject(target, isReadonly, baseHandlers, collectionHandlers, proxyMap) {
  940. if (!isObject(target)) {
  941. if ((process.env.NODE_ENV !== 'production')) {
  942. console.warn(`value cannot be made reactive: ${String(target)}`);
  943. }
  944. return target;
  945. }
  946. // target is already a Proxy, return it.
  947. // exception: calling readonly() on a reactive object
  948. if (target["__v_raw" /* ReactiveFlags.RAW */] &&
  949. !(isReadonly && target["__v_isReactive" /* ReactiveFlags.IS_REACTIVE */])) {
  950. return target;
  951. }
  952. // target already has corresponding Proxy
  953. const existingProxy = proxyMap.get(target);
  954. if (existingProxy) {
  955. return existingProxy;
  956. }
  957. // only specific value types can be observed.
  958. const targetType = getTargetType(target);
  959. if (targetType === 0 /* TargetType.INVALID */) {
  960. return target;
  961. }
  962. const proxy = new Proxy(target, targetType === 2 /* TargetType.COLLECTION */ ? collectionHandlers : baseHandlers);
  963. proxyMap.set(target, proxy);
  964. return proxy;
  965. }
  966. function isReactive(value) {
  967. if (isReadonly(value)) {
  968. return isReactive(value["__v_raw" /* ReactiveFlags.RAW */]);
  969. }
  970. return !!(value && value["__v_isReactive" /* ReactiveFlags.IS_REACTIVE */]);
  971. }
  972. function isReadonly(value) {
  973. return !!(value && value["__v_isReadonly" /* ReactiveFlags.IS_READONLY */]);
  974. }
  975. function isShallow(value) {
  976. return !!(value && value["__v_isShallow" /* ReactiveFlags.IS_SHALLOW */]);
  977. }
  978. function isProxy(value) {
  979. return isReactive(value) || isReadonly(value);
  980. }
  981. function toRaw(observed) {
  982. const raw = observed && observed["__v_raw" /* ReactiveFlags.RAW */];
  983. return raw ? toRaw(raw) : observed;
  984. }
  985. function markRaw(value) {
  986. def(value, "__v_skip" /* ReactiveFlags.SKIP */, true);
  987. return value;
  988. }
  989. const toReactive = (value) => isObject(value) ? reactive(value) : value;
  990. const toReadonly = (value) => isObject(value) ? readonly(value) : value;
  991. function trackRefValue(ref) {
  992. if (shouldTrack && activeEffect) {
  993. ref = toRaw(ref);
  994. if ((process.env.NODE_ENV !== 'production')) {
  995. trackEffects(ref.dep || (ref.dep = createDep()), {
  996. target: ref,
  997. type: "get" /* TrackOpTypes.GET */,
  998. key: 'value'
  999. });
  1000. }
  1001. else {
  1002. trackEffects(ref.dep || (ref.dep = createDep()));
  1003. }
  1004. }
  1005. }
  1006. function triggerRefValue(ref, newVal) {
  1007. ref = toRaw(ref);
  1008. const dep = ref.dep;
  1009. if (dep) {
  1010. if ((process.env.NODE_ENV !== 'production')) {
  1011. triggerEffects(dep, {
  1012. target: ref,
  1013. type: "set" /* TriggerOpTypes.SET */,
  1014. key: 'value',
  1015. newValue: newVal
  1016. });
  1017. }
  1018. else {
  1019. triggerEffects(dep);
  1020. }
  1021. }
  1022. }
  1023. function isRef(r) {
  1024. return !!(r && r.__v_isRef === true);
  1025. }
  1026. function ref(value) {
  1027. return createRef(value, false);
  1028. }
  1029. function shallowRef(value) {
  1030. return createRef(value, true);
  1031. }
  1032. function createRef(rawValue, shallow) {
  1033. if (isRef(rawValue)) {
  1034. return rawValue;
  1035. }
  1036. return new RefImpl(rawValue, shallow);
  1037. }
  1038. class RefImpl {
  1039. constructor(value, __v_isShallow) {
  1040. this.__v_isShallow = __v_isShallow;
  1041. this.dep = undefined;
  1042. this.__v_isRef = true;
  1043. this._rawValue = __v_isShallow ? value : toRaw(value);
  1044. this._value = __v_isShallow ? value : toReactive(value);
  1045. }
  1046. get value() {
  1047. trackRefValue(this);
  1048. return this._value;
  1049. }
  1050. set value(newVal) {
  1051. const useDirectValue = this.__v_isShallow || isShallow(newVal) || isReadonly(newVal);
  1052. newVal = useDirectValue ? newVal : toRaw(newVal);
  1053. if (hasChanged(newVal, this._rawValue)) {
  1054. this._rawValue = newVal;
  1055. this._value = useDirectValue ? newVal : toReactive(newVal);
  1056. triggerRefValue(this, newVal);
  1057. }
  1058. }
  1059. }
  1060. function triggerRef(ref) {
  1061. triggerRefValue(ref, (process.env.NODE_ENV !== 'production') ? ref.value : void 0);
  1062. }
  1063. function unref(ref) {
  1064. return isRef(ref) ? ref.value : ref;
  1065. }
  1066. const shallowUnwrapHandlers = {
  1067. get: (target, key, receiver) => unref(Reflect.get(target, key, receiver)),
  1068. set: (target, key, value, receiver) => {
  1069. const oldValue = target[key];
  1070. if (isRef(oldValue) && !isRef(value)) {
  1071. oldValue.value = value;
  1072. return true;
  1073. }
  1074. else {
  1075. return Reflect.set(target, key, value, receiver);
  1076. }
  1077. }
  1078. };
  1079. function proxyRefs(objectWithRefs) {
  1080. return isReactive(objectWithRefs)
  1081. ? objectWithRefs
  1082. : new Proxy(objectWithRefs, shallowUnwrapHandlers);
  1083. }
  1084. class CustomRefImpl {
  1085. constructor(factory) {
  1086. this.dep = undefined;
  1087. this.__v_isRef = true;
  1088. const { get, set } = factory(() => trackRefValue(this), () => triggerRefValue(this));
  1089. this._get = get;
  1090. this._set = set;
  1091. }
  1092. get value() {
  1093. return this._get();
  1094. }
  1095. set value(newVal) {
  1096. this._set(newVal);
  1097. }
  1098. }
  1099. function customRef(factory) {
  1100. return new CustomRefImpl(factory);
  1101. }
  1102. function toRefs(object) {
  1103. if ((process.env.NODE_ENV !== 'production') && !isProxy(object)) {
  1104. console.warn(`toRefs() expects a reactive object but received a plain one.`);
  1105. }
  1106. const ret = isArray(object) ? new Array(object.length) : {};
  1107. for (const key in object) {
  1108. ret[key] = toRef(object, key);
  1109. }
  1110. return ret;
  1111. }
  1112. class ObjectRefImpl {
  1113. constructor(_object, _key, _defaultValue) {
  1114. this._object = _object;
  1115. this._key = _key;
  1116. this._defaultValue = _defaultValue;
  1117. this.__v_isRef = true;
  1118. }
  1119. get value() {
  1120. const val = this._object[this._key];
  1121. return val === undefined ? this._defaultValue : val;
  1122. }
  1123. set value(newVal) {
  1124. this._object[this._key] = newVal;
  1125. }
  1126. get dep() {
  1127. return getDepFromReactive(toRaw(this._object), this._key);
  1128. }
  1129. }
  1130. function toRef(object, key, defaultValue) {
  1131. const val = object[key];
  1132. return isRef(val)
  1133. ? val
  1134. : new ObjectRefImpl(object, key, defaultValue);
  1135. }
  1136. var _a;
  1137. class ComputedRefImpl {
  1138. constructor(getter, _setter, isReadonly, isSSR) {
  1139. this._setter = _setter;
  1140. this.dep = undefined;
  1141. this.__v_isRef = true;
  1142. this[_a] = false;
  1143. this._dirty = true;
  1144. this.effect = new ReactiveEffect(getter, () => {
  1145. if (!this._dirty) {
  1146. this._dirty = true;
  1147. triggerRefValue(this);
  1148. }
  1149. });
  1150. this.effect.computed = this;
  1151. this.effect.active = this._cacheable = !isSSR;
  1152. this["__v_isReadonly" /* ReactiveFlags.IS_READONLY */] = isReadonly;
  1153. }
  1154. get value() {
  1155. // the computed ref may get wrapped by other proxies e.g. readonly() #3376
  1156. const self = toRaw(this);
  1157. trackRefValue(self);
  1158. if (self._dirty || !self._cacheable) {
  1159. self._dirty = false;
  1160. self._value = self.effect.run();
  1161. }
  1162. return self._value;
  1163. }
  1164. set value(newValue) {
  1165. this._setter(newValue);
  1166. }
  1167. }
  1168. _a = "__v_isReadonly" /* ReactiveFlags.IS_READONLY */;
  1169. function computed$1(getterOrOptions, debugOptions, isSSR = false) {
  1170. let getter;
  1171. let setter;
  1172. const onlyGetter = isFunction(getterOrOptions);
  1173. if (onlyGetter) {
  1174. getter = getterOrOptions;
  1175. setter = (process.env.NODE_ENV !== 'production')
  1176. ? () => {
  1177. console.warn('Write operation failed: computed value is readonly');
  1178. }
  1179. : NOOP;
  1180. }
  1181. else {
  1182. getter = getterOrOptions.get;
  1183. setter = getterOrOptions.set;
  1184. }
  1185. const cRef = new ComputedRefImpl(getter, setter, onlyGetter || !setter, isSSR);
  1186. if ((process.env.NODE_ENV !== 'production') && debugOptions && !isSSR) {
  1187. cRef.effect.onTrack = debugOptions.onTrack;
  1188. cRef.effect.onTrigger = debugOptions.onTrigger;
  1189. }
  1190. return cRef;
  1191. }
  1192. const stack = [];
  1193. function pushWarningContext(vnode) {
  1194. stack.push(vnode);
  1195. }
  1196. function popWarningContext() {
  1197. stack.pop();
  1198. }
  1199. function warn(msg, ...args) {
  1200. if (!(process.env.NODE_ENV !== 'production'))
  1201. return;
  1202. // avoid props formatting or warn handler tracking deps that might be mutated
  1203. // during patch, leading to infinite recursion.
  1204. pauseTracking();
  1205. const instance = stack.length ? stack[stack.length - 1].component : null;
  1206. const appWarnHandler = instance && instance.appContext.config.warnHandler;
  1207. const trace = getComponentTrace();
  1208. if (appWarnHandler) {
  1209. callWithErrorHandling(appWarnHandler, instance, 11 /* ErrorCodes.APP_WARN_HANDLER */, [
  1210. msg + args.join(''),
  1211. instance && instance.proxy,
  1212. trace
  1213. .map(({ vnode }) => `at <${formatComponentName(instance, vnode.type)}>`)
  1214. .join('\n'),
  1215. trace
  1216. ]);
  1217. }
  1218. else {
  1219. const warnArgs = [`[Vue warn]: ${msg}`, ...args];
  1220. /* istanbul ignore if */
  1221. if (trace.length &&
  1222. // avoid spamming console during tests
  1223. !false) {
  1224. warnArgs.push(`\n`, ...formatTrace(trace));
  1225. }
  1226. console.warn(...warnArgs);
  1227. }
  1228. resetTracking();
  1229. }
  1230. function getComponentTrace() {
  1231. let currentVNode = stack[stack.length - 1];
  1232. if (!currentVNode) {
  1233. return [];
  1234. }
  1235. // we can't just use the stack because it will be incomplete during updates
  1236. // that did not start from the root. Re-construct the parent chain using
  1237. // instance parent pointers.
  1238. const normalizedStack = [];
  1239. while (currentVNode) {
  1240. const last = normalizedStack[0];
  1241. if (last && last.vnode === currentVNode) {
  1242. last.recurseCount++;
  1243. }
  1244. else {
  1245. normalizedStack.push({
  1246. vnode: currentVNode,
  1247. recurseCount: 0
  1248. });
  1249. }
  1250. const parentInstance = currentVNode.component && currentVNode.component.parent;
  1251. currentVNode = parentInstance && parentInstance.vnode;
  1252. }
  1253. return normalizedStack;
  1254. }
  1255. /* istanbul ignore next */
  1256. function formatTrace(trace) {
  1257. const logs = [];
  1258. trace.forEach((entry, i) => {
  1259. logs.push(...(i === 0 ? [] : [`\n`]), ...formatTraceEntry(entry));
  1260. });
  1261. return logs;
  1262. }
  1263. function formatTraceEntry({ vnode, recurseCount }) {
  1264. const postfix = recurseCount > 0 ? `... (${recurseCount} recursive calls)` : ``;
  1265. const isRoot = vnode.component ? vnode.component.parent == null : false;
  1266. const open = ` at <${formatComponentName(vnode.component, vnode.type, isRoot)}`;
  1267. const close = `>` + postfix;
  1268. return vnode.props
  1269. ? [open, ...formatProps(vnode.props), close]
  1270. : [open + close];
  1271. }
  1272. /* istanbul ignore next */
  1273. function formatProps(props) {
  1274. const res = [];
  1275. const keys = Object.keys(props);
  1276. keys.slice(0, 3).forEach(key => {
  1277. res.push(...formatProp(key, props[key]));
  1278. });
  1279. if (keys.length > 3) {
  1280. res.push(` ...`);
  1281. }
  1282. return res;
  1283. }
  1284. /* istanbul ignore next */
  1285. function formatProp(key, value, raw) {
  1286. if (isString(value)) {
  1287. value = JSON.stringify(value);
  1288. return raw ? value : [`${key}=${value}`];
  1289. }
  1290. else if (typeof value === 'number' ||
  1291. typeof value === 'boolean' ||
  1292. value == null) {
  1293. return raw ? value : [`${key}=${value}`];
  1294. }
  1295. else if (isRef(value)) {
  1296. value = formatProp(key, toRaw(value.value), true);
  1297. return raw ? value : [`${key}=Ref<`, value, `>`];
  1298. }
  1299. else if (isFunction(value)) {
  1300. return [`${key}=fn${value.name ? `<${value.name}>` : ``}`];
  1301. }
  1302. else {
  1303. value = toRaw(value);
  1304. return raw ? value : [`${key}=`, value];
  1305. }
  1306. }
  1307. const ErrorTypeStrings = {
  1308. ["sp" /* LifecycleHooks.SERVER_PREFETCH */]: 'serverPrefetch hook',
  1309. ["bc" /* LifecycleHooks.BEFORE_CREATE */]: 'beforeCreate hook',
  1310. ["c" /* LifecycleHooks.CREATED */]: 'created hook',
  1311. ["bm" /* LifecycleHooks.BEFORE_MOUNT */]: 'beforeMount hook',
  1312. ["m" /* LifecycleHooks.MOUNTED */]: 'mounted hook',
  1313. ["bu" /* LifecycleHooks.BEFORE_UPDATE */]: 'beforeUpdate hook',
  1314. ["u" /* LifecycleHooks.UPDATED */]: 'updated',
  1315. ["bum" /* LifecycleHooks.BEFORE_UNMOUNT */]: 'beforeUnmount hook',
  1316. ["um" /* LifecycleHooks.UNMOUNTED */]: 'unmounted hook',
  1317. ["a" /* LifecycleHooks.ACTIVATED */]: 'activated hook',
  1318. ["da" /* LifecycleHooks.DEACTIVATED */]: 'deactivated hook',
  1319. ["ec" /* LifecycleHooks.ERROR_CAPTURED */]: 'errorCaptured hook',
  1320. ["rtc" /* LifecycleHooks.RENDER_TRACKED */]: 'renderTracked hook',
  1321. ["rtg" /* LifecycleHooks.RENDER_TRIGGERED */]: 'renderTriggered hook',
  1322. [0 /* ErrorCodes.SETUP_FUNCTION */]: 'setup function',
  1323. [1 /* ErrorCodes.RENDER_FUNCTION */]: 'render function',
  1324. [2 /* ErrorCodes.WATCH_GETTER */]: 'watcher getter',
  1325. [3 /* ErrorCodes.WATCH_CALLBACK */]: 'watcher callback',
  1326. [4 /* ErrorCodes.WATCH_CLEANUP */]: 'watcher cleanup function',
  1327. [5 /* ErrorCodes.NATIVE_EVENT_HANDLER */]: 'native event handler',
  1328. [6 /* ErrorCodes.COMPONENT_EVENT_HANDLER */]: 'component event handler',
  1329. [7 /* ErrorCodes.VNODE_HOOK */]: 'vnode hook',
  1330. [8 /* ErrorCodes.DIRECTIVE_HOOK */]: 'directive hook',
  1331. [9 /* ErrorCodes.TRANSITION_HOOK */]: 'transition hook',
  1332. [10 /* ErrorCodes.APP_ERROR_HANDLER */]: 'app errorHandler',
  1333. [11 /* ErrorCodes.APP_WARN_HANDLER */]: 'app warnHandler',
  1334. [12 /* ErrorCodes.FUNCTION_REF */]: 'ref function',
  1335. [13 /* ErrorCodes.ASYNC_COMPONENT_LOADER */]: 'async component loader',
  1336. [14 /* ErrorCodes.SCHEDULER */]: 'scheduler flush. This is likely a Vue internals bug. ' +
  1337. 'Please open an issue at https://new-issue.vuejs.org/?repo=vuejs/core'
  1338. };
  1339. function callWithErrorHandling(fn, instance, type, args) {
  1340. let res;
  1341. try {
  1342. res = args ? fn(...args) : fn();
  1343. }
  1344. catch (err) {
  1345. handleError(err, instance, type);
  1346. }
  1347. return res;
  1348. }
  1349. function callWithAsyncErrorHandling(fn, instance, type, args) {
  1350. if (isFunction(fn)) {
  1351. const res = callWithErrorHandling(fn, instance, type, args);
  1352. if (res && isPromise(res)) {
  1353. res.catch(err => {
  1354. handleError(err, instance, type);
  1355. });
  1356. }
  1357. return res;
  1358. }
  1359. const values = [];
  1360. for (let i = 0; i < fn.length; i++) {
  1361. values.push(callWithAsyncErrorHandling(fn[i], instance, type, args));
  1362. }
  1363. return values;
  1364. }
  1365. function handleError(err, instance, type, throwInDev = true) {
  1366. const contextVNode = instance ? instance.vnode : null;
  1367. if (instance) {
  1368. let cur = instance.parent;
  1369. // the exposed instance is the render proxy to keep it consistent with 2.x
  1370. const exposedInstance = instance.proxy;
  1371. // in production the hook receives only the error code
  1372. const errorInfo = (process.env.NODE_ENV !== 'production') ? ErrorTypeStrings[type] || type : type; // fixed by xxxxxxx
  1373. while (cur) {
  1374. const errorCapturedHooks = cur.ec;
  1375. if (errorCapturedHooks) {
  1376. for (let i = 0; i < errorCapturedHooks.length; i++) {
  1377. if (errorCapturedHooks[i](err, exposedInstance, errorInfo) === false) {
  1378. return;
  1379. }
  1380. }
  1381. }
  1382. cur = cur.parent;
  1383. }
  1384. // app-level handling
  1385. const appErrorHandler = instance.appContext.config.errorHandler;
  1386. if (appErrorHandler) {
  1387. callWithErrorHandling(appErrorHandler, null, 10 /* ErrorCodes.APP_ERROR_HANDLER */, [err, exposedInstance, errorInfo]);
  1388. return;
  1389. }
  1390. }
  1391. logError(err, type, contextVNode, throwInDev);
  1392. }
  1393. // fixed by xxxxxx
  1394. function logError(err, type, contextVNode, throwInDev = true) {
  1395. if ((process.env.NODE_ENV !== 'production')) {
  1396. const info = ErrorTypeStrings[type] || type; // fixed by xxxxxx
  1397. if (contextVNode) {
  1398. pushWarningContext(contextVNode);
  1399. }
  1400. warn(`Unhandled error${info ? ` during execution of ${info}` : ``}`);
  1401. if (contextVNode) {
  1402. popWarningContext();
  1403. }
  1404. // crash in dev by default so it's more noticeable
  1405. if (throwInDev) {
  1406. // throw err fixed by xxxxxx 避免 error 导致 小程序 端不可用(比如跳转时报错)
  1407. console.error(err);
  1408. }
  1409. else {
  1410. console.error(err);
  1411. }
  1412. }
  1413. else {
  1414. // recover in prod to reduce the impact on end-user
  1415. console.error(err);
  1416. }
  1417. }
  1418. let isFlushing = false;
  1419. let isFlushPending = false;
  1420. // fixed by xxxxxx
  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$1(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 hasQueueJob(job) {
  1473. return queue.indexOf(job) > -1;
  1474. }
  1475. function invalidateJob(job) {
  1476. const i = queue.indexOf(job);
  1477. if (i > flushIndex) {
  1478. queue.splice(i, 1);
  1479. }
  1480. }
  1481. function queuePostFlushCb(cb) {
  1482. if (!isArray(cb)) {
  1483. if (!activePostFlushCbs ||
  1484. !activePostFlushCbs.includes(cb, cb.allowRecurse ? postFlushIndex + 1 : postFlushIndex)) {
  1485. pendingPostFlushCbs.push(cb);
  1486. }
  1487. }
  1488. else {
  1489. // if cb is an array, it is a component lifecycle hook which can only be
  1490. // triggered by a job, which is already deduped in the main queue, so
  1491. // we can skip duplicate check here to improve perf
  1492. pendingPostFlushCbs.push(...cb);
  1493. }
  1494. queueFlush();
  1495. }
  1496. function flushPreFlushCbs(seen,
  1497. // if currently flushing, skip the current job itself
  1498. i = isFlushing ? flushIndex + 1 : 0) {
  1499. if ((process.env.NODE_ENV !== 'production')) {
  1500. seen = seen || new Map();
  1501. }
  1502. for (; i < queue.length; i++) {
  1503. const cb = queue[i];
  1504. if (cb && cb.pre) {
  1505. if ((process.env.NODE_ENV !== 'production') && checkRecursiveUpdates(seen, cb)) {
  1506. continue;
  1507. }
  1508. queue.splice(i, 1);
  1509. i--;
  1510. cb();
  1511. }
  1512. }
  1513. }
  1514. function flushPostFlushCbs(seen) {
  1515. if (pendingPostFlushCbs.length) {
  1516. const deduped = [...new Set(pendingPostFlushCbs)];
  1517. pendingPostFlushCbs.length = 0;
  1518. // #1947 already has active queue, nested flushPostFlushCbs call
  1519. if (activePostFlushCbs) {
  1520. activePostFlushCbs.push(...deduped);
  1521. return;
  1522. }
  1523. activePostFlushCbs = deduped;
  1524. if ((process.env.NODE_ENV !== 'production')) {
  1525. seen = seen || new Map();
  1526. }
  1527. activePostFlushCbs.sort((a, b) => getId(a) - getId(b));
  1528. for (postFlushIndex = 0; postFlushIndex < activePostFlushCbs.length; postFlushIndex++) {
  1529. if ((process.env.NODE_ENV !== 'production') &&
  1530. checkRecursiveUpdates(seen, activePostFlushCbs[postFlushIndex])) {
  1531. continue;
  1532. }
  1533. activePostFlushCbs[postFlushIndex]();
  1534. }
  1535. activePostFlushCbs = null;
  1536. postFlushIndex = 0;
  1537. }
  1538. }
  1539. const getId = (job) => job.id == null ? Infinity : job.id;
  1540. const comparator = (a, b) => {
  1541. const diff = getId(a) - getId(b);
  1542. if (diff === 0) {
  1543. if (a.pre && !b.pre)
  1544. return -1;
  1545. if (b.pre && !a.pre)
  1546. return 1;
  1547. }
  1548. return diff;
  1549. };
  1550. function flushJobs(seen) {
  1551. isFlushPending = false;
  1552. isFlushing = true;
  1553. if ((process.env.NODE_ENV !== 'production')) {
  1554. seen = seen || new Map();
  1555. }
  1556. // Sort queue before flush.
  1557. // This ensures that:
  1558. // 1. Components are updated from parent to child. (because parent is always
  1559. // created before the child so its render effect will have smaller
  1560. // priority number)
  1561. // 2. If a component is unmounted during a parent component's update,
  1562. // its update can be skipped.
  1563. queue.sort(comparator);
  1564. // conditional usage of checkRecursiveUpdate must be determined out of
  1565. // try ... catch block since Rollup by default de-optimizes treeshaking
  1566. // inside try-catch. This can leave all warning code unshaked. Although
  1567. // they would get eventually shaken by a minifier like terser, some minifiers
  1568. // would fail to do that (e.g. https://github.com/evanw/esbuild/issues/1610)
  1569. const check = (process.env.NODE_ENV !== 'production')
  1570. ? (job) => checkRecursiveUpdates(seen, job)
  1571. : NOOP;
  1572. try {
  1573. for (flushIndex = 0; flushIndex < queue.length; flushIndex++) {
  1574. const job = queue[flushIndex];
  1575. if (job && job.active !== false) {
  1576. if ((process.env.NODE_ENV !== 'production') && check(job)) {
  1577. continue;
  1578. }
  1579. // console.log(`running:`, job.id)
  1580. callWithErrorHandling(job, null, 14 /* ErrorCodes.SCHEDULER */);
  1581. }
  1582. }
  1583. }
  1584. finally {
  1585. flushIndex = 0;
  1586. queue.length = 0;
  1587. flushPostFlushCbs(seen);
  1588. isFlushing = false;
  1589. currentFlushPromise = null;
  1590. // some postFlushCb queued jobs!
  1591. // keep flushing until it drains.
  1592. if (queue.length || pendingPostFlushCbs.length) {
  1593. flushJobs(seen);
  1594. }
  1595. }
  1596. }
  1597. function checkRecursiveUpdates(seen, fn) {
  1598. if (!seen.has(fn)) {
  1599. seen.set(fn, 1);
  1600. }
  1601. else {
  1602. const count = seen.get(fn);
  1603. if (count > RECURSION_LIMIT) {
  1604. const instance = fn.ownerInstance;
  1605. const componentName = instance && getComponentName(instance.type);
  1606. warn(`Maximum recursive updates exceeded${componentName ? ` in component <${componentName}>` : ``}. ` +
  1607. `This means you have a reactive effect that is mutating its own ` +
  1608. `dependencies and thus recursively triggering itself. Possible sources ` +
  1609. `include component template, render function, updated hook or ` +
  1610. `watcher source function.`);
  1611. return true;
  1612. }
  1613. else {
  1614. seen.set(fn, count + 1);
  1615. }
  1616. }
  1617. }
  1618. let devtools;
  1619. let buffer = [];
  1620. let devtoolsNotInstalled = false;
  1621. function emit$1(event, ...args) {
  1622. if (devtools) {
  1623. devtools.emit(event, ...args);
  1624. }
  1625. else if (!devtoolsNotInstalled) {
  1626. buffer.push({ event, args });
  1627. }
  1628. }
  1629. function setDevtoolsHook(hook, target) {
  1630. var _a, _b;
  1631. devtools = hook;
  1632. if (devtools) {
  1633. devtools.enabled = true;
  1634. buffer.forEach(({ event, args }) => devtools.emit(event, ...args));
  1635. buffer = [];
  1636. }
  1637. else if (
  1638. // handle late devtools injection - only do this if we are in an actual
  1639. // browser environment to avoid the timer handle stalling test runner exit
  1640. // (#4815)
  1641. typeof window !== 'undefined' &&
  1642. // some envs mock window but not fully
  1643. // eslint-disable-next-line no-restricted-globals
  1644. window.HTMLElement &&
  1645. // also exclude jsdom
  1646. // eslint-disable-next-line no-restricted-globals
  1647. !((_b = (_a = window.navigator) === null || _a === void 0 ? void 0 : _a.userAgent) === null || _b === void 0 ? void 0 : _b.includes('jsdom'))) {
  1648. const replay = (target.__VUE_DEVTOOLS_HOOK_REPLAY__ =
  1649. target.__VUE_DEVTOOLS_HOOK_REPLAY__ || []);
  1650. replay.push((newHook) => {
  1651. setDevtoolsHook(newHook, target);
  1652. });
  1653. // clear buffer after 3s - the user probably doesn't have devtools installed
  1654. // at all, and keeping the buffer will cause memory leaks (#4738)
  1655. setTimeout(() => {
  1656. if (!devtools) {
  1657. target.__VUE_DEVTOOLS_HOOK_REPLAY__ = null;
  1658. devtoolsNotInstalled = true;
  1659. buffer = [];
  1660. }
  1661. }, 3000);
  1662. }
  1663. else {
  1664. // non-browser env, assume not installed
  1665. devtoolsNotInstalled = true;
  1666. buffer = [];
  1667. }
  1668. }
  1669. function devtoolsInitApp(app, version) {
  1670. emit$1("app:init" /* DevtoolsHooks.APP_INIT */, app, version, {
  1671. Fragment,
  1672. Text,
  1673. Comment,
  1674. Static
  1675. });
  1676. }
  1677. const devtoolsComponentAdded = /*#__PURE__*/ createDevtoolsComponentHook("component:added" /* DevtoolsHooks.COMPONENT_ADDED */);
  1678. const devtoolsComponentUpdated =
  1679. /*#__PURE__*/ createDevtoolsComponentHook("component:updated" /* DevtoolsHooks.COMPONENT_UPDATED */);
  1680. const _devtoolsComponentRemoved = /*#__PURE__*/ createDevtoolsComponentHook("component:removed" /* DevtoolsHooks.COMPONENT_REMOVED */);
  1681. const devtoolsComponentRemoved = (component) => {
  1682. if (devtools &&
  1683. typeof devtools.cleanupBuffer === 'function' &&
  1684. // remove the component if it wasn't buffered
  1685. !devtools.cleanupBuffer(component)) {
  1686. _devtoolsComponentRemoved(component);
  1687. }
  1688. };
  1689. function createDevtoolsComponentHook(hook) {
  1690. return (component) => {
  1691. emit$1(hook, component.appContext.app, component.uid,
  1692. // fixed by xxxxxx
  1693. // 为 0 是 App,无 parent 是 Page 指向 App
  1694. component.uid === 0
  1695. ? undefined
  1696. : component.parent
  1697. ? component.parent.uid
  1698. : 0, component);
  1699. };
  1700. }
  1701. const devtoolsPerfStart = /*#__PURE__*/ createDevtoolsPerformanceHook("perf:start" /* DevtoolsHooks.PERFORMANCE_START */);
  1702. const devtoolsPerfEnd = /*#__PURE__*/ createDevtoolsPerformanceHook("perf:end" /* DevtoolsHooks.PERFORMANCE_END */);
  1703. function createDevtoolsPerformanceHook(hook) {
  1704. return (component, type, time) => {
  1705. emit$1(hook, component.appContext.app, component.uid, component, type, time);
  1706. };
  1707. }
  1708. function devtoolsComponentEmit(component, event, params) {
  1709. emit$1("component:emit" /* DevtoolsHooks.COMPONENT_EMIT */, component.appContext.app, component, event, params);
  1710. }
  1711. function emit(instance, event, ...rawArgs) {
  1712. if (instance.isUnmounted)
  1713. return;
  1714. const props = instance.vnode.props || EMPTY_OBJ;
  1715. if ((process.env.NODE_ENV !== 'production')) {
  1716. const { emitsOptions, propsOptions: [propsOptions] } = instance;
  1717. if (emitsOptions) {
  1718. if (!(event in emitsOptions) &&
  1719. !(false )) {
  1720. if (!propsOptions || !(toHandlerKey(event) in propsOptions)) {
  1721. warn(`Component emitted event "${event}" but it is neither declared in ` +
  1722. `the emits option nor as an "${toHandlerKey(event)}" prop.`);
  1723. }
  1724. }
  1725. else {
  1726. const validator = emitsOptions[event];
  1727. if (isFunction(validator)) {
  1728. const isValid = validator(...rawArgs);
  1729. if (!isValid) {
  1730. warn(`Invalid event arguments: event validation failed for event "${event}".`);
  1731. }
  1732. }
  1733. }
  1734. }
  1735. }
  1736. let args = rawArgs;
  1737. const isModelListener = event.startsWith('update:');
  1738. // for v-model update:xxx events, apply modifiers on args
  1739. const modelArg = isModelListener && event.slice(7);
  1740. if (modelArg && modelArg in props) {
  1741. const modifiersKey = `${modelArg === 'modelValue' ? 'model' : modelArg}Modifiers`;
  1742. const { number, trim } = props[modifiersKey] || EMPTY_OBJ;
  1743. if (trim) {
  1744. args = rawArgs.map(a => (isString(a) ? a.trim() : a));
  1745. }
  1746. if (number) {
  1747. args = rawArgs.map(looseToNumber);
  1748. }
  1749. }
  1750. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  1751. devtoolsComponentEmit(instance, event, args);
  1752. }
  1753. if ((process.env.NODE_ENV !== 'production')) {
  1754. const lowerCaseEvent = event.toLowerCase();
  1755. if (lowerCaseEvent !== event && props[toHandlerKey(lowerCaseEvent)]) {
  1756. warn(`Event "${lowerCaseEvent}" is emitted in component ` +
  1757. `${formatComponentName(instance, instance.type)} but the handler is registered for "${event}". ` +
  1758. `Note that HTML attributes are case-insensitive and you cannot use ` +
  1759. `v-on to listen to camelCase events when using in-DOM templates. ` +
  1760. `You should probably use "${hyphenate(event)}" instead of "${event}".`);
  1761. }
  1762. }
  1763. let handlerName;
  1764. let handler = props[(handlerName = toHandlerKey(event))] ||
  1765. // also try camelCase event handler (#2249)
  1766. props[(handlerName = toHandlerKey(camelize(event)))];
  1767. // for v-model update:xxx events, also trigger kebab-case equivalent
  1768. // for props passed via kebab-case
  1769. if (!handler && isModelListener) {
  1770. handler = props[(handlerName = toHandlerKey(hyphenate(event)))];
  1771. }
  1772. if (handler) {
  1773. callWithAsyncErrorHandling(handler, instance, 6 /* ErrorCodes.COMPONENT_EVENT_HANDLER */, args);
  1774. }
  1775. const onceHandler = props[handlerName + `Once`];
  1776. if (onceHandler) {
  1777. if (!instance.emitted) {
  1778. instance.emitted = {};
  1779. }
  1780. else if (instance.emitted[handlerName]) {
  1781. return;
  1782. }
  1783. instance.emitted[handlerName] = true;
  1784. callWithAsyncErrorHandling(onceHandler, instance, 6 /* ErrorCodes.COMPONENT_EVENT_HANDLER */, args);
  1785. }
  1786. }
  1787. function normalizeEmitsOptions(comp, appContext, asMixin = false) {
  1788. const cache = appContext.emitsCache;
  1789. const cached = cache.get(comp);
  1790. if (cached !== undefined) {
  1791. return cached;
  1792. }
  1793. const raw = comp.emits;
  1794. let normalized = {};
  1795. // apply mixin/extends props
  1796. let hasExtends = false;
  1797. if (__VUE_OPTIONS_API__ && !isFunction(comp)) {
  1798. const extendEmits = (raw) => {
  1799. const normalizedFromExtend = normalizeEmitsOptions(raw, appContext, true);
  1800. if (normalizedFromExtend) {
  1801. hasExtends = true;
  1802. extend(normalized, normalizedFromExtend);
  1803. }
  1804. };
  1805. if (!asMixin && appContext.mixins.length) {
  1806. appContext.mixins.forEach(extendEmits);
  1807. }
  1808. if (comp.extends) {
  1809. extendEmits(comp.extends);
  1810. }
  1811. if (comp.mixins) {
  1812. comp.mixins.forEach(extendEmits);
  1813. }
  1814. }
  1815. if (!raw && !hasExtends) {
  1816. if (isObject(comp)) {
  1817. cache.set(comp, null);
  1818. }
  1819. return null;
  1820. }
  1821. if (isArray(raw)) {
  1822. raw.forEach(key => (normalized[key] = null));
  1823. }
  1824. else {
  1825. extend(normalized, raw);
  1826. }
  1827. if (isObject(comp)) {
  1828. cache.set(comp, normalized);
  1829. }
  1830. return normalized;
  1831. }
  1832. // Check if an incoming prop key is a declared emit event listener.
  1833. // e.g. With `emits: { click: null }`, props named `onClick` and `onclick` are
  1834. // both considered matched listeners.
  1835. function isEmitListener(options, key) {
  1836. if (!options || !isOn(key)) {
  1837. return false;
  1838. }
  1839. key = key.slice(2).replace(/Once$/, '');
  1840. return (hasOwn(options, key[0].toLowerCase() + key.slice(1)) ||
  1841. hasOwn(options, hyphenate(key)) ||
  1842. hasOwn(options, key));
  1843. }
  1844. /**
  1845. * mark the current rendering instance for asset resolution (e.g.
  1846. * resolveComponent, resolveDirective) during render
  1847. */
  1848. let currentRenderingInstance = null;
  1849. let currentScopeId = null;
  1850. /**
  1851. * Note: rendering calls maybe nested. The function returns the parent rendering
  1852. * instance if present, which should be restored after the render is done:
  1853. *
  1854. * ```js
  1855. * const prev = setCurrentRenderingInstance(i)
  1856. * // ...render
  1857. * setCurrentRenderingInstance(prev)
  1858. * ```
  1859. */
  1860. function setCurrentRenderingInstance(instance) {
  1861. const prev = currentRenderingInstance;
  1862. currentRenderingInstance = instance;
  1863. currentScopeId = (instance && instance.type.__scopeId) || null;
  1864. return prev;
  1865. }
  1866. /**
  1867. * Only for backwards compat
  1868. * @private
  1869. */
  1870. const withScopeId = (_id) => withCtx;
  1871. /**
  1872. * Wrap a slot function to memoize current rendering instance
  1873. * @private compiler helper
  1874. */
  1875. function withCtx(fn, ctx = currentRenderingInstance, isNonScopedSlot // false only
  1876. ) {
  1877. if (!ctx)
  1878. return fn;
  1879. // already normalized
  1880. if (fn._n) {
  1881. return fn;
  1882. }
  1883. const renderFnWithContext = (...args) => {
  1884. // If a user calls a compiled slot inside a template expression (#1745), it
  1885. // can mess up block tracking, so by default we disable block tracking and
  1886. // force bail out when invoking a compiled slot (indicated by the ._d flag).
  1887. // This isn't necessary if rendering a compiled `<slot>`, so we flip the
  1888. // ._d flag off when invoking the wrapped fn inside `renderSlot`.
  1889. if (renderFnWithContext._d) {
  1890. setBlockTracking(-1);
  1891. }
  1892. const prevInstance = setCurrentRenderingInstance(ctx);
  1893. let res;
  1894. try {
  1895. res = fn(...args);
  1896. }
  1897. finally {
  1898. setCurrentRenderingInstance(prevInstance);
  1899. if (renderFnWithContext._d) {
  1900. setBlockTracking(1);
  1901. }
  1902. }
  1903. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  1904. devtoolsComponentUpdated(ctx);
  1905. }
  1906. return res;
  1907. };
  1908. // mark normalized to avoid duplicated wrapping
  1909. renderFnWithContext._n = true;
  1910. // mark this as compiled by default
  1911. // this is used in vnode.ts -> normalizeChildren() to set the slot
  1912. // rendering flag.
  1913. renderFnWithContext._c = true;
  1914. // disable block tracking by default
  1915. renderFnWithContext._d = true;
  1916. return renderFnWithContext;
  1917. }
  1918. function markAttrsAccessed() {
  1919. }
  1920. function provide(key, value) {
  1921. if (!currentInstance) {
  1922. if ((process.env.NODE_ENV !== 'production')) {
  1923. warn(`provide() can only be used inside setup().`);
  1924. }
  1925. }
  1926. else {
  1927. let provides = currentInstance.provides;
  1928. // by default an instance inherits its parent's provides object
  1929. // but when it needs to provide values of its own, it creates its
  1930. // own provides object using parent provides object as prototype.
  1931. // this way in `inject` we can simply look up injections from direct
  1932. // parent and let the prototype chain do the work.
  1933. const parentProvides = currentInstance.parent && currentInstance.parent.provides;
  1934. if (parentProvides === provides) {
  1935. provides = currentInstance.provides = Object.create(parentProvides);
  1936. }
  1937. // TS doesn't allow symbol as index type
  1938. provides[key] = value;
  1939. // 当实例为 App 时,同步到全局 provide
  1940. if (currentInstance.type.mpType === 'app') {
  1941. currentInstance.appContext.app.provide(key, value);
  1942. }
  1943. }
  1944. }
  1945. function inject(key, defaultValue, treatDefaultAsFactory = false) {
  1946. // fallback to `currentRenderingInstance` so that this can be called in
  1947. // a functional component
  1948. const instance = currentInstance || currentRenderingInstance;
  1949. if (instance) {
  1950. // #2400
  1951. // to support `app.use` plugins,
  1952. // fallback to appContext's `provides` if the instance is at root
  1953. const provides = instance.parent == null
  1954. ? instance.vnode.appContext && instance.vnode.appContext.provides
  1955. : instance.parent.provides;
  1956. if (provides && key in provides) {
  1957. // TS doesn't allow symbol as index type
  1958. return provides[key];
  1959. }
  1960. else if (arguments.length > 1) {
  1961. return treatDefaultAsFactory && isFunction(defaultValue)
  1962. ? defaultValue.call(instance.proxy)
  1963. : defaultValue;
  1964. }
  1965. else if ((process.env.NODE_ENV !== 'production')) {
  1966. warn(`injection "${String(key)}" not found.`);
  1967. }
  1968. }
  1969. else if ((process.env.NODE_ENV !== 'production')) {
  1970. warn(`inject() can only be used inside setup() or functional components.`);
  1971. }
  1972. }
  1973. // Simple effect.
  1974. function watchEffect(effect, options) {
  1975. return doWatch(effect, null, options);
  1976. }
  1977. function watchPostEffect(effect, options) {
  1978. return doWatch(effect, null, (process.env.NODE_ENV !== 'production') ? Object.assign(Object.assign({}, options), { flush: 'post' }) : { flush: 'post' });
  1979. }
  1980. function watchSyncEffect(effect, options) {
  1981. return doWatch(effect, null, (process.env.NODE_ENV !== 'production') ? Object.assign(Object.assign({}, options), { flush: 'sync' }) : { flush: 'sync' });
  1982. }
  1983. // initial value for watchers to trigger on undefined initial values
  1984. const INITIAL_WATCHER_VALUE = {};
  1985. // implementation
  1986. function watch(source, cb, options) {
  1987. if ((process.env.NODE_ENV !== 'production') && !isFunction(cb)) {
  1988. warn(`\`watch(fn, options?)\` signature has been moved to a separate API. ` +
  1989. `Use \`watchEffect(fn, options?)\` instead. \`watch\` now only ` +
  1990. `supports \`watch(source, cb, options?) signature.`);
  1991. }
  1992. return doWatch(source, cb, options);
  1993. }
  1994. function doWatch(source, cb, { immediate, deep, flush, onTrack, onTrigger } = EMPTY_OBJ) {
  1995. if ((process.env.NODE_ENV !== 'production') && !cb) {
  1996. if (immediate !== undefined) {
  1997. warn(`watch() "immediate" option is only respected when using the ` +
  1998. `watch(source, callback, options?) signature.`);
  1999. }
  2000. if (deep !== undefined) {
  2001. warn(`watch() "deep" option is only respected when using the ` +
  2002. `watch(source, callback, options?) signature.`);
  2003. }
  2004. }
  2005. const warnInvalidSource = (s) => {
  2006. warn(`Invalid watch source: `, s, `A watch source can only be a getter/effect function, a ref, ` +
  2007. `a reactive object, or an array of these types.`);
  2008. };
  2009. const instance = getCurrentScope() === (currentInstance === null || currentInstance === void 0 ? void 0 : currentInstance.scope) ? currentInstance : null;
  2010. // const instance = currentInstance
  2011. let getter;
  2012. let forceTrigger = false;
  2013. let isMultiSource = false;
  2014. if (isRef(source)) {
  2015. getter = () => source.value;
  2016. forceTrigger = isShallow(source);
  2017. }
  2018. else if (isReactive(source)) {
  2019. getter = () => source;
  2020. deep = true;
  2021. }
  2022. else if (isArray(source)) {
  2023. isMultiSource = true;
  2024. forceTrigger = source.some(s => isReactive(s) || isShallow(s));
  2025. getter = () => source.map(s => {
  2026. if (isRef(s)) {
  2027. return s.value;
  2028. }
  2029. else if (isReactive(s)) {
  2030. return traverse(s);
  2031. }
  2032. else if (isFunction(s)) {
  2033. return callWithErrorHandling(s, instance, 2 /* ErrorCodes.WATCH_GETTER */);
  2034. }
  2035. else {
  2036. (process.env.NODE_ENV !== 'production') && warnInvalidSource(s);
  2037. }
  2038. });
  2039. }
  2040. else if (isFunction(source)) {
  2041. if (cb) {
  2042. // getter with cb
  2043. getter = () => callWithErrorHandling(source, instance, 2 /* ErrorCodes.WATCH_GETTER */);
  2044. }
  2045. else {
  2046. // no cb -> simple effect
  2047. getter = () => {
  2048. if (instance && instance.isUnmounted) {
  2049. return;
  2050. }
  2051. if (cleanup) {
  2052. cleanup();
  2053. }
  2054. return callWithAsyncErrorHandling(source, instance, 3 /* ErrorCodes.WATCH_CALLBACK */, [onCleanup]);
  2055. };
  2056. }
  2057. }
  2058. else {
  2059. getter = NOOP;
  2060. (process.env.NODE_ENV !== 'production') && warnInvalidSource(source);
  2061. }
  2062. if (cb && deep) {
  2063. const baseGetter = getter;
  2064. getter = () => traverse(baseGetter());
  2065. }
  2066. let cleanup;
  2067. let onCleanup = (fn) => {
  2068. cleanup = effect.onStop = () => {
  2069. callWithErrorHandling(fn, instance, 4 /* ErrorCodes.WATCH_CLEANUP */);
  2070. };
  2071. };
  2072. let oldValue = isMultiSource
  2073. ? new Array(source.length).fill(INITIAL_WATCHER_VALUE)
  2074. : INITIAL_WATCHER_VALUE;
  2075. const job = () => {
  2076. if (!effect.active) {
  2077. return;
  2078. }
  2079. if (cb) {
  2080. // watch(source, cb)
  2081. const newValue = effect.run();
  2082. if (deep ||
  2083. forceTrigger ||
  2084. (isMultiSource
  2085. ? newValue.some((v, i) => hasChanged(v, oldValue[i]))
  2086. : hasChanged(newValue, oldValue)) ||
  2087. (false )) {
  2088. // cleanup before running cb again
  2089. if (cleanup) {
  2090. cleanup();
  2091. }
  2092. callWithAsyncErrorHandling(cb, instance, 3 /* ErrorCodes.WATCH_CALLBACK */, [
  2093. newValue,
  2094. // pass undefined as the old value when it's changed for the first time
  2095. oldValue === INITIAL_WATCHER_VALUE
  2096. ? undefined
  2097. : isMultiSource && oldValue[0] === INITIAL_WATCHER_VALUE
  2098. ? []
  2099. : oldValue,
  2100. onCleanup
  2101. ]);
  2102. oldValue = newValue;
  2103. }
  2104. }
  2105. else {
  2106. // watchEffect
  2107. effect.run();
  2108. }
  2109. };
  2110. // important: mark the job as a watcher callback so that scheduler knows
  2111. // it is allowed to self-trigger (#1727)
  2112. job.allowRecurse = !!cb;
  2113. let scheduler;
  2114. if (flush === 'sync') {
  2115. scheduler = job; // the scheduler function gets called directly
  2116. }
  2117. else if (flush === 'post') {
  2118. scheduler = () => queuePostRenderEffect$1(job, instance && instance.suspense);
  2119. }
  2120. else {
  2121. // default: 'pre'
  2122. job.pre = true;
  2123. if (instance)
  2124. job.id = instance.uid;
  2125. scheduler = () => queueJob(job);
  2126. }
  2127. const effect = new ReactiveEffect(getter, scheduler);
  2128. if ((process.env.NODE_ENV !== 'production')) {
  2129. effect.onTrack = onTrack;
  2130. effect.onTrigger = onTrigger;
  2131. }
  2132. // initial run
  2133. if (cb) {
  2134. if (immediate) {
  2135. job();
  2136. }
  2137. else {
  2138. oldValue = effect.run();
  2139. }
  2140. }
  2141. else if (flush === 'post') {
  2142. queuePostRenderEffect$1(effect.run.bind(effect), instance && instance.suspense);
  2143. }
  2144. else {
  2145. effect.run();
  2146. }
  2147. const unwatch = () => {
  2148. effect.stop();
  2149. if (instance && instance.scope) {
  2150. remove(instance.scope.effects, effect);
  2151. }
  2152. };
  2153. return unwatch;
  2154. }
  2155. // this.$watch
  2156. function instanceWatch(source, value, options) {
  2157. const publicThis = this.proxy;
  2158. const getter = isString(source)
  2159. ? source.includes('.')
  2160. ? createPathGetter(publicThis, source)
  2161. : () => publicThis[source]
  2162. : source.bind(publicThis, publicThis);
  2163. let cb;
  2164. if (isFunction(value)) {
  2165. cb = value;
  2166. }
  2167. else {
  2168. cb = value.handler;
  2169. options = value;
  2170. }
  2171. const cur = currentInstance;
  2172. setCurrentInstance(this);
  2173. const res = doWatch(getter, cb.bind(publicThis), options);
  2174. if (cur) {
  2175. setCurrentInstance(cur);
  2176. }
  2177. else {
  2178. unsetCurrentInstance();
  2179. }
  2180. return res;
  2181. }
  2182. function createPathGetter(ctx, path) {
  2183. const segments = path.split('.');
  2184. return () => {
  2185. let cur = ctx;
  2186. for (let i = 0; i < segments.length && cur; i++) {
  2187. cur = cur[segments[i]];
  2188. }
  2189. return cur;
  2190. };
  2191. }
  2192. function traverse(value, seen) {
  2193. if (!isObject(value) || value["__v_skip" /* ReactiveFlags.SKIP */]) {
  2194. return value;
  2195. }
  2196. seen = seen || new Set();
  2197. if (seen.has(value)) {
  2198. return value;
  2199. }
  2200. seen.add(value);
  2201. if (isRef(value)) {
  2202. traverse(value.value, seen);
  2203. }
  2204. else if (isArray(value)) {
  2205. for (let i = 0; i < value.length; i++) {
  2206. traverse(value[i], seen);
  2207. }
  2208. }
  2209. else if (isSet(value) || isMap(value)) {
  2210. value.forEach((v) => {
  2211. traverse(v, seen);
  2212. });
  2213. }
  2214. else if (isPlainObject(value)) {
  2215. for (const key in value) {
  2216. traverse(value[key], seen);
  2217. }
  2218. }
  2219. return value;
  2220. }
  2221. // implementation, close to no-op
  2222. function defineComponent(options) {
  2223. return isFunction(options) ? { setup: options, name: options.name } : options;
  2224. }
  2225. const isKeepAlive = (vnode) => vnode.type.__isKeepAlive;
  2226. function onActivated(hook, target) {
  2227. registerKeepAliveHook(hook, "a" /* LifecycleHooks.ACTIVATED */, target);
  2228. }
  2229. function onDeactivated(hook, target) {
  2230. registerKeepAliveHook(hook, "da" /* LifecycleHooks.DEACTIVATED */, target);
  2231. }
  2232. function registerKeepAliveHook(hook, type, target = currentInstance) {
  2233. // cache the deactivate branch check wrapper for injected hooks so the same
  2234. // hook can be properly deduped by the scheduler. "__wdc" stands for "with
  2235. // deactivation check".
  2236. const wrappedHook = hook.__wdc ||
  2237. (hook.__wdc = () => {
  2238. // only fire the hook if the target instance is NOT in a deactivated branch.
  2239. let current = target;
  2240. while (current) {
  2241. if (current.isDeactivated) {
  2242. return;
  2243. }
  2244. current = current.parent;
  2245. }
  2246. return hook();
  2247. });
  2248. injectHook(type, wrappedHook, target);
  2249. // In addition to registering it on the target instance, we walk up the parent
  2250. // chain and register it on all ancestor instances that are keep-alive roots.
  2251. // This avoids the need to walk the entire component tree when invoking these
  2252. // hooks, and more importantly, avoids the need to track child components in
  2253. // arrays.
  2254. if (target) {
  2255. let current = target.parent;
  2256. while (current && current.parent) {
  2257. if (isKeepAlive(current.parent.vnode)) {
  2258. injectToKeepAliveRoot(wrappedHook, type, target, current);
  2259. }
  2260. current = current.parent;
  2261. }
  2262. }
  2263. }
  2264. function injectToKeepAliveRoot(hook, type, target, keepAliveRoot) {
  2265. // injectHook wraps the original for error handling, so make sure to remove
  2266. // the wrapped version.
  2267. const injected = injectHook(type, hook, keepAliveRoot, true /* prepend */);
  2268. onUnmounted(() => {
  2269. remove(keepAliveRoot[type], injected);
  2270. }, target);
  2271. }
  2272. function injectHook(type, hook, target = currentInstance, prepend = false) {
  2273. if (target) {
  2274. // fixed by xxxxxx
  2275. if (isRootHook(type)) {
  2276. target = target.root;
  2277. }
  2278. const hooks = target[type] || (target[type] = []);
  2279. // cache the error handling wrapper for injected hooks so the same hook
  2280. // can be properly deduped by the scheduler. "__weh" stands for "with error
  2281. // handling".
  2282. const wrappedHook = hook.__weh ||
  2283. (hook.__weh = (...args) => {
  2284. if (target.isUnmounted) {
  2285. return;
  2286. }
  2287. // disable tracking inside all lifecycle hooks
  2288. // since they can potentially be called inside effects.
  2289. pauseTracking();
  2290. // Set currentInstance during hook invocation.
  2291. // This assumes the hook does not synchronously trigger other hooks, which
  2292. // can only be false when the user does something really funky.
  2293. setCurrentInstance(target); // fixed by xxxxxx
  2294. const res = callWithAsyncErrorHandling(hook, target, type, args);
  2295. unsetCurrentInstance();
  2296. resetTracking();
  2297. return res;
  2298. });
  2299. if (prepend) {
  2300. hooks.unshift(wrappedHook);
  2301. }
  2302. else {
  2303. hooks.push(wrappedHook);
  2304. }
  2305. return wrappedHook;
  2306. }
  2307. else if ((process.env.NODE_ENV !== 'production')) {
  2308. // fixed by xxxxxx
  2309. const apiName = toHandlerKey((ErrorTypeStrings[type] || type.replace(/^on/, '')).replace(/ hook$/, ''));
  2310. warn(`${apiName} is called when there is no active component instance to be ` +
  2311. `associated with. ` +
  2312. `Lifecycle injection APIs can only be used during execution of setup().` +
  2313. (``));
  2314. }
  2315. }
  2316. const createHook = (lifecycle) => (hook, target = currentInstance) =>
  2317. // post-create lifecycle registrations are noops during SSR (except for serverPrefetch)
  2318. (!isInSSRComponentSetup || lifecycle === "sp" /* LifecycleHooks.SERVER_PREFETCH */) &&
  2319. injectHook(lifecycle, (...args) => hook(...args), target);
  2320. const onBeforeMount = createHook("bm" /* LifecycleHooks.BEFORE_MOUNT */);
  2321. const onMounted = createHook("m" /* LifecycleHooks.MOUNTED */);
  2322. const onBeforeUpdate = createHook("bu" /* LifecycleHooks.BEFORE_UPDATE */);
  2323. const onUpdated = createHook("u" /* LifecycleHooks.UPDATED */);
  2324. const onBeforeUnmount = createHook("bum" /* LifecycleHooks.BEFORE_UNMOUNT */);
  2325. const onUnmounted = createHook("um" /* LifecycleHooks.UNMOUNTED */);
  2326. const onServerPrefetch = createHook("sp" /* LifecycleHooks.SERVER_PREFETCH */);
  2327. const onRenderTriggered = createHook("rtg" /* LifecycleHooks.RENDER_TRIGGERED */);
  2328. const onRenderTracked = createHook("rtc" /* LifecycleHooks.RENDER_TRACKED */);
  2329. function onErrorCaptured(hook, target = currentInstance) {
  2330. injectHook("ec" /* LifecycleHooks.ERROR_CAPTURED */, hook, target);
  2331. }
  2332. /**
  2333. Runtime helper for applying directives to a vnode. Example usage:
  2334. const comp = resolveComponent('comp')
  2335. const foo = resolveDirective('foo')
  2336. const bar = resolveDirective('bar')
  2337. return withDirectives(h(comp), [
  2338. [foo, this.x],
  2339. [bar, this.y]
  2340. ])
  2341. */
  2342. function validateDirectiveName(name) {
  2343. if (isBuiltInDirective(name)) {
  2344. warn('Do not use built-in directive ids as custom directive id: ' + name);
  2345. }
  2346. }
  2347. /**
  2348. * Adds directives to a VNode.
  2349. */
  2350. function withDirectives(vnode, directives) {
  2351. const internalInstance = currentRenderingInstance;
  2352. if (internalInstance === null) {
  2353. (process.env.NODE_ENV !== 'production') && warn(`withDirectives can only be used inside render functions.`);
  2354. return vnode;
  2355. }
  2356. const instance = getExposeProxy(internalInstance) ||
  2357. internalInstance.proxy;
  2358. const bindings = vnode.dirs || (vnode.dirs = []);
  2359. for (let i = 0; i < directives.length; i++) {
  2360. let [dir, value, arg, modifiers = EMPTY_OBJ] = directives[i];
  2361. if (dir) {
  2362. if (isFunction(dir)) {
  2363. dir = {
  2364. mounted: dir,
  2365. updated: dir
  2366. };
  2367. }
  2368. if (dir.deep) {
  2369. traverse(value);
  2370. }
  2371. bindings.push({
  2372. dir,
  2373. instance,
  2374. value,
  2375. oldValue: void 0,
  2376. arg,
  2377. modifiers
  2378. });
  2379. }
  2380. }
  2381. return vnode;
  2382. }
  2383. const COMPONENTS = 'components';
  2384. const DIRECTIVES = 'directives';
  2385. /**
  2386. * @private
  2387. */
  2388. function resolveComponent(name, maybeSelfReference) {
  2389. return resolveAsset(COMPONENTS, name, true, maybeSelfReference) || name;
  2390. }
  2391. const NULL_DYNAMIC_COMPONENT = Symbol();
  2392. /**
  2393. * @private
  2394. */
  2395. function resolveDirective(name) {
  2396. return resolveAsset(DIRECTIVES, name);
  2397. }
  2398. // implementation
  2399. function resolveAsset(type, name, warnMissing = true, maybeSelfReference = false) {
  2400. const instance = currentRenderingInstance || currentInstance;
  2401. if (instance) {
  2402. const Component = instance.type;
  2403. // explicit self name has highest priority
  2404. if (type === COMPONENTS) {
  2405. const selfName = getComponentName(Component, false /* do not include inferred name to avoid breaking existing code */);
  2406. if (selfName &&
  2407. (selfName === name ||
  2408. selfName === camelize(name) ||
  2409. selfName === capitalize(camelize(name)))) {
  2410. return Component;
  2411. }
  2412. }
  2413. const res =
  2414. // local registration
  2415. // check instance[type] first which is resolved for options API
  2416. resolve(instance[type] || Component[type], name) ||
  2417. // global registration
  2418. resolve(instance.appContext[type], name);
  2419. if (!res && maybeSelfReference) {
  2420. // fallback to implicit self-reference
  2421. return Component;
  2422. }
  2423. if ((process.env.NODE_ENV !== 'production') && warnMissing && !res) {
  2424. const extra = type === COMPONENTS
  2425. ? `\nIf this is a native custom element, make sure to exclude it from ` +
  2426. `component resolution via compilerOptions.isCustomElement.`
  2427. : ``;
  2428. warn(`Failed to resolve ${type.slice(0, -1)}: ${name}${extra}`);
  2429. }
  2430. return res;
  2431. }
  2432. else if ((process.env.NODE_ENV !== 'production')) {
  2433. warn(`resolve${capitalize(type.slice(0, -1))} ` +
  2434. `can only be used in render() or setup().`);
  2435. }
  2436. }
  2437. function resolve(registry, name) {
  2438. return (registry &&
  2439. (registry[name] ||
  2440. registry[camelize(name)] ||
  2441. registry[capitalize(camelize(name))]));
  2442. }
  2443. /**
  2444. * For prefixing keys in v-on="obj" with "on"
  2445. * @private
  2446. */
  2447. function toHandlers(obj, preserveCaseIfNecessary) {
  2448. const ret = {};
  2449. if ((process.env.NODE_ENV !== 'production') && !isObject(obj)) {
  2450. warn(`v-on with no argument expects an object value.`);
  2451. return ret;
  2452. }
  2453. for (const key in obj) {
  2454. ret[preserveCaseIfNecessary && /[A-Z]/.test(key)
  2455. ? `on:${key}`
  2456. : toHandlerKey(key)] = obj[key];
  2457. }
  2458. return ret;
  2459. }
  2460. /**
  2461. * #2437 In Vue 3, functional components do not have a public instance proxy but
  2462. * they exist in the internal parent chain. For code that relies on traversing
  2463. * public $parent chains, skip functional ones and go to the parent instead.
  2464. */
  2465. const getPublicInstance = (i) => {
  2466. if (!i)
  2467. return null;
  2468. if (isStatefulComponent(i))
  2469. return getExposeProxy(i) || i.proxy;
  2470. return getPublicInstance(i.parent);
  2471. };
  2472. const publicPropertiesMap =
  2473. // Move PURE marker to new line to workaround compiler discarding it
  2474. // due to type annotation
  2475. /*#__PURE__*/ extend(Object.create(null), {
  2476. $: i => i,
  2477. // fixed by xxxxxx vue-i18n 在 dev 模式,访问了 $el,故模拟一个假的
  2478. // $el: i => i.vnode.el,
  2479. $el: i => i.__$el || (i.__$el = {}),
  2480. $data: i => i.data,
  2481. $props: i => ((process.env.NODE_ENV !== 'production') ? shallowReadonly(i.props) : i.props),
  2482. $attrs: i => ((process.env.NODE_ENV !== 'production') ? shallowReadonly(i.attrs) : i.attrs),
  2483. $slots: i => ((process.env.NODE_ENV !== 'production') ? shallowReadonly(i.slots) : i.slots),
  2484. $refs: i => ((process.env.NODE_ENV !== 'production') ? shallowReadonly(i.refs) : i.refs),
  2485. $parent: i => getPublicInstance(i.parent),
  2486. $root: i => getPublicInstance(i.root),
  2487. $emit: i => i.emit,
  2488. $options: i => (__VUE_OPTIONS_API__ ? resolveMergedOptions(i) : i.type),
  2489. $forceUpdate: i => i.f || (i.f = () => queueJob(i.update)),
  2490. // $nextTick: i => i.n || (i.n = nextTick.bind(i.proxy!)),// fixed by xxxxxx
  2491. $watch: i => (__VUE_OPTIONS_API__ ? instanceWatch.bind(i) : NOOP)
  2492. });
  2493. const isReservedPrefix = (key) => key === '_' || key === '$';
  2494. const hasSetupBinding = (state, key) => state !== EMPTY_OBJ && !state.__isScriptSetup && hasOwn(state, key);
  2495. const PublicInstanceProxyHandlers = {
  2496. get({ _: instance }, key) {
  2497. const { ctx, setupState, data, props, accessCache, type, appContext } = instance;
  2498. // for internal formatters to know that this is a Vue instance
  2499. if ((process.env.NODE_ENV !== 'production') && key === '__isVue') {
  2500. return true;
  2501. }
  2502. // data / props / ctx
  2503. // This getter gets called for every property access on the render context
  2504. // during render and is a major hotspot. The most expensive part of this
  2505. // is the multiple hasOwn() calls. It's much faster to do a simple property
  2506. // access on a plain object, so we use an accessCache object (with null
  2507. // prototype) to memoize what access type a key corresponds to.
  2508. let normalizedProps;
  2509. if (key[0] !== '$') {
  2510. const n = accessCache[key];
  2511. if (n !== undefined) {
  2512. switch (n) {
  2513. case 1 /* AccessTypes.SETUP */:
  2514. return setupState[key];
  2515. case 2 /* AccessTypes.DATA */:
  2516. return data[key];
  2517. case 4 /* AccessTypes.CONTEXT */:
  2518. return ctx[key];
  2519. case 3 /* AccessTypes.PROPS */:
  2520. return props[key];
  2521. // default: just fallthrough
  2522. }
  2523. }
  2524. else if (hasSetupBinding(setupState, key)) {
  2525. accessCache[key] = 1 /* AccessTypes.SETUP */;
  2526. return setupState[key];
  2527. }
  2528. else if (data !== EMPTY_OBJ && hasOwn(data, key)) {
  2529. accessCache[key] = 2 /* AccessTypes.DATA */;
  2530. return data[key];
  2531. }
  2532. else if (
  2533. // only cache other properties when instance has declared (thus stable)
  2534. // props
  2535. (normalizedProps = instance.propsOptions[0]) &&
  2536. hasOwn(normalizedProps, key)) {
  2537. accessCache[key] = 3 /* AccessTypes.PROPS */;
  2538. return props[key];
  2539. }
  2540. else if (ctx !== EMPTY_OBJ && hasOwn(ctx, key)) {
  2541. accessCache[key] = 4 /* AccessTypes.CONTEXT */;
  2542. return ctx[key];
  2543. }
  2544. else if (!__VUE_OPTIONS_API__ || shouldCacheAccess) {
  2545. accessCache[key] = 0 /* AccessTypes.OTHER */;
  2546. }
  2547. }
  2548. const publicGetter = publicPropertiesMap[key];
  2549. let cssModule, globalProperties;
  2550. // public $xxx properties
  2551. if (publicGetter) {
  2552. if (key === '$attrs') {
  2553. track(instance, "get" /* TrackOpTypes.GET */, key);
  2554. (process.env.NODE_ENV !== 'production') && markAttrsAccessed();
  2555. }
  2556. return publicGetter(instance);
  2557. }
  2558. else if (
  2559. // css module (injected by vue-loader)
  2560. (cssModule = type.__cssModules) &&
  2561. (cssModule = cssModule[key])) {
  2562. return cssModule;
  2563. }
  2564. else if (ctx !== EMPTY_OBJ && hasOwn(ctx, key)) {
  2565. // user may set custom properties to `this` that start with `$`
  2566. accessCache[key] = 4 /* AccessTypes.CONTEXT */;
  2567. return ctx[key];
  2568. }
  2569. else if (
  2570. // global properties
  2571. ((globalProperties = appContext.config.globalProperties),
  2572. hasOwn(globalProperties, key))) {
  2573. {
  2574. return globalProperties[key];
  2575. }
  2576. }
  2577. else if ((process.env.NODE_ENV !== 'production') &&
  2578. currentRenderingInstance &&
  2579. (!isString(key) ||
  2580. // #1091 avoid internal isRef/isVNode checks on component instance leading
  2581. // to infinite warning loop
  2582. key.indexOf('__v') !== 0)) {
  2583. if (data !== EMPTY_OBJ && isReservedPrefix(key[0]) && hasOwn(data, key)) {
  2584. warn(`Property ${JSON.stringify(key)} must be accessed via $data because it starts with a reserved ` +
  2585. `character ("$" or "_") and is not proxied on the render context.`);
  2586. }
  2587. else if (instance === currentRenderingInstance) {
  2588. warn(`Property ${JSON.stringify(key)} was accessed during render ` +
  2589. `but is not defined on instance.`);
  2590. }
  2591. }
  2592. },
  2593. set({ _: instance }, key, value) {
  2594. const { data, setupState, ctx } = instance;
  2595. if (hasSetupBinding(setupState, key)) {
  2596. setupState[key] = value;
  2597. return true;
  2598. }
  2599. else if ((process.env.NODE_ENV !== 'production') &&
  2600. setupState.__isScriptSetup &&
  2601. hasOwn(setupState, key)) {
  2602. warn(`Cannot mutate <script setup> binding "${key}" from Options API.`);
  2603. return false;
  2604. }
  2605. else if (data !== EMPTY_OBJ && hasOwn(data, key)) {
  2606. data[key] = value;
  2607. return true;
  2608. }
  2609. else if (hasOwn(instance.props, key)) {
  2610. (process.env.NODE_ENV !== 'production') && warn(`Attempting to mutate prop "${key}". Props are readonly.`);
  2611. return false;
  2612. }
  2613. if (key[0] === '$' && key.slice(1) in instance) {
  2614. (process.env.NODE_ENV !== 'production') &&
  2615. warn(`Attempting to mutate public property "${key}". ` +
  2616. `Properties starting with $ are reserved and readonly.`);
  2617. return false;
  2618. }
  2619. else {
  2620. if ((process.env.NODE_ENV !== 'production') && key in instance.appContext.config.globalProperties) {
  2621. Object.defineProperty(ctx, key, {
  2622. enumerable: true,
  2623. configurable: true,
  2624. value
  2625. });
  2626. }
  2627. else {
  2628. ctx[key] = value;
  2629. }
  2630. }
  2631. return true;
  2632. },
  2633. has({ _: { data, setupState, accessCache, ctx, appContext, propsOptions } }, key) {
  2634. let normalizedProps;
  2635. return (!!accessCache[key] ||
  2636. (data !== EMPTY_OBJ && hasOwn(data, key)) ||
  2637. hasSetupBinding(setupState, key) ||
  2638. ((normalizedProps = propsOptions[0]) && hasOwn(normalizedProps, key)) ||
  2639. hasOwn(ctx, key) ||
  2640. hasOwn(publicPropertiesMap, key) ||
  2641. hasOwn(appContext.config.globalProperties, key));
  2642. },
  2643. defineProperty(target, key, descriptor) {
  2644. if (descriptor.get != null) {
  2645. // invalidate key cache of a getter based property #5417
  2646. target._.accessCache[key] = 0;
  2647. }
  2648. else if (hasOwn(descriptor, 'value')) {
  2649. this.set(target, key, descriptor.value, null);
  2650. }
  2651. return Reflect.defineProperty(target, key, descriptor);
  2652. }
  2653. };
  2654. if ((process.env.NODE_ENV !== 'production') && !false) {
  2655. PublicInstanceProxyHandlers.ownKeys = (target) => {
  2656. warn(`Avoid app logic that relies on enumerating keys on a component instance. ` +
  2657. `The keys will be empty in production mode to avoid performance overhead.`);
  2658. return Reflect.ownKeys(target);
  2659. };
  2660. }
  2661. // dev only
  2662. // In dev mode, the proxy target exposes the same properties as seen on `this`
  2663. // for easier console inspection. In prod mode it will be an empty object so
  2664. // these properties definitions can be skipped.
  2665. function createDevRenderContext(instance) {
  2666. const target = {};
  2667. // expose internal instance for proxy handlers
  2668. Object.defineProperty(target, `_`, {
  2669. configurable: true,
  2670. enumerable: false,
  2671. get: () => instance
  2672. });
  2673. // expose public properties
  2674. Object.keys(publicPropertiesMap).forEach(key => {
  2675. Object.defineProperty(target, key, {
  2676. configurable: true,
  2677. enumerable: false,
  2678. get: () => publicPropertiesMap[key](instance),
  2679. // intercepted by the proxy so no need for implementation,
  2680. // but needed to prevent set errors
  2681. set: NOOP
  2682. });
  2683. });
  2684. return target;
  2685. }
  2686. // dev only
  2687. function exposePropsOnRenderContext(instance) {
  2688. const { ctx, propsOptions: [propsOptions] } = instance;
  2689. if (propsOptions) {
  2690. Object.keys(propsOptions).forEach(key => {
  2691. Object.defineProperty(ctx, key, {
  2692. enumerable: true,
  2693. configurable: true,
  2694. get: () => instance.props[key],
  2695. set: NOOP
  2696. });
  2697. });
  2698. }
  2699. }
  2700. // dev only
  2701. function exposeSetupStateOnRenderContext(instance) {
  2702. const { ctx, setupState } = instance;
  2703. Object.keys(toRaw(setupState)).forEach(key => {
  2704. if (!setupState.__isScriptSetup) {
  2705. if (isReservedPrefix(key[0])) {
  2706. warn(`setup() return property ${JSON.stringify(key)} should not start with "$" or "_" ` +
  2707. `which are reserved prefixes for Vue internals.`);
  2708. return;
  2709. }
  2710. Object.defineProperty(ctx, key, {
  2711. enumerable: true,
  2712. configurable: true,
  2713. get: () => setupState[key],
  2714. set: NOOP
  2715. });
  2716. }
  2717. });
  2718. }
  2719. function createDuplicateChecker() {
  2720. const cache = Object.create(null);
  2721. return (type, key) => {
  2722. if (cache[key]) {
  2723. warn(`${type} property "${key}" is already defined in ${cache[key]}.`);
  2724. }
  2725. else {
  2726. cache[key] = type;
  2727. }
  2728. };
  2729. }
  2730. let shouldCacheAccess = true;
  2731. function applyOptions$1(instance) {
  2732. const options = resolveMergedOptions(instance);
  2733. const publicThis = instance.proxy;
  2734. const ctx = instance.ctx;
  2735. // do not cache property access on public proxy during state initialization
  2736. shouldCacheAccess = false;
  2737. // call beforeCreate first before accessing other options since
  2738. // the hook may mutate resolved options (#2791)
  2739. if (options.beforeCreate) {
  2740. callHook(options.beforeCreate, instance, "bc" /* LifecycleHooks.BEFORE_CREATE */);
  2741. }
  2742. const {
  2743. // state
  2744. data: dataOptions, computed: computedOptions, methods, watch: watchOptions, provide: provideOptions, inject: injectOptions,
  2745. // lifecycle
  2746. created, beforeMount, mounted, beforeUpdate, updated, activated, deactivated, beforeDestroy, beforeUnmount, destroyed, unmounted, render, renderTracked, renderTriggered, errorCaptured, serverPrefetch,
  2747. // public API
  2748. expose, inheritAttrs,
  2749. // assets
  2750. components, directives, filters } = options;
  2751. const checkDuplicateProperties = (process.env.NODE_ENV !== 'production') ? createDuplicateChecker() : null;
  2752. if ((process.env.NODE_ENV !== 'production')) {
  2753. const [propsOptions] = instance.propsOptions;
  2754. if (propsOptions) {
  2755. for (const key in propsOptions) {
  2756. checkDuplicateProperties("Props" /* OptionTypes.PROPS */, key);
  2757. }
  2758. }
  2759. }
  2760. // options initialization order (to be consistent with Vue 2):
  2761. // - props (already done outside of this function)
  2762. // - inject
  2763. // - methods
  2764. // - data (deferred since it relies on `this` access)
  2765. // - computed
  2766. // - watch (deferred since it relies on `this` access)
  2767. // fixed by xxxxxx
  2768. if (!__VUE_CREATED_DEFERRED__ && injectOptions) {
  2769. resolveInjections(injectOptions, ctx, checkDuplicateProperties, instance.appContext.config.unwrapInjectedRef);
  2770. }
  2771. if (methods) {
  2772. for (const key in methods) {
  2773. const methodHandler = methods[key];
  2774. if (isFunction(methodHandler)) {
  2775. // In dev mode, we use the `createRenderContext` function to define
  2776. // methods to the proxy target, and those are read-only but
  2777. // reconfigurable, so it needs to be redefined here
  2778. if ((process.env.NODE_ENV !== 'production')) {
  2779. Object.defineProperty(ctx, key, {
  2780. value: methodHandler.bind(publicThis),
  2781. configurable: true,
  2782. enumerable: true,
  2783. writable: true
  2784. });
  2785. }
  2786. else {
  2787. ctx[key] = methodHandler.bind(publicThis);
  2788. }
  2789. if ((process.env.NODE_ENV !== 'production')) {
  2790. checkDuplicateProperties("Methods" /* OptionTypes.METHODS */, key);
  2791. }
  2792. }
  2793. else if ((process.env.NODE_ENV !== 'production')) {
  2794. warn(`Method "${key}" has type "${typeof methodHandler}" in the component definition. ` +
  2795. `Did you reference the function correctly?`);
  2796. }
  2797. }
  2798. }
  2799. if (dataOptions) {
  2800. if ((process.env.NODE_ENV !== 'production') && !isFunction(dataOptions)) {
  2801. warn(`The data option must be a function. ` +
  2802. `Plain object usage is no longer supported.`);
  2803. }
  2804. const data = dataOptions.call(publicThis, publicThis);
  2805. if ((process.env.NODE_ENV !== 'production') && isPromise(data)) {
  2806. warn(`data() returned a Promise - note data() cannot be async; If you ` +
  2807. `intend to perform data fetching before component renders, use ` +
  2808. `async setup() + <Suspense>.`);
  2809. }
  2810. if (!isObject(data)) {
  2811. (process.env.NODE_ENV !== 'production') && warn(`data() should return an object.`);
  2812. }
  2813. else {
  2814. instance.data = reactive(data);
  2815. if ((process.env.NODE_ENV !== 'production')) {
  2816. for (const key in data) {
  2817. checkDuplicateProperties("Data" /* OptionTypes.DATA */, key);
  2818. // expose data on ctx during dev
  2819. if (!isReservedPrefix(key[0])) {
  2820. Object.defineProperty(ctx, key, {
  2821. configurable: true,
  2822. enumerable: true,
  2823. get: () => data[key],
  2824. set: NOOP
  2825. });
  2826. }
  2827. }
  2828. }
  2829. }
  2830. }
  2831. // state initialization complete at this point - start caching access
  2832. shouldCacheAccess = true;
  2833. if (computedOptions) {
  2834. for (const key in computedOptions) {
  2835. const opt = computedOptions[key];
  2836. const get = isFunction(opt)
  2837. ? opt.bind(publicThis, publicThis)
  2838. : isFunction(opt.get)
  2839. ? opt.get.bind(publicThis, publicThis)
  2840. : NOOP;
  2841. if ((process.env.NODE_ENV !== 'production') && get === NOOP) {
  2842. warn(`Computed property "${key}" has no getter.`);
  2843. }
  2844. const set = !isFunction(opt) && isFunction(opt.set)
  2845. ? opt.set.bind(publicThis)
  2846. : (process.env.NODE_ENV !== 'production')
  2847. ? () => {
  2848. warn(`Write operation failed: computed property "${key}" is readonly.`);
  2849. }
  2850. : NOOP;
  2851. const c = computed({
  2852. get,
  2853. set
  2854. });
  2855. Object.defineProperty(ctx, key, {
  2856. enumerable: true,
  2857. configurable: true,
  2858. get: () => c.value,
  2859. set: v => (c.value = v)
  2860. });
  2861. if ((process.env.NODE_ENV !== 'production')) {
  2862. checkDuplicateProperties("Computed" /* OptionTypes.COMPUTED */, key);
  2863. }
  2864. }
  2865. }
  2866. if (watchOptions) {
  2867. for (const key in watchOptions) {
  2868. createWatcher(watchOptions[key], ctx, publicThis, key);
  2869. }
  2870. }
  2871. // fixed by xxxxxx
  2872. if (!__VUE_CREATED_DEFERRED__) {
  2873. if (provideOptions) {
  2874. const provides = isFunction(provideOptions)
  2875. ? provideOptions.call(publicThis)
  2876. : provideOptions;
  2877. Reflect.ownKeys(provides).forEach(key => {
  2878. provide(key, provides[key]);
  2879. });
  2880. }
  2881. }
  2882. // fixed by xxxxxx
  2883. if (__VUE_CREATED_DEFERRED__) {
  2884. ctx.$callCreatedHook = function (name) {
  2885. if (created) {
  2886. return callHook(created, instance, "c" /* LifecycleHooks.CREATED */);
  2887. }
  2888. };
  2889. }
  2890. else {
  2891. if (created) {
  2892. callHook(created, instance, "c" /* LifecycleHooks.CREATED */);
  2893. }
  2894. }
  2895. function registerLifecycleHook(register, hook) {
  2896. if (isArray(hook)) {
  2897. hook.forEach(_hook => register(_hook.bind(publicThis)));
  2898. }
  2899. else if (hook) {
  2900. register(hook.bind(publicThis));
  2901. }
  2902. }
  2903. registerLifecycleHook(onBeforeMount, beforeMount);
  2904. registerLifecycleHook(onMounted, mounted);
  2905. registerLifecycleHook(onBeforeUpdate, beforeUpdate);
  2906. registerLifecycleHook(onUpdated, updated);
  2907. registerLifecycleHook(onActivated, activated);
  2908. registerLifecycleHook(onDeactivated, deactivated);
  2909. registerLifecycleHook(onErrorCaptured, errorCaptured);
  2910. registerLifecycleHook(onRenderTracked, renderTracked);
  2911. registerLifecycleHook(onRenderTriggered, renderTriggered);
  2912. registerLifecycleHook(onBeforeUnmount, beforeUnmount);
  2913. registerLifecycleHook(onUnmounted, unmounted);
  2914. registerLifecycleHook(onServerPrefetch, serverPrefetch);
  2915. if (isArray(expose)) {
  2916. if (expose.length) {
  2917. const exposed = instance.exposed || (instance.exposed = {});
  2918. expose.forEach(key => {
  2919. Object.defineProperty(exposed, key, {
  2920. get: () => publicThis[key],
  2921. set: val => (publicThis[key] = val)
  2922. });
  2923. });
  2924. }
  2925. else if (!instance.exposed) {
  2926. instance.exposed = {};
  2927. }
  2928. }
  2929. // options that are handled when creating the instance but also need to be
  2930. // applied from mixins
  2931. if (render && instance.render === NOOP) {
  2932. instance.render = render;
  2933. }
  2934. if (inheritAttrs != null) {
  2935. instance.inheritAttrs = inheritAttrs;
  2936. }
  2937. // asset options.
  2938. if (components)
  2939. instance.components = components;
  2940. if (directives)
  2941. instance.directives = directives;
  2942. // fixed by xxxxxx
  2943. if (instance.ctx.$onApplyOptions) {
  2944. instance.ctx.$onApplyOptions(options, instance, publicThis);
  2945. }
  2946. }
  2947. function resolveInjections(injectOptions, ctx, checkDuplicateProperties = NOOP, unwrapRef = false) {
  2948. if (isArray(injectOptions)) {
  2949. injectOptions = normalizeInject(injectOptions);
  2950. }
  2951. for (const key in injectOptions) {
  2952. const opt = injectOptions[key];
  2953. let injected;
  2954. if (isObject(opt)) {
  2955. if ('default' in opt) {
  2956. injected = inject(opt.from || key, opt.default, true /* treat default function as factory */);
  2957. }
  2958. else {
  2959. injected = inject(opt.from || key);
  2960. }
  2961. }
  2962. else {
  2963. injected = inject(opt);
  2964. }
  2965. if (isRef(injected)) {
  2966. // TODO remove the check in 3.3
  2967. if (unwrapRef) {
  2968. Object.defineProperty(ctx, key, {
  2969. enumerable: true,
  2970. configurable: true,
  2971. get: () => injected.value,
  2972. set: v => (injected.value = v)
  2973. });
  2974. }
  2975. else {
  2976. if ((process.env.NODE_ENV !== 'production')) {
  2977. warn(`injected property "${key}" is a ref and will be auto-unwrapped ` +
  2978. `and no longer needs \`.value\` in the next minor release. ` +
  2979. `To opt-in to the new behavior now, ` +
  2980. `set \`app.config.unwrapInjectedRef = true\` (this config is ` +
  2981. `temporary and will not be needed in the future.)`);
  2982. }
  2983. ctx[key] = injected;
  2984. }
  2985. }
  2986. else {
  2987. ctx[key] = injected;
  2988. }
  2989. if ((process.env.NODE_ENV !== 'production')) {
  2990. checkDuplicateProperties("Inject" /* OptionTypes.INJECT */, key);
  2991. }
  2992. }
  2993. }
  2994. function callHook(hook, instance, type) {
  2995. callWithAsyncErrorHandling(isArray(hook)
  2996. ? hook.map(h => h.bind(instance.proxy))
  2997. : hook.bind(instance.proxy), instance, type);
  2998. }
  2999. function createWatcher(raw, ctx, publicThis, key) {
  3000. const getter = key.includes('.')
  3001. ? createPathGetter(publicThis, key)
  3002. : () => publicThis[key];
  3003. if (isString(raw)) {
  3004. const handler = ctx[raw];
  3005. if (isFunction(handler)) {
  3006. watch(getter, handler);
  3007. }
  3008. else if ((process.env.NODE_ENV !== 'production')) {
  3009. warn(`Invalid watch handler specified by key "${raw}"`, handler);
  3010. }
  3011. }
  3012. else if (isFunction(raw)) {
  3013. watch(getter, raw.bind(publicThis));
  3014. }
  3015. else if (isObject(raw)) {
  3016. if (isArray(raw)) {
  3017. raw.forEach(r => createWatcher(r, ctx, publicThis, key));
  3018. }
  3019. else {
  3020. const handler = isFunction(raw.handler)
  3021. ? raw.handler.bind(publicThis)
  3022. : ctx[raw.handler];
  3023. if (isFunction(handler)) {
  3024. watch(getter, handler, raw);
  3025. }
  3026. else if ((process.env.NODE_ENV !== 'production')) {
  3027. warn(`Invalid watch handler specified by key "${raw.handler}"`, handler);
  3028. }
  3029. }
  3030. }
  3031. else if ((process.env.NODE_ENV !== 'production')) {
  3032. warn(`Invalid watch option: "${key}"`, raw);
  3033. }
  3034. }
  3035. /**
  3036. * Resolve merged options and cache it on the component.
  3037. * This is done only once per-component since the merging does not involve
  3038. * instances.
  3039. */
  3040. function resolveMergedOptions(instance) {
  3041. const base = instance.type;
  3042. const { mixins, extends: extendsOptions } = base;
  3043. const { mixins: globalMixins, optionsCache: cache, config: { optionMergeStrategies } } = instance.appContext;
  3044. const cached = cache.get(base);
  3045. let resolved;
  3046. if (cached) {
  3047. resolved = cached;
  3048. }
  3049. else if (!globalMixins.length && !mixins && !extendsOptions) {
  3050. {
  3051. resolved = base;
  3052. }
  3053. }
  3054. else {
  3055. resolved = {};
  3056. if (globalMixins.length) {
  3057. globalMixins.forEach(m => mergeOptions(resolved, m, optionMergeStrategies, true));
  3058. }
  3059. mergeOptions(resolved, base, optionMergeStrategies);
  3060. }
  3061. if (isObject(base)) {
  3062. cache.set(base, resolved);
  3063. }
  3064. return resolved;
  3065. }
  3066. function mergeOptions(to, from, strats, asMixin = false) {
  3067. const { mixins, extends: extendsOptions } = from;
  3068. if (extendsOptions) {
  3069. mergeOptions(to, extendsOptions, strats, true);
  3070. }
  3071. if (mixins) {
  3072. mixins.forEach((m) => mergeOptions(to, m, strats, true));
  3073. }
  3074. for (const key in from) {
  3075. if (asMixin && key === 'expose') {
  3076. (process.env.NODE_ENV !== 'production') &&
  3077. warn(`"expose" option is ignored when declared in mixins or extends. ` +
  3078. `It should only be declared in the base component itself.`);
  3079. }
  3080. else {
  3081. const strat = internalOptionMergeStrats[key] || (strats && strats[key]);
  3082. to[key] = strat ? strat(to[key], from[key]) : from[key];
  3083. }
  3084. }
  3085. return to;
  3086. }
  3087. const internalOptionMergeStrats = {
  3088. data: mergeDataFn,
  3089. props: mergeObjectOptions,
  3090. emits: mergeObjectOptions,
  3091. // objects
  3092. methods: mergeObjectOptions,
  3093. computed: mergeObjectOptions,
  3094. // lifecycle
  3095. beforeCreate: mergeAsArray$1,
  3096. created: mergeAsArray$1,
  3097. beforeMount: mergeAsArray$1,
  3098. mounted: mergeAsArray$1,
  3099. beforeUpdate: mergeAsArray$1,
  3100. updated: mergeAsArray$1,
  3101. beforeDestroy: mergeAsArray$1,
  3102. beforeUnmount: mergeAsArray$1,
  3103. destroyed: mergeAsArray$1,
  3104. unmounted: mergeAsArray$1,
  3105. activated: mergeAsArray$1,
  3106. deactivated: mergeAsArray$1,
  3107. errorCaptured: mergeAsArray$1,
  3108. serverPrefetch: mergeAsArray$1,
  3109. // assets
  3110. components: mergeObjectOptions,
  3111. directives: mergeObjectOptions,
  3112. // watch
  3113. watch: mergeWatchOptions,
  3114. // provide / inject
  3115. provide: mergeDataFn,
  3116. inject: mergeInject
  3117. };
  3118. function mergeDataFn(to, from) {
  3119. if (!from) {
  3120. return to;
  3121. }
  3122. if (!to) {
  3123. return from;
  3124. }
  3125. return function mergedDataFn() {
  3126. return (extend)(isFunction(to) ? to.call(this, this) : to, isFunction(from) ? from.call(this, this) : from);
  3127. };
  3128. }
  3129. function mergeInject(to, from) {
  3130. return mergeObjectOptions(normalizeInject(to), normalizeInject(from));
  3131. }
  3132. function normalizeInject(raw) {
  3133. if (isArray(raw)) {
  3134. const res = {};
  3135. for (let i = 0; i < raw.length; i++) {
  3136. res[raw[i]] = raw[i];
  3137. }
  3138. return res;
  3139. }
  3140. return raw;
  3141. }
  3142. function mergeAsArray$1(to, from) {
  3143. return to ? [...new Set([].concat(to, from))] : from;
  3144. }
  3145. function mergeObjectOptions(to, from) {
  3146. return to ? extend(extend(Object.create(null), to), from) : from;
  3147. }
  3148. function mergeWatchOptions(to, from) {
  3149. if (!to)
  3150. return from;
  3151. if (!from)
  3152. return to;
  3153. const merged = extend(Object.create(null), to);
  3154. for (const key in from) {
  3155. merged[key] = mergeAsArray$1(to[key], from[key]);
  3156. }
  3157. return merged;
  3158. }
  3159. function initProps(instance, rawProps, isStateful, // result of bitwise flag comparison
  3160. isSSR = false) {
  3161. const props = {};
  3162. const attrs = {};
  3163. // def(attrs, InternalObjectKey, 1) // fixed by xxxxxx
  3164. instance.propsDefaults = Object.create(null);
  3165. setFullProps(instance, rawProps, props, attrs);
  3166. // ensure all declared prop keys are present
  3167. for (const key in instance.propsOptions[0]) {
  3168. if (!(key in props)) {
  3169. props[key] = undefined;
  3170. }
  3171. }
  3172. // validation
  3173. if ((process.env.NODE_ENV !== 'production')) {
  3174. validateProps(rawProps || {}, props, instance);
  3175. }
  3176. if (isStateful) {
  3177. // stateful
  3178. instance.props = isSSR ? props : shallowReactive(props);
  3179. }
  3180. else {
  3181. if (!instance.type.props) {
  3182. // functional w/ optional props, props === attrs
  3183. instance.props = attrs;
  3184. }
  3185. else {
  3186. // functional w/ declared props
  3187. instance.props = props;
  3188. }
  3189. }
  3190. instance.attrs = attrs;
  3191. }
  3192. function isInHmrContext(instance) {
  3193. while (instance) {
  3194. if (instance.type.__hmrId)
  3195. return true;
  3196. instance = instance.parent;
  3197. }
  3198. }
  3199. function updateProps(instance, rawProps, rawPrevProps, optimized) {
  3200. const { props, attrs, vnode: { patchFlag } } = instance;
  3201. const rawCurrentProps = toRaw(props);
  3202. const [options] = instance.propsOptions;
  3203. let hasAttrsChanged = false;
  3204. if (
  3205. // always force full diff in dev
  3206. // - #1942 if hmr is enabled with sfc component
  3207. // - vite#872 non-sfc component used by sfc component
  3208. !((process.env.NODE_ENV !== 'production') && isInHmrContext(instance)) &&
  3209. (optimized || patchFlag > 0) &&
  3210. !(patchFlag & 16 /* PatchFlags.FULL_PROPS */)) {
  3211. if (patchFlag & 8 /* PatchFlags.PROPS */) {
  3212. // Compiler-generated props & no keys change, just set the updated
  3213. // the props.
  3214. const propsToUpdate = instance.vnode.dynamicProps;
  3215. for (let i = 0; i < propsToUpdate.length; i++) {
  3216. let key = propsToUpdate[i];
  3217. // skip if the prop key is a declared emit event listener
  3218. if (isEmitListener(instance.emitsOptions, key)) {
  3219. continue;
  3220. }
  3221. // PROPS flag guarantees rawProps to be non-null
  3222. const value = rawProps[key];
  3223. if (options) {
  3224. // attr / props separation was done on init and will be consistent
  3225. // in this code path, so just check if attrs have it.
  3226. if (hasOwn(attrs, key)) {
  3227. if (value !== attrs[key]) {
  3228. attrs[key] = value;
  3229. hasAttrsChanged = true;
  3230. }
  3231. }
  3232. else {
  3233. const camelizedKey = camelize(key);
  3234. props[camelizedKey] = resolvePropValue(options, rawCurrentProps, camelizedKey, value, instance, false /* isAbsent */);
  3235. }
  3236. }
  3237. else {
  3238. if (value !== attrs[key]) {
  3239. attrs[key] = value;
  3240. hasAttrsChanged = true;
  3241. }
  3242. }
  3243. }
  3244. }
  3245. }
  3246. else {
  3247. // full props update.
  3248. if (setFullProps(instance, rawProps, props, attrs)) {
  3249. hasAttrsChanged = true;
  3250. }
  3251. // in case of dynamic props, check if we need to delete keys from
  3252. // the props object
  3253. let kebabKey;
  3254. for (const key in rawCurrentProps) {
  3255. if (!rawProps ||
  3256. // for camelCase
  3257. (!hasOwn(rawProps, key) &&
  3258. // it's possible the original props was passed in as kebab-case
  3259. // and converted to camelCase (#955)
  3260. ((kebabKey = hyphenate(key)) === key || !hasOwn(rawProps, kebabKey)))) {
  3261. if (options) {
  3262. if (rawPrevProps &&
  3263. // for camelCase
  3264. (rawPrevProps[key] !== undefined ||
  3265. // for kebab-case
  3266. rawPrevProps[kebabKey] !== undefined)) {
  3267. props[key] = resolvePropValue(options, rawCurrentProps, key, undefined, instance, true /* isAbsent */);
  3268. }
  3269. }
  3270. else {
  3271. delete props[key];
  3272. }
  3273. }
  3274. }
  3275. // in the case of functional component w/o props declaration, props and
  3276. // attrs point to the same object so it should already have been updated.
  3277. if (attrs !== rawCurrentProps) {
  3278. for (const key in attrs) {
  3279. if (!rawProps ||
  3280. (!hasOwn(rawProps, key) &&
  3281. (!false ))) {
  3282. delete attrs[key];
  3283. hasAttrsChanged = true;
  3284. }
  3285. }
  3286. }
  3287. }
  3288. // trigger updates for $attrs in case it's used in component slots
  3289. if (hasAttrsChanged) {
  3290. trigger(instance, "set" /* TriggerOpTypes.SET */, '$attrs');
  3291. }
  3292. if ((process.env.NODE_ENV !== 'production')) {
  3293. validateProps(rawProps || {}, props, instance);
  3294. }
  3295. }
  3296. function setFullProps(instance, rawProps, props, attrs) {
  3297. const [options, needCastKeys] = instance.propsOptions;
  3298. let hasAttrsChanged = false;
  3299. let rawCastValues;
  3300. if (rawProps) {
  3301. for (let key in rawProps) {
  3302. // key, ref are reserved and never passed down
  3303. if (isReservedProp(key)) {
  3304. continue;
  3305. }
  3306. const value = rawProps[key];
  3307. // prop option names are camelized during normalization, so to support
  3308. // kebab -> camel conversion here we need to camelize the key.
  3309. let camelKey;
  3310. if (options && hasOwn(options, (camelKey = camelize(key)))) {
  3311. if (!needCastKeys || !needCastKeys.includes(camelKey)) {
  3312. props[camelKey] = value;
  3313. }
  3314. else {
  3315. (rawCastValues || (rawCastValues = {}))[camelKey] = value;
  3316. }
  3317. }
  3318. else if (!isEmitListener(instance.emitsOptions, key)) {
  3319. if (!(key in attrs) || value !== attrs[key]) {
  3320. attrs[key] = value;
  3321. hasAttrsChanged = true;
  3322. }
  3323. }
  3324. }
  3325. }
  3326. if (needCastKeys) {
  3327. const rawCurrentProps = toRaw(props);
  3328. const castValues = rawCastValues || EMPTY_OBJ;
  3329. for (let i = 0; i < needCastKeys.length; i++) {
  3330. const key = needCastKeys[i];
  3331. props[key] = resolvePropValue(options, rawCurrentProps, key, castValues[key], instance, !hasOwn(castValues, key));
  3332. }
  3333. }
  3334. return hasAttrsChanged;
  3335. }
  3336. function resolvePropValue(options, props, key, value, instance, isAbsent) {
  3337. const opt = options[key];
  3338. if (opt != null) {
  3339. const hasDefault = hasOwn(opt, 'default');
  3340. // default values
  3341. if (hasDefault && value === undefined) {
  3342. const defaultValue = opt.default;
  3343. if (opt.type !== Function && isFunction(defaultValue)) {
  3344. const { propsDefaults } = instance;
  3345. if (key in propsDefaults) {
  3346. value = propsDefaults[key];
  3347. }
  3348. else {
  3349. setCurrentInstance(instance);
  3350. value = propsDefaults[key] = defaultValue.call(null, props);
  3351. unsetCurrentInstance();
  3352. }
  3353. }
  3354. else {
  3355. value = defaultValue;
  3356. }
  3357. }
  3358. // boolean casting
  3359. if (opt[0 /* BooleanFlags.shouldCast */]) {
  3360. if (isAbsent && !hasDefault) {
  3361. value = false;
  3362. }
  3363. else if (opt[1 /* BooleanFlags.shouldCastTrue */] &&
  3364. (value === '' || value === hyphenate(key))) {
  3365. value = true;
  3366. }
  3367. }
  3368. }
  3369. return value;
  3370. }
  3371. function normalizePropsOptions(comp, appContext, asMixin = false) {
  3372. const cache = appContext.propsCache;
  3373. const cached = cache.get(comp);
  3374. if (cached) {
  3375. return cached;
  3376. }
  3377. const raw = comp.props;
  3378. const normalized = {};
  3379. const needCastKeys = [];
  3380. // apply mixin/extends props
  3381. let hasExtends = false;
  3382. if (__VUE_OPTIONS_API__ && !isFunction(comp)) {
  3383. const extendProps = (raw) => {
  3384. hasExtends = true;
  3385. const [props, keys] = normalizePropsOptions(raw, appContext, true);
  3386. extend(normalized, props);
  3387. if (keys)
  3388. needCastKeys.push(...keys);
  3389. };
  3390. if (!asMixin && appContext.mixins.length) {
  3391. appContext.mixins.forEach(extendProps);
  3392. }
  3393. if (comp.extends) {
  3394. extendProps(comp.extends);
  3395. }
  3396. if (comp.mixins) {
  3397. comp.mixins.forEach(extendProps);
  3398. }
  3399. }
  3400. if (!raw && !hasExtends) {
  3401. if (isObject(comp)) {
  3402. cache.set(comp, EMPTY_ARR);
  3403. }
  3404. return EMPTY_ARR;
  3405. }
  3406. if (isArray(raw)) {
  3407. for (let i = 0; i < raw.length; i++) {
  3408. if ((process.env.NODE_ENV !== 'production') && !isString(raw[i])) {
  3409. warn(`props must be strings when using array syntax.`, raw[i]);
  3410. }
  3411. const normalizedKey = camelize(raw[i]);
  3412. if (validatePropName(normalizedKey)) {
  3413. normalized[normalizedKey] = EMPTY_OBJ;
  3414. }
  3415. }
  3416. }
  3417. else if (raw) {
  3418. if ((process.env.NODE_ENV !== 'production') && !isObject(raw)) {
  3419. warn(`invalid props options`, raw);
  3420. }
  3421. for (const key in raw) {
  3422. const normalizedKey = camelize(key);
  3423. if (validatePropName(normalizedKey)) {
  3424. const opt = raw[key];
  3425. const prop = (normalized[normalizedKey] =
  3426. isArray(opt) || isFunction(opt) ? { type: opt } : Object.assign({}, opt));
  3427. if (prop) {
  3428. const booleanIndex = getTypeIndex(Boolean, prop.type);
  3429. const stringIndex = getTypeIndex(String, prop.type);
  3430. prop[0 /* BooleanFlags.shouldCast */] = booleanIndex > -1;
  3431. prop[1 /* BooleanFlags.shouldCastTrue */] =
  3432. stringIndex < 0 || booleanIndex < stringIndex;
  3433. // if the prop needs boolean casting or default value
  3434. if (booleanIndex > -1 || hasOwn(prop, 'default')) {
  3435. needCastKeys.push(normalizedKey);
  3436. }
  3437. }
  3438. }
  3439. }
  3440. }
  3441. const res = [normalized, needCastKeys];
  3442. if (isObject(comp)) {
  3443. cache.set(comp, res);
  3444. }
  3445. return res;
  3446. }
  3447. function validatePropName(key) {
  3448. if (key[0] !== '$') {
  3449. return true;
  3450. }
  3451. else if ((process.env.NODE_ENV !== 'production')) {
  3452. warn(`Invalid prop name: "${key}" is a reserved property.`);
  3453. }
  3454. return false;
  3455. }
  3456. // use function string name to check type constructors
  3457. // so that it works across vms / iframes.
  3458. function getType(ctor) {
  3459. const match = ctor && ctor.toString().match(/^\s*(function|class) (\w+)/);
  3460. return match ? match[2] : ctor === null ? 'null' : '';
  3461. }
  3462. function isSameType(a, b) {
  3463. return getType(a) === getType(b);
  3464. }
  3465. function getTypeIndex(type, expectedTypes) {
  3466. if (isArray(expectedTypes)) {
  3467. return expectedTypes.findIndex(t => isSameType(t, type));
  3468. }
  3469. else if (isFunction(expectedTypes)) {
  3470. return isSameType(expectedTypes, type) ? 0 : -1;
  3471. }
  3472. return -1;
  3473. }
  3474. /**
  3475. * dev only
  3476. */
  3477. function validateProps(rawProps, props, instance) {
  3478. const resolvedValues = toRaw(props);
  3479. const options = instance.propsOptions[0];
  3480. for (const key in options) {
  3481. let opt = options[key];
  3482. if (opt == null)
  3483. continue;
  3484. validateProp(key, resolvedValues[key], opt, !hasOwn(rawProps, key) && !hasOwn(rawProps, hyphenate(key)));
  3485. }
  3486. }
  3487. /**
  3488. * dev only
  3489. */
  3490. function validateProp(name, value, prop, isAbsent) {
  3491. const { type, required, validator } = prop;
  3492. // required!
  3493. if (required && isAbsent) {
  3494. warn('Missing required prop: "' + name + '"');
  3495. return;
  3496. }
  3497. // missing but optional
  3498. if (value == null && !prop.required) {
  3499. return;
  3500. }
  3501. // type check
  3502. if (type != null && type !== true) {
  3503. let isValid = false;
  3504. const types = isArray(type) ? type : [type];
  3505. const expectedTypes = [];
  3506. // value is valid as long as one of the specified types match
  3507. for (let i = 0; i < types.length && !isValid; i++) {
  3508. const { valid, expectedType } = assertType(value, types[i]);
  3509. expectedTypes.push(expectedType || '');
  3510. isValid = valid;
  3511. }
  3512. if (!isValid) {
  3513. warn(getInvalidTypeMessage(name, value, expectedTypes));
  3514. return;
  3515. }
  3516. }
  3517. // custom validator
  3518. if (validator && !validator(value)) {
  3519. warn('Invalid prop: custom validator check failed for prop "' + name + '".');
  3520. }
  3521. }
  3522. const isSimpleType = /*#__PURE__*/ makeMap('String,Number,Boolean,Function,Symbol,BigInt');
  3523. /**
  3524. * dev only
  3525. */
  3526. function assertType(value, type) {
  3527. let valid;
  3528. const expectedType = getType(type);
  3529. if (isSimpleType(expectedType)) {
  3530. const t = typeof value;
  3531. valid = t === expectedType.toLowerCase();
  3532. // for primitive wrapper objects
  3533. if (!valid && t === 'object') {
  3534. valid = value instanceof type;
  3535. }
  3536. }
  3537. else if (expectedType === 'Object') {
  3538. valid = isObject(value);
  3539. }
  3540. else if (expectedType === 'Array') {
  3541. valid = isArray(value);
  3542. }
  3543. else if (expectedType === 'null') {
  3544. valid = value === null;
  3545. }
  3546. else {
  3547. valid = value instanceof type;
  3548. }
  3549. return {
  3550. valid,
  3551. expectedType
  3552. };
  3553. }
  3554. /**
  3555. * dev only
  3556. */
  3557. function getInvalidTypeMessage(name, value, expectedTypes) {
  3558. let message = `Invalid prop: type check failed for prop "${name}".` +
  3559. ` Expected ${expectedTypes.map(capitalize).join(' | ')}`;
  3560. const expectedType = expectedTypes[0];
  3561. const receivedType = toRawType(value);
  3562. const expectedValue = styleValue(value, expectedType);
  3563. const receivedValue = styleValue(value, receivedType);
  3564. // check if we need to specify expected value
  3565. if (expectedTypes.length === 1 &&
  3566. isExplicable(expectedType) &&
  3567. !isBoolean(expectedType, receivedType)) {
  3568. message += ` with value ${expectedValue}`;
  3569. }
  3570. message += `, got ${receivedType} `;
  3571. // check if we need to specify received value
  3572. if (isExplicable(receivedType)) {
  3573. message += `with value ${receivedValue}.`;
  3574. }
  3575. return message;
  3576. }
  3577. /**
  3578. * dev only
  3579. */
  3580. function styleValue(value, type) {
  3581. if (type === 'String') {
  3582. return `"${value}"`;
  3583. }
  3584. else if (type === 'Number') {
  3585. return `${Number(value)}`;
  3586. }
  3587. else {
  3588. return `${value}`;
  3589. }
  3590. }
  3591. /**
  3592. * dev only
  3593. */
  3594. function isExplicable(type) {
  3595. const explicitTypes = ['string', 'number', 'boolean'];
  3596. return explicitTypes.some(elem => type.toLowerCase() === elem);
  3597. }
  3598. /**
  3599. * dev only
  3600. */
  3601. function isBoolean(...args) {
  3602. return args.some(elem => elem.toLowerCase() === 'boolean');
  3603. }
  3604. function createAppContext() {
  3605. return {
  3606. app: null,
  3607. config: {
  3608. isNativeTag: NO,
  3609. performance: false,
  3610. globalProperties: {},
  3611. optionMergeStrategies: {},
  3612. errorHandler: undefined,
  3613. warnHandler: undefined,
  3614. compilerOptions: {}
  3615. },
  3616. mixins: [],
  3617. components: {},
  3618. directives: {},
  3619. provides: Object.create(null),
  3620. optionsCache: new WeakMap(),
  3621. propsCache: new WeakMap(),
  3622. emitsCache: new WeakMap()
  3623. };
  3624. }
  3625. let uid$1 = 0;
  3626. function createAppAPI(render, // fixed by xxxxxx
  3627. hydrate) {
  3628. return function createApp(rootComponent, rootProps = null) {
  3629. if (!isFunction(rootComponent)) {
  3630. rootComponent = Object.assign({}, rootComponent);
  3631. }
  3632. if (rootProps != null && !isObject(rootProps)) {
  3633. (process.env.NODE_ENV !== 'production') && warn(`root props passed to app.mount() must be an object.`);
  3634. rootProps = null;
  3635. }
  3636. const context = createAppContext();
  3637. const installedPlugins = new Set();
  3638. // fixed by xxxxxx
  3639. // let isMounted = false
  3640. const app = (context.app = {
  3641. _uid: uid$1++,
  3642. _component: rootComponent,
  3643. _props: rootProps,
  3644. _container: null,
  3645. _context: context,
  3646. _instance: null,
  3647. version,
  3648. get config() {
  3649. return context.config;
  3650. },
  3651. set config(v) {
  3652. if ((process.env.NODE_ENV !== 'production')) {
  3653. warn(`app.config cannot be replaced. Modify individual options instead.`);
  3654. }
  3655. },
  3656. use(plugin, ...options) {
  3657. if (installedPlugins.has(plugin)) {
  3658. (process.env.NODE_ENV !== 'production') && warn(`Plugin has already been applied to target app.`);
  3659. }
  3660. else if (plugin && isFunction(plugin.install)) {
  3661. installedPlugins.add(plugin);
  3662. plugin.install(app, ...options);
  3663. }
  3664. else if (isFunction(plugin)) {
  3665. installedPlugins.add(plugin);
  3666. plugin(app, ...options);
  3667. }
  3668. else if ((process.env.NODE_ENV !== 'production')) {
  3669. warn(`A plugin must either be a function or an object with an "install" ` +
  3670. `function.`);
  3671. }
  3672. return app;
  3673. },
  3674. mixin(mixin) {
  3675. if (__VUE_OPTIONS_API__) {
  3676. if (!context.mixins.includes(mixin)) {
  3677. context.mixins.push(mixin);
  3678. }
  3679. else if ((process.env.NODE_ENV !== 'production')) {
  3680. warn('Mixin has already been applied to target app' +
  3681. (mixin.name ? `: ${mixin.name}` : ''));
  3682. }
  3683. }
  3684. else if ((process.env.NODE_ENV !== 'production')) {
  3685. warn('Mixins are only available in builds supporting Options API');
  3686. }
  3687. return app;
  3688. },
  3689. component(name, component) {
  3690. if ((process.env.NODE_ENV !== 'production')) {
  3691. validateComponentName(name, context.config);
  3692. }
  3693. if (!component) {
  3694. return context.components[name];
  3695. }
  3696. if ((process.env.NODE_ENV !== 'production') && context.components[name]) {
  3697. warn(`Component "${name}" has already been registered in target app.`);
  3698. }
  3699. context.components[name] = component;
  3700. return app;
  3701. },
  3702. directive(name, directive) {
  3703. if ((process.env.NODE_ENV !== 'production')) {
  3704. validateDirectiveName(name);
  3705. }
  3706. if (!directive) {
  3707. return context.directives[name];
  3708. }
  3709. if ((process.env.NODE_ENV !== 'production') && context.directives[name]) {
  3710. warn(`Directive "${name}" has already been registered in target app.`);
  3711. }
  3712. context.directives[name] = directive;
  3713. return app;
  3714. },
  3715. // fixed by xxxxxx
  3716. mount() { },
  3717. // fixed by xxxxxx
  3718. unmount() { },
  3719. provide(key, value) {
  3720. if ((process.env.NODE_ENV !== 'production') && key in context.provides) {
  3721. warn(`App already provides property with key "${String(key)}". ` +
  3722. `It will be overwritten with the new value.`);
  3723. }
  3724. context.provides[key] = value;
  3725. return app;
  3726. }
  3727. });
  3728. // fixed by xxxxxx
  3729. // if (false) {
  3730. // installAppCompatProperties(app, context, render)
  3731. // }
  3732. return app;
  3733. };
  3734. }
  3735. /* eslint-disable no-restricted-globals */
  3736. let supported;
  3737. let perf;
  3738. function startMeasure(instance, type) {
  3739. if (instance.appContext.config.performance && isSupported()) {
  3740. perf.mark(`vue-${type}-${instance.uid}`);
  3741. }
  3742. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  3743. devtoolsPerfStart(instance, type, isSupported() ? perf.now() : Date.now());
  3744. }
  3745. }
  3746. function endMeasure(instance, type) {
  3747. if (instance.appContext.config.performance && isSupported()) {
  3748. const startTag = `vue-${type}-${instance.uid}`;
  3749. const endTag = startTag + `:end`;
  3750. perf.mark(endTag);
  3751. perf.measure(`<${formatComponentName(instance, instance.type)}> ${type}`, startTag, endTag);
  3752. perf.clearMarks(startTag);
  3753. perf.clearMarks(endTag);
  3754. }
  3755. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  3756. devtoolsPerfEnd(instance, type, isSupported() ? perf.now() : Date.now());
  3757. }
  3758. }
  3759. function isSupported() {
  3760. if (supported !== undefined) {
  3761. return supported;
  3762. }
  3763. if (typeof window !== 'undefined' && window.performance) {
  3764. supported = true;
  3765. perf = window.performance;
  3766. }
  3767. else {
  3768. supported = false;
  3769. }
  3770. return supported;
  3771. }
  3772. const queuePostRenderEffect$1 = queuePostFlushCb;
  3773. const isTeleport = (type) => type.__isTeleport;
  3774. const Fragment = Symbol((process.env.NODE_ENV !== 'production') ? 'Fragment' : undefined);
  3775. const Text = Symbol((process.env.NODE_ENV !== 'production') ? 'Text' : undefined);
  3776. const Comment = Symbol((process.env.NODE_ENV !== 'production') ? 'Comment' : undefined);
  3777. const Static = Symbol((process.env.NODE_ENV !== 'production') ? 'Static' : undefined);
  3778. let currentBlock = null;
  3779. // Whether we should be tracking dynamic child nodes inside a block.
  3780. // Only tracks when this value is > 0
  3781. // We are not using a simple boolean because this value may need to be
  3782. // incremented/decremented by nested usage of v-once (see below)
  3783. let isBlockTreeEnabled = 1;
  3784. /**
  3785. * Block tracking sometimes needs to be disabled, for example during the
  3786. * creation of a tree that needs to be cached by v-once. The compiler generates
  3787. * code like this:
  3788. *
  3789. * ``` js
  3790. * _cache[1] || (
  3791. * setBlockTracking(-1),
  3792. * _cache[1] = createVNode(...),
  3793. * setBlockTracking(1),
  3794. * _cache[1]
  3795. * )
  3796. * ```
  3797. *
  3798. * @private
  3799. */
  3800. function setBlockTracking(value) {
  3801. isBlockTreeEnabled += value;
  3802. }
  3803. function isVNode(value) {
  3804. return value ? value.__v_isVNode === true : false;
  3805. }
  3806. const createVNodeWithArgsTransform = (...args) => {
  3807. return _createVNode(...(args));
  3808. };
  3809. const InternalObjectKey = `__vInternal`;
  3810. const normalizeKey = ({ key }) => key != null ? key : null;
  3811. const normalizeRef = ({ ref, ref_key, ref_for }) => {
  3812. return (ref != null
  3813. ? isString(ref) || isRef(ref) || isFunction(ref)
  3814. ? { i: currentRenderingInstance, r: ref, k: ref_key, f: !!ref_for }
  3815. : ref
  3816. : null);
  3817. };
  3818. function createBaseVNode(type, props = null, children = null, patchFlag = 0, dynamicProps = null, shapeFlag = type === Fragment ? 0 : 1 /* ShapeFlags.ELEMENT */, isBlockNode = false, needFullChildrenNormalization = false) {
  3819. const vnode = {
  3820. __v_isVNode: true,
  3821. __v_skip: true,
  3822. type,
  3823. props,
  3824. key: props && normalizeKey(props),
  3825. ref: props && normalizeRef(props),
  3826. scopeId: currentScopeId,
  3827. slotScopeIds: null,
  3828. children,
  3829. component: null,
  3830. suspense: null,
  3831. ssContent: null,
  3832. ssFallback: null,
  3833. dirs: null,
  3834. transition: null,
  3835. el: null,
  3836. anchor: null,
  3837. target: null,
  3838. targetAnchor: null,
  3839. staticCount: 0,
  3840. shapeFlag,
  3841. patchFlag,
  3842. dynamicProps,
  3843. dynamicChildren: null,
  3844. appContext: null,
  3845. ctx: currentRenderingInstance
  3846. };
  3847. if (needFullChildrenNormalization) {
  3848. normalizeChildren(vnode, children);
  3849. }
  3850. else if (children) {
  3851. // compiled element vnode - if children is passed, only possible types are
  3852. // string or Array.
  3853. vnode.shapeFlag |= isString(children)
  3854. ? 8 /* ShapeFlags.TEXT_CHILDREN */
  3855. : 16 /* ShapeFlags.ARRAY_CHILDREN */;
  3856. }
  3857. // validate key
  3858. if ((process.env.NODE_ENV !== 'production') && vnode.key !== vnode.key) {
  3859. warn(`VNode created with invalid key (NaN). VNode type:`, vnode.type);
  3860. }
  3861. // track vnode for block tree
  3862. if (isBlockTreeEnabled > 0 &&
  3863. // avoid a block node from tracking itself
  3864. !isBlockNode &&
  3865. // has current parent block
  3866. currentBlock &&
  3867. // presence of a patch flag indicates this node needs patching on updates.
  3868. // component nodes also should always be patched, because even if the
  3869. // component doesn't need to update, it needs to persist the instance on to
  3870. // the next vnode so that it can be properly unmounted later.
  3871. (vnode.patchFlag > 0 || shapeFlag & 6 /* ShapeFlags.COMPONENT */) &&
  3872. // the EVENTS flag is only for hydration and if it is the only flag, the
  3873. // vnode should not be considered dynamic due to handler caching.
  3874. vnode.patchFlag !== 32 /* PatchFlags.HYDRATE_EVENTS */) {
  3875. currentBlock.push(vnode);
  3876. }
  3877. return vnode;
  3878. }
  3879. const createVNode$1 = ((process.env.NODE_ENV !== 'production') ? createVNodeWithArgsTransform : _createVNode);
  3880. function _createVNode(type, props = null, children = null, patchFlag = 0, dynamicProps = null, isBlockNode = false) {
  3881. if (!type || type === NULL_DYNAMIC_COMPONENT) {
  3882. if ((process.env.NODE_ENV !== 'production') && !type) {
  3883. warn(`Invalid vnode type when creating vnode: ${type}.`);
  3884. }
  3885. type = Comment;
  3886. }
  3887. if (isVNode(type)) {
  3888. // createVNode receiving an existing vnode. This happens in cases like
  3889. // <component :is="vnode"/>
  3890. // #2078 make sure to merge refs during the clone instead of overwriting it
  3891. const cloned = cloneVNode(type, props, true /* mergeRef: true */);
  3892. if (children) {
  3893. normalizeChildren(cloned, children);
  3894. }
  3895. if (isBlockTreeEnabled > 0 && !isBlockNode && currentBlock) {
  3896. if (cloned.shapeFlag & 6 /* ShapeFlags.COMPONENT */) {
  3897. currentBlock[currentBlock.indexOf(type)] = cloned;
  3898. }
  3899. else {
  3900. currentBlock.push(cloned);
  3901. }
  3902. }
  3903. cloned.patchFlag |= -2 /* PatchFlags.BAIL */;
  3904. return cloned;
  3905. }
  3906. // class component normalization.
  3907. if (isClassComponent(type)) {
  3908. type = type.__vccOpts;
  3909. }
  3910. // class & style normalization.
  3911. if (props) {
  3912. // for reactive or proxy objects, we need to clone it to enable mutation.
  3913. props = guardReactiveProps(props);
  3914. let { class: klass, style } = props;
  3915. if (klass && !isString(klass)) {
  3916. props.class = normalizeClass(klass);
  3917. }
  3918. if (isObject(style)) {
  3919. // reactive state objects need to be cloned since they are likely to be
  3920. // mutated
  3921. if (isProxy(style) && !isArray(style)) {
  3922. style = extend({}, style);
  3923. }
  3924. props.style = normalizeStyle(style);
  3925. }
  3926. }
  3927. // encode the vnode type information into a bitmap
  3928. const shapeFlag = isString(type)
  3929. ? 1 /* ShapeFlags.ELEMENT */
  3930. : isTeleport(type)
  3931. ? 64 /* ShapeFlags.TELEPORT */
  3932. : isObject(type)
  3933. ? 4 /* ShapeFlags.STATEFUL_COMPONENT */
  3934. : isFunction(type)
  3935. ? 2 /* ShapeFlags.FUNCTIONAL_COMPONENT */
  3936. : 0;
  3937. if ((process.env.NODE_ENV !== 'production') && shapeFlag & 4 /* ShapeFlags.STATEFUL_COMPONENT */ && isProxy(type)) {
  3938. type = toRaw(type);
  3939. warn(`Vue received a Component which was made a reactive object. This can ` +
  3940. `lead to unnecessary performance overhead, and should be avoided by ` +
  3941. `marking the component with \`markRaw\` or using \`shallowRef\` ` +
  3942. `instead of \`ref\`.`, `\nComponent that was made reactive: `, type);
  3943. }
  3944. return createBaseVNode(type, props, children, patchFlag, dynamicProps, shapeFlag, isBlockNode, true);
  3945. }
  3946. function guardReactiveProps(props) {
  3947. if (!props)
  3948. return null;
  3949. return isProxy(props) || InternalObjectKey in props
  3950. ? extend({}, props)
  3951. : props;
  3952. }
  3953. function cloneVNode(vnode, extraProps, mergeRef = false) {
  3954. // This is intentionally NOT using spread or extend to avoid the runtime
  3955. // key enumeration cost.
  3956. const { props, ref, patchFlag, children } = vnode;
  3957. const mergedProps = extraProps ? mergeProps(props || {}, extraProps) : props;
  3958. const cloned = {
  3959. __v_isVNode: true,
  3960. __v_skip: true,
  3961. type: vnode.type,
  3962. props: mergedProps,
  3963. key: mergedProps && normalizeKey(mergedProps),
  3964. ref: extraProps && extraProps.ref
  3965. ? // #2078 in the case of <component :is="vnode" ref="extra"/>
  3966. // if the vnode itself already has a ref, cloneVNode will need to merge
  3967. // the refs so the single vnode can be set on multiple refs
  3968. mergeRef && ref
  3969. ? isArray(ref)
  3970. ? ref.concat(normalizeRef(extraProps))
  3971. : [ref, normalizeRef(extraProps)]
  3972. : normalizeRef(extraProps)
  3973. : ref,
  3974. scopeId: vnode.scopeId,
  3975. slotScopeIds: vnode.slotScopeIds,
  3976. children: (process.env.NODE_ENV !== 'production') && patchFlag === -1 /* PatchFlags.HOISTED */ && isArray(children)
  3977. ? children.map(deepCloneVNode)
  3978. : children,
  3979. target: vnode.target,
  3980. targetAnchor: vnode.targetAnchor,
  3981. staticCount: vnode.staticCount,
  3982. shapeFlag: vnode.shapeFlag,
  3983. // if the vnode is cloned with extra props, we can no longer assume its
  3984. // existing patch flag to be reliable and need to add the FULL_PROPS flag.
  3985. // note: preserve flag for fragments since they use the flag for children
  3986. // fast paths only.
  3987. patchFlag: extraProps && vnode.type !== Fragment
  3988. ? patchFlag === -1 // hoisted node
  3989. ? 16 /* PatchFlags.FULL_PROPS */
  3990. : patchFlag | 16 /* PatchFlags.FULL_PROPS */
  3991. : patchFlag,
  3992. dynamicProps: vnode.dynamicProps,
  3993. dynamicChildren: vnode.dynamicChildren,
  3994. appContext: vnode.appContext,
  3995. dirs: vnode.dirs,
  3996. transition: vnode.transition,
  3997. // These should technically only be non-null on mounted VNodes. However,
  3998. // they *should* be copied for kept-alive vnodes. So we just always copy
  3999. // them since them being non-null during a mount doesn't affect the logic as
  4000. // they will simply be overwritten.
  4001. component: vnode.component,
  4002. suspense: vnode.suspense,
  4003. ssContent: vnode.ssContent && cloneVNode(vnode.ssContent),
  4004. ssFallback: vnode.ssFallback && cloneVNode(vnode.ssFallback),
  4005. el: vnode.el,
  4006. anchor: vnode.anchor,
  4007. ctx: vnode.ctx,
  4008. ce: vnode.ce
  4009. };
  4010. return cloned;
  4011. }
  4012. /**
  4013. * Dev only, for HMR of hoisted vnodes reused in v-for
  4014. * https://github.com/vitejs/vite/issues/2022
  4015. */
  4016. function deepCloneVNode(vnode) {
  4017. const cloned = cloneVNode(vnode);
  4018. if (isArray(vnode.children)) {
  4019. cloned.children = vnode.children.map(deepCloneVNode);
  4020. }
  4021. return cloned;
  4022. }
  4023. /**
  4024. * @private
  4025. */
  4026. function createTextVNode(text = ' ', flag = 0) {
  4027. return createVNode$1(Text, null, text, flag);
  4028. }
  4029. function normalizeChildren(vnode, children) {
  4030. let type = 0;
  4031. const { shapeFlag } = vnode;
  4032. if (children == null) {
  4033. children = null;
  4034. }
  4035. else if (isArray(children)) {
  4036. type = 16 /* ShapeFlags.ARRAY_CHILDREN */;
  4037. }
  4038. else if (typeof children === 'object') {
  4039. if (shapeFlag & (1 /* ShapeFlags.ELEMENT */ | 64 /* ShapeFlags.TELEPORT */)) {
  4040. // Normalize slot to plain children for plain element and Teleport
  4041. const slot = children.default;
  4042. if (slot) {
  4043. // _c marker is added by withCtx() indicating this is a compiled slot
  4044. slot._c && (slot._d = false);
  4045. normalizeChildren(vnode, slot());
  4046. slot._c && (slot._d = true);
  4047. }
  4048. return;
  4049. }
  4050. else {
  4051. type = 32 /* ShapeFlags.SLOTS_CHILDREN */;
  4052. const slotFlag = children._;
  4053. if (!slotFlag && !(InternalObjectKey in children)) {
  4054. children._ctx = currentRenderingInstance;
  4055. }
  4056. else if (slotFlag === 3 /* SlotFlags.FORWARDED */ && currentRenderingInstance) {
  4057. // a child component receives forwarded slots from the parent.
  4058. // its slot type is determined by its parent's slot type.
  4059. if (currentRenderingInstance.slots._ === 1 /* SlotFlags.STABLE */) {
  4060. children._ = 1 /* SlotFlags.STABLE */;
  4061. }
  4062. else {
  4063. children._ = 2 /* SlotFlags.DYNAMIC */;
  4064. vnode.patchFlag |= 1024 /* PatchFlags.DYNAMIC_SLOTS */;
  4065. }
  4066. }
  4067. }
  4068. }
  4069. else if (isFunction(children)) {
  4070. children = { default: children, _ctx: currentRenderingInstance };
  4071. type = 32 /* ShapeFlags.SLOTS_CHILDREN */;
  4072. }
  4073. else {
  4074. children = String(children);
  4075. // force teleport children to array so it can be moved around
  4076. if (shapeFlag & 64 /* ShapeFlags.TELEPORT */) {
  4077. type = 16 /* ShapeFlags.ARRAY_CHILDREN */;
  4078. children = [createTextVNode(children)];
  4079. }
  4080. else {
  4081. type = 8 /* ShapeFlags.TEXT_CHILDREN */;
  4082. }
  4083. }
  4084. vnode.children = children;
  4085. vnode.shapeFlag |= type;
  4086. }
  4087. function mergeProps(...args) {
  4088. const ret = {};
  4089. for (let i = 0; i < args.length; i++) {
  4090. const toMerge = args[i];
  4091. for (const key in toMerge) {
  4092. if (key === 'class') {
  4093. if (ret.class !== toMerge.class) {
  4094. ret.class = normalizeClass([ret.class, toMerge.class]);
  4095. }
  4096. }
  4097. else if (key === 'style') {
  4098. ret.style = normalizeStyle([ret.style, toMerge.style]);
  4099. }
  4100. else if (isOn(key)) {
  4101. const existing = ret[key];
  4102. const incoming = toMerge[key];
  4103. if (incoming &&
  4104. existing !== incoming &&
  4105. !(isArray(existing) && existing.includes(incoming))) {
  4106. ret[key] = existing
  4107. ? [].concat(existing, incoming)
  4108. : incoming;
  4109. }
  4110. }
  4111. else if (key !== '') {
  4112. ret[key] = toMerge[key];
  4113. }
  4114. }
  4115. }
  4116. return ret;
  4117. }
  4118. const emptyAppContext = createAppContext();
  4119. let uid = 0;
  4120. function createComponentInstance(vnode, parent, suspense) {
  4121. const type = vnode.type;
  4122. // inherit parent app context - or - if root, adopt from root vnode
  4123. const appContext = (parent ? parent.appContext : vnode.appContext) || emptyAppContext;
  4124. const instance = {
  4125. uid: uid++,
  4126. vnode,
  4127. type,
  4128. parent,
  4129. appContext,
  4130. root: null,
  4131. next: null,
  4132. subTree: null,
  4133. effect: null,
  4134. update: null,
  4135. scope: new EffectScope(true /* detached */),
  4136. render: null,
  4137. proxy: null,
  4138. exposed: null,
  4139. exposeProxy: null,
  4140. withProxy: null,
  4141. provides: parent ? parent.provides : Object.create(appContext.provides),
  4142. accessCache: null,
  4143. renderCache: [],
  4144. // local resolved assets
  4145. components: null,
  4146. directives: null,
  4147. // resolved props and emits options
  4148. propsOptions: normalizePropsOptions(type, appContext),
  4149. emitsOptions: normalizeEmitsOptions(type, appContext),
  4150. // emit
  4151. emit: null,
  4152. emitted: null,
  4153. // props default value
  4154. propsDefaults: EMPTY_OBJ,
  4155. // inheritAttrs
  4156. inheritAttrs: type.inheritAttrs,
  4157. // state
  4158. ctx: EMPTY_OBJ,
  4159. data: EMPTY_OBJ,
  4160. props: EMPTY_OBJ,
  4161. attrs: EMPTY_OBJ,
  4162. slots: EMPTY_OBJ,
  4163. refs: EMPTY_OBJ,
  4164. setupState: EMPTY_OBJ,
  4165. setupContext: null,
  4166. // suspense related
  4167. suspense,
  4168. suspenseId: suspense ? suspense.pendingId : 0,
  4169. asyncDep: null,
  4170. asyncResolved: false,
  4171. // lifecycle hooks
  4172. // not using enums here because it results in computed properties
  4173. isMounted: false,
  4174. isUnmounted: false,
  4175. isDeactivated: false,
  4176. bc: null,
  4177. c: null,
  4178. bm: null,
  4179. m: null,
  4180. bu: null,
  4181. u: null,
  4182. um: null,
  4183. bum: null,
  4184. da: null,
  4185. a: null,
  4186. rtg: null,
  4187. rtc: null,
  4188. ec: null,
  4189. sp: null
  4190. };
  4191. if ((process.env.NODE_ENV !== 'production')) {
  4192. instance.ctx = createDevRenderContext(instance);
  4193. }
  4194. else {
  4195. instance.ctx = { _: instance };
  4196. }
  4197. instance.root = parent ? parent.root : instance;
  4198. instance.emit = emit.bind(null, instance);
  4199. // apply custom element special handling
  4200. if (vnode.ce) {
  4201. vnode.ce(instance);
  4202. }
  4203. return instance;
  4204. }
  4205. let currentInstance = null;
  4206. const getCurrentInstance = () => currentInstance || currentRenderingInstance;
  4207. const setCurrentInstance = (instance) => {
  4208. currentInstance = instance;
  4209. instance.scope.on();
  4210. };
  4211. const unsetCurrentInstance = () => {
  4212. currentInstance && currentInstance.scope.off();
  4213. currentInstance = null;
  4214. };
  4215. const isBuiltInTag = /*#__PURE__*/ makeMap('slot,component');
  4216. function validateComponentName(name, config) {
  4217. const appIsNativeTag = config.isNativeTag || NO;
  4218. if (isBuiltInTag(name) || appIsNativeTag(name)) {
  4219. warn('Do not use built-in or reserved HTML elements as component id: ' + name);
  4220. }
  4221. }
  4222. function isStatefulComponent(instance) {
  4223. return instance.vnode.shapeFlag & 4 /* ShapeFlags.STATEFUL_COMPONENT */;
  4224. }
  4225. let isInSSRComponentSetup = false;
  4226. function setupComponent(instance, isSSR = false) {
  4227. isInSSRComponentSetup = isSSR;
  4228. // fixed by xxxxxx
  4229. const { props /*, children*/ } = instance.vnode;
  4230. const isStateful = isStatefulComponent(instance);
  4231. initProps(instance, props, isStateful, isSSR);
  4232. // initSlots(instance, children) // fixed by xxxxxx
  4233. const setupResult = isStateful
  4234. ? setupStatefulComponent(instance, isSSR)
  4235. : undefined;
  4236. isInSSRComponentSetup = false;
  4237. return setupResult;
  4238. }
  4239. function setupStatefulComponent(instance, isSSR) {
  4240. const Component = instance.type;
  4241. if ((process.env.NODE_ENV !== 'production')) {
  4242. if (Component.name) {
  4243. validateComponentName(Component.name, instance.appContext.config);
  4244. }
  4245. if (Component.components) {
  4246. const names = Object.keys(Component.components);
  4247. for (let i = 0; i < names.length; i++) {
  4248. validateComponentName(names[i], instance.appContext.config);
  4249. }
  4250. }
  4251. if (Component.directives) {
  4252. const names = Object.keys(Component.directives);
  4253. for (let i = 0; i < names.length; i++) {
  4254. validateDirectiveName(names[i]);
  4255. }
  4256. }
  4257. if (Component.compilerOptions && isRuntimeOnly()) {
  4258. warn(`"compilerOptions" is only supported when using a build of Vue that ` +
  4259. `includes the runtime compiler. Since you are using a runtime-only ` +
  4260. `build, the options should be passed via your build tool config instead.`);
  4261. }
  4262. }
  4263. // 0. create render proxy property access cache
  4264. instance.accessCache = Object.create(null);
  4265. // 1. create public instance / render proxy
  4266. // also mark it raw so it's never observed
  4267. instance.proxy = markRaw(new Proxy(instance.ctx, PublicInstanceProxyHandlers));
  4268. if ((process.env.NODE_ENV !== 'production')) {
  4269. exposePropsOnRenderContext(instance);
  4270. }
  4271. // 2. call setup()
  4272. const { setup } = Component;
  4273. if (setup) {
  4274. const setupContext = (instance.setupContext =
  4275. setup.length > 1 ? createSetupContext(instance) : null);
  4276. setCurrentInstance(instance);
  4277. pauseTracking();
  4278. const setupResult = callWithErrorHandling(setup, instance, 0 /* ErrorCodes.SETUP_FUNCTION */, [(process.env.NODE_ENV !== 'production') ? shallowReadonly(instance.props) : instance.props, setupContext]);
  4279. resetTracking();
  4280. unsetCurrentInstance();
  4281. if (isPromise(setupResult)) {
  4282. setupResult.then(unsetCurrentInstance, unsetCurrentInstance);
  4283. // fixed by xxxxxx
  4284. if ((process.env.NODE_ENV !== 'production')) {
  4285. warn(`setup() returned a Promise, but the version of Vue you are using ` +
  4286. `does not support it yet.`);
  4287. }
  4288. }
  4289. else {
  4290. handleSetupResult(instance, setupResult, isSSR);
  4291. }
  4292. }
  4293. else {
  4294. finishComponentSetup(instance, isSSR);
  4295. }
  4296. }
  4297. function handleSetupResult(instance, setupResult, isSSR) {
  4298. if (isFunction(setupResult)) {
  4299. // setup returned an inline render function
  4300. {
  4301. instance.render = setupResult;
  4302. }
  4303. }
  4304. else if (isObject(setupResult)) {
  4305. if ((process.env.NODE_ENV !== 'production') && isVNode(setupResult)) {
  4306. warn(`setup() should not return VNodes directly - ` +
  4307. `return a render function instead.`);
  4308. }
  4309. // setup returned bindings.
  4310. // assuming a render function compiled from template is present.
  4311. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  4312. instance.devtoolsRawSetupState = setupResult;
  4313. }
  4314. instance.setupState = proxyRefs(setupResult);
  4315. if ((process.env.NODE_ENV !== 'production')) {
  4316. exposeSetupStateOnRenderContext(instance);
  4317. }
  4318. }
  4319. else if ((process.env.NODE_ENV !== 'production') && setupResult !== undefined) {
  4320. warn(`setup() should return an object. Received: ${setupResult === null ? 'null' : typeof setupResult}`);
  4321. }
  4322. finishComponentSetup(instance, isSSR);
  4323. }
  4324. let compile;
  4325. // dev only
  4326. const isRuntimeOnly = () => !compile;
  4327. function finishComponentSetup(instance, isSSR, skipOptions) {
  4328. const Component = instance.type;
  4329. // template / render function normalization
  4330. // could be already set when returned from setup()
  4331. if (!instance.render) {
  4332. instance.render = (Component.render || NOOP);
  4333. }
  4334. // support for 2.x options
  4335. if (__VUE_OPTIONS_API__ && !(false )) {
  4336. setCurrentInstance(instance);
  4337. pauseTracking();
  4338. applyOptions$1(instance);
  4339. resetTracking();
  4340. unsetCurrentInstance();
  4341. }
  4342. // warn missing template/render
  4343. // the runtime compilation of template in SSR is done by server-render
  4344. if ((process.env.NODE_ENV !== 'production') && !Component.render && instance.render === NOOP && !isSSR) {
  4345. /* istanbul ignore if */
  4346. if (Component.template) {
  4347. warn(`Component provided template option but ` +
  4348. `runtime compilation is not supported in this build of Vue.` +
  4349. (` Configure your bundler to alias "vue" to "vue/dist/vue.esm-bundler.js".`
  4350. ) /* should not happen */);
  4351. }
  4352. else {
  4353. warn(`Component is missing template or render function.`);
  4354. }
  4355. }
  4356. }
  4357. function createAttrsProxy(instance) {
  4358. return new Proxy(instance.attrs, (process.env.NODE_ENV !== 'production')
  4359. ? {
  4360. get(target, key) {
  4361. track(instance, "get" /* TrackOpTypes.GET */, '$attrs');
  4362. return target[key];
  4363. },
  4364. set() {
  4365. warn(`setupContext.attrs is readonly.`);
  4366. return false;
  4367. },
  4368. deleteProperty() {
  4369. warn(`setupContext.attrs is readonly.`);
  4370. return false;
  4371. }
  4372. }
  4373. : {
  4374. get(target, key) {
  4375. track(instance, "get" /* TrackOpTypes.GET */, '$attrs');
  4376. return target[key];
  4377. }
  4378. });
  4379. }
  4380. function createSetupContext(instance) {
  4381. const expose = exposed => {
  4382. if ((process.env.NODE_ENV !== 'production')) {
  4383. if (instance.exposed) {
  4384. warn(`expose() should be called only once per setup().`);
  4385. }
  4386. if (exposed != null) {
  4387. let exposedType = typeof exposed;
  4388. if (exposedType === 'object') {
  4389. if (isArray(exposed)) {
  4390. exposedType = 'array';
  4391. }
  4392. else if (isRef(exposed)) {
  4393. exposedType = 'ref';
  4394. }
  4395. }
  4396. if (exposedType !== 'object') {
  4397. warn(`expose() should be passed a plain object, received ${exposedType}.`);
  4398. }
  4399. }
  4400. }
  4401. instance.exposed = exposed || {};
  4402. };
  4403. let attrs;
  4404. if ((process.env.NODE_ENV !== 'production')) {
  4405. // We use getters in dev in case libs like test-utils overwrite instance
  4406. // properties (overwrites should not be done in prod)
  4407. return Object.freeze({
  4408. get attrs() {
  4409. return attrs || (attrs = createAttrsProxy(instance));
  4410. },
  4411. get slots() {
  4412. return shallowReadonly(instance.slots);
  4413. },
  4414. get emit() {
  4415. return (event, ...args) => instance.emit(event, ...args);
  4416. },
  4417. expose
  4418. });
  4419. }
  4420. else {
  4421. return {
  4422. get attrs() {
  4423. return attrs || (attrs = createAttrsProxy(instance));
  4424. },
  4425. slots: instance.slots,
  4426. emit: instance.emit,
  4427. expose
  4428. };
  4429. }
  4430. }
  4431. function getExposeProxy(instance) {
  4432. if (instance.exposed) {
  4433. return (instance.exposeProxy ||
  4434. (instance.exposeProxy = new Proxy(proxyRefs(markRaw(instance.exposed)), {
  4435. get(target, key) {
  4436. if (key in target) {
  4437. return target[key];
  4438. }
  4439. // fixed by xxxxxx 框架内部需要访问很多非 public 属性,暂不做限制
  4440. return instance.proxy[key];
  4441. // else if (key in publicPropertiesMap) {
  4442. // return publicPropertiesMap[key](instance)
  4443. // }
  4444. },
  4445. has(target, key) {
  4446. return key in target || key in publicPropertiesMap;
  4447. }
  4448. })));
  4449. }
  4450. }
  4451. const classifyRE = /(?:^|[-_])(\w)/g;
  4452. const classify = (str) => str.replace(classifyRE, c => c.toUpperCase()).replace(/[-_]/g, '');
  4453. function getComponentName(Component, includeInferred = true) {
  4454. return isFunction(Component)
  4455. ? Component.displayName || Component.name
  4456. : Component.name || (includeInferred && Component.__name);
  4457. }
  4458. /* istanbul ignore next */
  4459. function formatComponentName(instance, Component, isRoot = false) {
  4460. let name = getComponentName(Component);
  4461. if (!name && Component.__file) {
  4462. const match = Component.__file.match(/([^/\\]+)\.\w+$/);
  4463. if (match) {
  4464. name = match[1];
  4465. }
  4466. }
  4467. if (!name && instance && instance.parent) {
  4468. // try to infer the name based on reverse resolution
  4469. const inferFromRegistry = (registry) => {
  4470. for (const key in registry) {
  4471. if (registry[key] === Component) {
  4472. return key;
  4473. }
  4474. }
  4475. };
  4476. name =
  4477. inferFromRegistry(instance.components ||
  4478. instance.parent.type.components) || inferFromRegistry(instance.appContext.components);
  4479. }
  4480. return name ? classify(name) : isRoot ? `App` : `Anonymous`;
  4481. }
  4482. function isClassComponent(value) {
  4483. return isFunction(value) && '__vccOpts' in value;
  4484. }
  4485. const computed = ((getterOrOptions, debugOptions) => {
  4486. // @ts-ignore
  4487. return computed$1(getterOrOptions, debugOptions, isInSSRComponentSetup);
  4488. });
  4489. // dev only
  4490. const warnRuntimeUsage = (method) => warn(`${method}() is a compiler-hint helper that is only usable inside ` +
  4491. `<script setup> of a single file component. Its arguments should be ` +
  4492. `compiled away and passing it at runtime has no effect.`);
  4493. // implementation
  4494. function defineProps() {
  4495. if ((process.env.NODE_ENV !== 'production')) {
  4496. warnRuntimeUsage(`defineProps`);
  4497. }
  4498. return null;
  4499. }
  4500. // implementation
  4501. function defineEmits() {
  4502. if ((process.env.NODE_ENV !== 'production')) {
  4503. warnRuntimeUsage(`defineEmits`);
  4504. }
  4505. return null;
  4506. }
  4507. /**
  4508. * Vue `<script setup>` compiler macro for declaring a component's exposed
  4509. * instance properties when it is accessed by a parent component via template
  4510. * refs.
  4511. *
  4512. * `<script setup>` components are closed by default - i.e. variables inside
  4513. * the `<script setup>` scope is not exposed to parent unless explicitly exposed
  4514. * via `defineExpose`.
  4515. *
  4516. * This is only usable inside `<script setup>`, is compiled away in the
  4517. * output and should **not** be actually called at runtime.
  4518. */
  4519. function defineExpose(exposed) {
  4520. if ((process.env.NODE_ENV !== 'production')) {
  4521. warnRuntimeUsage(`defineExpose`);
  4522. }
  4523. }
  4524. /**
  4525. * Vue `<script setup>` compiler macro for providing props default values when
  4526. * using type-based `defineProps` declaration.
  4527. *
  4528. * Example usage:
  4529. * ```ts
  4530. * withDefaults(defineProps<{
  4531. * size?: number
  4532. * labels?: string[]
  4533. * }>(), {
  4534. * size: 3,
  4535. * labels: () => ['default label']
  4536. * })
  4537. * ```
  4538. *
  4539. * This is only usable inside `<script setup>`, is compiled away in the output
  4540. * and should **not** be actually called at runtime.
  4541. */
  4542. function withDefaults(props, defaults) {
  4543. if ((process.env.NODE_ENV !== 'production')) {
  4544. warnRuntimeUsage(`withDefaults`);
  4545. }
  4546. return null;
  4547. }
  4548. function useSlots() {
  4549. return getContext().slots;
  4550. }
  4551. function useAttrs() {
  4552. return getContext().attrs;
  4553. }
  4554. function getContext() {
  4555. const i = getCurrentInstance();
  4556. if ((process.env.NODE_ENV !== 'production') && !i) {
  4557. warn(`useContext() called without active instance.`);
  4558. }
  4559. return i.setupContext || (i.setupContext = createSetupContext(i));
  4560. }
  4561. /**
  4562. * Runtime helper for merging default declarations. Imported by compiled code
  4563. * only.
  4564. * @internal
  4565. */
  4566. function mergeDefaults(raw, defaults) {
  4567. const props = isArray(raw)
  4568. ? raw.reduce((normalized, p) => ((normalized[p] = {}), normalized), {})
  4569. : raw;
  4570. for (const key in defaults) {
  4571. const opt = props[key];
  4572. if (opt) {
  4573. if (isArray(opt) || isFunction(opt)) {
  4574. props[key] = { type: opt, default: defaults[key] };
  4575. }
  4576. else {
  4577. opt.default = defaults[key];
  4578. }
  4579. }
  4580. else if (opt === null) {
  4581. props[key] = { default: defaults[key] };
  4582. }
  4583. else if ((process.env.NODE_ENV !== 'production')) {
  4584. warn(`props default key "${key}" has no corresponding declaration.`);
  4585. }
  4586. }
  4587. return props;
  4588. }
  4589. /**
  4590. * `<script setup>` helper for persisting the current instance context over
  4591. * async/await flows.
  4592. *
  4593. * `@vue/compiler-sfc` converts the following:
  4594. *
  4595. * ```ts
  4596. * const x = await foo()
  4597. * ```
  4598. *
  4599. * into:
  4600. *
  4601. * ```ts
  4602. * let __temp, __restore
  4603. * const x = (([__temp, __restore] = withAsyncContext(() => foo())),__temp=await __temp,__restore(),__temp)
  4604. * ```
  4605. * @internal
  4606. */
  4607. function withAsyncContext(getAwaitable) {
  4608. const ctx = getCurrentInstance();
  4609. if ((process.env.NODE_ENV !== 'production') && !ctx) {
  4610. warn(`withAsyncContext called without active current instance. ` +
  4611. `This is likely a bug.`);
  4612. }
  4613. let awaitable = getAwaitable();
  4614. unsetCurrentInstance();
  4615. if (isPromise(awaitable)) {
  4616. awaitable = awaitable.catch(e => {
  4617. setCurrentInstance(ctx);
  4618. throw e;
  4619. });
  4620. }
  4621. return [awaitable, () => setCurrentInstance(ctx)];
  4622. }
  4623. const ssrContextKey = Symbol((process.env.NODE_ENV !== 'production') ? `ssrContext` : ``);
  4624. const useSSRContext = () => {
  4625. {
  4626. const ctx = inject(ssrContextKey);
  4627. if (!ctx) {
  4628. (process.env.NODE_ENV !== 'production') &&
  4629. warn(`Server rendering context not provided. Make sure to only call ` +
  4630. `useSSRContext() conditionally in the server build.`);
  4631. }
  4632. return ctx;
  4633. }
  4634. };
  4635. // Core API ------------------------------------------------------------------
  4636. const version = "3.2.47";
  4637. /**
  4638. * @internal only exposed in compat builds
  4639. */
  4640. const resolveFilter = null;
  4641. function unwrapper(target) {
  4642. return unref(target);
  4643. }
  4644. function defineAsyncComponent(source) {
  4645. console.error('defineAsyncComponent is unsupported');
  4646. }
  4647. // import deepCopy from './deepCopy'
  4648. /**
  4649. * https://raw.githubusercontent.com/Tencent/westore/master/packages/westore/utils/diff.js
  4650. */
  4651. const ARRAYTYPE = '[object Array]';
  4652. const OBJECTTYPE = '[object Object]';
  4653. // const FUNCTIONTYPE = '[object Function]'
  4654. function diff(current, pre) {
  4655. const result = {};
  4656. syncKeys(current, pre);
  4657. _diff(current, pre, '', result);
  4658. return result;
  4659. }
  4660. function syncKeys(current, pre) {
  4661. current = unwrapper(current);
  4662. if (current === pre)
  4663. return;
  4664. const rootCurrentType = toTypeString(current);
  4665. const rootPreType = toTypeString(pre);
  4666. if (rootCurrentType == OBJECTTYPE && rootPreType == OBJECTTYPE) {
  4667. for (let key in pre) {
  4668. const currentValue = current[key];
  4669. if (currentValue === undefined) {
  4670. current[key] = null;
  4671. }
  4672. else {
  4673. syncKeys(currentValue, pre[key]);
  4674. }
  4675. }
  4676. }
  4677. else if (rootCurrentType == ARRAYTYPE && rootPreType == ARRAYTYPE) {
  4678. if (current.length >= pre.length) {
  4679. pre.forEach((item, index) => {
  4680. syncKeys(current[index], item);
  4681. });
  4682. }
  4683. }
  4684. }
  4685. function _diff(current, pre, path, result) {
  4686. current = unwrapper(current);
  4687. if (current === pre)
  4688. return;
  4689. const rootCurrentType = toTypeString(current);
  4690. const rootPreType = toTypeString(pre);
  4691. if (rootCurrentType == OBJECTTYPE) {
  4692. if (rootPreType != OBJECTTYPE ||
  4693. Object.keys(current).length < Object.keys(pre).length) {
  4694. setResult(result, path, current);
  4695. }
  4696. else {
  4697. for (let key in current) {
  4698. const currentValue = unwrapper(current[key]);
  4699. const preValue = pre[key];
  4700. const currentType = toTypeString(currentValue);
  4701. const preType = toTypeString(preValue);
  4702. if (currentType != ARRAYTYPE && currentType != OBJECTTYPE) {
  4703. if (currentValue != preValue) {
  4704. setResult(result, (path == '' ? '' : path + '.') + key, currentValue);
  4705. }
  4706. }
  4707. else if (currentType == ARRAYTYPE) {
  4708. if (preType != ARRAYTYPE) {
  4709. setResult(result, (path == '' ? '' : path + '.') + key, currentValue);
  4710. }
  4711. else {
  4712. if (currentValue.length < preValue.length) {
  4713. setResult(result, (path == '' ? '' : path + '.') + key, currentValue);
  4714. }
  4715. else {
  4716. currentValue.forEach((item, index) => {
  4717. _diff(item, preValue[index], (path == '' ? '' : path + '.') + key + '[' + index + ']', result);
  4718. });
  4719. }
  4720. }
  4721. }
  4722. else if (currentType == OBJECTTYPE) {
  4723. if (preType != OBJECTTYPE ||
  4724. Object.keys(currentValue).length < Object.keys(preValue).length) {
  4725. setResult(result, (path == '' ? '' : path + '.') + key, currentValue);
  4726. }
  4727. else {
  4728. for (let subKey in currentValue) {
  4729. _diff(currentValue[subKey], preValue[subKey], (path == '' ? '' : path + '.') + key + '.' + subKey, result);
  4730. }
  4731. }
  4732. }
  4733. }
  4734. }
  4735. }
  4736. else if (rootCurrentType == ARRAYTYPE) {
  4737. if (rootPreType != ARRAYTYPE) {
  4738. setResult(result, path, current);
  4739. }
  4740. else {
  4741. if (current.length < pre.length) {
  4742. setResult(result, path, current);
  4743. }
  4744. else {
  4745. current.forEach((item, index) => {
  4746. _diff(item, pre[index], path + '[' + index + ']', result);
  4747. });
  4748. }
  4749. }
  4750. }
  4751. else {
  4752. setResult(result, path, current);
  4753. }
  4754. }
  4755. function setResult(result, k, v) {
  4756. result[k] = v; //deepCopy(v)
  4757. }
  4758. function hasComponentEffect(instance) {
  4759. return queue.includes(instance.update);
  4760. }
  4761. function flushCallbacks(instance) {
  4762. const ctx = instance.ctx;
  4763. const callbacks = ctx.__next_tick_callbacks;
  4764. if (callbacks && callbacks.length) {
  4765. if (process.env.UNI_DEBUG) {
  4766. const mpInstance = ctx.$scope;
  4767. console.log('[' +
  4768. +new Date() +
  4769. '][' +
  4770. (mpInstance.is || mpInstance.route) +
  4771. '][' +
  4772. instance.uid +
  4773. ']:flushCallbacks[' +
  4774. callbacks.length +
  4775. ']');
  4776. }
  4777. const copies = callbacks.slice(0);
  4778. callbacks.length = 0;
  4779. for (let i = 0; i < copies.length; i++) {
  4780. copies[i]();
  4781. }
  4782. }
  4783. }
  4784. function nextTick(instance, fn) {
  4785. const ctx = instance.ctx;
  4786. if (!ctx.__next_tick_pending && !hasComponentEffect(instance)) {
  4787. if (process.env.UNI_DEBUG) {
  4788. const mpInstance = ctx.$scope;
  4789. console.log('[' +
  4790. +new Date() +
  4791. '][' +
  4792. (mpInstance.is || mpInstance.route) +
  4793. '][' +
  4794. instance.uid +
  4795. ']:nextVueTick');
  4796. }
  4797. return nextTick$1(fn && fn.bind(instance.proxy));
  4798. }
  4799. if (process.env.UNI_DEBUG) {
  4800. const mpInstance = ctx.$scope;
  4801. console.log('[' +
  4802. +new Date() +
  4803. '][' +
  4804. (mpInstance.is || mpInstance.route) +
  4805. '][' +
  4806. instance.uid +
  4807. ']:nextMPTick');
  4808. }
  4809. let _resolve;
  4810. if (!ctx.__next_tick_callbacks) {
  4811. ctx.__next_tick_callbacks = [];
  4812. }
  4813. ctx.__next_tick_callbacks.push(() => {
  4814. if (fn) {
  4815. callWithErrorHandling(fn.bind(instance.proxy), instance, 14 /* ErrorCodes.SCHEDULER */);
  4816. }
  4817. else if (_resolve) {
  4818. _resolve(instance.proxy);
  4819. }
  4820. });
  4821. return new Promise(resolve => {
  4822. _resolve = resolve;
  4823. });
  4824. }
  4825. function clone(src, seen) {
  4826. src = unwrapper(src);
  4827. const type = typeof src;
  4828. if (type === 'object' && src !== null) {
  4829. let copy = seen.get(src);
  4830. if (typeof copy !== 'undefined') {
  4831. // (circular refs)
  4832. return copy;
  4833. }
  4834. if (isArray(src)) {
  4835. const len = src.length;
  4836. copy = new Array(len);
  4837. seen.set(src, copy);
  4838. for (let i = 0; i < len; i++) {
  4839. copy[i] = clone(src[i], seen);
  4840. }
  4841. }
  4842. else {
  4843. copy = {};
  4844. seen.set(src, copy);
  4845. for (const name in src) {
  4846. if (hasOwn(src, name)) {
  4847. copy[name] = clone(src[name], seen);
  4848. }
  4849. }
  4850. }
  4851. return copy;
  4852. }
  4853. if (type !== 'symbol') {
  4854. return src;
  4855. }
  4856. }
  4857. /**
  4858. * 与微信小程序保持一致的深度克隆
  4859. * @param src
  4860. * @returns
  4861. */
  4862. function deepCopy(src) {
  4863. return clone(src, typeof WeakMap !== 'undefined' ? new WeakMap() : new Map());
  4864. }
  4865. function getMPInstanceData(instance, keys) {
  4866. const data = instance.data;
  4867. const ret = Object.create(null);
  4868. //仅同步 data 中有的数据
  4869. keys.forEach(key => {
  4870. ret[key] = data[key];
  4871. });
  4872. return ret;
  4873. }
  4874. function patch(instance, data, oldData) {
  4875. if (!data) {
  4876. return;
  4877. }
  4878. // TODO 微信小程序会对 props 序列化,目前通过序列化再次触发数据响应式收集,因为 render 中收集的数据可能不全面(也不能仅仅这里收集,render 中也要收集),导致子组件无法局部响应式更新
  4879. // 举例:
  4880. // uni-indexed-list 组件传递 item 给 uni-indexed-list-item 组件,uni-indexed-list-item 发送点击到 uni-indexed-list 组件中修改 item.checked
  4881. // uni-indexed-list 组件 render 中并未访问 item.checked(在 uni-indexed-list-item 中访问了,但被小程序序列化了,无法响应式),故无法收集依赖
  4882. data = deepCopy(data);
  4883. // data = JSON.parse(JSON.stringify(data))
  4884. const ctx = instance.ctx;
  4885. const mpType = ctx.mpType;
  4886. if (mpType === 'page' || mpType === 'component') {
  4887. data.r0 = 1; // ready
  4888. const start = Date.now();
  4889. const mpInstance = ctx.$scope;
  4890. const keys = Object.keys(data);
  4891. // data.__webviewId__ = mpInstance.data.__webviewId__
  4892. const diffData = diff(data, oldData || getMPInstanceData(mpInstance, keys));
  4893. if (Object.keys(diffData).length) {
  4894. if (process.env.UNI_DEBUG) {
  4895. console.log('[' +
  4896. +new Date() +
  4897. '][' +
  4898. (mpInstance.is || mpInstance.route) +
  4899. '][' +
  4900. instance.uid +
  4901. '][耗时' +
  4902. (Date.now() - start) +
  4903. ']差量更新', JSON.stringify(diffData));
  4904. }
  4905. ctx.__next_tick_pending = true;
  4906. mpInstance.setData(diffData, () => {
  4907. ctx.__next_tick_pending = false;
  4908. flushCallbacks(instance);
  4909. });
  4910. // props update may have triggered pre-flush watchers.
  4911. flushPreFlushCbs();
  4912. }
  4913. else {
  4914. flushCallbacks(instance);
  4915. }
  4916. }
  4917. }
  4918. function initAppConfig(appConfig) {
  4919. appConfig.globalProperties.$nextTick = function $nextTick(fn) {
  4920. return nextTick(this.$, fn);
  4921. };
  4922. }
  4923. function onApplyOptions(options, instance, publicThis) {
  4924. instance.appContext.config.globalProperties.$applyOptions(options, instance, publicThis);
  4925. const computedOptions = options.computed;
  4926. if (computedOptions) {
  4927. const keys = Object.keys(computedOptions);
  4928. if (keys.length) {
  4929. const ctx = instance.ctx;
  4930. if (!ctx.$computedKeys) {
  4931. ctx.$computedKeys = [];
  4932. }
  4933. ctx.$computedKeys.push(...keys);
  4934. }
  4935. }
  4936. // remove
  4937. delete instance.ctx.$onApplyOptions;
  4938. }
  4939. /**
  4940. * Function for handling a template ref
  4941. */
  4942. function setRef$1(instance, isUnmount = false) {
  4943. const { setupState, $templateRefs, ctx: { $scope, $mpPlatform } } = instance;
  4944. if ($mpPlatform === 'mp-alipay') {
  4945. return;
  4946. }
  4947. if (!$templateRefs || !$scope) {
  4948. return;
  4949. }
  4950. if (isUnmount) {
  4951. return $templateRefs.forEach(templateRef => setTemplateRef(templateRef, null, setupState));
  4952. }
  4953. const check = $mpPlatform === 'mp-baidu' || $mpPlatform === 'mp-toutiao';
  4954. const doSetByRefs = (refs) => {
  4955. const mpComponents =
  4956. // 字节小程序 selectAllComponents 可能返回 null
  4957. // https://github.com/dcloudio/uni-app/issues/3954
  4958. ($scope.selectAllComponents('.r') || []).concat($scope.selectAllComponents('.r-i-f') || []);
  4959. return refs.filter(templateRef => {
  4960. const refValue = findComponentPublicInstance(mpComponents, templateRef.i);
  4961. // 部分平台,在一些 if 条件下,部分 slot 组件初始化会被延迟到下一次渲染,需要二次检测
  4962. if (check && refValue === null) {
  4963. return true;
  4964. }
  4965. setTemplateRef(templateRef, refValue, setupState);
  4966. return false;
  4967. });
  4968. };
  4969. const doSet = () => {
  4970. const refs = doSetByRefs($templateRefs);
  4971. if (refs.length && instance.proxy && instance.proxy.$scope) {
  4972. instance.proxy.$scope.setData({ r1: 1 }, () => {
  4973. doSetByRefs(refs);
  4974. });
  4975. }
  4976. };
  4977. if ($scope._$setRef) {
  4978. $scope._$setRef(doSet);
  4979. }
  4980. else {
  4981. nextTick(instance, doSet);
  4982. }
  4983. }
  4984. function toSkip(value) {
  4985. if (isObject(value)) {
  4986. markRaw(value);
  4987. }
  4988. return value;
  4989. }
  4990. function findComponentPublicInstance(mpComponents, id) {
  4991. const mpInstance = mpComponents.find(com => com && (com.properties || com.props).uI === id);
  4992. if (mpInstance) {
  4993. const vm = mpInstance.$vm;
  4994. if (vm) {
  4995. return getExposeProxy(vm.$) || vm;
  4996. }
  4997. // 可能是原生组件
  4998. return toSkip(mpInstance);
  4999. }
  5000. return null;
  5001. }
  5002. function setTemplateRef({ r, f }, refValue, setupState) {
  5003. if (isFunction(r)) {
  5004. r(refValue, {});
  5005. }
  5006. else {
  5007. const _isString = isString(r);
  5008. const _isRef = isRef(r);
  5009. if (_isString || _isRef) {
  5010. if (f) {
  5011. if (!_isRef) {
  5012. return;
  5013. }
  5014. if (!isArray(r.value)) {
  5015. r.value = [];
  5016. }
  5017. const existing = r.value;
  5018. if (existing.indexOf(refValue) === -1) {
  5019. existing.push(refValue);
  5020. if (!refValue) {
  5021. return;
  5022. }
  5023. // 实例销毁时,移除
  5024. onBeforeUnmount(() => remove(existing, refValue), refValue.$);
  5025. }
  5026. }
  5027. else if (_isString) {
  5028. if (hasOwn(setupState, r)) {
  5029. setupState[r] = refValue;
  5030. }
  5031. }
  5032. else if (isRef(r)) {
  5033. r.value = refValue;
  5034. }
  5035. else if ((process.env.NODE_ENV !== 'production')) {
  5036. warnRef(r);
  5037. }
  5038. }
  5039. else if ((process.env.NODE_ENV !== 'production')) {
  5040. warnRef(r);
  5041. }
  5042. }
  5043. }
  5044. function warnRef(ref) {
  5045. warn('Invalid template ref type:', ref, `(${typeof ref})`);
  5046. }
  5047. var MPType;
  5048. (function (MPType) {
  5049. MPType["APP"] = "app";
  5050. MPType["PAGE"] = "page";
  5051. MPType["COMPONENT"] = "component";
  5052. })(MPType || (MPType = {}));
  5053. const queuePostRenderEffect = queuePostFlushCb;
  5054. function mountComponent(initialVNode, options) {
  5055. const instance = (initialVNode.component =
  5056. createComponentInstance(initialVNode, options.parentComponent, null));
  5057. if (__VUE_OPTIONS_API__) {
  5058. instance.ctx.$onApplyOptions = onApplyOptions;
  5059. instance.ctx.$children = [];
  5060. }
  5061. if (options.mpType === 'app') {
  5062. instance.render = NOOP;
  5063. }
  5064. if (options.onBeforeSetup) {
  5065. options.onBeforeSetup(instance, options);
  5066. }
  5067. if ((process.env.NODE_ENV !== 'production')) {
  5068. pushWarningContext(initialVNode);
  5069. startMeasure(instance, `mount`);
  5070. }
  5071. if ((process.env.NODE_ENV !== 'production')) {
  5072. startMeasure(instance, `init`);
  5073. }
  5074. setupComponent(instance);
  5075. if ((process.env.NODE_ENV !== 'production')) {
  5076. endMeasure(instance, `init`);
  5077. }
  5078. if (__VUE_OPTIONS_API__) {
  5079. // $children
  5080. if (options.parentComponent && instance.proxy) {
  5081. options.parentComponent.ctx.$children.push(getExposeProxy(instance) || instance.proxy);
  5082. }
  5083. }
  5084. setupRenderEffect(instance);
  5085. if ((process.env.NODE_ENV !== 'production')) {
  5086. popWarningContext();
  5087. endMeasure(instance, `mount`);
  5088. }
  5089. return instance.proxy;
  5090. }
  5091. const getFunctionalFallthrough = (attrs) => {
  5092. let res;
  5093. for (const key in attrs) {
  5094. if (key === 'class' || key === 'style' || isOn(key)) {
  5095. (res || (res = {}))[key] = attrs[key];
  5096. }
  5097. }
  5098. return res;
  5099. };
  5100. function renderComponentRoot(instance) {
  5101. const { type: Component, vnode, proxy, withProxy, props, propsOptions: [propsOptions], slots, attrs, emit, render, renderCache, data, setupState, ctx, uid, appContext: { app: { config: { globalProperties: { pruneComponentPropsCache } } } }, inheritAttrs } = instance;
  5102. instance.$templateRefs = [];
  5103. instance.$ei = 0;
  5104. // props
  5105. pruneComponentPropsCache(uid);
  5106. instance.__counter =
  5107. instance.__counter === 0 ? 1 : 0;
  5108. let result;
  5109. const prev = setCurrentRenderingInstance(instance);
  5110. try {
  5111. if (vnode.shapeFlag & 4 /* ShapeFlags.STATEFUL_COMPONENT */) {
  5112. fallthroughAttrs(inheritAttrs, props, propsOptions, attrs);
  5113. // withProxy is a proxy with a different `has` trap only for
  5114. // runtime-compiled render functions using `with` block.
  5115. const proxyToUse = withProxy || proxy;
  5116. result = render.call(proxyToUse, proxyToUse, renderCache, props, setupState, data, ctx);
  5117. }
  5118. else {
  5119. fallthroughAttrs(inheritAttrs, props, propsOptions, Component.props ? attrs : getFunctionalFallthrough(attrs));
  5120. // functional
  5121. const render = Component;
  5122. result =
  5123. render.length > 1
  5124. ? render(props, { attrs, slots, emit })
  5125. : render(props, null /* we know it doesn't need it */);
  5126. }
  5127. }
  5128. catch (err) {
  5129. handleError(err, instance, 1 /* ErrorCodes.RENDER_FUNCTION */);
  5130. result = false;
  5131. }
  5132. setRef$1(instance);
  5133. setCurrentRenderingInstance(prev);
  5134. return result;
  5135. }
  5136. function fallthroughAttrs(inheritAttrs, props, propsOptions, fallthroughAttrs) {
  5137. if (props && fallthroughAttrs && inheritAttrs !== false) {
  5138. const keys = Object.keys(fallthroughAttrs).filter(key => key !== 'class' && key !== 'style');
  5139. if (!keys.length) {
  5140. return;
  5141. }
  5142. if (propsOptions && keys.some(isModelListener)) {
  5143. keys.forEach(key => {
  5144. if (!isModelListener(key) || !(key.slice(9) in propsOptions)) {
  5145. props[key] = fallthroughAttrs[key];
  5146. }
  5147. });
  5148. }
  5149. else {
  5150. keys.forEach(key => (props[key] = fallthroughAttrs[key]));
  5151. }
  5152. }
  5153. }
  5154. const updateComponentPreRender = (instance) => {
  5155. pauseTracking();
  5156. // props update may have triggered pre-flush watchers.
  5157. // flush them before the render update.
  5158. flushPreFlushCbs();
  5159. resetTracking();
  5160. };
  5161. function componentUpdateScopedSlotsFn() {
  5162. const scopedSlotsData = this.$scopedSlotsData;
  5163. if (!scopedSlotsData || scopedSlotsData.length === 0) {
  5164. return;
  5165. }
  5166. const start = Date.now();
  5167. const mpInstance = this.ctx.$scope;
  5168. const oldData = mpInstance.data;
  5169. const diffData = Object.create(null);
  5170. scopedSlotsData.forEach(({ path, index, data }) => {
  5171. const oldScopedSlotData = getValueByDataPath(oldData, path);
  5172. const diffPath = isString(index) ? `${path}.${index}` : `${path}[${index}]`;
  5173. if (typeof oldScopedSlotData === 'undefined' ||
  5174. typeof oldScopedSlotData[index] === 'undefined') {
  5175. diffData[diffPath] = data;
  5176. }
  5177. else {
  5178. const diffScopedSlotData = diff(data, oldScopedSlotData[index]);
  5179. Object.keys(diffScopedSlotData).forEach(name => {
  5180. diffData[diffPath + '.' + name] = diffScopedSlotData[name];
  5181. });
  5182. }
  5183. });
  5184. scopedSlotsData.length = 0;
  5185. if (Object.keys(diffData).length) {
  5186. if (process.env.UNI_DEBUG) {
  5187. console.log('[' +
  5188. +new Date() +
  5189. '][' +
  5190. (mpInstance.is || mpInstance.route) +
  5191. '][' +
  5192. this.uid +
  5193. '][耗时' +
  5194. (Date.now() - start) +
  5195. ']作用域插槽差量更新', JSON.stringify(diffData));
  5196. }
  5197. mpInstance.setData(diffData);
  5198. }
  5199. }
  5200. function toggleRecurse({ effect, update }, allowed) {
  5201. effect.allowRecurse = update.allowRecurse = allowed;
  5202. }
  5203. function setupRenderEffect(instance) {
  5204. const updateScopedSlots = componentUpdateScopedSlotsFn.bind(instance);
  5205. instance.$updateScopedSlots = () => nextTick$1(() => queueJob(updateScopedSlots));
  5206. const componentUpdateFn = () => {
  5207. if (!instance.isMounted) {
  5208. onBeforeUnmount(() => {
  5209. setRef$1(instance, true);
  5210. }, instance);
  5211. if ((process.env.NODE_ENV !== 'production')) {
  5212. startMeasure(instance, `patch`);
  5213. }
  5214. patch(instance, renderComponentRoot(instance));
  5215. if ((process.env.NODE_ENV !== 'production')) {
  5216. endMeasure(instance, `patch`);
  5217. }
  5218. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  5219. devtoolsComponentAdded(instance);
  5220. }
  5221. }
  5222. else {
  5223. // updateComponent
  5224. const { next, bu, u } = instance;
  5225. if ((process.env.NODE_ENV !== 'production')) {
  5226. pushWarningContext(next || instance.vnode);
  5227. }
  5228. // Disallow component effect recursion during pre-lifecycle hooks.
  5229. toggleRecurse(instance, false);
  5230. updateComponentPreRender();
  5231. // beforeUpdate hook
  5232. if (bu) {
  5233. invokeArrayFns(bu);
  5234. }
  5235. toggleRecurse(instance, true);
  5236. if ((process.env.NODE_ENV !== 'production')) {
  5237. startMeasure(instance, `patch`);
  5238. }
  5239. patch(instance, renderComponentRoot(instance));
  5240. if ((process.env.NODE_ENV !== 'production')) {
  5241. endMeasure(instance, `patch`);
  5242. }
  5243. // updated hook
  5244. if (u) {
  5245. queuePostRenderEffect(u);
  5246. }
  5247. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  5248. devtoolsComponentUpdated(instance);
  5249. }
  5250. if ((process.env.NODE_ENV !== 'production')) {
  5251. popWarningContext();
  5252. }
  5253. }
  5254. };
  5255. // create reactive effect for rendering
  5256. const effect = (instance.effect = new ReactiveEffect(componentUpdateFn, () => queueJob(instance.update), instance.scope // track it in component's effect scope
  5257. ));
  5258. const update = (instance.update = effect.run.bind(effect));
  5259. update.id = instance.uid;
  5260. // allowRecurse
  5261. // #1801, #2043 component render effects should allow recursive updates
  5262. toggleRecurse(instance, true);
  5263. if ((process.env.NODE_ENV !== 'production')) {
  5264. effect.onTrack = instance.rtc
  5265. ? e => invokeArrayFns(instance.rtc, e)
  5266. : void 0;
  5267. effect.onTrigger = instance.rtg
  5268. ? e => invokeArrayFns(instance.rtg, e)
  5269. : void 0;
  5270. // @ts-ignore (for scheduler)
  5271. update.ownerInstance = instance;
  5272. }
  5273. update();
  5274. }
  5275. function unmountComponent(instance) {
  5276. const { bum, scope, update, um } = instance;
  5277. // beforeUnmount hook
  5278. if (bum) {
  5279. invokeArrayFns(bum);
  5280. }
  5281. // stop effects in component scope
  5282. scope.stop();
  5283. // update may be null if a component is unmounted before its async
  5284. // setup has resolved.
  5285. if (update) {
  5286. update.active = false;
  5287. }
  5288. // unmounted hook
  5289. if (um) {
  5290. queuePostRenderEffect(um);
  5291. }
  5292. queuePostRenderEffect(() => {
  5293. instance.isUnmounted = true;
  5294. });
  5295. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  5296. devtoolsComponentRemoved(instance);
  5297. }
  5298. }
  5299. const oldCreateApp = createAppAPI();
  5300. function getTarget() {
  5301. if (typeof window !== 'undefined') {
  5302. return window;
  5303. }
  5304. if (typeof globalThis !== 'undefined') {
  5305. return globalThis;
  5306. }
  5307. if (typeof global !== 'undefined') {
  5308. return global;
  5309. }
  5310. if (typeof my !== 'undefined') {
  5311. return my;
  5312. }
  5313. }
  5314. function createVueApp(rootComponent, rootProps = null) {
  5315. const target = getTarget();
  5316. target.__VUE__ = true;
  5317. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  5318. setDevtoolsHook(target.__VUE_DEVTOOLS_GLOBAL_HOOK__, target);
  5319. }
  5320. const app = oldCreateApp(rootComponent, rootProps);
  5321. const appContext = app._context;
  5322. initAppConfig(appContext.config);
  5323. const createVNode = initialVNode => {
  5324. initialVNode.appContext = appContext;
  5325. initialVNode.shapeFlag = 6 /* ShapeFlags.COMPONENT */;
  5326. return initialVNode;
  5327. };
  5328. const createComponent = function createComponent(initialVNode, options) {
  5329. return mountComponent(createVNode(initialVNode), options);
  5330. };
  5331. const destroyComponent = function destroyComponent(component) {
  5332. return component && unmountComponent(component.$);
  5333. };
  5334. app.mount = function mount() {
  5335. rootComponent.render = NOOP;
  5336. const instance = mountComponent(createVNode({ type: rootComponent }), {
  5337. mpType: MPType.APP,
  5338. mpInstance: null,
  5339. parentComponent: null,
  5340. slots: [],
  5341. props: null
  5342. });
  5343. app._instance = instance.$;
  5344. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  5345. devtoolsInitApp(app, version);
  5346. }
  5347. instance.$app = app;
  5348. instance.$createComponent = createComponent;
  5349. instance.$destroyComponent = destroyComponent;
  5350. appContext.$appInstance = instance;
  5351. return instance;
  5352. };
  5353. app.unmount = function unmount() {
  5354. warn(`Cannot unmount an app.`);
  5355. };
  5356. return app;
  5357. }
  5358. function useCssModule(name = '$style') {
  5359. /* istanbul ignore else */
  5360. {
  5361. const instance = getCurrentInstance();
  5362. if (!instance) {
  5363. (process.env.NODE_ENV !== 'production') && warn(`useCssModule must be called inside setup()`);
  5364. return EMPTY_OBJ;
  5365. }
  5366. const modules = instance.type.__cssModules;
  5367. if (!modules) {
  5368. (process.env.NODE_ENV !== 'production') && warn(`Current instance does not have CSS modules injected.`);
  5369. return EMPTY_OBJ;
  5370. }
  5371. const mod = modules[name];
  5372. if (!mod) {
  5373. (process.env.NODE_ENV !== 'production') &&
  5374. warn(`Current instance does not have CSS module named "${name}".`);
  5375. return EMPTY_OBJ;
  5376. }
  5377. return mod;
  5378. }
  5379. }
  5380. /**
  5381. * Runtime helper for SFC's CSS variable injection feature.
  5382. * @private
  5383. */
  5384. function useCssVars(getter) {
  5385. const instance = getCurrentInstance();
  5386. /* istanbul ignore next */
  5387. if (!instance) {
  5388. (process.env.NODE_ENV !== 'production') &&
  5389. warn(`useCssVars is called without current active component instance.`);
  5390. return;
  5391. }
  5392. initCssVarsRender(instance, getter);
  5393. }
  5394. function initCssVarsRender(instance, getter) {
  5395. instance.ctx.__cssVars = () => {
  5396. const vars = getter(instance.proxy);
  5397. const cssVars = {};
  5398. for (const key in vars) {
  5399. cssVars[`--${key}`] = vars[key];
  5400. }
  5401. return cssVars;
  5402. };
  5403. }
  5404. function withModifiers() { }
  5405. function createVNode() { }
  5406. function injectLifecycleHook(name, hook, publicThis, instance) {
  5407. if (isFunction(hook)) {
  5408. injectHook(name, hook.bind(publicThis), instance);
  5409. }
  5410. }
  5411. function initHooks(options, instance, publicThis) {
  5412. const mpType = options.mpType || publicThis.$mpType;
  5413. if (!mpType || mpType === 'component') {
  5414. // 仅 App,Page 类型支持在 options 中配置 on 生命周期,组件可以使用组合式 API 定义页面生命周期
  5415. return;
  5416. }
  5417. Object.keys(options).forEach((name) => {
  5418. if (isUniLifecycleHook(name, options[name], false)) {
  5419. const hooks = options[name];
  5420. if (isArray(hooks)) {
  5421. hooks.forEach((hook) => injectLifecycleHook(name, hook, publicThis, instance));
  5422. }
  5423. else {
  5424. injectLifecycleHook(name, hooks, publicThis, instance);
  5425. }
  5426. }
  5427. });
  5428. }
  5429. function applyOptions(options, instance, publicThis) {
  5430. initHooks(options, instance, publicThis);
  5431. }
  5432. function set(target, key, val) {
  5433. return (target[key] = val);
  5434. }
  5435. function $callMethod(method, ...args) {
  5436. const fn = this[method];
  5437. if (fn) {
  5438. return fn(...args);
  5439. }
  5440. console.error(`method ${method} not found`);
  5441. return null;
  5442. }
  5443. function createErrorHandler(app) {
  5444. return function errorHandler(err, instance, _info) {
  5445. if (!instance) {
  5446. throw err;
  5447. }
  5448. const appInstance = app._instance;
  5449. if (!appInstance || !appInstance.proxy) {
  5450. throw err;
  5451. }
  5452. {
  5453. appInstance.proxy.$callHook(ON_ERROR, err);
  5454. }
  5455. };
  5456. }
  5457. function mergeAsArray(to, from) {
  5458. return to ? [...new Set([].concat(to, from))] : from;
  5459. }
  5460. function initOptionMergeStrategies(optionMergeStrategies) {
  5461. UniLifecycleHooks.forEach((name) => {
  5462. optionMergeStrategies[name] = mergeAsArray;
  5463. });
  5464. }
  5465. let realAtob;
  5466. const b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  5467. const b64re = /^(?:[A-Za-z\d+/]{4})*?(?:[A-Za-z\d+/]{2}(?:==)?|[A-Za-z\d+/]{3}=?)?$/;
  5468. if (typeof atob !== 'function') {
  5469. realAtob = function (str) {
  5470. str = String(str).replace(/[\t\n\f\r ]+/g, '');
  5471. if (!b64re.test(str)) {
  5472. throw new Error("Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.");
  5473. }
  5474. // Adding the padding if missing, for semplicity
  5475. str += '=='.slice(2 - (str.length & 3));
  5476. var bitmap;
  5477. var result = '';
  5478. var r1;
  5479. var r2;
  5480. var i = 0;
  5481. for (; i < str.length;) {
  5482. bitmap =
  5483. (b64.indexOf(str.charAt(i++)) << 18) |
  5484. (b64.indexOf(str.charAt(i++)) << 12) |
  5485. ((r1 = b64.indexOf(str.charAt(i++))) << 6) |
  5486. (r2 = b64.indexOf(str.charAt(i++)));
  5487. result +=
  5488. r1 === 64
  5489. ? String.fromCharCode((bitmap >> 16) & 255)
  5490. : r2 === 64
  5491. ? String.fromCharCode((bitmap >> 16) & 255, (bitmap >> 8) & 255)
  5492. : String.fromCharCode((bitmap >> 16) & 255, (bitmap >> 8) & 255, bitmap & 255);
  5493. }
  5494. return result;
  5495. };
  5496. }
  5497. else {
  5498. // 注意atob只能在全局对象上调用,例如:`const Base64 = {atob};Base64.atob('xxxx')`是错误的用法
  5499. realAtob = atob;
  5500. }
  5501. function b64DecodeUnicode(str) {
  5502. return decodeURIComponent(realAtob(str)
  5503. .split('')
  5504. .map(function (c) {
  5505. return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
  5506. })
  5507. .join(''));
  5508. }
  5509. function getCurrentUserInfo() {
  5510. const token = uni.getStorageSync('uni_id_token') || '';
  5511. const tokenArr = token.split('.');
  5512. if (!token || tokenArr.length !== 3) {
  5513. return {
  5514. uid: null,
  5515. role: [],
  5516. permission: [],
  5517. tokenExpired: 0,
  5518. };
  5519. }
  5520. let userInfo;
  5521. try {
  5522. userInfo = JSON.parse(b64DecodeUnicode(tokenArr[1]));
  5523. }
  5524. catch (error) {
  5525. throw new Error('获取当前用户信息出错,详细错误信息为:' + error.message);
  5526. }
  5527. userInfo.tokenExpired = userInfo.exp * 1000;
  5528. delete userInfo.exp;
  5529. delete userInfo.iat;
  5530. return userInfo;
  5531. }
  5532. function uniIdMixin(globalProperties) {
  5533. globalProperties.uniIDHasRole = function (roleId) {
  5534. const { role } = getCurrentUserInfo();
  5535. return role.indexOf(roleId) > -1;
  5536. };
  5537. globalProperties.uniIDHasPermission = function (permissionId) {
  5538. const { permission } = getCurrentUserInfo();
  5539. return this.uniIDHasRole('admin') || permission.indexOf(permissionId) > -1;
  5540. };
  5541. globalProperties.uniIDTokenValid = function () {
  5542. const { tokenExpired } = getCurrentUserInfo();
  5543. return tokenExpired > Date.now();
  5544. };
  5545. }
  5546. function initApp(app) {
  5547. const appConfig = app._context.config;
  5548. appConfig.errorHandler = invokeCreateErrorHandler(app, createErrorHandler);
  5549. initOptionMergeStrategies(appConfig.optionMergeStrategies);
  5550. const globalProperties = appConfig.globalProperties;
  5551. {
  5552. uniIdMixin(globalProperties);
  5553. }
  5554. if (__VUE_OPTIONS_API__) {
  5555. globalProperties.$set = set;
  5556. globalProperties.$applyOptions = applyOptions;
  5557. globalProperties.$callMethod = $callMethod;
  5558. }
  5559. {
  5560. uni.invokeCreateVueAppHook(app);
  5561. }
  5562. }
  5563. const propsCaches = Object.create(null);
  5564. function renderProps(props) {
  5565. const { uid, __counter } = getCurrentInstance();
  5566. const propsId = (propsCaches[uid] || (propsCaches[uid] = [])).push(guardReactiveProps(props)) - 1;
  5567. // 强制每次更新
  5568. return uid + ',' + propsId + ',' + __counter;
  5569. }
  5570. function pruneComponentPropsCache(uid) {
  5571. delete propsCaches[uid];
  5572. }
  5573. function findComponentPropsData(up) {
  5574. if (!up) {
  5575. return;
  5576. }
  5577. const [uid, propsId] = up.split(',');
  5578. if (!propsCaches[uid]) {
  5579. return;
  5580. }
  5581. return propsCaches[uid][parseInt(propsId)];
  5582. }
  5583. var plugin = {
  5584. install(app) {
  5585. initApp(app);
  5586. app.config.globalProperties.pruneComponentPropsCache =
  5587. pruneComponentPropsCache;
  5588. const oldMount = app.mount;
  5589. app.mount = function mount(rootContainer) {
  5590. const instance = oldMount.call(app, rootContainer);
  5591. const createApp = getCreateApp();
  5592. if (createApp) {
  5593. createApp(instance);
  5594. }
  5595. else {
  5596. // @ts-ignore 旧编译器
  5597. if (typeof createMiniProgramApp !== 'undefined') {
  5598. // @ts-ignore
  5599. createMiniProgramApp(instance);
  5600. }
  5601. }
  5602. return instance;
  5603. };
  5604. },
  5605. };
  5606. function getCreateApp() {
  5607. const method = process.env.UNI_MP_PLUGIN
  5608. ? 'createPluginApp'
  5609. : process.env.UNI_SUBPACKAGE
  5610. ? 'createSubpackageApp'
  5611. : 'createApp';
  5612. if (typeof global !== 'undefined' &&
  5613. typeof global[method] !== 'undefined') {
  5614. return global[method];
  5615. }
  5616. else if (typeof my !== 'undefined') {
  5617. // 支付宝小程序开启globalObjectMode配置后才会有global
  5618. return my[method];
  5619. }
  5620. }
  5621. function vOn(value, key) {
  5622. const instance = getCurrentInstance();
  5623. const ctx = instance.ctx;
  5624. // 微信小程序,QQ小程序,当 setData diff 的时候,若事件不主动同步过去,会导致事件绑定不更新,(question/137217)
  5625. const extraKey = typeof key !== 'undefined' &&
  5626. (ctx.$mpPlatform === 'mp-weixin' || ctx.$mpPlatform === 'mp-qq') &&
  5627. (isString(key) || typeof key === 'number')
  5628. ? '_' + key
  5629. : '';
  5630. const name = 'e' + instance.$ei++ + extraKey;
  5631. const mpInstance = ctx.$scope;
  5632. if (!value) {
  5633. // remove
  5634. delete mpInstance[name];
  5635. return name;
  5636. }
  5637. const existingInvoker = mpInstance[name];
  5638. if (existingInvoker) {
  5639. // patch
  5640. existingInvoker.value = value;
  5641. }
  5642. else {
  5643. // add
  5644. mpInstance[name] = createInvoker(value, instance);
  5645. }
  5646. return name;
  5647. }
  5648. function createInvoker(initialValue, instance) {
  5649. const invoker = (e) => {
  5650. patchMPEvent(e);
  5651. let args = [e];
  5652. if (e.detail && e.detail.__args__) {
  5653. args = e.detail.__args__;
  5654. }
  5655. const eventValue = invoker.value;
  5656. const invoke = () => callWithAsyncErrorHandling(patchStopImmediatePropagation(e, eventValue), instance, 5 /* ErrorCodes.NATIVE_EVENT_HANDLER */, args);
  5657. // 冒泡事件触发时,启用延迟策略,避免同一批次的事件执行时机不正确,对性能可能有略微影响 https://github.com/dcloudio/uni-app/issues/3228
  5658. const eventTarget = e.target;
  5659. const eventSync = eventTarget
  5660. ? eventTarget.dataset
  5661. ? String(eventTarget.dataset.eventsync) === 'true'
  5662. : false
  5663. : false;
  5664. if (bubbles.includes(e.type) && !eventSync) {
  5665. setTimeout(invoke);
  5666. }
  5667. else {
  5668. const res = invoke();
  5669. if (e.type === 'input' && (isArray(res) || isPromise(res))) {
  5670. return;
  5671. }
  5672. return res;
  5673. }
  5674. };
  5675. invoker.value = initialValue;
  5676. return invoker;
  5677. }
  5678. // 冒泡事件列表
  5679. const bubbles = [
  5680. // touch事件暂不做延迟,否则在 Android 上会影响性能,比如一些拖拽跟手手势等
  5681. // 'touchstart',
  5682. // 'touchmove',
  5683. // 'touchcancel',
  5684. // 'touchend',
  5685. 'tap',
  5686. 'longpress',
  5687. 'longtap',
  5688. 'transitionend',
  5689. 'animationstart',
  5690. 'animationiteration',
  5691. 'animationend',
  5692. 'touchforcechange',
  5693. ];
  5694. function patchMPEvent(event) {
  5695. if (event.type && event.target) {
  5696. event.preventDefault = NOOP;
  5697. event.stopPropagation = NOOP;
  5698. event.stopImmediatePropagation = NOOP;
  5699. if (!hasOwn(event, 'detail')) {
  5700. event.detail = {};
  5701. }
  5702. if (hasOwn(event, 'markerId')) {
  5703. event.detail = typeof event.detail === 'object' ? event.detail : {};
  5704. event.detail.markerId = event.markerId;
  5705. }
  5706. // mp-baidu,checked=>value
  5707. if (isPlainObject(event.detail) &&
  5708. hasOwn(event.detail, 'checked') &&
  5709. !hasOwn(event.detail, 'value')) {
  5710. event.detail.value = event.detail.checked;
  5711. }
  5712. if (isPlainObject(event.detail)) {
  5713. event.target = extend({}, event.target, event.detail);
  5714. }
  5715. }
  5716. }
  5717. function patchStopImmediatePropagation(e, value) {
  5718. if (isArray(value)) {
  5719. const originalStop = e.stopImmediatePropagation;
  5720. e.stopImmediatePropagation = () => {
  5721. originalStop && originalStop.call(e);
  5722. e._stopped = true;
  5723. };
  5724. return value.map((fn) => (e) => !e._stopped && fn(e));
  5725. }
  5726. else {
  5727. return value;
  5728. }
  5729. }
  5730. /**
  5731. * Actual implementation
  5732. */
  5733. function vFor(source, renderItem) {
  5734. let ret;
  5735. if (isArray(source) || isString(source)) {
  5736. ret = new Array(source.length);
  5737. for (let i = 0, l = source.length; i < l; i++) {
  5738. ret[i] = renderItem(source[i], i, i);
  5739. }
  5740. }
  5741. else if (typeof source === 'number') {
  5742. if ((process.env.NODE_ENV !== 'production') && !Number.isInteger(source)) {
  5743. warn(`The v-for range expect an integer value but got ${source}.`);
  5744. return [];
  5745. }
  5746. ret = new Array(source);
  5747. for (let i = 0; i < source; i++) {
  5748. ret[i] = renderItem(i + 1, i, i);
  5749. }
  5750. }
  5751. else if (isObject(source)) {
  5752. if (source[Symbol.iterator]) {
  5753. ret = Array.from(source, (item, i) => renderItem(item, i, i));
  5754. }
  5755. else {
  5756. const keys = Object.keys(source);
  5757. ret = new Array(keys.length);
  5758. for (let i = 0, l = keys.length; i < l; i++) {
  5759. const key = keys[i];
  5760. ret[i] = renderItem(source[key], key, i);
  5761. }
  5762. }
  5763. }
  5764. else {
  5765. ret = [];
  5766. }
  5767. return ret;
  5768. }
  5769. function renderSlot(name, props = {}, key) {
  5770. const instance = getCurrentInstance();
  5771. const { parent, isMounted, ctx: { $scope }, } = instance;
  5772. // mp-alipay 为 props
  5773. const vueIds = ($scope.properties || $scope.props).uI;
  5774. if (!vueIds) {
  5775. return;
  5776. }
  5777. if (!parent && !isMounted) {
  5778. // 头条小程序首次 render 时,还没有 parent
  5779. onMounted(() => {
  5780. renderSlot(name, props, key);
  5781. }, instance);
  5782. return;
  5783. }
  5784. const invoker = findScopedSlotInvoker(vueIds, instance);
  5785. // 可能不存在,因为插槽不是必需的
  5786. if (invoker) {
  5787. invoker(name, props, key);
  5788. }
  5789. }
  5790. function findScopedSlotInvoker(vueId, instance) {
  5791. let parent = instance.parent;
  5792. while (parent) {
  5793. const invokers = parent.$ssi;
  5794. if (invokers && invokers[vueId]) {
  5795. return invokers[vueId];
  5796. }
  5797. parent = parent.parent;
  5798. }
  5799. }
  5800. function withScopedSlot(fn, { name, path, vueId, }) {
  5801. const instance = getCurrentInstance();
  5802. fn.path = path;
  5803. const scopedSlots = (instance.$ssi ||
  5804. (instance.$ssi = {}));
  5805. const invoker = scopedSlots[vueId] ||
  5806. (scopedSlots[vueId] = createScopedSlotInvoker(instance));
  5807. if (!invoker.slots[name]) {
  5808. invoker.slots[name] = {
  5809. fn,
  5810. };
  5811. }
  5812. else {
  5813. invoker.slots[name].fn = fn;
  5814. }
  5815. return getValueByDataPath(instance.ctx.$scope.data, path);
  5816. }
  5817. function createScopedSlotInvoker(instance) {
  5818. const invoker = (slotName, args, index) => {
  5819. const slot = invoker.slots[slotName];
  5820. if (!slot) {
  5821. // slot 可能不存在 https://github.com/dcloudio/uni-app/issues/3346
  5822. return;
  5823. }
  5824. const hasIndex = typeof index !== 'undefined';
  5825. index = index || 0;
  5826. // 确保当前 slot 的上下文,类似 withCtx
  5827. const prevInstance = setCurrentRenderingInstance(instance);
  5828. const data = slot.fn(args, slotName + (hasIndex ? '-' + index : ''), index);
  5829. const path = slot.fn.path;
  5830. setCurrentRenderingInstance(prevInstance);
  5831. (instance.$scopedSlotsData || (instance.$scopedSlotsData = [])).push({
  5832. path,
  5833. index,
  5834. data,
  5835. });
  5836. instance.$updateScopedSlots();
  5837. };
  5838. invoker.slots = {};
  5839. return invoker;
  5840. }
  5841. function stringifyStyle(value) {
  5842. if (isString(value)) {
  5843. return value;
  5844. }
  5845. return stringify(normalizeStyle(value));
  5846. }
  5847. function stringify(styles) {
  5848. let ret = '';
  5849. if (!styles || isString(styles)) {
  5850. return ret;
  5851. }
  5852. for (const key in styles) {
  5853. ret += `${key.startsWith(`--`) ? key : hyphenate(key)}:${styles[key]};`;
  5854. }
  5855. return ret;
  5856. }
  5857. /**
  5858. * quickapp-webview 不能使用 default 作为插槽名称,故统一转换 default 为 d
  5859. * @param names
  5860. * @returns
  5861. */
  5862. function dynamicSlot(names) {
  5863. if (isString(names)) {
  5864. return dynamicSlotName(names);
  5865. }
  5866. return names.map((name) => dynamicSlotName(name));
  5867. }
  5868. function setRef(ref, id, opts = {}) {
  5869. const { $templateRefs } = getCurrentInstance();
  5870. $templateRefs.push({ i: id, r: ref, k: opts.k, f: opts.f });
  5871. }
  5872. function withModelModifiers(fn, { number, trim }, isComponent = false) {
  5873. if (isComponent) {
  5874. return (...args) => {
  5875. if (trim) {
  5876. args = args.map((a) => a.trim());
  5877. }
  5878. else if (number) {
  5879. args = args.map(toNumber);
  5880. }
  5881. return fn(...args);
  5882. };
  5883. }
  5884. return (event) => {
  5885. const value = event.detail.value;
  5886. if (trim) {
  5887. event.detail.value = value.trim();
  5888. }
  5889. else if (number) {
  5890. event.detail.value = toNumber(value);
  5891. }
  5892. return fn(event);
  5893. };
  5894. }
  5895. function setupDevtoolsPlugin() {
  5896. // noop
  5897. }
  5898. const o = (value, key) => vOn(value, key);
  5899. const f = (source, renderItem) => vFor(source, renderItem);
  5900. const d = (names) => dynamicSlot(names);
  5901. const r = (name, props, key) => renderSlot(name, props, key);
  5902. const w = (fn, options) => withScopedSlot(fn, options);
  5903. const s = (value) => stringifyStyle(value);
  5904. const c = (str) => camelize(str);
  5905. const e = (target, ...sources) => extend(target, ...sources);
  5906. const h = (str) => hyphenate(str);
  5907. const n = (value) => normalizeClass(value);
  5908. const t = (val) => toDisplayString(val);
  5909. const p = (props) => renderProps(props);
  5910. const sr = (ref, id, opts) => setRef(ref, id, opts);
  5911. const m = (fn, modifiers, isComponent = false) => withModelModifiers(fn, modifiers, isComponent);
  5912. const j = (obj) => JSON.stringify(obj);
  5913. function createApp(rootComponent, rootProps = null) {
  5914. rootComponent && (rootComponent.mpType = 'app');
  5915. return createVueApp(rootComponent, rootProps).use(plugin);
  5916. }
  5917. const createSSRApp = createApp;
  5918. export { EffectScope, Fragment, ReactiveEffect, Text, c, callWithAsyncErrorHandling, callWithErrorHandling, computed, createApp, createSSRApp, createVNode, createVueApp, customRef, d, defineAsyncComponent, defineComponent, defineEmits, defineExpose, defineProps, devtoolsComponentAdded, devtoolsComponentRemoved, devtoolsComponentUpdated, diff, e, effect, effectScope, f, findComponentPropsData, getCurrentInstance, getCurrentScope, getExposeProxy, guardReactiveProps, h, hasQueueJob, inject, injectHook, invalidateJob, isInSSRComponentSetup, isProxy, isReactive, isReadonly, isRef, j, logError, m, markRaw, mergeDefaults, mergeProps, n, nextTick$1 as nextTick, o, onActivated, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onScopeDispose, onServerPrefetch, onUnmounted, onUpdated, p, patch, provide, proxyRefs, pruneComponentPropsCache, queuePostFlushCb, r, reactive, readonly, ref, resolveComponent, resolveDirective, resolveFilter, s, setCurrentRenderingInstance, setTemplateRef, setupDevtoolsPlugin, shallowReactive, shallowReadonly, shallowRef, sr, stop, t, toHandlers, toRaw, toRef, toRefs, triggerRef, unref, updateProps, useAttrs, useCssModule, useCssVars, useSSRContext, useSlots, version, w, warn, watch, watchEffect, watchPostEffect, watchSyncEffect, withAsyncContext, withCtx, withDefaults, withDirectives, withModifiers, withScopeId };