@tarojs/router 4.0.0-beta.1 → 4.0.0-beta.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.
package/dist/index.cjs.js CHANGED
@@ -1,50 +1,40 @@
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);
18
-
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
- });
42
- }
43
-
44
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
45
- var e = new Error(message);
46
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
47
- };
11
+ function initTabbar(config, history) {
12
+ if (config.tabBar == null || config.tabBar.custom) {
13
+ return;
14
+ }
15
+ // TODO: custom-tab-bar
16
+ components.defineCustomElementTaroTabbar();
17
+ const tabbar = document.createElement('taro-tabbar');
18
+ const homePage = config.entryPagePath || (config.pages ? config.pages[0] : '');
19
+ tabbar.conf = config.tabBar;
20
+ tabbar.conf.homePage = history.location.pathname === '/' ? homePage : history.location.pathname;
21
+ const routerConfig = config.router;
22
+ tabbar.conf.mode = routerConfig && routerConfig.mode ? routerConfig.mode : 'hash';
23
+ if (routerConfig.customRoutes) {
24
+ tabbar.conf.custom = true;
25
+ tabbar.conf.customRoutes = routerConfig.customRoutes;
26
+ }
27
+ else {
28
+ tabbar.conf.custom = false;
29
+ tabbar.conf.customRoutes = {};
30
+ }
31
+ if (typeof routerConfig.basename !== 'undefined') {
32
+ tabbar.conf.basename = routerConfig.basename;
33
+ }
34
+ const container = document.getElementById('container');
35
+ container === null || container === void 0 ? void 0 : container.appendChild(tabbar);
36
+ taro.initTabBarApis(config);
37
+ }
48
38
 
49
39
  class RouterConfig {
50
40
  static set config(e) {
@@ -147,6 +137,13 @@ class MpaHistory {
147
137
  };
148
138
  }
149
139
  }
