@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.esm.js CHANGED
@@ -1,94 +1,65 @@
1
- import { createBrowserHistory, createHashHistory, Action, parsePath } from 'history';
2
- import { Current, incrementId, eventCenter, createPageConfig, hooks, stringify, requestAnimationFrame as requestAnimationFrame$1 } from '@tarojs/runtime';
3
- import MobileDetect from 'mobile-detect';
4
- import queryString from 'query-string';
5
1
  import { defineCustomElementTaroTabbar } from '@tarojs/components/dist/components';
6
2
  import { initTabBarApis } from '@tarojs/taro';
3
+ import { __awaiter } from 'tslib';
4
+ import { eventCenter, addLeadingSlash, Current, stripBasename, incrementId, createPageConfig, hooks, stringify, getHomePage, getCurrentPage, stripTrailing, requestAnimationFrame as requestAnimationFrame$1 } from '@tarojs/runtime';
5
+ import { createBrowserHistory, createHashHistory, Action, parsePath } from 'history';
6
+ export { createBrowserHistory, createHashHistory } from 'history';
7
+ import queryString from 'query-string';
7
8
  import UniversalRouter from 'universal-router';
8
9
 
9
- /******************************************************************************
10
- Copyright (c) Microsoft Corporation.
11
-
12
- Permission to use, copy, modify, and/or distribute this software for any
13
- purpose with or without fee is hereby granted.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
16
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
17
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
18
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
19
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
20
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
21
- PERFORMANCE OF THIS SOFTWARE.
22
- ***************************************************************************** */
23
-
24
- function __awaiter(thisArg, _arguments, P, generator) {
25
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
26
- return new (P || (P = Promise))(function (resolve, reject) {
27
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
28
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
29
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
30
- step((generator = generator.apply(thisArg, _arguments || [])).next());
31
- });
10
+ const home_svg_str = `
11
+ <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
12
+ <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"/>
13
+ </svg>
14
+ `;
15
+ const back_svg_str = `
16
+ <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
17
+ <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"/>
18
+ </svg>
19
+
20
+ `;
21
+ function initNavigationBar(container) {
22
+ const navigationBar = document.createElement('taro-navigation-bar-wrap');
23
+ navigationBar.classList.add('taro-navigation-bar-no-icon');
24
+ const navigationBarBackBtn = document.createElement('taro-navigation-bar-back');
25
+ const navigationBarHomeBtn = document.createElement('taro-navigation-bar-home');
26
+ navigationBarBackBtn.innerHTML = back_svg_str;
27
+ navigationBarHomeBtn.innerHTML = home_svg_str;
28
+ const navigationBarTitle = document.createElement('taro-navigation-bar-title');
29
+ navigationBar.appendChild(navigationBarHomeBtn);
30
+ navigationBar.appendChild(navigationBarBackBtn);
31
+ navigationBar.appendChild(navigationBarTitle);
32
+ navigationBar.id = 'taro-navigation-bar';
33
+ container.prepend(navigationBar);
32
34
  }
33
35
 
34
- // export const removeLeadingSlash = (str = '') => str.replace(/^\.?\//, '')
35
- // export const removeTrailingSearch = (str = '') => str.replace(/\?[\s\S]*$/, '')
36
- const addLeadingSlash = (url = '') => (url.charAt(0) === '/' ? url : '/' + url);
37
- const hasBasename = (path = '', prefix = '') => new RegExp('^' + prefix + '(\\/|\\?|#|$)', 'i').test(path) || path === prefix;
38
- const stripBasename = (path = '', prefix = '') => hasBasename(path, prefix) ? path.substring(prefix.length) : path;
39
- const stripTrailing = (str = '') => str.replace(/[?#][\s\S]*$/, '');
40
- const getHomePage = (path = '', basename = '', customRoutes = {}, entryPagePath = '') => {
41
- var _a;
42
- const routePath = addLeadingSlash(stripBasename(path, basename));
43
- const alias = ((_a = Object.entries(customRoutes).find(([key]) => key === routePath)) === null || _a === void 0 ? void 0 : _a[1]) || routePath;
44
- return entryPagePath || (typeof alias === 'string' ? alias : alias[0]) || basename;
45
- };
46
- const getCurrentPage = (routerMode = 'hash', basename = '/') => {
47
- const pagePath = routerMode === 'hash'
48
- ? location.hash.slice(1).split('?')[0]
49
- : location.pathname;
50
- return addLeadingSlash(stripBasename(pagePath, basename));
51
- };
52
- class RoutesAlias {
53
- constructor() {
54
- this.conf = [];
55
- this.getConfig = (url = '') => {
56
- const customRoute = this.conf.filter((arr) => {
57
- return arr.includes(url);
58
- });
59
- return customRoute[0];
60
- };
61
- this.getOrigin = (url = '') => {
62
- var _a;
63
- return ((_a = this.getConfig(url)) === null || _a === void 0 ? void 0 : _a[0]) || url;
64
- };
65
- this.getAlias = (url = '') => {
66
- var _a;
67
- return ((_a = this.getConfig(url)) === null || _a === void 0 ? void 0 : _a[1]) || url;
68
- };
69
- this.getAll = (url = '') => {
70
- return this.conf
71
- .filter((arr) => arr.includes(url))
72
- .reduceRight((p, a) => {
73
- p.unshift(a[1]);
74
- return p;
75
- }, []);
76
- };
36
+ function initTabbar(config, history) {
37
+ if (config.tabBar == null || config.tabBar.custom) {
38
+ return;
77
39
  }
78
- set(customRoutes = {}) {
79
- for (let key in customRoutes) {
80
- const path = customRoutes[key];
81
- key = addLeadingSlash(key);
82
- if (typeof path === 'string') {
83
- this.conf.push([key, addLeadingSlash(path)]);
84
- }
85
- else if ((path === null || path === void 0 ? void 0 : path.length) > 0) {
86
- this.conf.push(...path.map(p => [key, addLeadingSlash(p)]));
87
- }
88
- }
40
+ // TODO: custom-tab-bar
41
+ defineCustomElementTaroTabbar();
42
+ const tabbar = document.createElement('taro-tabbar');
43
+ const homePage = config.entryPagePath || (config.pages ? config.pages[0] : '');
44
+ tabbar.conf = config.tabBar;
45
+ tabbar.conf.homePage = history.location.pathname === '/' ? homePage : history.location.pathname;
46
+ const routerConfig = config.router;
47
+ tabbar.conf.mode = routerConfig && routerConfig.mode ? routerConfig.mode : 'hash';
48
+ if (routerConfig.customRoutes) {
49
+ tabbar.conf.custom = true;
50
+ tabbar.conf.customRoutes = routerConfig.customRoutes;
51
+ }
52
+ else {
53
+ tabbar.conf.custom = false;
54
+ tabbar.conf.customRoutes = {};
89
55
  }
56
+ if (typeof routerConfig.basename !== 'undefined') {
57
+ tabbar.conf.basename = routerConfig.basename;
58
+ }
59
+ const container = document.getElementById('container');
60
+ container === null || container === void 0 ? void 0 : container.appendChild(tabbar);
61
+ initTabBarApis(config);
90
62
  }
91
- const routesAlias = new RoutesAlias();
92
63
 
93
64
  class RouterConfig {
94
65
  static set config(e) {
@@ -108,7 +79,7 @@ class RouterConfig {
108
79
  }
109
80
  static get customRoutes() { return this.router.customRoutes || {}; }
110
81
  static isPage(url = '') {
111
- return this.pages.findIndex(e => addLeadingSlash(e) === url) !== -1;
82
+ return this.pages.findIndex(e => prependBasename(e) === url) !== -1;
112
83
  }
113
84
  }
114
85
 
@@ -142,7 +113,7 @@ class MpaHistory {
142
113
  url += `?${to.search}`;
143
114
  }
144
115
  if (to.hash) {
145
- url += `#${to.hash}`;
116
+ url += to.hash.startsWith('#') ? to.hash : `#${to.hash}`;
146
117
  }
147
118
  return url;
148
119
  }
@@ -191,6 +162,13 @@ class MpaHistory {
191
162
  };
192
163
  }
193
164
  }
165
+ function setHistory(h, base = '/') {
166
+ history = h;
167
+ basename = base;
168
+ }
169
+ function createMpaHistory(_) {
170
+ return new MpaHistory();
171
+ }
194
172
  function setHistoryMode(mode, base = '/') {
195
173
  const options = {
196
174
  window
@@ -200,7 +178,7 @@ function setHistoryMode(mode, base = '/') {
200
178
  history = createBrowserHistory(options);
201
179
  }
202
180
  else if (mode === 'multi') {
203
- history = new MpaHistory();
181
+ history = createMpaHistory();
204
182
  }
205
183
  else {
206
184
  // default is hash
@@ -292,6 +270,72 @@ class Stacks {
292
270
  }
293
271
  const stacks = new Stacks();
294
272
 
273
+ const isWeixin = () => !!navigator.userAgent.match(/\bMicroMessenger\b/ig);
274
+ const isDingTalk = () => !!navigator.userAgent.match(/\bDingTalk\b/ig);
275
+ let preTitle = document.title;
276
+ let isLoadDdEntry = false;
277
+ function setMpaTitle(title) {
278
+ if (preTitle === title)
279
+ return;
280
+ document.title = title;
281
+ preTitle = title;
282
+ if (process.env.SUPPORT_DINGTALK_NAVIGATE !== 'disabled' && isDingTalk()) {
283
+ if (!isLoadDdEntry) {
284
+ isLoadDdEntry = true;
285
+ require('dingtalk-jsapi/platform');
286
+ }
287
+ const setDingTitle = require('dingtalk-jsapi/api/biz/navigation/setTitle').default;
288
+ setDingTitle({ title });
289
+ }
290
+ }
291
+ function setTitle(title) {
292
+ eventCenter.trigger('__taroH5SetNavigationTitle', title);
293
+ }
294
+ function setNavigationBarStyle(option) {
295
+ eventCenter.trigger('__taroH5setNavigationBarColor', option);
296
+ }
297
+
298
+ class RoutesAlias {
299
+ constructor() {
300
+ this.conf = [];
301
+ this.getConfig = (url = '') => {
302
+ const customRoute = this.conf.filter((arr) => {
303
+ return arr.includes(url);
304
+ });
305
+ return customRoute[0];
306
+ };
307
+ this.getOrigin = (url = '') => {
308
+ var _a;
309
+ return ((_a = this.getConfig(url)) === null || _a === void 0 ? void 0 : _a[0]) || url;
310
+ };
311
+ this.getAlias = (url = '') => {
312
+ var _a;
313
+ return ((_a = this.getConfig(url)) === null || _a === void 0 ? void 0 : _a[1]) || url;
314
+ };
315
+ this.getAll = (url = '') => {
316
+ return this.conf
317
+ .filter((arr) => arr.includes(url))
318
+ .reduceRight((p, a) => {
319
+ p.unshift(a[1]);
320
+ return p;
321
+ }, []);
322
+ };
323
+ }
324
+ set(customRoutes = {}) {
325
+ for (let key in customRoutes) {
326
+ const path = customRoutes[key];
327
+ key = addLeadingSlash(key);
328
+ if (typeof path === 'string') {
329
+ this.conf.push([key, addLeadingSlash(path)]);
330
+ }
331
+ else if ((path === null || path === void 0 ? void 0 : path.length) > 0) {
332
+ this.conf.push(...path.map(p => [key, addLeadingSlash(p)]));
333
+ }
334
+ }
335
+ }
336
+ }
337
+ const routesAlias = new RoutesAlias();
338
+
295
339
  function processNavigateUrl(option) {
296
340
  var _a;
297
341
  const pathPieces = parsePath(option.url);
@@ -332,6 +376,21 @@ function navigate(option, method) {
332
376
  if ('url' in option) {
333
377
  const pathPieces = processNavigateUrl(option);
334
378
  const state = { timestamp: Date.now() };
379
+ if (pathPieces.pathname) {
380
+ const originPath = routesAlias.getOrigin(pathPieces.pathname);
381
+ const pagePath = originPath.startsWith('/') ? originPath.substring(1) : originPath;
382
+ if (!RouterConfig.pages.includes(pagePath)) {
383
+ const res = { errMsg: `${method}:fail page ${pagePath} is not found` };
384
+ fail === null || fail === void 0 ? void 0 : fail(res);
385
+ complete === null || complete === void 0 ? void 0 : complete(res);
386
+ if (fail || complete) {
387
+ return resolve(res);
388
+ }
389
+ else {
390
+ return reject(res);
391
+ }
392
+ }
393
+ }
335
394
  if (method === 'navigateTo') {
336
395
  history.push(pathPieces, state);
337
396
  }
@@ -345,14 +404,24 @@ function navigate(option, method) {
345
404
  }
346
405
  else if (method === 'navigateBack') {
347
406
  stacks.delta = option.delta;
348
- history.go(-option.delta);
407
+ if (stacks.length > option.delta) {
408
+ history.go(-option.delta);
409
+ }
410
+ else {
411
+ history.go(1 - stacks.length);
412
+ }
349
413
  }
350
414
  }
351
415
  catch (error) {
352
416
  const res = { errMsg: `${method}:fail ${error.message || error}` };
353
417
  fail === null || fail === void 0 ? void 0 : fail(res);
354
418
  complete === null || complete === void 0 ? void 0 : complete(res);
355
- reject(res);
419
+ if (fail || complete) {
420
+ return resolve(res);
421
+ }
422
+ else {
423
+ return reject(res);
424
+ }
356
425
  }
357
426
  });
358
427
  });
@@ -383,47 +452,22 @@ function getCurrentPages() {
383
452
  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, '')) || '' })); });
