vueonrails 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +70 -0
  3. data/app/controllers/vue_controller.rb +2 -0
  4. data/app/helpers/syntax_helper.rb +28 -0
  5. data/app/views/vue/index.html.erb +1 -0
  6. data/config/routes.rb +5 -0
  7. data/lib/generators/generator_templates/packs/index.css +4 -0
  8. data/lib/generators/generator_templates/packs/index.js +30 -0
  9. data/lib/generators/generator_templates/packs/index.vue +13 -0
  10. data/lib/generators/generator_templates/packs/pack.js.erb +18 -0
  11. data/lib/generators/generator_templates/sfc/single-file-component.vue +45 -0
  12. data/lib/generators/generator_templates/tests/unit.test.js.erb +17 -0
  13. data/lib/generators/generator_templates/turbolinks/turbolinks-pack.js.erb +23 -0
  14. data/lib/generators/options/click.rb +10 -0
  15. data/lib/generators/options/form.rb +19 -0
  16. data/lib/generators/options/list.rb +32 -0
  17. data/lib/generators/options/modal.rb +26 -0
  18. data/lib/generators/options/seperate.rb +5 -0
  19. data/lib/generators/options/single.rb +3 -0
  20. data/lib/generators/options/table.rb +10 -0
  21. data/lib/generators/options/test.rb +2 -0
  22. data/lib/generators/options/turbolinks-seperate.rb +5 -0
  23. data/lib/generators/options/turbolinks-single.rb +3 -0
  24. data/lib/generators/options/vuex.rb +10 -0
  25. data/lib/generators/vue/USAGE +17 -0
  26. data/lib/generators/vue/vue_generator.rb +60 -0
  27. data/lib/install/Procfile +2 -0
  28. data/lib/install/config/alias.js +9 -0
  29. data/lib/install/setup.rb +78 -0
  30. data/lib/install/spv.rb +20 -0
  31. data/lib/install/test.rb +46 -0
  32. data/lib/install/turbolinks.rb +3 -0
  33. data/lib/install/ui.rb +4 -0
  34. data/lib/install/vuex.rb +12 -0
  35. data/lib/tasks/assets.rake +12 -0
  36. data/lib/tasks/info.rake +21 -0
  37. data/lib/tasks/vue.rake +27 -0
  38. data/lib/vueonrails.rb +13 -0
  39. data/lib/vueonrails/post_message.rb +4 -0
  40. data/lib/vueonrails/version.rb +3 -0
  41. data/vendor/assets/javascripts/axios.js +1545 -0
  42. data/vendor/assets/javascripts/axios.map +1 -0
  43. data/vendor/assets/javascripts/element-ui.js +12 -0
  44. data/vendor/assets/javascripts/vue-resource.js +1531 -0
  45. data/vendor/assets/javascripts/vue-router.js +2709 -0
  46. data/vendor/assets/javascripts/vue-router2.js +2284 -0
  47. data/vendor/assets/javascripts/vue-validator.js +910 -0
  48. data/vendor/assets/javascripts/vue-validator2.js +2615 -0
  49. data/vendor/assets/javascripts/vue-validator3.js +2054 -0
  50. data/vendor/assets/javascripts/vue.js +10237 -0
  51. data/vendor/assets/javascripts/vue.min.js +9 -0
  52. data/vendor/assets/javascripts/vue2.js +8568 -0
  53. data/vendor/assets/javascripts/vue2.min.js +8 -0
  54. data/vendor/assets/javascripts/vueonrails.js +39 -0
  55. data/vendor/assets/javascripts/vuex.js +722 -0
  56. data/vendor/assets/javascripts/vuex2.js +805 -0
  57. data/vendor/assets/stylesheets/element-ui.css +1 -0
  58. metadata +128 -0
