vue.js 241 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308
  1. /*!
  2. * Vue.js v1.0.10
  3. * (c) 2015 Evan You
  4. * Released under the MIT License.
  5. */
  6. (function (global, factory) {
  7. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  8. typeof define === 'function' && define.amd ? define(factory) :
  9. global.Vue = factory();
  10. }(this, function () { 'use strict';
  11. function set(obj, key, val) {
  12. if (hasOwn(obj, key)) {
  13. obj[key] = val;
  14. return;
  15. }
  16. if (obj._isVue) {
  17. set(obj._data, key, val);
  18. return;
  19. }
  20. var ob = obj.__ob__;
  21. if (!ob) {
  22. obj[key] = val;
  23. return;
  24. }
  25. ob.convert(key, val);
  26. ob.dep.notify();
  27. if (ob.vms) {
  28. var i = ob.vms.length;
  29. while (i--) {
  30. var vm = ob.vms[i];
  31. vm._proxy(key);
  32. vm._digest();
  33. }
  34. }
  35. }
  36. /**
  37. * Delete a property and trigger change if necessary.
  38. *
  39. * @param {Object} obj
  40. * @param {String} key
  41. */
  42. function del(obj, key) {
  43. if (!hasOwn(obj, key)) {
  44. return;
  45. }
  46. delete obj[key];
  47. var ob = obj.__ob__;
  48. if (!ob) {
  49. return;
  50. }
  51. ob.dep.notify();
  52. if (ob.vms) {
  53. var i = ob.vms.length;
  54. while (i--) {
  55. var vm = ob.vms[i];
  56. vm._unproxy(key);
  57. vm._digest();
  58. }
  59. }
  60. }
  61. var hasOwnProperty = Object.prototype.hasOwnProperty;
  62. /**
  63. * Check whether the object has the property.
  64. *
  65. * @param {Object} obj
  66. * @param {String} key
  67. * @return {Boolean}
  68. */
  69. function hasOwn(obj, key) {
  70. return hasOwnProperty.call(obj, key);
  71. }
  72. /**
  73. * Check if an expression is a literal value.
  74. *
  75. * @param {String} exp
  76. * @return {Boolean}
  77. */
  78. var literalValueRE = /^\s?(true|false|[\d\.]+|'[^']*'|"[^"]*")\s?$/;
  79. function isLiteral(exp) {
  80. return literalValueRE.test(exp);
  81. }
  82. /**
  83. * Check if a string starts with $ or _
  84. *
  85. * @param {String} str
  86. * @return {Boolean}
  87. */
  88. function isReserved(str) {
  89. var c = (str + '').charCodeAt(0);
  90. return c === 0x24 || c === 0x5F;
  91. }
  92. /**
  93. * Guard text output, make sure undefined outputs
  94. * empty string
  95. *
  96. * @param {*} value
  97. * @return {String}
  98. */
  99. function _toString(value) {
  100. return value == null ? '' : value.toString();
  101. }
  102. /**
  103. * Check and convert possible numeric strings to numbers
  104. * before setting back to data
  105. *
  106. * @param {*} value
  107. * @return {*|Number}
  108. */
  109. function toNumber(value) {
  110. if (typeof value !== 'string') {
  111. return value;
  112. } else {
  113. var parsed = Number(value);
  114. return isNaN(parsed) ? value : parsed;
  115. }
  116. }
  117. /**
  118. * Convert string boolean literals into real booleans.
  119. *
  120. * @param {*} value
  121. * @return {*|Boolean}
  122. */
  123. function toBoolean(value) {
  124. return value === 'true' ? true : value === 'false' ? false : value;
  125. }
  126. /**
  127. * Strip quotes from a string
  128. *
  129. * @param {String} str
  130. * @return {String | false}
  131. */
  132. function stripQuotes(str) {
  133. var a = str.charCodeAt(0);
  134. var b = str.charCodeAt(str.length - 1);
  135. return a === b && (a === 0x22 || a === 0x27) ? str.slice(1, -1) : str;
  136. }
  137. /**
  138. * Camelize a hyphen-delmited string.
  139. *
  140. * @param {String} str
  141. * @return {String}
  142. */
  143. var camelizeRE = /-(\w)/g;
  144. function camelize(str) {
  145. return str.replace(camelizeRE, toUpper);
  146. }
  147. function toUpper(_, c) {
  148. return c ? c.toUpperCase() : '';
  149. }
  150. /**
  151. * Hyphenate a camelCase string.
  152. *
  153. * @param {String} str
  154. * @return {String}
  155. */
  156. var hyphenateRE = /([a-z\d])([A-Z])/g;
  157. function hyphenate(str) {
  158. return str.replace(hyphenateRE, '$1-$2').toLowerCase();
  159. }
  160. /**
  161. * Converts hyphen/underscore/slash delimitered names into
  162. * camelized classNames.
  163. *
  164. * e.g. my-component => MyComponent
  165. * some_else => SomeElse
  166. * some/comp => SomeComp
  167. *
  168. * @param {String} str
  169. * @return {String}
  170. */
  171. var classifyRE = /(?:^|[-_\/])(\w)/g;
  172. function classify(str) {
  173. return str.replace(classifyRE, toUpper);
  174. }
  175. /**
  176. * Simple bind, faster than native
  177. *
  178. * @param {Function} fn
  179. * @param {Object} ctx
  180. * @return {Function}
  181. */
  182. function bind$1(fn, ctx) {
  183. return function (a) {
  184. var l = arguments.length;
  185. return l ? l > 1 ? fn.apply(ctx, arguments) : fn.call(ctx, a) : fn.call(ctx);
  186. };
  187. }
  188. /**
  189. * Convert an Array-like object to a real Array.
  190. *
  191. * @param {Array-like} list
  192. * @param {Number} [start] - start index
  193. * @return {Array}
  194. */
  195. function toArray(list, start) {
  196. start = start || 0;
  197. var i = list.length - start;
  198. var ret = new Array(i);
  199. while (i--) {
  200. ret[i] = list[i + start];
  201. }
  202. return ret;
  203. }
  204. /**
  205. * Mix properties into target object.
  206. *
  207. * @param {Object} to
  208. * @param {Object} from
  209. */
  210. function extend(to, from) {
  211. var keys = Object.keys(from);
  212. var i = keys.length;
  213. while (i--) {
  214. to[keys[i]] = from[keys[i]];
  215. }
  216. return to;
  217. }
  218. /**
  219. * Quick object check - this is primarily used to tell
  220. * Objects from primitive values when we know the value
  221. * is a JSON-compliant type.
  222. *
  223. * @param {*} obj
  224. * @return {Boolean}
  225. */
  226. function isObject(obj) {
  227. return obj !== null && typeof obj === 'object';
  228. }
  229. /**
  230. * Strict object type check. Only returns true
  231. * for plain JavaScript objects.
  232. *
  233. * @param {*} obj
  234. * @return {Boolean}
  235. */
  236. var toString = Object.prototype.toString;
  237. var OBJECT_STRING = '[object Object]';
  238. function isPlainObject(obj) {
  239. return toString.call(obj) === OBJECT_STRING;
  240. }
  241. /**
  242. * Array type check.
  243. *
  244. * @param {*} obj
  245. * @return {Boolean}
  246. */
  247. var isArray = Array.isArray;
  248. /**
  249. * Define a non-enumerable property
  250. *
  251. * @param {Object} obj
  252. * @param {String} key
  253. * @param {*} val
  254. * @param {Boolean} [enumerable]
  255. */
  256. function def(obj, key, val, enumerable) {
  257. Object.defineProperty(obj, key, {
  258. value: val,
  259. enumerable: !!enumerable,
  260. writable: true,
  261. configurable: true
  262. });
  263. }
  264. /**
  265. * Debounce a function so it only gets called after the
  266. * input stops arriving after the given wait period.
  267. *
  268. * @param {Function} func
  269. * @param {Number} wait
  270. * @return {Function} - the debounced function
  271. */
  272. function _debounce(func, wait) {
  273. var timeout, args, context, timestamp, result;
  274. var later = function later() {
  275. var last = Date.now() - timestamp;
  276. if (last < wait && last >= 0) {
  277. timeout = setTimeout(later, wait - last);
  278. } else {
  279. timeout = null;
  280. result = func.apply(context, args);
  281. if (!timeout) context = args = null;
  282. }
  283. };
  284. return function () {
  285. context = this;
  286. args = arguments;
  287. timestamp = Date.now();
  288. if (!timeout) {
  289. timeout = setTimeout(later, wait);
  290. }
  291. return result;
  292. };
  293. }
  294. /**
  295. * Manual indexOf because it's slightly faster than
  296. * native.
  297. *
  298. * @param {Array} arr
  299. * @param {*} obj
  300. */
  301. function indexOf(arr, obj) {
  302. var i = arr.length;
  303. while (i--) {
  304. if (arr[i] === obj) return i;
  305. }
  306. return -1;
  307. }
  308. /**
  309. * Make a cancellable version of an async callback.
  310. *
  311. * @param {Function} fn
  312. * @return {Function}
  313. */
  314. function cancellable(fn) {
  315. var cb = function cb() {
  316. if (!cb.cancelled) {
  317. return fn.apply(this, arguments);
  318. }
  319. };
  320. cb.cancel = function () {
  321. cb.cancelled = true;
  322. };
  323. return cb;
  324. }
  325. /**
  326. * Check if two values are loosely equal - that is,
  327. * if they are plain objects, do they have the same shape?
  328. *
  329. * @param {*} a
  330. * @param {*} b
  331. * @return {Boolean}
  332. */
  333. function looseEqual(a, b) {
  334. /* eslint-disable eqeqeq */
  335. return a == b || (isObject(a) && isObject(b) ? JSON.stringify(a) === JSON.stringify(b) : false);
  336. /* eslint-enable eqeqeq */
  337. }
  338. var hasProto = ('__proto__' in {});
  339. // Browser environment sniffing
  340. var inBrowser = typeof window !== 'undefined' && Object.prototype.toString.call(window) !== '[object Object]';
  341. var isIE9 = inBrowser && navigator.userAgent.toLowerCase().indexOf('msie 9.0') > 0;
  342. var isAndroid = inBrowser && navigator.userAgent.toLowerCase().indexOf('android') > 0;
  343. var transitionProp = undefined;
  344. var transitionEndEvent = undefined;
  345. var animationProp = undefined;
  346. var animationEndEvent = undefined;
  347. // Transition property/event sniffing
  348. if (inBrowser && !isIE9) {
  349. var isWebkitTrans = window.ontransitionend === undefined && window.onwebkittransitionend !== undefined;
  350. var isWebkitAnim = window.onanimationend === undefined && window.onwebkitanimationend !== undefined;
  351. transitionProp = isWebkitTrans ? 'WebkitTransition' : 'transition';
  352. transitionEndEvent = isWebkitTrans ? 'webkitTransitionEnd' : 'transitionend';
  353. animationProp = isWebkitAnim ? 'WebkitAnimation' : 'animation';
  354. animationEndEvent = isWebkitAnim ? 'webkitAnimationEnd' : 'animationend';
  355. }
  356. /**
  357. * Defer a task to execute it asynchronously. Ideally this
  358. * should be executed as a microtask, so we leverage
  359. * MutationObserver if it's available, and fallback to
  360. * setTimeout(0).
  361. *
  362. * @param {Function} cb
  363. * @param {Object} ctx
  364. */
  365. var nextTick = (function () {
  366. var callbacks = [];
  367. var pending = false;
  368. var timerFunc;
  369. function nextTickHandler() {
  370. pending = false;
  371. var copies = callbacks.slice(0);
  372. callbacks = [];
  373. for (var i = 0; i < copies.length; i++) {
  374. copies[i]();
  375. }
  376. }
  377. /* istanbul ignore if */
  378. if (typeof MutationObserver !== 'undefined') {
  379. var counter = 1;
  380. var observer = new MutationObserver(nextTickHandler);
  381. var textNode = document.createTextNode(counter);
  382. observer.observe(textNode, {
  383. characterData: true
  384. });
  385. timerFunc = function () {
  386. counter = (counter + 1) % 2;
  387. textNode.data = counter;
  388. };
  389. } else {
  390. timerFunc = setTimeout;
  391. }
  392. return function (cb, ctx) {
  393. var func = ctx ? function () {
  394. cb.call(ctx);
  395. } : cb;
  396. callbacks.push(func);
  397. if (pending) return;
  398. pending = true;
  399. timerFunc(nextTickHandler, 0);
  400. };
  401. })();
  402. function Cache(limit) {
  403. this.size = 0;
  404. this.limit = limit;
  405. this.head = this.tail = undefined;
  406. this._keymap = Object.create(null);
  407. }
  408. var p = Cache.prototype;
  409. /**
  410. * Put <value> into the cache associated with <key>.
  411. * Returns the entry which was removed to make room for
  412. * the new entry. Otherwise undefined is returned.
  413. * (i.e. if there was enough room already).
  414. *
  415. * @param {String} key
  416. * @param {*} value
  417. * @return {Entry|undefined}
  418. */
  419. p.put = function (key, value) {
  420. var entry = {
  421. key: key,
  422. value: value
  423. };
  424. this._keymap[key] = entry;
  425. if (this.tail) {
  426. this.tail.newer = entry;
  427. entry.older = this.tail;
  428. } else {
  429. this.head = entry;
  430. }
  431. this.tail = entry;
  432. if (this.size === this.limit) {
  433. return this.shift();
  434. } else {
  435. this.size++;
  436. }
  437. };
  438. /**
  439. * Purge the least recently used (oldest) entry from the
  440. * cache. Returns the removed entry or undefined if the
  441. * cache was empty.
  442. */
  443. p.shift = function () {
  444. var entry = this.head;
  445. if (entry) {
  446. this.head = this.head.newer;
  447. this.head.older = undefined;
  448. entry.newer = entry.older = undefined;
  449. this._keymap[entry.key] = undefined;
  450. }
  451. return entry;
  452. };
  453. /**
  454. * Get and register recent use of <key>. Returns the value
  455. * associated with <key> or undefined if not in cache.
  456. *
  457. * @param {String} key
  458. * @param {Boolean} returnEntry
  459. * @return {Entry|*}
  460. */
  461. p.get = function (key, returnEntry) {
  462. var entry = this._keymap[key];
  463. if (entry === undefined) return;
  464. if (entry === this.tail) {
  465. return returnEntry ? entry : entry.value;
  466. }
  467. // HEAD--------------TAIL
  468. // <.older .newer>
  469. // <--- add direction --
  470. // A B C <D> E
  471. if (entry.newer) {
  472. if (entry === this.head) {
  473. this.head = entry.newer;
  474. }
  475. entry.newer.older = entry.older; // C <-- E.
  476. }
  477. if (entry.older) {
  478. entry.older.newer = entry.newer; // C. --> E
  479. }
  480. entry.newer = undefined; // D --x
  481. entry.older = this.tail; // D. --> E
  482. if (this.tail) {
  483. this.tail.newer = entry; // E. <-- D
  484. }
  485. this.tail = entry;
  486. return returnEntry ? entry : entry.value;
  487. };
  488. var cache$1 = new Cache(1000);
  489. var filterTokenRE = /[^\s'"]+|'[^']*'|"[^"]*"/g;
  490. var reservedArgRE = /^in$|^-?\d+/;
  491. /**
  492. * Parser state
  493. */
  494. var str;
  495. var dir;
  496. var c;
  497. var i;
  498. var l;
  499. var lastFilterIndex;
  500. var inSingle;
  501. var inDouble;
  502. var curly;
  503. var square;
  504. var paren;
  505. /**
  506. * Push a filter to the current directive object
  507. */
  508. function pushFilter() {
  509. var exp = str.slice(lastFilterIndex, i).trim();
  510. var filter;
  511. if (exp) {
  512. filter = {};
  513. var tokens = exp.match(filterTokenRE);
  514. filter.name = tokens[0];
  515. if (tokens.length > 1) {
  516. filter.args = tokens.slice(1).map(processFilterArg);
  517. }
  518. }
  519. if (filter) {
  520. (dir.filters = dir.filters || []).push(filter);
  521. }
  522. lastFilterIndex = i + 1;
  523. }
  524. /**
  525. * Check if an argument is dynamic and strip quotes.
  526. *
  527. * @param {String} arg
  528. * @return {Object}
  529. */
  530. function processFilterArg(arg) {
  531. if (reservedArgRE.test(arg)) {
  532. return {
  533. value: toNumber(arg),
  534. dynamic: false
  535. };
  536. } else {
  537. var stripped = stripQuotes(arg);
  538. var dynamic = stripped === arg;
  539. return {
  540. value: dynamic ? arg : stripped,
  541. dynamic: dynamic
  542. };
  543. }
  544. }
  545. /**
  546. * Parse a directive value and extract the expression
  547. * and its filters into a descriptor.
  548. *
  549. * Example:
  550. *
  551. * "a + 1 | uppercase" will yield:
  552. * {
  553. * expression: 'a + 1',
  554. * filters: [
  555. * { name: 'uppercase', args: null }
  556. * ]
  557. * }
  558. *
  559. * @param {String} str
  560. * @return {Object}
  561. */
  562. function parseDirective(s) {
  563. var hit = cache$1.get(s);
  564. if (hit) {
  565. return hit;
  566. }
  567. // reset parser state
  568. str = s;
  569. inSingle = inDouble = false;
  570. curly = square = paren = 0;
  571. lastFilterIndex = 0;
  572. dir = {};
  573. for (i = 0, l = str.length; i < l; i++) {
  574. c = str.charCodeAt(i);
  575. if (inSingle) {
  576. // check single quote
  577. if (c === 0x27) inSingle = !inSingle;
  578. } else if (inDouble) {
  579. // check double quote
  580. if (c === 0x22) inDouble = !inDouble;
  581. } else if (c === 0x7C && // pipe
  582. str.charCodeAt(i + 1) !== 0x7C && str.charCodeAt(i - 1) !== 0x7C) {
  583. if (dir.expression == null) {
  584. // first filter, end of expression
  585. lastFilterIndex = i + 1;
  586. dir.expression = str.slice(0, i).trim();
  587. } else {
  588. // already has filter
  589. pushFilter();
  590. }
  591. } else {
  592. switch (c) {
  593. case 0x22:
  594. inDouble = true;break; // "
  595. case 0x27:
  596. inSingle = true;break; // '
  597. case 0x28:
  598. paren++;break; // (
  599. case 0x29:
  600. paren--;break; // )
  601. case 0x5B:
  602. square++;break; // [
  603. case 0x5D:
  604. square--;break; // ]
  605. case 0x7B:
  606. curly++;break; // {
  607. case 0x7D:
  608. curly--;break; // }
  609. }
  610. }
  611. }
  612. if (dir.expression == null) {
  613. dir.expression = str.slice(0, i).trim();
  614. } else if (lastFilterIndex !== 0) {
  615. pushFilter();
  616. }
  617. cache$1.put(s, dir);
  618. return dir;
  619. }
  620. var directive = Object.freeze({
  621. parseDirective: parseDirective
  622. });
  623. var regexEscapeRE = /[-.*+?^${}()|[\]\/\\]/g;
  624. var cache = undefined;
  625. var tagRE = undefined;
  626. var htmlRE = undefined;
  627. /**
  628. * Escape a string so it can be used in a RegExp
  629. * constructor.
  630. *
  631. * @param {String} str
  632. */
  633. function escapeRegex(str) {
  634. return str.replace(regexEscapeRE, '\\$&');
  635. }
  636. function compileRegex() {
  637. var open = escapeRegex(config.delimiters[0]);
  638. var close = escapeRegex(config.delimiters[1]);
  639. var unsafeOpen = escapeRegex(config.unsafeDelimiters[0]);
  640. var unsafeClose = escapeRegex(config.unsafeDelimiters[1]);
  641. tagRE = new RegExp(unsafeOpen + '(.+?)' + unsafeClose + '|' + open + '(.+?)' + close, 'g');
  642. htmlRE = new RegExp('^' + unsafeOpen + '.*' + unsafeClose + '$');
  643. // reset cache
  644. cache = new Cache(1000);
  645. }
  646. /**
  647. * Parse a template text string into an array of tokens.
  648. *
  649. * @param {String} text
  650. * @return {Array<Object> | null}
  651. * - {String} type
  652. * - {String} value
  653. * - {Boolean} [html]
  654. * - {Boolean} [oneTime]
  655. */
  656. function parseText(text) {
  657. if (!cache) {
  658. compileRegex();
  659. }
  660. var hit = cache.get(text);
  661. if (hit) {
  662. return hit;
  663. }
  664. text = text.replace(/\n/g, '');
  665. if (!tagRE.test(text)) {
  666. return null;
  667. }
  668. var tokens = [];
  669. var lastIndex = tagRE.lastIndex = 0;
  670. var match, index, html, value, first, oneTime;
  671. /* eslint-disable no-cond-assign */
  672. while (match = tagRE.exec(text)) {
  673. /* eslint-enable no-cond-assign */
  674. index = match.index;
  675. // push text token
  676. if (index > lastIndex) {
  677. tokens.push({
  678. value: text.slice(lastIndex, index)
  679. });
  680. }
  681. // tag token
  682. html = htmlRE.test(match[0]);
  683. value = html ? match[1] : match[2];
  684. first = value.charCodeAt(0);
  685. oneTime = first === 42; // *
  686. value = oneTime ? value.slice(1) : value;
  687. tokens.push({
  688. tag: true,
  689. value: value.trim(),
  690. html: html,
  691. oneTime: oneTime
  692. });
  693. lastIndex = index + match[0].length;
  694. }
  695. if (lastIndex < text.length) {
  696. tokens.push({
  697. value: text.slice(lastIndex)
  698. });
  699. }
  700. cache.put(text, tokens);
  701. return tokens;
  702. }
  703. /**
  704. * Format a list of tokens into an expression.
  705. * e.g. tokens parsed from 'a {{b}} c' can be serialized
  706. * into one single expression as '"a " + b + " c"'.
  707. *
  708. * @param {Array} tokens
  709. * @return {String}
  710. */
  711. function tokensToExp(tokens) {
  712. if (tokens.length > 1) {
  713. return tokens.map(function (token) {
  714. return formatToken(token);
  715. }).join('+');
  716. } else {
  717. return formatToken(tokens[0], true);
  718. }
  719. }
  720. /**
  721. * Format a single token.
  722. *
  723. * @param {Object} token
  724. * @param {Boolean} single
  725. * @return {String}
  726. */
  727. function formatToken(token, single) {
  728. return token.tag ? inlineFilters(token.value, single) : '"' + token.value + '"';
  729. }
  730. /**
  731. * For an attribute with multiple interpolation tags,
  732. * e.g. attr="some-{{thing | filter}}", in order to combine
  733. * the whole thing into a single watchable expression, we
  734. * have to inline those filters. This function does exactly
  735. * that. This is a bit hacky but it avoids heavy changes
  736. * to directive parser and watcher mechanism.
  737. *
  738. * @param {String} exp
  739. * @param {Boolean} single
  740. * @return {String}
  741. */
  742. var filterRE$1 = /[^|]\|[^|]/;
  743. function inlineFilters(exp, single) {
  744. if (!filterRE$1.test(exp)) {
  745. return single ? exp : '(' + exp + ')';
  746. } else {
  747. var dir = parseDirective(exp);
  748. if (!dir.filters) {
  749. return '(' + exp + ')';
  750. } else {
  751. return 'this._applyFilters(' + dir.expression + // value
  752. ',null,' + // oldValue (null for read)
  753. JSON.stringify(dir.filters) + // filter descriptors
  754. ',false)'; // write?
  755. }
  756. }
  757. }
  758. var text$1 = Object.freeze({
  759. compileRegex: compileRegex,
  760. parseText: parseText,
  761. tokensToExp: tokensToExp
  762. });
  763. var delimiters = ['{{', '}}'];
  764. var unsafeDelimiters = ['{{{', '}}}'];
  765. var config = Object.defineProperties({
  766. /**
  767. * Whether to print debug messages.
  768. * Also enables stack trace for warnings.
  769. *
  770. * @type {Boolean}
  771. */
  772. debug: false,
  773. /**
  774. * Whether to suppress warnings.
  775. *
  776. * @type {Boolean}
  777. */
  778. silent: false,
  779. /**
  780. * Whether to use async rendering.
  781. */
  782. async: true,
  783. /**
  784. * Whether to warn against errors caught when evaluating
  785. * expressions.
  786. */
  787. warnExpressionErrors: true,
  788. /**
  789. * Whether or not to handle fully object properties which
  790. * are already backed by getters and seters. Depending on
  791. * use case and environment, this might introduce non-neglible
  792. * performance penalties.
  793. */
  794. convertAllProperties: false,
  795. /**
  796. * Internal flag to indicate the delimiters have been
  797. * changed.
  798. *
  799. * @type {Boolean}
  800. */
  801. _delimitersChanged: true,
  802. /**
  803. * List of asset types that a component can own.
  804. *
  805. * @type {Array}
  806. */
  807. _assetTypes: ['component', 'directive', 'elementDirective', 'filter', 'transition', 'partial'],
  808. /**
  809. * prop binding modes
  810. */
  811. _propBindingModes: {
  812. ONE_WAY: 0,
  813. TWO_WAY: 1,
  814. ONE_TIME: 2
  815. },
  816. /**
  817. * Max circular updates allowed in a batcher flush cycle.
  818. */
  819. _maxUpdateCount: 100
  820. }, {
  821. delimiters: { /**
  822. * Interpolation delimiters. Changing these would trigger
  823. * the text parser to re-compile the regular expressions.
  824. *
  825. * @type {Array<String>}
  826. */
  827. get: function get() {
  828. return delimiters;
  829. },
  830. set: function set(val) {
  831. delimiters = val;
  832. compileRegex();
  833. },
  834. configurable: true,
  835. enumerable: true
  836. },
  837. unsafeDelimiters: {
  838. get: function get() {
  839. return unsafeDelimiters;
  840. },
  841. set: function set(val) {
  842. unsafeDelimiters = val;
  843. compileRegex();
  844. },
  845. configurable: true,
  846. enumerable: true
  847. }
  848. });
  849. var warn = undefined;
  850. if ('development' !== 'production') {
  851. (function () {
  852. var hasConsole = typeof console !== 'undefined';
  853. warn = function (msg, e) {
  854. if (hasConsole && (!config.silent || config.debug)) {
  855. console.warn('[Vue warn]: ' + msg);
  856. /* istanbul ignore if */
  857. if (config.debug) {
  858. if (e) {
  859. throw e;
  860. } else {
  861. console.warn(new Error('Warning Stack Trace').stack);
  862. }
  863. }
  864. }
  865. };
  866. })();
  867. }
  868. /**
  869. * Append with transition.
  870. *
  871. * @param {Element} el
  872. * @param {Element} target
  873. * @param {Vue} vm
  874. * @param {Function} [cb]
  875. */
  876. function appendWithTransition(el, target, vm, cb) {
  877. applyTransition(el, 1, function () {
  878. target.appendChild(el);
  879. }, vm, cb);
  880. }
  881. /**
  882. * InsertBefore with transition.
  883. *
  884. * @param {Element} el
  885. * @param {Element} target
  886. * @param {Vue} vm
  887. * @param {Function} [cb]
  888. */
  889. function beforeWithTransition(el, target, vm, cb) {
  890. applyTransition(el, 1, function () {
  891. before(el, target);
  892. }, vm, cb);
  893. }
  894. /**
  895. * Remove with transition.
  896. *
  897. * @param {Element} el
  898. * @param {Vue} vm
  899. * @param {Function} [cb]
  900. */
  901. function removeWithTransition(el, vm, cb) {
  902. applyTransition(el, -1, function () {
  903. remove(el);
  904. }, vm, cb);
  905. }
  906. /**
  907. * Apply transitions with an operation callback.
  908. *
  909. * @param {Element} el
  910. * @param {Number} direction
  911. * 1: enter
  912. * -1: leave
  913. * @param {Function} op - the actual DOM operation
  914. * @param {Vue} vm
  915. * @param {Function} [cb]
  916. */
  917. function applyTransition(el, direction, op, vm, cb) {
  918. var transition = el.__v_trans;
  919. if (!transition ||
  920. // skip if there are no js hooks and CSS transition is
  921. // not supported
  922. !transition.hooks && !transitionEndEvent ||
  923. // skip transitions for initial compile
  924. !vm._isCompiled ||
  925. // if the vm is being manipulated by a parent directive
  926. // during the parent's compilation phase, skip the
  927. // animation.
  928. vm.$parent && !vm.$parent._isCompiled) {
  929. op();
  930. if (cb) cb();
  931. return;
  932. }
  933. var action = direction > 0 ? 'enter' : 'leave';
  934. transition[action](op, cb);
  935. }
  936. /**
  937. * Query an element selector if it's not an element already.
  938. *
  939. * @param {String|Element} el
  940. * @return {Element}
  941. */
  942. function query(el) {
  943. if (typeof el === 'string') {
  944. var selector = el;
  945. el = document.querySelector(el);
  946. if (!el) {
  947. 'development' !== 'production' && warn('Cannot find element: ' + selector);
  948. }
  949. }
  950. return el;
  951. }
  952. /**
  953. * Check if a node is in the document.
  954. * Note: document.documentElement.contains should work here
  955. * but always returns false for comment nodes in phantomjs,
  956. * making unit tests difficult. This is fixed by doing the
  957. * contains() check on the node's parentNode instead of
  958. * the node itself.
  959. *
  960. * @param {Node} node
  961. * @return {Boolean}
  962. */
  963. function inDoc(node) {
  964. var doc = document.documentElement;
  965. var parent = node && node.parentNode;
  966. return doc === node || doc === parent || !!(parent && parent.nodeType === 1 && doc.contains(parent));
  967. }
  968. /**
  969. * Get and remove an attribute from a node.
  970. *
  971. * @param {Node} node
  972. * @param {String} _attr
  973. */
  974. function getAttr(node, _attr) {
  975. var val = node.getAttribute(_attr);
  976. if (val !== null) {
  977. node.removeAttribute(_attr);
  978. }
  979. return val;
  980. }
  981. /**
  982. * Get an attribute with colon or v-bind: prefix.
  983. *
  984. * @param {Node} node
  985. * @param {String} name
  986. * @return {String|null}
  987. */
  988. function getBindAttr(node, name) {
  989. var val = getAttr(node, ':' + name);
  990. if (val === null) {
  991. val = getAttr(node, 'v-bind:' + name);
  992. }
  993. return val;
  994. }
  995. /**
  996. * Insert el before target
  997. *
  998. * @param {Element} el
  999. * @param {Element} target
  1000. */
  1001. function before(el, target) {
  1002. target.parentNode.insertBefore(el, target);
  1003. }
  1004. /**
  1005. * Insert el after target
  1006. *
  1007. * @param {Element} el
  1008. * @param {Element} target
  1009. */
  1010. function after(el, target) {
  1011. if (target.nextSibling) {
  1012. before(el, target.nextSibling);
  1013. } else {
  1014. target.parentNode.appendChild(el);
  1015. }
  1016. }
  1017. /**
  1018. * Remove el from DOM
  1019. *
  1020. * @param {Element} el
  1021. */
  1022. function remove(el) {
  1023. el.parentNode.removeChild(el);
  1024. }
  1025. /**
  1026. * Prepend el to target
  1027. *
  1028. * @param {Element} el
  1029. * @param {Element} target
  1030. */
  1031. function prepend(el, target) {
  1032. if (target.firstChild) {
  1033. before(el, target.firstChild);
  1034. } else {
  1035. target.appendChild(el);
  1036. }
  1037. }
  1038. /**
  1039. * Replace target with el
  1040. *
  1041. * @param {Element} target
  1042. * @param {Element} el
  1043. */
  1044. function replace(target, el) {
  1045. var parent = target.parentNode;
  1046. if (parent) {
  1047. parent.replaceChild(el, target);
  1048. }
  1049. }
  1050. /**
  1051. * Add event listener shorthand.
  1052. *
  1053. * @param {Element} el
  1054. * @param {String} event
  1055. * @param {Function} cb
  1056. */
  1057. function on$1(el, event, cb) {
  1058. el.addEventListener(event, cb);
  1059. }
  1060. /**
  1061. * Remove event listener shorthand.
  1062. *
  1063. * @param {Element} el
  1064. * @param {String} event
  1065. * @param {Function} cb
  1066. */
  1067. function off(el, event, cb) {
  1068. el.removeEventListener(event, cb);
  1069. }
  1070. /**
  1071. * Add class with compatibility for IE & SVG
  1072. *
  1073. * @param {Element} el
  1074. * @param {Strong} cls
  1075. */
  1076. function addClass(el, cls) {
  1077. if (el.classList) {
  1078. el.classList.add(cls);
  1079. } else {
  1080. var cur = ' ' + (el.getAttribute('class') || '') + ' ';
  1081. if (cur.indexOf(' ' + cls + ' ') < 0) {
  1082. el.setAttribute('class', (cur + cls).trim());
  1083. }
  1084. }
  1085. }
  1086. /**
  1087. * Remove class with compatibility for IE & SVG
  1088. *
  1089. * @param {Element} el
  1090. * @param {Strong} cls
  1091. */
  1092. function removeClass(el, cls) {
  1093. if (el.classList) {
  1094. el.classList.remove(cls);
  1095. } else {
  1096. var cur = ' ' + (el.getAttribute('class') || '') + ' ';
  1097. var tar = ' ' + cls + ' ';
  1098. while (cur.indexOf(tar) >= 0) {
  1099. cur = cur.replace(tar, ' ');
  1100. }
  1101. el.setAttribute('class', cur.trim());
  1102. }
  1103. if (!el.className) {
  1104. el.removeAttribute('class');
  1105. }
  1106. }
  1107. /**
  1108. * Extract raw content inside an element into a temporary
  1109. * container div
  1110. *
  1111. * @param {Element} el
  1112. * @param {Boolean} asFragment
  1113. * @return {Element}
  1114. */
  1115. function extractContent(el, asFragment) {
  1116. var child;
  1117. var rawContent;
  1118. /* istanbul ignore if */
  1119. if (isTemplate(el) && el.content instanceof DocumentFragment) {
  1120. el = el.content;
  1121. }
  1122. if (el.hasChildNodes()) {
  1123. trimNode(el);
  1124. rawContent = asFragment ? document.createDocumentFragment() : document.createElement('div');
  1125. /* eslint-disable no-cond-assign */
  1126. while (child = el.firstChild) {
  1127. /* eslint-enable no-cond-assign */
  1128. rawContent.appendChild(child);
  1129. }
  1130. }
  1131. return rawContent;
  1132. }
  1133. /**
  1134. * Trim possible empty head/tail textNodes inside a parent.
  1135. *
  1136. * @param {Node} node
  1137. */
  1138. function trimNode(node) {
  1139. trim(node, node.firstChild);
  1140. trim(node, node.lastChild);
  1141. }
  1142. function trim(parent, node) {
  1143. if (node && node.nodeType === 3 && !node.data.trim()) {
  1144. parent.removeChild(node);
  1145. }
  1146. }
  1147. /**
  1148. * Check if an element is a template tag.
  1149. * Note if the template appears inside an SVG its tagName
  1150. * will be in lowercase.
  1151. *
  1152. * @param {Element} el
  1153. */
  1154. function isTemplate(el) {
  1155. return el.tagName && el.tagName.toLowerCase() === 'template';
  1156. }
  1157. /**
  1158. * Create an "anchor" for performing dom insertion/removals.
  1159. * This is used in a number of scenarios:
  1160. * - fragment instance
  1161. * - v-html
  1162. * - v-if
  1163. * - v-for
  1164. * - component
  1165. *
  1166. * @param {String} content
  1167. * @param {Boolean} persist - IE trashes empty textNodes on
  1168. * cloneNode(true), so in certain
  1169. * cases the anchor needs to be
  1170. * non-empty to be persisted in
  1171. * templates.
  1172. * @return {Comment|Text}
  1173. */
  1174. function createAnchor(content, persist) {
  1175. var anchor = config.debug ? document.createComment(content) : document.createTextNode(persist ? ' ' : '');
  1176. anchor.__vue_anchor = true;
  1177. return anchor;
  1178. }
  1179. /**
  1180. * Find a component ref attribute that starts with $.
  1181. *
  1182. * @param {Element} node
  1183. * @return {String|undefined}
  1184. */
  1185. var refRE = /^v-ref:/;
  1186. function findRef(node) {
  1187. if (node.hasAttributes()) {
  1188. var attrs = node.attributes;
  1189. for (var i = 0, l = attrs.length; i < l; i++) {
  1190. var name = attrs[i].name;
  1191. if (refRE.test(name)) {
  1192. return camelize(name.replace(refRE, ''));
  1193. }
  1194. }
  1195. }
  1196. }
  1197. /**
  1198. * Map a function to a range of nodes .
  1199. *
  1200. * @param {Node} node
  1201. * @param {Node} end
  1202. * @param {Function} op
  1203. */
  1204. function mapNodeRange(node, end, op) {
  1205. var next;
  1206. while (node !== end) {
  1207. next = node.nextSibling;
  1208. op(node);
  1209. node = next;
  1210. }
  1211. op(end);
  1212. }
  1213. /**
  1214. * Remove a range of nodes with transition, store
  1215. * the nodes in a fragment with correct ordering,
  1216. * and call callback when done.
  1217. *
  1218. * @param {Node} start
  1219. * @param {Node} end
  1220. * @param {Vue} vm
  1221. * @param {DocumentFragment} frag
  1222. * @param {Function} cb
  1223. */
  1224. function removeNodeRange(start, end, vm, frag, cb) {
  1225. var done = false;
  1226. var removed = 0;
  1227. var nodes = [];
  1228. mapNodeRange(start, end, function (node) {
  1229. if (node === end) done = true;
  1230. nodes.push(node);
  1231. removeWithTransition(node, vm, onRemoved);
  1232. });
  1233. function onRemoved() {
  1234. removed++;
  1235. if (done && removed >= nodes.length) {
  1236. for (var i = 0; i < nodes.length; i++) {
  1237. frag.appendChild(nodes[i]);
  1238. }
  1239. cb && cb();
  1240. }
  1241. }
  1242. }
  1243. var commonTagRE = /^(div|p|span|img|a|b|i|br|ul|ol|li|h1|h2|h3|h4|h5|h6|code|pre|table|th|td|tr|form|label|input|select|option|nav|article|section|header|footer)$/;
  1244. /**
  1245. * Check if an element is a component, if yes return its
  1246. * component id.
  1247. *
  1248. * @param {Element} el
  1249. * @param {Object} options
  1250. * @return {Object|undefined}
  1251. */
  1252. function checkComponentAttr(el, options) {
  1253. var tag = el.tagName.toLowerCase();
  1254. var hasAttrs = el.hasAttributes();
  1255. if (!commonTagRE.test(tag) && tag !== 'component') {
  1256. if (resolveAsset(options, 'components', tag)) {
  1257. return { id: tag };
  1258. } else {
  1259. var is = hasAttrs && getIsBinding(el);
  1260. if (is) {
  1261. return is;
  1262. } else if ('development' !== 'production') {
  1263. if (tag.indexOf('-') > -1 || /HTMLUnknownElement/.test(el.toString()) &&
  1264. // Chrome returns unknown for several HTML5 elements.
  1265. // https://code.google.com/p/chromium/issues/detail?id=540526
  1266. !/^(data|time|rtc|rb)$/.test(tag)) {
  1267. warn('Unknown custom element: <' + tag + '> - did you ' + 'register the component correctly?');
  1268. }
  1269. }
  1270. }
  1271. } else if (hasAttrs) {
  1272. return getIsBinding(el);
  1273. }
  1274. }
  1275. /**
  1276. * Get "is" binding from an element.
  1277. *
  1278. * @param {Element} el
  1279. * @return {Object|undefined}
  1280. */
  1281. function getIsBinding(el) {
  1282. // dynamic syntax
  1283. var exp = getAttr(el, 'is');
  1284. if (exp != null) {
  1285. return { id: exp };
  1286. } else {
  1287. exp = getBindAttr(el, 'is');
  1288. if (exp != null) {
  1289. return { id: exp, dynamic: true };
  1290. }
  1291. }
  1292. }
  1293. /**
  1294. * Set a prop's initial value on a vm and its data object.
  1295. *
  1296. * @param {Vue} vm
  1297. * @param {Object} prop
  1298. * @param {*} value
  1299. */
  1300. function initProp(vm, prop, value) {
  1301. var key = prop.path;
  1302. vm[key] = vm._data[key] = assertProp(prop, value) ? value : undefined;
  1303. }
  1304. /**
  1305. * Assert whether a prop is valid.
  1306. *
  1307. * @param {Object} prop
  1308. * @param {*} value
  1309. */
  1310. function assertProp(prop, value) {
  1311. // if a prop is not provided and is not required,
  1312. // skip the check.
  1313. if (prop.raw === null && !prop.required) {
  1314. return true;
  1315. }
  1316. var options = prop.options;
  1317. var type = options.type;
  1318. var valid = true;
  1319. var expectedType;
  1320. if (type) {
  1321. if (type === String) {
  1322. expectedType = 'string';
  1323. valid = typeof value === expectedType;
  1324. } else if (type === Number) {
  1325. expectedType = 'number';
  1326. valid = typeof value === 'number';
  1327. } else if (type === Boolean) {
  1328. expectedType = 'boolean';
  1329. valid = typeof value === 'boolean';
  1330. } else if (type === Function) {
  1331. expectedType = 'function';
  1332. valid = typeof value === 'function';
  1333. } else if (type === Object) {
  1334. expectedType = 'object';
  1335. valid = isPlainObject(value);
  1336. } else if (type === Array) {
  1337. expectedType = 'array';
  1338. valid = isArray(value);
  1339. } else {
  1340. valid = value instanceof type;
  1341. }
  1342. }
  1343. if (!valid) {
  1344. 'development' !== 'production' && warn('Invalid prop: type check failed for ' + prop.path + '="' + prop.raw + '".' + ' Expected ' + formatType(expectedType) + ', got ' + formatValue(value) + '.');
  1345. return false;
  1346. }
  1347. var validator = options.validator;
  1348. if (validator) {
  1349. if (!validator.call(null, value)) {
  1350. 'development' !== 'production' && warn('Invalid prop: custom validator check failed for ' + prop.path + '="' + prop.raw + '"');
  1351. return false;
  1352. }
  1353. }
  1354. return true;
  1355. }
  1356. function formatType(val) {
  1357. return val ? val.charAt(0).toUpperCase() + val.slice(1) : 'custom type';
  1358. }
  1359. function formatValue(val) {
  1360. return Object.prototype.toString.call(val).slice(8, -1);
  1361. }
  1362. /**
  1363. * Option overwriting strategies are functions that handle
  1364. * how to merge a parent option value and a child option
  1365. * value into the final value.
  1366. *
  1367. * All strategy functions follow the same signature:
  1368. *
  1369. * @param {*} parentVal
  1370. * @param {*} childVal
  1371. * @param {Vue} [vm]
  1372. */
  1373. var strats = config.optionMergeStrategies = Object.create(null);
  1374. /**
  1375. * Helper that recursively merges two data objects together.
  1376. */
  1377. function mergeData(to, from) {
  1378. var key, toVal, fromVal;
  1379. for (key in from) {
  1380. toVal = to[key];
  1381. fromVal = from[key];
  1382. if (!hasOwn(to, key)) {
  1383. set(to, key, fromVal);
  1384. } else if (isObject(toVal) && isObject(fromVal)) {
  1385. mergeData(toVal, fromVal);
  1386. }
  1387. }
  1388. return to;
  1389. }
  1390. /**
  1391. * Data
  1392. */
  1393. strats.data = function (parentVal, childVal, vm) {
  1394. if (!vm) {
  1395. // in a Vue.extend merge, both should be functions
  1396. if (!childVal) {
  1397. return parentVal;
  1398. }
  1399. if (typeof childVal !== 'function') {
  1400. 'development' !== 'production' && warn('The "data" option should be a function ' + 'that returns a per-instance value in component ' + 'definitions.');
  1401. return parentVal;
  1402. }
  1403. if (!parentVal) {
  1404. return childVal;
  1405. }
  1406. // when parentVal & childVal are both present,
  1407. // we need to return a function that returns the
  1408. // merged result of both functions... no need to
  1409. // check if parentVal is a function here because
  1410. // it has to be a function to pass previous merges.
  1411. return function mergedDataFn() {
  1412. return mergeData(childVal.call(this), parentVal.call(this));
  1413. };
  1414. } else if (parentVal || childVal) {
  1415. return function mergedInstanceDataFn() {
  1416. // instance merge
  1417. var instanceData = typeof childVal === 'function' ? childVal.call(vm) : childVal;
  1418. var defaultData = typeof parentVal === 'function' ? parentVal.call(vm) : undefined;
  1419. if (instanceData) {
  1420. return mergeData(instanceData, defaultData);
  1421. } else {
  1422. return defaultData;
  1423. }
  1424. };
  1425. }
  1426. };
  1427. /**
  1428. * El
  1429. */
  1430. strats.el = function (parentVal, childVal, vm) {
  1431. if (!vm && childVal && typeof childVal !== 'function') {
  1432. 'development' !== 'production' && warn('The "el" option should be a function ' + 'that returns a per-instance value in component ' + 'definitions.');
  1433. return;
  1434. }
  1435. var ret = childVal || parentVal;
  1436. // invoke the element factory if this is instance merge
  1437. return vm && typeof ret === 'function' ? ret.call(vm) : ret;
  1438. };
  1439. /**
  1440. * Hooks and param attributes are merged as arrays.
  1441. */
  1442. strats.init = strats.created = strats.ready = strats.attached = strats.detached = strats.beforeCompile = strats.compiled = strats.beforeDestroy = strats.destroyed = function (parentVal, childVal) {
  1443. return childVal ? parentVal ? parentVal.concat(childVal) : isArray(childVal) ? childVal : [childVal] : parentVal;
  1444. };
  1445. /**
  1446. * 0.11 deprecation warning
  1447. */
  1448. strats.paramAttributes = function () {
  1449. /* istanbul ignore next */
  1450. 'development' !== 'production' && warn('"paramAttributes" option has been deprecated in 0.12. ' + 'Use "props" instead.');
  1451. };
  1452. /**
  1453. * Assets
  1454. *
  1455. * When a vm is present (instance creation), we need to do
  1456. * a three-way merge between constructor options, instance
  1457. * options and parent options.
  1458. */
  1459. function mergeAssets(parentVal, childVal) {
  1460. var res = Object.create(parentVal);
  1461. return childVal ? extend(res, guardArrayAssets(childVal)) : res;
  1462. }
  1463. config._assetTypes.forEach(function (type) {
  1464. strats[type + 's'] = mergeAssets;
  1465. });
  1466. /**
  1467. * Events & Watchers.
  1468. *
  1469. * Events & watchers hashes should not overwrite one
  1470. * another, so we merge them as arrays.
  1471. */
  1472. strats.watch = strats.events = function (parentVal, childVal) {
  1473. if (!childVal) return parentVal;
  1474. if (!parentVal) return childVal;
  1475. var ret = {};
  1476. extend(ret, parentVal);
  1477. for (var key in childVal) {
  1478. var parent = ret[key];
  1479. var child = childVal[key];
  1480. if (parent && !isArray(parent)) {
  1481. parent = [parent];
  1482. }
  1483. ret[key] = parent ? parent.concat(child) : [child];
  1484. }
  1485. return ret;
  1486. };
  1487. /**
  1488. * Other object hashes.
  1489. */
  1490. strats.props = strats.methods = strats.computed = function (parentVal, childVal) {
  1491. if (!childVal) return parentVal;
  1492. if (!parentVal) return childVal;
  1493. var ret = Object.create(null);
  1494. extend(ret, parentVal);
  1495. extend(ret, childVal);
  1496. return ret;
  1497. };
  1498. /**
  1499. * Default strategy.
  1500. */
  1501. var defaultStrat = function defaultStrat(parentVal, childVal) {
  1502. return childVal === undefined ? parentVal : childVal;
  1503. };
  1504. /**
  1505. * Make sure component options get converted to actual
  1506. * constructors.
  1507. *
  1508. * @param {Object} options
  1509. */
  1510. function guardComponents(options) {
  1511. if (options.components) {
  1512. var components = options.components = guardArrayAssets(options.components);
  1513. var def;
  1514. var ids = Object.keys(components);
  1515. for (var i = 0, l = ids.length; i < l; i++) {
  1516. var key = ids[i];
  1517. if (commonTagRE.test(key)) {
  1518. 'development' !== 'production' && warn('Do not use built-in HTML elements as component ' + 'id: ' + key);
  1519. continue;
  1520. }
  1521. def = components[key];
  1522. if (isPlainObject(def)) {
  1523. components[key] = Vue.extend(def);
  1524. }
  1525. }
  1526. }
  1527. }
  1528. /**
  1529. * Ensure all props option syntax are normalized into the
  1530. * Object-based format.
  1531. *
  1532. * @param {Object} options
  1533. */
  1534. function guardProps(options) {
  1535. var props = options.props;
  1536. var i, val;
  1537. if (isArray(props)) {
  1538. options.props = {};
  1539. i = props.length;
  1540. while (i--) {
  1541. val = props[i];
  1542. if (typeof val === 'string') {
  1543. options.props[val] = null;
  1544. } else if (val.name) {
  1545. options.props[val.name] = val;
  1546. }
  1547. }
  1548. } else if (isPlainObject(props)) {
  1549. var keys = Object.keys(props);
  1550. i = keys.length;
  1551. while (i--) {
  1552. val = props[keys[i]];
  1553. if (typeof val === 'function') {
  1554. props[keys[i]] = { type: val };
  1555. }
  1556. }
  1557. }
  1558. }
  1559. /**
  1560. * Guard an Array-format assets option and converted it
  1561. * into the key-value Object format.
  1562. *
  1563. * @param {Object|Array} assets
  1564. * @return {Object}
  1565. */
  1566. function guardArrayAssets(assets) {
  1567. if (isArray(assets)) {
  1568. var res = {};
  1569. var i = assets.length;
  1570. var asset;
  1571. while (i--) {
  1572. asset = assets[i];
  1573. var id = typeof asset === 'function' ? asset.options && asset.options.name || asset.id : asset.name || asset.id;
  1574. if (!id) {
  1575. 'development' !== 'production' && warn('Array-syntax assets must provide a "name" or "id" field.');
  1576. } else {
  1577. res[id] = asset;
  1578. }
  1579. }
  1580. return res;
  1581. }
  1582. return assets;
  1583. }
  1584. /**
  1585. * Merge two option objects into a new one.
  1586. * Core utility used in both instantiation and inheritance.
  1587. *
  1588. * @param {Object} parent
  1589. * @param {Object} child
  1590. * @param {Vue} [vm] - if vm is present, indicates this is
  1591. * an instantiation merge.
  1592. */
  1593. function mergeOptions(parent, child, vm) {
  1594. guardComponents(child);
  1595. guardProps(child);
  1596. var options = {};
  1597. var key;
  1598. if (child.mixins) {
  1599. for (var i = 0, l = child.mixins.length; i < l; i++) {
  1600. parent = mergeOptions(parent, child.mixins[i], vm);
  1601. }
  1602. }
  1603. for (key in parent) {
  1604. mergeField(key);
  1605. }
  1606. for (key in child) {
  1607. if (!hasOwn(parent, key)) {
  1608. mergeField(key);
  1609. }
  1610. }
  1611. function mergeField(key) {
  1612. var strat = strats[key] || defaultStrat;
  1613. options[key] = strat(parent[key], child[key], vm, key);
  1614. }
  1615. return options;
  1616. }
  1617. /**
  1618. * Resolve an asset.
  1619. * This function is used because child instances need access
  1620. * to assets defined in its ancestor chain.
  1621. *
  1622. * @param {Object} options
  1623. * @param {String} type
  1624. * @param {String} id
  1625. * @return {Object|Function}
  1626. */
  1627. function resolveAsset(options, type, id) {
  1628. var assets = options[type];
  1629. var camelizedId;
  1630. return assets[id] ||
  1631. // camelCase ID
  1632. assets[camelizedId = camelize(id)] ||
  1633. // Pascal Case ID
  1634. assets[camelizedId.charAt(0).toUpperCase() + camelizedId.slice(1)];
  1635. }
  1636. /**
  1637. * Assert asset exists
  1638. */
  1639. function assertAsset(val, type, id) {
  1640. if (!val) {
  1641. 'development' !== 'production' && warn('Failed to resolve ' + type + ': ' + id);
  1642. }
  1643. }
  1644. var arrayProto = Array.prototype;
  1645. var arrayMethods = Object.create(arrayProto)
  1646. /**
  1647. * Intercept mutating methods and emit events
  1648. */
  1649. ;['push', 'pop', 'shift', 'unshift', 'splice', 'sort', 'reverse'].forEach(function (method) {
  1650. // cache original method
  1651. var original = arrayProto[method];
  1652. def(arrayMethods, method, function mutator() {
  1653. // avoid leaking arguments:
  1654. // http://jsperf.com/closure-with-arguments
  1655. var i = arguments.length;
  1656. var args = new Array(i);
  1657. while (i--) {
  1658. args[i] = arguments[i];
  1659. }
  1660. var result = original.apply(this, args);
  1661. var ob = this.__ob__;
  1662. var inserted;
  1663. switch (method) {
  1664. case 'push':
  1665. inserted = args;
  1666. break;
  1667. case 'unshift':
  1668. inserted = args;
  1669. break;
  1670. case 'splice':
  1671. inserted = args.slice(2);
  1672. break;
  1673. }
  1674. if (inserted) ob.observeArray(inserted);
  1675. // notify change
  1676. ob.dep.notify();
  1677. return result;
  1678. });
  1679. });
  1680. /**
  1681. * Swap the element at the given index with a new value
  1682. * and emits corresponding event.
  1683. *
  1684. * @param {Number} index
  1685. * @param {*} val
  1686. * @return {*} - replaced element
  1687. */
  1688. def(arrayProto, '$set', function $set(index, val) {
  1689. if (index >= this.length) {
  1690. this.length = index + 1;
  1691. }
  1692. return this.splice(index, 1, val)[0];
  1693. });
  1694. /**
  1695. * Convenience method to remove the element at given index.
  1696. *
  1697. * @param {Number} index
  1698. * @param {*} val
  1699. */
  1700. def(arrayProto, '$remove', function $remove(item) {
  1701. /* istanbul ignore if */
  1702. if (!this.length) return;
  1703. var index = indexOf(this, item);
  1704. if (index > -1) {
  1705. return this.splice(index, 1);
  1706. }
  1707. });
  1708. var uid$3 = 0;
  1709. /**
  1710. * A dep is an observable that can have multiple
  1711. * directives subscribing to it.
  1712. *
  1713. * @constructor
  1714. */
  1715. function Dep() {
  1716. this.id = uid$3++;
  1717. this.subs = [];
  1718. }
  1719. // the current target watcher being evaluated.
  1720. // this is globally unique because there could be only one
  1721. // watcher being evaluated at any time.
  1722. Dep.target = null;
  1723. /**
  1724. * Add a directive subscriber.
  1725. *
  1726. * @param {Directive} sub
  1727. */
  1728. Dep.prototype.addSub = function (sub) {
  1729. this.subs.push(sub);
  1730. };
  1731. /**
  1732. * Remove a directive subscriber.
  1733. *
  1734. * @param {Directive} sub
  1735. */
  1736. Dep.prototype.removeSub = function (sub) {
  1737. this.subs.$remove(sub);
  1738. };
  1739. /**
  1740. * Add self as a dependency to the target watcher.
  1741. */
  1742. Dep.prototype.depend = function () {
  1743. Dep.target.addDep(this);
  1744. };
  1745. /**
  1746. * Notify all subscribers of a new value.
  1747. */
  1748. Dep.prototype.notify = function () {
  1749. // stablize the subscriber list first
  1750. var subs = toArray(this.subs);
  1751. for (var i = 0, l = subs.length; i < l; i++) {
  1752. subs[i].update();
  1753. }
  1754. };
  1755. var arrayKeys = Object.getOwnPropertyNames(arrayMethods);
  1756. /**
  1757. * Observer class that are attached to each observed
  1758. * object. Once attached, the observer converts target
  1759. * object's property keys into getter/setters that
  1760. * collect dependencies and dispatches updates.
  1761. *
  1762. * @param {Array|Object} value
  1763. * @constructor
  1764. */
  1765. function Observer(value) {
  1766. this.value = value;
  1767. this.dep = new Dep();
  1768. def(value, '__ob__', this);
  1769. if (isArray(value)) {
  1770. var augment = hasProto ? protoAugment : copyAugment;
  1771. augment(value, arrayMethods, arrayKeys);
  1772. this.observeArray(value);
  1773. } else {
  1774. this.walk(value);
  1775. }
  1776. }
  1777. // Instance methods
  1778. /**
  1779. * Walk through each property and convert them into
  1780. * getter/setters. This method should only be called when
  1781. * value type is Object.
  1782. *
  1783. * @param {Object} obj
  1784. */
  1785. Observer.prototype.walk = function (obj) {
  1786. var keys = Object.keys(obj);
  1787. var i = keys.length;
  1788. while (i--) {
  1789. this.convert(keys[i], obj[keys[i]]);
  1790. }
  1791. };
  1792. /**
  1793. * Observe a list of Array items.
  1794. *
  1795. * @param {Array} items
  1796. */
  1797. Observer.prototype.observeArray = function (items) {
  1798. var i = items.length;
  1799. while (i--) {
  1800. observe(items[i]);
  1801. }
  1802. };
  1803. /**
  1804. * Convert a property into getter/setter so we can emit
  1805. * the events when the property is accessed/changed.
  1806. *
  1807. * @param {String} key
  1808. * @param {*} val
  1809. */
  1810. Observer.prototype.convert = function (key, val) {
  1811. defineReactive(this.value, key, val);
  1812. };
  1813. /**
  1814. * Add an owner vm, so that when $set/$delete mutations
  1815. * happen we can notify owner vms to proxy the keys and
  1816. * digest the watchers. This is only called when the object
  1817. * is observed as an instance's root $data.
  1818. *
  1819. * @param {Vue} vm
  1820. */
  1821. Observer.prototype.addVm = function (vm) {
  1822. (this.vms || (this.vms = [])).push(vm);
  1823. };
  1824. /**
  1825. * Remove an owner vm. This is called when the object is
  1826. * swapped out as an instance's $data object.
  1827. *
  1828. * @param {Vue} vm
  1829. */
  1830. Observer.prototype.removeVm = function (vm) {
  1831. this.vms.$remove(vm);
  1832. };
  1833. // helpers
  1834. /**
  1835. * Augment an target Object or Array by intercepting
  1836. * the prototype chain using __proto__
  1837. *
  1838. * @param {Object|Array} target
  1839. * @param {Object} proto
  1840. */
  1841. function protoAugment(target, src) {
  1842. target.__proto__ = src;
  1843. }
  1844. /**
  1845. * Augment an target Object or Array by defining
  1846. * hidden properties.
  1847. *
  1848. * @param {Object|Array} target
  1849. * @param {Object} proto
  1850. */
  1851. function copyAugment(target, src, keys) {
  1852. var i = keys.length;
  1853. var key;
  1854. while (i--) {
  1855. key = keys[i];
  1856. def(target, key, src[key]);
  1857. }
  1858. }
  1859. /**
  1860. * Attempt to create an observer instance for a value,
  1861. * returns the new observer if successfully observed,
  1862. * or the existing observer if the value already has one.
  1863. *
  1864. * @param {*} value
  1865. * @param {Vue} [vm]
  1866. * @return {Observer|undefined}
  1867. * @static
  1868. */
  1869. function observe(value, vm) {
  1870. if (!value || typeof value !== 'object') {
  1871. return;
  1872. }
  1873. var ob;
  1874. if (hasOwn(value, '__ob__') && value.__ob__ instanceof Observer) {
  1875. ob = value.__ob__;
  1876. } else if ((isArray(value) || isPlainObject(value)) && !Object.isFrozen(value) && !value._isVue) {
  1877. ob = new Observer(value);
  1878. }
  1879. if (ob && vm) {
  1880. ob.addVm(vm);
  1881. }
  1882. return ob;
  1883. }
  1884. /**
  1885. * Define a reactive property on an Object.
  1886. *
  1887. * @param {Object} obj
  1888. * @param {String} key
  1889. * @param {*} val
  1890. */
  1891. function defineReactive(obj, key, val) {
  1892. var dep = new Dep();
  1893. // cater for pre-defined getter/setters
  1894. var getter, setter;
  1895. if (config.convertAllProperties) {
  1896. var property = Object.getOwnPropertyDescriptor(obj, key);
  1897. if (property && property.configurable === false) {
  1898. return;
  1899. }
  1900. getter = property && property.get;
  1901. setter = property && property.set;
  1902. }
  1903. var childOb = observe(val);
  1904. Object.defineProperty(obj, key, {
  1905. enumerable: true,
  1906. configurable: true,
  1907. get: function reactiveGetter() {
  1908. var value = getter ? getter.call(obj) : val;
  1909. if (Dep.target) {
  1910. dep.depend();
  1911. if (childOb) {
  1912. childOb.dep.depend();
  1913. }
  1914. if (isArray(value)) {
  1915. for (var e, i = 0, l = value.length; i < l; i++) {
  1916. e = value[i];
  1917. e && e.__ob__ && e.__ob__.dep.depend();
  1918. }
  1919. }
  1920. }
  1921. return value;
  1922. },
  1923. set: function reactiveSetter(newVal) {
  1924. var value = getter ? getter.call(obj) : val;
  1925. if (newVal === value) {
  1926. return;
  1927. }
  1928. if (setter) {
  1929. setter.call(obj, newVal);
  1930. } else {
  1931. val = newVal;
  1932. }
  1933. childOb = observe(newVal);
  1934. dep.notify();
  1935. }
  1936. });
  1937. }
  1938. var util = Object.freeze({
  1939. defineReactive: defineReactive,
  1940. set: set,
  1941. del: del,
  1942. hasOwn: hasOwn,
  1943. isLiteral: isLiteral,
  1944. isReserved: isReserved,
  1945. _toString: _toString,
  1946. toNumber: toNumber,
  1947. toBoolean: toBoolean,
  1948. stripQuotes: stripQuotes,
  1949. camelize: camelize,
  1950. hyphenate: hyphenate,
  1951. classify: classify,
  1952. bind: bind$1,
  1953. toArray: toArray,
  1954. extend: extend,
  1955. isObject: isObject,
  1956. isPlainObject: isPlainObject,
  1957. def: def,
  1958. debounce: _debounce,
  1959. indexOf: indexOf,
  1960. cancellable: cancellable,
  1961. looseEqual: looseEqual,
  1962. isArray: isArray,
  1963. hasProto: hasProto,
  1964. inBrowser: inBrowser,
  1965. isIE9: isIE9,
  1966. isAndroid: isAndroid,
  1967. get transitionProp () { return transitionProp; },
  1968. get transitionEndEvent () { return transitionEndEvent; },
  1969. get animationProp () { return animationProp; },
  1970. get animationEndEvent () { return animationEndEvent; },
  1971. nextTick: nextTick,
  1972. query: query,
  1973. inDoc: inDoc,
  1974. getAttr: getAttr,
  1975. getBindAttr: getBindAttr,
  1976. before: before,
  1977. after: after,
  1978. remove: remove,
  1979. prepend: prepend,
  1980. replace: replace,
  1981. on: on$1,
  1982. off: off,
  1983. addClass: addClass,
  1984. removeClass: removeClass,
  1985. extractContent: extractContent,
  1986. trimNode: trimNode,
  1987. isTemplate: isTemplate,
  1988. createAnchor: createAnchor,
  1989. findRef: findRef,
  1990. mapNodeRange: mapNodeRange,
  1991. removeNodeRange: removeNodeRange,
  1992. mergeOptions: mergeOptions,
  1993. resolveAsset: resolveAsset,
  1994. assertAsset: assertAsset,
  1995. checkComponentAttr: checkComponentAttr,
  1996. initProp: initProp,
  1997. assertProp: assertProp,
  1998. commonTagRE: commonTagRE,
  1999. get warn () { return warn; }
  2000. });
  2001. var uid = 0;
  2002. function initMixin (Vue) {
  2003. /**
  2004. * The main init sequence. This is called for every
  2005. * instance, including ones that are created from extended
  2006. * constructors.
  2007. *
  2008. * @param {Object} options - this options object should be
  2009. * the result of merging class
  2010. * options and the options passed
  2011. * in to the constructor.
  2012. */
  2013. Vue.prototype._init = function (options) {
  2014. options = options || {};
  2015. this.$el = null;
  2016. this.$parent = options.parent;
  2017. this.$root = this.$parent ? this.$parent.$root : this;
  2018. this.$children = [];
  2019. this.$refs = {}; // child vm references
  2020. this.$els = {}; // element references
  2021. this._watchers = []; // all watchers as an array
  2022. this._directives = []; // all directives
  2023. // a uid
  2024. this._uid = uid++;
  2025. // a flag to avoid this being observed
  2026. this._isVue = true;
  2027. // events bookkeeping
  2028. this._events = {}; // registered callbacks
  2029. this._eventsCount = {}; // for $broadcast optimization
  2030. // fragment instance properties
  2031. this._isFragment = false;
  2032. this._fragment = // @type {DocumentFragment}
  2033. this._fragmentStart = // @type {Text|Comment}
  2034. this._fragmentEnd = null; // @type {Text|Comment}
  2035. // lifecycle state
  2036. this._isCompiled = this._isDestroyed = this._isReady = this._isAttached = this._isBeingDestroyed = false;
  2037. this._unlinkFn = null;
  2038. // context:
  2039. // if this is a transcluded component, context
  2040. // will be the common parent vm of this instance
  2041. // and its host.
  2042. this._context = options._context || this.$parent;
  2043. // scope:
  2044. // if this is inside an inline v-for, the scope
  2045. // will be the intermediate scope created for this
  2046. // repeat fragment. this is used for linking props
  2047. // and container directives.
  2048. this._scope = options._scope;
  2049. // fragment:
  2050. // if this instance is compiled inside a Fragment, it
  2051. // needs to reigster itself as a child of that fragment
  2052. // for attach/detach to work properly.
  2053. this._frag = options._frag;
  2054. if (this._frag) {
  2055. this._frag.children.push(this);
  2056. }
  2057. // push self into parent / transclusion host
  2058. if (this.$parent) {
  2059. this.$parent.$children.push(this);
  2060. }
  2061. // merge options.
  2062. options = this.$options = mergeOptions(this.constructor.options, options, this);
  2063. // set ref
  2064. this._updateRef();
  2065. // initialize data as empty object.
  2066. // it will be filled up in _initScope().
  2067. this._data = {};
  2068. // call init hook
  2069. this._callHook('init');
  2070. // initialize data observation and scope inheritance.
  2071. this._initState();
  2072. // setup event system and option events.
  2073. this._initEvents();
  2074. // call created hook
  2075. this._callHook('created');
  2076. // if `el` option is passed, start compilation.
  2077. if (options.el) {
  2078. this.$mount(options.el);
  2079. }
  2080. };
  2081. }
  2082. var pathCache = new Cache(1000);
  2083. // actions
  2084. var APPEND = 0;
  2085. var PUSH = 1;
  2086. var INC_SUB_PATH_DEPTH = 2;
  2087. var PUSH_SUB_PATH = 3;
  2088. // states
  2089. var BEFORE_PATH = 0;
  2090. var IN_PATH = 1;
  2091. var BEFORE_IDENT = 2;
  2092. var IN_IDENT = 3;
  2093. var IN_SUB_PATH = 4;
  2094. var IN_SINGLE_QUOTE = 5;
  2095. var IN_DOUBLE_QUOTE = 6;
  2096. var AFTER_PATH = 7;
  2097. var ERROR = 8;
  2098. var pathStateMachine = [];
  2099. pathStateMachine[BEFORE_PATH] = {
  2100. 'ws': [BEFORE_PATH],
  2101. 'ident': [IN_IDENT, APPEND],
  2102. '[': [IN_SUB_PATH],
  2103. 'eof': [AFTER_PATH]
  2104. };
  2105. pathStateMachine[IN_PATH] = {
  2106. 'ws': [IN_PATH],
  2107. '.': [BEFORE_IDENT],
  2108. '[': [IN_SUB_PATH],
  2109. 'eof': [AFTER_PATH]
  2110. };
  2111. pathStateMachine[BEFORE_IDENT] = {
  2112. 'ws': [BEFORE_IDENT],
  2113. 'ident': [IN_IDENT, APPEND]
  2114. };
  2115. pathStateMachine[IN_IDENT] = {
  2116. 'ident': [IN_IDENT, APPEND],
  2117. '0': [IN_IDENT, APPEND],
  2118. 'number': [IN_IDENT, APPEND],
  2119. 'ws': [IN_PATH, PUSH],
  2120. '.': [BEFORE_IDENT, PUSH],
  2121. '[': [IN_SUB_PATH, PUSH],
  2122. 'eof': [AFTER_PATH, PUSH]
  2123. };
  2124. pathStateMachine[IN_SUB_PATH] = {
  2125. "'": [IN_SINGLE_QUOTE, APPEND],
  2126. '"': [IN_DOUBLE_QUOTE, APPEND],
  2127. '[': [IN_SUB_PATH, INC_SUB_PATH_DEPTH],
  2128. ']': [IN_PATH, PUSH_SUB_PATH],
  2129. 'eof': ERROR,
  2130. 'else': [IN_SUB_PATH, APPEND]
  2131. };
  2132. pathStateMachine[IN_SINGLE_QUOTE] = {
  2133. "'": [IN_SUB_PATH, APPEND],
  2134. 'eof': ERROR,
  2135. 'else': [IN_SINGLE_QUOTE, APPEND]
  2136. };
  2137. pathStateMachine[IN_DOUBLE_QUOTE] = {
  2138. '"': [IN_SUB_PATH, APPEND],
  2139. 'eof': ERROR,
  2140. 'else': [IN_DOUBLE_QUOTE, APPEND]
  2141. };
  2142. /**
  2143. * Determine the type of a character in a keypath.
  2144. *
  2145. * @param {Char} ch
  2146. * @return {String} type
  2147. */
  2148. function getPathCharType(ch) {
  2149. if (ch === undefined) {
  2150. return 'eof';
  2151. }
  2152. var code = ch.charCodeAt(0);
  2153. switch (code) {
  2154. case 0x5B: // [
  2155. case 0x5D: // ]
  2156. case 0x2E: // .
  2157. case 0x22: // "
  2158. case 0x27: // '
  2159. case 0x30:
  2160. // 0
  2161. return ch;
  2162. case 0x5F: // _
  2163. case 0x24:
  2164. // $
  2165. return 'ident';
  2166. case 0x20: // Space
  2167. case 0x09: // Tab
  2168. case 0x0A: // Newline
  2169. case 0x0D: // Return
  2170. case 0xA0: // No-break space
  2171. case 0xFEFF: // Byte Order Mark
  2172. case 0x2028: // Line Separator
  2173. case 0x2029:
  2174. // Paragraph Separator
  2175. return 'ws';
  2176. }
  2177. // a-z, A-Z
  2178. if (code >= 0x61 && code <= 0x7A || code >= 0x41 && code <= 0x5A) {
  2179. return 'ident';
  2180. }
  2181. // 1-9
  2182. if (code >= 0x31 && code <= 0x39) {
  2183. return 'number';
  2184. }
  2185. return 'else';
  2186. }
  2187. /**
  2188. * Format a subPath, return its plain form if it is
  2189. * a literal string or number. Otherwise prepend the
  2190. * dynamic indicator (*).
  2191. *
  2192. * @param {String} path
  2193. * @return {String}
  2194. */
  2195. function formatSubPath(path) {
  2196. var trimmed = path.trim();
  2197. // invalid leading 0
  2198. if (path.charAt(0) === '0' && isNaN(path)) {
  2199. return false;
  2200. }
  2201. return isLiteral(trimmed) ? stripQuotes(trimmed) : '*' + trimmed;
  2202. }
  2203. /**
  2204. * Parse a string path into an array of segments
  2205. *
  2206. * @param {String} path
  2207. * @return {Array|undefined}
  2208. */
  2209. function parse(path) {
  2210. var keys = [];
  2211. var index = -1;
  2212. var mode = BEFORE_PATH;
  2213. var subPathDepth = 0;
  2214. var c, newChar, key, type, transition, action, typeMap;
  2215. var actions = [];
  2216. actions[PUSH] = function () {
  2217. if (key !== undefined) {
  2218. keys.push(key);
  2219. key = undefined;
  2220. }
  2221. };
  2222. actions[APPEND] = function () {
  2223. if (key === undefined) {
  2224. key = newChar;
  2225. } else {
  2226. key += newChar;
  2227. }
  2228. };
  2229. actions[INC_SUB_PATH_DEPTH] = function () {
  2230. actions[APPEND]();
  2231. subPathDepth++;
  2232. };
  2233. actions[PUSH_SUB_PATH] = function () {
  2234. if (subPathDepth > 0) {
  2235. subPathDepth--;
  2236. mode = IN_SUB_PATH;
  2237. actions[APPEND]();
  2238. } else {
  2239. subPathDepth = 0;
  2240. key = formatSubPath(key);
  2241. if (key === false) {
  2242. return false;
  2243. } else {
  2244. actions[PUSH]();
  2245. }
  2246. }
  2247. };
  2248. function maybeUnescapeQuote() {
  2249. var nextChar = path[index + 1];
  2250. if (mode === IN_SINGLE_QUOTE && nextChar === "'" || mode === IN_DOUBLE_QUOTE && nextChar === '"') {
  2251. index++;
  2252. newChar = '\\' + nextChar;
  2253. actions[APPEND]();
  2254. return true;
  2255. }
  2256. }
  2257. while (mode != null) {
  2258. index++;
  2259. c = path[index];
  2260. if (c === '\\' && maybeUnescapeQuote()) {
  2261. continue;
  2262. }
  2263. type = getPathCharType(c);
  2264. typeMap = pathStateMachine[mode];
  2265. transition = typeMap[type] || typeMap['else'] || ERROR;
  2266. if (transition === ERROR) {
  2267. return; // parse error
  2268. }
  2269. mode = transition[0];
  2270. action = actions[transition[1]];
  2271. if (action) {
  2272. newChar = transition[2];
  2273. newChar = newChar === undefined ? c : newChar;
  2274. if (action() === false) {
  2275. return;
  2276. }
  2277. }
  2278. if (mode === AFTER_PATH) {
  2279. keys.raw = path;
  2280. return keys;
  2281. }
  2282. }
  2283. }
  2284. /**
  2285. * External parse that check for a cache hit first
  2286. *
  2287. * @param {String} path
  2288. * @return {Array|undefined}
  2289. */
  2290. function parsePath(path) {
  2291. var hit = pathCache.get(path);
  2292. if (!hit) {
  2293. hit = parse(path);
  2294. if (hit) {
  2295. pathCache.put(path, hit);
  2296. }
  2297. }
  2298. return hit;
  2299. }
  2300. /**
  2301. * Get from an object from a path string
  2302. *
  2303. * @param {Object} obj
  2304. * @param {String} path
  2305. */
  2306. function getPath(obj, path) {
  2307. return parseExpression(path).get(obj);
  2308. }
  2309. /**
  2310. * Warn against setting non-existent root path on a vm.
  2311. */
  2312. var warnNonExistent;
  2313. if ('development' !== 'production') {
  2314. warnNonExistent = function (path) {
  2315. warn('You are setting a non-existent path "' + path.raw + '" ' + 'on a vm instance. Consider pre-initializing the property ' + 'with the "data" option for more reliable reactivity ' + 'and better performance.');
  2316. };
  2317. }
  2318. /**
  2319. * Set on an object from a path
  2320. *
  2321. * @param {Object} obj
  2322. * @param {String | Array} path
  2323. * @param {*} val
  2324. */
  2325. function setPath(obj, path, val) {
  2326. var original = obj;
  2327. if (typeof path === 'string') {
  2328. path = parse(path);
  2329. }
  2330. if (!path || !isObject(obj)) {
  2331. return false;
  2332. }
  2333. var last, key;
  2334. for (var i = 0, l = path.length; i < l; i++) {
  2335. last = obj;
  2336. key = path[i];
  2337. if (key.charAt(0) === '*') {
  2338. key = parseExpression(key.slice(1)).get.call(original, original);
  2339. }
  2340. if (i < l - 1) {
  2341. obj = obj[key];
  2342. if (!isObject(obj)) {
  2343. obj = {};
  2344. if ('development' !== 'production' && last._isVue) {
  2345. warnNonExistent(path);
  2346. }
  2347. set(last, key, obj);
  2348. }
  2349. } else {
  2350. if (isArray(obj)) {
  2351. obj.$set(key, val);
  2352. } else if (key in obj) {
  2353. obj[key] = val;
  2354. } else {
  2355. if ('development' !== 'production' && obj._isVue) {
  2356. warnNonExistent(path);
  2357. }
  2358. set(obj, key, val);
  2359. }
  2360. }
  2361. }
  2362. return true;
  2363. }
  2364. var path = Object.freeze({
  2365. parsePath: parsePath,
  2366. getPath: getPath,
  2367. setPath: setPath
  2368. });
  2369. var expressionCache = new Cache(1000);
  2370. var allowedKeywords = 'Math,Date,this,true,false,null,undefined,Infinity,NaN,' + 'isNaN,isFinite,decodeURI,decodeURIComponent,encodeURI,' + 'encodeURIComponent,parseInt,parseFloat';
  2371. var allowedKeywordsRE = new RegExp('^(' + allowedKeywords.replace(/,/g, '\\b|') + '\\b)');
  2372. // keywords that don't make sense inside expressions
  2373. var improperKeywords = 'break,case,class,catch,const,continue,debugger,default,' + 'delete,do,else,export,extends,finally,for,function,if,' + 'import,in,instanceof,let,return,super,switch,throw,try,' + 'var,while,with,yield,enum,await,implements,package,' + 'proctected,static,interface,private,public';
  2374. var improperKeywordsRE = new RegExp('^(' + improperKeywords.replace(/,/g, '\\b|') + '\\b)');
  2375. var wsRE = /\s/g;
  2376. var newlineRE = /\n/g;
  2377. var saveRE = /[\{,]\s*[\w\$_]+\s*:|('[^']*'|"[^"]*")|new |typeof |void /g;
  2378. var restoreRE = /"(\d+)"/g;
  2379. var pathTestRE = /^[A-Za-z_$][\w$]*(\.[A-Za-z_$][\w$]*|\['.*?'\]|\[".*?"\]|\[\d+\]|\[[A-Za-z_$][\w$]*\])*$/;
  2380. var pathReplaceRE = /[^\w$\.]([A-Za-z_$][\w$]*(\.[A-Za-z_$][\w$]*|\['.*?'\]|\[".*?"\])*)/g;
  2381. var booleanLiteralRE = /^(true|false)$/;
  2382. /**
  2383. * Save / Rewrite / Restore
  2384. *
  2385. * When rewriting paths found in an expression, it is
  2386. * possible for the same letter sequences to be found in
  2387. * strings and Object literal property keys. Therefore we
  2388. * remove and store these parts in a temporary array, and
  2389. * restore them after the path rewrite.
  2390. */
  2391. var saved = [];
  2392. /**
  2393. * Save replacer
  2394. *
  2395. * The save regex can match two possible cases:
  2396. * 1. An opening object literal
  2397. * 2. A string
  2398. * If matched as a plain string, we need to escape its
  2399. * newlines, since the string needs to be preserved when
  2400. * generating the function body.
  2401. *
  2402. * @param {String} str
  2403. * @param {String} isString - str if matched as a string
  2404. * @return {String} - placeholder with index
  2405. */
  2406. function save(str, isString) {
  2407. var i = saved.length;
  2408. saved[i] = isString ? str.replace(newlineRE, '\\n') : str;
  2409. return '"' + i + '"';
  2410. }
  2411. /**
  2412. * Path rewrite replacer
  2413. *
  2414. * @param {String} raw
  2415. * @return {String}
  2416. */
  2417. function rewrite(raw) {
  2418. var c = raw.charAt(0);
  2419. var path = raw.slice(1);
  2420. if (allowedKeywordsRE.test(path)) {
  2421. return raw;
  2422. } else {
  2423. path = path.indexOf('"') > -1 ? path.replace(restoreRE, restore) : path;
  2424. return c + 'scope.' + path;
  2425. }
  2426. }
  2427. /**
  2428. * Restore replacer
  2429. *
  2430. * @param {String} str
  2431. * @param {String} i - matched save index
  2432. * @return {String}
  2433. */
  2434. function restore(str, i) {
  2435. return saved[i];
  2436. }
  2437. /**
  2438. * Rewrite an expression, prefixing all path accessors with
  2439. * `scope.` and generate getter/setter functions.
  2440. *
  2441. * @param {String} exp
  2442. * @return {Function}
  2443. */
  2444. function compileGetter(exp) {
  2445. if (improperKeywordsRE.test(exp)) {
  2446. 'development' !== 'production' && warn('Avoid using reserved keywords in expression: ' + exp);
  2447. }
  2448. // reset state
  2449. saved.length = 0;
  2450. // save strings and object literal keys
  2451. var body = exp.replace(saveRE, save).replace(wsRE, '');
  2452. // rewrite all paths
  2453. // pad 1 space here becaue the regex matches 1 extra char
  2454. body = (' ' + body).replace(pathReplaceRE, rewrite).replace(restoreRE, restore);
  2455. return makeGetterFn(body);
  2456. }
  2457. /**
  2458. * Build a getter function. Requires eval.
  2459. *
  2460. * We isolate the try/catch so it doesn't affect the
  2461. * optimization of the parse function when it is not called.
  2462. *
  2463. * @param {String} body
  2464. * @return {Function|undefined}
  2465. */
  2466. function makeGetterFn(body) {
  2467. try {
  2468. return new Function('scope', 'return ' + body + ';');
  2469. } catch (e) {
  2470. 'development' !== 'production' && warn('Invalid expression. ' + 'Generated function body: ' + body);
  2471. }
  2472. }
  2473. /**
  2474. * Compile a setter function for the expression.
  2475. *
  2476. * @param {String} exp
  2477. * @return {Function|undefined}
  2478. */
  2479. function compileSetter(exp) {
  2480. var path = parsePath(exp);
  2481. if (path) {
  2482. return function (scope, val) {
  2483. setPath(scope, path, val);
  2484. };
  2485. } else {
  2486. 'development' !== 'production' && warn('Invalid setter expression: ' + exp);
  2487. }
  2488. }
  2489. /**
  2490. * Parse an expression into re-written getter/setters.
  2491. *
  2492. * @param {String} exp
  2493. * @param {Boolean} needSet
  2494. * @return {Function}
  2495. */
  2496. function parseExpression(exp, needSet) {
  2497. exp = exp.trim();
  2498. // try cache
  2499. var hit = expressionCache.get(exp);
  2500. if (hit) {
  2501. if (needSet && !hit.set) {
  2502. hit.set = compileSetter(hit.exp);
  2503. }
  2504. return hit;
  2505. }
  2506. var res = { exp: exp };
  2507. res.get = isSimplePath(exp) && exp.indexOf('[') < 0
  2508. // optimized super simple getter
  2509. ? makeGetterFn('scope.' + exp)
  2510. // dynamic getter
  2511. : compileGetter(exp);
  2512. if (needSet) {
  2513. res.set = compileSetter(exp);
  2514. }
  2515. expressionCache.put(exp, res);
  2516. return res;
  2517. }
  2518. /**
  2519. * Check if an expression is a simple path.
  2520. *
  2521. * @param {String} exp
  2522. * @return {Boolean}
  2523. */
  2524. function isSimplePath(exp) {
  2525. return pathTestRE.test(exp) &&
  2526. // don't treat true/false as paths
  2527. !booleanLiteralRE.test(exp) &&
  2528. // Math constants e.g. Math.PI, Math.E etc.
  2529. exp.slice(0, 5) !== 'Math.';
  2530. }
  2531. var expression = Object.freeze({
  2532. parseExpression: parseExpression,
  2533. isSimplePath: isSimplePath
  2534. });
  2535. // we have two separate queues: one for directive updates
  2536. // and one for user watcher registered via $watch().
  2537. // we want to guarantee directive updates to be called
  2538. // before user watchers so that when user watchers are
  2539. // triggered, the DOM would have already been in updated
  2540. // state.
  2541. var queue = [];
  2542. var userQueue = [];
  2543. var has = {};
  2544. var circular = {};
  2545. var waiting = false;
  2546. var internalQueueDepleted = false;
  2547. /**
  2548. * Reset the batcher's state.
  2549. */
  2550. function resetBatcherState() {
  2551. queue = [];
  2552. userQueue = [];
  2553. has = {};
  2554. circular = {};
  2555. waiting = internalQueueDepleted = false;
  2556. }
  2557. /**
  2558. * Flush both queues and run the watchers.
  2559. */
  2560. function flushBatcherQueue() {
  2561. runBatcherQueue(queue);
  2562. internalQueueDepleted = true;
  2563. runBatcherQueue(userQueue);
  2564. // dev tool hook
  2565. /* istanbul ignore if */
  2566. if ('development' !== 'production') {
  2567. if (inBrowser && window.__VUE_DEVTOOLS_GLOBAL_HOOK__) {
  2568. window.__VUE_DEVTOOLS_GLOBAL_HOOK__.emit('flush');
  2569. }
  2570. }
  2571. resetBatcherState();
  2572. }
  2573. /**
  2574. * Run the watchers in a single queue.
  2575. *
  2576. * @param {Array} queue
  2577. */
  2578. function runBatcherQueue(queue) {
  2579. // do not cache length because more watchers might be pushed
  2580. // as we run existing watchers
  2581. for (var i = 0; i < queue.length; i++) {
  2582. var watcher = queue[i];
  2583. var id = watcher.id;
  2584. has[id] = null;
  2585. watcher.run();
  2586. // in dev build, check and stop circular updates.
  2587. if ('development' !== 'production' && has[id] != null) {
  2588. circular[id] = (circular[id] || 0) + 1;
  2589. if (circular[id] > config._maxUpdateCount) {
  2590. queue.splice(has[id], 1);
  2591. warn('You may have an infinite update loop for watcher ' + 'with expression: ' + watcher.expression);
  2592. }
  2593. }
  2594. }
  2595. }
  2596. /**
  2597. * Push a watcher into the watcher queue.
  2598. * Jobs with duplicate IDs will be skipped unless it's
  2599. * pushed when the queue is being flushed.
  2600. *
  2601. * @param {Watcher} watcher
  2602. * properties:
  2603. * - {Number} id
  2604. * - {Function} run
  2605. */
  2606. function pushWatcher(watcher) {
  2607. var id = watcher.id;
  2608. if (has[id] == null) {
  2609. // if an internal watcher is pushed, but the internal
  2610. // queue is already depleted, we run it immediately.
  2611. if (internalQueueDepleted && !watcher.user) {
  2612. watcher.run();
  2613. return;
  2614. }
  2615. // push watcher into appropriate queue
  2616. var q = watcher.user ? userQueue : queue;
  2617. has[id] = q.length;
  2618. q.push(watcher);
  2619. // queue the flush
  2620. if (!waiting) {
  2621. waiting = true;
  2622. nextTick(flushBatcherQueue);
  2623. }
  2624. }
  2625. }
  2626. var uid$2 = 0;
  2627. /**
  2628. * A watcher parses an expression, collects dependencies,
  2629. * and fires callback when the expression value changes.
  2630. * This is used for both the $watch() api and directives.
  2631. *
  2632. * @param {Vue} vm
  2633. * @param {String} expression
  2634. * @param {Function} cb
  2635. * @param {Object} options
  2636. * - {Array} filters
  2637. * - {Boolean} twoWay
  2638. * - {Boolean} deep
  2639. * - {Boolean} user
  2640. * - {Boolean} sync
  2641. * - {Boolean} lazy
  2642. * - {Function} [preProcess]
  2643. * - {Function} [postProcess]
  2644. * @constructor
  2645. */
  2646. function Watcher(vm, expOrFn, cb, options) {
  2647. // mix in options
  2648. if (options) {
  2649. extend(this, options);
  2650. }
  2651. var isFn = typeof expOrFn === 'function';
  2652. this.vm = vm;
  2653. vm._watchers.push(this);
  2654. this.expression = isFn ? expOrFn.toString() : expOrFn;
  2655. this.cb = cb;
  2656. this.id = ++uid$2; // uid for batching
  2657. this.active = true;
  2658. this.dirty = this.lazy; // for lazy watchers
  2659. this.deps = Object.create(null);
  2660. this.newDeps = null;
  2661. this.prevError = null; // for async error stacks
  2662. // parse expression for getter/setter
  2663. if (isFn) {
  2664. this.getter = expOrFn;
  2665. this.setter = undefined;
  2666. } else {
  2667. var res = parseExpression(expOrFn, this.twoWay);
  2668. this.getter = res.get;
  2669. this.setter = res.set;
  2670. }
  2671. this.value = this.lazy ? undefined : this.get();
  2672. // state for avoiding false triggers for deep and Array
  2673. // watchers during vm._digest()
  2674. this.queued = this.shallow = false;
  2675. }
  2676. /**
  2677. * Add a dependency to this directive.
  2678. *
  2679. * @param {Dep} dep
  2680. */
  2681. Watcher.prototype.addDep = function (dep) {
  2682. var id = dep.id;
  2683. if (!this.newDeps[id]) {
  2684. this.newDeps[id] = dep;
  2685. if (!this.deps[id]) {
  2686. this.deps[id] = dep;
  2687. dep.addSub(this);
  2688. }
  2689. }
  2690. };
  2691. /**
  2692. * Evaluate the getter, and re-collect dependencies.
  2693. */
  2694. Watcher.prototype.get = function () {
  2695. this.beforeGet();
  2696. var scope = this.scope || this.vm;
  2697. var value;
  2698. try {
  2699. value = this.getter.call(scope, scope);
  2700. } catch (e) {
  2701. if ('development' !== 'production' && config.warnExpressionErrors) {
  2702. warn('Error when evaluating expression "' + this.expression + '". ' + (config.debug ? '' : 'Turn on debug mode to see stack trace.'), e);
  2703. }
  2704. }
  2705. // "touch" every property so they are all tracked as
  2706. // dependencies for deep watching
  2707. if (this.deep) {
  2708. traverse(value);
  2709. }
  2710. if (this.preProcess) {
  2711. value = this.preProcess(value);
  2712. }
  2713. if (this.filters) {
  2714. value = scope._applyFilters(value, null, this.filters, false);
  2715. }
  2716. if (this.postProcess) {
  2717. value = this.postProcess(value);
  2718. }
  2719. this.afterGet();
  2720. return value;
  2721. };
  2722. /**
  2723. * Set the corresponding value with the setter.
  2724. *
  2725. * @param {*} value
  2726. */
  2727. Watcher.prototype.set = function (value) {
  2728. var scope = this.scope || this.vm;
  2729. if (this.filters) {
  2730. value = scope._applyFilters(value, this.value, this.filters, true);
  2731. }
  2732. try {
  2733. this.setter.call(scope, scope, value);
  2734. } catch (e) {
  2735. if ('development' !== 'production' && config.warnExpressionErrors) {
  2736. warn('Error when evaluating setter "' + this.expression + '"', e);
  2737. }
  2738. }
  2739. // two-way sync for v-for alias
  2740. var forContext = scope.$forContext;
  2741. if (forContext && forContext.alias === this.expression) {
  2742. if (forContext.filters) {
  2743. 'development' !== 'production' && warn('It seems you are using two-way binding on ' + 'a v-for alias (' + this.expression + '), and the ' + 'v-for has filters. This will not work properly. ' + 'Either remove the filters or use an array of ' + 'objects and bind to object properties instead.');
  2744. return;
  2745. }
  2746. forContext._withLock(function () {
  2747. if (scope.$key) {
  2748. // original is an object
  2749. forContext.rawValue[scope.$key] = value;
  2750. } else {
  2751. forContext.rawValue.$set(scope.$index, value);
  2752. }
  2753. });
  2754. }
  2755. };
  2756. /**
  2757. * Prepare for dependency collection.
  2758. */
  2759. Watcher.prototype.beforeGet = function () {
  2760. Dep.target = this;
  2761. this.newDeps = Object.create(null);
  2762. };
  2763. /**
  2764. * Clean up for dependency collection.
  2765. */
  2766. Watcher.prototype.afterGet = function () {
  2767. Dep.target = null;
  2768. var ids = Object.keys(this.deps);
  2769. var i = ids.length;
  2770. while (i--) {
  2771. var id = ids[i];
  2772. if (!this.newDeps[id]) {
  2773. this.deps[id].removeSub(this);
  2774. }
  2775. }
  2776. this.deps = this.newDeps;
  2777. };
  2778. /**
  2779. * Subscriber interface.
  2780. * Will be called when a dependency changes.
  2781. *
  2782. * @param {Boolean} shallow
  2783. */
  2784. Watcher.prototype.update = function (shallow) {
  2785. if (this.lazy) {
  2786. this.dirty = true;
  2787. } else if (this.sync || !config.async) {
  2788. this.run();
  2789. } else {
  2790. // if queued, only overwrite shallow with non-shallow,
  2791. // but not the other way around.
  2792. this.shallow = this.queued ? shallow ? this.shallow : false : !!shallow;
  2793. this.queued = true;
  2794. // record before-push error stack in debug mode
  2795. /* istanbul ignore if */
  2796. if ('development' !== 'production' && config.debug) {
  2797. this.prevError = new Error('[vue] async stack trace');
  2798. }
  2799. pushWatcher(this);
  2800. }
  2801. };
  2802. /**
  2803. * Batcher job interface.
  2804. * Will be called by the batcher.
  2805. */
  2806. Watcher.prototype.run = function () {
  2807. if (this.active) {
  2808. var value = this.get();
  2809. if (value !== this.value ||
  2810. // Deep watchers and Array watchers should fire even
  2811. // when the value is the same, because the value may
  2812. // have mutated; but only do so if this is a
  2813. // non-shallow update (caused by a vm digest).
  2814. (isArray(value) || this.deep) && !this.shallow) {
  2815. // set new value
  2816. var oldValue = this.value;
  2817. this.value = value;
  2818. // in debug + async mode, when a watcher callbacks
  2819. // throws, we also throw the saved before-push error
  2820. // so the full cross-tick stack trace is available.
  2821. var prevError = this.prevError;
  2822. /* istanbul ignore if */
  2823. if ('development' !== 'production' && config.debug && prevError) {
  2824. this.prevError = null;
  2825. try {
  2826. this.cb.call(this.vm, value, oldValue);
  2827. } catch (e) {
  2828. nextTick(function () {
  2829. throw prevError;
  2830. }, 0);
  2831. throw e;
  2832. }
  2833. } else {
  2834. this.cb.call(this.vm, value, oldValue);
  2835. }
  2836. }
  2837. this.queued = this.shallow = false;
  2838. }
  2839. };
  2840. /**
  2841. * Evaluate the value of the watcher.
  2842. * This only gets called for lazy watchers.
  2843. */
  2844. Watcher.prototype.evaluate = function () {
  2845. // avoid overwriting another watcher that is being
  2846. // collected.
  2847. var current = Dep.target;
  2848. this.value = this.get();
  2849. this.dirty = false;
  2850. Dep.target = current;
  2851. };
  2852. /**
  2853. * Depend on all deps collected by this watcher.
  2854. */
  2855. Watcher.prototype.depend = function () {
  2856. var depIds = Object.keys(this.deps);
  2857. var i = depIds.length;
  2858. while (i--) {
  2859. this.deps[depIds[i]].depend();
  2860. }
  2861. };
  2862. /**
  2863. * Remove self from all dependencies' subcriber list.
  2864. */
  2865. Watcher.prototype.teardown = function () {
  2866. if (this.active) {
  2867. // remove self from vm's watcher list
  2868. // we can skip this if the vm if being destroyed
  2869. // which can improve teardown performance.
  2870. if (!this.vm._isBeingDestroyed) {
  2871. this.vm._watchers.$remove(this);
  2872. }
  2873. var depIds = Object.keys(this.deps);
  2874. var i = depIds.length;
  2875. while (i--) {
  2876. this.deps[depIds[i]].removeSub(this);
  2877. }
  2878. this.active = false;
  2879. this.vm = this.cb = this.value = null;
  2880. }
  2881. };
  2882. /**
  2883. * Recrusively traverse an object to evoke all converted
  2884. * getters, so that every nested property inside the object
  2885. * is collected as a "deep" dependency.
  2886. *
  2887. * @param {*} val
  2888. */
  2889. function traverse(val) {
  2890. var i, keys;
  2891. if (isArray(val)) {
  2892. i = val.length;
  2893. while (i--) traverse(val[i]);
  2894. } else if (isObject(val)) {
  2895. keys = Object.keys(val);
  2896. i = keys.length;
  2897. while (i--) traverse(val[keys[i]]);
  2898. }
  2899. }
  2900. var cloak = {
  2901. bind: function bind() {
  2902. var el = this.el;
  2903. this.vm.$once('hook:compiled', function () {
  2904. el.removeAttribute('v-cloak');
  2905. });
  2906. }
  2907. };
  2908. var ref = {
  2909. bind: function bind() {
  2910. 'development' !== 'production' && warn('v-ref:' + this.arg + ' must be used on a child ' + 'component. Found on <' + this.el.tagName.toLowerCase() + '>.');
  2911. }
  2912. };
  2913. var el = {
  2914. priority: 1500,
  2915. bind: function bind() {
  2916. /* istanbul ignore if */
  2917. if (!this.arg) {
  2918. return;
  2919. }
  2920. var id = this.id = camelize(this.arg);
  2921. var refs = (this._scope || this.vm).$els;
  2922. if (hasOwn(refs, id)) {
  2923. refs[id] = this.el;
  2924. } else {
  2925. defineReactive(refs, id, this.el);
  2926. }
  2927. },
  2928. unbind: function unbind() {
  2929. var refs = (this._scope || this.vm).$els;
  2930. if (refs[this.id] === this.el) {
  2931. refs[this.id] = null;
  2932. }
  2933. }
  2934. };
  2935. var prefixes = ['-webkit-', '-moz-', '-ms-'];
  2936. var camelPrefixes = ['Webkit', 'Moz', 'ms'];
  2937. var importantRE = /!important;?$/;
  2938. var propCache = Object.create(null);
  2939. var testEl = null;
  2940. var style = {
  2941. deep: true,
  2942. update: function update(value) {
  2943. if (typeof value === 'string') {
  2944. this.el.style.cssText = value;
  2945. } else if (isArray(value)) {
  2946. this.handleObject(value.reduce(extend, {}));
  2947. } else {
  2948. this.handleObject(value || {});
  2949. }
  2950. },
  2951. handleObject: function handleObject(value) {
  2952. // cache object styles so that only changed props
  2953. // are actually updated.
  2954. var cache = this.cache || (this.cache = {});
  2955. var name, val;
  2956. for (name in cache) {
  2957. if (!(name in value)) {
  2958. this.handleSingle(name, null);
  2959. delete cache[name];
  2960. }
  2961. }
  2962. for (name in value) {
  2963. val = value[name];
  2964. if (val !== cache[name]) {
  2965. cache[name] = val;
  2966. this.handleSingle(name, val);
  2967. }
  2968. }
  2969. },
  2970. handleSingle: function handleSingle(prop, value) {
  2971. prop = normalize(prop);
  2972. if (!prop) return; // unsupported prop
  2973. // cast possible numbers/booleans into strings
  2974. if (value != null) value += '';
  2975. if (value) {
  2976. var isImportant = importantRE.test(value) ? 'important' : '';
  2977. if (isImportant) {
  2978. value = value.replace(importantRE, '').trim();
  2979. }
  2980. this.el.style.setProperty(prop, value, isImportant);
  2981. } else {
  2982. this.el.style.removeProperty(prop);
  2983. }
  2984. }
  2985. };
  2986. /**
  2987. * Normalize a CSS property name.
  2988. * - cache result
  2989. * - auto prefix
  2990. * - camelCase -> dash-case
  2991. *
  2992. * @param {String} prop
  2993. * @return {String}
  2994. */
  2995. function normalize(prop) {
  2996. if (propCache[prop]) {
  2997. return propCache[prop];
  2998. }
  2999. var res = prefix(prop);
  3000. propCache[prop] = propCache[res] = res;
  3001. return res;
  3002. }
  3003. /**
  3004. * Auto detect the appropriate prefix for a CSS property.
  3005. * https://gist.github.com/paulirish/523692
  3006. *
  3007. * @param {String} prop
  3008. * @return {String}
  3009. */
  3010. function prefix(prop) {
  3011. prop = hyphenate(prop);
  3012. var camel = camelize(prop);
  3013. var upper = camel.charAt(0).toUpperCase() + camel.slice(1);
  3014. if (!testEl) {
  3015. testEl = document.createElement('div');
  3016. }
  3017. if (camel in testEl.style) {
  3018. return prop;
  3019. }
  3020. var i = prefixes.length;
  3021. var prefixed;
  3022. while (i--) {
  3023. prefixed = camelPrefixes[i] + upper;
  3024. if (prefixed in testEl.style) {
  3025. return prefixes[i] + prop;
  3026. }
  3027. }
  3028. }
  3029. // xlink
  3030. var xlinkNS = 'http://www.w3.org/1999/xlink';
  3031. var xlinkRE = /^xlink:/;
  3032. // these input element attributes should also set their
  3033. // corresponding properties
  3034. var inputProps = {
  3035. value: 1,
  3036. checked: 1,
  3037. selected: 1
  3038. };
  3039. // these attributes should set a hidden property for
  3040. // binding v-model to object values
  3041. var modelProps = {
  3042. value: '_value',
  3043. 'true-value': '_trueValue',
  3044. 'false-value': '_falseValue'
  3045. };
  3046. // check for attributes that prohibit interpolations
  3047. var disallowedInterpAttrRE = /^v-|^:|^@|^(is|transition|transition-mode|debounce|track-by|stagger|enter-stagger|leave-stagger)$/;
  3048. var bind = {
  3049. priority: 850,
  3050. bind: function bind() {
  3051. var attr = this.arg;
  3052. var tag = this.el.tagName;
  3053. // should be deep watch on object mode
  3054. if (!attr) {
  3055. this.deep = true;
  3056. }
  3057. // handle interpolation bindings
  3058. if (this.descriptor.interp) {
  3059. // only allow binding on native attributes
  3060. if (disallowedInterpAttrRE.test(attr) || attr === 'name' && (tag === 'PARTIAL' || tag === 'SLOT')) {
  3061. 'development' !== 'production' && warn(attr + '="' + this.descriptor.raw + '": ' + 'attribute interpolation is not allowed in Vue.js ' + 'directives and special attributes.');
  3062. this.el.removeAttribute(attr);
  3063. this.invalid = true;
  3064. }
  3065. /* istanbul ignore if */
  3066. if ('development' !== 'production') {
  3067. var raw = attr + '="' + this.descriptor.raw + '": ';
  3068. // warn src
  3069. if (attr === 'src') {
  3070. warn(raw + 'interpolation in "src" attribute will cause ' + 'a 404 request. Use v-bind:src instead.');
  3071. }
  3072. // warn style
  3073. if (attr === 'style') {
  3074. warn(raw + 'interpolation in "style" attribute will cause ' + 'the attribute to be discarded in Internet Explorer. ' + 'Use v-bind:style instead.');
  3075. }
  3076. }
  3077. }
  3078. },
  3079. update: function update(value) {
  3080. if (this.invalid) {
  3081. return;
  3082. }
  3083. var attr = this.arg;
  3084. if (this.arg) {
  3085. this.handleSingle(attr, value);
  3086. } else {
  3087. this.handleObject(value || {});
  3088. }
  3089. },
  3090. // share object handler with v-bind:class
  3091. handleObject: style.handleObject,
  3092. handleSingle: function handleSingle(attr, value) {
  3093. if (inputProps[attr] && attr in this.el) {
  3094. this.el[attr] = attr === 'value' ? value || '' : // IE9 will set input.value to "null" for null...
  3095. value;
  3096. }
  3097. // set model props
  3098. var modelProp = modelProps[attr];
  3099. if (modelProp) {
  3100. this.el[modelProp] = value;
  3101. // update v-model if present
  3102. var model = this.el.__v_model;
  3103. if (model) {
  3104. model.listener();
  3105. }
  3106. }
  3107. // do not set value attribute for textarea
  3108. if (attr === 'value' && this.el.tagName === 'TEXTAREA') {
  3109. this.el.removeAttribute(attr);
  3110. return;
  3111. }
  3112. // update attribute
  3113. if (value != null && value !== false) {
  3114. if (xlinkRE.test(attr)) {
  3115. this.el.setAttributeNS(xlinkNS, attr, value);
  3116. } else {
  3117. this.el.setAttribute(attr, value);
  3118. }
  3119. } else {
  3120. this.el.removeAttribute(attr);
  3121. }
  3122. }
  3123. };
  3124. // keyCode aliases
  3125. var keyCodes = {
  3126. esc: 27,
  3127. tab: 9,
  3128. enter: 13,
  3129. space: 32,
  3130. 'delete': 46,
  3131. up: 38,
  3132. left: 37,
  3133. right: 39,
  3134. down: 40
  3135. };
  3136. function keyFilter(handler, keys) {
  3137. var codes = keys.map(function (key) {
  3138. var charCode = key.charCodeAt(0);
  3139. if (charCode > 47 && charCode < 58) {
  3140. return parseInt(key, 10);
  3141. }
  3142. if (key.length === 1) {
  3143. charCode = key.toUpperCase().charCodeAt(0);
  3144. if (charCode > 64 && charCode < 91) {
  3145. return charCode;
  3146. }
  3147. }
  3148. return keyCodes[key];
  3149. });
  3150. return function keyHandler(e) {
  3151. if (codes.indexOf(e.keyCode) > -1) {
  3152. return handler.call(this, e);
  3153. }
  3154. };
  3155. }
  3156. function stopFilter(handler) {
  3157. return function stopHandler(e) {
  3158. e.stopPropagation();
  3159. return handler.call(this, e);
  3160. };
  3161. }
  3162. function preventFilter(handler) {
  3163. return function preventHandler(e) {
  3164. e.preventDefault();
  3165. return handler.call(this, e);
  3166. };
  3167. }
  3168. var on = {
  3169. acceptStatement: true,
  3170. priority: 700,
  3171. bind: function bind() {
  3172. // deal with iframes
  3173. if (this.el.tagName === 'IFRAME' && this.arg !== 'load') {
  3174. var self = this;
  3175. this.iframeBind = function () {
  3176. on$1(self.el.contentWindow, self.arg, self.handler);
  3177. };
  3178. this.on('load', this.iframeBind);
  3179. }
  3180. },
  3181. update: function update(handler) {
  3182. // stub a noop for v-on with no value,
  3183. // e.g. @mousedown.prevent
  3184. if (!this.descriptor.raw) {
  3185. handler = function () {};
  3186. }
  3187. if (typeof handler !== 'function') {
  3188. 'development' !== 'production' && warn('v-on:' + this.arg + '="' + this.expression + '" expects a function value, ' + 'got ' + handler);
  3189. return;
  3190. }
  3191. // apply modifiers
  3192. if (this.modifiers.stop) {
  3193. handler = stopFilter(handler);
  3194. }
  3195. if (this.modifiers.prevent) {
  3196. handler = preventFilter(handler);
  3197. }
  3198. // key filter
  3199. var keys = Object.keys(this.modifiers).filter(function (key) {
  3200. return key !== 'stop' && key !== 'prevent';
  3201. });
  3202. if (keys.length) {
  3203. handler = keyFilter(handler, keys);
  3204. }
  3205. this.reset();
  3206. this.handler = handler;
  3207. if (this.iframeBind) {
  3208. this.iframeBind();
  3209. } else {
  3210. on$1(this.el, this.arg, this.handler);
  3211. }
  3212. },
  3213. reset: function reset() {
  3214. var el = this.iframeBind ? this.el.contentWindow : this.el;
  3215. if (this.handler) {
  3216. off(el, this.arg, this.handler);
  3217. }
  3218. },
  3219. unbind: function unbind() {
  3220. this.reset();
  3221. }
  3222. };
  3223. var checkbox = {
  3224. bind: function bind() {
  3225. var self = this;
  3226. var el = this.el;
  3227. this.getValue = function () {
  3228. return el.hasOwnProperty('_value') ? el._value : self.params.number ? toNumber(el.value) : el.value;
  3229. };
  3230. function getBooleanValue() {
  3231. var val = el.checked;
  3232. if (val && el.hasOwnProperty('_trueValue')) {
  3233. return el._trueValue;
  3234. }
  3235. if (!val && el.hasOwnProperty('_falseValue')) {
  3236. return el._falseValue;
  3237. }
  3238. return val;
  3239. }
  3240. this.listener = function () {
  3241. var model = self._watcher.value;
  3242. if (isArray(model)) {
  3243. var val = self.getValue();
  3244. if (el.checked) {
  3245. if (indexOf(model, val) < 0) {
  3246. model.push(val);
  3247. }
  3248. } else {
  3249. model.$remove(val);
  3250. }
  3251. } else {
  3252. self.set(getBooleanValue());
  3253. }
  3254. };
  3255. this.on('change', this.listener);
  3256. if (el.checked) {
  3257. this.afterBind = this.listener;
  3258. }
  3259. },
  3260. update: function update(value) {
  3261. var el = this.el;
  3262. if (isArray(value)) {
  3263. el.checked = indexOf(value, this.getValue()) > -1;
  3264. } else {
  3265. if (el.hasOwnProperty('_trueValue')) {
  3266. el.checked = looseEqual(value, el._trueValue);
  3267. } else {
  3268. el.checked = !!value;
  3269. }
  3270. }
  3271. }
  3272. };
  3273. var select = {
  3274. bind: function bind() {
  3275. var self = this;
  3276. var el = this.el;
  3277. // method to force update DOM using latest value.
  3278. this.forceUpdate = function () {
  3279. if (self._watcher) {
  3280. self.update(self._watcher.get());
  3281. }
  3282. };
  3283. // check if this is a multiple select
  3284. var multiple = this.multiple = el.hasAttribute('multiple');
  3285. // attach listener
  3286. this.listener = function () {
  3287. var value = getValue(el, multiple);
  3288. value = self.params.number ? isArray(value) ? value.map(toNumber) : toNumber(value) : value;
  3289. self.set(value);
  3290. };
  3291. this.on('change', this.listener);
  3292. // if has initial value, set afterBind
  3293. var initValue = getValue(el, multiple, true);
  3294. if (multiple && initValue.length || !multiple && initValue !== null) {
  3295. this.afterBind = this.listener;
  3296. }
  3297. // All major browsers except Firefox resets
  3298. // selectedIndex with value -1 to 0 when the element
  3299. // is appended to a new parent, therefore we have to
  3300. // force a DOM update whenever that happens...
  3301. this.vm.$on('hook:attached', this.forceUpdate);
  3302. },
  3303. update: function update(value) {
  3304. var el = this.el;
  3305. el.selectedIndex = -1;
  3306. var multi = this.multiple && isArray(value);
  3307. var options = el.options;
  3308. var i = options.length;
  3309. var op, val;
  3310. while (i--) {
  3311. op = options[i];
  3312. val = op.hasOwnProperty('_value') ? op._value : op.value;
  3313. /* eslint-disable eqeqeq */
  3314. op.selected = multi ? indexOf$1(value, val) > -1 : looseEqual(value, val);
  3315. /* eslint-enable eqeqeq */
  3316. }
  3317. },
  3318. unbind: function unbind() {
  3319. /* istanbul ignore next */
  3320. this.vm.$off('hook:attached', this.forceUpdate);
  3321. }
  3322. };
  3323. /**
  3324. * Get select value
  3325. *
  3326. * @param {SelectElement} el
  3327. * @param {Boolean} multi
  3328. * @param {Boolean} init
  3329. * @return {Array|*}
  3330. */
  3331. function getValue(el, multi, init) {
  3332. var res = multi ? [] : null;
  3333. var op, val, selected;
  3334. for (var i = 0, l = el.options.length; i < l; i++) {
  3335. op = el.options[i];
  3336. selected = init ? op.hasAttribute('selected') : op.selected;
  3337. if (selected) {
  3338. val = op.hasOwnProperty('_value') ? op._value : op.value;
  3339. if (multi) {
  3340. res.push(val);
  3341. } else {
  3342. return val;
  3343. }
  3344. }
  3345. }
  3346. return res;
  3347. }
  3348. /**
  3349. * Native Array.indexOf uses strict equal, but in this
  3350. * case we need to match string/numbers with custom equal.
  3351. *
  3352. * @param {Array} arr
  3353. * @param {*} val
  3354. */
  3355. function indexOf$1(arr, val) {
  3356. var i = arr.length;
  3357. while (i--) {
  3358. if (looseEqual(arr[i], val)) {
  3359. return i;
  3360. }
  3361. }
  3362. return -1;
  3363. }
  3364. var radio = {
  3365. bind: function bind() {
  3366. var self = this;
  3367. var el = this.el;
  3368. this.getValue = function () {
  3369. // value overwrite via v-bind:value
  3370. if (el.hasOwnProperty('_value')) {
  3371. return el._value;
  3372. }
  3373. var val = el.value;
  3374. if (self.params.number) {
  3375. val = toNumber(val);
  3376. }
  3377. return val;
  3378. };
  3379. this.listener = function () {
  3380. self.set(self.getValue());
  3381. };
  3382. this.on('change', this.listener);
  3383. if (el.checked) {
  3384. this.afterBind = this.listener;
  3385. }
  3386. },
  3387. update: function update(value) {
  3388. this.el.checked = looseEqual(value, this.getValue());
  3389. }
  3390. };
  3391. var text$2 = {
  3392. bind: function bind() {
  3393. var self = this;
  3394. var el = this.el;
  3395. var isRange = el.type === 'range';
  3396. var lazy = this.params.lazy;
  3397. var number = this.params.number;
  3398. var debounce = this.params.debounce;
  3399. // handle composition events.
  3400. // http://blog.evanyou.me/2014/01/03/composition-event/
  3401. // skip this for Android because it handles composition
  3402. // events quite differently. Android doesn't trigger
  3403. // composition events for language input methods e.g.
  3404. // Chinese, but instead triggers them for spelling
  3405. // suggestions... (see Discussion/#162)
  3406. var composing = false;
  3407. if (!isAndroid && !isRange) {
  3408. this.on('compositionstart', function () {
  3409. composing = true;
  3410. });
  3411. this.on('compositionend', function () {
  3412. composing = false;
  3413. // in IE11 the "compositionend" event fires AFTER
  3414. // the "input" event, so the input handler is blocked
  3415. // at the end... have to call it here.
  3416. //
  3417. // #1327: in lazy mode this is unecessary.
  3418. if (!lazy) {
  3419. self.listener();
  3420. }
  3421. });
  3422. }
  3423. // prevent messing with the input when user is typing,
  3424. // and force update on blur.
  3425. this.focused = false;
  3426. if (!isRange) {
  3427. this.on('focus', function () {
  3428. self.focused = true;
  3429. });
  3430. this.on('blur', function () {
  3431. self.focused = false;
  3432. self.listener();
  3433. });
  3434. }
  3435. // Now attach the main listener
  3436. this.listener = function () {
  3437. if (composing) return;
  3438. var val = number || isRange ? toNumber(el.value) : el.value;
  3439. self.set(val);
  3440. // force update on next tick to avoid lock & same value
  3441. // also only update when user is not typing
  3442. nextTick(function () {
  3443. if (self._bound && !self.focused) {
  3444. self.update(self._watcher.value);
  3445. }
  3446. });
  3447. };
  3448. // apply debounce
  3449. if (debounce) {
  3450. this.listener = _debounce(this.listener, debounce);
  3451. }
  3452. // Support jQuery events, since jQuery.trigger() doesn't
  3453. // trigger native events in some cases and some plugins
  3454. // rely on $.trigger()
  3455. //
  3456. // We want to make sure if a listener is attached using
  3457. // jQuery, it is also removed with jQuery, that's why
  3458. // we do the check for each directive instance and
  3459. // store that check result on itself. This also allows
  3460. // easier test coverage control by unsetting the global
  3461. // jQuery variable in tests.
  3462. this.hasjQuery = typeof jQuery === 'function';
  3463. if (this.hasjQuery) {
  3464. jQuery(el).on('change', this.listener);
  3465. if (!lazy) {
  3466. jQuery(el).on('input', this.listener);
  3467. }
  3468. } else {
  3469. this.on('change', this.listener);
  3470. if (!lazy) {
  3471. this.on('input', this.listener);
  3472. }
  3473. }
  3474. // IE9 doesn't fire input event on backspace/del/cut
  3475. if (!lazy && isIE9) {
  3476. this.on('cut', function () {
  3477. nextTick(self.listener);
  3478. });
  3479. this.on('keyup', function (e) {
  3480. if (e.keyCode === 46 || e.keyCode === 8) {
  3481. self.listener();
  3482. }
  3483. });
  3484. }
  3485. // set initial value if present
  3486. if (el.hasAttribute('value') || el.tagName === 'TEXTAREA' && el.value.trim()) {
  3487. this.afterBind = this.listener;
  3488. }
  3489. },
  3490. update: function update(value) {
  3491. this.el.value = _toString(value);
  3492. },
  3493. unbind: function unbind() {
  3494. var el = this.el;
  3495. if (this.hasjQuery) {
  3496. jQuery(el).off('change', this.listener);
  3497. jQuery(el).off('input', this.listener);
  3498. }
  3499. }
  3500. };
  3501. var handlers = {
  3502. text: text$2,
  3503. radio: radio,
  3504. select: select,
  3505. checkbox: checkbox
  3506. };
  3507. var model = {
  3508. priority: 800,
  3509. twoWay: true,
  3510. handlers: handlers,
  3511. params: ['lazy', 'number', 'debounce'],
  3512. /**
  3513. * Possible elements:
  3514. * <select>
  3515. * <textarea>
  3516. * <input type="*">
  3517. * - text
  3518. * - checkbox
  3519. * - radio
  3520. * - number
  3521. */
  3522. bind: function bind() {
  3523. // friendly warning...
  3524. this.checkFilters();
  3525. if (this.hasRead && !this.hasWrite) {
  3526. 'development' !== 'production' && warn('It seems you are using a read-only filter with ' + 'v-model. You might want to use a two-way filter ' + 'to ensure correct behavior.');
  3527. }
  3528. var el = this.el;
  3529. var tag = el.tagName;
  3530. var handler;
  3531. if (tag === 'INPUT') {
  3532. handler = handlers[el.type] || handlers.text;
  3533. } else if (tag === 'SELECT') {
  3534. handler = handlers.select;
  3535. } else if (tag === 'TEXTAREA') {
  3536. handler = handlers.text;
  3537. } else {
  3538. 'development' !== 'production' && warn('v-model does not support element type: ' + tag);
  3539. return;
  3540. }
  3541. el.__v_model = this;
  3542. handler.bind.call(this);
  3543. this.update = handler.update;
  3544. this._unbind = handler.unbind;
  3545. },
  3546. /**
  3547. * Check read/write filter stats.
  3548. */
  3549. checkFilters: function checkFilters() {
  3550. var filters = this.filters;
  3551. if (!filters) return;
  3552. var i = filters.length;
  3553. while (i--) {
  3554. var filter = resolveAsset(this.vm.$options, 'filters', filters[i].name);
  3555. if (typeof filter === 'function' || filter.read) {
  3556. this.hasRead = true;
  3557. }
  3558. if (filter.write) {
  3559. this.hasWrite = true;
  3560. }
  3561. }
  3562. },
  3563. unbind: function unbind() {
  3564. this.el.__v_model = null;
  3565. this._unbind && this._unbind();
  3566. }
  3567. };
  3568. var show = {
  3569. bind: function bind() {
  3570. // check else block
  3571. var next = this.el.nextElementSibling;
  3572. if (next && getAttr(next, 'v-else') !== null) {
  3573. this.elseEl = next;
  3574. }
  3575. },
  3576. update: function update(value) {
  3577. this.apply(this.el, value);
  3578. if (this.elseEl) {
  3579. this.apply(this.elseEl, !value);
  3580. }
  3581. },
  3582. apply: function apply(el, value) {
  3583. applyTransition(el, value ? 1 : -1, function () {
  3584. el.style.display = value ? '' : 'none';
  3585. }, this.vm);
  3586. }
  3587. };
  3588. var templateCache = new Cache(1000);
  3589. var idSelectorCache = new Cache(1000);
  3590. var map = {
  3591. efault: [0, '', ''],
  3592. legend: [1, '<fieldset>', '</fieldset>'],
  3593. tr: [2, '<table><tbody>', '</tbody></table>'],
  3594. col: [2, '<table><tbody></tbody><colgroup>', '</colgroup></table>']
  3595. };
  3596. map.td = map.th = [3, '<table><tbody><tr>', '</tr></tbody></table>'];
  3597. map.option = map.optgroup = [1, '<select multiple="multiple">', '</select>'];
  3598. map.thead = map.tbody = map.colgroup = map.caption = map.tfoot = [1, '<table>', '</table>'];
  3599. map.g = map.defs = map.symbol = map.use = map.image = map.text = map.circle = map.ellipse = map.line = map.path = map.polygon = map.polyline = map.rect = [1, '<svg ' + 'xmlns="http://www.w3.org/2000/svg" ' + 'xmlns:xlink="http://www.w3.org/1999/xlink" ' + 'xmlns:ev="http://www.w3.org/2001/xml-events"' + 'version="1.1">', '</svg>'];
  3600. /**
  3601. * Check if a node is a supported template node with a
  3602. * DocumentFragment content.
  3603. *
  3604. * @param {Node} node
  3605. * @return {Boolean}
  3606. */
  3607. function isRealTemplate(node) {
  3608. return isTemplate(node) && node.content instanceof DocumentFragment;
  3609. }
  3610. var tagRE$1 = /<([\w:]+)/;
  3611. var entityRE = /&\w+;|&#\d+;|&#x[\dA-F]+;/;
  3612. /**
  3613. * Convert a string template to a DocumentFragment.
  3614. * Determines correct wrapping by tag types. Wrapping
  3615. * strategy found in jQuery & component/domify.
  3616. *
  3617. * @param {String} templateString
  3618. * @param {Boolean} raw
  3619. * @return {DocumentFragment}
  3620. */
  3621. function stringToFragment(templateString, raw) {
  3622. // try a cache hit first
  3623. var hit = templateCache.get(templateString);
  3624. if (hit) {
  3625. return hit;
  3626. }
  3627. var frag = document.createDocumentFragment();
  3628. var tagMatch = templateString.match(tagRE$1);
  3629. var entityMatch = entityRE.test(templateString);
  3630. if (!tagMatch && !entityMatch) {
  3631. // text only, return a single text node.
  3632. frag.appendChild(document.createTextNode(templateString));
  3633. } else {
  3634. var tag = tagMatch && tagMatch[1];
  3635. var wrap = map[tag] || map.efault;
  3636. var depth = wrap[0];
  3637. var prefix = wrap[1];
  3638. var suffix = wrap[2];
  3639. var node = document.createElement('div');
  3640. if (!raw) {
  3641. templateString = templateString.trim();
  3642. }
  3643. node.innerHTML = prefix + templateString + suffix;
  3644. while (depth--) {
  3645. node = node.lastChild;
  3646. }
  3647. var child;
  3648. /* eslint-disable no-cond-assign */
  3649. while (child = node.firstChild) {
  3650. /* eslint-enable no-cond-assign */
  3651. frag.appendChild(child);
  3652. }
  3653. }
  3654. templateCache.put(templateString, frag);
  3655. return frag;
  3656. }
  3657. /**
  3658. * Convert a template node to a DocumentFragment.
  3659. *
  3660. * @param {Node} node
  3661. * @return {DocumentFragment}
  3662. */
  3663. function nodeToFragment(node) {
  3664. // if its a template tag and the browser supports it,
  3665. // its content is already a document fragment.
  3666. if (isRealTemplate(node)) {
  3667. trimNode(node.content);
  3668. return node.content;
  3669. }
  3670. // script template
  3671. if (node.tagName === 'SCRIPT') {
  3672. return stringToFragment(node.textContent);
  3673. }
  3674. // normal node, clone it to avoid mutating the original
  3675. var clonedNode = cloneNode(node);
  3676. var frag = document.createDocumentFragment();
  3677. var child;
  3678. /* eslint-disable no-cond-assign */
  3679. while (child = clonedNode.firstChild) {
  3680. /* eslint-enable no-cond-assign */
  3681. frag.appendChild(child);
  3682. }
  3683. trimNode(frag);
  3684. return frag;
  3685. }
  3686. // Test for the presence of the Safari template cloning bug
  3687. // https://bugs.webkit.org/showug.cgi?id=137755
  3688. var hasBrokenTemplate = (function () {
  3689. /* istanbul ignore else */
  3690. if (inBrowser) {
  3691. var a = document.createElement('div');
  3692. a.innerHTML = '<template>1</template>';
  3693. return !a.cloneNode(true).firstChild.innerHTML;
  3694. } else {
  3695. return false;
  3696. }
  3697. })();
  3698. // Test for IE10/11 textarea placeholder clone bug
  3699. var hasTextareaCloneBug = (function () {
  3700. /* istanbul ignore else */
  3701. if (inBrowser) {
  3702. var t = document.createElement('textarea');
  3703. t.placeholder = 't';
  3704. return t.cloneNode(true).value === 't';
  3705. } else {
  3706. return false;
  3707. }
  3708. })();
  3709. /**
  3710. * 1. Deal with Safari cloning nested <template> bug by
  3711. * manually cloning all template instances.
  3712. * 2. Deal with IE10/11 textarea placeholder bug by setting
  3713. * the correct value after cloning.
  3714. *
  3715. * @param {Element|DocumentFragment} node
  3716. * @return {Element|DocumentFragment}
  3717. */
  3718. function cloneNode(node) {
  3719. if (!node.querySelectorAll) {
  3720. return node.cloneNode();
  3721. }
  3722. var res = node.cloneNode(true);
  3723. var i, original, cloned;
  3724. /* istanbul ignore if */
  3725. if (hasBrokenTemplate) {
  3726. var tempClone = res;
  3727. if (isRealTemplate(node)) {
  3728. node = node.content;
  3729. tempClone = res.content;
  3730. }
  3731. original = node.querySelectorAll('template');
  3732. if (original.length) {
  3733. cloned = tempClone.querySelectorAll('template');
  3734. i = cloned.length;
  3735. while (i--) {
  3736. cloned[i].parentNode.replaceChild(cloneNode(original[i]), cloned[i]);
  3737. }
  3738. }
  3739. }
  3740. /* istanbul ignore if */
  3741. if (hasTextareaCloneBug) {
  3742. if (node.tagName === 'TEXTAREA') {
  3743. res.value = node.value;
  3744. } else {
  3745. original = node.querySelectorAll('textarea');
  3746. if (original.length) {
  3747. cloned = res.querySelectorAll('textarea');
  3748. i = cloned.length;
  3749. while (i--) {
  3750. cloned[i].value = original[i].value;
  3751. }
  3752. }
  3753. }
  3754. }
  3755. return res;
  3756. }
  3757. /**
  3758. * Process the template option and normalizes it into a
  3759. * a DocumentFragment that can be used as a partial or a
  3760. * instance template.
  3761. *
  3762. * @param {*} template
  3763. * Possible values include:
  3764. * - DocumentFragment object
  3765. * - Node object of type Template
  3766. * - id selector: '#some-template-id'
  3767. * - template string: '<div><span>{{msg}}</span></div>'
  3768. * @param {Boolean} shouldClone
  3769. * @param {Boolean} raw
  3770. * inline HTML interpolation. Do not check for id
  3771. * selector and keep whitespace in the string.
  3772. * @return {DocumentFragment|undefined}
  3773. */
  3774. function parseTemplate(template, shouldClone, raw) {
  3775. var node, frag;
  3776. // if the template is already a document fragment,
  3777. // do nothing
  3778. if (template instanceof DocumentFragment) {
  3779. trimNode(template);
  3780. return shouldClone ? cloneNode(template) : template;
  3781. }
  3782. if (typeof template === 'string') {
  3783. // id selector
  3784. if (!raw && template.charAt(0) === '#') {
  3785. // id selector can be cached too
  3786. frag = idSelectorCache.get(template);
  3787. if (!frag) {
  3788. node = document.getElementById(template.slice(1));
  3789. if (node) {
  3790. frag = nodeToFragment(node);
  3791. // save selector to cache
  3792. idSelectorCache.put(template, frag);
  3793. }
  3794. }
  3795. } else {
  3796. // normal string template
  3797. frag = stringToFragment(template, raw);
  3798. }
  3799. } else if (template.nodeType) {
  3800. // a direct node
  3801. frag = nodeToFragment(template);
  3802. }
  3803. return frag && shouldClone ? cloneNode(frag) : frag;
  3804. }
  3805. var template = Object.freeze({
  3806. cloneNode: cloneNode,
  3807. parseTemplate: parseTemplate
  3808. });
  3809. /**
  3810. * Abstraction for a partially-compiled fragment.
  3811. * Can optionally compile content with a child scope.
  3812. *
  3813. * @param {Function} linker
  3814. * @param {Vue} vm
  3815. * @param {DocumentFragment} frag
  3816. * @param {Vue} [host]
  3817. * @param {Object} [scope]
  3818. */
  3819. function Fragment(linker, vm, frag, host, scope, parentFrag) {
  3820. this.children = [];
  3821. this.childFrags = [];
  3822. this.vm = vm;
  3823. this.scope = scope;
  3824. this.inserted = false;
  3825. this.parentFrag = parentFrag;
  3826. if (parentFrag) {
  3827. parentFrag.childFrags.push(this);
  3828. }
  3829. this.unlink = linker(vm, frag, host, scope, this);
  3830. var single = this.single = frag.childNodes.length === 1 &&
  3831. // do not go single mode if the only node is an anchor
  3832. !frag.childNodes[0].__vue_anchor;
  3833. if (single) {
  3834. this.node = frag.childNodes[0];
  3835. this.before = singleBefore;
  3836. this.remove = singleRemove;
  3837. } else {
  3838. this.node = createAnchor('fragment-start');
  3839. this.end = createAnchor('fragment-end');
  3840. this.frag = frag;
  3841. prepend(this.node, frag);
  3842. frag.appendChild(this.end);
  3843. this.before = multiBefore;
  3844. this.remove = multiRemove;
  3845. }
  3846. this.node.__vfrag__ = this;
  3847. }
  3848. /**
  3849. * Call attach/detach for all components contained within
  3850. * this fragment. Also do so recursively for all child
  3851. * fragments.
  3852. *
  3853. * @param {Function} hook
  3854. */
  3855. Fragment.prototype.callHook = function (hook) {
  3856. var i, l;
  3857. for (i = 0, l = this.children.length; i < l; i++) {
  3858. hook(this.children[i]);
  3859. }
  3860. for (i = 0, l = this.childFrags.length; i < l; i++) {
  3861. this.childFrags[i].callHook(hook);
  3862. }
  3863. };
  3864. /**
  3865. * Destroy the fragment.
  3866. */
  3867. Fragment.prototype.destroy = function () {
  3868. if (this.parentFrag) {
  3869. this.parentFrag.childFrags.$remove(this);
  3870. }
  3871. this.unlink();
  3872. };
  3873. /**
  3874. * Insert fragment before target, single node version
  3875. *
  3876. * @param {Node} target
  3877. * @param {Boolean} withTransition
  3878. */
  3879. function singleBefore(target, withTransition) {
  3880. this.inserted = true;
  3881. var method = withTransition !== false ? beforeWithTransition : before;
  3882. method(this.node, target, this.vm);
  3883. if (inDoc(this.node)) {
  3884. this.callHook(attach);
  3885. }
  3886. }
  3887. /**
  3888. * Remove fragment, single node version
  3889. */
  3890. function singleRemove() {
  3891. this.inserted = false;
  3892. var shouldCallRemove = inDoc(this.node);
  3893. var self = this;
  3894. self.callHook(destroyChild);
  3895. removeWithTransition(this.node, this.vm, function () {
  3896. if (shouldCallRemove) {
  3897. self.callHook(detach);
  3898. }
  3899. self.destroy();
  3900. });
  3901. }
  3902. /**
  3903. * Insert fragment before target, multi-nodes version
  3904. *
  3905. * @param {Node} target
  3906. * @param {Boolean} withTransition
  3907. */
  3908. function multiBefore(target, withTransition) {
  3909. this.inserted = true;
  3910. var vm = this.vm;
  3911. var method = withTransition !== false ? beforeWithTransition : before;
  3912. mapNodeRange(this.node, this.end, function (node) {
  3913. method(node, target, vm);
  3914. });
  3915. if (inDoc(this.node)) {
  3916. this.callHook(attach);
  3917. }
  3918. }
  3919. /**
  3920. * Remove fragment, multi-nodes version
  3921. */
  3922. function multiRemove() {
  3923. this.inserted = false;
  3924. var self = this;
  3925. var shouldCallRemove = inDoc(this.node);
  3926. self.callHook(destroyChild);
  3927. removeNodeRange(this.node, this.end, this.vm, this.frag, function () {
  3928. if (shouldCallRemove) {
  3929. self.callHook(detach);
  3930. }
  3931. self.destroy();
  3932. });
  3933. }
  3934. /**
  3935. * Call attach hook for a Vue instance.
  3936. *
  3937. * @param {Vue} child
  3938. */
  3939. function attach(child) {
  3940. if (!child._isAttached) {
  3941. child._callHook('attached');
  3942. }
  3943. }
  3944. /**
  3945. * Call destroy for all contained instances,
  3946. * with remove:false and defer:true.
  3947. * Defer is necessary because we need to
  3948. * keep the children to call detach hooks
  3949. * on them.
  3950. *
  3951. * @param {Vue} child
  3952. */
  3953. function destroyChild(child) {
  3954. child.$destroy(false, true);
  3955. }
  3956. /**
  3957. * Call detach hook for a Vue instance.
  3958. *
  3959. * @param {Vue} child
  3960. */
  3961. function detach(child) {
  3962. if (child._isAttached) {
  3963. child._callHook('detached');
  3964. }
  3965. }
  3966. var linkerCache = new Cache(5000);
  3967. /**
  3968. * A factory that can be used to create instances of a
  3969. * fragment. Caches the compiled linker if possible.
  3970. *
  3971. * @param {Vue} vm
  3972. * @param {Element|String} el
  3973. */
  3974. function FragmentFactory(vm, el) {
  3975. this.vm = vm;
  3976. var template;
  3977. var isString = typeof el === 'string';
  3978. if (isString || isTemplate(el)) {
  3979. template = parseTemplate(el, true);
  3980. } else {
  3981. template = document.createDocumentFragment();
  3982. template.appendChild(el);
  3983. }
  3984. this.template = template;
  3985. // linker can be cached, but only for components
  3986. var linker;
  3987. var cid = vm.constructor.cid;
  3988. if (cid > 0) {
  3989. var cacheId = cid + (isString ? el : el.outerHTML);
  3990. linker = linkerCache.get(cacheId);
  3991. if (!linker) {
  3992. linker = compile(template, vm.$options, true);
  3993. linkerCache.put(cacheId, linker);
  3994. }
  3995. } else {
  3996. linker = compile(template, vm.$options, true);
  3997. }
  3998. this.linker = linker;
  3999. }
  4000. /**
  4001. * Create a fragment instance with given host and scope.
  4002. *
  4003. * @param {Vue} host
  4004. * @param {Object} scope
  4005. * @param {Fragment} parentFrag
  4006. */
  4007. FragmentFactory.prototype.create = function (host, scope, parentFrag) {
  4008. var frag = cloneNode(this.template);
  4009. return new Fragment(this.linker, this.vm, frag, host, scope, parentFrag);
  4010. };
  4011. var vIf = {
  4012. priority: 2000,
  4013. bind: function bind() {
  4014. var el = this.el;
  4015. if (!el.__vue__) {
  4016. // check else block
  4017. var next = el.nextElementSibling;
  4018. if (next && getAttr(next, 'v-else') !== null) {
  4019. remove(next);
  4020. this.elseFactory = new FragmentFactory(this.vm, next);
  4021. }
  4022. // check main block
  4023. this.anchor = createAnchor('v-if');
  4024. replace(el, this.anchor);
  4025. this.factory = new FragmentFactory(this.vm, el);
  4026. } else {
  4027. 'development' !== 'production' && warn('v-if="' + this.expression + '" cannot be ' + 'used on an instance root element.');
  4028. this.invalid = true;
  4029. }
  4030. },
  4031. update: function update(value) {
  4032. if (this.invalid) return;
  4033. if (value) {
  4034. if (!this.frag) {
  4035. this.insert();
  4036. }
  4037. } else {
  4038. this.remove();
  4039. }
  4040. },
  4041. insert: function insert() {
  4042. if (this.elseFrag) {
  4043. this.elseFrag.remove();
  4044. this.elseFrag = null;
  4045. }
  4046. this.frag = this.factory.create(this._host, this._scope, this._frag);
  4047. this.frag.before(this.anchor);
  4048. },
  4049. remove: function remove() {
  4050. if (this.frag) {
  4051. this.frag.remove();
  4052. this.frag = null;
  4053. }
  4054. if (this.elseFactory && !this.elseFrag) {
  4055. this.elseFrag = this.elseFactory.create(this._host, this._scope, this._frag);
  4056. this.elseFrag.before(this.anchor);
  4057. }
  4058. },
  4059. unbind: function unbind() {
  4060. if (this.frag) {
  4061. this.frag.destroy();
  4062. }
  4063. }
  4064. };
  4065. var uid$1 = 0;
  4066. var vFor = {
  4067. priority: 2000,
  4068. params: ['track-by', 'stagger', 'enter-stagger', 'leave-stagger'],
  4069. bind: function bind() {
  4070. // support "item in items" syntax
  4071. var inMatch = this.expression.match(/(.*) in (.*)/);
  4072. if (inMatch) {
  4073. var itMatch = inMatch[1].match(/\((.*),(.*)\)/);
  4074. if (itMatch) {
  4075. this.iterator = itMatch[1].trim();
  4076. this.alias = itMatch[2].trim();
  4077. } else {
  4078. this.alias = inMatch[1].trim();
  4079. }
  4080. this.expression = inMatch[2];
  4081. }
  4082. if (!this.alias) {
  4083. 'development' !== 'production' && warn('Alias is required in v-for.');
  4084. return;
  4085. }
  4086. // uid as a cache identifier
  4087. this.id = '__v-for__' + ++uid$1;
  4088. // check if this is an option list,
  4089. // so that we know if we need to update the <select>'s
  4090. // v-model when the option list has changed.
  4091. // because v-model has a lower priority than v-for,
  4092. // the v-model is not bound here yet, so we have to
  4093. // retrive it in the actual updateModel() function.
  4094. var tag = this.el.tagName;
  4095. this.isOption = (tag === 'OPTION' || tag === 'OPTGROUP') && this.el.parentNode.tagName === 'SELECT';
  4096. // setup anchor nodes
  4097. this.start = createAnchor('v-for-start');
  4098. this.end = createAnchor('v-for-end');
  4099. replace(this.el, this.end);
  4100. before(this.start, this.end);
  4101. // cache
  4102. this.cache = Object.create(null);
  4103. // fragment factory
  4104. this.factory = new FragmentFactory(this.vm, this.el);
  4105. },
  4106. update: function update(data) {
  4107. this.diff(data);
  4108. this.updateRef();
  4109. this.updateModel();
  4110. },
  4111. /**
  4112. * Diff, based on new data and old data, determine the
  4113. * minimum amount of DOM manipulations needed to make the
  4114. * DOM reflect the new data Array.
  4115. *
  4116. * The algorithm diffs the new data Array by storing a
  4117. * hidden reference to an owner vm instance on previously
  4118. * seen data. This allows us to achieve O(n) which is
  4119. * better than a levenshtein distance based algorithm,
  4120. * which is O(m * n).
  4121. *
  4122. * @param {Array} data
  4123. */
  4124. diff: function diff(data) {
  4125. // check if the Array was converted from an Object
  4126. var item = data[0];
  4127. var convertedFromObject = this.fromObject = isObject(item) && hasOwn(item, '$key') && hasOwn(item, '$value');
  4128. var trackByKey = this.params.trackBy;
  4129. var oldFrags = this.frags;
  4130. var frags = this.frags = new Array(data.length);
  4131. var alias = this.alias;
  4132. var iterator = this.iterator;
  4133. var start = this.start;
  4134. var end = this.end;
  4135. var inDocument = inDoc(start);
  4136. var init = !oldFrags;
  4137. var i, l, frag, key, value, primitive;
  4138. // First pass, go through the new Array and fill up
  4139. // the new frags array. If a piece of data has a cached
  4140. // instance for it, we reuse it. Otherwise build a new
  4141. // instance.
  4142. for (i = 0, l = data.length; i < l; i++) {
  4143. item = data[i];
  4144. key = convertedFromObject ? item.$key : null;
  4145. value = convertedFromObject ? item.$value : item;
  4146. primitive = !isObject(value);
  4147. frag = !init && this.getCachedFrag(value, i, key);
  4148. if (frag) {
  4149. // reusable fragment
  4150. frag.reused = true;
  4151. // update $index
  4152. frag.scope.$index = i;
  4153. // update $key
  4154. if (key) {
  4155. frag.scope.$key = key;
  4156. }
  4157. // update iterator
  4158. if (iterator) {
  4159. frag.scope[iterator] = key !== null ? key : i;
  4160. }
  4161. // update data for track-by, object repeat &
  4162. // primitive values.
  4163. if (trackByKey || convertedFromObject || primitive) {
  4164. frag.scope[alias] = value;
  4165. }
  4166. } else {
  4167. // new isntance
  4168. frag = this.create(value, alias, i, key);
  4169. frag.fresh = !init;
  4170. }
  4171. frags[i] = frag;
  4172. if (init) {
  4173. frag.before(end);
  4174. }
  4175. }
  4176. // we're done for the initial render.
  4177. if (init) {
  4178. return;
  4179. }
  4180. // Second pass, go through the old fragments and
  4181. // destroy those who are not reused (and remove them
  4182. // from cache)
  4183. var removalIndex = 0;
  4184. var totalRemoved = oldFrags.length - frags.length;
  4185. for (i = 0, l = oldFrags.length; i < l; i++) {
  4186. frag = oldFrags[i];
  4187. if (!frag.reused) {
  4188. this.deleteCachedFrag(frag);
  4189. this.remove(frag, removalIndex++, totalRemoved, inDocument);
  4190. }
  4191. }
  4192. // Final pass, move/insert new fragments into the
  4193. // right place.
  4194. var targetPrev, prevEl, currentPrev;
  4195. var insertionIndex = 0;
  4196. for (i = 0, l = frags.length; i < l; i++) {
  4197. frag = frags[i];
  4198. // this is the frag that we should be after
  4199. targetPrev = frags[i - 1];
  4200. prevEl = targetPrev ? targetPrev.staggerCb ? targetPrev.staggerAnchor : targetPrev.end || targetPrev.node : start;
  4201. if (frag.reused && !frag.staggerCb) {
  4202. currentPrev = findPrevFrag(frag, start, this.id);
  4203. if (currentPrev !== targetPrev && (!currentPrev ||
  4204. // optimization for moving a single item.
  4205. // thanks to suggestions by @livoras in #1807
  4206. findPrevFrag(currentPrev, start, this.id) !== targetPrev)) {
  4207. this.move(frag, prevEl);
  4208. }
  4209. } else {
  4210. // new instance, or still in stagger.
  4211. // insert with updated stagger index.
  4212. this.insert(frag, insertionIndex++, prevEl, inDocument);
  4213. }
  4214. frag.reused = frag.fresh = false;
  4215. }
  4216. },
  4217. /**
  4218. * Create a new fragment instance.
  4219. *
  4220. * @param {*} value
  4221. * @param {String} alias
  4222. * @param {Number} index
  4223. * @param {String} [key]
  4224. * @return {Fragment}
  4225. */
  4226. create: function create(value, alias, index, key) {
  4227. var host = this._host;
  4228. // create iteration scope
  4229. var parentScope = this._scope || this.vm;
  4230. var scope = Object.create(parentScope);
  4231. // ref holder for the scope
  4232. scope.$refs = Object.create(parentScope.$refs);
  4233. scope.$els = Object.create(parentScope.$els);
  4234. // make sure point $parent to parent scope
  4235. scope.$parent = parentScope;
  4236. // for two-way binding on alias
  4237. scope.$forContext = this;
  4238. // define scope properties
  4239. defineReactive(scope, alias, value);
  4240. defineReactive(scope, '$index', index);
  4241. if (key) {
  4242. defineReactive(scope, '$key', key);
  4243. } else if (scope.$key) {
  4244. // avoid accidental fallback
  4245. def(scope, '$key', null);
  4246. }
  4247. if (this.iterator) {
  4248. defineReactive(scope, this.iterator, key !== null ? key : index);
  4249. }
  4250. var frag = this.factory.create(host, scope, this._frag);
  4251. frag.forId = this.id;
  4252. this.cacheFrag(value, frag, index, key);
  4253. return frag;
  4254. },
  4255. /**
  4256. * Update the v-ref on owner vm.
  4257. */
  4258. updateRef: function updateRef() {
  4259. var ref = this.descriptor.ref;
  4260. if (!ref) return;
  4261. var hash = (this._scope || this.vm).$refs;
  4262. var refs;
  4263. if (!this.fromObject) {
  4264. refs = this.frags.map(findVmFromFrag);
  4265. } else {
  4266. refs = {};
  4267. this.frags.forEach(function (frag) {
  4268. refs[frag.scope.$key] = findVmFromFrag(frag);
  4269. });
  4270. }
  4271. hash[ref] = refs;
  4272. },
  4273. /**
  4274. * For option lists, update the containing v-model on
  4275. * parent <select>.
  4276. */
  4277. updateModel: function updateModel() {
  4278. if (this.isOption) {
  4279. var parent = this.start.parentNode;
  4280. var model = parent && parent.__v_model;
  4281. if (model) {
  4282. model.forceUpdate();
  4283. }
  4284. }
  4285. },
  4286. /**
  4287. * Insert a fragment. Handles staggering.
  4288. *
  4289. * @param {Fragment} frag
  4290. * @param {Number} index
  4291. * @param {Node} prevEl
  4292. * @param {Boolean} inDocument
  4293. */
  4294. insert: function insert(frag, index, prevEl, inDocument) {
  4295. if (frag.staggerCb) {
  4296. frag.staggerCb.cancel();
  4297. frag.staggerCb = null;
  4298. }
  4299. var staggerAmount = this.getStagger(frag, index, null, 'enter');
  4300. if (inDocument && staggerAmount) {
  4301. // create an anchor and insert it synchronously,
  4302. // so that we can resolve the correct order without
  4303. // worrying about some elements not inserted yet
  4304. var anchor = frag.staggerAnchor;
  4305. if (!anchor) {
  4306. anchor = frag.staggerAnchor = createAnchor('stagger-anchor');
  4307. anchor.__vfrag__ = frag;
  4308. }
  4309. after(anchor, prevEl);
  4310. var op = frag.staggerCb = cancellable(function () {
  4311. frag.staggerCb = null;
  4312. frag.before(anchor);
  4313. remove(anchor);
  4314. });
  4315. setTimeout(op, staggerAmount);
  4316. } else {
  4317. frag.before(prevEl.nextSibling);
  4318. }
  4319. },
  4320. /**
  4321. * Remove a fragment. Handles staggering.
  4322. *
  4323. * @param {Fragment} frag
  4324. * @param {Number} index
  4325. * @param {Number} total
  4326. * @param {Boolean} inDocument
  4327. */
  4328. remove: function remove(frag, index, total, inDocument) {
  4329. if (frag.staggerCb) {
  4330. frag.staggerCb.cancel();
  4331. frag.staggerCb = null;
  4332. // it's not possible for the same frag to be removed
  4333. // twice, so if we have a pending stagger callback,
  4334. // it means this frag is queued for enter but removed
  4335. // before its transition started. Since it is already
  4336. // destroyed, we can just leave it in detached state.
  4337. return;
  4338. }
  4339. var staggerAmount = this.getStagger(frag, index, total, 'leave');
  4340. if (inDocument && staggerAmount) {
  4341. var op = frag.staggerCb = cancellable(function () {
  4342. frag.staggerCb = null;
  4343. frag.remove();
  4344. });
  4345. setTimeout(op, staggerAmount);
  4346. } else {
  4347. frag.remove();
  4348. }
  4349. },
  4350. /**
  4351. * Move a fragment to a new position.
  4352. * Force no transition.
  4353. *
  4354. * @param {Fragment} frag
  4355. * @param {Node} prevEl
  4356. */
  4357. move: function move(frag, prevEl) {
  4358. frag.before(prevEl.nextSibling, false);
  4359. },
  4360. /**
  4361. * Cache a fragment using track-by or the object key.
  4362. *
  4363. * @param {*} value
  4364. * @param {Fragment} frag
  4365. * @param {Number} index
  4366. * @param {String} [key]
  4367. */
  4368. cacheFrag: function cacheFrag(value, frag, index, key) {
  4369. var trackByKey = this.params.trackBy;
  4370. var cache = this.cache;
  4371. var primitive = !isObject(value);
  4372. var id;
  4373. if (key || trackByKey || primitive) {
  4374. id = trackByKey ? trackByKey === '$index' ? index : value[trackByKey] : key || value;
  4375. if (!cache[id]) {
  4376. cache[id] = frag;
  4377. } else if (trackByKey !== '$index') {
  4378. 'development' !== 'production' && this.warnDuplicate(value);
  4379. }
  4380. } else {
  4381. id = this.id;
  4382. if (hasOwn(value, id)) {
  4383. if (value[id] === null) {
  4384. value[id] = frag;
  4385. } else {
  4386. 'development' !== 'production' && this.warnDuplicate(value);
  4387. }
  4388. } else {
  4389. def(value, id, frag);
  4390. }
  4391. }
  4392. frag.raw = value;
  4393. },
  4394. /**
  4395. * Get a cached fragment from the value/index/key
  4396. *
  4397. * @param {*} value
  4398. * @param {Number} index
  4399. * @param {String} key
  4400. * @return {Fragment}
  4401. */
  4402. getCachedFrag: function getCachedFrag(value, index, key) {
  4403. var trackByKey = this.params.trackBy;
  4404. var primitive = !isObject(value);
  4405. var frag;
  4406. if (key || trackByKey || primitive) {
  4407. var id = trackByKey ? trackByKey === '$index' ? index : value[trackByKey] : key || value;
  4408. frag = this.cache[id];
  4409. } else {
  4410. frag = value[this.id];
  4411. }
  4412. if (frag && (frag.reused || frag.fresh)) {
  4413. 'development' !== 'production' && this.warnDuplicate(value);
  4414. }
  4415. return frag;
  4416. },
  4417. /**
  4418. * Delete a fragment from cache.
  4419. *
  4420. * @param {Fragment} frag
  4421. */
  4422. deleteCachedFrag: function deleteCachedFrag(frag) {
  4423. var value = frag.raw;
  4424. var trackByKey = this.params.trackBy;
  4425. var scope = frag.scope;
  4426. var index = scope.$index;
  4427. // fix #948: avoid accidentally fall through to
  4428. // a parent repeater which happens to have $key.
  4429. var key = hasOwn(scope, '$key') && scope.$key;
  4430. var primitive = !isObject(value);
  4431. if (trackByKey || key || primitive) {
  4432. var id = trackByKey ? trackByKey === '$index' ? index : value[trackByKey] : key || value;
  4433. this.cache[id] = null;
  4434. } else {
  4435. value[this.id] = null;
  4436. frag.raw = null;
  4437. }
  4438. },
  4439. /**
  4440. * Get the stagger amount for an insertion/removal.
  4441. *
  4442. * @param {Fragment} frag
  4443. * @param {Number} index
  4444. * @param {Number} total
  4445. * @param {String} type
  4446. */
  4447. getStagger: function getStagger(frag, index, total, type) {
  4448. type = type + 'Stagger';
  4449. var trans = frag.node.__v_trans;
  4450. var hooks = trans && trans.hooks;
  4451. var hook = hooks && (hooks[type] || hooks.stagger);
  4452. return hook ? hook.call(frag, index, total) : index * parseInt(this.params[type] || this.params.stagger, 10);
  4453. },
  4454. /**
  4455. * Pre-process the value before piping it through the
  4456. * filters. This is passed to and called by the watcher.
  4457. */
  4458. _preProcess: function _preProcess(value) {
  4459. // regardless of type, store the un-filtered raw value.
  4460. this.rawValue = value;
  4461. return value;
  4462. },
  4463. /**
  4464. * Post-process the value after it has been piped through
  4465. * the filters. This is passed to and called by the watcher.
  4466. *
  4467. * It is necessary for this to be called during the
  4468. * wathcer's dependency collection phase because we want
  4469. * the v-for to update when the source Object is mutated.
  4470. */
  4471. _postProcess: function _postProcess(value) {
  4472. if (isArray(value)) {
  4473. return value;
  4474. } else if (isPlainObject(value)) {
  4475. // convert plain object to array.
  4476. var keys = Object.keys(value);
  4477. var i = keys.length;
  4478. var res = new Array(i);
  4479. var key;
  4480. while (i--) {
  4481. key = keys[i];
  4482. res[i] = {
  4483. $key: key,
  4484. $value: value[key]
  4485. };
  4486. }
  4487. return res;
  4488. } else {
  4489. if (typeof value === 'number') {
  4490. value = range(value);
  4491. }
  4492. return value || [];
  4493. }
  4494. },
  4495. unbind: function unbind() {
  4496. if (this.descriptor.ref) {
  4497. (this._scope || this.vm).$refs[this.descriptor.ref] = null;
  4498. }
  4499. if (this.frags) {
  4500. var i = this.frags.length;
  4501. var frag;
  4502. while (i--) {
  4503. frag = this.frags[i];
  4504. this.deleteCachedFrag(frag);
  4505. frag.destroy();
  4506. }
  4507. }
  4508. }
  4509. };
  4510. /**
  4511. * Helper to find the previous element that is a fragment
  4512. * anchor. This is necessary because a destroyed frag's
  4513. * element could still be lingering in the DOM before its
  4514. * leaving transition finishes, but its inserted flag
  4515. * should have been set to false so we can skip them.
  4516. *
  4517. * If this is a block repeat, we want to make sure we only
  4518. * return frag that is bound to this v-for. (see #929)
  4519. *
  4520. * @param {Fragment} frag
  4521. * @param {Comment|Text} anchor
  4522. * @param {String} id
  4523. * @return {Fragment}
  4524. */
  4525. function findPrevFrag(frag, anchor, id) {
  4526. var el = frag.node.previousSibling;
  4527. /* istanbul ignore if */
  4528. if (!el) return;
  4529. frag = el.__vfrag__;
  4530. while ((!frag || frag.forId !== id || !frag.inserted) && el !== anchor) {
  4531. el = el.previousSibling;
  4532. /* istanbul ignore if */
  4533. if (!el) return;
  4534. frag = el.__vfrag__;
  4535. }
  4536. return frag;
  4537. }
  4538. /**
  4539. * Find a vm from a fragment.
  4540. *
  4541. * @param {Fragment} frag
  4542. * @return {Vue|undefined}
  4543. */
  4544. function findVmFromFrag(frag) {
  4545. var node = frag.node;
  4546. // handle multi-node frag
  4547. if (frag.end) {
  4548. while (!node.__vue__ && node !== frag.end && node.nextSibling) {
  4549. node = node.nextSibling;
  4550. }
  4551. }
  4552. return node.__vue__;
  4553. }
  4554. /**
  4555. * Create a range array from given number.
  4556. *
  4557. * @param {Number} n
  4558. * @return {Array}
  4559. */
  4560. function range(n) {
  4561. var i = -1;
  4562. var ret = new Array(n);
  4563. while (++i < n) {
  4564. ret[i] = i;
  4565. }
  4566. return ret;
  4567. }
  4568. if ('development' !== 'production') {
  4569. vFor.warnDuplicate = function (value) {
  4570. warn('Duplicate value found in v-for="' + this.descriptor.raw + '": ' + JSON.stringify(value) + '. Use track-by="$index" if ' + 'you are expecting duplicate values.');
  4571. };
  4572. }
  4573. var html = {
  4574. bind: function bind() {
  4575. // a comment node means this is a binding for
  4576. // {{{ inline unescaped html }}}
  4577. if (this.el.nodeType === 8) {
  4578. // hold nodes
  4579. this.nodes = [];
  4580. // replace the placeholder with proper anchor
  4581. this.anchor = createAnchor('v-html');
  4582. replace(this.el, this.anchor);
  4583. }
  4584. },
  4585. update: function update(value) {
  4586. value = _toString(value);
  4587. if (this.nodes) {
  4588. this.swap(value);
  4589. } else {
  4590. this.el.innerHTML = value;
  4591. }
  4592. },
  4593. swap: function swap(value) {
  4594. // remove old nodes
  4595. var i = this.nodes.length;
  4596. while (i--) {
  4597. remove(this.nodes[i]);
  4598. }
  4599. // convert new value to a fragment
  4600. // do not attempt to retrieve from id selector
  4601. var frag = parseTemplate(value, true, true);
  4602. // save a reference to these nodes so we can remove later
  4603. this.nodes = toArray(frag.childNodes);
  4604. before(frag, this.anchor);
  4605. }
  4606. };
  4607. var text = {
  4608. bind: function bind() {
  4609. this.attr = this.el.nodeType === 3 ? 'data' : 'textContent';
  4610. },
  4611. update: function update(value) {
  4612. this.el[this.attr] = _toString(value);
  4613. }
  4614. };
  4615. // must export plain object
  4616. var publicDirectives = {
  4617. text: text,
  4618. html: html,
  4619. 'for': vFor,
  4620. 'if': vIf,
  4621. show: show,
  4622. model: model,
  4623. on: on,
  4624. bind: bind,
  4625. el: el,
  4626. ref: ref,
  4627. cloak: cloak
  4628. };
  4629. var queue$1 = [];
  4630. var queued = false;
  4631. /**
  4632. * Push a job into the queue.
  4633. *
  4634. * @param {Function} job
  4635. */
  4636. function pushJob(job) {
  4637. queue$1.push(job);
  4638. if (!queued) {
  4639. queued = true;
  4640. nextTick(flush);
  4641. }
  4642. }
  4643. /**
  4644. * Flush the queue, and do one forced reflow before
  4645. * triggering transitions.
  4646. */
  4647. function flush() {
  4648. // Force layout
  4649. var f = document.documentElement.offsetHeight;
  4650. for (var i = 0; i < queue$1.length; i++) {
  4651. queue$1[i]();
  4652. }
  4653. queue$1 = [];
  4654. queued = false;
  4655. // dummy return, so js linters don't complain about
  4656. // unused variable f
  4657. return f;
  4658. }
  4659. var TYPE_TRANSITION = 1;
  4660. var TYPE_ANIMATION = 2;
  4661. var transDurationProp = transitionProp + 'Duration';
  4662. var animDurationProp = animationProp + 'Duration';
  4663. /**
  4664. * A Transition object that encapsulates the state and logic
  4665. * of the transition.
  4666. *
  4667. * @param {Element} el
  4668. * @param {String} id
  4669. * @param {Object} hooks
  4670. * @param {Vue} vm
  4671. */
  4672. function Transition(el, id, hooks, vm) {
  4673. this.id = id;
  4674. this.el = el;
  4675. this.enterClass = id + '-enter';
  4676. this.leaveClass = id + '-leave';
  4677. this.hooks = hooks;
  4678. this.vm = vm;
  4679. // async state
  4680. this.pendingCssEvent = this.pendingCssCb = this.cancel = this.pendingJsCb = this.op = this.cb = null;
  4681. this.justEntered = false;
  4682. this.entered = this.left = false;
  4683. this.typeCache = {};
  4684. // bind
  4685. var self = this;['enterNextTick', 'enterDone', 'leaveNextTick', 'leaveDone'].forEach(function (m) {
  4686. self[m] = bind$1(self[m], self);
  4687. });
  4688. }
  4689. var p$1 = Transition.prototype;
  4690. /**
  4691. * Start an entering transition.
  4692. *
  4693. * 1. enter transition triggered
  4694. * 2. call beforeEnter hook
  4695. * 3. add enter class
  4696. * 4. insert/show element
  4697. * 5. call enter hook (with possible explicit js callback)
  4698. * 6. reflow
  4699. * 7. based on transition type:
  4700. * - transition:
  4701. * remove class now, wait for transitionend,
  4702. * then done if there's no explicit js callback.
  4703. * - animation:
  4704. * wait for animationend, remove class,
  4705. * then done if there's no explicit js callback.
  4706. * - no css transition:
  4707. * done now if there's no explicit js callback.
  4708. * 8. wait for either done or js callback, then call
  4709. * afterEnter hook.
  4710. *
  4711. * @param {Function} op - insert/show the element
  4712. * @param {Function} [cb]
  4713. */
  4714. p$1.enter = function (op, cb) {
  4715. this.cancelPending();
  4716. this.callHook('beforeEnter');
  4717. this.cb = cb;
  4718. addClass(this.el, this.enterClass);
  4719. op();
  4720. this.entered = false;
  4721. this.callHookWithCb('enter');
  4722. if (this.entered) {
  4723. return; // user called done synchronously.
  4724. }
  4725. this.cancel = this.hooks && this.hooks.enterCancelled;
  4726. pushJob(this.enterNextTick);
  4727. };
  4728. /**
  4729. * The "nextTick" phase of an entering transition, which is
  4730. * to be pushed into a queue and executed after a reflow so
  4731. * that removing the class can trigger a CSS transition.
  4732. */
  4733. p$1.enterNextTick = function () {
  4734. // Important hack:
  4735. // in Chrome, if a just-entered element is applied the
  4736. // leave class while its interpolated property still has
  4737. // a very small value (within one frame), Chrome will
  4738. // skip the leave transition entirely and not firing the
  4739. // transtionend event. Therefore we need to protected
  4740. // against such cases using a one-frame timeout.
  4741. this.justEntered = true;
  4742. var self = this;
  4743. setTimeout(function () {
  4744. self.justEntered = false;
  4745. }, 17);
  4746. var enterDone = this.enterDone;
  4747. var type = this.getCssTransitionType(this.enterClass);
  4748. if (!this.pendingJsCb) {
  4749. if (type === TYPE_TRANSITION) {
  4750. // trigger transition by removing enter class now
  4751. removeClass(this.el, this.enterClass);
  4752. this.setupCssCb(transitionEndEvent, enterDone);
  4753. } else if (type === TYPE_ANIMATION) {
  4754. this.setupCssCb(animationEndEvent, enterDone);
  4755. } else {
  4756. enterDone();
  4757. }
  4758. } else if (type === TYPE_TRANSITION) {
  4759. removeClass(this.el, this.enterClass);
  4760. }
  4761. };
  4762. /**
  4763. * The "cleanup" phase of an entering transition.
  4764. */
  4765. p$1.enterDone = function () {
  4766. this.entered = true;
  4767. this.cancel = this.pendingJsCb = null;
  4768. removeClass(this.el, this.enterClass);
  4769. this.callHook('afterEnter');
  4770. if (this.cb) this.cb();
  4771. };
  4772. /**
  4773. * Start a leaving transition.
  4774. *
  4775. * 1. leave transition triggered.
  4776. * 2. call beforeLeave hook
  4777. * 3. add leave class (trigger css transition)
  4778. * 4. call leave hook (with possible explicit js callback)
  4779. * 5. reflow if no explicit js callback is provided
  4780. * 6. based on transition type:
  4781. * - transition or animation:
  4782. * wait for end event, remove class, then done if
  4783. * there's no explicit js callback.
  4784. * - no css transition:
  4785. * done if there's no explicit js callback.
  4786. * 7. wait for either done or js callback, then call
  4787. * afterLeave hook.
  4788. *
  4789. * @param {Function} op - remove/hide the element
  4790. * @param {Function} [cb]
  4791. */
  4792. p$1.leave = function (op, cb) {
  4793. this.cancelPending();
  4794. this.callHook('beforeLeave');
  4795. this.op = op;
  4796. this.cb = cb;
  4797. addClass(this.el, this.leaveClass);
  4798. this.left = false;
  4799. this.callHookWithCb('leave');
  4800. if (this.left) {
  4801. return; // user called done synchronously.
  4802. }
  4803. this.cancel = this.hooks && this.hooks.leaveCancelled;
  4804. // only need to handle leaveDone if
  4805. // 1. the transition is already done (synchronously called
  4806. // by the user, which causes this.op set to null)
  4807. // 2. there's no explicit js callback
  4808. if (this.op && !this.pendingJsCb) {
  4809. // if a CSS transition leaves immediately after enter,
  4810. // the transitionend event never fires. therefore we
  4811. // detect such cases and end the leave immediately.
  4812. if (this.justEntered) {
  4813. this.leaveDone();
  4814. } else {
  4815. pushJob(this.leaveNextTick);
  4816. }
  4817. }
  4818. };
  4819. /**
  4820. * The "nextTick" phase of a leaving transition.
  4821. */
  4822. p$1.leaveNextTick = function () {
  4823. var type = this.getCssTransitionType(this.leaveClass);
  4824. if (type) {
  4825. var event = type === TYPE_TRANSITION ? transitionEndEvent : animationEndEvent;
  4826. this.setupCssCb(event, this.leaveDone);
  4827. } else {
  4828. this.leaveDone();
  4829. }
  4830. };
  4831. /**
  4832. * The "cleanup" phase of a leaving transition.
  4833. */
  4834. p$1.leaveDone = function () {
  4835. this.left = true;
  4836. this.cancel = this.pendingJsCb = null;
  4837. this.op();
  4838. removeClass(this.el, this.leaveClass);
  4839. this.callHook('afterLeave');
  4840. if (this.cb) this.cb();
  4841. this.op = null;
  4842. };
  4843. /**
  4844. * Cancel any pending callbacks from a previously running
  4845. * but not finished transition.
  4846. */
  4847. p$1.cancelPending = function () {
  4848. this.op = this.cb = null;
  4849. var hasPending = false;
  4850. if (this.pendingCssCb) {
  4851. hasPending = true;
  4852. off(this.el, this.pendingCssEvent, this.pendingCssCb);
  4853. this.pendingCssEvent = this.pendingCssCb = null;
  4854. }
  4855. if (this.pendingJsCb) {
  4856. hasPending = true;
  4857. this.pendingJsCb.cancel();
  4858. this.pendingJsCb = null;
  4859. }
  4860. if (hasPending) {
  4861. removeClass(this.el, this.enterClass);
  4862. removeClass(this.el, this.leaveClass);
  4863. }
  4864. if (this.cancel) {
  4865. this.cancel.call(this.vm, this.el);
  4866. this.cancel = null;
  4867. }
  4868. };
  4869. /**
  4870. * Call a user-provided synchronous hook function.
  4871. *
  4872. * @param {String} type
  4873. */
  4874. p$1.callHook = function (type) {
  4875. if (this.hooks && this.hooks[type]) {
  4876. this.hooks[type].call(this.vm, this.el);
  4877. }
  4878. };
  4879. /**
  4880. * Call a user-provided, potentially-async hook function.
  4881. * We check for the length of arguments to see if the hook
  4882. * expects a `done` callback. If true, the transition's end
  4883. * will be determined by when the user calls that callback;
  4884. * otherwise, the end is determined by the CSS transition or
  4885. * animation.
  4886. *
  4887. * @param {String} type
  4888. */
  4889. p$1.callHookWithCb = function (type) {
  4890. var hook = this.hooks && this.hooks[type];
  4891. if (hook) {
  4892. if (hook.length > 1) {
  4893. this.pendingJsCb = cancellable(this[type + 'Done']);
  4894. }
  4895. hook.call(this.vm, this.el, this.pendingJsCb);
  4896. }
  4897. };
  4898. /**
  4899. * Get an element's transition type based on the
  4900. * calculated styles.
  4901. *
  4902. * @param {String} className
  4903. * @return {Number}
  4904. */
  4905. p$1.getCssTransitionType = function (className) {
  4906. /* istanbul ignore if */
  4907. if (!transitionEndEvent ||
  4908. // skip CSS transitions if page is not visible -
  4909. // this solves the issue of transitionend events not
  4910. // firing until the page is visible again.
  4911. // pageVisibility API is supported in IE10+, same as
  4912. // CSS transitions.
  4913. document.hidden ||
  4914. // explicit js-only transition
  4915. this.hooks && this.hooks.css === false ||
  4916. // element is hidden
  4917. isHidden(this.el)) {
  4918. return;
  4919. }
  4920. var type = this.typeCache[className];
  4921. if (type) return type;
  4922. var inlineStyles = this.el.style;
  4923. var computedStyles = window.getComputedStyle(this.el);
  4924. var transDuration = inlineStyles[transDurationProp] || computedStyles[transDurationProp];
  4925. if (transDuration && transDuration !== '0s') {
  4926. type = TYPE_TRANSITION;
  4927. } else {
  4928. var animDuration = inlineStyles[animDurationProp] || computedStyles[animDurationProp];
  4929. if (animDuration && animDuration !== '0s') {
  4930. type = TYPE_ANIMATION;
  4931. }
  4932. }
  4933. if (type) {
  4934. this.typeCache[className] = type;
  4935. }
  4936. return type;
  4937. };
  4938. /**
  4939. * Setup a CSS transitionend/animationend callback.
  4940. *
  4941. * @param {String} event
  4942. * @param {Function} cb
  4943. */
  4944. p$1.setupCssCb = function (event, cb) {
  4945. this.pendingCssEvent = event;
  4946. var self = this;
  4947. var el = this.el;
  4948. var onEnd = this.pendingCssCb = function (e) {
  4949. if (e.target === el) {
  4950. off(el, event, onEnd);
  4951. self.pendingCssEvent = self.pendingCssCb = null;
  4952. if (!self.pendingJsCb && cb) {
  4953. cb();
  4954. }
  4955. }
  4956. };
  4957. on$1(el, event, onEnd);
  4958. };
  4959. /**
  4960. * Check if an element is hidden - in that case we can just
  4961. * skip the transition alltogether.
  4962. *
  4963. * @param {Element} el
  4964. * @return {Boolean}
  4965. */
  4966. function isHidden(el) {
  4967. return !(el.offsetWidth || el.offsetHeight || el.getClientRects().length);
  4968. }
  4969. var transition = {
  4970. priority: 1100,
  4971. update: function update(id, oldId) {
  4972. var el = this.el;
  4973. // resolve on owner vm
  4974. var hooks = resolveAsset(this.vm.$options, 'transitions', id);
  4975. id = id || 'v';
  4976. // apply on closest vm
  4977. el.__v_trans = new Transition(el, id, hooks, this.el.__vue__ || this.vm);
  4978. if (oldId) {
  4979. removeClass(el, oldId + '-transition');
  4980. }
  4981. addClass(el, id + '-transition');
  4982. }
  4983. };
  4984. var bindingModes = config._propBindingModes;
  4985. var propDef = {
  4986. bind: function bind() {
  4987. var child = this.vm;
  4988. var parent = child._context;
  4989. // passed in from compiler directly
  4990. var prop = this.descriptor.prop;
  4991. var childKey = prop.path;
  4992. var parentKey = prop.parentPath;
  4993. var twoWay = prop.mode === bindingModes.TWO_WAY;
  4994. var parentWatcher = this.parentWatcher = new Watcher(parent, parentKey, function (val) {
  4995. if (assertProp(prop, val)) {
  4996. child[childKey] = val;
  4997. }
  4998. }, {
  4999. twoWay: twoWay,
  5000. filters: prop.filters,
  5001. // important: props need to be observed on the
  5002. // v-for scope if present
  5003. scope: this._scope
  5004. });
  5005. // set the child initial value.
  5006. initProp(child, prop, parentWatcher.value);
  5007. // setup two-way binding
  5008. if (twoWay) {
  5009. // important: defer the child watcher creation until
  5010. // the created hook (after data observation)
  5011. var self = this;
  5012. child.$once('hook:created', function () {
  5013. self.childWatcher = new Watcher(child, childKey, function (val) {
  5014. parentWatcher.set(val);
  5015. }, {
  5016. // ensure sync upward before parent sync down.
  5017. // this is necessary in cases e.g. the child
  5018. // mutates a prop array, then replaces it. (#1683)
  5019. sync: true
  5020. });
  5021. });
  5022. }
  5023. },
  5024. unbind: function unbind() {
  5025. this.parentWatcher.teardown();
  5026. if (this.childWatcher) {
  5027. this.childWatcher.teardown();
  5028. }
  5029. }
  5030. };
  5031. var component = {
  5032. priority: 1500,
  5033. params: ['keep-alive', 'transition-mode', 'inline-template'],
  5034. /**
  5035. * Setup. Two possible usages:
  5036. *
  5037. * - static:
  5038. * <comp> or <div v-component="comp">
  5039. *
  5040. * - dynamic:
  5041. * <component :is="view">
  5042. */
  5043. bind: function bind() {
  5044. if (!this.el.__vue__) {
  5045. // keep-alive cache
  5046. this.keepAlive = this.params.keepAlive;
  5047. if (this.keepAlive) {
  5048. this.cache = {};
  5049. }
  5050. // check inline-template
  5051. if (this.params.inlineTemplate) {
  5052. // extract inline template as a DocumentFragment
  5053. this.inlineTemplate = extractContent(this.el, true);
  5054. }
  5055. // component resolution related state
  5056. this.pendingComponentCb = this.Component = null;
  5057. // transition related state
  5058. this.pendingRemovals = 0;
  5059. this.pendingRemovalCb = null;
  5060. // create a ref anchor
  5061. this.anchor = createAnchor('v-component');
  5062. replace(this.el, this.anchor);
  5063. // remove is attribute.
  5064. // this is removed during compilation, but because compilation is
  5065. // cached, when the component is used elsewhere this attribute
  5066. // will remain at link time.
  5067. this.el.removeAttribute('is');
  5068. // remove ref, same as above
  5069. if (this.descriptor.ref) {
  5070. this.el.removeAttribute('v-ref:' + hyphenate(this.descriptor.ref));
  5071. }
  5072. // if static, build right now.
  5073. if (this.literal) {
  5074. this.setComponent(this.expression);
  5075. }
  5076. } else {
  5077. 'development' !== 'production' && warn('cannot mount component "' + this.expression + '" ' + 'on already mounted element: ' + this.el);
  5078. }
  5079. },
  5080. /**
  5081. * Public update, called by the watcher in the dynamic
  5082. * literal scenario, e.g. <component :is="view">
  5083. */
  5084. update: function update(value) {
  5085. if (!this.literal) {
  5086. this.setComponent(value);
  5087. }
  5088. },
  5089. /**
  5090. * Switch dynamic components. May resolve the component
  5091. * asynchronously, and perform transition based on
  5092. * specified transition mode. Accepts a few additional
  5093. * arguments specifically for vue-router.
  5094. *
  5095. * The callback is called when the full transition is
  5096. * finished.
  5097. *
  5098. * @param {String} value
  5099. * @param {Function} [cb]
  5100. */
  5101. setComponent: function setComponent(value, cb) {
  5102. this.invalidatePending();
  5103. if (!value) {
  5104. // just remove current
  5105. this.unbuild(true);
  5106. this.remove(this.childVM, cb);
  5107. this.childVM = null;
  5108. } else {
  5109. var self = this;
  5110. this.resolveComponent(value, function () {
  5111. self.mountComponent(cb);
  5112. });
  5113. }
  5114. },
  5115. /**
  5116. * Resolve the component constructor to use when creating
  5117. * the child vm.
  5118. */
  5119. resolveComponent: function resolveComponent(id, cb) {
  5120. var self = this;
  5121. this.pendingComponentCb = cancellable(function (Component) {
  5122. self.ComponentName = Component.options.name || id;
  5123. self.Component = Component;
  5124. cb();
  5125. });
  5126. this.vm._resolveComponent(id, this.pendingComponentCb);
  5127. },
  5128. /**
  5129. * Create a new instance using the current constructor and
  5130. * replace the existing instance. This method doesn't care
  5131. * whether the new component and the old one are actually
  5132. * the same.
  5133. *
  5134. * @param {Function} [cb]
  5135. */
  5136. mountComponent: function mountComponent(cb) {
  5137. // actual mount
  5138. this.unbuild(true);
  5139. var self = this;
  5140. var activateHook = this.Component.options.activate;
  5141. var cached = this.getCached();
  5142. var newComponent = this.build();
  5143. if (activateHook && !cached) {
  5144. this.waitingFor = newComponent;
  5145. activateHook.call(newComponent, function () {
  5146. self.waitingFor = null;
  5147. self.transition(newComponent, cb);
  5148. });
  5149. } else {
  5150. // update ref for kept-alive component
  5151. if (cached) {
  5152. newComponent._updateRef();
  5153. }
  5154. this.transition(newComponent, cb);
  5155. }
  5156. },
  5157. /**
  5158. * When the component changes or unbinds before an async
  5159. * constructor is resolved, we need to invalidate its
  5160. * pending callback.
  5161. */
  5162. invalidatePending: function invalidatePending() {
  5163. if (this.pendingComponentCb) {
  5164. this.pendingComponentCb.cancel();
  5165. this.pendingComponentCb = null;
  5166. }
  5167. },
  5168. /**
  5169. * Instantiate/insert a new child vm.
  5170. * If keep alive and has cached instance, insert that
  5171. * instance; otherwise build a new one and cache it.
  5172. *
  5173. * @param {Object} [extraOptions]
  5174. * @return {Vue} - the created instance
  5175. */
  5176. build: function build(extraOptions) {
  5177. var cached = this.getCached();
  5178. if (cached) {
  5179. return cached;
  5180. }
  5181. if (this.Component) {
  5182. // default options
  5183. var options = {
  5184. name: this.ComponentName,
  5185. el: cloneNode(this.el),
  5186. template: this.inlineTemplate,
  5187. // make sure to add the child with correct parent
  5188. // if this is a transcluded component, its parent
  5189. // should be the transclusion host.
  5190. parent: this._host || this.vm,
  5191. // if no inline-template, then the compiled
  5192. // linker can be cached for better performance.
  5193. _linkerCachable: !this.inlineTemplate,
  5194. _ref: this.descriptor.ref,
  5195. _asComponent: true,
  5196. _isRouterView: this._isRouterView,
  5197. // if this is a transcluded component, context
  5198. // will be the common parent vm of this instance
  5199. // and its host.
  5200. _context: this.vm,
  5201. // if this is inside an inline v-for, the scope
  5202. // will be the intermediate scope created for this
  5203. // repeat fragment. this is used for linking props
  5204. // and container directives.
  5205. _scope: this._scope,
  5206. // pass in the owner fragment of this component.
  5207. // this is necessary so that the fragment can keep
  5208. // track of its contained components in order to
  5209. // call attach/detach hooks for them.
  5210. _frag: this._frag
  5211. };
  5212. // extra options
  5213. // in 1.0.0 this is used by vue-router only
  5214. /* istanbul ignore if */
  5215. if (extraOptions) {
  5216. extend(options, extraOptions);
  5217. }
  5218. var child = new this.Component(options);
  5219. if (this.keepAlive) {
  5220. this.cache[this.Component.cid] = child;
  5221. }
  5222. /* istanbul ignore if */
  5223. if ('development' !== 'production' && this.el.hasAttribute('transition') && child._isFragment) {
  5224. warn('Transitions will not work on a fragment instance. ' + 'Template: ' + child.$options.template);
  5225. }
  5226. return child;
  5227. }
  5228. },
  5229. /**
  5230. * Try to get a cached instance of the current component.
  5231. *
  5232. * @return {Vue|undefined}
  5233. */
  5234. getCached: function getCached() {
  5235. return this.keepAlive && this.cache[this.Component.cid];
  5236. },
  5237. /**
  5238. * Teardown the current child, but defers cleanup so
  5239. * that we can separate the destroy and removal steps.
  5240. *
  5241. * @param {Boolean} defer
  5242. */
  5243. unbuild: function unbuild(defer) {
  5244. if (this.waitingFor) {
  5245. this.waitingFor.$destroy();
  5246. this.waitingFor = null;
  5247. }
  5248. var child = this.childVM;
  5249. if (!child || this.keepAlive) {
  5250. if (child) {
  5251. // remove ref
  5252. child._updateRef(true);
  5253. }
  5254. return;
  5255. }
  5256. // the sole purpose of `deferCleanup` is so that we can
  5257. // "deactivate" the vm right now and perform DOM removal
  5258. // later.
  5259. child.$destroy(false, defer);
  5260. },
  5261. /**
  5262. * Remove current destroyed child and manually do
  5263. * the cleanup after removal.
  5264. *
  5265. * @param {Function} cb
  5266. */
  5267. remove: function remove(child, cb) {
  5268. var keepAlive = this.keepAlive;
  5269. if (child) {
  5270. // we may have a component switch when a previous
  5271. // component is still being transitioned out.
  5272. // we want to trigger only one lastest insertion cb
  5273. // when the existing transition finishes. (#1119)
  5274. this.pendingRemovals++;
  5275. this.pendingRemovalCb = cb;
  5276. var self = this;
  5277. child.$remove(function () {
  5278. self.pendingRemovals--;
  5279. if (!keepAlive) child._cleanup();
  5280. if (!self.pendingRemovals && self.pendingRemovalCb) {
  5281. self.pendingRemovalCb();
  5282. self.pendingRemovalCb = null;
  5283. }
  5284. });
  5285. } else if (cb) {
  5286. cb();
  5287. }
  5288. },
  5289. /**
  5290. * Actually swap the components, depending on the
  5291. * transition mode. Defaults to simultaneous.
  5292. *
  5293. * @param {Vue} target
  5294. * @param {Function} [cb]
  5295. */
  5296. transition: function transition(target, cb) {
  5297. var self = this;
  5298. var current = this.childVM;
  5299. // for devtool inspection
  5300. if ('development' !== 'production') {
  5301. if (current) current._inactive = true;
  5302. target._inactive = false;
  5303. }
  5304. this.childVM = target;
  5305. switch (self.params.transitionMode) {
  5306. case 'in-out':
  5307. target.$before(self.anchor, function () {
  5308. self.remove(current, cb);
  5309. });
  5310. break;
  5311. case 'out-in':
  5312. self.remove(current, function () {
  5313. target.$before(self.anchor, cb);
  5314. });
  5315. break;
  5316. default:
  5317. self.remove(current);
  5318. target.$before(self.anchor, cb);
  5319. }
  5320. },
  5321. /**
  5322. * Unbind.
  5323. */
  5324. unbind: function unbind() {
  5325. this.invalidatePending();
  5326. // Do not defer cleanup when unbinding
  5327. this.unbuild();
  5328. // destroy all keep-alive cached instances
  5329. if (this.cache) {
  5330. for (var key in this.cache) {
  5331. this.cache[key].$destroy();
  5332. }
  5333. this.cache = null;
  5334. }
  5335. }
  5336. };
  5337. var vClass = {
  5338. deep: true,
  5339. update: function update(value) {
  5340. if (value && typeof value === 'string') {
  5341. this.handleObject(stringToObject(value));
  5342. } else if (isPlainObject(value)) {
  5343. this.handleObject(value);
  5344. } else if (isArray(value)) {
  5345. this.handleArray(value);
  5346. } else {
  5347. this.cleanup();
  5348. }
  5349. },
  5350. handleObject: function handleObject(value) {
  5351. this.cleanup(value);
  5352. var keys = this.prevKeys = Object.keys(value);
  5353. for (var i = 0, l = keys.length; i < l; i++) {
  5354. var key = keys[i];
  5355. if (value[key]) {
  5356. addClass(this.el, key);
  5357. } else {
  5358. removeClass(this.el, key);
  5359. }
  5360. }
  5361. },
  5362. handleArray: function handleArray(value) {
  5363. this.cleanup(value);
  5364. for (var i = 0, l = value.length; i < l; i++) {
  5365. if (value[i]) {
  5366. addClass(this.el, value[i]);
  5367. }
  5368. }
  5369. this.prevKeys = value.slice();
  5370. },
  5371. cleanup: function cleanup(value) {
  5372. if (this.prevKeys) {
  5373. var i = this.prevKeys.length;
  5374. while (i--) {
  5375. var key = this.prevKeys[i];
  5376. if (key && (!value || !contains$1(value, key))) {
  5377. removeClass(this.el, key);
  5378. }
  5379. }
  5380. }
  5381. }
  5382. };
  5383. function stringToObject(value) {
  5384. var res = {};
  5385. var keys = value.trim().split(/\s+/);
  5386. var i = keys.length;
  5387. while (i--) {
  5388. res[keys[i]] = true;
  5389. }
  5390. return res;
  5391. }
  5392. function contains$1(value, key) {
  5393. return isArray(value) ? value.indexOf(key) > -1 : hasOwn(value, key);
  5394. }
  5395. var internalDirectives = {
  5396. style: style,
  5397. 'class': vClass,
  5398. component: component,
  5399. prop: propDef,
  5400. transition: transition
  5401. };
  5402. var propBindingModes = config._propBindingModes;
  5403. var empty = {};
  5404. // regexes
  5405. var identRE = /^[$_a-zA-Z]+[\w$]*$/;
  5406. var settablePathRE = /^[A-Za-z_$][\w$]*(\.[A-Za-z_$][\w$]*|\[[^\[\]]+\])*$/;
  5407. /**
  5408. * Compile props on a root element and return
  5409. * a props link function.
  5410. *
  5411. * @param {Element|DocumentFragment} el
  5412. * @param {Array} propOptions
  5413. * @return {Function} propsLinkFn
  5414. */
  5415. function compileProps(el, propOptions) {
  5416. var props = [];
  5417. var names = Object.keys(propOptions);
  5418. var i = names.length;
  5419. var options, name, attr, value, path, parsed, prop;
  5420. while (i--) {
  5421. name = names[i];
  5422. options = propOptions[name] || empty;
  5423. if ('development' !== 'production' && name === '$data') {
  5424. warn('Do not use $data as prop.');
  5425. continue;
  5426. }
  5427. // props could contain dashes, which will be
  5428. // interpreted as minus calculations by the parser
  5429. // so we need to camelize the path here
  5430. path = camelize(name);
  5431. if (!identRE.test(path)) {
  5432. 'development' !== 'production' && warn('Invalid prop key: "' + name + '". Prop keys ' + 'must be valid identifiers.');
  5433. continue;
  5434. }
  5435. prop = {
  5436. name: name,
  5437. path: path,
  5438. options: options,
  5439. mode: propBindingModes.ONE_WAY,
  5440. raw: null
  5441. };
  5442. attr = hyphenate(name);
  5443. // first check dynamic version
  5444. if ((value = getBindAttr(el, attr)) === null) {
  5445. if ((value = getBindAttr(el, attr + '.sync')) !== null) {
  5446. prop.mode = propBindingModes.TWO_WAY;
  5447. } else if ((value = getBindAttr(el, attr + '.once')) !== null) {
  5448. prop.mode = propBindingModes.ONE_TIME;
  5449. }
  5450. }
  5451. if (value !== null) {
  5452. // has dynamic binding!
  5453. prop.raw = value;
  5454. parsed = parseDirective(value);
  5455. value = parsed.expression;
  5456. prop.filters = parsed.filters;
  5457. // check binding type
  5458. if (isLiteral(value)) {
  5459. // for expressions containing literal numbers and
  5460. // booleans, there's no need to setup a prop binding,
  5461. // so we can optimize them as a one-time set.
  5462. prop.optimizedLiteral = true;
  5463. } else {
  5464. prop.dynamic = true;
  5465. // check non-settable path for two-way bindings
  5466. if ('development' !== 'production' && prop.mode === propBindingModes.TWO_WAY && !settablePathRE.test(value)) {
  5467. prop.mode = propBindingModes.ONE_WAY;
  5468. warn('Cannot bind two-way prop with non-settable ' + 'parent path: ' + value);
  5469. }
  5470. }
  5471. prop.parentPath = value;
  5472. // warn required two-way
  5473. if ('development' !== 'production' && options.twoWay && prop.mode !== propBindingModes.TWO_WAY) {
  5474. warn('Prop "' + name + '" expects a two-way binding type.');
  5475. }
  5476. } else if ((value = getAttr(el, attr)) !== null) {
  5477. // has literal binding!
  5478. prop.raw = value;
  5479. } else if (options.required) {
  5480. // warn missing required
  5481. 'development' !== 'production' && warn('Missing required prop: ' + name);
  5482. }
  5483. // push prop
  5484. props.push(prop);
  5485. }
  5486. return makePropsLinkFn(props);
  5487. }
  5488. /**
  5489. * Build a function that applies props to a vm.
  5490. *
  5491. * @param {Array} props
  5492. * @return {Function} propsLinkFn
  5493. */
  5494. function makePropsLinkFn(props) {
  5495. return function propsLinkFn(vm, scope) {
  5496. // store resolved props info
  5497. vm._props = {};
  5498. var i = props.length;
  5499. var prop, path, options, value, raw;
  5500. while (i--) {
  5501. prop = props[i];
  5502. raw = prop.raw;
  5503. path = prop.path;
  5504. options = prop.options;
  5505. vm._props[path] = prop;
  5506. if (raw === null) {
  5507. // initialize absent prop
  5508. initProp(vm, prop, getDefault(vm, options));
  5509. } else if (prop.dynamic) {
  5510. // dynamic prop
  5511. if (vm._context) {
  5512. if (prop.mode === propBindingModes.ONE_TIME) {
  5513. // one time binding
  5514. value = (scope || vm._context).$get(prop.parentPath);
  5515. initProp(vm, prop, value);
  5516. } else {
  5517. // dynamic binding
  5518. vm._bindDir({
  5519. name: 'prop',
  5520. def: propDef,
  5521. prop: prop
  5522. }, null, null, scope); // el, host, scope
  5523. }
  5524. } else {
  5525. 'development' !== 'production' && warn('Cannot bind dynamic prop on a root instance' + ' with no parent: ' + prop.name + '="' + raw + '"');
  5526. }
  5527. } else if (prop.optimizedLiteral) {
  5528. // optimized literal, cast it and just set once
  5529. var stripped = stripQuotes(raw);
  5530. value = stripped === raw ? toBoolean(toNumber(raw)) : stripped;
  5531. initProp(vm, prop, value);
  5532. } else {
  5533. // string literal, but we need to cater for
  5534. // Boolean props with no value
  5535. value = options.type === Boolean && raw === '' ? true : raw;
  5536. initProp(vm, prop, value);
  5537. }
  5538. }
  5539. };
  5540. }
  5541. /**
  5542. * Get the default value of a prop.
  5543. *
  5544. * @param {Vue} vm
  5545. * @param {Object} options
  5546. * @return {*}
  5547. */
  5548. function getDefault(vm, options) {
  5549. // no default, return undefined
  5550. if (!hasOwn(options, 'default')) {
  5551. // absent boolean value defaults to false
  5552. return options.type === Boolean ? false : undefined;
  5553. }
  5554. var def = options['default'];
  5555. // warn against non-factory defaults for Object & Array
  5556. if (isObject(def)) {
  5557. 'development' !== 'production' && warn('Object/Array as default prop values will be shared ' + 'across multiple instances. Use a factory function ' + 'to return the default value instead.');
  5558. }
  5559. // call factory function for non-Function types
  5560. return typeof def === 'function' && options.type !== Function ? def.call(vm) : def;
  5561. }
  5562. // special binding prefixes
  5563. var bindRE = /^v-bind:|^:/;
  5564. var onRE = /^v-on:|^@/;
  5565. var argRE = /:(.*)$/;
  5566. var modifierRE = /\.[^\.]+/g;
  5567. var transitionRE = /^(v-bind:|:)?transition$/;
  5568. // terminal directives
  5569. var terminalDirectives = ['for', 'if'];
  5570. // default directive priority
  5571. var DEFAULT_PRIORITY = 1000;
  5572. /**
  5573. * Compile a template and return a reusable composite link
  5574. * function, which recursively contains more link functions
  5575. * inside. This top level compile function would normally
  5576. * be called on instance root nodes, but can also be used
  5577. * for partial compilation if the partial argument is true.
  5578. *
  5579. * The returned composite link function, when called, will
  5580. * return an unlink function that tearsdown all directives
  5581. * created during the linking phase.
  5582. *
  5583. * @param {Element|DocumentFragment} el
  5584. * @param {Object} options
  5585. * @param {Boolean} partial
  5586. * @return {Function}
  5587. */
  5588. function compile(el, options, partial) {
  5589. // link function for the node itself.
  5590. var nodeLinkFn = partial || !options._asComponent ? compileNode(el, options) : null;
  5591. // link function for the childNodes
  5592. var childLinkFn = !(nodeLinkFn && nodeLinkFn.terminal) && el.tagName !== 'SCRIPT' && el.hasChildNodes() ? compileNodeList(el.childNodes, options) : null;
  5593. /**
  5594. * A composite linker function to be called on a already
  5595. * compiled piece of DOM, which instantiates all directive
  5596. * instances.
  5597. *
  5598. * @param {Vue} vm
  5599. * @param {Element|DocumentFragment} el
  5600. * @param {Vue} [host] - host vm of transcluded content
  5601. * @param {Object} [scope] - v-for scope
  5602. * @param {Fragment} [frag] - link context fragment
  5603. * @return {Function|undefined}
  5604. */
  5605. return function compositeLinkFn(vm, el, host, scope, frag) {
  5606. // cache childNodes before linking parent, fix #657
  5607. var childNodes = toArray(el.childNodes);
  5608. // link
  5609. var dirs = linkAndCapture(function compositeLinkCapturer() {
  5610. if (nodeLinkFn) nodeLinkFn(vm, el, host, scope, frag);
  5611. if (childLinkFn) childLinkFn(vm, childNodes, host, scope, frag);
  5612. }, vm);
  5613. return makeUnlinkFn(vm, dirs);
  5614. };
  5615. }
  5616. /**
  5617. * Apply a linker to a vm/element pair and capture the
  5618. * directives created during the process.
  5619. *
  5620. * @param {Function} linker
  5621. * @param {Vue} vm
  5622. */
  5623. function linkAndCapture(linker, vm) {
  5624. var originalDirCount = vm._directives.length;
  5625. linker();
  5626. var dirs = vm._directives.slice(originalDirCount);
  5627. dirs.sort(directiveComparator);
  5628. for (var i = 0, l = dirs.length; i < l; i++) {
  5629. dirs[i]._bind();
  5630. }
  5631. return dirs;
  5632. }
  5633. /**
  5634. * Directive priority sort comparator
  5635. *
  5636. * @param {Object} a
  5637. * @param {Object} b
  5638. */
  5639. function directiveComparator(a, b) {
  5640. a = a.descriptor.def.priority || DEFAULT_PRIORITY;
  5641. b = b.descriptor.def.priority || DEFAULT_PRIORITY;
  5642. return a > b ? -1 : a === b ? 0 : 1;
  5643. }
  5644. /**
  5645. * Linker functions return an unlink function that
  5646. * tearsdown all directives instances generated during
  5647. * the process.
  5648. *
  5649. * We create unlink functions with only the necessary
  5650. * information to avoid retaining additional closures.
  5651. *
  5652. * @param {Vue} vm
  5653. * @param {Array} dirs
  5654. * @param {Vue} [context]
  5655. * @param {Array} [contextDirs]
  5656. * @return {Function}
  5657. */
  5658. function makeUnlinkFn(vm, dirs, context, contextDirs) {
  5659. return function unlink(destroying) {
  5660. teardownDirs(vm, dirs, destroying);
  5661. if (context && contextDirs) {
  5662. teardownDirs(context, contextDirs);
  5663. }
  5664. };
  5665. }
  5666. /**
  5667. * Teardown partial linked directives.
  5668. *
  5669. * @param {Vue} vm
  5670. * @param {Array} dirs
  5671. * @param {Boolean} destroying
  5672. */
  5673. function teardownDirs(vm, dirs, destroying) {
  5674. var i = dirs.length;
  5675. while (i--) {
  5676. dirs[i]._teardown();
  5677. if (!destroying) {
  5678. vm._directives.$remove(dirs[i]);
  5679. }
  5680. }
  5681. }
  5682. /**
  5683. * Compile link props on an instance.
  5684. *
  5685. * @param {Vue} vm
  5686. * @param {Element} el
  5687. * @param {Object} props
  5688. * @param {Object} [scope]
  5689. * @return {Function}
  5690. */
  5691. function compileAndLinkProps(vm, el, props, scope) {
  5692. var propsLinkFn = compileProps(el, props);
  5693. var propDirs = linkAndCapture(function () {
  5694. propsLinkFn(vm, scope);
  5695. }, vm);
  5696. return makeUnlinkFn(vm, propDirs);
  5697. }
  5698. /**
  5699. * Compile the root element of an instance.
  5700. *
  5701. * 1. attrs on context container (context scope)
  5702. * 2. attrs on the component template root node, if
  5703. * replace:true (child scope)
  5704. *
  5705. * If this is a fragment instance, we only need to compile 1.
  5706. *
  5707. * @param {Vue} vm
  5708. * @param {Element} el
  5709. * @param {Object} options
  5710. * @param {Object} contextOptions
  5711. * @return {Function}
  5712. */
  5713. function compileRoot(el, options, contextOptions) {
  5714. var containerAttrs = options._containerAttrs;
  5715. var replacerAttrs = options._replacerAttrs;
  5716. var contextLinkFn, replacerLinkFn;
  5717. // only need to compile other attributes for
  5718. // non-fragment instances
  5719. if (el.nodeType !== 11) {
  5720. // for components, container and replacer need to be
  5721. // compiled separately and linked in different scopes.
  5722. if (options._asComponent) {
  5723. // 2. container attributes
  5724. if (containerAttrs && contextOptions) {
  5725. contextLinkFn = compileDirectives(containerAttrs, contextOptions);
  5726. }
  5727. if (replacerAttrs) {
  5728. // 3. replacer attributes
  5729. replacerLinkFn = compileDirectives(replacerAttrs, options);
  5730. }
  5731. } else {
  5732. // non-component, just compile as a normal element.
  5733. replacerLinkFn = compileDirectives(el.attributes, options);
  5734. }
  5735. } else if ('development' !== 'production' && containerAttrs) {
  5736. // warn container directives for fragment instances
  5737. var names = containerAttrs.filter(function (attr) {
  5738. // allow vue-loader/vueify scoped css attributes
  5739. return attr.name.indexOf('_v-') < 0 &&
  5740. // allow event listeners
  5741. !onRE.test(attr.name) &&
  5742. // allow slots
  5743. attr.name !== 'slot';
  5744. }).map(function (attr) {
  5745. return '"' + attr.name + '"';
  5746. });
  5747. if (names.length) {
  5748. var plural = names.length > 1;
  5749. warn('Attribute' + (plural ? 's ' : ' ') + names.join(', ') + (plural ? ' are' : ' is') + ' ignored on component ' + '<' + options.el.tagName.toLowerCase() + '> because ' + 'the component is a fragment instance: ' + 'http://vuejs.org/guide/components.html#Fragment_Instance');
  5750. }
  5751. }
  5752. return function rootLinkFn(vm, el, scope) {
  5753. // link context scope dirs
  5754. var context = vm._context;
  5755. var contextDirs;
  5756. if (context && contextLinkFn) {
  5757. contextDirs = linkAndCapture(function () {
  5758. contextLinkFn(context, el, null, scope);
  5759. }, context);
  5760. }
  5761. // link self
  5762. var selfDirs = linkAndCapture(function () {
  5763. if (replacerLinkFn) replacerLinkFn(vm, el);
  5764. }, vm);
  5765. // return the unlink function that tearsdown context
  5766. // container directives.
  5767. return makeUnlinkFn(vm, selfDirs, context, contextDirs);
  5768. };
  5769. }
  5770. /**
  5771. * Compile a node and return a nodeLinkFn based on the
  5772. * node type.
  5773. *
  5774. * @param {Node} node
  5775. * @param {Object} options
  5776. * @return {Function|null}
  5777. */
  5778. function compileNode(node, options) {
  5779. var type = node.nodeType;
  5780. if (type === 1 && node.tagName !== 'SCRIPT') {
  5781. return compileElement(node, options);
  5782. } else if (type === 3 && node.data.trim()) {
  5783. return compileTextNode(node, options);
  5784. } else {
  5785. return null;
  5786. }
  5787. }
  5788. /**
  5789. * Compile an element and return a nodeLinkFn.
  5790. *
  5791. * @param {Element} el
  5792. * @param {Object} options
  5793. * @return {Function|null}
  5794. */
  5795. function compileElement(el, options) {
  5796. // preprocess textareas.
  5797. // textarea treats its text content as the initial value.
  5798. // just bind it as an attr directive for value.
  5799. if (el.tagName === 'TEXTAREA') {
  5800. var tokens = parseText(el.value);
  5801. if (tokens) {
  5802. el.setAttribute(':value', tokensToExp(tokens));
  5803. el.value = '';
  5804. }
  5805. }
  5806. var linkFn;
  5807. var hasAttrs = el.hasAttributes();
  5808. // check terminal directives (for & if)
  5809. if (hasAttrs) {
  5810. linkFn = checkTerminalDirectives(el, options);
  5811. }
  5812. // check element directives
  5813. if (!linkFn) {
  5814. linkFn = checkElementDirectives(el, options);
  5815. }
  5816. // check component
  5817. if (!linkFn) {
  5818. linkFn = checkComponent(el, options);
  5819. }
  5820. // normal directives
  5821. if (!linkFn && hasAttrs) {
  5822. linkFn = compileDirectives(el.attributes, options);
  5823. }
  5824. return linkFn;
  5825. }
  5826. /**
  5827. * Compile a textNode and return a nodeLinkFn.
  5828. *
  5829. * @param {TextNode} node
  5830. * @param {Object} options
  5831. * @return {Function|null} textNodeLinkFn
  5832. */
  5833. function compileTextNode(node, options) {
  5834. // skip marked text nodes
  5835. if (node._skip) {
  5836. return removeText;
  5837. }
  5838. var tokens = parseText(node.wholeText);
  5839. if (!tokens) {
  5840. return null;
  5841. }
  5842. // mark adjacent text nodes as skipped,
  5843. // because we are using node.wholeText to compile
  5844. // all adjacent text nodes together. This fixes
  5845. // issues in IE where sometimes it splits up a single
  5846. // text node into multiple ones.
  5847. var next = node.nextSibling;
  5848. while (next && next.nodeType === 3) {
  5849. next._skip = true;
  5850. next = next.nextSibling;
  5851. }
  5852. var frag = document.createDocumentFragment();
  5853. var el, token;
  5854. for (var i = 0, l = tokens.length; i < l; i++) {
  5855. token = tokens[i];
  5856. el = token.tag ? processTextToken(token, options) : document.createTextNode(token.value);
  5857. frag.appendChild(el);
  5858. }
  5859. return makeTextNodeLinkFn(tokens, frag, options);
  5860. }
  5861. /**
  5862. * Linker for an skipped text node.
  5863. *
  5864. * @param {Vue} vm
  5865. * @param {Text} node
  5866. */
  5867. function removeText(vm, node) {
  5868. remove(node);
  5869. }
  5870. /**
  5871. * Process a single text token.
  5872. *
  5873. * @param {Object} token
  5874. * @param {Object} options
  5875. * @return {Node}
  5876. */
  5877. function processTextToken(token, options) {
  5878. var el;
  5879. if (token.oneTime) {
  5880. el = document.createTextNode(token.value);
  5881. } else {
  5882. if (token.html) {
  5883. el = document.createComment('v-html');
  5884. setTokenType('html');
  5885. } else {
  5886. // IE will clean up empty textNodes during
  5887. // frag.cloneNode(true), so we have to give it
  5888. // something here...
  5889. el = document.createTextNode(' ');
  5890. setTokenType('text');
  5891. }
  5892. }
  5893. function setTokenType(type) {
  5894. if (token.descriptor) return;
  5895. var parsed = parseDirective(token.value);
  5896. token.descriptor = {
  5897. name: type,
  5898. def: publicDirectives[type],
  5899. expression: parsed.expression,
  5900. filters: parsed.filters
  5901. };
  5902. }
  5903. return el;
  5904. }
  5905. /**
  5906. * Build a function that processes a textNode.
  5907. *
  5908. * @param {Array<Object>} tokens
  5909. * @param {DocumentFragment} frag
  5910. */
  5911. function makeTextNodeLinkFn(tokens, frag) {
  5912. return function textNodeLinkFn(vm, el, host, scope) {
  5913. var fragClone = frag.cloneNode(true);
  5914. var childNodes = toArray(fragClone.childNodes);
  5915. var token, value, node;
  5916. for (var i = 0, l = tokens.length; i < l; i++) {
  5917. token = tokens[i];
  5918. value = token.value;
  5919. if (token.tag) {
  5920. node = childNodes[i];
  5921. if (token.oneTime) {
  5922. value = (scope || vm).$eval(value);
  5923. if (token.html) {
  5924. replace(node, parseTemplate(value, true));
  5925. } else {
  5926. node.data = value;
  5927. }
  5928. } else {
  5929. vm._bindDir(token.descriptor, node, host, scope);
  5930. }
  5931. }
  5932. }
  5933. replace(el, fragClone);
  5934. };
  5935. }
  5936. /**
  5937. * Compile a node list and return a childLinkFn.
  5938. *
  5939. * @param {NodeList} nodeList
  5940. * @param {Object} options
  5941. * @return {Function|undefined}
  5942. */
  5943. function compileNodeList(nodeList, options) {
  5944. var linkFns = [];
  5945. var nodeLinkFn, childLinkFn, node;
  5946. for (var i = 0, l = nodeList.length; i < l; i++) {
  5947. node = nodeList[i];
  5948. nodeLinkFn = compileNode(node, options);
  5949. childLinkFn = !(nodeLinkFn && nodeLinkFn.terminal) && node.tagName !== 'SCRIPT' && node.hasChildNodes() ? compileNodeList(node.childNodes, options) : null;
  5950. linkFns.push(nodeLinkFn, childLinkFn);
  5951. }
  5952. return linkFns.length ? makeChildLinkFn(linkFns) : null;
  5953. }
  5954. /**
  5955. * Make a child link function for a node's childNodes.
  5956. *
  5957. * @param {Array<Function>} linkFns
  5958. * @return {Function} childLinkFn
  5959. */
  5960. function makeChildLinkFn(linkFns) {
  5961. return function childLinkFn(vm, nodes, host, scope, frag) {
  5962. var node, nodeLinkFn, childrenLinkFn;
  5963. for (var i = 0, n = 0, l = linkFns.length; i < l; n++) {
  5964. node = nodes[n];
  5965. nodeLinkFn = linkFns[i++];
  5966. childrenLinkFn = linkFns[i++];
  5967. // cache childNodes before linking parent, fix #657
  5968. var childNodes = toArray(node.childNodes);
  5969. if (nodeLinkFn) {
  5970. nodeLinkFn(vm, node, host, scope, frag);
  5971. }
  5972. if (childrenLinkFn) {
  5973. childrenLinkFn(vm, childNodes, host, scope, frag);
  5974. }
  5975. }
  5976. };
  5977. }
  5978. /**
  5979. * Check for element directives (custom elements that should
  5980. * be resovled as terminal directives).
  5981. *
  5982. * @param {Element} el
  5983. * @param {Object} options
  5984. */
  5985. function checkElementDirectives(el, options) {
  5986. var tag = el.tagName.toLowerCase();
  5987. if (commonTagRE.test(tag)) return;
  5988. var def = resolveAsset(options, 'elementDirectives', tag);
  5989. if (def) {
  5990. return makeTerminalNodeLinkFn(el, tag, '', options, def);
  5991. }
  5992. }
  5993. /**
  5994. * Check if an element is a component. If yes, return
  5995. * a component link function.
  5996. *
  5997. * @param {Element} el
  5998. * @param {Object} options
  5999. * @return {Function|undefined}
  6000. */
  6001. function checkComponent(el, options) {
  6002. var component = checkComponentAttr(el, options);
  6003. if (component) {
  6004. var ref = findRef(el);
  6005. var descriptor = {
  6006. name: 'component',
  6007. ref: ref,
  6008. expression: component.id,
  6009. def: internalDirectives.component,
  6010. modifiers: {
  6011. literal: !component.dynamic
  6012. }
  6013. };
  6014. var componentLinkFn = function componentLinkFn(vm, el, host, scope, frag) {
  6015. if (ref) {
  6016. defineReactive((scope || vm).$refs, ref, null);
  6017. }
  6018. vm._bindDir(descriptor, el, host, scope, frag);
  6019. };
  6020. componentLinkFn.terminal = true;
  6021. return componentLinkFn;
  6022. }
  6023. }
  6024. /**
  6025. * Check an element for terminal directives in fixed order.
  6026. * If it finds one, return a terminal link function.
  6027. *
  6028. * @param {Element} el
  6029. * @param {Object} options
  6030. * @return {Function} terminalLinkFn
  6031. */
  6032. function checkTerminalDirectives(el, options) {
  6033. // skip v-pre
  6034. if (getAttr(el, 'v-pre') !== null) {
  6035. return skip;
  6036. }
  6037. // skip v-else block, but only if following v-if
  6038. if (el.hasAttribute('v-else')) {
  6039. var prev = el.previousElementSibling;
  6040. if (prev && prev.hasAttribute('v-if')) {
  6041. return skip;
  6042. }
  6043. }
  6044. var value, dirName;
  6045. for (var i = 0, l = terminalDirectives.length; i < l; i++) {
  6046. dirName = terminalDirectives[i];
  6047. /* eslint-disable no-cond-assign */
  6048. if (value = el.getAttribute('v-' + dirName)) {
  6049. return makeTerminalNodeLinkFn(el, dirName, value, options);
  6050. }
  6051. /* eslint-enable no-cond-assign */
  6052. }
  6053. }
  6054. function skip() {}
  6055. skip.terminal = true;
  6056. /**
  6057. * Build a node link function for a terminal directive.
  6058. * A terminal link function terminates the current
  6059. * compilation recursion and handles compilation of the
  6060. * subtree in the directive.
  6061. *
  6062. * @param {Element} el
  6063. * @param {String} dirName
  6064. * @param {String} value
  6065. * @param {Object} options
  6066. * @param {Object} [def]
  6067. * @return {Function} terminalLinkFn
  6068. */
  6069. function makeTerminalNodeLinkFn(el, dirName, value, options, def) {
  6070. var parsed = parseDirective(value);
  6071. var descriptor = {
  6072. name: dirName,
  6073. expression: parsed.expression,
  6074. filters: parsed.filters,
  6075. raw: value,
  6076. // either an element directive, or if/for
  6077. def: def || publicDirectives[dirName]
  6078. };
  6079. // check ref for v-for and router-view
  6080. if (dirName === 'for' || dirName === 'router-view') {
  6081. descriptor.ref = findRef(el);
  6082. }
  6083. var fn = function terminalNodeLinkFn(vm, el, host, scope, frag) {
  6084. if (descriptor.ref) {
  6085. defineReactive((scope || vm).$refs, descriptor.ref, null);
  6086. }
  6087. vm._bindDir(descriptor, el, host, scope, frag);
  6088. };
  6089. fn.terminal = true;
  6090. return fn;
  6091. }
  6092. /**
  6093. * Compile the directives on an element and return a linker.
  6094. *
  6095. * @param {Array|NamedNodeMap} attrs
  6096. * @param {Object} options
  6097. * @return {Function}
  6098. */
  6099. function compileDirectives(attrs, options) {
  6100. var i = attrs.length;
  6101. var dirs = [];
  6102. var attr, name, value, rawName, rawValue, dirName, arg, modifiers, dirDef, tokens;
  6103. while (i--) {
  6104. attr = attrs[i];
  6105. name = rawName = attr.name;
  6106. value = rawValue = attr.value;
  6107. tokens = parseText(value);
  6108. // reset arg
  6109. arg = null;
  6110. // check modifiers
  6111. modifiers = parseModifiers(name);
  6112. name = name.replace(modifierRE, '');
  6113. // attribute interpolations
  6114. if (tokens) {
  6115. value = tokensToExp(tokens);
  6116. arg = name;
  6117. pushDir('bind', publicDirectives.bind, true);
  6118. // warn against mixing mustaches with v-bind
  6119. if ('development' !== 'production') {
  6120. if (name === 'class' && Array.prototype.some.call(attrs, function (attr) {
  6121. return attr.name === ':class' || attr.name === 'v-bind:class';
  6122. })) {
  6123. warn('class="' + rawValue + '": Do not mix mustache interpolation ' + 'and v-bind for "class" on the same element. Use one or the other.');
  6124. }
  6125. }
  6126. } else
  6127. // special attribute: transition
  6128. if (transitionRE.test(name)) {
  6129. modifiers.literal = !bindRE.test(name);
  6130. pushDir('transition', internalDirectives.transition);
  6131. } else
  6132. // event handlers
  6133. if (onRE.test(name)) {
  6134. arg = name.replace(onRE, '');
  6135. pushDir('on', publicDirectives.on);
  6136. } else
  6137. // attribute bindings
  6138. if (bindRE.test(name)) {
  6139. dirName = name.replace(bindRE, '');
  6140. if (dirName === 'style' || dirName === 'class') {
  6141. pushDir(dirName, internalDirectives[dirName]);
  6142. } else {
  6143. arg = dirName;
  6144. pushDir('bind', publicDirectives.bind);
  6145. }
  6146. } else
  6147. // normal directives
  6148. if (name.indexOf('v-') === 0) {
  6149. // check arg
  6150. arg = (arg = name.match(argRE)) && arg[1];
  6151. if (arg) {
  6152. name = name.replace(argRE, '');
  6153. }
  6154. // extract directive name
  6155. dirName = name.slice(2);
  6156. // skip v-else (when used with v-show)
  6157. if (dirName === 'else') {
  6158. continue;
  6159. }
  6160. dirDef = resolveAsset(options, 'directives', dirName);
  6161. if ('development' !== 'production') {
  6162. assertAsset(dirDef, 'directive', dirName);
  6163. }
  6164. if (dirDef) {
  6165. pushDir(dirName, dirDef);
  6166. }
  6167. }
  6168. }
  6169. /**
  6170. * Push a directive.
  6171. *
  6172. * @param {String} dirName
  6173. * @param {Object|Function} def
  6174. * @param {Boolean} [interp]
  6175. */
  6176. function pushDir(dirName, def, interp) {
  6177. var parsed = parseDirective(value);
  6178. dirs.push({
  6179. name: dirName,
  6180. attr: rawName,
  6181. raw: rawValue,
  6182. def: def,
  6183. arg: arg,
  6184. modifiers: modifiers,
  6185. expression: parsed.expression,
  6186. filters: parsed.filters,
  6187. interp: interp
  6188. });
  6189. }
  6190. if (dirs.length) {
  6191. return makeNodeLinkFn(dirs);
  6192. }
  6193. }
  6194. /**
  6195. * Parse modifiers from directive attribute name.
  6196. *
  6197. * @param {String} name
  6198. * @return {Object}
  6199. */
  6200. function parseModifiers(name) {
  6201. var res = Object.create(null);
  6202. var match = name.match(modifierRE);
  6203. if (match) {
  6204. var i = match.length;
  6205. while (i--) {
  6206. res[match[i].slice(1)] = true;
  6207. }
  6208. }
  6209. return res;
  6210. }
  6211. /**
  6212. * Build a link function for all directives on a single node.
  6213. *
  6214. * @param {Array} directives
  6215. * @return {Function} directivesLinkFn
  6216. */
  6217. function makeNodeLinkFn(directives) {
  6218. return function nodeLinkFn(vm, el, host, scope, frag) {
  6219. // reverse apply because it's sorted low to high
  6220. var i = directives.length;
  6221. while (i--) {
  6222. vm._bindDir(directives[i], el, host, scope, frag);
  6223. }
  6224. };
  6225. }
  6226. var specialCharRE = /[^\w\-:\.]/;
  6227. /**
  6228. * Process an element or a DocumentFragment based on a
  6229. * instance option object. This allows us to transclude
  6230. * a template node/fragment before the instance is created,
  6231. * so the processed fragment can then be cloned and reused
  6232. * in v-for.
  6233. *
  6234. * @param {Element} el
  6235. * @param {Object} options
  6236. * @return {Element|DocumentFragment}
  6237. */
  6238. function transclude(el, options) {
  6239. // extract container attributes to pass them down
  6240. // to compiler, because they need to be compiled in
  6241. // parent scope. we are mutating the options object here
  6242. // assuming the same object will be used for compile
  6243. // right after this.
  6244. if (options) {
  6245. options._containerAttrs = extractAttrs(el);
  6246. }
  6247. // for template tags, what we want is its content as
  6248. // a documentFragment (for fragment instances)
  6249. if (isTemplate(el)) {
  6250. el = parseTemplate(el);
  6251. }
  6252. if (options) {
  6253. if (options._asComponent && !options.template) {
  6254. options.template = '<slot></slot>';
  6255. }
  6256. if (options.template) {
  6257. options._content = extractContent(el);
  6258. el = transcludeTemplate(el, options);
  6259. }
  6260. }
  6261. if (el instanceof DocumentFragment) {
  6262. // anchors for fragment instance
  6263. // passing in `persist: true` to avoid them being
  6264. // discarded by IE during template cloning
  6265. prepend(createAnchor('v-start', true), el);
  6266. el.appendChild(createAnchor('v-end', true));
  6267. }
  6268. return el;
  6269. }
  6270. /**
  6271. * Process the template option.
  6272. * If the replace option is true this will swap the $el.
  6273. *
  6274. * @param {Element} el
  6275. * @param {Object} options
  6276. * @return {Element|DocumentFragment}
  6277. */
  6278. function transcludeTemplate(el, options) {
  6279. var template = options.template;
  6280. var frag = parseTemplate(template, true);
  6281. if (frag) {
  6282. var replacer = frag.firstChild;
  6283. var tag = replacer.tagName && replacer.tagName.toLowerCase();
  6284. if (options.replace) {
  6285. /* istanbul ignore if */
  6286. if (el === document.body) {
  6287. 'development' !== 'production' && warn('You are mounting an instance with a template to ' + '<body>. This will replace <body> entirely. You ' + 'should probably use `replace: false` here.');
  6288. }
  6289. // there are many cases where the instance must
  6290. // become a fragment instance: basically anything that
  6291. // can create more than 1 root nodes.
  6292. if (
  6293. // multi-children template
  6294. frag.childNodes.length > 1 ||
  6295. // non-element template
  6296. replacer.nodeType !== 1 ||
  6297. // single nested component
  6298. tag === 'component' || resolveAsset(options, 'components', tag) || replacer.hasAttribute('is') || replacer.hasAttribute(':is') || replacer.hasAttribute('v-bind:is') ||
  6299. // element directive
  6300. resolveAsset(options, 'elementDirectives', tag) ||
  6301. // for block
  6302. replacer.hasAttribute('v-for') ||
  6303. // if block
  6304. replacer.hasAttribute('v-if')) {
  6305. return frag;
  6306. } else {
  6307. options._replacerAttrs = extractAttrs(replacer);
  6308. mergeAttrs(el, replacer);
  6309. return replacer;
  6310. }
  6311. } else {
  6312. el.appendChild(frag);
  6313. return el;
  6314. }
  6315. } else {
  6316. 'development' !== 'production' && warn('Invalid template option: ' + template);
  6317. }
  6318. }
  6319. /**
  6320. * Helper to extract a component container's attributes
  6321. * into a plain object array.
  6322. *
  6323. * @param {Element} el
  6324. * @return {Array}
  6325. */
  6326. function extractAttrs(el) {
  6327. if (el.nodeType === 1 && el.hasAttributes()) {
  6328. return toArray(el.attributes);
  6329. }
  6330. }
  6331. /**
  6332. * Merge the attributes of two elements, and make sure
  6333. * the class names are merged properly.
  6334. *
  6335. * @param {Element} from
  6336. * @param {Element} to
  6337. */
  6338. function mergeAttrs(from, to) {
  6339. var attrs = from.attributes;
  6340. var i = attrs.length;
  6341. var name, value;
  6342. while (i--) {
  6343. name = attrs[i].name;
  6344. value = attrs[i].value;
  6345. if (!to.hasAttribute(name) && !specialCharRE.test(name)) {
  6346. to.setAttribute(name, value);
  6347. } else if (name === 'class') {
  6348. value.split(/\s+/).forEach(function (cls) {
  6349. addClass(to, cls);
  6350. });
  6351. }
  6352. }
  6353. }
  6354. var compiler = Object.freeze({
  6355. compile: compile,
  6356. compileAndLinkProps: compileAndLinkProps,
  6357. compileRoot: compileRoot,
  6358. transclude: transclude
  6359. });
  6360. function stateMixin (Vue) {
  6361. /**
  6362. * Accessor for `$data` property, since setting $data
  6363. * requires observing the new object and updating
  6364. * proxied properties.
  6365. */
  6366. Object.defineProperty(Vue.prototype, '$data', {
  6367. get: function get() {
  6368. return this._data;
  6369. },
  6370. set: function set(newData) {
  6371. if (newData !== this._data) {
  6372. this._setData(newData);
  6373. }
  6374. }
  6375. });
  6376. /**
  6377. * Setup the scope of an instance, which contains:
  6378. * - observed data
  6379. * - computed properties
  6380. * - user methods
  6381. * - meta properties
  6382. */
  6383. Vue.prototype._initState = function () {
  6384. this._initProps();
  6385. this._initMeta();
  6386. this._initMethods();
  6387. this._initData();
  6388. this._initComputed();
  6389. };
  6390. /**
  6391. * Initialize props.
  6392. */
  6393. Vue.prototype._initProps = function () {
  6394. var options = this.$options;
  6395. var el = options.el;
  6396. var props = options.props;
  6397. if (props && !el) {
  6398. 'development' !== 'production' && warn('Props will not be compiled if no `el` option is ' + 'provided at instantiation.');
  6399. }
  6400. // make sure to convert string selectors into element now
  6401. el = options.el = query(el);
  6402. this._propsUnlinkFn = el && el.nodeType === 1 && props
  6403. // props must be linked in proper scope if inside v-for
  6404. ? compileAndLinkProps(this, el, props, this._scope) : null;
  6405. };
  6406. /**
  6407. * Initialize the data.
  6408. */
  6409. Vue.prototype._initData = function () {
  6410. var propsData = this._data;
  6411. var optionsDataFn = this.$options.data;
  6412. var optionsData = optionsDataFn && optionsDataFn();
  6413. if (optionsData) {
  6414. this._data = optionsData;
  6415. for (var prop in propsData) {
  6416. if ('development' !== 'production' && hasOwn(optionsData, prop)) {
  6417. warn('Data field "' + prop + '" is already defined ' + 'as a prop. Use prop default value instead.');
  6418. }
  6419. if (this._props[prop].raw !== null || !hasOwn(optionsData, prop)) {
  6420. set(optionsData, prop, propsData[prop]);
  6421. }
  6422. }
  6423. }
  6424. var data = this._data;
  6425. // proxy data on instance
  6426. var keys = Object.keys(data);
  6427. var i, key;
  6428. i = keys.length;
  6429. while (i--) {
  6430. key = keys[i];
  6431. this._proxy(key);
  6432. }
  6433. // observe data
  6434. observe(data, this);
  6435. };
  6436. /**
  6437. * Swap the instance's $data. Called in $data's setter.
  6438. *
  6439. * @param {Object} newData
  6440. */
  6441. Vue.prototype._setData = function (newData) {
  6442. newData = newData || {};
  6443. var oldData = this._data;
  6444. this._data = newData;
  6445. var keys, key, i;
  6446. // unproxy keys not present in new data
  6447. keys = Object.keys(oldData);
  6448. i = keys.length;
  6449. while (i--) {
  6450. key = keys[i];
  6451. if (!(key in newData)) {
  6452. this._unproxy(key);
  6453. }
  6454. }
  6455. // proxy keys not already proxied,
  6456. // and trigger change for changed values
  6457. keys = Object.keys(newData);
  6458. i = keys.length;
  6459. while (i--) {
  6460. key = keys[i];
  6461. if (!hasOwn(this, key)) {
  6462. // new property
  6463. this._proxy(key);
  6464. }
  6465. }
  6466. oldData.__ob__.removeVm(this);
  6467. observe(newData, this);
  6468. this._digest();
  6469. };
  6470. /**
  6471. * Proxy a property, so that
  6472. * vm.prop === vm._data.prop
  6473. *
  6474. * @param {String} key
  6475. */
  6476. Vue.prototype._proxy = function (key) {
  6477. if (!isReserved(key)) {
  6478. // need to store ref to self here
  6479. // because these getter/setters might
  6480. // be called by child scopes via
  6481. // prototype inheritance.
  6482. var self = this;
  6483. Object.defineProperty(self, key, {
  6484. configurable: true,
  6485. enumerable: true,
  6486. get: function proxyGetter() {
  6487. return self._data[key];
  6488. },
  6489. set: function proxySetter(val) {
  6490. self._data[key] = val;
  6491. }
  6492. });
  6493. }
  6494. };
  6495. /**
  6496. * Unproxy a property.
  6497. *
  6498. * @param {String} key
  6499. */
  6500. Vue.prototype._unproxy = function (key) {
  6501. if (!isReserved(key)) {
  6502. delete this[key];
  6503. }
  6504. };
  6505. /**
  6506. * Force update on every watcher in scope.
  6507. */
  6508. Vue.prototype._digest = function () {
  6509. for (var i = 0, l = this._watchers.length; i < l; i++) {
  6510. this._watchers[i].update(true); // shallow updates
  6511. }
  6512. };
  6513. /**
  6514. * Setup computed properties. They are essentially
  6515. * special getter/setters
  6516. */
  6517. function noop() {}
  6518. Vue.prototype._initComputed = function () {
  6519. var computed = this.$options.computed;
  6520. if (computed) {
  6521. for (var key in computed) {
  6522. var userDef = computed[key];
  6523. var def = {
  6524. enumerable: true,
  6525. configurable: true
  6526. };
  6527. if (typeof userDef === 'function') {
  6528. def.get = makeComputedGetter(userDef, this);
  6529. def.set = noop;
  6530. } else {
  6531. def.get = userDef.get ? userDef.cache !== false ? makeComputedGetter(userDef.get, this) : bind$1(userDef.get, this) : noop;
  6532. def.set = userDef.set ? bind$1(userDef.set, this) : noop;
  6533. }
  6534. Object.defineProperty(this, key, def);
  6535. }
  6536. }
  6537. };
  6538. function makeComputedGetter(getter, owner) {
  6539. var watcher = new Watcher(owner, getter, null, {
  6540. lazy: true
  6541. });
  6542. return function computedGetter() {
  6543. if (watcher.dirty) {
  6544. watcher.evaluate();
  6545. }
  6546. if (Dep.target) {
  6547. watcher.depend();
  6548. }
  6549. return watcher.value;
  6550. };
  6551. }
  6552. /**
  6553. * Setup instance methods. Methods must be bound to the
  6554. * instance since they might be passed down as a prop to
  6555. * child components.
  6556. */
  6557. Vue.prototype._initMethods = function () {
  6558. var methods = this.$options.methods;
  6559. if (methods) {
  6560. for (var key in methods) {
  6561. this[key] = bind$1(methods[key], this);
  6562. }
  6563. }
  6564. };
  6565. /**
  6566. * Initialize meta information like $index, $key & $value.
  6567. */
  6568. Vue.prototype._initMeta = function () {
  6569. var metas = this.$options._meta;
  6570. if (metas) {
  6571. for (var key in metas) {
  6572. defineReactive(this, key, metas[key]);
  6573. }
  6574. }
  6575. };
  6576. }
  6577. var eventRE = /^v-on:|^@/;
  6578. function eventsMixin (Vue) {
  6579. /**
  6580. * Setup the instance's option events & watchers.
  6581. * If the value is a string, we pull it from the
  6582. * instance's methods by name.
  6583. */
  6584. Vue.prototype._initEvents = function () {
  6585. var options = this.$options;
  6586. if (options._asComponent) {
  6587. registerComponentEvents(this, options.el);
  6588. }
  6589. registerCallbacks(this, '$on', options.events);
  6590. registerCallbacks(this, '$watch', options.watch);
  6591. };
  6592. /**
  6593. * Register v-on events on a child component
  6594. *
  6595. * @param {Vue} vm
  6596. * @param {Element} el
  6597. */
  6598. function registerComponentEvents(vm, el) {
  6599. var attrs = el.attributes;
  6600. var name, handler;
  6601. for (var i = 0, l = attrs.length; i < l; i++) {
  6602. name = attrs[i].name;
  6603. if (eventRE.test(name)) {
  6604. name = name.replace(eventRE, '');
  6605. handler = (vm._scope || vm._context).$eval(attrs[i].value, true);
  6606. vm.$on(name.replace(eventRE), handler);
  6607. }
  6608. }
  6609. }
  6610. /**
  6611. * Register callbacks for option events and watchers.
  6612. *
  6613. * @param {Vue} vm
  6614. * @param {String} action
  6615. * @param {Object} hash
  6616. */
  6617. function registerCallbacks(vm, action, hash) {
  6618. if (!hash) return;
  6619. var handlers, key, i, j;
  6620. for (key in hash) {
  6621. handlers = hash[key];
  6622. if (isArray(handlers)) {
  6623. for (i = 0, j = handlers.length; i < j; i++) {
  6624. register(vm, action, key, handlers[i]);
  6625. }
  6626. } else {
  6627. register(vm, action, key, handlers);
  6628. }
  6629. }
  6630. }
  6631. /**
  6632. * Helper to register an event/watch callback.
  6633. *
  6634. * @param {Vue} vm
  6635. * @param {String} action
  6636. * @param {String} key
  6637. * @param {Function|String|Object} handler
  6638. * @param {Object} [options]
  6639. */
  6640. function register(vm, action, key, handler, options) {
  6641. var type = typeof handler;
  6642. if (type === 'function') {
  6643. vm[action](key, handler, options);
  6644. } else if (type === 'string') {
  6645. var methods = vm.$options.methods;
  6646. var method = methods && methods[handler];
  6647. if (method) {
  6648. vm[action](key, method, options);
  6649. } else {
  6650. 'development' !== 'production' && warn('Unknown method: "' + handler + '" when ' + 'registering callback for ' + action + ': "' + key + '".');
  6651. }
  6652. } else if (handler && type === 'object') {
  6653. register(vm, action, key, handler.handler, handler);
  6654. }
  6655. }
  6656. /**
  6657. * Setup recursive attached/detached calls
  6658. */
  6659. Vue.prototype._initDOMHooks = function () {
  6660. this.$on('hook:attached', onAttached);
  6661. this.$on('hook:detached', onDetached);
  6662. };
  6663. /**
  6664. * Callback to recursively call attached hook on children
  6665. */
  6666. function onAttached() {
  6667. if (!this._isAttached) {
  6668. this._isAttached = true;
  6669. this.$children.forEach(callAttach);
  6670. }
  6671. }
  6672. /**
  6673. * Iterator to call attached hook
  6674. *
  6675. * @param {Vue} child
  6676. */
  6677. function callAttach(child) {
  6678. if (!child._isAttached && inDoc(child.$el)) {
  6679. child._callHook('attached');
  6680. }
  6681. }
  6682. /**
  6683. * Callback to recursively call detached hook on children
  6684. */
  6685. function onDetached() {
  6686. if (this._isAttached) {
  6687. this._isAttached = false;
  6688. this.$children.forEach(callDetach);
  6689. }
  6690. }
  6691. /**
  6692. * Iterator to call detached hook
  6693. *
  6694. * @param {Vue} child
  6695. */
  6696. function callDetach(child) {
  6697. if (child._isAttached && !inDoc(child.$el)) {
  6698. child._callHook('detached');
  6699. }
  6700. }
  6701. /**
  6702. * Trigger all handlers for a hook
  6703. *
  6704. * @param {String} hook
  6705. */
  6706. Vue.prototype._callHook = function (hook) {
  6707. var handlers = this.$options[hook];
  6708. if (handlers) {
  6709. for (var i = 0, j = handlers.length; i < j; i++) {
  6710. handlers[i].call(this);
  6711. }
  6712. }
  6713. this.$emit('hook:' + hook);
  6714. };
  6715. }
  6716. function noop() {}
  6717. /**
  6718. * A directive links a DOM element with a piece of data,
  6719. * which is the result of evaluating an expression.
  6720. * It registers a watcher with the expression and calls
  6721. * the DOM update function when a change is triggered.
  6722. *
  6723. * @param {String} name
  6724. * @param {Node} el
  6725. * @param {Vue} vm
  6726. * @param {Object} descriptor
  6727. * - {String} name
  6728. * - {Object} def
  6729. * - {String} expression
  6730. * - {Array<Object>} [filters]
  6731. * - {Boolean} literal
  6732. * - {String} attr
  6733. * - {String} raw
  6734. * @param {Object} def - directive definition object
  6735. * @param {Vue} [host] - transclusion host component
  6736. * @param {Object} [scope] - v-for scope
  6737. * @param {Fragment} [frag] - owner fragment
  6738. * @constructor
  6739. */
  6740. function Directive(descriptor, vm, el, host, scope, frag) {
  6741. this.vm = vm;
  6742. this.el = el;
  6743. // copy descriptor properties
  6744. this.descriptor = descriptor;
  6745. this.name = descriptor.name;
  6746. this.expression = descriptor.expression;
  6747. this.arg = descriptor.arg;
  6748. this.modifiers = descriptor.modifiers;
  6749. this.filters = descriptor.filters;
  6750. this.literal = this.modifiers && this.modifiers.literal;
  6751. // private
  6752. this._locked = false;
  6753. this._bound = false;
  6754. this._listeners = null;
  6755. // link context
  6756. this._host = host;
  6757. this._scope = scope;
  6758. this._frag = frag;
  6759. // store directives on node in dev mode
  6760. if ('development' !== 'production' && this.el) {
  6761. this.el._vue_directives = this.el._vue_directives || [];
  6762. this.el._vue_directives.push(this);
  6763. }
  6764. }
  6765. /**
  6766. * Initialize the directive, mixin definition properties,
  6767. * setup the watcher, call definition bind() and update()
  6768. * if present.
  6769. *
  6770. * @param {Object} def
  6771. */
  6772. Directive.prototype._bind = function () {
  6773. var name = this.name;
  6774. var descriptor = this.descriptor;
  6775. // remove attribute
  6776. if ((name !== 'cloak' || this.vm._isCompiled) && this.el && this.el.removeAttribute) {
  6777. var attr = descriptor.attr || 'v-' + name;
  6778. this.el.removeAttribute(attr);
  6779. }
  6780. // copy def properties
  6781. var def = descriptor.def;
  6782. if (typeof def === 'function') {
  6783. this.update = def;
  6784. } else {
  6785. extend(this, def);
  6786. }
  6787. // setup directive params
  6788. this._setupParams();
  6789. // initial bind
  6790. if (this.bind) {
  6791. this.bind();
  6792. }
  6793. if (this.literal) {
  6794. this.update && this.update(descriptor.raw);
  6795. } else if ((this.expression || this.modifiers) && (this.update || this.twoWay) && !this._checkStatement()) {
  6796. // wrapped updater for context
  6797. var dir = this;
  6798. if (this.update) {
  6799. this._update = function (val, oldVal) {
  6800. if (!dir._locked) {
  6801. dir.update(val, oldVal);
  6802. }
  6803. };
  6804. } else {
  6805. this._update = noop;
  6806. }
  6807. var preProcess = this._preProcess ? bind$1(this._preProcess, this) : null;
  6808. var postProcess = this._postProcess ? bind$1(this._postProcess, this) : null;
  6809. var watcher = this._watcher = new Watcher(this.vm, this.expression, this._update, // callback
  6810. {
  6811. filters: this.filters,
  6812. twoWay: this.twoWay,
  6813. deep: this.deep,
  6814. preProcess: preProcess,
  6815. postProcess: postProcess,
  6816. scope: this._scope
  6817. });
  6818. // v-model with inital inline value need to sync back to
  6819. // model instead of update to DOM on init. They would
  6820. // set the afterBind hook to indicate that.
  6821. if (this.afterBind) {
  6822. this.afterBind();
  6823. } else if (this.update) {
  6824. this.update(watcher.value);
  6825. }
  6826. }
  6827. this._bound = true;
  6828. };
  6829. /**
  6830. * Setup all param attributes, e.g. track-by,
  6831. * transition-mode, etc...
  6832. */
  6833. Directive.prototype._setupParams = function () {
  6834. if (!this.params) {
  6835. return;
  6836. }
  6837. var params = this.params;
  6838. // swap the params array with a fresh object.
  6839. this.params = Object.create(null);
  6840. var i = params.length;
  6841. var key, val, mappedKey;
  6842. while (i--) {
  6843. key = params[i];
  6844. mappedKey = camelize(key);
  6845. val = getBindAttr(this.el, key);
  6846. if (val != null) {
  6847. // dynamic
  6848. this._setupParamWatcher(mappedKey, val);
  6849. } else {
  6850. // static
  6851. val = getAttr(this.el, key);
  6852. if (val != null) {
  6853. this.params[mappedKey] = val === '' ? true : val;
  6854. }
  6855. }
  6856. }
  6857. };
  6858. /**
  6859. * Setup a watcher for a dynamic param.
  6860. *
  6861. * @param {String} key
  6862. * @param {String} expression
  6863. */
  6864. Directive.prototype._setupParamWatcher = function (key, expression) {
  6865. var self = this;
  6866. var called = false;
  6867. var unwatch = (this._scope || this.vm).$watch(expression, function (val, oldVal) {
  6868. self.params[key] = val;
  6869. // since we are in immediate mode,
  6870. // only call the param change callbacks if this is not the first update.
  6871. if (called) {
  6872. var cb = self.paramWatchers && self.paramWatchers[key];
  6873. if (cb) {
  6874. cb.call(self, val, oldVal);
  6875. }
  6876. } else {
  6877. called = true;
  6878. }
  6879. }, {
  6880. immediate: true
  6881. });(this._paramUnwatchFns || (this._paramUnwatchFns = [])).push(unwatch);
  6882. };
  6883. /**
  6884. * Check if the directive is a function caller
  6885. * and if the expression is a callable one. If both true,
  6886. * we wrap up the expression and use it as the event
  6887. * handler.
  6888. *
  6889. * e.g. on-click="a++"
  6890. *
  6891. * @return {Boolean}
  6892. */
  6893. Directive.prototype._checkStatement = function () {
  6894. var expression = this.expression;
  6895. if (expression && this.acceptStatement && !isSimplePath(expression)) {
  6896. var fn = parseExpression(expression).get;
  6897. var scope = this._scope || this.vm;
  6898. var handler = function handler(e) {
  6899. scope.$event = e;
  6900. fn.call(scope, scope);
  6901. scope.$event = null;
  6902. };
  6903. if (this.filters) {
  6904. handler = scope._applyFilters(handler, null, this.filters);
  6905. }
  6906. this.update(handler);
  6907. return true;
  6908. }
  6909. };
  6910. /**
  6911. * Set the corresponding value with the setter.
  6912. * This should only be used in two-way directives
  6913. * e.g. v-model.
  6914. *
  6915. * @param {*} value
  6916. * @public
  6917. */
  6918. Directive.prototype.set = function (value) {
  6919. /* istanbul ignore else */
  6920. if (this.twoWay) {
  6921. this._withLock(function () {
  6922. this._watcher.set(value);
  6923. });
  6924. } else if ('development' !== 'production') {
  6925. warn('Directive.set() can only be used inside twoWay' + 'directives.');
  6926. }
  6927. };
  6928. /**
  6929. * Execute a function while preventing that function from
  6930. * triggering updates on this directive instance.
  6931. *
  6932. * @param {Function} fn
  6933. */
  6934. Directive.prototype._withLock = function (fn) {
  6935. var self = this;
  6936. self._locked = true;
  6937. fn.call(self);
  6938. nextTick(function () {
  6939. self._locked = false;
  6940. });
  6941. };
  6942. /**
  6943. * Convenience method that attaches a DOM event listener
  6944. * to the directive element and autometically tears it down
  6945. * during unbind.
  6946. *
  6947. * @param {String} event
  6948. * @param {Function} handler
  6949. */
  6950. Directive.prototype.on = function (event, handler) {
  6951. on$1(this.el, event, handler);(this._listeners || (this._listeners = [])).push([event, handler]);
  6952. };
  6953. /**
  6954. * Teardown the watcher and call unbind.
  6955. */
  6956. Directive.prototype._teardown = function () {
  6957. if (this._bound) {
  6958. this._bound = false;
  6959. if (this.unbind) {
  6960. this.unbind();
  6961. }
  6962. if (this._watcher) {
  6963. this._watcher.teardown();
  6964. }
  6965. var listeners = this._listeners;
  6966. var i;
  6967. if (listeners) {
  6968. i = listeners.length;
  6969. while (i--) {
  6970. off(this.el, listeners[i][0], listeners[i][1]);
  6971. }
  6972. }
  6973. var unwatchFns = this._paramUnwatchFns;
  6974. if (unwatchFns) {
  6975. i = unwatchFns.length;
  6976. while (i--) {
  6977. unwatchFns[i]();
  6978. }
  6979. }
  6980. if ('development' !== 'production' && this.el) {
  6981. this.el._vue_directives.$remove(this);
  6982. }
  6983. this.vm = this.el = this._watcher = this._listeners = null;
  6984. }
  6985. };
  6986. function lifecycleMixin (Vue) {
  6987. /**
  6988. * Update v-ref for component.
  6989. *
  6990. * @param {Boolean} remove
  6991. */
  6992. Vue.prototype._updateRef = function (remove) {
  6993. var ref = this.$options._ref;
  6994. if (ref) {
  6995. var refs = (this._scope || this._context).$refs;
  6996. if (remove) {
  6997. if (refs[ref] === this) {
  6998. refs[ref] = null;
  6999. }
  7000. } else {
  7001. refs[ref] = this;
  7002. }
  7003. }
  7004. };
  7005. /**
  7006. * Transclude, compile and link element.
  7007. *
  7008. * If a pre-compiled linker is available, that means the
  7009. * passed in element will be pre-transcluded and compiled
  7010. * as well - all we need to do is to call the linker.
  7011. *
  7012. * Otherwise we need to call transclude/compile/link here.
  7013. *
  7014. * @param {Element} el
  7015. * @return {Element}
  7016. */
  7017. Vue.prototype._compile = function (el) {
  7018. var options = this.$options;
  7019. // transclude and init element
  7020. // transclude can potentially replace original
  7021. // so we need to keep reference; this step also injects
  7022. // the template and caches the original attributes
  7023. // on the container node and replacer node.
  7024. var original = el;
  7025. el = transclude(el, options);
  7026. this._initElement(el);
  7027. // root is always compiled per-instance, because
  7028. // container attrs and props can be different every time.
  7029. var contextOptions = this._context && this._context.$options;
  7030. var rootLinker = compileRoot(el, options, contextOptions);
  7031. // compile and link the rest
  7032. var contentLinkFn;
  7033. var ctor = this.constructor;
  7034. // component compilation can be cached
  7035. // as long as it's not using inline-template
  7036. if (options._linkerCachable) {
  7037. contentLinkFn = ctor.linker;
  7038. if (!contentLinkFn) {
  7039. contentLinkFn = ctor.linker = compile(el, options);
  7040. }
  7041. }
  7042. // link phase
  7043. // make sure to link root with prop scope!
  7044. var rootUnlinkFn = rootLinker(this, el, this._scope);
  7045. var contentUnlinkFn = contentLinkFn ? contentLinkFn(this, el) : compile(el, options)(this, el);
  7046. // register composite unlink function
  7047. // to be called during instance destruction
  7048. this._unlinkFn = function () {
  7049. rootUnlinkFn();
  7050. // passing destroying: true to avoid searching and
  7051. // splicing the directives
  7052. contentUnlinkFn(true);
  7053. };
  7054. // finally replace original
  7055. if (options.replace) {
  7056. replace(original, el);
  7057. }
  7058. this._isCompiled = true;
  7059. this._callHook('compiled');
  7060. return el;
  7061. };
  7062. /**
  7063. * Initialize instance element. Called in the public
  7064. * $mount() method.
  7065. *
  7066. * @param {Element} el
  7067. */
  7068. Vue.prototype._initElement = function (el) {
  7069. if (el instanceof DocumentFragment) {
  7070. this._isFragment = true;
  7071. this.$el = this._fragmentStart = el.firstChild;
  7072. this._fragmentEnd = el.lastChild;
  7073. // set persisted text anchors to empty
  7074. if (this._fragmentStart.nodeType === 3) {
  7075. this._fragmentStart.data = this._fragmentEnd.data = '';
  7076. }
  7077. this._fragment = el;
  7078. } else {
  7079. this.$el = el;
  7080. }
  7081. this.$el.__vue__ = this;
  7082. this._callHook('beforeCompile');
  7083. };
  7084. /**
  7085. * Create and bind a directive to an element.
  7086. *
  7087. * @param {String} name - directive name
  7088. * @param {Node} node - target node
  7089. * @param {Object} desc - parsed directive descriptor
  7090. * @param {Object} def - directive definition object
  7091. * @param {Vue} [host] - transclusion host component
  7092. * @param {Object} [scope] - v-for scope
  7093. * @param {Fragment} [frag] - owner fragment
  7094. */
  7095. Vue.prototype._bindDir = function (descriptor, node, host, scope, frag) {
  7096. this._directives.push(new Directive(descriptor, this, node, host, scope, frag));
  7097. };
  7098. /**
  7099. * Teardown an instance, unobserves the data, unbind all the
  7100. * directives, turn off all the event listeners, etc.
  7101. *
  7102. * @param {Boolean} remove - whether to remove the DOM node.
  7103. * @param {Boolean} deferCleanup - if true, defer cleanup to
  7104. * be called later
  7105. */
  7106. Vue.prototype._destroy = function (remove, deferCleanup) {
  7107. if (this._isBeingDestroyed) {
  7108. if (!deferCleanup) {
  7109. this._cleanup();
  7110. }
  7111. return;
  7112. }
  7113. this._callHook('beforeDestroy');
  7114. this._isBeingDestroyed = true;
  7115. var i;
  7116. // remove self from parent. only necessary
  7117. // if parent is not being destroyed as well.
  7118. var parent = this.$parent;
  7119. if (parent && !parent._isBeingDestroyed) {
  7120. parent.$children.$remove(this);
  7121. // unregister ref (remove: true)
  7122. this._updateRef(true);
  7123. }
  7124. // destroy all children.
  7125. i = this.$children.length;
  7126. while (i--) {
  7127. this.$children[i].$destroy();
  7128. }
  7129. // teardown props
  7130. if (this._propsUnlinkFn) {
  7131. this._propsUnlinkFn();
  7132. }
  7133. // teardown all directives. this also tearsdown all
  7134. // directive-owned watchers.
  7135. if (this._unlinkFn) {
  7136. this._unlinkFn();
  7137. }
  7138. i = this._watchers.length;
  7139. while (i--) {
  7140. this._watchers[i].teardown();
  7141. }
  7142. // remove reference to self on $el
  7143. if (this.$el) {
  7144. this.$el.__vue__ = null;
  7145. }
  7146. // remove DOM element
  7147. var self = this;
  7148. if (remove && this.$el) {
  7149. this.$remove(function () {
  7150. self._cleanup();
  7151. });
  7152. } else if (!deferCleanup) {
  7153. this._cleanup();
  7154. }
  7155. };
  7156. /**
  7157. * Clean up to ensure garbage collection.
  7158. * This is called after the leave transition if there
  7159. * is any.
  7160. */
  7161. Vue.prototype._cleanup = function () {
  7162. if (this._isDestroyed) {
  7163. return;
  7164. }
  7165. // remove self from owner fragment
  7166. // do it in cleanup so that we can call $destroy with
  7167. // defer right when a fragment is about to be removed.
  7168. if (this._frag) {
  7169. this._frag.children.$remove(this);
  7170. }
  7171. // remove reference from data ob
  7172. // frozen object may not have observer.
  7173. if (this._data.__ob__) {
  7174. this._data.__ob__.removeVm(this);
  7175. }
  7176. // Clean up references to private properties and other
  7177. // instances. preserve reference to _data so that proxy
  7178. // accessors still work. The only potential side effect
  7179. // here is that mutating the instance after it's destroyed
  7180. // may affect the state of other components that are still
  7181. // observing the same object, but that seems to be a
  7182. // reasonable responsibility for the user rather than
  7183. // always throwing an error on them.
  7184. this.$el = this.$parent = this.$root = this.$children = this._watchers = this._context = this._scope = this._directives = null;
  7185. // call the last hook...
  7186. this._isDestroyed = true;
  7187. this._callHook('destroyed');
  7188. // turn off all instance listeners.
  7189. this.$off();
  7190. };
  7191. }
  7192. function miscMixin (Vue) {
  7193. /**
  7194. * Apply a list of filter (descriptors) to a value.
  7195. * Using plain for loops here because this will be called in
  7196. * the getter of any watcher with filters so it is very
  7197. * performance sensitive.
  7198. *
  7199. * @param {*} value
  7200. * @param {*} [oldValue]
  7201. * @param {Array} filters
  7202. * @param {Boolean} write
  7203. * @return {*}
  7204. */
  7205. Vue.prototype._applyFilters = function (value, oldValue, filters, write) {
  7206. var filter, fn, args, arg, offset, i, l, j, k;
  7207. for (i = 0, l = filters.length; i < l; i++) {
  7208. filter = filters[i];
  7209. fn = resolveAsset(this.$options, 'filters', filter.name);
  7210. if ('development' !== 'production') {
  7211. assertAsset(fn, 'filter', filter.name);
  7212. }
  7213. if (!fn) continue;
  7214. fn = write ? fn.write : fn.read || fn;
  7215. if (typeof fn !== 'function') continue;
  7216. args = write ? [value, oldValue] : [value];
  7217. offset = write ? 2 : 1;
  7218. if (filter.args) {
  7219. for (j = 0, k = filter.args.length; j < k; j++) {
  7220. arg = filter.args[j];
  7221. args[j + offset] = arg.dynamic ? this.$get(arg.value) : arg.value;
  7222. }
  7223. }
  7224. value = fn.apply(this, args);
  7225. }
  7226. return value;
  7227. };
  7228. /**
  7229. * Resolve a component, depending on whether the component
  7230. * is defined normally or using an async factory function.
  7231. * Resolves synchronously if already resolved, otherwise
  7232. * resolves asynchronously and caches the resolved
  7233. * constructor on the factory.
  7234. *
  7235. * @param {String} id
  7236. * @param {Function} cb
  7237. */
  7238. Vue.prototype._resolveComponent = function (id, cb) {
  7239. var factory = resolveAsset(this.$options, 'components', id);
  7240. if ('development' !== 'production') {
  7241. assertAsset(factory, 'component', id);
  7242. }
  7243. if (!factory) {
  7244. return;
  7245. }
  7246. // async component factory
  7247. if (!factory.options) {
  7248. if (factory.resolved) {
  7249. // cached
  7250. cb(factory.resolved);
  7251. } else if (factory.requested) {
  7252. // pool callbacks
  7253. factory.pendingCallbacks.push(cb);
  7254. } else {
  7255. factory.requested = true;
  7256. var cbs = factory.pendingCallbacks = [cb];
  7257. factory(function resolve(res) {
  7258. if (isPlainObject(res)) {
  7259. res = Vue.extend(res);
  7260. }
  7261. // cache resolved
  7262. factory.resolved = res;
  7263. // invoke callbacks
  7264. for (var i = 0, l = cbs.length; i < l; i++) {
  7265. cbs[i](res);
  7266. }
  7267. }, function reject(reason) {
  7268. 'development' !== 'production' && warn('Failed to resolve async component: ' + id + '. ' + (reason ? '\nReason: ' + reason : ''));
  7269. });
  7270. }
  7271. } else {
  7272. // normal component
  7273. cb(factory);
  7274. }
  7275. };
  7276. }
  7277. function globalAPI (Vue) {
  7278. /**
  7279. * Expose useful internals
  7280. */
  7281. Vue.util = util;
  7282. Vue.config = config;
  7283. Vue.set = set;
  7284. Vue['delete'] = del;
  7285. Vue.nextTick = nextTick;
  7286. /**
  7287. * The following are exposed for advanced usage / plugins
  7288. */
  7289. Vue.compiler = compiler;
  7290. Vue.FragmentFactory = FragmentFactory;
  7291. Vue.internalDirectives = internalDirectives;
  7292. Vue.parsers = {
  7293. path: path,
  7294. text: text$1,
  7295. template: template,
  7296. directive: directive,
  7297. expression: expression
  7298. };
  7299. /**
  7300. * Each instance constructor, including Vue, has a unique
  7301. * cid. This enables us to create wrapped "child
  7302. * constructors" for prototypal inheritance and cache them.
  7303. */
  7304. Vue.cid = 0;
  7305. var cid = 1;
  7306. /**
  7307. * Class inheritance
  7308. *
  7309. * @param {Object} extendOptions
  7310. */
  7311. Vue.extend = function (extendOptions) {
  7312. extendOptions = extendOptions || {};
  7313. var Super = this;
  7314. var isFirstExtend = Super.cid === 0;
  7315. if (isFirstExtend && extendOptions._Ctor) {
  7316. return extendOptions._Ctor;
  7317. }
  7318. var name = extendOptions.name || Super.options.name;
  7319. var Sub = createClass(name || 'VueComponent');
  7320. Sub.prototype = Object.create(Super.prototype);
  7321. Sub.prototype.constructor = Sub;
  7322. Sub.cid = cid++;
  7323. Sub.options = mergeOptions(Super.options, extendOptions);
  7324. Sub['super'] = Super;
  7325. // allow further extension
  7326. Sub.extend = Super.extend;
  7327. // create asset registers, so extended classes
  7328. // can have their private assets too.
  7329. config._assetTypes.forEach(function (type) {
  7330. Sub[type] = Super[type];
  7331. });
  7332. // enable recursive self-lookup
  7333. if (name) {
  7334. Sub.options.components[name] = Sub;
  7335. }
  7336. // cache constructor
  7337. if (isFirstExtend) {
  7338. extendOptions._Ctor = Sub;
  7339. }
  7340. return Sub;
  7341. };
  7342. /**
  7343. * A function that returns a sub-class constructor with the
  7344. * given name. This gives us much nicer output when
  7345. * logging instances in the console.
  7346. *
  7347. * @param {String} name
  7348. * @return {Function}
  7349. */
  7350. function createClass(name) {
  7351. return new Function('return function ' + classify(name) + ' (options) { this._init(options) }')();
  7352. }
  7353. /**
  7354. * Plugin system
  7355. *
  7356. * @param {Object} plugin
  7357. */
  7358. Vue.use = function (plugin) {
  7359. /* istanbul ignore if */
  7360. if (plugin.installed) {
  7361. return;
  7362. }
  7363. // additional parameters
  7364. var args = toArray(arguments, 1);
  7365. args.unshift(this);
  7366. if (typeof plugin.install === 'function') {
  7367. plugin.install.apply(plugin, args);
  7368. } else {
  7369. plugin.apply(null, args);
  7370. }
  7371. plugin.installed = true;
  7372. return this;
  7373. };
  7374. /**
  7375. * Apply a global mixin by merging it into the default
  7376. * options.
  7377. */
  7378. Vue.mixin = function (mixin) {
  7379. Vue.options = mergeOptions(Vue.options, mixin);
  7380. };
  7381. /**
  7382. * Create asset registration methods with the following
  7383. * signature:
  7384. *
  7385. * @param {String} id
  7386. * @param {*} definition
  7387. */
  7388. config._assetTypes.forEach(function (type) {
  7389. Vue[type] = function (id, definition) {
  7390. if (!definition) {
  7391. return this.options[type + 's'][id];
  7392. } else {
  7393. /* istanbul ignore if */
  7394. if ('development' !== 'production') {
  7395. if (type === 'component' && commonTagRE.test(id)) {
  7396. warn('Do not use built-in HTML elements as component ' + 'id: ' + id);
  7397. }
  7398. }
  7399. if (type === 'component' && isPlainObject(definition)) {
  7400. definition.name = id;
  7401. definition = Vue.extend(definition);
  7402. }
  7403. this.options[type + 's'][id] = definition;
  7404. return definition;
  7405. }
  7406. };
  7407. });
  7408. }
  7409. var filterRE = /[^|]\|[^|]/;
  7410. function dataAPI (Vue) {
  7411. /**
  7412. * Get the value from an expression on this vm.
  7413. *
  7414. * @param {String} exp
  7415. * @param {Boolean} [asStatement]
  7416. * @return {*}
  7417. */
  7418. Vue.prototype.$get = function (exp, asStatement) {
  7419. var res = parseExpression(exp);
  7420. if (res) {
  7421. if (asStatement && !isSimplePath(exp)) {
  7422. var self = this;
  7423. return function statementHandler() {
  7424. res.get.call(self, self);
  7425. };
  7426. } else {
  7427. try {
  7428. return res.get.call(this, this);
  7429. } catch (e) {}
  7430. }
  7431. }
  7432. };
  7433. /**
  7434. * Set the value from an expression on this vm.
  7435. * The expression must be a valid left-hand
  7436. * expression in an assignment.
  7437. *
  7438. * @param {String} exp
  7439. * @param {*} val
  7440. */
  7441. Vue.prototype.$set = function (exp, val) {
  7442. var res = parseExpression(exp, true);
  7443. if (res && res.set) {
  7444. res.set.call(this, this, val);
  7445. }
  7446. };
  7447. /**
  7448. * Delete a property on the VM
  7449. *
  7450. * @param {String} key
  7451. */
  7452. Vue.prototype.$delete = function (key) {
  7453. del(this._data, key);
  7454. };
  7455. /**
  7456. * Watch an expression, trigger callback when its
  7457. * value changes.
  7458. *
  7459. * @param {String|Function} expOrFn
  7460. * @param {Function} cb
  7461. * @param {Object} [options]
  7462. * - {Boolean} deep
  7463. * - {Boolean} immediate
  7464. * @return {Function} - unwatchFn
  7465. */
  7466. Vue.prototype.$watch = function (expOrFn, cb, options) {
  7467. var vm = this;
  7468. var parsed;
  7469. if (typeof expOrFn === 'string') {
  7470. parsed = parseDirective(expOrFn);
  7471. expOrFn = parsed.expression;
  7472. }
  7473. var watcher = new Watcher(vm, expOrFn, cb, {
  7474. deep: options && options.deep,
  7475. filters: parsed && parsed.filters
  7476. });
  7477. if (options && options.immediate) {
  7478. cb.call(vm, watcher.value);
  7479. }
  7480. return function unwatchFn() {
  7481. watcher.teardown();
  7482. };
  7483. };
  7484. /**
  7485. * Evaluate a text directive, including filters.
  7486. *
  7487. * @param {String} text
  7488. * @param {Boolean} [asStatement]
  7489. * @return {String}
  7490. */
  7491. Vue.prototype.$eval = function (text, asStatement) {
  7492. // check for filters.
  7493. if (filterRE.test(text)) {
  7494. var dir = parseDirective(text);
  7495. // the filter regex check might give false positive
  7496. // for pipes inside strings, so it's possible that
  7497. // we don't get any filters here
  7498. var val = this.$get(dir.expression, asStatement);
  7499. return dir.filters ? this._applyFilters(val, null, dir.filters) : val;
  7500. } else {
  7501. // no filter
  7502. return this.$get(text, asStatement);
  7503. }
  7504. };
  7505. /**
  7506. * Interpolate a piece of template text.
  7507. *
  7508. * @param {String} text
  7509. * @return {String}
  7510. */
  7511. Vue.prototype.$interpolate = function (text) {
  7512. var tokens = parseText(text);
  7513. var vm = this;
  7514. if (tokens) {
  7515. if (tokens.length === 1) {
  7516. return vm.$eval(tokens[0].value) + '';
  7517. } else {
  7518. return tokens.map(function (token) {
  7519. return token.tag ? vm.$eval(token.value) : token.value;
  7520. }).join('');
  7521. }
  7522. } else {
  7523. return text;
  7524. }
  7525. };
  7526. /**
  7527. * Log instance data as a plain JS object
  7528. * so that it is easier to inspect in console.
  7529. * This method assumes console is available.
  7530. *
  7531. * @param {String} [path]
  7532. */
  7533. Vue.prototype.$log = function (path) {
  7534. var data = path ? getPath(this._data, path) : this._data;
  7535. if (data) {
  7536. data = clean(data);
  7537. }
  7538. // include computed fields
  7539. if (!path) {
  7540. for (var key in this.$options.computed) {
  7541. data[key] = clean(this[key]);
  7542. }
  7543. }
  7544. console.log(data);
  7545. };
  7546. /**
  7547. * "clean" a getter/setter converted object into a plain
  7548. * object copy.
  7549. *
  7550. * @param {Object} - obj
  7551. * @return {Object}
  7552. */
  7553. function clean(obj) {
  7554. return JSON.parse(JSON.stringify(obj));
  7555. }
  7556. }
  7557. function domAPI (Vue) {
  7558. /**
  7559. * Convenience on-instance nextTick. The callback is
  7560. * auto-bound to the instance, and this avoids component
  7561. * modules having to rely on the global Vue.
  7562. *
  7563. * @param {Function} fn
  7564. */
  7565. Vue.prototype.$nextTick = function (fn) {
  7566. nextTick(fn, this);
  7567. };
  7568. /**
  7569. * Append instance to target
  7570. *
  7571. * @param {Node} target
  7572. * @param {Function} [cb]
  7573. * @param {Boolean} [withTransition] - defaults to true
  7574. */
  7575. Vue.prototype.$appendTo = function (target, cb, withTransition) {
  7576. return insert(this, target, cb, withTransition, append, appendWithTransition);
  7577. };
  7578. /**
  7579. * Prepend instance to target
  7580. *
  7581. * @param {Node} target
  7582. * @param {Function} [cb]
  7583. * @param {Boolean} [withTransition] - defaults to true
  7584. */
  7585. Vue.prototype.$prependTo = function (target, cb, withTransition) {
  7586. target = query(target);
  7587. if (target.hasChildNodes()) {
  7588. this.$before(target.firstChild, cb, withTransition);
  7589. } else {
  7590. this.$appendTo(target, cb, withTransition);
  7591. }
  7592. return this;
  7593. };
  7594. /**
  7595. * Insert instance before target
  7596. *
  7597. * @param {Node} target
  7598. * @param {Function} [cb]
  7599. * @param {Boolean} [withTransition] - defaults to true
  7600. */
  7601. Vue.prototype.$before = function (target, cb, withTransition) {
  7602. return insert(this, target, cb, withTransition, beforeWithCb, beforeWithTransition);
  7603. };
  7604. /**
  7605. * Insert instance after target
  7606. *
  7607. * @param {Node} target
  7608. * @param {Function} [cb]
  7609. * @param {Boolean} [withTransition] - defaults to true
  7610. */
  7611. Vue.prototype.$after = function (target, cb, withTransition) {
  7612. target = query(target);
  7613. if (target.nextSibling) {
  7614. this.$before(target.nextSibling, cb, withTransition);
  7615. } else {
  7616. this.$appendTo(target.parentNode, cb, withTransition);
  7617. }
  7618. return this;
  7619. };
  7620. /**
  7621. * Remove instance from DOM
  7622. *
  7623. * @param {Function} [cb]
  7624. * @param {Boolean} [withTransition] - defaults to true
  7625. */
  7626. Vue.prototype.$remove = function (cb, withTransition) {
  7627. if (!this.$el.parentNode) {
  7628. return cb && cb();
  7629. }
  7630. var inDocument = this._isAttached && inDoc(this.$el);
  7631. // if we are not in document, no need to check
  7632. // for transitions
  7633. if (!inDocument) withTransition = false;
  7634. var self = this;
  7635. var realCb = function realCb() {
  7636. if (inDocument) self._callHook('detached');
  7637. if (cb) cb();
  7638. };
  7639. if (this._isFragment) {
  7640. removeNodeRange(this._fragmentStart, this._fragmentEnd, this, this._fragment, realCb);
  7641. } else {
  7642. var op = withTransition === false ? removeWithCb : removeWithTransition;
  7643. op(this.$el, this, realCb);
  7644. }
  7645. return this;
  7646. };
  7647. /**
  7648. * Shared DOM insertion function.
  7649. *
  7650. * @param {Vue} vm
  7651. * @param {Element} target
  7652. * @param {Function} [cb]
  7653. * @param {Boolean} [withTransition]
  7654. * @param {Function} op1 - op for non-transition insert
  7655. * @param {Function} op2 - op for transition insert
  7656. * @return vm
  7657. */
  7658. function insert(vm, target, cb, withTransition, op1, op2) {
  7659. target = query(target);
  7660. var targetIsDetached = !inDoc(target);
  7661. var op = withTransition === false || targetIsDetached ? op1 : op2;
  7662. var shouldCallHook = !targetIsDetached && !vm._isAttached && !inDoc(vm.$el);
  7663. if (vm._isFragment) {
  7664. mapNodeRange(vm._fragmentStart, vm._fragmentEnd, function (node) {
  7665. op(node, target, vm);
  7666. });
  7667. cb && cb();
  7668. } else {
  7669. op(vm.$el, target, vm, cb);
  7670. }
  7671. if (shouldCallHook) {
  7672. vm._callHook('attached');
  7673. }
  7674. return vm;
  7675. }
  7676. /**
  7677. * Check for selectors
  7678. *
  7679. * @param {String|Element} el
  7680. */
  7681. function query(el) {
  7682. return typeof el === 'string' ? document.querySelector(el) : el;
  7683. }
  7684. /**
  7685. * Append operation that takes a callback.
  7686. *
  7687. * @param {Node} el
  7688. * @param {Node} target
  7689. * @param {Vue} vm - unused
  7690. * @param {Function} [cb]
  7691. */
  7692. function append(el, target, vm, cb) {
  7693. target.appendChild(el);
  7694. if (cb) cb();
  7695. }
  7696. /**
  7697. * InsertBefore operation that takes a callback.
  7698. *
  7699. * @param {Node} el
  7700. * @param {Node} target
  7701. * @param {Vue} vm - unused
  7702. * @param {Function} [cb]
  7703. */
  7704. function beforeWithCb(el, target, vm, cb) {
  7705. before(el, target);
  7706. if (cb) cb();
  7707. }
  7708. /**
  7709. * Remove operation that takes a callback.
  7710. *
  7711. * @param {Node} el
  7712. * @param {Vue} vm - unused
  7713. * @param {Function} [cb]
  7714. */
  7715. function removeWithCb(el, vm, cb) {
  7716. remove(el);
  7717. if (cb) cb();
  7718. }
  7719. }
  7720. function eventsAPI (Vue) {
  7721. /**
  7722. * Listen on the given `event` with `fn`.
  7723. *
  7724. * @param {String} event
  7725. * @param {Function} fn
  7726. */
  7727. Vue.prototype.$on = function (event, fn) {
  7728. (this._events[event] || (this._events[event] = [])).push(fn);
  7729. modifyListenerCount(this, event, 1);
  7730. return this;
  7731. };
  7732. /**
  7733. * Adds an `event` listener that will be invoked a single
  7734. * time then automatically removed.
  7735. *
  7736. * @param {String} event
  7737. * @param {Function} fn
  7738. */
  7739. Vue.prototype.$once = function (event, fn) {
  7740. var self = this;
  7741. function on() {
  7742. self.$off(event, on);
  7743. fn.apply(this, arguments);
  7744. }
  7745. on.fn = fn;
  7746. this.$on(event, on);
  7747. return this;
  7748. };
  7749. /**
  7750. * Remove the given callback for `event` or all
  7751. * registered callbacks.
  7752. *
  7753. * @param {String} event
  7754. * @param {Function} fn
  7755. */
  7756. Vue.prototype.$off = function (event, fn) {
  7757. var cbs;
  7758. // all
  7759. if (!arguments.length) {
  7760. if (this.$parent) {
  7761. for (event in this._events) {
  7762. cbs = this._events[event];
  7763. if (cbs) {
  7764. modifyListenerCount(this, event, -cbs.length);
  7765. }
  7766. }
  7767. }
  7768. this._events = {};
  7769. return this;
  7770. }
  7771. // specific event
  7772. cbs = this._events[event];
  7773. if (!cbs) {
  7774. return this;
  7775. }
  7776. if (arguments.length === 1) {
  7777. modifyListenerCount(this, event, -cbs.length);
  7778. this._events[event] = null;
  7779. return this;
  7780. }
  7781. // specific handler
  7782. var cb;
  7783. var i = cbs.length;
  7784. while (i--) {
  7785. cb = cbs[i];
  7786. if (cb === fn || cb.fn === fn) {
  7787. modifyListenerCount(this, event, -1);
  7788. cbs.splice(i, 1);
  7789. break;
  7790. }
  7791. }
  7792. return this;
  7793. };
  7794. /**
  7795. * Trigger an event on self.
  7796. *
  7797. * @param {String} event
  7798. * @return {Boolean} shouldPropagate
  7799. */
  7800. Vue.prototype.$emit = function (event) {
  7801. var cbs = this._events[event];
  7802. var shouldPropagate = !cbs;
  7803. if (cbs) {
  7804. cbs = cbs.length > 1 ? toArray(cbs) : cbs;
  7805. var args = toArray(arguments, 1);
  7806. for (var i = 0, l = cbs.length; i < l; i++) {
  7807. var res = cbs[i].apply(this, args);
  7808. if (res === true) {
  7809. shouldPropagate = true;
  7810. }
  7811. }
  7812. }
  7813. return shouldPropagate;
  7814. };
  7815. /**
  7816. * Recursively broadcast an event to all children instances.
  7817. *
  7818. * @param {String} event
  7819. * @param {...*} additional arguments
  7820. */
  7821. Vue.prototype.$broadcast = function (event) {
  7822. // if no child has registered for this event,
  7823. // then there's no need to broadcast.
  7824. if (!this._eventsCount[event]) return;
  7825. var children = this.$children;
  7826. for (var i = 0, l = children.length; i < l; i++) {
  7827. var child = children[i];
  7828. var shouldPropagate = child.$emit.apply(child, arguments);
  7829. if (shouldPropagate) {
  7830. child.$broadcast.apply(child, arguments);
  7831. }
  7832. }
  7833. return this;
  7834. };
  7835. /**
  7836. * Recursively propagate an event up the parent chain.
  7837. *
  7838. * @param {String} event
  7839. * @param {...*} additional arguments
  7840. */
  7841. Vue.prototype.$dispatch = function () {
  7842. this.$emit.apply(this, arguments);
  7843. var parent = this.$parent;
  7844. while (parent) {
  7845. var shouldPropagate = parent.$emit.apply(parent, arguments);
  7846. parent = shouldPropagate ? parent.$parent : null;
  7847. }
  7848. return this;
  7849. };
  7850. /**
  7851. * Modify the listener counts on all parents.
  7852. * This bookkeeping allows $broadcast to return early when
  7853. * no child has listened to a certain event.
  7854. *
  7855. * @param {Vue} vm
  7856. * @param {String} event
  7857. * @param {Number} count
  7858. */
  7859. var hookRE = /^hook:/;
  7860. function modifyListenerCount(vm, event, count) {
  7861. var parent = vm.$parent;
  7862. // hooks do not get broadcasted so no need
  7863. // to do bookkeeping for them
  7864. if (!parent || !count || hookRE.test(event)) return;
  7865. while (parent) {
  7866. parent._eventsCount[event] = (parent._eventsCount[event] || 0) + count;
  7867. parent = parent.$parent;
  7868. }
  7869. }
  7870. }
  7871. function lifecycleAPI (Vue) {
  7872. /**
  7873. * Set instance target element and kick off the compilation
  7874. * process. The passed in `el` can be a selector string, an
  7875. * existing Element, or a DocumentFragment (for block
  7876. * instances).
  7877. *
  7878. * @param {Element|DocumentFragment|string} el
  7879. * @public
  7880. */
  7881. Vue.prototype.$mount = function (el) {
  7882. if (this._isCompiled) {
  7883. 'development' !== 'production' && warn('$mount() should be called only once.');
  7884. return;
  7885. }
  7886. el = query(el);
  7887. if (!el) {
  7888. el = document.createElement('div');
  7889. }
  7890. this._compile(el);
  7891. this._initDOMHooks();
  7892. if (inDoc(this.$el)) {
  7893. this._callHook('attached');
  7894. ready.call(this);
  7895. } else {
  7896. this.$once('hook:attached', ready);
  7897. }
  7898. return this;
  7899. };
  7900. /**
  7901. * Mark an instance as ready.
  7902. */
  7903. function ready() {
  7904. this._isAttached = true;
  7905. this._isReady = true;
  7906. this._callHook('ready');
  7907. }
  7908. /**
  7909. * Teardown the instance, simply delegate to the internal
  7910. * _destroy.
  7911. */
  7912. Vue.prototype.$destroy = function (remove, deferCleanup) {
  7913. this._destroy(remove, deferCleanup);
  7914. };
  7915. /**
  7916. * Partially compile a piece of DOM and return a
  7917. * decompile function.
  7918. *
  7919. * @param {Element|DocumentFragment} el
  7920. * @param {Vue} [host]
  7921. * @return {Function}
  7922. */
  7923. Vue.prototype.$compile = function (el, host, scope, frag) {
  7924. return compile(el, this.$options, true)(this, el, host, scope, frag);
  7925. };
  7926. }
  7927. /**
  7928. * The exposed Vue constructor.
  7929. *
  7930. * API conventions:
  7931. * - public API methods/properties are prefixed with `$`
  7932. * - internal methods/properties are prefixed with `_`
  7933. * - non-prefixed properties are assumed to be proxied user
  7934. * data.
  7935. *
  7936. * @constructor
  7937. * @param {Object} [options]
  7938. * @public
  7939. */
  7940. function Vue(options) {
  7941. this._init(options);
  7942. }
  7943. // install internals
  7944. initMixin(Vue);
  7945. stateMixin(Vue);
  7946. eventsMixin(Vue);
  7947. lifecycleMixin(Vue);
  7948. miscMixin(Vue);
  7949. // install APIs
  7950. globalAPI(Vue);
  7951. dataAPI(Vue);
  7952. domAPI(Vue);
  7953. eventsAPI(Vue);
  7954. lifecycleAPI(Vue);
  7955. var convertArray = vFor._postProcess;
  7956. /**
  7957. * Limit filter for arrays
  7958. *
  7959. * @param {Number} n
  7960. * @param {Number} offset (Decimal expected)
  7961. */
  7962. function limitBy(arr, n, offset) {
  7963. offset = offset ? parseInt(offset, 10) : 0;
  7964. return typeof n === 'number' ? arr.slice(offset, offset + n) : arr;
  7965. }
  7966. /**
  7967. * Filter filter for arrays
  7968. *
  7969. * @param {String} search
  7970. * @param {String} [delimiter]
  7971. * @param {String} ...dataKeys
  7972. */
  7973. function filterBy(arr, search, delimiter) {
  7974. arr = convertArray(arr);
  7975. if (search == null) {
  7976. return arr;
  7977. }
  7978. if (typeof search === 'function') {
  7979. return arr.filter(search);
  7980. }
  7981. // cast to lowercase string
  7982. search = ('' + search).toLowerCase();
  7983. // allow optional `in` delimiter
  7984. // because why not
  7985. var n = delimiter === 'in' ? 3 : 2;
  7986. // extract and flatten keys
  7987. var keys = toArray(arguments, n).reduce(function (prev, cur) {
  7988. return prev.concat(cur);
  7989. }, []);
  7990. var res = [];
  7991. var item, key, val, j;
  7992. for (var i = 0, l = arr.length; i < l; i++) {
  7993. item = arr[i];
  7994. val = item && item.$value || item;
  7995. j = keys.length;
  7996. if (j) {
  7997. while (j--) {
  7998. key = keys[j];
  7999. if (key === '$key' && contains(item.$key, search) || contains(getPath(val, key), search)) {
  8000. res.push(item);
  8001. break;
  8002. }
  8003. }
  8004. } else if (contains(item, search)) {
  8005. res.push(item);
  8006. }
  8007. }
  8008. return res;
  8009. }
  8010. /**
  8011. * Filter filter for arrays
  8012. *
  8013. * @param {String} sortKey
  8014. * @param {String} reverse
  8015. */
  8016. function orderBy(arr, sortKey, reverse) {
  8017. arr = convertArray(arr);
  8018. if (!sortKey) {
  8019. return arr;
  8020. }
  8021. var order = reverse && reverse < 0 ? -1 : 1;
  8022. // sort on a copy to avoid mutating original array
  8023. return arr.slice().sort(function (a, b) {
  8024. if (sortKey !== '$key') {
  8025. if (isObject(a) && '$value' in a) a = a.$value;
  8026. if (isObject(b) && '$value' in b) b = b.$value;
  8027. }
  8028. a = isObject(a) ? getPath(a, sortKey) : a;
  8029. b = isObject(b) ? getPath(b, sortKey) : b;
  8030. return a === b ? 0 : a > b ? order : -order;
  8031. });
  8032. }
  8033. /**
  8034. * String contain helper
  8035. *
  8036. * @param {*} val
  8037. * @param {String} search
  8038. */
  8039. function contains(val, search) {
  8040. var i;
  8041. if (isPlainObject(val)) {
  8042. var keys = Object.keys(val);
  8043. i = keys.length;
  8044. while (i--) {
  8045. if (contains(val[keys[i]], search)) {
  8046. return true;
  8047. }
  8048. }
  8049. } else if (isArray(val)) {
  8050. i = val.length;
  8051. while (i--) {
  8052. if (contains(val[i], search)) {
  8053. return true;
  8054. }
  8055. }
  8056. } else if (val != null) {
  8057. return val.toString().toLowerCase().indexOf(search) > -1;
  8058. }
  8059. }
  8060. var digitsRE = /(\d{3})(?=\d)/g;
  8061. // asset collections must be a plain object.
  8062. var filters = {
  8063. orderBy: orderBy,
  8064. filterBy: filterBy,
  8065. limitBy: limitBy,
  8066. /**
  8067. * Stringify value.
  8068. *
  8069. * @param {Number} indent
  8070. */
  8071. json: {
  8072. read: function read(value, indent) {
  8073. return typeof value === 'string' ? value : JSON.stringify(value, null, Number(indent) || 2);
  8074. },
  8075. write: function write(value) {
  8076. try {
  8077. return JSON.parse(value);
  8078. } catch (e) {
  8079. return value;
  8080. }
  8081. }
  8082. },
  8083. /**
  8084. * 'abc' => 'Abc'
  8085. */
  8086. capitalize: function capitalize(value) {
  8087. if (!value && value !== 0) return '';
  8088. value = value.toString();
  8089. return value.charAt(0).toUpperCase() + value.slice(1);
  8090. },
  8091. /**
  8092. * 'abc' => 'ABC'
  8093. */
  8094. uppercase: function uppercase(value) {
  8095. return value || value === 0 ? value.toString().toUpperCase() : '';
  8096. },
  8097. /**
  8098. * 'AbC' => 'abc'
  8099. */
  8100. lowercase: function lowercase(value) {
  8101. return value || value === 0 ? value.toString().toLowerCase() : '';
  8102. },
  8103. /**
  8104. * 12345 => $12,345.00
  8105. *
  8106. * @param {String} sign
  8107. */
  8108. currency: function currency(value, _currency) {
  8109. value = parseFloat(value);
  8110. if (!isFinite(value) || !value && value !== 0) return '';
  8111. _currency = _currency != null ? _currency : '$';
  8112. var stringified = Math.abs(value).toFixed(2);
  8113. var _int = stringified.slice(0, -3);
  8114. var i = _int.length % 3;
  8115. var head = i > 0 ? _int.slice(0, i) + (_int.length > 3 ? ',' : '') : '';
  8116. var _float = stringified.slice(-3);
  8117. var sign = value < 0 ? '-' : '';
  8118. return _currency + sign + head + _int.slice(i).replace(digitsRE, '$1,') + _float;
  8119. },
  8120. /**
  8121. * 'item' => 'items'
  8122. *
  8123. * @params
  8124. * an array of strings corresponding to
  8125. * the single, double, triple ... forms of the word to
  8126. * be pluralized. When the number to be pluralized
  8127. * exceeds the length of the args, it will use the last
  8128. * entry in the array.
  8129. *
  8130. * e.g. ['single', 'double', 'triple', 'multiple']
  8131. */
  8132. pluralize: function pluralize(value) {
  8133. var args = toArray(arguments, 1);
  8134. return args.length > 1 ? args[value % 10 - 1] || args[args.length - 1] : args[0] + (value === 1 ? '' : 's');
  8135. },
  8136. /**
  8137. * Debounce a handler function.
  8138. *
  8139. * @param {Function} handler
  8140. * @param {Number} delay = 300
  8141. * @return {Function}
  8142. */
  8143. debounce: function debounce(handler, delay) {
  8144. if (!handler) return;
  8145. if (!delay) {
  8146. delay = 300;
  8147. }
  8148. return _debounce(handler, delay);
  8149. }
  8150. };
  8151. var partial = {
  8152. priority: 1750,
  8153. params: ['name'],
  8154. // watch changes to name for dynamic partials
  8155. paramWatchers: {
  8156. name: function name(value) {
  8157. vIf.remove.call(this);
  8158. if (value) {
  8159. this.insert(value);
  8160. }
  8161. }
  8162. },
  8163. bind: function bind() {
  8164. this.anchor = createAnchor('v-partial');
  8165. replace(this.el, this.anchor);
  8166. this.insert(this.params.name);
  8167. },
  8168. insert: function insert(id) {
  8169. var partial = resolveAsset(this.vm.$options, 'partials', id);
  8170. if ('development' !== 'production') {
  8171. assertAsset(partial, 'partial', id);
  8172. }
  8173. if (partial) {
  8174. this.factory = new FragmentFactory(this.vm, partial);
  8175. vIf.insert.call(this);
  8176. }
  8177. },
  8178. unbind: function unbind() {
  8179. if (this.frag) {
  8180. this.frag.destroy();
  8181. }
  8182. }
  8183. };
  8184. // This is the elementDirective that handles <content>
  8185. // transclusions. It relies on the raw content of an
  8186. // instance being stored as `$options._content` during
  8187. // the transclude phase.
  8188. var slot = {
  8189. priority: 1750,
  8190. params: ['name'],
  8191. bind: function bind() {
  8192. var host = this.vm;
  8193. var raw = host.$options._content;
  8194. var content;
  8195. if (!raw) {
  8196. this.fallback();
  8197. return;
  8198. }
  8199. var context = host._context;
  8200. var slotName = this.params.name;
  8201. if (!slotName) {
  8202. // Default content
  8203. var self = this;
  8204. var compileDefaultContent = function compileDefaultContent() {
  8205. self.compile(extractFragment(raw.childNodes, raw, true), context, host);
  8206. };
  8207. if (!host._isCompiled) {
  8208. // defer until the end of instance compilation,
  8209. // because the default outlet must wait until all
  8210. // other possible outlets with selectors have picked
  8211. // out their contents.
  8212. host.$once('hook:compiled', compileDefaultContent);
  8213. } else {
  8214. compileDefaultContent();
  8215. }
  8216. } else {
  8217. var selector = '[slot="' + slotName + '"]';
  8218. var nodes = raw.querySelectorAll(selector);
  8219. if (nodes.length) {
  8220. content = extractFragment(nodes, raw);
  8221. if (content.hasChildNodes()) {
  8222. this.compile(content, context, host);
  8223. } else {
  8224. this.fallback();
  8225. }
  8226. } else {
  8227. this.fallback();
  8228. }
  8229. }
  8230. },
  8231. fallback: function fallback() {
  8232. this.compile(extractContent(this.el, true), this.vm);
  8233. },
  8234. compile: function compile(content, context, host) {
  8235. if (content && context) {
  8236. var scope = host ? host._scope : this._scope;
  8237. this.unlink = context.$compile(content, host, scope, this._frag);
  8238. }
  8239. if (content) {
  8240. replace(this.el, content);
  8241. } else {
  8242. remove(this.el);
  8243. }
  8244. },
  8245. unbind: function unbind() {
  8246. if (this.unlink) {
  8247. this.unlink();
  8248. }
  8249. }
  8250. };
  8251. /**
  8252. * Extract qualified content nodes from a node list.
  8253. *
  8254. * @param {NodeList} nodes
  8255. * @param {Element} parent
  8256. * @param {Boolean} main
  8257. * @return {DocumentFragment}
  8258. */
  8259. function extractFragment(nodes, parent, main) {
  8260. var frag = document.createDocumentFragment();
  8261. for (var i = 0, l = nodes.length; i < l; i++) {
  8262. var node = nodes[i];
  8263. // if this is the main outlet, we want to skip all
  8264. // previously selected nodes;
  8265. // otherwise, we want to mark the node as selected.
  8266. // clone the node so the original raw content remains
  8267. // intact. this ensures proper re-compilation in cases
  8268. // where the outlet is inside a conditional block
  8269. if (main && !node.__v_selected) {
  8270. append(node);
  8271. } else if (!main && node.parentNode === parent) {
  8272. node.__v_selected = true;
  8273. append(node);
  8274. }
  8275. }
  8276. return frag;
  8277. function append(node) {
  8278. if (isTemplate(node) && !node.hasAttribute('v-if') && !node.hasAttribute('v-for')) {
  8279. node = parseTemplate(node);
  8280. }
  8281. node = cloneNode(node);
  8282. frag.appendChild(node);
  8283. }
  8284. }
  8285. var elementDirectives = {
  8286. slot: slot,
  8287. partial: partial
  8288. };
  8289. Vue.version = '1.0.10';
  8290. /**
  8291. * Vue and every constructor that extends Vue has an
  8292. * associated options object, which can be accessed during
  8293. * compilation steps as `this.constructor.options`.
  8294. *
  8295. * These can be seen as the default options of every
  8296. * Vue instance.
  8297. */
  8298. Vue.options = {
  8299. directives: publicDirectives,
  8300. elementDirectives: elementDirectives,
  8301. filters: filters,
  8302. transitions: {},
  8303. components: {},
  8304. partials: {},
  8305. replace: true
  8306. };
  8307. // devtools global hook
  8308. /* istanbul ignore if */
  8309. if ('development' !== 'production') {
  8310. if (inBrowser && window.__VUE_DEVTOOLS_GLOBAL_HOOK__) {
  8311. window.__VUE_DEVTOOLS_GLOBAL_HOOK__.emit('init', Vue);
  8312. }
  8313. }
  8314. return Vue;
  8315. }));