runtime-core.cjs.prod.js 211 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var reactivity = require('@vue/reactivity');
  4. var shared = require('@vue/shared');
  5. const stack = [];
  6. function warn(msg, ...args) {
  7. // avoid props formatting or warn handler tracking deps that might be mutated
  8. // during patch, leading to infinite recursion.
  9. reactivity.pauseTracking();
  10. const instance = stack.length ? stack[stack.length - 1].component : null;
  11. const appWarnHandler = instance && instance.appContext.config.warnHandler;
  12. const trace = getComponentTrace();
  13. if (appWarnHandler) {
  14. callWithErrorHandling(appWarnHandler, instance, 11 /* APP_WARN_HANDLER */, [
  15. msg + args.join(''),
  16. instance && instance.proxy,
  17. trace
  18. .map(({ vnode }) => `at <${formatComponentName(instance, vnode.type)}>`)
  19. .join('\n'),
  20. trace
  21. ]);
  22. }
  23. else {
  24. const warnArgs = [`[Vue warn]: ${msg}`, ...args];
  25. /* istanbul ignore if */
  26. if (trace.length &&
  27. // avoid spamming console during tests
  28. !false) {
  29. warnArgs.push(`\n`, ...formatTrace(trace));
  30. }
  31. console.warn(...warnArgs);
  32. }
  33. reactivity.resetTracking();
  34. }
  35. function getComponentTrace() {
  36. let currentVNode = stack[stack.length - 1];
  37. if (!currentVNode) {
  38. return [];
  39. }
  40. // we can't just use the stack because it will be incomplete during updates
  41. // that did not start from the root. Re-construct the parent chain using
  42. // instance parent pointers.
  43. const normalizedStack = [];
  44. while (currentVNode) {
  45. const last = normalizedStack[0];
  46. if (last && last.vnode === currentVNode) {
  47. last.recurseCount++;
  48. }
  49. else {
  50. normalizedStack.push({
  51. vnode: currentVNode,
  52. recurseCount: 0
  53. });
  54. }
  55. const parentInstance = currentVNode.component && currentVNode.component.parent;
  56. currentVNode = parentInstance && parentInstance.vnode;
  57. }
  58. return normalizedStack;
  59. }
  60. /* istanbul ignore next */
  61. function formatTrace(trace) {
  62. const logs = [];
  63. trace.forEach((entry, i) => {
  64. logs.push(...(i === 0 ? [] : [`\n`]), ...formatTraceEntry(entry));
  65. });
  66. return logs;
  67. }
  68. function formatTraceEntry({ vnode, recurseCount }) {
  69. const postfix = recurseCount > 0 ? `... (${recurseCount} recursive calls)` : ``;
  70. const isRoot = vnode.component ? vnode.component.parent == null : false;
  71. const open = ` at <${formatComponentName(vnode.component, vnode.type, isRoot)}`;
  72. const close = `>` + postfix;
  73. return vnode.props
  74. ? [open, ...formatProps(vnode.props), close]
  75. : [open + close];
  76. }
  77. /* istanbul ignore next */
  78. function formatProps(props) {
  79. const res = [];
  80. const keys = Object.keys(props);
  81. keys.slice(0, 3).forEach(key => {
  82. res.push(...formatProp(key, props[key]));
  83. });
  84. if (keys.length > 3) {
  85. res.push(` ...`);
  86. }
  87. return res;
  88. }
  89. /* istanbul ignore next */
  90. function formatProp(key, value, raw) {
  91. if (shared.isString(value)) {
  92. value = JSON.stringify(value);
  93. return raw ? value : [`${key}=${value}`];
  94. }
  95. else if (typeof value === 'number' ||
  96. typeof value === 'boolean' ||
  97. value == null) {
  98. return raw ? value : [`${key}=${value}`];
  99. }
  100. else if (reactivity.isRef(value)) {
  101. value = formatProp(key, reactivity.toRaw(value.value), true);
  102. return raw ? value : [`${key}=Ref<`, value, `>`];
  103. }
  104. else if (shared.isFunction(value)) {
  105. return [`${key}=fn${value.name ? `<${value.name}>` : ``}`];
  106. }
  107. else {
  108. value = reactivity.toRaw(value);
  109. return raw ? value : [`${key}=`, value];
  110. }
  111. }
  112. function callWithErrorHandling(fn, instance, type, args) {
  113. let res;
  114. try {
  115. res = args ? fn(...args) : fn();
  116. }
  117. catch (err) {
  118. handleError(err, instance, type);
  119. }
  120. return res;
  121. }
  122. function callWithAsyncErrorHandling(fn, instance, type, args) {
  123. if (shared.isFunction(fn)) {
  124. const res = callWithErrorHandling(fn, instance, type, args);
  125. if (res && shared.isPromise(res)) {
  126. res.catch(err => {
  127. handleError(err, instance, type);
  128. });
  129. }
  130. return res;
  131. }
  132. const values = [];
  133. for (let i = 0; i < fn.length; i++) {
  134. values.push(callWithAsyncErrorHandling(fn[i], instance, type, args));
  135. }
  136. return values;
  137. }
  138. function handleError(err, instance, type, throwInDev = true) {
  139. const contextVNode = instance ? instance.vnode : null;
  140. if (instance) {
  141. let cur = instance.parent;
  142. // the exposed instance is the render proxy to keep it consistent with 2.x
  143. const exposedInstance = instance.proxy;
  144. // in production the hook receives only the error code
  145. const errorInfo = type;
  146. while (cur) {
  147. const errorCapturedHooks = cur.ec;
  148. if (errorCapturedHooks) {
  149. for (let i = 0; i < errorCapturedHooks.length; i++) {
  150. if (errorCapturedHooks[i](err, exposedInstance, errorInfo) === false) {
  151. return;
  152. }
  153. }
  154. }
  155. cur = cur.parent;
  156. }
  157. // app-level handling
  158. const appErrorHandler = instance.appContext.config.errorHandler;
  159. if (appErrorHandler) {
  160. callWithErrorHandling(appErrorHandler, null, 10 /* APP_ERROR_HANDLER */, [err, exposedInstance, errorInfo]);
  161. return;
  162. }
  163. }
  164. logError(err, type, contextVNode, throwInDev);
  165. }
  166. function logError(err, type, contextVNode, throwInDev = true) {
  167. {
  168. // recover in prod to reduce the impact on end-user
  169. console.error(err);
  170. }
  171. }
  172. let isFlushing = false;
  173. let isFlushPending = false;
  174. const queue = [];
  175. let flushIndex = 0;
  176. const pendingPreFlushCbs = [];
  177. let activePreFlushCbs = null;
  178. let preFlushIndex = 0;
  179. const pendingPostFlushCbs = [];
  180. let activePostFlushCbs = null;
  181. let postFlushIndex = 0;
  182. const resolvedPromise = Promise.resolve();
  183. let currentFlushPromise = null;
  184. let currentPreFlushParentJob = null;
  185. const RECURSION_LIMIT = 100;
  186. function nextTick(fn) {
  187. const p = currentFlushPromise || resolvedPromise;
  188. return fn ? p.then(this ? fn.bind(this) : fn) : p;
  189. }
  190. function queueJob(job) {
  191. // the dedupe search uses the startIndex argument of Array.includes()
  192. // by default the search index includes the current job that is being run
  193. // so it cannot recursively trigger itself again.
  194. // if the job is a watch() callback, the search will start with a +1 index to
  195. // allow it recursively trigger itself - it is the user's responsibility to
  196. // ensure it doesn't end up in an infinite loop.
  197. if ((!queue.length ||
  198. !queue.includes(job, isFlushing && job.allowRecurse ? flushIndex + 1 : flushIndex)) &&
  199. job !== currentPreFlushParentJob) {
  200. queue.push(job);
  201. queueFlush();
  202. }
  203. }
  204. function queueFlush() {
  205. if (!isFlushing && !isFlushPending) {
  206. isFlushPending = true;
  207. currentFlushPromise = resolvedPromise.then(flushJobs);
  208. }
  209. }
  210. function invalidateJob(job) {
  211. const i = queue.indexOf(job);
  212. if (i > -1) {
  213. queue.splice(i, 1);
  214. }
  215. }
  216. function queueCb(cb, activeQueue, pendingQueue, index) {
  217. if (!shared.isArray(cb)) {
  218. if (!activeQueue ||
  219. !activeQueue.includes(cb, cb.allowRecurse ? index + 1 : index)) {
  220. pendingQueue.push(cb);
  221. }
  222. }
  223. else {
  224. // if cb is an array, it is a component lifecycle hook which can only be
  225. // triggered by a job, which is already deduped in the main queue, so
  226. // we can skip duplicate check here to improve perf
  227. pendingQueue.push(...cb);
  228. }
  229. queueFlush();
  230. }
  231. function queuePreFlushCb(cb) {
  232. queueCb(cb, activePreFlushCbs, pendingPreFlushCbs, preFlushIndex);
  233. }
  234. function queuePostFlushCb(cb) {
  235. queueCb(cb, activePostFlushCbs, pendingPostFlushCbs, postFlushIndex);
  236. }
  237. function flushPreFlushCbs(seen, parentJob = null) {
  238. if (pendingPreFlushCbs.length) {
  239. currentPreFlushParentJob = parentJob;
  240. activePreFlushCbs = [...new Set(pendingPreFlushCbs)];
  241. pendingPreFlushCbs.length = 0;
  242. for (preFlushIndex = 0; preFlushIndex < activePreFlushCbs.length; preFlushIndex++) {
  243. activePreFlushCbs[preFlushIndex]();
  244. }
  245. activePreFlushCbs = null;
  246. preFlushIndex = 0;
  247. currentPreFlushParentJob = null;
  248. // recursively flush until it drains
  249. flushPreFlushCbs(seen, parentJob);
  250. }
  251. }
  252. function flushPostFlushCbs(seen) {
  253. if (pendingPostFlushCbs.length) {
  254. const deduped = [...new Set(pendingPostFlushCbs)];
  255. pendingPostFlushCbs.length = 0;
  256. // #1947 already has active queue, nested flushPostFlushCbs call
  257. if (activePostFlushCbs) {
  258. activePostFlushCbs.push(...deduped);
  259. return;
  260. }
  261. activePostFlushCbs = deduped;
  262. activePostFlushCbs.sort((a, b) => getId(a) - getId(b));
  263. for (postFlushIndex = 0; postFlushIndex < activePostFlushCbs.length; postFlushIndex++) {
  264. activePostFlushCbs[postFlushIndex]();
  265. }
  266. activePostFlushCbs = null;
  267. postFlushIndex = 0;
  268. }
  269. }
  270. const getId = (job) => job.id == null ? Infinity : job.id;
  271. function flushJobs(seen) {
  272. isFlushPending = false;
  273. isFlushing = true;
  274. flushPreFlushCbs(seen);
  275. // Sort queue before flush.
  276. // This ensures that:
  277. // 1. Components are updated from parent to child. (because parent is always
  278. // created before the child so its render effect will have smaller
  279. // priority number)
  280. // 2. If a component is unmounted during a parent component's update,
  281. // its update can be skipped.
  282. queue.sort((a, b) => getId(a) - getId(b));
  283. try {
  284. for (flushIndex = 0; flushIndex < queue.length; flushIndex++) {
  285. const job = queue[flushIndex];
  286. if (job) {
  287. if (false) ;
  288. callWithErrorHandling(job, null, 14 /* SCHEDULER */);
  289. }
  290. }
  291. }
  292. finally {
  293. flushIndex = 0;
  294. queue.length = 0;
  295. flushPostFlushCbs();
  296. isFlushing = false;
  297. currentFlushPromise = null;
  298. // some postFlushCb queued jobs!
  299. // keep flushing until it drains.
  300. if (queue.length || pendingPostFlushCbs.length) {
  301. flushJobs(seen);
  302. }
  303. }
  304. }
  305. function checkRecursiveUpdates(seen, fn) {
  306. if (!seen.has(fn)) {
  307. seen.set(fn, 1);
  308. }
  309. else {
  310. const count = seen.get(fn);
  311. if (count > RECURSION_LIMIT) {
  312. throw new Error(`Maximum recursive updates exceeded. ` +
  313. `This means you have a reactive effect that is mutating its own ` +
  314. `dependencies and thus recursively triggering itself. Possible sources ` +
  315. `include component template, render function, updated hook or ` +
  316. `watcher source function.`);
  317. }
  318. else {
  319. seen.set(fn, count + 1);
  320. }
  321. }
  322. }
  323. exports.devtools = void 0;
  324. function setDevtoolsHook(hook) {
  325. exports.devtools = hook;
  326. }
  327. function emit(instance, event, ...rawArgs) {
  328. const props = instance.vnode.props || shared.EMPTY_OBJ;
  329. let args = rawArgs;
  330. const isModelListener = event.startsWith('update:');
  331. // for v-model update:xxx events, apply modifiers on args
  332. const modelArg = isModelListener && event.slice(7);
  333. if (modelArg && modelArg in props) {
  334. const modifiersKey = `${modelArg === 'modelValue' ? 'model' : modelArg}Modifiers`;
  335. const { number, trim } = props[modifiersKey] || shared.EMPTY_OBJ;
  336. if (trim) {
  337. args = rawArgs.map(a => a.trim());
  338. }
  339. else if (number) {
  340. args = rawArgs.map(shared.toNumber);
  341. }
  342. }
  343. // convert handler name to camelCase. See issue #2249
  344. let handlerName = shared.toHandlerKey(shared.camelize(event));
  345. let handler = props[handlerName];
  346. // for v-model update:xxx events, also trigger kebab-case equivalent
  347. // for props passed via kebab-case
  348. if (!handler && isModelListener) {
  349. handlerName = shared.toHandlerKey(shared.hyphenate(event));
  350. handler = props[handlerName];
  351. }
  352. if (handler) {
  353. callWithAsyncErrorHandling(handler, instance, 6 /* COMPONENT_EVENT_HANDLER */, args);
  354. }
  355. const onceHandler = props[handlerName + `Once`];
  356. if (onceHandler) {
  357. if (!instance.emitted) {
  358. (instance.emitted = {})[handlerName] = true;
  359. }
  360. else if (instance.emitted[handlerName]) {
  361. return;
  362. }
  363. callWithAsyncErrorHandling(onceHandler, instance, 6 /* COMPONENT_EVENT_HANDLER */, args);
  364. }
  365. }
  366. function normalizeEmitsOptions(comp, appContext, asMixin = false) {
  367. if (!appContext.deopt && comp.__emits !== undefined) {
  368. return comp.__emits;
  369. }
  370. const raw = comp.emits;
  371. let normalized = {};
  372. // apply mixin/extends props
  373. let hasExtends = false;
  374. if (!shared.isFunction(comp)) {
  375. const extendEmits = (raw) => {
  376. hasExtends = true;
  377. shared.extend(normalized, normalizeEmitsOptions(raw, appContext, true));
  378. };
  379. if (!asMixin && appContext.mixins.length) {
  380. appContext.mixins.forEach(extendEmits);
  381. }
  382. if (comp.extends) {
  383. extendEmits(comp.extends);
  384. }
  385. if (comp.mixins) {
  386. comp.mixins.forEach(extendEmits);
  387. }
  388. }
  389. if (!raw && !hasExtends) {
  390. return (comp.__emits = null);
  391. }
  392. if (shared.isArray(raw)) {
  393. raw.forEach(key => (normalized[key] = null));
  394. }
  395. else {
  396. shared.extend(normalized, raw);
  397. }
  398. return (comp.__emits = normalized);
  399. }
  400. // Check if an incoming prop key is a declared emit event listener.
  401. // e.g. With `emits: { click: null }`, props named `onClick` and `onclick` are
  402. // both considered matched listeners.
  403. function isEmitListener(options, key) {
  404. if (!options || !shared.isOn(key)) {
  405. return false;
  406. }
  407. key = key.slice(2).replace(/Once$/, '');
  408. return (shared.hasOwn(options, key[0].toLowerCase() + key.slice(1)) ||
  409. shared.hasOwn(options, shared.hyphenate(key)) ||
  410. shared.hasOwn(options, key));
  411. }
  412. /**
  413. * mark the current rendering instance for asset resolution (e.g.
  414. * resolveComponent, resolveDirective) during render
  415. */
  416. let currentRenderingInstance = null;
  417. function setCurrentRenderingInstance(instance) {
  418. currentRenderingInstance = instance;
  419. }
  420. /**
  421. * dev only flag to track whether $attrs was used during render.
  422. * If $attrs was used during render then the warning for failed attrs
  423. * fallthrough can be suppressed.
  424. */
  425. let accessedAttrs = false;
  426. function markAttrsAccessed() {
  427. accessedAttrs = true;
  428. }
  429. function renderComponentRoot(instance) {
  430. const { type: Component, vnode, proxy, withProxy, props, propsOptions: [propsOptions], slots, attrs, emit, render, renderCache, data, setupState, ctx } = instance;
  431. let result;
  432. currentRenderingInstance = instance;
  433. try {
  434. let fallthroughAttrs;
  435. if (vnode.shapeFlag & 4 /* STATEFUL_COMPONENT */) {
  436. // withProxy is a proxy with a different `has` trap only for
  437. // runtime-compiled render functions using `with` block.
  438. const proxyToUse = withProxy || proxy;
  439. result = normalizeVNode(render.call(proxyToUse, proxyToUse, renderCache, props, setupState, data, ctx));
  440. fallthroughAttrs = attrs;
  441. }
  442. else {
  443. // functional
  444. const render = Component;
  445. // in dev, mark attrs accessed if optional props (attrs === props)
  446. if (false && attrs === props) ;
  447. result = normalizeVNode(render.length > 1
  448. ? render(props, false
  449. ? {
  450. get attrs() {
  451. markAttrsAccessed();
  452. return attrs;
  453. },
  454. slots,
  455. emit
  456. }
  457. : { attrs, slots, emit })
  458. : render(props, null /* we know it doesn't need it */));
  459. fallthroughAttrs = Component.props
  460. ? attrs
  461. : getFunctionalFallthrough(attrs);
  462. }
  463. // attr merging
  464. // in dev mode, comments are preserved, and it's possible for a template
  465. // to have comments along side the root element which makes it a fragment
  466. let root = result;
  467. let setRoot = undefined;
  468. if (false &&
  469. result.patchFlag > 0 &&
  470. result.patchFlag & 2048 /* DEV_ROOT_FRAGMENT */) ;
  471. if (Component.inheritAttrs !== false && fallthroughAttrs) {
  472. const keys = Object.keys(fallthroughAttrs);
  473. const { shapeFlag } = root;
  474. if (keys.length) {
  475. if (shapeFlag & 1 /* ELEMENT */ ||
  476. shapeFlag & 6 /* COMPONENT */) {
  477. if (propsOptions && keys.some(shared.isModelListener)) {
  478. // If a v-model listener (onUpdate:xxx) has a corresponding declared
  479. // prop, it indicates this component expects to handle v-model and
  480. // it should not fallthrough.
  481. // related: #1543, #1643, #1989
  482. fallthroughAttrs = filterModelListeners(fallthroughAttrs, propsOptions);
  483. }
  484. root = cloneVNode(root, fallthroughAttrs);
  485. }
  486. else if (false && !accessedAttrs && root.type !== Comment) ;
  487. }
  488. }
  489. // inherit directives
  490. if (vnode.dirs) {
  491. if (false && !isElementRoot(root)) ;
  492. root.dirs = root.dirs ? root.dirs.concat(vnode.dirs) : vnode.dirs;
  493. }
  494. // inherit transition data
  495. if (vnode.transition) {
  496. if (false && !isElementRoot(root)) ;
  497. root.transition = vnode.transition;
  498. }
  499. if (false && setRoot) ;
  500. else {
  501. result = root;
  502. }
  503. }
  504. catch (err) {
  505. handleError(err, instance, 1 /* RENDER_FUNCTION */);
  506. result = createVNode(Comment);
  507. }
  508. currentRenderingInstance = null;
  509. return result;
  510. }
  511. /**
  512. * dev only
  513. * In dev mode, template root level comments are rendered, which turns the
  514. * template into a fragment root, but we need to locate the single element
  515. * root for attrs and scope id processing.
  516. */
  517. const getChildRoot = (vnode) => {
  518. const rawChildren = vnode.children;
  519. const dynamicChildren = vnode.dynamicChildren;
  520. const childRoot = filterSingleRoot(rawChildren);
  521. if (!childRoot) {
  522. return [vnode, undefined];
  523. }
  524. const index = rawChildren.indexOf(childRoot);
  525. const dynamicIndex = dynamicChildren ? dynamicChildren.indexOf(childRoot) : -1;
  526. const setRoot = (updatedRoot) => {
  527. rawChildren[index] = updatedRoot;
  528. if (dynamicChildren) {
  529. if (dynamicIndex > -1) {
  530. dynamicChildren[dynamicIndex] = updatedRoot;
  531. }
  532. else if (updatedRoot.patchFlag > 0) {
  533. vnode.dynamicChildren = [...dynamicChildren, updatedRoot];
  534. }
  535. }
  536. };
  537. return [normalizeVNode(childRoot), setRoot];
  538. };
  539. function filterSingleRoot(children) {
  540. let singleRoot;
  541. for (let i = 0; i < children.length; i++) {
  542. const child = children[i];
  543. if (isVNode(child)) {
  544. // ignore user comment
  545. if (child.type !== Comment || child.children === 'v-if') {
  546. if (singleRoot) {
  547. // has more than 1 non-comment child, return now
  548. return;
  549. }
  550. else {
  551. singleRoot = child;
  552. }
  553. }
  554. }
  555. else {
  556. return;
  557. }
  558. }
  559. return singleRoot;
  560. }
  561. const getFunctionalFallthrough = (attrs) => {
  562. let res;
  563. for (const key in attrs) {
  564. if (key === 'class' || key === 'style' || shared.isOn(key)) {
  565. (res || (res = {}))[key] = attrs[key];
  566. }
  567. }
  568. return res;
  569. };
  570. const filterModelListeners = (attrs, props) => {
  571. const res = {};
  572. for (const key in attrs) {
  573. if (!shared.isModelListener(key) || !(key.slice(9) in props)) {
  574. res[key] = attrs[key];
  575. }
  576. }
  577. return res;
  578. };
  579. const isElementRoot = (vnode) => {
  580. return (vnode.shapeFlag & 6 /* COMPONENT */ ||
  581. vnode.shapeFlag & 1 /* ELEMENT */ ||
  582. vnode.type === Comment // potential v-if branch switch
  583. );
  584. };
  585. function shouldUpdateComponent(prevVNode, nextVNode, optimized) {
  586. const { props: prevProps, children: prevChildren, component } = prevVNode;
  587. const { props: nextProps, children: nextChildren, patchFlag } = nextVNode;
  588. const emits = component.emitsOptions;
  589. // force child update for runtime directive or transition on component vnode.
  590. if (nextVNode.dirs || nextVNode.transition) {
  591. return true;
  592. }
  593. if (optimized && patchFlag >= 0) {
  594. if (patchFlag & 1024 /* DYNAMIC_SLOTS */) {
  595. // slot content that references values that might have changed,
  596. // e.g. in a v-for
  597. return true;
  598. }
  599. if (patchFlag & 16 /* FULL_PROPS */) {
  600. if (!prevProps) {
  601. return !!nextProps;
  602. }
  603. // presence of this flag indicates props are always non-null
  604. return hasPropsChanged(prevProps, nextProps, emits);
  605. }
  606. else if (patchFlag & 8 /* PROPS */) {
  607. const dynamicProps = nextVNode.dynamicProps;
  608. for (let i = 0; i < dynamicProps.length; i++) {
  609. const key = dynamicProps[i];
  610. if (nextProps[key] !== prevProps[key] &&
  611. !isEmitListener(emits, key)) {
  612. return true;
  613. }
  614. }
  615. }
  616. }
  617. else {
  618. // this path is only taken by manually written render functions
  619. // so presence of any children leads to a forced update
  620. if (prevChildren || nextChildren) {
  621. if (!nextChildren || !nextChildren.$stable) {
  622. return true;
  623. }
  624. }
  625. if (prevProps === nextProps) {
  626. return false;
  627. }
  628. if (!prevProps) {
  629. return !!nextProps;
  630. }
  631. if (!nextProps) {
  632. return true;
  633. }
  634. return hasPropsChanged(prevProps, nextProps, emits);
  635. }
  636. return false;
  637. }
  638. function hasPropsChanged(prevProps, nextProps, emitsOptions) {
  639. const nextKeys = Object.keys(nextProps);
  640. if (nextKeys.length !== Object.keys(prevProps).length) {
  641. return true;
  642. }
  643. for (let i = 0; i < nextKeys.length; i++) {
  644. const key = nextKeys[i];
  645. if (nextProps[key] !== prevProps[key] &&
  646. !isEmitListener(emitsOptions, key)) {
  647. return true;
  648. }
  649. }
  650. return false;
  651. }
  652. function updateHOCHostEl({ vnode, parent }, el // HostNode
  653. ) {
  654. while (parent && parent.subTree === vnode) {
  655. (vnode = parent.vnode).el = el;
  656. parent = parent.parent;
  657. }
  658. }
  659. const isSuspense = (type) => type.__isSuspense;
  660. // Suspense exposes a component-like API, and is treated like a component
  661. // in the compiler, but internally it's a special built-in type that hooks
  662. // directly into the renderer.
  663. const SuspenseImpl = {
  664. // In order to make Suspense tree-shakable, we need to avoid importing it
  665. // directly in the renderer. The renderer checks for the __isSuspense flag
  666. // on a vnode's type and calls the `process` method, passing in renderer
  667. // internals.
  668. __isSuspense: true,
  669. process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized,
  670. // platform-specific impl passed from renderer
  671. rendererInternals) {
  672. if (n1 == null) {
  673. mountSuspense(n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized, rendererInternals);
  674. }
  675. else {
  676. patchSuspense(n1, n2, container, anchor, parentComponent, isSVG, rendererInternals);
  677. }
  678. },
  679. hydrate: hydrateSuspense,
  680. create: createSuspenseBoundary
  681. };
  682. // Force-casted public typing for h and TSX props inference
  683. const Suspense = (SuspenseImpl
  684. );
  685. function mountSuspense(vnode, container, anchor, parentComponent, parentSuspense, isSVG, optimized, rendererInternals) {
  686. const { p: patch, o: { createElement } } = rendererInternals;
  687. const hiddenContainer = createElement('div');
  688. const suspense = (vnode.suspense = createSuspenseBoundary(vnode, parentSuspense, parentComponent, container, hiddenContainer, anchor, isSVG, optimized, rendererInternals));
  689. // start mounting the content subtree in an off-dom container
  690. patch(null, (suspense.pendingBranch = vnode.ssContent), hiddenContainer, null, parentComponent, suspense, isSVG);
  691. // now check if we have encountered any async deps
  692. if (suspense.deps > 0) {
  693. // has async
  694. // mount the fallback tree
  695. patch(null, vnode.ssFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  696. isSVG);
  697. setActiveBranch(suspense, vnode.ssFallback);
  698. }
  699. else {
  700. // Suspense has no async deps. Just resolve.
  701. suspense.resolve();
  702. }
  703. }
  704. function patchSuspense(n1, n2, container, anchor, parentComponent, isSVG, { p: patch, um: unmount, o: { createElement } }) {
  705. const suspense = (n2.suspense = n1.suspense);
  706. suspense.vnode = n2;
  707. n2.el = n1.el;
  708. const newBranch = n2.ssContent;
  709. const newFallback = n2.ssFallback;
  710. const { activeBranch, pendingBranch, isInFallback, isHydrating } = suspense;
  711. if (pendingBranch) {
  712. suspense.pendingBranch = newBranch;
  713. if (isSameVNodeType(newBranch, pendingBranch)) {
  714. // same root type but content may have changed.
  715. patch(pendingBranch, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG);
  716. if (suspense.deps <= 0) {
  717. suspense.resolve();
  718. }
  719. else if (isInFallback) {
  720. patch(activeBranch, newFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  721. isSVG);
  722. setActiveBranch(suspense, newFallback);
  723. }
  724. }
  725. else {
  726. // toggled before pending tree is resolved
  727. suspense.pendingId++;
  728. if (isHydrating) {
  729. // if toggled before hydration is finished, the current DOM tree is
  730. // no longer valid. set it as the active branch so it will be unmounted
  731. // when resolved
  732. suspense.isHydrating = false;
  733. suspense.activeBranch = pendingBranch;
  734. }
  735. else {
  736. unmount(pendingBranch, parentComponent, suspense);
  737. }
  738. // increment pending ID. this is used to invalidate async callbacks
  739. // reset suspense state
  740. suspense.deps = 0;
  741. // discard effects from pending branch
  742. suspense.effects.length = 0;
  743. // discard previous container
  744. suspense.hiddenContainer = createElement('div');
  745. if (isInFallback) {
  746. // already in fallback state
  747. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG);
  748. if (suspense.deps <= 0) {
  749. suspense.resolve();
  750. }
  751. else {
  752. patch(activeBranch, newFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  753. isSVG);
  754. setActiveBranch(suspense, newFallback);
  755. }
  756. }
  757. else if (activeBranch && isSameVNodeType(newBranch, activeBranch)) {
  758. // toggled "back" to current active branch
  759. patch(activeBranch, newBranch, container, anchor, parentComponent, suspense, isSVG);
  760. // force resolve
  761. suspense.resolve(true);
  762. }
  763. else {
  764. // switched to a 3rd branch
  765. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG);
  766. if (suspense.deps <= 0) {
  767. suspense.resolve();
  768. }
  769. }
  770. }
  771. }
  772. else {
  773. if (activeBranch && isSameVNodeType(newBranch, activeBranch)) {
  774. // root did not change, just normal patch
  775. patch(activeBranch, newBranch, container, anchor, parentComponent, suspense, isSVG);
  776. setActiveBranch(suspense, newBranch);
  777. }
  778. else {
  779. // root node toggled
  780. // invoke @pending event
  781. const onPending = n2.props && n2.props.onPending;
  782. if (shared.isFunction(onPending)) {
  783. onPending();
  784. }
  785. // mount pending branch in off-dom container
  786. suspense.pendingBranch = newBranch;
  787. suspense.pendingId++;
  788. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG);
  789. if (suspense.deps <= 0) {
  790. // incoming branch has no async deps, resolve now.
  791. suspense.resolve();
  792. }
  793. else {
  794. const { timeout, pendingId } = suspense;
  795. if (timeout > 0) {
  796. setTimeout(() => {
  797. if (suspense.pendingId === pendingId) {
  798. suspense.fallback(newFallback);
  799. }
  800. }, timeout);
  801. }
  802. else if (timeout === 0) {
  803. suspense.fallback(newFallback);
  804. }
  805. }
  806. }
  807. }
  808. }
  809. function createSuspenseBoundary(vnode, parent, parentComponent, container, hiddenContainer, anchor, isSVG, optimized, rendererInternals, isHydrating = false) {
  810. const { p: patch, m: move, um: unmount, n: next, o: { parentNode, remove } } = rendererInternals;
  811. const timeout = shared.toNumber(vnode.props && vnode.props.timeout);
  812. const suspense = {
  813. vnode,
  814. parent,
  815. parentComponent,
  816. isSVG,
  817. container,
  818. hiddenContainer,
  819. anchor,
  820. deps: 0,
  821. pendingId: 0,
  822. timeout: typeof timeout === 'number' ? timeout : -1,
  823. activeBranch: null,
  824. pendingBranch: null,
  825. isInFallback: true,
  826. isHydrating,
  827. isUnmounted: false,
  828. effects: [],
  829. resolve(resume = false) {
  830. const { vnode, activeBranch, pendingBranch, pendingId, effects, parentComponent, container } = suspense;
  831. if (suspense.isHydrating) {
  832. suspense.isHydrating = false;
  833. }
  834. else if (!resume) {
  835. const delayEnter = activeBranch &&
  836. pendingBranch.transition &&
  837. pendingBranch.transition.mode === 'out-in';
  838. if (delayEnter) {
  839. activeBranch.transition.afterLeave = () => {
  840. if (pendingId === suspense.pendingId) {
  841. move(pendingBranch, container, anchor, 0 /* ENTER */);
  842. }
  843. };
  844. }
  845. // this is initial anchor on mount
  846. let { anchor } = suspense;
  847. // unmount current active tree
  848. if (activeBranch) {
  849. // if the fallback tree was mounted, it may have been moved
  850. // as part of a parent suspense. get the latest anchor for insertion
  851. anchor = next(activeBranch);
  852. unmount(activeBranch, parentComponent, suspense, true);
  853. }
  854. if (!delayEnter) {
  855. // move content from off-dom container to actual container
  856. move(pendingBranch, container, anchor, 0 /* ENTER */);
  857. }
  858. }
  859. setActiveBranch(suspense, pendingBranch);
  860. suspense.pendingBranch = null;
  861. suspense.isInFallback = false;
  862. // flush buffered effects
  863. // check if there is a pending parent suspense
  864. let parent = suspense.parent;
  865. let hasUnresolvedAncestor = false;
  866. while (parent) {
  867. if (parent.pendingBranch) {
  868. // found a pending parent suspense, merge buffered post jobs
  869. // into that parent
  870. parent.effects.push(...effects);
  871. hasUnresolvedAncestor = true;
  872. break;
  873. }
  874. parent = parent.parent;
  875. }
  876. // no pending parent suspense, flush all jobs
  877. if (!hasUnresolvedAncestor) {
  878. queuePostFlushCb(effects);
  879. }
  880. suspense.effects = [];
  881. // invoke @resolve event
  882. const onResolve = vnode.props && vnode.props.onResolve;
  883. if (shared.isFunction(onResolve)) {
  884. onResolve();
  885. }
  886. },
  887. fallback(fallbackVNode) {
  888. if (!suspense.pendingBranch) {
  889. return;
  890. }
  891. const { vnode, activeBranch, parentComponent, container, isSVG } = suspense;
  892. // invoke @fallback event
  893. const onFallback = vnode.props && vnode.props.onFallback;
  894. if (shared.isFunction(onFallback)) {
  895. onFallback();
  896. }
  897. const anchor = next(activeBranch);
  898. const mountFallback = () => {
  899. if (!suspense.isInFallback) {
  900. return;
  901. }
  902. // mount the fallback tree
  903. patch(null, fallbackVNode, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  904. isSVG);
  905. setActiveBranch(suspense, fallbackVNode);
  906. };
  907. const delayEnter = fallbackVNode.transition && fallbackVNode.transition.mode === 'out-in';
  908. if (delayEnter) {
  909. activeBranch.transition.afterLeave = mountFallback;
  910. }
  911. // unmount current active branch
  912. unmount(activeBranch, parentComponent, null, // no suspense so unmount hooks fire now
  913. true // shouldRemove
  914. );
  915. suspense.isInFallback = true;
  916. if (!delayEnter) {
  917. mountFallback();
  918. }
  919. },
  920. move(container, anchor, type) {
  921. suspense.activeBranch &&
  922. move(suspense.activeBranch, container, anchor, type);
  923. suspense.container = container;
  924. },
  925. next() {
  926. return suspense.activeBranch && next(suspense.activeBranch);
  927. },
  928. registerDep(instance, setupRenderEffect) {
  929. const isInPendingSuspense = !!suspense.pendingBranch;
  930. if (isInPendingSuspense) {
  931. suspense.deps++;
  932. }
  933. const hydratedEl = instance.vnode.el;
  934. instance
  935. .asyncDep.catch(err => {
  936. handleError(err, instance, 0 /* SETUP_FUNCTION */);
  937. })
  938. .then(asyncSetupResult => {
  939. // retry when the setup() promise resolves.
  940. // component may have been unmounted before resolve.
  941. if (instance.isUnmounted ||
  942. suspense.isUnmounted ||
  943. suspense.pendingId !== instance.suspenseId) {
  944. return;
  945. }
  946. // retry from this component
  947. instance.asyncResolved = true;
  948. const { vnode } = instance;
  949. handleSetupResult(instance, asyncSetupResult, false);
  950. if (hydratedEl) {
  951. // vnode may have been replaced if an update happened before the
  952. // async dep is resolved.
  953. vnode.el = hydratedEl;
  954. }
  955. const placeholder = !hydratedEl && instance.subTree.el;
  956. setupRenderEffect(instance, vnode,
  957. // component may have been moved before resolve.
  958. // if this is not a hydration, instance.subTree will be the comment
  959. // placeholder.
  960. parentNode(hydratedEl || instance.subTree.el),
  961. // anchor will not be used if this is hydration, so only need to
  962. // consider the comment placeholder case.
  963. hydratedEl ? null : next(instance.subTree), suspense, isSVG, optimized);
  964. if (placeholder) {
  965. remove(placeholder);
  966. }
  967. updateHOCHostEl(instance, vnode.el);
  968. // only decrease deps count if suspense is not already resolved
  969. if (isInPendingSuspense && --suspense.deps === 0) {
  970. suspense.resolve();
  971. }
  972. });
  973. },
  974. unmount(parentSuspense, doRemove) {
  975. suspense.isUnmounted = true;
  976. if (suspense.activeBranch) {
  977. unmount(suspense.activeBranch, parentComponent, parentSuspense, doRemove);
  978. }
  979. if (suspense.pendingBranch) {
  980. unmount(suspense.pendingBranch, parentComponent, parentSuspense, doRemove);
  981. }
  982. }
  983. };
  984. return suspense;
  985. }
  986. function hydrateSuspense(node, vnode, parentComponent, parentSuspense, isSVG, optimized, rendererInternals, hydrateNode) {
  987. /* eslint-disable no-restricted-globals */
  988. const suspense = (vnode.suspense = createSuspenseBoundary(vnode, parentSuspense, parentComponent, node.parentNode, document.createElement('div'), null, isSVG, optimized, rendererInternals, true /* hydrating */));
  989. // there are two possible scenarios for server-rendered suspense:
  990. // - success: ssr content should be fully resolved
  991. // - failure: ssr content should be the fallback branch.
  992. // however, on the client we don't really know if it has failed or not
  993. // attempt to hydrate the DOM assuming it has succeeded, but we still
  994. // need to construct a suspense boundary first
  995. const result = hydrateNode(node, (suspense.pendingBranch = vnode.ssContent), parentComponent, suspense, optimized);
  996. if (suspense.deps === 0) {
  997. suspense.resolve();
  998. }
  999. return result;
  1000. /* eslint-enable no-restricted-globals */
  1001. }
  1002. function normalizeSuspenseChildren(vnode) {
  1003. const { shapeFlag, children } = vnode;
  1004. let content;
  1005. let fallback;
  1006. if (shapeFlag & 32 /* SLOTS_CHILDREN */) {
  1007. content = normalizeSuspenseSlot(children.default);
  1008. fallback = normalizeSuspenseSlot(children.fallback);
  1009. }
  1010. else {
  1011. content = normalizeSuspenseSlot(children);
  1012. fallback = normalizeVNode(null);
  1013. }
  1014. return {
  1015. content,
  1016. fallback
  1017. };
  1018. }
  1019. function normalizeSuspenseSlot(s) {
  1020. if (shared.isFunction(s)) {
  1021. s = s();
  1022. }
  1023. if (shared.isArray(s)) {
  1024. const singleChild = filterSingleRoot(s);
  1025. s = singleChild;
  1026. }
  1027. return normalizeVNode(s);
  1028. }
  1029. function queueEffectWithSuspense(fn, suspense) {
  1030. if (suspense && suspense.pendingBranch) {
  1031. if (shared.isArray(fn)) {
  1032. suspense.effects.push(...fn);
  1033. }
  1034. else {
  1035. suspense.effects.push(fn);
  1036. }
  1037. }
  1038. else {
  1039. queuePostFlushCb(fn);
  1040. }
  1041. }
  1042. function setActiveBranch(suspense, branch) {
  1043. suspense.activeBranch = branch;
  1044. const { vnode, parentComponent } = suspense;
  1045. const el = (vnode.el = branch.el);
  1046. // in case suspense is the root node of a component,
  1047. // recursively update the HOC el
  1048. if (parentComponent && parentComponent.subTree === vnode) {
  1049. parentComponent.vnode.el = el;
  1050. updateHOCHostEl(parentComponent, el);
  1051. }
  1052. }
  1053. let isRenderingCompiledSlot = 0;
  1054. const setCompiledSlotRendering = (n) => (isRenderingCompiledSlot += n);
  1055. /**
  1056. * Compiler runtime helper for rendering `<slot/>`
  1057. * @private
  1058. */
  1059. function renderSlot(slots, name, props = {},
  1060. // this is not a user-facing function, so the fallback is always generated by
  1061. // the compiler and guaranteed to be a function returning an array
  1062. fallback) {
  1063. let slot = slots[name];
  1064. // a compiled slot disables block tracking by default to avoid manual
  1065. // invocation interfering with template-based block tracking, but in
  1066. // `renderSlot` we can be sure that it's template-based so we can force
  1067. // enable it.
  1068. isRenderingCompiledSlot++;
  1069. openBlock();
  1070. const validSlotContent = slot && ensureValidVNode(slot(props));
  1071. const rendered = createBlock(Fragment, { key: props.key || `_${name}` }, validSlotContent || (fallback ? fallback() : []), validSlotContent && slots._ === 1 /* STABLE */
  1072. ? 64 /* STABLE_FRAGMENT */
  1073. : -2 /* BAIL */);
  1074. isRenderingCompiledSlot--;
  1075. return rendered;
  1076. }
  1077. function ensureValidVNode(vnodes) {
  1078. return vnodes.some(child => {
  1079. if (!isVNode(child))
  1080. return true;
  1081. if (child.type === Comment)
  1082. return false;
  1083. if (child.type === Fragment &&
  1084. !ensureValidVNode(child.children))
  1085. return false;
  1086. return true;
  1087. })
  1088. ? vnodes
  1089. : null;
  1090. }
  1091. /**
  1092. * Wrap a slot function to memoize current rendering instance
  1093. * @private
  1094. */
  1095. function withCtx(fn, ctx = currentRenderingInstance) {
  1096. if (!ctx)
  1097. return fn;
  1098. const renderFnWithContext = (...args) => {
  1099. // If a user calls a compiled slot inside a template expression (#1745), it
  1100. // can mess up block tracking, so by default we need to push a null block to
  1101. // avoid that. This isn't necessary if rendering a compiled `<slot>`.
  1102. if (!isRenderingCompiledSlot) {
  1103. openBlock(true /* null block that disables tracking */);
  1104. }
  1105. const owner = currentRenderingInstance;
  1106. setCurrentRenderingInstance(ctx);
  1107. const res = fn(...args);
  1108. setCurrentRenderingInstance(owner);
  1109. if (!isRenderingCompiledSlot) {
  1110. closeBlock();
  1111. }
  1112. return res;
  1113. };
  1114. renderFnWithContext._c = true;
  1115. return renderFnWithContext;
  1116. }
  1117. // SFC scoped style ID management.
  1118. let currentScopeId = null;
  1119. const scopeIdStack = [];
  1120. /**
  1121. * @private
  1122. */
  1123. function pushScopeId(id) {
  1124. scopeIdStack.push((currentScopeId = id));
  1125. }
  1126. /**
  1127. * @private
  1128. */
  1129. function popScopeId() {
  1130. scopeIdStack.pop();
  1131. currentScopeId = scopeIdStack[scopeIdStack.length - 1] || null;
  1132. }
  1133. /**
  1134. * @private
  1135. */
  1136. function withScopeId(id) {
  1137. return ((fn) => withCtx(function () {
  1138. pushScopeId(id);
  1139. const res = fn.apply(this, arguments);
  1140. popScopeId();
  1141. return res;
  1142. }));
  1143. }
  1144. function initProps(instance, rawProps, isStateful, // result of bitwise flag comparison
  1145. isSSR = false) {
  1146. const props = {};
  1147. const attrs = {};
  1148. shared.def(attrs, InternalObjectKey, 1);
  1149. setFullProps(instance, rawProps, props, attrs);
  1150. if (isStateful) {
  1151. // stateful
  1152. instance.props = isSSR ? props : reactivity.shallowReactive(props);
  1153. }
  1154. else {
  1155. if (!instance.type.props) {
  1156. // functional w/ optional props, props === attrs
  1157. instance.props = attrs;
  1158. }
  1159. else {
  1160. // functional w/ declared props
  1161. instance.props = props;
  1162. }
  1163. }
  1164. instance.attrs = attrs;
  1165. }
  1166. function updateProps(instance, rawProps, rawPrevProps, optimized) {
  1167. const { props, attrs, vnode: { patchFlag } } = instance;
  1168. const rawCurrentProps = reactivity.toRaw(props);
  1169. const [options] = instance.propsOptions;
  1170. if (
  1171. // always force full diff in dev
  1172. // - #1942 if hmr is enabled with sfc component
  1173. // - vite#872 non-sfc component used by sfc component
  1174. (optimized || patchFlag > 0) &&
  1175. !(patchFlag & 16 /* FULL_PROPS */)) {
  1176. if (patchFlag & 8 /* PROPS */) {
  1177. // Compiler-generated props & no keys change, just set the updated
  1178. // the props.
  1179. const propsToUpdate = instance.vnode.dynamicProps;
  1180. for (let i = 0; i < propsToUpdate.length; i++) {
  1181. const key = propsToUpdate[i];
  1182. // PROPS flag guarantees rawProps to be non-null
  1183. const value = rawProps[key];
  1184. if (options) {
  1185. // attr / props separation was done on init and will be consistent
  1186. // in this code path, so just check if attrs have it.
  1187. if (shared.hasOwn(attrs, key)) {
  1188. attrs[key] = value;
  1189. }
  1190. else {
  1191. const camelizedKey = shared.camelize(key);
  1192. props[camelizedKey] = resolvePropValue(options, rawCurrentProps, camelizedKey, value, instance);
  1193. }
  1194. }
  1195. else {
  1196. attrs[key] = value;
  1197. }
  1198. }
  1199. }
  1200. }
  1201. else {
  1202. // full props update.
  1203. setFullProps(instance, rawProps, props, attrs);
  1204. // in case of dynamic props, check if we need to delete keys from
  1205. // the props object
  1206. let kebabKey;
  1207. for (const key in rawCurrentProps) {
  1208. if (!rawProps ||
  1209. // for camelCase
  1210. (!shared.hasOwn(rawProps, key) &&
  1211. // it's possible the original props was passed in as kebab-case
  1212. // and converted to camelCase (#955)
  1213. ((kebabKey = shared.hyphenate(key)) === key || !shared.hasOwn(rawProps, kebabKey)))) {
  1214. if (options) {
  1215. if (rawPrevProps &&
  1216. // for camelCase
  1217. (rawPrevProps[key] !== undefined ||
  1218. // for kebab-case
  1219. rawPrevProps[kebabKey] !== undefined)) {
  1220. props[key] = resolvePropValue(options, rawProps || shared.EMPTY_OBJ, key, undefined, instance);
  1221. }
  1222. }
  1223. else {
  1224. delete props[key];
  1225. }
  1226. }
  1227. }
  1228. // in the case of functional component w/o props declaration, props and
  1229. // attrs point to the same object so it should already have been updated.
  1230. if (attrs !== rawCurrentProps) {
  1231. for (const key in attrs) {
  1232. if (!rawProps || !shared.hasOwn(rawProps, key)) {
  1233. delete attrs[key];
  1234. }
  1235. }
  1236. }
  1237. }
  1238. // trigger updates for $attrs in case it's used in component slots
  1239. reactivity.trigger(instance, "set" /* SET */, '$attrs');
  1240. }
  1241. function setFullProps(instance, rawProps, props, attrs) {
  1242. const [options, needCastKeys] = instance.propsOptions;
  1243. if (rawProps) {
  1244. for (const key in rawProps) {
  1245. const value = rawProps[key];
  1246. // key, ref are reserved and never passed down
  1247. if (shared.isReservedProp(key)) {
  1248. continue;
  1249. }
  1250. // prop option names are camelized during normalization, so to support
  1251. // kebab -> camel conversion here we need to camelize the key.
  1252. let camelKey;
  1253. if (options && shared.hasOwn(options, (camelKey = shared.camelize(key)))) {
  1254. props[camelKey] = value;
  1255. }
  1256. else if (!isEmitListener(instance.emitsOptions, key)) {
  1257. // Any non-declared (either as a prop or an emitted event) props are put
  1258. // into a separate `attrs` object for spreading. Make sure to preserve
  1259. // original key casing
  1260. attrs[key] = value;
  1261. }
  1262. }
  1263. }
  1264. if (needCastKeys) {
  1265. const rawCurrentProps = reactivity.toRaw(props);
  1266. for (let i = 0; i < needCastKeys.length; i++) {
  1267. const key = needCastKeys[i];
  1268. props[key] = resolvePropValue(options, rawCurrentProps, key, rawCurrentProps[key], instance);
  1269. }
  1270. }
  1271. }
  1272. function resolvePropValue(options, props, key, value, instance) {
  1273. const opt = options[key];
  1274. if (opt != null) {
  1275. const hasDefault = shared.hasOwn(opt, 'default');
  1276. // default values
  1277. if (hasDefault && value === undefined) {
  1278. const defaultValue = opt.default;
  1279. if (opt.type !== Function && shared.isFunction(defaultValue)) {
  1280. setCurrentInstance(instance);
  1281. value = defaultValue(props);
  1282. setCurrentInstance(null);
  1283. }
  1284. else {
  1285. value = defaultValue;
  1286. }
  1287. }
  1288. // boolean casting
  1289. if (opt[0 /* shouldCast */]) {
  1290. if (!shared.hasOwn(props, key) && !hasDefault) {
  1291. value = false;
  1292. }
  1293. else if (opt[1 /* shouldCastTrue */] &&
  1294. (value === '' || value === shared.hyphenate(key))) {
  1295. value = true;
  1296. }
  1297. }
  1298. }
  1299. return value;
  1300. }
  1301. function normalizePropsOptions(comp, appContext, asMixin = false) {
  1302. if (!appContext.deopt && comp.__props) {
  1303. return comp.__props;
  1304. }
  1305. const raw = comp.props;
  1306. const normalized = {};
  1307. const needCastKeys = [];
  1308. // apply mixin/extends props
  1309. let hasExtends = false;
  1310. if (!shared.isFunction(comp)) {
  1311. const extendProps = (raw) => {
  1312. hasExtends = true;
  1313. const [props, keys] = normalizePropsOptions(raw, appContext, true);
  1314. shared.extend(normalized, props);
  1315. if (keys)
  1316. needCastKeys.push(...keys);
  1317. };
  1318. if (!asMixin && appContext.mixins.length) {
  1319. appContext.mixins.forEach(extendProps);
  1320. }
  1321. if (comp.extends) {
  1322. extendProps(comp.extends);
  1323. }
  1324. if (comp.mixins) {
  1325. comp.mixins.forEach(extendProps);
  1326. }
  1327. }
  1328. if (!raw && !hasExtends) {
  1329. return (comp.__props = shared.EMPTY_ARR);
  1330. }
  1331. if (shared.isArray(raw)) {
  1332. for (let i = 0; i < raw.length; i++) {
  1333. const normalizedKey = shared.camelize(raw[i]);
  1334. if (validatePropName(normalizedKey)) {
  1335. normalized[normalizedKey] = shared.EMPTY_OBJ;
  1336. }
  1337. }
  1338. }
  1339. else if (raw) {
  1340. for (const key in raw) {
  1341. const normalizedKey = shared.camelize(key);
  1342. if (validatePropName(normalizedKey)) {
  1343. const opt = raw[key];
  1344. const prop = (normalized[normalizedKey] =
  1345. shared.isArray(opt) || shared.isFunction(opt) ? { type: opt } : opt);
  1346. if (prop) {
  1347. const booleanIndex = getTypeIndex(Boolean, prop.type);
  1348. const stringIndex = getTypeIndex(String, prop.type);
  1349. prop[0 /* shouldCast */] = booleanIndex > -1;
  1350. prop[1 /* shouldCastTrue */] =
  1351. stringIndex < 0 || booleanIndex < stringIndex;
  1352. // if the prop needs boolean casting or default value
  1353. if (booleanIndex > -1 || shared.hasOwn(prop, 'default')) {
  1354. needCastKeys.push(normalizedKey);
  1355. }
  1356. }
  1357. }
  1358. }
  1359. }
  1360. return (comp.__props = [normalized, needCastKeys]);
  1361. }
  1362. function validatePropName(key) {
  1363. if (key[0] !== '$') {
  1364. return true;
  1365. }
  1366. return false;
  1367. }
  1368. // use function string name to check type constructors
  1369. // so that it works across vms / iframes.
  1370. function getType(ctor) {
  1371. const match = ctor && ctor.toString().match(/^\s*function (\w+)/);
  1372. return match ? match[1] : '';
  1373. }
  1374. function isSameType(a, b) {
  1375. return getType(a) === getType(b);
  1376. }
  1377. function getTypeIndex(type, expectedTypes) {
  1378. if (shared.isArray(expectedTypes)) {
  1379. for (let i = 0, len = expectedTypes.length; i < len; i++) {
  1380. if (isSameType(expectedTypes[i], type)) {
  1381. return i;
  1382. }
  1383. }
  1384. }
  1385. else if (shared.isFunction(expectedTypes)) {
  1386. return isSameType(expectedTypes, type) ? 0 : -1;
  1387. }
  1388. return -1;
  1389. }
  1390. function injectHook(type, hook, target = currentInstance, prepend = false) {
  1391. if (target) {
  1392. const hooks = target[type] || (target[type] = []);
  1393. // cache the error handling wrapper for injected hooks so the same hook
  1394. // can be properly deduped by the scheduler. "__weh" stands for "with error
  1395. // handling".
  1396. const wrappedHook = hook.__weh ||
  1397. (hook.__weh = (...args) => {
  1398. if (target.isUnmounted) {
  1399. return;
  1400. }
  1401. // disable tracking inside all lifecycle hooks
  1402. // since they can potentially be called inside effects.
  1403. reactivity.pauseTracking();
  1404. // Set currentInstance during hook invocation.
  1405. // This assumes the hook does not synchronously trigger other hooks, which
  1406. // can only be false when the user does something really funky.
  1407. setCurrentInstance(target);
  1408. const res = callWithAsyncErrorHandling(hook, target, type, args);
  1409. setCurrentInstance(null);
  1410. reactivity.resetTracking();
  1411. return res;
  1412. });
  1413. if (prepend) {
  1414. hooks.unshift(wrappedHook);
  1415. }
  1416. else {
  1417. hooks.push(wrappedHook);
  1418. }
  1419. return wrappedHook;
  1420. }
  1421. }
  1422. const createHook = (lifecycle) => (hook, target = currentInstance) =>
  1423. // post-create lifecycle registrations are noops during SSR
  1424. !isInSSRComponentSetup && injectHook(lifecycle, hook, target);
  1425. const onBeforeMount = createHook("bm" /* BEFORE_MOUNT */);
  1426. const onMounted = createHook("m" /* MOUNTED */);
  1427. const onBeforeUpdate = createHook("bu" /* BEFORE_UPDATE */);
  1428. const onUpdated = createHook("u" /* UPDATED */);
  1429. const onBeforeUnmount = createHook("bum" /* BEFORE_UNMOUNT */);
  1430. const onUnmounted = createHook("um" /* UNMOUNTED */);
  1431. const onRenderTriggered = createHook("rtg" /* RENDER_TRIGGERED */);
  1432. const onRenderTracked = createHook("rtc" /* RENDER_TRACKED */);
  1433. const onErrorCaptured = (hook, target = currentInstance) => {
  1434. injectHook("ec" /* ERROR_CAPTURED */, hook, target);
  1435. };
  1436. // Simple effect.
  1437. function watchEffect(effect, options) {
  1438. return doWatch(effect, null, options);
  1439. }
  1440. // initial value for watchers to trigger on undefined initial values
  1441. const INITIAL_WATCHER_VALUE = {};
  1442. // implementation
  1443. function watch(source, cb, options) {
  1444. return doWatch(source, cb, options);
  1445. }
  1446. function doWatch(source, cb, { immediate, deep, flush, onTrack, onTrigger } = shared.EMPTY_OBJ, instance = currentInstance) {
  1447. let getter;
  1448. let forceTrigger = false;
  1449. if (reactivity.isRef(source)) {
  1450. getter = () => source.value;
  1451. forceTrigger = !!source._shallow;
  1452. }
  1453. else if (reactivity.isReactive(source)) {
  1454. getter = () => source;
  1455. deep = true;
  1456. }
  1457. else if (shared.isArray(source)) {
  1458. getter = () => source.map(s => {
  1459. if (reactivity.isRef(s)) {
  1460. return s.value;
  1461. }
  1462. else if (reactivity.isReactive(s)) {
  1463. return traverse(s);
  1464. }
  1465. else if (shared.isFunction(s)) {
  1466. return callWithErrorHandling(s, instance, 2 /* WATCH_GETTER */, [
  1467. instance && instance.proxy
  1468. ]);
  1469. }
  1470. else ;
  1471. });
  1472. }
  1473. else if (shared.isFunction(source)) {
  1474. if (cb) {
  1475. // getter with cb
  1476. getter = () => callWithErrorHandling(source, instance, 2 /* WATCH_GETTER */, [
  1477. instance && instance.proxy
  1478. ]);
  1479. }
  1480. else {
  1481. // no cb -> simple effect
  1482. getter = () => {
  1483. if (instance && instance.isUnmounted) {
  1484. return;
  1485. }
  1486. if (cleanup) {
  1487. cleanup();
  1488. }
  1489. return callWithErrorHandling(source, instance, 3 /* WATCH_CALLBACK */, [onInvalidate]);
  1490. };
  1491. }
  1492. }
  1493. else {
  1494. getter = shared.NOOP;
  1495. }
  1496. if (cb && deep) {
  1497. const baseGetter = getter;
  1498. getter = () => traverse(baseGetter());
  1499. }
  1500. let cleanup;
  1501. const onInvalidate = (fn) => {
  1502. cleanup = runner.options.onStop = () => {
  1503. callWithErrorHandling(fn, instance, 4 /* WATCH_CLEANUP */);
  1504. };
  1505. };
  1506. // in SSR there is no need to setup an actual effect, and it should be noop
  1507. // unless it's eager
  1508. if (isInSSRComponentSetup) {
  1509. if (!cb) {
  1510. getter();
  1511. }
  1512. else if (immediate) {
  1513. callWithAsyncErrorHandling(cb, instance, 3 /* WATCH_CALLBACK */, [
  1514. getter(),
  1515. undefined,
  1516. onInvalidate
  1517. ]);
  1518. }
  1519. return shared.NOOP;
  1520. }
  1521. let oldValue = shared.isArray(source) ? [] : INITIAL_WATCHER_VALUE;
  1522. const job = () => {
  1523. if (!runner.active) {
  1524. return;
  1525. }
  1526. if (cb) {
  1527. // watch(source, cb)
  1528. const newValue = runner();
  1529. if (deep || forceTrigger || shared.hasChanged(newValue, oldValue)) {
  1530. // cleanup before running cb again
  1531. if (cleanup) {
  1532. cleanup();
  1533. }
  1534. callWithAsyncErrorHandling(cb, instance, 3 /* WATCH_CALLBACK */, [
  1535. newValue,
  1536. // pass undefined as the old value when it's changed for the first time
  1537. oldValue === INITIAL_WATCHER_VALUE ? undefined : oldValue,
  1538. onInvalidate
  1539. ]);
  1540. oldValue = newValue;
  1541. }
  1542. }
  1543. else {
  1544. // watchEffect
  1545. runner();
  1546. }
  1547. };
  1548. // important: mark the job as a watcher callback so that scheduler knows
  1549. // it is allowed to self-trigger (#1727)
  1550. job.allowRecurse = !!cb;
  1551. let scheduler;
  1552. if (flush === 'sync') {
  1553. scheduler = job;
  1554. }
  1555. else if (flush === 'post') {
  1556. scheduler = () => queuePostRenderEffect(job, instance && instance.suspense);
  1557. }
  1558. else {
  1559. // default: 'pre'
  1560. scheduler = () => {
  1561. if (!instance || instance.isMounted) {
  1562. queuePreFlushCb(job);
  1563. }
  1564. else {
  1565. // with 'pre' option, the first call must happen before
  1566. // the component is mounted so it is called synchronously.
  1567. job();
  1568. }
  1569. };
  1570. }
  1571. const runner = reactivity.effect(getter, {
  1572. lazy: true,
  1573. onTrack,
  1574. onTrigger,
  1575. scheduler
  1576. });
  1577. recordInstanceBoundEffect(runner, instance);
  1578. // initial run
  1579. if (cb) {
  1580. if (immediate) {
  1581. job();
  1582. }
  1583. else {
  1584. oldValue = runner();
  1585. }
  1586. }
  1587. else if (flush === 'post') {
  1588. queuePostRenderEffect(runner, instance && instance.suspense);
  1589. }
  1590. else {
  1591. runner();
  1592. }
  1593. return () => {
  1594. reactivity.stop(runner);
  1595. if (instance) {
  1596. shared.remove(instance.effects, runner);
  1597. }
  1598. };
  1599. }
  1600. // this.$watch
  1601. function instanceWatch(source, cb, options) {
  1602. const publicThis = this.proxy;
  1603. const getter = shared.isString(source)
  1604. ? () => publicThis[source]
  1605. : source.bind(publicThis);
  1606. return doWatch(getter, cb.bind(publicThis), options, this);
  1607. }
  1608. function traverse(value, seen = new Set()) {
  1609. if (!shared.isObject(value) || seen.has(value)) {
  1610. return value;
  1611. }
  1612. seen.add(value);
  1613. if (reactivity.isRef(value)) {
  1614. traverse(value.value, seen);
  1615. }
  1616. else if (shared.isArray(value)) {
  1617. for (let i = 0; i < value.length; i++) {
  1618. traverse(value[i], seen);
  1619. }
  1620. }
  1621. else if (shared.isSet(value) || shared.isMap(value)) {
  1622. value.forEach((v) => {
  1623. traverse(v, seen);
  1624. });
  1625. }
  1626. else {
  1627. for (const key in value) {
  1628. traverse(value[key], seen);
  1629. }
  1630. }
  1631. return value;
  1632. }
  1633. function useTransitionState() {
  1634. const state = {
  1635. isMounted: false,
  1636. isLeaving: false,
  1637. isUnmounting: false,
  1638. leavingVNodes: new Map()
  1639. };
  1640. onMounted(() => {
  1641. state.isMounted = true;
  1642. });
  1643. onBeforeUnmount(() => {
  1644. state.isUnmounting = true;
  1645. });
  1646. return state;
  1647. }
  1648. const TransitionHookValidator = [Function, Array];
  1649. const BaseTransitionImpl = {
  1650. name: `BaseTransition`,
  1651. props: {
  1652. mode: String,
  1653. appear: Boolean,
  1654. persisted: Boolean,
  1655. // enter
  1656. onBeforeEnter: TransitionHookValidator,
  1657. onEnter: TransitionHookValidator,
  1658. onAfterEnter: TransitionHookValidator,
  1659. onEnterCancelled: TransitionHookValidator,
  1660. // leave
  1661. onBeforeLeave: TransitionHookValidator,
  1662. onLeave: TransitionHookValidator,
  1663. onAfterLeave: TransitionHookValidator,
  1664. onLeaveCancelled: TransitionHookValidator,
  1665. // appear
  1666. onBeforeAppear: TransitionHookValidator,
  1667. onAppear: TransitionHookValidator,
  1668. onAfterAppear: TransitionHookValidator,
  1669. onAppearCancelled: TransitionHookValidator
  1670. },
  1671. setup(props, { slots }) {
  1672. const instance = getCurrentInstance();
  1673. const state = useTransitionState();
  1674. let prevTransitionKey;
  1675. return () => {
  1676. const children = slots.default && getTransitionRawChildren(slots.default(), true);
  1677. if (!children || !children.length) {
  1678. return;
  1679. }
  1680. // there's no need to track reactivity for these props so use the raw
  1681. // props for a bit better perf
  1682. const rawProps = reactivity.toRaw(props);
  1683. const { mode } = rawProps;
  1684. // at this point children has a guaranteed length of 1.
  1685. const child = children[0];
  1686. if (state.isLeaving) {
  1687. return emptyPlaceholder(child);
  1688. }
  1689. // in the case of <transition><keep-alive/></transition>, we need to
  1690. // compare the type of the kept-alive children.
  1691. const innerChild = getKeepAliveChild(child);
  1692. if (!innerChild) {
  1693. return emptyPlaceholder(child);
  1694. }
  1695. const enterHooks = resolveTransitionHooks(innerChild, rawProps, state, instance);
  1696. setTransitionHooks(innerChild, enterHooks);
  1697. const oldChild = instance.subTree;
  1698. const oldInnerChild = oldChild && getKeepAliveChild(oldChild);
  1699. let transitionKeyChanged = false;
  1700. const { getTransitionKey } = innerChild.type;
  1701. if (getTransitionKey) {
  1702. const key = getTransitionKey();
  1703. if (prevTransitionKey === undefined) {
  1704. prevTransitionKey = key;
  1705. }
  1706. else if (key !== prevTransitionKey) {
  1707. prevTransitionKey = key;
  1708. transitionKeyChanged = true;
  1709. }
  1710. }
  1711. // handle mode
  1712. if (oldInnerChild &&
  1713. oldInnerChild.type !== Comment &&
  1714. (!isSameVNodeType(innerChild, oldInnerChild) || transitionKeyChanged)) {
  1715. const leavingHooks = resolveTransitionHooks(oldInnerChild, rawProps, state, instance);
  1716. // update old tree's hooks in case of dynamic transition
  1717. setTransitionHooks(oldInnerChild, leavingHooks);
  1718. // switching between different views
  1719. if (mode === 'out-in') {
  1720. state.isLeaving = true;
  1721. // return placeholder node and queue update when leave finishes
  1722. leavingHooks.afterLeave = () => {
  1723. state.isLeaving = false;
  1724. instance.update();
  1725. };
  1726. return emptyPlaceholder(child);
  1727. }
  1728. else if (mode === 'in-out') {
  1729. leavingHooks.delayLeave = (el, earlyRemove, delayedLeave) => {
  1730. const leavingVNodesCache = getLeavingNodesForType(state, oldInnerChild);
  1731. leavingVNodesCache[String(oldInnerChild.key)] = oldInnerChild;
  1732. // early removal callback
  1733. el._leaveCb = () => {
  1734. earlyRemove();
  1735. el._leaveCb = undefined;
  1736. delete enterHooks.delayedLeave;
  1737. };
  1738. enterHooks.delayedLeave = delayedLeave;
  1739. };
  1740. }
  1741. }
  1742. return child;
  1743. };
  1744. }
  1745. };
  1746. // export the public type for h/tsx inference
  1747. // also to avoid inline import() in generated d.ts files
  1748. const BaseTransition = BaseTransitionImpl;
  1749. function getLeavingNodesForType(state, vnode) {
  1750. const { leavingVNodes } = state;
  1751. let leavingVNodesCache = leavingVNodes.get(vnode.type);
  1752. if (!leavingVNodesCache) {
  1753. leavingVNodesCache = Object.create(null);
  1754. leavingVNodes.set(vnode.type, leavingVNodesCache);
  1755. }
  1756. return leavingVNodesCache;
  1757. }
  1758. // The transition hooks are attached to the vnode as vnode.transition
  1759. // and will be called at appropriate timing in the renderer.
  1760. function resolveTransitionHooks(vnode, props, state, instance) {
  1761. const { appear, mode, persisted = false, onBeforeEnter, onEnter, onAfterEnter, onEnterCancelled, onBeforeLeave, onLeave, onAfterLeave, onLeaveCancelled, onBeforeAppear, onAppear, onAfterAppear, onAppearCancelled } = props;
  1762. const key = String(vnode.key);
  1763. const leavingVNodesCache = getLeavingNodesForType(state, vnode);
  1764. const callHook = (hook, args) => {
  1765. hook &&
  1766. callWithAsyncErrorHandling(hook, instance, 9 /* TRANSITION_HOOK */, args);
  1767. };
  1768. const hooks = {
  1769. mode,
  1770. persisted,
  1771. beforeEnter(el) {
  1772. let hook = onBeforeEnter;
  1773. if (!state.isMounted) {
  1774. if (appear) {
  1775. hook = onBeforeAppear || onBeforeEnter;
  1776. }
  1777. else {
  1778. return;
  1779. }
  1780. }
  1781. // for same element (v-show)
  1782. if (el._leaveCb) {
  1783. el._leaveCb(true /* cancelled */);
  1784. }
  1785. // for toggled element with same key (v-if)
  1786. const leavingVNode = leavingVNodesCache[key];
  1787. if (leavingVNode &&
  1788. isSameVNodeType(vnode, leavingVNode) &&
  1789. leavingVNode.el._leaveCb) {
  1790. // force early removal (not cancelled)
  1791. leavingVNode.el._leaveCb();
  1792. }
  1793. callHook(hook, [el]);
  1794. },
  1795. enter(el) {
  1796. let hook = onEnter;
  1797. let afterHook = onAfterEnter;
  1798. let cancelHook = onEnterCancelled;
  1799. if (!state.isMounted) {
  1800. if (appear) {
  1801. hook = onAppear || onEnter;
  1802. afterHook = onAfterAppear || onAfterEnter;
  1803. cancelHook = onAppearCancelled || onEnterCancelled;
  1804. }
  1805. else {
  1806. return;
  1807. }
  1808. }
  1809. let called = false;
  1810. const done = (el._enterCb = (cancelled) => {
  1811. if (called)
  1812. return;
  1813. called = true;
  1814. if (cancelled) {
  1815. callHook(cancelHook, [el]);
  1816. }
  1817. else {
  1818. callHook(afterHook, [el]);
  1819. }
  1820. if (hooks.delayedLeave) {
  1821. hooks.delayedLeave();
  1822. }
  1823. el._enterCb = undefined;
  1824. });
  1825. if (hook) {
  1826. hook(el, done);
  1827. if (hook.length <= 1) {
  1828. done();
  1829. }
  1830. }
  1831. else {
  1832. done();
  1833. }
  1834. },
  1835. leave(el, remove) {
  1836. const key = String(vnode.key);
  1837. if (el._enterCb) {
  1838. el._enterCb(true /* cancelled */);
  1839. }
  1840. if (state.isUnmounting) {
  1841. return remove();
  1842. }
  1843. callHook(onBeforeLeave, [el]);
  1844. let called = false;
  1845. const done = (el._leaveCb = (cancelled) => {
  1846. if (called)
  1847. return;
  1848. called = true;
  1849. remove();
  1850. if (cancelled) {
  1851. callHook(onLeaveCancelled, [el]);
  1852. }
  1853. else {
  1854. callHook(onAfterLeave, [el]);
  1855. }
  1856. el._leaveCb = undefined;
  1857. if (leavingVNodesCache[key] === vnode) {
  1858. delete leavingVNodesCache[key];
  1859. }
  1860. });
  1861. leavingVNodesCache[key] = vnode;
  1862. if (onLeave) {
  1863. onLeave(el, done);
  1864. if (onLeave.length <= 1) {
  1865. done();
  1866. }
  1867. }
  1868. else {
  1869. done();
  1870. }
  1871. },
  1872. clone(vnode) {
  1873. return resolveTransitionHooks(vnode, props, state, instance);
  1874. }
  1875. };
  1876. return hooks;
  1877. }
  1878. // the placeholder really only handles one special case: KeepAlive
  1879. // in the case of a KeepAlive in a leave phase we need to return a KeepAlive
  1880. // placeholder with empty content to avoid the KeepAlive instance from being
  1881. // unmounted.
  1882. function emptyPlaceholder(vnode) {
  1883. if (isKeepAlive(vnode)) {
  1884. vnode = cloneVNode(vnode);
  1885. vnode.children = null;
  1886. return vnode;
  1887. }
  1888. }
  1889. function getKeepAliveChild(vnode) {
  1890. return isKeepAlive(vnode)
  1891. ? vnode.children
  1892. ? vnode.children[0]
  1893. : undefined
  1894. : vnode;
  1895. }
  1896. function setTransitionHooks(vnode, hooks) {
  1897. if (vnode.shapeFlag & 6 /* COMPONENT */ && vnode.component) {
  1898. setTransitionHooks(vnode.component.subTree, hooks);
  1899. }
  1900. else if (vnode.shapeFlag & 128 /* SUSPENSE */) {
  1901. vnode.ssContent.transition = hooks.clone(vnode.ssContent);
  1902. vnode.ssFallback.transition = hooks.clone(vnode.ssFallback);
  1903. }
  1904. else {
  1905. vnode.transition = hooks;
  1906. }
  1907. }
  1908. function getTransitionRawChildren(children, keepComment = false) {
  1909. let ret = [];
  1910. let keyedFragmentCount = 0;
  1911. for (let i = 0; i < children.length; i++) {
  1912. const child = children[i];
  1913. // handle fragment children case, e.g. v-for
  1914. if (child.type === Fragment) {
  1915. if (child.patchFlag & 128 /* KEYED_FRAGMENT */)
  1916. keyedFragmentCount++;
  1917. ret = ret.concat(getTransitionRawChildren(child.children, keepComment));
  1918. }
  1919. // comment placeholders should be skipped, e.g. v-if
  1920. else if (keepComment || child.type !== Comment) {
  1921. ret.push(child);
  1922. }
  1923. }
  1924. // #1126 if a transition children list contains multiple sub fragments, these
  1925. // fragments will be merged into a flat children array. Since each v-for
  1926. // fragment may contain different static bindings inside, we need to de-op
  1927. // these children to force full diffs to ensure correct behavior.
  1928. if (keyedFragmentCount > 1) {
  1929. for (let i = 0; i < ret.length; i++) {
  1930. ret[i].patchFlag = -2 /* BAIL */;
  1931. }
  1932. }
  1933. return ret;
  1934. }
  1935. const isKeepAlive = (vnode) => vnode.type.__isKeepAlive;
  1936. const KeepAliveImpl = {
  1937. name: `KeepAlive`,
  1938. // Marker for special handling inside the renderer. We are not using a ===
  1939. // check directly on KeepAlive in the renderer, because importing it directly
  1940. // would prevent it from being tree-shaken.
  1941. __isKeepAlive: true,
  1942. props: {
  1943. include: [String, RegExp, Array],
  1944. exclude: [String, RegExp, Array],
  1945. max: [String, Number]
  1946. },
  1947. setup(props, { slots }) {
  1948. const cache = new Map();
  1949. const keys = new Set();
  1950. let current = null;
  1951. const instance = getCurrentInstance();
  1952. const parentSuspense = instance.suspense;
  1953. // KeepAlive communicates with the instantiated renderer via the
  1954. // ctx where the renderer passes in its internals,
  1955. // and the KeepAlive instance exposes activate/deactivate implementations.
  1956. // The whole point of this is to avoid importing KeepAlive directly in the
  1957. // renderer to facilitate tree-shaking.
  1958. const sharedContext = instance.ctx;
  1959. const { renderer: { p: patch, m: move, um: _unmount, o: { createElement } } } = sharedContext;
  1960. const storageContainer = createElement('div');
  1961. sharedContext.activate = (vnode, container, anchor, isSVG, optimized) => {
  1962. const instance = vnode.component;
  1963. move(vnode, container, anchor, 0 /* ENTER */, parentSuspense);
  1964. // in case props have changed
  1965. patch(instance.vnode, vnode, container, anchor, instance, parentSuspense, isSVG, optimized);
  1966. queuePostRenderEffect(() => {
  1967. instance.isDeactivated = false;
  1968. if (instance.a) {
  1969. shared.invokeArrayFns(instance.a);
  1970. }
  1971. const vnodeHook = vnode.props && vnode.props.onVnodeMounted;
  1972. if (vnodeHook) {
  1973. invokeVNodeHook(vnodeHook, instance.parent, vnode);
  1974. }
  1975. }, parentSuspense);
  1976. };
  1977. sharedContext.deactivate = (vnode) => {
  1978. const instance = vnode.component;
  1979. move(vnode, storageContainer, null, 1 /* LEAVE */, parentSuspense);
  1980. queuePostRenderEffect(() => {
  1981. if (instance.da) {
  1982. shared.invokeArrayFns(instance.da);
  1983. }
  1984. const vnodeHook = vnode.props && vnode.props.onVnodeUnmounted;
  1985. if (vnodeHook) {
  1986. invokeVNodeHook(vnodeHook, instance.parent, vnode);
  1987. }
  1988. instance.isDeactivated = true;
  1989. }, parentSuspense);
  1990. };
  1991. function unmount(vnode) {
  1992. // reset the shapeFlag so it can be properly unmounted
  1993. resetShapeFlag(vnode);
  1994. _unmount(vnode, instance, parentSuspense);
  1995. }
  1996. function pruneCache(filter) {
  1997. cache.forEach((vnode, key) => {
  1998. const name = getComponentName(vnode.type);
  1999. if (name && (!filter || !filter(name))) {
  2000. pruneCacheEntry(key);
  2001. }
  2002. });
  2003. }
  2004. function pruneCacheEntry(key) {
  2005. const cached = cache.get(key);
  2006. if (!current || cached.type !== current.type) {
  2007. unmount(cached);
  2008. }
  2009. else if (current) {
  2010. // current active instance should no longer be kept-alive.
  2011. // we can't unmount it now but it might be later, so reset its flag now.
  2012. resetShapeFlag(current);
  2013. }
  2014. cache.delete(key);
  2015. keys.delete(key);
  2016. }
  2017. // prune cache on include/exclude prop change
  2018. watch(() => [props.include, props.exclude], ([include, exclude]) => {
  2019. include && pruneCache(name => matches(include, name));
  2020. exclude && pruneCache(name => !matches(exclude, name));
  2021. },
  2022. // prune post-render after `current` has been updated
  2023. { flush: 'post', deep: true });
  2024. // cache sub tree after render
  2025. let pendingCacheKey = null;
  2026. const cacheSubtree = () => {
  2027. // fix #1621, the pendingCacheKey could be 0
  2028. if (pendingCacheKey != null) {
  2029. cache.set(pendingCacheKey, getInnerChild(instance.subTree));
  2030. }
  2031. };
  2032. onMounted(cacheSubtree);
  2033. onUpdated(cacheSubtree);
  2034. onBeforeUnmount(() => {
  2035. cache.forEach(cached => {
  2036. const { subTree, suspense } = instance;
  2037. const vnode = getInnerChild(subTree);
  2038. if (cached.type === vnode.type) {
  2039. // current instance will be unmounted as part of keep-alive's unmount
  2040. resetShapeFlag(vnode);
  2041. // but invoke its deactivated hook here
  2042. const da = vnode.component.da;
  2043. da && queuePostRenderEffect(da, suspense);
  2044. return;
  2045. }
  2046. unmount(cached);
  2047. });
  2048. });
  2049. return () => {
  2050. pendingCacheKey = null;
  2051. if (!slots.default) {
  2052. return null;
  2053. }
  2054. const children = slots.default();
  2055. const rawVNode = children[0];
  2056. if (children.length > 1) {
  2057. current = null;
  2058. return children;
  2059. }
  2060. else if (!isVNode(rawVNode) ||
  2061. (!(rawVNode.shapeFlag & 4 /* STATEFUL_COMPONENT */) &&
  2062. !(rawVNode.shapeFlag & 128 /* SUSPENSE */))) {
  2063. current = null;
  2064. return rawVNode;
  2065. }
  2066. let vnode = getInnerChild(rawVNode);
  2067. const comp = vnode.type;
  2068. const name = getComponentName(comp);
  2069. const { include, exclude, max } = props;
  2070. if ((include && (!name || !matches(include, name))) ||
  2071. (exclude && name && matches(exclude, name))) {
  2072. current = vnode;
  2073. return rawVNode;
  2074. }
  2075. const key = vnode.key == null ? comp : vnode.key;
  2076. const cachedVNode = cache.get(key);
  2077. // clone vnode if it's reused because we are going to mutate it
  2078. if (vnode.el) {
  2079. vnode = cloneVNode(vnode);
  2080. if (rawVNode.shapeFlag & 128 /* SUSPENSE */) {
  2081. rawVNode.ssContent = vnode;
  2082. }
  2083. }
  2084. // #1513 it's possible for the returned vnode to be cloned due to attr
  2085. // fallthrough or scopeId, so the vnode here may not be the final vnode
  2086. // that is mounted. Instead of caching it directly, we store the pending
  2087. // key and cache `instance.subTree` (the normalized vnode) in
  2088. // beforeMount/beforeUpdate hooks.
  2089. pendingCacheKey = key;
  2090. if (cachedVNode) {
  2091. // copy over mounted state
  2092. vnode.el = cachedVNode.el;
  2093. vnode.component = cachedVNode.component;
  2094. if (vnode.transition) {
  2095. // recursively update transition hooks on subTree
  2096. setTransitionHooks(vnode, vnode.transition);
  2097. }
  2098. // avoid vnode being mounted as fresh
  2099. vnode.shapeFlag |= 512 /* COMPONENT_KEPT_ALIVE */;
  2100. // make this key the freshest
  2101. keys.delete(key);
  2102. keys.add(key);
  2103. }
  2104. else {
  2105. keys.add(key);
  2106. // prune oldest entry
  2107. if (max && keys.size > parseInt(max, 10)) {
  2108. pruneCacheEntry(keys.values().next().value);
  2109. }
  2110. }
  2111. // avoid vnode being unmounted
  2112. vnode.shapeFlag |= 256 /* COMPONENT_SHOULD_KEEP_ALIVE */;
  2113. current = vnode;
  2114. return rawVNode;
  2115. };
  2116. }
  2117. };
  2118. // export the public type for h/tsx inference
  2119. // also to avoid inline import() in generated d.ts files
  2120. const KeepAlive = KeepAliveImpl;
  2121. function matches(pattern, name) {
  2122. if (shared.isArray(pattern)) {
  2123. return pattern.some((p) => matches(p, name));
  2124. }
  2125. else if (shared.isString(pattern)) {
  2126. return pattern.split(',').indexOf(name) > -1;
  2127. }
  2128. else if (pattern.test) {
  2129. return pattern.test(name);
  2130. }
  2131. /* istanbul ignore next */
  2132. return false;
  2133. }
  2134. function onActivated(hook, target) {
  2135. registerKeepAliveHook(hook, "a" /* ACTIVATED */, target);
  2136. }
  2137. function onDeactivated(hook, target) {
  2138. registerKeepAliveHook(hook, "da" /* DEACTIVATED */, target);
  2139. }
  2140. function registerKeepAliveHook(hook, type, target = currentInstance) {
  2141. // cache the deactivate branch check wrapper for injected hooks so the same
  2142. // hook can be properly deduped by the scheduler. "__wdc" stands for "with
  2143. // deactivation check".
  2144. const wrappedHook = hook.__wdc ||
  2145. (hook.__wdc = () => {
  2146. // only fire the hook if the target instance is NOT in a deactivated branch.
  2147. let current = target;
  2148. while (current) {
  2149. if (current.isDeactivated) {
  2150. return;
  2151. }
  2152. current = current.parent;
  2153. }
  2154. hook();
  2155. });
  2156. injectHook(type, wrappedHook, target);
  2157. // In addition to registering it on the target instance, we walk up the parent
  2158. // chain and register it on all ancestor instances that are keep-alive roots.
  2159. // This avoids the need to walk the entire component tree when invoking these
  2160. // hooks, and more importantly, avoids the need to track child components in
  2161. // arrays.
  2162. if (target) {
  2163. let current = target.parent;
  2164. while (current && current.parent) {
  2165. if (isKeepAlive(current.parent.vnode)) {
  2166. injectToKeepAliveRoot(wrappedHook, type, target, current);
  2167. }
  2168. current = current.parent;
  2169. }
  2170. }
  2171. }
  2172. function injectToKeepAliveRoot(hook, type, target, keepAliveRoot) {
  2173. // injectHook wraps the original for error handling, so make sure to remove
  2174. // the wrapped version.
  2175. const injected = injectHook(type, hook, keepAliveRoot, true /* prepend */);
  2176. onUnmounted(() => {
  2177. shared.remove(keepAliveRoot[type], injected);
  2178. }, target);
  2179. }
  2180. function resetShapeFlag(vnode) {
  2181. let shapeFlag = vnode.shapeFlag;
  2182. if (shapeFlag & 256 /* COMPONENT_SHOULD_KEEP_ALIVE */) {
  2183. shapeFlag -= 256 /* COMPONENT_SHOULD_KEEP_ALIVE */;
  2184. }
  2185. if (shapeFlag & 512 /* COMPONENT_KEPT_ALIVE */) {
  2186. shapeFlag -= 512 /* COMPONENT_KEPT_ALIVE */;
  2187. }
  2188. vnode.shapeFlag = shapeFlag;
  2189. }
  2190. function getInnerChild(vnode) {
  2191. return vnode.shapeFlag & 128 /* SUSPENSE */ ? vnode.ssContent : vnode;
  2192. }
  2193. const isInternalKey = (key) => key[0] === '_' || key === '$stable';
  2194. const normalizeSlotValue = (value) => shared.isArray(value)
  2195. ? value.map(normalizeVNode)
  2196. : [normalizeVNode(value)];
  2197. const normalizeSlot = (key, rawSlot, ctx) => withCtx((props) => {
  2198. return normalizeSlotValue(rawSlot(props));
  2199. }, ctx);
  2200. const normalizeObjectSlots = (rawSlots, slots) => {
  2201. const ctx = rawSlots._ctx;
  2202. for (const key in rawSlots) {
  2203. if (isInternalKey(key))
  2204. continue;
  2205. const value = rawSlots[key];
  2206. if (shared.isFunction(value)) {
  2207. slots[key] = normalizeSlot(key, value, ctx);
  2208. }
  2209. else if (value != null) {
  2210. const normalized = normalizeSlotValue(value);
  2211. slots[key] = () => normalized;
  2212. }
  2213. }
  2214. };
  2215. const normalizeVNodeSlots = (instance, children) => {
  2216. const normalized = normalizeSlotValue(children);
  2217. instance.slots.default = () => normalized;
  2218. };
  2219. const initSlots = (instance, children) => {
  2220. if (instance.vnode.shapeFlag & 32 /* SLOTS_CHILDREN */) {
  2221. const type = children._;
  2222. if (type) {
  2223. instance.slots = children;
  2224. // make compiler marker non-enumerable
  2225. shared.def(children, '_', type);
  2226. }
  2227. else {
  2228. normalizeObjectSlots(children, (instance.slots = {}));
  2229. }
  2230. }
  2231. else {
  2232. instance.slots = {};
  2233. if (children) {
  2234. normalizeVNodeSlots(instance, children);
  2235. }
  2236. }
  2237. shared.def(instance.slots, InternalObjectKey, 1);
  2238. };
  2239. const updateSlots = (instance, children) => {
  2240. const { vnode, slots } = instance;
  2241. let needDeletionCheck = true;
  2242. let deletionComparisonTarget = shared.EMPTY_OBJ;
  2243. if (vnode.shapeFlag & 32 /* SLOTS_CHILDREN */) {
  2244. const type = children._;
  2245. if (type) {
  2246. // compiled slots.
  2247. if (type === 1 /* STABLE */) {
  2248. // compiled AND stable.
  2249. // no need to update, and skip stale slots removal.
  2250. needDeletionCheck = false;
  2251. }
  2252. else {
  2253. // compiled but dynamic (v-if/v-for on slots) - update slots, but skip
  2254. // normalization.
  2255. shared.extend(slots, children);
  2256. }
  2257. }
  2258. else {
  2259. needDeletionCheck = !children.$stable;
  2260. normalizeObjectSlots(children, slots);
  2261. }
  2262. deletionComparisonTarget = children;
  2263. }
  2264. else if (children) {
  2265. // non slot object children (direct value) passed to a component
  2266. normalizeVNodeSlots(instance, children);
  2267. deletionComparisonTarget = { default: 1 };
  2268. }
  2269. // delete stale slots
  2270. if (needDeletionCheck) {
  2271. for (const key in slots) {
  2272. if (!isInternalKey(key) && !(key in deletionComparisonTarget)) {
  2273. delete slots[key];
  2274. }
  2275. }
  2276. }
  2277. };
  2278. /**
  2279. Runtime helper for applying directives to a vnode. Example usage:
  2280. const comp = resolveComponent('comp')
  2281. const foo = resolveDirective('foo')
  2282. const bar = resolveDirective('bar')
  2283. return withDirectives(h(comp), [
  2284. [foo, this.x],
  2285. [bar, this.y]
  2286. ])
  2287. */
  2288. /**
  2289. * Adds directives to a VNode.
  2290. */
  2291. function withDirectives(vnode, directives) {
  2292. const internalInstance = currentRenderingInstance;
  2293. if (internalInstance === null) {
  2294. return vnode;
  2295. }
  2296. const instance = internalInstance.proxy;
  2297. const bindings = vnode.dirs || (vnode.dirs = []);
  2298. for (let i = 0; i < directives.length; i++) {
  2299. let [dir, value, arg, modifiers = shared.EMPTY_OBJ] = directives[i];
  2300. if (shared.isFunction(dir)) {
  2301. dir = {
  2302. mounted: dir,
  2303. updated: dir
  2304. };
  2305. }
  2306. bindings.push({
  2307. dir,
  2308. instance,
  2309. value,
  2310. oldValue: void 0,
  2311. arg,
  2312. modifiers
  2313. });
  2314. }
  2315. return vnode;
  2316. }
  2317. function invokeDirectiveHook(vnode, prevVNode, instance, name) {
  2318. const bindings = vnode.dirs;
  2319. const oldBindings = prevVNode && prevVNode.dirs;
  2320. for (let i = 0; i < bindings.length; i++) {
  2321. const binding = bindings[i];
  2322. if (oldBindings) {
  2323. binding.oldValue = oldBindings[i].value;
  2324. }
  2325. const hook = binding.dir[name];
  2326. if (hook) {
  2327. callWithAsyncErrorHandling(hook, instance, 8 /* DIRECTIVE_HOOK */, [
  2328. vnode.el,
  2329. binding,
  2330. vnode,
  2331. prevVNode
  2332. ]);
  2333. }
  2334. }
  2335. }
  2336. function createAppContext() {
  2337. return {
  2338. app: null,
  2339. config: {
  2340. isNativeTag: shared.NO,
  2341. performance: false,
  2342. globalProperties: {},
  2343. optionMergeStrategies: {},
  2344. isCustomElement: shared.NO,
  2345. errorHandler: undefined,
  2346. warnHandler: undefined
  2347. },
  2348. mixins: [],
  2349. components: {},
  2350. directives: {},
  2351. provides: Object.create(null)
  2352. };
  2353. }
  2354. let uid = 0;
  2355. function createAppAPI(render, hydrate) {
  2356. return function createApp(rootComponent, rootProps = null) {
  2357. if (rootProps != null && !shared.isObject(rootProps)) {
  2358. rootProps = null;
  2359. }
  2360. const context = createAppContext();
  2361. const installedPlugins = new Set();
  2362. let isMounted = false;
  2363. const app = (context.app = {
  2364. _uid: uid++,
  2365. _component: rootComponent,
  2366. _props: rootProps,
  2367. _container: null,
  2368. _context: context,
  2369. version,
  2370. get config() {
  2371. return context.config;
  2372. },
  2373. set config(v) {
  2374. },
  2375. use(plugin, ...options) {
  2376. if (installedPlugins.has(plugin)) ;
  2377. else if (plugin && shared.isFunction(plugin.install)) {
  2378. installedPlugins.add(plugin);
  2379. plugin.install(app, ...options);
  2380. }
  2381. else if (shared.isFunction(plugin)) {
  2382. installedPlugins.add(plugin);
  2383. plugin(app, ...options);
  2384. }
  2385. else ;
  2386. return app;
  2387. },
  2388. mixin(mixin) {
  2389. {
  2390. if (!context.mixins.includes(mixin)) {
  2391. context.mixins.push(mixin);
  2392. // global mixin with props/emits de-optimizes props/emits
  2393. // normalization caching.
  2394. if (mixin.props || mixin.emits) {
  2395. context.deopt = true;
  2396. }
  2397. }
  2398. }
  2399. return app;
  2400. },
  2401. component(name, component) {
  2402. if (!component) {
  2403. return context.components[name];
  2404. }
  2405. context.components[name] = component;
  2406. return app;
  2407. },
  2408. directive(name, directive) {
  2409. if (!directive) {
  2410. return context.directives[name];
  2411. }
  2412. context.directives[name] = directive;
  2413. return app;
  2414. },
  2415. mount(rootContainer, isHydrate) {
  2416. if (!isMounted) {
  2417. const vnode = createVNode(rootComponent, rootProps);
  2418. // store app context on the root VNode.
  2419. // this will be set on the root instance on initial mount.
  2420. vnode.appContext = context;
  2421. if (isHydrate && hydrate) {
  2422. hydrate(vnode, rootContainer);
  2423. }
  2424. else {
  2425. render(vnode, rootContainer);
  2426. }
  2427. isMounted = true;
  2428. app._container = rootContainer;
  2429. rootContainer.__vue_app__ = app;
  2430. return vnode.component.proxy;
  2431. }
  2432. },
  2433. unmount() {
  2434. if (isMounted) {
  2435. render(null, app._container);
  2436. delete app._container.__vue_app__;
  2437. }
  2438. },
  2439. provide(key, value) {
  2440. // TypeScript doesn't allow symbols as index type
  2441. // https://github.com/Microsoft/TypeScript/issues/24587
  2442. context.provides[key] = value;
  2443. return app;
  2444. }
  2445. });
  2446. return app;
  2447. };
  2448. }
  2449. let hasMismatch = false;
  2450. const isSVGContainer = (container) => /svg/.test(container.namespaceURI) && container.tagName !== 'foreignObject';
  2451. const isComment = (node) => node.nodeType === 8 /* COMMENT */;
  2452. // Note: hydration is DOM-specific
  2453. // But we have to place it in core due to tight coupling with core - splitting
  2454. // it out creates a ton of unnecessary complexity.
  2455. // Hydration also depends on some renderer internal logic which needs to be
  2456. // passed in via arguments.
  2457. function createHydrationFunctions(rendererInternals) {
  2458. const { mt: mountComponent, p: patch, o: { patchProp, nextSibling, parentNode, remove, insert, createComment } } = rendererInternals;
  2459. const hydrate = (vnode, container) => {
  2460. hasMismatch = false;
  2461. hydrateNode(container.firstChild, vnode, null, null);
  2462. flushPostFlushCbs();
  2463. if (hasMismatch && !false) {
  2464. // this error should show up in production
  2465. console.error(`Hydration completed but contains mismatches.`);
  2466. }
  2467. };
  2468. const hydrateNode = (node, vnode, parentComponent, parentSuspense, optimized = false) => {
  2469. const isFragmentStart = isComment(node) && node.data === '[';
  2470. const onMismatch = () => handleMismatch(node, vnode, parentComponent, parentSuspense, isFragmentStart);
  2471. const { type, ref, shapeFlag } = vnode;
  2472. const domType = node.nodeType;
  2473. vnode.el = node;
  2474. let nextNode = null;
  2475. switch (type) {
  2476. case Text:
  2477. if (domType !== 3 /* TEXT */) {
  2478. nextNode = onMismatch();
  2479. }
  2480. else {
  2481. if (node.data !== vnode.children) {
  2482. hasMismatch = true;
  2483. node.data = vnode.children;
  2484. }
  2485. nextNode = nextSibling(node);
  2486. }
  2487. break;
  2488. case Comment:
  2489. if (domType !== 8 /* COMMENT */ || isFragmentStart) {
  2490. nextNode = onMismatch();
  2491. }
  2492. else {
  2493. nextNode = nextSibling(node);
  2494. }
  2495. break;
  2496. case Static:
  2497. if (domType !== 1 /* ELEMENT */) {
  2498. nextNode = onMismatch();
  2499. }
  2500. else {
  2501. // determine anchor, adopt content
  2502. nextNode = node;
  2503. // if the static vnode has its content stripped during build,
  2504. // adopt it from the server-rendered HTML.
  2505. const needToAdoptContent = !vnode.children.length;
  2506. for (let i = 0; i < vnode.staticCount; i++) {
  2507. if (needToAdoptContent)
  2508. vnode.children += nextNode.outerHTML;
  2509. if (i === vnode.staticCount - 1) {
  2510. vnode.anchor = nextNode;
  2511. }
  2512. nextNode = nextSibling(nextNode);
  2513. }
  2514. return nextNode;
  2515. }
  2516. break;
  2517. case Fragment:
  2518. if (!isFragmentStart) {
  2519. nextNode = onMismatch();
  2520. }
  2521. else {
  2522. nextNode = hydrateFragment(node, vnode, parentComponent, parentSuspense, optimized);
  2523. }
  2524. break;
  2525. default:
  2526. if (shapeFlag & 1 /* ELEMENT */) {
  2527. if (domType !== 1 /* ELEMENT */ ||
  2528. vnode.type !== node.tagName.toLowerCase()) {
  2529. nextNode = onMismatch();
  2530. }
  2531. else {
  2532. nextNode = hydrateElement(node, vnode, parentComponent, parentSuspense, optimized);
  2533. }
  2534. }
  2535. else if (shapeFlag & 6 /* COMPONENT */) {
  2536. // when setting up the render effect, if the initial vnode already
  2537. // has .el set, the component will perform hydration instead of mount
  2538. // on its sub-tree.
  2539. const container = parentNode(node);
  2540. const hydrateComponent = () => {
  2541. mountComponent(vnode, container, null, parentComponent, parentSuspense, isSVGContainer(container), optimized);
  2542. };
  2543. // async component
  2544. const loadAsync = vnode.type.__asyncLoader;
  2545. if (loadAsync) {
  2546. loadAsync().then(hydrateComponent);
  2547. }
  2548. else {
  2549. hydrateComponent();
  2550. }
  2551. // component may be async, so in the case of fragments we cannot rely
  2552. // on component's rendered output to determine the end of the fragment
  2553. // instead, we do a lookahead to find the end anchor node.
  2554. nextNode = isFragmentStart
  2555. ? locateClosingAsyncAnchor(node)
  2556. : nextSibling(node);
  2557. }
  2558. else if (shapeFlag & 64 /* TELEPORT */) {
  2559. if (domType !== 8 /* COMMENT */) {
  2560. nextNode = onMismatch();
  2561. }
  2562. else {
  2563. nextNode = vnode.type.hydrate(node, vnode, parentComponent, parentSuspense, optimized, rendererInternals, hydrateChildren);
  2564. }
  2565. }
  2566. else if (shapeFlag & 128 /* SUSPENSE */) {
  2567. nextNode = vnode.type.hydrate(node, vnode, parentComponent, parentSuspense, isSVGContainer(parentNode(node)), optimized, rendererInternals, hydrateNode);
  2568. }
  2569. else ;
  2570. }
  2571. if (ref != null) {
  2572. setRef(ref, null, parentSuspense, vnode);
  2573. }
  2574. return nextNode;
  2575. };
  2576. const hydrateElement = (el, vnode, parentComponent, parentSuspense, optimized) => {
  2577. optimized = optimized || !!vnode.dynamicChildren;
  2578. const { props, patchFlag, shapeFlag, dirs } = vnode;
  2579. // skip props & children if this is hoisted static nodes
  2580. if (patchFlag !== -1 /* HOISTED */) {
  2581. if (dirs) {
  2582. invokeDirectiveHook(vnode, null, parentComponent, 'created');
  2583. }
  2584. // props
  2585. if (props) {
  2586. if (!optimized ||
  2587. (patchFlag & 16 /* FULL_PROPS */ ||
  2588. patchFlag & 32 /* HYDRATE_EVENTS */)) {
  2589. for (const key in props) {
  2590. if (!shared.isReservedProp(key) && shared.isOn(key)) {
  2591. patchProp(el, key, null, props[key]);
  2592. }
  2593. }
  2594. }
  2595. else if (props.onClick) {
  2596. // Fast path for click listeners (which is most often) to avoid
  2597. // iterating through props.
  2598. patchProp(el, 'onClick', null, props.onClick);
  2599. }
  2600. }
  2601. // vnode / directive hooks
  2602. let vnodeHooks;
  2603. if ((vnodeHooks = props && props.onVnodeBeforeMount)) {
  2604. invokeVNodeHook(vnodeHooks, parentComponent, vnode);
  2605. }
  2606. if (dirs) {
  2607. invokeDirectiveHook(vnode, null, parentComponent, 'beforeMount');
  2608. }
  2609. if ((vnodeHooks = props && props.onVnodeMounted) || dirs) {
  2610. queueEffectWithSuspense(() => {
  2611. vnodeHooks && invokeVNodeHook(vnodeHooks, parentComponent, vnode);
  2612. dirs && invokeDirectiveHook(vnode, null, parentComponent, 'mounted');
  2613. }, parentSuspense);
  2614. }
  2615. // children
  2616. if (shapeFlag & 16 /* ARRAY_CHILDREN */ &&
  2617. // skip if element has innerHTML / textContent
  2618. !(props && (props.innerHTML || props.textContent))) {
  2619. let next = hydrateChildren(el.firstChild, vnode, el, parentComponent, parentSuspense, optimized);
  2620. while (next) {
  2621. hasMismatch = true;
  2622. // The SSRed DOM contains more nodes than it should. Remove them.
  2623. const cur = next;
  2624. next = next.nextSibling;
  2625. remove(cur);
  2626. }
  2627. }
  2628. else if (shapeFlag & 8 /* TEXT_CHILDREN */) {
  2629. if (el.textContent !== vnode.children) {
  2630. hasMismatch = true;
  2631. el.textContent = vnode.children;
  2632. }
  2633. }
  2634. }
  2635. return el.nextSibling;
  2636. };
  2637. const hydrateChildren = (node, parentVNode, container, parentComponent, parentSuspense, optimized) => {
  2638. optimized = optimized || !!parentVNode.dynamicChildren;
  2639. const children = parentVNode.children;
  2640. const l = children.length;
  2641. for (let i = 0; i < l; i++) {
  2642. const vnode = optimized
  2643. ? children[i]
  2644. : (children[i] = normalizeVNode(children[i]));
  2645. if (node) {
  2646. node = hydrateNode(node, vnode, parentComponent, parentSuspense, optimized);
  2647. }
  2648. else {
  2649. hasMismatch = true;
  2650. // the SSRed DOM didn't contain enough nodes. Mount the missing ones.
  2651. patch(null, vnode, container, null, parentComponent, parentSuspense, isSVGContainer(container));
  2652. }
  2653. }
  2654. return node;
  2655. };
  2656. const hydrateFragment = (node, vnode, parentComponent, parentSuspense, optimized) => {
  2657. const container = parentNode(node);
  2658. const next = hydrateChildren(nextSibling(node), vnode, container, parentComponent, parentSuspense, optimized);
  2659. if (next && isComment(next) && next.data === ']') {
  2660. return nextSibling((vnode.anchor = next));
  2661. }
  2662. else {
  2663. // fragment didn't hydrate successfully, since we didn't get a end anchor
  2664. // back. This should have led to node/children mismatch warnings.
  2665. hasMismatch = true;
  2666. // since the anchor is missing, we need to create one and insert it
  2667. insert((vnode.anchor = createComment(`]`)), container, next);
  2668. return next;
  2669. }
  2670. };
  2671. const handleMismatch = (node, vnode, parentComponent, parentSuspense, isFragment) => {
  2672. hasMismatch = true;
  2673. vnode.el = null;
  2674. if (isFragment) {
  2675. // remove excessive fragment nodes
  2676. const end = locateClosingAsyncAnchor(node);
  2677. while (true) {
  2678. const next = nextSibling(node);
  2679. if (next && next !== end) {
  2680. remove(next);
  2681. }
  2682. else {
  2683. break;
  2684. }
  2685. }
  2686. }
  2687. const next = nextSibling(node);
  2688. const container = parentNode(node);
  2689. remove(node);
  2690. patch(null, vnode, container, next, parentComponent, parentSuspense, isSVGContainer(container));
  2691. return next;
  2692. };
  2693. const locateClosingAsyncAnchor = (node) => {
  2694. let match = 0;
  2695. while (node) {
  2696. node = nextSibling(node);
  2697. if (node && isComment(node)) {
  2698. if (node.data === '[')
  2699. match++;
  2700. if (node.data === ']') {
  2701. if (match === 0) {
  2702. return nextSibling(node);
  2703. }
  2704. else {
  2705. match--;
  2706. }
  2707. }
  2708. }
  2709. }
  2710. return node;
  2711. };
  2712. return [hydrate, hydrateNode];
  2713. }
  2714. // implementation, close to no-op
  2715. function defineComponent(options) {
  2716. return shared.isFunction(options) ? { setup: options, name: options.name } : options;
  2717. }
  2718. const isAsyncWrapper = (i) => !!i.type.__asyncLoader;
  2719. function defineAsyncComponent(source) {
  2720. if (shared.isFunction(source)) {
  2721. source = { loader: source };
  2722. }
  2723. const { loader, loadingComponent, errorComponent, delay = 200, timeout, // undefined = never times out
  2724. suspensible = true, onError: userOnError } = source;
  2725. let pendingRequest = null;
  2726. let resolvedComp;
  2727. let retries = 0;
  2728. const retry = () => {
  2729. retries++;
  2730. pendingRequest = null;
  2731. return load();
  2732. };
  2733. const load = () => {
  2734. let thisRequest;
  2735. return (pendingRequest ||
  2736. (thisRequest = pendingRequest = loader()
  2737. .catch(err => {
  2738. err = err instanceof Error ? err : new Error(String(err));
  2739. if (userOnError) {
  2740. return new Promise((resolve, reject) => {
  2741. const userRetry = () => resolve(retry());
  2742. const userFail = () => reject(err);
  2743. userOnError(err, userRetry, userFail, retries + 1);
  2744. });
  2745. }
  2746. else {
  2747. throw err;
  2748. }
  2749. })
  2750. .then((comp) => {
  2751. if (thisRequest !== pendingRequest && pendingRequest) {
  2752. return pendingRequest;
  2753. }
  2754. // interop module default
  2755. if (comp &&
  2756. (comp.__esModule || comp[Symbol.toStringTag] === 'Module')) {
  2757. comp = comp.default;
  2758. }
  2759. resolvedComp = comp;
  2760. return comp;
  2761. })));
  2762. };
  2763. return defineComponent({
  2764. __asyncLoader: load,
  2765. name: 'AsyncComponentWrapper',
  2766. setup() {
  2767. const instance = currentInstance;
  2768. // already resolved
  2769. if (resolvedComp) {
  2770. return () => createInnerComp(resolvedComp, instance);
  2771. }
  2772. const onError = (err) => {
  2773. pendingRequest = null;
  2774. handleError(err, instance, 13 /* ASYNC_COMPONENT_LOADER */, !errorComponent /* do not throw in dev if user provided error component */);
  2775. };
  2776. // suspense-controlled or SSR.
  2777. if ((suspensible && instance.suspense) ||
  2778. (isInSSRComponentSetup)) {
  2779. return load()
  2780. .then(comp => {
  2781. return () => createInnerComp(comp, instance);
  2782. })
  2783. .catch(err => {
  2784. onError(err);
  2785. return () => errorComponent
  2786. ? createVNode(errorComponent, {
  2787. error: err
  2788. })
  2789. : null;
  2790. });
  2791. }
  2792. const loaded = reactivity.ref(false);
  2793. const error = reactivity.ref();
  2794. const delayed = reactivity.ref(!!delay);
  2795. if (delay) {
  2796. setTimeout(() => {
  2797. delayed.value = false;
  2798. }, delay);
  2799. }
  2800. if (timeout != null) {
  2801. setTimeout(() => {
  2802. if (!loaded.value && !error.value) {
  2803. const err = new Error(`Async component timed out after ${timeout}ms.`);
  2804. onError(err);
  2805. error.value = err;
  2806. }
  2807. }, timeout);
  2808. }
  2809. load()
  2810. .then(() => {
  2811. loaded.value = true;
  2812. })
  2813. .catch(err => {
  2814. onError(err);
  2815. error.value = err;
  2816. });
  2817. return () => {
  2818. if (loaded.value && resolvedComp) {
  2819. return createInnerComp(resolvedComp, instance);
  2820. }
  2821. else if (error.value && errorComponent) {
  2822. return createVNode(errorComponent, {
  2823. error: error.value
  2824. });
  2825. }
  2826. else if (loadingComponent && !delayed.value) {
  2827. return createVNode(loadingComponent);
  2828. }
  2829. };
  2830. }
  2831. });
  2832. }
  2833. function createInnerComp(comp, { vnode: { ref, props, children } }) {
  2834. const vnode = createVNode(comp, props, children);
  2835. // ensure inner component inherits the async wrapper's ref owner
  2836. vnode.ref = ref;
  2837. return vnode;
  2838. }
  2839. const prodEffectOptions = {
  2840. scheduler: queueJob,
  2841. // #1801, #2043 component render effects should allow recursive updates
  2842. allowRecurse: true
  2843. };
  2844. const queuePostRenderEffect = queueEffectWithSuspense
  2845. ;
  2846. const setRef = (rawRef, oldRawRef, parentSuspense, vnode) => {
  2847. if (shared.isArray(rawRef)) {
  2848. rawRef.forEach((r, i) => setRef(r, oldRawRef && (shared.isArray(oldRawRef) ? oldRawRef[i] : oldRawRef), parentSuspense, vnode));
  2849. return;
  2850. }
  2851. let value;
  2852. if (!vnode || isAsyncWrapper(vnode)) {
  2853. value = null;
  2854. }
  2855. else {
  2856. if (vnode.shapeFlag & 4 /* STATEFUL_COMPONENT */) {
  2857. value = vnode.component.exposed || vnode.component.proxy;
  2858. }
  2859. else {
  2860. value = vnode.el;
  2861. }
  2862. }
  2863. const { i: owner, r: ref } = rawRef;
  2864. const oldRef = oldRawRef && oldRawRef.r;
  2865. const refs = owner.refs === shared.EMPTY_OBJ ? (owner.refs = {}) : owner.refs;
  2866. const setupState = owner.setupState;
  2867. // unset old ref
  2868. if (oldRef != null && oldRef !== ref) {
  2869. if (shared.isString(oldRef)) {
  2870. refs[oldRef] = null;
  2871. if (shared.hasOwn(setupState, oldRef)) {
  2872. setupState[oldRef] = null;
  2873. }
  2874. }
  2875. else if (reactivity.isRef(oldRef)) {
  2876. oldRef.value = null;
  2877. }
  2878. }
  2879. if (shared.isString(ref)) {
  2880. const doSet = () => {
  2881. refs[ref] = value;
  2882. if (shared.hasOwn(setupState, ref)) {
  2883. setupState[ref] = value;
  2884. }
  2885. };
  2886. // #1789: for non-null values, set them after render
  2887. // null values means this is unmount and it should not overwrite another
  2888. // ref with the same key
  2889. if (value) {
  2890. doSet.id = -1;
  2891. queuePostRenderEffect(doSet, parentSuspense);
  2892. }
  2893. else {
  2894. doSet();
  2895. }
  2896. }
  2897. else if (reactivity.isRef(ref)) {
  2898. const doSet = () => {
  2899. ref.value = value;
  2900. };
  2901. if (value) {
  2902. doSet.id = -1;
  2903. queuePostRenderEffect(doSet, parentSuspense);
  2904. }
  2905. else {
  2906. doSet();
  2907. }
  2908. }
  2909. else if (shared.isFunction(ref)) {
  2910. callWithErrorHandling(ref, owner, 12 /* FUNCTION_REF */, [value, refs]);
  2911. }
  2912. else ;
  2913. };
  2914. /**
  2915. * The createRenderer function accepts two generic arguments:
  2916. * HostNode and HostElement, corresponding to Node and Element types in the
  2917. * host environment. For example, for runtime-dom, HostNode would be the DOM
  2918. * `Node` interface and HostElement would be the DOM `Element` interface.
  2919. *
  2920. * Custom renderers can pass in the platform specific types like this:
  2921. *
  2922. * ``` js
  2923. * const { render, createApp } = createRenderer<Node, Element>({
  2924. * patchProp,
  2925. * ...nodeOps
  2926. * })
  2927. * ```
  2928. */
  2929. function createRenderer(options) {
  2930. return baseCreateRenderer(options);
  2931. }
  2932. // Separate API for creating hydration-enabled renderer.
  2933. // Hydration logic is only used when calling this function, making it
  2934. // tree-shakable.
  2935. function createHydrationRenderer(options) {
  2936. return baseCreateRenderer(options, createHydrationFunctions);
  2937. }
  2938. // implementation
  2939. function baseCreateRenderer(options, createHydrationFns) {
  2940. const { insert: hostInsert, remove: hostRemove, patchProp: hostPatchProp, forcePatchProp: hostForcePatchProp, createElement: hostCreateElement, createText: hostCreateText, createComment: hostCreateComment, setText: hostSetText, setElementText: hostSetElementText, parentNode: hostParentNode, nextSibling: hostNextSibling, setScopeId: hostSetScopeId = shared.NOOP, cloneNode: hostCloneNode, insertStaticContent: hostInsertStaticContent } = options;
  2941. // Note: functions inside this closure should use `const xxx = () => {}`
  2942. // style in order to prevent being inlined by minifiers.
  2943. const patch = (n1, n2, container, anchor = null, parentComponent = null, parentSuspense = null, isSVG = false, optimized = false) => {
  2944. // patching & not same type, unmount old tree
  2945. if (n1 && !isSameVNodeType(n1, n2)) {
  2946. anchor = getNextHostNode(n1);
  2947. unmount(n1, parentComponent, parentSuspense, true);
  2948. n1 = null;
  2949. }
  2950. if (n2.patchFlag === -2 /* BAIL */) {
  2951. optimized = false;
  2952. n2.dynamicChildren = null;
  2953. }
  2954. const { type, ref, shapeFlag } = n2;
  2955. switch (type) {
  2956. case Text:
  2957. processText(n1, n2, container, anchor);
  2958. break;
  2959. case Comment:
  2960. processCommentNode(n1, n2, container, anchor);
  2961. break;
  2962. case Static:
  2963. if (n1 == null) {
  2964. mountStaticNode(n2, container, anchor, isSVG);
  2965. }
  2966. break;
  2967. case Fragment:
  2968. processFragment(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  2969. break;
  2970. default:
  2971. if (shapeFlag & 1 /* ELEMENT */) {
  2972. processElement(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  2973. }
  2974. else if (shapeFlag & 6 /* COMPONENT */) {
  2975. processComponent(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  2976. }
  2977. else if (shapeFlag & 64 /* TELEPORT */) {
  2978. type.process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized, internals);
  2979. }
  2980. else if (shapeFlag & 128 /* SUSPENSE */) {
  2981. type.process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized, internals);
  2982. }
  2983. else ;
  2984. }
  2985. // set ref
  2986. if (ref != null && parentComponent) {
  2987. setRef(ref, n1 && n1.ref, parentSuspense, n2);
  2988. }
  2989. };
  2990. const processText = (n1, n2, container, anchor) => {
  2991. if (n1 == null) {
  2992. hostInsert((n2.el = hostCreateText(n2.children)), container, anchor);
  2993. }
  2994. else {
  2995. const el = (n2.el = n1.el);
  2996. if (n2.children !== n1.children) {
  2997. hostSetText(el, n2.children);
  2998. }
  2999. }
  3000. };
  3001. const processCommentNode = (n1, n2, container, anchor) => {
  3002. if (n1 == null) {
  3003. hostInsert((n2.el = hostCreateComment(n2.children || '')), container, anchor);
  3004. }
  3005. else {
  3006. // there's no support for dynamic comments
  3007. n2.el = n1.el;
  3008. }
  3009. };
  3010. const mountStaticNode = (n2, container, anchor, isSVG) => {
  3011. [n2.el, n2.anchor] = hostInsertStaticContent(n2.children, container, anchor, isSVG);
  3012. };
  3013. const moveStaticNode = ({ el, anchor }, container, nextSibling) => {
  3014. let next;
  3015. while (el && el !== anchor) {
  3016. next = hostNextSibling(el);
  3017. hostInsert(el, container, nextSibling);
  3018. el = next;
  3019. }
  3020. hostInsert(anchor, container, nextSibling);
  3021. };
  3022. const removeStaticNode = ({ el, anchor }) => {
  3023. let next;
  3024. while (el && el !== anchor) {
  3025. next = hostNextSibling(el);
  3026. hostRemove(el);
  3027. el = next;
  3028. }
  3029. hostRemove(anchor);
  3030. };
  3031. const processElement = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized) => {
  3032. isSVG = isSVG || n2.type === 'svg';
  3033. if (n1 == null) {
  3034. mountElement(n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  3035. }
  3036. else {
  3037. patchElement(n1, n2, parentComponent, parentSuspense, isSVG, optimized);
  3038. }
  3039. };
  3040. const mountElement = (vnode, container, anchor, parentComponent, parentSuspense, isSVG, optimized) => {
  3041. let el;
  3042. let vnodeHook;
  3043. const { type, props, shapeFlag, transition, scopeId, patchFlag, dirs } = vnode;
  3044. if (vnode.el &&
  3045. hostCloneNode !== undefined &&
  3046. patchFlag === -1 /* HOISTED */) {
  3047. // If a vnode has non-null el, it means it's being reused.
  3048. // Only static vnodes can be reused, so its mounted DOM nodes should be
  3049. // exactly the same, and we can simply do a clone here.
  3050. // only do this in production since cloned trees cannot be HMR updated.
  3051. el = vnode.el = hostCloneNode(vnode.el);
  3052. }
  3053. else {
  3054. el = vnode.el = hostCreateElement(vnode.type, isSVG, props && props.is);
  3055. // mount children first, since some props may rely on child content
  3056. // being already rendered, e.g. `<select value>`
  3057. if (shapeFlag & 8 /* TEXT_CHILDREN */) {
  3058. hostSetElementText(el, vnode.children);
  3059. }
  3060. else if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  3061. mountChildren(vnode.children, el, null, parentComponent, parentSuspense, isSVG && type !== 'foreignObject', optimized || !!vnode.dynamicChildren);
  3062. }
  3063. if (dirs) {
  3064. invokeDirectiveHook(vnode, null, parentComponent, 'created');
  3065. }
  3066. // props
  3067. if (props) {
  3068. for (const key in props) {
  3069. if (!shared.isReservedProp(key)) {
  3070. hostPatchProp(el, key, null, props[key], isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  3071. }
  3072. }
  3073. if ((vnodeHook = props.onVnodeBeforeMount)) {
  3074. invokeVNodeHook(vnodeHook, parentComponent, vnode);
  3075. }
  3076. }
  3077. // scopeId
  3078. setScopeId(el, scopeId, vnode, parentComponent);
  3079. }
  3080. if (dirs) {
  3081. invokeDirectiveHook(vnode, null, parentComponent, 'beforeMount');
  3082. }
  3083. // #1583 For inside suspense + suspense not resolved case, enter hook should call when suspense resolved
  3084. // #1689 For inside suspense + suspense resolved case, just call it
  3085. const needCallTransitionHooks = (!parentSuspense || (parentSuspense && !parentSuspense.pendingBranch)) &&
  3086. transition &&
  3087. !transition.persisted;
  3088. if (needCallTransitionHooks) {
  3089. transition.beforeEnter(el);
  3090. }
  3091. hostInsert(el, container, anchor);
  3092. if ((vnodeHook = props && props.onVnodeMounted) ||
  3093. needCallTransitionHooks ||
  3094. dirs) {
  3095. queuePostRenderEffect(() => {
  3096. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, vnode);
  3097. needCallTransitionHooks && transition.enter(el);
  3098. dirs && invokeDirectiveHook(vnode, null, parentComponent, 'mounted');
  3099. }, parentSuspense);
  3100. }
  3101. };
  3102. const setScopeId = (el, scopeId, vnode, parentComponent) => {
  3103. if (scopeId) {
  3104. hostSetScopeId(el, scopeId);
  3105. }
  3106. if (parentComponent) {
  3107. const treeOwnerId = parentComponent.type.__scopeId;
  3108. // vnode's own scopeId and the current patched component's scopeId is
  3109. // different - this is a slot content node.
  3110. if (treeOwnerId && treeOwnerId !== scopeId) {
  3111. hostSetScopeId(el, treeOwnerId + '-s');
  3112. }
  3113. let subTree = parentComponent.subTree;
  3114. if (vnode === subTree) {
  3115. setScopeId(el, parentComponent.vnode.scopeId, parentComponent.vnode, parentComponent.parent);
  3116. }
  3117. }
  3118. };
  3119. const mountChildren = (children, container, anchor, parentComponent, parentSuspense, isSVG, optimized, start = 0) => {
  3120. for (let i = start; i < children.length; i++) {
  3121. const child = (children[i] = optimized
  3122. ? cloneIfMounted(children[i])
  3123. : normalizeVNode(children[i]));
  3124. patch(null, child, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  3125. }
  3126. };
  3127. const patchElement = (n1, n2, parentComponent, parentSuspense, isSVG, optimized) => {
  3128. const el = (n2.el = n1.el);
  3129. let { patchFlag, dynamicChildren, dirs } = n2;
  3130. // #1426 take the old vnode's patch flag into account since user may clone a
  3131. // compiler-generated vnode, which de-opts to FULL_PROPS
  3132. patchFlag |= n1.patchFlag & 16 /* FULL_PROPS */;
  3133. const oldProps = n1.props || shared.EMPTY_OBJ;
  3134. const newProps = n2.props || shared.EMPTY_OBJ;
  3135. let vnodeHook;
  3136. if ((vnodeHook = newProps.onVnodeBeforeUpdate)) {
  3137. invokeVNodeHook(vnodeHook, parentComponent, n2, n1);
  3138. }
  3139. if (dirs) {
  3140. invokeDirectiveHook(n2, n1, parentComponent, 'beforeUpdate');
  3141. }
  3142. if (patchFlag > 0) {
  3143. // the presence of a patchFlag means this element's render code was
  3144. // generated by the compiler and can take the fast path.
  3145. // in this path old node and new node are guaranteed to have the same shape
  3146. // (i.e. at the exact same position in the source template)
  3147. if (patchFlag & 16 /* FULL_PROPS */) {
  3148. // element props contain dynamic keys, full diff needed
  3149. patchProps(el, n2, oldProps, newProps, parentComponent, parentSuspense, isSVG);
  3150. }
  3151. else {
  3152. // class
  3153. // this flag is matched when the element has dynamic class bindings.
  3154. if (patchFlag & 2 /* CLASS */) {
  3155. if (oldProps.class !== newProps.class) {
  3156. hostPatchProp(el, 'class', null, newProps.class, isSVG);
  3157. }
  3158. }
  3159. // style
  3160. // this flag is matched when the element has dynamic style bindings
  3161. if (patchFlag & 4 /* STYLE */) {
  3162. hostPatchProp(el, 'style', oldProps.style, newProps.style, isSVG);
  3163. }
  3164. // props
  3165. // This flag is matched when the element has dynamic prop/attr bindings
  3166. // other than class and style. The keys of dynamic prop/attrs are saved for
  3167. // faster iteration.
  3168. // Note dynamic keys like :[foo]="bar" will cause this optimization to
  3169. // bail out and go through a full diff because we need to unset the old key
  3170. if (patchFlag & 8 /* PROPS */) {
  3171. // if the flag is present then dynamicProps must be non-null
  3172. const propsToUpdate = n2.dynamicProps;
  3173. for (let i = 0; i < propsToUpdate.length; i++) {
  3174. const key = propsToUpdate[i];
  3175. const prev = oldProps[key];
  3176. const next = newProps[key];
  3177. if (next !== prev ||
  3178. (hostForcePatchProp && hostForcePatchProp(el, key))) {
  3179. hostPatchProp(el, key, prev, next, isSVG, n1.children, parentComponent, parentSuspense, unmountChildren);
  3180. }
  3181. }
  3182. }
  3183. }
  3184. // text
  3185. // This flag is matched when the element has only dynamic text children.
  3186. if (patchFlag & 1 /* TEXT */) {
  3187. if (n1.children !== n2.children) {
  3188. hostSetElementText(el, n2.children);
  3189. }
  3190. }
  3191. }
  3192. else if (!optimized && dynamicChildren == null) {
  3193. // unoptimized, full diff
  3194. patchProps(el, n2, oldProps, newProps, parentComponent, parentSuspense, isSVG);
  3195. }
  3196. const areChildrenSVG = isSVG && n2.type !== 'foreignObject';
  3197. if (dynamicChildren) {
  3198. patchBlockChildren(n1.dynamicChildren, dynamicChildren, el, parentComponent, parentSuspense, areChildrenSVG);
  3199. }
  3200. else if (!optimized) {
  3201. // full diff
  3202. patchChildren(n1, n2, el, null, parentComponent, parentSuspense, areChildrenSVG);
  3203. }
  3204. if ((vnodeHook = newProps.onVnodeUpdated) || dirs) {
  3205. queuePostRenderEffect(() => {
  3206. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, n2, n1);
  3207. dirs && invokeDirectiveHook(n2, n1, parentComponent, 'updated');
  3208. }, parentSuspense);
  3209. }
  3210. };
  3211. // The fast path for blocks.
  3212. const patchBlockChildren = (oldChildren, newChildren, fallbackContainer, parentComponent, parentSuspense, isSVG) => {
  3213. for (let i = 0; i < newChildren.length; i++) {
  3214. const oldVNode = oldChildren[i];
  3215. const newVNode = newChildren[i];
  3216. // Determine the container (parent element) for the patch.
  3217. const container =
  3218. // - In the case of a Fragment, we need to provide the actual parent
  3219. // of the Fragment itself so it can move its children.
  3220. oldVNode.type === Fragment ||
  3221. // - In the case of different nodes, there is going to be a replacement
  3222. // which also requires the correct parent container
  3223. !isSameVNodeType(oldVNode, newVNode) ||
  3224. // - In the case of a component, it could contain anything.
  3225. oldVNode.shapeFlag & 6 /* COMPONENT */ ||
  3226. oldVNode.shapeFlag & 64 /* TELEPORT */
  3227. ? hostParentNode(oldVNode.el)
  3228. : // In other cases, the parent container is not actually used so we
  3229. // just pass the block element here to avoid a DOM parentNode call.
  3230. fallbackContainer;
  3231. patch(oldVNode, newVNode, container, null, parentComponent, parentSuspense, isSVG, true);
  3232. }
  3233. };
  3234. const patchProps = (el, vnode, oldProps, newProps, parentComponent, parentSuspense, isSVG) => {
  3235. if (oldProps !== newProps) {
  3236. for (const key in newProps) {
  3237. // empty string is not valid prop
  3238. if (shared.isReservedProp(key))
  3239. continue;
  3240. const next = newProps[key];
  3241. const prev = oldProps[key];
  3242. if (next !== prev ||
  3243. (hostForcePatchProp && hostForcePatchProp(el, key))) {
  3244. hostPatchProp(el, key, prev, next, isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  3245. }
  3246. }
  3247. if (oldProps !== shared.EMPTY_OBJ) {
  3248. for (const key in oldProps) {
  3249. if (!shared.isReservedProp(key) && !(key in newProps)) {
  3250. hostPatchProp(el, key, oldProps[key], null, isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  3251. }
  3252. }
  3253. }
  3254. }
  3255. };
  3256. const processFragment = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized) => {
  3257. const fragmentStartAnchor = (n2.el = n1 ? n1.el : hostCreateText(''));
  3258. const fragmentEndAnchor = (n2.anchor = n1 ? n1.anchor : hostCreateText(''));
  3259. let { patchFlag, dynamicChildren } = n2;
  3260. if (patchFlag > 0) {
  3261. optimized = true;
  3262. }
  3263. if (n1 == null) {
  3264. hostInsert(fragmentStartAnchor, container, anchor);
  3265. hostInsert(fragmentEndAnchor, container, anchor);
  3266. // a fragment can only have array children
  3267. // since they are either generated by the compiler, or implicitly created
  3268. // from arrays.
  3269. mountChildren(n2.children, container, fragmentEndAnchor, parentComponent, parentSuspense, isSVG, optimized);
  3270. }
  3271. else {
  3272. if (patchFlag > 0 &&
  3273. patchFlag & 64 /* STABLE_FRAGMENT */ &&
  3274. dynamicChildren &&
  3275. // #2715 the previous fragment could've been a BAILed one as a result
  3276. // of renderSlot() with no valid children
  3277. n1.dynamicChildren) {
  3278. // a stable fragment (template root or <template v-for>) doesn't need to
  3279. // patch children order, but it may contain dynamicChildren.
  3280. patchBlockChildren(n1.dynamicChildren, dynamicChildren, container, parentComponent, parentSuspense, isSVG);
  3281. if (
  3282. // #2080 if the stable fragment has a key, it's a <template v-for> that may
  3283. // get moved around. Make sure all root level vnodes inherit el.
  3284. // #2134 or if it's a component root, it may also get moved around
  3285. // as the component is being moved.
  3286. n2.key != null ||
  3287. (parentComponent && n2 === parentComponent.subTree)) {
  3288. traverseStaticChildren(n1, n2, true /* shallow */);
  3289. }
  3290. }
  3291. else {
  3292. // keyed / unkeyed, or manual fragments.
  3293. // for keyed & unkeyed, since they are compiler generated from v-for,
  3294. // each child is guaranteed to be a block so the fragment will never
  3295. // have dynamicChildren.
  3296. patchChildren(n1, n2, container, fragmentEndAnchor, parentComponent, parentSuspense, isSVG, optimized);
  3297. }
  3298. }
  3299. };
  3300. const processComponent = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized) => {
  3301. if (n1 == null) {
  3302. if (n2.shapeFlag & 512 /* COMPONENT_KEPT_ALIVE */) {
  3303. parentComponent.ctx.activate(n2, container, anchor, isSVG, optimized);
  3304. }
  3305. else {
  3306. mountComponent(n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  3307. }
  3308. }
  3309. else {
  3310. updateComponent(n1, n2, optimized);
  3311. }
  3312. };
  3313. const mountComponent = (initialVNode, container, anchor, parentComponent, parentSuspense, isSVG, optimized) => {
  3314. const instance = (initialVNode.component = createComponentInstance(initialVNode, parentComponent, parentSuspense));
  3315. // inject renderer internals for keepAlive
  3316. if (isKeepAlive(initialVNode)) {
  3317. instance.ctx.renderer = internals;
  3318. }
  3319. setupComponent(instance);
  3320. // setup() is async. This component relies on async logic to be resolved
  3321. // before proceeding
  3322. if (instance.asyncDep) {
  3323. parentSuspense && parentSuspense.registerDep(instance, setupRenderEffect);
  3324. // Give it a placeholder if this is not hydration
  3325. // TODO handle self-defined fallback
  3326. if (!initialVNode.el) {
  3327. const placeholder = (instance.subTree = createVNode(Comment));
  3328. processCommentNode(null, placeholder, container, anchor);
  3329. }
  3330. return;
  3331. }
  3332. setupRenderEffect(instance, initialVNode, container, anchor, parentSuspense, isSVG, optimized);
  3333. };
  3334. const updateComponent = (n1, n2, optimized) => {
  3335. const instance = (n2.component = n1.component);
  3336. if (shouldUpdateComponent(n1, n2, optimized)) {
  3337. if (instance.asyncDep &&
  3338. !instance.asyncResolved) {
  3339. updateComponentPreRender(instance, n2, optimized);
  3340. return;
  3341. }
  3342. else {
  3343. // normal update
  3344. instance.next = n2;
  3345. // in case the child component is also queued, remove it to avoid
  3346. // double updating the same child component in the same flush.
  3347. invalidateJob(instance.update);
  3348. // instance.update is the reactive effect runner.
  3349. instance.update();
  3350. }
  3351. }
  3352. else {
  3353. // no update needed. just copy over properties
  3354. n2.component = n1.component;
  3355. n2.el = n1.el;
  3356. instance.vnode = n2;
  3357. }
  3358. };
  3359. const setupRenderEffect = (instance, initialVNode, container, anchor, parentSuspense, isSVG, optimized) => {
  3360. // create reactive effect for rendering
  3361. instance.update = reactivity.effect(function componentEffect() {
  3362. if (!instance.isMounted) {
  3363. let vnodeHook;
  3364. const { el, props } = initialVNode;
  3365. const { bm, m, parent } = instance;
  3366. // beforeMount hook
  3367. if (bm) {
  3368. shared.invokeArrayFns(bm);
  3369. }
  3370. // onVnodeBeforeMount
  3371. if ((vnodeHook = props && props.onVnodeBeforeMount)) {
  3372. invokeVNodeHook(vnodeHook, parent, initialVNode);
  3373. }
  3374. const subTree = (instance.subTree = renderComponentRoot(instance));
  3375. if (el && hydrateNode) {
  3376. // vnode has adopted host node - perform hydration instead of mount.
  3377. hydrateNode(initialVNode.el, subTree, instance, parentSuspense);
  3378. }
  3379. else {
  3380. patch(null, subTree, container, anchor, instance, parentSuspense, isSVG);
  3381. initialVNode.el = subTree.el;
  3382. }
  3383. // mounted hook
  3384. if (m) {
  3385. queuePostRenderEffect(m, parentSuspense);
  3386. }
  3387. // onVnodeMounted
  3388. if ((vnodeHook = props && props.onVnodeMounted)) {
  3389. const scopedInitialVNode = initialVNode;
  3390. queuePostRenderEffect(() => {
  3391. invokeVNodeHook(vnodeHook, parent, scopedInitialVNode);
  3392. }, parentSuspense);
  3393. }
  3394. // activated hook for keep-alive roots.
  3395. // #1742 activated hook must be accessed after first render
  3396. // since the hook may be injected by a child keep-alive
  3397. const { a } = instance;
  3398. if (a &&
  3399. initialVNode.shapeFlag & 256 /* COMPONENT_SHOULD_KEEP_ALIVE */) {
  3400. queuePostRenderEffect(a, parentSuspense);
  3401. }
  3402. instance.isMounted = true;
  3403. // #2458: deference mount-only object parameters to prevent memleaks
  3404. initialVNode = container = anchor = null;
  3405. }
  3406. else {
  3407. // updateComponent
  3408. // This is triggered by mutation of component's own state (next: null)
  3409. // OR parent calling processComponent (next: VNode)
  3410. let { next, bu, u, parent, vnode } = instance;
  3411. let originNext = next;
  3412. let vnodeHook;
  3413. if (next) {
  3414. next.el = vnode.el;
  3415. updateComponentPreRender(instance, next, optimized);
  3416. }
  3417. else {
  3418. next = vnode;
  3419. }
  3420. // beforeUpdate hook
  3421. if (bu) {
  3422. shared.invokeArrayFns(bu);
  3423. }
  3424. // onVnodeBeforeUpdate
  3425. if ((vnodeHook = next.props && next.props.onVnodeBeforeUpdate)) {
  3426. invokeVNodeHook(vnodeHook, parent, next, vnode);
  3427. }
  3428. const nextTree = renderComponentRoot(instance);
  3429. const prevTree = instance.subTree;
  3430. instance.subTree = nextTree;
  3431. patch(prevTree, nextTree,
  3432. // parent may have changed if it's in a teleport
  3433. hostParentNode(prevTree.el),
  3434. // anchor may have changed if it's in a fragment
  3435. getNextHostNode(prevTree), instance, parentSuspense, isSVG);
  3436. next.el = nextTree.el;
  3437. if (originNext === null) {
  3438. // self-triggered update. In case of HOC, update parent component
  3439. // vnode el. HOC is indicated by parent instance's subTree pointing
  3440. // to child component's vnode
  3441. updateHOCHostEl(instance, nextTree.el);
  3442. }
  3443. // updated hook
  3444. if (u) {
  3445. queuePostRenderEffect(u, parentSuspense);
  3446. }
  3447. // onVnodeUpdated
  3448. if ((vnodeHook = next.props && next.props.onVnodeUpdated)) {
  3449. queuePostRenderEffect(() => {
  3450. invokeVNodeHook(vnodeHook, parent, next, vnode);
  3451. }, parentSuspense);
  3452. }
  3453. }
  3454. }, prodEffectOptions);
  3455. };
  3456. const updateComponentPreRender = (instance, nextVNode, optimized) => {
  3457. nextVNode.component = instance;
  3458. const prevProps = instance.vnode.props;
  3459. instance.vnode = nextVNode;
  3460. instance.next = null;
  3461. updateProps(instance, nextVNode.props, prevProps, optimized);
  3462. updateSlots(instance, nextVNode.children);
  3463. // props update may have triggered pre-flush watchers.
  3464. // flush them before the render update.
  3465. flushPreFlushCbs(undefined, instance.update);
  3466. };
  3467. const patchChildren = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized = false) => {
  3468. const c1 = n1 && n1.children;
  3469. const prevShapeFlag = n1 ? n1.shapeFlag : 0;
  3470. const c2 = n2.children;
  3471. const { patchFlag, shapeFlag } = n2;
  3472. // fast path
  3473. if (patchFlag > 0) {
  3474. if (patchFlag & 128 /* KEYED_FRAGMENT */) {
  3475. // this could be either fully-keyed or mixed (some keyed some not)
  3476. // presence of patchFlag means children are guaranteed to be arrays
  3477. patchKeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  3478. return;
  3479. }
  3480. else if (patchFlag & 256 /* UNKEYED_FRAGMENT */) {
  3481. // unkeyed
  3482. patchUnkeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  3483. return;
  3484. }
  3485. }
  3486. // children has 3 possibilities: text, array or no children.
  3487. if (shapeFlag & 8 /* TEXT_CHILDREN */) {
  3488. // text children fast path
  3489. if (prevShapeFlag & 16 /* ARRAY_CHILDREN */) {
  3490. unmountChildren(c1, parentComponent, parentSuspense);
  3491. }
  3492. if (c2 !== c1) {
  3493. hostSetElementText(container, c2);
  3494. }
  3495. }
  3496. else {
  3497. if (prevShapeFlag & 16 /* ARRAY_CHILDREN */) {
  3498. // prev children was array
  3499. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  3500. // two arrays, cannot assume anything, do full diff
  3501. patchKeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  3502. }
  3503. else {
  3504. // no new children, just unmount old
  3505. unmountChildren(c1, parentComponent, parentSuspense, true);
  3506. }
  3507. }
  3508. else {
  3509. // prev children was text OR null
  3510. // new children is array OR null
  3511. if (prevShapeFlag & 8 /* TEXT_CHILDREN */) {
  3512. hostSetElementText(container, '');
  3513. }
  3514. // mount new if array
  3515. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  3516. mountChildren(c2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  3517. }
  3518. }
  3519. }
  3520. };
  3521. const patchUnkeyedChildren = (c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, optimized) => {
  3522. c1 = c1 || shared.EMPTY_ARR;
  3523. c2 = c2 || shared.EMPTY_ARR;
  3524. const oldLength = c1.length;
  3525. const newLength = c2.length;
  3526. const commonLength = Math.min(oldLength, newLength);
  3527. let i;
  3528. for (i = 0; i < commonLength; i++) {
  3529. const nextChild = (c2[i] = optimized
  3530. ? cloneIfMounted(c2[i])
  3531. : normalizeVNode(c2[i]));
  3532. patch(c1[i], nextChild, container, null, parentComponent, parentSuspense, isSVG, optimized);
  3533. }
  3534. if (oldLength > newLength) {
  3535. // remove old
  3536. unmountChildren(c1, parentComponent, parentSuspense, true, false, commonLength);
  3537. }
  3538. else {
  3539. // mount new
  3540. mountChildren(c2, container, anchor, parentComponent, parentSuspense, isSVG, optimized, commonLength);
  3541. }
  3542. };
  3543. // can be all-keyed or mixed
  3544. const patchKeyedChildren = (c1, c2, container, parentAnchor, parentComponent, parentSuspense, isSVG, optimized) => {
  3545. let i = 0;
  3546. const l2 = c2.length;
  3547. let e1 = c1.length - 1; // prev ending index
  3548. let e2 = l2 - 1; // next ending index
  3549. // 1. sync from start
  3550. // (a b) c
  3551. // (a b) d e
  3552. while (i <= e1 && i <= e2) {
  3553. const n1 = c1[i];
  3554. const n2 = (c2[i] = optimized
  3555. ? cloneIfMounted(c2[i])
  3556. : normalizeVNode(c2[i]));
  3557. if (isSameVNodeType(n1, n2)) {
  3558. patch(n1, n2, container, null, parentComponent, parentSuspense, isSVG, optimized);
  3559. }
  3560. else {
  3561. break;
  3562. }
  3563. i++;
  3564. }
  3565. // 2. sync from end
  3566. // a (b c)
  3567. // d e (b c)
  3568. while (i <= e1 && i <= e2) {
  3569. const n1 = c1[e1];
  3570. const n2 = (c2[e2] = optimized
  3571. ? cloneIfMounted(c2[e2])
  3572. : normalizeVNode(c2[e2]));
  3573. if (isSameVNodeType(n1, n2)) {
  3574. patch(n1, n2, container, null, parentComponent, parentSuspense, isSVG, optimized);
  3575. }
  3576. else {
  3577. break;
  3578. }
  3579. e1--;
  3580. e2--;
  3581. }
  3582. // 3. common sequence + mount
  3583. // (a b)
  3584. // (a b) c
  3585. // i = 2, e1 = 1, e2 = 2
  3586. // (a b)
  3587. // c (a b)
  3588. // i = 0, e1 = -1, e2 = 0
  3589. if (i > e1) {
  3590. if (i <= e2) {
  3591. const nextPos = e2 + 1;
  3592. const anchor = nextPos < l2 ? c2[nextPos].el : parentAnchor;
  3593. while (i <= e2) {
  3594. patch(null, (c2[i] = optimized
  3595. ? cloneIfMounted(c2[i])
  3596. : normalizeVNode(c2[i])), container, anchor, parentComponent, parentSuspense, isSVG);
  3597. i++;
  3598. }
  3599. }
  3600. }
  3601. // 4. common sequence + unmount
  3602. // (a b) c
  3603. // (a b)
  3604. // i = 2, e1 = 2, e2 = 1
  3605. // a (b c)
  3606. // (b c)
  3607. // i = 0, e1 = 0, e2 = -1
  3608. else if (i > e2) {
  3609. while (i <= e1) {
  3610. unmount(c1[i], parentComponent, parentSuspense, true);
  3611. i++;
  3612. }
  3613. }
  3614. // 5. unknown sequence
  3615. // [i ... e1 + 1]: a b [c d e] f g
  3616. // [i ... e2 + 1]: a b [e d c h] f g
  3617. // i = 2, e1 = 4, e2 = 5
  3618. else {
  3619. const s1 = i; // prev starting index
  3620. const s2 = i; // next starting index
  3621. // 5.1 build key:index map for newChildren
  3622. const keyToNewIndexMap = new Map();
  3623. for (i = s2; i <= e2; i++) {
  3624. const nextChild = (c2[i] = optimized
  3625. ? cloneIfMounted(c2[i])
  3626. : normalizeVNode(c2[i]));
  3627. if (nextChild.key != null) {
  3628. keyToNewIndexMap.set(nextChild.key, i);
  3629. }
  3630. }
  3631. // 5.2 loop through old children left to be patched and try to patch
  3632. // matching nodes & remove nodes that are no longer present
  3633. let j;
  3634. let patched = 0;
  3635. const toBePatched = e2 - s2 + 1;
  3636. let moved = false;
  3637. // used to track whether any node has moved
  3638. let maxNewIndexSoFar = 0;
  3639. // works as Map<newIndex, oldIndex>
  3640. // Note that oldIndex is offset by +1
  3641. // and oldIndex = 0 is a special value indicating the new node has
  3642. // no corresponding old node.
  3643. // used for determining longest stable subsequence
  3644. const newIndexToOldIndexMap = new Array(toBePatched);
  3645. for (i = 0; i < toBePatched; i++)
  3646. newIndexToOldIndexMap[i] = 0;
  3647. for (i = s1; i <= e1; i++) {
  3648. const prevChild = c1[i];
  3649. if (patched >= toBePatched) {
  3650. // all new children have been patched so this can only be a removal
  3651. unmount(prevChild, parentComponent, parentSuspense, true);
  3652. continue;
  3653. }
  3654. let newIndex;
  3655. if (prevChild.key != null) {
  3656. newIndex = keyToNewIndexMap.get(prevChild.key);
  3657. }
  3658. else {
  3659. // key-less node, try to locate a key-less node of the same type
  3660. for (j = s2; j <= e2; j++) {
  3661. if (newIndexToOldIndexMap[j - s2] === 0 &&
  3662. isSameVNodeType(prevChild, c2[j])) {
  3663. newIndex = j;
  3664. break;
  3665. }
  3666. }
  3667. }
  3668. if (newIndex === undefined) {
  3669. unmount(prevChild, parentComponent, parentSuspense, true);
  3670. }
  3671. else {
  3672. newIndexToOldIndexMap[newIndex - s2] = i + 1;
  3673. if (newIndex >= maxNewIndexSoFar) {
  3674. maxNewIndexSoFar = newIndex;
  3675. }
  3676. else {
  3677. moved = true;
  3678. }
  3679. patch(prevChild, c2[newIndex], container, null, parentComponent, parentSuspense, isSVG, optimized);
  3680. patched++;
  3681. }
  3682. }
  3683. // 5.3 move and mount
  3684. // generate longest stable subsequence only when nodes have moved
  3685. const increasingNewIndexSequence = moved
  3686. ? getSequence(newIndexToOldIndexMap)
  3687. : shared.EMPTY_ARR;
  3688. j = increasingNewIndexSequence.length - 1;
  3689. // looping backwards so that we can use last patched node as anchor
  3690. for (i = toBePatched - 1; i >= 0; i--) {
  3691. const nextIndex = s2 + i;
  3692. const nextChild = c2[nextIndex];
  3693. const anchor = nextIndex + 1 < l2 ? c2[nextIndex + 1].el : parentAnchor;
  3694. if (newIndexToOldIndexMap[i] === 0) {
  3695. // mount new
  3696. patch(null, nextChild, container, anchor, parentComponent, parentSuspense, isSVG);
  3697. }
  3698. else if (moved) {
  3699. // move if:
  3700. // There is no stable subsequence (e.g. a reverse)
  3701. // OR current node is not among the stable sequence
  3702. if (j < 0 || i !== increasingNewIndexSequence[j]) {
  3703. move(nextChild, container, anchor, 2 /* REORDER */);
  3704. }
  3705. else {
  3706. j--;
  3707. }
  3708. }
  3709. }
  3710. }
  3711. };
  3712. const move = (vnode, container, anchor, moveType, parentSuspense = null) => {
  3713. const { el, type, transition, children, shapeFlag } = vnode;
  3714. if (shapeFlag & 6 /* COMPONENT */) {
  3715. move(vnode.component.subTree, container, anchor, moveType);
  3716. return;
  3717. }
  3718. if (shapeFlag & 128 /* SUSPENSE */) {
  3719. vnode.suspense.move(container, anchor, moveType);
  3720. return;
  3721. }
  3722. if (shapeFlag & 64 /* TELEPORT */) {
  3723. type.move(vnode, container, anchor, internals);
  3724. return;
  3725. }
  3726. if (type === Fragment) {
  3727. hostInsert(el, container, anchor);
  3728. for (let i = 0; i < children.length; i++) {
  3729. move(children[i], container, anchor, moveType);
  3730. }
  3731. hostInsert(vnode.anchor, container, anchor);
  3732. return;
  3733. }
  3734. if (type === Static) {
  3735. moveStaticNode(vnode, container, anchor);
  3736. return;
  3737. }
  3738. // single nodes
  3739. const needTransition = moveType !== 2 /* REORDER */ &&
  3740. shapeFlag & 1 /* ELEMENT */ &&
  3741. transition;
  3742. if (needTransition) {
  3743. if (moveType === 0 /* ENTER */) {
  3744. transition.beforeEnter(el);
  3745. hostInsert(el, container, anchor);
  3746. queuePostRenderEffect(() => transition.enter(el), parentSuspense);
  3747. }
  3748. else {
  3749. const { leave, delayLeave, afterLeave } = transition;
  3750. const remove = () => hostInsert(el, container, anchor);
  3751. const performLeave = () => {
  3752. leave(el, () => {
  3753. remove();
  3754. afterLeave && afterLeave();
  3755. });
  3756. };
  3757. if (delayLeave) {
  3758. delayLeave(el, remove, performLeave);
  3759. }
  3760. else {
  3761. performLeave();
  3762. }
  3763. }
  3764. }
  3765. else {
  3766. hostInsert(el, container, anchor);
  3767. }
  3768. };
  3769. const unmount = (vnode, parentComponent, parentSuspense, doRemove = false, optimized = false) => {
  3770. const { type, props, ref, children, dynamicChildren, shapeFlag, patchFlag, dirs } = vnode;
  3771. // unset ref
  3772. if (ref != null) {
  3773. setRef(ref, null, parentSuspense, null);
  3774. }
  3775. if (shapeFlag & 256 /* COMPONENT_SHOULD_KEEP_ALIVE */) {
  3776. parentComponent.ctx.deactivate(vnode);
  3777. return;
  3778. }
  3779. const shouldInvokeDirs = shapeFlag & 1 /* ELEMENT */ && dirs;
  3780. let vnodeHook;
  3781. if ((vnodeHook = props && props.onVnodeBeforeUnmount)) {
  3782. invokeVNodeHook(vnodeHook, parentComponent, vnode);
  3783. }
  3784. if (shapeFlag & 6 /* COMPONENT */) {
  3785. unmountComponent(vnode.component, parentSuspense, doRemove);
  3786. }
  3787. else {
  3788. if (shapeFlag & 128 /* SUSPENSE */) {
  3789. vnode.suspense.unmount(parentSuspense, doRemove);
  3790. return;
  3791. }
  3792. if (shouldInvokeDirs) {
  3793. invokeDirectiveHook(vnode, null, parentComponent, 'beforeUnmount');
  3794. }
  3795. if (dynamicChildren &&
  3796. // #1153: fast path should not be taken for non-stable (v-for) fragments
  3797. (type !== Fragment ||
  3798. (patchFlag > 0 && patchFlag & 64 /* STABLE_FRAGMENT */))) {
  3799. // fast path for block nodes: only need to unmount dynamic children.
  3800. unmountChildren(dynamicChildren, parentComponent, parentSuspense, false, true);
  3801. }
  3802. else if ((type === Fragment &&
  3803. (patchFlag & 128 /* KEYED_FRAGMENT */ ||
  3804. patchFlag & 256 /* UNKEYED_FRAGMENT */)) ||
  3805. (!optimized && shapeFlag & 16 /* ARRAY_CHILDREN */)) {
  3806. unmountChildren(children, parentComponent, parentSuspense);
  3807. }
  3808. // an unmounted teleport should always remove its children if not disabled
  3809. if (shapeFlag & 64 /* TELEPORT */ &&
  3810. (doRemove || !isTeleportDisabled(vnode.props))) {
  3811. vnode.type.remove(vnode, internals);
  3812. }
  3813. if (doRemove) {
  3814. remove(vnode);
  3815. }
  3816. }
  3817. if ((vnodeHook = props && props.onVnodeUnmounted) || shouldInvokeDirs) {
  3818. queuePostRenderEffect(() => {
  3819. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, vnode);
  3820. shouldInvokeDirs &&
  3821. invokeDirectiveHook(vnode, null, parentComponent, 'unmounted');
  3822. }, parentSuspense);
  3823. }
  3824. };
  3825. const remove = vnode => {
  3826. const { type, el, anchor, transition } = vnode;
  3827. if (type === Fragment) {
  3828. removeFragment(el, anchor);
  3829. return;
  3830. }
  3831. if (type === Static) {
  3832. removeStaticNode(vnode);
  3833. return;
  3834. }
  3835. const performRemove = () => {
  3836. hostRemove(el);
  3837. if (transition && !transition.persisted && transition.afterLeave) {
  3838. transition.afterLeave();
  3839. }
  3840. };
  3841. if (vnode.shapeFlag & 1 /* ELEMENT */ &&
  3842. transition &&
  3843. !transition.persisted) {
  3844. const { leave, delayLeave } = transition;
  3845. const performLeave = () => leave(el, performRemove);
  3846. if (delayLeave) {
  3847. delayLeave(vnode.el, performRemove, performLeave);
  3848. }
  3849. else {
  3850. performLeave();
  3851. }
  3852. }
  3853. else {
  3854. performRemove();
  3855. }
  3856. };
  3857. const removeFragment = (cur, end) => {
  3858. // For fragments, directly remove all contained DOM nodes.
  3859. // (fragment child nodes cannot have transition)
  3860. let next;
  3861. while (cur !== end) {
  3862. next = hostNextSibling(cur);
  3863. hostRemove(cur);
  3864. cur = next;
  3865. }
  3866. hostRemove(end);
  3867. };
  3868. const unmountComponent = (instance, parentSuspense, doRemove) => {
  3869. const { bum, effects, update, subTree, um } = instance;
  3870. // beforeUnmount hook
  3871. if (bum) {
  3872. shared.invokeArrayFns(bum);
  3873. }
  3874. if (effects) {
  3875. for (let i = 0; i < effects.length; i++) {
  3876. reactivity.stop(effects[i]);
  3877. }
  3878. }
  3879. // update may be null if a component is unmounted before its async
  3880. // setup has resolved.
  3881. if (update) {
  3882. reactivity.stop(update);
  3883. unmount(subTree, instance, parentSuspense, doRemove);
  3884. }
  3885. // unmounted hook
  3886. if (um) {
  3887. queuePostRenderEffect(um, parentSuspense);
  3888. }
  3889. queuePostRenderEffect(() => {
  3890. instance.isUnmounted = true;
  3891. }, parentSuspense);
  3892. // A component with async dep inside a pending suspense is unmounted before
  3893. // its async dep resolves. This should remove the dep from the suspense, and
  3894. // cause the suspense to resolve immediately if that was the last dep.
  3895. if (parentSuspense &&
  3896. parentSuspense.pendingBranch &&
  3897. !parentSuspense.isUnmounted &&
  3898. instance.asyncDep &&
  3899. !instance.asyncResolved &&
  3900. instance.suspenseId === parentSuspense.pendingId) {
  3901. parentSuspense.deps--;
  3902. if (parentSuspense.deps === 0) {
  3903. parentSuspense.resolve();
  3904. }
  3905. }
  3906. };
  3907. const unmountChildren = (children, parentComponent, parentSuspense, doRemove = false, optimized = false, start = 0) => {
  3908. for (let i = start; i < children.length; i++) {
  3909. unmount(children[i], parentComponent, parentSuspense, doRemove, optimized);
  3910. }
  3911. };
  3912. const getNextHostNode = vnode => {
  3913. if (vnode.shapeFlag & 6 /* COMPONENT */) {
  3914. return getNextHostNode(vnode.component.subTree);
  3915. }
  3916. if (vnode.shapeFlag & 128 /* SUSPENSE */) {
  3917. return vnode.suspense.next();
  3918. }
  3919. return hostNextSibling((vnode.anchor || vnode.el));
  3920. };
  3921. const render = (vnode, container) => {
  3922. if (vnode == null) {
  3923. if (container._vnode) {
  3924. unmount(container._vnode, null, null, true);
  3925. }
  3926. }
  3927. else {
  3928. patch(container._vnode || null, vnode, container);
  3929. }
  3930. flushPostFlushCbs();
  3931. container._vnode = vnode;
  3932. };
  3933. const internals = {
  3934. p: patch,
  3935. um: unmount,
  3936. m: move,
  3937. r: remove,
  3938. mt: mountComponent,
  3939. mc: mountChildren,
  3940. pc: patchChildren,
  3941. pbc: patchBlockChildren,
  3942. n: getNextHostNode,
  3943. o: options
  3944. };
  3945. let hydrate;
  3946. let hydrateNode;
  3947. if (createHydrationFns) {
  3948. [hydrate, hydrateNode] = createHydrationFns(internals);
  3949. }
  3950. return {
  3951. render,
  3952. hydrate,
  3953. createApp: createAppAPI(render, hydrate)
  3954. };
  3955. }
  3956. function invokeVNodeHook(hook, instance, vnode, prevVNode = null) {
  3957. callWithAsyncErrorHandling(hook, instance, 7 /* VNODE_HOOK */, [
  3958. vnode,
  3959. prevVNode
  3960. ]);
  3961. }
  3962. /**
  3963. * #1156
  3964. * When a component is HMR-enabled, we need to make sure that all static nodes
  3965. * inside a block also inherit the DOM element from the previous tree so that
  3966. * HMR updates (which are full updates) can retrieve the element for patching.
  3967. *
  3968. * #2080
  3969. * Inside keyed `template` fragment static children, if a fragment is moved,
  3970. * the children will always moved so that need inherit el form previous nodes
  3971. * to ensure correct moved position.
  3972. */
  3973. function traverseStaticChildren(n1, n2, shallow = false) {
  3974. const ch1 = n1.children;
  3975. const ch2 = n2.children;
  3976. if (shared.isArray(ch1) && shared.isArray(ch2)) {
  3977. for (let i = 0; i < ch1.length; i++) {
  3978. // this is only called in the optimized path so array children are
  3979. // guaranteed to be vnodes
  3980. const c1 = ch1[i];
  3981. let c2 = ch2[i];
  3982. if (c2.shapeFlag & 1 /* ELEMENT */ && !c2.dynamicChildren) {
  3983. if (c2.patchFlag <= 0 || c2.patchFlag === 32 /* HYDRATE_EVENTS */) {
  3984. c2 = ch2[i] = cloneIfMounted(ch2[i]);
  3985. c2.el = c1.el;
  3986. }
  3987. if (!shallow)
  3988. traverseStaticChildren(c1, c2);
  3989. }
  3990. }
  3991. }
  3992. }
  3993. // https://en.wikipedia.org/wiki/Longest_increasing_subsequence
  3994. function getSequence(arr) {
  3995. const p = arr.slice();
  3996. const result = [0];
  3997. let i, j, u, v, c;
  3998. const len = arr.length;
  3999. for (i = 0; i < len; i++) {
  4000. const arrI = arr[i];
  4001. if (arrI !== 0) {
  4002. j = result[result.length - 1];
  4003. if (arr[j] < arrI) {
  4004. p[i] = j;
  4005. result.push(i);
  4006. continue;
  4007. }
  4008. u = 0;
  4009. v = result.length - 1;
  4010. while (u < v) {
  4011. c = ((u + v) / 2) | 0;
  4012. if (arr[result[c]] < arrI) {
  4013. u = c + 1;
  4014. }
  4015. else {
  4016. v = c;
  4017. }
  4018. }
  4019. if (arrI < arr[result[u]]) {
  4020. if (u > 0) {
  4021. p[i] = result[u - 1];
  4022. }
  4023. result[u] = i;
  4024. }
  4025. }
  4026. }
  4027. u = result.length;
  4028. v = result[u - 1];
  4029. while (u-- > 0) {
  4030. result[u] = v;
  4031. v = p[v];
  4032. }
  4033. return result;
  4034. }
  4035. const isTeleport = (type) => type.__isTeleport;
  4036. const isTeleportDisabled = (props) => props && (props.disabled || props.disabled === '');
  4037. const isTargetSVG = (target) => typeof SVGElement !== 'undefined' && target instanceof SVGElement;
  4038. const resolveTarget = (props, select) => {
  4039. const targetSelector = props && props.to;
  4040. if (shared.isString(targetSelector)) {
  4041. if (!select) {
  4042. return null;
  4043. }
  4044. else {
  4045. const target = select(targetSelector);
  4046. return target;
  4047. }
  4048. }
  4049. else {
  4050. return targetSelector;
  4051. }
  4052. };
  4053. const TeleportImpl = {
  4054. __isTeleport: true,
  4055. process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized, internals) {
  4056. const { mc: mountChildren, pc: patchChildren, pbc: patchBlockChildren, o: { insert, querySelector, createText, createComment } } = internals;
  4057. const disabled = isTeleportDisabled(n2.props);
  4058. const { shapeFlag, children } = n2;
  4059. if (n1 == null) {
  4060. // insert anchors in the main view
  4061. const placeholder = (n2.el = createText(''));
  4062. const mainAnchor = (n2.anchor = createText(''));
  4063. insert(placeholder, container, anchor);
  4064. insert(mainAnchor, container, anchor);
  4065. const target = (n2.target = resolveTarget(n2.props, querySelector));
  4066. const targetAnchor = (n2.targetAnchor = createText(''));
  4067. if (target) {
  4068. insert(targetAnchor, target);
  4069. // #2652 we could be teleporting from a non-SVG tree into an SVG tree
  4070. isSVG = isSVG || isTargetSVG(target);
  4071. }
  4072. const mount = (container, anchor) => {
  4073. // Teleport *always* has Array children. This is enforced in both the
  4074. // compiler and vnode children normalization.
  4075. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  4076. mountChildren(children, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  4077. }
  4078. };
  4079. if (disabled) {
  4080. mount(container, mainAnchor);
  4081. }
  4082. else if (target) {
  4083. mount(target, targetAnchor);
  4084. }
  4085. }
  4086. else {
  4087. // update content
  4088. n2.el = n1.el;
  4089. const mainAnchor = (n2.anchor = n1.anchor);
  4090. const target = (n2.target = n1.target);
  4091. const targetAnchor = (n2.targetAnchor = n1.targetAnchor);
  4092. const wasDisabled = isTeleportDisabled(n1.props);
  4093. const currentContainer = wasDisabled ? container : target;
  4094. const currentAnchor = wasDisabled ? mainAnchor : targetAnchor;
  4095. isSVG = isSVG || isTargetSVG(target);
  4096. if (n2.dynamicChildren) {
  4097. // fast path when the teleport happens to be a block root
  4098. patchBlockChildren(n1.dynamicChildren, n2.dynamicChildren, currentContainer, parentComponent, parentSuspense, isSVG);
  4099. // even in block tree mode we need to make sure all root-level nodes
  4100. // in the teleport inherit previous DOM references so that they can
  4101. // be moved in future patches.
  4102. traverseStaticChildren(n1, n2, true);
  4103. }
  4104. else if (!optimized) {
  4105. patchChildren(n1, n2, currentContainer, currentAnchor, parentComponent, parentSuspense, isSVG);
  4106. }
  4107. if (disabled) {
  4108. if (!wasDisabled) {
  4109. // enabled -> disabled
  4110. // move into main container
  4111. moveTeleport(n2, container, mainAnchor, internals, 1 /* TOGGLE */);
  4112. }
  4113. }
  4114. else {
  4115. // target changed
  4116. if ((n2.props && n2.props.to) !== (n1.props && n1.props.to)) {
  4117. const nextTarget = (n2.target = resolveTarget(n2.props, querySelector));
  4118. if (nextTarget) {
  4119. moveTeleport(n2, nextTarget, null, internals, 0 /* TARGET_CHANGE */);
  4120. }
  4121. }
  4122. else if (wasDisabled) {
  4123. // disabled -> enabled
  4124. // move into teleport target
  4125. moveTeleport(n2, target, targetAnchor, internals, 1 /* TOGGLE */);
  4126. }
  4127. }
  4128. }
  4129. },
  4130. remove(vnode, { r: remove, o: { remove: hostRemove } }) {
  4131. const { shapeFlag, children, anchor } = vnode;
  4132. hostRemove(anchor);
  4133. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  4134. for (let i = 0; i < children.length; i++) {
  4135. remove(children[i]);
  4136. }
  4137. }
  4138. },
  4139. move: moveTeleport,
  4140. hydrate: hydrateTeleport
  4141. };
  4142. function moveTeleport(vnode, container, parentAnchor, { o: { insert }, m: move }, moveType = 2 /* REORDER */) {
  4143. // move target anchor if this is a target change.
  4144. if (moveType === 0 /* TARGET_CHANGE */) {
  4145. insert(vnode.targetAnchor, container, parentAnchor);
  4146. }
  4147. const { el, anchor, shapeFlag, children, props } = vnode;
  4148. const isReorder = moveType === 2 /* REORDER */;
  4149. // move main view anchor if this is a re-order.
  4150. if (isReorder) {
  4151. insert(el, container, parentAnchor);
  4152. }
  4153. // if this is a re-order and teleport is enabled (content is in target)
  4154. // do not move children. So the opposite is: only move children if this
  4155. // is not a reorder, or the teleport is disabled
  4156. if (!isReorder || isTeleportDisabled(props)) {
  4157. // Teleport has either Array children or no children.
  4158. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  4159. for (let i = 0; i < children.length; i++) {
  4160. move(children[i], container, parentAnchor, 2 /* REORDER */);
  4161. }
  4162. }
  4163. }
  4164. // move main view anchor if this is a re-order.
  4165. if (isReorder) {
  4166. insert(anchor, container, parentAnchor);
  4167. }
  4168. }
  4169. function hydrateTeleport(node, vnode, parentComponent, parentSuspense, optimized, { o: { nextSibling, parentNode, querySelector } }, hydrateChildren) {
  4170. const target = (vnode.target = resolveTarget(vnode.props, querySelector));
  4171. if (target) {
  4172. // if multiple teleports rendered to the same target element, we need to
  4173. // pick up from where the last teleport finished instead of the first node
  4174. const targetNode = target._lpa || target.firstChild;
  4175. if (vnode.shapeFlag & 16 /* ARRAY_CHILDREN */) {
  4176. if (isTeleportDisabled(vnode.props)) {
  4177. vnode.anchor = hydrateChildren(nextSibling(node), vnode, parentNode(node), parentComponent, parentSuspense, optimized);
  4178. vnode.targetAnchor = targetNode;
  4179. }
  4180. else {
  4181. vnode.anchor = nextSibling(node);
  4182. vnode.targetAnchor = hydrateChildren(targetNode, vnode, target, parentComponent, parentSuspense, optimized);
  4183. }
  4184. target._lpa =
  4185. vnode.targetAnchor && nextSibling(vnode.targetAnchor);
  4186. }
  4187. }
  4188. return vnode.anchor && nextSibling(vnode.anchor);
  4189. }
  4190. // Force-casted public typing for h and TSX props inference
  4191. const Teleport = TeleportImpl;
  4192. const COMPONENTS = 'components';
  4193. const DIRECTIVES = 'directives';
  4194. /**
  4195. * @private
  4196. */
  4197. function resolveComponent(name) {
  4198. return resolveAsset(COMPONENTS, name) || name;
  4199. }
  4200. const NULL_DYNAMIC_COMPONENT = Symbol();
  4201. /**
  4202. * @private
  4203. */
  4204. function resolveDynamicComponent(component) {
  4205. if (shared.isString(component)) {
  4206. return resolveAsset(COMPONENTS, component, false) || component;
  4207. }
  4208. else {
  4209. // invalid types will fallthrough to createVNode and raise warning
  4210. return (component || NULL_DYNAMIC_COMPONENT);
  4211. }
  4212. }
  4213. /**
  4214. * @private
  4215. */
  4216. function resolveDirective(name) {
  4217. return resolveAsset(DIRECTIVES, name);
  4218. }
  4219. // implementation
  4220. function resolveAsset(type, name, warnMissing = true) {
  4221. const instance = currentRenderingInstance || currentInstance;
  4222. if (instance) {
  4223. const Component = instance.type;
  4224. // self name has highest priority
  4225. if (type === COMPONENTS) {
  4226. // special self referencing call generated by compiler
  4227. // inferred from SFC filename
  4228. if (name === `_self`) {
  4229. return Component;
  4230. }
  4231. const selfName = getComponentName(Component);
  4232. if (selfName &&
  4233. (selfName === name ||
  4234. selfName === shared.camelize(name) ||
  4235. selfName === shared.capitalize(shared.camelize(name)))) {
  4236. return Component;
  4237. }
  4238. }
  4239. const res =
  4240. // local registration
  4241. // check instance[type] first for components with mixin or extends.
  4242. resolve(instance[type] || Component[type], name) ||
  4243. // global registration
  4244. resolve(instance.appContext[type], name);
  4245. return res;
  4246. }
  4247. }
  4248. function resolve(registry, name) {
  4249. return (registry &&
  4250. (registry[name] ||
  4251. registry[shared.camelize(name)] ||
  4252. registry[shared.capitalize(shared.camelize(name))]));
  4253. }
  4254. const Fragment = Symbol(undefined);
  4255. const Text = Symbol(undefined);
  4256. const Comment = Symbol(undefined);
  4257. const Static = Symbol(undefined);
  4258. // Since v-if and v-for are the two possible ways node structure can dynamically
  4259. // change, once we consider v-if branches and each v-for fragment a block, we
  4260. // can divide a template into nested blocks, and within each block the node
  4261. // structure would be stable. This allows us to skip most children diffing
  4262. // and only worry about the dynamic nodes (indicated by patch flags).
  4263. const blockStack = [];
  4264. let currentBlock = null;
  4265. /**
  4266. * Open a block.
  4267. * This must be called before `createBlock`. It cannot be part of `createBlock`
  4268. * because the children of the block are evaluated before `createBlock` itself
  4269. * is called. The generated code typically looks like this:
  4270. *
  4271. * ```js
  4272. * function render() {
  4273. * return (openBlock(),createBlock('div', null, [...]))
  4274. * }
  4275. * ```
  4276. * disableTracking is true when creating a v-for fragment block, since a v-for
  4277. * fragment always diffs its children.
  4278. *
  4279. * @private
  4280. */
  4281. function openBlock(disableTracking = false) {
  4282. blockStack.push((currentBlock = disableTracking ? null : []));
  4283. }
  4284. function closeBlock() {
  4285. blockStack.pop();
  4286. currentBlock = blockStack[blockStack.length - 1] || null;
  4287. }
  4288. // Whether we should be tracking dynamic child nodes inside a block.
  4289. // Only tracks when this value is > 0
  4290. // We are not using a simple boolean because this value may need to be
  4291. // incremented/decremented by nested usage of v-once (see below)
  4292. let shouldTrack = 1;
  4293. /**
  4294. * Block tracking sometimes needs to be disabled, for example during the
  4295. * creation of a tree that needs to be cached by v-once. The compiler generates
  4296. * code like this:
  4297. *
  4298. * ``` js
  4299. * _cache[1] || (
  4300. * setBlockTracking(-1),
  4301. * _cache[1] = createVNode(...),
  4302. * setBlockTracking(1),
  4303. * _cache[1]
  4304. * )
  4305. * ```
  4306. *
  4307. * @private
  4308. */
  4309. function setBlockTracking(value) {
  4310. shouldTrack += value;
  4311. }
  4312. /**
  4313. * Create a block root vnode. Takes the same exact arguments as `createVNode`.
  4314. * A block root keeps track of dynamic nodes within the block in the
  4315. * `dynamicChildren` array.
  4316. *
  4317. * @private
  4318. */
  4319. function createBlock(type, props, children, patchFlag, dynamicProps) {
  4320. const vnode = createVNode(type, props, children, patchFlag, dynamicProps, true /* isBlock: prevent a block from tracking itself */);
  4321. // save current block children on the block vnode
  4322. vnode.dynamicChildren = currentBlock || shared.EMPTY_ARR;
  4323. // close block
  4324. closeBlock();
  4325. // a block is always going to be patched, so track it as a child of its
  4326. // parent block
  4327. if (shouldTrack > 0 && currentBlock) {
  4328. currentBlock.push(vnode);
  4329. }
  4330. return vnode;
  4331. }
  4332. function isVNode(value) {
  4333. return value ? value.__v_isVNode === true : false;
  4334. }
  4335. function isSameVNodeType(n1, n2) {
  4336. return n1.type === n2.type && n1.key === n2.key;
  4337. }
  4338. /**
  4339. * Internal API for registering an arguments transform for createVNode
  4340. * used for creating stubs in the test-utils
  4341. * It is *internal* but needs to be exposed for test-utils to pick up proper
  4342. * typings
  4343. */
  4344. function transformVNodeArgs(transformer) {
  4345. }
  4346. const InternalObjectKey = `__vInternal`;
  4347. const normalizeKey = ({ key }) => key != null ? key : null;
  4348. const normalizeRef = ({ ref }) => {
  4349. return (ref != null
  4350. ? shared.isString(ref) || reactivity.isRef(ref) || shared.isFunction(ref)
  4351. ? { i: currentRenderingInstance, r: ref }
  4352. : ref
  4353. : null);
  4354. };
  4355. const createVNode = (_createVNode);
  4356. function _createVNode(type, props = null, children = null, patchFlag = 0, dynamicProps = null, isBlockNode = false) {
  4357. if (!type || type === NULL_DYNAMIC_COMPONENT) {
  4358. type = Comment;
  4359. }
  4360. if (isVNode(type)) {
  4361. // createVNode receiving an existing vnode. This happens in cases like
  4362. // <component :is="vnode"/>
  4363. // #2078 make sure to merge refs during the clone instead of overwriting it
  4364. const cloned = cloneVNode(type, props, true /* mergeRef: true */);
  4365. if (children) {
  4366. normalizeChildren(cloned, children);
  4367. }
  4368. return cloned;
  4369. }
  4370. // class component normalization.
  4371. if (isClassComponent(type)) {
  4372. type = type.__vccOpts;
  4373. }
  4374. // class & style normalization.
  4375. if (props) {
  4376. // for reactive or proxy objects, we need to clone it to enable mutation.
  4377. if (reactivity.isProxy(props) || InternalObjectKey in props) {
  4378. props = shared.extend({}, props);
  4379. }
  4380. let { class: klass, style } = props;
  4381. if (klass && !shared.isString(klass)) {
  4382. props.class = shared.normalizeClass(klass);
  4383. }
  4384. if (shared.isObject(style)) {
  4385. // reactive state objects need to be cloned since they are likely to be
  4386. // mutated
  4387. if (reactivity.isProxy(style) && !shared.isArray(style)) {
  4388. style = shared.extend({}, style);
  4389. }
  4390. props.style = shared.normalizeStyle(style);
  4391. }
  4392. }
  4393. // encode the vnode type information into a bitmap
  4394. const shapeFlag = shared.isString(type)
  4395. ? 1 /* ELEMENT */
  4396. : isSuspense(type)
  4397. ? 128 /* SUSPENSE */
  4398. : isTeleport(type)
  4399. ? 64 /* TELEPORT */
  4400. : shared.isObject(type)
  4401. ? 4 /* STATEFUL_COMPONENT */
  4402. : shared.isFunction(type)
  4403. ? 2 /* FUNCTIONAL_COMPONENT */
  4404. : 0;
  4405. const vnode = {
  4406. __v_isVNode: true,
  4407. ["__v_skip" /* SKIP */]: true,
  4408. type,
  4409. props,
  4410. key: props && normalizeKey(props),
  4411. ref: props && normalizeRef(props),
  4412. scopeId: currentScopeId,
  4413. children: null,
  4414. component: null,
  4415. suspense: null,
  4416. ssContent: null,
  4417. ssFallback: null,
  4418. dirs: null,
  4419. transition: null,
  4420. el: null,
  4421. anchor: null,
  4422. target: null,
  4423. targetAnchor: null,
  4424. staticCount: 0,
  4425. shapeFlag,
  4426. patchFlag,
  4427. dynamicProps,
  4428. dynamicChildren: null,
  4429. appContext: null
  4430. };
  4431. normalizeChildren(vnode, children);
  4432. // normalize suspense children
  4433. if (shapeFlag & 128 /* SUSPENSE */) {
  4434. const { content, fallback } = normalizeSuspenseChildren(vnode);
  4435. vnode.ssContent = content;
  4436. vnode.ssFallback = fallback;
  4437. }
  4438. if (shouldTrack > 0 &&
  4439. // avoid a block node from tracking itself
  4440. !isBlockNode &&
  4441. // has current parent block
  4442. currentBlock &&
  4443. // presence of a patch flag indicates this node needs patching on updates.
  4444. // component nodes also should always be patched, because even if the
  4445. // component doesn't need to update, it needs to persist the instance on to
  4446. // the next vnode so that it can be properly unmounted later.
  4447. (patchFlag > 0 || shapeFlag & 6 /* COMPONENT */) &&
  4448. // the EVENTS flag is only for hydration and if it is the only flag, the
  4449. // vnode should not be considered dynamic due to handler caching.
  4450. patchFlag !== 32 /* HYDRATE_EVENTS */) {
  4451. currentBlock.push(vnode);
  4452. }
  4453. return vnode;
  4454. }
  4455. function cloneVNode(vnode, extraProps, mergeRef = false) {
  4456. // This is intentionally NOT using spread or extend to avoid the runtime
  4457. // key enumeration cost.
  4458. const { props, ref, patchFlag, children } = vnode;
  4459. const mergedProps = extraProps ? mergeProps(props || {}, extraProps) : props;
  4460. return {
  4461. __v_isVNode: true,
  4462. ["__v_skip" /* SKIP */]: true,
  4463. type: vnode.type,
  4464. props: mergedProps,
  4465. key: mergedProps && normalizeKey(mergedProps),
  4466. ref: extraProps && extraProps.ref
  4467. ? // #2078 in the case of <component :is="vnode" ref="extra"/>
  4468. // if the vnode itself already has a ref, cloneVNode will need to merge
  4469. // the refs so the single vnode can be set on multiple refs
  4470. mergeRef && ref
  4471. ? shared.isArray(ref)
  4472. ? ref.concat(normalizeRef(extraProps))
  4473. : [ref, normalizeRef(extraProps)]
  4474. : normalizeRef(extraProps)
  4475. : ref,
  4476. scopeId: vnode.scopeId,
  4477. children: children,
  4478. target: vnode.target,
  4479. targetAnchor: vnode.targetAnchor,
  4480. staticCount: vnode.staticCount,
  4481. shapeFlag: vnode.shapeFlag,
  4482. // if the vnode is cloned with extra props, we can no longer assume its
  4483. // existing patch flag to be reliable and need to add the FULL_PROPS flag.
  4484. // note: perserve flag for fragments since they use the flag for children
  4485. // fast paths only.
  4486. patchFlag: extraProps && vnode.type !== Fragment
  4487. ? patchFlag === -1 // hoisted node
  4488. ? 16 /* FULL_PROPS */
  4489. : patchFlag | 16 /* FULL_PROPS */
  4490. : patchFlag,
  4491. dynamicProps: vnode.dynamicProps,
  4492. dynamicChildren: vnode.dynamicChildren,
  4493. appContext: vnode.appContext,
  4494. dirs: vnode.dirs,
  4495. transition: vnode.transition,
  4496. // These should technically only be non-null on mounted VNodes. However,
  4497. // they *should* be copied for kept-alive vnodes. So we just always copy
  4498. // them since them being non-null during a mount doesn't affect the logic as
  4499. // they will simply be overwritten.
  4500. component: vnode.component,
  4501. suspense: vnode.suspense,
  4502. ssContent: vnode.ssContent && cloneVNode(vnode.ssContent),
  4503. ssFallback: vnode.ssFallback && cloneVNode(vnode.ssFallback),
  4504. el: vnode.el,
  4505. anchor: vnode.anchor
  4506. };
  4507. }
  4508. /**
  4509. * @private
  4510. */
  4511. function createTextVNode(text = ' ', flag = 0) {
  4512. return createVNode(Text, null, text, flag);
  4513. }
  4514. /**
  4515. * @private
  4516. */
  4517. function createStaticVNode(content, numberOfNodes) {
  4518. // A static vnode can contain multiple stringified elements, and the number
  4519. // of elements is necessary for hydration.
  4520. const vnode = createVNode(Static, null, content);
  4521. vnode.staticCount = numberOfNodes;
  4522. return vnode;
  4523. }
  4524. /**
  4525. * @private
  4526. */
  4527. function createCommentVNode(text = '',
  4528. // when used as the v-else branch, the comment node must be created as a
  4529. // block to ensure correct updates.
  4530. asBlock = false) {
  4531. return asBlock
  4532. ? (openBlock(), createBlock(Comment, null, text))
  4533. : createVNode(Comment, null, text);
  4534. }
  4535. function normalizeVNode(child) {
  4536. if (child == null || typeof child === 'boolean') {
  4537. // empty placeholder
  4538. return createVNode(Comment);
  4539. }
  4540. else if (shared.isArray(child)) {
  4541. // fragment
  4542. return createVNode(Fragment, null, child);
  4543. }
  4544. else if (typeof child === 'object') {
  4545. // already vnode, this should be the most common since compiled templates
  4546. // always produce all-vnode children arrays
  4547. return child.el === null ? child : cloneVNode(child);
  4548. }
  4549. else {
  4550. // strings and numbers
  4551. return createVNode(Text, null, String(child));
  4552. }
  4553. }
  4554. // optimized normalization for template-compiled render fns
  4555. function cloneIfMounted(child) {
  4556. return child.el === null ? child : cloneVNode(child);
  4557. }
  4558. function normalizeChildren(vnode, children) {
  4559. let type = 0;
  4560. const { shapeFlag } = vnode;
  4561. if (children == null) {
  4562. children = null;
  4563. }
  4564. else if (shared.isArray(children)) {
  4565. type = 16 /* ARRAY_CHILDREN */;
  4566. }
  4567. else if (typeof children === 'object') {
  4568. if (shapeFlag & 1 /* ELEMENT */ || shapeFlag & 64 /* TELEPORT */) {
  4569. // Normalize slot to plain children for plain element and Teleport
  4570. const slot = children.default;
  4571. if (slot) {
  4572. // _c marker is added by withCtx() indicating this is a compiled slot
  4573. slot._c && setCompiledSlotRendering(1);
  4574. normalizeChildren(vnode, slot());
  4575. slot._c && setCompiledSlotRendering(-1);
  4576. }
  4577. return;
  4578. }
  4579. else {
  4580. type = 32 /* SLOTS_CHILDREN */;
  4581. const slotFlag = children._;
  4582. if (!slotFlag && !(InternalObjectKey in children)) {
  4583. children._ctx = currentRenderingInstance;
  4584. }
  4585. else if (slotFlag === 3 /* FORWARDED */ && currentRenderingInstance) {
  4586. // a child component receives forwarded slots from the parent.
  4587. // its slot type is determined by its parent's slot type.
  4588. if (currentRenderingInstance.vnode.patchFlag & 1024 /* DYNAMIC_SLOTS */) {
  4589. children._ = 2 /* DYNAMIC */;
  4590. vnode.patchFlag |= 1024 /* DYNAMIC_SLOTS */;
  4591. }
  4592. else {
  4593. children._ = 1 /* STABLE */;
  4594. }
  4595. }
  4596. }
  4597. }
  4598. else if (shared.isFunction(children)) {
  4599. children = { default: children, _ctx: currentRenderingInstance };
  4600. type = 32 /* SLOTS_CHILDREN */;
  4601. }
  4602. else {
  4603. children = String(children);
  4604. // force teleport children to array so it can be moved around
  4605. if (shapeFlag & 64 /* TELEPORT */) {
  4606. type = 16 /* ARRAY_CHILDREN */;
  4607. children = [createTextVNode(children)];
  4608. }
  4609. else {
  4610. type = 8 /* TEXT_CHILDREN */;
  4611. }
  4612. }
  4613. vnode.children = children;
  4614. vnode.shapeFlag |= type;
  4615. }
  4616. function mergeProps(...args) {
  4617. const ret = shared.extend({}, args[0]);
  4618. for (let i = 1; i < args.length; i++) {
  4619. const toMerge = args[i];
  4620. for (const key in toMerge) {
  4621. if (key === 'class') {
  4622. if (ret.class !== toMerge.class) {
  4623. ret.class = shared.normalizeClass([ret.class, toMerge.class]);
  4624. }
  4625. }
  4626. else if (key === 'style') {
  4627. ret.style = shared.normalizeStyle([ret.style, toMerge.style]);
  4628. }
  4629. else if (shared.isOn(key)) {
  4630. const existing = ret[key];
  4631. const incoming = toMerge[key];
  4632. if (existing !== incoming) {
  4633. ret[key] = existing
  4634. ? [].concat(existing, toMerge[key])
  4635. : incoming;
  4636. }
  4637. }
  4638. else if (key !== '') {
  4639. ret[key] = toMerge[key];
  4640. }
  4641. }
  4642. }
  4643. return ret;
  4644. }
  4645. function provide(key, value) {
  4646. if (!currentInstance) ;
  4647. else {
  4648. let provides = currentInstance.provides;
  4649. // by default an instance inherits its parent's provides object
  4650. // but when it needs to provide values of its own, it creates its
  4651. // own provides object using parent provides object as prototype.
  4652. // this way in `inject` we can simply look up injections from direct
  4653. // parent and let the prototype chain do the work.
  4654. const parentProvides = currentInstance.parent && currentInstance.parent.provides;
  4655. if (parentProvides === provides) {
  4656. provides = currentInstance.provides = Object.create(parentProvides);
  4657. }
  4658. // TS doesn't allow symbol as index type
  4659. provides[key] = value;
  4660. }
  4661. }
  4662. function inject(key, defaultValue, treatDefaultAsFactory = false) {
  4663. // fallback to `currentRenderingInstance` so that this can be called in
  4664. // a functional component
  4665. const instance = currentInstance || currentRenderingInstance;
  4666. if (instance) {
  4667. // #2400
  4668. // to support `app.use` plugins,
  4669. // fallback to appContext's `provides` if the intance is at root
  4670. const provides = instance.parent == null
  4671. ? instance.vnode.appContext && instance.vnode.appContext.provides
  4672. : instance.parent.provides;
  4673. if (provides && key in provides) {
  4674. // TS doesn't allow symbol as index type
  4675. return provides[key];
  4676. }
  4677. else if (arguments.length > 1) {
  4678. return treatDefaultAsFactory && shared.isFunction(defaultValue)
  4679. ? defaultValue()
  4680. : defaultValue;
  4681. }
  4682. else ;
  4683. }
  4684. }
  4685. let isInBeforeCreate = false;
  4686. function applyOptions(instance, options, deferredData = [], deferredWatch = [], deferredProvide = [], asMixin = false) {
  4687. const {
  4688. // composition
  4689. mixins, extends: extendsOptions,
  4690. // state
  4691. data: dataOptions, computed: computedOptions, methods, watch: watchOptions, provide: provideOptions, inject: injectOptions,
  4692. // assets
  4693. components, directives,
  4694. // lifecycle
  4695. beforeMount, mounted, beforeUpdate, updated, activated, deactivated, beforeDestroy, beforeUnmount, destroyed, unmounted, render, renderTracked, renderTriggered, errorCaptured,
  4696. // public API
  4697. expose } = options;
  4698. const publicThis = instance.proxy;
  4699. const ctx = instance.ctx;
  4700. const globalMixins = instance.appContext.mixins;
  4701. if (asMixin && render && instance.render === shared.NOOP) {
  4702. instance.render = render;
  4703. }
  4704. // applyOptions is called non-as-mixin once per instance
  4705. if (!asMixin) {
  4706. isInBeforeCreate = true;
  4707. callSyncHook('beforeCreate', "bc" /* BEFORE_CREATE */, options, instance, globalMixins);
  4708. isInBeforeCreate = false;
  4709. // global mixins are applied first
  4710. applyMixins(instance, globalMixins, deferredData, deferredWatch, deferredProvide);
  4711. }
  4712. // extending a base component...
  4713. if (extendsOptions) {
  4714. applyOptions(instance, extendsOptions, deferredData, deferredWatch, deferredProvide, true);
  4715. }
  4716. // local mixins
  4717. if (mixins) {
  4718. applyMixins(instance, mixins, deferredData, deferredWatch, deferredProvide);
  4719. }
  4720. // options initialization order (to be consistent with Vue 2):
  4721. // - props (already done outside of this function)
  4722. // - inject
  4723. // - methods
  4724. // - data (deferred since it relies on `this` access)
  4725. // - computed
  4726. // - watch (deferred since it relies on `this` access)
  4727. if (injectOptions) {
  4728. if (shared.isArray(injectOptions)) {
  4729. for (let i = 0; i < injectOptions.length; i++) {
  4730. const key = injectOptions[i];
  4731. ctx[key] = inject(key);
  4732. }
  4733. }
  4734. else {
  4735. for (const key in injectOptions) {
  4736. const opt = injectOptions[key];
  4737. if (shared.isObject(opt)) {
  4738. ctx[key] = inject(opt.from || key, opt.default, true /* treat default function as factory */);
  4739. }
  4740. else {
  4741. ctx[key] = inject(opt);
  4742. }
  4743. }
  4744. }
  4745. }
  4746. if (methods) {
  4747. for (const key in methods) {
  4748. const methodHandler = methods[key];
  4749. if (shared.isFunction(methodHandler)) {
  4750. // In dev mode, we use the `createRenderContext` function to define methods to the proxy target,
  4751. // and those are read-only but reconfigurable, so it needs to be redefined here
  4752. {
  4753. ctx[key] = methodHandler.bind(publicThis);
  4754. }
  4755. }
  4756. }
  4757. }
  4758. if (!asMixin) {
  4759. if (deferredData.length) {
  4760. deferredData.forEach(dataFn => resolveData(instance, dataFn, publicThis));
  4761. }
  4762. if (dataOptions) {
  4763. // @ts-ignore dataOptions is not fully type safe
  4764. resolveData(instance, dataOptions, publicThis);
  4765. }
  4766. }
  4767. else if (dataOptions) {
  4768. deferredData.push(dataOptions);
  4769. }
  4770. if (computedOptions) {
  4771. for (const key in computedOptions) {
  4772. const opt = computedOptions[key];
  4773. const get = shared.isFunction(opt)
  4774. ? opt.bind(publicThis, publicThis)
  4775. : shared.isFunction(opt.get)
  4776. ? opt.get.bind(publicThis, publicThis)
  4777. : shared.NOOP;
  4778. const set = !shared.isFunction(opt) && shared.isFunction(opt.set)
  4779. ? opt.set.bind(publicThis)
  4780. : shared.NOOP;
  4781. const c = computed({
  4782. get,
  4783. set
  4784. });
  4785. Object.defineProperty(ctx, key, {
  4786. enumerable: true,
  4787. configurable: true,
  4788. get: () => c.value,
  4789. set: v => (c.value = v)
  4790. });
  4791. }
  4792. }
  4793. if (watchOptions) {
  4794. deferredWatch.push(watchOptions);
  4795. }
  4796. if (!asMixin && deferredWatch.length) {
  4797. deferredWatch.forEach(watchOptions => {
  4798. for (const key in watchOptions) {
  4799. createWatcher(watchOptions[key], ctx, publicThis, key);
  4800. }
  4801. });
  4802. }
  4803. if (provideOptions) {
  4804. deferredProvide.push(provideOptions);
  4805. }
  4806. if (!asMixin && deferredProvide.length) {
  4807. deferredProvide.forEach(provideOptions => {
  4808. const provides = shared.isFunction(provideOptions)
  4809. ? provideOptions.call(publicThis)
  4810. : provideOptions;
  4811. Reflect.ownKeys(provides).forEach(key => {
  4812. provide(key, provides[key]);
  4813. });
  4814. });
  4815. }
  4816. // asset options.
  4817. // To reduce memory usage, only components with mixins or extends will have
  4818. // resolved asset registry attached to instance.
  4819. if (asMixin) {
  4820. if (components) {
  4821. shared.extend(instance.components ||
  4822. (instance.components = shared.extend({}, instance.type.components)), components);
  4823. }
  4824. if (directives) {
  4825. shared.extend(instance.directives ||
  4826. (instance.directives = shared.extend({}, instance.type.directives)), directives);
  4827. }
  4828. }
  4829. // lifecycle options
  4830. if (!asMixin) {
  4831. callSyncHook('created', "c" /* CREATED */, options, instance, globalMixins);
  4832. }
  4833. if (beforeMount) {
  4834. onBeforeMount(beforeMount.bind(publicThis));
  4835. }
  4836. if (mounted) {
  4837. onMounted(mounted.bind(publicThis));
  4838. }
  4839. if (beforeUpdate) {
  4840. onBeforeUpdate(beforeUpdate.bind(publicThis));
  4841. }
  4842. if (updated) {
  4843. onUpdated(updated.bind(publicThis));
  4844. }
  4845. if (activated) {
  4846. onActivated(activated.bind(publicThis));
  4847. }
  4848. if (deactivated) {
  4849. onDeactivated(deactivated.bind(publicThis));
  4850. }
  4851. if (errorCaptured) {
  4852. onErrorCaptured(errorCaptured.bind(publicThis));
  4853. }
  4854. if (renderTracked) {
  4855. onRenderTracked(renderTracked.bind(publicThis));
  4856. }
  4857. if (renderTriggered) {
  4858. onRenderTriggered(renderTriggered.bind(publicThis));
  4859. }
  4860. if (beforeUnmount) {
  4861. onBeforeUnmount(beforeUnmount.bind(publicThis));
  4862. }
  4863. if (unmounted) {
  4864. onUnmounted(unmounted.bind(publicThis));
  4865. }
  4866. if (shared.isArray(expose)) {
  4867. if (!asMixin) {
  4868. if (expose.length) {
  4869. const exposed = instance.exposed || (instance.exposed = reactivity.proxyRefs({}));
  4870. expose.forEach(key => {
  4871. exposed[key] = reactivity.toRef(publicThis, key);
  4872. });
  4873. }
  4874. else if (!instance.exposed) {
  4875. instance.exposed = shared.EMPTY_OBJ;
  4876. }
  4877. }
  4878. }
  4879. }
  4880. function callSyncHook(name, type, options, instance, globalMixins) {
  4881. callHookFromMixins(name, type, globalMixins, instance);
  4882. const { extends: base, mixins } = options;
  4883. if (base) {
  4884. callHookFromExtends(name, type, base, instance);
  4885. }
  4886. if (mixins) {
  4887. callHookFromMixins(name, type, mixins, instance);
  4888. }
  4889. const selfHook = options[name];
  4890. if (selfHook) {
  4891. callWithAsyncErrorHandling(selfHook.bind(instance.proxy), instance, type);
  4892. }
  4893. }
  4894. function callHookFromExtends(name, type, base, instance) {
  4895. if (base.extends) {
  4896. callHookFromExtends(name, type, base.extends, instance);
  4897. }
  4898. const baseHook = base[name];
  4899. if (baseHook) {
  4900. callWithAsyncErrorHandling(baseHook.bind(instance.proxy), instance, type);
  4901. }
  4902. }
  4903. function callHookFromMixins(name, type, mixins, instance) {
  4904. for (let i = 0; i < mixins.length; i++) {
  4905. const chainedMixins = mixins[i].mixins;
  4906. if (chainedMixins) {
  4907. callHookFromMixins(name, type, chainedMixins, instance);
  4908. }
  4909. const fn = mixins[i][name];
  4910. if (fn) {
  4911. callWithAsyncErrorHandling(fn.bind(instance.proxy), instance, type);
  4912. }
  4913. }
  4914. }
  4915. function applyMixins(instance, mixins, deferredData, deferredWatch, deferredProvide) {
  4916. for (let i = 0; i < mixins.length; i++) {
  4917. applyOptions(instance, mixins[i], deferredData, deferredWatch, deferredProvide, true);
  4918. }
  4919. }
  4920. function resolveData(instance, dataFn, publicThis) {
  4921. const data = dataFn.call(publicThis, publicThis);
  4922. if (!shared.isObject(data)) ;
  4923. else if (instance.data === shared.EMPTY_OBJ) {
  4924. instance.data = reactivity.reactive(data);
  4925. }
  4926. else {
  4927. // existing data: this is a mixin or extends.
  4928. shared.extend(instance.data, data);
  4929. }
  4930. }
  4931. function createWatcher(raw, ctx, publicThis, key) {
  4932. const getter = key.includes('.')
  4933. ? createPathGetter(publicThis, key)
  4934. : () => publicThis[key];
  4935. if (shared.isString(raw)) {
  4936. const handler = ctx[raw];
  4937. if (shared.isFunction(handler)) {
  4938. watch(getter, handler);
  4939. }
  4940. }
  4941. else if (shared.isFunction(raw)) {
  4942. watch(getter, raw.bind(publicThis));
  4943. }
  4944. else if (shared.isObject(raw)) {
  4945. if (shared.isArray(raw)) {
  4946. raw.forEach(r => createWatcher(r, ctx, publicThis, key));
  4947. }
  4948. else {
  4949. const handler = shared.isFunction(raw.handler)
  4950. ? raw.handler.bind(publicThis)
  4951. : ctx[raw.handler];
  4952. if (shared.isFunction(handler)) {
  4953. watch(getter, handler, raw);
  4954. }
  4955. }
  4956. }
  4957. else ;
  4958. }
  4959. function createPathGetter(ctx, path) {
  4960. const segments = path.split('.');
  4961. return () => {
  4962. let cur = ctx;
  4963. for (let i = 0; i < segments.length && cur; i++) {
  4964. cur = cur[segments[i]];
  4965. }
  4966. return cur;
  4967. };
  4968. }
  4969. function resolveMergedOptions(instance) {
  4970. const raw = instance.type;
  4971. const { __merged, mixins, extends: extendsOptions } = raw;
  4972. if (__merged)
  4973. return __merged;
  4974. const globalMixins = instance.appContext.mixins;
  4975. if (!globalMixins.length && !mixins && !extendsOptions)
  4976. return raw;
  4977. const options = {};
  4978. globalMixins.forEach(m => mergeOptions(options, m, instance));
  4979. mergeOptions(options, raw, instance);
  4980. return (raw.__merged = options);
  4981. }
  4982. function mergeOptions(to, from, instance) {
  4983. const strats = instance.appContext.config.optionMergeStrategies;
  4984. const { mixins, extends: extendsOptions } = from;
  4985. extendsOptions && mergeOptions(to, extendsOptions, instance);
  4986. mixins &&
  4987. mixins.forEach((m) => mergeOptions(to, m, instance));
  4988. for (const key in from) {
  4989. if (strats && shared.hasOwn(strats, key)) {
  4990. to[key] = strats[key](to[key], from[key], instance.proxy, key);
  4991. }
  4992. else {
  4993. to[key] = from[key];
  4994. }
  4995. }
  4996. }
  4997. /**
  4998. * #2437 In Vue 3, functional components do not have a public instance proxy but
  4999. * they exist in the internal parent chain. For code that relies on traversing
  5000. * public $parent chains, skip functional ones and go to the parent instead.
  5001. */
  5002. const getPublicInstance = (i) => {
  5003. if (!i)
  5004. return null;
  5005. if (isStatefulComponent(i))
  5006. return i.exposed ? i.exposed : i.proxy;
  5007. return getPublicInstance(i.parent);
  5008. };
  5009. const publicPropertiesMap = shared.extend(Object.create(null), {
  5010. $: i => i,
  5011. $el: i => i.vnode.el,
  5012. $data: i => i.data,
  5013. $props: i => (i.props),
  5014. $attrs: i => (i.attrs),
  5015. $slots: i => (i.slots),
  5016. $refs: i => (i.refs),
  5017. $parent: i => getPublicInstance(i.parent),
  5018. $root: i => getPublicInstance(i.root),
  5019. $emit: i => i.emit,
  5020. $options: i => (resolveMergedOptions(i) ),
  5021. $forceUpdate: i => () => queueJob(i.update),
  5022. $nextTick: i => nextTick.bind(i.proxy),
  5023. $watch: i => (instanceWatch.bind(i) )
  5024. });
  5025. const PublicInstanceProxyHandlers = {
  5026. get({ _: instance }, key) {
  5027. const { ctx, setupState, data, props, accessCache, type, appContext } = instance;
  5028. // let @vue/reactivity know it should never observe Vue public instances.
  5029. if (key === "__v_skip" /* SKIP */) {
  5030. return true;
  5031. }
  5032. // data / props / ctx
  5033. // This getter gets called for every property access on the render context
  5034. // during render and is a major hotspot. The most expensive part of this
  5035. // is the multiple hasOwn() calls. It's much faster to do a simple property
  5036. // access on a plain object, so we use an accessCache object (with null
  5037. // prototype) to memoize what access type a key corresponds to.
  5038. let normalizedProps;
  5039. if (key[0] !== '$') {
  5040. const n = accessCache[key];
  5041. if (n !== undefined) {
  5042. switch (n) {
  5043. case 0 /* SETUP */:
  5044. return setupState[key];
  5045. case 1 /* DATA */:
  5046. return data[key];
  5047. case 3 /* CONTEXT */:
  5048. return ctx[key];
  5049. case 2 /* PROPS */:
  5050. return props[key];
  5051. // default: just fallthrough
  5052. }
  5053. }
  5054. else if (setupState !== shared.EMPTY_OBJ && shared.hasOwn(setupState, key)) {
  5055. accessCache[key] = 0 /* SETUP */;
  5056. return setupState[key];
  5057. }
  5058. else if (data !== shared.EMPTY_OBJ && shared.hasOwn(data, key)) {
  5059. accessCache[key] = 1 /* DATA */;
  5060. return data[key];
  5061. }
  5062. else if (
  5063. // only cache other properties when instance has declared (thus stable)
  5064. // props
  5065. (normalizedProps = instance.propsOptions[0]) &&
  5066. shared.hasOwn(normalizedProps, key)) {
  5067. accessCache[key] = 2 /* PROPS */;
  5068. return props[key];
  5069. }
  5070. else if (ctx !== shared.EMPTY_OBJ && shared.hasOwn(ctx, key)) {
  5071. accessCache[key] = 3 /* CONTEXT */;
  5072. return ctx[key];
  5073. }
  5074. else if (!isInBeforeCreate) {
  5075. accessCache[key] = 4 /* OTHER */;
  5076. }
  5077. }
  5078. const publicGetter = publicPropertiesMap[key];
  5079. let cssModule, globalProperties;
  5080. // public $xxx properties
  5081. if (publicGetter) {
  5082. if (key === '$attrs') {
  5083. reactivity.track(instance, "get" /* GET */, key);
  5084. }
  5085. return publicGetter(instance);
  5086. }
  5087. else if (
  5088. // css module (injected by vue-loader)
  5089. (cssModule = type.__cssModules) &&
  5090. (cssModule = cssModule[key])) {
  5091. return cssModule;
  5092. }
  5093. else if (ctx !== shared.EMPTY_OBJ && shared.hasOwn(ctx, key)) {
  5094. // user may set custom properties to `this` that start with `$`
  5095. accessCache[key] = 3 /* CONTEXT */;
  5096. return ctx[key];
  5097. }
  5098. else if (
  5099. // global properties
  5100. ((globalProperties = appContext.config.globalProperties),
  5101. shared.hasOwn(globalProperties, key))) {
  5102. return globalProperties[key];
  5103. }
  5104. else ;
  5105. },
  5106. set({ _: instance }, key, value) {
  5107. const { data, setupState, ctx } = instance;
  5108. if (setupState !== shared.EMPTY_OBJ && shared.hasOwn(setupState, key)) {
  5109. setupState[key] = value;
  5110. }
  5111. else if (data !== shared.EMPTY_OBJ && shared.hasOwn(data, key)) {
  5112. data[key] = value;
  5113. }
  5114. else if (shared.hasOwn(instance.props, key)) {
  5115. return false;
  5116. }
  5117. if (key[0] === '$' && key.slice(1) in instance) {
  5118. return false;
  5119. }
  5120. else {
  5121. {
  5122. ctx[key] = value;
  5123. }
  5124. }
  5125. return true;
  5126. },
  5127. has({ _: { data, setupState, accessCache, ctx, appContext, propsOptions } }, key) {
  5128. let normalizedProps;
  5129. return (accessCache[key] !== undefined ||
  5130. (data !== shared.EMPTY_OBJ && shared.hasOwn(data, key)) ||
  5131. (setupState !== shared.EMPTY_OBJ && shared.hasOwn(setupState, key)) ||
  5132. ((normalizedProps = propsOptions[0]) && shared.hasOwn(normalizedProps, key)) ||
  5133. shared.hasOwn(ctx, key) ||
  5134. shared.hasOwn(publicPropertiesMap, key) ||
  5135. shared.hasOwn(appContext.config.globalProperties, key));
  5136. }
  5137. };
  5138. const RuntimeCompiledPublicInstanceProxyHandlers = shared.extend({}, PublicInstanceProxyHandlers, {
  5139. get(target, key) {
  5140. // fast path for unscopables when using `with` block
  5141. if (key === Symbol.unscopables) {
  5142. return;
  5143. }
  5144. return PublicInstanceProxyHandlers.get(target, key, target);
  5145. },
  5146. has(_, key) {
  5147. const has = key[0] !== '_' && !shared.isGloballyWhitelisted(key);
  5148. return has;
  5149. }
  5150. });
  5151. const emptyAppContext = createAppContext();
  5152. let uid$1 = 0;
  5153. function createComponentInstance(vnode, parent, suspense) {
  5154. const type = vnode.type;
  5155. // inherit parent app context - or - if root, adopt from root vnode
  5156. const appContext = (parent ? parent.appContext : vnode.appContext) || emptyAppContext;
  5157. const instance = {
  5158. uid: uid$1++,
  5159. vnode,
  5160. type,
  5161. parent,
  5162. appContext,
  5163. root: null,
  5164. next: null,
  5165. subTree: null,
  5166. update: null,
  5167. render: null,
  5168. proxy: null,
  5169. exposed: null,
  5170. withProxy: null,
  5171. effects: null,
  5172. provides: parent ? parent.provides : Object.create(appContext.provides),
  5173. accessCache: null,
  5174. renderCache: [],
  5175. // local resovled assets
  5176. components: null,
  5177. directives: null,
  5178. // resolved props and emits options
  5179. propsOptions: normalizePropsOptions(type, appContext),
  5180. emitsOptions: normalizeEmitsOptions(type, appContext),
  5181. // emit
  5182. emit: null,
  5183. emitted: null,
  5184. // state
  5185. ctx: shared.EMPTY_OBJ,
  5186. data: shared.EMPTY_OBJ,
  5187. props: shared.EMPTY_OBJ,
  5188. attrs: shared.EMPTY_OBJ,
  5189. slots: shared.EMPTY_OBJ,
  5190. refs: shared.EMPTY_OBJ,
  5191. setupState: shared.EMPTY_OBJ,
  5192. setupContext: null,
  5193. // suspense related
  5194. suspense,
  5195. suspenseId: suspense ? suspense.pendingId : 0,
  5196. asyncDep: null,
  5197. asyncResolved: false,
  5198. // lifecycle hooks
  5199. // not using enums here because it results in computed properties
  5200. isMounted: false,
  5201. isUnmounted: false,
  5202. isDeactivated: false,
  5203. bc: null,
  5204. c: null,
  5205. bm: null,
  5206. m: null,
  5207. bu: null,
  5208. u: null,
  5209. um: null,
  5210. bum: null,
  5211. da: null,
  5212. a: null,
  5213. rtg: null,
  5214. rtc: null,
  5215. ec: null
  5216. };
  5217. {
  5218. instance.ctx = { _: instance };
  5219. }
  5220. instance.root = parent ? parent.root : instance;
  5221. instance.emit = emit.bind(null, instance);
  5222. return instance;
  5223. }
  5224. let currentInstance = null;
  5225. const getCurrentInstance = () => currentInstance || currentRenderingInstance;
  5226. const setCurrentInstance = (instance) => {
  5227. currentInstance = instance;
  5228. };
  5229. function isStatefulComponent(instance) {
  5230. return instance.vnode.shapeFlag & 4 /* STATEFUL_COMPONENT */;
  5231. }
  5232. let isInSSRComponentSetup = false;
  5233. function setupComponent(instance, isSSR = false) {
  5234. isInSSRComponentSetup = isSSR;
  5235. const { props, children } = instance.vnode;
  5236. const isStateful = isStatefulComponent(instance);
  5237. initProps(instance, props, isStateful, isSSR);
  5238. initSlots(instance, children);
  5239. const setupResult = isStateful
  5240. ? setupStatefulComponent(instance, isSSR)
  5241. : undefined;
  5242. isInSSRComponentSetup = false;
  5243. return setupResult;
  5244. }
  5245. function setupStatefulComponent(instance, isSSR) {
  5246. const Component = instance.type;
  5247. // 0. create render proxy property access cache
  5248. instance.accessCache = Object.create(null);
  5249. // 1. create public instance / render proxy
  5250. // also mark it raw so it's never observed
  5251. instance.proxy = new Proxy(instance.ctx, PublicInstanceProxyHandlers);
  5252. // 2. call setup()
  5253. const { setup } = Component;
  5254. if (setup) {
  5255. const setupContext = (instance.setupContext =
  5256. setup.length > 1 ? createSetupContext(instance) : null);
  5257. currentInstance = instance;
  5258. reactivity.pauseTracking();
  5259. const setupResult = callWithErrorHandling(setup, instance, 0 /* SETUP_FUNCTION */, [instance.props, setupContext]);
  5260. reactivity.resetTracking();
  5261. currentInstance = null;
  5262. if (shared.isPromise(setupResult)) {
  5263. if (isSSR) {
  5264. // return the promise so server-renderer can wait on it
  5265. return setupResult.then((resolvedResult) => {
  5266. handleSetupResult(instance, resolvedResult, isSSR);
  5267. });
  5268. }
  5269. else {
  5270. // async setup returned Promise.
  5271. // bail here and wait for re-entry.
  5272. instance.asyncDep = setupResult;
  5273. }
  5274. }
  5275. else {
  5276. handleSetupResult(instance, setupResult, isSSR);
  5277. }
  5278. }
  5279. else {
  5280. finishComponentSetup(instance, isSSR);
  5281. }
  5282. }
  5283. function handleSetupResult(instance, setupResult, isSSR) {
  5284. if (shared.isFunction(setupResult)) {
  5285. // setup returned an inline render function
  5286. if (instance.type.__ssrInlineRender) {
  5287. // when the function's name is `ssrRender` (compiled by SFC inline mode),
  5288. // set it as ssrRender instead.
  5289. instance.ssrRender = setupResult;
  5290. }
  5291. else {
  5292. instance.render = setupResult;
  5293. }
  5294. }
  5295. else if (shared.isObject(setupResult)) {
  5296. instance.setupState = reactivity.proxyRefs(setupResult);
  5297. }
  5298. else ;
  5299. finishComponentSetup(instance, isSSR);
  5300. }
  5301. let compile;
  5302. /**
  5303. * For runtime-dom to register the compiler.
  5304. * Note the exported method uses any to avoid d.ts relying on the compiler types.
  5305. */
  5306. function registerRuntimeCompiler(_compile) {
  5307. compile = _compile;
  5308. }
  5309. function finishComponentSetup(instance, isSSR) {
  5310. const Component = instance.type;
  5311. // template / render function normalization
  5312. if (isSSR) {
  5313. if (Component.render) {
  5314. instance.render = Component.render;
  5315. }
  5316. }
  5317. else if (!instance.render) {
  5318. // could be set from setup()
  5319. if (compile && Component.template && !Component.render) {
  5320. Component.render = compile(Component.template, {
  5321. isCustomElement: instance.appContext.config.isCustomElement,
  5322. delimiters: Component.delimiters
  5323. });
  5324. }
  5325. instance.render = (Component.render || shared.NOOP);
  5326. // for runtime-compiled render functions using `with` blocks, the render
  5327. // proxy used needs a different `has` handler which is more performant and
  5328. // also only allows a whitelist of globals to fallthrough.
  5329. if (instance.render._rc) {
  5330. instance.withProxy = new Proxy(instance.ctx, RuntimeCompiledPublicInstanceProxyHandlers);
  5331. }
  5332. }
  5333. // support for 2.x options
  5334. {
  5335. currentInstance = instance;
  5336. reactivity.pauseTracking();
  5337. applyOptions(instance, Component);
  5338. reactivity.resetTracking();
  5339. currentInstance = null;
  5340. }
  5341. }
  5342. function createSetupContext(instance) {
  5343. const expose = exposed => {
  5344. instance.exposed = reactivity.proxyRefs(exposed);
  5345. };
  5346. {
  5347. return {
  5348. attrs: instance.attrs,
  5349. slots: instance.slots,
  5350. emit: instance.emit,
  5351. expose
  5352. };
  5353. }
  5354. }
  5355. // record effects created during a component's setup() so that they can be
  5356. // stopped when the component unmounts
  5357. function recordInstanceBoundEffect(effect, instance = currentInstance) {
  5358. if (instance) {
  5359. (instance.effects || (instance.effects = [])).push(effect);
  5360. }
  5361. }
  5362. const classifyRE = /(?:^|[-_])(\w)/g;
  5363. const classify = (str) => str.replace(classifyRE, c => c.toUpperCase()).replace(/[-_]/g, '');
  5364. function getComponentName(Component) {
  5365. return shared.isFunction(Component)
  5366. ? Component.displayName || Component.name
  5367. : Component.name;
  5368. }
  5369. /* istanbul ignore next */
  5370. function formatComponentName(instance, Component, isRoot = false) {
  5371. let name = getComponentName(Component);
  5372. if (!name && Component.__file) {
  5373. const match = Component.__file.match(/([^/\\]+)\.\w+$/);
  5374. if (match) {
  5375. name = match[1];
  5376. }
  5377. }
  5378. if (!name && instance && instance.parent) {
  5379. // try to infer the name based on reverse resolution
  5380. const inferFromRegistry = (registry) => {
  5381. for (const key in registry) {
  5382. if (registry[key] === Component) {
  5383. return key;
  5384. }
  5385. }
  5386. };
  5387. name =
  5388. inferFromRegistry(instance.components ||
  5389. instance.parent.type.components) || inferFromRegistry(instance.appContext.components);
  5390. }
  5391. return name ? classify(name) : isRoot ? `App` : `Anonymous`;
  5392. }
  5393. function isClassComponent(value) {
  5394. return shared.isFunction(value) && '__vccOpts' in value;
  5395. }
  5396. function computed(getterOrOptions) {
  5397. const c = reactivity.computed(getterOrOptions);
  5398. recordInstanceBoundEffect(c.effect);
  5399. return c;
  5400. }
  5401. // implementation
  5402. function defineProps() {
  5403. return null;
  5404. }
  5405. // implementation
  5406. function defineEmit() {
  5407. return null;
  5408. }
  5409. function useContext() {
  5410. const i = getCurrentInstance();
  5411. return i.setupContext || (i.setupContext = createSetupContext(i));
  5412. }
  5413. // Actual implementation
  5414. function h(type, propsOrChildren, children) {
  5415. const l = arguments.length;
  5416. if (l === 2) {
  5417. if (shared.isObject(propsOrChildren) && !shared.isArray(propsOrChildren)) {
  5418. // single vnode without props
  5419. if (isVNode(propsOrChildren)) {
  5420. return createVNode(type, null, [propsOrChildren]);
  5421. }
  5422. // props without children
  5423. return createVNode(type, propsOrChildren);
  5424. }
  5425. else {
  5426. // omit props
  5427. return createVNode(type, null, propsOrChildren);
  5428. }
  5429. }
  5430. else {
  5431. if (l > 3) {
  5432. children = Array.prototype.slice.call(arguments, 2);
  5433. }
  5434. else if (l === 3 && isVNode(children)) {
  5435. children = [children];
  5436. }
  5437. return createVNode(type, propsOrChildren, children);
  5438. }
  5439. }
  5440. const ssrContextKey = Symbol(``);
  5441. const useSSRContext = () => {
  5442. {
  5443. const ctx = inject(ssrContextKey);
  5444. if (!ctx) {
  5445. warn(`Server rendering context not provided. Make sure to only call ` +
  5446. `useSSRContext() conditionally in the server build.`);
  5447. }
  5448. return ctx;
  5449. }
  5450. };
  5451. function initCustomFormatter() {
  5452. /* eslint-disable no-restricted-globals */
  5453. {
  5454. return;
  5455. }
  5456. }
  5457. /**
  5458. * Actual implementation
  5459. */
  5460. function renderList(source, renderItem) {
  5461. let ret;
  5462. if (shared.isArray(source) || shared.isString(source)) {
  5463. ret = new Array(source.length);
  5464. for (let i = 0, l = source.length; i < l; i++) {
  5465. ret[i] = renderItem(source[i], i);
  5466. }
  5467. }
  5468. else if (typeof source === 'number') {
  5469. ret = new Array(source);
  5470. for (let i = 0; i < source; i++) {
  5471. ret[i] = renderItem(i + 1, i);
  5472. }
  5473. }
  5474. else if (shared.isObject(source)) {
  5475. if (source[Symbol.iterator]) {
  5476. ret = Array.from(source, renderItem);
  5477. }
  5478. else {
  5479. const keys = Object.keys(source);
  5480. ret = new Array(keys.length);
  5481. for (let i = 0, l = keys.length; i < l; i++) {
  5482. const key = keys[i];
  5483. ret[i] = renderItem(source[key], key, i);
  5484. }
  5485. }
  5486. }
  5487. else {
  5488. ret = [];
  5489. }
  5490. return ret;
  5491. }
  5492. /**
  5493. * For prefixing keys in v-on="obj" with "on"
  5494. * @private
  5495. */
  5496. function toHandlers(obj) {
  5497. const ret = {};
  5498. for (const key in obj) {
  5499. ret[shared.toHandlerKey(key)] = obj[key];
  5500. }
  5501. return ret;
  5502. }
  5503. /**
  5504. * Compiler runtime helper for creating dynamic slots object
  5505. * @private
  5506. */
  5507. function createSlots(slots, dynamicSlots) {
  5508. for (let i = 0; i < dynamicSlots.length; i++) {
  5509. const slot = dynamicSlots[i];
  5510. // array of dynamic slot generated by <template v-for="..." #[...]>
  5511. if (shared.isArray(slot)) {
  5512. for (let j = 0; j < slot.length; j++) {
  5513. slots[slot[j].name] = slot[j].fn;
  5514. }
  5515. }
  5516. else if (slot) {
  5517. // conditional single slot generated by <template v-if="..." #foo>
  5518. slots[slot.name] = slot.fn;
  5519. }
  5520. }
  5521. return slots;
  5522. }
  5523. // Core API ------------------------------------------------------------------
  5524. const version = "3.0.6";
  5525. const _ssrUtils = {
  5526. createComponentInstance,
  5527. setupComponent,
  5528. renderComponentRoot,
  5529. setCurrentRenderingInstance,
  5530. isVNode,
  5531. normalizeVNode
  5532. };
  5533. /**
  5534. * SSR utils for \@vue/server-renderer. Only exposed in cjs builds.
  5535. * @internal
  5536. */
  5537. const ssrUtils = (_ssrUtils );
  5538. exports.customRef = reactivity.customRef;
  5539. exports.isProxy = reactivity.isProxy;
  5540. exports.isReactive = reactivity.isReactive;
  5541. exports.isReadonly = reactivity.isReadonly;
  5542. exports.isRef = reactivity.isRef;
  5543. exports.markRaw = reactivity.markRaw;
  5544. exports.proxyRefs = reactivity.proxyRefs;
  5545. exports.reactive = reactivity.reactive;
  5546. exports.readonly = reactivity.readonly;
  5547. exports.ref = reactivity.ref;
  5548. exports.shallowReactive = reactivity.shallowReactive;
  5549. exports.shallowReadonly = reactivity.shallowReadonly;
  5550. exports.shallowRef = reactivity.shallowRef;
  5551. exports.toRaw = reactivity.toRaw;
  5552. exports.toRef = reactivity.toRef;
  5553. exports.toRefs = reactivity.toRefs;
  5554. exports.triggerRef = reactivity.triggerRef;
  5555. exports.unref = reactivity.unref;
  5556. exports.camelize = shared.camelize;
  5557. exports.capitalize = shared.capitalize;
  5558. exports.toDisplayString = shared.toDisplayString;
  5559. exports.toHandlerKey = shared.toHandlerKey;
  5560. exports.BaseTransition = BaseTransition;
  5561. exports.Comment = Comment;
  5562. exports.Fragment = Fragment;
  5563. exports.KeepAlive = KeepAlive;
  5564. exports.Static = Static;
  5565. exports.Suspense = Suspense;
  5566. exports.Teleport = Teleport;
  5567. exports.Text = Text;
  5568. exports.callWithAsyncErrorHandling = callWithAsyncErrorHandling;
  5569. exports.callWithErrorHandling = callWithErrorHandling;
  5570. exports.cloneVNode = cloneVNode;
  5571. exports.computed = computed;
  5572. exports.createBlock = createBlock;
  5573. exports.createCommentVNode = createCommentVNode;
  5574. exports.createHydrationRenderer = createHydrationRenderer;
  5575. exports.createRenderer = createRenderer;
  5576. exports.createSlots = createSlots;
  5577. exports.createStaticVNode = createStaticVNode;
  5578. exports.createTextVNode = createTextVNode;
  5579. exports.createVNode = createVNode;
  5580. exports.defineAsyncComponent = defineAsyncComponent;
  5581. exports.defineComponent = defineComponent;
  5582. exports.defineEmit = defineEmit;
  5583. exports.defineProps = defineProps;
  5584. exports.getCurrentInstance = getCurrentInstance;
  5585. exports.getTransitionRawChildren = getTransitionRawChildren;
  5586. exports.h = h;
  5587. exports.handleError = handleError;
  5588. exports.initCustomFormatter = initCustomFormatter;
  5589. exports.inject = inject;
  5590. exports.isVNode = isVNode;
  5591. exports.mergeProps = mergeProps;
  5592. exports.nextTick = nextTick;
  5593. exports.onActivated = onActivated;
  5594. exports.onBeforeMount = onBeforeMount;
  5595. exports.onBeforeUnmount = onBeforeUnmount;
  5596. exports.onBeforeUpdate = onBeforeUpdate;
  5597. exports.onDeactivated = onDeactivated;
  5598. exports.onErrorCaptured = onErrorCaptured;
  5599. exports.onMounted = onMounted;
  5600. exports.onRenderTracked = onRenderTracked;
  5601. exports.onRenderTriggered = onRenderTriggered;
  5602. exports.onUnmounted = onUnmounted;
  5603. exports.onUpdated = onUpdated;
  5604. exports.openBlock = openBlock;
  5605. exports.popScopeId = popScopeId;
  5606. exports.provide = provide;
  5607. exports.pushScopeId = pushScopeId;
  5608. exports.queuePostFlushCb = queuePostFlushCb;
  5609. exports.registerRuntimeCompiler = registerRuntimeCompiler;
  5610. exports.renderList = renderList;
  5611. exports.renderSlot = renderSlot;
  5612. exports.resolveComponent = resolveComponent;
  5613. exports.resolveDirective = resolveDirective;
  5614. exports.resolveDynamicComponent = resolveDynamicComponent;
  5615. exports.resolveTransitionHooks = resolveTransitionHooks;
  5616. exports.setBlockTracking = setBlockTracking;
  5617. exports.setDevtoolsHook = setDevtoolsHook;
  5618. exports.setTransitionHooks = setTransitionHooks;
  5619. exports.ssrContextKey = ssrContextKey;
  5620. exports.ssrUtils = ssrUtils;
  5621. exports.toHandlers = toHandlers;
  5622. exports.transformVNodeArgs = transformVNodeArgs;
  5623. exports.useContext = useContext;
  5624. exports.useSSRContext = useSSRContext;
  5625. exports.useTransitionState = useTransitionState;
  5626. exports.version = version;
  5627. exports.warn = warn;
  5628. exports.watch = watch;
  5629. exports.watchEffect = watchEffect;
  5630. exports.withCtx = withCtx;
  5631. exports.withDirectives = withDirectives;
  5632. exports.withScopeId = withScopeId;