vue.common.js 98 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949
  1. 'use strict';
  2. /**
  3. * Convert a value to a string that is actually rendered.
  4. *
  5. * @param {*} val
  6. * @return {String}
  7. */
  8. function renderString(val) {
  9. return val == null ? '' : typeof val === 'object' ? JSON.stringify(val, null, 2) : String(val);
  10. }
  11. /**
  12. * Make a map and return a function for checking if a key
  13. * is in that map.
  14. *
  15. * @param {String} str
  16. * @param {Boolean} expectsLowerCase
  17. * @return {Function}
  18. */
  19. function makeMap(str, expectsLowerCase) {
  20. var map = Object.create(null);
  21. var list = str.split(',');
  22. for (var i = 0; i < list.length; i++) {
  23. map[list[i]] = true;
  24. }
  25. return expectsLowerCase ? function (val) {
  26. return map[val.toLowerCase()];
  27. } : function (val) {
  28. return map[val];
  29. };
  30. }
  31. /**
  32. * Check if a tag is a built-in tag.
  33. */
  34. var isBuiltInTag = makeMap('slot,component,render,transition', true);
  35. /**
  36. * Remove an item from an array
  37. *
  38. * @param {Array} arr
  39. * @param {*} item
  40. */
  41. function remove(arr, item) {
  42. if (arr.length) {
  43. var index = arr.indexOf(item);
  44. if (index > -1) {
  45. return arr.splice(index, 1);
  46. }
  47. }
  48. }
  49. /**
  50. * Check whether the object has the property.
  51. *
  52. * @param {Object} obj
  53. * @param {String} key
  54. * @return {Boolean}
  55. */
  56. var hasOwnProperty = Object.prototype.hasOwnProperty;
  57. function hasOwn(obj, key) {
  58. return hasOwnProperty.call(obj, key);
  59. }
  60. /**
  61. * Check if value is primitive
  62. *
  63. * @param {*} value
  64. * @return {Boolean}
  65. */
  66. function isPrimitive(value) {
  67. return typeof value === 'string' || typeof value === 'number';
  68. }
  69. /**
  70. * Create a cached version of a pure function.
  71. *
  72. * @param {Function} fn
  73. * @return {Function}
  74. */
  75. function cached(fn) {
  76. var cache = Object.create(null);
  77. return function cachedFn(str) {
  78. var hit = cache[str];
  79. return hit || (cache[str] = fn(str));
  80. };
  81. }
  82. /**
  83. * Camelize a hyphen-delmited string.
  84. *
  85. * @param {String} str
  86. * @return {String}
  87. */
  88. var camelizeRE = /-(\w)/g;
  89. var camelize = cached(function (str) {
  90. return str.replace(camelizeRE, toUpper);
  91. });
  92. function toUpper(_, c) {
  93. return c ? c.toUpperCase() : '';
  94. }
  95. /**
  96. * Hyphenate a camelCase string.
  97. *
  98. * @param {String} str
  99. * @return {String}
  100. */
  101. var hyphenateRE = /([a-z\d])([A-Z])/g;
  102. var hyphenate = cached(function (str) {
  103. return str.replace(hyphenateRE, '$1-$2').toLowerCase();
  104. });
  105. /**
  106. * Simple bind, faster than native
  107. *
  108. * @param {Function} fn
  109. * @param {Object} ctx
  110. * @return {Function}
  111. */
  112. function bind(fn, ctx) {
  113. return function (a) {
  114. var l = arguments.length;
  115. return l ? l > 1 ? fn.apply(ctx, arguments) : fn.call(ctx, a) : fn.call(ctx);
  116. };
  117. }
  118. /**
  119. * Convert an Array-like object to a real Array.
  120. *
  121. * @param {Array-like} list
  122. * @param {Number} [start] - start index
  123. * @return {Array}
  124. */
  125. function toArray(list, start) {
  126. start = start || 0;
  127. var i = list.length - start;
  128. var ret = new Array(i);
  129. while (i--) {
  130. ret[i] = list[i + start];
  131. }
  132. return ret;
  133. }
  134. /**
  135. * Mix properties into target object.
  136. *
  137. * @param {Object} to
  138. * @param {Object} from
  139. */
  140. function extend(to, from) {
  141. for (var key in from) {
  142. to[key] = from[key];
  143. }
  144. return to;
  145. }
  146. /**
  147. * Quick object check - this is primarily used to tell
  148. * Objects from primitive values when we know the value
  149. * is a JSON-compliant type.
  150. *
  151. * @param {*} obj
  152. * @return {Boolean}
  153. */
  154. function isObject(obj) {
  155. return obj !== null && typeof obj === 'object';
  156. }
  157. /**
  158. * Strict object type check. Only returns true
  159. * for plain JavaScript objects.
  160. *
  161. * @param {*} obj
  162. * @return {Boolean}
  163. */
  164. var toString = Object.prototype.toString;
  165. var OBJECT_STRING = '[object Object]';
  166. function isPlainObject(obj) {
  167. return toString.call(obj) === OBJECT_STRING;
  168. }
  169. /**
  170. * Array type check.
  171. *
  172. * @param {*} obj
  173. * @return {Boolean}
  174. */
  175. var isArray = Array.isArray;
  176. /**
  177. * Check if a string starts with $ or _
  178. *
  179. * @param {String} str
  180. * @return {Boolean}
  181. */
  182. function isReserved(str) {
  183. var c = (str + '').charCodeAt(0);
  184. return c === 0x24 || c === 0x5F;
  185. }
  186. /**
  187. * Define a property.
  188. *
  189. * @param {Object} obj
  190. * @param {String} key
  191. * @param {*} val
  192. * @param {Boolean} [enumerable]
  193. */
  194. function def(obj, key, val, enumerable) {
  195. Object.defineProperty(obj, key, {
  196. value: val,
  197. enumerable: !!enumerable,
  198. writable: true,
  199. configurable: true
  200. });
  201. }
  202. /**
  203. * Parse simple path.
  204. */
  205. var bailRE = /[^\w\.]/;
  206. function parsePath(path) {
  207. if (bailRE.test(path)) {
  208. return;
  209. } else {
  210. path = path.split('.');
  211. return function (obj) {
  212. for (var i = 0; i < path.length; i++) {
  213. if (!obj) return;
  214. obj = obj[path[i]];
  215. }
  216. return obj;
  217. };
  218. }
  219. }
  220. /* global MutationObserver */
  221. // can we use __proto__?
  222. var hasProto = '__proto__' in {};
  223. // Browser environment sniffing
  224. var inBrowser = typeof window !== 'undefined' && Object.prototype.toString.call(window) !== '[object Object]';
  225. // detect devtools
  226. var devtools = inBrowser && window.__VUE_DEVTOOLS_GLOBAL_HOOK__;
  227. // UA sniffing for working around browser-specific quirks
  228. var UA = inBrowser && window.navigator.userAgent.toLowerCase();
  229. var isIos = UA && /(iphone|ipad|ipod|ios)/i.test(UA);
  230. var isWechat = UA && UA.indexOf('micromessenger') > 0;
  231. /**
  232. * Defer a task to execute it asynchronously. Ideally this
  233. * should be executed as a microtask, so we leverage
  234. * MutationObserver if it's available, and fallback to
  235. * setTimeout(0).
  236. *
  237. * @param {Function} cb
  238. * @param {Object} ctx
  239. */
  240. var nextTick = function () {
  241. var callbacks = [];
  242. var pending = false;
  243. var timerFunc;
  244. function nextTickHandler() {
  245. pending = false;
  246. var copies = callbacks.slice(0);
  247. callbacks = [];
  248. for (var i = 0; i < copies.length; i++) {
  249. copies[i]();
  250. }
  251. }
  252. /* istanbul ignore if */
  253. if (typeof MutationObserver !== 'undefined' && !(isWechat && isIos)) {
  254. var counter = 1;
  255. var observer = new MutationObserver(nextTickHandler);
  256. var textNode = document.createTextNode(counter);
  257. observer.observe(textNode, {
  258. characterData: true
  259. });
  260. timerFunc = function timerFunc() {
  261. counter = (counter + 1) % 2;
  262. textNode.data = counter;
  263. };
  264. } else {
  265. // webpack attempts to inject a shim for setImmediate
  266. // if it is used as a global, so we have to work around that to
  267. // avoid bundling unnecessary code.
  268. var context = inBrowser ? window : typeof global !== 'undefined' ? global : {};
  269. timerFunc = context.setImmediate || setTimeout;
  270. }
  271. return function (cb, ctx) {
  272. var func = ctx ? function () {
  273. cb.call(ctx);
  274. } : cb;
  275. callbacks.push(func);
  276. if (pending) return;
  277. pending = true;
  278. timerFunc(nextTickHandler, 0);
  279. };
  280. }();
  281. var _Set = void 0;
  282. /* istanbul ignore if */
  283. if (typeof Set !== 'undefined' && Set.toString().match(/native code/)) {
  284. // use native Set when available.
  285. _Set = Set;
  286. } else {
  287. // a non-standard Set polyfill that only works with primitive keys.
  288. _Set = function _Set() {
  289. this.set = Object.create(null);
  290. };
  291. _Set.prototype.has = function (key) {
  292. return this.set[key] !== undefined;
  293. };
  294. _Set.prototype.add = function (key) {
  295. this.set[key] = 1;
  296. };
  297. _Set.prototype.clear = function () {
  298. this.set = Object.create(null);
  299. };
  300. }
  301. var config = {
  302. /**
  303. * Preserve whitespaces between elements.
  304. */
  305. preserveWhitespace: true,
  306. /**
  307. * Whether to suppress warnings.
  308. *
  309. * @type {Boolean}
  310. */
  311. silent: false,
  312. /**
  313. * Check if a tag is reserved so that it cannot be registered as a
  314. * component. This is platform-dependent and may be overwritten.
  315. */
  316. isReservedTag: function isReservedTag() {
  317. return false;
  318. },
  319. /**
  320. * Check if a tag is an unknown element.
  321. * Platform-dependent.
  322. */
  323. isUnknownElement: function isUnknownElement() {
  324. return false;
  325. },
  326. /**
  327. * List of asset types that a component can own.
  328. *
  329. * @type {Array}
  330. */
  331. _assetTypes: ['component', 'directive', 'transition'],
  332. /**
  333. * List of lifecycle hooks.
  334. *
  335. * @type {Array}
  336. */
  337. _lifecycleHooks: ['init', 'created', 'beforeMount', 'mounted', 'ready', 'beforeUpdate', 'updated', 'beforeDestroy', 'destroyed'],
  338. /**
  339. * Max circular updates allowed in a batcher flush cycle.
  340. */
  341. _maxUpdateCount: 100
  342. };
  343. var warn = void 0;
  344. var formatComponentName = void 0;
  345. if (process.env.NODE_ENV !== 'production') {
  346. (function () {
  347. var hasConsole = typeof console !== 'undefined';
  348. warn = function warn(msg, vm) {
  349. if (hasConsole && !config.silent) {
  350. console.error('[Vue warn]: ' + msg + (vm ? formatComponentName(vm) : ''));
  351. }
  352. };
  353. formatComponentName = function formatComponentName(vm) {
  354. var name = vm._isVue ? vm.$options.name : vm.name;
  355. return name ? ' (found in component: <' + hyphenate(name) + '>)' : '';
  356. };
  357. })();
  358. }
  359. var uid$1 = 0;
  360. /**
  361. * A dep is an observable that can have multiple
  362. * directives subscribing to it.
  363. *
  364. * @constructor
  365. */
  366. function Dep() {
  367. this.id = uid$1++;
  368. this.subs = [];
  369. }
  370. // the current target watcher being evaluated.
  371. // this is globally unique because there could be only one
  372. // watcher being evaluated at any time.
  373. Dep.target = null;
  374. /**
  375. * Add a directive subscriber.
  376. *
  377. * @param {Directive} sub
  378. */
  379. Dep.prototype.addSub = function (sub) {
  380. this.subs.push(sub);
  381. };
  382. /**
  383. * Remove a directive subscriber.
  384. *
  385. * @param {Directive} sub
  386. */
  387. Dep.prototype.removeSub = function (sub) {
  388. remove(this.subs, sub);
  389. };
  390. /**
  391. * Add self as a dependency to the target watcher.
  392. */
  393. Dep.prototype.depend = function () {
  394. Dep.target.addDep(this);
  395. };
  396. /**
  397. * Notify all subscribers of a new value.
  398. */
  399. Dep.prototype.notify = function () {
  400. // stablize the subscriber list first
  401. var subs = this.subs.slice();
  402. for (var i = 0, l = subs.length; i < l; i++) {
  403. subs[i].update();
  404. }
  405. };
  406. var arrayProto = Array.prototype;
  407. var arrayMethods = Object.create(arrayProto)
  408. /**
  409. * Intercept mutating methods and emit events
  410. */
  411. ;['push', 'pop', 'shift', 'unshift', 'splice', 'sort', 'reverse'].forEach(function (method) {
  412. // cache original method
  413. var original = arrayProto[method];
  414. def(arrayMethods, method, function mutator() {
  415. // avoid leaking arguments:
  416. // http://jsperf.com/closure-with-arguments
  417. var i = arguments.length;
  418. var args = new Array(i);
  419. while (i--) {
  420. args[i] = arguments[i];
  421. }
  422. var result = original.apply(this, args);
  423. var ob = this.__ob__;
  424. var inserted;
  425. switch (method) {
  426. case 'push':
  427. inserted = args;
  428. break;
  429. case 'unshift':
  430. inserted = args;
  431. break;
  432. case 'splice':
  433. inserted = args.slice(2);
  434. break;
  435. }
  436. if (inserted) ob.observeArray(inserted);
  437. // notify change
  438. ob.dep.notify();
  439. return result;
  440. });
  441. });
  442. var arrayKeys = Object.getOwnPropertyNames(arrayMethods);
  443. /**
  444. * By default, when a reactive property is set, the new value is
  445. * also converted to become reactive. However when passing down props,
  446. * we don't want to force conversion because the value may be a nested value
  447. * under a frozen data structure. Converting it would defeat the optimization.
  448. */
  449. var observerState = {
  450. shouldConvert: true
  451. };
  452. /**
  453. * Observer class that are attached to each observed
  454. * object. Once attached, the observer converts target
  455. * object's property keys into getter/setters that
  456. * collect dependencies and dispatches updates.
  457. *
  458. * @param {Array|Object} value
  459. * @constructor
  460. */
  461. function Observer(value) {
  462. this.value = value;
  463. this.dep = new Dep();
  464. def(value, '__ob__', this);
  465. if (isArray(value)) {
  466. var augment = hasProto ? protoAugment : copyAugment;
  467. augment(value, arrayMethods, arrayKeys);
  468. this.observeArray(value);
  469. } else {
  470. this.walk(value);
  471. }
  472. }
  473. // Instance methods
  474. /**
  475. * Walk through each property and convert them into
  476. * getter/setters. This method should only be called when
  477. * value type is Object.
  478. *
  479. * @param {Object} obj
  480. */
  481. Observer.prototype.walk = function (obj) {
  482. for (var key in obj) {
  483. this.convert(key, obj[key]);
  484. }
  485. };
  486. /**
  487. * Observe a list of Array items.
  488. *
  489. * @param {Array} items
  490. */
  491. Observer.prototype.observeArray = function (items) {
  492. for (var i = 0, l = items.length; i < l; i++) {
  493. observe(items[i]);
  494. }
  495. };
  496. /**
  497. * Convert a property into getter/setter so we can emit
  498. * the events when the property is accessed/changed.
  499. *
  500. * @param {String} key
  501. * @param {*} val
  502. */
  503. Observer.prototype.convert = function (key, val) {
  504. defineReactive(this.value, key, val);
  505. };
  506. /**
  507. * Add an owner vm, so that when $set/$delete mutations
  508. * happen we can notify owner vms to proxy the keys and
  509. * digest the watchers. This is only called when the object
  510. * is observed as an instance's root $data.
  511. *
  512. * @param {Vue} vm
  513. */
  514. Observer.prototype.addVm = function (vm) {
  515. (this.vms || (this.vms = [])).push(vm);
  516. };
  517. /**
  518. * Remove an owner vm. This is called when the object is
  519. * swapped out as an instance's $data object.
  520. *
  521. * @param {Vue} vm
  522. */
  523. Observer.prototype.removeVm = function (vm) {
  524. remove(this.vms, vm);
  525. };
  526. // helpers
  527. /**
  528. * Augment an target Object or Array by intercepting
  529. * the prototype chain using __proto__
  530. *
  531. * @param {Object|Array} target
  532. * @param {Object} src
  533. */
  534. function protoAugment(target, src) {
  535. /* eslint-disable no-proto */
  536. target.__proto__ = src;
  537. /* eslint-enable no-proto */
  538. }
  539. /**
  540. * Augment an target Object or Array by defining
  541. * hidden properties.
  542. *
  543. * @param {Object|Array} target
  544. * @param {Object} proto
  545. */
  546. function copyAugment(target, src, keys) {
  547. for (var i = 0, l = keys.length; i < l; i++) {
  548. var key = keys[i];
  549. def(target, key, src[key]);
  550. }
  551. }
  552. /**
  553. * Attempt to create an observer instance for a value,
  554. * returns the new observer if successfully observed,
  555. * or the existing observer if the value already has one.
  556. *
  557. * @param {*} value
  558. * @param {Vue} [vm]
  559. * @return {Observer|undefined}
  560. * @static
  561. */
  562. function observe(value, vm) {
  563. if (!isObject(value)) {
  564. return;
  565. }
  566. var ob;
  567. if (hasOwn(value, '__ob__') && value.__ob__ instanceof Observer) {
  568. ob = value.__ob__;
  569. } else if (observerState.shouldConvert && (isArray(value) || isPlainObject(value)) && Object.isExtensible(value) && !value._isVue) {
  570. ob = new Observer(value);
  571. }
  572. if (ob && vm) {
  573. ob.addVm(vm);
  574. }
  575. return ob;
  576. }
  577. /**
  578. * Define a reactive property on an Object.
  579. *
  580. * @param {Object} obj
  581. * @param {String} key
  582. * @param {*} val
  583. */
  584. function defineReactive(obj, key, val) {
  585. var dep = new Dep();
  586. var property = Object.getOwnPropertyDescriptor(obj, key);
  587. if (property && property.configurable === false) {
  588. return;
  589. }
  590. // cater for pre-defined getter/setters
  591. var getter = property && property.get;
  592. var setter = property && property.set;
  593. var childOb = observe(val);
  594. Object.defineProperty(obj, key, {
  595. enumerable: true,
  596. configurable: true,
  597. get: function reactiveGetter() {
  598. var value = getter ? getter.call(obj) : val;
  599. if (Dep.target) {
  600. dep.depend();
  601. if (childOb) {
  602. childOb.dep.depend();
  603. }
  604. if (isArray(value)) {
  605. for (var e, i = 0, l = value.length; i < l; i++) {
  606. e = value[i];
  607. e && e.__ob__ && e.__ob__.dep.depend();
  608. }
  609. }
  610. }
  611. return value;
  612. },
  613. set: function reactiveSetter(newVal) {
  614. var value = getter ? getter.call(obj) : val;
  615. if (newVal === value) {
  616. return;
  617. }
  618. if (setter) {
  619. setter.call(obj, newVal);
  620. } else {
  621. val = newVal;
  622. }
  623. childOb = observe(newVal);
  624. dep.notify();
  625. }
  626. });
  627. }
  628. /**
  629. * Set a property on an object. Adds the new property and
  630. * triggers change notification if the property doesn't
  631. * already exist.
  632. *
  633. * @param {Object} obj
  634. * @param {String} key
  635. * @param {*} val
  636. * @public
  637. */
  638. function set(obj, key, val) {
  639. if (isArray(obj)) {
  640. return obj.splice(key, 1, val);
  641. }
  642. if (hasOwn(obj, key)) {
  643. obj[key] = val;
  644. return;
  645. }
  646. if (obj._isVue) {
  647. set(obj._data, key, val);
  648. return;
  649. }
  650. var ob = obj.__ob__;
  651. if (!ob) {
  652. obj[key] = val;
  653. return;
  654. }
  655. ob.convert(key, val);
  656. ob.dep.notify();
  657. if (ob.vms) {
  658. var i = ob.vms.length;
  659. while (i--) {
  660. var vm = ob.vms[i];
  661. proxy(vm, key);
  662. vm.$forceUpdate();
  663. }
  664. }
  665. return val;
  666. }
  667. /**
  668. * Delete a property and trigger change if necessary.
  669. *
  670. * @param {Object} obj
  671. * @param {String} key
  672. */
  673. function del(obj, key) {
  674. if (!hasOwn(obj, key)) {
  675. return;
  676. }
  677. delete obj[key];
  678. var ob = obj.__ob__;
  679. if (!ob) {
  680. if (obj._isVue) {
  681. delete obj._data[key];
  682. obj.$forceUpdate();
  683. }
  684. return;
  685. }
  686. ob.dep.notify();
  687. if (ob.vms) {
  688. var i = ob.vms.length;
  689. while (i--) {
  690. var vm = ob.vms[i];
  691. unproxy(vm, key);
  692. vm.$forceUpdate();
  693. }
  694. }
  695. }
  696. function proxy(vm, key) {
  697. if (!isReserved(key)) {
  698. Object.defineProperty(vm, key, {
  699. configurable: true,
  700. enumerable: true,
  701. get: function proxyGetter() {
  702. return vm._data[key];
  703. },
  704. set: function proxySetter(val) {
  705. vm._data[key] = val;
  706. }
  707. });
  708. }
  709. }
  710. function unproxy(vm, key) {
  711. if (!isReserved(key)) {
  712. delete vm[key];
  713. }
  714. }
  715. /**
  716. * Option overwriting strategies are functions that handle
  717. * how to merge a parent option value and a child option
  718. * value into the final value.
  719. *
  720. * All strategy functions follow the same signature:
  721. *
  722. * @param {*} parentVal
  723. * @param {*} childVal
  724. * @param {Vue} [vm]
  725. */
  726. var strats = config.optionMergeStrategies = Object.create(null);
  727. /**
  728. * Helper that recursively merges two data objects together.
  729. */
  730. function mergeData(to, from) {
  731. var key, toVal, fromVal;
  732. for (key in from) {
  733. toVal = to[key];
  734. fromVal = from[key];
  735. if (!hasOwn(to, key)) {
  736. set(to, key, fromVal);
  737. } else if (isObject(toVal) && isObject(fromVal)) {
  738. mergeData(toVal, fromVal);
  739. }
  740. }
  741. return to;
  742. }
  743. /**
  744. * Data
  745. */
  746. strats.data = function (parentVal, childVal, vm) {
  747. if (!vm) {
  748. // in a Vue.extend merge, both should be functions
  749. if (!childVal) {
  750. return parentVal;
  751. }
  752. if (typeof childVal !== 'function') {
  753. process.env.NODE_ENV !== 'production' && warn('The "data" option should be a function ' + 'that returns a per-instance value in component ' + 'definitions.', vm);
  754. return parentVal;
  755. }
  756. if (!parentVal) {
  757. return childVal;
  758. }
  759. // when parentVal & childVal are both present,
  760. // we need to return a function that returns the
  761. // merged result of both functions... no need to
  762. // check if parentVal is a function here because
  763. // it has to be a function to pass previous merges.
  764. return function mergedDataFn() {
  765. return mergeData(childVal.call(this), parentVal.call(this));
  766. };
  767. } else if (parentVal || childVal) {
  768. return function mergedInstanceDataFn() {
  769. // instance merge
  770. var instanceData = typeof childVal === 'function' ? childVal.call(vm) : childVal;
  771. var defaultData = typeof parentVal === 'function' ? parentVal.call(vm) : undefined;
  772. if (instanceData) {
  773. return mergeData(instanceData, defaultData);
  774. } else {
  775. return defaultData;
  776. }
  777. };
  778. }
  779. };
  780. /**
  781. * El
  782. */
  783. strats.el = function (parentVal, childVal, vm) {
  784. if (!vm && childVal && typeof childVal !== 'function') {
  785. process.env.NODE_ENV !== 'production' && warn('The "el" option should be a function ' + 'that returns a per-instance value in component ' + 'definitions.', vm);
  786. return;
  787. }
  788. var ret = childVal || parentVal;
  789. // invoke the element factory if this is instance merge
  790. return vm && typeof ret === 'function' ? ret.call(vm) : ret;
  791. };
  792. /**
  793. * Hooks and param attributes are merged as arrays.
  794. */
  795. function mergeHook(parentVal, childVal) {
  796. return childVal ? parentVal ? parentVal.concat(childVal) : isArray(childVal) ? childVal : [childVal] : parentVal;
  797. }
  798. config._lifecycleHooks.forEach(function (hook) {
  799. strats[hook] = mergeHook;
  800. });
  801. /**
  802. * Assets
  803. *
  804. * When a vm is present (instance creation), we need to do
  805. * a three-way merge between constructor options, instance
  806. * options and parent options.
  807. */
  808. function mergeAssets(parentVal, childVal) {
  809. var res = Object.create(parentVal);
  810. return childVal ? extend(res, childVal) : res;
  811. }
  812. config._assetTypes.forEach(function (type) {
  813. strats[type + 's'] = mergeAssets;
  814. });
  815. /**
  816. * Watchers.
  817. *
  818. * Watchers hashes should not overwrite one
  819. * another, so we merge them as arrays.
  820. */
  821. strats.watch = function (parentVal, childVal) {
  822. if (!childVal) return parentVal;
  823. if (!parentVal) return childVal;
  824. var ret = {};
  825. extend(ret, parentVal);
  826. for (var key in childVal) {
  827. var parent = ret[key];
  828. var child = childVal[key];
  829. if (parent && !isArray(parent)) {
  830. parent = [parent];
  831. }
  832. ret[key] = parent ? parent.concat(child) : [child];
  833. }
  834. return ret;
  835. };
  836. /**
  837. * Other object hashes.
  838. */
  839. strats.props = strats.methods = strats.computed = function (parentVal, childVal) {
  840. if (!childVal) return parentVal;
  841. if (!parentVal) return childVal;
  842. var ret = Object.create(null);
  843. extend(ret, parentVal);
  844. extend(ret, childVal);
  845. return ret;
  846. };
  847. /**
  848. * Default strategy.
  849. */
  850. var defaultStrat = function defaultStrat(parentVal, childVal) {
  851. return childVal === undefined ? parentVal : childVal;
  852. };
  853. /**
  854. * Make sure component options get converted to actual
  855. * constructors.
  856. *
  857. * @param {Object} options
  858. */
  859. function guardComponents(options) {
  860. if (options.components) {
  861. var components = options.components;
  862. var def;
  863. for (var key in components) {
  864. if (isBuiltInTag(key) || config.isReservedTag(key)) {
  865. process.env.NODE_ENV !== 'production' && warn('Do not use built-in or reserved HTML elements as component ' + 'id: ' + key);
  866. continue;
  867. }
  868. def = components[key];
  869. if (isPlainObject(def)) {
  870. components[key] = Vue.extend(def);
  871. }
  872. }
  873. }
  874. }
  875. /**
  876. * Ensure all props option syntax are normalized into the
  877. * Object-based format.
  878. *
  879. * @param {Object} options
  880. */
  881. function guardProps(options) {
  882. var props = options.props;
  883. if (!props) return;
  884. var res = {};
  885. var i = void 0,
  886. val = void 0,
  887. name = void 0;
  888. if (isArray(props)) {
  889. i = props.length;
  890. while (i--) {
  891. val = props[i];
  892. if (typeof val === 'string') {
  893. name = camelize(val);
  894. res[name] = { type: null };
  895. } else if (process.env.NODE_ENV !== 'production') {
  896. warn('props must be strings when using array syntax.');
  897. }
  898. }
  899. } else if (isPlainObject(props)) {
  900. for (var key in props) {
  901. val = props[key];
  902. name = camelize(key);
  903. res[name] = isPlainObject(val) ? val : { type: val };
  904. }
  905. }
  906. options.props = res;
  907. }
  908. function guardDirectives(options) {
  909. var dirs = options.directives;
  910. if (dirs) {
  911. for (var key in dirs) {
  912. if (typeof dirs[key] === 'function') {
  913. dirs[key] = { update: dirs[key] };
  914. }
  915. }
  916. }
  917. }
  918. /**
  919. * Merge two option objects into a new one.
  920. * Core utility used in both instantiation and inheritance.
  921. *
  922. * @param {Object} parent
  923. * @param {Object} child
  924. * @param {Vue} [vm] - if vm is present, indicates this is
  925. * an instantiation merge.
  926. */
  927. function mergeOptions(parent, child, vm) {
  928. guardComponents(child);
  929. guardProps(child);
  930. guardDirectives(child);
  931. if (process.env.NODE_ENV !== 'production') {
  932. if (child.propsData && !vm) {
  933. warn('propsData can only be used as an instantiation option.');
  934. }
  935. }
  936. var options = {};
  937. var key;
  938. if (child.mixins) {
  939. for (var i = 0, l = child.mixins.length; i < l; i++) {
  940. parent = mergeOptions(parent, child.mixins[i], vm);
  941. }
  942. }
  943. for (key in parent) {
  944. mergeField(key);
  945. }
  946. for (key in child) {
  947. if (!hasOwn(parent, key)) {
  948. mergeField(key);
  949. }
  950. }
  951. function mergeField(key) {
  952. var strat = strats[key] || defaultStrat;
  953. options[key] = strat(parent[key], child[key], vm, key);
  954. }
  955. return options;
  956. }
  957. /**
  958. * Resolve an asset.
  959. * This function is used because child instances need access
  960. * to assets defined in its ancestor chain.
  961. *
  962. * @param {Object} options
  963. * @param {String} type
  964. * @param {String} id
  965. * @param {Boolean} warnMissing
  966. * @return {Object|Function}
  967. */
  968. function resolveAsset(options, type, id, warnMissing) {
  969. /* istanbul ignore if */
  970. if (typeof id !== 'string') {
  971. return;
  972. }
  973. var assets = options[type];
  974. var camelizedId;
  975. var res = assets[id] ||
  976. // camelCase ID
  977. assets[camelizedId = camelize(id)] ||
  978. // Pascal Case ID
  979. assets[camelizedId.charAt(0).toUpperCase() + camelizedId.slice(1)];
  980. if (process.env.NODE_ENV !== 'production' && warnMissing && !res) {
  981. warn('Failed to resolve ' + type.slice(0, -1) + ': ' + id, options);
  982. }
  983. return res;
  984. }
  985. function validateProp(vm, key, propsData) {
  986. if (!propsData) return;
  987. var prop = vm.$options.props[key];
  988. var absent = hasOwn(propsData, key);
  989. var value = propsData[key];
  990. // check default value
  991. if (value === undefined) {
  992. value = getPropDefaultValue(vm, prop, key);
  993. // since the default value is a fresh copy,
  994. // make sure to observe it.
  995. observerState.shouldConvert = true;
  996. observe(value);
  997. observerState.shouldConvert = false;
  998. }
  999. if (process.env.NODE_ENV !== 'production') {
  1000. assertProp(prop, key, value, vm, absent);
  1001. }
  1002. return value;
  1003. }
  1004. /**
  1005. * Get the default value of a prop.
  1006. *
  1007. * @param {Vue} vm
  1008. * @param {Object} prop
  1009. * @return {*}
  1010. */
  1011. function getPropDefaultValue(vm, prop, name) {
  1012. // no default, return undefined
  1013. if (!hasOwn(prop, 'default')) {
  1014. // absent boolean value defaults to false
  1015. return prop.type === Boolean ? false : undefined;
  1016. }
  1017. var def = prop.default;
  1018. // warn against non-factory defaults for Object & Array
  1019. if (isObject(def)) {
  1020. process.env.NODE_ENV !== 'production' && warn('Invalid default value for prop "' + name + '": ' + 'Props with type Object/Array must use a factory function ' + 'to return the default value.', vm);
  1021. }
  1022. // call factory function for non-Function types
  1023. return typeof def === 'function' && prop.type !== Function ? def.call(vm) : def;
  1024. }
  1025. /**
  1026. * Assert whether a prop is valid.
  1027. *
  1028. * @param {Object} prop
  1029. * @param {String} name
  1030. * @param {*} value
  1031. * @param {Vue} vm
  1032. * @param {Boolean} absent
  1033. */
  1034. function assertProp(prop, name, value, vm, absent) {
  1035. if (prop.required && absent) {
  1036. process.env.NODE_ENV !== 'production' && warn('Missing required prop: "' + name + '"', vm);
  1037. return false;
  1038. }
  1039. if (value == null) {
  1040. return true;
  1041. }
  1042. var type = prop.type;
  1043. var valid = !type;
  1044. var expectedTypes = [];
  1045. if (type) {
  1046. if (!isArray(type)) {
  1047. type = [type];
  1048. }
  1049. for (var i = 0; i < type.length && !valid; i++) {
  1050. var assertedType = assertType(value, type[i]);
  1051. expectedTypes.push(assertedType.expectedType);
  1052. valid = assertedType.valid;
  1053. }
  1054. }
  1055. if (!valid) {
  1056. if (process.env.NODE_ENV !== 'production') {
  1057. warn('Invalid prop: type check failed for prop "' + name + '".' + ' Expected ' + expectedTypes.map(formatType).join(', ') + ', got ' + formatValue(value) + '.', vm);
  1058. }
  1059. return false;
  1060. }
  1061. var validator = prop.validator;
  1062. if (validator) {
  1063. if (!validator(value)) {
  1064. process.env.NODE_ENV !== 'production' && warn('Invalid prop: custom validator check failed for prop "' + name + '".', vm);
  1065. return false;
  1066. }
  1067. }
  1068. return true;
  1069. }
  1070. /**
  1071. * Assert the type of a value
  1072. *
  1073. * @param {*} value
  1074. * @param {Function} type
  1075. * @return {Object}
  1076. */
  1077. function assertType(value, type) {
  1078. var valid;
  1079. var expectedType;
  1080. if (type === String) {
  1081. expectedType = 'string';
  1082. valid = typeof value === expectedType;
  1083. } else if (type === Number) {
  1084. expectedType = 'number';
  1085. valid = typeof value === expectedType;
  1086. } else if (type === Boolean) {
  1087. expectedType = 'boolean';
  1088. valid = typeof value === expectedType;
  1089. } else if (type === Function) {
  1090. expectedType = 'function';
  1091. valid = typeof value === expectedType;
  1092. } else if (type === Object) {
  1093. expectedType = 'object';
  1094. valid = isPlainObject(value);
  1095. } else if (type === Array) {
  1096. expectedType = 'array';
  1097. valid = isArray(value);
  1098. } else {
  1099. valid = value instanceof type;
  1100. }
  1101. return {
  1102. valid: valid,
  1103. expectedType: expectedType
  1104. };
  1105. }
  1106. /**
  1107. * Format type for output
  1108. *
  1109. * @param {String} type
  1110. * @return {String}
  1111. */
  1112. function formatType(type) {
  1113. return type ? type.charAt(0).toUpperCase() + type.slice(1) : 'custom type';
  1114. }
  1115. /**
  1116. * Format value
  1117. *
  1118. * @param {*} value
  1119. * @return {String}
  1120. */
  1121. function formatValue(val) {
  1122. return Object.prototype.toString.call(val).slice(8, -1);
  1123. }
  1124. var util = Object.freeze({
  1125. defineReactive: defineReactive,
  1126. renderString: renderString,
  1127. makeMap: makeMap,
  1128. isBuiltInTag: isBuiltInTag,
  1129. remove: remove,
  1130. hasOwn: hasOwn,
  1131. isPrimitive: isPrimitive,
  1132. cached: cached,
  1133. camelize: camelize,
  1134. hyphenate: hyphenate,
  1135. bind: bind,
  1136. toArray: toArray,
  1137. extend: extend,
  1138. isObject: isObject,
  1139. isPlainObject: isPlainObject,
  1140. isArray: isArray,
  1141. isReserved: isReserved,
  1142. def: def,
  1143. parsePath: parsePath,
  1144. hasProto: hasProto,
  1145. inBrowser: inBrowser,
  1146. devtools: devtools,
  1147. nextTick: nextTick,
  1148. get _Set () { return _Set; },
  1149. mergeOptions: mergeOptions,
  1150. resolveAsset: resolveAsset,
  1151. get warn () { return warn; },
  1152. validateProp: validateProp
  1153. });
  1154. var hasProxy = void 0;
  1155. var proxyHandlers = void 0;
  1156. var initProxy = void 0;
  1157. if (process.env.NODE_ENV !== 'production') {
  1158. (function () {
  1159. 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');
  1160. hasProxy = typeof Proxy !== 'undefined' && Proxy.toString().match(/native code/);
  1161. proxyHandlers = {
  1162. has: function has(target, key) {
  1163. var has = key in target;
  1164. var isAllowedGlobal = allowedGlobals(key);
  1165. if (!has && !isAllowedGlobal) {
  1166. warn('Trying to access non-existent property "' + key + '" while rendering.', target);
  1167. }
  1168. return !isAllowedGlobal;
  1169. }
  1170. };
  1171. initProxy = function initProxy(vm) {
  1172. if (hasProxy) {
  1173. vm._renderProxy = new Proxy(vm, proxyHandlers);
  1174. } else {
  1175. vm._renderProxy = vm;
  1176. }
  1177. };
  1178. })();
  1179. }
  1180. // we have two separate queues: one for directive updates
  1181. // and one for user watcher registered via $watch().
  1182. // we want to guarantee directive updates to be called
  1183. // before user watchers so that when user watchers are
  1184. // triggered, the DOM would have already been in updated
  1185. // state.
  1186. var queueIndex;
  1187. var queue = [];
  1188. var userQueue = [];
  1189. var has = {};
  1190. var circular = {};
  1191. var waiting = false;
  1192. var internalQueueDepleted = false;
  1193. /**
  1194. * Reset the batcher's state.
  1195. */
  1196. function resetBatcherState() {
  1197. queue = [];
  1198. userQueue = [];
  1199. has = {};
  1200. circular = {};
  1201. waiting = internalQueueDepleted = false;
  1202. }
  1203. /**
  1204. * Flush both queues and run the watchers.
  1205. */
  1206. function flushBatcherQueue() {
  1207. queue.sort(queueSorter);
  1208. runBatcherQueue(queue);
  1209. internalQueueDepleted = true;
  1210. runBatcherQueue(userQueue);
  1211. resetBatcherState();
  1212. }
  1213. /**
  1214. * Sort queue before flush.
  1215. * This ensures components are updated from parent to child
  1216. * so there will be no duplicate updates, e.g. a child was
  1217. * pushed into the queue first and then its parent's props
  1218. * changed.
  1219. */
  1220. function queueSorter(a, b) {
  1221. return a.id - b.id;
  1222. }
  1223. /**
  1224. * Run the watchers in a single queue.
  1225. *
  1226. * @param {Array} queue
  1227. */
  1228. function runBatcherQueue(queue) {
  1229. // do not cache length because more watchers might be pushed
  1230. // as we run existing watchers
  1231. for (queueIndex = 0; queueIndex < queue.length; queueIndex++) {
  1232. var watcher = queue[queueIndex];
  1233. var id = watcher.id;
  1234. has[id] = null;
  1235. watcher.run();
  1236. // in dev build, check and stop circular updates.
  1237. if (process.env.NODE_ENV !== 'production' && has[id] != null) {
  1238. circular[id] = (circular[id] || 0) + 1;
  1239. if (circular[id] > config._maxUpdateCount) {
  1240. warn('You may have an infinite update loop for watcher ' + 'with expression "' + watcher.expression + '"', watcher.vm);
  1241. break;
  1242. }
  1243. }
  1244. }
  1245. }
  1246. /**
  1247. * Push a watcher into the watcher queue.
  1248. * Jobs with duplicate IDs will be skipped unless it's
  1249. * pushed when the queue is being flushed.
  1250. *
  1251. * @param {Watcher} watcher
  1252. * properties:
  1253. * - {Number} id
  1254. * - {Function} run
  1255. */
  1256. function pushWatcher(watcher) {
  1257. var id = watcher.id;
  1258. if (has[id] == null) {
  1259. if (internalQueueDepleted && !watcher.user) {
  1260. // an internal watcher triggered by a user watcher...
  1261. // let's run it immediately after current user watcher is done.
  1262. userQueue.splice(queueIndex + 1, 0, watcher);
  1263. } else {
  1264. // push watcher into appropriate queue
  1265. var q = watcher.user ? userQueue : queue;
  1266. has[id] = q.length;
  1267. q.push(watcher);
  1268. // queue the flush
  1269. if (!waiting) {
  1270. waiting = true;
  1271. nextTick(flushBatcherQueue);
  1272. }
  1273. }
  1274. }
  1275. }
  1276. var uid$2 = 0;
  1277. var prevTarget = void 0;
  1278. /**
  1279. * A watcher parses an expression, collects dependencies,
  1280. * and fires callback when the expression value changes.
  1281. * This is used for both the $watch() api and directives.
  1282. *
  1283. * @param {Vue} vm
  1284. * @param {String|Function} expOrFn
  1285. * @param {Function} cb
  1286. * @param {Object} options
  1287. * - {Array} filters
  1288. * - {Boolean} twoWay
  1289. * - {Boolean} deep
  1290. * - {Boolean} user
  1291. * - {Boolean} sync
  1292. * - {Boolean} lazy
  1293. * - {Function} [preProcess]
  1294. * - {Function} [postProcess]
  1295. * @constructor
  1296. */
  1297. function Watcher(vm, expOrFn, cb, options) {
  1298. // mix in options
  1299. if (options) {
  1300. extend(this, options);
  1301. }
  1302. var isFn = typeof expOrFn === 'function';
  1303. this.vm = vm;
  1304. vm._watchers.push(this);
  1305. this.expression = expOrFn;
  1306. this.cb = cb;
  1307. this.id = ++uid$2; // uid for batching
  1308. this.active = true;
  1309. this.dirty = this.lazy; // for lazy watchers
  1310. this.deps = [];
  1311. this.newDeps = [];
  1312. this.depIds = new _Set();
  1313. this.newDepIds = new _Set();
  1314. // parse expression for getter
  1315. if (isFn) {
  1316. this.getter = expOrFn;
  1317. } else {
  1318. this.getter = parsePath(expOrFn);
  1319. if (!this.getter) {
  1320. this.getter = function () {};
  1321. process.env.NODE_ENV !== 'production' && warn('Failed watching path: ' + expOrFn + 'Watcher only accepts simple dot-delimited paths. ' + 'For full control, use a function instead.', vm);
  1322. }
  1323. }
  1324. this.value = this.lazy ? undefined : this.get();
  1325. // state for avoiding false triggers for deep and Array
  1326. // watchers during vm._digest()
  1327. this.queued = this.shallow = false;
  1328. }
  1329. /**
  1330. * Evaluate the getter, and re-collect dependencies.
  1331. */
  1332. Watcher.prototype.get = function () {
  1333. this.beforeGet();
  1334. var value = this.getter.call(this.vm, this.vm);
  1335. // "touch" every property so they are all tracked as
  1336. // dependencies for deep watching
  1337. if (this.deep) {
  1338. traverse(value);
  1339. }
  1340. this.afterGet();
  1341. return value;
  1342. };
  1343. /**
  1344. * Prepare for dependency collection.
  1345. */
  1346. Watcher.prototype.beforeGet = function () {
  1347. prevTarget = Dep.target;
  1348. Dep.target = this;
  1349. };
  1350. /**
  1351. * Add a dependency to this directive.
  1352. *
  1353. * @param {Dep} dep
  1354. */
  1355. Watcher.prototype.addDep = function (dep) {
  1356. var id = dep.id;
  1357. if (!this.newDepIds.has(id)) {
  1358. this.newDepIds.add(id);
  1359. this.newDeps.push(dep);
  1360. if (!this.depIds.has(id)) {
  1361. dep.addSub(this);
  1362. }
  1363. }
  1364. };
  1365. /**
  1366. * Clean up for dependency collection.
  1367. */
  1368. Watcher.prototype.afterGet = function () {
  1369. Dep.target = prevTarget;
  1370. var i = this.deps.length;
  1371. while (i--) {
  1372. var dep = this.deps[i];
  1373. if (!this.newDepIds.has(dep.id)) {
  1374. dep.removeSub(this);
  1375. }
  1376. }
  1377. var tmp = this.depIds;
  1378. this.depIds = this.newDepIds;
  1379. this.newDepIds = tmp;
  1380. this.newDepIds.clear();
  1381. tmp = this.deps;
  1382. this.deps = this.newDeps;
  1383. this.newDeps = tmp;
  1384. this.newDeps.length = 0;
  1385. };
  1386. /**
  1387. * Subscriber interface.
  1388. * Will be called when a dependency changes.
  1389. *
  1390. * @param {Boolean} shallow
  1391. */
  1392. Watcher.prototype.update = function (shallow) {
  1393. if (this.lazy) {
  1394. this.dirty = true;
  1395. } else if (this.sync) {
  1396. this.run();
  1397. } else {
  1398. // if queued, only overwrite shallow with non-shallow,
  1399. // but not the other way around.
  1400. this.shallow = this.queued ? shallow ? this.shallow : false : !!shallow;
  1401. this.queued = true;
  1402. pushWatcher(this);
  1403. }
  1404. };
  1405. /**
  1406. * Batcher job interface.
  1407. * Will be called by the batcher.
  1408. */
  1409. Watcher.prototype.run = function () {
  1410. if (this.active) {
  1411. var value = this.get();
  1412. if (value !== this.value ||
  1413. // Deep watchers and watchers on Object/Arrays should fire even
  1414. // when the value is the same, because the value may
  1415. // have mutated; but only do so if this is a
  1416. // non-shallow update (caused by a vm digest).
  1417. (isObject(value) || this.deep) && !this.shallow) {
  1418. // set new value
  1419. var oldValue = this.value;
  1420. this.value = value;
  1421. this.cb.call(this.vm, value, oldValue);
  1422. }
  1423. this.queued = this.shallow = false;
  1424. }
  1425. };
  1426. /**
  1427. * Evaluate the value of the watcher.
  1428. * This only gets called for lazy watchers.
  1429. */
  1430. Watcher.prototype.evaluate = function () {
  1431. // avoid overwriting another watcher that is being
  1432. // collected.
  1433. var current = Dep.target;
  1434. this.value = this.get();
  1435. this.dirty = false;
  1436. Dep.target = current;
  1437. };
  1438. /**
  1439. * Depend on all deps collected by this watcher.
  1440. */
  1441. Watcher.prototype.depend = function () {
  1442. var i = this.deps.length;
  1443. while (i--) {
  1444. this.deps[i].depend();
  1445. }
  1446. };
  1447. /**
  1448. * Remove self from all dependencies' subcriber list.
  1449. */
  1450. Watcher.prototype.teardown = function () {
  1451. if (this.active) {
  1452. // remove self from vm's watcher list
  1453. // this is a somewhat expensive operation so we skip it
  1454. // if the vm is being destroyed or is performing a v-for
  1455. // re-render (the watcher list is then filtered by v-for).
  1456. if (!this.vm._isBeingDestroyed && !this.vm._vForRemoving) {
  1457. remove(this.vm._watchers, this);
  1458. }
  1459. var i = this.deps.length;
  1460. while (i--) {
  1461. this.deps[i].removeSub(this);
  1462. }
  1463. this.active = false;
  1464. this.vm = this.cb = this.value = null;
  1465. }
  1466. };
  1467. /**
  1468. * Recrusively traverse an object to evoke all converted
  1469. * getters, so that every nested property inside the object
  1470. * is collected as a "deep" dependency.
  1471. *
  1472. * @param {*} val
  1473. * @param {Set} seen
  1474. */
  1475. var seenObjects = new _Set();
  1476. function traverse(val, seen) {
  1477. var i = void 0,
  1478. keys = void 0,
  1479. isA = void 0,
  1480. isO = void 0;
  1481. if (!seen) {
  1482. seen = seenObjects;
  1483. seen.clear();
  1484. }
  1485. isA = isArray(val);
  1486. isO = isObject(val);
  1487. if (isA || isO) {
  1488. if (val.__ob__) {
  1489. var depId = val.__ob__.dep.id;
  1490. if (seen.has(depId)) {
  1491. return;
  1492. } else {
  1493. seen.add(depId);
  1494. }
  1495. }
  1496. if (isA) {
  1497. i = val.length;
  1498. while (i--) {
  1499. traverse(val[i], seen);
  1500. }
  1501. } else if (isO) {
  1502. keys = Object.keys(val);
  1503. i = keys.length;
  1504. while (i--) {
  1505. traverse(val[keys[i]], seen);
  1506. }
  1507. }
  1508. }
  1509. }
  1510. function initState(vm) {
  1511. vm._watchers = [];
  1512. initProps(vm);
  1513. initData(vm);
  1514. initComputed(vm);
  1515. initMethods(vm);
  1516. initWatch(vm);
  1517. }
  1518. function initProps(vm) {
  1519. var props = vm.$options.props;
  1520. var propsData = vm.$options.propsData;
  1521. if (props) {
  1522. var keys = vm.$options.propKeys = Object.keys(props);
  1523. var isRoot = !vm.$parent;
  1524. // root instance props should be converted
  1525. observerState.shouldConvert = isRoot;
  1526. for (var i = 0; i < keys.length; i++) {
  1527. var key = keys[i];
  1528. defineReactive(vm, key, validateProp(vm, key, propsData));
  1529. }
  1530. observerState.shouldConvert = true;
  1531. }
  1532. }
  1533. function initData(vm) {
  1534. var data = vm.$options.data;
  1535. data = vm._data = typeof data === 'function' ? data() : data || {};
  1536. if (!isPlainObject(data)) {
  1537. data = {};
  1538. process.env.NODE_ENV !== 'production' && warn('data functions should return an object.', vm);
  1539. }
  1540. // proxy data on instance
  1541. var keys = Object.keys(data);
  1542. var i = keys.length;
  1543. while (i--) {
  1544. proxy(vm, keys[i]);
  1545. }
  1546. // observe data
  1547. observe(data, vm);
  1548. }
  1549. function noop() {}
  1550. function initComputed(vm) {
  1551. var computed = vm.$options.computed;
  1552. if (computed) {
  1553. for (var key in computed) {
  1554. var userDef = computed[key];
  1555. var def = {
  1556. enumerable: true,
  1557. configurable: true
  1558. };
  1559. if (typeof userDef === 'function') {
  1560. def.get = makeComputedGetter(userDef, vm);
  1561. def.set = noop;
  1562. } else {
  1563. def.get = userDef.get ? userDef.cache !== false ? makeComputedGetter(userDef.get, vm) : bind(userDef.get, vm) : noop;
  1564. def.set = userDef.set ? bind(userDef.set, vm) : noop;
  1565. }
  1566. Object.defineProperty(vm, key, def);
  1567. }
  1568. }
  1569. }
  1570. function makeComputedGetter(getter, owner) {
  1571. var watcher = new Watcher(owner, getter, null, {
  1572. lazy: true
  1573. });
  1574. return function computedGetter() {
  1575. if (watcher.dirty) {
  1576. watcher.evaluate();
  1577. }
  1578. if (Dep.target) {
  1579. watcher.depend();
  1580. }
  1581. return watcher.value;
  1582. };
  1583. }
  1584. function initMethods(vm) {
  1585. var methods = vm.$options.methods;
  1586. if (methods) {
  1587. for (var key in methods) {
  1588. vm[key] = bind(methods[key], vm);
  1589. }
  1590. }
  1591. }
  1592. function initWatch(vm) {
  1593. var watch = vm.$options.watch;
  1594. if (watch) {
  1595. for (var key in watch) {
  1596. var handler = watch[key];
  1597. if (isArray(handler)) {
  1598. for (var i = 0; i < handler.length; i++) {
  1599. createWatcher(vm, key, handler[i]);
  1600. }
  1601. } else {
  1602. createWatcher(vm, key, handler);
  1603. }
  1604. }
  1605. }
  1606. }
  1607. function createWatcher(vm, key, handler) {
  1608. var options = void 0;
  1609. if (isPlainObject(handler)) {
  1610. options = handler;
  1611. handler = handler.handler;
  1612. }
  1613. if (typeof handler === 'string') {
  1614. handler = vm[handler];
  1615. }
  1616. vm.$watch(key, handler, options);
  1617. }
  1618. function stateMixin(Vue) {
  1619. Object.defineProperty(Vue.prototype, '$data', {
  1620. get: function get() {
  1621. return this._data;
  1622. },
  1623. set: function set(newData) {
  1624. if (newData !== this._data) {
  1625. setData(this, newData);
  1626. }
  1627. }
  1628. });
  1629. Vue.prototype.$watch = function (fn, cb, options) {
  1630. options = options || {};
  1631. options.user = true;
  1632. var watcher = new Watcher(this, fn, cb, options);
  1633. if (options.immediate) {
  1634. cb.call(this, watcher.value);
  1635. }
  1636. return function unwatchFn() {
  1637. watcher.teardown();
  1638. };
  1639. };
  1640. }
  1641. function setData(vm, newData) {
  1642. newData = newData || {};
  1643. var oldData = vm._data;
  1644. vm._data = newData;
  1645. var keys, key, i;
  1646. // unproxy keys not present in new data
  1647. keys = Object.keys(oldData);
  1648. i = keys.length;
  1649. while (i--) {
  1650. key = keys[i];
  1651. if (!(key in newData)) {
  1652. unproxy(vm, key);
  1653. }
  1654. }
  1655. // proxy keys not already proxied,
  1656. // and trigger change for changed values
  1657. keys = Object.keys(newData);
  1658. i = keys.length;
  1659. while (i--) {
  1660. key = keys[i];
  1661. if (!hasOwn(vm, key)) {
  1662. // new property
  1663. proxy(vm, key);
  1664. }
  1665. }
  1666. oldData.__ob__.removeVm(vm);
  1667. observe(newData, vm);
  1668. vm.$forceUpdate();
  1669. }
  1670. function VNode(tag, data, children, text, elm, ns, context) {
  1671. return {
  1672. tag: tag,
  1673. data: data,
  1674. children: children,
  1675. text: text,
  1676. elm: elm,
  1677. ns: ns,
  1678. context: context,
  1679. key: data && data.key
  1680. };
  1681. }
  1682. function flatten(children) {
  1683. if (typeof children === 'string') {
  1684. return [VNode(undefined, undefined, undefined, children)];
  1685. }
  1686. if (isArray(children)) {
  1687. var res = [];
  1688. for (var i = 0, l = children.length; i < l; i++) {
  1689. var c = children[i];
  1690. // flatten nested
  1691. if (isArray(c)) {
  1692. res.push.apply(res, flatten(c));
  1693. } else if (isPrimitive(c)) {
  1694. // convert primitive to vnode
  1695. res.push(VNode(undefined, undefined, undefined, c));
  1696. } else if (c) {
  1697. res.push(c);
  1698. }
  1699. }
  1700. return res;
  1701. }
  1702. }
  1703. function updateListeners(on, oldOn, add) {
  1704. var name = void 0,
  1705. cur = void 0,
  1706. old = void 0,
  1707. event = void 0,
  1708. capture = void 0;
  1709. for (name in on) {
  1710. cur = on[name];
  1711. old = oldOn[name];
  1712. if (old === undefined) {
  1713. capture = name.charAt(0) === '!';
  1714. event = capture ? name.slice(1) : name;
  1715. if (isArray(cur)) {
  1716. add(event, arrInvoker(cur), capture);
  1717. } else {
  1718. cur = { fn: cur };
  1719. on[name] = cur;
  1720. add(event, fnInvoker(cur), capture);
  1721. }
  1722. } else if (isArray(old)) {
  1723. old.length = cur.length;
  1724. for (var i = 0; i < old.length; i++) {
  1725. old[i] = cur[i];
  1726. }on[name] = old;
  1727. } else {
  1728. old.fn = cur;
  1729. on[name] = old;
  1730. }
  1731. }
  1732. }
  1733. function arrInvoker(arr) {
  1734. return function (ev) {
  1735. for (var i = 0; i < arr.length; i++) {
  1736. arr[i](ev);
  1737. }
  1738. };
  1739. }
  1740. function fnInvoker(o) {
  1741. return function (ev) {
  1742. o.fn(ev);
  1743. };
  1744. }
  1745. function initLifecycle(vm) {
  1746. var options = vm.$options;
  1747. vm.$parent = options.parent;
  1748. vm.$root = vm.$parent ? vm.$parent.$root : vm;
  1749. if (vm.$parent) {
  1750. vm.$parent.$children.push(vm);
  1751. }
  1752. vm.$children = [];
  1753. vm.$refs = {};
  1754. vm._isDestroyed = false;
  1755. vm._isBeingDestroyed = false;
  1756. }
  1757. function lifecycleMixin(Vue) {
  1758. Vue.prototype._mount = function () {
  1759. var _this = this;
  1760. if (!this.$options.render) {
  1761. this.$options.render = function () {
  1762. return _this.$createElement('div');
  1763. };
  1764. if (process.env.NODE_ENV !== 'production') {
  1765. if (this.$options.template) {
  1766. 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);
  1767. } else {
  1768. warn('Failed to mount component: template or render function not defined.', this);
  1769. }
  1770. }
  1771. }
  1772. // render static sub-trees for once on mount
  1773. var staticRenderFns = this.$options.staticRenderFns;
  1774. if (staticRenderFns) {
  1775. this._staticTrees = new Array(staticRenderFns.length);
  1776. for (var i = 0; i < staticRenderFns.length; i++) {
  1777. this._staticTrees[i] = staticRenderFns[i].call(this._renderProxy);
  1778. }
  1779. }
  1780. this._watcher = new Watcher(this, this._render, this._update);
  1781. this._update(this._watcher.value);
  1782. this._mounted = true;
  1783. // root instance, call ready on self
  1784. if (this.$root === this) {
  1785. callHook(this, 'ready');
  1786. }
  1787. return this;
  1788. };
  1789. Vue.prototype._update = function (vnode) {
  1790. if (this._mounted) {
  1791. callHook(this, 'beforeUpdate');
  1792. }
  1793. var parentNode = this.$options._parentVnode;
  1794. // set vnode parent before patch
  1795. vnode.parent = parentNode;
  1796. if (!this._vnode) {
  1797. // Vue.prototype.__patch__ is injected in entry points
  1798. // based on the rendering backend used.
  1799. this.$el = this.__patch__(this.$el, vnode);
  1800. } else {
  1801. this.$el = this.__patch__(this._vnode, vnode);
  1802. }
  1803. this._vnode = vnode;
  1804. // set parent vnode element after patch
  1805. if (parentNode) {
  1806. parentNode.elm = this.$el;
  1807. }
  1808. if (this._mounted) {
  1809. callHook(this, 'updated');
  1810. }
  1811. };
  1812. Vue.prototype._updateFromParent = function (propsData, listeners, parentVnode, children) {
  1813. var _this2 = this;
  1814. this.$options._parentVnode = parentVnode;
  1815. this.$options._renderChildren = children;
  1816. // update props
  1817. if (propsData && this.$options.props) {
  1818. observerState.shouldConvert = false;
  1819. var propKeys = this.$options.propKeys;
  1820. for (var i = 0; i < propKeys.length; i++) {
  1821. var key = propKeys[i];
  1822. this[key] = validateProp(this, key, propsData);
  1823. }
  1824. observerState.shouldConvert = true;
  1825. }
  1826. // update listeners
  1827. if (listeners) {
  1828. var oldListeners = this.$options._parentListeners;
  1829. this.$options._parentListeners = listeners;
  1830. updateListeners(listeners, oldListeners || {}, function (event, handler) {
  1831. _this2.$on(event, handler);
  1832. });
  1833. }
  1834. };
  1835. Vue.prototype.$forceUpdate = function () {
  1836. this._watcher.update();
  1837. };
  1838. Vue.prototype.$destroy = function () {
  1839. if (this._isDestroyed) {
  1840. return;
  1841. }
  1842. callHook(this, 'beforeDestroy');
  1843. this._isBeingDestroyed = true;
  1844. // remove self from parent
  1845. var parent = this.$parent;
  1846. if (parent && !parent._isBeingDestroyed) {
  1847. remove(parent.$children, this);
  1848. }
  1849. // unregister ref
  1850. if (this._ref) {
  1851. this._context.$refs[this._ref] = undefined;
  1852. }
  1853. // teardown watchers
  1854. var i = this._watchers.length;
  1855. while (i--) {
  1856. this._watchers[i].teardown();
  1857. }
  1858. // remove reference from data ob
  1859. // frozen object may not have observer.
  1860. if (this._data.__ob__) {
  1861. this._data.__ob__.removeVm(this);
  1862. }
  1863. // call the last hook...
  1864. this._isDestroyed = true;
  1865. callHook(this, 'destroyed');
  1866. // turn off all instance listeners.
  1867. this.$off();
  1868. };
  1869. }
  1870. function callHook(vm, hook) {
  1871. vm.$emit('pre-hook:' + hook);
  1872. var handlers = vm.$options[hook];
  1873. if (handlers) {
  1874. for (var i = 0, j = handlers.length; i < j; i++) {
  1875. handlers[i].call(vm);
  1876. }
  1877. }
  1878. vm.$emit('hook:' + hook);
  1879. }
  1880. var hooks = { init: init, prepatch: prepatch, insert: insert, destroy: destroy };
  1881. var hooksToMerge = Object.keys(hooks);
  1882. function createComponent(Ctor, data, parent, children, context) {
  1883. if (process.env.NODE_ENV !== 'production' && children && typeof children !== 'function') {
  1884. 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.');
  1885. }
  1886. if (!Ctor) {
  1887. return;
  1888. }
  1889. if (isObject(Ctor)) {
  1890. Ctor = Vue.extend(Ctor);
  1891. }
  1892. if (process.env.NODE_ENV !== 'production' && typeof Ctor !== 'function') {
  1893. warn('Invalid Component definition: ' + Ctor, parent);
  1894. return;
  1895. }
  1896. // async component
  1897. if (!Ctor.cid) {
  1898. if (Ctor.resolved) {
  1899. Ctor = Ctor.resolved;
  1900. } else {
  1901. resolveAsyncComponent(Ctor, function () {
  1902. // it's ok to queue this on every render because
  1903. // $forceUpdate is buffered.
  1904. parent.$forceUpdate();
  1905. });
  1906. return;
  1907. }
  1908. }
  1909. data = data || {};
  1910. // merge component management hooks onto the placeholder node
  1911. mergeHooks(data);
  1912. // extract props
  1913. var propsData = extractProps(data, Ctor);
  1914. // extract listeners, since these needs to be treated as
  1915. // child component listeners instead of DOM listeners
  1916. var listeners = data.on;
  1917. if (listeners) {
  1918. data.on = null;
  1919. }
  1920. // return a placeholder vnode
  1921. var name = Ctor.options.name ? '-' + Ctor.options.name : '';
  1922. var vnode = VNode('vue-component-' + Ctor.cid + name, data, undefined, undefined, undefined, undefined, context);
  1923. vnode.componentOptions = { Ctor: Ctor, propsData: propsData, listeners: listeners, parent: parent, children: children };
  1924. return vnode;
  1925. }
  1926. function init(vnode) {
  1927. var _vnode$componentOptio = vnode.componentOptions;
  1928. var Ctor = _vnode$componentOptio.Ctor;
  1929. var propsData = _vnode$componentOptio.propsData;
  1930. var listeners = _vnode$componentOptio.listeners;
  1931. var parent = _vnode$componentOptio.parent;
  1932. var children = _vnode$componentOptio.children;
  1933. var child = new Ctor({
  1934. parent: parent,
  1935. propsData: propsData,
  1936. _parentVnode: vnode,
  1937. _parentListeners: listeners,
  1938. _renderChildren: children
  1939. });
  1940. // if this is a server-rendered mount,
  1941. // the vnode would already have an element.
  1942. // otherwise the child sets the parent vnode's elm when mounted
  1943. // and when updated.
  1944. child.$mount(vnode.elm);
  1945. vnode.child = child;
  1946. }
  1947. function prepatch(oldVnode, vnode) {
  1948. var _vnode$componentOptio2 = vnode.componentOptions;
  1949. var listeners = _vnode$componentOptio2.listeners;
  1950. var propsData = _vnode$componentOptio2.propsData;
  1951. var children = _vnode$componentOptio2.children;
  1952. vnode.child = oldVnode.child;
  1953. vnode.child._updateFromParent(propsData, // updated props
  1954. listeners, // updated listeners
  1955. vnode, // new parent vnode
  1956. children // new children
  1957. );
  1958. }
  1959. function insert(vnode) {
  1960. callHook(vnode.child, 'ready');
  1961. }
  1962. function destroy(vnode) {
  1963. vnode.child.$destroy();
  1964. }
  1965. function resolveAsyncComponent(factory, cb) {
  1966. if (factory.resolved) {
  1967. // cached
  1968. cb(factory.resolved);
  1969. } else if (factory.requested) {
  1970. // pool callbacks
  1971. factory.pendingCallbacks.push(cb);
  1972. } else {
  1973. (function () {
  1974. factory.requested = true;
  1975. var cbs = factory.pendingCallbacks = [cb];
  1976. factory(function resolve(res) {
  1977. if (isObject(res)) {
  1978. res = Vue.extend(res);
  1979. }
  1980. // cache resolved
  1981. factory.resolved = res;
  1982. // invoke callbacks
  1983. for (var i = 0, l = cbs.length; i < l; i++) {
  1984. cbs[i](res);
  1985. }
  1986. }, function reject(reason) {
  1987. process.env.NODE_ENV !== 'production' && warn('Failed to resolve async component: ' + factory + (reason ? '\nReason: ' + reason : ''));
  1988. });
  1989. })();
  1990. }
  1991. }
  1992. function extractProps(data, Ctor) {
  1993. // we are only extrating raw values here.
  1994. // validation and default values are handled in the child
  1995. // component itself.
  1996. var propOptions = Ctor.options.props;
  1997. if (!propOptions) {
  1998. return;
  1999. }
  2000. var res = {};
  2001. var attrs = data.attrs;
  2002. var props = data.props;
  2003. var staticAttrs = data.staticAttrs;
  2004. if (!attrs && !props) {
  2005. return res;
  2006. }
  2007. for (var key in propOptions) {
  2008. var altKey = hyphenate(key);
  2009. checkProp(res, attrs, key, altKey) || checkProp(res, props, key, altKey) || checkProp(res, staticAttrs, key, altKey);
  2010. }
  2011. return res;
  2012. }
  2013. function checkProp(res, hash, key, altKey) {
  2014. if (hash) {
  2015. if (hasOwn(hash, key)) {
  2016. res[key] = hash[key];
  2017. delete hash[key];
  2018. return true;
  2019. } else if (hasOwn(hash, altKey)) {
  2020. res[key] = hash[altKey];
  2021. delete hash[altKey];
  2022. return true;
  2023. }
  2024. }
  2025. }
  2026. function mergeHooks(data) {
  2027. if (data.hook) {
  2028. for (var i = 0; i < hooksToMerge.length; i++) {
  2029. var key = hooksToMerge[i];
  2030. var fromParent = data.hook[key];
  2031. var ours = hooks[key];
  2032. data.hook[key] = fromParent ? mergeHook$1(ours, fromParent) : ours;
  2033. }
  2034. } else {
  2035. data.hook = hooks;
  2036. }
  2037. }
  2038. function mergeHook$1(a, b) {
  2039. // since all hooks have at most two args, use fixed args
  2040. // to avoid having to use fn.apply().
  2041. return function (_, __) {
  2042. a(_, __);
  2043. b(_, __);
  2044. };
  2045. }
  2046. function createElement(tag, data, children, namespace) {
  2047. var context = this;
  2048. var parent = renderState.activeInstance;
  2049. if (typeof tag === 'string') {
  2050. var Ctor = void 0;
  2051. if (config.isReservedTag(tag)) {
  2052. return VNode(tag, data, flatten(children), undefined, undefined, namespace, context);
  2053. } else if (Ctor = resolveAsset(context.$options, 'components', tag)) {
  2054. return createComponent(Ctor, data, parent, children, context);
  2055. } else {
  2056. if (process.env.NODE_ENV !== 'production') {
  2057. if (!namespace && config.isUnknownElement(tag)) {
  2058. warn('Unknown custom element: <' + tag + '> - did you ' + 'register the component correctly? For recursive components, ' + 'make sure to provide the "name" option.');
  2059. }
  2060. }
  2061. return VNode(tag, data, flatten(children && children()), undefined, undefined, namespace, context);
  2062. }
  2063. } else {
  2064. return createComponent(tag, data, parent, children, context);
  2065. }
  2066. }
  2067. var renderState = {
  2068. activeInstance: null
  2069. };
  2070. function initRender(vm) {
  2071. vm._vnode = null;
  2072. vm._mounted = false;
  2073. vm._staticTrees = null;
  2074. vm.$slots = {};
  2075. // bind the public createElement fn to this instance
  2076. // so that we get proper render context inside it.
  2077. vm.$createElement = bind(createElement, vm);
  2078. if (vm.$options.el) {
  2079. vm.$mount(vm.$options.el);
  2080. }
  2081. }
  2082. function renderMixin(Vue) {
  2083. Vue.prototype._render = function () {
  2084. var prev = renderState.activeInstance;
  2085. renderState.activeInstance = this;
  2086. var _$options = this.$options;
  2087. var render = _$options.render;
  2088. var _renderChildren = _$options._renderChildren;
  2089. // resolve slots. becaues slots are rendered in parent scope,
  2090. // we set the activeInstance to parent.
  2091. if (_renderChildren) {
  2092. resolveSlots(this, _renderChildren);
  2093. }
  2094. // render self
  2095. var vnode = render.call(this._renderProxy);
  2096. // restore render state
  2097. renderState.activeInstance = prev;
  2098. return vnode;
  2099. };
  2100. // shorthands used in render functions
  2101. Vue.prototype.__h__ = createElement;
  2102. // toString for mustaches
  2103. Vue.prototype.__toString__ = renderString;
  2104. // render v-for
  2105. Vue.prototype.__renderList__ = function (val, render) {
  2106. var ret = void 0,
  2107. i = void 0,
  2108. l = void 0,
  2109. keys = void 0,
  2110. key = void 0;
  2111. if (isArray(val)) {
  2112. ret = new Array(val.length);
  2113. for (i = 0, l = val.length; i < l; i++) {
  2114. ret[i] = render(val[i], i, i);
  2115. }
  2116. } else if (typeof val === 'number') {
  2117. ret = new Array(val);
  2118. for (i = 0; i < val; i++) {
  2119. ret[i] = render(i + 1, i, i);
  2120. }
  2121. } else if (isObject(val)) {
  2122. keys = Object.keys(val);
  2123. ret = new Array(keys.length);
  2124. for (i = 0, l = keys.length; i < l; i++) {
  2125. key = keys[i];
  2126. ret[i] = render(val[key], i, key);
  2127. }
  2128. }
  2129. return ret;
  2130. };
  2131. // register ref
  2132. Vue.prototype.__registerRef__ = function (key, ref, vFor, remove) {
  2133. var refs = this.$refs;
  2134. if (remove) {
  2135. if (vFor) {
  2136. remove(refs[key], ref);
  2137. } else {
  2138. refs[key] = undefined;
  2139. }
  2140. } else {
  2141. if (vFor) {
  2142. if (refs[key]) {
  2143. refs[key].push(ref);
  2144. } else {
  2145. refs[key] = [ref];
  2146. }
  2147. } else {
  2148. refs[key] = ref;
  2149. }
  2150. }
  2151. };
  2152. }
  2153. function resolveSlots(vm, children) {
  2154. if (children) {
  2155. children = flatten(isArray(children) ? children : children());
  2156. var slots = { default: children };
  2157. var i = children.length;
  2158. var name = void 0,
  2159. child = void 0;
  2160. while (i--) {
  2161. child = children[i];
  2162. if (name = child.data && child.data.slot) {
  2163. var slot = slots[name] || (slots[name] = []);
  2164. if (child.tag === 'template') {
  2165. slot.push.apply(slot, child.children);
  2166. } else {
  2167. slot.push(child);
  2168. }
  2169. children.splice(i, 1);
  2170. }
  2171. }
  2172. vm.$slots = slots;
  2173. }
  2174. }
  2175. function initEvents(vm) {
  2176. vm._events = Object.create(null);
  2177. // init parent attached events
  2178. var listeners = vm.$options._parentListeners;
  2179. if (listeners) {
  2180. updateListeners(listeners, {}, function (event, handler) {
  2181. vm.$on(event, handler);
  2182. });
  2183. }
  2184. }
  2185. function eventsMixin(Vue) {
  2186. Vue.prototype.$on = function (event, fn) {
  2187. (this._events[event] || (this._events[event] = [])).push(fn);
  2188. return this;
  2189. };
  2190. /**
  2191. * Adds an `event` listener that will be invoked a single
  2192. * time then automatically removed.
  2193. *
  2194. * @param {String} event
  2195. * @param {Function} fn
  2196. */
  2197. Vue.prototype.$once = function (event, fn) {
  2198. var self = this;
  2199. function on() {
  2200. self.$off(event, on);
  2201. fn.apply(this, arguments);
  2202. }
  2203. on.fn = fn;
  2204. this.$on(event, on);
  2205. return this;
  2206. };
  2207. /**
  2208. * Remove the given callback for `event` or all
  2209. * registered callbacks.
  2210. *
  2211. * @param {String} event
  2212. * @param {Function} fn
  2213. */
  2214. Vue.prototype.$off = function (event, fn) {
  2215. var cbs;
  2216. // all
  2217. if (!arguments.length) {
  2218. this._events = Object.create(null);
  2219. return this;
  2220. }
  2221. // specific event
  2222. cbs = this._events[event];
  2223. if (!cbs) {
  2224. return this;
  2225. }
  2226. if (arguments.length === 1) {
  2227. this._events[event] = null;
  2228. return this;
  2229. }
  2230. // specific handler
  2231. var cb;
  2232. var i = cbs.length;
  2233. while (i--) {
  2234. cb = cbs[i];
  2235. if (cb === fn || cb.fn === fn) {
  2236. cbs.splice(i, 1);
  2237. break;
  2238. }
  2239. }
  2240. return this;
  2241. };
  2242. /**
  2243. * Trigger an event on self.
  2244. *
  2245. * @param {String} event
  2246. */
  2247. Vue.prototype.$emit = function (event) {
  2248. var cbs = this._events[event];
  2249. if (cbs) {
  2250. cbs = cbs.length > 1 ? toArray(cbs) : cbs;
  2251. var args = toArray(arguments, 1);
  2252. for (var i = 0, l = cbs.length; i < l; i++) {
  2253. cbs[i].apply(this, args);
  2254. }
  2255. }
  2256. };
  2257. }
  2258. var uid = 0;
  2259. function Vue(options) {
  2260. this._init(options);
  2261. }
  2262. Vue.prototype._init = function (options) {
  2263. // a uid
  2264. this._uid = uid++;
  2265. // a flag to avoid this being observed
  2266. this._isVue = true;
  2267. // merge options
  2268. this.$options = mergeOptions(this.constructor.options, options || {}, this);
  2269. if (process.env.NODE_ENV !== 'production') {
  2270. initProxy(this);
  2271. } else {
  2272. this._renderProxy = this;
  2273. }
  2274. initLifecycle(this);
  2275. initEvents(this);
  2276. callHook(this, 'init');
  2277. initState(this);
  2278. callHook(this, 'created');
  2279. initRender(this);
  2280. };
  2281. Vue.prototype.$nextTick = function (fn) {
  2282. nextTick(fn, this);
  2283. };
  2284. stateMixin(Vue);
  2285. eventsMixin(Vue);
  2286. lifecycleMixin(Vue);
  2287. renderMixin(Vue);
  2288. function initUse(Vue) {
  2289. /**
  2290. * Plugin system
  2291. *
  2292. * @param {Object} plugin
  2293. */
  2294. Vue.use = function (plugin) {
  2295. /* istanbul ignore if */
  2296. if (plugin.installed) {
  2297. return;
  2298. }
  2299. // additional parameters
  2300. var args = toArray(arguments, 1);
  2301. args.unshift(this);
  2302. if (typeof plugin.install === 'function') {
  2303. plugin.install.apply(plugin, args);
  2304. } else {
  2305. plugin.apply(null, args);
  2306. }
  2307. plugin.installed = true;
  2308. return this;
  2309. };
  2310. }
  2311. function initMixin(Vue) {
  2312. Vue.mixin = function (mixin) {
  2313. Vue.options = mergeOptions(Vue.options, mixin);
  2314. };
  2315. }
  2316. function initExtend(Vue) {
  2317. /**
  2318. * Each instance constructor, including Vue, has a unique
  2319. * cid. This enables us to create wrapped "child
  2320. * constructors" for prototypal inheritance and cache them.
  2321. */
  2322. Vue.cid = 0;
  2323. var cid = 1;
  2324. /**
  2325. * Class inheritance
  2326. *
  2327. * @param {Object} extendOptions
  2328. */
  2329. Vue.extend = function (extendOptions) {
  2330. extendOptions = extendOptions || {};
  2331. var Super = this;
  2332. var isFirstExtend = Super.cid === 0;
  2333. if (isFirstExtend && extendOptions._Ctor) {
  2334. return extendOptions._Ctor;
  2335. }
  2336. var name = extendOptions.name || Super.options.name;
  2337. if (process.env.NODE_ENV !== 'production') {
  2338. if (!/^[a-zA-Z][\w-]*$/.test(name)) {
  2339. warn('Invalid component name: "' + name + '". Component names ' + 'can only contain alphanumeric characaters and the hyphen.');
  2340. name = null;
  2341. }
  2342. }
  2343. var Sub = function VueComponent(options) {
  2344. this._init(options);
  2345. };
  2346. Sub.prototype = Object.create(Super.prototype);
  2347. Sub.prototype.constructor = Sub;
  2348. Sub.cid = cid++;
  2349. Sub.options = mergeOptions(Super.options, extendOptions);
  2350. Sub['super'] = Super;
  2351. // allow further extension
  2352. Sub.extend = Super.extend;
  2353. // create asset registers, so extended classes
  2354. // can have their private assets too.
  2355. config._assetTypes.forEach(function (type) {
  2356. Sub[type] = Super[type];
  2357. });
  2358. // enable recursive self-lookup
  2359. if (name) {
  2360. Sub.options.components[name] = Sub;
  2361. }
  2362. // cache constructor
  2363. if (isFirstExtend) {
  2364. extendOptions._Ctor = Sub;
  2365. }
  2366. return Sub;
  2367. };
  2368. }
  2369. function initAssetRegisters(Vue) {
  2370. /**
  2371. * Create asset registration methods with the following
  2372. * signature:
  2373. *
  2374. * @param {String} id
  2375. * @param {*} definition
  2376. */
  2377. config._assetTypes.forEach(function (type) {
  2378. Vue[type] = function (id, definition) {
  2379. if (!definition) {
  2380. return this.options[type + 's'][id];
  2381. } else {
  2382. /* istanbul ignore if */
  2383. if (process.env.NODE_ENV !== 'production') {
  2384. if (type === 'component' && config.isReservedTag(id)) {
  2385. warn('Do not use built-in or reserved HTML elements as component ' + 'id: ' + id);
  2386. }
  2387. }
  2388. if (type === 'component' && isPlainObject(definition)) {
  2389. definition.name = id;
  2390. definition = Vue.extend(definition);
  2391. }
  2392. this.options[type + 's'][id] = definition;
  2393. return definition;
  2394. }
  2395. };
  2396. });
  2397. }
  2398. function initGlobalAPI(Vue) {
  2399. Vue.config = config;
  2400. Vue.util = util;
  2401. Vue.set = set;
  2402. Vue.delete = del;
  2403. Vue.nextTick = nextTick;
  2404. Vue.options = {
  2405. directives: Object.create(null),
  2406. filters: Object.create(null),
  2407. components: Object.create(null),
  2408. transitions: Object.create(null)
  2409. };
  2410. initUse(Vue);
  2411. initMixin(Vue);
  2412. initExtend(Vue);
  2413. initAssetRegisters(Vue);
  2414. }
  2415. initGlobalAPI(Vue);
  2416. Vue.version = '2.0.0-alpha.0';
  2417. var emptyNode = VNode('', {}, []);
  2418. var hooks$1 = ['create', 'update', 'remove', 'destroy'];
  2419. function isUndef(s) {
  2420. return s === undefined;
  2421. }
  2422. function isDef(s) {
  2423. return s !== undefined;
  2424. }
  2425. function sameVnode(vnode1, vnode2) {
  2426. return vnode1.key === vnode2.key && vnode1.tag === vnode2.tag;
  2427. }
  2428. function createKeyToOldIdx(children, beginIdx, endIdx) {
  2429. var i = void 0,
  2430. key = void 0;
  2431. var map = {};
  2432. for (i = beginIdx; i <= endIdx; ++i) {
  2433. key = children[i].key;
  2434. if (isDef(key)) map[key] = i;
  2435. }
  2436. return map;
  2437. }
  2438. function createPatchFunction(backend) {
  2439. var i = void 0,
  2440. j = void 0;
  2441. var cbs = {};
  2442. var modules = backend.modules;
  2443. var nodeOps = backend.nodeOps;
  2444. for (i = 0; i < hooks$1.length; ++i) {
  2445. cbs[hooks$1[i]] = [];
  2446. for (j = 0; j < modules.length; ++j) {
  2447. if (modules[j][hooks$1[i]] !== undefined) cbs[hooks$1[i]].push(modules[j][hooks$1[i]]);
  2448. }
  2449. }
  2450. function emptyNodeAt(elm) {
  2451. return VNode(nodeOps.tagName(elm).toLowerCase(), {}, [], undefined, elm);
  2452. }
  2453. function createRmCb(childElm, listeners) {
  2454. function remove() {
  2455. if (--remove.listeners === 0) {
  2456. removeElement(childElm);
  2457. }
  2458. }
  2459. remove.listeners = listeners;
  2460. return remove;
  2461. }
  2462. function removeElement(el) {
  2463. var parent = nodeOps.parentNode(el);
  2464. nodeOps.removeChild(parent, el);
  2465. }
  2466. function createElm(vnode, insertedVnodeQueue) {
  2467. var i = void 0,
  2468. elm = void 0;
  2469. var data = vnode.data;
  2470. if (isDef(data)) {
  2471. if (isDef(i = data.hook) && isDef(i = i.init)) i(vnode);
  2472. // after calling the init hook, if the vnode is a child component
  2473. // it should've created a child instance and mounted it. the child
  2474. // component also has set the placeholder vnode's elm.
  2475. // in that case we can just return the element and be done.
  2476. if (isDef(i = vnode.child)) {
  2477. invokeCreateHooks(vnode, insertedVnodeQueue);
  2478. return vnode.elm;
  2479. }
  2480. }
  2481. var children = vnode.children;
  2482. var tag = vnode.tag;
  2483. if (isDef(tag)) {
  2484. elm = vnode.elm = vnode.ns ? nodeOps.createElementNS(vnode.ns, tag) : nodeOps.createElement(tag);
  2485. if (Array.isArray(children)) {
  2486. for (i = 0; i < children.length; ++i) {
  2487. nodeOps.appendChild(elm, createElm(children[i], insertedVnodeQueue));
  2488. }
  2489. } else if (isPrimitive(vnode.text)) {
  2490. nodeOps.appendChild(elm, nodeOps.createTextNode(vnode.text));
  2491. }
  2492. if (isDef(data)) {
  2493. invokeCreateHooks(vnode, insertedVnodeQueue);
  2494. }
  2495. } else {
  2496. elm = vnode.elm = nodeOps.createTextNode(vnode.text);
  2497. }
  2498. return vnode.elm;
  2499. }
  2500. function invokeCreateHooks(vnode, insertedVnodeQueue) {
  2501. for (var _i = 0; _i < cbs.create.length; ++_i) {
  2502. cbs.create[_i](emptyNode, vnode);
  2503. }
  2504. i = vnode.data.hook; // Reuse variable
  2505. if (isDef(i)) {
  2506. if (i.create) i.create(emptyNode, vnode);
  2507. if (i.insert) insertedVnodeQueue.push(vnode);
  2508. }
  2509. }
  2510. function addVnodes(parentElm, before, vnodes, startIdx, endIdx, insertedVnodeQueue) {
  2511. for (; startIdx <= endIdx; ++startIdx) {
  2512. nodeOps.insertBefore(parentElm, createElm(vnodes[startIdx], insertedVnodeQueue), before);
  2513. }
  2514. }
  2515. function invokeDestroyHook(vnode) {
  2516. var i = void 0,
  2517. j = void 0;
  2518. var data = vnode.data;
  2519. if (isDef(data)) {
  2520. if (isDef(i = data.hook) && isDef(i = i.destroy)) i(vnode);
  2521. for (i = 0; i < cbs.destroy.length; ++i) {
  2522. cbs.destroy[i](vnode);
  2523. }if (isDef(i = vnode.children)) {
  2524. for (j = 0; j < vnode.children.length; ++j) {
  2525. invokeDestroyHook(vnode.children[j]);
  2526. }
  2527. }
  2528. if (isDef(i = vnode.child)) {
  2529. invokeDestroyHook(i._vnode);
  2530. }
  2531. }
  2532. }
  2533. function removeVnodes(parentElm, vnodes, startIdx, endIdx) {
  2534. for (; startIdx <= endIdx; ++startIdx) {
  2535. var ch = vnodes[startIdx];
  2536. if (isDef(ch)) {
  2537. if (isDef(ch.tag)) {
  2538. invokeDestroyHook(ch);
  2539. removeAndInvokeRemoveHook(ch);
  2540. } else {
  2541. // Text node
  2542. nodeOps.removeChild(parentElm, ch.elm);
  2543. }
  2544. }
  2545. }
  2546. }
  2547. function removeAndInvokeRemoveHook(vnode, rm) {
  2548. if (rm || isDef(vnode.data)) {
  2549. var listeners = cbs.remove.length + 1;
  2550. if (!rm) {
  2551. // directly removing
  2552. rm = createRmCb(vnode.elm, listeners);
  2553. } else {
  2554. // we have a recursively passed down rm callback
  2555. // increase the listeners count
  2556. rm.listeners += listeners;
  2557. }
  2558. // recursively invoke hooks on child component root node
  2559. if (isDef(i = vnode.child) && isDef(i = i._vnode) && isDef(i.data)) {
  2560. removeAndInvokeRemoveHook(i, rm);
  2561. }
  2562. for (i = 0; i < cbs.remove.length; ++i) {
  2563. cbs.remove[i](vnode, rm);
  2564. }
  2565. if (isDef(i = vnode.data.hook) && isDef(i = i.remove)) {
  2566. i(vnode, rm);
  2567. } else {
  2568. rm();
  2569. }
  2570. } else {
  2571. removeElement(vnode.elm);
  2572. }
  2573. }
  2574. function updateChildren(parentElm, oldCh, newCh, insertedVnodeQueue) {
  2575. var oldStartIdx = 0;
  2576. var newStartIdx = 0;
  2577. var oldEndIdx = oldCh.length - 1;
  2578. var oldStartVnode = oldCh[0];
  2579. var oldEndVnode = oldCh[oldEndIdx];
  2580. var newEndIdx = newCh.length - 1;
  2581. var newStartVnode = newCh[0];
  2582. var newEndVnode = newCh[newEndIdx];
  2583. var oldKeyToIdx = void 0,
  2584. idxInOld = void 0,
  2585. elmToMove = void 0,
  2586. before = void 0;
  2587. while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
  2588. if (isUndef(oldStartVnode)) {
  2589. oldStartVnode = oldCh[++oldStartIdx]; // Vnode has been moved left
  2590. } else if (isUndef(oldEndVnode)) {
  2591. oldEndVnode = oldCh[--oldEndIdx];
  2592. } else if (sameVnode(oldStartVnode, newStartVnode)) {
  2593. patchVnode(oldStartVnode, newStartVnode, insertedVnodeQueue);
  2594. oldStartVnode = oldCh[++oldStartIdx];
  2595. newStartVnode = newCh[++newStartIdx];
  2596. } else if (sameVnode(oldEndVnode, newEndVnode)) {
  2597. patchVnode(oldEndVnode, newEndVnode, insertedVnodeQueue);
  2598. oldEndVnode = oldCh[--oldEndIdx];
  2599. newEndVnode = newCh[--newEndIdx];
  2600. } else if (sameVnode(oldStartVnode, newEndVnode)) {
  2601. // Vnode moved right
  2602. patchVnode(oldStartVnode, newEndVnode, insertedVnodeQueue);
  2603. nodeOps.insertBefore(parentElm, oldStartVnode.elm, nodeOps.nextSibling(oldEndVnode.elm));
  2604. oldStartVnode = oldCh[++oldStartIdx];
  2605. newEndVnode = newCh[--newEndIdx];
  2606. } else if (sameVnode(oldEndVnode, newStartVnode)) {
  2607. // Vnode moved left
  2608. patchVnode(oldEndVnode, newStartVnode, insertedVnodeQueue);
  2609. nodeOps.insertBefore(parentElm, oldEndVnode.elm, oldStartVnode.elm);
  2610. oldEndVnode = oldCh[--oldEndIdx];
  2611. newStartVnode = newCh[++newStartIdx];
  2612. } else {
  2613. if (isUndef(oldKeyToIdx)) oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx);
  2614. idxInOld = oldKeyToIdx[newStartVnode.key];
  2615. if (isUndef(idxInOld)) {
  2616. // New element
  2617. nodeOps.insertBefore(parentElm, createElm(newStartVnode, insertedVnodeQueue), oldStartVnode.elm);
  2618. newStartVnode = newCh[++newStartIdx];
  2619. } else {
  2620. elmToMove = oldCh[idxInOld];
  2621. if (process.env.NODE_ENV !== 'production' && !elmToMove) {
  2622. warn('Duplicate track-by key: ' + idxInOld + '. ' + 'Make sure each v-for item has a unique track-by key.');
  2623. }
  2624. patchVnode(elmToMove, newStartVnode, insertedVnodeQueue);
  2625. oldCh[idxInOld] = undefined;
  2626. nodeOps.insertBefore(parentElm, elmToMove.elm, oldStartVnode.elm);
  2627. newStartVnode = newCh[++newStartIdx];
  2628. }
  2629. }
  2630. }
  2631. if (oldStartIdx > oldEndIdx) {
  2632. before = isUndef(newCh[newEndIdx + 1]) ? null : newCh[newEndIdx + 1].elm;
  2633. addVnodes(parentElm, before, newCh, newStartIdx, newEndIdx, insertedVnodeQueue);
  2634. } else if (newStartIdx > newEndIdx) {
  2635. removeVnodes(parentElm, oldCh, oldStartIdx, oldEndIdx);
  2636. }
  2637. }
  2638. function patchVnode(oldVnode, vnode, insertedVnodeQueue) {
  2639. var i = void 0,
  2640. hook = void 0;
  2641. if (isDef(i = vnode.data) && isDef(hook = i.hook) && isDef(i = hook.prepatch)) {
  2642. i(oldVnode, vnode);
  2643. }
  2644. // skip nodes with v-pre
  2645. if (isDef(i = vnode.data) && i.pre) {
  2646. return;
  2647. }
  2648. var elm = vnode.elm = oldVnode.elm;
  2649. var oldCh = oldVnode.children;
  2650. var ch = vnode.children;
  2651. if (oldVnode === vnode) return;
  2652. if (!sameVnode(oldVnode, vnode)) {
  2653. var parentElm = nodeOps.parentNode(oldVnode.elm);
  2654. elm = createElm(vnode, insertedVnodeQueue);
  2655. nodeOps.insertBefore(parentElm, elm, oldVnode.elm);
  2656. removeVnodes(parentElm, [oldVnode], 0, 0);
  2657. return;
  2658. }
  2659. if (isDef(vnode.data)) {
  2660. for (i = 0; i < cbs.update.length; ++i) {
  2661. cbs.update[i](oldVnode, vnode);
  2662. }i = vnode.data.hook;
  2663. if (isDef(i) && isDef(i = i.update)) i(oldVnode, vnode);
  2664. }
  2665. if (isUndef(vnode.text)) {
  2666. if (isDef(oldCh) && isDef(ch)) {
  2667. if (oldCh !== ch) updateChildren(elm, oldCh, ch, insertedVnodeQueue);
  2668. } else if (isDef(ch)) {
  2669. if (isDef(oldVnode.text)) nodeOps.setTextContent(elm, '');
  2670. addVnodes(elm, null, ch, 0, ch.length - 1, insertedVnodeQueue);
  2671. } else if (isDef(oldCh)) {
  2672. removeVnodes(elm, oldCh, 0, oldCh.length - 1);
  2673. } else if (isDef(oldVnode.text)) {
  2674. nodeOps.setTextContent(elm, '');
  2675. }
  2676. } else if (oldVnode.text !== vnode.text) {
  2677. nodeOps.setTextContent(elm, vnode.text);
  2678. }
  2679. if (isDef(hook) && isDef(i = hook.postpatch)) {
  2680. i(oldVnode, vnode);
  2681. }
  2682. }
  2683. function invokeInsertHook(queue) {
  2684. for (i = 0; i < queue.length; ++i) {
  2685. queue[i].data.hook.insert(queue[i]);
  2686. }
  2687. }
  2688. function hydrate(elm, vnode, insertedVnodeQueue) {
  2689. if (process.env.NODE_ENV !== 'production') {
  2690. if (!assertNodeMatch(elm, vnode)) {
  2691. return false;
  2692. }
  2693. }
  2694. vnode.elm = elm;
  2695. var tag = vnode.tag;
  2696. var data = vnode.data;
  2697. var children = vnode.children;
  2698. if (isDef(data)) {
  2699. if (isDef(i = data.hook) && isDef(i = i.init)) i(vnode);
  2700. if (isDef(i = vnode.child)) {
  2701. // child component. it should have hydrated its own tree.
  2702. invokeCreateHooks(vnode, insertedVnodeQueue);
  2703. return true;
  2704. }
  2705. }
  2706. if (isDef(tag)) {
  2707. if (isDef(children)) {
  2708. var childNodes = elm.childNodes;
  2709. for (var _i2 = 0; _i2 < children.length; _i2++) {
  2710. var success = hydrate(childNodes[_i2], children[_i2], insertedVnodeQueue);
  2711. if (!success) {
  2712. return false;
  2713. }
  2714. }
  2715. }
  2716. if (isDef(data)) {
  2717. invokeCreateHooks(vnode, insertedVnodeQueue);
  2718. }
  2719. }
  2720. return true;
  2721. }
  2722. function assertNodeMatch(node, vnode) {
  2723. if (vnode.tag) {
  2724. if (vnode.tag.indexOf('vue-component') === 0) {
  2725. return true;
  2726. } else {
  2727. return vnode.tag === node.tagName.toLowerCase() && (vnode.children ? vnode.children.length === node.childNodes.length : node.childNodes.length === 0);
  2728. }
  2729. } else {
  2730. return renderString(vnode.text) === node.data;
  2731. }
  2732. }
  2733. return function patch(oldVnode, vnode) {
  2734. var elm, parent;
  2735. var insertedVnodeQueue = [];
  2736. if (!oldVnode) {
  2737. // empty mount, create new root element
  2738. createElm(vnode, insertedVnodeQueue);
  2739. } else {
  2740. if (sameVnode(oldVnode, vnode)) {
  2741. patchVnode(oldVnode, vnode, insertedVnodeQueue);
  2742. } else {
  2743. if (isUndef(oldVnode.tag)) {
  2744. // mounting to a real element
  2745. // check if this is server-rendered content and if we can perform
  2746. // a successful hydration.
  2747. if (oldVnode.hasAttribute('server-rendered')) {
  2748. oldVnode.removeAttribute('server-rendered');
  2749. if (hydrate(oldVnode, vnode, insertedVnodeQueue)) {
  2750. invokeInsertHook(insertedVnodeQueue);
  2751. return oldVnode;
  2752. } else if (process.env.NODE_ENV !== 'production') {
  2753. warn('The client-side rendered virtual DOM tree is not matching ' + 'server-rendered content. Bailing hydration and performing ' + 'full client-side render.');
  2754. }
  2755. }
  2756. // either not server-rendered, or hydration failed.
  2757. // create an empty node and replace it
  2758. oldVnode = emptyNodeAt(oldVnode);
  2759. }
  2760. elm = oldVnode.elm;
  2761. parent = nodeOps.parentNode(elm);
  2762. createElm(vnode, insertedVnodeQueue);
  2763. if (parent !== null) {
  2764. nodeOps.insertBefore(parent, vnode.elm, nodeOps.nextSibling(elm));
  2765. removeVnodes(parent, [oldVnode], 0, 0);
  2766. }
  2767. }
  2768. }
  2769. invokeInsertHook(insertedVnodeQueue);
  2770. return vnode.elm;
  2771. };
  2772. }
  2773. // attributes that should be using props for binding
  2774. var mustUseProp = makeMap('value,selected,checked,muted');
  2775. var isEnumeratedAttr = makeMap('contenteditable,draggable,spellcheck');
  2776. 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');
  2777. var xlinkNS = 'http://www.w3.org/1999/xlink';
  2778. var isXlink = function isXlink(name) {
  2779. return name.charAt(5) === ':' && name.slice(0, 5) === 'xlink';
  2780. };
  2781. function genClassForVnode(vnode) {
  2782. var data = vnode.data;
  2783. // Important: check if this is a component container node
  2784. // or a child component root node
  2785. var i = void 0;
  2786. if ((i = vnode.child) && (i = i._vnode.data)) {
  2787. data = mergeClassData(i, data);
  2788. }
  2789. if ((i = vnode.parent) && (i = i.data)) {
  2790. data = mergeClassData(data, i);
  2791. }
  2792. return genClassFromData(data);
  2793. }
  2794. function mergeClassData(child, parent) {
  2795. return {
  2796. staticClass: concat(child.staticClass, parent.staticClass),
  2797. class: child.class ? extend(child.class, parent.class) : parent.class
  2798. };
  2799. }
  2800. function genClassFromData(data) {
  2801. var dynamicClass = data.class;
  2802. var staticClass = data.staticClass;
  2803. if (staticClass || dynamicClass) {
  2804. return concat(staticClass, stringifyClass(dynamicClass));
  2805. }
  2806. }
  2807. function concat(a, b) {
  2808. return a ? b ? a + ' ' + b : a : b || '';
  2809. }
  2810. function stringifyClass(value) {
  2811. if (!value) {
  2812. return '';
  2813. }
  2814. if (typeof value === 'string') {
  2815. return value;
  2816. }
  2817. if (isArray(value)) {
  2818. var res = '';
  2819. for (var i = 0, l = value.length; i < l; i++) {
  2820. if (value[i]) res += stringifyClass(value[i]) + ' ';
  2821. }
  2822. return res.slice(0, -1);
  2823. }
  2824. if (isObject(value)) {
  2825. var _res = '';
  2826. for (var key in value) {
  2827. if (value[key]) _res += key + ' ';
  2828. }
  2829. return _res.slice(0, -1);
  2830. }
  2831. }
  2832. var namespaceMap = {
  2833. svg: 'http://www.w3.org/2000/svg',
  2834. math: 'http://www.w3.org/1998/Math/MathML'
  2835. };
  2836. 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');
  2837. var isUnaryTag = makeMap('area,base,br,col,embed,frame,hr,img,input,isindex,keygen,' + 'link,meta,param,source,track,wbr', true);
  2838. // Elements that you can, intentionally, leave open
  2839. // (and which close themselves)
  2840. var canBeLeftOpenTag = makeMap('colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr,source', true);
  2841. // HTML5 tags https://html.spec.whatwg.org/multipage/indices.html#elements-3
  2842. // Phrasing Content https://html.spec.whatwg.org/multipage/dom.html#phrasing-content
  2843. 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);
  2844. // this map covers namespace elements that can appear as template root nodes
  2845. var isSVG = makeMap('svg,g,defs,symbol,use,image,text,circle,ellipse,' + 'line,path,polygon,polyline,rect', true);
  2846. var unknownElementCache = Object.create(null);
  2847. function isUnknownElement(tag) {
  2848. if (!inBrowser) {
  2849. return true;
  2850. }
  2851. tag = tag.toLowerCase();
  2852. if (unknownElementCache[tag] != null) {
  2853. return unknownElementCache[tag];
  2854. }
  2855. var el = document.createElement(tag);
  2856. if (tag.indexOf('-') > -1) {
  2857. // http://stackoverflow.com/a/28210364/1070244
  2858. return unknownElementCache[tag] = el.constructor === window.HTMLUnknownElement || el.constructor === window.HTMLElement;
  2859. } else {
  2860. return unknownElementCache[tag] = /HTMLUnknownElement/.test(el.toString()) &&
  2861. // Chrome returns unknown for several HTML5 elements.
  2862. // https://code.google.com/p/chromium/issues/detail?id=540526
  2863. !/^(data|time|rtc|rb)$/.test(tag);
  2864. }
  2865. }
  2866. var UA$1 = inBrowser && window.navigator.userAgent.toLowerCase();
  2867. var isIE9 = UA$1 && UA$1.indexOf('msie 9.0') > 0;
  2868. var isAndroid = UA$1 && UA$1.indexOf('android') > 0;
  2869. /**
  2870. * Query an element selector if it's not an element already.
  2871. *
  2872. * @param {String|Element} el
  2873. * @return {Element}
  2874. */
  2875. function query(el) {
  2876. if (typeof el === 'string') {
  2877. var selector = el;
  2878. el = document.querySelector(el);
  2879. if (!el) {
  2880. process.env.NODE_ENV !== 'production' && warn('Cannot find element: ' + selector);
  2881. }
  2882. }
  2883. return el;
  2884. }
  2885. function createElement$1(tagName) {
  2886. return document.createElement(tagName);
  2887. }
  2888. function createElementNS(namespace, tagName) {
  2889. return document.createElementNS(namespaceMap[namespace], tagName);
  2890. }
  2891. function createTextNode(text) {
  2892. return document.createTextNode(text);
  2893. }
  2894. function insertBefore(parentNode, newNode, referenceNode) {
  2895. parentNode.insertBefore(newNode, referenceNode);
  2896. }
  2897. function removeChild(node, child) {
  2898. node.removeChild(child);
  2899. }
  2900. function appendChild(node, child) {
  2901. node.appendChild(child);
  2902. }
  2903. function parentNode(node) {
  2904. return node.parentElement;
  2905. }
  2906. function nextSibling(node) {
  2907. return node.nextSibling;
  2908. }
  2909. function tagName(node) {
  2910. return node.tagName;
  2911. }
  2912. function setTextContent(node, text) {
  2913. node.textContent = text;
  2914. }
  2915. var nodeOps = Object.freeze({
  2916. createElement: createElement$1,
  2917. createElementNS: createElementNS,
  2918. createTextNode: createTextNode,
  2919. insertBefore: insertBefore,
  2920. removeChild: removeChild,
  2921. appendChild: appendChild,
  2922. parentNode: parentNode,
  2923. nextSibling: nextSibling,
  2924. tagName: tagName,
  2925. setTextContent: setTextContent
  2926. });
  2927. if (isIE9) {
  2928. // http://www.matts411.com/post/internet-explorer-9-oninput/
  2929. document.addEventListener('selectionchange', function () {
  2930. var el = document.activeElement;
  2931. if (el && el.vmodel) {
  2932. trigger(el);
  2933. }
  2934. });
  2935. }
  2936. var model = {
  2937. bind: function bind(el) {
  2938. if (!isAndroid) {
  2939. el.addEventListener('compositionstart', onCompositionStart);
  2940. el.addEventListener('compositionend', onCompositionEnd);
  2941. }
  2942. if (isIE9) {
  2943. el.vmodel = true;
  2944. }
  2945. },
  2946. unbind: function unbind(el) {
  2947. if (!isAndroid) {
  2948. el.removeEventListener('compositionstart', onCompositionStart);
  2949. el.removeEventListener('compositionend', onCompositionEnd);
  2950. }
  2951. }
  2952. };
  2953. function onCompositionStart(e) {
  2954. e.target.composing = true;
  2955. }
  2956. function onCompositionEnd(e) {
  2957. e.target.composing = false;
  2958. trigger(e.target);
  2959. }
  2960. function trigger(el) {
  2961. var e = document.createEvent('HTMLEvents');
  2962. e.initEvent('input', true, true);
  2963. el.dispatchEvent(e);
  2964. }
  2965. var svgNS = namespaceMap.svg;
  2966. /**
  2967. * In IE9, setAttribute('class') will result in empty class
  2968. * if the element also has the :class attribute; However in
  2969. * PhantomJS, setting `className` does not work on SVG elements...
  2970. * So we have to do a conditional check here.
  2971. *
  2972. * @param {Element} el
  2973. * @param {String} cls
  2974. */
  2975. function setClass(el, cls) {
  2976. /* istanbul ignore else */
  2977. if (!isIE9 || el.namespaceURI === svgNS) {
  2978. el.setAttribute('class', cls);
  2979. } else {
  2980. el.className = cls;
  2981. }
  2982. }
  2983. /**
  2984. * Add class with compatibility for IE & SVG
  2985. *
  2986. * @param {Element} el
  2987. * @param {String} cls
  2988. */
  2989. function addClass(el, cls) {
  2990. if (el.classList) {
  2991. if (cls.indexOf(' ') > -1) {
  2992. cls.split(/\s+/).forEach(function (c) {
  2993. return el.classList.add(c);
  2994. });
  2995. } else {
  2996. el.classList.add(cls);
  2997. }
  2998. } else {
  2999. var cur = ' ' + getClass(el) + ' ';
  3000. if (cur.indexOf(' ' + cls + ' ') < 0) {
  3001. setClass(el, (cur + cls).trim());
  3002. }
  3003. }
  3004. }
  3005. /**
  3006. * Remove class with compatibility for IE & SVG
  3007. *
  3008. * @param {Element} el
  3009. * @param {String} cls
  3010. */
  3011. function removeClass(el, cls) {
  3012. if (el.classList) {
  3013. if (cls.indexOf(' ') > -1) {
  3014. cls.split(/\s+/).forEach(function (c) {
  3015. return el.classList.remove(c);
  3016. });
  3017. } else {
  3018. el.classList.remove(cls);
  3019. }
  3020. } else {
  3021. var cur = ' ' + getClass(el) + ' ';
  3022. var tar = ' ' + cls + ' ';
  3023. while (cur.indexOf(tar) >= 0) {
  3024. cur = cur.replace(tar, ' ');
  3025. }
  3026. setClass(el, cur.trim());
  3027. }
  3028. if (!el.className) {
  3029. el.removeAttribute('class');
  3030. }
  3031. }
  3032. /**
  3033. * For IE9 compat: when both class and :class are present
  3034. * getAttribute('class') returns wrong value... but className
  3035. * on SVG elements returns an object.
  3036. *
  3037. * @param {Element} el
  3038. * @return {String}
  3039. */
  3040. function getClass(el) {
  3041. var classname = el.className;
  3042. if (typeof classname === 'object') {
  3043. classname = classname.baseVal || '';
  3044. }
  3045. return classname;
  3046. }
  3047. var TRANSITION = 'transition';
  3048. var ANIMATION = 'animation';
  3049. // Transition property/event sniffing
  3050. var transitionProp = void 0;
  3051. var transitionEndEvent = void 0;
  3052. var animationProp = void 0;
  3053. var animationEndEvent = void 0;
  3054. if (inBrowser && !isIE9) {
  3055. var isWebkitTrans = window.ontransitionend === undefined && window.onwebkittransitionend !== undefined;
  3056. var isWebkitAnim = window.onanimationend === undefined && window.onwebkitanimationend !== undefined;
  3057. transitionProp = isWebkitTrans ? 'WebkitTransition' : 'transition';
  3058. transitionEndEvent = isWebkitTrans ? 'webkitTransitionEnd' : 'transitionend';
  3059. animationProp = isWebkitAnim ? 'WebkitAnimation' : 'animation';
  3060. animationEndEvent = isWebkitAnim ? 'webkitAnimationEnd' : 'animationend';
  3061. }
  3062. var raf = inBrowser && window.requestAnimationFrame || setTimeout;
  3063. function nextFrame(fn) {
  3064. raf(function () {
  3065. raf(fn);
  3066. });
  3067. }
  3068. function enter(vnode) {
  3069. var el = vnode.elm;
  3070. // call leave callback now
  3071. if (el._leaveCb) {
  3072. el._leaveCb.cancelled = true;
  3073. el._leaveCb();
  3074. }
  3075. var data = vnode.data.transition;
  3076. if (!data) {
  3077. return;
  3078. }
  3079. if (!vnode.context.$root._mounted && !data.appear) {
  3080. return;
  3081. }
  3082. var _resolveTransition = resolveTransition(data.definition, vnode.context);
  3083. var enterClass = _resolveTransition.enterClass;
  3084. var enterActiveClass = _resolveTransition.enterActiveClass;
  3085. var beforeEnter = _resolveTransition.beforeEnter;
  3086. var enter = _resolveTransition.enter;
  3087. var afterEnter = _resolveTransition.afterEnter;
  3088. var enterCancelled = _resolveTransition.enterCancelled;
  3089. var userWantsControl = enter && enter.length > 1;
  3090. var cb = el._enterCb = once(function () {
  3091. if (enterActiveClass) {
  3092. removeTransitionClass(el, enterActiveClass);
  3093. }
  3094. if (cb.cancelled) {
  3095. enterCancelled && enterCancelled(el);
  3096. } else {
  3097. afterEnter && afterEnter(el);
  3098. }
  3099. el._enterCb = null;
  3100. });
  3101. beforeEnter && beforeEnter(el);
  3102. if (enterClass) {
  3103. addTransitionClass(el, enterClass);
  3104. nextFrame(function () {
  3105. removeTransitionClass(el, enterClass);
  3106. });
  3107. }
  3108. if (enterActiveClass) {
  3109. nextFrame(function () {
  3110. addTransitionClass(el, enterActiveClass);
  3111. if (!userWantsControl) {
  3112. whenTransitionEnds(el, cb);
  3113. }
  3114. });
  3115. }
  3116. enter && enter(el, cb);
  3117. if (!enterActiveClass && !userWantsControl) {
  3118. cb();
  3119. }
  3120. }
  3121. function leave(vnode, rm) {
  3122. var el = vnode.elm;
  3123. // call enter callback now
  3124. if (el._enterCb) {
  3125. el._enterCb.cancelled = true;
  3126. el._enterCb();
  3127. }
  3128. var data = vnode.data.transition;
  3129. if (!data) {
  3130. return rm();
  3131. }
  3132. var _resolveTransition2 = resolveTransition(data.definition, vnode.context);
  3133. var leaveClass = _resolveTransition2.leaveClass;
  3134. var leaveActiveClass = _resolveTransition2.leaveActiveClass;
  3135. var beforeLeave = _resolveTransition2.beforeLeave;
  3136. var leave = _resolveTransition2.leave;
  3137. var afterLeave = _resolveTransition2.afterLeave;
  3138. var leaveCancelled = _resolveTransition2.leaveCancelled;
  3139. var userWantsControl = leave && leave.length > 1;
  3140. var cb = el._leaveCb = once(function () {
  3141. if (leaveActiveClass) {
  3142. removeTransitionClass(el, leaveActiveClass);
  3143. }
  3144. if (cb.cancelled) {
  3145. leaveCancelled && leaveCancelled(el);
  3146. } else {
  3147. rm();
  3148. afterLeave && afterLeave(el);
  3149. }
  3150. el._leaveCb = null;
  3151. });
  3152. beforeLeave && beforeLeave(el);
  3153. if (leaveClass) {
  3154. addTransitionClass(el, leaveClass);
  3155. nextFrame(function () {
  3156. removeTransitionClass(el, leaveClass);
  3157. });
  3158. }
  3159. if (leaveActiveClass) {
  3160. nextFrame(function () {
  3161. addTransitionClass(el, leaveActiveClass);
  3162. if (!userWantsControl) {
  3163. whenTransitionEnds(el, cb);
  3164. }
  3165. });
  3166. }
  3167. leave && leave(el, cb);
  3168. if (!leaveActiveClass && !userWantsControl) {
  3169. cb();
  3170. }
  3171. }
  3172. function resolveTransition(id, context) {
  3173. var definition = id && typeof id === 'string' ? resolveAsset(context.$options, 'transitions', id) || id : id;
  3174. if (definition === true) definition = 'v';
  3175. return typeof definition === 'string' ? autoCssTransition(definition) : definition;
  3176. }
  3177. var autoCssTransition = cached(function (name) {
  3178. return {
  3179. enterClass: name + '-enter',
  3180. leaveClass: name + '-leave',
  3181. enterActiveClass: name + '-enter-active',
  3182. leaveActiveClass: name + '-leave-active'
  3183. };
  3184. });
  3185. function addTransitionClass(el, cls) {
  3186. (el._transitionClasses || (el._transitionClasses = [])).push(cls);
  3187. addClass(el, cls);
  3188. }
  3189. function removeTransitionClass(el, cls) {
  3190. remove(el._transitionClasses, cls);
  3191. removeClass(el, cls);
  3192. }
  3193. function whenTransitionEnds(el, cb) {
  3194. var _getTransitionInfo = getTransitionInfo(el);
  3195. var type = _getTransitionInfo.type;
  3196. var timeout = _getTransitionInfo.timeout;
  3197. var propCount = _getTransitionInfo.propCount;
  3198. if (!type) return cb();
  3199. var event = type === TRANSITION ? transitionEndEvent : animationEndEvent;
  3200. var ended = 0;
  3201. var end = function end() {
  3202. el.removeEventListener(event, onEnd);
  3203. cb();
  3204. };
  3205. var onEnd = function onEnd() {
  3206. if (++ended >= propCount) {
  3207. end();
  3208. }
  3209. };
  3210. setTimeout(function () {
  3211. if (ended < propCount) {
  3212. end();
  3213. }
  3214. }, timeout);
  3215. el.addEventListener(event, onEnd);
  3216. }
  3217. function getTransitionInfo(el) {
  3218. var styles = window.getComputedStyle(el);
  3219. // 1. determine the maximum duration (timeout)
  3220. var transitioneDelays = styles[transitionProp + 'Delay'].split(', ');
  3221. var transitionDurations = styles[transitionProp + 'Duration'].split(', ');
  3222. var animationDelays = styles[animationProp + 'Delay'].split(', ');
  3223. var animationDurations = styles[animationProp + 'Duration'].split(', ');
  3224. var transitionTimeout = getTimeout(transitioneDelays, transitionDurations);
  3225. var animationTimeout = getTimeout(animationDelays, animationDurations);
  3226. var timeout = Math.max(transitionTimeout, animationTimeout);
  3227. var type = timeout > 0 ? transitionTimeout > animationTimeout ? TRANSITION : ANIMATION : null;
  3228. var propCount = type ? type === TRANSITION ? transitionDurations.length : animationDurations.length : 0;
  3229. return {
  3230. type: type,
  3231. timeout: timeout,
  3232. propCount: propCount
  3233. };
  3234. }
  3235. function getTimeout(delays, durations) {
  3236. return Math.max.apply(null, durations.map(function (d, i) {
  3237. return toMs(d) + toMs(delays[i]);
  3238. }));
  3239. }
  3240. function toMs(s) {
  3241. return Number(s.slice(0, -1)) * 1000;
  3242. }
  3243. function once(fn) {
  3244. var called = false;
  3245. return function () {
  3246. if (!called) {
  3247. called = true;
  3248. fn();
  3249. }
  3250. };
  3251. }
  3252. function shouldSkipTransition(vnode) {
  3253. return(
  3254. // if this is a component root node and the compoennt's
  3255. // parent container node also has transition, skip.
  3256. vnode.parent && vnode.parent.data.transition ||
  3257. // if the element has v-show, let the runtime directive
  3258. // call the hooks instead
  3259. vnode.data.show
  3260. );
  3261. }
  3262. var transition = !transitionEndEvent ? {} : {
  3263. create: function create(_, vnode) {
  3264. if (!shouldSkipTransition(vnode)) {
  3265. enter(vnode);
  3266. }
  3267. },
  3268. remove: function remove(vnode, rm) {
  3269. if (!shouldSkipTransition(vnode)) {
  3270. leave(vnode, rm);
  3271. } else {
  3272. rm();
  3273. }
  3274. }
  3275. };
  3276. var show = {
  3277. bind: function bind(el, value, _, vnode) {
  3278. var transition = getTransition(vnode);
  3279. if (value && transition && transition.appea && !isIE9) {
  3280. enter(vnode);
  3281. }
  3282. el.style.display = value ? '' : 'none';
  3283. },
  3284. update: function update(el, value, _, vnode) {
  3285. var transition = getTransition(vnode);
  3286. if (transition && !isIE9) {
  3287. if (value) {
  3288. enter(vnode);
  3289. el.style.display = '';
  3290. } else {
  3291. leave(vnode, function () {
  3292. el.style.display = 'none';
  3293. });
  3294. }
  3295. } else {
  3296. el.style.display = value ? '' : 'none';
  3297. }
  3298. }
  3299. };
  3300. function getTransition(vnode) {
  3301. var parent = vnode.parent;
  3302. return parent && parent.data.transition != null ? parent.data.transition : vnode.data.transition;
  3303. }
  3304. var platformDirectives = {
  3305. model: model,
  3306. show: show
  3307. };
  3308. var directives = {
  3309. create: function bindDirectives(oldVnode, vnode) {
  3310. applyDirectives(oldVnode, vnode, 'bind');
  3311. },
  3312. update: function updateDirectives(oldVnode, vnode) {
  3313. applyDirectives(oldVnode, vnode, 'update', true);
  3314. },
  3315. destroy: function unbindDirectives(vnode) {
  3316. applyDirectives(null, vnode, 'unbind');
  3317. }
  3318. };
  3319. function applyDirectives(oldVnode, vnode, hook, update) {
  3320. var dirs = vnode.data.directives;
  3321. if (dirs) {
  3322. for (var i = 0; i < dirs.length; i++) {
  3323. var dir = dirs[i];
  3324. var def = resolveAsset(vnode.context.$options, 'directives', dir.name, true);
  3325. var fn = def && def[hook];
  3326. if (fn) {
  3327. // only call update if value has changed
  3328. if (update) {
  3329. var oldValue = oldVnode.data.directives[i].value;
  3330. if (oldValue === dir.value) {
  3331. continue;
  3332. }
  3333. }
  3334. fn(vnode.elm, dir.value, dir.modifiers, vnode, oldVnode);
  3335. }
  3336. }
  3337. }
  3338. }
  3339. var baseModules = [directives];
  3340. function updateAttrs(oldVnode, vnode) {
  3341. if (!oldVnode.data.attrs && !vnode.data.attrs) {
  3342. return;
  3343. }
  3344. var key = void 0,
  3345. cur = void 0,
  3346. old = void 0;
  3347. var elm = vnode.elm;
  3348. var oldAttrs = oldVnode.data.attrs || {};
  3349. var attrs = vnode.data.attrs || {};
  3350. for (key in attrs) {
  3351. cur = attrs[key];
  3352. old = oldAttrs[key];
  3353. if (old !== cur) {
  3354. setAttr(elm, key, cur);
  3355. }
  3356. }
  3357. for (key in oldAttrs) {
  3358. if (attrs[key] == null) {
  3359. if (isXlink(key)) {
  3360. elm.removeAttributeNS(xlinkNS, key);
  3361. } else {
  3362. elm.removeAttribute(key);
  3363. }
  3364. }
  3365. }
  3366. }
  3367. function setAttr(el, key, value) {
  3368. if (isBooleanAttr(key)) {
  3369. if (value == null) {
  3370. el.removeAttribute(key);
  3371. } else {
  3372. el.setAttribute(key, key);
  3373. }
  3374. } else if (isEnumeratedAttr(key)) {
  3375. el.setAttribute(key, value == null ? 'false' : 'true');
  3376. } else if (isXlink(key)) {
  3377. el.setAttributeNS(xlinkNS, key, value);
  3378. } else {
  3379. el.setAttribute(key, value);
  3380. }
  3381. }
  3382. var attrs = {
  3383. create: function create(_, vnode) {
  3384. var attrs = vnode.data.staticAttrs;
  3385. if (attrs) {
  3386. for (var key in attrs) {
  3387. if (!vnode.elm) debugger;
  3388. setAttr(vnode.elm, key, attrs[key]);
  3389. }
  3390. }
  3391. updateAttrs(_, vnode);
  3392. },
  3393. update: updateAttrs
  3394. };
  3395. function updateClass(oldVnode, vnode) {
  3396. var el = vnode.elm;
  3397. var data = vnode.data;
  3398. if (!data.staticClass && !data.class) {
  3399. return;
  3400. }
  3401. var cls = genClassForVnode(vnode);
  3402. // handle transition classes
  3403. var transitionClass = el._transitionClasses;
  3404. if (transitionClass) {
  3405. cls = concat(cls, stringifyClass(transitionClass));
  3406. }
  3407. // set the class
  3408. if (cls !== el._prevClass) {
  3409. setClass(el, cls);
  3410. el._prevClass = cls;
  3411. }
  3412. }
  3413. var klass = {
  3414. create: updateClass,
  3415. update: updateClass
  3416. };
  3417. function updateDOMListeners(oldVnode, vnode) {
  3418. if (!oldVnode.data.on && !vnode.data.on) {
  3419. return;
  3420. }
  3421. var on = vnode.data.on || {};
  3422. var oldOn = oldVnode.data.on || {};
  3423. updateListeners(on, oldOn, function (event, handler, capture) {
  3424. vnode.elm.addEventListener(event, handler, capture);
  3425. });
  3426. }
  3427. var events = {
  3428. create: updateDOMListeners,
  3429. update: updateDOMListeners
  3430. };
  3431. function updateProps(oldVnode, vnode) {
  3432. if (!oldVnode.data.props && !vnode.data.props) {
  3433. return;
  3434. }
  3435. var key = void 0,
  3436. cur = void 0,
  3437. old = void 0;
  3438. var elm = vnode.elm;
  3439. var oldProps = oldVnode.data.props || {};
  3440. var props = vnode.data.props || {};
  3441. for (key in oldProps) {
  3442. if (props[key] == null) {
  3443. elm[key] = undefined;
  3444. }
  3445. }
  3446. for (key in props) {
  3447. cur = props[key];
  3448. old = oldProps[key];
  3449. if (old !== cur) {
  3450. if (key === 'value') {
  3451. // store value as _value as well since
  3452. // non-string values will be stringified
  3453. if (elm._value !== cur) {
  3454. elm.value = elm._value = cur;
  3455. }
  3456. } else {
  3457. elm[key] = cur;
  3458. }
  3459. }
  3460. }
  3461. }
  3462. var props = {
  3463. create: updateProps,
  3464. update: updateProps
  3465. };
  3466. var prefixes = ['Webkit', 'Moz', 'ms'];
  3467. var testEl = inBrowser && document.createElement('div');
  3468. var normalize = cached(function (prop) {
  3469. prop = camelize(prop);
  3470. if (prop !== 'filter' && prop in testEl.style) {
  3471. return prop;
  3472. }
  3473. var upper = prop.charAt(0).toUpperCase() + prop.slice(1);
  3474. for (var i = 0; i < prefixes.length; i++) {
  3475. var prefixed = prefixes[i] + upper;
  3476. if (prefixed in testEl.style) {
  3477. return prefixed;
  3478. }
  3479. }
  3480. });
  3481. function updateStyle(oldVnode, vnode) {
  3482. if (!oldVnode.data.style && !vnode.data.style) {
  3483. return;
  3484. }
  3485. var cur = void 0,
  3486. name = void 0;
  3487. var elm = vnode.elm;
  3488. var oldStyle = oldVnode.data.style || {};
  3489. var style = vnode.data.style || {};
  3490. // handle array syntax
  3491. if (isArray(style)) {
  3492. style = vnode.data.style = toObject(style);
  3493. }
  3494. for (name in oldStyle) {
  3495. if (!style[name]) {
  3496. elm.style[normalize(name)] = '';
  3497. }
  3498. }
  3499. for (name in style) {
  3500. cur = style[name];
  3501. if (cur !== oldStyle[name]) {
  3502. elm.style[normalize(name)] = cur;
  3503. }
  3504. }
  3505. }
  3506. function toObject(arr) {
  3507. var res = arr[0] || {};
  3508. for (var i = 1; i < arr.length; i++) {
  3509. if (arr[i]) {
  3510. extend(res, arr[i]);
  3511. }
  3512. }
  3513. return res;
  3514. }
  3515. var style = {
  3516. create: updateStyle,
  3517. update: updateStyle
  3518. };
  3519. var platformModules = [attrs, klass, events, props, style, transition];
  3520. // install platform specific utils
  3521. Vue.config.isUnknownElement = isUnknownElement;
  3522. Vue.config.isReservedTag = isReservedTag;
  3523. // install platform runtime directives
  3524. Vue.options.directives = platformDirectives;
  3525. // install platform patch function
  3526. var modules = baseModules.concat(platformModules);
  3527. Vue.prototype.__patch__ = inBrowser ? createPatchFunction({ nodeOps: nodeOps, modules: modules }) : function noop() {};
  3528. // wrap mount
  3529. Vue.prototype.$mount = function (el) {
  3530. this.$el = el && query(el);
  3531. this._mount();
  3532. };
  3533. module.exports = Vue;