@@ -0,0 +1,2284 @@
1
+ /**
2
+ * vue-router v2.2.1
3
+ * (c) 2017 Evan You
4
+ * @license MIT
5
+ */
6
+ (function (global, factory) {
7
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
8
+ typeof define === 'function' && define.amd ? define(factory) :
9
+ (global.VueRouter = factory());
10
+ }(this, (function () { 'use strict';
11
+
12
+ /* */
13
+
14
+ function assert (condition, message) {
15
+ if (!condition) {
16
+ throw new Error(("[vue-router] " + message))
17
+ }
18
+ }
19
+
20
+ function warn (condition, message) {
21
+ if (!condition) {
22
+ typeof console !== 'undefined' && console.warn(("[vue-router] " + message));
23
+ }
24
+ }
25
+
26
+ var View = {
27
+ name: 'router-view',
28
+ functional: true,
29
+ props: {
30
+ name: {
31
+ type: String,
32
+ default: 'default'
33
+ }
34
+ },
35
+ render: function render (h, ref) {
36
+ var props = ref.props;
37
+ var children = ref.children;
38
+ var parent = ref.parent;
39
+ var data = ref.data;
40
+
41
+ data.routerView = true;
42
+
43
+ var name = props.name;
44
+ var route = parent.$route;
45
+ var cache = parent._routerViewCache || (parent._routerViewCache = {});
46
+
47
+ // determine current view depth, also check to see if the tree
48
+ // has been toggled inactive but kept-alive.
49
+ var depth = 0;
50
+ var inactive = false;
51
+ while (parent) {
52
+ if (parent.$vnode && parent.$vnode.data.routerView) {
53
+ depth++;
54
+ }
55
+ if (parent._inactive) {
56
+ inactive = true;
57
+ }
58
+ parent = parent.$parent;
59
+ }
60
+ data.routerViewDepth = depth;
61
+
62
+ // render previous view if the tree is inactive and kept-alive
63
+ if (inactive) {
64
+ return h(cache[name], data, children)
65
+ }
66
+
67
+ var matched = route.matched[depth];
68
+ // render empty node if no matched route
69
+ if (!matched) {
70
+ cache[name] = null;
71
+ return h()
72
+ }
73
+
74
+ var component = cache[name] = matched.components[name];
75
+
76
+ // inject instance registration hooks
77
+ var hooks = data.hook || (data.hook = {});
78
+ hooks.init = function (vnode) {
79
+ matched.instances[name] = vnode.child;
80
+ };
81
+ hooks.prepatch = function (oldVnode, vnode) {
82
+ matched.instances[name] = vnode.child;
83
+ };
84
+ hooks.destroy = function (vnode) {
85
+ if (matched.instances[name] === vnode.child) {
86
+ matched.instances[name] = undefined;
87
+ }
88
+ };
89
+
90
+ // resolve props
91
+ data.props = resolveProps(route, matched.props && matched.props[name]);
92
+
93
+ return h(component, data, children)
94
+ }
95
+ };
96
+
97
+ function resolveProps (route, config) {
98
+ switch (typeof config) {
99
+ case 'undefined':
100
+ return
101
+ case 'object':
102
+ return config
103
+ case 'function':
104
+ return config(route)
105
+ case 'boolean':
106
+ return config ? route.params : undefined
107
+ default:
108
+ warn(false, ("props in \"" + (route.path) + "\" is a " + (typeof config) + ", expecting an object, function or boolean."));
109
+ }
110
+ }
111
+
112
+ /* */
113
+
114
+ var encodeReserveRE = /[!'()*]/g;
115
+ var encodeReserveReplacer = function (c) { return '%' + c.charCodeAt(0).toString(16); };
116
+ var commaRE = /%2C/g;
117
+
118
+ // fixed encodeURIComponent which is more comformant to RFC3986:
119
+ // - escapes [!'()*]
120
+ // - preserve commas
121
+ var encode = function (str) { return encodeURIComponent(str)
122
+ .replace(encodeReserveRE, encodeReserveReplacer)
123
+ .replace(commaRE, ','); };
124
+
125
+ var decode = decodeURIComponent;
126
+
127
+ function resolveQuery (
128
+ query,
129
+ extraQuery
130
+ ) {
131
+ if ( extraQuery === void 0 ) extraQuery = {};
132
+
133
+ if (query) {
134
+ var parsedQuery;
135
+ try {
136
+ parsedQuery = parseQuery(query);
137
+ } catch (e) {
138
+ "development" !== 'production' && warn(false, e.message);
139
+ parsedQuery = {};
140
+ }
141
+ for (var key in extraQuery) {
142
+ parsedQuery[key] = extraQuery[key];
143
+ }
144
+ return parsedQuery
145
+ } else {
146
+ return extraQuery
147
+ }
148
+ }
149
+
150
+ function parseQuery (query) {
151
+ var res = {};
152
+
153
+ query = query.trim().replace(/^(\?|#|&)/, '');
154
+
155
+ if (!query) {
156
+ return res
157
+ }
158
+
159
+ query.split('&').forEach(function (param) {
160
+ var parts = param.replace(/\+/g, ' ').split('=');
161
+ var key = decode(parts.shift());
162
+ var val = parts.length > 0
163
+ ? decode(parts.join('='))
164
+ : null;
165
+
166
+ if (res[key] === undefined) {
167
+ res[key] = val;
168
+ } else if (Array.isArray(res[key])) {
169
+ res[key].push(val);
170
+ } else {
171
+ res[key] = [res[key], val];
172
+ }
173
+ });
174
+
175
+ return res
176
+ }
177
+
178
+ function stringifyQuery (obj) {
179
+ var res = obj ? Object.keys(obj).map(function (key) {
180
+ var val = obj[key];
181
+
182
+ if (val === undefined) {
183
+ return ''
184
+ }
185
+
186
+ if (val === null) {
187
+ return encode(key)
188
+ }
189
+
190
+ if (Array.isArray(val)) {
191
+ var result = [];
192
+ val.slice().forEach(function (val2) {
193
+ if (val2 === undefined) {
194
+ return
195
+ }
196
+ if (val2 === null) {
197
+ result.push(encode(key));
198
+ } else {
199
+ result.push(encode(key) + '=' + encode(val2));
200
+ }
201
+ });
202
+ return result.join('&')
203
+ }
204
+
205
+ return encode(key) + '=' + encode(val)
206
+ }).filter(function (x) { return x.length > 0; }).join('&') : null;
207
+ return res ? ("?" + res) : ''
208
+ }
209
+
210
+ /* */
211
+
212
+ var trailingSlashRE = /\/?$/;
213
+
214
+ function createRoute (
215
+ record,
216
+ location,
217
+ redirectedFrom
218
+ ) {
219
+ var route = {
220
+ name: location.name || (record && record.name),
221
+ meta: (record && record.meta) || {},
222
+ path: location.path || '/',
223
+ hash: location.hash || '',
224
+ query: location.query || {},
225
+ params: location.params || {},
226
+ fullPath: getFullPath(location),
227
+ matched: record ? formatMatch(record) : []
228
+ };
229
+ if (redirectedFrom) {
230
+ route.redirectedFrom = getFullPath(redirectedFrom);
231
+ }
232
+ return Object.freeze(route)
233
+ }
234
+
235
+ // the starting route that represents the initial state
236
+ var START = createRoute(null, {
237
+ path: '/'
238
+ });
239
+
240
+ function formatMatch (record) {
241
+ var res = [];
242
+ while (record) {
243
+ res.unshift(record);
244
+ record = record.parent;
245
+ }
246
+ return res
247
+ }
248
+
249
+ function getFullPath (ref) {
250
+ var path = ref.path;
251
+ var query = ref.query; if ( query === void 0 ) query = {};
252
+ var hash = ref.hash; if ( hash === void 0 ) hash = '';
253
+
254
+ return (path || '/') + stringifyQuery(query) + hash
255
+ }
256
+
257
+ function isSameRoute (a, b) {
258
+ if (b === START) {
259
+ return a === b
260
+ } else if (!b) {
261
+ return false
262
+ } else if (a.path && b.path) {
263
+ return (
264
+ a.path.replace(trailingSlashRE, '') === b.path.replace(trailingSlashRE, '') &&
265
+ a.hash === b.hash &&
266
+ isObjectEqual(a.query, b.query)
267
+ )
268
+ } else if (a.name && b.name) {
269
+ return (
270
+ a.name === b.name &&
271
+ a.hash === b.hash &&
272
+ isObjectEqual(a.query, b.query) &&
273
+ isObjectEqual(a.params, b.params)
274
+ )
275
+ } else {
276
+ return false
277
+ }
278
+ }
279
+
280
+ function isObjectEqual (a, b) {
281
+ if ( a === void 0 ) a = {};
282
+ if ( b === void 0 ) b = {};
283
+
284
+ var aKeys = Object.keys(a);
285
+ var bKeys = Object.keys(b);
286
+ if (aKeys.length !== bKeys.length) {
287
+ return false
288
+ }
289
+ return aKeys.every(function (key) { return String(a[key]) === String(b[key]); })
290
+ }
291
+
292
+ function isIncludedRoute (current, target) {
293
+ return (
294
+ current.path.replace(trailingSlashRE, '/').indexOf(
295
+ target.path.replace(trailingSlashRE, '/')
296
+ ) === 0 &&
297
+ (!target.hash || current.hash === target.hash) &&
298
+ queryIncludes(current.query, target.query)
299
+ )
300
+ }
301
+
302
+ function queryIncludes (current, target) {
303
+ for (var key in target) {
304
+ if (!(key in current)) {
305
+ return false
306
+ }
307
+ }
308
+ return true
309
+ }
310
+
311
+ /* */
312
+
313
+ // work around weird flow bug
314
+ var toTypes = [String, Object];
315
+ var eventTypes = [String, Array];
316
+
317
+ var Link = {
318
+ name: 'router-link',
319
+ props: {
320
+ to: {
321
+ type: toTypes,
322
+ required: true
323
+ },
324
+ tag: {
325
+ type: String,
326
+ default: 'a'
327
+ },
328
+ exact: Boolean,
329
+ append: Boolean,
330
+ replace: Boolean,
331
+ activeClass: String,
332
+ event: {
333
+ type: eventTypes,
334
+ default: 'click'
335
+ }
336
+ },
337
+ render: function render (h) {
338
+ var this$1 = this;
339
+
340
+ var router = this.$router;
341
+ var current = this.$route;
342
+ var ref = router.resolve(this.to, current, this.append);
343
+ var location = ref.location;
344
+ var route = ref.route;
345
+ var href = ref.href;
346
+ var classes = {};
347
+ var activeClass = this.activeClass || router.options.linkActiveClass || 'router-link-active';
348
+ var compareTarget = location.path ? createRoute(null, location) : route;
349
+ classes[activeClass] = this.exact
350
+ ? isSameRoute(current, compareTarget)
351
+ : isIncludedRoute(current, compareTarget);
352
+
353
+ var handler = function (e) {
354
+ if (guardEvent(e)) {
355
+ if (this$1.replace) {
356
+ router.replace(location);
357
+ } else {
358
+ router.push(location);
359
+ }
360
+ }
361
+ };
362
+
363
+ var on = { click: guardEvent };
364
+ if (Array.isArray(this.event)) {
365
+ this.event.forEach(function (e) { on[e] = handler; });
366
+ } else {
367
+ on[this.event] = handler;
368
+ }
369
+
370
+ var data = {
371
+ class: classes
372
+ };
373
+
374
+ if (this.tag === 'a') {
375
+ data.on = on;
376
+ data.attrs = { href: href };
377
+ } else {
378
+ // find the first <a> child and apply listener and href
379
+ var a = findAnchor(this.$slots.default);
380
+ if (a) {
381
+ // in case the <a> is a static node
382
+ a.isStatic = false;
383
+ var extend = _Vue.util.extend;
384
+ var aData = a.data = extend({}, a.data);
385
+ aData.on = on;
386
+ var aAttrs = a.data.attrs = extend({}, a.data.attrs);
387
+ aAttrs.href = href;
388
+ } else {
389
+ // doesn't have <a> child, apply listener to self
390
+ data.on = on;
391
+ }
392
+ }
393
+
394
+ return h(this.tag, data, this.$slots.default)
395
+ }
396
+ };
397
+
398
+ function guardEvent (e) {
399
+ // don't redirect with control keys
400
+ if (e.metaKey || e.ctrlKey || e.shiftKey) { return }
401
+ // don't redirect when preventDefault called
402
+ if (e.defaultPrevented) { return }
403
+ // don't redirect on right click
404
+ if (e.button !== undefined && e.button !== 0) { return }
405
+ // don't redirect if `target="_blank"`
406
+ if (e.target && e.target.getAttribute) {
407
+ var target = e.target.getAttribute('target');
408
+ if (/\b_blank\b/i.test(target)) { return }
409
+ }
410
+ // this may be a Weex event which doesn't have this method
411
+ if (e.preventDefault) {
412
+ e.preventDefault();
413
+ }
414
+ return true
415
+ }
416
+
417
+ function findAnchor (children) {
418
+ if (children) {
419
+ var child;
420
+ for (var i = 0; i < children.length; i++) {
421
+ child = children[i];
422
+ if (child.tag === 'a') {
423
+ return child
424
+ }
425
+ if (child.children && (child = findAnchor(child.children))) {
426
+ return child
427
+ }
428
+ }
429
+ }
430
+ }
431
+
432
+ var _Vue;
433
+
434
+ function install (Vue) {
435
+ if (install.installed) { return }
436
+ install.installed = true;
437
+
438
+ _Vue = Vue;
439
+
440
+ Object.defineProperty(Vue.prototype, '$router', {
441
+ get: function get () { return this.$root._router }
442
+ });
443
+
444
+ Object.defineProperty(Vue.prototype, '$route', {
445
+ get: function get () { return this.$root._route }
446
+ });
447
+
448
+ Vue.mixin({
449
+ beforeCreate: function beforeCreate () {
450
+ if (this.$options.router) {
451
+ this._router = this.$options.router;
452
+ this._router.init(this);
453
+ Vue.util.defineReactive(this, '_route', this._router.history.current);
454
+ }
455
+ }
456
+ });
457
+
458
+ Vue.component('router-view', View);
459
+ Vue.component('router-link', Link);
460
+
461
+ var strats = Vue.config.optionMergeStrategies;
462
+ // use the same hook merging strategy for route hooks
463
+ strats.beforeRouteEnter = strats.beforeRouteLeave = strats.created;
464
+ }
465
+
466
+ /* */
467
+
468
+ var inBrowser = typeof window !== 'undefined';
469
+
470
+ /* */
471
+
472
+ function resolvePath (
473
+ relative,
474
+ base,
475
+ append
476
+ ) {
477
+ if (relative.charAt(0) === '/') {
478
+ return relative
479
+ }
480
+
481
+ if (relative.charAt(0) === '?' || relative.charAt(0) === '#') {
482
+ return base + relative
483
+ }
484
+
485
+ var stack = base.split('/');
486
+
487
+ // remove trailing segment if:
488
+ // - not appending
489
+ // - appending to trailing slash (last segment is empty)
490
+ if (!append || !stack[stack.length - 1]) {
491
+ stack.pop();
492
+ }
493
+
494
+ // resolve relative path
495
+ var segments = relative.replace(/^\//, '').split('/');
496
+ for (var i = 0; i < segments.length; i++) {
497
+ var segment = segments[i];
498
+ if (segment === '.') {
499
+ continue
500
+ } else if (segment === '..') {
501
+ stack.pop();
502
+ } else {
503
+ stack.push(segment);
504
+ }
505
+ }
506
+
507
+ // ensure leading slash
508
+ if (stack[0] !== '') {
509
+ stack.unshift('');
510
+ }
511
+
512
+ return stack.join('/')
513
+ }
514
+
515
+ function parsePath (path) {
516
+ var hash = '';
517
+ var query = '';
518
+
519
+ var hashIndex = path.indexOf('#');
520
+ if (hashIndex >= 0) {
521
+ hash = path.slice(hashIndex);
522
+ path = path.slice(0, hashIndex);
523
+ }
524
+
525
+ var queryIndex = path.indexOf('?');
526
+ if (queryIndex >= 0) {
527
+ query = path.slice(queryIndex + 1);
528
+ path = path.slice(0, queryIndex);
529
+ }
530
+
531
+ return {
532
+ path: path,
533
+ query: query,
534
+ hash: hash
535
+ }
536
+ }
537
+
538
+ function cleanPath (path) {
539
+ return path.replace(/\/\//g, '/')
540
+ }
541
+
542
+ /* */
543
+
544
+ function createRouteMap (
545
+ routes,
546
+ oldPathMap,
547
+ oldNameMap
548
+ ) {
549
+ var pathMap = oldPathMap || Object.create(null);
550
+ var nameMap = oldNameMap || Object.create(null);
551
+
552
+ routes.forEach(function (route) {
553
+ addRouteRecord(pathMap, nameMap, route);
554
+ });
555
+
556
+ return {
557
+ pathMap: pathMap,
558
+ nameMap: nameMap
559
+ }
560
+ }
561
+
562
+ function addRouteRecord (
563
+ pathMap,
564
+ nameMap,
565
+ route,
566
+ parent,
567
+ matchAs
568
+ ) {
569
+ var path = route.path;
570
+ var name = route.name;
571
+ {
572
+ assert(path != null, "\"path\" is required in a route configuration.");
573
+ assert(
574
+ typeof route.component !== 'string',
575
+ "route config \"component\" for path: " + (String(path || name)) + " cannot be a " +
576
+ "string id. Use an actual component instead."
577
+ );
578
+ }
579
+
580
+ var record = {
581
+ path: normalizePath(path, parent),
582
+ components: route.components || { default: route.component },
583
+ instances: {},
584
+ name: name,
585
+ parent: parent,
586
+ matchAs: matchAs,
587
+ redirect: route.redirect,
588
+ beforeEnter: route.beforeEnter,
589
+ meta: route.meta || {},
590
+ props: route.props == null
591
+ ? {}
592
+ : route.components
593
+ ? route.props
594
+ : { default: route.props }
595
+ };
596
+
597
+ if (route.children) {
598
+ // Warn if route is named and has a default child route.
599
+ // If users navigate to this route by name, the default child will
600
+ // not be rendered (GH Issue #629)
601
+ {
602
+ if (route.name && route.children.some(function (child) { return /^\/?$/.test(child.path); })) {
603
+ warn(
604
+ false,
605
+ "Named Route '" + (route.name) + "' has a default child route. " +
606
+ "When navigating to this named route (:to=\"{name: '" + (route.name) + "'\"), " +
607
+ "the default child route will not be rendered. Remove the name from " +
608
+ "this route and use the name of the default child route for named " +
609
+ "links instead."
610
+ );
611
+ }
612
+ }
613
+ route.children.forEach(function (child) {
614
+ var childMatchAs = matchAs
615
+ ? cleanPath((matchAs + "/" + (child.path)))
616
+ : undefined;
617
+ addRouteRecord(pathMap, nameMap, child, record, childMatchAs);
618
+ });
619
+ }
620
+
621
+ if (route.alias !== undefined) {
622
+ if (Array.isArray(route.alias)) {
623
+ route.alias.forEach(function (alias) {
624
+ var aliasRoute = {
625
+ path: alias,
626
+ children: route.children
627
+ };
628
+ addRouteRecord(pathMap, nameMap, aliasRoute, parent, record.path);
629
+ });
630
+ } else {
631
+ var aliasRoute = {
632
+ path: route.alias,
633
+ children: route.children
634
+ };
635
+ addRouteRecord(pathMap, nameMap, aliasRoute, parent, record.path);
636
+ }
637
+ }
638
+
639
+ if (!pathMap[record.path]) {
640
+ pathMap[record.path] = record;
641
+ }
642
+
643
+ if (name) {
644
+ if (!nameMap[name]) {
645
+ nameMap[name] = record;
646
+ } else if ("development" !== 'production' && !matchAs) {
647
+ warn(
648
+ false,
649
+ "Duplicate named routes definition: " +
650
+ "{ name: \"" + name + "\", path: \"" + (record.path) + "\" }"
651
+ );
652
+ }
653
+ }
654
+ }
655
+
656
+ function normalizePath (path, parent) {
657
+ path = path.replace(/\/$/, '');
658
+ if (path[0] === '/') { return path }
659
+ if (parent == null) { return path }
660
+ return cleanPath(((parent.path) + "/" + path))
661
+ }
662
+
663
+ var index$1 = Array.isArray || function (arr) {
664
+ return Object.prototype.toString.call(arr) == '[object Array]';
665
+ };
666
+
667
+ var isarray = index$1;
668
+
669
+ /**
670
+ * Expose `pathToRegexp`.
671
+ */
672
+ var index = pathToRegexp;
673
+ var parse_1 = parse;
674
+ var compile_1 = compile;
675
+ var tokensToFunction_1 = tokensToFunction;
676
+ var tokensToRegExp_1 = tokensToRegExp;
677
+
678
+ /**
679
+ * The main path matching regexp utility.
680
+ *
681
+ * @type {RegExp}
682
+ */
683
+ var PATH_REGEXP = new RegExp([
684
+ // Match escaped characters that would otherwise appear in future matches.
685
+ // This allows the user to escape special characters that won't transform.
686
+ '(\\\\.)',
687
+ // Match Express-style parameters and un-named parameters with a prefix
688
+ // and optional suffixes. Matches appear as:
689
+ //
690
+ // "/:test(\\d+)?" => ["/", "test", "\d+", undefined, "?", undefined]
691
+ // "/route(\\d+)" => [undefined, undefined, undefined, "\d+", undefined, undefined]
692
+ // "/*" => ["/", undefined, undefined, undefined, undefined, "*"]
693
+ '([\\/.])?(?:(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?|(\\*))'
694
+ ].join('|'), 'g');
695
+
696
+ /**
697
+ * Parse a string for the raw tokens.
698
+ *
699
+ * @param {string} str
700
+ * @param {Object=} options
701
+ * @return {!Array}
702
+ */
703
+ function parse (str, options) {
704
+ var tokens = [];
705
+ var key = 0;
706
+ var index = 0;
707
+ var path = '';
708
+ var defaultDelimiter = options && options.delimiter || '/';
709
+ var res;
710
+
711
+ while ((res = PATH_REGEXP.exec(str)) != null) {
712
+ var m = res[0];
713
+ var escaped = res[1];
714
+ var offset = res.index;
715
+ path += str.slice(index, offset);
716
+ index = offset + m.length;
717
+
718
+ // Ignore already escaped sequences.
719
+ if (escaped) {
720
+ path += escaped[1];
721
+ continue
722
+ }
723
+
724
+ var next = str[index];
725
+ var prefix = res[2];
726
+ var name = res[3];
727
+ var capture = res[4];
728
+ var group = res[5];
729
+ var modifier = res[6];
730
+ var asterisk = res[7];
731
+
732
+ // Push the current path onto the tokens.
733
+ if (path) {
734
+ tokens.push(path);
735
+ path = '';
736
+ }
737
+
738
+ var partial = prefix != null && next != null && next !== prefix;
739
+ var repeat = modifier === '+' || modifier === '*';
740
+ var optional = modifier === '?' || modifier === '*';
741
+ var delimiter = res[2] || defaultDelimiter;
742
+ var pattern = capture || group;
743
+
744
+ tokens.push({
745
+ name: name || key++,
746
+ prefix: prefix || '',
747
+ delimiter: delimiter,
748
+ optional: optional,
749
+ repeat: repeat,
750
+ partial: partial,
751
+ asterisk: !!asterisk,
752
+ pattern: pattern ? escapeGroup(pattern) : (asterisk ? '.*' : '[^' + escapeString(delimiter) + ']+?')
753
+ });
754
+ }
755
+
756
+ // Match any characters still remaining.
757
+ if (index < str.length) {
758
+ path += str.substr(index);
759
+ }
760
+
761
+ // If the path exists, push it onto the end.
762
+ if (path) {
763
+ tokens.push(path);
764
+ }
765
+
766
+ return tokens
767
+ }
768
+
769
+ /**
770
+ * Compile a string to a template function for the path.
771
+ *
772
+ * @param {string} str
773
+ * @param {Object=} options
774
+ * @return {!function(Object=, Object=)}
775
+ */
776
+ function compile (str, options) {
777
+ return tokensToFunction(parse(str, options))
778
+ }
779
+
780
+ /**
781
+ * Prettier encoding of URI path segments.
782
+ *
783
+ * @param {string}
784
+ * @return {string}
785
+ */
786
+ function encodeURIComponentPretty (str) {
787
+ return encodeURI(str).replace(/[\/?#]/g, function (c) {
788
+ return '%' + c.charCodeAt(0).toString(16).toUpperCase()
789
+ })
790
+ }
791
+
792
+ /**
793
+ * Encode the asterisk parameter. Similar to `pretty`, but allows slashes.
794
+ *
795
+ * @param {string}
796
+ * @return {string}
797
+ */
798
+ function encodeAsterisk (str) {
799
+ return encodeURI(str).replace(/[?#]/g, function (c) {
800
+ return '%' + c.charCodeAt(0).toString(16).toUpperCase()
801
+ })
802
+ }
803
+
804
+ /**
805
+ * Expose a method for transforming tokens into the path function.
806
+ */
807
+ function tokensToFunction (tokens) {
808
+ // Compile all the tokens into regexps.
809
+ var matches = new Array(tokens.length);
810
+
811
+ // Compile all the patterns before compilation.
812
+ for (var i = 0; i < tokens.length; i++) {
813
+ if (typeof tokens[i] === 'object') {
814
+ matches[i] = new RegExp('^(?:' + tokens[i].pattern + ')$');
815
+ }
816
+ }
817
+
818
+ return function (obj, opts) {
819
+ var path = '';
820
+ var data = obj || {};
821
+ var options = opts || {};
822
+ var encode = options.pretty ? encodeURIComponentPretty : encodeURIComponent;
823
+
824
+ for (var i = 0; i < tokens.length; i++) {
825
+ var token = tokens[i];
826
+
827
+ if (typeof token === 'string') {
828
+ path += token;
829
+
830
+ continue
831
+ }
832
+
833
+ var value = data[token.name];
834
+ var segment;
835
+
836
+ if (value == null) {
837
+ if (token.optional) {
838
+ // Prepend partial segment prefixes.
839
+ if (token.partial) {
840
+ path += token.prefix;
841
+ }
842
+
843
+ continue
844
+ } else {
845
+ throw new TypeError('Expected "' + token.name + '" to be defined')
846
+ }
847
+ }
848
+
849
+ if (isarray(value)) {
850
+ if (!token.repeat) {
851
+ throw new TypeError('Expected "' + token.name + '" to not repeat, but received `' + JSON.stringify(value) + '`')
852
+ }
853
+
854
+ if (value.length === 0) {
855
+ if (token.optional) {
856
+ continue
857
+ } else {
858
+ throw new TypeError('Expected "' + token.name + '" to not be empty')
859
+ }
860
+ }
861
+
862
+ for (var j = 0; j < value.length; j++) {
863
+ segment = encode(value[j]);
864
+
865
+ if (!matches[i].test(segment)) {
866
+ throw new TypeError('Expected all "' + token.name + '" to match "' + token.pattern + '", but received `' + JSON.stringify(segment) + '`')
867
+ }
868
+
869
+ path += (j === 0 ? token.prefix : token.delimiter) + segment;
870
+ }
871
+
872
+ continue
873
+ }
874
+
875
+ segment = token.asterisk ? encodeAsterisk(value) : encode(value);
876
+
877
+ if (!matches[i].test(segment)) {
878
+ throw new TypeError('Expected "' + token.name + '" to match "' + token.pattern + '", but received "' + segment + '"')
879
+ }
880
+
881
+ path += token.prefix + segment;
882
+ }
883
+
884
+ return path
885
+ }
886
+ }
887
+
888
+ /**
889
+ * Escape a regular expression string.
890
+ *
891
+ * @param {string} str
892
+ * @return {string}
893
+ */
894
+ function escapeString (str) {
895
+ return str.replace(/([.+*?=^!:${}()[\]|\/\\])/g, '\\$1')
896
+ }
897
+
898
+ /**
899
+ * Escape the capturing group by escaping special characters and meaning.
900
+ *
901
+ * @param {string} group
902
+ * @return {string}
903
+ */
904
+ function escapeGroup (group) {
905
+ return group.replace(/([=!:$\/()])/g, '\\$1')
906
+ }
907
+
908
+ /**
909
+ * Attach the keys as a property of the regexp.
910
+ *
911
+ * @param {!RegExp} re
912
+ * @param {Array} keys
913
+ * @return {!RegExp}
914
+ */
915
+ function attachKeys (re, keys) {
916
+ re.keys = keys;
917
+ return re
918
+ }
919
+
920
+ /**
921
+ * Get the flags for a regexp from the options.
922
+ *
923
+ * @param {Object} options
924
+ * @return {string}
925
+ */
926
+ function flags (options) {
927
+ return options.sensitive ? '' : 'i'
928
+ }
929
+
930
+ /**
931
+ * Pull out keys from a regexp.
932
+ *
933
+ * @param {!RegExp} path
934
+ * @param {!Array} keys
935
+ * @return {!RegExp}
936
+ */
937
+ function regexpToRegexp (path, keys) {
938
+ // Use a negative lookahead to match only capturing groups.
939
+ var groups = path.source.match(/\((?!\?)/g);
940
+
941
+ if (groups) {
942
+ for (var i = 0; i < groups.length; i++) {
943
+ keys.push({
944
+ name: i,
945
+ prefix: null,
946
+ delimiter: null,
947
+ optional: false,
948
+ repeat: false,
949
+ partial: false,
950
+ asterisk: false,
951
+ pattern: null
952
+ });
953
+ }
954
+ }
955
+
956
+ return attachKeys(path, keys)
957
+ }
958
+
959
+ /**
960
+ * Transform an array into a regexp.
961
+ *
962
+ * @param {!Array} path
963
+ * @param {Array} keys
964
+ * @param {!Object} options
965
+ * @return {!RegExp}
966
+ */
967
+ function arrayToRegexp (path, keys, options) {
968
+ var parts = [];
969
+
970
+ for (var i = 0; i < path.length; i++) {
971
+ parts.push(pathToRegexp(path[i], keys, options).source);
972
+ }
973
+
974
+ var regexp = new RegExp('(?:' + parts.join('|') + ')', flags(options));
975
+
976
+ return attachKeys(regexp, keys)
977
+ }
978
+
979
+ /**
980
+ * Create a path regexp from string input.
981
+ *
982
+ * @param {string} path
983
+ * @param {!Array} keys
984
+ * @param {!Object} options
985
+ * @return {!RegExp}
986
+ */
987
+ function stringToRegexp (path, keys, options) {
988
+ return tokensToRegExp(parse(path, options), keys, options)
989
+ }
990
+
991
+ /**
992
+ * Expose a function for taking tokens and returning a RegExp.
993
+ *
994
+ * @param {!Array} tokens
995
+ * @param {(Array|Object)=} keys
996
+ * @param {Object=} options
997
+ * @return {!RegExp}
998
+ */
999
+ function tokensToRegExp (tokens, keys, options) {
1000
+ if (!isarray(keys)) {
1001
+ options = /** @type {!Object} */ (keys || options);
1002
+ keys = [];
1003
+ }
1004
+
1005
+ options = options || {};
1006
+
1007
+ var strict = options.strict;
1008
+ var end = options.end !== false;
1009
+ var route = '';
1010
+
1011
+ // Iterate over the tokens and create our regexp string.
1012
+ for (var i = 0; i < tokens.length; i++) {
1013
+ var token = tokens[i];
1014
+
1015
+ if (typeof token === 'string') {
1016
+ route += escapeString(token);
1017
+ } else {
1018
+ var prefix = escapeString(token.prefix);
1019
+ var capture = '(?:' + token.pattern + ')';
1020
+
1021
+ keys.push(token);
1022
+
1023
+ if (token.repeat) {
1024
+ capture += '(?:' + prefix + capture + ')*';
1025
+ }
1026
+
1027
+ if (token.optional) {
1028
+ if (!token.partial) {
1029
+ capture = '(?:' + prefix + '(' + capture + '))?';
1030
+ } else {
1031
+ capture = prefix + '(' + capture + ')?';
1032
+ }
1033
+ } else {
1034
+ capture = prefix + '(' + capture + ')';
1035
+ }
1036
+
1037
+ route += capture;
1038
+ }
1039
+ }
1040
+
1041
+ var delimiter = escapeString(options.delimiter || '/');
1042
+ var endsWithDelimiter = route.slice(-delimiter.length) === delimiter;
1043
+
1044
+ // In non-strict mode we allow a slash at the end of match. If the path to
1045
+ // match already ends with a slash, we remove it for consistency. The slash
1046
+ // is valid at the end of a path match, not in the middle. This is important
1047
+ // in non-ending mode, where "/test/" shouldn't match "/test//route".
1048
+ if (!strict) {
1049
+ route = (endsWithDelimiter ? route.slice(0, -delimiter.length) : route) + '(?:' + delimiter + '(?=$))?';
1050
+ }
1051
+
1052
+ if (end) {
1053
+ route += '$';
1054
+ } else {
1055
+ // In non-ending mode, we need the capturing groups to match as much as
1056
+ // possible by using a positive lookahead to the end or next path segment.
1057
+ route += strict && endsWithDelimiter ? '' : '(?=' + delimiter + '|$)';
1058
+ }
1059
+
1060
+ return attachKeys(new RegExp('^' + route, flags(options)), keys)
1061
+ }
1062
+
1063
+ /**
1064
+ * Normalize the given path string, returning a regular expression.
1065
+ *
1066
+ * An empty array can be passed in for the keys, which will hold the
1067
+ * placeholder key descriptions. For example, using `/user/:id`, `keys` will
1068
+ * contain `[{ name: 'id', delimiter: '/', optional: false, repeat: false }]`.
1069
+ *
1070
+ * @param {(string|RegExp|Array)} path
1071
+ * @param {(Array|Object)=} keys
1072
+ * @param {Object=} options
1073
+ * @return {!RegExp}
1074
+ */
1075
+ function pathToRegexp (path, keys, options) {
1076
+ if (!isarray(keys)) {
1077
+ options = /** @type {!Object} */ (keys || options);
1078
+ keys = [];
1079
+ }
1080
+
1081
+ options = options || {};
1082
+
1083
+ if (path instanceof RegExp) {
1084
+ return regexpToRegexp(path, /** @type {!Array} */ (keys))
1085
+ }
1086
+
1087
+ if (isarray(path)) {
1088
+ return arrayToRegexp(/** @type {!Array} */ (path), /** @type {!Array} */ (keys), options)
1089
+ }
1090
+
1091
+ return stringToRegexp(/** @type {string} */ (path), /** @type {!Array} */ (keys), options)
1092
+ }
1093
+
1094
+ index.parse = parse_1;
1095
+ index.compile = compile_1;
1096
+ index.tokensToFunction = tokensToFunction_1;
1097
+ index.tokensToRegExp = tokensToRegExp_1;
1098
+
1099
+ /* */
1100
+
1101
+ var regexpCache = Object.create(null);
1102
+
1103
+ function getRouteRegex (path) {
1104
+ var hit = regexpCache[path];
1105
+ var keys, regexp;
1106
+
1107
+ if (hit) {
1108
+ keys = hit.keys;
1109
+ regexp = hit.regexp;
1110
+ } else {
1111
+ keys = [];
1112
+ regexp = index(path, keys);
1113
+ regexpCache[path] = { keys: keys, regexp: regexp };
1114
+ }
1115
+
1116
+ return { keys: keys, regexp: regexp }
1117
+ }
1118
+
1119
+ var regexpCompileCache = Object.create(null);
1120
+
1121
+ function fillParams (
1122
+ path,
1123
+ params,
1124
+ routeMsg
1125
+ ) {
1126
+ try {
1127
+ var filler =
1128
+ regexpCompileCache[path] ||
1129
+ (regexpCompileCache[path] = index.compile(path));
1130
+ return filler(params || {}, { pretty: true })
1131
+ } catch (e) {
1132
+ {
1133
+ warn(false, ("missing param for " + routeMsg + ": " + (e.message)));
1134
+ }
1135
+ return ''
1136
+ }
1137
+ }
1138
+
1139
+ /* */
1140
+
1141
+ function normalizeLocation (
1142
+ raw,
1143
+ current,
1144
+ append
1145
+ ) {
1146
+ var next = typeof raw === 'string' ? { path: raw } : raw;
1147
+ // named target
1148
+ if (next.name || next._normalized) {
1149
+ return next
1150
+ }
1151
+
1152
+ // relative params
1153
+ if (!next.path && next.params && current) {
1154
+ next = assign({}, next);
1155
+ next._normalized = true;
1156
+ var params = assign(assign({}, current.params), next.params);
1157
+ if (current.name) {
1158
+ next.name = current.name;
1159
+ next.params = params;
1160
+ } else if (current.matched) {
1161
+ var rawPath = current.matched[current.matched.length - 1].path;
1162
+ next.path = fillParams(rawPath, params, ("path " + (current.path)));
1163
+ } else {
1164
+ warn(false, "relative params navigation requires a current route.");
1165
+ }
1166
+ return next
1167
+ }
1168
+
1169
+ var parsedPath = parsePath(next.path || '');
1170
+ var basePath = (current && current.path) || '/';
1171
+ var path = parsedPath.path
1172
+ ? resolvePath(parsedPath.path, basePath, append || next.append)
1173
+ : (current && current.path) || '/';
1174
+ var query = resolveQuery(parsedPath.query, next.query);
1175
+ var hash = next.hash || parsedPath.hash;
1176
+ if (hash && hash.charAt(0) !== '#') {
1177
+ hash = "#" + hash;
1178
+ }
1179
+
1180
+ return {
1181
+ _normalized: true,
1182
+ path: path,
1183
+ query: query,
1184
+ hash: hash
1185
+ }
1186
+ }
1187
+
1188
+ function assign (a, b) {
1189
+ for (var key in b) {
1190
+ a[key] = b[key];
1191
+ }
1192
+ return a
1193
+ }
1194
+
1195
+ /* */
1196
+
1197
+ function createMatcher (routes) {
1198
+ var ref = createRouteMap(routes);
1199
+ var pathMap = ref.pathMap;
1200
+ var nameMap = ref.nameMap;
1201
+
1202
+ function addRoutes (routes) {
1203
+ createRouteMap(routes, pathMap, nameMap);
1204
+ }
1205
+
1206
+ function match (
1207
+ raw,
1208
+ currentRoute,
1209
+ redirectedFrom
1210
+ ) {
1211
+ var location = normalizeLocation(raw, currentRoute);
1212
+ var name = location.name;
1213
+
1214
+ if (name) {
1215
+ var record = nameMap[name];
1216
+ {
1217
+ warn(record, ("Route with name '" + name + "' does not exist"));
1218
+ }
1219
+ var paramNames = getRouteRegex(record.path).keys
1220
+ .filter(function (key) { return !key.optional; })
1221
+ .map(function (key) { return key.name; });
1222
+
1223
+ if (typeof location.params !== 'object') {
1224
+ location.params = {};
1225
+ }
1226
+
1227
+ if (currentRoute && typeof currentRoute.params === 'object') {
1228
+ for (var key in currentRoute.params) {
1229
+ if (!(key in location.params) && paramNames.indexOf(key) > -1) {
1230
+ location.params[key] = currentRoute.params[key];
1231
+ }
1232
+ }
1233
+ }
1234
+
1235
+ if (record) {
1236
+ location.path = fillParams(record.path, location.params, ("named route \"" + name + "\""));
1237
+ return _createRoute(record, location, redirectedFrom)
1238
+ }
1239
+ } else if (location.path) {
1240
+ location.params = {};
1241
+ for (var path in pathMap) {
1242
+ if (matchRoute(path, location.params, location.path)) {
1243
+ return _createRoute(pathMap[path], location, redirectedFrom)
1244
+ }
1245
+ }
1246
+ }
1247
+ // no match
1248
+ return _createRoute(null, location)
1249
+ }
1250
+
1251
+ function redirect (
1252
+ record,
1253
+ location
1254
+ ) {
1255
+ var originalRedirect = record.redirect;
1256
+ var redirect = typeof originalRedirect === 'function'
1257
+ ? originalRedirect(createRoute(record, location))
1258
+ : originalRedirect;
1259
+
1260
+ if (typeof redirect === 'string') {
1261
+ redirect = { path: redirect };
1262
+ }
1263
+
1264
+ if (!redirect || typeof redirect !== 'object') {
1265
+ "development" !== 'production' && warn(
1266
+ false, ("invalid redirect option: " + (JSON.stringify(redirect)))
1267
+ );
1268
+ return _createRoute(null, location)
1269
+ }
1270
+
1271
+ var re = redirect;
1272
+ var name = re.name;
1273
+ var path = re.path;
1274
+ var query = location.query;
1275
+ var hash = location.hash;
1276
+ var params = location.params;
1277
+ query = re.hasOwnProperty('query') ? re.query : query;
1278
+ hash = re.hasOwnProperty('hash') ? re.hash : hash;
1279
+ params = re.hasOwnProperty('params') ? re.params : params;
1280
+
1281
+ if (name) {
1282
+ // resolved named direct
1283
+ var targetRecord = nameMap[name];
1284
+ {
1285
+ assert(targetRecord, ("redirect failed: named route \"" + name + "\" not found."));
1286
+ }
1287
+ return match({
1288
+ _normalized: true,
1289
+ name: name,
1290
+ query: query,
1291
+ hash: hash,
1292
+ params: params
1293
+ }, undefined, location)
1294
+ } else if (path) {
1295
+ // 1. resolve relative redirect
1296
+ var rawPath = resolveRecordPath(path, record);
1297
+ // 2. resolve params
1298
+ var resolvedPath = fillParams(rawPath, params, ("redirect route with path \"" + rawPath + "\""));
1299
+ // 3. rematch with existing query and hash
1300
+ return match({
1301
+ _normalized: true,
1302
+ path: resolvedPath,
1303
+ query: query,
1304
+ hash: hash
1305
+ }, undefined, location)
1306
+ } else {
1307
+ warn(false, ("invalid redirect option: " + (JSON.stringify(redirect))));
1308
+ return _createRoute(null, location)
1309
+ }
1310
+ }
1311
+
1312
+ function alias (
1313
+ record,
1314
+ location,
1315
+ matchAs
1316
+ ) {
1317
+ var aliasedPath = fillParams(matchAs, location.params, ("aliased route with path \"" + matchAs + "\""));
1318
+ var aliasedMatch = match({
1319
+ _normalized: true,
1320
+ path: aliasedPath
1321
+ });
1322
+ if (aliasedMatch) {
1323
+ var matched = aliasedMatch.matched;
1324
+ var aliasedRecord = matched[matched.length - 1];
1325
+ location.params = aliasedMatch.params;
1326
+ return _createRoute(aliasedRecord, location)
1327
+ }
1328
+ return _createRoute(null, location)
1329
+ }
1330
+
1331
+ function _createRoute (
1332
+ record,
1333
+ location,
1334
+ redirectedFrom
1335
+ ) {
1336
+ if (record && record.redirect) {
1337
+ return redirect(record, redirectedFrom || location)
1338
+ }
1339
+ if (record && record.matchAs) {
1340
+ return alias(record, location, record.matchAs)
1341
+ }
1342
+ return createRoute(record, location, redirectedFrom)
1343
+ }
1344
+
1345
+ return {
1346
+ match: match,
1347
+ addRoutes: addRoutes
1348
+ }
1349
+ }
1350
+
1351
+ function matchRoute (
1352
+ path,
1353
+ params,
1354
+ pathname
1355
+ ) {
1356
+ var ref = getRouteRegex(path);
1357
+ var regexp = ref.regexp;
1358
+ var keys = ref.keys;
1359
+ var m = pathname.match(regexp);
1360
+
1361
+ if (!m) {
1362
+ return false
1363
+ } else if (!params) {
1364
+ return true
1365
+ }
1366
+
1367
+ for (var i = 1, len = m.length; i < len; ++i) {
1368
+ var key = keys[i - 1];
1369
+ var val = typeof m[i] === 'string' ? decodeURIComponent(m[i]) : m[i];
1370
+ if (key) { params[key.name] = val; }
1371
+ }
1372
+
1373
+ return true
1374
+ }
1375
+
1376
+ function resolveRecordPath (path, record) {
1377
+ return resolvePath(path, record.parent ? record.parent.path : '/', true)
1378
+ }
1379
+
1380
+ /* */
1381
+
1382
+
1383
+ var positionStore = Object.create(null);
1384
+
1385
+ function setupScroll () {
1386
+ window.addEventListener('popstate', function (e) {
1387
+ saveScrollPosition();
1388
+ if (e.state && e.state.key) {
1389
+ setStateKey(e.state.key);
1390
+ }
1391
+ });
1392
+ }
1393
+
1394
+ function handleScroll (
1395
+ router,
1396
+ to,
1397
+ from,
1398
+ isPop
1399
+ ) {
1400
+ if (!router.app) {
1401
+ return
1402
+ }
1403
+
1404
+ var behavior = router.options.scrollBehavior;
1405
+ if (!behavior) {
1406
+ return
1407
+ }
1408
+
1409
+ {
1410
+ assert(typeof behavior === 'function', "scrollBehavior must be a function");
1411
+ }
1412
+
1413
+ // wait until re-render finishes before scrolling
1414
+ router.app.$nextTick(function () {
1415
+ var position = getScrollPosition();
1416
+ var shouldScroll = behavior(to, from, isPop ? position : null);
1417
+ if (!shouldScroll) {
1418
+ return
1419
+ }
1420
+ var isObject = typeof shouldScroll === 'object';
1421
+ if (isObject && typeof shouldScroll.selector === 'string') {
1422
+ var el = document.querySelector(shouldScroll.selector);
1423
+ if (el) {
1424
+ position = getElementPosition(el);
1425
+ } else if (isValidPosition(shouldScroll)) {
1426
+ position = normalizePosition(shouldScroll);
1427
+ }
1428
+ } else if (isObject && isValidPosition(shouldScroll)) {
1429
+ position = normalizePosition(shouldScroll);
1430
+ }
1431
+
1432
+ if (position) {
1433
+ window.scrollTo(position.x, position.y);
1434
+ }
1435
+ });
1436
+ }
1437
+
1438
+ function saveScrollPosition () {
1439
+ var key = getStateKey();
1440
+ if (key) {
1441
+ positionStore[key] = {
1442
+ x: window.pageXOffset,
1443
+ y: window.pageYOffset
1444
+ };
1445
+ }
1446
+ }
1447
+
1448
+ function getScrollPosition () {
1449
+ var key = getStateKey();
1450
+ if (key) {
1451
+ return positionStore[key]
1452
+ }
1453
+ }
1454
+
1455
+ function getElementPosition (el) {
1456
+ var docRect = document.documentElement.getBoundingClientRect();
1457
+ var elRect = el.getBoundingClientRect();
1458
+ return {
1459
+ x: elRect.left - docRect.left,
1460
+ y: elRect.top - docRect.top
1461
+ }
1462
+ }
1463
+
1464
+ function isValidPosition (obj) {
1465
+ return isNumber(obj.x) || isNumber(obj.y)
1466
+ }
1467
+
1468
+ function normalizePosition (obj) {
1469
+ return {
1470
+ x: isNumber(obj.x) ? obj.x : window.pageXOffset,
1471
+ y: isNumber(obj.y) ? obj.y : window.pageYOffset
1472
+ }
1473
+ }
1474
+
1475
+ function isNumber (v) {
1476
+ return typeof v === 'number'
1477
+ }
1478
+
1479
+ /* */
1480
+
1481
+ var supportsPushState = inBrowser && (function () {
1482
+ var ua = window.navigator.userAgent;
1483
+
1484
+ if (
1485
+ (ua.indexOf('Android 2.') !== -1 || ua.indexOf('Android 4.0') !== -1) &&
1486
+ ua.indexOf('Mobile Safari') !== -1 &&
1487
+ ua.indexOf('Chrome') === -1 &&
1488
+ ua.indexOf('Windows Phone') === -1
1489
+ ) {
1490
+ return false
1491
+ }
1492
+
1493
+ return window.history && 'pushState' in window.history
1494
+ })();
1495
+
1496
+ // use User Timing api (if present) for more accurate key precision
1497
+ var Time = inBrowser && window.performance && window.performance.now
1498
+ ? window.performance
1499
+ : Date;
1500
+
1501
+ var _key = genKey();
1502
+
1503
+ function genKey () {
1504
+ return Time.now().toFixed(3)
1505
+ }
1506
+
1507
+ function getStateKey () {
1508
+ return _key
1509
+ }
1510
+
1511
+ function setStateKey (key) {
1512
+ _key = key;
1513
+ }
1514
+
1515
+ function pushState (url, replace) {
1516
+ saveScrollPosition();
1517
+ // try...catch the pushState call to get around Safari
1518
+ // DOM Exception 18 where it limits to 100 pushState calls
1519
+ var history = window.history;
1520
+ try {
1521
+ if (replace) {
1522
+ history.replaceState({ key: _key }, '', url);
1523
+ } else {
1524
+ _key = genKey();
1525
+ history.pushState({ key: _key }, '', url);
1526
+ }
1527
+ } catch (e) {
1528
+ window.location[replace ? 'replace' : 'assign'](url);
1529
+ }
1530
+ }
1531
+
1532
+ function replaceState (url) {
1533
+ pushState(url, true);
1534
+ }
1535
+
1536
+ /* */
1537
+
1538
+ function runQueue (queue, fn, cb) {
1539
+ var step = function (index) {
1540
+ if (index >= queue.length) {
1541
+ cb();
1542
+ } else {
1543
+ if (queue[index]) {
1544
+ fn(queue[index], function () {
1545
+ step(index + 1);
1546
+ });
1547
+ } else {
1548
+ step(index + 1);
1549
+ }
1550
+ }
1551
+ };
1552
+ step(0);
1553
+ }
1554
+
1555
+ /* */
1556
+
1557
+
1558
+ var History = function History (router, base) {
1559
+ this.router = router;
1560
+ this.base = normalizeBase(base);
1561
+ // start with a route object that stands for "nowhere"
1562
+ this.current = START;
1563
+ this.pending = null;
1564
+ this.ready = false;
1565
+ this.readyCbs = [];
1566
+ };
1567
+
1568
+ History.prototype.listen = function listen (cb) {
1569
+ this.cb = cb;
1570
+ };
1571
+
1572
+ History.prototype.onReady = function onReady (cb) {
1573
+ if (this.ready) {
1574
+ cb();
1575
+ } else {
1576
+ this.readyCbs.push(cb);
1577
+ }
1578
+ };
1579
+
1580
+ History.prototype.transitionTo = function transitionTo (location, onComplete, onAbort) {
1581
+ var this$1 = this;
1582
+
1583
+ var route = this.router.match(location, this.current);
1584
+ this.confirmTransition(route, function () {
1585
+ this$1.updateRoute(route);
1586
+ onComplete && onComplete(route);
1587
+ this$1.ensureURL();
1588
+
1589
+ // fire ready cbs once
1590
+ if (!this$1.ready) {
1591
+ this$1.ready = true;
1592
+ this$1.readyCbs.forEach(function (cb) {
1593
+ cb(route);
1594
+ });
1595
+ }
1596
+ }, onAbort);
1597
+ };
1598
+
1599
+ History.prototype.confirmTransition = function confirmTransition (route, onComplete, onAbort) {
1600
+ var this$1 = this;
1601
+
1602
+ var current = this.current;
1603
+ var abort = function () { onAbort && onAbort(); };
1604
+ if (
1605
+ isSameRoute(route, current) &&
1606
+ // in the case the route map has been dynamically appended to
1607
+ route.matched.length === current.matched.length
1608
+ ) {
1609
+ this.ensureURL();
1610
+ return abort()
1611
+ }
1612
+
1613
+ var ref = resolveQueue(this.current.matched, route.matched);
1614
+ var updated = ref.updated;
1615
+ var deactivated = ref.deactivated;
1616
+ var activated = ref.activated;
1617
+
1618
+ var queue = [].concat(
1619
+ // in-component leave guards
1620
+ extractLeaveGuards(deactivated),
1621
+ // global before hooks
1622
+ this.router.beforeHooks,
1623
+ // in-component update hooks
1624
+ extractUpdateHooks(updated),
1625
+ // in-config enter guards
1626
+ activated.map(function (m) { return m.beforeEnter; }),
1627
+ // async components
1628
+ resolveAsyncComponents(activated)
1629
+ );
1630
+
1631
+ this.pending = route;
1632
+ var iterator = function (hook, next) {
1633
+ if (this$1.pending !== route) {
1634
+ return abort()
1635
+ }
1636
+ hook(route, current, function (to) {
1637
+ if (to === false) {
1638
+ // next(false) -> abort navigation, ensure current URL
1639
+ this$1.ensureURL(true);
1640
+ abort();
1641
+ } else if (typeof to === 'string' || typeof to === 'object') {
1642
+ // next('/') or next({ path: '/' }) -> redirect
1643
+ (typeof to === 'object' && to.replace) ? this$1.replace(to) : this$1.push(to);
1644
+ abort();
1645
+ } else {
1646
+ // confirm transition and pass on the value
1647
+ next(to);
1648
+ }
1649
+ });
1650
+ };
1651
+
1652
+ runQueue(queue, iterator, function () {
1653
+ var postEnterCbs = [];
1654
+ var isValid = function () { return this$1.current === route; };
1655
+ var enterGuards = extractEnterGuards(activated, postEnterCbs, isValid);
1656
+ // wait until async components are resolved before
1657
+ // extracting in-component enter guards
1658
+ runQueue(enterGuards, iterator, function () {
1659
+ if (this$1.pending !== route) {
1660
+ return abort()
1661
+ }
1662
+ this$1.pending = null;
1663
+ onComplete(route);
1664
+ if (this$1.router.app) {
1665
+ this$1.router.app.$nextTick(function () {
1666
+ postEnterCbs.forEach(function (cb) { return cb(); });
1667
+ });
1668
+ }
1669
+ });
1670
+ });
1671
+ };
1672
+
1673
+ History.prototype.updateRoute = function updateRoute (route) {
1674
+ var prev = this.current;
1675
+ this.current = route;
1676
+ this.cb && this.cb(route);
1677
+ this.router.afterHooks.forEach(function (hook) {
1678
+ hook && hook(route, prev);
1679
+ });
1680
+ };
1681
+
1682
+ function normalizeBase (base) {
1683
+ if (!base) {
1684
+ if (inBrowser) {
1685
+ // respect <base> tag
1686
+ var baseEl = document.querySelector('base');
1687
+ base = baseEl ? baseEl.getAttribute('href') : '/';
1688
+ } else {
1689
+ base = '/';
1690
+ }
1691
+ }
1692
+ // make sure there's the starting slash
1693
+ if (base.charAt(0) !== '/') {
1694
+ base = '/' + base;
1695
+ }
1696
+ // remove trailing slash
1697
+ return base.replace(/\/$/, '')
1698
+ }
1699
+
1700
+ function resolveQueue (
1701
+ current,
1702
+ next
1703
+ ) {
1704
+ var i;
1705
+ var max = Math.max(current.length, next.length);
1706
+ for (i = 0; i < max; i++) {
1707
+ if (current[i] !== next[i]) {
1708
+ break
1709
+ }
1710
+ }
1711
+ return {
1712
+ updated: next.slice(0, i),
1713
+ activated: next.slice(i),
1714
+ deactivated: current.slice(i)
1715
+ }
1716
+ }
1717
+
1718
+ function extractGuards (
1719
+ records,
1720
+ name,
1721
+ bind,
1722
+ reverse
1723
+ ) {
1724
+ var guards = flatMapComponents(records, function (def, instance, match, key) {
1725
+ var guard = extractGuard(def, name);
1726
+ if (guard) {
1727
+ return Array.isArray(guard)
1728
+ ? guard.map(function (guard) { return bind(guard, instance, match, key); })
1729
+ : bind(guard, instance, match, key)
1730
+ }
1731
+ });
1732
+ return flatten(reverse ? guards.reverse() : guards)
1733
+ }
1734
+
1735
+ function extractGuard (
1736
+ def,
1737
+ key
1738
+ ) {
1739
+ if (typeof def !== 'function') {
1740
+ // extend now so that global mixins are applied.
1741
+ def = _Vue.extend(def);
1742
+ }
1743
+ return def.options[key]
1744
+ }
1745
+
1746
+ function extractLeaveGuards (deactivated) {
1747
+ return extractGuards(deactivated, 'beforeRouteLeave', bindGuard, true)
1748
+ }
1749
+
1750
+ function extractUpdateHooks (updated) {
1751
+ return extractGuards(updated, 'beforeRouteUpdate', bindGuard)
1752
+ }
1753
+
1754
+ function bindGuard (guard, instance) {
1755
+ return function boundRouteGuard () {
1756
+ return guard.apply(instance, arguments)
1757
+ }
1758
+ }
1759
+
1760
+ function extractEnterGuards (
1761
+ activated,
1762
+ cbs,
1763
+ isValid
1764
+ ) {
1765
+ return extractGuards(activated, 'beforeRouteEnter', function (guard, _, match, key) {
1766
+ return bindEnterGuard(guard, match, key, cbs, isValid)
1767
+ })
1768
+ }
1769
+
1770
+ function bindEnterGuard (
1771
+ guard,
1772
+ match,
1773
+ key,
1774
+ cbs,
1775
+ isValid
1776
+ ) {
1777
+ return function routeEnterGuard (to, from, next) {
1778
+ return guard(to, from, function (cb) {
1779
+ next(cb);
1780
+ if (typeof cb === 'function') {
1781
+ cbs.push(function () {
1782
+ // #750
1783
+ // if a router-view is wrapped with an out-in transition,
1784
+ // the instance may not have been registered at this time.
1785
+ // we will need to poll for registration until current route
1786
+ // is no longer valid.
1787
+ poll(cb, match.instances, key, isValid);
1788
+ });
1789
+ }
1790
+ })
1791
+ }
1792
+ }
1793
+
1794
+ function poll (
1795
+ cb, // somehow flow cannot infer this is a function
1796
+ instances,
1797
+ key,
1798
+ isValid
1799
+ ) {
1800
+ if (instances[key]) {
1801
+ cb(instances[key]);
1802
+ } else if (isValid()) {
1803
+ setTimeout(function () {
1804
+ poll(cb, instances, key, isValid);
1805
+ }, 16);
1806
+ }
1807
+ }
1808
+
1809
+ function resolveAsyncComponents (matched) {
1810
+ return flatMapComponents(matched, function (def, _, match, key) {
1811
+ // if it's a function and doesn't have Vue options attached,
1812
+ // assume it's an async component resolve function.
1813
+ // we are not using Vue's default async resolving mechanism because
1814
+ // we want to halt the navigation until the incoming component has been
1815
+ // resolved.
1816
+ if (typeof def === 'function' && !def.options) {
1817
+ return function (to, from, next) {
1818
+ var resolve = once(function (resolvedDef) {
1819
+ match.components[key] = resolvedDef;
1820
+ next();
1821
+ });
1822
+
1823
+ var reject = once(function (reason) {
1824
+ warn(false, ("Failed to resolve async component " + key + ": " + reason));
1825
+ next(false);
1826
+ });
1827
+
1828
+ var res = def(resolve, reject);
1829
+ if (res && typeof res.then === 'function') {
1830
+ res.then(resolve, reject);
1831
+ }
1832
+ }
1833
+ }
1834
+ })
1835
+ }
1836
+
1837
+ function flatMapComponents (
1838
+ matched,
1839
+ fn
1840
+ ) {
1841
+ return flatten(matched.map(function (m) {
1842
+ return Object.keys(m.components).map(function (key) { return fn(
1843
+ m.components[key],
1844
+ m.instances[key],
1845
+ m, key
1846
+ ); })
1847
+ }))
1848
+ }
1849
+
1850
+ function flatten (arr) {
1851
+ return Array.prototype.concat.apply([], arr)
1852
+ }
1853
+
1854
+ // in Webpack 2, require.ensure now also returns a Promise
1855
+ // so the resolve/reject functions may get called an extra time
1856
+ // if the user uses an arrow function shorthand that happens to
1857
+ // return that Promise.
1858
+ function once (fn) {
1859
+ var called = false;
1860
+ return function () {
1861
+ if (called) { return }
1862
+ called = true;
1863
+ return fn.apply(this, arguments)
1864
+ }
1865
+ }
1866
+
1867
+ /* */
1868
+
1869
+
1870
+ var HTML5History = (function (History$$1) {
1871
+ function HTML5History (router, base) {
1872
+ var this$1 = this;
1873
+
1874
+ History$$1.call(this, router, base);
1875
+
1876
+ var expectScroll = router.options.scrollBehavior;
1877
+
1878
+ if (expectScroll) {
1879
+ setupScroll();
1880
+ }
1881
+
1882
+ window.addEventListener('popstate', function (e) {
1883
+ this$1.transitionTo(getLocation(this$1.base), function (route) {
1884
+ if (expectScroll) {
1885
+ handleScroll(router, route, this$1.current, true);
1886
+ }
1887
+ });
1888
+ });
1889
+ }
1890
+
1891
+ if ( History$$1 ) HTML5History.__proto__ = History$$1;
1892
+ HTML5History.prototype = Object.create( History$$1 && History$$1.prototype );
1893
+ HTML5History.prototype.constructor = HTML5History;
1894
+
1895
+ HTML5History.prototype.go = function go (n) {
1896
+ window.history.go(n);
1897
+ };
1898
+
1899
+ HTML5History.prototype.push = function push (location, onComplete, onAbort) {
1900
+ var this$1 = this;
1901
+
1902
+ this.transitionTo(location, function (route) {
1903
+ pushState(cleanPath(this$1.base + route.fullPath));
1904
+ handleScroll(this$1.router, route, this$1.current, false);
1905
+ onComplete && onComplete(route);
1906
+ }, onAbort);
1907
+ };
1908
+
1909
+ HTML5History.prototype.replace = function replace (location, onComplete, onAbort) {
1910
+ var this$1 = this;
1911
+
1912
+ this.transitionTo(location, function (route) {
1913
+ replaceState(cleanPath(this$1.base + route.fullPath));
1914
+ handleScroll(this$1.router, route, this$1.current, false);
1915
+ onComplete && onComplete(route);
1916
+ }, onAbort);
1917
+ };
1918
+
1919
+ HTML5History.prototype.ensureURL = function ensureURL (push) {
1920
+ if (getLocation(this.base) !== this.current.fullPath) {
1921
+ var current = cleanPath(this.base + this.current.fullPath);
1922
+ push ? pushState(current) : replaceState(current);
1923
+ }
1924
+ };
1925
+
1926
+ HTML5History.prototype.getCurrentLocation = function getCurrentLocation () {
1927
+ return getLocation(this.base)
1928
+ };
1929
+
1930
+ return HTML5History;
1931
+ }(History));
1932
+
1933
+ function getLocation (base) {
1934
+ var path = window.location.pathname;
1935
+ if (base && path.indexOf(base) === 0) {
1936
+ path = path.slice(base.length);
1937
+ }
1938
+ return (path || '/') + window.location.search + window.location.hash
1939
+ }
1940
+
1941
+ /* */
1942
+
1943
+
1944
+ var HashHistory = (function (History$$1) {
1945
+ function HashHistory (router, base, fallback) {
1946
+ History$$1.call(this, router, base);
1947
+ // check history fallback deeplinking
1948
+ if (fallback && checkFallback(this.base)) {
1949
+ return
1950
+ }
1951
+ ensureSlash();
1952
+ }
1953
+
1954
+ if ( History$$1 ) HashHistory.__proto__ = History$$1;
1955
+ HashHistory.prototype = Object.create( History$$1 && History$$1.prototype );
1956
+ HashHistory.prototype.constructor = HashHistory;
1957
+
1958
+ // this is delayed until the app mounts
1959
+ // to avoid the hashchange listener being fired too early
1960
+ HashHistory.prototype.setupListeners = function setupListeners () {
1961
+ var this$1 = this;
1962
+
1963
+ window.addEventListener('hashchange', function () {
1964
+ if (!ensureSlash()) {
1965
+ return
1966
+ }
1967
+ this$1.transitionTo(getHash(), function (route) {
1968
+ replaceHash(route.fullPath);
1969
+ });
1970
+ });
1971
+ };
1972
+
1973
+ HashHistory.prototype.push = function push (location, onComplete, onAbort) {
1974
+ this.transitionTo(location, function (route) {
1975
+ pushHash(route.fullPath);
1976
+ onComplete && onComplete(route);
1977
+ }, onAbort);
1978
+ };
1979
+
1980
+ HashHistory.prototype.replace = function replace (location, onComplete, onAbort) {
1981
+ this.transitionTo(location, function (route) {
1982
+ replaceHash(route.fullPath);
1983
+ onComplete && onComplete(route);
1984
+ }, onAbort);
1985
+ };
1986
+
1987
+ HashHistory.prototype.go = function go (n) {
1988
+ window.history.go(n);
1989
+ };
1990
+
1991
+ HashHistory.prototype.ensureURL = function ensureURL (push) {
1992
+ var current = this.current.fullPath;
1993
+ if (getHash() !== current) {
1994
+ push ? pushHash(current) : replaceHash(current);
1995
+ }
1996
+ };
1997
+
1998
+ HashHistory.prototype.getCurrentLocation = function getCurrentLocation () {
1999
+ return getHash()
2000
+ };
2001
+
2002
+ return HashHistory;
2003
+ }(History));
2004
+
2005
+ function checkFallback (base) {
2006
+ var location = getLocation(base);
2007
+ if (!/^\/#/.test(location)) {
2008
+ window.location.replace(
2009
+ cleanPath(base + '/#' + location)
2010
+ );
2011
+ return true
2012
+ }
2013
+ }
2014
+
2015
+ function ensureSlash () {
2016
+ var path = getHash();
2017
+ if (path.charAt(0) === '/') {
2018
+ return true
2019
+ }
2020
+ replaceHash('/' + path);
2021
+ return false
2022
+ }
2023
+
2024
+ function getHash () {
2025
+ // We can't use window.location.hash here because it's not
2026
+ // consistent across browsers - Firefox will pre-decode it!
2027
+ var href = window.location.href;
2028
+ var index = href.indexOf('#');
2029
+ return index === -1 ? '' : href.slice(index + 1)
2030
+ }
2031
+
2032
+ function pushHash (path) {
2033
+ window.location.hash = path;
2034
+ }
2035
+
2036
+ function replaceHash (path) {
2037
+ var i = window.location.href.indexOf('#');
2038
+ window.location.replace(
2039
+ window.location.href.slice(0, i >= 0 ? i : 0) + '#' + path
2040
+ );
2041
+ }
2042
+
2043
+ /* */
2044
+
2045
+
2046
+ var AbstractHistory = (function (History$$1) {
2047
+ function AbstractHistory (router, base) {
2048
+ History$$1.call(this, router, base);
2049
+ this.stack = [];
2050
+ this.index = -1;
2051
+ }
2052
+
2053
+ if ( History$$1 ) AbstractHistory.__proto__ = History$$1;
2054
+ AbstractHistory.prototype = Object.create( History$$1 && History$$1.prototype );
2055
+ AbstractHistory.prototype.constructor = AbstractHistory;
2056
+
2057
+ AbstractHistory.prototype.push = function push (location, onComplete, onAbort) {
2058
+ var this$1 = this;
2059
+
2060
+ this.transitionTo(location, function (route) {
2061
+ this$1.stack = this$1.stack.slice(0, this$1.index + 1).concat(route);
2062
+ this$1.index++;
2063
+ onComplete && onComplete(route);
2064
+ }, onAbort);
2065
+ };
2066
+
2067
+ AbstractHistory.prototype.replace = function replace (location, onComplete, onAbort) {
2068
+ var this$1 = this;
2069
+
2070
+ this.transitionTo(location, function (route) {
2071
+ this$1.stack = this$1.stack.slice(0, this$1.index).concat(route);
2072
+ onComplete && onComplete(route);
2073
+ }, onAbort);
2074
+ };
2075
+
2076
+ AbstractHistory.prototype.go = function go (n) {
2077
+ var this$1 = this;
2078
+
2079
+ var targetIndex = this.index + n;
2080
+ if (targetIndex < 0 || targetIndex >= this.stack.length) {
2081
+ return
2082
+ }
2083
+ var route = this.stack[targetIndex];
2084
+ this.confirmTransition(route, function () {
2085
+ this$1.index = targetIndex;
2086
+ this$1.updateRoute(route);
2087
+ });
2088
+ };
2089
+
2090
+ AbstractHistory.prototype.getCurrentLocation = function getCurrentLocation () {
2091
+ var current = this.stack[this.stack.length - 1];
2092
+ return current ? current.fullPath : '/'
2093
+ };
2094
+
2095
+ AbstractHistory.prototype.ensureURL = function ensureURL () {
2096
+ // noop
2097
+ };
2098
+
2099
+ return AbstractHistory;
2100
+ }(History));
2101
+
2102
+ /* */
2103
+
2104
+ var VueRouter = function VueRouter (options) {
2105
+ if ( options === void 0 ) options = {};
2106
+
2107
+ this.app = null;
2108
+ this.apps = [];
2109
+ this.options = options;
2110
+ this.beforeHooks = [];
2111
+ this.afterHooks = [];
2112
+ this.matcher = createMatcher(options.routes || []);
2113
+
2114
+ var mode = options.mode || 'hash';
2115
+ this.fallback = mode === 'history' && !supportsPushState;
2116
+ if (this.fallback) {
2117
+ mode = 'hash';
2118
+ }
2119
+ if (!inBrowser) {
2120
+ mode = 'abstract';
2121
+ }
2122
+ this.mode = mode;
2123
+
2124
+ switch (mode) {
2125
+ case 'history':
2126
+ this.history = new HTML5History(this, options.base);
2127
+ break
2128
+ case 'hash':
2129
+ this.history = new HashHistory(this, options.base, this.fallback);
2130
+ break
2131
+ case 'abstract':
2132
+ this.history = new AbstractHistory(this, options.base);
2133
+ break
2134
+ default:
2135
+ {
2136
+ assert(false, ("invalid mode: " + mode));
2137
+ }
2138
+ }
2139
+ };
2140
+
2141
+ var prototypeAccessors = { currentRoute: {} };
2142
+
2143
+ VueRouter.prototype.match = function match (
2144
+ raw,
2145
+ current,
2146
+ redirectedFrom
2147
+ ) {
2148
+ return this.matcher.match(raw, current, redirectedFrom)
2149
+ };
2150
+
2151
+ prototypeAccessors.currentRoute.get = function () {
2152
+ return this.history && this.history.current
2153
+ };
2154
+
2155
+ VueRouter.prototype.init = function init (app /* Vue component instance */) {
2156
+ var this$1 = this;
2157
+
2158
+ "development" !== 'production' && assert(
2159
+ install.installed,
2160
+ "not installed. Make sure to call `Vue.use(VueRouter)` " +
2161
+ "before creating root instance."
2162
+ );
2163
+
2164
+ this.apps.push(app);
2165
+
2166
+ // main app already initialized.
2167
+ if (this.app) {
2168
+ return
2169
+ }
2170
+
2171
+ this.app = app;
2172
+
2173
+ var history = this.history;
2174
+
2175
+ if (history instanceof HTML5History) {
2176
+ history.transitionTo(history.getCurrentLocation());
2177
+ } else if (history instanceof HashHistory) {
2178
+ var setupHashListener = function () {
2179
+ history.setupListeners();
2180
+ };
2181
+ history.transitionTo(
2182
+ history.getCurrentLocation(),
2183
+ setupHashListener,
2184
+ setupHashListener
2185
+ );
2186
+ }
2187
+
2188
+ history.listen(function (route) {
2189
+ this$1.apps.forEach(function (app) {
2190
+ app._route = route;
2191
+ });
2192
+ });
2193
+ };
2194
+
2195
+ VueRouter.prototype.beforeEach = function beforeEach (fn) {
2196
+ this.beforeHooks.push(fn);
2197
+ };
2198
+
2199
+ VueRouter.prototype.afterEach = function afterEach (fn) {
2200
+ this.afterHooks.push(fn);
2201
+ };
2202
+
2203
+ VueRouter.prototype.onReady = function onReady (cb) {
2204
+ this.history.onReady(cb);
2205
+ };
2206
+
2207
+ VueRouter.prototype.push = function push (location, onComplete, onAbort) {
2208
+ this.history.push(location, onComplete, onAbort);
2209
+ };
2210
+
2211
+ VueRouter.prototype.replace = function replace (location, onComplete, onAbort) {
2212
+ this.history.replace(location, onComplete, onAbort);
2213
+ };
2214
+
2215
+ VueRouter.prototype.go = function go (n) {
2216
+ this.history.go(n);
2217
+ };
2218
+
2219
+ VueRouter.prototype.back = function back () {
2220
+ this.go(-1);
2221
+ };
2222
+
2223
+ VueRouter.prototype.forward = function forward () {
2224
+ this.go(1);
2225
+ };
2226
+
2227
+ VueRouter.prototype.getMatchedComponents = function getMatchedComponents (to) {
2228
+ var route = to
2229
+ ? this.resolve(to).route
2230
+ : this.currentRoute;
2231
+ if (!route) {
2232
+ return []
2233
+ }
2234
+ return [].concat.apply([], route.matched.map(function (m) {
2235
+ return Object.keys(m.components).map(function (key) {
2236
+ return m.components[key]
2237
+ })
2238
+ }))
2239
+ };
2240
+
2241
+ VueRouter.prototype.resolve = function resolve (
2242
+ to,
2243
+ current,
2244
+ append
2245
+ ) {
2246
+ var location = normalizeLocation(to, current || this.history.current, append);
2247
+ var route = this.match(location, current);
2248
+ var fullPath = route.redirectedFrom || route.fullPath;
2249
+ var base = this.history.base;
2250
+ var href = createHref(base, fullPath, this.mode);
2251
+ return {
2252
+ location: location,
2253
+ route: route,
2254
+ href: href,
2255
+ // for backwards compat
2256
+ normalizedTo: location,
2257
+ resolved: route
2258
+ }
2259
+ };
2260
+
2261
+ VueRouter.prototype.addRoutes = function addRoutes (routes) {
2262
+ this.matcher.addRoutes(routes);
2263
+ if (this.history.current !== START) {
2264
+ this.history.transitionTo(this.history.getCurrentLocation());
2265
+ }
2266
+ };
2267
+
2268
+ Object.defineProperties( VueRouter.prototype, prototypeAccessors );
2269
+
2270
+ function createHref (base, fullPath, mode) {
2271
+ var path = mode === 'hash' ? '#' + fullPath : fullPath;
2272
+ return base ? cleanPath(base + '/' + path) : path
2273
+ }
2274
+
2275
+ VueRouter.install = install;
2276
+ VueRouter.version = '2.2.1';
2277
+
2278
+ if (inBrowser && window.Vue) {
2279
+ window.Vue.use(VueRouter);
2280
+ }
2281
+
2282
+ return VueRouter;
2283
+
2284
+ })));