@tarojs/router 3.8.0-canary.0 → 4.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/LICENSE +14 -0
  2. package/dist/api.d.ts +7 -6
  3. package/dist/api.js +42 -21
  4. package/dist/events/resize.d.ts +2 -1
  5. package/dist/events/resize.js +15 -7
  6. package/dist/events/scroll.d.ts +2 -1
  7. package/dist/events/scroll.js +4 -1
  8. package/dist/history.d.ts +24 -5
  9. package/dist/history.js +18 -7
  10. package/dist/index.cjs.d.ts +49 -6
  11. package/dist/index.cjs.js +625 -287
  12. package/dist/index.d.ts +10 -4
  13. package/dist/index.esm.d.ts +49 -6
  14. package/dist/index.esm.js +586 -259
  15. package/dist/index.js +52 -4
  16. package/dist/navigationBar.d.ts +2 -0
  17. package/dist/navigationBar.js +27 -0
  18. package/dist/router/index.d.ts +4 -3
  19. package/dist/router/index.js +6 -3
  20. package/dist/router/mpa.d.ts +5 -3
  21. package/dist/router/mpa.js +22 -17
  22. package/dist/router/multi-page.d.ts +11 -6
  23. package/dist/router/multi-page.js +41 -43
  24. package/dist/router/navigation-bar.d.ts +32 -0
  25. package/dist/router/navigation-bar.js +209 -0
  26. package/dist/router/page.d.ts +13 -7
  27. package/dist/router/page.js +40 -54
  28. package/dist/router/spa.d.ts +5 -3
  29. package/dist/router/spa.js +40 -26
  30. package/dist/router/stack.d.ts +1 -1
  31. package/dist/router/stack.js +2 -1
  32. package/dist/style.d.ts +8 -2
  33. package/dist/style.js +80 -18
  34. package/dist/tabbar.d.ts +3 -1
  35. package/dist/tabbar.js +5 -4
  36. package/dist/utils/index.d.ts +3 -9
  37. package/dist/utils/index.js +5 -20
  38. package/dist/utils/navigate.d.ts +9 -5
  39. package/dist/utils/navigate.js +22 -38
  40. package/package.json +25 -15
  41. package/types/component.d.ts +5 -0
  42. package/types/taro.d.ts +8 -0
  43. package/dist/index.cjs.js.map +0 -1
  44. package/dist/index.esm.js.map +0 -1
package/dist/index.cjs.js CHANGED
@@ -1,104 +1,66 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var history = require('history');
6
- var runtime = require('@tarojs/runtime');
7
- var MobileDetect = require('mobile-detect');
8
- var queryString = require('query-string');
9
3
  var components = require('@tarojs/components/dist/components');
10
4
  var taro = require('@tarojs/taro');
5
+ var tslib = require('tslib');
6
+ var runtime = require('@tarojs/runtime');
7
+ var history = require('history');
8
+ var queryString = require('query-string');
11
9
  var UniversalRouter = require('universal-router');
12
10
 
13
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
14
-
15
- var MobileDetect__default = /*#__PURE__*/_interopDefaultLegacy(MobileDetect);
16
- var queryString__default = /*#__PURE__*/_interopDefaultLegacy(queryString);
17
- var UniversalRouter__default = /*#__PURE__*/_interopDefaultLegacy(UniversalRouter);
11
+ const home_svg_str = `
12
+ <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
13
+ <path d="M23.8899 12.2737C23.8232 12.3584 23.7237 12.3997 23.6198 12.3974H20.7994V23.5996C20.7994 23.8194 20.6213 24 20.4001 24H14.7994C14.5791 24 14.4002 23.8194 14.4002 23.5996V15.6H9.59963V23.5996C9.59963 23.8194 9.42075 24 9.20033 24H3.59968C3.48981 24 3.38964 23.954 3.31764 23.8811C3.24495 23.8091 3.2004 23.7087 3.2004 23.5996V12.3975H0.398546V12.3967C0.296893 12.396 0.194446 12.3544 0.11579 12.2738C-0.0371146 12.114 -0.0400714 11.864 0.11579 11.7076L11.7201 0.117284C11.8767 -0.0390948 12.1298 -0.0390948 12.2863 0.117284L23.8899 11.7076C24.0465 11.864 24.0265 12.0995 23.8899 12.2737ZM12.0029 0.964625L1.37086 11.5854L3.59968 11.5839V11.5999C3.65537 11.5999 3.70804 11.611 3.75557 11.6307C3.89952 11.692 4.00046 11.8339 4.00046 11.9996V23.1991H8.79955V15.2003C8.79955 14.9789 8.97917 14.8002 9.20033 14.8002H14.7995C15.0207 14.8002 15.2003 14.9789 15.2003 15.2003V23.1991H20.0001V11.9996C20.0001 11.8339 20.1003 11.692 20.2443 11.6307C20.2918 11.611 20.3453 11.5999 20.4001 11.5999V11.5713L22.6193 11.5691L12.0029 0.964625Z" fill="currentColor"/>
14
+ </svg>
15
+ `;
16
+ const back_svg_str = `
17
+ <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
18
+ <path d="M17.8206 22.9016L7.45515 11.8756L17.8206 1.09845C18.0598 0.849741 18.0598 0.435233 17.8206 0.186528C17.5814 -0.0621762 17.1827 -0.0621762 16.9435 0.186528L6.1794 11.4611C5.9402 11.7098 5.9402 12.1244 6.1794 12.3731L16.9435 23.8135C17.1827 24.0622 17.5814 24.0622 17.8206 23.8135C18.0598 23.5648 18.0598 23.1503 17.8206 22.9016Z" fill="currentColor"/>
19
+ </svg>
18
20
 
19
- /******************************************************************************
20
- Copyright (c) Microsoft Corporation.
21
-
22
- Permission to use, copy, modify, and/or distribute this software for any
23
- purpose with or without fee is hereby granted.
24
-
25
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
26
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
27
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
28
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
29
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
30
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
31
- PERFORMANCE OF THIS SOFTWARE.
32
- ***************************************************************************** */
33
-
34
- function __awaiter(thisArg, _arguments, P, generator) {
35
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
36
- return new (P || (P = Promise))(function (resolve, reject) {
37
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
38
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
39
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
40
- step((generator = generator.apply(thisArg, _arguments || [])).next());
41
- });
21
+ `;
22
+ function initNavigationBar(container) {
23
+ const navigationBar = document.createElement('taro-navigation-bar-wrap');
24
+ navigationBar.classList.add('taro-navigation-bar-no-icon');
25
+ const navigationBarBackBtn = document.createElement('taro-navigation-bar-back');
26
+ const navigationBarHomeBtn = document.createElement('taro-navigation-bar-home');
27
+ navigationBarBackBtn.innerHTML = back_svg_str;
28
+ navigationBarHomeBtn.innerHTML = home_svg_str;
29
+ const navigationBarTitle = document.createElement('taro-navigation-bar-title');
30
+ navigationBar.appendChild(navigationBarHomeBtn);
31
+ navigationBar.appendChild(navigationBarBackBtn);
32
+ navigationBar.appendChild(navigationBarTitle);
33
+ navigationBar.id = 'taro-navigation-bar';
34
+ container.prepend(navigationBar);
42
35
  }
43
36
 
