server-renderer.js 72 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931
  1. 'use strict';
  2. function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
  3. var stream = _interopDefault(require('stream'));
  4. var babelHelpers = {};
  5. babelHelpers.classCallCheck = function (instance, Constructor) {
  6. if (!(instance instanceof Constructor)) {
  7. throw new TypeError("Cannot call a class as a function");
  8. }
  9. };
  10. babelHelpers.createClass = function () {
  11. function defineProperties(target, props) {
  12. for (var i = 0; i < props.length; i++) {
  13. var descriptor = props[i];
  14. descriptor.enumerable = descriptor.enumerable || false;
  15. descriptor.configurable = true;
  16. if ("value" in descriptor) descriptor.writable = true;
  17. Object.defineProperty(target, descriptor.key, descriptor);
  18. }
  19. }
  20. return function (Constructor, protoProps, staticProps) {
  21. if (protoProps) defineProperties(Constructor.prototype, protoProps);
  22. if (staticProps) defineProperties(Constructor, staticProps);
  23. return Constructor;
  24. };
  25. }();
  26. babelHelpers.inherits = function (subClass, superClass) {
  27. if (typeof superClass !== "function" && superClass !== null) {
  28. throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
  29. }
  30. subClass.prototype = Object.create(superClass && superClass.prototype, {
  31. constructor: {
  32. value: subClass,
  33. enumerable: false,
  34. writable: true,
  35. configurable: true
  36. }
  37. });
  38. if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
  39. };
  40. babelHelpers.possibleConstructorReturn = function (self, call) {
  41. if (!self) {
  42. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  43. }
  44. return call && (typeof call === "object" || typeof call === "function") ? call : self;
  45. };
  46. babelHelpers;
  47. function renderStartingTag(node, modules, directives) {
  48. var markup = '<' + node.tag;
  49. if (node.data) {
  50. // check directives
  51. var dirs = node.data.directives;
  52. if (dirs) {
  53. for (var i = 0; i < dirs.length; i++) {
  54. var dirRenderer = directives[dirs[i].name];
  55. if (dirRenderer) {
  56. // directives mutate the node's data
  57. // which then gets rendered by modules
  58. dirRenderer(node, dirs[i]);
  59. }
  60. }
  61. }
  62. // apply other modules
  63. for (var _i = 0; _i < modules.length; _i++) {
  64. var res = modules[_i](node);
  65. if (res) {
  66. markup += res;
  67. }
  68. }
  69. }
  70. return markup + '>';
  71. }
  72. function createSyncRenderer(modules, directives, isUnaryTag) {
  73. function renderComponent(component, isRoot) {
  74. component.$mount();
  75. return renderNode(component._vnode, isRoot);
  76. }
  77. function renderNode(node, isRoot) {
  78. if (node.componentOptions) {
  79. node.data.hook.init(node);
  80. return renderComponent(node.child, isRoot);
  81. } else {
  82. return node.tag ? renderElement(node, isRoot) : node.text;
  83. }
  84. }
  85. function renderElement(el, isRoot) {
  86. if (isRoot) {
  87. if (!el.data) el.data = {};
  88. if (!el.data.attrs) el.data.attrs = {};
  89. el.data.attrs['server-rendered'] = true;
  90. }
  91. var startTag = renderStartingTag(el, modules, directives);
  92. var endTag = '</' + el.tag + '>';
  93. if (isUnaryTag(el.tag)) {
  94. return startTag;
  95. } else if (!el.children || !el.children.length) {
  96. return startTag + endTag;
  97. } else {
  98. var children = '';
  99. for (var i = 0; i < el.children.length; i++) {
  100. children += renderNode(el.children[i]);
  101. }
  102. return startTag + children + endTag;
  103. }
  104. }
  105. return function renderToString(component) {
  106. return renderComponent(component, true);
  107. };
  108. }
  109. var MAX_STACK_DEPTH = 500;
  110. /**
  111. * Original RenderStream implmentation by Sasha Aickin (@aickin)
  112. * Licensed under the Apache License, Version 2.0
  113. * Modified by Evan You (@yyx990803)
  114. */
  115. var RenderStream = function (_stream$Readable) {
  116. babelHelpers.inherits(RenderStream, _stream$Readable);
  117. function RenderStream(render) {
  118. babelHelpers.classCallCheck(this, RenderStream);
  119. var _this = babelHelpers.possibleConstructorReturn(this, Object.getPrototypeOf(RenderStream).call(this));
  120. _this.buffer = '';
  121. _this.render = render;
  122. return _this;
  123. }
  124. babelHelpers.createClass(RenderStream, [{
  125. key: '_read',
  126. value: function _read(n) {
  127. var _this2 = this;
  128. var bufferToPush;
  129. // it's possible that the last chunk added bumped the buffer up to > 2 * n,
  130. // which means we will need to go through multiple read calls to drain it
  131. // down to < n.
  132. if (this.done) {
  133. this.push(null);
  134. return;
  135. }
  136. if (this.buffer.length >= n) {
  137. bufferToPush = this.buffer.substring(0, n);
  138. this.buffer = this.buffer.substring(n);
  139. this.push(bufferToPush);
  140. return;
  141. }
  142. if (!this.next) {
  143. this.stackDepth = 0;
  144. // start the rendering chain.
  145. this.render(
  146. // write
  147. function (text, next) {
  148. _this2.buffer += text;
  149. if (_this2.buffer.length >= n) {
  150. _this2.next = next;
  151. bufferToPush = _this2.buffer.substring(0, n);
  152. _this2.buffer = _this2.buffer.substring(n);
  153. _this2.push(bufferToPush);
  154. } else {
  155. // continue rendering until we have enough text to call this.push().
  156. // sometimes do this as process.nextTick to get out of stack overflows.
  157. if (_this2.stackDepth >= MAX_STACK_DEPTH) {
  158. process.nextTick(next);
  159. } else {
  160. _this2.stackDepth++;
  161. next();
  162. _this2.stackDepth--;
  163. }
  164. }
  165. },
  166. // done
  167. function () {
  168. // the rendering is finished; we should push out the last of the buffer.
  169. _this2.done = true;
  170. _this2.push(_this2.buffer);
  171. });
  172. } else {
  173. // continue with the rendering.
  174. this.next();
  175. }
  176. }
  177. }]);
  178. return RenderStream;
  179. }(stream.Readable);
  180. function createStreamingRenderer(modules, directives, isUnaryTag) {
  181. function renderComponent(component, write, next, isRoot) {
  182. component.$mount();
  183. renderNode(component._vnode, write, next, isRoot);
  184. }
  185. function renderNode(node, write, next, isRoot) {
  186. if (node.componentOptions) {
  187. node.data.hook.init(node);
  188. renderComponent(node.child, write, next, isRoot);
  189. } else {
  190. if (node.tag) {
  191. renderElement(node, write, next, isRoot);
  192. } else {
  193. write(node.text, next);
  194. }
  195. }
  196. }
  197. function renderElement(el, write, next, isRoot) {
  198. if (isRoot) {
  199. if (!el.data) el.data = {};
  200. if (!el.data.attrs) el.data.attrs = {};
  201. el.data.attrs['server-rendered'] = true;
  202. }
  203. var startTag = renderStartingTag(el, modules, directives);
  204. var endTag = '</' + el.tag + '>';
  205. if (isUnaryTag(el.tag)) {
  206. write(startTag, next);
  207. } else if (!el.children || !el.children.length) {
  208. write(startTag + endTag, next);
  209. } else {
  210. write(startTag, function () {
  211. var total = el.children.length;
  212. var rendered = 0;
  213. function renderChild(child) {
  214. renderNode(child, write, function () {
  215. rendered++;
  216. if (rendered < total) {
  217. renderChild(el.children[rendered]);
  218. } else {
  219. write(endTag, next);
  220. }
  221. });
  222. }
  223. renderChild(el.children[0]);
  224. });
  225. }
  226. }
  227. return function renderToStream(component) {
  228. return new RenderStream(function (write, done) {
  229. renderComponent(component, write, done, true);
  230. });
  231. };
  232. }
  233. function createRenderer() {
  234. var _ref = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
  235. var _ref$modules = _ref.modules;
  236. var modules = _ref$modules === undefined ? [] : _ref$modules;
  237. var _ref$directives = _ref.directives;
  238. var directives = _ref$directives === undefined ? {} : _ref$directives;
  239. var _ref$isUnaryTag = _ref.isUnaryTag;
  240. var isUnaryTag = _ref$isUnaryTag === undefined ? function () {
  241. return false;
  242. } : _ref$isUnaryTag;
  243. return {
  244. renderToString: createSyncRenderer(modules, directives, isUnaryTag),
  245. renderToStream: createStreamingRenderer(modules, directives, isUnaryTag)
  246. };
  247. }
  248. /**
  249. * Convert a value to a string that is actually rendered.
  250. *
  251. * @param {*} val
  252. * @return {String}
  253. */
  254. function renderString(val) {
  255. return val == null ? '' : typeof val === 'object' ? JSON.stringify(val, null, 2) : String(val);
  256. }
  257. /**
  258. * Make a map and return a function for checking if a key
  259. * is in that map.
  260. *
  261. * @param {String} str
  262. * @param {Boolean} expectsLowerCase
  263. * @return {Function}
  264. */
  265. function makeMap(str, expectsLowerCase) {
  266. var map = Object.create(null);
  267. var list = str.split(',');
  268. for (var i = 0; i < list.length; i++) {
  269. map[list[i]] = true;
  270. }
  271. return expectsLowerCase ? function (val) {
  272. return map[val.toLowerCase()];
  273. } : function (val) {
  274. return map[val];
  275. };
  276. }
  277. /**
  278. * Check if a tag is a built-in tag.
  279. */
  280. var isBuiltInTag = makeMap('slot,component,render,transition', true);
  281. /**
  282. * Remove an item from an array
  283. *
  284. * @param {Array} arr
  285. * @param {*} item
  286. */
  287. function remove(arr, item) {
  288. if (arr.length) {
  289. var index = arr.indexOf(item);
  290. if (index > -1) {
  291. return arr.splice(index, 1);
  292. }
  293. }
  294. }
  295. /**
  296. * Check whether the object has the property.
  297. *
  298. * @param {Object} obj
  299. * @param {String} key
  300. * @return {Boolean}
  301. */
  302. var hasOwnProperty = Object.prototype.hasOwnProperty;
  303. function hasOwn(obj, key) {
  304. return hasOwnProperty.call(obj, key);
  305. }
  306. /**
  307. * Check if value is primitive
  308. *
  309. * @param {*} value
  310. * @return {Boolean}
  311. */
  312. function isPrimitive(value) {
  313. return typeof value === 'string' || typeof value === 'number';
  314. }
  315. /**
  316. * Create a cached version of a pure function.
  317. *
  318. * @param {Function} fn
  319. * @return {Function}
  320. */
  321. function cached(fn) {
  322. var cache = Object.create(null);
  323. return function cachedFn(str) {
  324. var hit = cache[str];
  325. return hit || (cache[str] = fn(str));
  326. };
  327. }
  328. /**
  329. * Camelize a hyphen-delmited string.
  330. *
  331. * @param {String} str
  332. * @return {String}
  333. */
  334. var camelizeRE = /-(\w)/g;
  335. var camelize = cached(function (str) {
  336. return str.replace(camelizeRE, toUpper);
  337. });
  338. function toUpper(_, c) {
  339. return c ? c.toUpperCase() : '';
  340. }
  341. /**
  342. * Hyphenate a camelCase string.
  343. *
  344. * @param {String} str
  345. * @return {String}
  346. */
  347. var hyphenateRE = /([a-z\d])([A-Z])/g;
  348. var hyphenate = cached(function (str) {
  349. return str.replace(hyphenateRE, '$1-$2').toLowerCase();
  350. });
  351. /**
  352. * Simple bind, faster than native
  353. *
  354. * @param {Function} fn
  355. * @param {Object} ctx
  356. * @return {Function}
  357. */
  358. function bind(fn, ctx) {
  359. return function (a) {
  360. var l = arguments.length;
  361. return l ? l > 1 ? fn.apply(ctx, arguments) : fn.call(ctx, a) : fn.call(ctx);
  362. };
  363. }
  364. /**
  365. * Convert an Array-like object to a real Array.
  366. *
  367. * @param {Array-like} list
  368. * @param {Number} [start] - start index
  369. * @return {Array}
  370. */
  371. function toArray(list, start) {
  372. start = start || 0;
  373. var i = list.length - start;
  374. var ret = new Array(i);
  375. while (i--) {
  376. ret[i] = list[i + start];
  377. }
  378. return ret;
  379. }
  380. /**
  381. * Mix properties into target object.
  382. *
  383. * @param {Object} to
  384. * @param {Object} from
  385. */
  386. function extend(to, from) {
  387. for (var key in from) {
  388. to[key] = from[key];
  389. }
  390. return to;
  391. }
  392. /**
  393. * Quick object check - this is primarily used to tell
  394. * Objects from primitive values when we know the value
  395. * is a JSON-compliant type.
  396. *
  397. * @param {*} obj
  398. * @return {Boolean}
  399. */
  400. function isObject(obj) {
  401. return obj !== null && typeof obj === 'object';
  402. }
  403. /**
  404. * Strict object type check. Only returns true
  405. * for plain JavaScript objects.
  406. *
  407. * @param {*} obj
  408. * @return {Boolean}
  409. */
  410. var toString = Object.prototype.toString;
  411. var OBJECT_STRING = '[object Object]';
  412. function isPlainObject(obj) {
  413. return toString.call(obj) === OBJECT_STRING;
  414. }
  415. /**
  416. * Array type check.
  417. *
  418. * @param {*} obj
  419. * @return {Boolean}
  420. */
  421. var isArray = Array.isArray;
  422. /**
  423. * Check if a string starts with $ or _
  424. *
  425. * @param {String} str
  426. * @return {Boolean}
  427. */
  428. function isReserved(str) {
  429. var c = (str + '').charCodeAt(0);
  430. return c === 0x24 || c === 0x5F;
  431. }
  432. /**
  433. * Define a property.
  434. *
  435. * @param {Object} obj
  436. * @param {String} key
  437. * @param {*} val
  438. * @param {Boolean} [enumerable]
  439. */
  440. function def(obj, key, val, enumerable) {
  441. Object.defineProperty(obj, key, {
  442. value: val,
  443. enumerable: !!enumerable,
  444. writable: true,
  445. configurable: true
  446. });
  447. }
  448. /**
  449. * Parse simple path.
  450. */
  451. var bailRE = /[^\w\.]/;
  452. function parsePath(path) {
  453. if (bailRE.test(path)) {
  454. return;
  455. } else {
  456. path = path.split('.');
  457. return function (obj) {
  458. for (var i = 0; i < path.length; i++) {
  459. if (!obj) return;
  460. obj = obj[path[i]];
  461. }
  462. return obj;
  463. };
  464. }
  465. }
  466. /* global MutationObserver */
  467. // can we use __proto__?
  468. var hasProto = '__proto__' in {};
  469. // Browser environment sniffing
  470. var inBrowser = typeof window !== 'undefined' && Object.prototype.toString.call(window) !== '[object Object]';
  471. // UA sniffing for working around browser-specific quirks
  472. var UA$1 = inBrowser && window.navigator.userAgent.toLowerCase();
  473. var isIos = UA$1 && /(iphone|ipad|ipod|ios)/i.test(UA$1);
  474. var isWechat = UA$1 && UA$1.indexOf('micromessenger') > 0;
  475. /**
  476. * Defer a task to execute it asynchronously. Ideally this
  477. * should be executed as a microtask, so we leverage
  478. * MutationObserver if it's available, and fallback to
  479. * setTimeout(0).
  480. *
  481. * @param {Function} cb
  482. * @param {Object} ctx
  483. */
  484. var nextTick = function () {
  485. var callbacks = [];
  486. var pending = false;
  487. var timerFunc;
  488. function nextTickHandler() {
  489. pending = false;
  490. var copies = callbacks.slice(0);
  491. callbacks = [];
  492. for (var i = 0; i < copies.length; i++) {
  493. copies[i]();
  494. }
  495. }
  496. /* istanbul ignore if */
  497. if (typeof MutationObserver !== 'undefined' && !(isWechat && isIos)) {
  498. var counter = 1;
  499. var observer = new MutationObserver(nextTickHandler);
  500. var textNode = document.createTextNode(counter);
  501. observer.observe(textNode, {
  502. characterData: true
  503. });
  504. timerFunc = function timerFunc() {
  505. counter = (counter + 1) % 2;
  506. textNode.data = counter;
  507. };
  508. } else {
  509. // webpack attempts to inject a shim for setImmediate
  510. // if it is used as a global, so we have to work around that to
  511. // avoid bundling unnecessary code.
  512. var context = inBrowser ? window : typeof global !== 'undefined' ? global : {};
  513. timerFunc = context.setImmediate || setTimeout;
  514. }
  515. return function (cb, ctx) {
  516. var func = ctx ? function () {
  517. cb.call(ctx);
  518. } : cb;
  519. callbacks.push(func);
  520. if (pending) return;
  521. pending = true;
  522. timerFunc(nextTickHandler, 0);
  523. };
  524. }();
  525. var Set$1 = void 0;
  526. /* istanbul ignore if */
  527. if (typeof Set !== 'undefined' && Set.toString().match(/native code/)) {
  528. // use native Set when available.
  529. Set$1 = Set;
  530. } else {
  531. // a non-standard Set polyfill that only works with primitive keys.
  532. Set$1 = function _Set() {
  533. this.set = Object.create(null);
  534. };
  535. Set$1.prototype.has = function (key) {
  536. return this.set[key] !== undefined;
  537. };
  538. Set$1.prototype.add = function (key) {
  539. this.set[key] = 1;
  540. };
  541. Set$1.prototype.clear = function () {
  542. this.set = Object.create(null);
  543. };
  544. }
  545. var hasProxy = void 0;
  546. var proxyHandlers = void 0;
  547. var initProxy = void 0;
  548. if (process.env.NODE_ENV !== 'production') {
  549. (function () {
  550. 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');
  551. hasProxy = typeof Proxy !== 'undefined' && Proxy.toString().match(/native code/);
  552. proxyHandlers = {
  553. has: function has(target, key) {
  554. var has = key in target;
  555. var isAllowedGlobal = allowedGlobals(key);
  556. if (!has && !isAllowedGlobal) {
  557. warn('Trying to access non-existent property "' + key + '" while rendering.', target);
  558. }
  559. return !isAllowedGlobal;
  560. }
  561. };
  562. initProxy = function initProxy(vm) {
  563. if (hasProxy) {
  564. vm._renderProxy = new Proxy(vm, proxyHandlers);
  565. } else {
  566. vm._renderProxy = vm;
  567. }
  568. };
  569. })();
  570. }
  571. var uid$2 = 0;
  572. /**
  573. * A dep is an observable that can have multiple
  574. * directives subscribing to it.
  575. *
  576. * @constructor
  577. */
  578. function Dep() {
  579. this.id = uid$2++;
  580. this.subs = [];
  581. }
  582. // the current target watcher being evaluated.
  583. // this is globally unique because there could be only one
  584. // watcher being evaluated at any time.
  585. Dep.target = null;
  586. /**
  587. * Add a directive subscriber.
  588. *
  589. * @param {Directive} sub
  590. */
  591. Dep.prototype.addSub = function (sub) {
  592. this.subs.push(sub);
  593. };
  594. /**
  595. * Remove a directive subscriber.
  596. *
  597. * @param {Directive} sub
  598. */
  599. Dep.prototype.removeSub = function (sub) {
  600. remove(this.subs, sub);
  601. };
  602. /**
  603. * Add self as a dependency to the target watcher.
  604. */
  605. Dep.prototype.depend = function () {
  606. Dep.target.addDep(this);
  607. };
  608. /**
  609. * Notify all subscribers of a new value.
  610. */
  611. Dep.prototype.notify = function () {
  612. // stablize the subscriber list first
  613. var subs = this.subs.slice();
  614. for (var i = 0, l = subs.length; i < l; i++) {
  615. subs[i].update();
  616. }
  617. };
  618. var config = {
  619. /**
  620. * Preserve whitespaces between elements.
  621. */
  622. preserveWhitespace: true,
  623. /**
  624. * Whether to suppress warnings.
  625. *
  626. * @type {Boolean}
  627. */
  628. silent: false,
  629. /**
  630. * Check if a tag is reserved so that it cannot be registered as a
  631. * component. This is platform-dependent and may be overwritten.
  632. */
  633. isReservedTag: function isReservedTag() {
  634. return false;
  635. },
  636. /**
  637. * Check if a tag is an unknown element.
  638. * Platform-dependent.
  639. */
  640. isUnknownElement: function isUnknownElement() {
  641. return false;
  642. },
  643. /**
  644. * List of asset types that a component can own.
  645. *
  646. * @type {Array}
  647. */
  648. _assetTypes: ['component', 'directive', 'transition'],
  649. /**
  650. * List of lifecycle hooks.
  651. *
  652. * @type {Array}
  653. */
  654. _lifecycleHooks: ['init', 'created', 'beforeMount', 'mounted', 'ready', 'beforeUpdate', 'updated', 'beforeDestroy', 'destroyed'],
  655. /**
  656. * Max circular updates allowed in a batcher flush cycle.
  657. */
  658. _maxUpdateCount: 100
  659. };
  660. // we have two separate queues: one for directive updates
  661. // and one for user watcher registered via $watch().
  662. // we want to guarantee directive updates to be called
  663. // before user watchers so that when user watchers are
  664. // triggered, the DOM would have already been in updated
  665. // state.
  666. var queueIndex;
  667. var queue = [];
  668. var userQueue = [];
  669. var has = {};
  670. var circular = {};
  671. var waiting = false;
  672. var internalQueueDepleted = false;
  673. /**
  674. * Reset the batcher's state.
  675. */
  676. function resetBatcherState() {
  677. queue = [];
  678. userQueue = [];
  679. has = {};
  680. circular = {};
  681. waiting = internalQueueDepleted = false;
  682. }
  683. /**
  684. * Flush both queues and run the watchers.
  685. */
  686. function flushBatcherQueue() {
  687. queue.sort(queueSorter);
  688. runBatcherQueue(queue);
  689. internalQueueDepleted = true;
  690. runBatcherQueue(userQueue);
  691. resetBatcherState();
  692. }
  693. /**
  694. * Sort queue before flush.
  695. * This ensures components are updated from parent to child
  696. * so there will be no duplicate updates, e.g. a child was
  697. * pushed into the queue first and then its parent's props
  698. * changed.
  699. */
  700. function queueSorter(a, b) {
  701. return a.id - b.id;
  702. }
  703. /**
  704. * Run the watchers in a single queue.
  705. *
  706. * @param {Array} queue
  707. */
  708. function runBatcherQueue(queue) {
  709. // do not cache length because more watchers might be pushed
  710. // as we run existing watchers
  711. for (queueIndex = 0; queueIndex < queue.length; queueIndex++) {
  712. var watcher = queue[queueIndex];
  713. var id = watcher.id;
  714. has[id] = null;
  715. watcher.run();
  716. // in dev build, check and stop circular updates.
  717. if (process.env.NODE_ENV !== 'production' && has[id] != null) {
  718. circular[id] = (circular[id] || 0) + 1;
  719. if (circular[id] > config._maxUpdateCount) {
  720. warn('You may have an infinite update loop for watcher ' + 'with expression "' + watcher.expression + '"', watcher.vm);
  721. break;
  722. }
  723. }
  724. }
  725. }
  726. /**
  727. * Push a watcher into the watcher queue.
  728. * Jobs with duplicate IDs will be skipped unless it's
  729. * pushed when the queue is being flushed.
  730. *
  731. * @param {Watcher} watcher
  732. * properties:
  733. * - {Number} id
  734. * - {Function} run
  735. */
  736. function pushWatcher(watcher) {
  737. var id = watcher.id;
  738. if (has[id] == null) {
  739. if (internalQueueDepleted && !watcher.user) {
  740. // an internal watcher triggered by a user watcher...
  741. // let's run it immediately after current user watcher is done.
  742. userQueue.splice(queueIndex + 1, 0, watcher);
  743. } else {
  744. // push watcher into appropriate queue
  745. var q = watcher.user ? userQueue : queue;
  746. has[id] = q.length;
  747. q.push(watcher);
  748. // queue the flush
  749. if (!waiting) {
  750. waiting = true;
  751. nextTick(flushBatcherQueue);
  752. }
  753. }
  754. }
  755. }
  756. var uid$1 = 0;
  757. var prevTarget = void 0;
  758. /**
  759. * A watcher parses an expression, collects dependencies,
  760. * and fires callback when the expression value changes.
  761. * This is used for both the $watch() api and directives.
  762. *
  763. * @param {Vue} vm
  764. * @param {String|Function} expOrFn
  765. * @param {Function} cb
  766. * @param {Object} options
  767. * - {Array} filters
  768. * - {Boolean} twoWay
  769. * - {Boolean} deep
  770. * - {Boolean} user
  771. * - {Boolean} sync
  772. * - {Boolean} lazy
  773. * - {Function} [preProcess]
  774. * - {Function} [postProcess]
  775. * @constructor
  776. */
  777. function Watcher(vm, expOrFn, cb, options) {
  778. // mix in options
  779. if (options) {
  780. extend(this, options);
  781. }
  782. var isFn = typeof expOrFn === 'function';
  783. this.vm = vm;
  784. vm._watchers.push(this);
  785. this.expression = expOrFn;
  786. this.cb = cb;
  787. this.id = ++uid$1; // uid for batching
  788. this.active = true;
  789. this.dirty = this.lazy; // for lazy watchers
  790. this.deps = [];
  791. this.newDeps = [];
  792. this.depIds = new Set$1();
  793. this.newDepIds = new Set$1();
  794. // parse expression for getter
  795. if (isFn) {
  796. this.getter = expOrFn;
  797. } else {
  798. this.getter = parsePath(expOrFn);
  799. if (!this.getter) {
  800. this.getter = function () {};
  801. 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);
  802. }
  803. }
  804. this.value = this.lazy ? undefined : this.get();
  805. // state for avoiding false triggers for deep and Array
  806. // watchers during vm._digest()
  807. this.queued = this.shallow = false;
  808. }
  809. /**
  810. * Evaluate the getter, and re-collect dependencies.
  811. */
  812. Watcher.prototype.get = function () {
  813. this.beforeGet();
  814. var value = this.getter.call(this.vm, this.vm);
  815. // "touch" every property so they are all tracked as
  816. // dependencies for deep watching
  817. if (this.deep) {
  818. traverse(value);
  819. }
  820. this.afterGet();
  821. return value;
  822. };
  823. /**
  824. * Prepare for dependency collection.
  825. */
  826. Watcher.prototype.beforeGet = function () {
  827. prevTarget = Dep.target;
  828. Dep.target = this;
  829. };
  830. /**
  831. * Add a dependency to this directive.
  832. *
  833. * @param {Dep} dep
  834. */
  835. Watcher.prototype.addDep = function (dep) {
  836. var id = dep.id;
  837. if (!this.newDepIds.has(id)) {
  838. this.newDepIds.add(id);
  839. this.newDeps.push(dep);
  840. if (!this.depIds.has(id)) {
  841. dep.addSub(this);
  842. }
  843. }
  844. };
  845. /**
  846. * Clean up for dependency collection.
  847. */
  848. Watcher.prototype.afterGet = function () {
  849. Dep.target = prevTarget;
  850. var i = this.deps.length;
  851. while (i--) {
  852. var dep = this.deps[i];
  853. if (!this.newDepIds.has(dep.id)) {
  854. dep.removeSub(this);
  855. }
  856. }
  857. var tmp = this.depIds;
  858. this.depIds = this.newDepIds;
  859. this.newDepIds = tmp;
  860. this.newDepIds.clear();
  861. tmp = this.deps;
  862. this.deps = this.newDeps;
  863. this.newDeps = tmp;
  864. this.newDeps.length = 0;
  865. };
  866. /**
  867. * Subscriber interface.
  868. * Will be called when a dependency changes.
  869. *
  870. * @param {Boolean} shallow
  871. */
  872. Watcher.prototype.update = function (shallow) {
  873. if (this.lazy) {
  874. this.dirty = true;
  875. } else if (this.sync) {
  876. this.run();
  877. } else {
  878. // if queued, only overwrite shallow with non-shallow,
  879. // but not the other way around.
  880. this.shallow = this.queued ? shallow ? this.shallow : false : !!shallow;
  881. this.queued = true;
  882. pushWatcher(this);
  883. }
  884. };
  885. /**
  886. * Batcher job interface.
  887. * Will be called by the batcher.
  888. */
  889. Watcher.prototype.run = function () {
  890. if (this.active) {
  891. var value = this.get();
  892. if (value !== this.value ||
  893. // Deep watchers and watchers on Object/Arrays should fire even
  894. // when the value is the same, because the value may
  895. // have mutated; but only do so if this is a
  896. // non-shallow update (caused by a vm digest).
  897. (isObject(value) || this.deep) && !this.shallow) {
  898. // set new value
  899. var oldValue = this.value;
  900. this.value = value;
  901. this.cb.call(this.vm, value, oldValue);
  902. }
  903. this.queued = this.shallow = false;
  904. }
  905. };
  906. /**
  907. * Evaluate the value of the watcher.
  908. * This only gets called for lazy watchers.
  909. */
  910. Watcher.prototype.evaluate = function () {
  911. // avoid overwriting another watcher that is being
  912. // collected.
  913. var current = Dep.target;
  914. this.value = this.get();
  915. this.dirty = false;
  916. Dep.target = current;
  917. };
  918. /**
  919. * Depend on all deps collected by this watcher.
  920. */
  921. Watcher.prototype.depend = function () {
  922. var i = this.deps.length;
  923. while (i--) {
  924. this.deps[i].depend();
  925. }
  926. };
  927. /**
  928. * Remove self from all dependencies' subcriber list.
  929. */
  930. Watcher.prototype.teardown = function () {
  931. if (this.active) {
  932. // remove self from vm's watcher list
  933. // this is a somewhat expensive operation so we skip it
  934. // if the vm is being destroyed or is performing a v-for
  935. // re-render (the watcher list is then filtered by v-for).
  936. if (!this.vm._isBeingDestroyed && !this.vm._vForRemoving) {
  937. remove(this.vm._watchers, this);
  938. }
  939. var i = this.deps.length;
  940. while (i--) {
  941. this.deps[i].removeSub(this);
  942. }
  943. this.active = false;
  944. this.vm = this.cb = this.value = null;
  945. }
  946. };
  947. /**
  948. * Recrusively traverse an object to evoke all converted
  949. * getters, so that every nested property inside the object
  950. * is collected as a "deep" dependency.
  951. *
  952. * @param {*} val
  953. * @param {Set} seen
  954. */
  955. var seenObjects = new Set$1();
  956. function traverse(val, seen) {
  957. var i = void 0,
  958. keys = void 0,
  959. isA = void 0,
  960. isO = void 0;
  961. if (!seen) {
  962. seen = seenObjects;
  963. seen.clear();
  964. }
  965. isA = isArray(val);
  966. isO = isObject(val);
  967. if (isA || isO) {
  968. if (val.__ob__) {
  969. var depId = val.__ob__.dep.id;
  970. if (seen.has(depId)) {
  971. return;
  972. } else {
  973. seen.add(depId);
  974. }
  975. }
  976. if (isA) {
  977. i = val.length;
  978. while (i--) {
  979. traverse(val[i], seen);
  980. }
  981. } else if (isO) {
  982. keys = Object.keys(val);
  983. i = keys.length;
  984. while (i--) {
  985. traverse(val[keys[i]], seen);
  986. }
  987. }
  988. }
  989. }
  990. var arrayProto = Array.prototype;
  991. var arrayMethods = Object.create(arrayProto)
  992. /**
  993. * Intercept mutating methods and emit events
  994. */
  995. ;['push', 'pop', 'shift', 'unshift', 'splice', 'sort', 'reverse'].forEach(function (method) {
  996. // cache original method
  997. var original = arrayProto[method];
  998. def(arrayMethods, method, function mutator() {
  999. // avoid leaking arguments:
  1000. // http://jsperf.com/closure-with-arguments
  1001. var i = arguments.length;
  1002. var args = new Array(i);
  1003. while (i--) {
  1004. args[i] = arguments[i];
  1005. }
  1006. var result = original.apply(this, args);
  1007. var ob = this.__ob__;
  1008. var inserted;
  1009. switch (method) {
  1010. case 'push':
  1011. inserted = args;
  1012. break;
  1013. case 'unshift':
  1014. inserted = args;
  1015. break;
  1016. case 'splice':
  1017. inserted = args.slice(2);
  1018. break;
  1019. }
  1020. if (inserted) ob.observeArray(inserted);
  1021. // notify change
  1022. ob.dep.notify();
  1023. return result;
  1024. });
  1025. });
  1026. var arrayKeys = Object.getOwnPropertyNames(arrayMethods);
  1027. /**
  1028. * By default, when a reactive property is set, the new value is
  1029. * also converted to become reactive. However when passing down props,
  1030. * we don't want to force conversion because the value may be a nested value
  1031. * under a frozen data structure. Converting it would defeat the optimization.
  1032. */
  1033. var observerState = {
  1034. shouldConvert: true
  1035. };
  1036. /**
  1037. * Observer class that are attached to each observed
  1038. * object. Once attached, the observer converts target
  1039. * object's property keys into getter/setters that
  1040. * collect dependencies and dispatches updates.
  1041. *
  1042. * @param {Array|Object} value
  1043. * @constructor
  1044. */
  1045. function Observer(value) {
  1046. this.value = value;
  1047. this.dep = new Dep();
  1048. def(value, '__ob__', this);
  1049. if (isArray(value)) {
  1050. var augment = hasProto ? protoAugment : copyAugment;
  1051. augment(value, arrayMethods, arrayKeys);
  1052. this.observeArray(value);
  1053. } else {
  1054. this.walk(value);
  1055. }
  1056. }
  1057. // Instance methods
  1058. /**
  1059. * Walk through each property and convert them into
  1060. * getter/setters. This method should only be called when
  1061. * value type is Object.
  1062. *
  1063. * @param {Object} obj
  1064. */
  1065. Observer.prototype.walk = function (obj) {
  1066. for (var key in obj) {
  1067. this.convert(key, obj[key]);
  1068. }
  1069. };
  1070. /**
  1071. * Observe a list of Array items.
  1072. *
  1073. * @param {Array} items
  1074. */
  1075. Observer.prototype.observeArray = function (items) {
  1076. for (var i = 0, l = items.length; i < l; i++) {
  1077. observe(items[i]);
  1078. }
  1079. };
  1080. /**
  1081. * Convert a property into getter/setter so we can emit
  1082. * the events when the property is accessed/changed.
  1083. *
  1084. * @param {String} key
  1085. * @param {*} val
  1086. */
  1087. Observer.prototype.convert = function (key, val) {
  1088. defineReactive(this.value, key, val);
  1089. };
  1090. /**
  1091. * Add an owner vm, so that when $set/$delete mutations
  1092. * happen we can notify owner vms to proxy the keys and
  1093. * digest the watchers. This is only called when the object
  1094. * is observed as an instance's root $data.
  1095. *
  1096. * @param {Vue} vm
  1097. */
  1098. Observer.prototype.addVm = function (vm) {
  1099. (this.vms || (this.vms = [])).push(vm);
  1100. };
  1101. /**
  1102. * Remove an owner vm. This is called when the object is
  1103. * swapped out as an instance's $data object.
  1104. *
  1105. * @param {Vue} vm
  1106. */
  1107. Observer.prototype.removeVm = function (vm) {
  1108. remove(this.vms, vm);
  1109. };
  1110. // helpers
  1111. /**
  1112. * Augment an target Object or Array by intercepting
  1113. * the prototype chain using __proto__
  1114. *
  1115. * @param {Object|Array} target
  1116. * @param {Object} src
  1117. */
  1118. function protoAugment(target, src) {
  1119. /* eslint-disable no-proto */
  1120. target.__proto__ = src;
  1121. /* eslint-enable no-proto */
  1122. }
  1123. /**
  1124. * Augment an target Object or Array by defining
  1125. * hidden properties.
  1126. *
  1127. * @param {Object|Array} target
  1128. * @param {Object} proto
  1129. */
  1130. function copyAugment(target, src, keys) {
  1131. for (var i = 0, l = keys.length; i < l; i++) {
  1132. var key = keys[i];
  1133. def(target, key, src[key]);
  1134. }
  1135. }
  1136. /**
  1137. * Attempt to create an observer instance for a value,
  1138. * returns the new observer if successfully observed,
  1139. * or the existing observer if the value already has one.
  1140. *
  1141. * @param {*} value
  1142. * @param {Vue} [vm]
  1143. * @return {Observer|undefined}
  1144. * @static
  1145. */
  1146. function observe(value, vm) {
  1147. if (!isObject(value)) {
  1148. return;
  1149. }
  1150. var ob;
  1151. if (hasOwn(value, '__ob__') && value.__ob__ instanceof Observer) {
  1152. ob = value.__ob__;
  1153. } else if (observerState.shouldConvert && (isArray(value) || isPlainObject(value)) && Object.isExtensible(value) && !value._isVue) {
  1154. ob = new Observer(value);
  1155. }
  1156. if (ob && vm) {
  1157. ob.addVm(vm);
  1158. }
  1159. return ob;
  1160. }
  1161. /**
  1162. * Define a reactive property on an Object.
  1163. *
  1164. * @param {Object} obj
  1165. * @param {String} key
  1166. * @param {*} val
  1167. */
  1168. function defineReactive(obj, key, val) {
  1169. var dep = new Dep();
  1170. var property = Object.getOwnPropertyDescriptor(obj, key);
  1171. if (property && property.configurable === false) {
  1172. return;
  1173. }
  1174. // cater for pre-defined getter/setters
  1175. var getter = property && property.get;
  1176. var setter = property && property.set;
  1177. var childOb = observe(val);
  1178. Object.defineProperty(obj, key, {
  1179. enumerable: true,
  1180. configurable: true,
  1181. get: function reactiveGetter() {
  1182. var value = getter ? getter.call(obj) : val;
  1183. if (Dep.target) {
  1184. dep.depend();
  1185. if (childOb) {
  1186. childOb.dep.depend();
  1187. }
  1188. if (isArray(value)) {
  1189. for (var e, i = 0, l = value.length; i < l; i++) {
  1190. e = value[i];
  1191. e && e.__ob__ && e.__ob__.dep.depend();
  1192. }
  1193. }
  1194. }
  1195. return value;
  1196. },
  1197. set: function reactiveSetter(newVal) {
  1198. var value = getter ? getter.call(obj) : val;
  1199. if (newVal === value) {
  1200. return;
  1201. }
  1202. if (setter) {
  1203. setter.call(obj, newVal);
  1204. } else {
  1205. val = newVal;
  1206. }
  1207. childOb = observe(newVal);
  1208. dep.notify();
  1209. }
  1210. });
  1211. }
  1212. /**
  1213. * Set a property on an object. Adds the new property and
  1214. * triggers change notification if the property doesn't
  1215. * already exist.
  1216. *
  1217. * @param {Object} obj
  1218. * @param {String} key
  1219. * @param {*} val
  1220. * @public
  1221. */
  1222. function set(obj, key, val) {
  1223. if (isArray(obj)) {
  1224. return obj.splice(key, 1, val);
  1225. }
  1226. if (hasOwn(obj, key)) {
  1227. obj[key] = val;
  1228. return;
  1229. }
  1230. if (obj._isVue) {
  1231. set(obj._data, key, val);
  1232. return;
  1233. }
  1234. var ob = obj.__ob__;
  1235. if (!ob) {
  1236. obj[key] = val;
  1237. return;
  1238. }
  1239. ob.convert(key, val);
  1240. ob.dep.notify();
  1241. if (ob.vms) {
  1242. var i = ob.vms.length;
  1243. while (i--) {
  1244. var vm = ob.vms[i];
  1245. proxy(vm, key);
  1246. vm.$forceUpdate();
  1247. }
  1248. }
  1249. return val;
  1250. }
  1251. function proxy(vm, key) {
  1252. if (!isReserved(key)) {
  1253. Object.defineProperty(vm, key, {
  1254. configurable: true,
  1255. enumerable: true,
  1256. get: function proxyGetter() {
  1257. return vm._data[key];
  1258. },
  1259. set: function proxySetter(val) {
  1260. vm._data[key] = val;
  1261. }
  1262. });
  1263. }
  1264. }
  1265. function unproxy(vm, key) {
  1266. if (!isReserved(key)) {
  1267. delete vm[key];
  1268. }
  1269. }
  1270. function initState(vm) {
  1271. vm._watchers = [];
  1272. initProps(vm);
  1273. initData(vm);
  1274. initComputed(vm);
  1275. initMethods(vm);
  1276. initWatch(vm);
  1277. }
  1278. function initProps(vm) {
  1279. var props = vm.$options.props;
  1280. var propsData = vm.$options.propsData;
  1281. if (props) {
  1282. var keys = vm.$options.propKeys = Object.keys(props);
  1283. var isRoot = !vm.$parent;
  1284. // root instance props should be converted
  1285. observerState.shouldConvert = isRoot;
  1286. for (var i = 0; i < keys.length; i++) {
  1287. var key = keys[i];
  1288. defineReactive(vm, key, validateProp(vm, key, propsData));
  1289. }
  1290. observerState.shouldConvert = true;
  1291. }
  1292. }
  1293. function initData(vm) {
  1294. var data = vm.$options.data;
  1295. data = vm._data = typeof data === 'function' ? data() : data || {};
  1296. if (!isPlainObject(data)) {
  1297. data = {};
  1298. process.env.NODE_ENV !== 'production' && warn('data functions should return an object.', vm);
  1299. }
  1300. // proxy data on instance
  1301. var keys = Object.keys(data);
  1302. var i = keys.length;
  1303. while (i--) {
  1304. proxy(vm, keys[i]);
  1305. }
  1306. // observe data
  1307. observe(data, vm);
  1308. }
  1309. function noop() {}
  1310. function initComputed(vm) {
  1311. var computed = vm.$options.computed;
  1312. if (computed) {
  1313. for (var key in computed) {
  1314. var userDef = computed[key];
  1315. var def = {
  1316. enumerable: true,
  1317. configurable: true
  1318. };
  1319. if (typeof userDef === 'function') {
  1320. def.get = makeComputedGetter(userDef, vm);
  1321. def.set = noop;
  1322. } else {
  1323. def.get = userDef.get ? userDef.cache !== false ? makeComputedGetter(userDef.get, vm) : bind(userDef.get, vm) : noop;
  1324. def.set = userDef.set ? bind(userDef.set, vm) : noop;
  1325. }
  1326. Object.defineProperty(vm, key, def);
  1327. }
  1328. }
  1329. }
  1330. function makeComputedGetter(getter, owner) {
  1331. var watcher = new Watcher(owner, getter, null, {
  1332. lazy: true
  1333. });
  1334. return function computedGetter() {
  1335. if (watcher.dirty) {
  1336. watcher.evaluate();
  1337. }
  1338. if (Dep.target) {
  1339. watcher.depend();
  1340. }
  1341. return watcher.value;
  1342. };
  1343. }
  1344. function initMethods(vm) {
  1345. var methods = vm.$options.methods;
  1346. if (methods) {
  1347. for (var key in methods) {
  1348. vm[key] = bind(methods[key], vm);
  1349. }
  1350. }
  1351. }
  1352. function initWatch(vm) {
  1353. var watch = vm.$options.watch;
  1354. if (watch) {
  1355. for (var key in watch) {
  1356. var handler = watch[key];
  1357. if (isArray(handler)) {
  1358. for (var i = 0; i < handler.length; i++) {
  1359. createWatcher(vm, key, handler[i]);
  1360. }
  1361. } else {
  1362. createWatcher(vm, key, handler);
  1363. }
  1364. }
  1365. }
  1366. }
  1367. function createWatcher(vm, key, handler) {
  1368. var options = void 0;
  1369. if (isPlainObject(handler)) {
  1370. options = handler;
  1371. handler = handler.handler;
  1372. }
  1373. if (typeof handler === 'string') {
  1374. handler = vm[handler];
  1375. }
  1376. vm.$watch(key, handler, options);
  1377. }
  1378. function stateMixin(Vue) {
  1379. Object.defineProperty(Vue.prototype, '$data', {
  1380. get: function get() {
  1381. return this._data;
  1382. },
  1383. set: function set(newData) {
  1384. if (newData !== this._data) {
  1385. setData(this, newData);
  1386. }
  1387. }
  1388. });
  1389. Vue.prototype.$watch = function (fn, cb, options) {
  1390. options = options || {};
  1391. options.user = true;
  1392. var watcher = new Watcher(this, fn, cb, options);
  1393. if (options.immediate) {
  1394. cb.call(this, watcher.value);
  1395. }
  1396. return function unwatchFn() {
  1397. watcher.teardown();
  1398. };
  1399. };
  1400. }
  1401. function setData(vm, newData) {
  1402. newData = newData || {};
  1403. var oldData = vm._data;
  1404. vm._data = newData;
  1405. var keys, key, i;
  1406. // unproxy keys not present in new data
  1407. keys = Object.keys(oldData);
  1408. i = keys.length;
  1409. while (i--) {
  1410. key = keys[i];
  1411. if (!(key in newData)) {
  1412. unproxy(vm, key);
  1413. }
  1414. }
  1415. // proxy keys not already proxied,
  1416. // and trigger change for changed values
  1417. keys = Object.keys(newData);
  1418. i = keys.length;
  1419. while (i--) {
  1420. key = keys[i];
  1421. if (!hasOwn(vm, key)) {
  1422. // new property
  1423. proxy(vm, key);
  1424. }
  1425. }
  1426. oldData.__ob__.removeVm(vm);
  1427. observe(newData, vm);
  1428. vm.$forceUpdate();
  1429. }
  1430. function VNode(tag, data, children, text, elm, ns, context) {
  1431. return {
  1432. tag: tag,
  1433. data: data,
  1434. children: children,
  1435. text: text,
  1436. elm: elm,
  1437. ns: ns,
  1438. context: context,
  1439. key: data && data.key
  1440. };
  1441. }
  1442. function flatten(children) {
  1443. if (typeof children === 'string') {
  1444. return [VNode(undefined, undefined, undefined, children)];
  1445. }
  1446. if (isArray(children)) {
  1447. var res = [];
  1448. for (var i = 0, l = children.length; i < l; i++) {
  1449. var c = children[i];
  1450. // flatten nested
  1451. if (isArray(c)) {
  1452. res.push.apply(res, flatten(c));
  1453. } else if (isPrimitive(c)) {
  1454. // convert primitive to vnode
  1455. res.push(VNode(undefined, undefined, undefined, c));
  1456. } else if (c) {
  1457. res.push(c);
  1458. }
  1459. }
  1460. return res;
  1461. }
  1462. }
  1463. function updateListeners(on, oldOn, add) {
  1464. var name = void 0,
  1465. cur = void 0,
  1466. old = void 0,
  1467. event = void 0,
  1468. capture = void 0;
  1469. for (name in on) {
  1470. cur = on[name];
  1471. old = oldOn[name];
  1472. if (old === undefined) {
  1473. capture = name.charAt(0) === '!';
  1474. event = capture ? name.slice(1) : name;
  1475. if (isArray(cur)) {
  1476. add(event, arrInvoker(cur), capture);
  1477. } else {
  1478. cur = { fn: cur };
  1479. on[name] = cur;
  1480. add(event, fnInvoker(cur), capture);
  1481. }
  1482. } else if (isArray(old)) {
  1483. old.length = cur.length;
  1484. for (var i = 0; i < old.length; i++) {
  1485. old[i] = cur[i];
  1486. }on[name] = old;
  1487. } else {
  1488. old.fn = cur;
  1489. on[name] = old;
  1490. }
  1491. }
  1492. }
  1493. function arrInvoker(arr) {
  1494. return function (ev) {
  1495. for (var i = 0; i < arr.length; i++) {
  1496. arr[i](ev);
  1497. }
  1498. };
  1499. }
  1500. function fnInvoker(o) {
  1501. return function (ev) {
  1502. o.fn(ev);
  1503. };
  1504. }
  1505. function initLifecycle(vm) {
  1506. var options = vm.$options;
  1507. vm.$parent = options.parent;
  1508. vm.$root = vm.$parent ? vm.$parent.$root : vm;
  1509. if (vm.$parent) {
  1510. vm.$parent.$children.push(vm);
  1511. }
  1512. vm.$children = [];
  1513. vm.$refs = {};
  1514. vm._isDestroyed = false;
  1515. vm._isBeingDestroyed = false;
  1516. }
  1517. function lifecycleMixin(Vue) {
  1518. Vue.prototype._mount = function () {
  1519. var _this = this;
  1520. if (!this.$options.render) {
  1521. this.$options.render = function () {
  1522. return _this.$createElement('div');
  1523. };
  1524. if (process.env.NODE_ENV !== 'production') {
  1525. if (this.$options.template) {
  1526. 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);
  1527. } else {
  1528. warn('Failed to mount component: template or render function not defined.', this);
  1529. }
  1530. }
  1531. }
  1532. // render static sub-trees for once on mount
  1533. var staticRenderFns = this.$options.staticRenderFns;
  1534. if (staticRenderFns) {
  1535. this._staticTrees = new Array(staticRenderFns.length);
  1536. for (var i = 0; i < staticRenderFns.length; i++) {
  1537. this._staticTrees[i] = staticRenderFns[i].call(this._renderProxy);
  1538. }
  1539. }
  1540. this._watcher = new Watcher(this, this._render, this._update);
  1541. this._update(this._watcher.value);
  1542. this._mounted = true;
  1543. // root instance, call ready on self
  1544. if (this.$root === this) {
  1545. callHook(this, 'ready');
  1546. }
  1547. return this;
  1548. };
  1549. Vue.prototype._update = function (vnode) {
  1550. if (this._mounted) {
  1551. callHook(this, 'beforeUpdate');
  1552. }
  1553. var parentNode = this.$options._parentVnode;
  1554. // set vnode parent before patch
  1555. vnode.parent = parentNode;
  1556. if (!this._vnode) {
  1557. // Vue.prototype.__patch__ is injected in entry points
  1558. // based on the rendering backend used.
  1559. this.$el = this.__patch__(this.$el, vnode);
  1560. } else {
  1561. this.$el = this.__patch__(this._vnode, vnode);
  1562. }
  1563. this._vnode = vnode;
  1564. // set parent vnode element after patch
  1565. if (parentNode) {
  1566. parentNode.elm = this.$el;
  1567. }
  1568. if (this._mounted) {
  1569. callHook(this, 'updated');
  1570. }
  1571. };
  1572. Vue.prototype._updateFromParent = function (propsData, listeners, parentVnode, children) {
  1573. var _this2 = this;
  1574. this.$options._parentVnode = parentVnode;
  1575. this.$options._renderChildren = children;
  1576. // update props
  1577. if (propsData && this.$options.props) {
  1578. observerState.shouldConvert = false;
  1579. var propKeys = this.$options.propKeys;
  1580. for (var i = 0; i < propKeys.length; i++) {
  1581. var key = propKeys[i];
  1582. this[key] = validateProp(this, key, propsData);
  1583. }
  1584. observerState.shouldConvert = true;
  1585. }
  1586. // update listeners
  1587. if (listeners) {
  1588. var oldListeners = this.$options._parentListeners;
  1589. this.$options._parentListeners = listeners;
  1590. updateListeners(listeners, oldListeners || {}, function (event, handler) {
  1591. _this2.$on(event, handler);
  1592. });
  1593. }
  1594. };
  1595. Vue.prototype.$forceUpdate = function () {
  1596. this._watcher.update();
  1597. };
  1598. Vue.prototype.$destroy = function () {
  1599. if (this._isDestroyed) {
  1600. return;
  1601. }
  1602. callHook(this, 'beforeDestroy');
  1603. this._isBeingDestroyed = true;
  1604. // remove self from parent
  1605. var parent = this.$parent;
  1606. if (parent && !parent._isBeingDestroyed) {
  1607. remove(parent.$children, this);
  1608. }
  1609. // unregister ref
  1610. if (this._ref) {
  1611. this._context.$refs[this._ref] = undefined;
  1612. }
  1613. // teardown watchers
  1614. var i = this._watchers.length;
  1615. while (i--) {
  1616. this._watchers[i].teardown();
  1617. }
  1618. // remove reference from data ob
  1619. // frozen object may not have observer.
  1620. if (this._data.__ob__) {
  1621. this._data.__ob__.removeVm(this);
  1622. }
  1623. // call the last hook...
  1624. this._isDestroyed = true;
  1625. callHook(this, 'destroyed');
  1626. // turn off all instance listeners.
  1627. this.$off();
  1628. };
  1629. }
  1630. function callHook(vm, hook) {
  1631. vm.$emit('pre-hook:' + hook);
  1632. var handlers = vm.$options[hook];
  1633. if (handlers) {
  1634. for (var i = 0, j = handlers.length; i < j; i++) {
  1635. handlers[i].call(vm);
  1636. }
  1637. }
  1638. vm.$emit('hook:' + hook);
  1639. }
  1640. var hooks = { init: init, prepatch: prepatch, insert: insert, destroy: destroy };
  1641. var hooksToMerge = Object.keys(hooks);
  1642. function createComponent(Ctor, data, parent, children, context) {
  1643. if (process.env.NODE_ENV !== 'production' && children && typeof children !== 'function') {
  1644. 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.');
  1645. }
  1646. if (!Ctor) {
  1647. return;
  1648. }
  1649. if (isObject(Ctor)) {
  1650. Ctor = Vue.extend(Ctor);
  1651. }
  1652. if (process.env.NODE_ENV !== 'production' && typeof Ctor !== 'function') {
  1653. warn('Invalid Component definition: ' + Ctor, parent);
  1654. return;
  1655. }
  1656. // async component
  1657. if (!Ctor.cid) {
  1658. if (Ctor.resolved) {
  1659. Ctor = Ctor.resolved;
  1660. } else {
  1661. resolveAsyncComponent(Ctor, function () {
  1662. // it's ok to queue this on every render because
  1663. // $forceUpdate is buffered.
  1664. parent.$forceUpdate();
  1665. });
  1666. return;
  1667. }
  1668. }
  1669. data = data || {};
  1670. // merge component management hooks onto the placeholder node
  1671. mergeHooks(data);
  1672. // extract props
  1673. var propsData = extractProps(data, Ctor);
  1674. // extract listeners, since these needs to be treated as
  1675. // child component listeners instead of DOM listeners
  1676. var listeners = data.on;
  1677. if (listeners) {
  1678. data.on = null;
  1679. }
  1680. // return a placeholder vnode
  1681. var name = Ctor.options.name ? '-' + Ctor.options.name : '';
  1682. var vnode = VNode('vue-component-' + Ctor.cid + name, data, undefined, undefined, undefined, undefined, context);
  1683. vnode.componentOptions = { Ctor: Ctor, propsData: propsData, listeners: listeners, parent: parent, children: children };
  1684. return vnode;
  1685. }
  1686. function init(vnode) {
  1687. var _vnode$componentOptio = vnode.componentOptions;
  1688. var Ctor = _vnode$componentOptio.Ctor;
  1689. var propsData = _vnode$componentOptio.propsData;
  1690. var listeners = _vnode$componentOptio.listeners;
  1691. var parent = _vnode$componentOptio.parent;
  1692. var children = _vnode$componentOptio.children;
  1693. var child = new Ctor({
  1694. parent: parent,
  1695. propsData: propsData,
  1696. _parentVnode: vnode,
  1697. _parentListeners: listeners,
  1698. _renderChildren: children
  1699. });
  1700. // if this is a server-rendered mount,
  1701. // the vnode would already have an element.
  1702. // otherwise the child sets the parent vnode's elm when mounted
  1703. // and when updated.
  1704. child.$mount(vnode.elm);
  1705. vnode.child = child;
  1706. }
  1707. function prepatch(oldVnode, vnode) {
  1708. var _vnode$componentOptio2 = vnode.componentOptions;
  1709. var listeners = _vnode$componentOptio2.listeners;
  1710. var propsData = _vnode$componentOptio2.propsData;
  1711. var children = _vnode$componentOptio2.children;
  1712. vnode.child = oldVnode.child;
  1713. vnode.child._updateFromParent(propsData, // updated props
  1714. listeners, // updated listeners
  1715. vnode, // new parent vnode
  1716. children // new children
  1717. );
  1718. }
  1719. function insert(vnode) {
  1720. callHook(vnode.child, 'ready');
  1721. }
  1722. function destroy(vnode) {
  1723. vnode.child.$destroy();
  1724. }
  1725. function resolveAsyncComponent(factory, cb) {
  1726. if (factory.resolved) {
  1727. // cached
  1728. cb(factory.resolved);
  1729. } else if (factory.requested) {
  1730. // pool callbacks
  1731. factory.pendingCallbacks.push(cb);
  1732. } else {
  1733. (function () {
  1734. factory.requested = true;
  1735. var cbs = factory.pendingCallbacks = [cb];
  1736. factory(function resolve(res) {
  1737. if (isObject(res)) {
  1738. res = Vue.extend(res);
  1739. }
  1740. // cache resolved
  1741. factory.resolved = res;
  1742. // invoke callbacks
  1743. for (var i = 0, l = cbs.length; i < l; i++) {
  1744. cbs[i](res);
  1745. }
  1746. }, function reject(reason) {
  1747. process.env.NODE_ENV !== 'production' && warn('Failed to resolve async component: ' + factory + (reason ? '\nReason: ' + reason : ''));
  1748. });
  1749. })();
  1750. }
  1751. }
  1752. function extractProps(data, Ctor) {
  1753. // we are only extrating raw values here.
  1754. // validation and default values are handled in the child
  1755. // component itself.
  1756. var propOptions = Ctor.options.props;
  1757. if (!propOptions) {
  1758. return;
  1759. }
  1760. var res = {};
  1761. var attrs = data.attrs;
  1762. var props = data.props;
  1763. var staticAttrs = data.staticAttrs;
  1764. if (!attrs && !props) {
  1765. return res;
  1766. }
  1767. for (var key in propOptions) {
  1768. var altKey = hyphenate(key);
  1769. checkProp(res, attrs, key, altKey) || checkProp(res, props, key, altKey) || checkProp(res, staticAttrs, key, altKey);
  1770. }
  1771. return res;
  1772. }
  1773. function checkProp(res, hash, key, altKey) {
  1774. if (hash) {
  1775. if (hasOwn(hash, key)) {
  1776. res[key] = hash[key];
  1777. delete hash[key];
  1778. return true;
  1779. } else if (hasOwn(hash, altKey)) {
  1780. res[key] = hash[altKey];
  1781. delete hash[altKey];
  1782. return true;
  1783. }
  1784. }
  1785. }
  1786. function mergeHooks(data) {
  1787. if (data.hook) {
  1788. for (var i = 0; i < hooksToMerge.length; i++) {
  1789. var key = hooksToMerge[i];
  1790. var fromParent = data.hook[key];
  1791. var ours = hooks[key];
  1792. data.hook[key] = fromParent ? mergeHook$1(ours, fromParent) : ours;
  1793. }
  1794. } else {
  1795. data.hook = hooks;
  1796. }
  1797. }
  1798. function mergeHook$1(a, b) {
  1799. // since all hooks have at most two args, use fixed args
  1800. // to avoid having to use fn.apply().
  1801. return function (_, __) {
  1802. a(_, __);
  1803. b(_, __);
  1804. };
  1805. }
  1806. function createElement(tag, data, children, namespace) {
  1807. var context = this;
  1808. var parent = renderState.activeInstance;
  1809. if (typeof tag === 'string') {
  1810. var Ctor = void 0;
  1811. if (config.isReservedTag(tag)) {
  1812. return VNode(tag, data, flatten(children), undefined, undefined, namespace, context);
  1813. } else if (Ctor = resolveAsset(context.$options, 'components', tag)) {
  1814. return createComponent(Ctor, data, parent, children, context);
  1815. } else {
  1816. if (process.env.NODE_ENV !== 'production') {
  1817. if (!namespace && config.isUnknownElement(tag)) {
  1818. warn('Unknown custom element: <' + tag + '> - did you ' + 'register the component correctly? For recursive components, ' + 'make sure to provide the "name" option.');
  1819. }
  1820. }
  1821. return VNode(tag, data, flatten(children && children()), undefined, undefined, namespace, context);
  1822. }
  1823. } else {
  1824. return createComponent(tag, data, parent, children, context);
  1825. }
  1826. }
  1827. var renderState = {
  1828. activeInstance: null
  1829. };
  1830. function initRender(vm) {
  1831. vm._vnode = null;
  1832. vm._mounted = false;
  1833. vm._staticTrees = null;
  1834. vm.$slots = {};
  1835. // bind the public createElement fn to this instance
  1836. // so that we get proper render context inside it.
  1837. vm.$createElement = bind(createElement, vm);
  1838. if (vm.$options.el) {
  1839. vm.$mount(vm.$options.el);
  1840. }
  1841. }
  1842. function renderMixin(Vue) {
  1843. Vue.prototype._render = function () {
  1844. var prev = renderState.activeInstance;
  1845. renderState.activeInstance = this;
  1846. var _$options = this.$options;
  1847. var render = _$options.render;
  1848. var _renderChildren = _$options._renderChildren;
  1849. // resolve slots. becaues slots are rendered in parent scope,
  1850. // we set the activeInstance to parent.
  1851. if (_renderChildren) {
  1852. resolveSlots(this, _renderChildren);
  1853. }
  1854. // render self
  1855. var vnode = render.call(this._renderProxy);
  1856. // restore render state
  1857. renderState.activeInstance = prev;
  1858. return vnode;
  1859. };
  1860. // shorthands used in render functions
  1861. Vue.prototype.__h__ = createElement;
  1862. // toString for mustaches
  1863. Vue.prototype.__toString__ = renderString;
  1864. // render v-for
  1865. Vue.prototype.__renderList__ = function (val, render) {
  1866. var ret = void 0,
  1867. i = void 0,
  1868. l = void 0,
  1869. keys = void 0,
  1870. key = void 0;
  1871. if (isArray(val)) {
  1872. ret = new Array(val.length);
  1873. for (i = 0, l = val.length; i < l; i++) {
  1874. ret[i] = render(val[i], i, i);
  1875. }
  1876. } else if (typeof val === 'number') {
  1877. ret = new Array(val);
  1878. for (i = 0; i < val; i++) {
  1879. ret[i] = render(i + 1, i, i);
  1880. }
  1881. } else if (isObject(val)) {
  1882. keys = Object.keys(val);
  1883. ret = new Array(keys.length);
  1884. for (i = 0, l = keys.length; i < l; i++) {
  1885. key = keys[i];
  1886. ret[i] = render(val[key], i, key);
  1887. }
  1888. }
  1889. return ret;
  1890. };
  1891. // register ref
  1892. Vue.prototype.__registerRef__ = function (key, ref, vFor, remove) {
  1893. var refs = this.$refs;
  1894. if (remove) {
  1895. if (vFor) {
  1896. remove(refs[key], ref);
  1897. } else {
  1898. refs[key] = undefined;
  1899. }
  1900. } else {
  1901. if (vFor) {
  1902. if (refs[key]) {
  1903. refs[key].push(ref);
  1904. } else {
  1905. refs[key] = [ref];
  1906. }
  1907. } else {
  1908. refs[key] = ref;
  1909. }
  1910. }
  1911. };
  1912. }
  1913. function resolveSlots(vm, children) {
  1914. if (children) {
  1915. children = flatten(isArray(children) ? children : children());
  1916. var slots = { default: children };
  1917. var i = children.length;
  1918. var name = void 0,
  1919. child = void 0;
  1920. while (i--) {
  1921. child = children[i];
  1922. if (name = child.data && child.data.slot) {
  1923. var slot = slots[name] || (slots[name] = []);
  1924. if (child.tag === 'template') {
  1925. slot.push.apply(slot, child.children);
  1926. } else {
  1927. slot.push(child);
  1928. }
  1929. children.splice(i, 1);
  1930. }
  1931. }
  1932. vm.$slots = slots;
  1933. }
  1934. }
  1935. function initEvents(vm) {
  1936. vm._events = Object.create(null);
  1937. // init parent attached events
  1938. var listeners = vm.$options._parentListeners;
  1939. if (listeners) {
  1940. updateListeners(listeners, {}, function (event, handler) {
  1941. vm.$on(event, handler);
  1942. });
  1943. }
  1944. }
  1945. function eventsMixin(Vue) {
  1946. Vue.prototype.$on = function (event, fn) {
  1947. (this._events[event] || (this._events[event] = [])).push(fn);
  1948. return this;
  1949. };
  1950. /**
  1951. * Adds an `event` listener that will be invoked a single
  1952. * time then automatically removed.
  1953. *
  1954. * @param {String} event
  1955. * @param {Function} fn
  1956. */
  1957. Vue.prototype.$once = function (event, fn) {
  1958. var self = this;
  1959. function on() {
  1960. self.$off(event, on);
  1961. fn.apply(this, arguments);
  1962. }
  1963. on.fn = fn;
  1964. this.$on(event, on);
  1965. return this;
  1966. };
  1967. /**
  1968. * Remove the given callback for `event` or all
  1969. * registered callbacks.
  1970. *
  1971. * @param {String} event
  1972. * @param {Function} fn
  1973. */
  1974. Vue.prototype.$off = function (event, fn) {
  1975. var cbs;
  1976. // all
  1977. if (!arguments.length) {
  1978. this._events = Object.create(null);
  1979. return this;
  1980. }
  1981. // specific event
  1982. cbs = this._events[event];
  1983. if (!cbs) {
  1984. return this;
  1985. }
  1986. if (arguments.length === 1) {
  1987. this._events[event] = null;
  1988. return this;
  1989. }
  1990. // specific handler
  1991. var cb;
  1992. var i = cbs.length;
  1993. while (i--) {
  1994. cb = cbs[i];
  1995. if (cb === fn || cb.fn === fn) {
  1996. cbs.splice(i, 1);
  1997. break;
  1998. }
  1999. }
  2000. return this;
  2001. };
  2002. /**
  2003. * Trigger an event on self.
  2004. *
  2005. * @param {String} event
  2006. */
  2007. Vue.prototype.$emit = function (event) {
  2008. var cbs = this._events[event];
  2009. if (cbs) {
  2010. cbs = cbs.length > 1 ? toArray(cbs) : cbs;
  2011. var args = toArray(arguments, 1);
  2012. for (var i = 0, l = cbs.length; i < l; i++) {
  2013. cbs[i].apply(this, args);
  2014. }
  2015. }
  2016. };
  2017. }
  2018. var uid = 0;
  2019. function Vue(options) {
  2020. this._init(options);
  2021. }
  2022. Vue.prototype._init = function (options) {
  2023. // a uid
  2024. this._uid = uid++;
  2025. // a flag to avoid this being observed
  2026. this._isVue = true;
  2027. // merge options
  2028. this.$options = mergeOptions(this.constructor.options, options || {}, this);
  2029. if (process.env.NODE_ENV !== 'production') {
  2030. initProxy(this);
  2031. } else {
  2032. this._renderProxy = this;
  2033. }
  2034. initLifecycle(this);
  2035. initEvents(this);
  2036. callHook(this, 'init');
  2037. initState(this);
  2038. callHook(this, 'created');
  2039. initRender(this);
  2040. };
  2041. Vue.prototype.$nextTick = function (fn) {
  2042. nextTick(fn, this);
  2043. };
  2044. stateMixin(Vue);
  2045. eventsMixin(Vue);
  2046. lifecycleMixin(Vue);
  2047. renderMixin(Vue);
  2048. var warn = void 0;
  2049. var formatComponentName = void 0;
  2050. if (process.env.NODE_ENV !== 'production') {
  2051. (function () {
  2052. var hasConsole = typeof console !== 'undefined';
  2053. warn = function warn(msg, vm) {
  2054. if (hasConsole && !config.silent) {
  2055. console.error('[Vue warn]: ' + msg + (vm ? formatComponentName(vm) : ''));
  2056. }
  2057. };
  2058. formatComponentName = function formatComponentName(vm) {
  2059. var name = vm._isVue ? vm.$options.name : vm.name;
  2060. return name ? ' (found in component: <' + hyphenate(name) + '>)' : '';
  2061. };
  2062. })();
  2063. }
  2064. /**
  2065. * Option overwriting strategies are functions that handle
  2066. * how to merge a parent option value and a child option
  2067. * value into the final value.
  2068. *
  2069. * All strategy functions follow the same signature:
  2070. *
  2071. * @param {*} parentVal
  2072. * @param {*} childVal
  2073. * @param {Vue} [vm]
  2074. */
  2075. var strats = config.optionMergeStrategies = Object.create(null);
  2076. /**
  2077. * Helper that recursively merges two data objects together.
  2078. */
  2079. function mergeData(to, from) {
  2080. var key, toVal, fromVal;
  2081. for (key in from) {
  2082. toVal = to[key];
  2083. fromVal = from[key];
  2084. if (!hasOwn(to, key)) {
  2085. set(to, key, fromVal);
  2086. } else if (isObject(toVal) && isObject(fromVal)) {
  2087. mergeData(toVal, fromVal);
  2088. }
  2089. }
  2090. return to;
  2091. }
  2092. /**
  2093. * Data
  2094. */
  2095. strats.data = function (parentVal, childVal, vm) {
  2096. if (!vm) {
  2097. // in a Vue.extend merge, both should be functions
  2098. if (!childVal) {
  2099. return parentVal;
  2100. }
  2101. if (typeof childVal !== 'function') {
  2102. process.env.NODE_ENV !== 'production' && warn('The "data" option should be a function ' + 'that returns a per-instance value in component ' + 'definitions.', vm);
  2103. return parentVal;
  2104. }
  2105. if (!parentVal) {
  2106. return childVal;
  2107. }
  2108. // when parentVal & childVal are both present,
  2109. // we need to return a function that returns the
  2110. // merged result of both functions... no need to
  2111. // check if parentVal is a function here because
  2112. // it has to be a function to pass previous merges.
  2113. return function mergedDataFn() {
  2114. return mergeData(childVal.call(this), parentVal.call(this));
  2115. };
  2116. } else if (parentVal || childVal) {
  2117. return function mergedInstanceDataFn() {
  2118. // instance merge
  2119. var instanceData = typeof childVal === 'function' ? childVal.call(vm) : childVal;
  2120. var defaultData = typeof parentVal === 'function' ? parentVal.call(vm) : undefined;
  2121. if (instanceData) {
  2122. return mergeData(instanceData, defaultData);
  2123. } else {
  2124. return defaultData;
  2125. }
  2126. };
  2127. }
  2128. };
  2129. /**
  2130. * El
  2131. */
  2132. strats.el = function (parentVal, childVal, vm) {
  2133. if (!vm && childVal && typeof childVal !== 'function') {
  2134. process.env.NODE_ENV !== 'production' && warn('The "el" option should be a function ' + 'that returns a per-instance value in component ' + 'definitions.', vm);
  2135. return;
  2136. }
  2137. var ret = childVal || parentVal;
  2138. // invoke the element factory if this is instance merge
  2139. return vm && typeof ret === 'function' ? ret.call(vm) : ret;
  2140. };
  2141. /**
  2142. * Hooks and param attributes are merged as arrays.
  2143. */
  2144. function mergeHook(parentVal, childVal) {
  2145. return childVal ? parentVal ? parentVal.concat(childVal) : isArray(childVal) ? childVal : [childVal] : parentVal;
  2146. }
  2147. config._lifecycleHooks.forEach(function (hook) {
  2148. strats[hook] = mergeHook;
  2149. });
  2150. /**
  2151. * Assets
  2152. *
  2153. * When a vm is present (instance creation), we need to do
  2154. * a three-way merge between constructor options, instance
  2155. * options and parent options.
  2156. */
  2157. function mergeAssets(parentVal, childVal) {
  2158. var res = Object.create(parentVal);
  2159. return childVal ? extend(res, childVal) : res;
  2160. }
  2161. config._assetTypes.forEach(function (type) {
  2162. strats[type + 's'] = mergeAssets;
  2163. });
  2164. /**
  2165. * Watchers.
  2166. *
  2167. * Watchers hashes should not overwrite one
  2168. * another, so we merge them as arrays.
  2169. */
  2170. strats.watch = function (parentVal, childVal) {
  2171. if (!childVal) return parentVal;
  2172. if (!parentVal) return childVal;
  2173. var ret = {};
  2174. extend(ret, parentVal);
  2175. for (var key in childVal) {
  2176. var parent = ret[key];
  2177. var child = childVal[key];
  2178. if (parent && !isArray(parent)) {
  2179. parent = [parent];
  2180. }
  2181. ret[key] = parent ? parent.concat(child) : [child];
  2182. }
  2183. return ret;
  2184. };
  2185. /**
  2186. * Other object hashes.
  2187. */
  2188. strats.props = strats.methods = strats.computed = function (parentVal, childVal) {
  2189. if (!childVal) return parentVal;
  2190. if (!parentVal) return childVal;
  2191. var ret = Object.create(null);
  2192. extend(ret, parentVal);
  2193. extend(ret, childVal);
  2194. return ret;
  2195. };
  2196. /**
  2197. * Default strategy.
  2198. */
  2199. var defaultStrat = function defaultStrat(parentVal, childVal) {
  2200. return childVal === undefined ? parentVal : childVal;
  2201. };
  2202. /**
  2203. * Make sure component options get converted to actual
  2204. * constructors.
  2205. *
  2206. * @param {Object} options
  2207. */
  2208. function guardComponents(options) {
  2209. if (options.components) {
  2210. var components = options.components;
  2211. var def;
  2212. for (var key in components) {
  2213. if (isBuiltInTag(key) || config.isReservedTag(key)) {
  2214. process.env.NODE_ENV !== 'production' && warn('Do not use built-in or reserved HTML elements as component ' + 'id: ' + key);
  2215. continue;
  2216. }
  2217. def = components[key];
  2218. if (isPlainObject(def)) {
  2219. components[key] = Vue.extend(def);
  2220. }
  2221. }
  2222. }
  2223. }
  2224. /**
  2225. * Ensure all props option syntax are normalized into the
  2226. * Object-based format.
  2227. *
  2228. * @param {Object} options
  2229. */
  2230. function guardProps(options) {
  2231. var props = options.props;
  2232. if (!props) return;
  2233. var res = {};
  2234. var i = void 0,
  2235. val = void 0,
  2236. name = void 0;
  2237. if (isArray(props)) {
  2238. i = props.length;
  2239. while (i--) {
  2240. val = props[i];
  2241. if (typeof val === 'string') {
  2242. name = camelize(val);
  2243. res[name] = { type: null };
  2244. } else if (process.env.NODE_ENV !== 'production') {
  2245. warn('props must be strings when using array syntax.');
  2246. }
  2247. }
  2248. } else if (isPlainObject(props)) {
  2249. for (var key in props) {
  2250. val = props[key];
  2251. name = camelize(key);
  2252. res[name] = isPlainObject(val) ? val : { type: val };
  2253. }
  2254. }
  2255. options.props = res;
  2256. }
  2257. function guardDirectives(options) {
  2258. var dirs = options.directives;
  2259. if (dirs) {
  2260. for (var key in dirs) {
  2261. if (typeof dirs[key] === 'function') {
  2262. dirs[key] = { update: dirs[key] };
  2263. }
  2264. }
  2265. }
  2266. }
  2267. /**
  2268. * Merge two option objects into a new one.
  2269. * Core utility used in both instantiation and inheritance.
  2270. *
  2271. * @param {Object} parent
  2272. * @param {Object} child
  2273. * @param {Vue} [vm] - if vm is present, indicates this is
  2274. * an instantiation merge.
  2275. */
  2276. function mergeOptions(parent, child, vm) {
  2277. guardComponents(child);
  2278. guardProps(child);
  2279. guardDirectives(child);
  2280. if (process.env.NODE_ENV !== 'production') {
  2281. if (child.propsData && !vm) {
  2282. warn('propsData can only be used as an instantiation option.');
  2283. }
  2284. }
  2285. var options = {};
  2286. var key;
  2287. if (child.mixins) {
  2288. for (var i = 0, l = child.mixins.length; i < l; i++) {
  2289. parent = mergeOptions(parent, child.mixins[i], vm);
  2290. }
  2291. }
  2292. for (key in parent) {
  2293. mergeField(key);
  2294. }
  2295. for (key in child) {
  2296. if (!hasOwn(parent, key)) {
  2297. mergeField(key);
  2298. }
  2299. }
  2300. function mergeField(key) {
  2301. var strat = strats[key] || defaultStrat;
  2302. options[key] = strat(parent[key], child[key], vm, key);
  2303. }
  2304. return options;
  2305. }
  2306. /**
  2307. * Resolve an asset.
  2308. * This function is used because child instances need access
  2309. * to assets defined in its ancestor chain.
  2310. *
  2311. * @param {Object} options
  2312. * @param {String} type
  2313. * @param {String} id
  2314. * @param {Boolean} warnMissing
  2315. * @return {Object|Function}
  2316. */
  2317. function resolveAsset(options, type, id, warnMissing) {
  2318. /* istanbul ignore if */
  2319. if (typeof id !== 'string') {
  2320. return;
  2321. }
  2322. var assets = options[type];
  2323. var camelizedId;
  2324. var res = assets[id] ||
  2325. // camelCase ID
  2326. assets[camelizedId = camelize(id)] ||
  2327. // Pascal Case ID
  2328. assets[camelizedId.charAt(0).toUpperCase() + camelizedId.slice(1)];
  2329. if (process.env.NODE_ENV !== 'production' && warnMissing && !res) {
  2330. warn('Failed to resolve ' + type.slice(0, -1) + ': ' + id, options);
  2331. }
  2332. return res;
  2333. }
  2334. function validateProp(vm, key, propsData) {
  2335. if (!propsData) return;
  2336. var prop = vm.$options.props[key];
  2337. var absent = hasOwn(propsData, key);
  2338. var value = propsData[key];
  2339. // check default value
  2340. if (value === undefined) {
  2341. value = getPropDefaultValue(vm, prop, key);
  2342. // since the default value is a fresh copy,
  2343. // make sure to observe it.
  2344. observerState.shouldConvert = true;
  2345. observe(value);
  2346. observerState.shouldConvert = false;
  2347. }
  2348. if (process.env.NODE_ENV !== 'production') {
  2349. assertProp(prop, key, value, vm, absent);
  2350. }
  2351. return value;
  2352. }
  2353. /**
  2354. * Get the default value of a prop.
  2355. *
  2356. * @param {Vue} vm
  2357. * @param {Object} prop
  2358. * @return {*}
  2359. */
  2360. function getPropDefaultValue(vm, prop, name) {
  2361. // no default, return undefined
  2362. if (!hasOwn(prop, 'default')) {
  2363. // absent boolean value defaults to false
  2364. return prop.type === Boolean ? false : undefined;
  2365. }
  2366. var def = prop.default;
  2367. // warn against non-factory defaults for Object & Array
  2368. if (isObject(def)) {
  2369. 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);
  2370. }
  2371. // call factory function for non-Function types
  2372. return typeof def === 'function' && prop.type !== Function ? def.call(vm) : def;
  2373. }
  2374. /**
  2375. * Assert whether a prop is valid.
  2376. *
  2377. * @param {Object} prop
  2378. * @param {String} name
  2379. * @param {*} value
  2380. * @param {Vue} vm
  2381. * @param {Boolean} absent
  2382. */
  2383. function assertProp(prop, name, value, vm, absent) {
  2384. if (prop.required && absent) {
  2385. process.env.NODE_ENV !== 'production' && warn('Missing required prop: "' + name + '"', vm);
  2386. return false;
  2387. }
  2388. if (value == null) {
  2389. return true;
  2390. }
  2391. var type = prop.type;
  2392. var valid = !type;
  2393. var expectedTypes = [];
  2394. if (type) {
  2395. if (!isArray(type)) {
  2396. type = [type];
  2397. }
  2398. for (var i = 0; i < type.length && !valid; i++) {
  2399. var assertedType = assertType(value, type[i]);
  2400. expectedTypes.push(assertedType.expectedType);
  2401. valid = assertedType.valid;
  2402. }
  2403. }
  2404. if (!valid) {
  2405. if (process.env.NODE_ENV !== 'production') {
  2406. warn('Invalid prop: type check failed for prop "' + name + '".' + ' Expected ' + expectedTypes.map(formatType).join(', ') + ', got ' + formatValue(value) + '.', vm);
  2407. }
  2408. return false;
  2409. }
  2410. var validator = prop.validator;
  2411. if (validator) {
  2412. if (!validator(value)) {
  2413. process.env.NODE_ENV !== 'production' && warn('Invalid prop: custom validator check failed for prop "' + name + '".', vm);
  2414. return false;
  2415. }
  2416. }
  2417. return true;
  2418. }
  2419. /**
  2420. * Assert the type of a value
  2421. *
  2422. * @param {*} value
  2423. * @param {Function} type
  2424. * @return {Object}
  2425. */
  2426. function assertType(value, type) {
  2427. var valid;
  2428. var expectedType;
  2429. if (type === String) {
  2430. expectedType = 'string';
  2431. valid = typeof value === expectedType;
  2432. } else if (type === Number) {
  2433. expectedType = 'number';
  2434. valid = typeof value === expectedType;
  2435. } else if (type === Boolean) {
  2436. expectedType = 'boolean';
  2437. valid = typeof value === expectedType;
  2438. } else if (type === Function) {
  2439. expectedType = 'function';
  2440. valid = typeof value === expectedType;
  2441. } else if (type === Object) {
  2442. expectedType = 'object';
  2443. valid = isPlainObject(value);
  2444. } else if (type === Array) {
  2445. expectedType = 'array';
  2446. valid = isArray(value);
  2447. } else {
  2448. valid = value instanceof type;
  2449. }
  2450. return {
  2451. valid: valid,
  2452. expectedType: expectedType
  2453. };
  2454. }
  2455. /**
  2456. * Format type for output
  2457. *
  2458. * @param {String} type
  2459. * @return {String}
  2460. */
  2461. function formatType(type) {
  2462. return type ? type.charAt(0).toUpperCase() + type.slice(1) : 'custom type';
  2463. }
  2464. /**
  2465. * Format value
  2466. *
  2467. * @param {*} value
  2468. * @return {String}
  2469. */
  2470. function formatValue(val) {
  2471. return Object.prototype.toString.call(val).slice(8, -1);
  2472. }
  2473. // attributes that should be using props for binding
  2474. var mustUseProp = makeMap('value,selected,checked,muted');
  2475. var isEnumeratedAttr = makeMap('contenteditable,draggable,spellcheck');
  2476. 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');
  2477. var propsToAttrMap = {
  2478. acceptCharset: 'accept-charset',
  2479. className: 'class',
  2480. htmlFor: 'for',
  2481. httpEquiv: 'http-equiv'
  2482. };
  2483. function genClassForVnode(vnode) {
  2484. var data = vnode.data;
  2485. // Important: check if this is a component container node
  2486. // or a child component root node
  2487. var i = void 0;
  2488. if ((i = vnode.child) && (i = i._vnode.data)) {
  2489. data = mergeClassData(i, data);
  2490. }
  2491. if ((i = vnode.parent) && (i = i.data)) {
  2492. data = mergeClassData(data, i);
  2493. }
  2494. return genClassFromData(data);
  2495. }
  2496. function mergeClassData(child, parent) {
  2497. return {
  2498. staticClass: concat(child.staticClass, parent.staticClass),
  2499. class: child.class ? extend(child.class, parent.class) : parent.class
  2500. };
  2501. }
  2502. function genClassFromData(data) {
  2503. var dynamicClass = data.class;
  2504. var staticClass = data.staticClass;
  2505. if (staticClass || dynamicClass) {
  2506. return concat(staticClass, stringifyClass(dynamicClass));
  2507. }
  2508. }
  2509. function concat(a, b) {
  2510. return a ? b ? a + ' ' + b : a : b || '';
  2511. }
  2512. function stringifyClass(value) {
  2513. if (!value) {
  2514. return '';
  2515. }
  2516. if (typeof value === 'string') {
  2517. return value;
  2518. }
  2519. if (isArray(value)) {
  2520. var res = '';
  2521. for (var i = 0, l = value.length; i < l; i++) {
  2522. if (value[i]) res += stringifyClass(value[i]) + ' ';
  2523. }
  2524. return res.slice(0, -1);
  2525. }
  2526. if (isObject(value)) {
  2527. var _res = '';
  2528. for (var key in value) {
  2529. if (value[key]) _res += key + ' ';
  2530. }
  2531. return _res.slice(0, -1);
  2532. }
  2533. }
  2534. 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');
  2535. var isUnaryTag = makeMap('area,base,br,col,embed,frame,hr,img,input,isindex,keygen,' + 'link,meta,param,source,track,wbr', true);
  2536. // Elements that you can, intentionally, leave open
  2537. // (and which close themselves)
  2538. var canBeLeftOpenTag = makeMap('colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr,source', true);
  2539. // HTML5 tags https://html.spec.whatwg.org/multipage/indices.html#elements-3
  2540. // Phrasing Content https://html.spec.whatwg.org/multipage/dom.html#phrasing-content
  2541. 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);
  2542. // this map covers namespace elements that can appear as template root nodes
  2543. var isSVG = makeMap('svg,g,defs,symbol,use,image,text,circle,ellipse,' + 'line,path,polygon,polyline,rect', true);
  2544. var UA = inBrowser && window.navigator.userAgent.toLowerCase();
  2545. var isIE9 = UA && UA.indexOf('msie 9.0') > 0;
  2546. var isAndroid = UA && UA.indexOf('android') > 0;
  2547. function renderAttrs(node) {
  2548. if (node.data.attrs || node.data.props || node.data.staticAttrs) {
  2549. return serialize(node.data.staticAttrs) + serialize(node.data.attrs) + serialize(node.data.props, true);
  2550. }
  2551. }
  2552. function serialize(attrs, asProps) {
  2553. var res = '';
  2554. if (!attrs) {
  2555. return res;
  2556. }
  2557. for (var key in attrs) {
  2558. if (key === 'style') {
  2559. // leave it to the style module
  2560. continue;
  2561. }
  2562. if (asProps) {
  2563. key = propsToAttrMap[key] || key.toLowerCase();
  2564. }
  2565. if (attrs[key] != null) {
  2566. if (isBooleanAttr(key)) {
  2567. res += ' ' + key + '="' + key + '"';
  2568. } else if (isEnumeratedAttr(key)) {
  2569. res += ' ' + key + '="true"';
  2570. } else {
  2571. res += ' ' + key + '="' + attrs[key] + '"';
  2572. }
  2573. }
  2574. }
  2575. return res;
  2576. }
  2577. function renderClass(node) {
  2578. if (node.data.class || node.data.staticClass) {
  2579. return ' class="' + genClassForVnode(node) + '"';
  2580. }
  2581. }
  2582. function renderStyle(node) {
  2583. var staticStyle = node.data.staticAttrs && node.data.staticAttrs.style;
  2584. if (node.data.style || staticStyle) {
  2585. var styles = node.data.style;
  2586. var res = ' style="';
  2587. for (var key in styles) {
  2588. res += hyphenate(key) + ':' + styles[key] + ';';
  2589. }
  2590. return res + (staticStyle || '') + '"';
  2591. }
  2592. }
  2593. function show(node, dir) {
  2594. if (!dir.value) {
  2595. (node.data.style || (node.data.style = {})).display = 'none';
  2596. }
  2597. }
  2598. var modules = [renderAttrs, renderClass, renderStyle];
  2599. var baseDirectives = {
  2600. show: show
  2601. };
  2602. function publicCreateRenderer() {
  2603. var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
  2604. // user can provide server-side implementations for custom directives
  2605. // when creating the renderer.
  2606. var directives = Object.assign(baseDirectives, options.directives);
  2607. return createRenderer({
  2608. isUnaryTag: isUnaryTag,
  2609. modules: modules,
  2610. directives: directives
  2611. });
  2612. }
  2613. module.exports = publicCreateRenderer;