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