44
- // export const removeLeadingSlash = (str = '') => str.replace(/^\.?\//, '')
45
- // export const removeTrailingSearch = (str = '') => str.replace(/\?[\s\S]*$/, '')
46
- const addLeadingSlash = (url = '') => (url.charAt(0) === '/' ? url : '/' + url);
47
- const hasBasename = (path = '', prefix = '') => new RegExp('^' + prefix + '(\\/|\\?|#|$)', 'i').test(path) || path === prefix;
48
- const stripBasename = (path = '', prefix = '') => hasBasename(path, prefix) ? path.substring(prefix.length) : path;
49
- const stripTrailing = (str = '') => str.replace(/[?#][\s\S]*$/, '');
50
- const getHomePage = (path = '', basename = '', customRoutes = {}, entryPagePath = '') => {
51
- var _a;
52
- const routePath = addLeadingSlash(stripBasename(path, basename));
53
- const alias = ((_a = Object.entries(customRoutes).find(([key]) => key === routePath)) === null || _a === void 0 ? void 0 : _a[1]) || routePath;
54
- return entryPagePath || (typeof alias === 'string' ? alias : alias[0]) || basename;
55
- };
56
- const getCurrentPage = (routerMode = 'hash', basename = '/') => {
57
- const pagePath = routerMode === 'hash'
58
- ? location.hash.slice(1).split('?')[0]
59
- : location.pathname;
60
- return addLeadingSlash(stripBasename(pagePath, basename));
61
- };
62
- class RoutesAlias {
63
- constructor() {
64
- this.conf = [];
65
- this.getConfig = (url = '') => {
66
- const customRoute = this.conf.filter((arr) => {
67
- return arr.includes(url);
68
- });
69
- return customRoute[0];
70
- };
71
- this.getOrigin = (url = '') => {
72
- var _a;
73
- return ((_a = this.getConfig(url)) === null || _a === void 0 ? void 0 : _a[0]) || url;
74
- };
75
- this.getAlias = (url = '') => {
76
- var _a;
77
- return ((_a = this.getConfig(url)) === null || _a === void 0 ? void 0 : _a[1]) || url;
78
- };
79
- this.getAll = (url = '') => {
80
- return this.conf
81
- .filter((arr) => arr.includes(url))
82
- .reduceRight((p, a) => {
83
- p.unshift(a[1]);
84
- return p;
85
- }, []);
86
- };
37
+ function initTabbar(config, history) {
38
+ if (config.tabBar == null || config.tabBar.custom) {
39
+ return;
87
40
  }
88
- set(customRoutes = {}) {
89
- for (let key in customRoutes) {
90
- const path = customRoutes[key];
91
- key = addLeadingSlash(key);
92
- if (typeof path === 'string') {
93
- this.conf.push([key, addLeadingSlash(path)]);
94
- }
95
- else if ((path === null || path === void 0 ? void 0 : path.length) > 0) {
96
- this.conf.push(...path.map(p => [key, addLeadingSlash(p)]));
97
- }
98
- }
41
+ // TODO: custom-tab-bar
42
+ components.defineCustomElementTaroTabbar();
43
+ const tabbar = document.createElement('taro-tabbar');
44
+ const homePage = config.entryPagePath || (config.pages ? config.pages[0] : '');
45
+ tabbar.conf = config.tabBar;
46
+ tabbar.conf.homePage = history.location.pathname === '/' ? homePage : history.location.pathname;
47
+ const routerConfig = config.router;
48
+ tabbar.conf.mode = routerConfig && routerConfig.mode ? routerConfig.mode : 'hash';
49
+ if (routerConfig.customRoutes) {
50
+ tabbar.conf.custom = true;
51
+ tabbar.conf.customRoutes = routerConfig.customRoutes;
52
+ }
53
+ else {
54
+ tabbar.conf.custom = false;
55
+ tabbar.conf.customRoutes = {};
56
+ }
57
+ if (typeof routerConfig.basename !== 'undefined') {
58
+ tabbar.conf.basename = routerConfig.basename;
99
59
  }
60
+ const container = document.getElementById('container');
61
+ container === null || container === void 0 ? void 0 : container.appendChild(tabbar);
62
+ taro.initTabBarApis(config);
100
63
  }
101
- const routesAlias = new RoutesAlias();
102
64
 
103
65
  class RouterConfig {
104
66
  static set config(e) {
@@ -118,7 +80,7 @@ class RouterConfig {
118
80
  }
119
81
  static get customRoutes() { return this.router.customRoutes || {}; }
120
82
  static isPage(url = '') {
121
- return this.pages.findIndex(e => addLeadingSlash(e) === url) !== -1;
83
+ return this.pages.findIndex(e => prependBasename(e) === url) !== -1;
122
84
  }
123
85
  }
124
86
 
@@ -152,7 +114,7 @@ class MpaHistory {
152
114
  url += `?${to.search}`;
153
115
  }
154
116
  if (to.hash) {
155
- url += `#${to.hash}`;
117
+ url += to.hash.startsWith('#') ? to.hash : `#${to.hash}`;
156
118
  }
157
119
  return url;
158
120
  }
@@ -201,6 +163,13 @@ class MpaHistory {
201
163
  };
202
164
  }
203
165
  }
166
+ function setHistory(h, base = '/') {
167
+ exports.history = h;
168
+ basename = base;
169
+ }
170
+ function createMpaHistory(_) {
171
+ return new MpaHistory();
172
+ }
204
173
  function setHistoryMode(mode, base = '/') {
205
174
  const options = {
206
175
  window
@@ -210,7 +179,7 @@ function setHistoryMode(mode, base = '/') {
210
179
  exports.history = history.createBrowserHistory(options);
211
180
  }
212
181
  else if (mode === 'multi') {
213
- exports.history = new MpaHistory();
182
+ exports.history = createMpaHistory();
214
183
  }
215
184
  else {
216
185
  // default is hash
@@ -302,6 +271,72 @@ class Stacks {
302
271
  }
303
272
  const stacks = new Stacks();
304
273
 
274
+ const isWeixin = () => !!navigator.userAgent.match(/\bMicroMessenger\b/ig);
275
+ const isDingTalk = () => !!navigator.userAgent.match(/\bDingTalk\b/ig);
276
+ let preTitle = document.title;
277
+ let isLoadDdEntry = false;
278
+ function setMpaTitle(title) {
279
+ if (preTitle === title)
280
+ return;
281
+ document.title = title;
282
+ preTitle = title;
283
+ if (process.env.SUPPORT_DINGTALK_NAVIGATE !== 'disabled' && isDingTalk()) {
284
+ if (!isLoadDdEntry) {
285
+ isLoadDdEntry = true;
286
+ require('dingtalk-jsapi/platform');
287
+ }
288
+ const setDingTitle = require('dingtalk-jsapi/api/biz/navigation/setTitle').default;
289
+ setDingTitle({ title });
290
+ }
291
+ }
292
+ function setTitle(title) {
293
+ runtime.eventCenter.trigger('__taroH5SetNavigationTitle', title);
294
+ }
295
+ function setNavigationBarStyle(option) {
296
+ runtime.eventCenter.trigger('__taroH5setNavigationBarColor', option);
297
+ }
298
+
299
+ class RoutesAlias {
300
+ constructor() {
301
+ this.conf = [];
302
+ this.getConfig = (url = '') => {
303
+ const customRoute = this.conf.filter((arr) => {
304
+ return arr.includes(url);
305
+ });
306
+ return customRoute[0];
307
+ };
308
+ this.getOrigin = (url = '') => {
309
+ var _a;
310
+ return ((_a = this.getConfig(url)) === null || _a === void 0 ? void 0 : _a[0]) || url;
311
+ };
312
+ this.getAlias = (url = '') => {
313
+ var _a;
314
+ return ((_a = this.getConfig(url)) === null || _a === void 0 ? void 0 : _a[1]) || url;
315
+ };
316
+ this.getAll = (url = '') => {
317
+ return this.conf
318
+ .filter((arr) => arr.includes(url))
319
+ .reduceRight((p, a) => {
320
+ p.unshift(a[1]);
321
+ return p;
322
+ }, []);
323
+ };
324
+ }
325
+ set(customRoutes = {}) {
326
+ for (let key in customRoutes) {
327
+ const path = customRoutes[key];
328
+ key = runtime.addLeadingSlash(key);
329
+ if (typeof path === 'string') {
330
+ this.conf.push([key, runtime.addLeadingSlash(path)]);
331
+ }
332
+ else if ((path === null || path === void 0 ? void 0 : path.length) > 0) {
333
+ this.conf.push(...path.map(p => [key, runtime.addLeadingSlash(p)]));
334
+ }
335
+ }
336
+ }
337
+ }
338
+ const routesAlias = new RoutesAlias();
339
+
305
340
  function processNavigateUrl(option) {
306
341
  var _a;
307
342
  const pathPieces = history.parsePath(option.url);
@@ -318,7 +353,7 @@ function processNavigateUrl(option) {
318
353
  pathPieces.pathname = parts.join('/');
319
354
  }
320
355
  // 处理自定义路由
321
- pathPieces.pathname = routesAlias.getAlias(addLeadingSlash(pathPieces.pathname));
356
+ pathPieces.pathname = routesAlias.getAlias(runtime.addLeadingSlash(pathPieces.pathname));
322
357
  // 处理 basename
323
358
  pathPieces.pathname = prependBasename(pathPieces.pathname);
324
359
  // hack fix history v5 bug: https://github.com/remix-run/history/issues/814
@@ -327,7 +362,7 @@ function processNavigateUrl(option) {
327
362
  return pathPieces;
328
363
  }
329
364
  function navigate(option, method) {
330
- return __awaiter(this, void 0, void 0, function* () {
365
+ return tslib.__awaiter(this, void 0, void 0, function* () {
331
366
  return new Promise((resolve, reject) => {
332
367
  stacks.method = method;
333
368
  const { success, complete, fail } = option;
@@ -342,6 +377,21 @@ function navigate(option, method) {
342
377
  if ('url' in option) {
343
378
  const pathPieces = processNavigateUrl(option);
344
379
  const state = { timestamp: Date.now() };
380
+ if (pathPieces.pathname) {
381
+ const originPath = routesAlias.getOrigin(pathPieces.pathname);
382
+ const pagePath = originPath.startsWith('/') ? originPath.substring(1) : originPath;
383
+ if (!RouterConfig.pages.includes(pagePath)) {
384
+ const res = { errMsg: `${method}:fail page ${pagePath} is not found` };
385
+ fail === null || fail === void 0 ? void 0 : fail(res);
386
+ complete === null || complete === void 0 ? void 0 : complete(res);
387
+ if (fail || complete) {
388
+ return resolve(res);
389
+ }
390
+ else {
391
+ return reject(res);
392
+ }
393
+ }
394
+ }
345
395
  if (method === 'navigateTo') {
346
396
  exports.history.push(pathPieces, state);
347
397
  }
@@ -355,14 +405,24 @@ function navigate(option, method) {
355
405
  }
356
406
  else if (method === 'navigateBack') {
357
407
  stacks.delta = option.delta;
358
- exports.history.go(-option.delta);
408
+ if (stacks.length > option.delta) {
409
+ exports.history.go(-option.delta);
410
+ }
411
+ else {
412
+ exports.history.go(1 - stacks.length);
413
+ }
359
414
  }
360
415
  }
361
416
  catch (error) {
362
417
  const res = { errMsg: `${method}:fail ${error.message || error}` };
363
418
  fail === null || fail === void 0 ? void 0 : fail(res);
364
419
  complete === null || complete === void 0 ? void 0 : complete(res);
365
- reject(res);
420
+ if (fail || complete) {
421
+ return resolve(res);
422
+ }
423
+ else {
424
+ return reject(res);
425
+ }
366
426
  }
367
427
  });
368
428
  });
@@ -393,47 +453,22 @@ function getCurrentPages() {
393
453
  return pages.map(e => { var _a; return (Object.assign(Object.assign({}, e), { route: ((_a = e.path) === null || _a === void 0 ? void 0 : _a.replace(/\?.*/g, '')) || '' })); });
394
454
  }
395
455
 
396
- let md;
397
- let preTitle = document.title;
398
- let isLoadDdEntry = false;
399
- function getMobileDetect() {
400
- if (!md) {
401
- md = new MobileDetect__default["default"](navigator.userAgent);
402
- }
403
- return md;
404
- }
405
- function setTitle(title) {
406
- return __awaiter(this, void 0, void 0, function* () {
407
- if (preTitle === title)
408
- return title;
409
- document.title = title;
410
- preTitle = title;
411
- if (process.env.SUPPORT_DINGTALK_NAVIGATE !== 'disabled' && isDingTalk()) {
412
- if (!isLoadDdEntry) {
413
- isLoadDdEntry = true;
414
- require('dingtalk-jsapi/platform');
415
- }
416
- const setDingTitle = require('dingtalk-jsapi/api/biz/navigation/setTitle').default;
417
- setDingTitle({ title });
418
- }
419
- return title;
420
- });
421
- }
422
- function isDingTalk() {
423
- const md = getMobileDetect();
424
- return md.match(/DingTalk/ig);
425
- }
426
-
427
456
  let pageResizeFn;
428
457
  function bindPageResize(page) {
429
458
  pageResizeFn && window.removeEventListener('resize', pageResizeFn);
430
459
  pageResizeFn = function () {
431
- page.onResize && page.onResize({
432
- size: {
433
- windowHeight: window.innerHeight,
434
- windowWidth: window.innerWidth
435
- }
436
- });
460
+ if (page.onResize) {
461
+ const mediaQuery = window.matchMedia('(orientation: portrait)');
462
+ page.onResize({
463
+ deviceOrientation: mediaQuery.matches ? 'portrait' : 'landscape',
464
+ size: {
465
+ windowHeight: window.innerHeight,
466
+ windowWidth: window.innerWidth,
467
+ screenHeight: window.screen.height,
468
+ screenWidth: window.screen.width,
469
+ }
470
+ });
471
+ }
437
472
  };
438
473
  window.addEventListener('resize', pageResizeFn, false);
439
474
  }
@@ -477,7 +512,10 @@ function getOffset() {
477
512
  */
478
513
  function loadAnimateStyle(ms = 300) {
479
514
  const css = `
480
- .taro_router .taro_page {
515
+ body {
516
+ overflow: hidden; // 防止 iOS 页面滚动
517
+ }
518
+ .taro_router > .taro_page {
481
519
  position: absolute;
482
520
  left: 0;
483
521
  top: 0;
@@ -489,52 +527,109 @@ function loadAnimateStyle(ms = 300) {
489
527
  z-index: 0;
490
528
  }
491
529
 
492
- .taro_router .taro_page.taro_tabbar_page,
493
- .taro_router .taro_page.taro_page_show.taro_page_stationed {
530
+ .taro_router > .taro_page.taro_tabbar_page,
531
+ .taro_router > .taro_page.taro_page_show.taro_page_stationed {
494
532
  transform: none;
495
533
  }
496
534
 
497
- .taro_router .taro_page.taro_page_show {
535
+ .taro_router > .taro_page.taro_page_show {
498
536
  transform: translate(0, 0);
499
- }`;
537
+ }
538
+ `;
500
539
  addStyle(css);
501
540
  }
502
541
  /**
503
542
  * 插入路由相关样式
504
543
  */
505
- function loadRouterStyle(usingWindowScroll) {
544
+ function loadRouterStyle(enableTabBar, enableWindowScroll) {
506
545
  const css = `
507
546
  .taro_router {
508
547
  position: relative;
509
548
  width: 100%;
510
549
  height: 100%;
511
- min-height: 100vh;
512
- }
513
-
514
- .taro-tabbar__container .taro_router {
515
- min-height: calc(100vh - 50px);
516
550
  }
517
551
 
518
552
  .taro_page {
519
553
  width: 100%;
520
554
  height: 100%;
521
- ${usingWindowScroll ? '' : `
555
+ ${enableWindowScroll ? '' : `
522
556
  overflow-x: hidden;
523
557
  overflow-y: scroll;
524
558
  max-height: 100vh;
525
- `}
559
+ `}
526
560
  }
527
-
528
- .taro-tabbar__container .taro-tabbar__panel {
561
+ ${enableTabBar ? `
562
+ .taro-tabbar__container > .taro-tabbar__panel {
529
563
  overflow: hidden;
530
564
  }
531
565
 
532
- .taro-tabbar__container .taro_page.taro_tabbar_page {
533
- max-height: calc(100vh - 50px);
566
+ .taro-tabbar__container > .taro-tabbar__panel > .taro_page.taro_tabbar_page {
567
+ max-height: calc(100vh - var(--taro-tabbar-height) - constant(safe-area-inset-bottom));
568
+ max-height: calc(100vh - var(--taro-tabbar-height) - env(safe-area-inset-bottom));
569
+ }
570
+
571
+ ` : ''}
572
+ .taro_page_shade,
573
+ .taro_router > .taro_page.taro_page_show.taro_page_stationed:not(.taro_page_shade):not(.taro_tabbar_page):not(:last-child) {
574
+ display: none;
534
575
  }
535
576
  `;
536
577
  addStyle(css);
537
578
  }
579
+ /**
580
+ * 插入导航栏相关的样式
581
+ */
582
+ function loadNavigationBarStyle() {
583
+ const css = `
584
+ .taro-navigation-bar-show {
585
+ background: white;
586
+ position: sticky;
587
+ z-index: 500;
588
+ top: 0;
589
+ padding-bottom: 8px;
590
+ padding-top: calc(env(safe-area-inset-top) + 8px);
591
+ display: flex;
592
+ justify-content: center;
593
+ align-items: center;
594
+ }
595
+
596
+ .taro-navigation-bar-hide {
597
+ display: none;
598
+ }
599
+
600
+ taro-navigation-bar-title {
601
+ font-size: 24px;
602
+ height: 24px;
603
+ line-height: 24px;
604
+ }
605
+
606
+ .taro-navigation-bar-no-icon > taro-navigation-bar-home {
607
+ display: none;
608
+ }
609
+
610
+ .taro-navigation-bar-no-icon > taro-navigation-bar-back {
611
+ display: none;
612
+ }
613
+
614
+ .taro-navigation-bar-home > taro-navigation-bar-home {
615
+ display: block;
616
+ left: 8px;
617
+ position: absolute;
618
+ width: 24px;
619
+ height: 24px;
620
+ }
621
+
622
+ .taro-navigation-bar-back > taro-navigation-bar-back {
623
+ display: block;
624
+ left: 8px;
625
+ position: absolute;
626
+ width: 24px;
627
+ height: 24px;
628
+ }
629
+
630
+ `;
631
+ addStyle(css);
632
+ }
538
633
  function addStyle(css) {
539
634
  if (!css)
540
635
  return;
@@ -543,38 +638,10 @@ function addStyle(css) {
543
638
  document.getElementsByTagName('head')[0].appendChild(style);
544
639
  }
545
640
 
546
- // @ts-nocheck
547
- function initTabbar(config) {
548
- if (config.tabBar == null) {
549
- return;
550
- }
551
- // TODO: custom-tab-bar
552
- components.defineCustomElementTaroTabbar();
553
- const tabbar = document.createElement('taro-tabbar');
554
- const homePage = config.entryPagePath || (config.pages ? config.pages[0] : '');
555
- tabbar.conf = config.tabBar;
556
- tabbar.conf.homePage = exports.history.location.pathname === '/' ? homePage : exports.history.location.pathname;
557
- const routerConfig = config.router;
558
- tabbar.conf.mode = routerConfig && routerConfig.mode ? routerConfig.mode : 'hash';
559
- if (routerConfig.customRoutes) {
560
- tabbar.conf.custom = true;
561
- tabbar.conf.customRoutes = routerConfig.customRoutes;
562
- }
563
- else {
564
- tabbar.conf.custom = false;
565
- tabbar.conf.customRoutes = {};
566
- }
567
- if (typeof routerConfig.basename !== 'undefined') {
568
- tabbar.conf.basename = routerConfig.basename;
569
- }
570
- const container = document.getElementById('container');
571
- container === null || container === void 0 ? void 0 : container.appendChild(tabbar);
572
- taro.initTabBarApis(config);
573
- }
574
-
575
641
  /* eslint-disable dot-notation */
576
642
  class MultiPageHandler {
577
- constructor(config) {
643
+ constructor(config, history) {
644
+ this.history = history;
578
645
  this.config = config;
579
646
  this.mount();
580
647
  }
@@ -590,7 +657,7 @@ class MultiPageHandler {
590
657
  get pageConfig() { return this.config.route; }
591
658
  get isTabBar() {
592
659
  var _a;
593
- const routePath = addLeadingSlash(stripBasename(this.pathname, this.basename));
660
+ const routePath = runtime.addLeadingSlash(runtime.stripBasename(this.pathname, this.basename));
594
661
  const pagePath = ((_a = Object.entries(this.customRoutes).find(([, target]) => {
595
662
  if (typeof target === 'string') {
596
663
  return target === routePath;
@@ -617,43 +684,22 @@ class MultiPageHandler {
617
684
  getQuery(search = '', options = {}) {
618
685
  search = search ? `${search}&${this.search}` : this.search;
619
686
  const query = search
620
- ? queryString__default["default"].parse(search)
687
+ ? queryString.parse(search)
621
688
  : {};
622
689
  return Object.assign(Object.assign({}, query), options);
623
690
  }
624
- mount() {
625
- setHistoryMode(this.routerMode, this.router.basename);
626
- loadRouterStyle(this.usingWindowScroll);
627
- const appId = this.appId;
628
- let app = document.getElementById(appId);
629
- let isPosition = true;
630
- if (!app) {
631
- app = document.createElement('div');
632
- app.id = appId;
633
- isPosition = false;
634
- }
635
- const appWrapper = (app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body;
636
- app.classList.add('taro_router');
637
- if (this.tabBarList.length > 1) {
638
- const container = document.createElement('div');
639
- container.classList.add('taro-tabbar__container');
640
- container.id = 'container';
641
- const panel = document.createElement('div');
642
- panel.classList.add('taro-tabbar__panel');
643
- panel.appendChild(app.cloneNode(true));
644
- container.appendChild(panel);
645
- if (!isPosition) {
646
- appWrapper.appendChild(container);
647
- }
648
- else {
649
- appWrapper.replaceChild(container, app);
650
- }
651
- initTabbar(this.config);
652
- }
653
- else {
654
- if (!isPosition)
655
- appWrapper.appendChild(app);
691
+ isDefaultNavigationStyle() {
692
+ var _a, _b;
693
+ let style = (_a = this.config.window) === null || _a === void 0 ? void 0 : _a.navigationStyle;
694
+ if (typeof ((_b = this.pageConfig) === null || _b === void 0 ? void 0 : _b.navigationStyle) === 'string') {
695
+ style = this.pageConfig.navigationStyle;
656
696
  }
697
+ return style !== 'custom';
698
+ }
699
+ mount() {
700
+ setHistory(this.history, this.basename);
701
+ // Note: 注入页面样式
702
+ loadRouterStyle(this.tabBarList.length > 1, this.usingWindowScroll);
657
703
  }
658
704
  onReady(page, onLoad = true) {
659
705
  var _a;
@@ -683,13 +729,17 @@ class MultiPageHandler {
683
729
  return;
684
730
  (_a = page.onLoad) === null || _a === void 0 ? void 0 : _a.call(page, this.getQuery('', page.options), () => {
685
731
  var _a;
732
+ const pageEl = this.getPageContainer(page);
686
733
  if (this.isTabBar) {
687
- const pageEl = this.getPageContainer(page);
688
734
  pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.add('taro_tabbar_page');
689
735
  }
736
+ if (this.isDefaultNavigationStyle()) {
737
+ pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.add('taro_navigation_page');
738
+ }
690
739
  this.onReady(page, true);
691
740
  (_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
692
741
  this.bindPageEvents(page, pageConfig);
742
+ this.triggerRouterChange();
693
743
  });
694
744
  }
695
745
  getPageContainer(page) {
@@ -717,6 +767,19 @@ class MultiPageHandler {
717
767
  bindPageScroll(page, scrollEl, distance);
718
768
  bindPageResize(page);
719
769
  }
770
+ triggerRouterChange() {
771
+ /**
772
+ * @tarojs/runtime 中生命周期跑在 promise 中,所以这里需要 setTimeout 延迟事件调用
773
+ * TODO 考虑将生命周期返回 Promise,用于处理相关事件调用顺序
774
+ */
775
+ setTimeout(() => {
776
+ runtime.eventCenter.trigger('__afterTaroRouterChange', {
777
+ toLocation: {
778
+ path: this.pathname
779
+ }
780
+ });
781
+ }, 0);
782
+ }
720
783
  }
721
784
 
722
785
  const createStampId$1 = runtime.incrementId();
@@ -729,14 +792,15 @@ const launchStampId$1 = createStampId$1();
729
792
  * - TabBar 会多次加载
730
793
  * - 不支持路由动画
731
794
  */
732
- function createMultiRouter(app, config, framework) {
795
+ function createMultiRouter(history, app, config, framework) {
733
796
  var _a, _b, _c, _d, _e, _f;
734
- return __awaiter(this, void 0, void 0, function* () {
797
+ return tslib.__awaiter(this, void 0, void 0, function* () {
735
798
  if (typeof app.onUnhandledRejection === 'function') {
736
799
  window.addEventListener('unhandledrejection', app.onUnhandledRejection);
737
800
  }
801
+ runtime.eventCenter.on('__taroH5SetNavigationTitle', setMpaTitle);
738
802
  RouterConfig.config = config;
739
- const handler = new MultiPageHandler(config);
803
+ const handler = new MultiPageHandler(config, history);
740
804
  const launchParam = {
741
805
  path: config.pageName,
742
806
  query: handler.getQuery(launchStampId$1),
@@ -768,7 +832,7 @@ function createMultiRouter(app, config, framework) {
768
832
  return;
769
833
  let enablePullDownRefresh = ((_c = config === null || config === void 0 ? void 0 : config.window) === null || _c === void 0 ? void 0 : _c.enablePullDownRefresh) || false;
770
834
  if (pageConfig) {
771
- setTitle((_d = pageConfig.navigationBarTitleText) !== null && _d !== void 0 ? _d : document.title);
835
+ setMpaTitle((_d = pageConfig.navigationBarTitleText) !== null && _d !== void 0 ? _d : document.title);
772
836
  if (typeof pageConfig.enablePullDownRefresh === 'boolean') {
773
837
  enablePullDownRefresh = pageConfig.enablePullDownRefresh;
774
838
  }
@@ -780,24 +844,231 @@ function createMultiRouter(app, config, framework) {
780
844
  const page = runtime.createPageConfig(enablePullDownRefresh ? runtime.hooks.call('createPullDownComponent', el, pathName, framework, handler.PullDownRefresh) : el, pathName + runtime.stringify(launchParam), {}, loadConfig);
781
845
  handler.load(page, pageConfig);
782
846
  (_f = app.onShow) === null || _f === void 0 ? void 0 : _f.call(app, launchParam);
847
+ window.addEventListener('visibilitychange', () => {
848
+ var _a, _b;
849
+ if (document.visibilityState === 'visible') {
850
+ (_a = app.onShow) === null || _a === void 0 ? void 0 : _a.call(app, launchParam);
851
+ }
852
+ else {
853
+ (_b = app.onHide) === null || _b === void 0 ? void 0 : _b.call(app, launchParam);
854
+ }
855
+ });
783
856
  });
784
857
  }
785
858
 
786
- /* eslint-disable dot-notation */
787
- function setDisplay(el, type = '') {
788
- if (el) {
789
- el.style.display = type;
859
+ class NavigationBarHandler {
860
+ constructor(pageContext) {
861
+ this.isLoadDdEntry = false;
862
+ this.cache = {};
863
+ this.pageContext = pageContext;
864
+ this.init();
865
+ loadNavigationBarStyle();
866
+ runtime.eventCenter.on('__taroH5SetNavigationTitle', (title) => {
867
+ this.setTitle(title);
868
+ });
869
+ runtime.eventCenter.on('__taroH5setNavigationBarColor', ({ backgroundColor, frontColor }) => {
870
+ if (typeof backgroundColor === 'string')
871
+ this.setNavigationBarBackground(backgroundColor);
872
+ if (typeof frontColor === 'string')
873
+ this.setNavigationBarTextStyle(frontColor);
874
+ });
875
+ }
876
+ toHomeFn() {
877
+ reLaunch({ url: this.pageContext.homePage });
878
+ }
879
+ backFn() {
880
+ navigateBack();
881
+ }
882
+ get homeBtnElement() {
883
+ var _a;
884
+ if (!this.navigationBarElement)
885
+ return null;
886
+ return (_a = this.navigationBarElement.getElementsByTagName('taro-navigation-bar-home')) === null || _a === void 0 ? void 0 : _a[0];
887
+ }
888
+ get backBtnElement() {
889
+ var _a;
890
+ if (!this.navigationBarElement)
891
+ return null;
892
+ return (_a = this.navigationBarElement.getElementsByTagName('taro-navigation-bar-back')) === null || _a === void 0 ? void 0 : _a[0];
893
+ }
894
+ get titleElement() {
895
+ var _a;
896
+ if (!this.navigationBarElement)
897
+ return null;
898
+ return (_a = this.navigationBarElement.getElementsByTagName('taro-navigation-bar-title')) === null || _a === void 0 ? void 0 : _a[0];
899
+ }
900
+ init() {
901
+ var _a, _b;
902
+ this.setNavigationBarElement();
903
+ if (!this.navigationBarElement)
904
+ return;
905
+ (_a = this.homeBtnElement) === null || _a === void 0 ? void 0 : _a.addEventListener('click', this.toHomeFn.bind(this));
906
+ (_b = this.backBtnElement) === null || _b === void 0 ? void 0 : _b.addEventListener('click', this.backFn.bind(this));
907
+ }
908
+ setNavigationBarElement() {
909
+ var _a;
910
+ this.navigationBarElement = (_a = document.getElementsByTagName('taro-navigation-bar-wrap')) === null || _a === void 0 ? void 0 : _a[0];
911
+ }
912
+ load() {
913
+ this.setCacheValue();
914
+ this.setTitle();
915
+ this.setNavigationBarVisible();
916
+ this.setFnBtnState();
917
+ this.setNavigationBarBackground();
918
+ this.setNavigationBarTextStyle();
919
+ }
920
+ setCacheValue() {
921
+ const currentPage = this.pageContext.currentPage;
922
+ if (typeof this.cache[currentPage] !== 'object') {
923
+ this.cache[currentPage] = {};
924
+ }
925
+ }
926
+ setFnBtnState() {
927
+ const currentRouter = this.pageContext.currentPage;
928
+ if (this.pageContext.isTabBar(currentRouter) || this.pageContext.homePage === currentRouter) {
929
+ this.fnBtnToggleToNone();
930
+ }
931
+ else if (stacks.length > 1) {
932
+ this.fnBtnToggleToBack();
933
+ }
934
+ else {
935
+ this.fnBtnToggleToHome();
936
+ }
937
+ }
938
+ setNavigationBarBackground(backgroundColor) {
939
+ var _a, _b, _c;
940
+ if (!this.navigationBarElement)
941
+ return;
942
+ const currentPage = this.pageContext.currentPage;
943
+ let color;
944
+ if (typeof backgroundColor === 'string') {
945
+ color = backgroundColor;
946
+ this.cache[currentPage] &&
947
+ (this.cache[currentPage].backgroundColor = color);
948
+ }
949
+ else {
950
+ const cacheValue = (_a = this.cache[currentPage]) === null || _a === void 0 ? void 0 : _a.backgroundColor;
951
+ if (typeof cacheValue === 'string') {
952
+ color = cacheValue;
953
+ }
954
+ else {
955
+ color = ((_c = (_b = this.pageContext.config) === null || _b === void 0 ? void 0 : _b.window) === null || _c === void 0 ? void 0 : _c.navigationBarBackgroundColor) || '#000000';
956
+ this.cache[currentPage] &&
957
+ (this.cache[currentPage].backgroundColor = color);
958
+ }
959
+ }
960
+ this.navigationBarElement.style.background = color;
961
+ }
962
+ setNavigationBarTextStyle(fontColor) {
963
+ var _a, _b, _c;
964
+ if (!this.navigationBarElement)
965
+ return;
966
+ const currentPage = this.pageContext.currentPage;
967
+ let color;
968
+ if (typeof fontColor === 'string') {
969
+ color = fontColor;
970
+ this.cache[currentPage] &&
971
+ (this.cache[currentPage].fontColor = color);
972
+ }
973
+ else {
974
+ const cacheValue = (_a = this.cache[currentPage]) === null || _a === void 0 ? void 0 : _a.fontColor;
975
+ if (typeof cacheValue === 'string') {
976
+ color = cacheValue;
977
+ }
978
+ else {
979
+ color = ((_c = (_b = this.pageContext.config) === null || _b === void 0 ? void 0 : _b.window) === null || _c === void 0 ? void 0 : _c.navigationBarTextStyle) || 'white';
980
+ this.cache[currentPage] &&
981
+ (this.cache[currentPage].fontColor = color);
982
+ }
983
+ }
984
+ this.navigationBarElement.style.color = color;
985
+ }
986
+ setTitle(title) {
987
+ var _a, _b, _c;
988
+ const currentPage = this.pageContext.currentPage;
989
+ let proceedTitle;
990
+ if (typeof title === 'string') {
991
+ proceedTitle = title;
992
+ this.cache[currentPage] &&
993
+ (this.cache[currentPage].title = proceedTitle);
994
+ }
995
+ else {
996
+ const cacheValue = (_a = this.cache[currentPage]) === null || _a === void 0 ? void 0 : _a.title;
997
+ if (typeof cacheValue === 'string') {
998
+ proceedTitle = cacheValue;
999
+ }
1000
+ else {
1001
+ proceedTitle = (_c = (_b = this.pageContext.pageConfig) === null || _b === void 0 ? void 0 : _b.navigationBarTitleText) !== null && _c !== void 0 ? _c : document.title;
1002
+ this.cache[currentPage] &&
1003
+ (this.cache[currentPage].title = proceedTitle);
1004
+ }
1005
+ }
1006
+ if (process.env.SUPPORT_DINGTALK_NAVIGATE !== 'disabled' && isDingTalk()) {
1007
+ if (!this.isLoadDdEntry) {
1008
+ this.isLoadDdEntry = true;
1009
+ require('dingtalk-jsapi/platform');
1010
+ }
1011
+ const setDingTitle = require('dingtalk-jsapi/api/biz/navigation/setTitle').default;
1012
+ setDingTitle({ proceedTitle });
1013
+ }
1014
+ document.title = proceedTitle;
1015
+ if (!this.titleElement)
1016
+ return;
1017
+ this.titleElement.innerHTML = proceedTitle;
1018
+ }
1019
+ fnBtnToggleToHome() {
1020
+ if (!this.navigationBarElement)
1021
+ return;
1022
+ this.navigationBarElement.classList.add('taro-navigation-bar-home');
1023
+ this.navigationBarElement.classList.remove('taro-navigation-bar-back');
1024
+ }
1025
+ fnBtnToggleToBack() {
1026
+ if (!this.navigationBarElement)
1027
+ return;
1028
+ this.navigationBarElement.classList.remove('taro-navigation-bar-home');
1029
+ this.navigationBarElement.classList.add('taro-navigation-bar-back');
1030
+ }
1031
+ fnBtnToggleToNone() {
1032
+ if (!this.navigationBarElement)
1033
+ return;
1034
+ this.navigationBarElement.classList.remove('taro-navigation-bar-home');
1035
+ this.navigationBarElement.classList.remove('taro-navigation-bar-back');
1036
+ }
1037
+ setNavigationBarVisible(show) {
1038
+ var _a, _b;
1039
+ let shouldShow;
1040
+ if (typeof show === 'boolean') {
1041
+ shouldShow = show;
1042
+ }
1043
+ else {
1044
+ shouldShow = (_a = this.pageContext.config.window) === null || _a === void 0 ? void 0 : _a.navigationStyle;
1045
+ if (typeof ((_b = this.pageContext.pageConfig) === null || _b === void 0 ? void 0 : _b.navigationStyle) === 'string') {
1046
+ shouldShow = this.pageContext.pageConfig.navigationStyle;
1047
+ }
1048
+ }
1049
+ if (shouldShow === 'default') {
1050
+ this.navigationBarElement.classList.add('taro-navigation-bar-show');
1051
+ this.navigationBarElement.classList.remove('taro-navigation-bar-hide');
1052
+ }
1053
+ else {
1054
+ this.navigationBarElement.classList.add('taro-navigation-bar-hide');
1055
+ this.navigationBarElement.classList.remove('taro-navigation-bar-show');
1056
+ }
790
1057
  }
791
1058
  }
1059
+
1060
+ /* eslint-disable dot-notation */
792
1061
  class PageHandler {
793
- constructor(config) {
1062
+ constructor(config, history) {
1063
+ this.history = history;
794
1064
  this.defaultAnimation = { duration: 300, delay: 50 };
795
1065
  this.config = config;
796
- this.homePage = getHomePage(this.routes[0].path, this.basename, this.customRoutes, this.config.entryPagePath);
1066
+ this.homePage = runtime.getHomePage(this.routes[0].path, this.basename, this.customRoutes, this.config.entryPagePath);
797
1067
  this.mount();
1068
+ this.navigationBarHandler = new NavigationBarHandler(this);
798
1069
  }
799
1070
  get currentPage() {
800
- const routePath = getCurrentPage(this.routerMode, this.basename);
1071
+ const routePath = runtime.getCurrentPage(this.routerMode, this.basename);
801
1072
  return routePath === '/' ? this.homePage : routePath;
802
1073
  }
803
1074
  get appId() { return this.config.appId || 'app'; }
@@ -828,17 +1099,17 @@ class PageHandler {
828
1099
  get pathname() { return this.router.pathname; }
829
1100
  get basename() { return this.router.basename || ''; }
830
1101
  get pageConfig() {
831
- const routePath = addLeadingSlash(stripBasename(this.pathname, this.basename));
832
- const homePage = addLeadingSlash(this.homePage);
1102
+ const routePath = runtime.addLeadingSlash(runtime.stripBasename(this.pathname, this.basename));
1103
+ const homePage = runtime.addLeadingSlash(this.homePage);
833
1104
  return this.routes.find(r => {
834
1105
  var _a;
835
- const pagePath = addLeadingSlash(r.path);
1106
+ const pagePath = runtime.addLeadingSlash(r.path);
836
1107
  return [pagePath, homePage].includes(routePath) || ((_a = routesAlias.getConfig(pagePath)) === null || _a === void 0 ? void 0 : _a.includes(routePath));
837
1108
  });
838
1109
  }
839
1110
  isTabBar(pathname) {
840
1111
  var _a;
841
- const routePath = addLeadingSlash(stripBasename(pathname, this.basename)).split('?')[0];
1112
+ const routePath = runtime.addLeadingSlash(runtime.stripBasename(pathname, this.basename)).split('?')[0];
842
1113
  const pagePath = ((_a = Object.entries(this.customRoutes).find(([, target]) => {
843
1114
  if (typeof target === 'string') {
844
1115
  return target === routePath;
@@ -848,11 +1119,19 @@ class PageHandler {
848
1119
  }
849
1120
  return false;
850
1121
  })) === null || _a === void 0 ? void 0 : _a[0]) || routePath;
851
- return !!pagePath && this.tabBarList.some(t => stripTrailing(t.pagePath) === pagePath);
1122
+ return !!pagePath && this.tabBarList.some(t => runtime.stripTrailing(t.pagePath) === pagePath);
1123
+ }
1124
+ isDefaultNavigationStyle() {
1125
+ var _a, _b;
1126
+ let style = (_a = this.config.window) === null || _a === void 0 ? void 0 : _a.navigationStyle;
1127
+ if (typeof ((_b = this.pageConfig) === null || _b === void 0 ? void 0 : _b.navigationStyle) === 'string') {
1128
+ style = this.pageConfig.navigationStyle;
1129
+ }
1130
+ return style !== 'custom';
852
1131
  }
853
1132
  isSamePage(page) {
854
- const routePath = stripBasename(this.pathname, this.basename);
855
- const pagePath = stripBasename(page === null || page === void 0 ? void 0 : page.path, this.basename);
1133
+ const routePath = runtime.stripBasename(this.pathname, this.basename);
1134
+ const pagePath = runtime.stripBasename(page === null || page === void 0 ? void 0 : page.path, this.basename);
856
1135
  return pagePath.startsWith(routePath + '?');
857
1136
  }
858
1137
  get search() {
@@ -882,46 +1161,17 @@ class PageHandler {
882
1161
  getQuery(stamp = '', search = '', options = {}) {
883
1162
  search = search ? `${search}&${this.search}` : this.search;
884
1163
  const query = search
885
- ? queryString__default["default"].parse(search, { decode: false })
1164
+ ? queryString.parse(search, { decode: false })
886
1165
  : {};
887
1166
  query.stamp = stamp;
888
1167
  return Object.assign(Object.assign({}, query), options);
889
1168
  }
890
1169
  mount() {
891
- setHistoryMode(this.routerMode, this.router.basename);
1170
+ setHistory(this.history, this.basename);
892
1171
  this.pathname = exports.history.location.pathname;
1172
+ // Note: 注入页面样式
893
1173
  this.animation && loadAnimateStyle(this.animationDuration);
894
- loadRouterStyle(this.usingWindowScroll);
895
- const appId = this.appId;
896
- let app = document.getElementById(appId);
897
- let isPosition = true;
898
- if (!app) {
899
- app = document.createElement('div');
900
- app.id = appId;
901
- isPosition = false;
902
- }
903
- const appWrapper = (app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body;
904
- app.classList.add('taro_router');
905
- if (this.tabBarList.length > 1) {
906
- const container = document.createElement('div');
907
- container.classList.add('taro-tabbar__container');
908
- container.id = 'container';
909
- const panel = document.createElement('div');
910
- panel.classList.add('taro-tabbar__panel');
911
- panel.appendChild(app.cloneNode(true));
912
- container.appendChild(panel);
913
- if (!isPosition) {
914
- appWrapper.appendChild(container);
915
- }
916
- else {
917
- appWrapper.replaceChild(container, app);
918
- }
919
- initTabbar(this.config);
920
- }
921
- else {
922
- if (!isPosition)
923
- appWrapper.appendChild(app);
924
- }
1174
+ loadRouterStyle(this.tabBarList.length > 1, this.usingWindowScroll);
925
1175
  }
926
1176
  onReady(page, onLoad = true) {
927
1177
  var _a;
@@ -954,21 +1204,26 @@ class PageHandler {
954
1204
  const param = this.getQuery(stampId, '', page.options);
955
1205
  let pageEl = this.getPageContainer(page);
956
1206
  if (pageEl) {
957
- setDisplay(pageEl);
1207
+ pageEl.classList.remove('taro_page_shade');
958
1208
  this.isTabBar(this.pathname) && pageEl.classList.add('taro_tabbar_page');
1209
+ this.isDefaultNavigationStyle() && pageEl.classList.add('taro_navigation_page');
959
1210
  this.addAnimation(pageEl, pageNo === 0);
960
1211
  (_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
1212
+ this.navigationBarHandler.load();
961
1213
  this.bindPageEvents(page, pageConfig);
962
1214
  this.triggerRouterChange();
963
1215
  }
964
1216
  else {
1217
+ // FIXME 在 iOS 端快速切换页面时,可能不会执行回调注入对应类名导致 TabBar 白屏
965
1218
  (_b = page.onLoad) === null || _b === void 0 ? void 0 : _b.call(page, param, () => {
966
1219
  var _a;
967
1220
  pageEl = this.getPageContainer(page);
968
1221
  this.isTabBar(this.pathname) && (pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.add('taro_tabbar_page'));
1222
+ this.isDefaultNavigationStyle() && (pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.add('taro_navigation_page'));
969
1223
  this.addAnimation(pageEl, pageNo === 0);
970
- this.onReady(page, true);
971
1224
  (_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
1225
+ this.navigationBarHandler.load();
1226
+ this.onReady(page, true);
972
1227
  this.bindPageEvents(page, pageConfig);
973
1228
  this.triggerRouterChange();
974
1229
  });
@@ -1019,9 +1274,10 @@ class PageHandler {
1019
1274
  const param = this.getQuery(page['$taroParams']['stamp'], '', page.options);
1020
1275
  let pageEl = this.getPageContainer(page);
1021
1276
  if (pageEl) {
1022
- setDisplay(pageEl);
1277
+ pageEl.classList.remove('taro_page_shade');
1023
1278
  this.addAnimation(pageEl, pageNo === 0);
1024
1279
  (_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
1280
+ this.navigationBarHandler.load();
1025
1281
  this.bindPageEvents(page, pageConfig);
1026
1282
  this.triggerRouterChange();
1027
1283
  }
@@ -1030,8 +1286,9 @@ class PageHandler {
1030
1286
  var _a;
1031
1287
  pageEl = this.getPageContainer(page);
1032
1288
  this.addAnimation(pageEl, pageNo === 0);
1033
- this.onReady(page, false);
1034
1289
  (_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
1290
+ this.navigationBarHandler.load();
1291
+ this.onReady(page, false);
1035
1292
  this.bindPageEvents(page, pageConfig);
1036
1293
  this.triggerRouterChange();
1037
1294
  });
@@ -1047,12 +1304,12 @@ class PageHandler {
1047
1304
  if (this.hideTimer) {
1048
1305
  clearTimeout(this.hideTimer);
1049
1306
  this.hideTimer = null;
1050
- setDisplay(this.lastHidePage, 'none');
1307
+ pageEl.classList.add('taro_page_shade');
1051
1308
  }
1052
1309
  this.lastHidePage = pageEl;
1053
1310
  this.hideTimer = setTimeout(() => {
1054
1311
  this.hideTimer = null;
1055
- setDisplay(this.lastHidePage, 'none');
1312
+ pageEl.classList.add('taro_page_shade');
1056
1313
  }, this.animationDuration + this.animationDelay);
1057
1314
  (_a = page.onHide) === null || _a === void 0 ? void 0 : _a.call(page);
1058
1315
  }
@@ -1118,24 +1375,24 @@ class PageHandler {
1118
1375
 
1119
1376
  const createStampId = runtime.incrementId();
1120
1377
  let launchStampId = createStampId();
1121
- function createRouter(app, config, framework) {
1378
+ function createRouter(history$1, app, config, framework) {
1122
1379
  var _a, _b;
1123
1380
  if (typeof app.onUnhandledRejection === 'function') {
1124
1381
  window.addEventListener('unhandledrejection', app.onUnhandledRejection);
1125
1382
  }
1126
1383
  RouterConfig.config = config;
1127
- const handler = new PageHandler(config);
1384
+ const handler = new PageHandler(config, history$1);
1128
1385
  routesAlias.set(handler.router.customRoutes);
1129
1386
  const basename = handler.router.basename;
1130
1387
  const routes = handler.routes.map(route => {
1131
- const routePath = addLeadingSlash(route.path);
1388
+ const routePath = runtime.addLeadingSlash(route.path);
1132
1389
  const paths = routesAlias.getAll(routePath);
1133
1390
  return {
1134
1391
  path: paths.length < 1 ? routePath : paths,
1135
1392
  action: route.load
1136
1393
  };
1137
1394
  });
1138
- const router = new UniversalRouter__default["default"](routes, { baseUrl: basename || '' });
1395
+ const router = new UniversalRouter(routes, { baseUrl: basename || '' });
1139
1396
  const launchParam = {
1140
1397
  path: handler.currentPage,
1141
1398
  query: handler.getQuery(launchStampId),
@@ -1146,8 +1403,8 @@ function createRouter(app, config, framework) {
1146
1403
  runtime.eventCenter.trigger('__taroRouterLaunch', launchParam);
1147
1404
  (_a = app.onLaunch) === null || _a === void 0 ? void 0 : _a.call(app, launchParam);
1148
1405
  app.onError && window.addEventListener('error', e => { var _a; return (_a = app.onError) === null || _a === void 0 ? void 0 : _a.call(app, e.message); });
1149
- const render = ({ location, action }) => __awaiter(this, void 0, void 0, function* () {
1150
- var _c, _d, _e, _f, _g, _h;
1406
+ const render = ({ location, action }) => tslib.__awaiter(this, void 0, void 0, function* () {
1407
+ var _c, _d, _e, _f, _g, _h, _j, _k;
1151
1408
  handler.pathname = decodeURI(location.pathname);
1152
1409
  if ((_c = window.__taroAppConfig) === null || _c === void 0 ? void 0 : _c.usingWindowScroll)
1153
1410
  window.scrollTo(0, 0);
@@ -1176,22 +1433,34 @@ function createRouter(app, config, framework) {
1176
1433
  window.location.reload();
1177
1434
  }
1178
1435
  else {
1179
- throw new Error(error);
1436
+ throw error;
1180
1437
  }
1181
1438
  }
1182
1439
  if (!element)
1183
1440
  return;
1184
1441
  const pageConfig = handler.pageConfig;
1185
1442
  let enablePullDownRefresh = ((_e = config === null || config === void 0 ? void 0 : config.window) === null || _e === void 0 ? void 0 : _e.enablePullDownRefresh) || false;
1443
+ let navigationStyle = ((_f = config === null || config === void 0 ? void 0 : config.window) === null || _f === void 0 ? void 0 : _f.navigationStyle) || 'default';
1444
+ let navigationBarTextStyle = ((_g = config === null || config === void 0 ? void 0 : config.window) === null || _g === void 0 ? void 0 : _g.navigationBarTextStyle) || 'white';
1445
+ let navigationBarBackgroundColor = ((_h = config === null || config === void 0 ? void 0 : config.window) === null || _h === void 0 ? void 0 : _h.navigationBarBackgroundColor) || '#000000';
1186
1446
  if (pageConfig) {
1187
- setTitle((_f = pageConfig.navigationBarTitleText) !== null && _f !== void 0 ? _f : document.title);
1188
1447
  if (typeof pageConfig.enablePullDownRefresh === 'boolean') {
1189
1448
  enablePullDownRefresh = pageConfig.enablePullDownRefresh;
1190
1449
  }
1450
+ if (typeof pageConfig.navigationStyle === 'string') {
1451
+ navigationStyle = pageConfig.navigationStyle;
1452
+ }
1453
+ if (typeof pageConfig.navigationBarTextStyle === 'string') {
1454
+ navigationBarTextStyle = pageConfig.navigationBarTextStyle;
1455
+ }
1456
+ if (typeof pageConfig.navigationBarBackgroundColor === 'string') {
1457
+ navigationBarBackgroundColor = pageConfig.navigationBarBackgroundColor;
1458
+ }
1191
1459
  }
1460
+ runtime.eventCenter.trigger('__taroSetNavigationStyle', navigationStyle, navigationBarTextStyle, navigationBarBackgroundColor);
1192
1461
  const currentPage = runtime.Current.page;
1193
1462
  const pathname = handler.pathname;
1194
- const methodName = (_g = stacks.method) !== null && _g !== void 0 ? _g : '';
1463
+ const methodName = (_j = stacks.method) !== null && _j !== void 0 ? _j : '';
1195
1464
  const cacheTabs = stacks.getTabs();
1196
1465
  let shouldLoad = false;
1197
1466
  stacks.method = '';
@@ -1257,7 +1526,7 @@ function createRouter(app, config, framework) {
1257
1526
  shouldLoad = true;
1258
1527
  }
1259
1528
  if (shouldLoad || stacks.length < 1) {
1260
- const el = (_h = element.default) !== null && _h !== void 0 ? _h : element;
1529
+ const el = (_k = element.default) !== null && _k !== void 0 ? _k : element;
1261
1530
  const loadConfig = Object.assign({}, pageConfig);
1262
1531
  const stacksIndex = stacks.length;
1263
1532
  delete loadConfig['path'];
@@ -1276,21 +1545,90 @@ function createRouter(app, config, framework) {
1276
1545
  handler.load(page, pageConfig, pageStampId, stacksIndex);
1277
1546
  }
1278
1547
  });
1279
- const routePath = addLeadingSlash(stripBasename(exports.history.location.pathname, handler.basename));
1548
+ const routePath = runtime.addLeadingSlash(runtime.stripBasename(history$1.location.pathname, handler.basename));
1280
1549
  if (routePath === '/') {
1281
- exports.history.replace(prependBasename(handler.homePage + exports.history.location.search));
1550
+ history$1.replace(prependBasename(handler.homePage + history$1.location.search));
1282
1551
  }
1283
- render({ location: exports.history.location, action: history.Action.Push });
1552
+ render({ location: history$1.location, action: history.Action.Push });
1284
1553
  (_b = app.onShow) === null || _b === void 0 ? void 0 : _b.call(app, launchParam);
1285
- return exports.history.listen(render);
1554
+ window.addEventListener('visibilitychange', () => {
1555
+ var _a, _b;
1556
+ if (document.visibilityState === 'visible') {
1557
+ (_a = app.onShow) === null || _a === void 0 ? void 0 : _a.call(app, launchParam);
1558
+ }
1559
+ else {
1560
+ (_b = app.onHide) === null || _b === void 0 ? void 0 : _b.call(app, launchParam);
1561
+ }
1562
+ });
1563
+ return history$1.listen(render);
1564
+ }
1565
+
1566
+ function handleAppMount(config, _, appId = config.appId || 'app') {
1567
+ let app = document.getElementById(appId);
1568
+ let isPosition = true;
1569
+ if (!app) {
1570
+ app = document.createElement('div');
1571
+ app.id = appId;
1572
+ isPosition = false;
1573
+ }
1574
+ const appWrapper = (app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body;
1575
+ app.classList.add('taro_router');
1576
+ if (!isPosition)
1577
+ appWrapper.appendChild(app);
1578
+ initNavigationBar(appWrapper);
1579
+ }
1580
+ function handleAppMountWithTabbar(config, history, appId = config.appId || 'app') {
1581
+ let app = document.getElementById(appId);
1582
+ let isPosition = true;
1583
+ if (!app) {
1584
+ app = document.createElement('div');
1585
+ app.id = appId;
1586
+ isPosition = false;
1587
+ }
1588
+ const appWrapper = (app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body;
1589
+ app.classList.add('taro_router');
1590
+ const container = document.createElement('div');
1591
+ container.classList.add('taro-tabbar__container');
1592
+ container.id = 'container';
1593
+ const panel = document.createElement('div');
1594
+ panel.classList.add('taro-tabbar__panel');
1595
+ panel.appendChild(app.cloneNode(true));
1596
+ container.appendChild(panel);
1597
+ if (!isPosition) {
1598
+ appWrapper.appendChild(container);
1599
+ }
1600
+ else {
1601
+ appWrapper.replaceChild(container, app);
1602
+ }
1603
+ initTabbar(config, history);
1604
+ initNavigationBar(container);
1286
1605
  }
1287
1606
 
1607
+ Object.defineProperty(exports, 'createBrowserHistory', {
1608
+ enumerable: true,
1609
+ get: function () { return history.createBrowserHistory; }
1610
+ });
1611
+ Object.defineProperty(exports, 'createHashHistory', {
1612
+ enumerable: true,
1613
+ get: function () { return history.createHashHistory; }
1614
+ });
1615
+ exports.createMpaHistory = createMpaHistory;
1288
1616
  exports.createMultiRouter = createMultiRouter;
1289
1617
  exports.createRouter = createRouter;
1290
1618
  exports.getCurrentPages = getCurrentPages;
1619
+ exports.handleAppMount = handleAppMount;
1620
+ exports.handleAppMountWithTabbar = handleAppMountWithTabbar;
1621
+ exports.isDingTalk = isDingTalk;
1622
+ exports.isWeixin = isWeixin;
1291
1623
  exports.navigateBack = navigateBack;
1292
1624
  exports.navigateTo = navigateTo;
1625
+ exports.prependBasename = prependBasename;
1293
1626
  exports.reLaunch = reLaunch;
1294
1627
  exports.redirectTo = redirectTo;
1628
+ exports.routesAlias = routesAlias;
1629
+ exports.setHistory = setHistory;
1630
+ exports.setHistoryMode = setHistoryMode;
1631
+ exports.setMpaTitle = setMpaTitle;
1632
+ exports.setNavigationBarStyle = setNavigationBarStyle;
1633
+ exports.setTitle = setTitle;
1295
1634
  exports.switchTab = switchTab;
1296
- //# sourceMappingURL=index.cjs.js.map