384
453
  }
385
454
 
386
- let md;
387
- let preTitle = document.title;
388
- let isLoadDdEntry = false;
389
- function getMobileDetect() {
390
- if (!md) {
391
- md = new MobileDetect(navigator.userAgent);
392
- }
393
- return md;
394
- }
395
- function setTitle(title) {
396
- return __awaiter(this, void 0, void 0, function* () {
397
- if (preTitle === title)
398
- return title;
399
- document.title = title;
400
- preTitle = title;
401
- if (process.env.SUPPORT_DINGTALK_NAVIGATE !== 'disabled' && isDingTalk()) {
402
- if (!isLoadDdEntry) {
403
- isLoadDdEntry = true;
404
- require('dingtalk-jsapi/platform');
405
- }
406
- const setDingTitle = require('dingtalk-jsapi/api/biz/navigation/setTitle').default;
407
- setDingTitle({ title });
408
- }
409
- return title;
410
- });
411
- }
412
- function isDingTalk() {
413
- const md = getMobileDetect();
414
- return md.match(/DingTalk/ig);
415
- }
416
-
417
455
  let pageResizeFn;
418
456
  function bindPageResize(page) {
419
457
  pageResizeFn && window.removeEventListener('resize', pageResizeFn);
420
458
  pageResizeFn = function () {
421
- page.onResize && page.onResize({
422
- size: {
423
- windowHeight: window.innerHeight,
424
- windowWidth: window.innerWidth
425
- }
426
- });
459
+ if (page.onResize) {
460
+ const mediaQuery = window.matchMedia('(orientation: portrait)');
461
+ page.onResize({
462
+ deviceOrientation: mediaQuery.matches ? 'portrait' : 'landscape',
463
+ size: {
464
+ windowHeight: window.innerHeight,
465
+ windowWidth: window.innerWidth,
466
+ screenHeight: window.screen.height,
467
+ screenWidth: window.screen.width,
468
+ }
469
+ });
470
+ }
427
471
  };
428
472
  window.addEventListener('resize', pageResizeFn, false);
429
473
  }