140
+ function setHistory(h, base = '/') {
141
+ exports.history = h;
142
+ basename = base;
143
+ }
144
+ function createMpaHistory(_) {
145
+ return new MpaHistory();
146
+ }
150
147
  function setHistoryMode(mode, base = '/') {
151
148
  const options = {
152
149
  window
@@ -156,7 +153,7 @@ function setHistoryMode(mode, base = '/') {
156
153
  exports.history = history.createBrowserHistory(options);
157
154
  }
158
155
  else if (mode === 'multi') {
159
- exports.history = new MpaHistory();
156
+ exports.history = createMpaHistory();
160
157
  }
161
158
  else {
162
159
  // default is hash
@@ -248,24 +245,28 @@ class Stacks {
248
245
  }
249
246
  const stacks = new Stacks();
250
247
 
251
- // export const removeLeadingSlash = (str = '') => str.replace(/^\.?\//, '')
252
- // export const removeTrailingSearch = (str = '') => str.replace(/\?[\s\S]*$/, '')
253
- const addLeadingSlash = (url = '') => (url.charAt(0) === '/' ? url : '/' + url);
254
- const hasBasename = (path = '', prefix = '') => new RegExp('^' + prefix + '(\\/|\\?|#|$)', 'i').test(path) || path === prefix;
255
- const stripBasename = (path = '', prefix = '') => hasBasename(path, prefix) ? path.substring(prefix.length) : path;
256
- const stripTrailing = (str = '') => str.replace(/[?#][\s\S]*$/, '');
257
- const getHomePage = (path = '', basename = '', customRoutes = {}, entryPagePath = '') => {
258
- var _a;
259
- const routePath = addLeadingSlash(stripBasename(path, basename));
260
- const alias = ((_a = Object.entries(customRoutes).find(([key]) => key === routePath)) === null || _a === void 0 ? void 0 : _a[1]) || routePath;
261
- return entryPagePath || (typeof alias === 'string' ? alias : alias[0]) || basename;
262
- };
263
- const getCurrentPage = (routerMode = 'hash', basename = '/') => {
264
- const pagePath = routerMode === 'hash'
265
- ? location.hash.slice(1).split('?')[0]
266
- : location.pathname;
267
- return addLeadingSlash(stripBasename(pagePath, basename));
268
- };
248
+ let preTitle = document.title;
249
+ let isLoadDdEntry = false;
250
+ const isWeixin = () => !!navigator.userAgent.match(/\bMicroMessenger\b/ig);
251
+ const isDingTalk = () => !!navigator.userAgent.match(/\bDingTalk\b/ig);
252
+ function setTitle(title) {
253
+ return tslib.__awaiter(this, void 0, void 0, function* () {
254
+ if (preTitle === title)
255
+ return title;
256
+ document.title = title;
257
+ preTitle = title;
258
+ if (process.env.SUPPORT_DINGTALK_NAVIGATE !== 'disabled' && isDingTalk()) {
259
+ if (!isLoadDdEntry) {
260
+ isLoadDdEntry = true;
261
+ require('dingtalk-jsapi/platform');
262
+ }
263
+ const setDingTitle = require('dingtalk-jsapi/api/biz/navigation/setTitle').default;
264
+ setDingTitle({ title });
265
+ }
266
+ return title;
267
+ });
268
+ }
269
+
269
270
  class RoutesAlias {
270
271
  constructor() {
271
272
  this.conf = [];
@@ -295,12 +296,12 @@ class RoutesAlias {
295
296
  set(customRoutes = {}) {
296
297
  for (let key in customRoutes) {
297
298
  const path = customRoutes[key];
298
- key = addLeadingSlash(key);
299
+ key = runtime.addLeadingSlash(key);
299
300
  if (typeof path === 'string') {
300
- this.conf.push([key, addLeadingSlash(path)]);
301
+ this.conf.push([key, runtime.addLeadingSlash(path)]);
301
302
  }
302
303
  else if ((path === null || path === void 0 ? void 0 : path.length) > 0) {
303
- this.conf.push(...path.map(p => [key, addLeadingSlash(p)]));
304
+ this.conf.push(...path.map(p => [key, runtime.addLeadingSlash(p)]));
304
305
  }
305
306
  }
306
307
  }
@@ -323,7 +324,7 @@ function processNavigateUrl(option) {
323
324
  pathPieces.pathname = parts.join('/');
324
325
  }
325
326
  // 处理自定义路由
326
- pathPieces.pathname = routesAlias.getAlias(addLeadingSlash(pathPieces.pathname));
327
+ pathPieces.pathname = routesAlias.getAlias(runtime.addLeadingSlash(pathPieces.pathname));
327
328
  // 处理 basename
328
329
  pathPieces.pathname = prependBasename(pathPieces.pathname);
329
330
  // hack fix history v5 bug: https://github.com/remix-run/history/issues/814
@@ -332,7 +333,7 @@ function processNavigateUrl(option) {
332
333
  return pathPieces;
333
334
  }
334
335
  function navigate(option, method) {
335
- return __awaiter(this, void 0, void 0, function* () {
336
+ return tslib.__awaiter(this, void 0, void 0, function* () {
336
337
  return new Promise((resolve, reject) => {
337
338
  stacks.method = method;
338
339
  const { success, complete, fail } = option;
@@ -403,37 +404,6 @@ function getCurrentPages() {
403
404
  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, '')) || '' })); });
404
405
  }
405
406
 
406
- let md;
407
- let preTitle = document.title;
408
- let isLoadDdEntry = false;
409
- function getMobileDetect() {
410
- if (!md) {
411
- md = new MobileDetect__default["default"](navigator.userAgent);
412
- }
413
- return md;
414
- }
415
- function setTitle(title) {
416
- return __awaiter(this, void 0, void 0, function* () {
417
- if (preTitle === title)
418
- return title;
419
- document.title = title;
420
- preTitle = title;
421
- if (process.env.SUPPORT_DINGTALK_NAVIGATE !== 'disabled' && isDingTalk()) {
422
- if (!isLoadDdEntry) {
423
- isLoadDdEntry = true;
424
- require('dingtalk-jsapi/platform');
425
- }
426
- const setDingTitle = require('dingtalk-jsapi/api/biz/navigation/setTitle').default;
427
- setDingTitle({ title });
428
- }
429
- return title;
430
- });
431
- }
432
- function isDingTalk() {
433
- const md = getMobileDetect();
434
- return md.match(/DingTalk/ig);
435
- }
436
-
437
407
  let pageResizeFn;
438
408
  function bindPageResize(page) {
439
409
  pageResizeFn && window.removeEventListener('resize', pageResizeFn);
@@ -513,7 +483,7 @@ function loadAnimateStyle(ms = 300) {
513
483
  /**
514
484
  * 插入路由相关样式
515
485
  */
516
- function loadRouterStyle(usingWindowScroll) {
486
+ function loadRouterStyle(enableTabBar, enableWindowScroll) {
517
487
  const css = `
518
488
  .taro_router {
519
489
  position: relative;
@@ -524,13 +494,13 @@ function loadRouterStyle(usingWindowScroll) {
524
494
  .taro_page {
525
495
  width: 100%;
526
496
  height: 100%;
527
- ${usingWindowScroll ? '' : `
497
+ ${enableWindowScroll ? '' : `
528
498
  overflow-x: hidden;
529
499
  overflow-y: scroll;
530
500
  max-height: 100vh;
531
- `}
501
+ `}
532
502
  }
533
-
503
+ ${enableTabBar ? `
534
504
  .taro-tabbar__container > .taro-tabbar__panel {
535
505
  overflow: hidden;
536
506
  }
@@ -540,6 +510,7 @@ function loadRouterStyle(usingWindowScroll) {
540
510
  max-height: calc(100vh - var(--taro-tabbar-height) - env(safe-area-inset-bottom));
541
511
  }
542
512
 
513
+ ` : ''}
543
514
  .taro_page_shade,
544
515
  .taro_router > .taro_page.taro_page_show.taro_page_stationed:not(.taro_page_shade):not(.taro_tabbar_page):not(:last-child) {
545
516
  display: none;
@@ -555,38 +526,10 @@ function addStyle(css) {
555
526
  document.getElementsByTagName('head')[0].appendChild(style);
556
527
  }
557
528
 
558
- // @ts-nocheck
559
- function initTabbar(config) {
560
- if (config.tabBar == null || config.tabBar.custom) {
561
- return;
562
- }
563
- // TODO: custom-tab-bar
564
- components.defineCustomElementTaroTabbar();
565
- const tabbar = document.createElement('taro-tabbar');
566
- const homePage = config.entryPagePath || (config.pages ? config.pages[0] : '');
567
- tabbar.conf = config.tabBar;
568
- tabbar.conf.homePage = exports.history.location.pathname === '/' ? homePage : exports.history.location.pathname;
569
- const routerConfig = config.router;
570
- tabbar.conf.mode = routerConfig && routerConfig.mode ? routerConfig.mode : 'hash';
571
- if (routerConfig.customRoutes) {
572
- tabbar.conf.custom = true;
573
- tabbar.conf.customRoutes = routerConfig.customRoutes;
574
- }
575
- else {
576
- tabbar.conf.custom = false;
577
- tabbar.conf.customRoutes = {};
578
- }
579
- if (typeof routerConfig.basename !== 'undefined') {
580
- tabbar.conf.basename = routerConfig.basename;
581
- }
582
- const container = document.getElementById('container');
583
- container === null || container === void 0 ? void 0 : container.appendChild(tabbar);
584
- taro.initTabBarApis(config);
585
- }
586
-
587
529
  /* eslint-disable dot-notation */
588
530
  class MultiPageHandler {
589
- constructor(config) {
531
+ constructor(config, history) {
532
+ this.history = history;
590
533
  this.config = config;
591
534
  this.mount();
592
535
  }
@@ -602,7 +545,7 @@ class MultiPageHandler {
602
545
  get pageConfig() { return this.config.route; }
603
546
  get isTabBar() {
604
547
  var _a;
605
- const routePath = addLeadingSlash(stripBasename(this.pathname, this.basename));
548
+ const routePath = runtime.addLeadingSlash(runtime.stripBasename(this.pathname, this.basename));
606
549
  const pagePath = ((_a = Object.entries(this.customRoutes).find(([, target]) => {
607
550
  if (typeof target === 'string') {
608
551
  return target === routePath;
@@ -629,43 +572,22 @@ class MultiPageHandler {
629
572
  getQuery(search = '', options = {}) {
630
573
  search = search ? `${search}&${this.search}` : this.search;
631
574
  const query = search
632
- ? queryString__default["default"].parse(search)
575
+ ? queryString.parse(search)
633
576
  : {};
634
577
  return Object.assign(Object.assign({}, query), options);
635
578
  }
636
- mount() {
637
- setHistoryMode(this.routerMode, this.router.basename);
638
- loadRouterStyle(this.usingWindowScroll);
639
- const appId = this.appId;
640
- let app = document.getElementById(appId);
641
- let isPosition = true;
642
- if (!app) {
643
- app = document.createElement('div');
644
- app.id = appId;
645
- isPosition = false;
646
- }
647
- const appWrapper = (app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body;
648
- app.classList.add('taro_router');
649
- if (this.tabBarList.length > 1) {
650
- const container = document.createElement('div');
651
- container.classList.add('taro-tabbar__container');
652
- container.id = 'container';
653
- const panel = document.createElement('div');
654
- panel.classList.add('taro-tabbar__panel');
655
- panel.appendChild(app.cloneNode(true));
656
- container.appendChild(panel);
657
- if (!isPosition) {
658
- appWrapper.appendChild(container);
659
- }
660
- else {
661
- appWrapper.replaceChild(container, app);
662
- }
663
- initTabbar(this.config);
664
- }
665
- else {
666
- if (!isPosition)
667
- appWrapper.appendChild(app);
579
+ isDefaultNavigationStyle() {
580
+ var _a, _b;
581
+ let style = (_a = this.config.window) === null || _a === void 0 ? void 0 : _a.navigationStyle;
582
+ if (typeof ((_b = this.pageConfig) === null || _b === void 0 ? void 0 : _b.navigationStyle) === 'string') {
583
+ style = this.pageConfig.navigationStyle;
668
584
  }
585
+ return style !== 'custom';
586
+ }
587
+ mount() {
588
+ setHistory(this.history, this.basename);
589
+ // Note: 注入页面样式
590
+ loadRouterStyle(this.tabBarList.length > 1, this.usingWindowScroll);
669
591
  }
670
592
  onReady(page, onLoad = true) {
671
593
  var _a;
@@ -695,10 +617,13 @@ class MultiPageHandler {
695
617
  return;
696
618
  (_a = page.onLoad) === null || _a === void 0 ? void 0 : _a.call(page, this.getQuery('', page.options), () => {
697
619
  var _a;
620
+ const pageEl = this.getPageContainer(page);
698
621
  if (this.isTabBar) {
699
- const pageEl = this.getPageContainer(page);
700
622
  pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.add('taro_tabbar_page');
701
623
  }
624
+ if (this.isDefaultNavigationStyle()) {
625
+ pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.add('taro_navigation_page');
626
+ }
702
627
  this.onReady(page, true);
703
628
  (_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
704
629
  this.bindPageEvents(page, pageConfig);
@@ -755,14 +680,14 @@ const launchStampId$1 = createStampId$1();
755
680
  * - TabBar 会多次加载
756
681
  * - 不支持路由动画
757
682
  */
758
- function createMultiRouter(app, config, framework) {
683
+ function createMultiRouter(history, app, config, framework) {
759
684
  var _a, _b, _c, _d, _e, _f;
760
- return __awaiter(this, void 0, void 0, function* () {
685
+ return tslib.__awaiter(this, void 0, void 0, function* () {
761
686
  if (typeof app.onUnhandledRejection === 'function') {
762
687
  window.addEventListener('unhandledrejection', app.onUnhandledRejection);
763
688
  }
764
689
  RouterConfig.config = config;
765
- const handler = new MultiPageHandler(config);
690
+ const handler = new MultiPageHandler(config, history);
766
691
  const launchParam = {
767
692
  path: config.pageName,
768
693
  query: handler.getQuery(launchStampId$1),
@@ -811,14 +736,15 @@ function createMultiRouter(app, config, framework) {
811
736
 
812
737
  /* eslint-disable dot-notation */
813
738
  class PageHandler {
814
- constructor(config) {
739
+ constructor(config, history) {
740
+ this.history = history;
815
741
  this.defaultAnimation = { duration: 300, delay: 50 };
816
742
  this.config = config;
817
- this.homePage = getHomePage(this.routes[0].path, this.basename, this.customRoutes, this.config.entryPagePath);
743
+ this.homePage = runtime.getHomePage(this.routes[0].path, this.basename, this.customRoutes, this.config.entryPagePath);
818
744
  this.mount();
819
745
  }
820
746
  get currentPage() {
821
- const routePath = getCurrentPage(this.routerMode, this.basename);
747
+ const routePath = runtime.getCurrentPage(this.routerMode, this.basename);
822
748
  return routePath === '/' ? this.homePage : routePath;
823
749
  }
824
750
  get appId() { return this.config.appId || 'app'; }
@@ -849,17 +775,17 @@ class PageHandler {
849
775
  get pathname() { return this.router.pathname; }
850
776
  get basename() { return this.router.basename || ''; }
851
777
  get pageConfig() {
852
- const routePath = addLeadingSlash(stripBasename(this.pathname, this.basename));
853
- const homePage = addLeadingSlash(this.homePage);
778
+ const routePath = runtime.addLeadingSlash(runtime.stripBasename(this.pathname, this.basename));
779
+ const homePage = runtime.addLeadingSlash(this.homePage);
854
780
  return this.routes.find(r => {
855
781
  var _a;
856
- const pagePath = addLeadingSlash(r.path);
782
+ const pagePath = runtime.addLeadingSlash(r.path);
857
783
  return [pagePath, homePage].includes(routePath) || ((_a = routesAlias.getConfig(pagePath)) === null || _a === void 0 ? void 0 : _a.includes(routePath));
858
784
  });
859
785
  }
860
786
  isTabBar(pathname) {
861
787
  var _a;
862
- const routePath = addLeadingSlash(stripBasename(pathname, this.basename)).split('?')[0];
788
+ const routePath = runtime.addLeadingSlash(runtime.stripBasename(pathname, this.basename)).split('?')[0];
863
789
  const pagePath = ((_a = Object.entries(this.customRoutes).find(([, target]) => {
864
790
  if (typeof target === 'string') {
865
791
  return target === routePath;
@@ -869,11 +795,19 @@ class PageHandler {
869
795
  }
870
796
  return false;
871
797
  })) === null || _a === void 0 ? void 0 : _a[0]) || routePath;
872
- return !!pagePath && this.tabBarList.some(t => stripTrailing(t.pagePath) === pagePath);
798
+ return !!pagePath && this.tabBarList.some(t => runtime.stripTrailing(t.pagePath) === pagePath);
799
+ }
800
+ isDefaultNavigationStyle() {
801
+ var _a, _b;
802
+ let style = (_a = this.config.window) === null || _a === void 0 ? void 0 : _a.navigationStyle;
803
+ if (typeof ((_b = this.pageConfig) === null || _b === void 0 ? void 0 : _b.navigationStyle) === 'string') {
804
+ style = this.pageConfig.navigationStyle;
805
+ }
806
+ return style !== 'custom';
873
807
  }
874
808
  isSamePage(page) {
875
- const routePath = stripBasename(this.pathname, this.basename);
876
- const pagePath = stripBasename(page === null || page === void 0 ? void 0 : page.path, this.basename);
809
+ const routePath = runtime.stripBasename(this.pathname, this.basename);
810
+ const pagePath = runtime.stripBasename(page === null || page === void 0 ? void 0 : page.path, this.basename);
877
811
  return pagePath.startsWith(routePath + '?');
878
812
  }
879
813
  get search() {
@@ -903,46 +837,17 @@ class PageHandler {
903
837
  getQuery(stamp = '', search = '', options = {}) {
904
838
  search = search ? `${search}&${this.search}` : this.search;
905
839
  const query = search
906
- ? queryString__default["default"].parse(search, { decode: false })
840
+ ? queryString.parse(search, { decode: false })
907
841
  : {};
908
842
  query.stamp = stamp;
909
843
  return Object.assign(Object.assign({}, query), options);
910
844
  }
911
845
  mount() {
912
- setHistoryMode(this.routerMode, this.router.basename);
846
+ setHistory(this.history, this.basename);
913
847
  this.pathname = exports.history.location.pathname;
848
+ // Note: 注入页面样式
914
849
  this.animation && loadAnimateStyle(this.animationDuration);
915
- loadRouterStyle(this.usingWindowScroll);
916
- const appId = this.appId;
917
- let app = document.getElementById(appId);
918
- let isPosition = true;
919
- if (!app) {
920
- app = document.createElement('div');
921
- app.id = appId;
922
- isPosition = false;
923
- }
924
- const appWrapper = (app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body;
925
- app.classList.add('taro_router');
926
- if (this.tabBarList.length > 1) {
927
- const container = document.createElement('div');
928
- container.classList.add('taro-tabbar__container');
929
- container.id = 'container';
930
- const panel = document.createElement('div');
931
- panel.classList.add('taro-tabbar__panel');
932
- panel.appendChild(app.cloneNode(true));
933
- container.appendChild(panel);
934
- if (!isPosition) {
935
- appWrapper.appendChild(container);
936
- }
937
- else {
938
- appWrapper.replaceChild(container, app);
939
- }
940
- initTabbar(this.config);
941
- }
942
- else {
943
- if (!isPosition)
944
- appWrapper.appendChild(app);
945
- }
850
+ loadRouterStyle(this.tabBarList.length > 1, this.usingWindowScroll);
946
851
  }
947
852
  onReady(page, onLoad = true) {
948
853
  var _a;
@@ -977,19 +882,22 @@ class PageHandler {
977
882
  if (pageEl) {
978
883
  pageEl.classList.remove('taro_page_shade');
979
884
  this.isTabBar(this.pathname) && pageEl.classList.add('taro_tabbar_page');
885
+ this.isDefaultNavigationStyle() && pageEl.classList.add('taro_navigation_page');
980
886
  this.addAnimation(pageEl, pageNo === 0);
981
887
  (_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
982
888
  this.bindPageEvents(page, pageConfig);
983
889
  this.triggerRouterChange();
984
890
  }
985
891
  else {
892
+ // FIXME 在 iOS 端快速切换页面时,可能不会执行回调注入对应类名导致 TabBar 白屏
986
893
  (_b = page.onLoad) === null || _b === void 0 ? void 0 : _b.call(page, param, () => {
987
894
  var _a;
988
895
  pageEl = this.getPageContainer(page);
989
896
  this.isTabBar(this.pathname) && (pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.add('taro_tabbar_page'));
897
+ this.isDefaultNavigationStyle() && (pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.add('taro_navigation_page'));
990
898
  this.addAnimation(pageEl, pageNo === 0);
991
- this.onReady(page, true);
992
899
  (_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
900
+ this.onReady(page, true);
993
901
  this.bindPageEvents(page, pageConfig);
994
902
  this.triggerRouterChange();
995
903
  });
@@ -1051,8 +959,8 @@ class PageHandler {
1051
959
  var _a;
1052
960
  pageEl = this.getPageContainer(page);
1053
961
  this.addAnimation(pageEl, pageNo === 0);
1054
- this.onReady(page, false);
1055
962
  (_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
963
+ this.onReady(page, false);
1056
964
  this.bindPageEvents(page, pageConfig);
1057
965
  this.triggerRouterChange();
1058
966
  });
@@ -1139,24 +1047,24 @@ class PageHandler {
1139
1047
 
1140
1048
  const createStampId = runtime.incrementId();
1141
1049
  let launchStampId = createStampId();
1142
- function createRouter(app, config, framework) {
1050
+ function createRouter(history$1, app, config, framework) {
1143
1051
  var _a, _b;
1144
1052
  if (typeof app.onUnhandledRejection === 'function') {
1145
1053
  window.addEventListener('unhandledrejection', app.onUnhandledRejection);
1146
1054
  }
1147
1055
  RouterConfig.config = config;
1148
- const handler = new PageHandler(config);
1056
+ const handler = new PageHandler(config, history$1);
1149
1057
  routesAlias.set(handler.router.customRoutes);
1150
1058
  const basename = handler.router.basename;
1151
1059
  const routes = handler.routes.map(route => {
1152
- const routePath = addLeadingSlash(route.path);
1060
+ const routePath = runtime.addLeadingSlash(route.path);
1153
1061
  const paths = routesAlias.getAll(routePath);
1154
1062
  return {
1155
1063
  path: paths.length < 1 ? routePath : paths,
1156
1064
  action: route.load
1157
1065
  };
1158
1066
  });
1159
- const router = new UniversalRouter__default["default"](routes, { baseUrl: basename || '' });
1067
+ const router = new UniversalRouter(routes, { baseUrl: basename || '' });
1160
1068
  const launchParam = {
1161
1069
  path: handler.currentPage,
1162
1070
  query: handler.getQuery(launchStampId),
@@ -1167,8 +1075,8 @@ function createRouter(app, config, framework) {
1167
1075
  runtime.eventCenter.trigger('__taroRouterLaunch', launchParam);
1168
1076
  (_a = app.onLaunch) === null || _a === void 0 ? void 0 : _a.call(app, launchParam);
1169
1077
  app.onError && window.addEventListener('error', e => { var _a; return (_a = app.onError) === null || _a === void 0 ? void 0 : _a.call(app, e.message); });
1170
- const render = ({ location, action }) => __awaiter(this, void 0, void 0, function* () {
1171
- var _c, _d, _e, _f, _g, _h;
1078
+ const render = ({ location, action }) => tslib.__awaiter(this, void 0, void 0, function* () {
1079
+ var _c, _d, _e, _f, _g, _h, _j, _k, _l;
1172
1080
  handler.pathname = decodeURI(location.pathname);
1173
1081
  if ((_c = window.__taroAppConfig) === null || _c === void 0 ? void 0 : _c.usingWindowScroll)
1174
1082
  window.scrollTo(0, 0);
@@ -1197,22 +1105,35 @@ function createRouter(app, config, framework) {
1197
1105
  window.location.reload();
1198
1106
  }
1199
1107
  else {
1200
- throw new Error(error);
1108
+ throw error;
1201
1109
  }
1202
1110
  }
1203
1111
  if (!element)
1204
1112
  return;
1205
1113
  const pageConfig = handler.pageConfig;
1206
1114
  let enablePullDownRefresh = ((_e = config === null || config === void 0 ? void 0 : config.window) === null || _e === void 0 ? void 0 : _e.enablePullDownRefresh) || false;
1115
+ let navigationStyle = ((_f = config === null || config === void 0 ? void 0 : config.window) === null || _f === void 0 ? void 0 : _f.navigationStyle) || 'default';
1116
+ let navigationBarTextStyle = ((_g = config === null || config === void 0 ? void 0 : config.window) === null || _g === void 0 ? void 0 : _g.navigationBarTextStyle) || 'white';
1117
+ let navigationBarBackgroundColor = ((_h = config === null || config === void 0 ? void 0 : config.window) === null || _h === void 0 ? void 0 : _h.navigationBarBackgroundColor) || '#000000';
1207
1118
  if (pageConfig) {
1208
- setTitle((_f = pageConfig.navigationBarTitleText) !== null && _f !== void 0 ? _f : document.title);
1119
+ setTitle((_j = pageConfig.navigationBarTitleText) !== null && _j !== void 0 ? _j : document.title);
1209
1120
  if (typeof pageConfig.enablePullDownRefresh === 'boolean') {
1210
1121
  enablePullDownRefresh = pageConfig.enablePullDownRefresh;
1211
1122
  }
1123
+ if (typeof pageConfig.navigationStyle === 'string') {
1124
+ navigationStyle = pageConfig.navigationStyle;
1125
+ }
1126
+ if (typeof pageConfig.navigationBarTextStyle === 'string') {
1127
+ navigationBarTextStyle = pageConfig.navigationBarTextStyle;
1128
+ }
1129
+ if (typeof pageConfig.navigationBarBackgroundColor === 'string') {
1130
+ navigationBarBackgroundColor = pageConfig.navigationBarBackgroundColor;
1131
+ }
1212
1132
  }
1133
+ runtime.eventCenter.trigger('__taroSetNavigationStyle', navigationStyle, navigationBarTextStyle, navigationBarBackgroundColor);
1213
1134
  const currentPage = runtime.Current.page;
1214
1135
  const pathname = handler.pathname;
1215
- const methodName = (_g = stacks.method) !== null && _g !== void 0 ? _g : '';
1136
+ const methodName = (_k = stacks.method) !== null && _k !== void 0 ? _k : '';
1216
1137
  const cacheTabs = stacks.getTabs();
1217
1138
  let shouldLoad = false;
1218
1139
  stacks.method = '';
@@ -1278,7 +1199,7 @@ function createRouter(app, config, framework) {
1278
1199
  shouldLoad = true;
1279
1200
  }
1280
1201
  if (shouldLoad || stacks.length < 1) {
1281
- const el = (_h = element.default) !== null && _h !== void 0 ? _h : element;
1202
+ const el = (_l = element.default) !== null && _l !== void 0 ? _l : element;
1282
1203
  const loadConfig = Object.assign({}, pageConfig);
1283
1204
  const stacksIndex = stacks.length;
1284
1205
  delete loadConfig['path'];
@@ -1297,21 +1218,77 @@ function createRouter(app, config, framework) {
1297
1218
  handler.load(page, pageConfig, pageStampId, stacksIndex);
1298
1219
  }
1299
1220
  });
1300
- const routePath = addLeadingSlash(stripBasename(exports.history.location.pathname, handler.basename));
1221
+ const routePath = runtime.addLeadingSlash(runtime.stripBasename(history$1.location.pathname, handler.basename));
1301
1222
  if (routePath === '/') {
1302
- exports.history.replace(prependBasename(handler.homePage + exports.history.location.search));
1223
+ history$1.replace(prependBasename(handler.homePage + history$1.location.search));
1303
1224
  }
1304
- render({ location: exports.history.location, action: history.Action.Push });
1225
+ render({ location: history$1.location, action: history.Action.Push });
1305
1226
  (_b = app.onShow) === null || _b === void 0 ? void 0 : _b.call(app, launchParam);
1306
- return exports.history.listen(render);
1227
+ return history$1.listen(render);
1228
+ }
1229
+
1230
+ function handleAppMount(config, _, appId = config.appId || 'app') {
1231
+ let app = document.getElementById(appId);
1232
+ let isPosition = true;
1233
+ if (!app) {
1234
+ app = document.createElement('div');
1235
+ app.id = appId;
1236
+ isPosition = false;
1237
+ }
1238
+ const appWrapper = (app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body;
1239
+ app.classList.add('taro_router');
1240
+ if (!isPosition)
1241
+ appWrapper.appendChild(app);
1242
+ }
1243
+ function handleAppMountWithTabbar(config, history, appId = config.appId || 'app') {
1244
+ let app = document.getElementById(appId);
1245
+ let isPosition = true;
1246
+ if (!app) {
1247
+ app = document.createElement('div');
1248
+ app.id = appId;
1249
+ isPosition = false;
1250
+ }
1251
+ const appWrapper = (app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body;
1252
+ app.classList.add('taro_router');
1253
+ const container = document.createElement('div');
1254
+ container.classList.add('taro-tabbar__container');
1255
+ container.id = 'container';
1256
+ const panel = document.createElement('div');
1257
+ panel.classList.add('taro-tabbar__panel');
1258
+ panel.appendChild(app.cloneNode(true));
1259
+ container.appendChild(panel);
1260
+ if (!isPosition) {
1261
+ appWrapper.appendChild(container);
1262
+ }
1263
+ else {
1264
+ appWrapper.replaceChild(container, app);
1265
+ }
1266
+ initTabbar(config, history);
1307
1267
  }
1308
1268
 
1269
+ Object.defineProperty(exports, 'createBrowserHistory', {
1270
+ enumerable: true,
1271
+ get: function () { return history.createBrowserHistory; }
1272
+ });
1273
+ Object.defineProperty(exports, 'createHashHistory', {
1274
+ enumerable: true,
1275
+ get: function () { return history.createHashHistory; }
1276
+ });
1277
+ exports.createMpaHistory = createMpaHistory;
1309
1278
  exports.createMultiRouter = createMultiRouter;
1310
1279
  exports.createRouter = createRouter;
1311
1280
  exports.getCurrentPages = getCurrentPages;
1281
+ exports.handleAppMount = handleAppMount;
1282
+ exports.handleAppMountWithTabbar = handleAppMountWithTabbar;
1283
+ exports.isDingTalk = isDingTalk;
1284
+ exports.isWeixin = isWeixin;
1312
1285
  exports.navigateBack = navigateBack;
1313
1286
  exports.navigateTo = navigateTo;
1287
+ exports.prependBasename = prependBasename;
1314
1288
  exports.reLaunch = reLaunch;
1315
1289
  exports.redirectTo = redirectTo;
1290
+ exports.routesAlias = routesAlias;
1291
+ exports.setHistory = setHistory;
1292
+ exports.setHistoryMode = setHistoryMode;
1293
+ exports.setTitle = setTitle;
1316
1294
  exports.switchTab = switchTab;
1317
- //# sourceMappingURL=index.cjs.js.map