vue.js 142 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275
  1. /*!
  2. * Vue.js v2.0.0-pre-alpha
  3. * (c) 2014-2016 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. var config = {
  12. /**
  13. * Preserve whitespaces between elements.
  14. */
  15. preserveWhitespace: true,
  16. /**
  17. * Whether to suppress warnings.
  18. *
  19. * @type {Boolean}
  20. */
  21. silent: false,
  22. /**
  23. * Check if a tag is reserved so that it cannot be registered as a
  24. * component. This is platform-dependent and may be overwritten.
  25. */
  26. isReservedTag: function isReservedTag() {
  27. return false;
  28. },
  29. /**
  30. * Check if a tag is an unknown element.
  31. * Platform-dependent.
  32. */
  33. isUnknownElement: function isUnknownElement() {
  34. return false;
  35. },
  36. /**
  37. * List of asset types that a component can own.
  38. *
  39. * @type {Array}
  40. */
  41. _assetTypes: ['component', 'directive', 'transition'],
  42. /**
  43. * List of lifecycle hooks.
  44. *
  45. * @type {Array}
  46. */
  47. _lifecycleHooks: ['init', 'created', 'beforeMount', 'mounted', 'ready', 'beforeUpdate', 'updated', 'beforeDestroy', 'destroyed'],
  48. /**
  49. * Max circular updates allowed in a batcher flush cycle.
  50. */
  51. _maxUpdateCount: 100
  52. };
  53. /**
  54. * Convert a value to a string that is actually rendered.
  55. *
  56. * @param {*} val
  57. * @return {String}
  58. */
  59. function renderString(val) {
  60. return val == null ? '' : typeof val === 'object' ? JSON.stringify(val, null, 2) : String(val);
  61. }
  62. /**
  63. * Make a map and return a function for checking if a key
  64. * is in that map.
  65. *
  66. * @param {String} str
  67. * @param {Boolean} expectsLowerCase
  68. * @return {Function}
  69. */
  70. function makeMap(str, expectsLowerCase) {
  71. var map = Object.create(null);
  72. var list = str.split(',');
  73. for (var i = 0; i < list.length; i++) {
  74. map[list[i]] = true;
  75. }
  76. return expectsLowerCase ? function (val) {
  77. return map[val.toLowerCase()];
  78. } : function (val) {
  79. return map[val];
  80. };
  81. }
  82. /**
  83. * Check if a tag is a built-in tag.
  84. */
  85. var isBuiltInTag = makeMap('slot,component,render,transition', true);
  86. /**
  87. * Remove an item from an array
  88. *
  89. * @param {Array} arr
  90. * @param {*} item
  91. */
  92. function remove(arr, item) {
  93. if (arr.length) {
  94. var index = arr.indexOf(item);
  95. if (index > -1) {
  96. return arr.splice(index, 1);
  97. }
  98. }
  99. }
  100. /**
  101. * Check whether the object has the property.
  102. *
  103. * @param {Object} obj
  104. * @param {String} key
  105. * @return {Boolean}
  106. */
  107. var hasOwnProperty = Object.prototype.hasOwnProperty;
  108. function hasOwn(obj, key) {
  109. return hasOwnProperty.call(obj, key);
  110. }
  111. /**
  112. * Check if value is primitive
  113. *
  114. * @param {*} value
  115. * @return {Boolean}
  116. */
  117. function isPrimitive(value) {
  118. return typeof value === 'string' || typeof value === 'number';
  119. }
  120. /**
  121. * Create a cached version of a pure function.
  122. *
  123. * @param {Function} fn
  124. * @return {Function}
  125. */
  126. function cached(fn) {
  127. var cache = Object.create(null);
  128. return function cachedFn(str) {
  129. var hit = cache[str];
  130. return hit || (cache[str] = fn(str));
  131. };
  132. }
  133. /**
  134. * Camelize a hyphen-delmited string.
  135. *
  136. * @param {String} str
  137. * @return {String}
  138. */
  139. var camelizeRE = /-(\w)/g;
  140. var camelize = cached(function (str) {
  141. return str.replace(camelizeRE, toUpper);
  142. });
  143. function toUpper(_, c) {
  144. return c ? c.toUpperCase() : '';
  145. }
  146. /**
  147. * Hyphenate a camelCase string.
  148. *
  149. * @param {String} str
  150. * @return {String}
  151. */
  152. var hyphenateRE = /([a-z\d])([A-Z])/g;
  153. var hyphenate = cached(function (str) {
  154. return str.replace(hyphenateRE, '$1-$2').toLowerCase();
  155. });
  156. /**
  157. * Simple bind, faster than native
  158. *
  159. * @param {Function} fn
  160. * @param {Object} ctx
  161. * @return {Function}
  162. */
  163. function bind(fn, ctx) {
  164. return function (a) {
  165. var l = arguments.length;
  166. return l ? l > 1 ? fn.apply(ctx, arguments) : fn.call(ctx, a) : fn.call(ctx);
  167. };
  168. }
  169. /**
  170. * Convert an Array-like object to a real Array.
  171. *
  172. * @param {Array-like} list
  173. * @param {Number} [start] - start index
  174. * @return {Array}
  175. */
  176. function toArray(list, start) {
  177. start = start || 0;
  178. var i = list.length - start;
  179. var ret = new Array(i);
  180. while (i--) {
  181. ret[i] = list[i + start];
  182. }
  183. return ret;
  184. }
  185. /**
  186. * Mix properties into target object.
  187. *
  188. * @param {Object} to
  189. * @param {Object} from
  190. */
  191. function extend(to, from) {
  192. for (var key in from) {
  193. to[key] = from[key];
  194. }
  195. return to;
  196. }
  197. /**
  198. * Quick object check - this is primarily used to tell
  199. * Objects from primitive values when we know the value
  200. * is a JSON-compliant type.
  201. *
  202. * @param {*} obj
  203. * @return {Boolean}
  204. */
  205. function isObject(obj) {
  206. return obj !== null && typeof obj === 'object';
  207. }
  208. /**
  209. * Strict object type check. Only returns true
  210. * for plain JavaScript objects.
  211. *
  212. * @param {*} obj
  213. * @return {Boolean}
  214. */
  215. var toString = Object.prototype.toString;
  216. var OBJECT_STRING = '[object Object]';
  217. function isPlainObject(obj) {
  218. return toString.call(obj) === OBJECT_STRING;
  219. }
  220. /**
  221. * Array type check.
  222. *
  223. * @param {*} obj
  224. * @return {Boolean}
  225. */
  226. var isArray = Array.isArray;
  227. /**
  228. * Check if a string starts with $ or _
  229. *
  230. * @param {String} str
  231. * @return {Boolean}
  232. */
  233. function isReserved(str) {
  234. var c = (str + '').charCodeAt(0);
  235. return c === 0x24 || c === 0x5F;
  236. }
  237. /**
  238. * Define a property.
  239. *
  240. * @param {Object} obj
  241. * @param {String} key
  242. * @param {*} val
  243. * @param {Boolean} [enumerable]
  244. */
  245. function def(obj, key, val, enumerable) {
  246. Object.defineProperty(obj, key, {
  247. value: val,
  248. enumerable: !!enumerable,
  249. writable: true,
  250. configurable: true
  251. });
  252. }
  253. /**
  254. * Parse simple path.
  255. */
  256. var bailRE = /[^\w\.]/;
  257. function parsePath(path) {
  258. if (bailRE.test(path)) {
  259. return;
  260. } else {
  261. path = path.split('.');
  262. return function (obj) {
  263. for (var i = 0; i < path.length; i++) {
  264. if (!obj) return;
  265. obj = obj[path[i]];
  266. }
  267. return obj;
  268. };
  269. }
  270. }
  271. /* global MutationObserver */
  272. // can we use __proto__?
  273. var hasProto = '__proto__' in {};
  274. // Browser environment sniffing
  275. var inBrowser = typeof window !== 'undefined' && Object.prototype.toString.call(window) !== '[object Object]';
  276. // detect devtools
  277. var devtools = inBrowser && window.__VUE_DEVTOOLS_GLOBAL_HOOK__;
  278. // UA sniffing for working around browser-specific quirks
  279. var UA = inBrowser && window.navigator.userAgent.toLowerCase();
  280. var isIos = UA && /(iphone|ipad|ipod|ios)/i.test(UA);
  281. var isWechat = UA && UA.indexOf('micromessenger') > 0;
  282. /**
  283. * Defer a task to execute it asynchronously. Ideally this
  284. * should be executed as a microtask, so we leverage
  285. * MutationObserver if it's available, and fallback to
  286. * setTimeout(0).
  287. *
  288. * @param {Function} cb
  289. * @param {Object} ctx
  290. */
  291. var nextTick = function () {
  292. var callbacks = [];
  293. var pending = false;
  294. var timerFunc;
  295. function nextTickHandler() {
  296. pending = false;
  297. var copies = callbacks.slice(0);
  298. callbacks = [];
  299. for (var i = 0; i < copies.length; i++) {
  300. copies[i]();
  301. }
  302. }
  303. /* istanbul ignore if */
  304. if (typeof MutationObserver !== 'undefined' && !(isWechat && isIos)) {
  305. var counter = 1;
  306. var observer = new MutationObserver(nextTickHandler);
  307. var textNode = document.createTextNode(counter);
  308. observer.observe(textNode, {
  309. characterData: true
  310. });
  311. timerFunc = function timerFunc() {
  312. counter = (counter + 1) % 2;
  313. textNode.data = counter;
  314. };
  315. } else {
  316. // webpack attempts to inject a shim for setImmediate
  317. // if it is used as a global, so we have to work around that to
  318. // avoid bundling unnecessary code.
  319. var context = inBrowser ? window : typeof global !== 'undefined' ? global : {};
  320. timerFunc = context.setImmediate || setTimeout;
  321. }
  322. return function (cb, ctx) {
  323. var func = ctx ? function () {
  324. cb.call(ctx);
  325. } : cb;
  326. callbacks.push(func);
  327. if (pending) return;
  328. pending = true;
  329. timerFunc(nextTickHandler, 0);
  330. };
  331. }();
  332. var _Set = void 0;
  333. /* istanbul ignore if */
  334. if (typeof Set !== 'undefined' && Set.toString().match(/native code/)) {
  335. // use native Set when available.
  336. _Set = Set;
  337. } else {
  338. // a non-standard Set polyfill that only works with primitive keys.
  339. _Set = function _Set() {
  340. this.set = Object.create(null);
  341. };
  342. _Set.prototype.has = function (key) {
  343. return this.set[key] !== undefined;
  344. };
  345. _Set.prototype.add = function (key) {
  346. this.set[key] = 1;
  347. };
  348. _Set.prototype.clear = function () {
  349. this.set = Object.create(null);
  350. };
  351. }
  352. var hasProxy = void 0;
  353. var proxyHandlers = void 0;
  354. var initProxy = void 0;
  355. if ("development" !== 'production') {
  356. (function () {
  357. var allowedGlobals = makeMap('Infinity,undefined,NaN,isFinite,isNaN,' + 'parseFloat,parseInt,decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,' + 'Math,Number,Date,Array,Object,Boolean,String,RegExp,Map,Set,JSON,Intl');
  358. hasProxy = typeof Proxy !== 'undefined' && Proxy.toString().match(/native code/);
  359. proxyHandlers = {
  360. has: function has(target, key) {
  361. var has = key in target;
  362. var isAllowedGlobal = allowedGlobals(key);
  363. if (!has && !isAllowedGlobal) {
  364. warn('Trying to access non-existent property "' + key + '" while rendering.', target);
  365. }
  366. return !isAllowedGlobal;
  367. }
  368. };
  369. initProxy = function initProxy(vm) {
  370. if (hasProxy) {
  371. vm._renderProxy = new Proxy(vm, proxyHandlers);
  372. } else {
  373. vm._renderProxy = vm;
  374. }
  375. };
  376. })();
  377. }
  378. var uid$2 = 0;
  379. /**
  380. * A dep is an observable that can have multiple
  381. * directives subscribing to it.
  382. *
  383. * @constructor
  384. */
  385. function Dep() {
  386. this.id = uid$2++;
  387. this.subs = [];
  388. }
  389. // the current target watcher being evaluated.
  390. // this is globally unique because there could be only one
  391. // watcher being evaluated at any time.
  392. Dep.target = null;
  393. /**
  394. * Add a directive subscriber.
  395. *
  396. * @param {Directive} sub
  397. */
  398. Dep.prototype.addSub = function (sub) {
  399. this.subs.push(sub);
  400. };
  401. /**
  402. * Remove a directive subscriber.
  403. *
  404. * @param {Directive} sub
  405. */
  406. Dep.prototype.removeSub = function (sub) {
  407. remove(this.subs, sub);
  408. };
  409. /**
  410. * Add self as a dependency to the target watcher.
  411. */
  412. Dep.prototype.depend = function () {
  413. Dep.target.addDep(this);
  414. };
  415. /**
  416. * Notify all subscribers of a new value.
  417. */
  418. Dep.prototype.notify = function () {
  419. // stablize the subscriber list first
  420. var subs = this.subs.slice();
  421. for (var i = 0, l = subs.length; i < l; i++) {
  422. subs[i].update();
  423. }
  424. };
  425. // we have two separate queues: one for directive updates
  426. // and one for user watcher registered via $watch().
  427. // we want to guarantee directive updates to be called
  428. // before user watchers so that when user watchers are
  429. // triggered, the DOM would have already been in updated
  430. // state.
  431. var queueIndex;
  432. var queue = [];
  433. var userQueue = [];
  434. var has = {};
  435. var circular = {};
  436. var waiting = false;
  437. var internalQueueDepleted = false;
  438. /**
  439. * Reset the batcher's state.
  440. */
  441. function resetBatcherState() {
  442. queue = [];
  443. userQueue = [];
  444. has = {};
  445. circular = {};
  446. waiting = internalQueueDepleted = false;
  447. }
  448. /**
  449. * Flush both queues and run the watchers.
  450. */
  451. function flushBatcherQueue() {
  452. queue.sort(queueSorter);
  453. runBatcherQueue(queue);
  454. internalQueueDepleted = true;
  455. runBatcherQueue(userQueue);
  456. resetBatcherState();
  457. }
  458. /**
  459. * Sort queue before flush.
  460. * This ensures components are updated from parent to child
  461. * so there will be no duplicate updates, e.g. a child was
  462. * pushed into the queue first and then its parent's props
  463. * changed.
  464. */
  465. function queueSorter(a, b) {
  466. return a.id - b.id;
  467. }
  468. /**
  469. * Run the watchers in a single queue.
  470. *
  471. * @param {Array} queue
  472. */
  473. function runBatcherQueue(queue) {
  474. // do not cache length because more watchers might be pushed
  475. // as we run existing watchers
  476. for (queueIndex = 0; queueIndex < queue.length; queueIndex++) {
  477. var watcher = queue[queueIndex];
  478. var id = watcher.id;
  479. has[id] = null;
  480. watcher.run();
  481. // in dev build, check and stop circular updates.
  482. if ("development" !== 'production' && has[id] != null) {
  483. circular[id] = (circular[id] || 0) + 1;
  484. if (circular[id] > config._maxUpdateCount) {
  485. warn('You may have an infinite update loop for watcher ' + 'with expression "' + watcher.expression + '"', watcher.vm);
  486. break;
  487. }
  488. }
  489. }
  490. }
  491. /**
  492. * Push a watcher into the watcher queue.
  493. * Jobs with duplicate IDs will be skipped unless it's
  494. * pushed when the queue is being flushed.
  495. *
  496. * @param {Watcher} watcher
  497. * properties:
  498. * - {Number} id
  499. * - {Function} run
  500. */
  501. function pushWatcher(watcher) {
  502. var id = watcher.id;
  503. if (has[id] == null) {
  504. if (internalQueueDepleted && !watcher.user) {
  505. // an internal watcher triggered by a user watcher...
  506. // let's run it immediately after current user watcher is done.
  507. userQueue.splice(queueIndex + 1, 0, watcher);
  508. } else {
  509. // push watcher into appropriate queue
  510. var q = watcher.user ? userQueue : queue;
  511. has[id] = q.length;
  512. q.push(watcher);
  513. // queue the flush
  514. if (!waiting) {
  515. waiting = true;
  516. nextTick(flushBatcherQueue);
  517. }
  518. }
  519. }
  520. }
  521. var uid$1 = 0;
  522. var prevTarget = void 0;
  523. /**
  524. * A watcher parses an expression, collects dependencies,
  525. * and fires callback when the expression value changes.
  526. * This is used for both the $watch() api and directives.
  527. *
  528. * @param {Vue} vm
  529. * @param {String|Function} expOrFn
  530. * @param {Function} cb
  531. * @param {Object} options
  532. * - {Array} filters
  533. * - {Boolean} twoWay
  534. * - {Boolean} deep
  535. * - {Boolean} user
  536. * - {Boolean} sync
  537. * - {Boolean} lazy
  538. * - {Function} [preProcess]
  539. * - {Function} [postProcess]
  540. * @constructor
  541. */
  542. function Watcher(vm, expOrFn, cb, options) {
  543. // mix in options
  544. if (options) {
  545. extend(this, options);
  546. }
  547. var isFn = typeof expOrFn === 'function';
  548. this.vm = vm;
  549. vm._watchers.push(this);
  550. this.expression = expOrFn;
  551. this.cb = cb;
  552. this.id = ++uid$1; // uid for batching
  553. this.active = true;
  554. this.dirty = this.lazy; // for lazy watchers
  555. this.deps = [];
  556. this.newDeps = [];
  557. this.depIds = new _Set();
  558. this.newDepIds = new _Set();
  559. // parse expression for getter
  560. if (isFn) {
  561. this.getter = expOrFn;
  562. } else {
  563. this.getter = parsePath(expOrFn);
  564. if (!this.getter) {
  565. this.getter = function () {};
  566. "development" !== 'production' && warn('Failed watching path: ' + expOrFn + 'Watcher only accepts simple dot-delimited paths. ' + 'For full control, use a function instead.', vm);
  567. }
  568. }
  569. this.value = this.lazy ? undefined : this.get();
  570. // state for avoiding false triggers for deep and Array
  571. // watchers during vm._digest()
  572. this.queued = this.shallow = false;
  573. }
  574. /**
  575. * Evaluate the getter, and re-collect dependencies.
  576. */
  577. Watcher.prototype.get = function () {
  578. this.beforeGet();
  579. var value = this.getter.call(this.vm, this.vm);
  580. // "touch" every property so they are all tracked as
  581. // dependencies for deep watching
  582. if (this.deep) {
  583. traverse(value);
  584. }
  585. this.afterGet();
  586. return value;
  587. };
  588. /**
  589. * Prepare for dependency collection.
  590. */
  591. Watcher.prototype.beforeGet = function () {
  592. prevTarget = Dep.target;
  593. Dep.target = this;
  594. };
  595. /**
  596. * Add a dependency to this directive.
  597. *
  598. * @param {Dep} dep
  599. */
  600. Watcher.prototype.addDep = function (dep) {
  601. var id = dep.id;
  602. if (!this.newDepIds.has(id)) {
  603. this.newDepIds.add(id);
  604. this.newDeps.push(dep);
  605. if (!this.depIds.has(id)) {
  606. dep.addSub(this);
  607. }
  608. }
  609. };
  610. /**
  611. * Clean up for dependency collection.
  612. */
  613. Watcher.prototype.afterGet = function () {
  614. Dep.target = prevTarget;
  615. var i = this.deps.length;
  616. while (i--) {
  617. var dep = this.deps[i];
  618. if (!this.newDepIds.has(dep.id)) {
  619. dep.removeSub(this);
  620. }
  621. }
  622. var tmp = this.depIds;
  623. this.depIds = this.newDepIds;
  624. this.newDepIds = tmp;
  625. this.newDepIds.clear();
  626. tmp = this.deps;
  627. this.deps = this.newDeps;
  628. this.newDeps = tmp;
  629. this.newDeps.length = 0;
  630. };
  631. /**
  632. * Subscriber interface.
  633. * Will be called when a dependency changes.
  634. *
  635. * @param {Boolean} shallow
  636. */
  637. Watcher.prototype.update = function (shallow) {
  638. if (this.lazy) {
  639. this.dirty = true;
  640. } else if (this.sync) {
  641. this.run();
  642. } else {
  643. // if queued, only overwrite shallow with non-shallow,
  644. // but not the other way around.
  645. this.shallow = this.queued ? shallow ? this.shallow : false : !!shallow;
  646. this.queued = true;
  647. pushWatcher(this);
  648. }
  649. };
  650. /**
  651. * Batcher job interface.
  652. * Will be called by the batcher.
  653. */
  654. Watcher.prototype.run = function () {
  655. if (this.active) {
  656. var value = this.get();
  657. if (value !== this.value ||
  658. // Deep watchers and watchers on Object/Arrays should fire even
  659. // when the value is the same, because the value may
  660. // have mutated; but only do so if this is a
  661. // non-shallow update (caused by a vm digest).
  662. (isObject(value) || this.deep) && !this.shallow) {
  663. // set new value
  664. var oldValue = this.value;
  665. this.value = value;
  666. this.cb.call(this.vm, value, oldValue);
  667. }
  668. this.queued = this.shallow = false;
  669. }
  670. };
  671. /**
  672. * Evaluate the value of the watcher.
  673. * This only gets called for lazy watchers.
  674. */
  675. Watcher.prototype.evaluate = function () {
  676. // avoid overwriting another watcher that is being
  677. // collected.
  678. var current = Dep.target;
  679. this.value = this.get();
  680. this.dirty = false;
  681. Dep.target = current;
  682. };
  683. /**
  684. * Depend on all deps collected by this watcher.
  685. */
  686. Watcher.prototype.depend = function () {
  687. var i = this.deps.length;
  688. while (i--) {
  689. this.deps[i].depend();
  690. }
  691. };
  692. /**
  693. * Remove self from all dependencies' subcriber list.
  694. */
  695. Watcher.prototype.teardown = function () {
  696. if (this.active) {
  697. // remove self from vm's watcher list
  698. // this is a somewhat expensive operation so we skip it
  699. // if the vm is being destroyed or is performing a v-for
  700. // re-render (the watcher list is then filtered by v-for).
  701. if (!this.vm._isBeingDestroyed && !this.vm._vForRemoving) {
  702. remove(this.vm._watchers, this);
  703. }
  704. var i = this.deps.length;
  705. while (i--) {
  706. this.deps[i].removeSub(this);
  707. }
  708. this.active = false;
  709. this.vm = this.cb = this.value = null;
  710. }
  711. };
  712. /**
  713. * Recrusively traverse an object to evoke all converted
  714. * getters, so that every nested property inside the object
  715. * is collected as a "deep" dependency.
  716. *
  717. * @param {*} val
  718. * @param {Set} seen
  719. */
  720. var seenObjects = new _Set();
  721. function traverse(val, seen) {
  722. var i = void 0,
  723. keys = void 0,
  724. isA = void 0,
  725. isO = void 0;
  726. if (!seen) {
  727. seen = seenObjects;
  728. seen.clear();
  729. }
  730. isA = isArray(val);
  731. isO = isObject(val);
  732. if (isA || isO) {
  733. if (val.__ob__) {
  734. var depId = val.__ob__.dep.id;
  735. if (seen.has(depId)) {
  736. return;
  737. } else {
  738. seen.add(depId);
  739. }
  740. }
  741. if (isA) {
  742. i = val.length;
  743. while (i--) {
  744. traverse(val[i], seen);
  745. }
  746. } else if (isO) {
  747. keys = Object.keys(val);
  748. i = keys.length;
  749. while (i--) {
  750. traverse(val[keys[i]], seen);
  751. }
  752. }
  753. }
  754. }
  755. var arrayProto = Array.prototype;
  756. var arrayMethods = Object.create(arrayProto)
  757. /**
  758. * Intercept mutating methods and emit events
  759. */
  760. ;['push', 'pop', 'shift', 'unshift', 'splice', 'sort', 'reverse'].forEach(function (method) {
  761. // cache original method
  762. var original = arrayProto[method];
  763. def(arrayMethods, method, function mutator() {
  764. // avoid leaking arguments:
  765. // http://jsperf.com/closure-with-arguments
  766. var i = arguments.length;
  767. var args = new Array(i);
  768. while (i--) {
  769. args[i] = arguments[i];
  770. }
  771. var result = original.apply(this, args);
  772. var ob = this.__ob__;
  773. var inserted;
  774. switch (method) {
  775. case 'push':
  776. inserted = args;
  777. break;
  778. case 'unshift':
  779. inserted = args;
  780. break;
  781. case 'splice':
  782. inserted = args.slice(2);
  783. break;
  784. }
  785. if (inserted) ob.observeArray(inserted);
  786. // notify change
  787. ob.dep.notify();
  788. return result;
  789. });
  790. });
  791. var arrayKeys = Object.getOwnPropertyNames(arrayMethods);
  792. /**
  793. * By default, when a reactive property is set, the new value is
  794. * also converted to become reactive. However when passing down props,
  795. * we don't want to force conversion because the value may be a nested value
  796. * under a frozen data structure. Converting it would defeat the optimization.
  797. */
  798. var observerState = {
  799. shouldConvert: true
  800. };
  801. /**
  802. * Observer class that are attached to each observed
  803. * object. Once attached, the observer converts target
  804. * object's property keys into getter/setters that
  805. * collect dependencies and dispatches updates.
  806. *
  807. * @param {Array|Object} value
  808. * @constructor
  809. */
  810. function Observer(value) {
  811. this.value = value;
  812. this.dep = new Dep();
  813. def(value, '__ob__', this);
  814. if (isArray(value)) {
  815. var augment = hasProto ? protoAugment : copyAugment;
  816. augment(value, arrayMethods, arrayKeys);
  817. this.observeArray(value);
  818. } else {
  819. this.walk(value);
  820. }
  821. }
  822. // Instance methods
  823. /**
  824. * Walk through each property and convert them into
  825. * getter/setters. This method should only be called when
  826. * value type is Object.
  827. *
  828. * @param {Object} obj
  829. */
  830. Observer.prototype.walk = function (obj) {
  831. for (var key in obj) {
  832. this.convert(key, obj[key]);
  833. }
  834. };
  835. /**
  836. * Observe a list of Array items.
  837. *
  838. * @param {Array} items
  839. */
  840. Observer.prototype.observeArray = function (items) {
  841. for (var i = 0, l = items.length; i < l; i++) {
  842. observe(items[i]);
  843. }
  844. };
  845. /**
  846. * Convert a property into getter/setter so we can emit
  847. * the events when the property is accessed/changed.
  848. *
  849. * @param {String} key
  850. * @param {*} val
  851. */
  852. Observer.prototype.convert = function (key, val) {
  853. defineReactive(this.value, key, val);
  854. };
  855. /**
  856. * Add an owner vm, so that when $set/$delete mutations
  857. * happen we can notify owner vms to proxy the keys and
  858. * digest the watchers. This is only called when the object
  859. * is observed as an instance's root $data.
  860. *
  861. * @param {Vue} vm
  862. */
  863. Observer.prototype.addVm = function (vm) {
  864. (this.vms || (this.vms = [])).push(vm);
  865. };
  866. /**
  867. * Remove an owner vm. This is called when the object is
  868. * swapped out as an instance's $data object.
  869. *
  870. * @param {Vue} vm
  871. */
  872. Observer.prototype.removeVm = function (vm) {
  873. remove(this.vms, vm);
  874. };
  875. // helpers
  876. /**
  877. * Augment an target Object or Array by intercepting
  878. * the prototype chain using __proto__
  879. *
  880. * @param {Object|Array} target
  881. * @param {Object} src
  882. */
  883. function protoAugment(target, src) {
  884. /* eslint-disable no-proto */
  885. target.__proto__ = src;
  886. /* eslint-enable no-proto */
  887. }
  888. /**
  889. * Augment an target Object or Array by defining
  890. * hidden properties.
  891. *
  892. * @param {Object|Array} target
  893. * @param {Object} proto
  894. */
  895. function copyAugment(target, src, keys) {
  896. for (var i = 0, l = keys.length; i < l; i++) {
  897. var key = keys[i];
  898. def(target, key, src[key]);
  899. }
  900. }
  901. /**
  902. * Attempt to create an observer instance for a value,
  903. * returns the new observer if successfully observed,
  904. * or the existing observer if the value already has one.
  905. *
  906. * @param {*} value
  907. * @param {Vue} [vm]
  908. * @return {Observer|undefined}
  909. * @static
  910. */
  911. function observe(value, vm) {
  912. if (!isObject(value)) {
  913. return;
  914. }
  915. var ob;
  916. if (hasOwn(value, '__ob__') && value.__ob__ instanceof Observer) {
  917. ob = value.__ob__;
  918. } else if (observerState.shouldConvert && (isArray(value) || isPlainObject(value)) && Object.isExtensible(value) && !value._isVue) {
  919. ob = new Observer(value);
  920. }
  921. if (ob && vm) {
  922. ob.addVm(vm);
  923. }
  924. return ob;
  925. }
  926. /**
  927. * Define a reactive property on an Object.
  928. *
  929. * @param {Object} obj
  930. * @param {String} key
  931. * @param {*} val
  932. */
  933. function defineReactive(obj, key, val) {
  934. var dep = new Dep();
  935. var property = Object.getOwnPropertyDescriptor(obj, key);
  936. if (property && property.configurable === false) {
  937. return;
  938. }
  939. // cater for pre-defined getter/setters
  940. var getter = property && property.get;
  941. var setter = property && property.set;
  942. var childOb = observe(val);
  943. Object.defineProperty(obj, key, {
  944. enumerable: true,
  945. configurable: true,
  946. get: function reactiveGetter() {
  947. var value = getter ? getter.call(obj) : val;
  948. if (Dep.target) {
  949. dep.depend();
  950. if (childOb) {
  951. childOb.dep.depend();
  952. }
  953. if (isArray(value)) {
  954. for (var e, i = 0, l = value.length; i < l; i++) {
  955. e = value[i];
  956. e && e.__ob__ && e.__ob__.dep.depend();
  957. }
  958. }
  959. }
  960. return value;
  961. },
  962. set: function reactiveSetter(newVal) {
  963. var value = getter ? getter.call(obj) : val;
  964. if (newVal === value) {
  965. return;
  966. }
  967. if (setter) {
  968. setter.call(obj, newVal);
  969. } else {
  970. val = newVal;
  971. }
  972. childOb = observe(newVal);
  973. dep.notify();
  974. }
  975. });
  976. }
  977. /**
  978. * Set a property on an object. Adds the new property and
  979. * triggers change notification if the property doesn't
  980. * already exist.
  981. *
  982. * @param {Object} obj
  983. * @param {String} key
  984. * @param {*} val
  985. * @public
  986. */
  987. function set(obj, key, val) {
  988. if (isArray(obj)) {
  989. return obj.splice(key, 1, val);
  990. }
  991. if (hasOwn(obj, key)) {
  992. obj[key] = val;
  993. return;
  994. }
  995. if (obj._isVue) {
  996. set(obj._data, key, val);
  997. return;
  998. }
  999. var ob = obj.__ob__;
  1000. if (!ob) {
  1001. obj[key] = val;
  1002. return;
  1003. }
  1004. ob.convert(key, val);
  1005. ob.dep.notify();
  1006. if (ob.vms) {
  1007. var i = ob.vms.length;
  1008. while (i--) {
  1009. var vm = ob.vms[i];
  1010. proxy(vm, key);
  1011. vm.$forceUpdate();
  1012. }
  1013. }
  1014. return val;
  1015. }
  1016. /**
  1017. * Delete a property and trigger change if necessary.
  1018. *
  1019. * @param {Object} obj
  1020. * @param {String} key
  1021. */
  1022. function del(obj, key) {
  1023. if (!hasOwn(obj, key)) {
  1024. return;
  1025. }
  1026. delete obj[key];
  1027. var ob = obj.__ob__;
  1028. if (!ob) {
  1029. if (obj._isVue) {
  1030. delete obj._data[key];
  1031. obj.$forceUpdate();
  1032. }
  1033. return;
  1034. }
  1035. ob.dep.notify();
  1036. if (ob.vms) {
  1037. var i = ob.vms.length;
  1038. while (i--) {
  1039. var vm = ob.vms[i];
  1040. unproxy(vm, key);
  1041. vm.$forceUpdate();
  1042. }
  1043. }
  1044. }
  1045. function proxy(vm, key) {
  1046. if (!isReserved(key)) {
  1047. Object.defineProperty(vm, key, {
  1048. configurable: true,
  1049. enumerable: true,
  1050. get: function proxyGetter() {
  1051. return vm._data[key];
  1052. },
  1053. set: function proxySetter(val) {
  1054. vm._data[key] = val;
  1055. }
  1056. });
  1057. }
  1058. }
  1059. function unproxy(vm, key) {
  1060. if (!isReserved(key)) {
  1061. delete vm[key];
  1062. }
  1063. }
  1064. function initState(vm) {
  1065. vm._watchers = [];
  1066. initProps(vm);
  1067. initData(vm);
  1068. initComputed(vm);
  1069. initMethods(vm);
  1070. initWatch(vm);
  1071. }
  1072. function initProps(vm) {
  1073. var props = vm.$options.props;
  1074. var propsData = vm.$options.propsData;
  1075. if (props) {
  1076. var keys = vm.$options.propKeys = Object.keys(props);
  1077. var isRoot = !vm.$parent;
  1078. // root instance props should be converted
  1079. observerState.shouldConvert = isRoot;
  1080. for (var i = 0; i < keys.length; i++) {
  1081. var key = keys[i];
  1082. defineReactive(vm, key, validateProp(vm, key, propsData));
  1083. }
  1084. observerState.shouldConvert = true;
  1085. }
  1086. }
  1087. function initData(vm) {
  1088. var data = vm.$options.data;
  1089. data = vm._data = typeof data === 'function' ? data() : data || {};
  1090. if (!isPlainObject(data)) {
  1091. data = {};
  1092. "development" !== 'production' && warn('data functions should return an object.', vm);
  1093. }
  1094. // proxy data on instance
  1095. var keys = Object.keys(data);
  1096. var i = keys.length;
  1097. while (i--) {
  1098. proxy(vm, keys[i]);
  1099. }
  1100. // observe data
  1101. observe(data, vm);
  1102. }
  1103. function noop() {}
  1104. function initComputed(vm) {
  1105. var computed = vm.$options.computed;
  1106. if (computed) {
  1107. for (var key in computed) {
  1108. var userDef = computed[key];
  1109. var def = {
  1110. enumerable: true,
  1111. configurable: true
  1112. };
  1113. if (typeof userDef === 'function') {
  1114. def.get = makeComputedGetter(userDef, vm);
  1115. def.set = noop;
  1116. } else {
  1117. def.get = userDef.get ? userDef.cache !== false ? makeComputedGetter(userDef.get, vm) : bind(userDef.get, vm) : noop;
  1118. def.set = userDef.set ? bind(userDef.set, vm) : noop;
  1119. }
  1120. Object.defineProperty(vm, key, def);
  1121. }
  1122. }
  1123. }
  1124. function makeComputedGetter(getter, owner) {
  1125. var watcher = new Watcher(owner, getter, null, {
  1126. lazy: true
  1127. });
  1128. return function computedGetter() {
  1129. if (watcher.dirty) {
  1130. watcher.evaluate();
  1131. }
  1132. if (Dep.target) {
  1133. watcher.depend();
  1134. }
  1135. return watcher.value;
  1136. };
  1137. }
  1138. function initMethods(vm) {
  1139. var methods = vm.$options.methods;
  1140. if (methods) {
  1141. for (var key in methods) {
  1142. vm[key] = bind(methods[key], vm);
  1143. }
  1144. }
  1145. }
  1146. function initWatch(vm) {
  1147. var watch = vm.$options.watch;
  1148. if (watch) {
  1149. for (var key in watch) {
  1150. var handler = watch[key];
  1151. if (isArray(handler)) {
  1152. for (var i = 0; i < handler.length; i++) {
  1153. createWatcher(vm, key, handler[i]);
  1154. }
  1155. } else {
  1156. createWatcher(vm, key, handler);
  1157. }
  1158. }
  1159. }
  1160. }
  1161. function createWatcher(vm, key, handler) {
  1162. var options = void 0;
  1163. if (isPlainObject(handler)) {
  1164. options = handler;
  1165. handler = handler.handler;
  1166. }
  1167. if (typeof handler === 'string') {
  1168. handler = vm[handler];
  1169. }
  1170. vm.$watch(key, handler, options);
  1171. }
  1172. function stateMixin(Vue) {
  1173. Object.defineProperty(Vue.prototype, '$data', {
  1174. get: function get() {
  1175. return this._data;
  1176. },
  1177. set: function set(newData) {
  1178. if (newData !== this._data) {
  1179. setData(this, newData);
  1180. }
  1181. }
  1182. });
  1183. Vue.prototype.$watch = function (fn, cb, options) {
  1184. options = options || {};
  1185. options.user = true;
  1186. var watcher = new Watcher(this, fn, cb, options);
  1187. if (options.immediate) {
  1188. cb.call(this, watcher.value);
  1189. }
  1190. return function unwatchFn() {
  1191. watcher.teardown();
  1192. };
  1193. };
  1194. }
  1195. function setData(vm, newData) {
  1196. newData = newData || {};
  1197. var oldData = vm._data;
  1198. vm._data = newData;
  1199. var keys, key, i;
  1200. // unproxy keys not present in new data
  1201. keys = Object.keys(oldData);
  1202. i = keys.length;
  1203. while (i--) {
  1204. key = keys[i];
  1205. if (!(key in newData)) {
  1206. unproxy(vm, key);
  1207. }
  1208. }
  1209. // proxy keys not already proxied,
  1210. // and trigger change for changed values
  1211. keys = Object.keys(newData);
  1212. i = keys.length;
  1213. while (i--) {
  1214. key = keys[i];
  1215. if (!hasOwn(vm, key)) {
  1216. // new property
  1217. proxy(vm, key);
  1218. }
  1219. }
  1220. oldData.__ob__.removeVm(vm);
  1221. observe(newData, vm);
  1222. vm.$forceUpdate();
  1223. }
  1224. function VNode(tag, data, children, text, elm, ns, context) {
  1225. return {
  1226. tag: tag,
  1227. data: data,
  1228. children: children,
  1229. text: text,
  1230. elm: elm,
  1231. ns: ns,
  1232. context: context,
  1233. key: data && data.key
  1234. };
  1235. }
  1236. function flatten(children) {
  1237. if (typeof children === 'string') {
  1238. return [VNode(undefined, undefined, undefined, children)];
  1239. }
  1240. if (isArray(children)) {
  1241. var res = [];
  1242. for (var i = 0, l = children.length; i < l; i++) {
  1243. var c = children[i];
  1244. // flatten nested
  1245. if (isArray(c)) {
  1246. res.push.apply(res, flatten(c));
  1247. } else if (isPrimitive(c)) {
  1248. // convert primitive to vnode
  1249. res.push(VNode(undefined, undefined, undefined, c));
  1250. } else if (c) {
  1251. res.push(c);
  1252. }
  1253. }
  1254. return res;
  1255. }
  1256. }
  1257. function updateListeners(on, oldOn, add) {
  1258. var name = void 0,
  1259. cur = void 0,
  1260. old = void 0,
  1261. event = void 0,
  1262. capture = void 0;
  1263. for (name in on) {
  1264. cur = on[name];
  1265. old = oldOn[name];
  1266. if (old === undefined) {
  1267. capture = name.charAt(0) === '!';
  1268. event = capture ? name.slice(1) : name;
  1269. if (isArray(cur)) {
  1270. add(event, arrInvoker(cur), capture);
  1271. } else {
  1272. cur = { fn: cur };
  1273. on[name] = cur;
  1274. add(event, fnInvoker(cur), capture);
  1275. }
  1276. } else if (isArray(old)) {
  1277. old.length = cur.length;
  1278. for (var i = 0; i < old.length; i++) {
  1279. old[i] = cur[i];
  1280. }on[name] = old;
  1281. } else {
  1282. old.fn = cur;
  1283. on[name] = old;
  1284. }
  1285. }
  1286. }
  1287. function arrInvoker(arr) {
  1288. return function (ev) {
  1289. for (var i = 0; i < arr.length; i++) {
  1290. arr[i](ev);
  1291. }
  1292. };
  1293. }
  1294. function fnInvoker(o) {
  1295. return function (ev) {
  1296. o.fn(ev);
  1297. };
  1298. }
  1299. function initLifecycle(vm) {
  1300. var options = vm.$options;
  1301. vm.$parent = options.parent;
  1302. vm.$root = vm.$parent ? vm.$parent.$root : vm;
  1303. if (vm.$parent) {
  1304. vm.$parent.$children.push(vm);
  1305. }
  1306. vm.$children = [];
  1307. vm.$refs = {};
  1308. vm._isDestroyed = false;
  1309. vm._isBeingDestroyed = false;
  1310. }
  1311. function lifecycleMixin(Vue) {
  1312. Vue.prototype._mount = function () {
  1313. var _this = this;
  1314. if (!this.$options.render) {
  1315. this.$options.render = function () {
  1316. return _this.$createElement('div');
  1317. };
  1318. if ("development" !== 'production') {
  1319. if (this.$options.template) {
  1320. warn('You are using the runtime-only build of Vue where the template ' + 'option is not available. Either pre-compile the templates into ' + 'render functions, or use the compiler-included build.', this);
  1321. } else {
  1322. warn('Failed to mount component: template or render function not defined.', this);
  1323. }
  1324. }
  1325. }
  1326. // render static sub-trees for once on mount
  1327. var staticRenderFns = this.$options.staticRenderFns;
  1328. if (staticRenderFns) {
  1329. this._staticTrees = new Array(staticRenderFns.length);
  1330. for (var i = 0; i < staticRenderFns.length; i++) {
  1331. this._staticTrees[i] = staticRenderFns[i].call(this._renderProxy);
  1332. }
  1333. }
  1334. this._watcher = new Watcher(this, this._render, this._update);
  1335. this._update(this._watcher.value);
  1336. this._mounted = true;
  1337. // root instance, call ready on self
  1338. if (this.$root === this) {
  1339. callHook(this, 'ready');
  1340. }
  1341. return this;
  1342. };
  1343. Vue.prototype._update = function (vnode) {
  1344. if (this._mounted) {
  1345. callHook(this, 'beforeUpdate');
  1346. }
  1347. var parentNode = this.$options._parentVnode;
  1348. // set vnode parent before patch
  1349. vnode.parent = parentNode;
  1350. if (!this._vnode) {
  1351. // Vue.prototype.__patch__ is injected in entry points
  1352. // based on the rendering backend used.
  1353. this.$el = this.__patch__(this.$el, vnode);
  1354. } else {
  1355. this.$el = this.__patch__(this._vnode, vnode);
  1356. }
  1357. this._vnode = vnode;
  1358. // set parent vnode element after patch
  1359. if (parentNode) {
  1360. parentNode.elm = this.$el;
  1361. }
  1362. if (this._mounted) {
  1363. callHook(this, 'updated');
  1364. }
  1365. };
  1366. Vue.prototype._updateFromParent = function (propsData, listeners, parentVnode, children) {
  1367. var _this2 = this;
  1368. this.$options._parentVnode = parentVnode;
  1369. this.$options._renderChildren = children;
  1370. // update props
  1371. if (propsData && this.$options.props) {
  1372. observerState.shouldConvert = false;
  1373. var propKeys = this.$options.propKeys;
  1374. for (var i = 0; i < propKeys.length; i++) {
  1375. var key = propKeys[i];
  1376. this[key] = validateProp(this, key, propsData);
  1377. }
  1378. observerState.shouldConvert = true;
  1379. }
  1380. // update listeners
  1381. if (listeners) {
  1382. var oldListeners = this.$options._parentListeners;
  1383. this.$options._parentListeners = listeners;
  1384. updateListeners(listeners, oldListeners || {}, function (event, handler) {
  1385. _this2.$on(event, handler);
  1386. });
  1387. }
  1388. };
  1389. Vue.prototype.$forceUpdate = function () {
  1390. this._watcher.update();
  1391. };
  1392. Vue.prototype.$destroy = function () {
  1393. if (this._isDestroyed) {
  1394. return;
  1395. }
  1396. callHook(this, 'beforeDestroy');
  1397. this._isBeingDestroyed = true;
  1398. // remove self from parent
  1399. var parent = this.$parent;
  1400. if (parent && !parent._isBeingDestroyed) {
  1401. remove(parent.$children, this);
  1402. }
  1403. // unregister ref
  1404. if (this._ref) {
  1405. this._context.$refs[this._ref] = undefined;
  1406. }
  1407. // teardown watchers
  1408. var i = this._watchers.length;
  1409. while (i--) {
  1410. this._watchers[i].teardown();
  1411. }
  1412. // remove reference from data ob
  1413. // frozen object may not have observer.
  1414. if (this._data.__ob__) {
  1415. this._data.__ob__.removeVm(this);
  1416. }
  1417. // call the last hook...
  1418. this._isDestroyed = true;
  1419. callHook(this, 'destroyed');
  1420. // turn off all instance listeners.
  1421. this.$off();
  1422. };
  1423. }
  1424. function callHook(vm, hook) {
  1425. vm.$emit('pre-hook:' + hook);
  1426. var handlers = vm.$options[hook];
  1427. if (handlers) {
  1428. for (var i = 0, j = handlers.length; i < j; i++) {
  1429. handlers[i].call(vm);
  1430. }
  1431. }
  1432. vm.$emit('hook:' + hook);
  1433. }
  1434. var hooks = { init: init, prepatch: prepatch, insert: insert, destroy: destroy };
  1435. var hooksToMerge = Object.keys(hooks);
  1436. function createComponent(Ctor, data, parent, children, context) {
  1437. if ("development" !== 'production' && children && typeof children !== 'function') {
  1438. warn('A component\'s children should be a function that returns the ' + 'children array. This allows the component to track the children ' + 'dependencies and optimizes re-rendering.');
  1439. }
  1440. if (!Ctor) {
  1441. return;
  1442. }
  1443. if (isObject(Ctor)) {
  1444. Ctor = Vue.extend(Ctor);
  1445. }
  1446. if ("development" !== 'production' && typeof Ctor !== 'function') {
  1447. warn('Invalid Component definition: ' + Ctor, parent);
  1448. return;
  1449. }
  1450. // async component
  1451. if (!Ctor.cid) {
  1452. if (Ctor.resolved) {
  1453. Ctor = Ctor.resolved;
  1454. } else {
  1455. resolveAsyncComponent(Ctor, function () {
  1456. // it's ok to queue this on every render because
  1457. // $forceUpdate is buffered.
  1458. parent.$forceUpdate();
  1459. });
  1460. return;
  1461. }
  1462. }
  1463. data = data || {};
  1464. // merge component management hooks onto the placeholder node
  1465. mergeHooks(data);
  1466. // extract props
  1467. var propsData = extractProps(data, Ctor);
  1468. // extract listeners, since these needs to be treated as
  1469. // child component listeners instead of DOM listeners
  1470. var listeners = data.on;
  1471. if (listeners) {
  1472. data.on = null;
  1473. }
  1474. // return a placeholder vnode
  1475. var name = Ctor.options.name ? '-' + Ctor.options.name : '';
  1476. var vnode = VNode('vue-component-' + Ctor.cid + name, data, undefined, undefined, undefined, undefined, context);
  1477. vnode.componentOptions = { Ctor: Ctor, propsData: propsData, listeners: listeners, parent: parent, children: children };
  1478. return vnode;
  1479. }
  1480. function init(vnode) {
  1481. var _vnode$componentOptio = vnode.componentOptions;
  1482. var Ctor = _vnode$componentOptio.Ctor;
  1483. var propsData = _vnode$componentOptio.propsData;
  1484. var listeners = _vnode$componentOptio.listeners;
  1485. var parent = _vnode$componentOptio.parent;
  1486. var children = _vnode$componentOptio.children;
  1487. var child = new Ctor({
  1488. parent: parent,
  1489. propsData: propsData,
  1490. _parentVnode: vnode,
  1491. _parentListeners: listeners,
  1492. _renderChildren: children
  1493. });
  1494. // if this is a server-rendered mount,
  1495. // the vnode would already have an element.
  1496. // otherwise the child sets the parent vnode's elm when mounted
  1497. // and when updated.
  1498. child.$mount(vnode.elm);
  1499. vnode.child = child;
  1500. }
  1501. function prepatch(oldVnode, vnode) {
  1502. var _vnode$componentOptio2 = vnode.componentOptions;
  1503. var listeners = _vnode$componentOptio2.listeners;
  1504. var propsData = _vnode$componentOptio2.propsData;
  1505. var children = _vnode$componentOptio2.children;
  1506. vnode.child = oldVnode.child;
  1507. vnode.child._updateFromParent(propsData, // updated props
  1508. listeners, // updated listeners
  1509. vnode, // new parent vnode
  1510. children // new children
  1511. );
  1512. }
  1513. function insert(vnode) {
  1514. callHook(vnode.child, 'ready');
  1515. }
  1516. function destroy(vnode) {
  1517. vnode.child.$destroy();
  1518. }
  1519. function resolveAsyncComponent(factory, cb) {
  1520. if (factory.resolved) {
  1521. // cached
  1522. cb(factory.resolved);
  1523. } else if (factory.requested) {
  1524. // pool callbacks
  1525. factory.pendingCallbacks.push(cb);
  1526. } else {
  1527. (function () {
  1528. factory.requested = true;
  1529. var cbs = factory.pendingCallbacks = [cb];
  1530. factory(function resolve(res) {
  1531. if (isObject(res)) {
  1532. res = Vue.extend(res);
  1533. }
  1534. // cache resolved
  1535. factory.resolved = res;
  1536. // invoke callbacks
  1537. for (var i = 0, l = cbs.length; i < l; i++) {
  1538. cbs[i](res);
  1539. }
  1540. }, function reject(reason) {
  1541. "development" !== 'production' && warn('Failed to resolve async component: ' + factory + (reason ? '\nReason: ' + reason : ''));
  1542. });
  1543. })();
  1544. }
  1545. }
  1546. function extractProps(data, Ctor) {
  1547. // we are only extrating raw values here.
  1548. // validation and default values are handled in the child
  1549. // component itself.
  1550. var propOptions = Ctor.options.props;
  1551. if (!propOptions) {
  1552. return;
  1553. }
  1554. var res = {};
  1555. var attrs = data.attrs;
  1556. var props = data.props;
  1557. var staticAttrs = data.staticAttrs;
  1558. if (!attrs && !props) {
  1559. return res;
  1560. }
  1561. for (var key in propOptions) {
  1562. var altKey = hyphenate(key);
  1563. checkProp(res, attrs, key, altKey) || checkProp(res, props, key, altKey) || checkProp(res, staticAttrs, key, altKey);
  1564. }
  1565. return res;
  1566. }
  1567. function checkProp(res, hash, key, altKey) {
  1568. if (hash) {
  1569. if (hasOwn(hash, key)) {
  1570. res[key] = hash[key];
  1571. delete hash[key];
  1572. return true;
  1573. } else if (hasOwn(hash, altKey)) {
  1574. res[key] = hash[altKey];
  1575. delete hash[altKey];
  1576. return true;
  1577. }
  1578. }
  1579. }
  1580. function mergeHooks(data) {
  1581. if (data.hook) {
  1582. for (var i = 0; i < hooksToMerge.length; i++) {
  1583. var key = hooksToMerge[i];
  1584. var fromParent = data.hook[key];
  1585. var ours = hooks[key];
  1586. data.hook[key] = fromParent ? mergeHook$1(ours, fromParent) : ours;
  1587. }
  1588. } else {
  1589. data.hook = hooks;
  1590. }
  1591. }
  1592. function mergeHook$1(a, b) {
  1593. // since all hooks have at most two args, use fixed args
  1594. // to avoid having to use fn.apply().
  1595. return function (_, __) {
  1596. a(_, __);
  1597. b(_, __);
  1598. };
  1599. }
  1600. function createElement(tag, data, children, namespace) {
  1601. var context = this;
  1602. var parent = renderState.activeInstance;
  1603. if (typeof tag === 'string') {
  1604. var Ctor = void 0;
  1605. if (config.isReservedTag(tag)) {
  1606. return VNode(tag, data, flatten(children), undefined, undefined, namespace, context);
  1607. } else if (Ctor = resolveAsset(context.$options, 'components', tag)) {
  1608. return createComponent(Ctor, data, parent, children, context);
  1609. } else {
  1610. if ("development" !== 'production') {
  1611. if (!namespace && config.isUnknownElement(tag)) {
  1612. warn('Unknown custom element: <' + tag + '> - did you ' + 'register the component correctly? For recursive components, ' + 'make sure to provide the "name" option.');
  1613. }
  1614. }
  1615. return VNode(tag, data, flatten(children && children()), undefined, undefined, namespace, context);
  1616. }
  1617. } else {
  1618. return createComponent(tag, data, parent, children, context);
  1619. }
  1620. }
  1621. var renderState = {
  1622. activeInstance: null
  1623. };
  1624. function initRender(vm) {
  1625. vm._vnode = null;
  1626. vm._mounted = false;
  1627. vm._staticTrees = null;
  1628. vm.$slots = {};
  1629. // bind the public createElement fn to this instance
  1630. // so that we get proper render context inside it.
  1631. vm.$createElement = bind(createElement, vm);
  1632. if (vm.$options.el) {
  1633. vm.$mount(vm.$options.el);
  1634. }
  1635. }
  1636. function renderMixin(Vue) {
  1637. Vue.prototype._render = function () {
  1638. var prev = renderState.activeInstance;
  1639. renderState.activeInstance = this;
  1640. var _$options = this.$options;
  1641. var render = _$options.render;
  1642. var _renderChildren = _$options._renderChildren;
  1643. // resolve slots. becaues slots are rendered in parent scope,
  1644. // we set the activeInstance to parent.
  1645. if (_renderChildren) {
  1646. resolveSlots(this, _renderChildren);
  1647. }
  1648. // render self
  1649. var vnode = render.call(this._renderProxy);
  1650. // restore render state
  1651. renderState.activeInstance = prev;
  1652. return vnode;
  1653. };
  1654. // shorthands used in render functions
  1655. Vue.prototype.__h__ = createElement;
  1656. // toString for mustaches
  1657. Vue.prototype.__toString__ = renderString;
  1658. // render v-for
  1659. Vue.prototype.__renderList__ = function (val, render) {
  1660. var ret = void 0,
  1661. i = void 0,
  1662. l = void 0,
  1663. keys = void 0,
  1664. key = void 0;
  1665. if (isArray(val)) {
  1666. ret = new Array(val.length);
  1667. for (i = 0, l = val.length; i < l; i++) {
  1668. ret[i] = render(val[i], i, i);
  1669. }
  1670. } else if (typeof val === 'number') {
  1671. ret = new Array(val);
  1672. for (i = 0; i < val; i++) {
  1673. ret[i] = render(i + 1, i, i);
  1674. }
  1675. } else if (isObject(val)) {
  1676. keys = Object.keys(val);
  1677. ret = new Array(keys.length);
  1678. for (i = 0, l = keys.length; i < l; i++) {
  1679. key = keys[i];
  1680. ret[i] = render(val[key], i, key);
  1681. }
  1682. }
  1683. return ret;
  1684. };
  1685. // register ref
  1686. Vue.prototype.__registerRef__ = function (key, ref, vFor, remove) {
  1687. var refs = this.$refs;
  1688. if (remove) {
  1689. if (vFor) {
  1690. remove(refs[key], ref);
  1691. } else {
  1692. refs[key] = undefined;
  1693. }
  1694. } else {
  1695. if (vFor) {
  1696. if (refs[key]) {
  1697. refs[key].push(ref);
  1698. } else {
  1699. refs[key] = [ref];
  1700. }
  1701. } else {
  1702. refs[key] = ref;
  1703. }
  1704. }
  1705. };
  1706. }
  1707. function resolveSlots(vm, children) {
  1708. if (children) {
  1709. children = flatten(isArray(children) ? children : children());
  1710. var slots = { default: children };
  1711. var i = children.length;
  1712. var name = void 0,
  1713. child = void 0;
  1714. while (i--) {
  1715. child = children[i];
  1716. if (name = child.data && child.data.slot) {
  1717. var slot = slots[name] || (slots[name] = []);
  1718. if (child.tag === 'template') {
  1719. slot.push.apply(slot, child.children);
  1720. } else {
  1721. slot.push(child);
  1722. }
  1723. children.splice(i, 1);
  1724. }
  1725. }
  1726. vm.$slots = slots;
  1727. }
  1728. }
  1729. function initEvents(vm) {
  1730. vm._events = Object.create(null);
  1731. // init parent attached events
  1732. var listeners = vm.$options._parentListeners;
  1733. if (listeners) {
  1734. updateListeners(listeners, {}, function (event, handler) {
  1735. vm.$on(event, handler);
  1736. });
  1737. }
  1738. }
  1739. function eventsMixin(Vue) {
  1740. Vue.prototype.$on = function (event, fn) {
  1741. (this._events[event] || (this._events[event] = [])).push(fn);
  1742. return this;
  1743. };
  1744. /**
  1745. * Adds an `event` listener that will be invoked a single
  1746. * time then automatically removed.
  1747. *
  1748. * @param {String} event
  1749. * @param {Function} fn
  1750. */
  1751. Vue.prototype.$once = function (event, fn) {
  1752. var self = this;
  1753. function on() {
  1754. self.$off(event, on);
  1755. fn.apply(this, arguments);
  1756. }
  1757. on.fn = fn;
  1758. this.$on(event, on);
  1759. return this;
  1760. };
  1761. /**
  1762. * Remove the given callback for `event` or all
  1763. * registered callbacks.
  1764. *
  1765. * @param {String} event
  1766. * @param {Function} fn
  1767. */
  1768. Vue.prototype.$off = function (event, fn) {
  1769. var cbs;
  1770. // all
  1771. if (!arguments.length) {
  1772. this._events = Object.create(null);
  1773. return this;
  1774. }
  1775. // specific event
  1776. cbs = this._events[event];
  1777. if (!cbs) {
  1778. return this;
  1779. }
  1780. if (arguments.length === 1) {
  1781. this._events[event] = null;
  1782. return this;
  1783. }
  1784. // specific handler
  1785. var cb;
  1786. var i = cbs.length;
  1787. while (i--) {
  1788. cb = cbs[i];
  1789. if (cb === fn || cb.fn === fn) {
  1790. cbs.splice(i, 1);
  1791. break;
  1792. }
  1793. }
  1794. return this;
  1795. };
  1796. /**
  1797. * Trigger an event on self.
  1798. *
  1799. * @param {String} event
  1800. */
  1801. Vue.prototype.$emit = function (event) {
  1802. var cbs = this._events[event];
  1803. if (cbs) {
  1804. cbs = cbs.length > 1 ? toArray(cbs) : cbs;
  1805. var args = toArray(arguments, 1);
  1806. for (var i = 0, l = cbs.length; i < l; i++) {
  1807. cbs[i].apply(this, args);
  1808. }
  1809. }
  1810. };
  1811. }
  1812. var uid = 0;
  1813. function Vue(options) {
  1814. this._init(options);
  1815. }
  1816. Vue.prototype._init = function (options) {
  1817. // a uid
  1818. this._uid = uid++;
  1819. // a flag to avoid this being observed
  1820. this._isVue = true;
  1821. // merge options
  1822. this.$options = mergeOptions(this.constructor.options, options || {}, this);
  1823. if ("development" !== 'production') {
  1824. initProxy(this);
  1825. } else {}
  1826. initLifecycle(this);
  1827. initEvents(this);
  1828. callHook(this, 'init');
  1829. initState(this);
  1830. callHook(this, 'created');
  1831. initRender(this);
  1832. };
  1833. Vue.prototype.$nextTick = function (fn) {
  1834. nextTick(fn, this);
  1835. };
  1836. stateMixin(Vue);
  1837. eventsMixin(Vue);
  1838. lifecycleMixin(Vue);
  1839. renderMixin(Vue);
  1840. var warn = void 0;
  1841. var formatComponentName = void 0;
  1842. if ("development" !== 'production') {
  1843. (function () {
  1844. var hasConsole = typeof console !== 'undefined';
  1845. warn = function warn(msg, vm) {
  1846. if (hasConsole && !config.silent) {
  1847. console.error('[Vue warn]: ' + msg + (vm ? formatComponentName(vm) : ''));
  1848. }
  1849. };
  1850. formatComponentName = function formatComponentName(vm) {
  1851. var name = vm._isVue ? vm.$options.name : vm.name;
  1852. return name ? ' (found in component: <' + hyphenate(name) + '>)' : '';
  1853. };
  1854. })();
  1855. }
  1856. /**
  1857. * Option overwriting strategies are functions that handle
  1858. * how to merge a parent option value and a child option
  1859. * value into the final value.
  1860. *
  1861. * All strategy functions follow the same signature:
  1862. *
  1863. * @param {*} parentVal
  1864. * @param {*} childVal
  1865. * @param {Vue} [vm]
  1866. */
  1867. var strats = config.optionMergeStrategies = Object.create(null);
  1868. /**
  1869. * Helper that recursively merges two data objects together.
  1870. */
  1871. function mergeData(to, from) {
  1872. var key, toVal, fromVal;
  1873. for (key in from) {
  1874. toVal = to[key];
  1875. fromVal = from[key];
  1876. if (!hasOwn(to, key)) {
  1877. set(to, key, fromVal);
  1878. } else if (isObject(toVal) && isObject(fromVal)) {
  1879. mergeData(toVal, fromVal);
  1880. }
  1881. }
  1882. return to;
  1883. }
  1884. /**
  1885. * Data
  1886. */
  1887. strats.data = function (parentVal, childVal, vm) {
  1888. if (!vm) {
  1889. // in a Vue.extend merge, both should be functions
  1890. if (!childVal) {
  1891. return parentVal;
  1892. }
  1893. if (typeof childVal !== 'function') {
  1894. "development" !== 'production' && warn('The "data" option should be a function ' + 'that returns a per-instance value in component ' + 'definitions.', vm);
  1895. return parentVal;
  1896. }
  1897. if (!parentVal) {
  1898. return childVal;
  1899. }
  1900. // when parentVal & childVal are both present,
  1901. // we need to return a function that returns the
  1902. // merged result of both functions... no need to
  1903. // check if parentVal is a function here because
  1904. // it has to be a function to pass previous merges.
  1905. return function mergedDataFn() {
  1906. return mergeData(childVal.call(this), parentVal.call(this));
  1907. };
  1908. } else if (parentVal || childVal) {
  1909. return function mergedInstanceDataFn() {
  1910. // instance merge
  1911. var instanceData = typeof childVal === 'function' ? childVal.call(vm) : childVal;
  1912. var defaultData = typeof parentVal === 'function' ? parentVal.call(vm) : undefined;
  1913. if (instanceData) {
  1914. return mergeData(instanceData, defaultData);
  1915. } else {
  1916. return defaultData;
  1917. }
  1918. };
  1919. }
  1920. };
  1921. /**
  1922. * El
  1923. */
  1924. strats.el = function (parentVal, childVal, vm) {
  1925. if (!vm && childVal && typeof childVal !== 'function') {
  1926. "development" !== 'production' && warn('The "el" option should be a function ' + 'that returns a per-instance value in component ' + 'definitions.', vm);
  1927. return;
  1928. }
  1929. var ret = childVal || parentVal;
  1930. // invoke the element factory if this is instance merge
  1931. return vm && typeof ret === 'function' ? ret.call(vm) : ret;
  1932. };
  1933. /**
  1934. * Hooks and param attributes are merged as arrays.
  1935. */
  1936. function mergeHook(parentVal, childVal) {
  1937. return childVal ? parentVal ? parentVal.concat(childVal) : isArray(childVal) ? childVal : [childVal] : parentVal;
  1938. }
  1939. config._lifecycleHooks.forEach(function (hook) {
  1940. strats[hook] = mergeHook;
  1941. });
  1942. /**
  1943. * Assets
  1944. *
  1945. * When a vm is present (instance creation), we need to do
  1946. * a three-way merge between constructor options, instance
  1947. * options and parent options.
  1948. */
  1949. function mergeAssets(parentVal, childVal) {
  1950. var res = Object.create(parentVal);
  1951. return childVal ? extend(res, childVal) : res;
  1952. }
  1953. config._assetTypes.forEach(function (type) {
  1954. strats[type + 's'] = mergeAssets;
  1955. });
  1956. /**
  1957. * Watchers.
  1958. *
  1959. * Watchers hashes should not overwrite one
  1960. * another, so we merge them as arrays.
  1961. */
  1962. strats.watch = function (parentVal, childVal) {
  1963. if (!childVal) return parentVal;
  1964. if (!parentVal) return childVal;
  1965. var ret = {};
  1966. extend(ret, parentVal);
  1967. for (var key in childVal) {
  1968. var parent = ret[key];
  1969. var child = childVal[key];
  1970. if (parent && !isArray(parent)) {
  1971. parent = [parent];
  1972. }
  1973. ret[key] = parent ? parent.concat(child) : [child];
  1974. }
  1975. return ret;
  1976. };
  1977. /**
  1978. * Other object hashes.
  1979. */
  1980. strats.props = strats.methods = strats.computed = function (parentVal, childVal) {
  1981. if (!childVal) return parentVal;
  1982. if (!parentVal) return childVal;
  1983. var ret = Object.create(null);
  1984. extend(ret, parentVal);
  1985. extend(ret, childVal);
  1986. return ret;
  1987. };
  1988. /**
  1989. * Default strategy.
  1990. */
  1991. var defaultStrat = function defaultStrat(parentVal, childVal) {
  1992. return childVal === undefined ? parentVal : childVal;
  1993. };
  1994. /**
  1995. * Make sure component options get converted to actual
  1996. * constructors.
  1997. *
  1998. * @param {Object} options
  1999. */
  2000. function guardComponents(options) {
  2001. if (options.components) {
  2002. var components = options.components;
  2003. var def;
  2004. for (var key in components) {
  2005. if (isBuiltInTag(key) || config.isReservedTag(key)) {
  2006. "development" !== 'production' && warn('Do not use built-in or reserved HTML elements as component ' + 'id: ' + key);
  2007. continue;
  2008. }
  2009. def = components[key];
  2010. if (isPlainObject(def)) {
  2011. components[key] = Vue.extend(def);
  2012. }
  2013. }
  2014. }
  2015. }
  2016. /**
  2017. * Ensure all props option syntax are normalized into the
  2018. * Object-based format.
  2019. *
  2020. * @param {Object} options
  2021. */
  2022. function guardProps(options) {
  2023. var props = options.props;
  2024. if (!props) return;
  2025. var res = {};
  2026. var i = void 0,
  2027. val = void 0,
  2028. name = void 0;
  2029. if (isArray(props)) {
  2030. i = props.length;
  2031. while (i--) {
  2032. val = props[i];
  2033. if (typeof val === 'string') {
  2034. name = camelize(val);
  2035. res[name] = { type: null };
  2036. } else if ("development" !== 'production') {
  2037. warn('props must be strings when using array syntax.');
  2038. }
  2039. }
  2040. } else if (isPlainObject(props)) {
  2041. for (var key in props) {
  2042. val = props[key];
  2043. name = camelize(key);
  2044. res[name] = isPlainObject(val) ? val : { type: val };
  2045. }
  2046. }
  2047. options.props = res;
  2048. }
  2049. function guardDirectives(options) {
  2050. var dirs = options.directives;
  2051. if (dirs) {
  2052. for (var key in dirs) {
  2053. if (typeof dirs[key] === 'function') {
  2054. dirs[key] = { update: dirs[key] };
  2055. }
  2056. }
  2057. }
  2058. }
  2059. /**
  2060. * Merge two option objects into a new one.
  2061. * Core utility used in both instantiation and inheritance.
  2062. *
  2063. * @param {Object} parent
  2064. * @param {Object} child
  2065. * @param {Vue} [vm] - if vm is present, indicates this is
  2066. * an instantiation merge.
  2067. */
  2068. function mergeOptions(parent, child, vm) {
  2069. guardComponents(child);
  2070. guardProps(child);
  2071. guardDirectives(child);
  2072. if ("development" !== 'production') {
  2073. if (child.propsData && !vm) {
  2074. warn('propsData can only be used as an instantiation option.');
  2075. }
  2076. }
  2077. var options = {};
  2078. var key;
  2079. if (child.mixins) {
  2080. for (var i = 0, l = child.mixins.length; i < l; i++) {
  2081. parent = mergeOptions(parent, child.mixins[i], vm);
  2082. }
  2083. }
  2084. for (key in parent) {
  2085. mergeField(key);
  2086. }
  2087. for (key in child) {
  2088. if (!hasOwn(parent, key)) {
  2089. mergeField(key);
  2090. }
  2091. }
  2092. function mergeField(key) {
  2093. var strat = strats[key] || defaultStrat;
  2094. options[key] = strat(parent[key], child[key], vm, key);
  2095. }
  2096. return options;
  2097. }
  2098. /**
  2099. * Resolve an asset.
  2100. * This function is used because child instances need access
  2101. * to assets defined in its ancestor chain.
  2102. *
  2103. * @param {Object} options
  2104. * @param {String} type
  2105. * @param {String} id
  2106. * @param {Boolean} warnMissing
  2107. * @return {Object|Function}
  2108. */
  2109. function resolveAsset(options, type, id, warnMissing) {
  2110. /* istanbul ignore if */
  2111. if (typeof id !== 'string') {
  2112. return;
  2113. }
  2114. var assets = options[type];
  2115. var camelizedId;
  2116. var res = assets[id] ||
  2117. // camelCase ID
  2118. assets[camelizedId = camelize(id)] ||
  2119. // Pascal Case ID
  2120. assets[camelizedId.charAt(0).toUpperCase() + camelizedId.slice(1)];
  2121. if ("development" !== 'production' && warnMissing && !res) {
  2122. warn('Failed to resolve ' + type.slice(0, -1) + ': ' + id, options);
  2123. }
  2124. return res;
  2125. }
  2126. function validateProp(vm, key, propsData) {
  2127. if (!propsData) return;
  2128. var prop = vm.$options.props[key];
  2129. var absent = hasOwn(propsData, key);
  2130. var value = propsData[key];
  2131. // check default value
  2132. if (value === undefined) {
  2133. value = getPropDefaultValue(vm, prop, key);
  2134. // since the default value is a fresh copy,
  2135. // make sure to observe it.
  2136. observerState.shouldConvert = true;
  2137. observe(value);
  2138. observerState.shouldConvert = false;
  2139. }
  2140. if ("development" !== 'production') {
  2141. assertProp(prop, key, value, vm, absent);
  2142. }
  2143. return value;
  2144. }
  2145. /**
  2146. * Get the default value of a prop.
  2147. *
  2148. * @param {Vue} vm
  2149. * @param {Object} prop
  2150. * @return {*}
  2151. */
  2152. function getPropDefaultValue(vm, prop, name) {
  2153. // no default, return undefined
  2154. if (!hasOwn(prop, 'default')) {
  2155. // absent boolean value defaults to false
  2156. return prop.type === Boolean ? false : undefined;
  2157. }
  2158. var def = prop.default;
  2159. // warn against non-factory defaults for Object & Array
  2160. if (isObject(def)) {
  2161. "development" !== 'production' && warn('Invalid default value for prop "' + name + '": ' + 'Props with type Object/Array must use a factory function ' + 'to return the default value.', vm);
  2162. }
  2163. // call factory function for non-Function types
  2164. return typeof def === 'function' && prop.type !== Function ? def.call(vm) : def;
  2165. }
  2166. /**
  2167. * Assert whether a prop is valid.
  2168. *
  2169. * @param {Object} prop
  2170. * @param {String} name
  2171. * @param {*} value
  2172. * @param {Vue} vm
  2173. * @param {Boolean} absent
  2174. */
  2175. function assertProp(prop, name, value, vm, absent) {
  2176. if (prop.required && absent) {
  2177. "development" !== 'production' && warn('Missing required prop: "' + name + '"', vm);
  2178. return false;
  2179. }
  2180. if (value == null) {
  2181. return true;
  2182. }
  2183. var type = prop.type;
  2184. var valid = !type;
  2185. var expectedTypes = [];
  2186. if (type) {
  2187. if (!isArray(type)) {
  2188. type = [type];
  2189. }
  2190. for (var i = 0; i < type.length && !valid; i++) {
  2191. var assertedType = assertType(value, type[i]);
  2192. expectedTypes.push(assertedType.expectedType);
  2193. valid = assertedType.valid;
  2194. }
  2195. }
  2196. if (!valid) {
  2197. if ("development" !== 'production') {
  2198. warn('Invalid prop: type check failed for prop "' + name + '".' + ' Expected ' + expectedTypes.map(formatType).join(', ') + ', got ' + formatValue(value) + '.', vm);
  2199. }
  2200. return false;
  2201. }
  2202. var validator = prop.validator;
  2203. if (validator) {
  2204. if (!validator(value)) {
  2205. "development" !== 'production' && warn('Invalid prop: custom validator check failed for prop "' + name + '".', vm);
  2206. return false;
  2207. }
  2208. }
  2209. return true;
  2210. }
  2211. /**
  2212. * Assert the type of a value
  2213. *
  2214. * @param {*} value
  2215. * @param {Function} type
  2216. * @return {Object}
  2217. */
  2218. function assertType(value, type) {
  2219. var valid;
  2220. var expectedType;
  2221. if (type === String) {
  2222. expectedType = 'string';
  2223. valid = typeof value === expectedType;
  2224. } else if (type === Number) {
  2225. expectedType = 'number';
  2226. valid = typeof value === expectedType;
  2227. } else if (type === Boolean) {
  2228. expectedType = 'boolean';
  2229. valid = typeof value === expectedType;
  2230. } else if (type === Function) {
  2231. expectedType = 'function';
  2232. valid = typeof value === expectedType;
  2233. } else if (type === Object) {
  2234. expectedType = 'object';
  2235. valid = isPlainObject(value);
  2236. } else if (type === Array) {
  2237. expectedType = 'array';
  2238. valid = isArray(value);
  2239. } else {
  2240. valid = value instanceof type;
  2241. }
  2242. return {
  2243. valid: valid,
  2244. expectedType: expectedType
  2245. };
  2246. }
  2247. /**
  2248. * Format type for output
  2249. *
  2250. * @param {String} type
  2251. * @return {String}
  2252. */
  2253. function formatType(type) {
  2254. return type ? type.charAt(0).toUpperCase() + type.slice(1) : 'custom type';
  2255. }
  2256. /**
  2257. * Format value
  2258. *
  2259. * @param {*} value
  2260. * @return {String}
  2261. */
  2262. function formatValue(val) {
  2263. return Object.prototype.toString.call(val).slice(8, -1);
  2264. }
  2265. var util = Object.freeze({
  2266. defineReactive: defineReactive,
  2267. renderString: renderString,
  2268. makeMap: makeMap,
  2269. isBuiltInTag: isBuiltInTag,
  2270. remove: remove,
  2271. hasOwn: hasOwn,
  2272. isPrimitive: isPrimitive,
  2273. cached: cached,
  2274. camelize: camelize,
  2275. hyphenate: hyphenate,
  2276. bind: bind,
  2277. toArray: toArray,
  2278. extend: extend,
  2279. isObject: isObject,
  2280. isPlainObject: isPlainObject,
  2281. isArray: isArray,
  2282. isReserved: isReserved,
  2283. def: def,
  2284. parsePath: parsePath,
  2285. hasProto: hasProto,
  2286. inBrowser: inBrowser,
  2287. devtools: devtools,
  2288. nextTick: nextTick,
  2289. get _Set () { return _Set; },
  2290. mergeOptions: mergeOptions,
  2291. resolveAsset: resolveAsset,
  2292. get warn () { return warn; },
  2293. validateProp: validateProp
  2294. });
  2295. // attributes that should be using props for binding
  2296. var mustUseProp = makeMap('value,selected,checked,muted');
  2297. var isEnumeratedAttr = makeMap('contenteditable,draggable,spellcheck');
  2298. var isBooleanAttr = makeMap('allowfullscreen,async,autofocus,autoplay,checked,compact,controls,declare,' + 'default,defaultchecked,defaultmuted,defaultselected,defer,disabled,' + 'enabled,formnovalidate,hidden,indeterminate,inert,ismap,itemscope,loop,multiple,' + 'muted,nohref,noresize,noshade,novalidate,nowrap,open,pauseonexit,readonly,' + 'required,reversed,scoped,seamless,selected,sortable,translate,' + 'truespeed,typemustmatch,visible');
  2299. var xlinkNS = 'http://www.w3.org/1999/xlink';
  2300. var isXlink = function isXlink(name) {
  2301. return name.charAt(5) === ':' && name.slice(0, 5) === 'xlink';
  2302. };
  2303. function genClassForVnode(vnode) {
  2304. var data = vnode.data;
  2305. // Important: check if this is a component container node
  2306. // or a child component root node
  2307. var i = void 0;
  2308. if ((i = vnode.child) && (i = i._vnode.data)) {
  2309. data = mergeClassData(i, data);
  2310. }
  2311. if ((i = vnode.parent) && (i = i.data)) {
  2312. data = mergeClassData(data, i);
  2313. }
  2314. return genClassFromData(data);
  2315. }
  2316. function mergeClassData(child, parent) {
  2317. return {
  2318. staticClass: concat(child.staticClass, parent.staticClass),
  2319. class: child.class ? extend(child.class, parent.class) : parent.class
  2320. };
  2321. }
  2322. function genClassFromData(data) {
  2323. var dynamicClass = data.class;
  2324. var staticClass = data.staticClass;
  2325. if (staticClass || dynamicClass) {
  2326. return concat(staticClass, stringifyClass(dynamicClass));
  2327. }
  2328. }
  2329. function concat(a, b) {
  2330. return a ? b ? a + ' ' + b : a : b || '';
  2331. }
  2332. function stringifyClass(value) {
  2333. if (!value) {
  2334. return '';
  2335. }
  2336. if (typeof value === 'string') {
  2337. return value;
  2338. }
  2339. if (isArray(value)) {
  2340. var res = '';
  2341. for (var i = 0, l = value.length; i < l; i++) {
  2342. if (value[i]) res += stringifyClass(value[i]) + ' ';
  2343. }
  2344. return res.slice(0, -1);
  2345. }
  2346. if (isObject(value)) {
  2347. var _res = '';
  2348. for (var key in value) {
  2349. if (value[key]) _res += key + ' ';
  2350. }
  2351. return _res.slice(0, -1);
  2352. }
  2353. }
  2354. var namespaceMap = {
  2355. svg: 'http://www.w3.org/2000/svg',
  2356. math: 'http://www.w3.org/1998/Math/MathML'
  2357. };
  2358. var isReservedTag = makeMap('html,base,head,link,meta,style,title,' + 'address,article,footer,header,h1,h2,h3,h4,h5,h6,hgroup,nav,section,' + 'div,dd,dl,dt,figcaption,figure,hr,li,main,ol,p,pre,ul,' + 'a,b,abbr,bdi,bdo,br,cite,code,data,dfn,em,i,kbd,mark,q,rp,rt,rtc,ruby,' + 's,samp,small,span,strong,sub,sup,time,u,var,wbr,area,audio,map,track,video,' + 'embed,object,param,source,canvas,script,noscript,del,ins,' + 'caption,col,colgroup,table,thead,tbody,td,th,tr,' + 'button,datalist,fieldset,form,input,label,legend,meter,optgroup,option,' + 'output,progress,select,textarea,' + 'details,dialog,menu,menuitem,summary,' + 'content,element,shadow,template');
  2359. var isUnaryTag = makeMap('area,base,br,col,embed,frame,hr,img,input,isindex,keygen,' + 'link,meta,param,source,track,wbr', true);
  2360. // Elements that you can, intentionally, leave open
  2361. // (and which close themselves)
  2362. var canBeLeftOpenTag = makeMap('colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr,source', true);
  2363. // HTML5 tags https://html.spec.whatwg.org/multipage/indices.html#elements-3
  2364. // Phrasing Content https://html.spec.whatwg.org/multipage/dom.html#phrasing-content
  2365. var isNonPhrasingTag = makeMap('address,article,aside,base,blockquote,body,caption,col,colgroup,dd,' + 'details,dialog,div,dl,dt,fieldset,figcaption,figure,footer,form,' + 'h1,h2,h3,h4,h5,h6,head,header,hgroup,hr,html,legend,li,menuitem,meta,' + 'optgroup,option,param,rp,rt,source,style,summary,tbody,td,tfoot,th,thead,' + 'title,tr,track', true);
  2366. // this map covers namespace elements that can appear as template root nodes
  2367. var isSVG = makeMap('svg,g,defs,symbol,use,image,text,circle,ellipse,' + 'line,path,polygon,polyline,rect', true);
  2368. function getTagNamespace(tag) {
  2369. if (isSVG(tag)) {
  2370. return 'svg';
  2371. }
  2372. // basic support for MathML
  2373. // note it doesn't support other MathML elements being component roots
  2374. if (tag === 'math') {
  2375. return 'math';
  2376. }
  2377. }
  2378. var unknownElementCache = Object.create(null);
  2379. function isUnknownElement(tag) {
  2380. if (!inBrowser) {
  2381. return true;
  2382. }
  2383. tag = tag.toLowerCase();
  2384. if (unknownElementCache[tag] != null) {
  2385. return unknownElementCache[tag];
  2386. }
  2387. var el = document.createElement(tag);
  2388. if (tag.indexOf('-') > -1) {
  2389. // http://stackoverflow.com/a/28210364/1070244
  2390. return unknownElementCache[tag] = el.constructor === window.HTMLUnknownElement || el.constructor === window.HTMLElement;
  2391. } else {
  2392. return unknownElementCache[tag] = /HTMLUnknownElement/.test(el.toString()) &&
  2393. // Chrome returns unknown for several HTML5 elements.
  2394. // https://code.google.com/p/chromium/issues/detail?id=540526
  2395. !/^(data|time|rtc|rb)$/.test(tag);
  2396. }
  2397. }
  2398. var UA$1 = inBrowser && window.navigator.userAgent.toLowerCase();
  2399. var isIE9 = UA$1 && UA$1.indexOf('msie 9.0') > 0;
  2400. var isAndroid = UA$1 && UA$1.indexOf('android') > 0;
  2401. /**
  2402. * Query an element selector if it's not an element already.
  2403. *
  2404. * @param {String|Element} el
  2405. * @return {Element}
  2406. */
  2407. function query(el) {
  2408. if (typeof el === 'string') {
  2409. var selector = el;
  2410. el = document.querySelector(el);
  2411. if (!el) {
  2412. "development" !== 'production' && warn('Cannot find element: ' + selector);
  2413. }
  2414. }
  2415. return el;
  2416. }
  2417. function initUse(Vue) {
  2418. /**
  2419. * Plugin system
  2420. *
  2421. * @param {Object} plugin
  2422. */
  2423. Vue.use = function (plugin) {
  2424. /* istanbul ignore if */
  2425. if (plugin.installed) {
  2426. return;
  2427. }
  2428. // additional parameters
  2429. var args = toArray(arguments, 1);
  2430. args.unshift(this);
  2431. if (typeof plugin.install === 'function') {
  2432. plugin.install.apply(plugin, args);
  2433. } else {
  2434. plugin.apply(null, args);
  2435. }
  2436. plugin.installed = true;
  2437. return this;
  2438. };
  2439. }
  2440. function initMixin(Vue) {
  2441. Vue.mixin = function (mixin) {
  2442. Vue.options = mergeOptions(Vue.options, mixin);
  2443. };
  2444. }
  2445. function initExtend(Vue) {
  2446. /**
  2447. * Each instance constructor, including Vue, has a unique
  2448. * cid. This enables us to create wrapped "child
  2449. * constructors" for prototypal inheritance and cache them.
  2450. */
  2451. Vue.cid = 0;
  2452. var cid = 1;
  2453. /**
  2454. * Class inheritance
  2455. *
  2456. * @param {Object} extendOptions
  2457. */
  2458. Vue.extend = function (extendOptions) {
  2459. extendOptions = extendOptions || {};
  2460. var Super = this;
  2461. var isFirstExtend = Super.cid === 0;
  2462. if (isFirstExtend && extendOptions._Ctor) {
  2463. return extendOptions._Ctor;
  2464. }
  2465. var name = extendOptions.name || Super.options.name;
  2466. if ("development" !== 'production') {
  2467. if (!/^[a-zA-Z][\w-]*$/.test(name)) {
  2468. warn('Invalid component name: "' + name + '". Component names ' + 'can only contain alphanumeric characaters and the hyphen.');
  2469. name = null;
  2470. }
  2471. }
  2472. var Sub = function VueComponent(options) {
  2473. this._init(options);
  2474. };
  2475. Sub.prototype = Object.create(Super.prototype);
  2476. Sub.prototype.constructor = Sub;
  2477. Sub.cid = cid++;
  2478. Sub.options = mergeOptions(Super.options, extendOptions);
  2479. Sub['super'] = Super;
  2480. // allow further extension
  2481. Sub.extend = Super.extend;
  2482. // create asset registers, so extended classes
  2483. // can have their private assets too.
  2484. config._assetTypes.forEach(function (type) {
  2485. Sub[type] = Super[type];
  2486. });
  2487. // enable recursive self-lookup
  2488. if (name) {
  2489. Sub.options.components[name] = Sub;
  2490. }
  2491. // cache constructor
  2492. if (isFirstExtend) {
  2493. extendOptions._Ctor = Sub;
  2494. }
  2495. return Sub;
  2496. };
  2497. }
  2498. function initAssetRegisters(Vue) {
  2499. /**
  2500. * Create asset registration methods with the following
  2501. * signature:
  2502. *
  2503. * @param {String} id
  2504. * @param {*} definition
  2505. */
  2506. config._assetTypes.forEach(function (type) {
  2507. Vue[type] = function (id, definition) {
  2508. if (!definition) {
  2509. return this.options[type + 's'][id];
  2510. } else {
  2511. /* istanbul ignore if */
  2512. if ("development" !== 'production') {
  2513. if (type === 'component' && config.isReservedTag(id)) {
  2514. warn('Do not use built-in or reserved HTML elements as component ' + 'id: ' + id);
  2515. }
  2516. }
  2517. if (type === 'component' && isPlainObject(definition)) {
  2518. definition.name = id;
  2519. definition = Vue.extend(definition);
  2520. }
  2521. this.options[type + 's'][id] = definition;
  2522. return definition;
  2523. }
  2524. };
  2525. });
  2526. }
  2527. function initGlobalAPI(Vue) {
  2528. Vue.config = config;
  2529. Vue.util = util;
  2530. Vue.set = set;
  2531. Vue.delete = del;
  2532. Vue.nextTick = nextTick;
  2533. Vue.options = {
  2534. directives: Object.create(null),
  2535. filters: Object.create(null),
  2536. components: Object.create(null),
  2537. transitions: Object.create(null)
  2538. };
  2539. initUse(Vue);
  2540. initMixin(Vue);
  2541. initExtend(Vue);
  2542. initAssetRegisters(Vue);
  2543. }
  2544. initGlobalAPI(Vue);
  2545. Vue.version = '2.0.0-alpha.0';
  2546. var emptyNode = VNode('', {}, []);
  2547. var hooks$1 = ['create', 'update', 'remove', 'destroy'];
  2548. function isUndef(s) {
  2549. return s === undefined;
  2550. }
  2551. function isDef(s) {
  2552. return s !== undefined;
  2553. }
  2554. function sameVnode(vnode1, vnode2) {
  2555. return vnode1.key === vnode2.key && vnode1.tag === vnode2.tag;
  2556. }
  2557. function createKeyToOldIdx(children, beginIdx, endIdx) {
  2558. var i = void 0,
  2559. key = void 0;
  2560. var map = {};
  2561. for (i = beginIdx; i <= endIdx; ++i) {
  2562. key = children[i].key;
  2563. if (isDef(key)) map[key] = i;
  2564. }
  2565. return map;
  2566. }
  2567. function createPatchFunction(backend) {
  2568. var i = void 0,
  2569. j = void 0;
  2570. var cbs = {};
  2571. var modules = backend.modules;
  2572. var nodeOps = backend.nodeOps;
  2573. for (i = 0; i < hooks$1.length; ++i) {
  2574. cbs[hooks$1[i]] = [];
  2575. for (j = 0; j < modules.length; ++j) {
  2576. if (modules[j][hooks$1[i]] !== undefined) cbs[hooks$1[i]].push(modules[j][hooks$1[i]]);
  2577. }
  2578. }
  2579. function emptyNodeAt(elm) {
  2580. return VNode(nodeOps.tagName(elm).toLowerCase(), {}, [], undefined, elm);
  2581. }
  2582. function createRmCb(childElm, listeners) {
  2583. function remove() {
  2584. if (--remove.listeners === 0) {
  2585. removeElement(childElm);
  2586. }
  2587. }
  2588. remove.listeners = listeners;
  2589. return remove;
  2590. }
  2591. function removeElement(el) {
  2592. var parent = nodeOps.parentNode(el);
  2593. nodeOps.removeChild(parent, el);
  2594. }
  2595. function createElm(vnode, insertedVnodeQueue) {
  2596. var i = void 0,
  2597. elm = void 0;
  2598. var data = vnode.data;
  2599. if (isDef(data)) {
  2600. if (isDef(i = data.hook) && isDef(i = i.init)) i(vnode);
  2601. // after calling the init hook, if the vnode is a child component
  2602. // it should've created a child instance and mounted it. the child
  2603. // component also has set the placeholder vnode's elm.
  2604. // in that case we can just return the element and be done.
  2605. if (isDef(i = vnode.child)) {
  2606. invokeCreateHooks(vnode, insertedVnodeQueue);
  2607. return vnode.elm;
  2608. }
  2609. }
  2610. var children = vnode.children;
  2611. var tag = vnode.tag;
  2612. if (isDef(tag)) {
  2613. elm = vnode.elm = vnode.ns ? nodeOps.createElementNS(vnode.ns, tag) : nodeOps.createElement(tag);
  2614. if (Array.isArray(children)) {
  2615. for (i = 0; i < children.length; ++i) {
  2616. nodeOps.appendChild(elm, createElm(children[i], insertedVnodeQueue));
  2617. }
  2618. } else if (isPrimitive(vnode.text)) {
  2619. nodeOps.appendChild(elm, nodeOps.createTextNode(vnode.text));
  2620. }
  2621. if (isDef(data)) {
  2622. invokeCreateHooks(vnode, insertedVnodeQueue);
  2623. }
  2624. } else {
  2625. elm = vnode.elm = nodeOps.createTextNode(vnode.text);
  2626. }
  2627. return vnode.elm;
  2628. }
  2629. function invokeCreateHooks(vnode, insertedVnodeQueue) {
  2630. for (var _i = 0; _i < cbs.create.length; ++_i) {
  2631. cbs.create[_i](emptyNode, vnode);
  2632. }
  2633. i = vnode.data.hook; // Reuse variable
  2634. if (isDef(i)) {
  2635. if (i.create) i.create(emptyNode, vnode);
  2636. if (i.insert) insertedVnodeQueue.push(vnode);
  2637. }
  2638. }
  2639. function addVnodes(parentElm, before, vnodes, startIdx, endIdx, insertedVnodeQueue) {
  2640. for (; startIdx <= endIdx; ++startIdx) {
  2641. nodeOps.insertBefore(parentElm, createElm(vnodes[startIdx], insertedVnodeQueue), before);
  2642. }
  2643. }
  2644. function invokeDestroyHook(vnode) {
  2645. var i = void 0,
  2646. j = void 0;
  2647. var data = vnode.data;
  2648. if (isDef(data)) {
  2649. if (isDef(i = data.hook) && isDef(i = i.destroy)) i(vnode);
  2650. for (i = 0; i < cbs.destroy.length; ++i) {
  2651. cbs.destroy[i](vnode);
  2652. }if (isDef(i = vnode.children)) {
  2653. for (j = 0; j < vnode.children.length; ++j) {
  2654. invokeDestroyHook(vnode.children[j]);
  2655. }
  2656. }
  2657. if (isDef(i = vnode.child)) {
  2658. invokeDestroyHook(i._vnode);
  2659. }
  2660. }
  2661. }
  2662. function removeVnodes(parentElm, vnodes, startIdx, endIdx) {
  2663. for (; startIdx <= endIdx; ++startIdx) {
  2664. var ch = vnodes[startIdx];
  2665. if (isDef(ch)) {
  2666. if (isDef(ch.tag)) {
  2667. invokeDestroyHook(ch);
  2668. removeAndInvokeRemoveHook(ch);
  2669. } else {
  2670. // Text node
  2671. nodeOps.removeChild(parentElm, ch.elm);
  2672. }
  2673. }
  2674. }
  2675. }
  2676. function removeAndInvokeRemoveHook(vnode, rm) {
  2677. if (rm || isDef(vnode.data)) {
  2678. var listeners = cbs.remove.length + 1;
  2679. if (!rm) {
  2680. // directly removing
  2681. rm = createRmCb(vnode.elm, listeners);
  2682. } else {
  2683. // we have a recursively passed down rm callback
  2684. // increase the listeners count
  2685. rm.listeners += listeners;
  2686. }
  2687. // recursively invoke hooks on child component root node
  2688. if (isDef(i = vnode.child) && isDef(i = i._vnode) && isDef(i.data)) {
  2689. removeAndInvokeRemoveHook(i, rm);
  2690. }
  2691. for (i = 0; i < cbs.remove.length; ++i) {
  2692. cbs.remove[i](vnode, rm);
  2693. }
  2694. if (isDef(i = vnode.data.hook) && isDef(i = i.remove)) {
  2695. i(vnode, rm);
  2696. } else {
  2697. rm();
  2698. }
  2699. } else {
  2700. removeElement(vnode.elm);
  2701. }
  2702. }
  2703. function updateChildren(parentElm, oldCh, newCh, insertedVnodeQueue) {
  2704. var oldStartIdx = 0;
  2705. var newStartIdx = 0;
  2706. var oldEndIdx = oldCh.length - 1;
  2707. var oldStartVnode = oldCh[0];
  2708. var oldEndVnode = oldCh[oldEndIdx];
  2709. var newEndIdx = newCh.length - 1;
  2710. var newStartVnode = newCh[0];
  2711. var newEndVnode = newCh[newEndIdx];
  2712. var oldKeyToIdx = void 0,
  2713. idxInOld = void 0,
  2714. elmToMove = void 0,
  2715. before = void 0;
  2716. while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
  2717. if (isUndef(oldStartVnode)) {
  2718. oldStartVnode = oldCh[++oldStartIdx]; // Vnode has been moved left
  2719. } else if (isUndef(oldEndVnode)) {
  2720. oldEndVnode = oldCh[--oldEndIdx];
  2721. } else if (sameVnode(oldStartVnode, newStartVnode)) {
  2722. patchVnode(oldStartVnode, newStartVnode, insertedVnodeQueue);
  2723. oldStartVnode = oldCh[++oldStartIdx];
  2724. newStartVnode = newCh[++newStartIdx];
  2725. } else if (sameVnode(oldEndVnode, newEndVnode)) {
  2726. patchVnode(oldEndVnode, newEndVnode, insertedVnodeQueue);
  2727. oldEndVnode = oldCh[--oldEndIdx];
  2728. newEndVnode = newCh[--newEndIdx];
  2729. } else if (sameVnode(oldStartVnode, newEndVnode)) {
  2730. // Vnode moved right
  2731. patchVnode(oldStartVnode, newEndVnode, insertedVnodeQueue);
  2732. nodeOps.insertBefore(parentElm, oldStartVnode.elm, nodeOps.nextSibling(oldEndVnode.elm));
  2733. oldStartVnode = oldCh[++oldStartIdx];
  2734. newEndVnode = newCh[--newEndIdx];
  2735. } else if (sameVnode(oldEndVnode, newStartVnode)) {
  2736. // Vnode moved left
  2737. patchVnode(oldEndVnode, newStartVnode, insertedVnodeQueue);
  2738. nodeOps.insertBefore(parentElm, oldEndVnode.elm, oldStartVnode.elm);
  2739. oldEndVnode = oldCh[--oldEndIdx];
  2740. newStartVnode = newCh[++newStartIdx];
  2741. } else {
  2742. if (isUndef(oldKeyToIdx)) oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx);
  2743. idxInOld = oldKeyToIdx[newStartVnode.key];
  2744. if (isUndef(idxInOld)) {
  2745. // New element
  2746. nodeOps.insertBefore(parentElm, createElm(newStartVnode, insertedVnodeQueue), oldStartVnode.elm);
  2747. newStartVnode = newCh[++newStartIdx];
  2748. } else {
  2749. elmToMove = oldCh[idxInOld];
  2750. if ("development" !== 'production' && !elmToMove) {
  2751. warn('Duplicate track-by key: ' + idxInOld + '. ' + 'Make sure each v-for item has a unique track-by key.');
  2752. }
  2753. patchVnode(elmToMove, newStartVnode, insertedVnodeQueue);
  2754. oldCh[idxInOld] = undefined;
  2755. nodeOps.insertBefore(parentElm, elmToMove.elm, oldStartVnode.elm);
  2756. newStartVnode = newCh[++newStartIdx];
  2757. }
  2758. }
  2759. }
  2760. if (oldStartIdx > oldEndIdx) {
  2761. before = isUndef(newCh[newEndIdx + 1]) ? null : newCh[newEndIdx + 1].elm;
  2762. addVnodes(parentElm, before, newCh, newStartIdx, newEndIdx, insertedVnodeQueue);
  2763. } else if (newStartIdx > newEndIdx) {
  2764. removeVnodes(parentElm, oldCh, oldStartIdx, oldEndIdx);
  2765. }
  2766. }
  2767. function patchVnode(oldVnode, vnode, insertedVnodeQueue) {
  2768. var i = void 0,
  2769. hook = void 0;
  2770. if (isDef(i = vnode.data) && isDef(hook = i.hook) && isDef(i = hook.prepatch)) {
  2771. i(oldVnode, vnode);
  2772. }
  2773. // skip nodes with v-pre
  2774. if (isDef(i = vnode.data) && i.pre) {
  2775. return;
  2776. }
  2777. var elm = vnode.elm = oldVnode.elm;
  2778. var oldCh = oldVnode.children;
  2779. var ch = vnode.children;
  2780. if (oldVnode === vnode) return;
  2781. if (!sameVnode(oldVnode, vnode)) {
  2782. var parentElm = nodeOps.parentNode(oldVnode.elm);
  2783. elm = createElm(vnode, insertedVnodeQueue);
  2784. nodeOps.insertBefore(parentElm, elm, oldVnode.elm);
  2785. removeVnodes(parentElm, [oldVnode], 0, 0);
  2786. return;
  2787. }
  2788. if (isDef(vnode.data)) {
  2789. for (i = 0; i < cbs.update.length; ++i) {
  2790. cbs.update[i](oldVnode, vnode);
  2791. }i = vnode.data.hook;
  2792. if (isDef(i) && isDef(i = i.update)) i(oldVnode, vnode);
  2793. }
  2794. if (isUndef(vnode.text)) {
  2795. if (isDef(oldCh) && isDef(ch)) {
  2796. if (oldCh !== ch) updateChildren(elm, oldCh, ch, insertedVnodeQueue);
  2797. } else if (isDef(ch)) {
  2798. if (isDef(oldVnode.text)) nodeOps.setTextContent(elm, '');
  2799. addVnodes(elm, null, ch, 0, ch.length - 1, insertedVnodeQueue);
  2800. } else if (isDef(oldCh)) {
  2801. removeVnodes(elm, oldCh, 0, oldCh.length - 1);
  2802. } else if (isDef(oldVnode.text)) {
  2803. nodeOps.setTextContent(elm, '');
  2804. }
  2805. } else if (oldVnode.text !== vnode.text) {
  2806. nodeOps.setTextContent(elm, vnode.text);
  2807. }
  2808. if (isDef(hook) && isDef(i = hook.postpatch)) {
  2809. i(oldVnode, vnode);
  2810. }
  2811. }
  2812. function invokeInsertHook(queue) {
  2813. for (i = 0; i < queue.length; ++i) {
  2814. queue[i].data.hook.insert(queue[i]);
  2815. }
  2816. }
  2817. function hydrate(elm, vnode, insertedVnodeQueue) {
  2818. if ("development" !== 'production') {
  2819. if (!assertNodeMatch(elm, vnode)) {
  2820. return false;
  2821. }
  2822. }
  2823. vnode.elm = elm;
  2824. var tag = vnode.tag;
  2825. var data = vnode.data;
  2826. var children = vnode.children;
  2827. if (isDef(data)) {
  2828. if (isDef(i = data.hook) && isDef(i = i.init)) i(vnode);
  2829. if (isDef(i = vnode.child)) {
  2830. // child component. it should have hydrated its own tree.
  2831. invokeCreateHooks(vnode, insertedVnodeQueue);
  2832. return true;
  2833. }
  2834. }
  2835. if (isDef(tag)) {
  2836. if (isDef(children)) {
  2837. var childNodes = elm.childNodes;
  2838. for (var _i2 = 0; _i2 < children.length; _i2++) {
  2839. var success = hydrate(childNodes[_i2], children[_i2], insertedVnodeQueue);
  2840. if (!success) {
  2841. return false;
  2842. }
  2843. }
  2844. }
  2845. if (isDef(data)) {
  2846. invokeCreateHooks(vnode, insertedVnodeQueue);
  2847. }
  2848. }
  2849. return true;
  2850. }
  2851. function assertNodeMatch(node, vnode) {
  2852. if (vnode.tag) {
  2853. if (vnode.tag.indexOf('vue-component') === 0) {
  2854. return true;
  2855. } else {
  2856. return vnode.tag === node.tagName.toLowerCase() && (vnode.children ? vnode.children.length === node.childNodes.length : node.childNodes.length === 0);
  2857. }
  2858. } else {
  2859. return renderString(vnode.text) === node.data;
  2860. }
  2861. }
  2862. return function patch(oldVnode, vnode) {
  2863. var elm, parent;
  2864. var insertedVnodeQueue = [];
  2865. if (!oldVnode) {
  2866. // empty mount, create new root element
  2867. createElm(vnode, insertedVnodeQueue);
  2868. } else {
  2869. if (sameVnode(oldVnode, vnode)) {
  2870. patchVnode(oldVnode, vnode, insertedVnodeQueue);
  2871. } else {
  2872. if (isUndef(oldVnode.tag)) {
  2873. // mounting to a real element
  2874. // check if this is server-rendered content and if we can perform
  2875. // a successful hydration.
  2876. if (oldVnode.hasAttribute('server-rendered')) {
  2877. oldVnode.removeAttribute('server-rendered');
  2878. if (hydrate(oldVnode, vnode, insertedVnodeQueue)) {
  2879. invokeInsertHook(insertedVnodeQueue);
  2880. return oldVnode;
  2881. } else if ("development" !== 'production') {
  2882. warn('The client-side rendered virtual DOM tree is not matching ' + 'server-rendered content. Bailing hydration and performing ' + 'full client-side render.');
  2883. }
  2884. }
  2885. // either not server-rendered, or hydration failed.
  2886. // create an empty node and replace it
  2887. oldVnode = emptyNodeAt(oldVnode);
  2888. }
  2889. elm = oldVnode.elm;
  2890. parent = nodeOps.parentNode(elm);
  2891. createElm(vnode, insertedVnodeQueue);
  2892. if (parent !== null) {
  2893. nodeOps.insertBefore(parent, vnode.elm, nodeOps.nextSibling(elm));
  2894. removeVnodes(parent, [oldVnode], 0, 0);
  2895. }
  2896. }
  2897. }
  2898. invokeInsertHook(insertedVnodeQueue);
  2899. return vnode.elm;
  2900. };
  2901. }
  2902. function createElement$1(tagName) {
  2903. return document.createElement(tagName);
  2904. }
  2905. function createElementNS(namespace, tagName) {
  2906. return document.createElementNS(namespaceMap[namespace], tagName);
  2907. }
  2908. function createTextNode(text) {
  2909. return document.createTextNode(text);
  2910. }
  2911. function insertBefore(parentNode, newNode, referenceNode) {
  2912. parentNode.insertBefore(newNode, referenceNode);
  2913. }
  2914. function removeChild(node, child) {
  2915. node.removeChild(child);
  2916. }
  2917. function appendChild(node, child) {
  2918. node.appendChild(child);
  2919. }
  2920. function parentNode(node) {
  2921. return node.parentElement;
  2922. }
  2923. function nextSibling(node) {
  2924. return node.nextSibling;
  2925. }
  2926. function tagName(node) {
  2927. return node.tagName;
  2928. }
  2929. function setTextContent(node, text) {
  2930. node.textContent = text;
  2931. }
  2932. var nodeOps = Object.freeze({
  2933. createElement: createElement$1,
  2934. createElementNS: createElementNS,
  2935. createTextNode: createTextNode,
  2936. insertBefore: insertBefore,
  2937. removeChild: removeChild,
  2938. appendChild: appendChild,
  2939. parentNode: parentNode,
  2940. nextSibling: nextSibling,
  2941. tagName: tagName,
  2942. setTextContent: setTextContent
  2943. });
  2944. if (isIE9) {
  2945. // http://www.matts411.com/post/internet-explorer-9-oninput/
  2946. document.addEventListener('selectionchange', function () {
  2947. var el = document.activeElement;
  2948. if (el && el.vmodel) {
  2949. trigger(el);
  2950. }
  2951. });
  2952. }
  2953. var model = {
  2954. bind: function bind(el) {
  2955. if (!isAndroid) {
  2956. el.addEventListener('compositionstart', onCompositionStart);
  2957. el.addEventListener('compositionend', onCompositionEnd);
  2958. }
  2959. if (isIE9) {
  2960. el.vmodel = true;
  2961. }
  2962. },
  2963. unbind: function unbind(el) {
  2964. if (!isAndroid) {
  2965. el.removeEventListener('compositionstart', onCompositionStart);
  2966. el.removeEventListener('compositionend', onCompositionEnd);
  2967. }
  2968. }
  2969. };
  2970. function onCompositionStart(e) {
  2971. e.target.composing = true;
  2972. }
  2973. function onCompositionEnd(e) {
  2974. e.target.composing = false;
  2975. trigger(e.target);
  2976. }
  2977. function trigger(el) {
  2978. var e = document.createEvent('HTMLEvents');
  2979. e.initEvent('input', true, true);
  2980. el.dispatchEvent(e);
  2981. }
  2982. var svgNS = namespaceMap.svg;
  2983. /**
  2984. * In IE9, setAttribute('class') will result in empty class
  2985. * if the element also has the :class attribute; However in
  2986. * PhantomJS, setting `className` does not work on SVG elements...
  2987. * So we have to do a conditional check here.
  2988. *
  2989. * @param {Element} el
  2990. * @param {String} cls
  2991. */
  2992. function setClass(el, cls) {
  2993. /* istanbul ignore else */
  2994. if (!isIE9 || el.namespaceURI === svgNS) {
  2995. el.setAttribute('class', cls);
  2996. } else {
  2997. el.className = cls;
  2998. }
  2999. }
  3000. /**
  3001. * Add class with compatibility for IE & SVG
  3002. *
  3003. * @param {Element} el
  3004. * @param {String} cls
  3005. */
  3006. function addClass(el, cls) {
  3007. if (el.classList) {
  3008. if (cls.indexOf(' ') > -1) {
  3009. cls.split(/\s+/).forEach(function (c) {
  3010. return el.classList.add(c);
  3011. });
  3012. } else {
  3013. el.classList.add(cls);
  3014. }
  3015. } else {
  3016. var cur = ' ' + getClass(el) + ' ';
  3017. if (cur.indexOf(' ' + cls + ' ') < 0) {
  3018. setClass(el, (cur + cls).trim());
  3019. }
  3020. }
  3021. }
  3022. /**
  3023. * Remove class with compatibility for IE & SVG
  3024. *
  3025. * @param {Element} el
  3026. * @param {String} cls
  3027. */
  3028. function removeClass(el, cls) {
  3029. if (el.classList) {
  3030. if (cls.indexOf(' ') > -1) {
  3031. cls.split(/\s+/).forEach(function (c) {
  3032. return el.classList.remove(c);
  3033. });
  3034. } else {
  3035. el.classList.remove(cls);
  3036. }
  3037. } else {
  3038. var cur = ' ' + getClass(el) + ' ';
  3039. var tar = ' ' + cls + ' ';
  3040. while (cur.indexOf(tar) >= 0) {
  3041. cur = cur.replace(tar, ' ');
  3042. }
  3043. setClass(el, cur.trim());
  3044. }
  3045. if (!el.className) {
  3046. el.removeAttribute('class');
  3047. }
  3048. }
  3049. /**
  3050. * For IE9 compat: when both class and :class are present
  3051. * getAttribute('class') returns wrong value... but className
  3052. * on SVG elements returns an object.
  3053. *
  3054. * @param {Element} el
  3055. * @return {String}
  3056. */
  3057. function getClass(el) {
  3058. var classname = el.className;
  3059. if (typeof classname === 'object') {
  3060. classname = classname.baseVal || '';
  3061. }
  3062. return classname;
  3063. }
  3064. var TRANSITION = 'transition';
  3065. var ANIMATION = 'animation';
  3066. // Transition property/event sniffing
  3067. var transitionProp = void 0;
  3068. var transitionEndEvent = void 0;
  3069. var animationProp = void 0;
  3070. var animationEndEvent = void 0;
  3071. if (inBrowser && !isIE9) {
  3072. var isWebkitTrans = window.ontransitionend === undefined && window.onwebkittransitionend !== undefined;
  3073. var isWebkitAnim = window.onanimationend === undefined && window.onwebkitanimationend !== undefined;
  3074. transitionProp = isWebkitTrans ? 'WebkitTransition' : 'transition';
  3075. transitionEndEvent = isWebkitTrans ? 'webkitTransitionEnd' : 'transitionend';
  3076. animationProp = isWebkitAnim ? 'WebkitAnimation' : 'animation';
  3077. animationEndEvent = isWebkitAnim ? 'webkitAnimationEnd' : 'animationend';
  3078. }
  3079. var raf = inBrowser && window.requestAnimationFrame || setTimeout;
  3080. function nextFrame(fn) {
  3081. raf(function () {
  3082. raf(fn);
  3083. });
  3084. }
  3085. function enter(vnode) {
  3086. var el = vnode.elm;
  3087. // call leave callback now
  3088. if (el._leaveCb) {
  3089. el._leaveCb.cancelled = true;
  3090. el._leaveCb();
  3091. }
  3092. var data = vnode.data.transition;
  3093. if (!data) {
  3094. return;
  3095. }
  3096. if (!vnode.context.$root._mounted && !data.appear) {
  3097. return;
  3098. }
  3099. var _resolveTransition = resolveTransition(data.definition, vnode.context);
  3100. var enterClass = _resolveTransition.enterClass;
  3101. var enterActiveClass = _resolveTransition.enterActiveClass;
  3102. var beforeEnter = _resolveTransition.beforeEnter;
  3103. var enter = _resolveTransition.enter;
  3104. var afterEnter = _resolveTransition.afterEnter;
  3105. var enterCancelled = _resolveTransition.enterCancelled;
  3106. var userWantsControl = enter && enter.length > 1;
  3107. var cb = el._enterCb = once(function () {
  3108. if (enterActiveClass) {
  3109. removeTransitionClass(el, enterActiveClass);
  3110. }
  3111. if (cb.cancelled) {
  3112. enterCancelled && enterCancelled(el);
  3113. } else {
  3114. afterEnter && afterEnter(el);
  3115. }
  3116. el._enterCb = null;
  3117. });
  3118. beforeEnter && beforeEnter(el);
  3119. if (enterClass) {
  3120. addTransitionClass(el, enterClass);
  3121. nextFrame(function () {
  3122. removeTransitionClass(el, enterClass);
  3123. });
  3124. }
  3125. if (enterActiveClass) {
  3126. nextFrame(function () {
  3127. addTransitionClass(el, enterActiveClass);
  3128. if (!userWantsControl) {
  3129. whenTransitionEnds(el, cb);
  3130. }
  3131. });
  3132. }
  3133. enter && enter(el, cb);
  3134. if (!enterActiveClass && !userWantsControl) {
  3135. cb();
  3136. }
  3137. }
  3138. function leave(vnode, rm) {
  3139. var el = vnode.elm;
  3140. // call enter callback now
  3141. if (el._enterCb) {
  3142. el._enterCb.cancelled = true;
  3143. el._enterCb();
  3144. }
  3145. var data = vnode.data.transition;
  3146. if (!data) {
  3147. return rm();
  3148. }
  3149. var _resolveTransition2 = resolveTransition(data.definition, vnode.context);
  3150. var leaveClass = _resolveTransition2.leaveClass;
  3151. var leaveActiveClass = _resolveTransition2.leaveActiveClass;
  3152. var beforeLeave = _resolveTransition2.beforeLeave;
  3153. var leave = _resolveTransition2.leave;
  3154. var afterLeave = _resolveTransition2.afterLeave;
  3155. var leaveCancelled = _resolveTransition2.leaveCancelled;
  3156. var userWantsControl = leave && leave.length > 1;
  3157. var cb = el._leaveCb = once(function () {
  3158. if (leaveActiveClass) {
  3159. removeTransitionClass(el, leaveActiveClass);
  3160. }
  3161. if (cb.cancelled) {
  3162. leaveCancelled && leaveCancelled(el);
  3163. } else {
  3164. rm();
  3165. afterLeave && afterLeave(el);
  3166. }
  3167. el._leaveCb = null;
  3168. });
  3169. beforeLeave && beforeLeave(el);
  3170. if (leaveClass) {
  3171. addTransitionClass(el, leaveClass);
  3172. nextFrame(function () {
  3173. removeTransitionClass(el, leaveClass);
  3174. });
  3175. }
  3176. if (leaveActiveClass) {
  3177. nextFrame(function () {
  3178. addTransitionClass(el, leaveActiveClass);
  3179. if (!userWantsControl) {
  3180. whenTransitionEnds(el, cb);
  3181. }
  3182. });
  3183. }
  3184. leave && leave(el, cb);
  3185. if (!leaveActiveClass && !userWantsControl) {
  3186. cb();
  3187. }
  3188. }
  3189. function resolveTransition(id, context) {
  3190. var definition = id && typeof id === 'string' ? resolveAsset(context.$options, 'transitions', id) || id : id;
  3191. if (definition === true) definition = 'v';
  3192. return typeof definition === 'string' ? autoCssTransition(definition) : definition;
  3193. }
  3194. var autoCssTransition = cached(function (name) {
  3195. return {
  3196. enterClass: name + '-enter',
  3197. leaveClass: name + '-leave',
  3198. enterActiveClass: name + '-enter-active',
  3199. leaveActiveClass: name + '-leave-active'
  3200. };
  3201. });
  3202. function addTransitionClass(el, cls) {
  3203. (el._transitionClasses || (el._transitionClasses = [])).push(cls);
  3204. addClass(el, cls);
  3205. }
  3206. function removeTransitionClass(el, cls) {
  3207. remove(el._transitionClasses, cls);
  3208. removeClass(el, cls);
  3209. }
  3210. function whenTransitionEnds(el, cb) {
  3211. var _getTransitionInfo = getTransitionInfo(el);
  3212. var type = _getTransitionInfo.type;
  3213. var timeout = _getTransitionInfo.timeout;
  3214. var propCount = _getTransitionInfo.propCount;
  3215. if (!type) return cb();
  3216. var event = type === TRANSITION ? transitionEndEvent : animationEndEvent;
  3217. var ended = 0;
  3218. var end = function end() {
  3219. el.removeEventListener(event, onEnd);
  3220. cb();
  3221. };
  3222. var onEnd = function onEnd() {
  3223. if (++ended >= propCount) {
  3224. end();
  3225. }
  3226. };
  3227. setTimeout(function () {
  3228. if (ended < propCount) {
  3229. end();
  3230. }
  3231. }, timeout);
  3232. el.addEventListener(event, onEnd);
  3233. }
  3234. function getTransitionInfo(el) {
  3235. var styles = window.getComputedStyle(el);
  3236. // 1. determine the maximum duration (timeout)
  3237. var transitioneDelays = styles[transitionProp + 'Delay'].split(', ');
  3238. var transitionDurations = styles[transitionProp + 'Duration'].split(', ');
  3239. var animationDelays = styles[animationProp + 'Delay'].split(', ');
  3240. var animationDurations = styles[animationProp + 'Duration'].split(', ');
  3241. var transitionTimeout = getTimeout(transitioneDelays, transitionDurations);
  3242. var animationTimeout = getTimeout(animationDelays, animationDurations);
  3243. var timeout = Math.max(transitionTimeout, animationTimeout);
  3244. var type = timeout > 0 ? transitionTimeout > animationTimeout ? TRANSITION : ANIMATION : null;
  3245. var propCount = type ? type === TRANSITION ? transitionDurations.length : animationDurations.length : 0;
  3246. return {
  3247. type: type,
  3248. timeout: timeout,
  3249. propCount: propCount
  3250. };
  3251. }
  3252. function getTimeout(delays, durations) {
  3253. return Math.max.apply(null, durations.map(function (d, i) {
  3254. return toMs(d) + toMs(delays[i]);
  3255. }));
  3256. }
  3257. function toMs(s) {
  3258. return Number(s.slice(0, -1)) * 1000;
  3259. }
  3260. function once(fn) {
  3261. var called = false;
  3262. return function () {
  3263. if (!called) {
  3264. called = true;
  3265. fn();
  3266. }
  3267. };
  3268. }
  3269. function shouldSkipTransition(vnode) {
  3270. return(
  3271. // if this is a component root node and the compoennt's
  3272. // parent container node also has transition, skip.
  3273. vnode.parent && vnode.parent.data.transition ||
  3274. // if the element has v-show, let the runtime directive
  3275. // call the hooks instead
  3276. vnode.data.show
  3277. );
  3278. }
  3279. var transition = !transitionEndEvent ? {} : {
  3280. create: function create(_, vnode) {
  3281. if (!shouldSkipTransition(vnode)) {
  3282. enter(vnode);
  3283. }
  3284. },
  3285. remove: function remove(vnode, rm) {
  3286. if (!shouldSkipTransition(vnode)) {
  3287. leave(vnode, rm);
  3288. } else {
  3289. rm();
  3290. }
  3291. }
  3292. };
  3293. var show = {
  3294. bind: function bind(el, value, _, vnode) {
  3295. var transition = getTransition(vnode);
  3296. if (value && transition && transition.appea && !isIE9) {
  3297. enter(vnode);
  3298. }
  3299. el.style.display = value ? '' : 'none';
  3300. },
  3301. update: function update(el, value, _, vnode) {
  3302. var transition = getTransition(vnode);
  3303. if (transition && !isIE9) {
  3304. if (value) {
  3305. enter(vnode);
  3306. el.style.display = '';
  3307. } else {
  3308. leave(vnode, function () {
  3309. el.style.display = 'none';
  3310. });
  3311. }
  3312. } else {
  3313. el.style.display = value ? '' : 'none';
  3314. }
  3315. }
  3316. };
  3317. function getTransition(vnode) {
  3318. var parent = vnode.parent;
  3319. return parent && parent.data.transition != null ? parent.data.transition : vnode.data.transition;
  3320. }
  3321. var platformDirectives = {
  3322. model: model,
  3323. show: show
  3324. };
  3325. var directives = {
  3326. create: function bindDirectives(oldVnode, vnode) {
  3327. applyDirectives(oldVnode, vnode, 'bind');
  3328. },
  3329. update: function updateDirectives(oldVnode, vnode) {
  3330. applyDirectives(oldVnode, vnode, 'update', true);
  3331. },
  3332. destroy: function unbindDirectives(vnode) {
  3333. applyDirectives(null, vnode, 'unbind');
  3334. }
  3335. };
  3336. function applyDirectives(oldVnode, vnode, hook, update) {
  3337. var dirs = vnode.data.directives;
  3338. if (dirs) {
  3339. for (var i = 0; i < dirs.length; i++) {
  3340. var dir = dirs[i];
  3341. var def = resolveAsset(vnode.context.$options, 'directives', dir.name, true);
  3342. var fn = def && def[hook];
  3343. if (fn) {
  3344. // only call update if value has changed
  3345. if (update) {
  3346. var oldValue = oldVnode.data.directives[i].value;
  3347. if (oldValue === dir.value) {
  3348. continue;
  3349. }
  3350. }
  3351. fn(vnode.elm, dir.value, dir.modifiers, vnode, oldVnode);
  3352. }
  3353. }
  3354. }
  3355. }
  3356. var baseModules = [directives];
  3357. function updateAttrs(oldVnode, vnode) {
  3358. if (!oldVnode.data.attrs && !vnode.data.attrs) {
  3359. return;
  3360. }
  3361. var key = void 0,
  3362. cur = void 0,
  3363. old = void 0;
  3364. var elm = vnode.elm;
  3365. var oldAttrs = oldVnode.data.attrs || {};
  3366. var attrs = vnode.data.attrs || {};
  3367. for (key in attrs) {
  3368. cur = attrs[key];
  3369. old = oldAttrs[key];
  3370. if (old !== cur) {
  3371. setAttr(elm, key, cur);
  3372. }
  3373. }
  3374. for (key in oldAttrs) {
  3375. if (attrs[key] == null) {
  3376. if (isXlink(key)) {
  3377. elm.removeAttributeNS(xlinkNS, key);
  3378. } else {
  3379. elm.removeAttribute(key);
  3380. }
  3381. }
  3382. }
  3383. }
  3384. function setAttr(el, key, value) {
  3385. if (isBooleanAttr(key)) {
  3386. if (value == null) {
  3387. el.removeAttribute(key);
  3388. } else {
  3389. el.setAttribute(key, key);
  3390. }
  3391. } else if (isEnumeratedAttr(key)) {
  3392. el.setAttribute(key, value == null ? 'false' : 'true');
  3393. } else if (isXlink(key)) {
  3394. el.setAttributeNS(xlinkNS, key, value);
  3395. } else {
  3396. el.setAttribute(key, value);
  3397. }
  3398. }
  3399. var attrs = {
  3400. create: function create(_, vnode) {
  3401. var attrs = vnode.data.staticAttrs;
  3402. if (attrs) {
  3403. for (var key in attrs) {
  3404. if (!vnode.elm) debugger;
  3405. setAttr(vnode.elm, key, attrs[key]);
  3406. }
  3407. }
  3408. updateAttrs(_, vnode);
  3409. },
  3410. update: updateAttrs
  3411. };
  3412. function updateClass(oldVnode, vnode) {
  3413. var el = vnode.elm;
  3414. var data = vnode.data;
  3415. if (!data.staticClass && !data.class) {
  3416. return;
  3417. }
  3418. var cls = genClassForVnode(vnode);
  3419. // handle transition classes
  3420. var transitionClass = el._transitionClasses;
  3421. if (transitionClass) {
  3422. cls = concat(cls, stringifyClass(transitionClass));
  3423. }
  3424. // set the class
  3425. if (cls !== el._prevClass) {
  3426. setClass(el, cls);
  3427. el._prevClass = cls;
  3428. }
  3429. }
  3430. var klass = {
  3431. create: updateClass,
  3432. update: updateClass
  3433. };
  3434. function updateDOMListeners(oldVnode, vnode) {
  3435. if (!oldVnode.data.on && !vnode.data.on) {
  3436. return;
  3437. }
  3438. var on = vnode.data.on || {};
  3439. var oldOn = oldVnode.data.on || {};
  3440. updateListeners(on, oldOn, function (event, handler, capture) {
  3441. vnode.elm.addEventListener(event, handler, capture);
  3442. });
  3443. }
  3444. var events = {
  3445. create: updateDOMListeners,
  3446. update: updateDOMListeners
  3447. };
  3448. function updateProps(oldVnode, vnode) {
  3449. if (!oldVnode.data.props && !vnode.data.props) {
  3450. return;
  3451. }
  3452. var key = void 0,
  3453. cur = void 0,
  3454. old = void 0;
  3455. var elm = vnode.elm;
  3456. var oldProps = oldVnode.data.props || {};
  3457. var props = vnode.data.props || {};
  3458. for (key in oldProps) {
  3459. if (props[key] == null) {
  3460. elm[key] = undefined;
  3461. }
  3462. }
  3463. for (key in props) {
  3464. cur = props[key];
  3465. old = oldProps[key];
  3466. if (old !== cur) {
  3467. if (key === 'value') {
  3468. // store value as _value as well since
  3469. // non-string values will be stringified
  3470. if (elm._value !== cur) {
  3471. elm.value = elm._value = cur;
  3472. }
  3473. } else {
  3474. elm[key] = cur;
  3475. }
  3476. }
  3477. }
  3478. }
  3479. var props = {
  3480. create: updateProps,
  3481. update: updateProps
  3482. };
  3483. var prefixes = ['Webkit', 'Moz', 'ms'];
  3484. var testEl = inBrowser && document.createElement('div');
  3485. var normalize = cached(function (prop) {
  3486. prop = camelize(prop);
  3487. if (prop !== 'filter' && prop in testEl.style) {
  3488. return prop;
  3489. }
  3490. var upper = prop.charAt(0).toUpperCase() + prop.slice(1);
  3491. for (var i = 0; i < prefixes.length; i++) {
  3492. var prefixed = prefixes[i] + upper;
  3493. if (prefixed in testEl.style) {
  3494. return prefixed;
  3495. }
  3496. }
  3497. });
  3498. function updateStyle(oldVnode, vnode) {
  3499. if (!oldVnode.data.style && !vnode.data.style) {
  3500. return;
  3501. }
  3502. var cur = void 0,
  3503. name = void 0;
  3504. var elm = vnode.elm;
  3505. var oldStyle = oldVnode.data.style || {};
  3506. var style = vnode.data.style || {};
  3507. // handle array syntax
  3508. if (isArray(style)) {
  3509. style = vnode.data.style = toObject(style);
  3510. }
  3511. for (name in oldStyle) {
  3512. if (!style[name]) {
  3513. elm.style[normalize(name)] = '';
  3514. }
  3515. }
  3516. for (name in style) {
  3517. cur = style[name];
  3518. if (cur !== oldStyle[name]) {
  3519. elm.style[normalize(name)] = cur;
  3520. }
  3521. }
  3522. }
  3523. function toObject(arr) {
  3524. var res = arr[0] || {};
  3525. for (var i = 1; i < arr.length; i++) {
  3526. if (arr[i]) {
  3527. extend(res, arr[i]);
  3528. }
  3529. }
  3530. return res;
  3531. }
  3532. var style = {
  3533. create: updateStyle,
  3534. update: updateStyle
  3535. };
  3536. var platformModules = [attrs, klass, events, props, style, transition];
  3537. // install platform specific utils
  3538. Vue.config.isUnknownElement = isUnknownElement;
  3539. Vue.config.isReservedTag = isReservedTag;
  3540. // install platform runtime directives
  3541. Vue.options.directives = platformDirectives;
  3542. // install platform patch function
  3543. var modules = baseModules.concat(platformModules);
  3544. Vue.prototype.__patch__ = inBrowser ? createPatchFunction({ nodeOps: nodeOps, modules: modules }) : function noop() {};
  3545. // wrap mount
  3546. Vue.prototype.$mount = function (el) {
  3547. this.$el = el && query(el);
  3548. this._mount();
  3549. };
  3550. var decoder = document.createElement('div');
  3551. function decodeHTML(html) {
  3552. decoder.innerHTML = html;
  3553. return decoder.textContent;
  3554. }
  3555. // Regular Expressions for parsing tags and attributes
  3556. var singleAttrIdentifier = /([^\s"'<>\/=]+)/;
  3557. var singleAttrAssign = /=/;
  3558. var singleAttrAssigns = [singleAttrAssign];
  3559. var singleAttrValues = [
  3560. // attr value double quotes
  3561. /"([^"]*)"+/.source,
  3562. // attr value, single quotes
  3563. /'([^']*)'+/.source,
  3564. // attr value, no quotes
  3565. /([^\s"'=<>`]+)/.source];
  3566. // could use https://www.w3.org/TR/1999/REC-xml-names-19990114/#NT-QName
  3567. // but for Vue templates we can enforce a simple charset
  3568. var ncname = '[a-zA-Z_][\\w\\-\\.]*';
  3569. var qnameCapture = '((?:' + ncname + '\\:)?' + ncname + ')';
  3570. var startTagOpen = new RegExp('^<' + qnameCapture);
  3571. var startTagClose = /^\s*(\/?)>/;
  3572. var endTag = new RegExp('^<\\/' + qnameCapture + '[^>]*>');
  3573. var doctype = /^<!DOCTYPE [^>]+>/i;
  3574. var IS_REGEX_CAPTURING_BROKEN = false;
  3575. 'x'.replace(/x(.)?/g, function (m, g) {
  3576. IS_REGEX_CAPTURING_BROKEN = g === '';
  3577. });
  3578. // Special Elements (can contain anything)
  3579. var special = makeMap('script,style', true);
  3580. var reCache = {};
  3581. function attrForHandler(handler) {
  3582. var pattern = singleAttrIdentifier.source + '(?:\\s*(' + joinSingleAttrAssigns(handler) + ')' + '\\s*(?:' + singleAttrValues.join('|') + '))?';
  3583. return new RegExp('^\\s*' + pattern);
  3584. }
  3585. function joinSingleAttrAssigns(handler) {
  3586. return singleAttrAssigns.map(function (assign) {
  3587. return '(?:' + assign.source + ')';
  3588. }).join('|');
  3589. }
  3590. function parseHTML(html, handler) {
  3591. var stack = [];
  3592. var attribute = attrForHandler(handler);
  3593. var expectHTML = handler.expectHTML;
  3594. var isUnaryTag = handler.isUnaryTag || function () {
  3595. return false;
  3596. };
  3597. var last = void 0,
  3598. prevTag = void 0,
  3599. nextTag = void 0,
  3600. lastTag = void 0;
  3601. while (html) {
  3602. last = html;
  3603. // Make sure we're not in a script or style element
  3604. if (!lastTag || !special(lastTag)) {
  3605. var textEnd = html.indexOf('<');
  3606. if (textEnd === 0) {
  3607. // Comment:
  3608. if (/^<!--/.test(html)) {
  3609. var commentEnd = html.indexOf('-->');
  3610. if (commentEnd >= 0) {
  3611. html = html.substring(commentEnd + 3);
  3612. prevTag = '';
  3613. continue;
  3614. }
  3615. }
  3616. // http://en.wikipedia.org/wiki/Conditional_comment#Downlevel-revealed_conditional_comment
  3617. if (/^<!\[/.test(html)) {
  3618. var conditionalEnd = html.indexOf(']>');
  3619. if (conditionalEnd >= 0) {
  3620. html = html.substring(conditionalEnd + 2);
  3621. prevTag = '';
  3622. continue;
  3623. }
  3624. }
  3625. // Doctype:
  3626. var doctypeMatch = html.match(doctype);
  3627. if (doctypeMatch) {
  3628. if (handler.doctype) {
  3629. handler.doctype(doctypeMatch[0]);
  3630. }
  3631. html = html.substring(doctypeMatch[0].length);
  3632. prevTag = '';
  3633. continue;
  3634. }
  3635. // End tag:
  3636. var endTagMatch = html.match(endTag);
  3637. if (endTagMatch) {
  3638. html = html.substring(endTagMatch[0].length);
  3639. endTagMatch[0].replace(endTag, parseEndTag);
  3640. prevTag = '/' + endTagMatch[1].toLowerCase();
  3641. continue;
  3642. }
  3643. // Start tag:
  3644. var startTagMatch = parseStartTag(html);
  3645. if (startTagMatch) {
  3646. html = startTagMatch.rest;
  3647. handleStartTag(startTagMatch);
  3648. prevTag = startTagMatch.tagName.toLowerCase();
  3649. continue;
  3650. }
  3651. }
  3652. var text;
  3653. if (textEnd >= 0) {
  3654. text = html.substring(0, textEnd);
  3655. html = html.substring(textEnd);
  3656. } else {
  3657. text = html;
  3658. html = '';
  3659. }
  3660. // next tag
  3661. var nextTagMatch = parseStartTag(html);
  3662. if (nextTagMatch) {
  3663. nextTag = nextTagMatch.tagName;
  3664. } else {
  3665. nextTagMatch = html.match(endTag);
  3666. if (nextTagMatch) {
  3667. nextTag = '/' + nextTagMatch[1];
  3668. } else {
  3669. nextTag = '';
  3670. }
  3671. }
  3672. if (handler.chars) {
  3673. handler.chars(text, prevTag, nextTag);
  3674. }
  3675. prevTag = '';
  3676. } else {
  3677. var stackedTag = lastTag.toLowerCase();
  3678. var reStackedTag = reCache[stackedTag] || (reCache[stackedTag] = new RegExp('([\\s\\S]*?)</' + stackedTag + '[^>]*>', 'i'));
  3679. html = html.replace(reStackedTag, function (all, text) {
  3680. if (stackedTag !== 'script' && stackedTag !== 'style' && stackedTag !== 'noscript') {
  3681. text = text.replace(/<!--([\s\S]*?)-->/g, '$1').replace(/<!\[CDATA\[([\s\S]*?)\]\]>/g, '$1');
  3682. }
  3683. if (handler.chars) {
  3684. handler.chars(text);
  3685. }
  3686. return '';
  3687. });
  3688. parseEndTag('</' + stackedTag + '>', stackedTag);
  3689. }
  3690. if (html === last) {
  3691. throw new Error('Error parsing template:\n\n' + html);
  3692. }
  3693. }
  3694. if (!handler.partialMarkup) {
  3695. // Clean up any remaining tags
  3696. parseEndTag();
  3697. }
  3698. function parseStartTag(input) {
  3699. var start = input.match(startTagOpen);
  3700. if (start) {
  3701. var match = {
  3702. tagName: start[1],
  3703. attrs: []
  3704. };
  3705. input = input.slice(start[0].length);
  3706. var end, attr;
  3707. while (!(end = input.match(startTagClose)) && (attr = input.match(attribute))) {
  3708. input = input.slice(attr[0].length);
  3709. match.attrs.push(attr);
  3710. }
  3711. if (end) {
  3712. match.unarySlash = end[1];
  3713. match.rest = input.slice(end[0].length);
  3714. return match;
  3715. }
  3716. }
  3717. }
  3718. function handleStartTag(match) {
  3719. var tagName = match.tagName;
  3720. var unarySlash = match.unarySlash;
  3721. if (expectHTML) {
  3722. if (lastTag === 'p' && isNonPhrasingTag(tagName)) {
  3723. parseEndTag('', lastTag);
  3724. }
  3725. if (canBeLeftOpenTag(tagName) && lastTag === tagName) {
  3726. parseEndTag('', tagName);
  3727. }
  3728. }
  3729. var unary = isUnaryTag(tagName) || tagName === 'html' && lastTag === 'head' || !!unarySlash;
  3730. var attrs = match.attrs.map(function (args) {
  3731. // hackish work around FF bug https://bugzilla.mozilla.org/show_bug.cgi?id=369778
  3732. if (IS_REGEX_CAPTURING_BROKEN && args[0].indexOf('""') === -1) {
  3733. if (args[3] === '') {
  3734. delete args[3];
  3735. }
  3736. if (args[4] === '') {
  3737. delete args[4];
  3738. }
  3739. if (args[5] === '') {
  3740. delete args[5];
  3741. }
  3742. }
  3743. return {
  3744. name: args[1],
  3745. value: decodeHTML(args[3] || args[4] || args[5] || '')
  3746. };
  3747. });
  3748. if (!unary) {
  3749. stack.push({ tag: tagName, attrs: attrs });
  3750. lastTag = tagName;
  3751. unarySlash = '';
  3752. }
  3753. if (handler.start) {
  3754. handler.start(tagName, attrs, unary, unarySlash);
  3755. }
  3756. }
  3757. function parseEndTag(tag, tagName) {
  3758. var pos;
  3759. // Find the closest opened tag of the same type
  3760. if (tagName) {
  3761. var needle = tagName.toLowerCase();
  3762. for (pos = stack.length - 1; pos >= 0; pos--) {
  3763. if (stack[pos].tag.toLowerCase() === needle) {
  3764. break;
  3765. }
  3766. }
  3767. } else {
  3768. // If no tag name is provided, clean shop
  3769. pos = 0;
  3770. }
  3771. if (pos >= 0) {
  3772. // Close all the open elements, up the stack
  3773. for (var i = stack.length - 1; i >= pos; i--) {
  3774. if (handler.end) {
  3775. handler.end(stack[i].tag, stack[i].attrs, i > pos || !tag);
  3776. }
  3777. }
  3778. // Remove the open elements from the stack
  3779. stack.length = pos;
  3780. lastTag = pos && stack[pos - 1].tag;
  3781. } else if (tagName.toLowerCase() === 'br') {
  3782. if (handler.start) {
  3783. handler.start(tagName, [], true, '');
  3784. }
  3785. } else if (tagName.toLowerCase() === 'p') {
  3786. if (handler.start) {
  3787. handler.start(tagName, [], false, '', true);
  3788. }
  3789. if (handler.end) {
  3790. handler.end(tagName, []);
  3791. }
  3792. }
  3793. }
  3794. }
  3795. var tagRE = /\{\{((?:.|\\n)+?)\}\}/g;
  3796. function parseText(text) {
  3797. if (!tagRE.test(text)) {
  3798. return null;
  3799. }
  3800. var tokens = [];
  3801. var lastIndex = tagRE.lastIndex = 0;
  3802. var match, index;
  3803. while (match = tagRE.exec(text)) {
  3804. index = match.index;
  3805. // push text token
  3806. if (index > lastIndex) {
  3807. tokens.push(JSON.stringify(text.slice(lastIndex, index)));
  3808. }
  3809. // tag token
  3810. var exp = match[1].trim();
  3811. tokens.push('__toString__(' + exp + ')');
  3812. lastIndex = index + match[0].length;
  3813. }
  3814. if (lastIndex < text.length) {
  3815. tokens.push(JSON.stringify(text.slice(lastIndex)));
  3816. }
  3817. return tokens.join('+');
  3818. }
  3819. function addProp(el, name, value) {
  3820. (el.props || (el.props = [])).push({ name: name, value: value });
  3821. }
  3822. function addAttr(el, name, value) {
  3823. (el.attrs || (el.attrs = [])).push({ name: name, value: value });
  3824. }
  3825. function addStaticAttr(el, name, value) {
  3826. (el.staticAttrs || (el.staticAttrs = [])).push({ name: name, value: value });
  3827. }
  3828. function addDirective(el, name, value, arg, modifiers) {
  3829. (el.directives || (el.directives = [])).push({ name: name, value: value, arg: arg, modifiers: modifiers });
  3830. }
  3831. function addHook(el, name, code) {
  3832. var hooks = el.hooks || (el.hooks = {});
  3833. var hook = hooks[name];
  3834. if (hook) {
  3835. hook.push(code);
  3836. } else {
  3837. hooks[name] = [code];
  3838. }
  3839. }
  3840. function addHandler(el, name, value, modifiers) {
  3841. var events = el.events || (el.events = {});
  3842. // check capture modifier
  3843. if (modifiers && modifiers.capture) {
  3844. delete modifiers.capture;
  3845. name = '!' + name; // mark the event as captured
  3846. }
  3847. var newHandler = { value: value, modifiers: modifiers };
  3848. var handlers = events[name];
  3849. if (isArray(handlers)) {
  3850. handlers.push(newHandler);
  3851. } else if (handlers) {
  3852. events[name] = [handlers, newHandler];
  3853. } else {
  3854. events[name] = newHandler;
  3855. }
  3856. }
  3857. function getBindingAttr(el, name, getStatic) {
  3858. var staticValue = getStatic !== false && getAndRemoveAttr(el, name);
  3859. return staticValue || staticValue === '' ? JSON.stringify(staticValue) : getAndRemoveAttr(el, ':' + name) || getAndRemoveAttr(el, 'v-bind:' + name);
  3860. }
  3861. function getAndRemoveAttr(el, name) {
  3862. var val = void 0;
  3863. if ((val = el.attrsMap[name]) != null) {
  3864. el.attrsMap[name] = null;
  3865. var list = el.attrsList;
  3866. for (var i = 0, l = list.length; i < l; i++) {
  3867. if (list[i].name === name) {
  3868. list.splice(i, 1);
  3869. break;
  3870. }
  3871. }
  3872. }
  3873. return val;
  3874. }
  3875. var dirRE = /^v-|^@|^:/;
  3876. var bindRE = /^:|^v-bind:/;
  3877. var onRE = /^@|^v-on:/;
  3878. var argRE = /:(.*)$/;
  3879. var modifierRE = /\.[^\.]+/g;
  3880. var forAliasRE = /(.*)\s+(?:in|of)\s+(.*)/;
  3881. var forIteratorRE = /\((.*),(.*)\)/;
  3882. var camelRE = /[a-z\d][A-Z]/;
  3883. var decodeHTMLCached = cached(decodeHTML);
  3884. // make warning customizable depending on environment.
  3885. var warn$1 = void 0;
  3886. var baseWarn = function baseWarn(msg) {
  3887. return console.error('[Vue parser]: ' + msg);
  3888. };
  3889. // platform-injected util functions
  3890. var platformGetTagNamespace = void 0;
  3891. var platformMustUseProp = void 0;
  3892. /**
  3893. * Convert HTML string to AST.
  3894. *
  3895. * @param {String} template
  3896. * @param {Object} options
  3897. * @return {Object}
  3898. */
  3899. function parse(template, options) {
  3900. warn$1 = options.warn || baseWarn;
  3901. platformGetTagNamespace = options.getTagNamespace || function () {
  3902. return null;
  3903. };
  3904. platformMustUseProp = options.mustUseProp || function () {
  3905. return false;
  3906. };
  3907. var stack = [];
  3908. var root = void 0;
  3909. var currentParent = void 0;
  3910. var inPre = false;
  3911. var warned = false;
  3912. parseHTML(template, {
  3913. expectHTML: options.expectHTML,
  3914. isUnaryTag: options.isUnaryTag,
  3915. start: function start(tag, attrs, unary) {
  3916. // check camelCase tag
  3917. if (camelRE.test(tag)) {
  3918. "development" !== 'production' && warn$1('Found camelCase tag in template: <' + tag + '>. ' + ('I\'ve converted it to <' + hyphenate(tag) + '> for you.'));
  3919. tag = hyphenate(tag);
  3920. }
  3921. tag = tag.toLowerCase();
  3922. var element = {
  3923. tag: tag,
  3924. attrsList: attrs,
  3925. attrsMap: makeAttrsMap(attrs),
  3926. parent: currentParent,
  3927. children: []
  3928. };
  3929. // check namespace.
  3930. // inherit parent ns if there is one
  3931. var ns = void 0;
  3932. if ((ns = currentParent && currentParent.ns) || (ns = platformGetTagNamespace(tag))) {
  3933. element.ns = ns;
  3934. }
  3935. if (!inPre) {
  3936. processPre(element);
  3937. if (element.pre) {
  3938. inPre = true;
  3939. }
  3940. }
  3941. if (inPre) {
  3942. processRawAttrs(element);
  3943. } else {
  3944. processFor(element);
  3945. processIf(element);
  3946. processOnce(element);
  3947. // determine whether this is a plain element after
  3948. // removing if/for/once attributes
  3949. element.plain = !attrs.length;
  3950. processRender(element);
  3951. processSlot(element);
  3952. processComponent(element);
  3953. processClassBinding(element);
  3954. processStyleBinding(element);
  3955. processTransition(element);
  3956. processAttrs(element);
  3957. }
  3958. // tree management
  3959. if (!root) {
  3960. root = element;
  3961. } else if ("development" !== 'production' && !stack.length && !warned) {
  3962. warned = true;
  3963. warn$1('Component template should contain exactly one root element:\n\n' + template);
  3964. }
  3965. if (currentParent) {
  3966. if (element.else) {
  3967. processElse(element, currentParent);
  3968. } else {
  3969. currentParent.children.push(element);
  3970. element.parent = currentParent;
  3971. }
  3972. }
  3973. if (!unary) {
  3974. currentParent = element;
  3975. stack.push(element);
  3976. }
  3977. },
  3978. end: function end(tag) {
  3979. // remove trailing whitespace
  3980. var element = stack[stack.length - 1];
  3981. var lastNode = element.children[element.children.length - 1];
  3982. if (lastNode && lastNode.text === ' ') element.children.pop();
  3983. // pop stack
  3984. stack.length -= 1;
  3985. currentParent = stack[stack.length - 1];
  3986. // check pre state
  3987. if (element.pre) {
  3988. inPre = false;
  3989. }
  3990. },
  3991. chars: function chars(text) {
  3992. if (!currentParent) {
  3993. if ("development" !== 'production' && !warned) {
  3994. warned = true;
  3995. warn$1('Component template should contain exactly one root element:\n\n' + template);
  3996. }
  3997. return;
  3998. }
  3999. text = currentParent.tag === 'pre' || text.trim() ? decodeHTMLCached(text)
  4000. // only preserve whitespace if its not right after a starting tag
  4001. : options.preserveWhitespace && currentParent.children.length ? ' ' : null;
  4002. if (text) {
  4003. var expression = void 0;
  4004. if (!inPre && text !== ' ' && (expression = parseText(text))) {
  4005. currentParent.children.push({ expression: expression });
  4006. } else {
  4007. currentParent.children.push({ text: text });
  4008. }
  4009. }
  4010. }
  4011. });
  4012. return root;
  4013. }
  4014. function processPre(el) {
  4015. if (getAndRemoveAttr(el, 'v-pre') != null) {
  4016. el.pre = true;
  4017. }
  4018. }
  4019. function processRawAttrs(el) {
  4020. var l = el.attrsList.length;
  4021. if (l) {
  4022. el.attrs = new Array(l);
  4023. for (var i = 0; i < l; i++) {
  4024. el.attrs[i] = {
  4025. name: el.attrsList[i].name,
  4026. value: JSON.stringify(el.attrsList[i].value)
  4027. };
  4028. }
  4029. }
  4030. }
  4031. function processFor(el) {
  4032. var exp = void 0;
  4033. if (exp = getAndRemoveAttr(el, 'v-for')) {
  4034. var inMatch = exp.match(forAliasRE);
  4035. if (!inMatch) {
  4036. "development" !== 'production' && warn$1('Invalid v-for expression: ' + exp);
  4037. return;
  4038. }
  4039. el.for = inMatch[2].trim();
  4040. var alias = inMatch[1].trim();
  4041. var iteratorMatch = alias.match(forIteratorRE);
  4042. if (iteratorMatch) {
  4043. el.iterator = iteratorMatch[1].trim();
  4044. el.alias = iteratorMatch[2].trim();
  4045. } else {
  4046. el.alias = alias;
  4047. }
  4048. if (exp = getAndRemoveAttr(el, 'track-by')) {
  4049. el.key = exp === '$index' ? exp : el.alias + '["' + exp + '"]';
  4050. }
  4051. }
  4052. }
  4053. function processIf(el) {
  4054. var exp = getAndRemoveAttr(el, 'v-if');
  4055. if (exp) {
  4056. el.if = exp;
  4057. }
  4058. if (getAndRemoveAttr(el, 'v-else') != null) {
  4059. el.else = true;
  4060. }
  4061. }
  4062. function processElse(el, parent) {
  4063. var prev = findPrevElement(parent.children);
  4064. if (prev && (prev.if || prev.attrsMap['v-show'])) {
  4065. if (prev.if) {
  4066. // v-if
  4067. prev.elseBlock = el;
  4068. } else {
  4069. // v-show: simply add a v-show with reversed value
  4070. addDirective(el, 'show', '!(' + prev.attrsMap['v-show'] + ')');
  4071. // also copy its transition
  4072. el.transition = prev.transition;
  4073. // als set show to true
  4074. el.show = true;
  4075. parent.children.push(el);
  4076. }
  4077. } else if ("development" !== 'production') {
  4078. warn$1('v-else used on element <' + el.tag + '> without corresponding v-if/v-show.');
  4079. }
  4080. }
  4081. function processOnce(el) {
  4082. var once = getAndRemoveAttr(el, 'v-once');
  4083. if (once != null) {
  4084. el.once = true;
  4085. }
  4086. }
  4087. function processRender(el) {
  4088. if (el.tag === 'render') {
  4089. el.render = true;
  4090. el.renderMethod = el.attrsMap.method;
  4091. el.renderArgs = el.attrsMap[':args'] || el.attrsMap['v-bind:args'];
  4092. if ("development" !== 'production') {
  4093. if (!el.renderMethod) {
  4094. warn$1('method attribute is required on <render>.');
  4095. }
  4096. if (el.attrsMap.args) {
  4097. warn$1('<render> args should use a dynamic binding, e.g. `:args="..."`.');
  4098. }
  4099. }
  4100. }
  4101. }
  4102. function processSlot(el) {
  4103. if (el.tag === 'slot') {
  4104. el.slotName = getBindingAttr(el, 'name');
  4105. } else {
  4106. var slotTarget = getBindingAttr(el, 'slot');
  4107. if (slotTarget) {
  4108. el.slotTarget = slotTarget;
  4109. }
  4110. }
  4111. }
  4112. function processComponent(el) {
  4113. if (el.tag === 'component') {
  4114. el.component = getBindingAttr(el, 'is');
  4115. }
  4116. }
  4117. function processClassBinding(el) {
  4118. var staticClass = getAndRemoveAttr(el, 'class');
  4119. el.staticClass = parseText(staticClass) || JSON.stringify(staticClass);
  4120. var classBinding = getBindingAttr(el, 'class', false /* getStatic */);
  4121. if (classBinding) {
  4122. el.classBinding = classBinding;
  4123. }
  4124. }
  4125. function processStyleBinding(el) {
  4126. var styleBinding = getBindingAttr(el, 'style', false /* getStatic */);
  4127. if (styleBinding) {
  4128. el.styleBinding = styleBinding;
  4129. }
  4130. }
  4131. function processTransition(el) {
  4132. var transition = getBindingAttr(el, 'transition');
  4133. if (transition === '""') {
  4134. transition = true;
  4135. }
  4136. if (transition) {
  4137. el.transition = transition;
  4138. el.transitionOnAppear = getBindingAttr(el, 'transition-on-appear') != null;
  4139. }
  4140. }
  4141. function processAttrs(el) {
  4142. var list = el.attrsList;
  4143. var i = void 0,
  4144. l = void 0,
  4145. name = void 0,
  4146. value = void 0,
  4147. arg = void 0,
  4148. modifiers = void 0;
  4149. for (i = 0, l = list.length; i < l; i++) {
  4150. name = list[i].name;
  4151. value = list[i].value;
  4152. if (dirRE.test(name)) {
  4153. // modifiers
  4154. modifiers = parseModifiers(name);
  4155. if (modifiers) {
  4156. name = name.replace(modifierRE, '');
  4157. }
  4158. if (bindRE.test(name)) {
  4159. // v-bind
  4160. name = name.replace(bindRE, '');
  4161. if (platformMustUseProp(name)) {
  4162. addProp(el, name, value);
  4163. } else {
  4164. addAttr(el, name, value);
  4165. }
  4166. } else if (onRE.test(name)) {
  4167. // v-on
  4168. name = name.replace(onRE, '');
  4169. addHandler(el, name, value, modifiers);
  4170. } else {
  4171. // normal directives
  4172. name = name.replace(dirRE, '');
  4173. // parse arg
  4174. if ((arg = name.match(argRE)) && (arg = arg[1])) {
  4175. name = name.slice(0, -(arg.length + 1));
  4176. }
  4177. addDirective(el, name, value, arg, modifiers);
  4178. }
  4179. } else {
  4180. // literal attribute
  4181. var expression = parseText(value);
  4182. if (expression) {
  4183. warn$1('Interpolation inside attributes has been deprecated. ' + 'Use v-bind or the colon shorthand instead.');
  4184. } else {
  4185. addStaticAttr(el, name, JSON.stringify(value));
  4186. }
  4187. }
  4188. }
  4189. }
  4190. function parseModifiers(name) {
  4191. var match = name.match(modifierRE);
  4192. if (match) {
  4193. var _ret = function () {
  4194. var ret = {};
  4195. match.forEach(function (m) {
  4196. ret[m.slice(1)] = true;
  4197. });
  4198. return {
  4199. v: ret
  4200. };
  4201. }();
  4202. if (typeof _ret === "object") return _ret.v;
  4203. }
  4204. }
  4205. function makeAttrsMap(attrs) {
  4206. var map = {};
  4207. for (var i = 0, l = attrs.length; i < l; i++) {
  4208. if ("development" !== 'production' && map[attrs[i].name]) {
  4209. warn$1('duplicate attribute: ' + attrs[i].name);
  4210. }
  4211. map[attrs[i].name] = attrs[i].value;
  4212. }
  4213. return map;
  4214. }
  4215. function findPrevElement(children) {
  4216. var i = children.length;
  4217. while (i--) {
  4218. if (children[i].tag) return children[i];
  4219. }
  4220. }
  4221. var isPlatformReservedTag = void 0;
  4222. /**
  4223. * Goal of the optimizier: walk the generated template AST tree
  4224. * and detect sub-trees that are purely static, i.e. parts of
  4225. * the DOM that never needs to change.
  4226. *
  4227. * Once we detect these sub-trees, we can:
  4228. *
  4229. * 1. Hoist them into constants, so that we no longer need to
  4230. * create fresh nodes for them on each re-render;
  4231. * 2. Completely skip them in the patching process.
  4232. */
  4233. function optimize(root, options) {
  4234. isPlatformReservedTag = options.isReservedTag || function () {
  4235. return false;
  4236. };
  4237. // first pass: mark all non-static nodes.
  4238. markStatic(root);
  4239. // second pass: mark static roots.
  4240. markStaticRoots(root);
  4241. }
  4242. function markStatic(node) {
  4243. node.static = isStatic(node);
  4244. if (node.children) {
  4245. for (var i = 0, l = node.children.length; i < l; i++) {
  4246. var child = node.children[i];
  4247. markStatic(child);
  4248. if (!child.static) {
  4249. node.static = false;
  4250. }
  4251. }
  4252. }
  4253. }
  4254. function markStaticRoots(node) {
  4255. if (node.tag && (node.once || node.static)) {
  4256. node.staticRoot = true;
  4257. return;
  4258. }
  4259. if (node.children) {
  4260. for (var i = 0, l = node.children.length; i < l; i++) {
  4261. markStaticRoots(node.children[i]);
  4262. }
  4263. }
  4264. }
  4265. var isStaticKey = makeMap('tag,attrsList,attrsMap,plain,parent,children,' + 'staticAttrs,staticClass');
  4266. function isStatic(node) {
  4267. return !!(node.text || node.pre || !node.expression && // not text with interpolation
  4268. !node.if && !node.for && ( // not v-if or v-for or v-else
  4269. !node.tag || isPlatformReservedTag(node.tag)) && // not a component
  4270. !isBuiltInTag(node.tag) && ( // not a built-in
  4271. node.plain || Object.keys(node).every(isStaticKey)) // no dynamic bindings
  4272. );
  4273. }
  4274. var simplePathRE = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['.*?'\]|\[".*?"\]|\[\d+\]|\[[A-Za-z_$][\w$]*\])*$/;
  4275. // keyCode aliases
  4276. var keyCodes = {
  4277. esc: 27,
  4278. tab: 9,
  4279. enter: 13,
  4280. space: 32,
  4281. up: 38,
  4282. left: 37,
  4283. right: 39,
  4284. down: 40,
  4285. 'delete': [8, 46]
  4286. };
  4287. var modifierCode = {
  4288. stop: '$event.stopPropagation();',
  4289. prevent: '$event.preventDefault();',
  4290. self: 'if($event.target !== $event.currentTarget)return;'
  4291. };
  4292. function genHandlers(events) {
  4293. var res = 'on:{';
  4294. for (var name in events) {
  4295. res += '"' + name + '":' + genHandler(events[name]) + ',';
  4296. }
  4297. return res.slice(0, -1) + '}';
  4298. }
  4299. function genHandler(handler) {
  4300. if (!handler) {
  4301. return 'function(){}';
  4302. } else if (isArray(handler)) {
  4303. return '[' + handler.map(genHandler).join(',') + ']';
  4304. } else if (!handler.modifiers) {
  4305. return simplePathRE.test(handler.value) ? handler.value : 'function($event){' + handler.value + '}';
  4306. } else {
  4307. var code = 'function($event){';
  4308. for (var key in handler.modifiers) {
  4309. code += modifierCode[key] || genKeyFilter(key);
  4310. }
  4311. var handlerCode = simplePathRE.test(handler.value) ? handler.value + '($event)' : handler.value;
  4312. return code + handlerCode + '}';
  4313. }
  4314. }
  4315. function genKeyFilter(key) {
  4316. var code = keyCodes[key];
  4317. if (isArray(code)) {
  4318. return 'if(' + code.map(function (c) {
  4319. return '$event.keyCode!==' + c;
  4320. }).join('&&') + ')return;';
  4321. } else {
  4322. return 'if($event.keyCode!==' + code + ')return;';
  4323. }
  4324. }
  4325. function ref(el, dir) {
  4326. // go up and check if this node is inside a v-for
  4327. var isFor = false;
  4328. var parent = el;
  4329. while (parent) {
  4330. if (parent.for !== undefined) {
  4331. isFor = true;
  4332. }
  4333. parent = parent.parent;
  4334. }
  4335. // __registerRef__(name, ref, vFor?, remove?)
  4336. var code = '__registerRef__("' + dir.arg + '", n1.child || n1.elm, ' + (isFor ? 'true' : 'false');
  4337. addHook(el, 'insert', code + ')');
  4338. addHook(el, 'destroy', code + ', true)');
  4339. }
  4340. var baseDirectives = {
  4341. ref: ref,
  4342. cloak: function cloak() {} // noop
  4343. };
  4344. // platform-injected utils
  4345. var platformDirectives$1 = void 0;
  4346. var isPlatformReservedTag$1 = void 0;
  4347. // reset on each call
  4348. var staticRenderFns = void 0;
  4349. function generate(ast, options) {
  4350. staticRenderFns = [];
  4351. platformDirectives$1 = options.directives || {};
  4352. isPlatformReservedTag$1 = options.isReservedTag || function () {
  4353. return false;
  4354. };
  4355. var code = ast ? genElement(ast) : '__h__("div")';
  4356. return {
  4357. render: 'with (this) { return ' + code + '}',
  4358. staticRenderFns: staticRenderFns
  4359. };
  4360. }
  4361. function genElement(el) {
  4362. if (el.for) {
  4363. return genFor(el);
  4364. } else if (el.if) {
  4365. return genIf(el);
  4366. } else if (el.tag === 'template' && !el.slotTarget) {
  4367. return genChildren(el);
  4368. } else if (el.tag === 'render') {
  4369. return genRender(el);
  4370. } else if (el.tag === 'slot') {
  4371. return genSlot(el);
  4372. } else if (el.tag === 'component') {
  4373. return genComponent(el);
  4374. } else {
  4375. // if the element is potentially a component,
  4376. // wrap its children as a thunk.
  4377. var children = genChildren(el, !isPlatformReservedTag$1(el.tag) /* asThunk */);
  4378. var code = '__h__(\'' + el.tag + '\', ' + genData(el) + ', ' + children + ', \'' + (el.ns || '') + '\')';
  4379. if (el.staticRoot) {
  4380. // hoist static sub-trees out
  4381. staticRenderFns.push('with(this){return ' + code + '}');
  4382. return '_staticTrees[' + (staticRenderFns.length - 1) + ']';
  4383. } else {
  4384. return code;
  4385. }
  4386. }
  4387. }
  4388. function genIf(el) {
  4389. var exp = el.if;
  4390. el.if = false; // avoid recursion
  4391. return '(' + exp + ') ? ' + genElement(el) + ' : ' + genElse(el);
  4392. }
  4393. function genElse(el) {
  4394. return el.elseBlock ? genElement(el.elseBlock) : 'null';
  4395. }
  4396. function genFor(el) {
  4397. var exp = el.for;
  4398. var alias = el.alias;
  4399. var iterator = el.iterator;
  4400. el.for = false; // avoid recursion
  4401. return '(' + exp + ')&&__renderList__((' + exp + '), ' + ('function(' + alias + ',$index' + (iterator ? ',' + iterator : '') + '){') + ('return ' + genElement(el)) + '})';
  4402. }
  4403. function genData(el) {
  4404. if (el.plain) {
  4405. return 'undefined';
  4406. }
  4407. var data = '{';
  4408. // directives first.
  4409. // directives may mutate the el's other properties before they are generated.
  4410. if (el.directives) {
  4411. var dirs = genDirectives(el);
  4412. if (dirs) data += dirs + ',';
  4413. }
  4414. // pre
  4415. if (el.pre) {
  4416. data += 'pre:true,';
  4417. }
  4418. // key
  4419. if (el.key) {
  4420. data += 'key:' + el.key + ',';
  4421. }
  4422. // slot target
  4423. if (el.slotTarget) {
  4424. data += 'slot:' + el.slotTarget + ',';
  4425. }
  4426. // class
  4427. if (el.staticClass) {
  4428. data += 'staticClass:' + el.staticClass + ',';
  4429. }
  4430. if (el.classBinding) {
  4431. data += 'class:' + el.classBinding + ',';
  4432. }
  4433. // style
  4434. if (el.styleBinding) {
  4435. data += 'style:' + el.styleBinding + ',';
  4436. }
  4437. // transition
  4438. if (el.transition) {
  4439. data += 'transition:{definition:(' + el.transition + '),appear:' + el.transitionOnAppear + '},';
  4440. }
  4441. // v-show, used to avoid transition being applied
  4442. // since v-show takes it over
  4443. if (el.attrsMap['v-show'] || el.show) {
  4444. data += 'show:true,';
  4445. }
  4446. // props
  4447. if (el.props) {
  4448. data += 'props:{' + genProps(el.props) + '},';
  4449. }
  4450. // attributes
  4451. if (el.attrs) {
  4452. data += 'attrs:{' + genProps(el.attrs) + '},';
  4453. }
  4454. // static attributes
  4455. if (el.staticAttrs) {
  4456. data += 'staticAttrs:{' + genProps(el.staticAttrs) + '},';
  4457. }
  4458. // hooks
  4459. if (el.hooks) {
  4460. data += 'hook:{' + genHooks(el.hooks) + '},';
  4461. }
  4462. // event handlers
  4463. if (el.events) {
  4464. data += genHandlers(el.events);
  4465. }
  4466. return data.replace(/,$/, '') + '}';
  4467. }
  4468. function genDirectives(el) {
  4469. var dirs = el.directives;
  4470. var res = 'directives:[';
  4471. var hasRuntime = false;
  4472. var i = void 0,
  4473. l = void 0,
  4474. dir = void 0,
  4475. needRuntime = void 0;
  4476. for (i = 0, l = dirs.length; i < l; i++) {
  4477. dir = dirs[i];
  4478. needRuntime = true;
  4479. var gen = platformDirectives$1[dir.name] || baseDirectives[dir.name];
  4480. if (gen) {
  4481. // compile-time directive that manipulates AST.
  4482. // returns true if it also needs a runtime counterpart.
  4483. needRuntime = !!gen(el, dir);
  4484. }
  4485. if (needRuntime) {
  4486. hasRuntime = true;
  4487. res += '{name:"' + dir.name + '"' + (dir.value ? ',value:(' + dir.value + ')' : '') + (dir.arg ? ',arg:"' + dir.arg + '"' : '') + (dir.modifiers ? ',modifiers:' + JSON.stringify(dir.modifiers) : '') + '},';
  4488. }
  4489. }
  4490. if (hasRuntime) {
  4491. return res.slice(0, -1) + ']';
  4492. }
  4493. }
  4494. function genChildren(el, asThunk) {
  4495. if (!el.children.length) {
  4496. return 'undefined';
  4497. }
  4498. var code = '[' + el.children.map(genNode).join(',') + ']';
  4499. return asThunk ? 'function(){return ' + code + '}' : code;
  4500. }
  4501. function genNode(node) {
  4502. if (node.tag) {
  4503. return genElement(node);
  4504. } else {
  4505. return genText(node);
  4506. }
  4507. }
  4508. function genText(text) {
  4509. return text.expression ? '(' + text.expression + ')' : JSON.stringify(text.text);
  4510. }
  4511. function genRender(el) {
  4512. return el.renderMethod + '(' + (el.renderArgs || 'null') + ',' + genChildren(el) + ')';
  4513. }
  4514. function genSlot(el) {
  4515. var name = el.slotName || '"default"';
  4516. return '($slots[' + name + '] || ' + genChildren(el) + ')';
  4517. }
  4518. function genComponent(el) {
  4519. return '__h__(' + el.component + ', ' + genData(el) + ', ' + genChildren(el, true) + ')';
  4520. }
  4521. function genProps(props) {
  4522. var res = '';
  4523. for (var i = 0; i < props.length; i++) {
  4524. var prop = props[i];
  4525. res += '"' + prop.name + '":' + prop.value + ',';
  4526. }
  4527. return res.slice(0, -1);
  4528. }
  4529. function genHooks(hooks) {
  4530. var res = '';
  4531. for (var key in hooks) {
  4532. res += '"' + key + '":function(n1,n2){' + hooks[key].join(';') + '},';
  4533. }
  4534. return res.slice(0, -1);
  4535. }
  4536. /**
  4537. * Compile a template.
  4538. *
  4539. * @param {String} template
  4540. * @param {Object} options
  4541. * - warn
  4542. * - directives
  4543. * - isReservedTag
  4544. * - mustUseProp
  4545. * - getTagNamespace
  4546. */
  4547. function compile$1(template, options) {
  4548. var ast = parse(template.trim(), options);
  4549. optimize(ast, options);
  4550. return generate(ast, options);
  4551. }
  4552. function model$1(el, dir) {
  4553. var value = dir.value;
  4554. var modifiers = dir.modifiers;
  4555. if (el.tag === 'select') {
  4556. if (el.attrsMap.multiple != null) {
  4557. genMultiSelect(el, value);
  4558. } else {
  4559. genSelect(el, value);
  4560. }
  4561. } else {
  4562. switch (el.attrsMap.type) {
  4563. case 'checkbox':
  4564. genCheckboxModel(el, value);
  4565. break;
  4566. case 'radio':
  4567. genRadioModel(el, value);
  4568. break;
  4569. default:
  4570. return genDefaultModel(el, value, modifiers);
  4571. }
  4572. }
  4573. }
  4574. function genCheckboxModel(el, value) {
  4575. var valueBinding = getBindingAttr(el, 'value');
  4576. addProp(el, 'checked', 'Array.isArray(' + value + ')' + ('?(' + value + ').indexOf(' + valueBinding + ')>-1') + (':!!(' + value + ')'));
  4577. addHandler(el, 'change', 'var $$a=' + value + ',' + '$$el=$event.target,' + '$$c=$$el.checked;' + 'if(Array.isArray($$a)){' + ('var $$v=' + valueBinding + ',') + '$$i=$$a.indexOf($$v);' + 'if($$c){$$i<0&&$$a.push($$v)}' + 'else{$$i>-1&&$$a.splice($$i,1)}' + ('}else{' + value + '=$$c}'));
  4578. }
  4579. function genRadioModel(el, value) {
  4580. var valueBinding = getBindingAttr(el, 'value');
  4581. addProp(el, 'checked', '(' + value + '==' + valueBinding + ')');
  4582. addHandler(el, 'change', value + '=' + valueBinding);
  4583. }
  4584. function genDefaultModel(el, value, modifiers) {
  4585. var type = el.attrsMap.type;
  4586. var _ref = modifiers || {};
  4587. var lazy = _ref.lazy;
  4588. var number = _ref.number;
  4589. var trim = _ref.trim;
  4590. var event = lazy ? 'change' : 'input';
  4591. var needCompositionGuard = !lazy && type !== 'range';
  4592. var valueExpression = '$event.target.value' + (trim ? '.trim()' : '');
  4593. var code = number || type === 'number' ? value + '=Number(' + valueExpression + ')' : value + '=' + valueExpression;
  4594. if (needCompositionGuard) {
  4595. code = 'if($event.target.composing)return;' + code;
  4596. }
  4597. addProp(el, 'value', '(' + value + ')');
  4598. addHandler(el, event, code);
  4599. if (needCompositionGuard) {
  4600. // need runtime directive code to help with composition events
  4601. return true;
  4602. }
  4603. }
  4604. var getSelectedValueCode = 'Array.prototype.filter' + '.call($event.target.options,function(o){return o.selected})' + '.map(function(o){return "_value" in o ? o._value : o.value})';
  4605. function patchChildOptions(el, fn) {
  4606. for (var i = 0; i < el.children.length; i++) {
  4607. var c = el.children[i];
  4608. if (c.tag === 'option') {
  4609. addProp(c, 'selected', fn(getBindingAttr(c, 'value')));
  4610. }
  4611. }
  4612. }
  4613. function genSelect(el, value) {
  4614. addHandler(el, 'change', value + '=' + getSelectedValueCode + '[0]');
  4615. patchChildOptions(el, function (valueBinding) {
  4616. return '$(' + value + ')===(' + valueBinding + ')';
  4617. });
  4618. }
  4619. function genMultiSelect(el, value) {
  4620. addHandler(el, 'change', value + '=' + getSelectedValueCode);
  4621. patchChildOptions(el, function (valueBinding) {
  4622. return '$(' + value + ').indexOf(' + valueBinding + ')>-1';
  4623. });
  4624. }
  4625. function text(el, dir) {
  4626. if (!dir.value) return;
  4627. addProp(el, 'textContent', '__toString__(' + dir.value + ')');
  4628. }
  4629. function html(el, dir) {
  4630. if (!dir.value) return;
  4631. addProp(el, 'innerHTML', '__toString__(' + dir.value + ')');
  4632. }
  4633. var directives$1 = {
  4634. model: model$1,
  4635. text: text,
  4636. html: html
  4637. };
  4638. var cache1 = Object.create(null);
  4639. var cache2 = Object.create(null);
  4640. var baseOptions = {
  4641. expectHTML: true,
  4642. directives: directives$1,
  4643. isReservedTag: isReservedTag,
  4644. isUnaryTag: isUnaryTag,
  4645. mustUseProp: mustUseProp,
  4646. getTagNamespace: getTagNamespace
  4647. };
  4648. function compile(template, options) {
  4649. options = options ? extend(extend({}, baseOptions), options) : baseOptions;
  4650. return compile$1(template, options);
  4651. }
  4652. function compileToFunctions(template) {
  4653. var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
  4654. var preserveWhitespace = options.preserveWhitespace !== false;
  4655. var cache = preserveWhitespace ? cache1 : cache2;
  4656. if (cache[template]) {
  4657. return cache[template];
  4658. }
  4659. var res = {};
  4660. var compiled = compile(template, { preserveWhitespace: preserveWhitespace });
  4661. res.render = new Function(compiled.render);
  4662. var l = compiled.staticRenderFns.length;
  4663. if (l) {
  4664. res.staticRenderFns = new Array(l);
  4665. for (var i = 0; i < l; i++) {
  4666. res.staticRenderFns[i] = new Function(compiled.staticRenderFns[i]);
  4667. }
  4668. }
  4669. return cache[template] = res;
  4670. }
  4671. var idToTemplate = cached(function (id) {
  4672. return query(id).innerHTML;
  4673. });
  4674. var mount = Vue.prototype.$mount;
  4675. Vue.prototype.$mount = function (el) {
  4676. el = el && query(el);
  4677. var options = this.$options;
  4678. // resolve template/el and convert to render function
  4679. if (!options.render) {
  4680. var template = options.template;
  4681. if (template) {
  4682. if (typeof template === 'string') {
  4683. if (template.charAt(0) === '#') {
  4684. template = idToTemplate(template);
  4685. }
  4686. } else if (template.nodeType) {
  4687. template = template.innerHTML;
  4688. } else {
  4689. warn('invalid template option:' + template, this);
  4690. }
  4691. } else if (el) {
  4692. template = getOuterHTML(el);
  4693. }
  4694. if (template) {
  4695. var _compileToFunctions = compileToFunctions(template, {
  4696. preserveWhitespace: config.preserveWhitespace
  4697. });
  4698. var render = _compileToFunctions.render;
  4699. var staticRenderFns = _compileToFunctions.staticRenderFns;
  4700. options.render = render;
  4701. options.staticRenderFns = staticRenderFns;
  4702. }
  4703. }
  4704. mount.call(this, el);
  4705. };
  4706. /**
  4707. * Get outerHTML of elements, taking care
  4708. * of SVG elements in IE as well.
  4709. *
  4710. * @param {Element} el
  4711. * @return {String}
  4712. */
  4713. function getOuterHTML(el) {
  4714. if (el.outerHTML) {
  4715. return el.outerHTML;
  4716. } else {
  4717. var container = document.createElement('div');
  4718. container.appendChild(el.cloneNode(true));
  4719. return container.innerHTML;
  4720. }
  4721. }
  4722. Vue.compile = compileToFunctions;
  4723. return Vue;
  4724. }));