PageRenderTime 33ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/files/vue/1.0.13/vue.common.js

https://gitlab.com/Mirros/jsdelivr
JavaScript | 2272 lines | 1497 code | 189 blank | 586 comment | 220 complexity | f3add5212a3fb09844e7255d58232bf4 MD5 | raw file
  1. /*!
  2. * Vue.js v1.0.13
  3. * (c) 2015 Evan You
  4. * Released under the MIT License.
  5. */
  6. 'use strict';
  7. function set(obj, key, val) {
  8. if (hasOwn(obj, key)) {
  9. obj[key] = val;
  10. return;
  11. }
  12. if (obj._isVue) {
  13. set(obj._data, key, val);
  14. return;
  15. }
  16. var ob = obj.__ob__;
  17. if (!ob) {
  18. obj[key] = val;
  19. return;
  20. }
  21. ob.convert(key, val);
  22. ob.dep.notify();
  23. if (ob.vms) {
  24. var i = ob.vms.length;
  25. while (i--) {
  26. var vm = ob.vms[i];
  27. vm._proxy(key);
  28. vm._digest();
  29. }
  30. }
  31. return val;
  32. }
  33. /**
  34. * Delete a property and trigger change if necessary.
  35. *
  36. * @param {Object} obj
  37. * @param {String} key
  38. */
  39. function del(obj, key) {
  40. if (!hasOwn(obj, key)) {
  41. return;
  42. }
  43. delete obj[key];
  44. var ob = obj.__ob__;
  45. if (!ob) {
  46. return;
  47. }
  48. ob.dep.notify();
  49. if (ob.vms) {
  50. var i = ob.vms.length;
  51. while (i--) {
  52. var vm = ob.vms[i];
  53. vm._unproxy(key);
  54. vm._digest();
  55. }
  56. }
  57. }
  58. var hasOwnProperty = Object.prototype.hasOwnProperty;
  59. /**
  60. * Check whether the object has the property.
  61. *
  62. * @param {Object} obj
  63. * @param {String} key
  64. * @return {Boolean}
  65. */
  66. function hasOwn(obj, key) {
  67. return hasOwnProperty.call(obj, key);
  68. }
  69. /**
  70. * Check if an expression is a literal value.
  71. *
  72. * @param {String} exp
  73. * @return {Boolean}
  74. */
  75. var literalValueRE = /^\s?(true|false|[\d\.]+|'[^']*'|"[^"]*")\s?$/;
  76. function isLiteral(exp) {
  77. return literalValueRE.test(exp);
  78. }
  79. /**
  80. * Check if a string starts with $ or _
  81. *
  82. * @param {String} str
  83. * @return {Boolean}
  84. */
  85. function isReserved(str) {
  86. var c = (str + '').charCodeAt(0);
  87. return c === 0x24 || c === 0x5F;
  88. }
  89. /**
  90. * Guard text output, make sure undefined outputs
  91. * empty string
  92. *
  93. * @param {*} value
  94. * @return {String}
  95. */
  96. function _toString(value) {
  97. return value == null ? '' : value.toString();
  98. }
  99. /**
  100. * Check and convert possible numeric strings to numbers
  101. * before setting back to data
  102. *
  103. * @param {*} value
  104. * @return {*|Number}
  105. */
  106. function toNumber(value) {
  107. if (typeof value !== 'string') {
  108. return value;
  109. } else {
  110. var parsed = Number(value);
  111. return isNaN(parsed) ? value : parsed;
  112. }
  113. }
  114. /**
  115. * Convert string boolean literals into real booleans.
  116. *
  117. * @param {*} value
  118. * @return {*|Boolean}
  119. */
  120. function toBoolean(value) {
  121. return value === 'true' ? true : value === 'false' ? false : value;
  122. }
  123. /**
  124. * Strip quotes from a string
  125. *
  126. * @param {String} str
  127. * @return {String | false}
  128. */
  129. function stripQuotes(str) {
  130. var a = str.charCodeAt(0);
  131. var b = str.charCodeAt(str.length - 1);
  132. return a === b && (a === 0x22 || a === 0x27) ? str.slice(1, -1) : str;
  133. }
  134. /**
  135. * Camelize a hyphen-delmited string.
  136. *
  137. * @param {String} str
  138. * @return {String}
  139. */
  140. var camelizeRE = /-(\w)/g;
  141. function camelize(str) {
  142. return str.replace(camelizeRE, toUpper);
  143. }
  144. function toUpper(_, c) {
  145. return c ? c.toUpperCase() : '';
  146. }
  147. /**
  148. * Hyphenate a camelCase string.
  149. *
  150. * @param {String} str
  151. * @return {String}
  152. */
  153. var hyphenateRE = /([a-z\d])([A-Z])/g;
  154. function hyphenate(str) {
  155. return str.replace(hyphenateRE, '$1-$2').toLowerCase();
  156. }
  157. /**
  158. * Converts hyphen/underscore/slash delimitered names into
  159. * camelized classNames.
  160. *
  161. * e.g. my-component => MyComponent
  162. * some_else => SomeElse
  163. * some/comp => SomeComp
  164. *
  165. * @param {String} str
  166. * @return {String}
  167. */
  168. var classifyRE = /(?:^|[-_\/])(\w)/g;
  169. function classify(str) {
  170. return str.replace(classifyRE, toUpper);
  171. }
  172. /**
  173. * Simple bind, faster than native
  174. *
  175. * @param {Function} fn
  176. * @param {Object} ctx
  177. * @return {Function}
  178. */
  179. function bind$1(fn, ctx) {
  180. return function (a) {
  181. var l = arguments.length;
  182. return l ? l > 1 ? fn.apply(ctx, arguments) : fn.call(ctx, a) : fn.call(ctx);
  183. };
  184. }
  185. /**
  186. * Convert an Array-like object to a real Array.
  187. *
  188. * @param {Array-like} list
  189. * @param {Number} [start] - start index
  190. * @return {Array}
  191. */
  192. function toArray(list, start) {
  193. start = start || 0;
  194. var i = list.length - start;
  195. var ret = new Array(i);
  196. while (i--) {
  197. ret[i] = list[i + start];
  198. }
  199. return ret;
  200. }
  201. /**
  202. * Mix properties into target object.
  203. *
  204. * @param {Object} to
  205. * @param {Object} from
  206. */
  207. function extend(to, from) {
  208. var keys = Object.keys(from);
  209. var i = keys.length;
  210. while (i--) {
  211. to[keys[i]] = from[keys[i]];
  212. }
  213. return to;
  214. }
  215. /**
  216. * Quick object check - this is primarily used to tell
  217. * Objects from primitive values when we know the value
  218. * is a JSON-compliant type.
  219. *
  220. * @param {*} obj
  221. * @return {Boolean}
  222. */
  223. function isObject(obj) {
  224. return obj !== null && typeof obj === 'object';
  225. }
  226. /**
  227. * Strict object type check. Only returns true
  228. * for plain JavaScript objects.
  229. *
  230. * @param {*} obj
  231. * @return {Boolean}
  232. */
  233. var toString = Object.prototype.toString;
  234. var OBJECT_STRING = '[object Object]';
  235. function isPlainObject(obj) {
  236. return toString.call(obj) === OBJECT_STRING;
  237. }
  238. /**
  239. * Array type check.
  240. *
  241. * @param {*} obj
  242. * @return {Boolean}
  243. */
  244. var isArray = Array.isArray;
  245. /**
  246. * Define a non-enumerable property
  247. *
  248. * @param {Object} obj
  249. * @param {String} key
  250. * @param {*} val
  251. * @param {Boolean} [enumerable]
  252. */
  253. function def(obj, key, val, enumerable) {
  254. Object.defineProperty(obj, key, {
  255. value: val,
  256. enumerable: !!enumerable,
  257. writable: true,
  258. configurable: true
  259. });
  260. }
  261. /**
  262. * Debounce a function so it only gets called after the
  263. * input stops arriving after the given wait period.
  264. *
  265. * @param {Function} func
  266. * @param {Number} wait
  267. * @return {Function} - the debounced function
  268. */
  269. function _debounce(func, wait) {
  270. var timeout, args, context, timestamp, result;
  271. var later = function later() {
  272. var last = Date.now() - timestamp;
  273. if (last < wait && last >= 0) {
  274. timeout = setTimeout(later, wait - last);
  275. } else {
  276. timeout = null;
  277. result = func.apply(context, args);
  278. if (!timeout) context = args = null;
  279. }
  280. };
  281. return function () {
  282. context = this;
  283. args = arguments;
  284. timestamp = Date.now();
  285. if (!timeout) {
  286. timeout = setTimeout(later, wait);
  287. }
  288. return result;
  289. };
  290. }
  291. /**
  292. * Manual indexOf because it's slightly faster than
  293. * native.
  294. *
  295. * @param {Array} arr
  296. * @param {*} obj
  297. */
  298. function indexOf(arr, obj) {
  299. var i = arr.length;
  300. while (i--) {
  301. if (arr[i] === obj) return i;
  302. }
  303. return -1;
  304. }
  305. /**
  306. * Make a cancellable version of an async callback.
  307. *
  308. * @param {Function} fn
  309. * @return {Function}
  310. */
  311. function cancellable(fn) {
  312. var cb = function cb() {
  313. if (!cb.cancelled) {
  314. return fn.apply(this, arguments);
  315. }
  316. };
  317. cb.cancel = function () {
  318. cb.cancelled = true;
  319. };
  320. return cb;
  321. }
  322. /**
  323. * Check if two values are loosely equal - that is,
  324. * if they are plain objects, do they have the same shape?
  325. *
  326. * @param {*} a
  327. * @param {*} b
  328. * @return {Boolean}
  329. */
  330. function looseEqual(a, b) {
  331. /* eslint-disable eqeqeq */
  332. return a == b || (isObject(a) && isObject(b) ? JSON.stringify(a) === JSON.stringify(b) : false);
  333. /* eslint-enable eqeqeq */
  334. }
  335. var hasProto = ('__proto__' in {});
  336. // Browser environment sniffing
  337. var inBrowser = typeof window !== 'undefined' && Object.prototype.toString.call(window) !== '[object Object]';
  338. var isIE9 = inBrowser && navigator.userAgent.toLowerCase().indexOf('msie 9.0') > 0;
  339. var isAndroid = inBrowser && navigator.userAgent.toLowerCase().indexOf('android') > 0;
  340. var transitionProp = undefined;
  341. var transitionEndEvent = undefined;
  342. var animationProp = undefined;
  343. var animationEndEvent = undefined;
  344. // Transition property/event sniffing
  345. if (inBrowser && !isIE9) {
  346. var isWebkitTrans = window.ontransitionend === undefined && window.onwebkittransitionend !== undefined;
  347. var isWebkitAnim = window.onanimationend === undefined && window.onwebkitanimationend !== undefined;
  348. transitionProp = isWebkitTrans ? 'WebkitTransition' : 'transition';
  349. transitionEndEvent = isWebkitTrans ? 'webkitTransitionEnd' : 'transitionend';
  350. animationProp = isWebkitAnim ? 'WebkitAnimation' : 'animation';
  351. animationEndEvent = isWebkitAnim ? 'webkitAnimationEnd' : 'animationend';
  352. }
  353. /**
  354. * Defer a task to execute it asynchronously. Ideally this
  355. * should be executed as a microtask, so we leverage
  356. * MutationObserver if it's available, and fallback to
  357. * setTimeout(0).
  358. *
  359. * @param {Function} cb
  360. * @param {Object} ctx
  361. */
  362. var nextTick = (function () {
  363. var callbacks = [];
  364. var pending = false;
  365. var timerFunc;
  366. function nextTickHandler() {
  367. pending = false;
  368. var copies = callbacks.slice(0);
  369. callbacks = [];
  370. for (var i = 0; i < copies.length; i++) {
  371. copies[i]();
  372. }
  373. }
  374. /* istanbul ignore if */
  375. if (typeof MutationObserver !== 'undefined') {
  376. var counter = 1;
  377. var observer = new MutationObserver(nextTickHandler);
  378. var textNode = document.createTextNode(counter);
  379. observer.observe(textNode, {
  380. characterData: true
  381. });
  382. timerFunc = function () {
  383. counter = (counter + 1) % 2;
  384. textNode.data = counter;
  385. };
  386. } else {
  387. timerFunc = setTimeout;
  388. }
  389. return function (cb, ctx) {
  390. var func = ctx ? function () {
  391. cb.call(ctx);
  392. } : cb;
  393. callbacks.push(func);
  394. if (pending) return;
  395. pending = true;
  396. timerFunc(nextTickHandler, 0);
  397. };
  398. })();
  399. function Cache(limit) {
  400. this.size = 0;
  401. this.limit = limit;
  402. this.head = this.tail = undefined;
  403. this._keymap = Object.create(null);
  404. }
  405. var p = Cache.prototype;
  406. /**
  407. * Put <value> into the cache associated with <key>.
  408. * Returns the entry which was removed to make room for
  409. * the new entry. Otherwise undefined is returned.
  410. * (i.e. if there was enough room already).
  411. *
  412. * @param {String} key
  413. * @param {*} value
  414. * @return {Entry|undefined}
  415. */
  416. p.put = function (key, value) {
  417. var entry = {
  418. key: key,
  419. value: value
  420. };
  421. this._keymap[key] = entry;
  422. if (this.tail) {
  423. this.tail.newer = entry;
  424. entry.older = this.tail;
  425. } else {
  426. this.head = entry;
  427. }
  428. this.tail = entry;
  429. if (this.size === this.limit) {
  430. return this.shift();
  431. } else {
  432. this.size++;
  433. }
  434. };
  435. /**
  436. * Purge the least recently used (oldest) entry from the
  437. * cache. Returns the removed entry or undefined if the
  438. * cache was empty.
  439. */
  440. p.shift = function () {
  441. var entry = this.head;
  442. if (entry) {
  443. this.head = this.head.newer;
  444. this.head.older = undefined;
  445. entry.newer = entry.older = undefined;
  446. this._keymap[entry.key] = undefined;
  447. }
  448. return entry;
  449. };
  450. /**
  451. * Get and register recent use of <key>. Returns the value
  452. * associated with <key> or undefined if not in cache.
  453. *
  454. * @param {String} key
  455. * @param {Boolean} returnEntry
  456. * @return {Entry|*}
  457. */
  458. p.get = function (key, returnEntry) {
  459. var entry = this._keymap[key];
  460. if (entry === undefined) return;
  461. if (entry === this.tail) {
  462. return returnEntry ? entry : entry.value;
  463. }
  464. // HEAD--------------TAIL
  465. // <.older .newer>
  466. // <--- add direction --
  467. // A B C <D> E
  468. if (entry.newer) {
  469. if (entry === this.head) {
  470. this.head = entry.newer;
  471. }
  472. entry.newer.older = entry.older; // C <-- E.
  473. }
  474. if (entry.older) {
  475. entry.older.newer = entry.newer; // C. --> E
  476. }
  477. entry.newer = undefined; // D --x
  478. entry.older = this.tail; // D. --> E
  479. if (this.tail) {
  480. this.tail.newer = entry; // E. <-- D
  481. }
  482. this.tail = entry;
  483. return returnEntry ? entry : entry.value;
  484. };
  485. var cache$1 = new Cache(1000);
  486. var filterTokenRE = /[^\s'"]+|'[^']*'|"[^"]*"/g;
  487. var reservedArgRE = /^in$|^-?\d+/;
  488. /**
  489. * Parser state
  490. */
  491. var str;
  492. var dir;
  493. var c;
  494. var prev;
  495. var i;
  496. var l;
  497. var lastFilterIndex;
  498. var inSingle;
  499. var inDouble;
  500. var curly;
  501. var square;
  502. var paren;
  503. /**
  504. * Push a filter to the current directive object
  505. */
  506. function pushFilter() {
  507. var exp = str.slice(lastFilterIndex, i).trim();
  508. var filter;
  509. if (exp) {
  510. filter = {};
  511. var tokens = exp.match(filterTokenRE);
  512. filter.name = tokens[0];
  513. if (tokens.length > 1) {
  514. filter.args = tokens.slice(1).map(processFilterArg);
  515. }
  516. }
  517. if (filter) {
  518. (dir.filters = dir.filters || []).push(filter);
  519. }
  520. lastFilterIndex = i + 1;
  521. }
  522. /**
  523. * Check if an argument is dynamic and strip quotes.
  524. *
  525. * @param {String} arg
  526. * @return {Object}
  527. */
  528. function processFilterArg(arg) {
  529. if (reservedArgRE.test(arg)) {
  530. return {
  531. value: toNumber(arg),
  532. dynamic: false
  533. };
  534. } else {
  535. var stripped = stripQuotes(arg);
  536. var dynamic = stripped === arg;
  537. return {
  538. value: dynamic ? arg : stripped,
  539. dynamic: dynamic
  540. };
  541. }
  542. }
  543. /**
  544. * Parse a directive value and extract the expression
  545. * and its filters into a descriptor.
  546. *
  547. * Example:
  548. *
  549. * "a + 1 | uppercase" will yield:
  550. * {
  551. * expression: 'a + 1',
  552. * filters: [
  553. * { name: 'uppercase', args: null }
  554. * ]
  555. * }
  556. *
  557. * @param {String} str
  558. * @return {Object}
  559. */
  560. function parseDirective(s) {
  561. var hit = cache$1.get(s);
  562. if (hit) {
  563. return hit;
  564. }
  565. // reset parser state
  566. str = s;
  567. inSingle = inDouble = false;
  568. curly = square = paren = 0;
  569. lastFilterIndex = 0;
  570. dir = {};
  571. for (i = 0, l = str.length; i < l; i++) {
  572. prev = c;
  573. c = str.charCodeAt(i);
  574. if (inSingle) {
  575. // check single quote
  576. if (c === 0x27 && prev !== 0x5C) inSingle = !inSingle;
  577. } else if (inDouble) {
  578. // check double quote
  579. if (c === 0x22 && prev !== 0x5C) inDouble = !inDouble;
  580. } else if (c === 0x7C && // pipe
  581. str.charCodeAt(i + 1) !== 0x7C && str.charCodeAt(i - 1) !== 0x7C) {
  582. if (dir.expression == null) {
  583. // first filter, end of expression
  584. lastFilterIndex = i + 1;
  585. dir.expression = str.slice(0, i).trim();
  586. } else {
  587. // already has filter
  588. pushFilter();
  589. }
  590. } else {
  591. switch (c) {
  592. case 0x22:
  593. inDouble = true;break; // "
  594. case 0x27:
  595. inSingle = true;break; // '
  596. case 0x28:
  597. paren++;break; // (
  598. case 0x29:
  599. paren--;break; // )
  600. case 0x5B:
  601. square++;break; // [
  602. case 0x5D:
  603. square--;break; // ]
  604. case 0x7B:
  605. curly++;break; // {
  606. case 0x7D:
  607. curly--;break; // }
  608. }
  609. }
  610. }
  611. if (dir.expression == null) {
  612. dir.expression = str.slice(0, i).trim();
  613. } else if (lastFilterIndex !== 0) {
  614. pushFilter();
  615. }
  616. cache$1.put(s, dir);
  617. return dir;
  618. }
  619. var directive = Object.freeze({
  620. parseDirective: parseDirective
  621. });
  622. var regexEscapeRE = /[-.*+?^${}()|[\]\/\\]/g;
  623. var cache = undefined;
  624. var tagRE = undefined;
  625. var htmlRE = undefined;
  626. /**
  627. * Escape a string so it can be used in a RegExp
  628. * constructor.
  629. *
  630. * @param {String} str
  631. */
  632. function escapeRegex(str) {
  633. return str.replace(regexEscapeRE, '\\$&');
  634. }
  635. function compileRegex() {
  636. var open = escapeRegex(config.delimiters[0]);
  637. var close = escapeRegex(config.delimiters[1]);
  638. var unsafeOpen = escapeRegex(config.unsafeDelimiters[0]);
  639. var unsafeClose = escapeRegex(config.unsafeDelimiters[1]);
  640. tagRE = new RegExp(unsafeOpen + '(.+?)' + unsafeClose + '|' + open + '(.+?)' + close, 'g');
  641. htmlRE = new RegExp('^' + unsafeOpen + '.*' + unsafeClose + '$');
  642. // reset cache
  643. cache = new Cache(1000);
  644. }
  645. /**
  646. * Parse a template text string into an array of tokens.
  647. *
  648. * @param {String} text
  649. * @return {Array<Object> | null}
  650. * - {String} type
  651. * - {String} value
  652. * - {Boolean} [html]
  653. * - {Boolean} [oneTime]
  654. */
  655. function parseText(text) {
  656. if (!cache) {
  657. compileRegex();
  658. }
  659. var hit = cache.get(text);
  660. if (hit) {
  661. return hit;
  662. }
  663. text = text.replace(/\n/g, '');
  664. if (!tagRE.test(text)) {
  665. return null;
  666. }
  667. var tokens = [];
  668. var lastIndex = tagRE.lastIndex = 0;
  669. var match, index, html, value, first, oneTime;
  670. /* eslint-disable no-cond-assign */
  671. while (match = tagRE.exec(text)) {
  672. /* eslint-enable no-cond-assign */
  673. index = match.index;
  674. // push text token
  675. if (index > lastIndex) {
  676. tokens.push({
  677. value: text.slice(lastIndex, index)
  678. });
  679. }
  680. // tag token
  681. html = htmlRE.test(match[0]);
  682. value = html ? match[1] : match[2];
  683. first = value.charCodeAt(0);
  684. oneTime = first === 42; // *
  685. value = oneTime ? value.slice(1) : value;
  686. tokens.push({
  687. tag: true,
  688. value: value.trim(),
  689. html: html,
  690. oneTime: oneTime
  691. });
  692. lastIndex = index + match[0].length;
  693. }
  694. if (lastIndex < text.length) {
  695. tokens.push({
  696. value: text.slice(lastIndex)
  697. });
  698. }
  699. cache.put(text, tokens);
  700. return tokens;
  701. }
  702. /**
  703. * Format a list of tokens into an expression.
  704. * e.g. tokens parsed from 'a {{b}} c' can be serialized
  705. * into one single expression as '"a " + b + " c"'.
  706. *
  707. * @param {Array} tokens
  708. * @return {String}
  709. */
  710. function tokensToExp(tokens) {
  711. if (tokens.length > 1) {
  712. return tokens.map(function (token) {
  713. return formatToken(token);
  714. }).join('+');
  715. } else {
  716. return formatToken(tokens[0], true);
  717. }
  718. }
  719. /**
  720. * Format a single token.
  721. *
  722. * @param {Object} token
  723. * @param {Boolean} single
  724. * @return {String}
  725. */
  726. function formatToken(token, single) {
  727. return token.tag ? inlineFilters(token.value, single) : '"' + token.value + '"';
  728. }
  729. /**
  730. * For an attribute with multiple interpolation tags,
  731. * e.g. attr="some-{{thing | filter}}", in order to combine
  732. * the whole thing into a single watchable expression, we
  733. * have to inline those filters. This function does exactly
  734. * that. This is a bit hacky but it avoids heavy changes
  735. * to directive parser and watcher mechanism.
  736. *
  737. * @param {String} exp
  738. * @param {Boolean} single
  739. * @return {String}
  740. */
  741. var filterRE$1 = /[^|]\|[^|]/;
  742. function inlineFilters(exp, single) {
  743. if (!filterRE$1.test(exp)) {
  744. return single ? exp : '(' + exp + ')';
  745. } else {
  746. var dir = parseDirective(exp);
  747. if (!dir.filters) {
  748. return '(' + exp + ')';
  749. } else {
  750. return 'this._applyFilters(' + dir.expression + // value
  751. ',null,' + // oldValue (null for read)
  752. JSON.stringify(dir.filters) + // filter descriptors
  753. ',false)'; // write?
  754. }
  755. }
  756. }
  757. var text$1 = Object.freeze({
  758. compileRegex: compileRegex,
  759. parseText: parseText,
  760. tokensToExp: tokensToExp
  761. });
  762. var delimiters = ['{{', '}}'];
  763. var unsafeDelimiters = ['{{{', '}}}'];
  764. var config = Object.defineProperties({
  765. /**
  766. * Whether to print debug messages.
  767. * Also enables stack trace for warnings.
  768. *
  769. * @type {Boolean}
  770. */
  771. debug: false,
  772. /**
  773. * Whether to suppress warnings.
  774. *
  775. * @type {Boolean}
  776. */
  777. silent: false,
  778. /**
  779. * Whether to use async rendering.
  780. */
  781. async: true,
  782. /**
  783. * Whether to warn against errors caught when evaluating
  784. * expressions.
  785. */
  786. warnExpressionErrors: true,
  787. /**
  788. * Whether or not to handle fully object properties which
  789. * are already backed by getters and seters. Depending on
  790. * use case and environment, this might introduce non-neglible
  791. * performance penalties.
  792. */
  793. convertAllProperties: false,
  794. /**
  795. * Internal flag to indicate the delimiters have been
  796. * changed.
  797. *
  798. * @type {Boolean}
  799. */
  800. _delimitersChanged: true,
  801. /**
  802. * List of asset types that a component can own.
  803. *
  804. * @type {Array}
  805. */
  806. _assetTypes: ['component', 'directive', 'elementDirective', 'filter', 'transition', 'partial'],
  807. /**
  808. * prop binding modes
  809. */
  810. _propBindingModes: {
  811. ONE_WAY: 0,
  812. TWO_WAY: 1,
  813. ONE_TIME: 2
  814. },
  815. /**
  816. * Max circular updates allowed in a batcher flush cycle.
  817. */
  818. _maxUpdateCount: 100
  819. }, {
  820. delimiters: { /**
  821. * Interpolation delimiters. Changing these would trigger
  822. * the text parser to re-compile the regular expressions.
  823. *
  824. * @type {Array<String>}
  825. */
  826. get: function get() {
  827. return delimiters;
  828. },
  829. set: function set(val) {
  830. delimiters = val;
  831. compileRegex();
  832. },
  833. configurable: true,
  834. enumerable: true
  835. },
  836. unsafeDelimiters: {
  837. get: function get() {
  838. return unsafeDelimiters;
  839. },
  840. set: function set(val) {
  841. unsafeDelimiters = val;
  842. compileRegex();
  843. },
  844. configurable: true,
  845. enumerable: true
  846. }
  847. });
  848. var warn = undefined;
  849. if (process.env.NODE_ENV !== 'production') {
  850. (function () {
  851. var hasConsole = typeof console !== 'undefined';
  852. warn = function (msg, e) {
  853. if (hasConsole && (!config.silent || config.debug)) {
  854. console.warn('[Vue warn]: ' + msg);
  855. /* istanbul ignore if */
  856. if (config.debug) {
  857. if (e) {
  858. throw e;
  859. } else {
  860. console.warn(new Error('Warning Stack Trace').stack);
  861. }
  862. }
  863. }
  864. };
  865. })();
  866. }
  867. /**
  868. * Append with transition.
  869. *
  870. * @param {Element} el
  871. * @param {Element} target
  872. * @param {Vue} vm
  873. * @param {Function} [cb]
  874. */
  875. function appendWithTransition(el, target, vm, cb) {
  876. applyTransition(el, 1, function () {
  877. target.appendChild(el);
  878. }, vm, cb);
  879. }
  880. /**
  881. * InsertBefore with transition.
  882. *
  883. * @param {Element} el
  884. * @param {Element} target
  885. * @param {Vue} vm
  886. * @param {Function} [cb]
  887. */
  888. function beforeWithTransition(el, target, vm, cb) {
  889. applyTransition(el, 1, function () {
  890. before(el, target);
  891. }, vm, cb);
  892. }
  893. /**
  894. * Remove with transition.
  895. *
  896. * @param {Element} el
  897. * @param {Vue} vm
  898. * @param {Function} [cb]
  899. */
  900. function removeWithTransition(el, vm, cb) {
  901. applyTransition(el, -1, function () {
  902. remove(el);
  903. }, vm, cb);
  904. }
  905. /**
  906. * Apply transitions with an operation callback.
  907. *
  908. * @param {Element} el
  909. * @param {Number} direction
  910. * 1: enter
  911. * -1: leave
  912. * @param {Function} op - the actual DOM operation
  913. * @param {Vue} vm
  914. * @param {Function} [cb]
  915. */
  916. function applyTransition(el, direction, op, vm, cb) {
  917. var transition = el.__v_trans;
  918. if (!transition ||
  919. // skip if there are no js hooks and CSS transition is
  920. // not supported
  921. !transition.hooks && !transitionEndEvent ||
  922. // skip transitions for initial compile
  923. !vm._isCompiled ||
  924. // if the vm is being manipulated by a parent directive
  925. // during the parent's compilation phase, skip the
  926. // animation.
  927. vm.$parent && !vm.$parent._isCompiled) {
  928. op();
  929. if (cb) cb();
  930. return;
  931. }
  932. var action = direction > 0 ? 'enter' : 'leave';
  933. transition[action](op, cb);
  934. }
  935. /**
  936. * Query an element selector if it's not an element already.
  937. *
  938. * @param {String|Element} el
  939. * @return {Element}
  940. */
  941. function query(el) {
  942. if (typeof el === 'string') {
  943. var selector = el;
  944. el = document.querySelector(el);
  945. if (!el) {
  946. process.env.NODE_ENV !== 'production' && warn('Cannot find element: ' + selector);
  947. }
  948. }
  949. return el;
  950. }
  951. /**
  952. * Check if a node is in the document.
  953. * Note: document.documentElement.contains should work here
  954. * but always returns false for comment nodes in phantomjs,
  955. * making unit tests difficult. This is fixed by doing the
  956. * contains() check on the node's parentNode instead of
  957. * the node itself.
  958. *
  959. * @param {Node} node
  960. * @return {Boolean}
  961. */
  962. function inDoc(node) {
  963. var doc = document.documentElement;
  964. var parent = node && node.parentNode;
  965. return doc === node || doc === parent || !!(parent && parent.nodeType === 1 && doc.contains(parent));
  966. }
  967. /**
  968. * Get and remove an attribute from a node.
  969. *
  970. * @param {Node} node
  971. * @param {String} _attr
  972. */
  973. function getAttr(node, _attr) {
  974. var val = node.getAttribute(_attr);
  975. if (val !== null) {
  976. node.removeAttribute(_attr);
  977. }
  978. return val;
  979. }
  980. /**
  981. * Get an attribute with colon or v-bind: prefix.
  982. *
  983. * @param {Node} node
  984. * @param {String} name
  985. * @return {String|null}
  986. */
  987. function getBindAttr(node, name) {
  988. var val = getAttr(node, ':' + name);
  989. if (val === null) {
  990. val = getAttr(node, 'v-bind:' + name);
  991. }
  992. return val;
  993. }
  994. /**
  995. * Check the presence of a bind attribute.
  996. *
  997. * @param {Node} node
  998. * @param {String} name
  999. * @return {Boolean}
  1000. */
  1001. function hasBindAttr(node, name) {
  1002. return node.hasAttribute(name) || node.hasAttribute(':' + name) || node.hasAttribute('v-bind:' + name);
  1003. }
  1004. /**
  1005. * Insert el before target
  1006. *
  1007. * @param {Element} el
  1008. * @param {Element} target
  1009. */
  1010. function before(el, target) {
  1011. target.parentNode.insertBefore(el, target);
  1012. }
  1013. /**
  1014. * Insert el after target
  1015. *
  1016. * @param {Element} el
  1017. * @param {Element} target
  1018. */
  1019. function after(el, target) {
  1020. if (target.nextSibling) {
  1021. before(el, target.nextSibling);
  1022. } else {
  1023. target.parentNode.appendChild(el);
  1024. }
  1025. }
  1026. /**
  1027. * Remove el from DOM
  1028. *
  1029. * @param {Element} el
  1030. */
  1031. function remove(el) {
  1032. el.parentNode.removeChild(el);
  1033. }
  1034. /**
  1035. * Prepend el to target
  1036. *
  1037. * @param {Element} el
  1038. * @param {Element} target
  1039. */
  1040. function prepend(el, target) {
  1041. if (target.firstChild) {
  1042. before(el, target.firstChild);
  1043. } else {
  1044. target.appendChild(el);
  1045. }
  1046. }
  1047. /**
  1048. * Replace target with el
  1049. *
  1050. * @param {Element} target
  1051. * @param {Element} el
  1052. */
  1053. function replace(target, el) {
  1054. var parent = target.parentNode;
  1055. if (parent) {
  1056. parent.replaceChild(el, target);
  1057. }
  1058. }
  1059. /**
  1060. * Add event listener shorthand.
  1061. *
  1062. * @param {Element} el
  1063. * @param {String} event
  1064. * @param {Function} cb
  1065. */
  1066. function on$1(el, event, cb) {
  1067. el.addEventListener(event, cb);
  1068. }
  1069. /**
  1070. * Remove event listener shorthand.
  1071. *
  1072. * @param {Element} el
  1073. * @param {String} event
  1074. * @param {Function} cb
  1075. */
  1076. function off(el, event, cb) {
  1077. el.removeEventListener(event, cb);
  1078. }
  1079. /**
  1080. * In IE9, setAttribute('class') will result in empty class
  1081. * if the element also has the :class attribute; However in
  1082. * PhantomJS, setting `className` does not work on SVG elements...
  1083. * So we have to do a conditional check here.
  1084. *
  1085. * @param {Element} el
  1086. * @param {String} cls
  1087. */
  1088. function setClass(el, cls) {
  1089. /* istanbul ignore if */
  1090. if (isIE9 && !(el instanceof SVGElement)) {
  1091. el.className = cls;
  1092. } else {
  1093. el.setAttribute('class', cls);
  1094. }
  1095. }
  1096. /**
  1097. * Add class with compatibility for IE & SVG
  1098. *
  1099. * @param {Element} el
  1100. * @param {String} cls
  1101. */
  1102. function addClass(el, cls) {
  1103. if (el.classList) {
  1104. el.classList.add(cls);
  1105. } else {
  1106. var cur = ' ' + (el.getAttribute('class') || '') + ' ';
  1107. if (cur.indexOf(' ' + cls + ' ') < 0) {
  1108. setClass(el, (cur + cls).trim());
  1109. }
  1110. }
  1111. }
  1112. /**
  1113. * Remove class with compatibility for IE & SVG
  1114. *
  1115. * @param {Element} el
  1116. * @param {String} cls
  1117. */
  1118. function removeClass(el, cls) {
  1119. if (el.classList) {
  1120. el.classList.remove(cls);
  1121. } else {
  1122. var cur = ' ' + (el.getAttribute('class') || '') + ' ';
  1123. var tar = ' ' + cls + ' ';
  1124. while (cur.indexOf(tar) >= 0) {
  1125. cur = cur.replace(tar, ' ');
  1126. }
  1127. setClass(el, cur.trim());
  1128. }
  1129. if (!el.className) {
  1130. el.removeAttribute('class');
  1131. }
  1132. }
  1133. /**
  1134. * Extract raw content inside an element into a temporary
  1135. * container div
  1136. *
  1137. * @param {Element} el
  1138. * @param {Boolean} asFragment
  1139. * @return {Element}
  1140. */
  1141. function extractContent(el, asFragment) {
  1142. var child;
  1143. var rawContent;
  1144. /* istanbul ignore if */
  1145. if (isTemplate(el) && el.content instanceof DocumentFragment) {
  1146. el = el.content;
  1147. }
  1148. if (el.hasChildNodes()) {
  1149. trimNode(el);
  1150. rawContent = asFragment ? document.createDocumentFragment() : document.createElement('div');
  1151. /* eslint-disable no-cond-assign */
  1152. while (child = el.firstChild) {
  1153. /* eslint-enable no-cond-assign */
  1154. rawContent.appendChild(child);
  1155. }
  1156. }
  1157. return rawContent;
  1158. }
  1159. /**
  1160. * Trim possible empty head/tail textNodes inside a parent.
  1161. *
  1162. * @param {Node} node
  1163. */
  1164. function trimNode(node) {
  1165. trim(node, node.firstChild);
  1166. trim(node, node.lastChild);
  1167. }
  1168. function trim(parent, node) {
  1169. if (node && node.nodeType === 3 && !node.data.trim()) {
  1170. parent.removeChild(node);
  1171. }
  1172. }
  1173. /**
  1174. * Check if an element is a template tag.
  1175. * Note if the template appears inside an SVG its tagName
  1176. * will be in lowercase.
  1177. *
  1178. * @param {Element} el
  1179. */
  1180. function isTemplate(el) {
  1181. return el.tagName && el.tagName.toLowerCase() === 'template';
  1182. }
  1183. /**
  1184. * Create an "anchor" for performing dom insertion/removals.
  1185. * This is used in a number of scenarios:
  1186. * - fragment instance
  1187. * - v-html
  1188. * - v-if
  1189. * - v-for
  1190. * - component
  1191. *
  1192. * @param {String} content
  1193. * @param {Boolean} persist - IE trashes empty textNodes on
  1194. * cloneNode(true), so in certain
  1195. * cases the anchor needs to be
  1196. * non-empty to be persisted in
  1197. * templates.
  1198. * @return {Comment|Text}
  1199. */
  1200. function createAnchor(content, persist) {
  1201. var anchor = config.debug ? document.createComment(content) : document.createTextNode(persist ? ' ' : '');
  1202. anchor.__vue_anchor = true;
  1203. return anchor;
  1204. }
  1205. /**
  1206. * Find a component ref attribute that starts with $.
  1207. *
  1208. * @param {Element} node
  1209. * @return {String|undefined}
  1210. */
  1211. var refRE = /^v-ref:/;
  1212. function findRef(node) {
  1213. if (node.hasAttributes()) {
  1214. var attrs = node.attributes;
  1215. for (var i = 0, l = attrs.length; i < l; i++) {
  1216. var name = attrs[i].name;
  1217. if (refRE.test(name)) {
  1218. return camelize(name.replace(refRE, ''));
  1219. }
  1220. }
  1221. }
  1222. }
  1223. /**
  1224. * Map a function to a range of nodes .
  1225. *
  1226. * @param {Node} node
  1227. * @param {Node} end
  1228. * @param {Function} op
  1229. */
  1230. function mapNodeRange(node, end, op) {
  1231. var next;
  1232. while (node !== end) {
  1233. next = node.nextSibling;
  1234. op(node);
  1235. node = next;
  1236. }
  1237. op(end);
  1238. }
  1239. /**
  1240. * Remove a range of nodes with transition, store
  1241. * the nodes in a fragment with correct ordering,
  1242. * and call callback when done.
  1243. *
  1244. * @param {Node} start
  1245. * @param {Node} end
  1246. * @param {Vue} vm
  1247. * @param {DocumentFragment} frag
  1248. * @param {Function} cb
  1249. */
  1250. function removeNodeRange(start, end, vm, frag, cb) {
  1251. var done = false;
  1252. var removed = 0;
  1253. var nodes = [];
  1254. mapNodeRange(start, end, function (node) {
  1255. if (node === end) done = true;
  1256. nodes.push(node);
  1257. removeWithTransition(node, vm, onRemoved);
  1258. });
  1259. function onRemoved() {
  1260. removed++;
  1261. if (done && removed >= nodes.length) {
  1262. for (var i = 0; i < nodes.length; i++) {
  1263. frag.appendChild(nodes[i]);
  1264. }
  1265. cb && cb();
  1266. }
  1267. }
  1268. }
  1269. var commonTagRE = /^(div|p|span|img|a|b|i|br|ul|ol|li|h1|h2|h3|h4|h5|h6|code|pre|table|th|td|tr|form|label|input|select|option|nav|article|section|header|footer)$/;
  1270. var reservedTagRE = /^(slot|partial|component)$/;
  1271. /**
  1272. * Check if an element is a component, if yes return its
  1273. * component id.
  1274. *
  1275. * @param {Element} el
  1276. * @param {Object} options
  1277. * @return {Object|undefined}
  1278. */
  1279. function checkComponentAttr(el, options) {
  1280. var tag = el.tagName.toLowerCase();
  1281. var hasAttrs = el.hasAttributes();
  1282. if (!commonTagRE.test(tag) && !reservedTagRE.test(tag)) {
  1283. if (resolveAsset(options, 'components', tag)) {
  1284. return { id: tag };
  1285. } else {
  1286. var is = hasAttrs && getIsBinding(el);
  1287. if (is) {
  1288. return is;
  1289. } else if (process.env.NODE_ENV !== 'production') {
  1290. if (tag.indexOf('-') > -1 || /HTMLUnknownElement/.test(el.toString()) &&
  1291. // Chrome returns unknown for several HTML5 elements.
  1292. // https://code.google.com/p/chromium/issues/detail?id=540526
  1293. !/^(data|time|rtc|rb)$/.test(tag)) {
  1294. warn('Unknown custom element: <' + tag + '> - did you ' + 'register the component correctly?');
  1295. }
  1296. }
  1297. }
  1298. } else if (hasAttrs) {
  1299. return getIsBinding(el);
  1300. }
  1301. }
  1302. /**
  1303. * Get "is" binding from an element.
  1304. *
  1305. * @param {Element} el
  1306. * @return {Object|undefined}
  1307. */
  1308. function getIsBinding(el) {
  1309. // dynamic syntax
  1310. var exp = getAttr(el, 'is');
  1311. if (exp != null) {
  1312. return { id: exp };
  1313. } else {
  1314. exp = getBindAttr(el, 'is');
  1315. if (exp != null) {
  1316. return { id: exp, dynamic: true };
  1317. }
  1318. }
  1319. }
  1320. /**
  1321. * Set a prop's initial value on a vm and its data object.
  1322. *
  1323. * @param {Vue} vm
  1324. * @param {Object} prop
  1325. * @param {*} value
  1326. */
  1327. function initProp(vm, prop, value) {
  1328. var key = prop.path;
  1329. value = coerceProp(prop, value);
  1330. vm[key] = vm._data[key] = assertProp(prop, value) ? value : undefined;
  1331. }
  1332. /**
  1333. * Assert whether a prop is valid.
  1334. *
  1335. * @param {Object} prop
  1336. * @param {*} value
  1337. */
  1338. function assertProp(prop, value) {
  1339. // if a prop is not provided and is not required,
  1340. // skip the check.
  1341. if (prop.raw === null && !prop.required) {
  1342. return true;
  1343. }
  1344. var options = prop.options;
  1345. var type = options.type;
  1346. var valid = true;
  1347. var expectedType;
  1348. if (type) {
  1349. if (type === String) {
  1350. expectedType = 'string';
  1351. valid = typeof value === expectedType;
  1352. } else if (type === Number) {
  1353. expectedType = 'number';
  1354. valid = typeof value === 'number';
  1355. } else if (type === Boolean) {
  1356. expectedType = 'boolean';
  1357. valid = typeof value === 'boolean';
  1358. } else if (type === Function) {
  1359. expectedType = 'function';
  1360. valid = typeof value === 'function';
  1361. } else if (type === Object) {
  1362. expectedType = 'object';
  1363. valid = isPlainObject(value);
  1364. } else if (type === Array) {
  1365. expectedType = 'array';
  1366. valid = isArray(value);
  1367. } else {
  1368. valid = value instanceof type;
  1369. }
  1370. }
  1371. if (!valid) {
  1372. process.env.NODE_ENV !== 'production' && warn('Invalid prop: type check failed for ' + prop.path + '="' + prop.raw + '".' + ' Expected ' + formatType(expectedType) + ', got ' + formatValue(value) + '.');
  1373. return false;
  1374. }
  1375. var validator = options.validator;
  1376. if (validator) {
  1377. if (!validator.call(null, value)) {
  1378. process.env.NODE_ENV !== 'production' && warn('Invalid prop: custom validator check failed for ' + prop.path + '="' + prop.raw + '"');
  1379. return false;
  1380. }
  1381. }
  1382. return true;
  1383. }
  1384. /**
  1385. * Force parsing value with coerce option.
  1386. *
  1387. * @param {*} value
  1388. * @param {Object} options
  1389. * @return {*}
  1390. */
  1391. function coerceProp(prop, value) {
  1392. var coerce = prop.options.coerce;
  1393. if (!coerce) {
  1394. return value;
  1395. }
  1396. // coerce is a function
  1397. return coerce(value);
  1398. }
  1399. function formatType(val) {
  1400. return val ? val.charAt(0).toUpperCase() + val.slice(1) : 'custom type';
  1401. }
  1402. function formatValue(val) {
  1403. return Object.prototype.toString.call(val).slice(8, -1);
  1404. }
  1405. /**
  1406. * Option overwriting strategies are functions that handle
  1407. * how to merge a parent option value and a child option
  1408. * value into the final value.
  1409. *
  1410. * All strategy functions follow the same signature:
  1411. *
  1412. * @param {*} parentVal
  1413. * @param {*} childVal
  1414. * @param {Vue} [vm]
  1415. */
  1416. var strats = config.optionMergeStrategies = Object.create(null);
  1417. /**
  1418. * Helper that recursively merges two data objects together.
  1419. */
  1420. function mergeData(to, from) {
  1421. var key, toVal, fromVal;
  1422. for (key in from) {
  1423. toVal = to[key];
  1424. fromVal = from[key];
  1425. if (!hasOwn(to, key)) {
  1426. set(to, key, fromVal);
  1427. } else if (isObject(toVal) && isObject(fromVal)) {
  1428. mergeData(toVal, fromVal);
  1429. }
  1430. }
  1431. return to;
  1432. }
  1433. /**
  1434. * Data
  1435. */
  1436. strats.data = function (parentVal, childVal, vm) {
  1437. if (!vm) {
  1438. // in a Vue.extend merge, both should be functions
  1439. if (!childVal) {
  1440. return parentVal;
  1441. }
  1442. if (typeof childVal !== 'function') {
  1443. process.env.NODE_ENV !== 'production' && warn('The "data" option should be a function ' + 'that returns a per-instance value in component ' + 'definitions.');
  1444. return parentVal;
  1445. }
  1446. if (!parentVal) {
  1447. return childVal;
  1448. }
  1449. // when parentVal & childVal are both present,
  1450. // we need to return a function that returns the
  1451. // merged result of both functions... no need to
  1452. // check if parentVal is a function here because
  1453. // it has to be a function to pass previous merges.
  1454. return function mergedDataFn() {
  1455. return mergeData(childVal.call(this), parentVal.call(this));
  1456. };
  1457. } else if (parentVal || childVal) {
  1458. return function mergedInstanceDataFn() {
  1459. // instance merge
  1460. var instanceData = typeof childVal === 'function' ? childVal.call(vm) : childVal;
  1461. var defaultData = typeof parentVal === 'function' ? parentVal.call(vm) : undefined;
  1462. if (instanceData) {
  1463. return mergeData(instanceData, defaultData);
  1464. } else {
  1465. return defaultData;
  1466. }
  1467. };
  1468. }
  1469. };
  1470. /**
  1471. * El
  1472. */
  1473. strats.el = function (parentVal, childVal, vm) {
  1474. if (!vm && childVal && typeof childVal !== 'function') {
  1475. process.env.NODE_ENV !== 'production' && warn('The "el" option should be a function ' + 'that returns a per-instance value in component ' + 'definitions.');
  1476. return;
  1477. }
  1478. var ret = childVal || parentVal;
  1479. // invoke the element factory if this is instance merge
  1480. return vm && typeof ret === 'function' ? ret.call(vm) : ret;
  1481. };
  1482. /**
  1483. * Hooks and param attributes are merged as arrays.
  1484. */
  1485. strats.init = strats.created = strats.ready = strats.attached = strats.detached = strats.beforeCompile = strats.compiled = strats.beforeDestroy = strats.destroyed = function (parentVal, childVal) {
  1486. return childVal ? parentVal ? parentVal.concat(childVal) : isArray(childVal) ? childVal : [childVal] : parentVal;
  1487. };
  1488. /**
  1489. * 0.11 deprecation warning
  1490. */
  1491. strats.paramAttributes = function () {
  1492. /* istanbul ignore next */
  1493. process.env.NODE_ENV !== 'production' && warn('"paramAttributes" option has been deprecated in 0.12. ' + 'Use "props" instead.');
  1494. };
  1495. /**
  1496. * Assets
  1497. *
  1498. * When a vm is present (instance creation), we need to do
  1499. * a three-way merge between constructor options, instance
  1500. * options and parent options.
  1501. */
  1502. function mergeAssets(parentVal, childVal) {
  1503. var res = Object.create(parentVal);
  1504. return childVal ? extend(res, guardArrayAssets(childVal)) : res;
  1505. }
  1506. config._assetTypes.forEach(function (type) {
  1507. strats[type + 's'] = mergeAssets;
  1508. });
  1509. /**
  1510. * Events & Watchers.
  1511. *
  1512. * Events & watchers hashes should not overwrite one
  1513. * another, so we merge them as arrays.
  1514. */
  1515. strats.watch = strats.events = function (parentVal, childVal) {
  1516. if (!childVal) return parentVal;
  1517. if (!parentVal) return childVal;
  1518. var ret = {};
  1519. extend(ret, parentVal);
  1520. for (var key in childVal) {
  1521. var parent = ret[key];
  1522. var child = childVal[key];
  1523. if (parent && !isArray(parent)) {
  1524. parent = [parent];
  1525. }
  1526. ret[key] = parent ? parent.concat(child) : [child];
  1527. }
  1528. return ret;
  1529. };
  1530. /**
  1531. * Other object hashes.
  1532. */
  1533. strats.props = strats.methods = strats.computed = function (parentVal, childVal) {
  1534. if (!childVal) return parentVal;
  1535. if (!parentVal) return childVal;
  1536. var ret = Object.create(null);
  1537. extend(ret, parentVal);
  1538. extend(ret, childVal);
  1539. return ret;
  1540. };
  1541. /**
  1542. * Default strategy.
  1543. */
  1544. var defaultStrat = function defaultStrat(parentVal, childVal) {
  1545. return childVal === undefined ? parentVal : childVal;
  1546. };
  1547. /**
  1548. * Make sure component options get converted to actual
  1549. * constructors.
  1550. *
  1551. * @param {Object} options
  1552. */
  1553. function guardComponents(options) {
  1554. if (options.components) {
  1555. var components = options.components = guardArrayAssets(options.components);
  1556. var def;
  1557. var ids = Object.keys(components);
  1558. for (var i = 0, l = ids.length; i < l; i++) {
  1559. var key = ids[i];
  1560. if (commonTagRE.test(key) || reservedTagRE.test(key)) {
  1561. process.env.NODE_ENV !== 'production' && warn('Do not use built-in or reserved HTML elements as component ' + 'id: ' + key);
  1562. continue;
  1563. }
  1564. def = components[key];
  1565. if (isPlainObject(def)) {
  1566. components[key] = Vue.extend(def);
  1567. }
  1568. }
  1569. }
  1570. }
  1571. /**
  1572. * Ensure all props option syntax are normalized into the
  1573. * Object-based format.
  1574. *
  1575. * @param {Object} options
  1576. */
  1577. function guardProps(options) {
  1578. var props = options.props;
  1579. var i, val;
  1580. if (isArray(props)) {
  1581. options.props = {};
  1582. i = props.length;
  1583. while (i--) {
  1584. val = props[i];
  1585. if (typeof val === 'string') {
  1586. options.props[val] = null;
  1587. } else if (val.name) {
  1588. options.props[val.name] = val;
  1589. }
  1590. }
  1591. } else if (isPlainObject(props)) {
  1592. var keys = Object.keys(props);
  1593. i = keys.length;
  1594. while (i--) {
  1595. val = props[keys[i]];
  1596. if (typeof val === 'function') {
  1597. props[keys[i]] = { type: val };
  1598. }
  1599. }
  1600. }
  1601. }
  1602. /**
  1603. * Guard an Array-format assets option and converted it
  1604. * into the key-value Object format.
  1605. *
  1606. * @param {Object|Array} assets
  1607. * @return {Object}
  1608. */
  1609. function guardArrayAssets(assets) {
  1610. if (isArray(assets)) {
  1611. var res = {};
  1612. var i = assets.length;
  1613. var asset;
  1614. while (i--) {
  1615. asset = assets[i];
  1616. var id = typeof asset === 'function' ? asset.options && asset.options.name || asset.id : asset.name || asset.id;
  1617. if (!id) {
  1618. process.env.NODE_ENV !== 'production' && warn('Array-syntax assets must provide a "name" or "id" field.');
  1619. } else {
  1620. res[id] = asset;
  1621. }
  1622. }
  1623. return res;
  1624. }
  1625. return assets;
  1626. }
  1627. /**
  1628. * Merge two option objects into a new one.
  1629. * Core utility used in both instantiation and inheritance.
  1630. *
  1631. * @param {Object} parent
  1632. * @param {Object} child
  1633. * @param {Vue} [vm] - if vm is present, indicates this is
  1634. * an instantiation merge.
  1635. */
  1636. function mergeOptions(parent, child, vm) {
  1637. guardComponents(child);
  1638. guardProps(child);
  1639. var options = {};
  1640. var key;
  1641. if (child.mixins) {
  1642. for (var i = 0, l = child.mixins.length; i < l; i++) {
  1643. parent = mergeOptions(parent, child.mixins[i], vm);
  1644. }
  1645. }
  1646. for (key in parent) {
  1647. mergeField(key);
  1648. }
  1649. for (key in child) {
  1650. if (!hasOwn(parent, key)) {
  1651. mergeField(key);
  1652. }
  1653. }
  1654. function mergeField(key) {
  1655. var strat = strats[key] || defaultStrat;
  1656. options[key] = strat(parent[key], child[key], vm, key);
  1657. }
  1658. return options;
  1659. }
  1660. /**
  1661. * Resolve an asset.
  1662. * This function is used because child instances need access
  1663. * to assets defined in its ancestor chain.
  1664. *
  1665. * @param {Object} options
  1666. * @param {String} type
  1667. * @param {String} id
  1668. * @return {Object|Function}
  1669. */
  1670. function resolveAsset(options, type, id) {
  1671. var assets = options[type];
  1672. var camelizedId;
  1673. return assets[id] ||
  1674. // camelCase ID
  1675. assets[camelizedId = camelize(id)] ||
  1676. // Pascal Case ID
  1677. assets[camelizedId.charAt(0).toUpperCase() + camelizedId.slice(1)];
  1678. }
  1679. /**
  1680. * Assert asset exists
  1681. */
  1682. function assertAsset(val, type, id) {
  1683. if (!val) {
  1684. process.env.NODE_ENV !== 'production' && warn('Failed to resolve ' + type + ': ' + id);
  1685. }
  1686. }
  1687. var arrayProto = Array.prototype;
  1688. var arrayMethods = Object.create(arrayProto)
  1689. /**
  1690. * Intercept mutating methods and emit events
  1691. */
  1692. ;['push', 'pop', 'shift', 'unshift', 'splice', 'sort', 'reverse'].forEach(function (method) {
  1693. // cache original method
  1694. var original = arrayProto[method];
  1695. def(arrayMethods, method, function mutator() {
  1696. // avoid leaking arguments:
  1697. // http://jsperf.com/closure-with-arguments
  1698. var i = arguments.length;
  1699. var args = new Array(i);
  1700. while (i--) {
  1701. args[i] = arguments[i];
  1702. }
  1703. var result = original.apply(this, args);
  1704. var ob = this.__ob__;
  1705. var inserted;
  1706. switch (method) {
  1707. case 'push':
  1708. inserted = args;
  1709. break;
  1710. case 'unshift':
  1711. inserted = args;
  1712. break;
  1713. case 'splice':
  1714. inserted = args.slice(2);
  1715. break;
  1716. }
  1717. if (inserted) ob.observeArray(inserted);
  1718. // notify change
  1719. ob.dep.notify();
  1720. return result;
  1721. });
  1722. });
  1723. /**
  1724. * Swap the element at the given index with a new value
  1725. * and emits corresponding event.
  1726. *
  1727. * @param {Number} index
  1728. * @param {*} val
  1729. * @return {*} - replaced element
  1730. */
  1731. def(arrayProto, '$set', function $set(index, val) {
  1732. if (index >= this.length) {
  1733. this.length = Number(index) + 1;
  1734. }
  1735. return this.splice(index, 1, val)[0];
  1736. });
  1737. /**
  1738. * Convenience method to remove the element at given index.
  1739. *
  1740. * @param {Number} index
  1741. * @param {*} val
  1742. */
  1743. def(arrayProto, '$remove', function $remove(item) {
  1744. /* istanbul ignore if */
  1745. if (!this.length) return;
  1746. var index = indexOf(this, item);
  1747. if (index > -1) {
  1748. return this.splice(index, 1);
  1749. }
  1750. });
  1751. var uid$3 = 0;
  1752. /**
  1753. * A dep is an observable that can have multiple
  1754. * directives subscribing to it.
  1755. *
  1756. * @constructor
  1757. */
  1758. function Dep() {
  1759. this.id = uid$3++;
  1760. this.subs = [];
  1761. }
  1762. // the current target watcher being evaluated.
  1763. // this is globally unique because there could be only one
  1764. // watcher being evaluated at any time.
  1765. Dep.target = null;
  1766. /**
  1767. * Add a directive subscriber.
  1768. *
  1769. * @param {Directive} sub
  1770. */
  1771. Dep.prototype.addSub = function (sub) {
  1772. this.subs.push(sub);
  1773. };
  1774. /**
  1775. * Remove a directive subscriber.
  1776. *
  1777. * @param {Directive} sub
  1778. */
  1779. Dep.prototype.removeSub = function (sub) {
  1780. this.subs.$remove(sub);
  1781. };
  1782. /**
  1783. * Add self as a dependency to the target watcher.
  1784. */
  1785. Dep.prototype.depend = function () {
  1786. Dep.target.addDep(this);
  1787. };
  1788. /**
  1789. * Notify all subscribers of a new value.
  1790. */
  1791. Dep.prototype.notify = function () {
  1792. // stablize the subscriber list first
  1793. var subs = toArray(this.subs);
  1794. for (var i = 0, l = subs.length; i < l; i++) {
  1795. subs[i].update();
  1796. }
  1797. };
  1798. var arrayKeys = Object.getOwnPropertyNames(arrayMethods);
  1799. /**
  1800. * Observer class that are attached to each observed
  1801. * object. Once attached, the observer converts target
  1802. * object's property keys into getter/setters that
  1803. * collect dependencies and dispatches updates.
  1804. *
  1805. * @param {Array|Object} value
  1806. * @constructor
  1807. */
  1808. function Observer(value) {
  1809. this.value = value;
  1810. this.dep = new Dep();
  1811. def(value, '__ob__', this);
  1812. if (isArray(value)) {
  1813. var augment = hasProto ? protoAugment : copyAugment;
  1814. augment(value, arrayMethods, arrayKeys);
  1815. this.observeArray(value);
  1816. } else {
  1817. this.walk(value);
  1818. }
  1819. }
  1820. // Instance methods
  1821. /**
  1822. * Walk through each property and convert them into
  1823. * getter/setters. This method should only be called when
  1824. * value type is Object.
  1825. *
  1826. * @param {Object} obj
  1827. */
  1828. Observer.prototype.walk = function (obj) {
  1829. var keys = Object.keys(obj);
  1830. for (var i = 0, l = keys.length; i < l; i++) {
  1831. this.convert(keys[i], obj[keys[i]]);
  1832. }
  1833. };
  1834. /**
  1835. * Observe a list of Array items.
  1836. *
  1837. * @param {Array} items
  1838. */
  1839. Observer.prototype.observeArray = function (items) {
  1840. for (var i = 0, l = items.length; i < l; i++) {
  1841. observe(items[i]);
  1842. }
  1843. };
  1844. /**
  1845. * Convert a property into getter/setter so we can emit
  1846. * the events when the property is accessed/changed.
  1847. *
  1848. * @param {String} key
  1849. * @param {*} val
  1850. */
  1851. Observer.prototype.convert = function (key, val) {
  1852. defineReactive(this.value, key, val);
  1853. };
  1854. /**
  1855. * Add an owner vm, so that when $set/$delete mutations
  1856. * happen we can notify owner vms to proxy the keys and
  1857. * digest the watchers. This is only called when the object
  1858. * is observed as an instance's root $data.
  1859. *
  1860. * @param {Vue} vm
  1861. */
  1862. Observer.prototype.addVm = function (vm) {
  1863. (this.vms || (this.vms = [])).push(vm);
  1864. };
  1865. /**
  1866. * Remove an owner vm. This is called when the object is
  1867. * swapped out as an instance's $data object.
  1868. *
  1869. * @param {Vue} vm
  1870. */
  1871. Observer.prototype.removeVm = function (vm) {
  1872. this.vms.$remove(vm);
  1873. };
  1874. // helpers
  1875. /**
  1876. * Augment an target Object or Array by intercepting
  1877. * the prototype chain using __proto__
  1878. *
  1879. * @param {Object|Array} target
  1880. * @param {Object} proto
  1881. */
  1882. function protoAugment(target, src) {
  1883. target.__proto__ = src;
  1884. }
  1885. /**
  1886. * Augment an target Object or Array by defining
  1887. * hidden properties.
  1888. *
  1889. * @param {Object|Array} target
  1890. * @param {Object} proto
  1891. */
  1892. function copyAugment(target, src, keys) {
  1893. for (var i = 0, l = keys.length; i < l; i++) {
  1894. var key = keys[i];
  1895. def(target, key, src[key]);
  1896. }
  1897. }
  1898. /**
  1899. * Attempt to create an observer instance for a value,
  1900. * returns the new observer if successfully observed,
  1901. * or the existing observer if the value already has one.
  1902. *
  1903. * @param {*} value
  1904. * @param {Vue} [vm]
  1905. * @return {Observer|undefined}
  1906. * @static
  1907. */
  1908. function observe(value, vm) {
  1909. if (!value || typeof value !== 'object') {
  1910. return;
  1911. }
  1912. var ob;
  1913. if (hasOwn(value, '__ob__') && value.__ob__ instanceof Observer) {
  1914. ob = value.__ob__;
  1915. } else if ((isArray(value) || isPlainObject(value)) && Object.isExtensible(value) && !value._isVue) {
  1916. ob = new Observer(value);
  1917. }
  1918. if (ob && vm) {
  1919. ob.addVm(vm);
  1920. }
  1921. return ob;
  1922. }
  1923. /**
  1924. * Define a reactive property on an Object.
  1925. *
  1926. * @param {Object} obj
  1927. * @param {String} key
  1928. * @param {*} val
  1929. */
  1930. function defineReactive(obj, key, val) {
  1931. var dep = new Dep();
  1932. // cater for pre-defined getter/setters
  1933. var getter, setter;
  1934. if (config.convertAllProperties) {
  1935. var property = Object.getOwnPropertyDescriptor(obj, key);
  1936. if (property && property.configurable === false) {
  1937. return;
  1938. }
  1939. getter = property && property.get;
  1940. setter = property && property.set;
  1941. }
  1942. var childOb = observe(val);
  1943. Object.defineProperty(obj, key, {
  1944. enumerable: true,
  1945. configurable: true,
  1946. get: function reactiveGetter() {
  1947. var value = getter ? getter.call(obj) : val;
  1948. if (Dep.target) {
  1949. dep.depend();
  1950. if (childOb) {
  1951. childOb.dep.depend();
  1952. }
  1953. if (isArray(value)) {
  1954. for (var e, i = 0, l = value.length; i < l; i++) {
  1955. e = value[i];
  1956. e && e.__ob__ && e.__ob__.dep.depend();
  1957. }
  1958. }
  1959. }
  1960. return value;
  1961. },
  1962. set: function reactiveSetter(newVal) {
  1963. var value = getter ? getter.call(obj) : val;
  1964. if (newVal === value) {
  1965. return;
  1966. }
  1967. if (setter) {
  1968. setter.call(obj, newVal);
  1969. } else {
  1970. val = newVal;
  1971. }
  1972. childOb = observe(newVal);
  1973. dep.notify();
  1974. }
  1975. });
  1976. }
  1977. var util = Object.freeze({
  1978. defineReactive: defineReactive,
  1979. set: set,
  1980. del: del,
  1981. hasOwn: hasOwn,
  1982. isLiteral: isLiteral,
  1983. isReserved: isReserved,
  1984. _toString: _toString,
  1985. toNumber: toNumber,
  1986. toBoolean: toBoolean,
  1987. stripQuotes: stripQuotes,
  1988. camelize: camelize,
  1989. hyphenate: hyphenate,
  1990. classify: classify,
  1991. bind: bind$1,
  1992. toArray: toArray,
  1993. extend: extend,
  1994. isObject: isObject,
  1995. isPlainObject: isPlainObject,
  1996. def: def,
  1997. debounce: _debounce,
  1998. indexOf: indexOf,
  1999. cancellable: cancellable,
  2000. looseEqual: looseEqual,
  2001. isArray: isArray,
  2002. hasProto: hasProto,
  2003. inBrowser: inBrowser,
  2004. isIE9: isIE9,
  2005. isAndroid: isAndroid,
  2006. get transitionProp () { return transitionProp; },
  2007. get transitionEndEvent () { return transitionEndEvent; },
  2008. get animationProp () { return animationProp; },
  2009. get animationEndEvent () { return animationEndEvent; },
  2010. nextTick: nextTick,
  2011. query: query,
  2012. inD