factory.js 159 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222
  1. 'use strict';
  2. module.exports = function weexFactory (exports, renderer) {
  3. /* */
  4. // these helpers produces better vm code in JS engines due to their
  5. // explicitness and function inlining
  6. function isUndef (v) {
  7. return v === undefined || v === null
  8. }
  9. function isDef (v) {
  10. return v !== undefined && v !== null
  11. }
  12. function isTrue (v) {
  13. return v === true
  14. }
  15. /**
  16. * Check if value is primitive
  17. */
  18. function isPrimitive (value) {
  19. return typeof value === 'string' || typeof value === 'number'
  20. }
  21. /**
  22. * Quick object check - this is primarily used to tell
  23. * Objects from primitive values when we know the value
  24. * is a JSON-compliant type.
  25. */
  26. function isObject (obj) {
  27. return obj !== null && typeof obj === 'object'
  28. }
  29. var toString = Object.prototype.toString;
  30. /**
  31. * Strict object type check. Only returns true
  32. * for plain JavaScript objects.
  33. */
  34. function isPlainObject (obj) {
  35. return toString.call(obj) === '[object Object]'
  36. }
  37. function isRegExp (v) {
  38. return toString.call(v) === '[object RegExp]'
  39. }
  40. /**
  41. * Convert a value to a string that is actually rendered.
  42. */
  43. function _toString (val) {
  44. return val == null
  45. ? ''
  46. : typeof val === 'object'
  47. ? JSON.stringify(val, null, 2)
  48. : String(val)
  49. }
  50. /**
  51. * Convert a input value to a number for persistence.
  52. * If the conversion fails, return original string.
  53. */
  54. function toNumber (val) {
  55. var n = parseFloat(val);
  56. return isNaN(n) ? val : n
  57. }
  58. /**
  59. * Make a map and return a function for checking if a key
  60. * is in that map.
  61. */
  62. function makeMap (
  63. str,
  64. expectsLowerCase
  65. ) {
  66. var map = Object.create(null);
  67. var list = str.split(',');
  68. for (var i = 0; i < list.length; i++) {
  69. map[list[i]] = true;
  70. }
  71. return expectsLowerCase
  72. ? function (val) { return map[val.toLowerCase()]; }
  73. : function (val) { return map[val]; }
  74. }
  75. /**
  76. * Check if a tag is a built-in tag.
  77. */
  78. var isBuiltInTag = makeMap('slot,component', true);
  79. /**
  80. * Remove an item from an array
  81. */
  82. function remove (arr, item) {
  83. if (arr.length) {
  84. var index = arr.indexOf(item);
  85. if (index > -1) {
  86. return arr.splice(index, 1)
  87. }
  88. }
  89. }
  90. /**
  91. * Check whether the object has the property.
  92. */
  93. var hasOwnProperty = Object.prototype.hasOwnProperty;
  94. function hasOwn (obj, key) {
  95. return hasOwnProperty.call(obj, key)
  96. }
  97. /**
  98. * Create a cached version of a pure function.
  99. */
  100. function cached (fn) {
  101. var cache = Object.create(null);
  102. return (function cachedFn (str) {
  103. var hit = cache[str];
  104. return hit || (cache[str] = fn(str))
  105. })
  106. }
  107. /**
  108. * Camelize a hyphen-delimited string.
  109. */
  110. var camelizeRE = /-(\w)/g;
  111. var camelize = cached(function (str) {
  112. return str.replace(camelizeRE, function (_, c) { return c ? c.toUpperCase() : ''; })
  113. });
  114. /**
  115. * Capitalize a string.
  116. */
  117. var capitalize = cached(function (str) {
  118. return str.charAt(0).toUpperCase() + str.slice(1)
  119. });
  120. /**
  121. * Hyphenate a camelCase string.
  122. */
  123. var hyphenateRE = /([^-])([A-Z])/g;
  124. var hyphenate = cached(function (str) {
  125. return str
  126. .replace(hyphenateRE, '$1-$2')
  127. .replace(hyphenateRE, '$1-$2')
  128. .toLowerCase()
  129. });
  130. /**
  131. * Simple bind, faster than native
  132. */
  133. function bind (fn, ctx) {
  134. function boundFn (a) {
  135. var l = arguments.length;
  136. return l
  137. ? l > 1
  138. ? fn.apply(ctx, arguments)
  139. : fn.call(ctx, a)
  140. : fn.call(ctx)
  141. }
  142. // record original fn length
  143. boundFn._length = fn.length;
  144. return boundFn
  145. }
  146. /**
  147. * Convert an Array-like object to a real Array.
  148. */
  149. function toArray (list, start) {
  150. start = start || 0;
  151. var i = list.length - start;
  152. var ret = new Array(i);
  153. while (i--) {
  154. ret[i] = list[i + start];
  155. }
  156. return ret
  157. }
  158. /**
  159. * Mix properties into target object.
  160. */
  161. function extend (to, _from) {
  162. for (var key in _from) {
  163. to[key] = _from[key];
  164. }
  165. return to
  166. }
  167. /**
  168. * Merge an Array of Objects into a single Object.
  169. */
  170. function toObject (arr) {
  171. var res = {};
  172. for (var i = 0; i < arr.length; i++) {
  173. if (arr[i]) {
  174. extend(res, arr[i]);
  175. }
  176. }
  177. return res
  178. }
  179. /**
  180. * Perform no operation.
  181. */
  182. function noop () {}
  183. /**
  184. * Always return false.
  185. */
  186. var no = function () { return false; };
  187. /**
  188. * Return same value
  189. */
  190. var identity = function (_) { return _; };
  191. /**
  192. * Generate a static keys string from compiler modules.
  193. */
  194. /**
  195. * Check if two values are loosely equal - that is,
  196. * if they are plain objects, do they have the same shape?
  197. */
  198. function looseEqual (a, b) {
  199. var isObjectA = isObject(a);
  200. var isObjectB = isObject(b);
  201. if (isObjectA && isObjectB) {
  202. try {
  203. return JSON.stringify(a) === JSON.stringify(b)
  204. } catch (e) {
  205. // possible circular reference
  206. return a === b
  207. }
  208. } else if (!isObjectA && !isObjectB) {
  209. return String(a) === String(b)
  210. } else {
  211. return false
  212. }
  213. }
  214. function looseIndexOf (arr, val) {
  215. for (var i = 0; i < arr.length; i++) {
  216. if (looseEqual(arr[i], val)) { return i }
  217. }
  218. return -1
  219. }
  220. /**
  221. * Ensure a function is called only once.
  222. */
  223. function once (fn) {
  224. var called = false;
  225. return function () {
  226. if (!called) {
  227. called = true;
  228. fn.apply(this, arguments);
  229. }
  230. }
  231. }
  232. var SSR_ATTR = 'data-server-rendered';
  233. var ASSET_TYPES = [
  234. 'component',
  235. 'directive',
  236. 'filter'
  237. ];
  238. var LIFECYCLE_HOOKS = [
  239. 'beforeCreate',
  240. 'created',
  241. 'beforeMount',
  242. 'mounted',
  243. 'beforeUpdate',
  244. 'updated',
  245. 'beforeDestroy',
  246. 'destroyed',
  247. 'activated',
  248. 'deactivated'
  249. ];
  250. /* */
  251. var config = ({
  252. /**
  253. * Option merge strategies (used in core/util/options)
  254. */
  255. optionMergeStrategies: Object.create(null),
  256. /**
  257. * Whether to suppress warnings.
  258. */
  259. silent: false,
  260. /**
  261. * Show production mode tip message on boot?
  262. */
  263. productionTip: process.env.NODE_ENV !== 'production',
  264. /**
  265. * Whether to enable devtools
  266. */
  267. devtools: process.env.NODE_ENV !== 'production',
  268. /**
  269. * Whether to record perf
  270. */
  271. performance: false,
  272. /**
  273. * Error handler for watcher errors
  274. */
  275. errorHandler: null,
  276. /**
  277. * Ignore certain custom elements
  278. */
  279. ignoredElements: [],
  280. /**
  281. * Custom user key aliases for v-on
  282. */
  283. keyCodes: Object.create(null),
  284. /**
  285. * Check if a tag is reserved so that it cannot be registered as a
  286. * component. This is platform-dependent and may be overwritten.
  287. */
  288. isReservedTag: no,
  289. /**
  290. * Check if an attribute is reserved so that it cannot be used as a component
  291. * prop. This is platform-dependent and may be overwritten.
  292. */
  293. isReservedAttr: no,
  294. /**
  295. * Check if a tag is an unknown element.
  296. * Platform-dependent.
  297. */
  298. isUnknownElement: no,
  299. /**
  300. * Get the namespace of an element
  301. */
  302. getTagNamespace: noop,
  303. /**
  304. * Parse the real tag name for the specific platform.
  305. */
  306. parsePlatformTagName: identity,
  307. /**
  308. * Check if an attribute must be bound using property, e.g. value
  309. * Platform-dependent.
  310. */
  311. mustUseProp: no,
  312. /**
  313. * Exposed for legacy reasons
  314. */
  315. _lifecycleHooks: LIFECYCLE_HOOKS
  316. });
  317. /* */
  318. var emptyObject = Object.freeze({});
  319. /**
  320. * Check if a string starts with $ or _
  321. */
  322. function isReserved (str) {
  323. var c = (str + '').charCodeAt(0);
  324. return c === 0x24 || c === 0x5F
  325. }
  326. /**
  327. * Define a property.
  328. */
  329. function def (obj, key, val, enumerable) {
  330. Object.defineProperty(obj, key, {
  331. value: val,
  332. enumerable: !!enumerable,
  333. writable: true,
  334. configurable: true
  335. });
  336. }
  337. /**
  338. * Parse simple path.
  339. */
  340. var bailRE = /[^\w.$]/;
  341. function parsePath (path) {
  342. if (bailRE.test(path)) {
  343. return
  344. }
  345. var segments = path.split('.');
  346. return function (obj) {
  347. for (var i = 0; i < segments.length; i++) {
  348. if (!obj) { return }
  349. obj = obj[segments[i]];
  350. }
  351. return obj
  352. }
  353. }
  354. var warn = noop;
  355. var tip = noop;
  356. var formatComponentName;
  357. if (process.env.NODE_ENV !== 'production') {
  358. var hasConsole = typeof console !== 'undefined';
  359. var classifyRE = /(?:^|[-_])(\w)/g;
  360. var classify = function (str) { return str
  361. .replace(classifyRE, function (c) { return c.toUpperCase(); })
  362. .replace(/[-_]/g, ''); };
  363. warn = function (msg, vm) {
  364. if (hasConsole && (!config.silent)) {
  365. console.error("[Vue warn]: " + msg + (
  366. vm ? generateComponentTrace(vm) : ''
  367. ));
  368. }
  369. };
  370. tip = function (msg, vm) {
  371. if (hasConsole && (!config.silent)) {
  372. console.warn("[Vue tip]: " + msg + (
  373. vm ? generateComponentTrace(vm) : ''
  374. ));
  375. }
  376. };
  377. formatComponentName = function (vm, includeFile) {
  378. if (vm.$root === vm) {
  379. return '<Root>'
  380. }
  381. var name = typeof vm === 'string'
  382. ? vm
  383. : typeof vm === 'function' && vm.options
  384. ? vm.options.name
  385. : vm._isVue
  386. ? vm.$options.name || vm.$options._componentTag
  387. : vm.name;
  388. var file = vm._isVue && vm.$options.__file;
  389. if (!name && file) {
  390. var match = file.match(/([^/\\]+)\.vue$/);
  391. name = match && match[1];
  392. }
  393. return (
  394. (name ? ("<" + (classify(name)) + ">") : "<Anonymous>") +
  395. (file && includeFile !== false ? (" at " + file) : '')
  396. )
  397. };
  398. var repeat = function (str, n) {
  399. var res = '';
  400. while (n) {
  401. if (n % 2 === 1) { res += str; }
  402. if (n > 1) { str += str; }
  403. n >>= 1;
  404. }
  405. return res
  406. };
  407. var generateComponentTrace = function (vm) {
  408. if (vm._isVue && vm.$parent) {
  409. var tree = [];
  410. var currentRecursiveSequence = 0;
  411. while (vm) {
  412. if (tree.length > 0) {
  413. var last = tree[tree.length - 1];
  414. if (last.constructor === vm.constructor) {
  415. currentRecursiveSequence++;
  416. vm = vm.$parent;
  417. continue
  418. } else if (currentRecursiveSequence > 0) {
  419. tree[tree.length - 1] = [last, currentRecursiveSequence];
  420. currentRecursiveSequence = 0;
  421. }
  422. }
  423. tree.push(vm);
  424. vm = vm.$parent;
  425. }
  426. return '\n\nfound in\n\n' + tree
  427. .map(function (vm, i) { return ("" + (i === 0 ? '---> ' : repeat(' ', 5 + i * 2)) + (Array.isArray(vm)
  428. ? ((formatComponentName(vm[0])) + "... (" + (vm[1]) + " recursive calls)")
  429. : formatComponentName(vm))); })
  430. .join('\n')
  431. } else {
  432. return ("\n\n(found in " + (formatComponentName(vm)) + ")")
  433. }
  434. };
  435. }
  436. function handleError (err, vm, info) {
  437. if (config.errorHandler) {
  438. config.errorHandler.call(null, err, vm, info);
  439. } else {
  440. if (process.env.NODE_ENV !== 'production') {
  441. warn(("Error in " + info + ": \"" + (err.toString()) + "\""), vm);
  442. }
  443. /* istanbul ignore else */
  444. if (inBrowser && typeof console !== 'undefined') {
  445. console.error(err);
  446. } else {
  447. throw err
  448. }
  449. }
  450. }
  451. /* */
  452. /* globals MutationObserver */
  453. // can we use __proto__?
  454. var hasProto = '__proto__' in {};
  455. // Browser environment sniffing
  456. var inBrowser = typeof window !== 'undefined';
  457. var UA = inBrowser && window.navigator.userAgent.toLowerCase();
  458. var isIE = UA && /msie|trident/.test(UA);
  459. var isIE9 = UA && UA.indexOf('msie 9.0') > 0;
  460. var isEdge = UA && UA.indexOf('edge/') > 0;
  461. var isAndroid = UA && UA.indexOf('android') > 0;
  462. var isIOS = UA && /iphone|ipad|ipod|ios/.test(UA);
  463. var isChrome = UA && /chrome\/\d+/.test(UA) && !isEdge;
  464. var supportsPassive = false;
  465. if (inBrowser) {
  466. try {
  467. var opts = {};
  468. Object.defineProperty(opts, 'passive', ({
  469. get: function get () {
  470. /* istanbul ignore next */
  471. supportsPassive = true;
  472. }
  473. } )); // https://github.com/facebook/flow/issues/285
  474. window.addEventListener('test-passive', null, opts);
  475. } catch (e) {}
  476. }
  477. // this needs to be lazy-evaled because vue may be required before
  478. // vue-server-renderer can set VUE_ENV
  479. var _isServer;
  480. var isServerRendering = function () {
  481. if (_isServer === undefined) {
  482. /* istanbul ignore if */
  483. if (!inBrowser && typeof global !== 'undefined') {
  484. // detect presence of vue-server-renderer and avoid
  485. // Webpack shimming the process
  486. _isServer = global['process'].env.VUE_ENV === 'server';
  487. } else {
  488. _isServer = false;
  489. }
  490. }
  491. return _isServer
  492. };
  493. // detect devtools
  494. var devtools = inBrowser && window.__VUE_DEVTOOLS_GLOBAL_HOOK__;
  495. /* istanbul ignore next */
  496. function isNative (Ctor) {
  497. return typeof Ctor === 'function' && /native code/.test(Ctor.toString())
  498. }
  499. var hasSymbol =
  500. typeof Symbol !== 'undefined' && isNative(Symbol) &&
  501. typeof Reflect !== 'undefined' && isNative(Reflect.ownKeys);
  502. /**
  503. * Defer a task to execute it asynchronously.
  504. */
  505. var nextTick = (function () {
  506. var callbacks = [];
  507. var pending = false;
  508. var timerFunc;
  509. function nextTickHandler () {
  510. pending = false;
  511. var copies = callbacks.slice(0);
  512. callbacks.length = 0;
  513. for (var i = 0; i < copies.length; i++) {
  514. copies[i]();
  515. }
  516. }
  517. // the nextTick behavior leverages the microtask queue, which can be accessed
  518. // via either native Promise.then or MutationObserver.
  519. // MutationObserver has wider support, however it is seriously bugged in
  520. // UIWebView in iOS >= 9.3.3 when triggered in touch event handlers. It
  521. // completely stops working after triggering a few times... so, if native
  522. // Promise is available, we will use it:
  523. /* istanbul ignore if */
  524. if (typeof Promise !== 'undefined' && isNative(Promise)) {
  525. var p = Promise.resolve();
  526. var logError = function (err) { console.error(err); };
  527. timerFunc = function () {
  528. p.then(nextTickHandler).catch(logError);
  529. // in problematic UIWebViews, Promise.then doesn't completely break, but
  530. // it can get stuck in a weird state where callbacks are pushed into the
  531. // microtask queue but the queue isn't being flushed, until the browser
  532. // needs to do some other work, e.g. handle a timer. Therefore we can
  533. // "force" the microtask queue to be flushed by adding an empty timer.
  534. if (isIOS) { setTimeout(noop); }
  535. };
  536. } else if (typeof MutationObserver !== 'undefined' && (
  537. isNative(MutationObserver) ||
  538. // PhantomJS and iOS 7.x
  539. MutationObserver.toString() === '[object MutationObserverConstructor]'
  540. )) {
  541. // use MutationObserver where native Promise is not available,
  542. // e.g. PhantomJS IE11, iOS7, Android 4.4
  543. var counter = 1;
  544. var observer = new MutationObserver(nextTickHandler);
  545. var textNode = document.createTextNode(String(counter));
  546. observer.observe(textNode, {
  547. characterData: true
  548. });
  549. timerFunc = function () {
  550. counter = (counter + 1) % 2;
  551. textNode.data = String(counter);
  552. };
  553. } else {
  554. // fallback to setTimeout
  555. /* istanbul ignore next */
  556. timerFunc = function () {
  557. setTimeout(nextTickHandler, 0);
  558. };
  559. }
  560. return function queueNextTick (cb, ctx) {
  561. var _resolve;
  562. callbacks.push(function () {
  563. if (cb) {
  564. try {
  565. cb.call(ctx);
  566. } catch (e) {
  567. handleError(e, ctx, 'nextTick');
  568. }
  569. } else if (_resolve) {
  570. _resolve(ctx);
  571. }
  572. });
  573. if (!pending) {
  574. pending = true;
  575. timerFunc();
  576. }
  577. if (!cb && typeof Promise !== 'undefined') {
  578. return new Promise(function (resolve, reject) {
  579. _resolve = resolve;
  580. })
  581. }
  582. }
  583. })();
  584. var _Set;
  585. /* istanbul ignore if */
  586. if (typeof Set !== 'undefined' && isNative(Set)) {
  587. // use native Set when available.
  588. _Set = Set;
  589. } else {
  590. // a non-standard Set polyfill that only works with primitive keys.
  591. _Set = (function () {
  592. function Set () {
  593. this.set = Object.create(null);
  594. }
  595. Set.prototype.has = function has (key) {
  596. return this.set[key] === true
  597. };
  598. Set.prototype.add = function add (key) {
  599. this.set[key] = true;
  600. };
  601. Set.prototype.clear = function clear () {
  602. this.set = Object.create(null);
  603. };
  604. return Set;
  605. }());
  606. }
  607. /* */
  608. var uid$1 = 0;
  609. /**
  610. * A dep is an observable that can have multiple
  611. * directives subscribing to it.
  612. */
  613. var Dep = function Dep () {
  614. this.id = uid$1++;
  615. this.subs = [];
  616. };
  617. Dep.prototype.addSub = function addSub (sub) {
  618. this.subs.push(sub);
  619. };
  620. Dep.prototype.removeSub = function removeSub (sub) {
  621. remove(this.subs, sub);
  622. };
  623. Dep.prototype.depend = function depend () {
  624. if (Dep.target) {
  625. Dep.target.addDep(this);
  626. }
  627. };
  628. Dep.prototype.notify = function notify () {
  629. // stabilize the subscriber list first
  630. var subs = this.subs.slice();
  631. for (var i = 0, l = subs.length; i < l; i++) {
  632. subs[i].update();
  633. }
  634. };
  635. // the current target watcher being evaluated.
  636. // this is globally unique because there could be only one
  637. // watcher being evaluated at any time.
  638. Dep.target = null;
  639. var targetStack = [];
  640. function pushTarget (_target) {
  641. if (Dep.target) { targetStack.push(Dep.target); }
  642. Dep.target = _target;
  643. }
  644. function popTarget () {
  645. Dep.target = targetStack.pop();
  646. }
  647. /*
  648. * not type checking this file because flow doesn't play well with
  649. * dynamically accessing methods on Array prototype
  650. */
  651. var arrayProto = Array.prototype;
  652. var arrayMethods = Object.create(arrayProto);[
  653. 'push',
  654. 'pop',
  655. 'shift',
  656. 'unshift',
  657. 'splice',
  658. 'sort',
  659. 'reverse'
  660. ]
  661. .forEach(function (method) {
  662. // cache original method
  663. var original = arrayProto[method];
  664. def(arrayMethods, method, function mutator () {
  665. var arguments$1 = arguments;
  666. // avoid leaking arguments:
  667. // http://jsperf.com/closure-with-arguments
  668. var i = arguments.length;
  669. var args = new Array(i);
  670. while (i--) {
  671. args[i] = arguments$1[i];
  672. }
  673. var result = original.apply(this, args);
  674. var ob = this.__ob__;
  675. var inserted;
  676. switch (method) {
  677. case 'push':
  678. inserted = args;
  679. break
  680. case 'unshift':
  681. inserted = args;
  682. break
  683. case 'splice':
  684. inserted = args.slice(2);
  685. break
  686. }
  687. if (inserted) { ob.observeArray(inserted); }
  688. // notify change
  689. ob.dep.notify();
  690. return result
  691. });
  692. });
  693. /* */
  694. var arrayKeys = Object.getOwnPropertyNames(arrayMethods);
  695. /**
  696. * By default, when a reactive property is set, the new value is
  697. * also converted to become reactive. However when passing down props,
  698. * we don't want to force conversion because the value may be a nested value
  699. * under a frozen data structure. Converting it would defeat the optimization.
  700. */
  701. var observerState = {
  702. shouldConvert: true,
  703. isSettingProps: false
  704. };
  705. /**
  706. * Observer class that are attached to each observed
  707. * object. Once attached, the observer converts target
  708. * object's property keys into getter/setters that
  709. * collect dependencies and dispatches updates.
  710. */
  711. var Observer = function Observer (value) {
  712. this.value = value;
  713. this.dep = new Dep();
  714. this.vmCount = 0;
  715. def(value, '__ob__', this);
  716. if (Array.isArray(value)) {
  717. var augment = hasProto
  718. ? protoAugment
  719. : copyAugment;
  720. augment(value, arrayMethods, arrayKeys);
  721. this.observeArray(value);
  722. } else {
  723. this.walk(value);
  724. }
  725. };
  726. /**
  727. * Walk through each property and convert them into
  728. * getter/setters. This method should only be called when
  729. * value type is Object.
  730. */
  731. Observer.prototype.walk = function walk (obj) {
  732. var keys = Object.keys(obj);
  733. for (var i = 0; i < keys.length; i++) {
  734. defineReactive$$1(obj, keys[i], obj[keys[i]]);
  735. }
  736. };
  737. /**
  738. * Observe a list of Array items.
  739. */
  740. Observer.prototype.observeArray = function observeArray (items) {
  741. for (var i = 0, l = items.length; i < l; i++) {
  742. observe(items[i]);
  743. }
  744. };
  745. // helpers
  746. /**
  747. * Augment an target Object or Array by intercepting
  748. * the prototype chain using __proto__
  749. */
  750. function protoAugment (target, src) {
  751. /* eslint-disable no-proto */
  752. target.__proto__ = src;
  753. /* eslint-enable no-proto */
  754. }
  755. /**
  756. * Augment an target Object or Array by defining
  757. * hidden properties.
  758. */
  759. /* istanbul ignore next */
  760. function copyAugment (target, src, keys) {
  761. for (var i = 0, l = keys.length; i < l; i++) {
  762. var key = keys[i];
  763. def(target, key, src[key]);
  764. }
  765. }
  766. /**
  767. * Attempt to create an observer instance for a value,
  768. * returns the new observer if successfully observed,
  769. * or the existing observer if the value already has one.
  770. */
  771. function observe (value, asRootData) {
  772. if (!isObject(value)) {
  773. return
  774. }
  775. var ob;
  776. if (hasOwn(value, '__ob__') && value.__ob__ instanceof Observer) {
  777. ob = value.__ob__;
  778. } else if (
  779. observerState.shouldConvert &&
  780. !isServerRendering() &&
  781. (Array.isArray(value) || isPlainObject(value)) &&
  782. Object.isExtensible(value) &&
  783. !value._isVue
  784. ) {
  785. ob = new Observer(value);
  786. }
  787. if (asRootData && ob) {
  788. ob.vmCount++;
  789. }
  790. return ob
  791. }
  792. /**
  793. * Define a reactive property on an Object.
  794. */
  795. function defineReactive$$1 (
  796. obj,
  797. key,
  798. val,
  799. customSetter
  800. ) {
  801. var dep = new Dep();
  802. var property = Object.getOwnPropertyDescriptor(obj, key);
  803. if (property && property.configurable === false) {
  804. return
  805. }
  806. // cater for pre-defined getter/setters
  807. var getter = property && property.get;
  808. var setter = property && property.set;
  809. var childOb = observe(val);
  810. Object.defineProperty(obj, key, {
  811. enumerable: true,
  812. configurable: true,
  813. get: function reactiveGetter () {
  814. var value = getter ? getter.call(obj) : val;
  815. if (Dep.target) {
  816. dep.depend();
  817. if (childOb) {
  818. childOb.dep.depend();
  819. }
  820. if (Array.isArray(value)) {
  821. dependArray(value);
  822. }
  823. }
  824. return value
  825. },
  826. set: function reactiveSetter (newVal) {
  827. var value = getter ? getter.call(obj) : val;
  828. /* eslint-disable no-self-compare */
  829. if (newVal === value || (newVal !== newVal && value !== value)) {
  830. return
  831. }
  832. /* eslint-enable no-self-compare */
  833. if (process.env.NODE_ENV !== 'production' && customSetter) {
  834. customSetter();
  835. }
  836. if (setter) {
  837. setter.call(obj, newVal);
  838. } else {
  839. val = newVal;
  840. }
  841. childOb = observe(newVal);
  842. dep.notify();
  843. }
  844. });
  845. }
  846. /**
  847. * Set a property on an object. Adds the new property and
  848. * triggers change notification if the property doesn't
  849. * already exist.
  850. */
  851. function set (target, key, val) {
  852. if (Array.isArray(target) && typeof key === 'number') {
  853. target.length = Math.max(target.length, key);
  854. target.splice(key, 1, val);
  855. return val
  856. }
  857. if (hasOwn(target, key)) {
  858. target[key] = val;
  859. return val
  860. }
  861. var ob = (target ).__ob__;
  862. if (target._isVue || (ob && ob.vmCount)) {
  863. process.env.NODE_ENV !== 'production' && warn(
  864. 'Avoid adding reactive properties to a Vue instance or its root $data ' +
  865. 'at runtime - declare it upfront in the data option.'
  866. );
  867. return val
  868. }
  869. if (!ob) {
  870. target[key] = val;
  871. return val
  872. }
  873. defineReactive$$1(ob.value, key, val);
  874. ob.dep.notify();
  875. return val
  876. }
  877. /**
  878. * Delete a property and trigger change if necessary.
  879. */
  880. function del (target, key) {
  881. if (Array.isArray(target) && typeof key === 'number') {
  882. target.splice(key, 1);
  883. return
  884. }
  885. var ob = (target ).__ob__;
  886. if (target._isVue || (ob && ob.vmCount)) {
  887. process.env.NODE_ENV !== 'production' && warn(
  888. 'Avoid deleting properties on a Vue instance or its root $data ' +
  889. '- just set it to null.'
  890. );
  891. return
  892. }
  893. if (!hasOwn(target, key)) {
  894. return
  895. }
  896. delete target[key];
  897. if (!ob) {
  898. return
  899. }
  900. ob.dep.notify();
  901. }
  902. /**
  903. * Collect dependencies on array elements when the array is touched, since
  904. * we cannot intercept array element access like property getters.
  905. */
  906. function dependArray (value) {
  907. for (var e = (void 0), i = 0, l = value.length; i < l; i++) {
  908. e = value[i];
  909. e && e.__ob__ && e.__ob__.dep.depend();
  910. if (Array.isArray(e)) {
  911. dependArray(e);
  912. }
  913. }
  914. }
  915. /* */
  916. /**
  917. * Option overwriting strategies are functions that handle
  918. * how to merge a parent option value and a child option
  919. * value into the final value.
  920. */
  921. var strats = config.optionMergeStrategies;
  922. /**
  923. * Options with restrictions
  924. */
  925. if (process.env.NODE_ENV !== 'production') {
  926. strats.el = strats.propsData = function (parent, child, vm, key) {
  927. if (!vm) {
  928. warn(
  929. "option \"" + key + "\" can only be used during instance " +
  930. 'creation with the `new` keyword.'
  931. );
  932. }
  933. return defaultStrat(parent, child)
  934. };
  935. }
  936. /**
  937. * Helper that recursively merges two data objects together.
  938. */
  939. function mergeData (to, from) {
  940. if (!from) { return to }
  941. var key, toVal, fromVal;
  942. var keys = Object.keys(from);
  943. for (var i = 0; i < keys.length; i++) {
  944. key = keys[i];
  945. toVal = to[key];
  946. fromVal = from[key];
  947. if (!hasOwn(to, key)) {
  948. set(to, key, fromVal);
  949. } else if (isPlainObject(toVal) && isPlainObject(fromVal)) {
  950. mergeData(toVal, fromVal);
  951. }
  952. }
  953. return to
  954. }
  955. /**
  956. * Data
  957. */
  958. strats.data = function (
  959. parentVal,
  960. childVal,
  961. vm
  962. ) {
  963. if (!vm) {
  964. // in a Vue.extend merge, both should be functions
  965. if (!childVal) {
  966. return parentVal
  967. }
  968. if (typeof childVal !== 'function') {
  969. process.env.NODE_ENV !== 'production' && warn(
  970. 'The "data" option should be a function ' +
  971. 'that returns a per-instance value in component ' +
  972. 'definitions.',
  973. vm
  974. );
  975. return parentVal
  976. }
  977. if (!parentVal) {
  978. return childVal
  979. }
  980. // when parentVal & childVal are both present,
  981. // we need to return a function that returns the
  982. // merged result of both functions... no need to
  983. // check if parentVal is a function here because
  984. // it has to be a function to pass previous merges.
  985. return function mergedDataFn () {
  986. return mergeData(
  987. childVal.call(this),
  988. parentVal.call(this)
  989. )
  990. }
  991. } else if (parentVal || childVal) {
  992. return function mergedInstanceDataFn () {
  993. // instance merge
  994. var instanceData = typeof childVal === 'function'
  995. ? childVal.call(vm)
  996. : childVal;
  997. var defaultData = typeof parentVal === 'function'
  998. ? parentVal.call(vm)
  999. : undefined;
  1000. if (instanceData) {
  1001. return mergeData(instanceData, defaultData)
  1002. } else {
  1003. return defaultData
  1004. }
  1005. }
  1006. }
  1007. };
  1008. /**
  1009. * Hooks and props are merged as arrays.
  1010. */
  1011. function mergeHook (
  1012. parentVal,
  1013. childVal
  1014. ) {
  1015. return childVal
  1016. ? parentVal
  1017. ? parentVal.concat(childVal)
  1018. : Array.isArray(childVal)
  1019. ? childVal
  1020. : [childVal]
  1021. : parentVal
  1022. }
  1023. LIFECYCLE_HOOKS.forEach(function (hook) {
  1024. strats[hook] = mergeHook;
  1025. });
  1026. /**
  1027. * Assets
  1028. *
  1029. * When a vm is present (instance creation), we need to do
  1030. * a three-way merge between constructor options, instance
  1031. * options and parent options.
  1032. */
  1033. function mergeAssets (parentVal, childVal) {
  1034. var res = Object.create(parentVal || null);
  1035. return childVal
  1036. ? extend(res, childVal)
  1037. : res
  1038. }
  1039. ASSET_TYPES.forEach(function (type) {
  1040. strats[type + 's'] = mergeAssets;
  1041. });
  1042. /**
  1043. * Watchers.
  1044. *
  1045. * Watchers hashes should not overwrite one
  1046. * another, so we merge them as arrays.
  1047. */
  1048. strats.watch = function (parentVal, childVal) {
  1049. /* istanbul ignore if */
  1050. if (!childVal) { return Object.create(parentVal || null) }
  1051. if (!parentVal) { return childVal }
  1052. var ret = {};
  1053. extend(ret, parentVal);
  1054. for (var key in childVal) {
  1055. var parent = ret[key];
  1056. var child = childVal[key];
  1057. if (parent && !Array.isArray(parent)) {
  1058. parent = [parent];
  1059. }
  1060. ret[key] = parent
  1061. ? parent.concat(child)
  1062. : [child];
  1063. }
  1064. return ret
  1065. };
  1066. /**
  1067. * Other object hashes.
  1068. */
  1069. strats.props =
  1070. strats.methods =
  1071. strats.computed = function (parentVal, childVal) {
  1072. if (!childVal) { return Object.create(parentVal || null) }
  1073. if (!parentVal) { return childVal }
  1074. var ret = Object.create(null);
  1075. extend(ret, parentVal);
  1076. extend(ret, childVal);
  1077. return ret
  1078. };
  1079. /**
  1080. * Default strategy.
  1081. */
  1082. var defaultStrat = function (parentVal, childVal) {
  1083. return childVal === undefined
  1084. ? parentVal
  1085. : childVal
  1086. };
  1087. /**
  1088. * Validate component names
  1089. */
  1090. function checkComponents (options) {
  1091. for (var key in options.components) {
  1092. var lower = key.toLowerCase();
  1093. if (isBuiltInTag(lower) || config.isReservedTag(lower)) {
  1094. warn(
  1095. 'Do not use built-in or reserved HTML elements as component ' +
  1096. 'id: ' + key
  1097. );
  1098. }
  1099. }
  1100. }
  1101. /**
  1102. * Ensure all props option syntax are normalized into the
  1103. * Object-based format.
  1104. */
  1105. function normalizeProps (options) {
  1106. var props = options.props;
  1107. if (!props) { return }
  1108. var res = {};
  1109. var i, val, name;
  1110. if (Array.isArray(props)) {
  1111. i = props.length;
  1112. while (i--) {
  1113. val = props[i];
  1114. if (typeof val === 'string') {
  1115. name = camelize(val);
  1116. res[name] = { type: null };
  1117. } else if (process.env.NODE_ENV !== 'production') {
  1118. warn('props must be strings when using array syntax.');
  1119. }
  1120. }
  1121. } else if (isPlainObject(props)) {
  1122. for (var key in props) {
  1123. val = props[key];
  1124. name = camelize(key);
  1125. res[name] = isPlainObject(val)
  1126. ? val
  1127. : { type: val };
  1128. }
  1129. }
  1130. options.props = res;
  1131. }
  1132. /**
  1133. * Normalize raw function directives into object format.
  1134. */
  1135. function normalizeDirectives (options) {
  1136. var dirs = options.directives;
  1137. if (dirs) {
  1138. for (var key in dirs) {
  1139. var def = dirs[key];
  1140. if (typeof def === 'function') {
  1141. dirs[key] = { bind: def, update: def };
  1142. }
  1143. }
  1144. }
  1145. }
  1146. /**
  1147. * Merge two option objects into a new one.
  1148. * Core utility used in both instantiation and inheritance.
  1149. */
  1150. function mergeOptions (
  1151. parent,
  1152. child,
  1153. vm
  1154. ) {
  1155. if (process.env.NODE_ENV !== 'production') {
  1156. checkComponents(child);
  1157. }
  1158. if (typeof child === 'function') {
  1159. child = child.options;
  1160. }
  1161. normalizeProps(child);
  1162. normalizeDirectives(child);
  1163. var extendsFrom = child.extends;
  1164. if (extendsFrom) {
  1165. parent = mergeOptions(parent, extendsFrom, vm);
  1166. }
  1167. if (child.mixins) {
  1168. for (var i = 0, l = child.mixins.length; i < l; i++) {
  1169. parent = mergeOptions(parent, child.mixins[i], vm);
  1170. }
  1171. }
  1172. var options = {};
  1173. var key;
  1174. for (key in parent) {
  1175. mergeField(key);
  1176. }
  1177. for (key in child) {
  1178. if (!hasOwn(parent, key)) {
  1179. mergeField(key);
  1180. }
  1181. }
  1182. function mergeField (key) {
  1183. var strat = strats[key] || defaultStrat;
  1184. options[key] = strat(parent[key], child[key], vm, key);
  1185. }
  1186. return options
  1187. }
  1188. /**
  1189. * Resolve an asset.
  1190. * This function is used because child instances need access
  1191. * to assets defined in its ancestor chain.
  1192. */
  1193. function resolveAsset (
  1194. options,
  1195. type,
  1196. id,
  1197. warnMissing
  1198. ) {
  1199. /* istanbul ignore if */
  1200. if (typeof id !== 'string') {
  1201. return
  1202. }
  1203. var assets = options[type];
  1204. // check local registration variations first
  1205. if (hasOwn(assets, id)) { return assets[id] }
  1206. var camelizedId = camelize(id);
  1207. if (hasOwn(assets, camelizedId)) { return assets[camelizedId] }
  1208. var PascalCaseId = capitalize(camelizedId);
  1209. if (hasOwn(assets, PascalCaseId)) { return assets[PascalCaseId] }
  1210. // fallback to prototype chain
  1211. var res = assets[id] || assets[camelizedId] || assets[PascalCaseId];
  1212. if (process.env.NODE_ENV !== 'production' && warnMissing && !res) {
  1213. warn(
  1214. 'Failed to resolve ' + type.slice(0, -1) + ': ' + id,
  1215. options
  1216. );
  1217. }
  1218. return res
  1219. }
  1220. /* */
  1221. function validateProp (
  1222. key,
  1223. propOptions,
  1224. propsData,
  1225. vm
  1226. ) {
  1227. var prop = propOptions[key];
  1228. var absent = !hasOwn(propsData, key);
  1229. var value = propsData[key];
  1230. // handle boolean props
  1231. if (isType(Boolean, prop.type)) {
  1232. if (absent && !hasOwn(prop, 'default')) {
  1233. value = false;
  1234. } else if (!isType(String, prop.type) && (value === '' || value === hyphenate(key))) {
  1235. value = true;
  1236. }
  1237. }
  1238. // check default value
  1239. if (value === undefined) {
  1240. value = getPropDefaultValue(vm, prop, key);
  1241. // since the default value is a fresh copy,
  1242. // make sure to observe it.
  1243. var prevShouldConvert = observerState.shouldConvert;
  1244. observerState.shouldConvert = true;
  1245. observe(value);
  1246. observerState.shouldConvert = prevShouldConvert;
  1247. }
  1248. if (process.env.NODE_ENV !== 'production') {
  1249. assertProp(prop, key, value, vm, absent);
  1250. }
  1251. return value
  1252. }
  1253. /**
  1254. * Get the default value of a prop.
  1255. */
  1256. function getPropDefaultValue (vm, prop, key) {
  1257. // no default, return undefined
  1258. if (!hasOwn(prop, 'default')) {
  1259. return undefined
  1260. }
  1261. var def = prop.default;
  1262. // warn against non-factory defaults for Object & Array
  1263. if (process.env.NODE_ENV !== 'production' && isObject(def)) {
  1264. warn(
  1265. 'Invalid default value for prop "' + key + '": ' +
  1266. 'Props with type Object/Array must use a factory function ' +
  1267. 'to return the default value.',
  1268. vm
  1269. );
  1270. }
  1271. // the raw prop value was also undefined from previous render,
  1272. // return previous default value to avoid unnecessary watcher trigger
  1273. if (vm && vm.$options.propsData &&
  1274. vm.$options.propsData[key] === undefined &&
  1275. vm._props[key] !== undefined) {
  1276. return vm._props[key]
  1277. }
  1278. // call factory function for non-Function types
  1279. // a value is Function if its prototype is function even across different execution context
  1280. return typeof def === 'function' && getType(prop.type) !== 'Function'
  1281. ? def.call(vm)
  1282. : def
  1283. }
  1284. /**
  1285. * Assert whether a prop is valid.
  1286. */
  1287. function assertProp (
  1288. prop,
  1289. name,
  1290. value,
  1291. vm,
  1292. absent
  1293. ) {
  1294. if (prop.required && absent) {
  1295. warn(
  1296. 'Missing required prop: "' + name + '"',
  1297. vm
  1298. );
  1299. return
  1300. }
  1301. if (value == null && !prop.required) {
  1302. return
  1303. }
  1304. var type = prop.type;
  1305. var valid = !type || type === true;
  1306. var expectedTypes = [];
  1307. if (type) {
  1308. if (!Array.isArray(type)) {
  1309. type = [type];
  1310. }
  1311. for (var i = 0; i < type.length && !valid; i++) {
  1312. var assertedType = assertType(value, type[i]);
  1313. expectedTypes.push(assertedType.expectedType || '');
  1314. valid = assertedType.valid;
  1315. }
  1316. }
  1317. if (!valid) {
  1318. warn(
  1319. 'Invalid prop: type check failed for prop "' + name + '".' +
  1320. ' Expected ' + expectedTypes.map(capitalize).join(', ') +
  1321. ', got ' + Object.prototype.toString.call(value).slice(8, -1) + '.',
  1322. vm
  1323. );
  1324. return
  1325. }
  1326. var validator = prop.validator;
  1327. if (validator) {
  1328. if (!validator(value)) {
  1329. warn(
  1330. 'Invalid prop: custom validator check failed for prop "' + name + '".',
  1331. vm
  1332. );
  1333. }
  1334. }
  1335. }
  1336. var simpleCheckRE = /^(String|Number|Boolean|Function|Symbol)$/;
  1337. function assertType (value, type) {
  1338. var valid;
  1339. var expectedType = getType(type);
  1340. if (simpleCheckRE.test(expectedType)) {
  1341. valid = typeof value === expectedType.toLowerCase();
  1342. } else if (expectedType === 'Object') {
  1343. valid = isPlainObject(value);
  1344. } else if (expectedType === 'Array') {
  1345. valid = Array.isArray(value);
  1346. } else {
  1347. valid = value instanceof type;
  1348. }
  1349. return {
  1350. valid: valid,
  1351. expectedType: expectedType
  1352. }
  1353. }
  1354. /**
  1355. * Use function string name to check built-in types,
  1356. * because a simple equality check will fail when running
  1357. * across different vms / iframes.
  1358. */
  1359. function getType (fn) {
  1360. var match = fn && fn.toString().match(/^\s*function (\w+)/);
  1361. return match ? match[1] : ''
  1362. }
  1363. function isType (type, fn) {
  1364. if (!Array.isArray(fn)) {
  1365. return getType(fn) === getType(type)
  1366. }
  1367. for (var i = 0, len = fn.length; i < len; i++) {
  1368. if (getType(fn[i]) === getType(type)) {
  1369. return true
  1370. }
  1371. }
  1372. /* istanbul ignore next */
  1373. return false
  1374. }
  1375. /* not type checking this file because flow doesn't play well with Proxy */
  1376. var initProxy;
  1377. if (process.env.NODE_ENV !== 'production') {
  1378. var allowedGlobals = makeMap(
  1379. 'Infinity,undefined,NaN,isFinite,isNaN,' +
  1380. 'parseFloat,parseInt,decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,' +
  1381. 'Math,Number,Date,Array,Object,Boolean,String,RegExp,Map,Set,JSON,Intl,' +
  1382. 'require' // for Webpack/Browserify
  1383. );
  1384. var warnNonPresent = function (target, key) {
  1385. warn(
  1386. "Property or method \"" + key + "\" is not defined on the instance but " +
  1387. "referenced during render. Make sure to declare reactive data " +
  1388. "properties in the data option.",
  1389. target
  1390. );
  1391. };
  1392. var hasProxy =
  1393. typeof Proxy !== 'undefined' &&
  1394. Proxy.toString().match(/native code/);
  1395. if (hasProxy) {
  1396. var isBuiltInModifier = makeMap('stop,prevent,self,ctrl,shift,alt,meta');
  1397. config.keyCodes = new Proxy(config.keyCodes, {
  1398. set: function set (target, key, value) {
  1399. if (isBuiltInModifier(key)) {
  1400. warn(("Avoid overwriting built-in modifier in config.keyCodes: ." + key));
  1401. return false
  1402. } else {
  1403. target[key] = value;
  1404. return true
  1405. }
  1406. }
  1407. });
  1408. }
  1409. var hasHandler = {
  1410. has: function has (target, key) {
  1411. var has = key in target;
  1412. var isAllowed = allowedGlobals(key) || key.charAt(0) === '_';
  1413. if (!has && !isAllowed) {
  1414. warnNonPresent(target, key);
  1415. }
  1416. return has || !isAllowed
  1417. }
  1418. };
  1419. var getHandler = {
  1420. get: function get (target, key) {
  1421. if (typeof key === 'string' && !(key in target)) {
  1422. warnNonPresent(target, key);
  1423. }
  1424. return target[key]
  1425. }
  1426. };
  1427. initProxy = function initProxy (vm) {
  1428. if (hasProxy) {
  1429. // determine which proxy handler to use
  1430. var options = vm.$options;
  1431. var handlers = options.render && options.render._withStripped
  1432. ? getHandler
  1433. : hasHandler;
  1434. vm._renderProxy = new Proxy(vm, handlers);
  1435. } else {
  1436. vm._renderProxy = vm;
  1437. }
  1438. };
  1439. }
  1440. var mark;
  1441. var measure;
  1442. if (process.env.NODE_ENV !== 'production') {
  1443. var perf = inBrowser && window.performance;
  1444. /* istanbul ignore if */
  1445. if (
  1446. perf &&
  1447. perf.mark &&
  1448. perf.measure &&
  1449. perf.clearMarks &&
  1450. perf.clearMeasures
  1451. ) {
  1452. mark = function (tag) { return perf.mark(tag); };
  1453. measure = function (name, startTag, endTag) {
  1454. perf.measure(name, startTag, endTag);
  1455. perf.clearMarks(startTag);
  1456. perf.clearMarks(endTag);
  1457. perf.clearMeasures(name);
  1458. };
  1459. }
  1460. }
  1461. /* */
  1462. var VNode = function VNode (
  1463. tag,
  1464. data,
  1465. children,
  1466. text,
  1467. elm,
  1468. context,
  1469. componentOptions
  1470. ) {
  1471. this.tag = tag;
  1472. this.data = data;
  1473. this.children = children;
  1474. this.text = text;
  1475. this.elm = elm;
  1476. this.ns = undefined;
  1477. this.context = context;
  1478. this.functionalContext = undefined;
  1479. this.key = data && data.key;
  1480. this.componentOptions = componentOptions;
  1481. this.componentInstance = undefined;
  1482. this.parent = undefined;
  1483. this.raw = false;
  1484. this.isStatic = false;
  1485. this.isRootInsert = true;
  1486. this.isComment = false;
  1487. this.isCloned = false;
  1488. this.isOnce = false;
  1489. };
  1490. var prototypeAccessors = { child: {} };
  1491. // DEPRECATED: alias for componentInstance for backwards compat.
  1492. /* istanbul ignore next */
  1493. prototypeAccessors.child.get = function () {
  1494. return this.componentInstance
  1495. };
  1496. Object.defineProperties( VNode.prototype, prototypeAccessors );
  1497. var createEmptyVNode = function () {
  1498. var node = new VNode();
  1499. node.text = '';
  1500. node.isComment = true;
  1501. return node
  1502. };
  1503. function createTextVNode (val) {
  1504. return new VNode(undefined, undefined, undefined, String(val))
  1505. }
  1506. // optimized shallow clone
  1507. // used for static nodes and slot nodes because they may be reused across
  1508. // multiple renders, cloning them avoids errors when DOM manipulations rely
  1509. // on their elm reference.
  1510. function cloneVNode (vnode) {
  1511. var cloned = new VNode(
  1512. vnode.tag,
  1513. vnode.data,
  1514. vnode.children,
  1515. vnode.text,
  1516. vnode.elm,
  1517. vnode.context,
  1518. vnode.componentOptions
  1519. );
  1520. cloned.ns = vnode.ns;
  1521. cloned.isStatic = vnode.isStatic;
  1522. cloned.key = vnode.key;
  1523. cloned.isCloned = true;
  1524. return cloned
  1525. }
  1526. function cloneVNodes (vnodes) {
  1527. var len = vnodes.length;
  1528. var res = new Array(len);
  1529. for (var i = 0; i < len; i++) {
  1530. res[i] = cloneVNode(vnodes[i]);
  1531. }
  1532. return res
  1533. }
  1534. /* */
  1535. var normalizeEvent = cached(function (name) {
  1536. var passive = name.charAt(0) === '&';
  1537. name = passive ? name.slice(1) : name;
  1538. var once$$1 = name.charAt(0) === '~'; // Prefixed last, checked first
  1539. name = once$$1 ? name.slice(1) : name;
  1540. var capture = name.charAt(0) === '!';
  1541. name = capture ? name.slice(1) : name;
  1542. return {
  1543. name: name,
  1544. once: once$$1,
  1545. capture: capture,
  1546. passive: passive
  1547. }
  1548. });
  1549. function createFnInvoker (fns) {
  1550. function invoker () {
  1551. var arguments$1 = arguments;
  1552. var fns = invoker.fns;
  1553. if (Array.isArray(fns)) {
  1554. for (var i = 0; i < fns.length; i++) {
  1555. fns[i].apply(null, arguments$1);
  1556. }
  1557. } else {
  1558. // return handler return value for single handlers
  1559. return fns.apply(null, arguments)
  1560. }
  1561. }
  1562. invoker.fns = fns;
  1563. return invoker
  1564. }
  1565. function updateListeners (
  1566. on,
  1567. oldOn,
  1568. add,
  1569. remove$$1,
  1570. vm
  1571. ) {
  1572. var name, cur, old, event;
  1573. for (name in on) {
  1574. cur = on[name];
  1575. old = oldOn[name];
  1576. event = normalizeEvent(name);
  1577. if (isUndef(cur)) {
  1578. process.env.NODE_ENV !== 'production' && warn(
  1579. "Invalid handler for event \"" + (event.name) + "\": got " + String(cur),
  1580. vm
  1581. );
  1582. } else if (isUndef(old)) {
  1583. if (isUndef(cur.fns)) {
  1584. cur = on[name] = createFnInvoker(cur);
  1585. }
  1586. add(event.name, cur, event.once, event.capture, event.passive);
  1587. } else if (cur !== old) {
  1588. old.fns = cur;
  1589. on[name] = old;
  1590. }
  1591. }
  1592. for (name in oldOn) {
  1593. if (isUndef(on[name])) {
  1594. event = normalizeEvent(name);
  1595. remove$$1(event.name, oldOn[name], event.capture);
  1596. }
  1597. }
  1598. }
  1599. /* */
  1600. function mergeVNodeHook (def, hookKey, hook) {
  1601. var invoker;
  1602. var oldHook = def[hookKey];
  1603. function wrappedHook () {
  1604. hook.apply(this, arguments);
  1605. // important: remove merged hook to ensure it's called only once
  1606. // and prevent memory leak
  1607. remove(invoker.fns, wrappedHook);
  1608. }
  1609. if (isUndef(oldHook)) {
  1610. // no existing hook
  1611. invoker = createFnInvoker([wrappedHook]);
  1612. } else {
  1613. /* istanbul ignore if */
  1614. if (isDef(oldHook.fns) && isTrue(oldHook.merged)) {
  1615. // already a merged invoker
  1616. invoker = oldHook;
  1617. invoker.fns.push(wrappedHook);
  1618. } else {
  1619. // existing plain hook
  1620. invoker = createFnInvoker([oldHook, wrappedHook]);
  1621. }
  1622. }
  1623. invoker.merged = true;
  1624. def[hookKey] = invoker;
  1625. }
  1626. /* */
  1627. function extractPropsFromVNodeData (
  1628. data,
  1629. Ctor,
  1630. tag
  1631. ) {
  1632. // we are only extracting raw values here.
  1633. // validation and default values are handled in the child
  1634. // component itself.
  1635. var propOptions = Ctor.options.props;
  1636. if (isUndef(propOptions)) {
  1637. return
  1638. }
  1639. var res = {};
  1640. var attrs = data.attrs;
  1641. var props = data.props;
  1642. if (isDef(attrs) || isDef(props)) {
  1643. for (var key in propOptions) {
  1644. var altKey = hyphenate(key);
  1645. if (process.env.NODE_ENV !== 'production') {
  1646. var keyInLowerCase = key.toLowerCase();
  1647. if (
  1648. key !== keyInLowerCase &&
  1649. attrs && hasOwn(attrs, keyInLowerCase)
  1650. ) {
  1651. tip(
  1652. "Prop \"" + keyInLowerCase + "\" is passed to component " +
  1653. (formatComponentName(tag || Ctor)) + ", but the declared prop name is" +
  1654. " \"" + key + "\". " +
  1655. "Note that HTML attributes are case-insensitive and camelCased " +
  1656. "props need to use their kebab-case equivalents when using in-DOM " +
  1657. "templates. You should probably use \"" + altKey + "\" instead of \"" + key + "\"."
  1658. );
  1659. }
  1660. }
  1661. checkProp(res, props, key, altKey, true) ||
  1662. checkProp(res, attrs, key, altKey, false);
  1663. }
  1664. }
  1665. return res
  1666. }
  1667. function checkProp (
  1668. res,
  1669. hash,
  1670. key,
  1671. altKey,
  1672. preserve
  1673. ) {
  1674. if (isDef(hash)) {
  1675. if (hasOwn(hash, key)) {
  1676. res[key] = hash[key];
  1677. if (!preserve) {
  1678. delete hash[key];
  1679. }
  1680. return true
  1681. } else if (hasOwn(hash, altKey)) {
  1682. res[key] = hash[altKey];
  1683. if (!preserve) {
  1684. delete hash[altKey];
  1685. }
  1686. return true
  1687. }
  1688. }
  1689. return false
  1690. }
  1691. /* */
  1692. // The template compiler attempts to minimize the need for normalization by
  1693. // statically analyzing the template at compile time.
  1694. //
  1695. // For plain HTML markup, normalization can be completely skipped because the
  1696. // generated render function is guaranteed to return Array<VNode>. There are
  1697. // two cases where extra normalization is needed:
  1698. // 1. When the children contains components - because a functional component
  1699. // may return an Array instead of a single root. In this case, just a simple
  1700. // normalization is needed - if any child is an Array, we flatten the whole
  1701. // thing with Array.prototype.concat. It is guaranteed to be only 1-level deep
  1702. // because functional components already normalize their own children.
  1703. function simpleNormalizeChildren (children) {
  1704. for (var i = 0; i < children.length; i++) {
  1705. if (Array.isArray(children[i])) {
  1706. return Array.prototype.concat.apply([], children)
  1707. }
  1708. }
  1709. return children
  1710. }
  1711. // 2. When the children contains constructs that always generated nested Arrays,
  1712. // e.g. <template>, <slot>, v-for, or when the children is provided by user
  1713. // with hand-written render functions / JSX. In such cases a full normalization
  1714. // is needed to cater to all possible types of children values.
  1715. function normalizeChildren (children) {
  1716. return isPrimitive(children)
  1717. ? [createTextVNode(children)]
  1718. : Array.isArray(children)
  1719. ? normalizeArrayChildren(children)
  1720. : undefined
  1721. }
  1722. function normalizeArrayChildren (children, nestedIndex) {
  1723. var res = [];
  1724. var i, c, last;
  1725. for (i = 0; i < children.length; i++) {
  1726. c = children[i];
  1727. if (isUndef(c) || typeof c === 'boolean') { continue }
  1728. last = res[res.length - 1];
  1729. // nested
  1730. if (Array.isArray(c)) {
  1731. res.push.apply(res, normalizeArrayChildren(c, ((nestedIndex || '') + "_" + i)));
  1732. } else if (isPrimitive(c)) {
  1733. if (isDef(last) && isDef(last.text)) {
  1734. (last).text += String(c);
  1735. } else if (c !== '') {
  1736. // convert primitive to vnode
  1737. res.push(createTextVNode(c));
  1738. }
  1739. } else {
  1740. if (isDef(c.text) && isDef(last) && isDef(last.text)) {
  1741. res[res.length - 1] = createTextVNode(last.text + c.text);
  1742. } else {
  1743. // default key for nested array children (likely generated by v-for)
  1744. if (isDef(c.tag) && isUndef(c.key) && isDef(nestedIndex)) {
  1745. c.key = "__vlist" + ((nestedIndex)) + "_" + i + "__";
  1746. }
  1747. res.push(c);
  1748. }
  1749. }
  1750. }
  1751. return res
  1752. }
  1753. /* */
  1754. function ensureCtor (comp, base) {
  1755. return isObject(comp)
  1756. ? base.extend(comp)
  1757. : comp
  1758. }
  1759. function resolveAsyncComponent (
  1760. factory,
  1761. baseCtor,
  1762. context
  1763. ) {
  1764. if (isTrue(factory.error) && isDef(factory.errorComp)) {
  1765. return factory.errorComp
  1766. }
  1767. if (isDef(factory.resolved)) {
  1768. return factory.resolved
  1769. }
  1770. if (isTrue(factory.loading) && isDef(factory.loadingComp)) {
  1771. return factory.loadingComp
  1772. }
  1773. if (isDef(factory.contexts)) {
  1774. // already pending
  1775. factory.contexts.push(context);
  1776. } else {
  1777. var contexts = factory.contexts = [context];
  1778. var sync = true;
  1779. var forceRender = function () {
  1780. for (var i = 0, l = contexts.length; i < l; i++) {
  1781. contexts[i].$forceUpdate();
  1782. }
  1783. };
  1784. var resolve = once(function (res) {
  1785. // cache resolved
  1786. factory.resolved = ensureCtor(res, baseCtor);
  1787. // invoke callbacks only if this is not a synchronous resolve
  1788. // (async resolves are shimmed as synchronous during SSR)
  1789. if (!sync) {
  1790. forceRender();
  1791. }
  1792. });
  1793. var reject = once(function (reason) {
  1794. process.env.NODE_ENV !== 'production' && warn(
  1795. "Failed to resolve async component: " + (String(factory)) +
  1796. (reason ? ("\nReason: " + reason) : '')
  1797. );
  1798. if (isDef(factory.errorComp)) {
  1799. factory.error = true;
  1800. forceRender();
  1801. }
  1802. });
  1803. var res = factory(resolve, reject);
  1804. if (isObject(res)) {
  1805. if (typeof res.then === 'function') {
  1806. // () => Promise
  1807. if (isUndef(factory.resolved)) {
  1808. res.then(resolve, reject);
  1809. }
  1810. } else if (isDef(res.component) && typeof res.component.then === 'function') {
  1811. res.component.then(resolve, reject);
  1812. if (isDef(res.error)) {
  1813. factory.errorComp = ensureCtor(res.error, baseCtor);
  1814. }
  1815. if (isDef(res.loading)) {
  1816. factory.loadingComp = ensureCtor(res.loading, baseCtor);
  1817. if (res.delay === 0) {
  1818. factory.loading = true;
  1819. } else {
  1820. setTimeout(function () {
  1821. if (isUndef(factory.resolved) && isUndef(factory.error)) {
  1822. factory.loading = true;
  1823. forceRender();
  1824. }
  1825. }, res.delay || 200);
  1826. }
  1827. }
  1828. if (isDef(res.timeout)) {
  1829. setTimeout(function () {
  1830. reject(
  1831. process.env.NODE_ENV !== 'production'
  1832. ? ("timeout (" + (res.timeout) + "ms)")
  1833. : null
  1834. );
  1835. }, res.timeout);
  1836. }
  1837. }
  1838. }
  1839. sync = false;
  1840. // return in case resolved synchronously
  1841. return factory.loading
  1842. ? factory.loadingComp
  1843. : factory.resolved
  1844. }
  1845. }
  1846. /* */
  1847. function getFirstComponentChild (children) {
  1848. if (Array.isArray(children)) {
  1849. for (var i = 0; i < children.length; i++) {
  1850. var c = children[i];
  1851. if (isDef(c) && isDef(c.componentOptions)) {
  1852. return c
  1853. }
  1854. }
  1855. }
  1856. }
  1857. /* */
  1858. /* */
  1859. function initEvents (vm) {
  1860. vm._events = Object.create(null);
  1861. vm._hasHookEvent = false;
  1862. // init parent attached events
  1863. var listeners = vm.$options._parentListeners;
  1864. if (listeners) {
  1865. updateComponentListeners(vm, listeners);
  1866. }
  1867. }
  1868. var target;
  1869. function add (event, fn, once$$1) {
  1870. if (once$$1) {
  1871. target.$once(event, fn);
  1872. } else {
  1873. target.$on(event, fn);
  1874. }
  1875. }
  1876. function remove$1 (event, fn) {
  1877. target.$off(event, fn);
  1878. }
  1879. function updateComponentListeners (
  1880. vm,
  1881. listeners,
  1882. oldListeners
  1883. ) {
  1884. target = vm;
  1885. updateListeners(listeners, oldListeners || {}, add, remove$1, vm);
  1886. }
  1887. function eventsMixin (Vue) {
  1888. var hookRE = /^hook:/;
  1889. Vue.prototype.$on = function (event, fn) {
  1890. var this$1 = this;
  1891. var vm = this;
  1892. if (Array.isArray(event)) {
  1893. for (var i = 0, l = event.length; i < l; i++) {
  1894. this$1.$on(event[i], fn);
  1895. }
  1896. } else {
  1897. (vm._events[event] || (vm._events[event] = [])).push(fn);
  1898. // optimize hook:event cost by using a boolean flag marked at registration
  1899. // instead of a hash lookup
  1900. if (hookRE.test(event)) {
  1901. vm._hasHookEvent = true;
  1902. }
  1903. }
  1904. return vm
  1905. };
  1906. Vue.prototype.$once = function (event, fn) {
  1907. var vm = this;
  1908. function on () {
  1909. vm.$off(event, on);
  1910. fn.apply(vm, arguments);
  1911. }
  1912. on.fn = fn;
  1913. vm.$on(event, on);
  1914. return vm
  1915. };
  1916. Vue.prototype.$off = function (event, fn) {
  1917. var this$1 = this;
  1918. var vm = this;
  1919. // all
  1920. if (!arguments.length) {
  1921. vm._events = Object.create(null);
  1922. return vm
  1923. }
  1924. // array of events
  1925. if (Array.isArray(event)) {
  1926. for (var i$1 = 0, l = event.length; i$1 < l; i$1++) {
  1927. this$1.$off(event[i$1], fn);
  1928. }
  1929. return vm
  1930. }
  1931. // specific event
  1932. var cbs = vm._events[event];
  1933. if (!cbs) {
  1934. return vm
  1935. }
  1936. if (arguments.length === 1) {
  1937. vm._events[event] = null;
  1938. return vm
  1939. }
  1940. // specific handler
  1941. var cb;
  1942. var i = cbs.length;
  1943. while (i--) {
  1944. cb = cbs[i];
  1945. if (cb === fn || cb.fn === fn) {
  1946. cbs.splice(i, 1);
  1947. break
  1948. }
  1949. }
  1950. return vm
  1951. };
  1952. Vue.prototype.$emit = function (event) {
  1953. var vm = this;
  1954. if (process.env.NODE_ENV !== 'production') {
  1955. var lowerCaseEvent = event.toLowerCase();
  1956. if (lowerCaseEvent !== event && vm._events[lowerCaseEvent]) {
  1957. tip(
  1958. "Event \"" + lowerCaseEvent + "\" is emitted in component " +
  1959. (formatComponentName(vm)) + " but the handler is registered for \"" + event + "\". " +
  1960. "Note that HTML attributes are case-insensitive and you cannot use " +
  1961. "v-on to listen to camelCase events when using in-DOM templates. " +
  1962. "You should probably use \"" + (hyphenate(event)) + "\" instead of \"" + event + "\"."
  1963. );
  1964. }
  1965. }
  1966. var cbs = vm._events[event];
  1967. if (cbs) {
  1968. cbs = cbs.length > 1 ? toArray(cbs) : cbs;
  1969. var args = toArray(arguments, 1);
  1970. for (var i = 0, l = cbs.length; i < l; i++) {
  1971. cbs[i].apply(vm, args);
  1972. }
  1973. }
  1974. return vm
  1975. };
  1976. }
  1977. /* */
  1978. /**
  1979. * Runtime helper for resolving raw children VNodes into a slot object.
  1980. */
  1981. function resolveSlots (
  1982. children,
  1983. context
  1984. ) {
  1985. var slots = {};
  1986. if (!children) {
  1987. return slots
  1988. }
  1989. var defaultSlot = [];
  1990. for (var i = 0, l = children.length; i < l; i++) {
  1991. var child = children[i];
  1992. // named slots should only be respected if the vnode was rendered in the
  1993. // same context.
  1994. if ((child.context === context || child.functionalContext === context) &&
  1995. child.data && child.data.slot != null) {
  1996. var name = child.data.slot;
  1997. var slot = (slots[name] || (slots[name] = []));
  1998. if (child.tag === 'template') {
  1999. slot.push.apply(slot, child.children);
  2000. } else {
  2001. slot.push(child);
  2002. }
  2003. } else {
  2004. defaultSlot.push(child);
  2005. }
  2006. }
  2007. // ignore whitespace
  2008. if (!defaultSlot.every(isWhitespace)) {
  2009. slots.default = defaultSlot;
  2010. }
  2011. return slots
  2012. }
  2013. function isWhitespace (node) {
  2014. return node.isComment || node.text === ' '
  2015. }
  2016. function resolveScopedSlots (
  2017. fns
  2018. ) {
  2019. var res = {};
  2020. for (var i = 0; i < fns.length; i++) {
  2021. res[fns[i][0]] = fns[i][1];
  2022. }
  2023. return res
  2024. }
  2025. /* */
  2026. var activeInstance = null;
  2027. function initLifecycle (vm) {
  2028. var options = vm.$options;
  2029. // locate first non-abstract parent
  2030. var parent = options.parent;
  2031. if (parent && !options.abstract) {
  2032. while (parent.$options.abstract && parent.$parent) {
  2033. parent = parent.$parent;
  2034. }
  2035. parent.$children.push(vm);
  2036. }
  2037. vm.$parent = parent;
  2038. vm.$root = parent ? parent.$root : vm;
  2039. vm.$children = [];
  2040. vm.$refs = {};
  2041. vm._watcher = null;
  2042. vm._inactive = null;
  2043. vm._directInactive = false;
  2044. vm._isMounted = false;
  2045. vm._isDestroyed = false;
  2046. vm._isBeingDestroyed = false;
  2047. }
  2048. function lifecycleMixin (Vue) {
  2049. Vue.prototype._update = function (vnode, hydrating) {
  2050. var vm = this;
  2051. if (vm._isMounted) {
  2052. callHook(vm, 'beforeUpdate');
  2053. }
  2054. var prevEl = vm.$el;
  2055. var prevVnode = vm._vnode;
  2056. var prevActiveInstance = activeInstance;
  2057. activeInstance = vm;
  2058. vm._vnode = vnode;
  2059. // Vue.prototype.__patch__ is injected in entry points
  2060. // based on the rendering backend used.
  2061. if (!prevVnode) {
  2062. // initial render
  2063. vm.$el = vm.__patch__(
  2064. vm.$el, vnode, hydrating, false /* removeOnly */,
  2065. vm.$options._parentElm,
  2066. vm.$options._refElm
  2067. );
  2068. } else {
  2069. // updates
  2070. vm.$el = vm.__patch__(prevVnode, vnode);
  2071. }
  2072. activeInstance = prevActiveInstance;
  2073. // update __vue__ reference
  2074. if (prevEl) {
  2075. prevEl.__vue__ = null;
  2076. }
  2077. if (vm.$el) {
  2078. vm.$el.__vue__ = vm;
  2079. }
  2080. // if parent is an HOC, update its $el as well
  2081. if (vm.$vnode && vm.$parent && vm.$vnode === vm.$parent._vnode) {
  2082. vm.$parent.$el = vm.$el;
  2083. }
  2084. // updated hook is called by the scheduler to ensure that children are
  2085. // updated in a parent's updated hook.
  2086. };
  2087. Vue.prototype.$forceUpdate = function () {
  2088. var vm = this;
  2089. if (vm._watcher) {
  2090. vm._watcher.update();
  2091. }
  2092. };
  2093. Vue.prototype.$destroy = function () {
  2094. var vm = this;
  2095. if (vm._isBeingDestroyed) {
  2096. return
  2097. }
  2098. callHook(vm, 'beforeDestroy');
  2099. vm._isBeingDestroyed = true;
  2100. // remove self from parent
  2101. var parent = vm.$parent;
  2102. if (parent && !parent._isBeingDestroyed && !vm.$options.abstract) {
  2103. remove(parent.$children, vm);
  2104. }
  2105. // teardown watchers
  2106. if (vm._watcher) {
  2107. vm._watcher.teardown();
  2108. }
  2109. var i = vm._watchers.length;
  2110. while (i--) {
  2111. vm._watchers[i].teardown();
  2112. }
  2113. // remove reference from data ob
  2114. // frozen object may not have observer.
  2115. if (vm._data.__ob__) {
  2116. vm._data.__ob__.vmCount--;
  2117. }
  2118. // call the last hook...
  2119. vm._isDestroyed = true;
  2120. // invoke destroy hooks on current rendered tree
  2121. vm.__patch__(vm._vnode, null);
  2122. // fire destroyed hook
  2123. callHook(vm, 'destroyed');
  2124. // turn off all instance listeners.
  2125. vm.$off();
  2126. // remove __vue__ reference
  2127. if (vm.$el) {
  2128. vm.$el.__vue__ = null;
  2129. }
  2130. // remove reference to DOM nodes (prevents leak)
  2131. vm.$options._parentElm = vm.$options._refElm = null;
  2132. };
  2133. }
  2134. function mountComponent (
  2135. vm,
  2136. el,
  2137. hydrating
  2138. ) {
  2139. vm.$el = el;
  2140. if (!vm.$options.render) {
  2141. vm.$options.render = createEmptyVNode;
  2142. if (process.env.NODE_ENV !== 'production') {
  2143. /* istanbul ignore if */
  2144. if ((vm.$options.template && vm.$options.template.charAt(0) !== '#') ||
  2145. vm.$options.el || el) {
  2146. warn(
  2147. 'You are using the runtime-only build of Vue where the template ' +
  2148. 'compiler is not available. Either pre-compile the templates into ' +
  2149. 'render functions, or use the compiler-included build.',
  2150. vm
  2151. );
  2152. } else {
  2153. warn(
  2154. 'Failed to mount component: template or render function not defined.',
  2155. vm
  2156. );
  2157. }
  2158. }
  2159. }
  2160. callHook(vm, 'beforeMount');
  2161. var updateComponent;
  2162. /* istanbul ignore if */
  2163. if (process.env.NODE_ENV !== 'production' && config.performance && mark) {
  2164. updateComponent = function () {
  2165. var name = vm._name;
  2166. var id = vm._uid;
  2167. var startTag = "vue-perf-start:" + id;
  2168. var endTag = "vue-perf-end:" + id;
  2169. mark(startTag);
  2170. var vnode = vm._render();
  2171. mark(endTag);
  2172. measure((name + " render"), startTag, endTag);
  2173. mark(startTag);
  2174. vm._update(vnode, hydrating);
  2175. mark(endTag);
  2176. measure((name + " patch"), startTag, endTag);
  2177. };
  2178. } else {
  2179. updateComponent = function () {
  2180. vm._update(vm._render(), hydrating);
  2181. };
  2182. }
  2183. vm._watcher = new Watcher(vm, updateComponent, noop);
  2184. hydrating = false;
  2185. // manually mounted instance, call mounted on self
  2186. // mounted is called for render-created child components in its inserted hook
  2187. if (vm.$vnode == null) {
  2188. vm._isMounted = true;
  2189. callHook(vm, 'mounted');
  2190. }
  2191. return vm
  2192. }
  2193. function updateChildComponent (
  2194. vm,
  2195. propsData,
  2196. listeners,
  2197. parentVnode,
  2198. renderChildren
  2199. ) {
  2200. // determine whether component has slot children
  2201. // we need to do this before overwriting $options._renderChildren
  2202. var hasChildren = !!(
  2203. renderChildren || // has new static slots
  2204. vm.$options._renderChildren || // has old static slots
  2205. parentVnode.data.scopedSlots || // has new scoped slots
  2206. vm.$scopedSlots !== emptyObject // has old scoped slots
  2207. );
  2208. vm.$options._parentVnode = parentVnode;
  2209. vm.$vnode = parentVnode; // update vm's placeholder node without re-render
  2210. if (vm._vnode) { // update child tree's parent
  2211. vm._vnode.parent = parentVnode;
  2212. }
  2213. vm.$options._renderChildren = renderChildren;
  2214. // update props
  2215. if (propsData && vm.$options.props) {
  2216. observerState.shouldConvert = false;
  2217. if (process.env.NODE_ENV !== 'production') {
  2218. observerState.isSettingProps = true;
  2219. }
  2220. var props = vm._props;
  2221. var propKeys = vm.$options._propKeys || [];
  2222. for (var i = 0; i < propKeys.length; i++) {
  2223. var key = propKeys[i];
  2224. props[key] = validateProp(key, vm.$options.props, propsData, vm);
  2225. }
  2226. observerState.shouldConvert = true;
  2227. if (process.env.NODE_ENV !== 'production') {
  2228. observerState.isSettingProps = false;
  2229. }
  2230. // keep a copy of raw propsData
  2231. vm.$options.propsData = propsData;
  2232. }
  2233. // update listeners
  2234. if (listeners) {
  2235. var oldListeners = vm.$options._parentListeners;
  2236. vm.$options._parentListeners = listeners;
  2237. updateComponentListeners(vm, listeners, oldListeners);
  2238. }
  2239. // resolve slots + force update if has children
  2240. if (hasChildren) {
  2241. vm.$slots = resolveSlots(renderChildren, parentVnode.context);
  2242. vm.$forceUpdate();
  2243. }
  2244. }
  2245. function isInInactiveTree (vm) {
  2246. while (vm && (vm = vm.$parent)) {
  2247. if (vm._inactive) { return true }
  2248. }
  2249. return false
  2250. }
  2251. function activateChildComponent (vm, direct) {
  2252. if (direct) {
  2253. vm._directInactive = false;
  2254. if (isInInactiveTree(vm)) {
  2255. return
  2256. }
  2257. } else if (vm._directInactive) {
  2258. return
  2259. }
  2260. if (vm._inactive || vm._inactive === null) {
  2261. vm._inactive = false;
  2262. for (var i = 0; i < vm.$children.length; i++) {
  2263. activateChildComponent(vm.$children[i]);
  2264. }
  2265. callHook(vm, 'activated');
  2266. }
  2267. }
  2268. function deactivateChildComponent (vm, direct) {
  2269. if (direct) {
  2270. vm._directInactive = true;
  2271. if (isInInactiveTree(vm)) {
  2272. return
  2273. }
  2274. }
  2275. if (!vm._inactive) {
  2276. vm._inactive = true;
  2277. for (var i = 0; i < vm.$children.length; i++) {
  2278. deactivateChildComponent(vm.$children[i]);
  2279. }
  2280. callHook(vm, 'deactivated');
  2281. }
  2282. }
  2283. function callHook (vm, hook) {
  2284. var handlers = vm.$options[hook];
  2285. if (handlers) {
  2286. for (var i = 0, j = handlers.length; i < j; i++) {
  2287. try {
  2288. handlers[i].call(vm);
  2289. } catch (e) {
  2290. handleError(e, vm, (hook + " hook"));
  2291. }
  2292. }
  2293. }
  2294. if (vm._hasHookEvent) {
  2295. vm.$emit('hook:' + hook);
  2296. }
  2297. }
  2298. /* */
  2299. var MAX_UPDATE_COUNT = 100;
  2300. var queue = [];
  2301. var activatedChildren = [];
  2302. var has = {};
  2303. var circular = {};
  2304. var waiting = false;
  2305. var flushing = false;
  2306. var index = 0;
  2307. /**
  2308. * Reset the scheduler's state.
  2309. */
  2310. function resetSchedulerState () {
  2311. queue.length = activatedChildren.length = 0;
  2312. has = {};
  2313. if (process.env.NODE_ENV !== 'production') {
  2314. circular = {};
  2315. }
  2316. waiting = flushing = false;
  2317. }
  2318. /**
  2319. * Flush both queues and run the watchers.
  2320. */
  2321. function flushSchedulerQueue () {
  2322. flushing = true;
  2323. var watcher, id;
  2324. // Sort queue before flush.
  2325. // This ensures that:
  2326. // 1. Components are updated from parent to child. (because parent is always
  2327. // created before the child)
  2328. // 2. A component's user watchers are run before its render watcher (because
  2329. // user watchers are created before the render watcher)
  2330. // 3. If a component is destroyed during a parent component's watcher run,
  2331. // its watchers can be skipped.
  2332. queue.sort(function (a, b) { return a.id - b.id; });
  2333. // do not cache length because more watchers might be pushed
  2334. // as we run existing watchers
  2335. for (index = 0; index < queue.length; index++) {
  2336. watcher = queue[index];
  2337. id = watcher.id;
  2338. has[id] = null;
  2339. watcher.run();
  2340. // in dev build, check and stop circular updates.
  2341. if (process.env.NODE_ENV !== 'production' && has[id] != null) {
  2342. circular[id] = (circular[id] || 0) + 1;
  2343. if (circular[id] > MAX_UPDATE_COUNT) {
  2344. warn(
  2345. 'You may have an infinite update loop ' + (
  2346. watcher.user
  2347. ? ("in watcher with expression \"" + (watcher.expression) + "\"")
  2348. : "in a component render function."
  2349. ),
  2350. watcher.vm
  2351. );
  2352. break
  2353. }
  2354. }
  2355. }
  2356. // keep copies of post queues before resetting state
  2357. var activatedQueue = activatedChildren.slice();
  2358. var updatedQueue = queue.slice();
  2359. resetSchedulerState();
  2360. // call component updated and activated hooks
  2361. callActivatedHooks(activatedQueue);
  2362. callUpdateHooks(updatedQueue);
  2363. // devtool hook
  2364. /* istanbul ignore if */
  2365. if (devtools && config.devtools) {
  2366. devtools.emit('flush');
  2367. }
  2368. }
  2369. function callUpdateHooks (queue) {
  2370. var i = queue.length;
  2371. while (i--) {
  2372. var watcher = queue[i];
  2373. var vm = watcher.vm;
  2374. if (vm._watcher === watcher && vm._isMounted) {
  2375. callHook(vm, 'updated');
  2376. }
  2377. }
  2378. }
  2379. /**
  2380. * Queue a kept-alive component that was activated during patch.
  2381. * The queue will be processed after the entire tree has been patched.
  2382. */
  2383. function queueActivatedComponent (vm) {
  2384. // setting _inactive to false here so that a render function can
  2385. // rely on checking whether it's in an inactive tree (e.g. router-view)
  2386. vm._inactive = false;
  2387. activatedChildren.push(vm);
  2388. }
  2389. function callActivatedHooks (queue) {
  2390. for (var i = 0; i < queue.length; i++) {
  2391. queue[i]._inactive = true;
  2392. activateChildComponent(queue[i], true /* true */);
  2393. }
  2394. }
  2395. /**
  2396. * Push a watcher into the watcher queue.
  2397. * Jobs with duplicate IDs will be skipped unless it's
  2398. * pushed when the queue is being flushed.
  2399. */
  2400. function queueWatcher (watcher) {
  2401. var id = watcher.id;
  2402. if (has[id] == null) {
  2403. has[id] = true;
  2404. if (!flushing) {
  2405. queue.push(watcher);
  2406. } else {
  2407. // if already flushing, splice the watcher based on its id
  2408. // if already past its id, it will be run next immediately.
  2409. var i = queue.length - 1;
  2410. while (i >= 0 && queue[i].id > watcher.id) {
  2411. i--;
  2412. }
  2413. queue.splice(Math.max(i, index) + 1, 0, watcher);
  2414. }
  2415. // queue the flush
  2416. if (!waiting) {
  2417. waiting = true;
  2418. nextTick(flushSchedulerQueue);
  2419. }
  2420. }
  2421. }
  2422. /* */
  2423. var uid$2 = 0;
  2424. /**
  2425. * A watcher parses an expression, collects dependencies,
  2426. * and fires callback when the expression value changes.
  2427. * This is used for both the $watch() api and directives.
  2428. */
  2429. var Watcher = function Watcher (
  2430. vm,
  2431. expOrFn,
  2432. cb,
  2433. options
  2434. ) {
  2435. this.vm = vm;
  2436. vm._watchers.push(this);
  2437. // options
  2438. if (options) {
  2439. this.deep = !!options.deep;
  2440. this.user = !!options.user;
  2441. this.lazy = !!options.lazy;
  2442. this.sync = !!options.sync;
  2443. } else {
  2444. this.deep = this.user = this.lazy = this.sync = false;
  2445. }
  2446. this.cb = cb;
  2447. this.id = ++uid$2; // uid for batching
  2448. this.active = true;
  2449. this.dirty = this.lazy; // for lazy watchers
  2450. this.deps = [];
  2451. this.newDeps = [];
  2452. this.depIds = new _Set();
  2453. this.newDepIds = new _Set();
  2454. this.expression = process.env.NODE_ENV !== 'production'
  2455. ? expOrFn.toString()
  2456. : '';
  2457. // parse expression for getter
  2458. if (typeof expOrFn === 'function') {
  2459. this.getter = expOrFn;
  2460. } else {
  2461. this.getter = parsePath(expOrFn);
  2462. if (!this.getter) {
  2463. this.getter = function () {};
  2464. process.env.NODE_ENV !== 'production' && warn(
  2465. "Failed watching path: \"" + expOrFn + "\" " +
  2466. 'Watcher only accepts simple dot-delimited paths. ' +
  2467. 'For full control, use a function instead.',
  2468. vm
  2469. );
  2470. }
  2471. }
  2472. this.value = this.lazy
  2473. ? undefined
  2474. : this.get();
  2475. };
  2476. /**
  2477. * Evaluate the getter, and re-collect dependencies.
  2478. */
  2479. Watcher.prototype.get = function get () {
  2480. pushTarget(this);
  2481. var value;
  2482. var vm = this.vm;
  2483. if (this.user) {
  2484. try {
  2485. value = this.getter.call(vm, vm);
  2486. } catch (e) {
  2487. handleError(e, vm, ("getter for watcher \"" + (this.expression) + "\""));
  2488. }
  2489. } else {
  2490. value = this.getter.call(vm, vm);
  2491. }
  2492. // "touch" every property so they are all tracked as
  2493. // dependencies for deep watching
  2494. if (this.deep) {
  2495. traverse(value);
  2496. }
  2497. popTarget();
  2498. this.cleanupDeps();
  2499. return value
  2500. };
  2501. /**
  2502. * Add a dependency to this directive.
  2503. */
  2504. Watcher.prototype.addDep = function addDep (dep) {
  2505. var id = dep.id;
  2506. if (!this.newDepIds.has(id)) {
  2507. this.newDepIds.add(id);
  2508. this.newDeps.push(dep);
  2509. if (!this.depIds.has(id)) {
  2510. dep.addSub(this);
  2511. }
  2512. }
  2513. };
  2514. /**
  2515. * Clean up for dependency collection.
  2516. */
  2517. Watcher.prototype.cleanupDeps = function cleanupDeps () {
  2518. var this$1 = this;
  2519. var i = this.deps.length;
  2520. while (i--) {
  2521. var dep = this$1.deps[i];
  2522. if (!this$1.newDepIds.has(dep.id)) {
  2523. dep.removeSub(this$1);
  2524. }
  2525. }
  2526. var tmp = this.depIds;
  2527. this.depIds = this.newDepIds;
  2528. this.newDepIds = tmp;
  2529. this.newDepIds.clear();
  2530. tmp = this.deps;
  2531. this.deps = this.newDeps;
  2532. this.newDeps = tmp;
  2533. this.newDeps.length = 0;
  2534. };
  2535. /**
  2536. * Subscriber interface.
  2537. * Will be called when a dependency changes.
  2538. */
  2539. Watcher.prototype.update = function update () {
  2540. /* istanbul ignore else */
  2541. if (this.lazy) {
  2542. this.dirty = true;
  2543. } else if (this.sync) {
  2544. this.run();
  2545. } else {
  2546. queueWatcher(this);
  2547. }
  2548. };
  2549. /**
  2550. * Scheduler job interface.
  2551. * Will be called by the scheduler.
  2552. */
  2553. Watcher.prototype.run = function run () {
  2554. if (this.active) {
  2555. var value = this.get();
  2556. if (
  2557. value !== this.value ||
  2558. // Deep watchers and watchers on Object/Arrays should fire even
  2559. // when the value is the same, because the value may
  2560. // have mutated.
  2561. isObject(value) ||
  2562. this.deep
  2563. ) {
  2564. // set new value
  2565. var oldValue = this.value;
  2566. this.value = value;
  2567. if (this.user) {
  2568. try {
  2569. this.cb.call(this.vm, value, oldValue);
  2570. } catch (e) {
  2571. handleError(e, this.vm, ("callback for watcher \"" + (this.expression) + "\""));
  2572. }
  2573. } else {
  2574. this.cb.call(this.vm, value, oldValue);
  2575. }
  2576. }
  2577. }
  2578. };
  2579. /**
  2580. * Evaluate the value of the watcher.
  2581. * This only gets called for lazy watchers.
  2582. */
  2583. Watcher.prototype.evaluate = function evaluate () {
  2584. this.value = this.get();
  2585. this.dirty = false;
  2586. };
  2587. /**
  2588. * Depend on all deps collected by this watcher.
  2589. */
  2590. Watcher.prototype.depend = function depend () {
  2591. var this$1 = this;
  2592. var i = this.deps.length;
  2593. while (i--) {
  2594. this$1.deps[i].depend();
  2595. }
  2596. };
  2597. /**
  2598. * Remove self from all dependencies' subscriber list.
  2599. */
  2600. Watcher.prototype.teardown = function teardown () {
  2601. var this$1 = this;
  2602. if (this.active) {
  2603. // remove self from vm's watcher list
  2604. // this is a somewhat expensive operation so we skip it
  2605. // if the vm is being destroyed.
  2606. if (!this.vm._isBeingDestroyed) {
  2607. remove(this.vm._watchers, this);
  2608. }
  2609. var i = this.deps.length;
  2610. while (i--) {
  2611. this$1.deps[i].removeSub(this$1);
  2612. }
  2613. this.active = false;
  2614. }
  2615. };
  2616. /**
  2617. * Recursively traverse an object to evoke all converted
  2618. * getters, so that every nested property inside the object
  2619. * is collected as a "deep" dependency.
  2620. */
  2621. var seenObjects = new _Set();
  2622. function traverse (val) {
  2623. seenObjects.clear();
  2624. _traverse(val, seenObjects);
  2625. }
  2626. function _traverse (val, seen) {
  2627. var i, keys;
  2628. var isA = Array.isArray(val);
  2629. if ((!isA && !isObject(val)) || !Object.isExtensible(val)) {
  2630. return
  2631. }
  2632. if (val.__ob__) {
  2633. var depId = val.__ob__.dep.id;
  2634. if (seen.has(depId)) {
  2635. return
  2636. }
  2637. seen.add(depId);
  2638. }
  2639. if (isA) {
  2640. i = val.length;
  2641. while (i--) { _traverse(val[i], seen); }
  2642. } else {
  2643. keys = Object.keys(val);
  2644. i = keys.length;
  2645. while (i--) { _traverse(val[keys[i]], seen); }
  2646. }
  2647. }
  2648. /* */
  2649. var sharedPropertyDefinition = {
  2650. enumerable: true,
  2651. configurable: true,
  2652. get: noop,
  2653. set: noop
  2654. };
  2655. function proxy (target, sourceKey, key) {
  2656. sharedPropertyDefinition.get = function proxyGetter () {
  2657. return this[sourceKey][key]
  2658. };
  2659. sharedPropertyDefinition.set = function proxySetter (val) {
  2660. this[sourceKey][key] = val;
  2661. };
  2662. Object.defineProperty(target, key, sharedPropertyDefinition);
  2663. }
  2664. function initState (vm) {
  2665. vm._watchers = [];
  2666. var opts = vm.$options;
  2667. if (opts.props) { initProps(vm, opts.props); }
  2668. if (opts.methods) { initMethods(vm, opts.methods); }
  2669. if (opts.data) {
  2670. initData(vm);
  2671. } else {
  2672. observe(vm._data = {}, true /* asRootData */);
  2673. }
  2674. if (opts.computed) { initComputed(vm, opts.computed); }
  2675. if (opts.watch) { initWatch(vm, opts.watch); }
  2676. }
  2677. var isReservedProp = {
  2678. key: 1,
  2679. ref: 1,
  2680. slot: 1
  2681. };
  2682. function initProps (vm, propsOptions) {
  2683. var propsData = vm.$options.propsData || {};
  2684. var props = vm._props = {};
  2685. // cache prop keys so that future props updates can iterate using Array
  2686. // instead of dynamic object key enumeration.
  2687. var keys = vm.$options._propKeys = [];
  2688. var isRoot = !vm.$parent;
  2689. // root instance props should be converted
  2690. observerState.shouldConvert = isRoot;
  2691. var loop = function ( key ) {
  2692. keys.push(key);
  2693. var value = validateProp(key, propsOptions, propsData, vm);
  2694. /* istanbul ignore else */
  2695. if (process.env.NODE_ENV !== 'production') {
  2696. if (isReservedProp[key] || config.isReservedAttr(key)) {
  2697. warn(
  2698. ("\"" + key + "\" is a reserved attribute and cannot be used as component prop."),
  2699. vm
  2700. );
  2701. }
  2702. defineReactive$$1(props, key, value, function () {
  2703. if (vm.$parent && !observerState.isSettingProps) {
  2704. warn(
  2705. "Avoid mutating a prop directly since the value will be " +
  2706. "overwritten whenever the parent component re-renders. " +
  2707. "Instead, use a data or computed property based on the prop's " +
  2708. "value. Prop being mutated: \"" + key + "\"",
  2709. vm
  2710. );
  2711. }
  2712. });
  2713. } else {
  2714. defineReactive$$1(props, key, value);
  2715. }
  2716. // static props are already proxied on the component's prototype
  2717. // during Vue.extend(). We only need to proxy props defined at
  2718. // instantiation here.
  2719. if (!(key in vm)) {
  2720. proxy(vm, "_props", key);
  2721. }
  2722. };
  2723. for (var key in propsOptions) loop( key );
  2724. observerState.shouldConvert = true;
  2725. }
  2726. function initData (vm) {
  2727. var data = vm.$options.data;
  2728. data = vm._data = typeof data === 'function'
  2729. ? getData(data, vm)
  2730. : data || {};
  2731. if (!isPlainObject(data)) {
  2732. data = {};
  2733. process.env.NODE_ENV !== 'production' && warn(
  2734. 'data functions should return an object:\n' +
  2735. 'https://vuejs.org/v2/guide/components.html#data-Must-Be-a-Function',
  2736. vm
  2737. );
  2738. }
  2739. // proxy data on instance
  2740. var keys = Object.keys(data);
  2741. var props = vm.$options.props;
  2742. var i = keys.length;
  2743. while (i--) {
  2744. if (props && hasOwn(props, keys[i])) {
  2745. process.env.NODE_ENV !== 'production' && warn(
  2746. "The data property \"" + (keys[i]) + "\" is already declared as a prop. " +
  2747. "Use prop default value instead.",
  2748. vm
  2749. );
  2750. } else if (!isReserved(keys[i])) {
  2751. proxy(vm, "_data", keys[i]);
  2752. }
  2753. }
  2754. // observe data
  2755. observe(data, true /* asRootData */);
  2756. }
  2757. function getData (data, vm) {
  2758. try {
  2759. return data.call(vm)
  2760. } catch (e) {
  2761. handleError(e, vm, "data()");
  2762. return {}
  2763. }
  2764. }
  2765. var computedWatcherOptions = { lazy: true };
  2766. function initComputed (vm, computed) {
  2767. var watchers = vm._computedWatchers = Object.create(null);
  2768. for (var key in computed) {
  2769. var userDef = computed[key];
  2770. var getter = typeof userDef === 'function' ? userDef : userDef.get;
  2771. if (process.env.NODE_ENV !== 'production') {
  2772. if (getter === undefined) {
  2773. warn(
  2774. ("No getter function has been defined for computed property \"" + key + "\"."),
  2775. vm
  2776. );
  2777. getter = noop;
  2778. }
  2779. }
  2780. // create internal watcher for the computed property.
  2781. watchers[key] = new Watcher(vm, getter, noop, computedWatcherOptions);
  2782. // component-defined computed properties are already defined on the
  2783. // component prototype. We only need to define computed properties defined
  2784. // at instantiation here.
  2785. if (!(key in vm)) {
  2786. defineComputed(vm, key, userDef);
  2787. } else if (process.env.NODE_ENV !== 'production') {
  2788. if (key in vm.$data) {
  2789. warn(("The computed property \"" + key + "\" is already defined in data."), vm);
  2790. } else if (vm.$options.props && key in vm.$options.props) {
  2791. warn(("The computed property \"" + key + "\" is already defined as a prop."), vm);
  2792. }
  2793. }
  2794. }
  2795. }
  2796. function defineComputed (target, key, userDef) {
  2797. if (typeof userDef === 'function') {
  2798. sharedPropertyDefinition.get = createComputedGetter(key);
  2799. sharedPropertyDefinition.set = noop;
  2800. } else {
  2801. sharedPropertyDefinition.get = userDef.get
  2802. ? userDef.cache !== false
  2803. ? createComputedGetter(key)
  2804. : userDef.get
  2805. : noop;
  2806. sharedPropertyDefinition.set = userDef.set
  2807. ? userDef.set
  2808. : noop;
  2809. }
  2810. Object.defineProperty(target, key, sharedPropertyDefinition);
  2811. }
  2812. function createComputedGetter (key) {
  2813. return function computedGetter () {
  2814. var watcher = this._computedWatchers && this._computedWatchers[key];
  2815. if (watcher) {
  2816. if (watcher.dirty) {
  2817. watcher.evaluate();
  2818. }
  2819. if (Dep.target) {
  2820. watcher.depend();
  2821. }
  2822. return watcher.value
  2823. }
  2824. }
  2825. }
  2826. function initMethods (vm, methods) {
  2827. var props = vm.$options.props;
  2828. for (var key in methods) {
  2829. vm[key] = methods[key] == null ? noop : bind(methods[key], vm);
  2830. if (process.env.NODE_ENV !== 'production') {
  2831. if (methods[key] == null) {
  2832. warn(
  2833. "method \"" + key + "\" has an undefined value in the component definition. " +
  2834. "Did you reference the function correctly?",
  2835. vm
  2836. );
  2837. }
  2838. if (props && hasOwn(props, key)) {
  2839. warn(
  2840. ("method \"" + key + "\" has already been defined as a prop."),
  2841. vm
  2842. );
  2843. }
  2844. }
  2845. }
  2846. }
  2847. function initWatch (vm, watch) {
  2848. for (var key in watch) {
  2849. var handler = watch[key];
  2850. if (Array.isArray(handler)) {
  2851. for (var i = 0; i < handler.length; i++) {
  2852. createWatcher(vm, key, handler[i]);
  2853. }
  2854. } else {
  2855. createWatcher(vm, key, handler);
  2856. }
  2857. }
  2858. }
  2859. function createWatcher (vm, key, handler) {
  2860. var options;
  2861. if (isPlainObject(handler)) {
  2862. options = handler;
  2863. handler = handler.handler;
  2864. }
  2865. if (typeof handler === 'string') {
  2866. handler = vm[handler];
  2867. }
  2868. vm.$watch(key, handler, options);
  2869. }
  2870. function stateMixin (Vue) {
  2871. // flow somehow has problems with directly declared definition object
  2872. // when using Object.defineProperty, so we have to procedurally build up
  2873. // the object here.
  2874. var dataDef = {};
  2875. dataDef.get = function () { return this._data };
  2876. var propsDef = {};
  2877. propsDef.get = function () { return this._props };
  2878. if (process.env.NODE_ENV !== 'production') {
  2879. dataDef.set = function (newData) {
  2880. warn(
  2881. 'Avoid replacing instance root $data. ' +
  2882. 'Use nested data properties instead.',
  2883. this
  2884. );
  2885. };
  2886. propsDef.set = function () {
  2887. warn("$props is readonly.", this);
  2888. };
  2889. }
  2890. Object.defineProperty(Vue.prototype, '$data', dataDef);
  2891. Object.defineProperty(Vue.prototype, '$props', propsDef);
  2892. Vue.prototype.$set = set;
  2893. Vue.prototype.$delete = del;
  2894. Vue.prototype.$watch = function (
  2895. expOrFn,
  2896. cb,
  2897. options
  2898. ) {
  2899. var vm = this;
  2900. options = options || {};
  2901. options.user = true;
  2902. var watcher = new Watcher(vm, expOrFn, cb, options);
  2903. if (options.immediate) {
  2904. cb.call(vm, watcher.value);
  2905. }
  2906. return function unwatchFn () {
  2907. watcher.teardown();
  2908. }
  2909. };
  2910. }
  2911. /* */
  2912. function initProvide (vm) {
  2913. var provide = vm.$options.provide;
  2914. if (provide) {
  2915. vm._provided = typeof provide === 'function'
  2916. ? provide.call(vm)
  2917. : provide;
  2918. }
  2919. }
  2920. function initInjections (vm) {
  2921. var result = resolveInject(vm.$options.inject, vm);
  2922. if (result) {
  2923. Object.keys(result).forEach(function (key) {
  2924. /* istanbul ignore else */
  2925. if (process.env.NODE_ENV !== 'production') {
  2926. defineReactive$$1(vm, key, result[key], function () {
  2927. warn(
  2928. "Avoid mutating an injected value directly since the changes will be " +
  2929. "overwritten whenever the provided component re-renders. " +
  2930. "injection being mutated: \"" + key + "\"",
  2931. vm
  2932. );
  2933. });
  2934. } else {
  2935. defineReactive$$1(vm, key, result[key]);
  2936. }
  2937. });
  2938. }
  2939. }
  2940. function resolveInject (inject, vm) {
  2941. if (inject) {
  2942. // inject is :any because flow is not smart enough to figure out cached
  2943. // isArray here
  2944. var isArray = Array.isArray(inject);
  2945. var result = Object.create(null);
  2946. var keys = isArray
  2947. ? inject
  2948. : hasSymbol
  2949. ? Reflect.ownKeys(inject)
  2950. : Object.keys(inject);
  2951. for (var i = 0; i < keys.length; i++) {
  2952. var key = keys[i];
  2953. var provideKey = isArray ? key : inject[key];
  2954. var source = vm;
  2955. while (source) {
  2956. if (source._provided && provideKey in source._provided) {
  2957. result[key] = source._provided[provideKey];
  2958. break
  2959. }
  2960. source = source.$parent;
  2961. }
  2962. }
  2963. return result
  2964. }
  2965. }
  2966. /* */
  2967. function createFunctionalComponent (
  2968. Ctor,
  2969. propsData,
  2970. data,
  2971. context,
  2972. children
  2973. ) {
  2974. var props = {};
  2975. var propOptions = Ctor.options.props;
  2976. if (isDef(propOptions)) {
  2977. for (var key in propOptions) {
  2978. props[key] = validateProp(key, propOptions, propsData);
  2979. }
  2980. } else {
  2981. if (isDef(data.attrs)) { mergeProps(props, data.attrs); }
  2982. if (isDef(data.props)) { mergeProps(props, data.props); }
  2983. }
  2984. // ensure the createElement function in functional components
  2985. // gets a unique context - this is necessary for correct named slot check
  2986. var _context = Object.create(context);
  2987. var h = function (a, b, c, d) { return createElement(_context, a, b, c, d, true); };
  2988. var vnode = Ctor.options.render.call(null, h, {
  2989. data: data,
  2990. props: props,
  2991. children: children,
  2992. parent: context,
  2993. listeners: data.on || {},
  2994. injections: resolveInject(Ctor.options.inject, context),
  2995. slots: function () { return resolveSlots(children, context); }
  2996. });
  2997. if (vnode instanceof VNode) {
  2998. vnode.functionalContext = context;
  2999. if (data.slot) {
  3000. (vnode.data || (vnode.data = {})).slot = data.slot;
  3001. }
  3002. }
  3003. return vnode
  3004. }
  3005. function mergeProps (to, from) {
  3006. for (var key in from) {
  3007. to[camelize(key)] = from[key];
  3008. }
  3009. }
  3010. /* */
  3011. // hooks to be invoked on component VNodes during patch
  3012. var componentVNodeHooks = {
  3013. init: function init (
  3014. vnode,
  3015. hydrating,
  3016. parentElm,
  3017. refElm
  3018. ) {
  3019. if (!vnode.componentInstance || vnode.componentInstance._isDestroyed) {
  3020. var child = vnode.componentInstance = createComponentInstanceForVnode(
  3021. vnode,
  3022. activeInstance,
  3023. parentElm,
  3024. refElm
  3025. );
  3026. child.$mount(hydrating ? vnode.elm : undefined, hydrating);
  3027. } else if (vnode.data.keepAlive) {
  3028. // kept-alive components, treat as a patch
  3029. var mountedNode = vnode; // work around flow
  3030. componentVNodeHooks.prepatch(mountedNode, mountedNode);
  3031. }
  3032. },
  3033. prepatch: function prepatch (oldVnode, vnode) {
  3034. var options = vnode.componentOptions;
  3035. var child = vnode.componentInstance = oldVnode.componentInstance;
  3036. updateChildComponent(
  3037. child,
  3038. options.propsData, // updated props
  3039. options.listeners, // updated listeners
  3040. vnode, // new parent vnode
  3041. options.children // new children
  3042. );
  3043. },
  3044. insert: function insert (vnode) {
  3045. var context = vnode.context;
  3046. var componentInstance = vnode.componentInstance;
  3047. if (!componentInstance._isMounted) {
  3048. componentInstance._isMounted = true;
  3049. callHook(componentInstance, 'mounted');
  3050. }
  3051. if (vnode.data.keepAlive) {
  3052. if (context._isMounted) {
  3053. // vue-router#1212
  3054. // During updates, a kept-alive component's child components may
  3055. // change, so directly walking the tree here may call activated hooks
  3056. // on incorrect children. Instead we push them into a queue which will
  3057. // be processed after the whole patch process ended.
  3058. queueActivatedComponent(componentInstance);
  3059. } else {
  3060. activateChildComponent(componentInstance, true /* direct */);
  3061. }
  3062. }
  3063. },
  3064. destroy: function destroy (vnode) {
  3065. var componentInstance = vnode.componentInstance;
  3066. if (!componentInstance._isDestroyed) {
  3067. if (!vnode.data.keepAlive) {
  3068. componentInstance.$destroy();
  3069. } else {
  3070. deactivateChildComponent(componentInstance, true /* direct */);
  3071. }
  3072. }
  3073. }
  3074. };
  3075. var hooksToMerge = Object.keys(componentVNodeHooks);
  3076. function createComponent (
  3077. Ctor,
  3078. data,
  3079. context,
  3080. children,
  3081. tag
  3082. ) {
  3083. if (isUndef(Ctor)) {
  3084. return
  3085. }
  3086. var baseCtor = context.$options._base;
  3087. // plain options object: turn it into a constructor
  3088. if (isObject(Ctor)) {
  3089. Ctor = baseCtor.extend(Ctor);
  3090. }
  3091. // if at this stage it's not a constructor or an async component factory,
  3092. // reject.
  3093. if (typeof Ctor !== 'function') {
  3094. if (process.env.NODE_ENV !== 'production') {
  3095. warn(("Invalid Component definition: " + (String(Ctor))), context);
  3096. }
  3097. return
  3098. }
  3099. // async component
  3100. if (isUndef(Ctor.cid)) {
  3101. Ctor = resolveAsyncComponent(Ctor, baseCtor, context);
  3102. if (Ctor === undefined) {
  3103. // return nothing if this is indeed an async component
  3104. // wait for the callback to trigger parent update.
  3105. return
  3106. }
  3107. }
  3108. // resolve constructor options in case global mixins are applied after
  3109. // component constructor creation
  3110. resolveConstructorOptions(Ctor);
  3111. data = data || {};
  3112. // transform component v-model data into props & events
  3113. if (isDef(data.model)) {
  3114. transformModel(Ctor.options, data);
  3115. }
  3116. // extract props
  3117. var propsData = extractPropsFromVNodeData(data, Ctor, tag);
  3118. // functional component
  3119. if (isTrue(Ctor.options.functional)) {
  3120. return createFunctionalComponent(Ctor, propsData, data, context, children)
  3121. }
  3122. // extract listeners, since these needs to be treated as
  3123. // child component listeners instead of DOM listeners
  3124. var listeners = data.on;
  3125. // replace with listeners with .native modifier
  3126. data.on = data.nativeOn;
  3127. if (isTrue(Ctor.options.abstract)) {
  3128. // abstract components do not keep anything
  3129. // other than props & listeners
  3130. data = {};
  3131. }
  3132. // merge component management hooks onto the placeholder node
  3133. mergeHooks(data);
  3134. // return a placeholder vnode
  3135. var name = Ctor.options.name || tag;
  3136. var vnode = new VNode(
  3137. ("vue-component-" + (Ctor.cid) + (name ? ("-" + name) : '')),
  3138. data, undefined, undefined, undefined, context,
  3139. { Ctor: Ctor, propsData: propsData, listeners: listeners, tag: tag, children: children }
  3140. );
  3141. return vnode
  3142. }
  3143. function createComponentInstanceForVnode (
  3144. vnode, // we know it's MountedComponentVNode but flow doesn't
  3145. parent, // activeInstance in lifecycle state
  3146. parentElm,
  3147. refElm
  3148. ) {
  3149. var vnodeComponentOptions = vnode.componentOptions;
  3150. var options = {
  3151. _isComponent: true,
  3152. parent: parent,
  3153. propsData: vnodeComponentOptions.propsData,
  3154. _componentTag: vnodeComponentOptions.tag,
  3155. _parentVnode: vnode,
  3156. _parentListeners: vnodeComponentOptions.listeners,
  3157. _renderChildren: vnodeComponentOptions.children,
  3158. _parentElm: parentElm || null,
  3159. _refElm: refElm || null
  3160. };
  3161. // check inline-template render functions
  3162. var inlineTemplate = vnode.data.inlineTemplate;
  3163. if (isDef(inlineTemplate)) {
  3164. options.render = inlineTemplate.render;
  3165. options.staticRenderFns = inlineTemplate.staticRenderFns;
  3166. }
  3167. return new vnodeComponentOptions.Ctor(options)
  3168. }
  3169. function mergeHooks (data) {
  3170. if (!data.hook) {
  3171. data.hook = {};
  3172. }
  3173. for (var i = 0; i < hooksToMerge.length; i++) {
  3174. var key = hooksToMerge[i];
  3175. var fromParent = data.hook[key];
  3176. var ours = componentVNodeHooks[key];
  3177. data.hook[key] = fromParent ? mergeHook$1(ours, fromParent) : ours;
  3178. }
  3179. }
  3180. function mergeHook$1 (one, two) {
  3181. return function (a, b, c, d) {
  3182. one(a, b, c, d);
  3183. two(a, b, c, d);
  3184. }
  3185. }
  3186. // transform component v-model info (value and callback) into
  3187. // prop and event handler respectively.
  3188. function transformModel (options, data) {
  3189. var prop = (options.model && options.model.prop) || 'value';
  3190. var event = (options.model && options.model.event) || 'input';(data.props || (data.props = {}))[prop] = data.model.value;
  3191. var on = data.on || (data.on = {});
  3192. if (isDef(on[event])) {
  3193. on[event] = [data.model.callback].concat(on[event]);
  3194. } else {
  3195. on[event] = data.model.callback;
  3196. }
  3197. }
  3198. /* */
  3199. var SIMPLE_NORMALIZE = 1;
  3200. var ALWAYS_NORMALIZE = 2;
  3201. // wrapper function for providing a more flexible interface
  3202. // without getting yelled at by flow
  3203. function createElement (
  3204. context,
  3205. tag,
  3206. data,
  3207. children,
  3208. normalizationType,
  3209. alwaysNormalize
  3210. ) {
  3211. if (Array.isArray(data) || isPrimitive(data)) {
  3212. normalizationType = children;
  3213. children = data;
  3214. data = undefined;
  3215. }
  3216. if (isTrue(alwaysNormalize)) {
  3217. normalizationType = ALWAYS_NORMALIZE;
  3218. }
  3219. return _createElement(context, tag, data, children, normalizationType)
  3220. }
  3221. function _createElement (
  3222. context,
  3223. tag,
  3224. data,
  3225. children,
  3226. normalizationType
  3227. ) {
  3228. if (isDef(data) && isDef((data).__ob__)) {
  3229. process.env.NODE_ENV !== 'production' && warn(
  3230. "Avoid using observed data object as vnode data: " + (JSON.stringify(data)) + "\n" +
  3231. 'Always create fresh vnode data objects in each render!',
  3232. context
  3233. );
  3234. return createEmptyVNode()
  3235. }
  3236. if (!tag) {
  3237. // in case of component :is set to falsy value
  3238. return createEmptyVNode()
  3239. }
  3240. // support single function children as default scoped slot
  3241. if (Array.isArray(children) &&
  3242. typeof children[0] === 'function') {
  3243. data = data || {};
  3244. data.scopedSlots = { default: children[0] };
  3245. children.length = 0;
  3246. }
  3247. if (normalizationType === ALWAYS_NORMALIZE) {
  3248. children = normalizeChildren(children);
  3249. } else if (normalizationType === SIMPLE_NORMALIZE) {
  3250. children = simpleNormalizeChildren(children);
  3251. }
  3252. var vnode, ns;
  3253. if (typeof tag === 'string') {
  3254. var Ctor;
  3255. ns = config.getTagNamespace(tag);
  3256. if (config.isReservedTag(tag)) {
  3257. // platform built-in elements
  3258. vnode = new VNode(
  3259. config.parsePlatformTagName(tag), data, children,
  3260. undefined, undefined, context
  3261. );
  3262. } else if (isDef(Ctor = resolveAsset(context.$options, 'components', tag))) {
  3263. // component
  3264. vnode = createComponent(Ctor, data, context, children, tag);
  3265. } else {
  3266. // unknown or unlisted namespaced elements
  3267. // check at runtime because it may get assigned a namespace when its
  3268. // parent normalizes children
  3269. vnode = new VNode(
  3270. tag, data, children,
  3271. undefined, undefined, context
  3272. );
  3273. }
  3274. } else {
  3275. // direct component options / constructor
  3276. vnode = createComponent(tag, data, context, children);
  3277. }
  3278. if (vnode !== undefined) {
  3279. if (ns) { applyNS(vnode, ns); }
  3280. return vnode
  3281. } else {
  3282. return createEmptyVNode()
  3283. }
  3284. }
  3285. function applyNS (vnode, ns) {
  3286. vnode.ns = ns;
  3287. if (vnode.tag === 'foreignObject') {
  3288. // use default namespace inside foreignObject
  3289. return
  3290. }
  3291. if (Array.isArray(vnode.children)) {
  3292. for (var i = 0, l = vnode.children.length; i < l; i++) {
  3293. var child = vnode.children[i];
  3294. if (isDef(child.tag) && isUndef(child.ns)) {
  3295. applyNS(child, ns);
  3296. }
  3297. }
  3298. }
  3299. }
  3300. /* */
  3301. /**
  3302. * Runtime helper for rendering v-for lists.
  3303. */
  3304. function renderList (
  3305. val,
  3306. render
  3307. ) {
  3308. var ret, i, l, keys, key;
  3309. if (Array.isArray(val) || typeof val === 'string') {
  3310. ret = new Array(val.length);
  3311. for (i = 0, l = val.length; i < l; i++) {
  3312. ret[i] = render(val[i], i);
  3313. }
  3314. } else if (typeof val === 'number') {
  3315. ret = new Array(val);
  3316. for (i = 0; i < val; i++) {
  3317. ret[i] = render(i + 1, i);
  3318. }
  3319. } else if (isObject(val)) {
  3320. keys = Object.keys(val);
  3321. ret = new Array(keys.length);
  3322. for (i = 0, l = keys.length; i < l; i++) {
  3323. key = keys[i];
  3324. ret[i] = render(val[key], key, i);
  3325. }
  3326. }
  3327. return ret
  3328. }
  3329. /* */
  3330. /**
  3331. * Runtime helper for rendering <slot>
  3332. */
  3333. function renderSlot (
  3334. name,
  3335. fallback,
  3336. props,
  3337. bindObject
  3338. ) {
  3339. var scopedSlotFn = this.$scopedSlots[name];
  3340. if (scopedSlotFn) { // scoped slot
  3341. props = props || {};
  3342. if (bindObject) {
  3343. extend(props, bindObject);
  3344. }
  3345. return scopedSlotFn(props) || fallback
  3346. } else {
  3347. var slotNodes = this.$slots[name];
  3348. // warn duplicate slot usage
  3349. if (slotNodes && process.env.NODE_ENV !== 'production') {
  3350. slotNodes._rendered && warn(
  3351. "Duplicate presence of slot \"" + name + "\" found in the same render tree " +
  3352. "- this will likely cause render errors.",
  3353. this
  3354. );
  3355. slotNodes._rendered = true;
  3356. }
  3357. return slotNodes || fallback
  3358. }
  3359. }
  3360. /* */
  3361. /**
  3362. * Runtime helper for resolving filters
  3363. */
  3364. function resolveFilter (id) {
  3365. return resolveAsset(this.$options, 'filters', id, true) || identity
  3366. }
  3367. /* */
  3368. /**
  3369. * Runtime helper for checking keyCodes from config.
  3370. */
  3371. function checkKeyCodes (
  3372. eventKeyCode,
  3373. key,
  3374. builtInAlias
  3375. ) {
  3376. var keyCodes = config.keyCodes[key] || builtInAlias;
  3377. if (Array.isArray(keyCodes)) {
  3378. return keyCodes.indexOf(eventKeyCode) === -1
  3379. } else {
  3380. return keyCodes !== eventKeyCode
  3381. }
  3382. }
  3383. /* */
  3384. /**
  3385. * Runtime helper for merging v-bind="object" into a VNode's data.
  3386. */
  3387. function bindObjectProps (
  3388. data,
  3389. tag,
  3390. value,
  3391. asProp
  3392. ) {
  3393. if (value) {
  3394. if (!isObject(value)) {
  3395. process.env.NODE_ENV !== 'production' && warn(
  3396. 'v-bind without argument expects an Object or Array value',
  3397. this
  3398. );
  3399. } else {
  3400. if (Array.isArray(value)) {
  3401. value = toObject(value);
  3402. }
  3403. var hash;
  3404. for (var key in value) {
  3405. if (key === 'class' || key === 'style') {
  3406. hash = data;
  3407. } else {
  3408. var type = data.attrs && data.attrs.type;
  3409. hash = asProp || config.mustUseProp(tag, type, key)
  3410. ? data.domProps || (data.domProps = {})
  3411. : data.attrs || (data.attrs = {});
  3412. }
  3413. if (!(key in hash)) {
  3414. hash[key] = value[key];
  3415. }
  3416. }
  3417. }
  3418. }
  3419. return data
  3420. }
  3421. /* */
  3422. /**
  3423. * Runtime helper for rendering static trees.
  3424. */
  3425. function renderStatic (
  3426. index,
  3427. isInFor
  3428. ) {
  3429. var tree = this._staticTrees[index];
  3430. // if has already-rendered static tree and not inside v-for,
  3431. // we can reuse the same tree by doing a shallow clone.
  3432. if (tree && !isInFor) {
  3433. return Array.isArray(tree)
  3434. ? cloneVNodes(tree)
  3435. : cloneVNode(tree)
  3436. }
  3437. // otherwise, render a fresh tree.
  3438. tree = this._staticTrees[index] =
  3439. this.$options.staticRenderFns[index].call(this._renderProxy);
  3440. markStatic(tree, ("__static__" + index), false);
  3441. return tree
  3442. }
  3443. /**
  3444. * Runtime helper for v-once.
  3445. * Effectively it means marking the node as static with a unique key.
  3446. */
  3447. function markOnce (
  3448. tree,
  3449. index,
  3450. key
  3451. ) {
  3452. markStatic(tree, ("__once__" + index + (key ? ("_" + key) : "")), true);
  3453. return tree
  3454. }
  3455. function markStatic (
  3456. tree,
  3457. key,
  3458. isOnce
  3459. ) {
  3460. if (Array.isArray(tree)) {
  3461. for (var i = 0; i < tree.length; i++) {
  3462. if (tree[i] && typeof tree[i] !== 'string') {
  3463. markStaticNode(tree[i], (key + "_" + i), isOnce);
  3464. }
  3465. }
  3466. } else {
  3467. markStaticNode(tree, key, isOnce);
  3468. }
  3469. }
  3470. function markStaticNode (node, key, isOnce) {
  3471. node.isStatic = true;
  3472. node.key = key;
  3473. node.isOnce = isOnce;
  3474. }
  3475. /* */
  3476. function initRender (vm) {
  3477. vm._vnode = null; // the root of the child tree
  3478. vm._staticTrees = null;
  3479. var parentVnode = vm.$vnode = vm.$options._parentVnode; // the placeholder node in parent tree
  3480. var renderContext = parentVnode && parentVnode.context;
  3481. vm.$slots = resolveSlots(vm.$options._renderChildren, renderContext);
  3482. vm.$scopedSlots = emptyObject;
  3483. // bind the createElement fn to this instance
  3484. // so that we get proper render context inside it.
  3485. // args order: tag, data, children, normalizationType, alwaysNormalize
  3486. // internal version is used by render functions compiled from templates
  3487. vm._c = function (a, b, c, d) { return createElement(vm, a, b, c, d, false); };
  3488. // normalization is always applied for the public version, used in
  3489. // user-written render functions.
  3490. vm.$createElement = function (a, b, c, d) { return createElement(vm, a, b, c, d, true); };
  3491. }
  3492. function renderMixin (Vue) {
  3493. Vue.prototype.$nextTick = function (fn) {
  3494. return nextTick(fn, this)
  3495. };
  3496. Vue.prototype._render = function () {
  3497. var vm = this;
  3498. var ref = vm.$options;
  3499. var render = ref.render;
  3500. var staticRenderFns = ref.staticRenderFns;
  3501. var _parentVnode = ref._parentVnode;
  3502. if (vm._isMounted) {
  3503. // clone slot nodes on re-renders
  3504. for (var key in vm.$slots) {
  3505. vm.$slots[key] = cloneVNodes(vm.$slots[key]);
  3506. }
  3507. }
  3508. vm.$scopedSlots = (_parentVnode && _parentVnode.data.scopedSlots) || emptyObject;
  3509. if (staticRenderFns && !vm._staticTrees) {
  3510. vm._staticTrees = [];
  3511. }
  3512. // set parent vnode. this allows render functions to have access
  3513. // to the data on the placeholder node.
  3514. vm.$vnode = _parentVnode;
  3515. // render self
  3516. var vnode;
  3517. try {
  3518. vnode = render.call(vm._renderProxy, vm.$createElement);
  3519. } catch (e) {
  3520. handleError(e, vm, "render function");
  3521. // return error render result,
  3522. // or previous vnode to prevent render error causing blank component
  3523. /* istanbul ignore else */
  3524. if (process.env.NODE_ENV !== 'production') {
  3525. vnode = vm.$options.renderError
  3526. ? vm.$options.renderError.call(vm._renderProxy, vm.$createElement, e)
  3527. : vm._vnode;
  3528. } else {
  3529. vnode = vm._vnode;
  3530. }
  3531. }
  3532. // return empty vnode in case the render function errored out
  3533. if (!(vnode instanceof VNode)) {
  3534. if (process.env.NODE_ENV !== 'production' && Array.isArray(vnode)) {
  3535. warn(
  3536. 'Multiple root nodes returned from render function. Render function ' +
  3537. 'should return a single root node.',
  3538. vm
  3539. );
  3540. }
  3541. vnode = createEmptyVNode();
  3542. }
  3543. // set parent
  3544. vnode.parent = _parentVnode;
  3545. return vnode
  3546. };
  3547. // internal render helpers.
  3548. // these are exposed on the instance prototype to reduce generated render
  3549. // code size.
  3550. Vue.prototype._o = markOnce;
  3551. Vue.prototype._n = toNumber;
  3552. Vue.prototype._s = _toString;
  3553. Vue.prototype._l = renderList;
  3554. Vue.prototype._t = renderSlot;
  3555. Vue.prototype._q = looseEqual;
  3556. Vue.prototype._i = looseIndexOf;
  3557. Vue.prototype._m = renderStatic;
  3558. Vue.prototype._f = resolveFilter;
  3559. Vue.prototype._k = checkKeyCodes;
  3560. Vue.prototype._b = bindObjectProps;
  3561. Vue.prototype._v = createTextVNode;
  3562. Vue.prototype._e = createEmptyVNode;
  3563. Vue.prototype._u = resolveScopedSlots;
  3564. }
  3565. /* */
  3566. var uid = 0;
  3567. function initMixin (Vue) {
  3568. Vue.prototype._init = function (options) {
  3569. var vm = this;
  3570. // a uid
  3571. vm._uid = uid++;
  3572. var startTag, endTag;
  3573. /* istanbul ignore if */
  3574. if (process.env.NODE_ENV !== 'production' && config.performance && mark) {
  3575. startTag = "vue-perf-init:" + (vm._uid);
  3576. endTag = "vue-perf-end:" + (vm._uid);
  3577. mark(startTag);
  3578. }
  3579. // a flag to avoid this being observed
  3580. vm._isVue = true;
  3581. // merge options
  3582. if (options && options._isComponent) {
  3583. // optimize internal component instantiation
  3584. // since dynamic options merging is pretty slow, and none of the
  3585. // internal component options needs special treatment.
  3586. initInternalComponent(vm, options);
  3587. } else {
  3588. vm.$options = mergeOptions(
  3589. resolveConstructorOptions(vm.constructor),
  3590. options || {},
  3591. vm
  3592. );
  3593. }
  3594. /* istanbul ignore else */
  3595. if (process.env.NODE_ENV !== 'production') {
  3596. initProxy(vm);
  3597. } else {
  3598. vm._renderProxy = vm;
  3599. }
  3600. // expose real self
  3601. vm._self = vm;
  3602. initLifecycle(vm);
  3603. initEvents(vm);
  3604. initRender(vm);
  3605. callHook(vm, 'beforeCreate');
  3606. initInjections(vm); // resolve injections before data/props
  3607. initState(vm);
  3608. initProvide(vm); // resolve provide after data/props
  3609. callHook(vm, 'created');
  3610. /* istanbul ignore if */
  3611. if (process.env.NODE_ENV !== 'production' && config.performance && mark) {
  3612. vm._name = formatComponentName(vm, false);
  3613. mark(endTag);
  3614. measure(((vm._name) + " init"), startTag, endTag);
  3615. }
  3616. if (vm.$options.el) {
  3617. vm.$mount(vm.$options.el);
  3618. }
  3619. };
  3620. }
  3621. function initInternalComponent (vm, options) {
  3622. var opts = vm.$options = Object.create(vm.constructor.options);
  3623. // doing this because it's faster than dynamic enumeration.
  3624. opts.parent = options.parent;
  3625. opts.propsData = options.propsData;
  3626. opts._parentVnode = options._parentVnode;
  3627. opts._parentListeners = options._parentListeners;
  3628. opts._renderChildren = options._renderChildren;
  3629. opts._componentTag = options._componentTag;
  3630. opts._parentElm = options._parentElm;
  3631. opts._refElm = options._refElm;
  3632. if (options.render) {
  3633. opts.render = options.render;
  3634. opts.staticRenderFns = options.staticRenderFns;
  3635. }
  3636. }
  3637. function resolveConstructorOptions (Ctor) {
  3638. var options = Ctor.options;
  3639. if (Ctor.super) {
  3640. var superOptions = resolveConstructorOptions(Ctor.super);
  3641. var cachedSuperOptions = Ctor.superOptions;
  3642. if (superOptions !== cachedSuperOptions) {
  3643. // super option changed,
  3644. // need to resolve new options.
  3645. Ctor.superOptions = superOptions;
  3646. // check if there are any late-modified/attached options (#4976)
  3647. var modifiedOptions = resolveModifiedOptions(Ctor);
  3648. // update base extend options
  3649. if (modifiedOptions) {
  3650. extend(Ctor.extendOptions, modifiedOptions);
  3651. }
  3652. options = Ctor.options = mergeOptions(superOptions, Ctor.extendOptions);
  3653. if (options.name) {
  3654. options.components[options.name] = Ctor;
  3655. }
  3656. }
  3657. }
  3658. return options
  3659. }
  3660. function resolveModifiedOptions (Ctor) {
  3661. var modified;
  3662. var latest = Ctor.options;
  3663. var extended = Ctor.extendOptions;
  3664. var sealed = Ctor.sealedOptions;
  3665. for (var key in latest) {
  3666. if (latest[key] !== sealed[key]) {
  3667. if (!modified) { modified = {}; }
  3668. modified[key] = dedupe(latest[key], extended[key], sealed[key]);
  3669. }
  3670. }
  3671. return modified
  3672. }
  3673. function dedupe (latest, extended, sealed) {
  3674. // compare latest and sealed to ensure lifecycle hooks won't be duplicated
  3675. // between merges
  3676. if (Array.isArray(latest)) {
  3677. var res = [];
  3678. sealed = Array.isArray(sealed) ? sealed : [sealed];
  3679. extended = Array.isArray(extended) ? extended : [extended];
  3680. for (var i = 0; i < latest.length; i++) {
  3681. // push original options and not sealed options to exclude duplicated options
  3682. if (extended.indexOf(latest[i]) >= 0 || sealed.indexOf(latest[i]) < 0) {
  3683. res.push(latest[i]);
  3684. }
  3685. }
  3686. return res
  3687. } else {
  3688. return latest
  3689. }
  3690. }
  3691. function Vue$2 (options) {
  3692. if (process.env.NODE_ENV !== 'production' &&
  3693. !(this instanceof Vue$2)) {
  3694. warn('Vue is a constructor and should be called with the `new` keyword');
  3695. }
  3696. this._init(options);
  3697. }
  3698. initMixin(Vue$2);
  3699. stateMixin(Vue$2);
  3700. eventsMixin(Vue$2);
  3701. lifecycleMixin(Vue$2);
  3702. renderMixin(Vue$2);
  3703. /* */
  3704. function initUse (Vue) {
  3705. Vue.use = function (plugin) {
  3706. /* istanbul ignore if */
  3707. if (plugin.installed) {
  3708. return
  3709. }
  3710. // additional parameters
  3711. var args = toArray(arguments, 1);
  3712. args.unshift(this);
  3713. if (typeof plugin.install === 'function') {
  3714. plugin.install.apply(plugin, args);
  3715. } else if (typeof plugin === 'function') {
  3716. plugin.apply(null, args);
  3717. }
  3718. plugin.installed = true;
  3719. return this
  3720. };
  3721. }
  3722. /* */
  3723. function initMixin$1 (Vue) {
  3724. Vue.mixin = function (mixin) {
  3725. this.options = mergeOptions(this.options, mixin);
  3726. };
  3727. }
  3728. /* */
  3729. function initExtend (Vue) {
  3730. /**
  3731. * Each instance constructor, including Vue, has a unique
  3732. * cid. This enables us to create wrapped "child
  3733. * constructors" for prototypal inheritance and cache them.
  3734. */
  3735. Vue.cid = 0;
  3736. var cid = 1;
  3737. /**
  3738. * Class inheritance
  3739. */
  3740. Vue.extend = function (extendOptions) {
  3741. extendOptions = extendOptions || {};
  3742. var Super = this;
  3743. var SuperId = Super.cid;
  3744. var cachedCtors = extendOptions._Ctor || (extendOptions._Ctor = {});
  3745. if (cachedCtors[SuperId]) {
  3746. return cachedCtors[SuperId]
  3747. }
  3748. var name = extendOptions.name || Super.options.name;
  3749. if (process.env.NODE_ENV !== 'production') {
  3750. if (!/^[a-zA-Z][\w-]*$/.test(name)) {
  3751. warn(
  3752. 'Invalid component name: "' + name + '". Component names ' +
  3753. 'can only contain alphanumeric characters and the hyphen, ' +
  3754. 'and must start with a letter.'
  3755. );
  3756. }
  3757. }
  3758. var Sub = function VueComponent (options) {
  3759. this._init(options);
  3760. };
  3761. Sub.prototype = Object.create(Super.prototype);
  3762. Sub.prototype.constructor = Sub;
  3763. Sub.cid = cid++;
  3764. Sub.options = mergeOptions(
  3765. Super.options,
  3766. extendOptions
  3767. );
  3768. Sub['super'] = Super;
  3769. // For props and computed properties, we define the proxy getters on
  3770. // the Vue instances at extension time, on the extended prototype. This
  3771. // avoids Object.defineProperty calls for each instance created.
  3772. if (Sub.options.props) {
  3773. initProps$1(Sub);
  3774. }
  3775. if (Sub.options.computed) {
  3776. initComputed$1(Sub);
  3777. }
  3778. // allow further extension/mixin/plugin usage
  3779. Sub.extend = Super.extend;
  3780. Sub.mixin = Super.mixin;
  3781. Sub.use = Super.use;
  3782. // create asset registers, so extended classes
  3783. // can have their private assets too.
  3784. ASSET_TYPES.forEach(function (type) {
  3785. Sub[type] = Super[type];
  3786. });
  3787. // enable recursive self-lookup
  3788. if (name) {
  3789. Sub.options.components[name] = Sub;
  3790. }
  3791. // keep a reference to the super options at extension time.
  3792. // later at instantiation we can check if Super's options have
  3793. // been updated.
  3794. Sub.superOptions = Super.options;
  3795. Sub.extendOptions = extendOptions;
  3796. Sub.sealedOptions = extend({}, Sub.options);
  3797. // cache constructor
  3798. cachedCtors[SuperId] = Sub;
  3799. return Sub
  3800. };
  3801. }
  3802. function initProps$1 (Comp) {
  3803. var props = Comp.options.props;
  3804. for (var key in props) {
  3805. proxy(Comp.prototype, "_props", key);
  3806. }
  3807. }
  3808. function initComputed$1 (Comp) {
  3809. var computed = Comp.options.computed;
  3810. for (var key in computed) {
  3811. defineComputed(Comp.prototype, key, computed[key]);
  3812. }
  3813. }
  3814. /* */
  3815. function initAssetRegisters (Vue) {
  3816. /**
  3817. * Create asset registration methods.
  3818. */
  3819. ASSET_TYPES.forEach(function (type) {
  3820. Vue[type] = function (
  3821. id,
  3822. definition
  3823. ) {
  3824. if (!definition) {
  3825. return this.options[type + 's'][id]
  3826. } else {
  3827. /* istanbul ignore if */
  3828. if (process.env.NODE_ENV !== 'production') {
  3829. if (type === 'component' && config.isReservedTag(id)) {
  3830. warn(
  3831. 'Do not use built-in or reserved HTML elements as component ' +
  3832. 'id: ' + id
  3833. );
  3834. }
  3835. }
  3836. if (type === 'component' && isPlainObject(definition)) {
  3837. definition.name = definition.name || id;
  3838. definition = this.options._base.extend(definition);
  3839. }
  3840. if (type === 'directive' && typeof definition === 'function') {
  3841. definition = { bind: definition, update: definition };
  3842. }
  3843. this.options[type + 's'][id] = definition;
  3844. return definition
  3845. }
  3846. };
  3847. });
  3848. }
  3849. /* */
  3850. var patternTypes = [String, RegExp];
  3851. function getComponentName (opts) {
  3852. return opts && (opts.Ctor.options.name || opts.tag)
  3853. }
  3854. function matches (pattern, name) {
  3855. if (typeof pattern === 'string') {
  3856. return pattern.split(',').indexOf(name) > -1
  3857. } else if (isRegExp(pattern)) {
  3858. return pattern.test(name)
  3859. }
  3860. /* istanbul ignore next */
  3861. return false
  3862. }
  3863. function pruneCache (cache, current, filter) {
  3864. for (var key in cache) {
  3865. var cachedNode = cache[key];
  3866. if (cachedNode) {
  3867. var name = getComponentName(cachedNode.componentOptions);
  3868. if (name && !filter(name)) {
  3869. if (cachedNode !== current) {
  3870. pruneCacheEntry(cachedNode);
  3871. }
  3872. cache[key] = null;
  3873. }
  3874. }
  3875. }
  3876. }
  3877. function pruneCacheEntry (vnode) {
  3878. if (vnode) {
  3879. vnode.componentInstance.$destroy();
  3880. }
  3881. }
  3882. var KeepAlive = {
  3883. name: 'keep-alive',
  3884. abstract: true,
  3885. props: {
  3886. include: patternTypes,
  3887. exclude: patternTypes
  3888. },
  3889. created: function created () {
  3890. this.cache = Object.create(null);
  3891. },
  3892. destroyed: function destroyed () {
  3893. var this$1 = this;
  3894. for (var key in this$1.cache) {
  3895. pruneCacheEntry(this$1.cache[key]);
  3896. }
  3897. },
  3898. watch: {
  3899. include: function include (val) {
  3900. pruneCache(this.cache, this._vnode, function (name) { return matches(val, name); });
  3901. },
  3902. exclude: function exclude (val) {
  3903. pruneCache(this.cache, this._vnode, function (name) { return !matches(val, name); });
  3904. }
  3905. },
  3906. render: function render () {
  3907. var vnode = getFirstComponentChild(this.$slots.default);
  3908. var componentOptions = vnode && vnode.componentOptions;
  3909. if (componentOptions) {
  3910. // check pattern
  3911. var name = getComponentName(componentOptions);
  3912. if (name && (
  3913. (this.include && !matches(this.include, name)) ||
  3914. (this.exclude && matches(this.exclude, name))
  3915. )) {
  3916. return vnode
  3917. }
  3918. var key = vnode.key == null
  3919. // same constructor may get registered as different local components
  3920. // so cid alone is not enough (#3269)
  3921. ? componentOptions.Ctor.cid + (componentOptions.tag ? ("::" + (componentOptions.tag)) : '')
  3922. : vnode.key;
  3923. if (this.cache[key]) {
  3924. vnode.componentInstance = this.cache[key].componentInstance;
  3925. } else {
  3926. this.cache[key] = vnode;
  3927. }
  3928. vnode.data.keepAlive = true;
  3929. }
  3930. return vnode
  3931. }
  3932. };
  3933. var builtInComponents = {
  3934. KeepAlive: KeepAlive
  3935. };
  3936. /* */
  3937. function initGlobalAPI (Vue) {
  3938. // config
  3939. var configDef = {};
  3940. configDef.get = function () { return config; };
  3941. if (process.env.NODE_ENV !== 'production') {
  3942. configDef.set = function () {
  3943. warn(
  3944. 'Do not replace the Vue.config object, set individual fields instead.'
  3945. );
  3946. };
  3947. }
  3948. Object.defineProperty(Vue, 'config', configDef);
  3949. // exposed util methods.
  3950. // NOTE: these are not considered part of the public API - avoid relying on
  3951. // them unless you are aware of the risk.
  3952. Vue.util = {
  3953. warn: warn,
  3954. extend: extend,
  3955. mergeOptions: mergeOptions,
  3956. defineReactive: defineReactive$$1
  3957. };
  3958. Vue.set = set;
  3959. Vue.delete = del;
  3960. Vue.nextTick = nextTick;
  3961. Vue.options = Object.create(null);
  3962. ASSET_TYPES.forEach(function (type) {
  3963. Vue.options[type + 's'] = Object.create(null);
  3964. });
  3965. // this is used to identify the "base" constructor to extend all plain-object
  3966. // components with in Weex's multi-instance scenarios.
  3967. Vue.options._base = Vue;
  3968. extend(Vue.options.components, builtInComponents);
  3969. initUse(Vue);
  3970. initMixin$1(Vue);
  3971. initExtend(Vue);
  3972. initAssetRegisters(Vue);
  3973. }
  3974. initGlobalAPI(Vue$2);
  3975. Object.defineProperty(Vue$2.prototype, '$isServer', {
  3976. get: isServerRendering
  3977. });
  3978. Vue$2.version = '2.3.0-beta.1';
  3979. /* globals renderer */
  3980. // renderer is injected by weex factory wrapper
  3981. var namespaceMap = {};
  3982. function createElement$1 (tagName) {
  3983. return new renderer.Element(tagName)
  3984. }
  3985. function createElementNS (namespace, tagName) {
  3986. return new renderer.Element(namespace + ':' + tagName)
  3987. }
  3988. function createTextNode (text) {
  3989. return new renderer.TextNode(text)
  3990. }
  3991. function createComment (text) {
  3992. return new renderer.Comment(text)
  3993. }
  3994. function insertBefore (node, target, before) {
  3995. if (target.nodeType === 3) {
  3996. if (node.type === 'text') {
  3997. node.setAttr('value', target.text);
  3998. target.parentNode = node;
  3999. } else {
  4000. var text = createElement$1('text');
  4001. text.setAttr('value', target.text);
  4002. node.insertBefore(text, before);
  4003. }
  4004. return
  4005. }
  4006. node.insertBefore(target, before);
  4007. }
  4008. function removeChild (node, child) {
  4009. if (child.nodeType === 3) {
  4010. node.setAttr('value', '');
  4011. return
  4012. }
  4013. node.removeChild(child);
  4014. }
  4015. function appendChild (node, child) {
  4016. if (child.nodeType === 3) {
  4017. if (node.type === 'text') {
  4018. node.setAttr('value', child.text);
  4019. child.parentNode = node;
  4020. } else {
  4021. var text = createElement$1('text');
  4022. text.setAttr('value', child.text);
  4023. node.appendChild(text);
  4024. }
  4025. return
  4026. }
  4027. node.appendChild(child);
  4028. }
  4029. function parentNode (node) {
  4030. return node.parentNode
  4031. }
  4032. function nextSibling (node) {
  4033. return node.nextSibling
  4034. }
  4035. function tagName (node) {
  4036. return node.type
  4037. }
  4038. function setTextContent (node, text) {
  4039. node.parentNode.setAttr('value', text);
  4040. }
  4041. function setAttribute (node, key, val) {
  4042. node.setAttr(key, val);
  4043. }
  4044. var nodeOps = Object.freeze({
  4045. namespaceMap: namespaceMap,
  4046. createElement: createElement$1,
  4047. createElementNS: createElementNS,
  4048. createTextNode: createTextNode,
  4049. createComment: createComment,
  4050. insertBefore: insertBefore,
  4051. removeChild: removeChild,
  4052. appendChild: appendChild,
  4053. parentNode: parentNode,
  4054. nextSibling: nextSibling,
  4055. tagName: tagName,
  4056. setTextContent: setTextContent,
  4057. setAttribute: setAttribute
  4058. });
  4059. /* */
  4060. var ref = {
  4061. create: function create (_, vnode) {
  4062. registerRef(vnode);
  4063. },
  4064. update: function update (oldVnode, vnode) {
  4065. if (oldVnode.data.ref !== vnode.data.ref) {
  4066. registerRef(oldVnode, true);
  4067. registerRef(vnode);
  4068. }
  4069. },
  4070. destroy: function destroy (vnode) {
  4071. registerRef(vnode, true);
  4072. }
  4073. };
  4074. function registerRef (vnode, isRemoval) {
  4075. var key = vnode.data.ref;
  4076. if (!key) { return }
  4077. var vm = vnode.context;
  4078. var ref = vnode.componentInstance || vnode.elm;
  4079. var refs = vm.$refs;
  4080. if (isRemoval) {
  4081. if (Array.isArray(refs[key])) {
  4082. remove(refs[key], ref);
  4083. } else if (refs[key] === ref) {
  4084. refs[key] = undefined;
  4085. }
  4086. } else {
  4087. if (vnode.data.refInFor) {
  4088. if (Array.isArray(refs[key]) && refs[key].indexOf(ref) < 0) {
  4089. refs[key].push(ref);
  4090. } else {
  4091. refs[key] = [ref];
  4092. }
  4093. } else {
  4094. refs[key] = ref;
  4095. }
  4096. }
  4097. }
  4098. /**
  4099. * Virtual DOM patching algorithm based on Snabbdom by
  4100. * Simon Friis Vindum (@paldepind)
  4101. * Licensed under the MIT License
  4102. * https://github.com/paldepind/snabbdom/blob/master/LICENSE
  4103. *
  4104. * modified by Evan You (@yyx990803)
  4105. *
  4106. /*
  4107. * Not type-checking this because this file is perf-critical and the cost
  4108. * of making flow understand it is not worth it.
  4109. */
  4110. var emptyNode = new VNode('', {}, []);
  4111. var hooks = ['create', 'activate', 'update', 'remove', 'destroy'];
  4112. function sameVnode (a, b) {
  4113. return (
  4114. a.key === b.key &&
  4115. a.tag === b.tag &&
  4116. a.isComment === b.isComment &&
  4117. isDef(a.data) === isDef(b.data) &&
  4118. sameInputType(a, b)
  4119. )
  4120. }
  4121. // Some browsers do not support dynamically changing type for <input>
  4122. // so they need to be treated as different nodes
  4123. function sameInputType (a, b) {
  4124. if (a.tag !== 'input') { return true }
  4125. var i;
  4126. var typeA = isDef(i = a.data) && isDef(i = i.attrs) && i.type;
  4127. var typeB = isDef(i = b.data) && isDef(i = i.attrs) && i.type;
  4128. return typeA === typeB
  4129. }
  4130. function createKeyToOldIdx (children, beginIdx, endIdx) {
  4131. var i, key;
  4132. var map = {};
  4133. for (i = beginIdx; i <= endIdx; ++i) {
  4134. key = children[i].key;
  4135. if (isDef(key)) { map[key] = i; }
  4136. }
  4137. return map
  4138. }
  4139. function createPatchFunction (backend) {
  4140. var i, j;
  4141. var cbs = {};
  4142. var modules = backend.modules;
  4143. var nodeOps = backend.nodeOps;
  4144. for (i = 0; i < hooks.length; ++i) {
  4145. cbs[hooks[i]] = [];
  4146. for (j = 0; j < modules.length; ++j) {
  4147. if (isDef(modules[j][hooks[i]])) {
  4148. cbs[hooks[i]].push(modules[j][hooks[i]]);
  4149. }
  4150. }
  4151. }
  4152. function emptyNodeAt (elm) {
  4153. return new VNode(nodeOps.tagName(elm).toLowerCase(), {}, [], undefined, elm)
  4154. }
  4155. function createRmCb (childElm, listeners) {
  4156. function remove$$1 () {
  4157. if (--remove$$1.listeners === 0) {
  4158. removeNode(childElm);
  4159. }
  4160. }
  4161. remove$$1.listeners = listeners;
  4162. return remove$$1
  4163. }
  4164. function removeNode (el) {
  4165. var parent = nodeOps.parentNode(el);
  4166. // element may have already been removed due to v-html / v-text
  4167. if (isDef(parent)) {
  4168. nodeOps.removeChild(parent, el);
  4169. }
  4170. }
  4171. var inPre = 0;
  4172. function createElm (vnode, insertedVnodeQueue, parentElm, refElm, nested) {
  4173. vnode.isRootInsert = !nested; // for transition enter check
  4174. if (createComponent(vnode, insertedVnodeQueue, parentElm, refElm)) {
  4175. return
  4176. }
  4177. var data = vnode.data;
  4178. var children = vnode.children;
  4179. var tag = vnode.tag;
  4180. if (isDef(tag)) {
  4181. if (process.env.NODE_ENV !== 'production') {
  4182. if (data && data.pre) {
  4183. inPre++;
  4184. }
  4185. if (
  4186. !inPre &&
  4187. !vnode.ns &&
  4188. !(config.ignoredElements.length && config.ignoredElements.indexOf(tag) > -1) &&
  4189. config.isUnknownElement(tag)
  4190. ) {
  4191. warn(
  4192. 'Unknown custom element: <' + tag + '> - did you ' +
  4193. 'register the component correctly? For recursive components, ' +
  4194. 'make sure to provide the "name" option.',
  4195. vnode.context
  4196. );
  4197. }
  4198. }
  4199. vnode.elm = vnode.ns
  4200. ? nodeOps.createElementNS(vnode.ns, tag)
  4201. : nodeOps.createElement(tag, vnode);
  4202. setScope(vnode);
  4203. /* istanbul ignore if */
  4204. {
  4205. // in Weex, the default insertion order is parent-first.
  4206. // List items can be optimized to use children-first insertion
  4207. // with append="tree".
  4208. var appendAsTree = isDef(data) && isTrue(data.appendAsTree);
  4209. if (!appendAsTree) {
  4210. if (isDef(data)) {
  4211. invokeCreateHooks(vnode, insertedVnodeQueue);
  4212. }
  4213. insert(parentElm, vnode.elm, refElm);
  4214. }
  4215. createChildren(vnode, children, insertedVnodeQueue);
  4216. if (appendAsTree) {
  4217. if (isDef(data)) {
  4218. invokeCreateHooks(vnode, insertedVnodeQueue);
  4219. }
  4220. insert(parentElm, vnode.elm, refElm);
  4221. }
  4222. }
  4223. if (process.env.NODE_ENV !== 'production' && data && data.pre) {
  4224. inPre--;
  4225. }
  4226. } else if (isTrue(vnode.isComment)) {
  4227. vnode.elm = nodeOps.createComment(vnode.text);
  4228. insert(parentElm, vnode.elm, refElm);
  4229. } else {
  4230. vnode.elm = nodeOps.createTextNode(vnode.text);
  4231. insert(parentElm, vnode.elm, refElm);
  4232. }
  4233. }
  4234. function createComponent (vnode, insertedVnodeQueue, parentElm, refElm) {
  4235. var i = vnode.data;
  4236. if (isDef(i)) {
  4237. var isReactivated = isDef(vnode.componentInstance) && i.keepAlive;
  4238. if (isDef(i = i.hook) && isDef(i = i.init)) {
  4239. i(vnode, false /* hydrating */, parentElm, refElm);
  4240. }
  4241. // after calling the init hook, if the vnode is a child component
  4242. // it should've created a child instance and mounted it. the child
  4243. // component also has set the placeholder vnode's elm.
  4244. // in that case we can just return the element and be done.
  4245. if (isDef(vnode.componentInstance)) {
  4246. initComponent(vnode, insertedVnodeQueue);
  4247. if (isTrue(isReactivated)) {
  4248. reactivateComponent(vnode, insertedVnodeQueue, parentElm, refElm);
  4249. }
  4250. return true
  4251. }
  4252. }
  4253. }
  4254. function initComponent (vnode, insertedVnodeQueue) {
  4255. if (isDef(vnode.data.pendingInsert)) {
  4256. insertedVnodeQueue.push.apply(insertedVnodeQueue, vnode.data.pendingInsert);
  4257. }
  4258. vnode.elm = vnode.componentInstance.$el;
  4259. if (isPatchable(vnode)) {
  4260. invokeCreateHooks(vnode, insertedVnodeQueue);
  4261. setScope(vnode);
  4262. } else {
  4263. // empty component root.
  4264. // skip all element-related modules except for ref (#3455)
  4265. registerRef(vnode);
  4266. // make sure to invoke the insert hook
  4267. insertedVnodeQueue.push(vnode);
  4268. }
  4269. }
  4270. function reactivateComponent (vnode, insertedVnodeQueue, parentElm, refElm) {
  4271. var i;
  4272. // hack for #4339: a reactivated component with inner transition
  4273. // does not trigger because the inner node's created hooks are not called
  4274. // again. It's not ideal to involve module-specific logic in here but
  4275. // there doesn't seem to be a better way to do it.
  4276. var innerNode = vnode;
  4277. while (innerNode.componentInstance) {
  4278. innerNode = innerNode.componentInstance._vnode;
  4279. if (isDef(i = innerNode.data) && isDef(i = i.transition)) {
  4280. for (i = 0; i < cbs.activate.length; ++i) {
  4281. cbs.activate[i](emptyNode, innerNode);
  4282. }
  4283. insertedVnodeQueue.push(innerNode);
  4284. break
  4285. }
  4286. }
  4287. // unlike a newly created component,
  4288. // a reactivated keep-alive component doesn't insert itself
  4289. insert(parentElm, vnode.elm, refElm);
  4290. }
  4291. function insert (parent, elm, ref) {
  4292. if (isDef(parent)) {
  4293. if (isDef(ref)) {
  4294. if (ref.parentNode === parent) {
  4295. nodeOps.insertBefore(parent, elm, ref);
  4296. }
  4297. } else {
  4298. nodeOps.appendChild(parent, elm);
  4299. }
  4300. }
  4301. }
  4302. function createChildren (vnode, children, insertedVnodeQueue) {
  4303. if (Array.isArray(children)) {
  4304. for (var i = 0; i < children.length; ++i) {
  4305. createElm(children[i], insertedVnodeQueue, vnode.elm, null, true);
  4306. }
  4307. } else if (isPrimitive(vnode.text)) {
  4308. nodeOps.appendChild(vnode.elm, nodeOps.createTextNode(vnode.text));
  4309. }
  4310. }
  4311. function isPatchable (vnode) {
  4312. while (vnode.componentInstance) {
  4313. vnode = vnode.componentInstance._vnode;
  4314. }
  4315. return isDef(vnode.tag)
  4316. }
  4317. function invokeCreateHooks (vnode, insertedVnodeQueue) {
  4318. for (var i$1 = 0; i$1 < cbs.create.length; ++i$1) {
  4319. cbs.create[i$1](emptyNode, vnode);
  4320. }
  4321. i = vnode.data.hook; // Reuse variable
  4322. if (isDef(i)) {
  4323. if (isDef(i.create)) { i.create(emptyNode, vnode); }
  4324. if (isDef(i.insert)) { insertedVnodeQueue.push(vnode); }
  4325. }
  4326. }
  4327. // set scope id attribute for scoped CSS.
  4328. // this is implemented as a special case to avoid the overhead
  4329. // of going through the normal attribute patching process.
  4330. function setScope (vnode) {
  4331. var i;
  4332. var ancestor = vnode;
  4333. while (ancestor) {
  4334. if (isDef(i = ancestor.context) && isDef(i = i.$options._scopeId)) {
  4335. nodeOps.setAttribute(vnode.elm, i, '');
  4336. }
  4337. ancestor = ancestor.parent;
  4338. }
  4339. // for slot content they should also get the scopeId from the host instance.
  4340. if (isDef(i = activeInstance) &&
  4341. i !== vnode.context &&
  4342. isDef(i = i.$options._scopeId)) {
  4343. nodeOps.setAttribute(vnode.elm, i, '');
  4344. }
  4345. }
  4346. function addVnodes (parentElm, refElm, vnodes, startIdx, endIdx, insertedVnodeQueue) {
  4347. for (; startIdx <= endIdx; ++startIdx) {
  4348. createElm(vnodes[startIdx], insertedVnodeQueue, parentElm, refElm);
  4349. }
  4350. }
  4351. function invokeDestroyHook (vnode) {
  4352. var i, j;
  4353. var data = vnode.data;
  4354. if (isDef(data)) {
  4355. if (isDef(i = data.hook) && isDef(i = i.destroy)) { i(vnode); }
  4356. for (i = 0; i < cbs.destroy.length; ++i) { cbs.destroy[i](vnode); }
  4357. }
  4358. if (isDef(i = vnode.children)) {
  4359. for (j = 0; j < vnode.children.length; ++j) {
  4360. invokeDestroyHook(vnode.children[j]);
  4361. }
  4362. }
  4363. }
  4364. function removeVnodes (parentElm, vnodes, startIdx, endIdx) {
  4365. for (; startIdx <= endIdx; ++startIdx) {
  4366. var ch = vnodes[startIdx];
  4367. if (isDef(ch)) {
  4368. if (isDef(ch.tag)) {
  4369. removeAndInvokeRemoveHook(ch);
  4370. invokeDestroyHook(ch);
  4371. } else { // Text node
  4372. removeNode(ch.elm);
  4373. }
  4374. }
  4375. }
  4376. }
  4377. function removeAndInvokeRemoveHook (vnode, rm) {
  4378. if (isDef(rm) || isDef(vnode.data)) {
  4379. var i;
  4380. var listeners = cbs.remove.length + 1;
  4381. if (isDef(rm)) {
  4382. // we have a recursively passed down rm callback
  4383. // increase the listeners count
  4384. rm.listeners += listeners;
  4385. } else {
  4386. // directly removing
  4387. rm = createRmCb(vnode.elm, listeners);
  4388. }
  4389. // recursively invoke hooks on child component root node
  4390. if (isDef(i = vnode.componentInstance) && isDef(i = i._vnode) && isDef(i.data)) {
  4391. removeAndInvokeRemoveHook(i, rm);
  4392. }
  4393. for (i = 0; i < cbs.remove.length; ++i) {
  4394. cbs.remove[i](vnode, rm);
  4395. }
  4396. if (isDef(i = vnode.data.hook) && isDef(i = i.remove)) {
  4397. i(vnode, rm);
  4398. } else {
  4399. rm();
  4400. }
  4401. } else {
  4402. removeNode(vnode.elm);
  4403. }
  4404. }
  4405. function updateChildren (parentElm, oldCh, newCh, insertedVnodeQueue, removeOnly) {
  4406. var oldStartIdx = 0;
  4407. var newStartIdx = 0;
  4408. var oldEndIdx = oldCh.length - 1;
  4409. var oldStartVnode = oldCh[0];
  4410. var oldEndVnode = oldCh[oldEndIdx];
  4411. var newEndIdx = newCh.length - 1;
  4412. var newStartVnode = newCh[0];
  4413. var newEndVnode = newCh[newEndIdx];
  4414. var oldKeyToIdx, idxInOld, elmToMove, refElm;
  4415. // removeOnly is a special flag used only by <transition-group>
  4416. // to ensure removed elements stay in correct relative positions
  4417. // during leaving transitions
  4418. var canMove = !removeOnly;
  4419. while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
  4420. if (isUndef(oldStartVnode)) {
  4421. oldStartVnode = oldCh[++oldStartIdx]; // Vnode has been moved left
  4422. } else if (isUndef(oldEndVnode)) {
  4423. oldEndVnode = oldCh[--oldEndIdx];
  4424. } else if (sameVnode(oldStartVnode, newStartVnode)) {
  4425. patchVnode(oldStartVnode, newStartVnode, insertedVnodeQueue);
  4426. oldStartVnode = oldCh[++oldStartIdx];
  4427. newStartVnode = newCh[++newStartIdx];
  4428. } else if (sameVnode(oldEndVnode, newEndVnode)) {
  4429. patchVnode(oldEndVnode, newEndVnode, insertedVnodeQueue);
  4430. oldEndVnode = oldCh[--oldEndIdx];
  4431. newEndVnode = newCh[--newEndIdx];
  4432. } else if (sameVnode(oldStartVnode, newEndVnode)) { // Vnode moved right
  4433. patchVnode(oldStartVnode, newEndVnode, insertedVnodeQueue);
  4434. canMove && nodeOps.insertBefore(parentElm, oldStartVnode.elm, nodeOps.nextSibling(oldEndVnode.elm));
  4435. oldStartVnode = oldCh[++oldStartIdx];
  4436. newEndVnode = newCh[--newEndIdx];
  4437. } else if (sameVnode(oldEndVnode, newStartVnode)) { // Vnode moved left
  4438. patchVnode(oldEndVnode, newStartVnode, insertedVnodeQueue);
  4439. canMove && nodeOps.insertBefore(parentElm, oldEndVnode.elm, oldStartVnode.elm);
  4440. oldEndVnode = oldCh[--oldEndIdx];
  4441. newStartVnode = newCh[++newStartIdx];
  4442. } else {
  4443. if (isUndef(oldKeyToIdx)) { oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx); }
  4444. idxInOld = isDef(newStartVnode.key) ? oldKeyToIdx[newStartVnode.key] : null;
  4445. if (isUndef(idxInOld)) { // New element
  4446. createElm(newStartVnode, insertedVnodeQueue, parentElm, oldStartVnode.elm);
  4447. newStartVnode = newCh[++newStartIdx];
  4448. } else {
  4449. elmToMove = oldCh[idxInOld];
  4450. /* istanbul ignore if */
  4451. if (process.env.NODE_ENV !== 'production' && !elmToMove) {
  4452. warn(
  4453. 'It seems there are duplicate keys that is causing an update error. ' +
  4454. 'Make sure each v-for item has a unique key.'
  4455. );
  4456. }
  4457. if (sameVnode(elmToMove, newStartVnode)) {
  4458. patchVnode(elmToMove, newStartVnode, insertedVnodeQueue);
  4459. oldCh[idxInOld] = undefined;
  4460. canMove && nodeOps.insertBefore(parentElm, newStartVnode.elm, oldStartVnode.elm);
  4461. newStartVnode = newCh[++newStartIdx];
  4462. } else {
  4463. // same key but different element. treat as new element
  4464. createElm(newStartVnode, insertedVnodeQueue, parentElm, oldStartVnode.elm);
  4465. newStartVnode = newCh[++newStartIdx];
  4466. }
  4467. }
  4468. }
  4469. }
  4470. if (oldStartIdx > oldEndIdx) {
  4471. refElm = isUndef(newCh[newEndIdx + 1]) ? null : newCh[newEndIdx + 1].elm;
  4472. addVnodes(parentElm, refElm, newCh, newStartIdx, newEndIdx, insertedVnodeQueue);
  4473. } else if (newStartIdx > newEndIdx) {
  4474. removeVnodes(parentElm, oldCh, oldStartIdx, oldEndIdx);
  4475. }
  4476. }
  4477. function patchVnode (oldVnode, vnode, insertedVnodeQueue, removeOnly) {
  4478. if (oldVnode === vnode) {
  4479. return
  4480. }
  4481. // reuse element for static trees.
  4482. // note we only do this if the vnode is cloned -
  4483. // if the new node is not cloned it means the render functions have been
  4484. // reset by the hot-reload-api and we need to do a proper re-render.
  4485. if (isTrue(vnode.isStatic) &&
  4486. isTrue(oldVnode.isStatic) &&
  4487. vnode.key === oldVnode.key &&
  4488. (isTrue(vnode.isCloned) || isTrue(vnode.isOnce))) {
  4489. vnode.elm = oldVnode.elm;
  4490. vnode.componentInstance = oldVnode.componentInstance;
  4491. return
  4492. }
  4493. var i;
  4494. var data = vnode.data;
  4495. if (isDef(data) && isDef(i = data.hook) && isDef(i = i.prepatch)) {
  4496. i(oldVnode, vnode);
  4497. }
  4498. var elm = vnode.elm = oldVnode.elm;
  4499. var oldCh = oldVnode.children;
  4500. var ch = vnode.children;
  4501. if (isDef(data) && isPatchable(vnode)) {
  4502. for (i = 0; i < cbs.update.length; ++i) { cbs.update[i](oldVnode, vnode); }
  4503. if (isDef(i = data.hook) && isDef(i = i.update)) { i(oldVnode, vnode); }
  4504. }
  4505. if (isUndef(vnode.text)) {
  4506. if (isDef(oldCh) && isDef(ch)) {
  4507. if (oldCh !== ch) { updateChildren(elm, oldCh, ch, insertedVnodeQueue, removeOnly); }
  4508. } else if (isDef(ch)) {
  4509. if (isDef(oldVnode.text)) { nodeOps.setTextContent(elm, ''); }
  4510. addVnodes(elm, null, ch, 0, ch.length - 1, insertedVnodeQueue);
  4511. } else if (isDef(oldCh)) {
  4512. removeVnodes(elm, oldCh, 0, oldCh.length - 1);
  4513. } else if (isDef(oldVnode.text)) {
  4514. nodeOps.setTextContent(elm, '');
  4515. }
  4516. } else if (oldVnode.text !== vnode.text) {
  4517. nodeOps.setTextContent(elm, vnode.text);
  4518. }
  4519. if (isDef(data)) {
  4520. if (isDef(i = data.hook) && isDef(i = i.postpatch)) { i(oldVnode, vnode); }
  4521. }
  4522. }
  4523. function invokeInsertHook (vnode, queue, initial) {
  4524. // delay insert hooks for component root nodes, invoke them after the
  4525. // element is really inserted
  4526. if (isTrue(initial) && isDef(vnode.parent)) {
  4527. vnode.parent.data.pendingInsert = queue;
  4528. } else {
  4529. for (var i = 0; i < queue.length; ++i) {
  4530. queue[i].data.hook.insert(queue[i]);
  4531. }
  4532. }
  4533. }
  4534. var bailed = false;
  4535. // list of modules that can skip create hook during hydration because they
  4536. // are already rendered on the client or has no need for initialization
  4537. var isRenderedModule = makeMap('attrs,style,class,staticClass,staticStyle,key');
  4538. // Note: this is a browser-only function so we can assume elms are DOM nodes.
  4539. function hydrate (elm, vnode, insertedVnodeQueue) {
  4540. if (process.env.NODE_ENV !== 'production') {
  4541. if (!assertNodeMatch(elm, vnode)) {
  4542. return false
  4543. }
  4544. }
  4545. vnode.elm = elm;
  4546. var tag = vnode.tag;
  4547. var data = vnode.data;
  4548. var children = vnode.children;
  4549. if (isDef(data)) {
  4550. if (isDef(i = data.hook) && isDef(i = i.init)) { i(vnode, true /* hydrating */); }
  4551. if (isDef(i = vnode.componentInstance)) {
  4552. // child component. it should have hydrated its own tree.
  4553. initComponent(vnode, insertedVnodeQueue);
  4554. return true
  4555. }
  4556. }
  4557. if (isDef(tag)) {
  4558. if (isDef(children)) {
  4559. // empty element, allow client to pick up and populate children
  4560. if (!elm.hasChildNodes()) {
  4561. createChildren(vnode, children, insertedVnodeQueue);
  4562. } else {
  4563. var childrenMatch = true;
  4564. var childNode = elm.firstChild;
  4565. for (var i$1 = 0; i$1 < children.length; i$1++) {
  4566. if (!childNode || !hydrate(childNode, children[i$1], insertedVnodeQueue)) {
  4567. childrenMatch = false;
  4568. break
  4569. }
  4570. childNode = childNode.nextSibling;
  4571. }
  4572. // if childNode is not null, it means the actual childNodes list is
  4573. // longer than the virtual children list.
  4574. if (!childrenMatch || childNode) {
  4575. if (process.env.NODE_ENV !== 'production' &&
  4576. typeof console !== 'undefined' &&
  4577. !bailed) {
  4578. bailed = true;
  4579. console.warn('Parent: ', elm);
  4580. console.warn('Mismatching childNodes vs. VNodes: ', elm.childNodes, children);
  4581. }
  4582. return false
  4583. }
  4584. }
  4585. }
  4586. if (isDef(data)) {
  4587. for (var key in data) {
  4588. if (!isRenderedModule(key)) {
  4589. invokeCreateHooks(vnode, insertedVnodeQueue);
  4590. break
  4591. }
  4592. }
  4593. }
  4594. } else if (elm.data !== vnode.text) {
  4595. elm.data = vnode.text;
  4596. }
  4597. return true
  4598. }
  4599. function assertNodeMatch (node, vnode) {
  4600. if (isDef(vnode.tag)) {
  4601. return (
  4602. vnode.tag.indexOf('vue-component') === 0 ||
  4603. vnode.tag.toLowerCase() === (node.tagName && node.tagName.toLowerCase())
  4604. )
  4605. } else {
  4606. return node.nodeType === (vnode.isComment ? 8 : 3)
  4607. }
  4608. }
  4609. return function patch (oldVnode, vnode, hydrating, removeOnly, parentElm, refElm) {
  4610. if (isUndef(vnode)) {
  4611. if (isDef(oldVnode)) { invokeDestroyHook(oldVnode); }
  4612. return
  4613. }
  4614. var isInitialPatch = false;
  4615. var insertedVnodeQueue = [];
  4616. if (isUndef(oldVnode)) {
  4617. // empty mount (likely as component), create new root element
  4618. isInitialPatch = true;
  4619. createElm(vnode, insertedVnodeQueue, parentElm, refElm);
  4620. } else {
  4621. var isRealElement = isDef(oldVnode.nodeType);
  4622. if (!isRealElement && sameVnode(oldVnode, vnode)) {
  4623. // patch existing root node
  4624. patchVnode(oldVnode, vnode, insertedVnodeQueue, removeOnly);
  4625. } else {
  4626. if (isRealElement) {
  4627. // mounting to a real element
  4628. // check if this is server-rendered content and if we can perform
  4629. // a successful hydration.
  4630. if (oldVnode.nodeType === 1 && oldVnode.hasAttribute(SSR_ATTR)) {
  4631. oldVnode.removeAttribute(SSR_ATTR);
  4632. hydrating = true;
  4633. }
  4634. if (isTrue(hydrating)) {
  4635. if (hydrate(oldVnode, vnode, insertedVnodeQueue)) {
  4636. invokeInsertHook(vnode, insertedVnodeQueue, true);
  4637. return oldVnode
  4638. } else if (process.env.NODE_ENV !== 'production') {
  4639. warn(
  4640. 'The client-side rendered virtual DOM tree is not matching ' +
  4641. 'server-rendered content. This is likely caused by incorrect ' +
  4642. 'HTML markup, for example nesting block-level elements inside ' +
  4643. '<p>, or missing <tbody>. Bailing hydration and performing ' +
  4644. 'full client-side render.'
  4645. );
  4646. }
  4647. }
  4648. // either not server-rendered, or hydration failed.
  4649. // create an empty node and replace it
  4650. oldVnode = emptyNodeAt(oldVnode);
  4651. }
  4652. // replacing existing element
  4653. var oldElm = oldVnode.elm;
  4654. var parentElm$1 = nodeOps.parentNode(oldElm);
  4655. createElm(
  4656. vnode,
  4657. insertedVnodeQueue,
  4658. // extremely rare edge case: do not insert if old element is in a
  4659. // leaving transition. Only happens when combining transition +
  4660. // keep-alive + HOCs. (#4590)
  4661. oldElm._leaveCb ? null : parentElm$1,
  4662. nodeOps.nextSibling(oldElm)
  4663. );
  4664. if (isDef(vnode.parent)) {
  4665. // component root element replaced.
  4666. // update parent placeholder node element, recursively
  4667. var ancestor = vnode.parent;
  4668. while (ancestor) {
  4669. ancestor.elm = vnode.elm;
  4670. ancestor = ancestor.parent;
  4671. }
  4672. if (isPatchable(vnode)) {
  4673. for (var i = 0; i < cbs.create.length; ++i) {
  4674. cbs.create[i](emptyNode, vnode.parent);
  4675. }
  4676. }
  4677. }
  4678. if (isDef(parentElm$1)) {
  4679. removeVnodes(parentElm$1, [oldVnode], 0, 0);
  4680. } else if (isDef(oldVnode.tag)) {
  4681. invokeDestroyHook(oldVnode);
  4682. }
  4683. }
  4684. }
  4685. invokeInsertHook(vnode, insertedVnodeQueue, isInitialPatch);
  4686. return vnode.elm
  4687. }
  4688. }
  4689. /* */
  4690. var directives = {
  4691. create: updateDirectives,
  4692. update: updateDirectives,
  4693. destroy: function unbindDirectives (vnode) {
  4694. updateDirectives(vnode, emptyNode);
  4695. }
  4696. };
  4697. function updateDirectives (oldVnode, vnode) {
  4698. if (oldVnode.data.directives || vnode.data.directives) {
  4699. _update(oldVnode, vnode);
  4700. }
  4701. }
  4702. function _update (oldVnode, vnode) {
  4703. var isCreate = oldVnode === emptyNode;
  4704. var isDestroy = vnode === emptyNode;
  4705. var oldDirs = normalizeDirectives$1(oldVnode.data.directives, oldVnode.context);
  4706. var newDirs = normalizeDirectives$1(vnode.data.directives, vnode.context);
  4707. var dirsWithInsert = [];
  4708. var dirsWithPostpatch = [];
  4709. var key, oldDir, dir;
  4710. for (key in newDirs) {
  4711. oldDir = oldDirs[key];
  4712. dir = newDirs[key];
  4713. if (!oldDir) {
  4714. // new directive, bind
  4715. callHook$1(dir, 'bind', vnode, oldVnode);
  4716. if (dir.def && dir.def.inserted) {
  4717. dirsWithInsert.push(dir);
  4718. }
  4719. } else {
  4720. // existing directive, update
  4721. dir.oldValue = oldDir.value;
  4722. callHook$1(dir, 'update', vnode, oldVnode);
  4723. if (dir.def && dir.def.componentUpdated) {
  4724. dirsWithPostpatch.push(dir);
  4725. }
  4726. }
  4727. }
  4728. if (dirsWithInsert.length) {
  4729. var callInsert = function () {
  4730. for (var i = 0; i < dirsWithInsert.length; i++) {
  4731. callHook$1(dirsWithInsert[i], 'inserted', vnode, oldVnode);
  4732. }
  4733. };
  4734. if (isCreate) {
  4735. mergeVNodeHook(vnode.data.hook || (vnode.data.hook = {}), 'insert', callInsert);
  4736. } else {
  4737. callInsert();
  4738. }
  4739. }
  4740. if (dirsWithPostpatch.length) {
  4741. mergeVNodeHook(vnode.data.hook || (vnode.data.hook = {}), 'postpatch', function () {
  4742. for (var i = 0; i < dirsWithPostpatch.length; i++) {
  4743. callHook$1(dirsWithPostpatch[i], 'componentUpdated', vnode, oldVnode);
  4744. }
  4745. });
  4746. }
  4747. if (!isCreate) {
  4748. for (key in oldDirs) {
  4749. if (!newDirs[key]) {
  4750. // no longer present, unbind
  4751. callHook$1(oldDirs[key], 'unbind', oldVnode, oldVnode, isDestroy);
  4752. }
  4753. }
  4754. }
  4755. }
  4756. var emptyModifiers = Object.create(null);
  4757. function normalizeDirectives$1 (
  4758. dirs,
  4759. vm
  4760. ) {
  4761. var res = Object.create(null);
  4762. if (!dirs) {
  4763. return res
  4764. }
  4765. var i, dir;
  4766. for (i = 0; i < dirs.length; i++) {
  4767. dir = dirs[i];
  4768. if (!dir.modifiers) {
  4769. dir.modifiers = emptyModifiers;
  4770. }
  4771. res[getRawDirName(dir)] = dir;
  4772. dir.def = resolveAsset(vm.$options, 'directives', dir.name, true);
  4773. }
  4774. return res
  4775. }
  4776. function getRawDirName (dir) {
  4777. return dir.rawName || ((dir.name) + "." + (Object.keys(dir.modifiers || {}).join('.')))
  4778. }
  4779. function callHook$1 (dir, hook, vnode, oldVnode, isDestroy) {
  4780. var fn = dir.def && dir.def[hook];
  4781. if (fn) {
  4782. try {
  4783. fn(vnode.elm, dir, vnode, oldVnode, isDestroy);
  4784. } catch (e) {
  4785. handleError(e, vnode.context, ("directive " + (dir.name) + " " + hook + " hook"));
  4786. }
  4787. }
  4788. }
  4789. var baseModules = [
  4790. ref,
  4791. directives
  4792. ];
  4793. /* */
  4794. function updateAttrs (oldVnode, vnode) {
  4795. if (!oldVnode.data.attrs && !vnode.data.attrs) {
  4796. return
  4797. }
  4798. var key, cur, old;
  4799. var elm = vnode.elm;
  4800. var oldAttrs = oldVnode.data.attrs || {};
  4801. var attrs = vnode.data.attrs || {};
  4802. // clone observed objects, as the user probably wants to mutate it
  4803. if (attrs.__ob__) {
  4804. attrs = vnode.data.attrs = extend({}, attrs);
  4805. }
  4806. for (key in attrs) {
  4807. cur = attrs[key];
  4808. old = oldAttrs[key];
  4809. if (old !== cur) {
  4810. elm.setAttr(key, cur);
  4811. }
  4812. }
  4813. for (key in oldAttrs) {
  4814. if (attrs[key] == null) {
  4815. elm.setAttr(key);
  4816. }
  4817. }
  4818. }
  4819. var attrs = {
  4820. create: updateAttrs,
  4821. update: updateAttrs
  4822. };
  4823. /* */
  4824. function updateClass (oldVnode, vnode) {
  4825. var el = vnode.elm;
  4826. var ctx = vnode.context;
  4827. var data = vnode.data;
  4828. var oldData = oldVnode.data;
  4829. if (!data.staticClass && !data.class &&
  4830. (!oldData || (!oldData.staticClass && !oldData.class))) {
  4831. return
  4832. }
  4833. var oldClassList = [];
  4834. // unlike web, weex vnode staticClass is an Array
  4835. var oldStaticClass = oldData.staticClass;
  4836. if (oldStaticClass) {
  4837. oldClassList.push.apply(oldClassList, oldStaticClass);
  4838. }
  4839. if (oldData.class) {
  4840. oldClassList.push.apply(oldClassList, oldData.class);
  4841. }
  4842. var classList = [];
  4843. // unlike web, weex vnode staticClass is an Array
  4844. var staticClass = data.staticClass;
  4845. if (staticClass) {
  4846. classList.push.apply(classList, staticClass);
  4847. }
  4848. if (data.class) {
  4849. classList.push.apply(classList, data.class);
  4850. }
  4851. var style = getStyle(oldClassList, classList, ctx);
  4852. for (var key in style) {
  4853. el.setStyle(key, style[key]);
  4854. }
  4855. }
  4856. function getStyle (oldClassList, classList, ctx) {
  4857. // style is a weex-only injected object
  4858. // compiled from <style> tags in weex files
  4859. var stylesheet = ctx.$options.style || {};
  4860. var result = {};
  4861. classList.forEach(function (name) {
  4862. var style = stylesheet[name];
  4863. extend(result, style);
  4864. });
  4865. oldClassList.forEach(function (name) {
  4866. var style = stylesheet[name];
  4867. for (var key in style) {
  4868. if (!result.hasOwnProperty(key)) {
  4869. result[key] = '';
  4870. }
  4871. }
  4872. });
  4873. return result
  4874. }
  4875. var klass = {
  4876. create: updateClass,
  4877. update: updateClass
  4878. };
  4879. /* */
  4880. var target$1;
  4881. function add$1 (
  4882. event,
  4883. handler,
  4884. once,
  4885. capture
  4886. ) {
  4887. if (capture) {
  4888. console.log('Weex do not support event in bubble phase.');
  4889. return
  4890. }
  4891. if (once) {
  4892. var oldHandler = handler;
  4893. var _target = target$1; // save current target element in closure
  4894. handler = function (ev) {
  4895. var res = arguments.length === 1
  4896. ? oldHandler(ev)
  4897. : oldHandler.apply(null, arguments);
  4898. if (res !== null) {
  4899. remove$2(event, null, null, _target);
  4900. }
  4901. };
  4902. }
  4903. target$1.addEvent(event, handler);
  4904. }
  4905. function remove$2 (
  4906. event,
  4907. handler,
  4908. capture,
  4909. _target
  4910. ) {
  4911. (_target || target$1).removeEvent(event);
  4912. }
  4913. function updateDOMListeners (oldVnode, vnode) {
  4914. if (!oldVnode.data.on && !vnode.data.on) {
  4915. return
  4916. }
  4917. var on = vnode.data.on || {};
  4918. var oldOn = oldVnode.data.on || {};
  4919. target$1 = vnode.elm;
  4920. updateListeners(on, oldOn, add$1, remove$2, vnode.context);
  4921. }
  4922. var events = {
  4923. create: updateDOMListeners,
  4924. update: updateDOMListeners
  4925. };
  4926. /* */
  4927. var normalize = cached(camelize);
  4928. function createStyle (oldVnode, vnode) {
  4929. if (!vnode.data.staticStyle) {
  4930. updateStyle(oldVnode, vnode);
  4931. return
  4932. }
  4933. var elm = vnode.elm;
  4934. var staticStyle = vnode.data.staticStyle;
  4935. for (var name in staticStyle) {
  4936. if (staticStyle[name]) {
  4937. elm.setStyle(normalize(name), staticStyle[name]);
  4938. }
  4939. }
  4940. updateStyle(oldVnode, vnode);
  4941. }
  4942. function updateStyle (oldVnode, vnode) {
  4943. if (!oldVnode.data.style && !vnode.data.style) {
  4944. return
  4945. }
  4946. var cur, name;
  4947. var elm = vnode.elm;
  4948. var oldStyle = oldVnode.data.style || {};
  4949. var style = vnode.data.style || {};
  4950. var needClone = style.__ob__;
  4951. // handle array syntax
  4952. if (Array.isArray(style)) {
  4953. style = vnode.data.style = toObject$1(style);
  4954. }
  4955. // clone the style for future updates,
  4956. // in case the user mutates the style object in-place.
  4957. if (needClone) {
  4958. style = vnode.data.style = extend({}, style);
  4959. }
  4960. for (name in oldStyle) {
  4961. if (!style[name]) {
  4962. elm.setStyle(normalize(name), '');
  4963. }
  4964. }
  4965. for (name in style) {
  4966. cur = style[name];
  4967. elm.setStyle(normalize(name), cur);
  4968. }
  4969. }
  4970. function toObject$1 (arr) {
  4971. var res = {};
  4972. for (var i = 0; i < arr.length; i++) {
  4973. if (arr[i]) {
  4974. extend(res, arr[i]);
  4975. }
  4976. }
  4977. return res
  4978. }
  4979. var style = {
  4980. create: createStyle,
  4981. update: updateStyle
  4982. };
  4983. /* */
  4984. /**
  4985. * Add class with compatibility for SVG since classList is not supported on
  4986. * SVG elements in IE
  4987. */
  4988. /**
  4989. * Remove class with compatibility for SVG since classList is not supported on
  4990. * SVG elements in IE
  4991. */
  4992. /* */
  4993. function resolveTransition (def$$1) {
  4994. if (!def$$1) {
  4995. return
  4996. }
  4997. /* istanbul ignore else */
  4998. if (typeof def$$1 === 'object') {
  4999. var res = {};
  5000. if (def$$1.css !== false) {
  5001. extend(res, autoCssTransition(def$$1.name || 'v'));
  5002. }
  5003. extend(res, def$$1);
  5004. return res
  5005. } else if (typeof def$$1 === 'string') {
  5006. return autoCssTransition(def$$1)
  5007. }
  5008. }
  5009. var autoCssTransition = cached(function (name) {
  5010. return {
  5011. enterClass: (name + "-enter"),
  5012. enterToClass: (name + "-enter-to"),
  5013. enterActiveClass: (name + "-enter-active"),
  5014. leaveClass: (name + "-leave"),
  5015. leaveToClass: (name + "-leave-to"),
  5016. leaveActiveClass: (name + "-leave-active")
  5017. }
  5018. });
  5019. // Transition property/event sniffing
  5020. // binding to window is necessary to make hot reload work in IE in strict mode
  5021. var raf = inBrowser && window.requestAnimationFrame
  5022. ? window.requestAnimationFrame.bind(window)
  5023. : setTimeout;
  5024. var transition = {
  5025. create: enter,
  5026. activate: enter,
  5027. remove: leave
  5028. };
  5029. function enter (_, vnode) {
  5030. var el = vnode.elm;
  5031. // call leave callback now
  5032. if (el._leaveCb) {
  5033. el._leaveCb.cancelled = true;
  5034. el._leaveCb();
  5035. }
  5036. var data = resolveTransition(vnode.data.transition);
  5037. if (!data) {
  5038. return
  5039. }
  5040. /* istanbul ignore if */
  5041. if (el._enterCb) {
  5042. return
  5043. }
  5044. var enterClass = data.enterClass;
  5045. var enterToClass = data.enterToClass;
  5046. var enterActiveClass = data.enterActiveClass;
  5047. var appearClass = data.appearClass;
  5048. var appearToClass = data.appearToClass;
  5049. var appearActiveClass = data.appearActiveClass;
  5050. var beforeEnter = data.beforeEnter;
  5051. var enter = data.enter;
  5052. var afterEnter = data.afterEnter;
  5053. var enterCancelled = data.enterCancelled;
  5054. var beforeAppear = data.beforeAppear;
  5055. var appear = data.appear;
  5056. var afterAppear = data.afterAppear;
  5057. var appearCancelled = data.appearCancelled;
  5058. var context = activeInstance;
  5059. var transitionNode = activeInstance.$vnode;
  5060. while (transitionNode && transitionNode.parent) {
  5061. transitionNode = transitionNode.parent;
  5062. context = transitionNode.context;
  5063. }
  5064. var isAppear = !context._isMounted || !vnode.isRootInsert;
  5065. if (isAppear && !appear && appear !== '') {
  5066. return
  5067. }
  5068. var startClass = isAppear ? appearClass : enterClass;
  5069. var toClass = isAppear ? appearToClass : enterToClass;
  5070. var activeClass = isAppear ? appearActiveClass : enterActiveClass;
  5071. var beforeEnterHook = isAppear ? (beforeAppear || beforeEnter) : beforeEnter;
  5072. var enterHook = isAppear ? (typeof appear === 'function' ? appear : enter) : enter;
  5073. var afterEnterHook = isAppear ? (afterAppear || afterEnter) : afterEnter;
  5074. var enterCancelledHook = isAppear ? (appearCancelled || enterCancelled) : enterCancelled;
  5075. var userWantsControl =
  5076. enterHook &&
  5077. // enterHook may be a bound method which exposes
  5078. // the length of original fn as _length
  5079. (enterHook._length || enterHook.length) > 1;
  5080. var stylesheet = vnode.context.$options.style || {};
  5081. var startState = stylesheet[startClass];
  5082. var transitionProperties = (stylesheet['@TRANSITION'] && stylesheet['@TRANSITION'][activeClass]) || {};
  5083. var endState = getEnterTargetState(el, stylesheet, startClass, toClass, activeClass, vnode.context);
  5084. var needAnimation = Object.keys(endState).length > 0;
  5085. var cb = el._enterCb = once(function () {
  5086. if (cb.cancelled) {
  5087. enterCancelledHook && enterCancelledHook(el);
  5088. } else {
  5089. afterEnterHook && afterEnterHook(el);
  5090. }
  5091. el._enterCb = null;
  5092. });
  5093. // We need to wait until the native element has been inserted, but currently
  5094. // there's no API to do that. So we have to wait "one frame" - not entirely
  5095. // sure if this is guaranteed to be enough (e.g. on slow devices?)
  5096. setTimeout(function () {
  5097. var parent = el.parentNode;
  5098. var pendingNode = parent && parent._pending && parent._pending[vnode.key];
  5099. if (pendingNode &&
  5100. pendingNode.context === vnode.context &&
  5101. pendingNode.tag === vnode.tag &&
  5102. pendingNode.elm._leaveCb) {
  5103. pendingNode.elm._leaveCb();
  5104. }
  5105. enterHook && enterHook(el, cb);
  5106. if (needAnimation) {
  5107. var animation = vnode.context.$requireWeexModule('animation');
  5108. animation.transition(el.ref, {
  5109. styles: endState,
  5110. duration: transitionProperties.duration || 0,
  5111. delay: transitionProperties.delay || 0,
  5112. timingFunction: transitionProperties.timingFunction || 'linear'
  5113. }, userWantsControl ? noop : cb);
  5114. } else if (!userWantsControl) {
  5115. cb();
  5116. }
  5117. }, 16);
  5118. // start enter transition
  5119. beforeEnterHook && beforeEnterHook(el);
  5120. if (startState) {
  5121. for (var key in startState) {
  5122. el.setStyle(key, startState[key]);
  5123. }
  5124. }
  5125. if (!needAnimation && !userWantsControl) {
  5126. cb();
  5127. }
  5128. }
  5129. function leave (vnode, rm) {
  5130. var el = vnode.elm;
  5131. // call enter callback now
  5132. if (el._enterCb) {
  5133. el._enterCb.cancelled = true;
  5134. el._enterCb();
  5135. }
  5136. var data = resolveTransition(vnode.data.transition);
  5137. if (!data) {
  5138. return rm()
  5139. }
  5140. if (el._leaveCb) {
  5141. return
  5142. }
  5143. var leaveClass = data.leaveClass;
  5144. var leaveToClass = data.leaveToClass;
  5145. var leaveActiveClass = data.leaveActiveClass;
  5146. var beforeLeave = data.beforeLeave;
  5147. var leave = data.leave;
  5148. var afterLeave = data.afterLeave;
  5149. var leaveCancelled = data.leaveCancelled;
  5150. var delayLeave = data.delayLeave;
  5151. var userWantsControl =
  5152. leave &&
  5153. // leave hook may be a bound method which exposes
  5154. // the length of original fn as _length
  5155. (leave._length || leave.length) > 1;
  5156. var stylesheet = vnode.context.$options.style || {};
  5157. var startState = stylesheet[leaveClass];
  5158. var endState = stylesheet[leaveToClass] || stylesheet[leaveActiveClass];
  5159. var transitionProperties = (stylesheet['@TRANSITION'] && stylesheet['@TRANSITION'][leaveActiveClass]) || {};
  5160. var cb = el._leaveCb = once(function () {
  5161. if (el.parentNode && el.parentNode._pending) {
  5162. el.parentNode._pending[vnode.key] = null;
  5163. }
  5164. if (cb.cancelled) {
  5165. leaveCancelled && leaveCancelled(el);
  5166. } else {
  5167. rm();
  5168. afterLeave && afterLeave(el);
  5169. }
  5170. el._leaveCb = null;
  5171. });
  5172. if (delayLeave) {
  5173. delayLeave(performLeave);
  5174. } else {
  5175. performLeave();
  5176. }
  5177. function performLeave () {
  5178. var animation = vnode.context.$requireWeexModule('animation');
  5179. // the delayed leave may have already been cancelled
  5180. if (cb.cancelled) {
  5181. return
  5182. }
  5183. // record leaving element
  5184. if (!vnode.data.show) {
  5185. (el.parentNode._pending || (el.parentNode._pending = {}))[vnode.key] = vnode;
  5186. }
  5187. beforeLeave && beforeLeave(el);
  5188. if (startState) {
  5189. animation.transition(el.ref, {
  5190. styles: startState
  5191. }, next);
  5192. } else {
  5193. next();
  5194. }
  5195. function next () {
  5196. animation.transition(el.ref, {
  5197. styles: endState,
  5198. duration: transitionProperties.duration || 0,
  5199. delay: transitionProperties.delay || 0,
  5200. timingFunction: transitionProperties.timingFunction || 'linear'
  5201. }, userWantsControl ? noop : cb);
  5202. }
  5203. leave && leave(el, cb);
  5204. if (!endState && !userWantsControl) {
  5205. cb();
  5206. }
  5207. }
  5208. }
  5209. // determine the target animation style for an entering transition.
  5210. function getEnterTargetState (el, stylesheet, startClass, endClass, activeClass, vm) {
  5211. var targetState = {};
  5212. var startState = stylesheet[startClass];
  5213. var endState = stylesheet[endClass];
  5214. var activeState = stylesheet[activeClass];
  5215. // 1. fallback to element's default styling
  5216. if (startState) {
  5217. for (var key in startState) {
  5218. targetState[key] = el.style[key];
  5219. if (
  5220. process.env.NODE_ENV !== 'production' &&
  5221. targetState[key] == null &&
  5222. (!activeState || activeState[key] == null) &&
  5223. (!endState || endState[key] == null)
  5224. ) {
  5225. warn(
  5226. "transition property \"" + key + "\" is declared in enter starting class (." + startClass + "), " +
  5227. "but not declared anywhere in enter ending class (." + endClass + "), " +
  5228. "enter active cass (." + activeClass + ") or the element's default styling. " +
  5229. "Note in Weex, CSS properties need explicit values to be transitionable."
  5230. );
  5231. }
  5232. }
  5233. }
  5234. // 2. if state is mixed in active state, extract them while excluding
  5235. // transition properties
  5236. if (activeState) {
  5237. for (var key$1 in activeState) {
  5238. if (key$1.indexOf('transition') !== 0) {
  5239. targetState[key$1] = activeState[key$1];
  5240. }
  5241. }
  5242. }
  5243. // 3. explicit endState has highest priority
  5244. if (endState) {
  5245. extend(targetState, endState);
  5246. }
  5247. return targetState
  5248. }
  5249. var platformModules = [
  5250. attrs,
  5251. klass,
  5252. events,
  5253. style,
  5254. transition
  5255. ];
  5256. /* */
  5257. // the directive module should be applied last, after all
  5258. // built-in modules have been applied.
  5259. var modules = platformModules.concat(baseModules);
  5260. var patch = createPatchFunction({
  5261. nodeOps: nodeOps,
  5262. modules: modules,
  5263. LONG_LIST_THRESHOLD: 10
  5264. });
  5265. var platformDirectives = {
  5266. };
  5267. /* */
  5268. // Provides transition support for a single element/component.
  5269. // supports transition mode (out-in / in-out)
  5270. var transitionProps = {
  5271. name: String,
  5272. appear: Boolean,
  5273. css: Boolean,
  5274. mode: String,
  5275. type: String,
  5276. enterClass: String,
  5277. leaveClass: String,
  5278. enterToClass: String,
  5279. leaveToClass: String,
  5280. enterActiveClass: String,
  5281. leaveActiveClass: String,
  5282. appearClass: String,
  5283. appearActiveClass: String,
  5284. appearToClass: String,
  5285. duration: [Number, String, Object]
  5286. };
  5287. // in case the child is also an abstract component, e.g. <keep-alive>
  5288. // we want to recursively retrieve the real component to be rendered
  5289. function getRealChild (vnode) {
  5290. var compOptions = vnode && vnode.componentOptions;
  5291. if (compOptions && compOptions.Ctor.options.abstract) {
  5292. return getRealChild(getFirstComponentChild(compOptions.children))
  5293. } else {
  5294. return vnode
  5295. }
  5296. }
  5297. function extractTransitionData (comp) {
  5298. var data = {};
  5299. var options = comp.$options;
  5300. // props
  5301. for (var key in options.propsData) {
  5302. data[key] = comp[key];
  5303. }
  5304. // events.
  5305. // extract listeners and pass them directly to the transition methods
  5306. var listeners = options._parentListeners;
  5307. for (var key$1 in listeners) {
  5308. data[camelize(key$1)] = listeners[key$1];
  5309. }
  5310. return data
  5311. }
  5312. function placeholder (h, rawChild) {
  5313. if (/\d-keep-alive$/.test(rawChild.tag)) {
  5314. return h('keep-alive', {
  5315. props: rawChild.componentOptions.propsData
  5316. })
  5317. }
  5318. }
  5319. function hasParentTransition (vnode) {
  5320. while ((vnode = vnode.parent)) {
  5321. if (vnode.data.transition) {
  5322. return true
  5323. }
  5324. }
  5325. }
  5326. function isSameChild (child, oldChild) {
  5327. return oldChild.key === child.key && oldChild.tag === child.tag
  5328. }
  5329. var Transition$1 = {
  5330. name: 'transition',
  5331. props: transitionProps,
  5332. abstract: true,
  5333. render: function render (h) {
  5334. var this$1 = this;
  5335. var children = this.$slots.default;
  5336. if (!children) {
  5337. return
  5338. }
  5339. // filter out text nodes (possible whitespaces)
  5340. children = children.filter(function (c) { return c.tag; });
  5341. /* istanbul ignore if */
  5342. if (!children.length) {
  5343. return
  5344. }
  5345. // warn multiple elements
  5346. if (process.env.NODE_ENV !== 'production' && children.length > 1) {
  5347. warn(
  5348. '<transition> can only be used on a single element. Use ' +
  5349. '<transition-group> for lists.',
  5350. this.$parent
  5351. );
  5352. }
  5353. var mode = this.mode;
  5354. // warn invalid mode
  5355. if (process.env.NODE_ENV !== 'production' &&
  5356. mode && mode !== 'in-out' && mode !== 'out-in') {
  5357. warn(
  5358. 'invalid <transition> mode: ' + mode,
  5359. this.$parent
  5360. );
  5361. }
  5362. var rawChild = children[0];
  5363. // if this is a component root node and the component's
  5364. // parent container node also has transition, skip.
  5365. if (hasParentTransition(this.$vnode)) {
  5366. return rawChild
  5367. }
  5368. // apply transition data to child
  5369. // use getRealChild() to ignore abstract components e.g. keep-alive
  5370. var child = getRealChild(rawChild);
  5371. /* istanbul ignore if */
  5372. if (!child) {
  5373. return rawChild
  5374. }
  5375. if (this._leaving) {
  5376. return placeholder(h, rawChild)
  5377. }
  5378. // ensure a key that is unique to the vnode type and to this transition
  5379. // component instance. This key will be used to remove pending leaving nodes
  5380. // during entering.
  5381. var id = "__transition-" + (this._uid) + "-";
  5382. child.key = child.key == null
  5383. ? id + child.tag
  5384. : isPrimitive(child.key)
  5385. ? (String(child.key).indexOf(id) === 0 ? child.key : id + child.key)
  5386. : child.key;
  5387. var data = (child.data || (child.data = {})).transition = extractTransitionData(this);
  5388. var oldRawChild = this._vnode;
  5389. var oldChild = getRealChild(oldRawChild);
  5390. // mark v-show
  5391. // so that the transition module can hand over the control to the directive
  5392. if (child.data.directives && child.data.directives.some(function (d) { return d.name === 'show'; })) {
  5393. child.data.show = true;
  5394. }
  5395. if (oldChild && oldChild.data && !isSameChild(child, oldChild)) {
  5396. // replace old child transition data with fresh one
  5397. // important for dynamic transitions!
  5398. var oldData = oldChild && (oldChild.data.transition = extend({}, data));
  5399. // handle transition mode
  5400. if (mode === 'out-in') {
  5401. // return placeholder node and queue update when leave finishes
  5402. this._leaving = true;
  5403. mergeVNodeHook(oldData, 'afterLeave', function () {
  5404. this$1._leaving = false;
  5405. this$1.$forceUpdate();
  5406. });
  5407. return placeholder(h, rawChild)
  5408. } else if (mode === 'in-out') {
  5409. var delayedLeave;
  5410. var performLeave = function () { delayedLeave(); };
  5411. mergeVNodeHook(data, 'afterEnter', performLeave);
  5412. mergeVNodeHook(data, 'enterCancelled', performLeave);
  5413. mergeVNodeHook(oldData, 'delayLeave', function (leave) { delayedLeave = leave; });
  5414. }
  5415. }
  5416. return rawChild
  5417. }
  5418. };
  5419. // reuse same transition component logic from web
  5420. var props = extend({
  5421. tag: String,
  5422. moveClass: String
  5423. }, transitionProps);
  5424. delete props.mode;
  5425. var TransitionGroup = {
  5426. props: props,
  5427. created: function created () {
  5428. var dom = this.$requireWeexModule('dom');
  5429. this.getPosition = function (el) { return new Promise(function (resolve, reject) {
  5430. dom.getComponentRect(el.ref, function (res) {
  5431. if (!res.result) {
  5432. reject(new Error(("failed to get rect for element: " + (el.tag))));
  5433. } else {
  5434. resolve(res.size);
  5435. }
  5436. });
  5437. }); };
  5438. var animation = this.$requireWeexModule('animation');
  5439. this.animate = function (el, options) { return new Promise(function (resolve) {
  5440. animation.transition(el.ref, options, resolve);
  5441. }); };
  5442. },
  5443. render: function render (h) {
  5444. var tag = this.tag || this.$vnode.data.tag || 'span';
  5445. var map = Object.create(null);
  5446. var prevChildren = this.prevChildren = this.children;
  5447. var rawChildren = this.$slots.default || [];
  5448. var children = this.children = [];
  5449. var transitionData = extractTransitionData(this);
  5450. for (var i = 0; i < rawChildren.length; i++) {
  5451. var c = rawChildren[i];
  5452. if (c.tag) {
  5453. if (c.key != null && String(c.key).indexOf('__vlist') !== 0) {
  5454. children.push(c);
  5455. map[c.key] = c
  5456. ;(c.data || (c.data = {})).transition = transitionData;
  5457. } else if (process.env.NODE_ENV !== 'production') {
  5458. var opts = c.componentOptions;
  5459. var name = opts
  5460. ? (opts.Ctor.options.name || opts.tag)
  5461. : c.tag;
  5462. warn(("<transition-group> children must be keyed: <" + name + ">"));
  5463. }
  5464. }
  5465. }
  5466. if (prevChildren) {
  5467. var kept = [];
  5468. var removed = [];
  5469. prevChildren.forEach(function (c) {
  5470. c.data.transition = transitionData;
  5471. // TODO: record before patch positions
  5472. if (map[c.key]) {
  5473. kept.push(c);
  5474. } else {
  5475. removed.push(c);
  5476. }
  5477. });
  5478. this.kept = h(tag, null, kept);
  5479. this.removed = removed;
  5480. }
  5481. return h(tag, null, children)
  5482. },
  5483. beforeUpdate: function beforeUpdate () {
  5484. // force removing pass
  5485. this.__patch__(
  5486. this._vnode,
  5487. this.kept,
  5488. false, // hydrating
  5489. true // removeOnly (!important, avoids unnecessary moves)
  5490. );
  5491. this._vnode = this.kept;
  5492. },
  5493. updated: function updated () {
  5494. var children = this.prevChildren;
  5495. var moveClass = this.moveClass || ((this.name || 'v') + '-move');
  5496. var moveData = children.length && this.getMoveData(children[0].context, moveClass);
  5497. if (!moveData) {
  5498. return
  5499. }
  5500. // TODO: finish implementing move animations once
  5501. // we have access to sync getComponentRect()
  5502. // children.forEach(callPendingCbs)
  5503. // Promise.all(children.map(c => {
  5504. // const oldPos = c.data.pos
  5505. // const newPos = c.data.newPos
  5506. // const dx = oldPos.left - newPos.left
  5507. // const dy = oldPos.top - newPos.top
  5508. // if (dx || dy) {
  5509. // c.data.moved = true
  5510. // return this.animate(c.elm, {
  5511. // styles: {
  5512. // transform: `translate(${dx}px,${dy}px)`
  5513. // }
  5514. // })
  5515. // }
  5516. // })).then(() => {
  5517. // children.forEach(c => {
  5518. // if (c.data.moved) {
  5519. // this.animate(c.elm, {
  5520. // styles: {
  5521. // transform: ''
  5522. // },
  5523. // duration: moveData.duration || 0,
  5524. // delay: moveData.delay || 0,
  5525. // timingFunction: moveData.timingFunction || 'linear'
  5526. // })
  5527. // }
  5528. // })
  5529. // })
  5530. },
  5531. methods: {
  5532. getMoveData: function getMoveData (context, moveClass) {
  5533. var stylesheet = context.$options.style || {};
  5534. return stylesheet['@TRANSITION'] && stylesheet['@TRANSITION'][moveClass]
  5535. }
  5536. }
  5537. };
  5538. // function callPendingCbs (c) {
  5539. // /* istanbul ignore if */
  5540. // if (c.elm._moveCb) {
  5541. // c.elm._moveCb()
  5542. // }
  5543. // /* istanbul ignore if */
  5544. // if (c.elm._enterCb) {
  5545. // c.elm._enterCb()
  5546. // }
  5547. // }
  5548. var platformComponents = {
  5549. Transition: Transition$1,
  5550. TransitionGroup: TransitionGroup
  5551. };
  5552. /* globals renderer */
  5553. var isReservedTag = makeMap(
  5554. 'template,script,style,element,content,slot,link,meta,svg,view,' +
  5555. 'a,div,img,image,text,span,richtext,input,switch,textarea,spinner,select,' +
  5556. 'slider,slider-neighbor,indicator,trisition,trisition-group,canvas,' +
  5557. 'list,cell,header,loading,loading-indicator,refresh,scrollable,scroller,' +
  5558. 'video,web,embed,tabbar,tabheader,datepicker,timepicker,marquee,countdown',
  5559. true
  5560. );
  5561. // Elements that you can, intentionally, leave open (and which close themselves)
  5562. // more flexable than web
  5563. var canBeLeftOpenTag = makeMap(
  5564. 'web,spinner,switch,video,textarea,canvas,' +
  5565. 'indicator,marquee,countdown',
  5566. true
  5567. );
  5568. var isUnaryTag = makeMap(
  5569. 'embed,img,image,input,link,meta',
  5570. true
  5571. );
  5572. function mustUseProp () { /* console.log('mustUseProp') */ }
  5573. function isUnknownElement () { /* console.log('isUnknownElement') */ }
  5574. function query (el, document) {
  5575. // renderer is injected by weex factory wrapper
  5576. var placeholder = new renderer.Comment('root');
  5577. placeholder.hasAttribute = placeholder.removeAttribute = function () {}; // hack for patch
  5578. document.documentElement.appendChild(placeholder);
  5579. return placeholder
  5580. }
  5581. /* */
  5582. // install platform specific utils
  5583. Vue$2.config.mustUseProp = mustUseProp;
  5584. Vue$2.config.isReservedTag = isReservedTag;
  5585. Vue$2.config.isUnknownElement = isUnknownElement;
  5586. // install platform runtime directives and components
  5587. Vue$2.options.directives = platformDirectives;
  5588. Vue$2.options.components = platformComponents;
  5589. // install platform patch function
  5590. Vue$2.prototype.__patch__ = patch;
  5591. // wrap mount
  5592. Vue$2.prototype.$mount = function (
  5593. el,
  5594. hydrating
  5595. ) {
  5596. return mountComponent(
  5597. this,
  5598. el && query(el, this.$document),
  5599. hydrating
  5600. )
  5601. };
  5602. // this entry is built and wrapped with a factory function
  5603. // used to generate a fresh copy of Vue for every Weex instance.
  5604. exports.Vue = Vue$2;
  5605. }