@@ -467,7 +511,10 @@ function getOffset() {
467
511
  */
468
512
  function loadAnimateStyle(ms = 300) {
469
513
  const css = `
470
- .taro_router .taro_page {
514
+ body {
515
+ overflow: hidden; // 防止 iOS 页面滚动
516
+ }
517
+ .taro_router > .taro_page {
471
518
  position: absolute;
472
519
  left: 0;
473
520
  top: 0;
@@ -479,52 +526,109 @@ function loadAnimateStyle(ms = 300) {
479
526
  z-index: 0;
480
527
  }
481
528
 
482
- .taro_router .taro_page.taro_tabbar_page,
483
- .taro_router .taro_page.taro_page_show.taro_page_stationed {
529
+ .taro_router > .taro_page.taro_tabbar_page,
530
+ .taro_router > .taro_page.taro_page_show.taro_page_stationed {
484
531
  transform: none;
485
532
  }
486
533
 
487
- .taro_router .taro_page.taro_page_show {
534
+ .taro_router > .taro_page.taro_page_show {
488
535
  transform: translate(0, 0);
489
- }`;
536
+ }
537
+ `;
490
538
  addStyle(css);
491
539
  }
492
540
  /**
493
541
  * 插入路由相关样式
494
542
  */
495
- function loadRouterStyle(usingWindowScroll) {
543
+ function loadRouterStyle(enableTabBar, enableWindowScroll) {
496
544
  const css = `
497
545
  .taro_router {
498
546
  position: relative;
499
547
  width: 100%;
500
548
  height: 100%;
501
- min-height: 100vh;
502
- }
503
-
504
- .taro-tabbar__container .taro_router {
505
- min-height: calc(100vh - 50px);
506
549
  }
507
550
 
508
551
  .taro_page {
509
552
  width: 100%;
510
553
  height: 100%;
511
- ${usingWindowScroll ? '' : `
554
+ ${enableWindowScroll ? '' : `
512
555
  overflow-x: hidden;
513
556
  overflow-y: scroll;
514
557
  max-height: 100vh;
515
- `}
558
+ `}
516
559
  }
517
-
518
- .taro-tabbar__container .taro-tabbar__panel {
560
+ ${enableTabBar ? `
561
+ .taro-tabbar__container > .taro-tabbar__panel {
519
562
  overflow: hidden;
520
563
  }
521
564
 
522
- .taro-tabbar__container .taro_page.taro_tabbar_page {
523
- max-height: calc(100vh - 50px);
565
+ .taro-tabbar__container > .taro-tabbar__panel > .taro_page.taro_tabbar_page {
566
+ max-height: calc(100vh - var(--taro-tabbar-height) - constant(safe-area-inset-bottom));
567
+ max-height: calc(100vh - var(--taro-tabbar-height) - env(safe-area-inset-bottom));
568
+ }
569
+
570
+ ` : ''}
571
+ .taro_page_shade,
572
+ .taro_router > .taro_page.taro_page_show.taro_page_stationed:not(.taro_page_shade):not(.taro_tabbar_page):not(:last-child) {
573
+ display: none;
524
574
  }
525
575
  `;
526
576
  addStyle(css);
527
577
  }
578
+ /**
579
+ * 插入导航栏相关的样式
580
+ */
581
+ function loadNavigationBarStyle() {
582
+ const css = `
583
+ .taro-navigation-bar-show {
584
+ background: white;
585
+ position: sticky;
586
+ z-index: 500;
587
+ top: 0;
588
+ padding-bottom: 8px;
589
+ padding-top: calc(env(safe-area-inset-top) + 8px);
590
+ display: flex;
591
+ justify-content: center;
592
+ align-items: center;
593
+ }
594
+
595
+ .taro-navigation-bar-hide {
596
+ display: none;
597
+ }
598
+
599
+ taro-navigation-bar-title {
600
+ font-size: 24px;
601
+ height: 24px;
602
+ line-height: 24px;
603
+ }
604
+
605
+ .taro-navigation-bar-no-icon > taro-navigation-bar-home {
606
+ display: none;
607
+ }
608
+
609
+ .taro-navigation-bar-no-icon > taro-navigation-bar-back {
610
+ display: none;
611
+ }
612
+
613
+ .taro-navigation-bar-home > taro-navigation-bar-home {
614
+ display: block;
615
+ left: 8px;
616
+ position: absolute;
617
+ width: 24px;
618
+ height: 24px;
619
+ }
620
+
621
+ .taro-navigation-bar-back > taro-navigation-bar-back {
622
+ display: block;
623
+ left: 8px;
624
+ position: absolute;
625
+ width: 24px;
626
+ height: 24px;
627
+ }
628
+
629
+ `;
630
+ addStyle(css);
631
+ }
528
632
  function addStyle(css) {
529
633
  if (!css)
530
634
  return;
@@ -533,38 +637,10 @@ function addStyle(css) {
533
637
  document.getElementsByTagName('head')[0].appendChild(style);
534
638
  }
535
639
 
536
- // @ts-nocheck
537
- function initTabbar(config) {
538
- if (config.tabBar == null) {
539
- return;
540
- }
541
- // TODO: custom-tab-bar
542
- defineCustomElementTaroTabbar();
543
- const tabbar = document.createElement('taro-tabbar');
544
- const homePage = config.entryPagePath || (config.pages ? config.pages[0] : '');
545
- tabbar.conf = config.tabBar;
546
- tabbar.conf.homePage = history.location.pathname === '/' ? homePage : history.location.pathname;
547
- const routerConfig = config.router;
548
- tabbar.conf.mode = routerConfig && routerConfig.mode ? routerConfig.mode : 'hash';
549
- if (routerConfig.customRoutes) {
550
- tabbar.conf.custom = true;
551
- tabbar.conf.customRoutes = routerConfig.customRoutes;
552
- }
553
- else {
554
- tabbar.conf.custom = false;
555
- tabbar.conf.customRoutes = {};
556
- }
557
- if (typeof routerConfig.basename !== 'undefined') {
558
- tabbar.conf.basename = routerConfig.basename;
559
- }
560
- const container = document.getElementById('container');
561
- container === null || container === void 0 ? void 0 : container.appendChild(tabbar);
562
- initTabBarApis(config);
563
- }
564
-
565
640
  /* eslint-disable dot-notation */
566
641
  class MultiPageHandler {
567
- constructor(config) {
642
+ constructor(config, history) {
643
+ this.history = history;
568
644
  this.config = config;
569
645
  this.mount();
570
646
  }
@@ -611,39 +687,18 @@ class MultiPageHandler {
611
687
  : {};
612
688
  return Object.assign(Object.assign({}, query), options);
613
689
  }
614
- mount() {
615
- setHistoryMode(this.routerMode, this.router.basename);
616
- loadRouterStyle(this.usingWindowScroll);
617
- const appId = this.appId;
618
- let app = document.getElementById(appId);
619
- let isPosition = true;
620
- if (!app) {
621
- app = document.createElement('div');
622
- app.id = appId;
623
- isPosition = false;
624
- }
625
- const appWrapper = (app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body;
626
- app.classList.add('taro_router');
627
- if (this.tabBarList.length > 1) {
628
- const container = document.createElement('div');
629
- container.classList.add('taro-tabbar__container');
630
- container.id = 'container';
631
- const panel = document.createElement('div');
632
- panel.classList.add('taro-tabbar__panel');
633
- panel.appendChild(app.cloneNode(true));
634
- container.appendChild(panel);
635
- if (!isPosition) {
636
- appWrapper.appendChild(container);
637
- }
638
- else {
639
- appWrapper.replaceChild(container, app);
640
- }
641
- initTabbar(this.config);
642
- }
643
- else {
644
- if (!isPosition)
645
- appWrapper.appendChild(app);
690
+ isDefaultNavigationStyle() {
691
+ var _a, _b;
692
+ let style = (_a = this.config.window) === null || _a === void 0 ? void 0 : _a.navigationStyle;
693
+ if (typeof ((_b = this.pageConfig) === null || _b === void 0 ? void 0 : _b.navigationStyle) === 'string') {
694
+ style = this.pageConfig.navigationStyle;
646
695
  }
696
+ return style !== 'custom';
697
+ }
698
+ mount() {
699
+ setHistory(this.history, this.basename);
700
+ // Note: 注入页面样式
701
+ loadRouterStyle(this.tabBarList.length > 1, this.usingWindowScroll);
647
702
  }
648
703
  onReady(page, onLoad = true) {
649
704
  var _a;
@@ -673,13 +728,17 @@ class MultiPageHandler {
673
728
  return;
674
729
  (_a = page.onLoad) === null || _a === void 0 ? void 0 : _a.call(page, this.getQuery('', page.options), () => {
675
730
  var _a;
731
+ const pageEl = this.getPageContainer(page);
676
732
  if (this.isTabBar) {
677
- const pageEl = this.getPageContainer(page);
678
733
  pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.add('taro_tabbar_page');
679
734
  }
735
+ if (this.isDefaultNavigationStyle()) {
736
+ pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.add('taro_navigation_page');
737
+ }
680
738
  this.onReady(page, true);
681
739
  (_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
682
740
  this.bindPageEvents(page, pageConfig);
741
+ this.triggerRouterChange();
683
742
  });
684
743
  }
685
744
  getPageContainer(page) {
@@ -707,6 +766,19 @@ class MultiPageHandler {
707
766
  bindPageScroll(page, scrollEl, distance);
708
767
  bindPageResize(page);
709
768
  }
769
+ triggerRouterChange() {
770
+ /**
771
+ * @tarojs/runtime 中生命周期跑在 promise 中,所以这里需要 setTimeout 延迟事件调用
772
+ * TODO 考虑将生命周期返回 Promise,用于处理相关事件调用顺序
773
+ */
774
+ setTimeout(() => {
775
+ eventCenter.trigger('__afterTaroRouterChange', {
776
+ toLocation: {
777
+ path: this.pathname
778
+ }
779
+ });
780
+ }, 0);
781
+ }
710
782
  }
711
783
 
712
784
  const createStampId$1 = incrementId();
@@ -719,14 +791,15 @@ const launchStampId$1 = createStampId$1();
719
791
  * - TabBar 会多次加载
720
792
  * - 不支持路由动画
721
793
  */
722
- function createMultiRouter(app, config, framework) {
794
+ function createMultiRouter(history, app, config, framework) {
723
795
  var _a, _b, _c, _d, _e, _f;
724
796
  return __awaiter(this, void 0, void 0, function* () {
725
797
  if (typeof app.onUnhandledRejection === 'function') {
726
798
  window.addEventListener('unhandledrejection', app.onUnhandledRejection);
727
799
  }
800
+ eventCenter.on('__taroH5SetNavigationTitle', setMpaTitle);
728
801
  RouterConfig.config = config;
729
- const handler = new MultiPageHandler(config);
802
+ const handler = new MultiPageHandler(config, history);
730
803
  const launchParam = {
731
804
  path: config.pageName,
732
805
  query: handler.getQuery(launchStampId$1),
@@ -758,7 +831,7 @@ function createMultiRouter(app, config, framework) {
758
831
  return;
759
832
  let enablePullDownRefresh = ((_c = config === null || config === void 0 ? void 0 : config.window) === null || _c === void 0 ? void 0 : _c.enablePullDownRefresh) || false;
760
833
  if (pageConfig) {
761
- setTitle((_d = pageConfig.navigationBarTitleText) !== null && _d !== void 0 ? _d : document.title);
834
+ setMpaTitle((_d = pageConfig.navigationBarTitleText) !== null && _d !== void 0 ? _d : document.title);
762
835
  if (typeof pageConfig.enablePullDownRefresh === 'boolean') {
763
836
  enablePullDownRefresh = pageConfig.enablePullDownRefresh;
764
837
  }
@@ -770,21 +843,228 @@ function createMultiRouter(app, config, framework) {
770
843
  const page = createPageConfig(enablePullDownRefresh ? hooks.call('createPullDownComponent', el, pathName, framework, handler.PullDownRefresh) : el, pathName + stringify(launchParam), {}, loadConfig);
771
844
  handler.load(page, pageConfig);
772
845
  (_f = app.onShow) === null || _f === void 0 ? void 0 : _f.call(app, launchParam);
846
+ window.addEventListener('visibilitychange', () => {
847
+ var _a, _b;
848
+ if (document.visibilityState === 'visible') {
849
+ (_a = app.onShow) === null || _a === void 0 ? void 0 : _a.call(app, launchParam);
850
+ }
851
+ else {
852
+ (_b = app.onHide) === null || _b === void 0 ? void 0 : _b.call(app, launchParam);
853
+ }
854
+ });
773
855
  });
774
856
  }
775
857
 
776
- /* eslint-disable dot-notation */
777
- function setDisplay(el, type = '') {
778
- if (el) {
779
- el.style.display = type;
858
+ class NavigationBarHandler {
859
+ constructor(pageContext) {
860
+ this.isLoadDdEntry = false;
861
+ this.cache = {};
862
+ this.pageContext = pageContext;
863
+ this.init();
864
+ loadNavigationBarStyle();
865
+ eventCenter.on('__taroH5SetNavigationTitle', (title) => {
866
+ this.setTitle(title);
867
+ });
868
+ eventCenter.on('__taroH5setNavigationBarColor', ({ backgroundColor, frontColor }) => {
869
+ if (typeof backgroundColor === 'string')
870
+ this.setNavigationBarBackground(backgroundColor);
871
+ if (typeof frontColor === 'string')
872
+ this.setNavigationBarTextStyle(frontColor);
873
+ });
874
+ }
875
+ toHomeFn() {
876
+ reLaunch({ url: this.pageContext.homePage });
877
+ }
878
+ backFn() {
879
+ navigateBack();
880
+ }
881
+ get homeBtnElement() {
882
+ var _a;
883
+ if (!this.navigationBarElement)
884
+ return null;
885
+ return (_a = this.navigationBarElement.getElementsByTagName('taro-navigation-bar-home')) === null || _a === void 0 ? void 0 : _a[0];
886
+ }
887
+ get backBtnElement() {
888
+ var _a;
889
+ if (!this.navigationBarElement)
890
+ return null;
891
+ return (_a = this.navigationBarElement.getElementsByTagName('taro-navigation-bar-back')) === null || _a === void 0 ? void 0 : _a[0];
892
+ }
893
+ get titleElement() {
894
+ var _a;
895
+ if (!this.navigationBarElement)
896
+ return null;
897
+ return (_a = this.navigationBarElement.getElementsByTagName('taro-navigation-bar-title')) === null || _a === void 0 ? void 0 : _a[0];
898
+ }
899
+ init() {
900
+ var _a, _b;
901
+ this.setNavigationBarElement();
902
+ if (!this.navigationBarElement)
903
+ return;
904
+ (_a = this.homeBtnElement) === null || _a === void 0 ? void 0 : _a.addEventListener('click', this.toHomeFn.bind(this));
905
+ (_b = this.backBtnElement) === null || _b === void 0 ? void 0 : _b.addEventListener('click', this.backFn.bind(this));
906
+ }
907
+ setNavigationBarElement() {
908
+ var _a;
909
+ this.navigationBarElement = (_a = document.getElementsByTagName('taro-navigation-bar-wrap')) === null || _a === void 0 ? void 0 : _a[0];
910
+ }
911
+ load() {
912
+ this.setCacheValue();
913
+ this.setTitle();
914
+ this.setNavigationBarVisible();
915
+ this.setFnBtnState();
916
+ this.setNavigationBarBackground();
917
+ this.setNavigationBarTextStyle();
918
+ }
919
+ setCacheValue() {
920
+ const currentPage = this.pageContext.currentPage;
921
+ if (typeof this.cache[currentPage] !== 'object') {
922
+ this.cache[currentPage] = {};
923
+ }
924
+ }
925
+ setFnBtnState() {
926
+ const currentRouter = this.pageContext.currentPage;
927
+ if (this.pageContext.isTabBar(currentRouter) || this.pageContext.homePage === currentRouter) {
928
+ this.fnBtnToggleToNone();
929
+ }
930
+ else if (stacks.length > 1) {
931
+ this.fnBtnToggleToBack();
932
+ }
933
+ else {
934
+ this.fnBtnToggleToHome();
935
+ }
936
+ }
937
+ setNavigationBarBackground(backgroundColor) {
938
+ var _a, _b, _c;
939
+ if (!this.navigationBarElement)
940
+ return;
941
+ const currentPage = this.pageContext.currentPage;
942
+ let color;
943
+ if (typeof backgroundColor === 'string') {
944
+ color = backgroundColor;
945
+ this.cache[currentPage] &&
946
+ (this.cache[currentPage].backgroundColor = color);
947
+ }
948
+ else {
949
+ const cacheValue = (_a = this.cache[currentPage]) === null || _a === void 0 ? void 0 : _a.backgroundColor;
950
+ if (typeof cacheValue === 'string') {
951
+ color = cacheValue;
952
+ }
953
+ else {
954
+ color = ((_c = (_b = this.pageContext.config) === null || _b === void 0 ? void 0 : _b.window) === null || _c === void 0 ? void 0 : _c.navigationBarBackgroundColor) || '#000000';
955
+ this.cache[currentPage] &&
956
+ (this.cache[currentPage].backgroundColor = color);
957
+ }
958
+ }
959
+ this.navigationBarElement.style.background = color;
960
+ }
961
+ setNavigationBarTextStyle(fontColor) {
962
+ var _a, _b, _c;
963
+ if (!this.navigationBarElement)
964
+ return;
965
+ const currentPage = this.pageContext.currentPage;
966
+ let color;
967
+ if (typeof fontColor === 'string') {
968
+ color = fontColor;
969
+ this.cache[currentPage] &&
970
+ (this.cache[currentPage].fontColor = color);
971
+ }
972
+ else {
973
+ const cacheValue = (_a = this.cache[currentPage]) === null || _a === void 0 ? void 0 : _a.fontColor;
974
+ if (typeof cacheValue === 'string') {
975
+ color = cacheValue;
976
+ }
977
+ else {
978
+ color = ((_c = (_b = this.pageContext.config) === null || _b === void 0 ? void 0 : _b.window) === null || _c === void 0 ? void 0 : _c.navigationBarTextStyle) || 'white';
979
+ this.cache[currentPage] &&
980
+ (this.cache[currentPage].fontColor = color);
981
+ }
982
+ }
983
+ this.navigationBarElement.style.color = color;
984
+ }
985
+ setTitle(title) {
986
+ var _a, _b, _c;
987
+ const currentPage = this.pageContext.currentPage;
988
+ let proceedTitle;
989
+ if (typeof title === 'string') {
990
+ proceedTitle = title;
991
+ this.cache[currentPage] &&
992
+ (this.cache[currentPage].title = proceedTitle);
993
+ }
994
+ else {
995
+ const cacheValue = (_a = this.cache[currentPage]) === null || _a === void 0 ? void 0 : _a.title;
996
+ if (typeof cacheValue === 'string') {
997
+ proceedTitle = cacheValue;
998
+ }
999
+ else {
1000
+ proceedTitle = (_c = (_b = this.pageContext.pageConfig) === null || _b === void 0 ? void 0 : _b.navigationBarTitleText) !== null && _c !== void 0 ? _c : document.title;
1001
+ this.cache[currentPage] &&
1002
+ (this.cache[currentPage].title = proceedTitle);
1003
+ }
1004
+ }
1005
+ if (process.env.SUPPORT_DINGTALK_NAVIGATE !== 'disabled' && isDingTalk()) {
1006
+ if (!this.isLoadDdEntry) {
1007
+ this.isLoadDdEntry = true;
1008
+ require('dingtalk-jsapi/platform');
1009
+ }
1010
+ const setDingTitle = require('dingtalk-jsapi/api/biz/navigation/setTitle').default;
1011
+ setDingTitle({ proceedTitle });
1012
+ }
1013
+ document.title = proceedTitle;
1014
+ if (!this.titleElement)
1015
+ return;
1016
+ this.titleElement.innerHTML = proceedTitle;
1017
+ }
1018
+ fnBtnToggleToHome() {
1019
+ if (!this.navigationBarElement)
1020
+ return;
1021
+ this.navigationBarElement.classList.add('taro-navigation-bar-home');
1022
+ this.navigationBarElement.classList.remove('taro-navigation-bar-back');
1023
+ }
1024
+ fnBtnToggleToBack() {
1025
+ if (!this.navigationBarElement)
1026
+ return;
1027
+ this.navigationBarElement.classList.remove('taro-navigation-bar-home');
1028
+ this.navigationBarElement.classList.add('taro-navigation-bar-back');
1029
+ }
1030
+ fnBtnToggleToNone() {
1031
+ if (!this.navigationBarElement)
1032
+ return;
1033
+ this.navigationBarElement.classList.remove('taro-navigation-bar-home');
1034
+ this.navigationBarElement.classList.remove('taro-navigation-bar-back');
1035
+ }
1036
+ setNavigationBarVisible(show) {
1037
+ var _a, _b;
1038
+ let shouldShow;
1039
+ if (typeof show === 'boolean') {
1040
+ shouldShow = show;
1041
+ }
1042
+ else {
1043
+ shouldShow = (_a = this.pageContext.config.window) === null || _a === void 0 ? void 0 : _a.navigationStyle;
1044
+ if (typeof ((_b = this.pageContext.pageConfig) === null || _b === void 0 ? void 0 : _b.navigationStyle) === 'string') {
1045
+ shouldShow = this.pageContext.pageConfig.navigationStyle;
1046
+ }
1047
+ }
1048
+ if (shouldShow === 'default') {
1049
+ this.navigationBarElement.classList.add('taro-navigation-bar-show');
1050
+ this.navigationBarElement.classList.remove('taro-navigation-bar-hide');
1051
+ }
1052
+ else {
1053
+ this.navigationBarElement.classList.add('taro-navigation-bar-hide');
1054
+ this.navigationBarElement.classList.remove('taro-navigation-bar-show');
1055
+ }
780
1056
  }
781
1057
  }
1058
+
1059
+ /* eslint-disable dot-notation */
782
1060
  class PageHandler {
783
- constructor(config) {
1061
+ constructor(config, history) {
1062
+ this.history = history;
784
1063
  this.defaultAnimation = { duration: 300, delay: 50 };
785
1064
  this.config = config;
786
1065
  this.homePage = getHomePage(this.routes[0].path, this.basename, this.customRoutes, this.config.entryPagePath);
787
1066
  this.mount();
1067
+ this.navigationBarHandler = new NavigationBarHandler(this);
788
1068
  }
789
1069
  get currentPage() {
790
1070
  const routePath = getCurrentPage(this.routerMode, this.basename);
@@ -840,6 +1120,14 @@ class PageHandler {
840
1120
  })) === null || _a === void 0 ? void 0 : _a[0]) || routePath;
841
1121
  return !!pagePath && this.tabBarList.some(t => stripTrailing(t.pagePath) === pagePath);
842
1122
  }
1123
+ isDefaultNavigationStyle() {
1124
+ var _a, _b;
1125
+ let style = (_a = this.config.window) === null || _a === void 0 ? void 0 : _a.navigationStyle;
1126
+ if (typeof ((_b = this.pageConfig) === null || _b === void 0 ? void 0 : _b.navigationStyle) === 'string') {
1127
+ style = this.pageConfig.navigationStyle;
1128
+ }
1129
+ return style !== 'custom';
1130
+ }
843
1131
  isSamePage(page) {
844
1132
  const routePath = stripBasename(this.pathname, this.basename);
845
1133
  const pagePath = stripBasename(page === null || page === void 0 ? void 0 : page.path, this.basename);
@@ -878,40 +1166,11 @@ class PageHandler {
878
1166
  return Object.assign(Object.assign({}, query), options);
879
1167
  }
880
1168
  mount() {
881
- setHistoryMode(this.routerMode, this.router.basename);
1169
+ setHistory(this.history, this.basename);
882
1170
  this.pathname = history.location.pathname;
1171
+ // Note: 注入页面样式
883
1172
  this.animation && loadAnimateStyle(this.animationDuration);
884
- loadRouterStyle(this.usingWindowScroll);
885
- const appId = this.appId;
886
- let app = document.getElementById(appId);
887
- let isPosition = true;
888
- if (!app) {
889
- app = document.createElement('div');
890
- app.id = appId;
891
- isPosition = false;
892
- }
893
- const appWrapper = (app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body;
894
- app.classList.add('taro_router');
895
- if (this.tabBarList.length > 1) {
896
- const container = document.createElement('div');
897
- container.classList.add('taro-tabbar__container');
898
- container.id = 'container';
899
- const panel = document.createElement('div');
900
- panel.classList.add('taro-tabbar__panel');
901
- panel.appendChild(app.cloneNode(true));
902
- container.appendChild(panel);
903
- if (!isPosition) {
904
- appWrapper.appendChild(container);
905
- }
906
- else {
907
- appWrapper.replaceChild(container, app);
908
- }
909
- initTabbar(this.config);
910
- }
911
- else {
912
- if (!isPosition)
913
- appWrapper.appendChild(app);
914
- }
1173
+ loadRouterStyle(this.tabBarList.length > 1, this.usingWindowScroll);
915
1174
  }
916
1175
  onReady(page, onLoad = true) {
917
1176
  var _a;
@@ -944,21 +1203,26 @@ class PageHandler {
944
1203
  const param = this.getQuery(stampId, '', page.options);
945
1204
  let pageEl = this.getPageContainer(page);
946
1205
  if (pageEl) {
947
- setDisplay(pageEl);
1206
+ pageEl.classList.remove('taro_page_shade');
948
1207
  this.isTabBar(this.pathname) && pageEl.classList.add('taro_tabbar_page');
1208
+ this.isDefaultNavigationStyle() && pageEl.classList.add('taro_navigation_page');
949
1209
  this.addAnimation(pageEl, pageNo === 0);
950
1210
  (_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
1211
+ this.navigationBarHandler.load();
951
1212
  this.bindPageEvents(page, pageConfig);
952
1213
  this.triggerRouterChange();
953
1214
  }
954
1215
  else {
1216
+ // FIXME 在 iOS 端快速切换页面时,可能不会执行回调注入对应类名导致 TabBar 白屏
955
1217
  (_b = page.onLoad) === null || _b === void 0 ? void 0 : _b.call(page, param, () => {
956
1218
  var _a;
957
1219
  pageEl = this.getPageContainer(page);
958
1220
  this.isTabBar(this.pathname) && (pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.add('taro_tabbar_page'));
1221
+ this.isDefaultNavigationStyle() && (pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.add('taro_navigation_page'));
959
1222
  this.addAnimation(pageEl, pageNo === 0);
960
- this.onReady(page, true);
961
1223
  (_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
1224
+ this.navigationBarHandler.load();
1225
+ this.onReady(page, true);
962
1226
  this.bindPageEvents(page, pageConfig);
963
1227
  this.triggerRouterChange();
964
1228
  });
@@ -1009,9 +1273,10 @@ class PageHandler {
1009
1273
  const param = this.getQuery(page['$taroParams']['stamp'], '', page.options);
1010
1274
  let pageEl = this.getPageContainer(page);
1011
1275
  if (pageEl) {
1012
- setDisplay(pageEl);
1276
+ pageEl.classList.remove('taro_page_shade');
1013
1277
  this.addAnimation(pageEl, pageNo === 0);
1014
1278
  (_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
1279
+ this.navigationBarHandler.load();
1015
1280
  this.bindPageEvents(page, pageConfig);
1016
1281
  this.triggerRouterChange();
1017
1282
  }
@@ -1020,8 +1285,9 @@ class PageHandler {
1020
1285
  var _a;
1021
1286
  pageEl = this.getPageContainer(page);
1022
1287
  this.addAnimation(pageEl, pageNo === 0);
1023
- this.onReady(page, false);
1024
1288
  (_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
1289
+ this.navigationBarHandler.load();
1290
+ this.onReady(page, false);
1025
1291
  this.bindPageEvents(page, pageConfig);
1026
1292
  this.triggerRouterChange();
1027
1293
  });
@@ -1037,12 +1303,12 @@ class PageHandler {
1037
1303
  if (this.hideTimer) {
1038
1304
  clearTimeout(this.hideTimer);
1039
1305
  this.hideTimer = null;
1040
- setDisplay(this.lastHidePage, 'none');
1306
+ pageEl.classList.add('taro_page_shade');
1041
1307
  }
1042
1308
  this.lastHidePage = pageEl;
1043
1309
  this.hideTimer = setTimeout(() => {
1044
1310
  this.hideTimer = null;
1045
- setDisplay(this.lastHidePage, 'none');
1311
+ pageEl.classList.add('taro_page_shade');
1046
1312
  }, this.animationDuration + this.animationDelay);
1047
1313
  (_a = page.onHide) === null || _a === void 0 ? void 0 : _a.call(page);
1048
1314
  }
@@ -1108,13 +1374,13 @@ class PageHandler {
1108
1374
 
1109
1375
  const createStampId = incrementId();
1110
1376
  let launchStampId = createStampId();
1111
- function createRouter(app, config, framework) {
1377
+ function createRouter(history, app, config, framework) {
1112
1378
  var _a, _b;
1113
1379
  if (typeof app.onUnhandledRejection === 'function') {
1114
1380
  window.addEventListener('unhandledrejection', app.onUnhandledRejection);
1115
1381
  }
1116
1382
  RouterConfig.config = config;
1117
- const handler = new PageHandler(config);
1383
+ const handler = new PageHandler(config, history);
1118
1384
  routesAlias.set(handler.router.customRoutes);
1119
1385
  const basename = handler.router.basename;
1120
1386
  const routes = handler.routes.map(route => {
@@ -1137,7 +1403,7 @@ function createRouter(app, config, framework) {
1137
1403
  (_a = app.onLaunch) === null || _a === void 0 ? void 0 : _a.call(app, launchParam);
1138
1404
  app.onError && window.addEventListener('error', e => { var _a; return (_a = app.onError) === null || _a === void 0 ? void 0 : _a.call(app, e.message); });
1139
1405
  const render = ({ location, action }) => __awaiter(this, void 0, void 0, function* () {
1140
- var _c, _d, _e, _f, _g, _h;
1406
+ var _c, _d, _e, _f, _g, _h, _j, _k;
1141
1407
  handler.pathname = decodeURI(location.pathname);
1142
1408
  if ((_c = window.__taroAppConfig) === null || _c === void 0 ? void 0 : _c.usingWindowScroll)
1143
1409
  window.scrollTo(0, 0);
@@ -1166,22 +1432,34 @@ function createRouter(app, config, framework) {
1166
1432
  window.location.reload();
1167
1433
  }
1168
1434
  else {
1169
- throw new Error(error);
1435
+ throw error;
1170
1436
  }
1171
1437
  }
1172
1438
  if (!element)
1173
1439
  return;
1174
1440
  const pageConfig = handler.pageConfig;
1175
1441
  let enablePullDownRefresh = ((_e = config === null || config === void 0 ? void 0 : config.window) === null || _e === void 0 ? void 0 : _e.enablePullDownRefresh) || false;
1442
+ let navigationStyle = ((_f = config === null || config === void 0 ? void 0 : config.window) === null || _f === void 0 ? void 0 : _f.navigationStyle) || 'default';
1443
+ let navigationBarTextStyle = ((_g = config === null || config === void 0 ? void 0 : config.window) === null || _g === void 0 ? void 0 : _g.navigationBarTextStyle) || 'white';
1444
+ let navigationBarBackgroundColor = ((_h = config === null || config === void 0 ? void 0 : config.window) === null || _h === void 0 ? void 0 : _h.navigationBarBackgroundColor) || '#000000';
1176
1445
  if (pageConfig) {
1177
- setTitle((_f = pageConfig.navigationBarTitleText) !== null && _f !== void 0 ? _f : document.title);
1178
1446
  if (typeof pageConfig.enablePullDownRefresh === 'boolean') {
1179
1447
  enablePullDownRefresh = pageConfig.enablePullDownRefresh;
1180
1448
  }
1449
+ if (typeof pageConfig.navigationStyle === 'string') {
1450
+ navigationStyle = pageConfig.navigationStyle;
1451
+ }
1452
+ if (typeof pageConfig.navigationBarTextStyle === 'string') {
1453
+ navigationBarTextStyle = pageConfig.navigationBarTextStyle;
1454
+ }
1455
+ if (typeof pageConfig.navigationBarBackgroundColor === 'string') {
1456
+ navigationBarBackgroundColor = pageConfig.navigationBarBackgroundColor;
1457
+ }
1181
1458
  }
1459
+ eventCenter.trigger('__taroSetNavigationStyle', navigationStyle, navigationBarTextStyle, navigationBarBackgroundColor);
1182
1460
  const currentPage = Current.page;
1183
1461
  const pathname = handler.pathname;
1184
- const methodName = (_g = stacks.method) !== null && _g !== void 0 ? _g : '';
1462
+ const methodName = (_j = stacks.method) !== null && _j !== void 0 ? _j : '';
1185
1463
  const cacheTabs = stacks.getTabs();
1186
1464
  let shouldLoad = false;
1187
1465
  stacks.method = '';
@@ -1247,7 +1525,7 @@ function createRouter(app, config, framework) {
1247
1525
  shouldLoad = true;
1248
1526
  }
1249
1527
  if (shouldLoad || stacks.length < 1) {
1250
- const el = (_h = element.default) !== null && _h !== void 0 ? _h : element;
1528
+ const el = (_k = element.default) !== null && _k !== void 0 ? _k : element;
1251
1529
  const loadConfig = Object.assign({}, pageConfig);
1252
1530
  const stacksIndex = stacks.length;
1253
1531
  delete loadConfig['path'];
@@ -1272,8 +1550,57 @@ function createRouter(app, config, framework) {
1272
1550
  }
1273
1551
  render({ location: history.location, action: Action.Push });
1274
1552
  (_b = app.onShow) === null || _b === void 0 ? void 0 : _b.call(app, launchParam);
1553
+ window.addEventListener('visibilitychange', () => {
1554
+ var _a, _b;
1555
+ if (document.visibilityState === 'visible') {
1556
+ (_a = app.onShow) === null || _a === void 0 ? void 0 : _a.call(app, launchParam);
1557
+ }
1558
+ else {
1559
+ (_b = app.onHide) === null || _b === void 0 ? void 0 : _b.call(app, launchParam);
1560
+ }
1561
+ });
1275
1562
  return history.listen(render);
1276
1563
  }
1277
1564
 
1278
- export { createMultiRouter, createRouter, getCurrentPages, history, navigateBack, navigateTo, reLaunch, redirectTo, switchTab };
1279
- //# sourceMappingURL=index.esm.js.map
1565
+ function handleAppMount(config, _, appId = config.appId || 'app') {
1566
+ let app = document.getElementById(appId);
1567
+ let isPosition = true;
1568
+ if (!app) {
1569
+ app = document.createElement('div');
1570
+ app.id = appId;
1571
+ isPosition = false;
1572
+ }
1573
+ const appWrapper = (app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body;
1574
+ app.classList.add('taro_router');
1575
+ if (!isPosition)
1576
+ appWrapper.appendChild(app);
1577
+ initNavigationBar(appWrapper);
1578
+ }
1579
+ function handleAppMountWithTabbar(config, history, appId = config.appId || 'app') {
1580
+ let app = document.getElementById(appId);
1581
+ let isPosition = true;
1582
+ if (!app) {
1583
+ app = document.createElement('div');
1584
+ app.id = appId;
1585
+ isPosition = false;
1586
+ }
1587
+ const appWrapper = (app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body;
1588
+ app.classList.add('taro_router');
1589
+ const container = document.createElement('div');
1590
+ container.classList.add('taro-tabbar__container');
1591
+ container.id = 'container';
1592
+ const panel = document.createElement('div');
1593
+ panel.classList.add('taro-tabbar__panel');
1594
+ panel.appendChild(app.cloneNode(true));
1595
+ container.appendChild(panel);
1596
+ if (!isPosition) {
1597
+ appWrapper.appendChild(container);
1598
+ }
1599
+ else {
1600
+ appWrapper.replaceChild(container, app);
1601
+ }
1602
+ initTabbar(config, history);
1603
+ initNavigationBar(container);
1604
+ }
1605
+
1606
+ export { createMpaHistory, createMultiRouter, createRouter, getCurrentPages, handleAppMount, handleAppMountWithTabbar, history, isDingTalk, isWeixin, navigateBack, navigateTo, prependBasename, reLaunch, redirectTo, routesAlias, setHistory, setHistoryMode, setMpaTitle, setNavigationBarStyle, setTitle, switchTab };