@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
@@ -1,24 +1,22 @@
1
- /* eslint-disable dot-notation */
2
- import { Current, eventCenter, requestAnimationFrame } from '@tarojs/runtime';
1
+ import { getHomePage, getCurrentPage, addLeadingSlash, stripBasename, stripTrailing, requestAnimationFrame, eventCenter, Current } from '@tarojs/runtime';
3
2
  import queryString from 'query-string';
4
- import { bindPageResize } from '../events/resize';
5
- import { bindPageScroll } from '../events/scroll';
6
- import { history, setHistoryMode } from '../history';
7
- import { loadAnimateStyle, loadRouterStyle } from '../style';
8
- import { initTabbar } from '../tabbar';
9
- import { addLeadingSlash, getCurrentPage, getHomePage, routesAlias, stripBasename, stripTrailing } from '../utils';
10
- import stacks from './stack';
11
- function setDisplay(el, type = '') {
12
- if (el) {
13
- el.style.display = type;
14
- }
15
- }
16
- export default class PageHandler {
17
- constructor(config) {
3
+ import { bindPageResize } from '../events/resize.js';
4
+ import { bindPageScroll } from '../events/scroll.js';
5
+ import { setHistory, history } from '../history.js';
6
+ import { loadAnimateStyle, loadRouterStyle } from '../style.js';
7
+ import { routesAlias } from '../utils/index.js';
8
+ import NavigationBarHandler from './navigation-bar.js';
9
+ import stacks from './stack.js';
10
+
11
+ /* eslint-disable dot-notation */
12
+ class PageHandler {
13
+ constructor(config, history) {
14
+ this.history = history;
18
15
  this.defaultAnimation = { duration: 300, delay: 50 };
19
16
  this.config = config;
20
17
  this.homePage = getHomePage(this.routes[0].path, this.basename, this.customRoutes, this.config.entryPagePath);
21
18
  this.mount();
19
+ this.navigationBarHandler = new NavigationBarHandler(this);
22
20
  }
23
21
  get currentPage() {
24
22
  const routePath = getCurrentPage(this.routerMode, this.basename);
@@ -74,6 +72,14 @@ export default class PageHandler {
74
72
  })) === null || _a === void 0 ? void 0 : _a[0]) || routePath;
75
73
  return !!pagePath && this.tabBarList.some(t => stripTrailing(t.pagePath) === pagePath);
76
74
  }
75
+ isDefaultNavigationStyle() {
76
+ var _a, _b;
77
+ let style = (_a = this.config.window) === null || _a === void 0 ? void 0 : _a.navigationStyle;
78
+ if (typeof ((_b = this.pageConfig) === null || _b === void 0 ? void 0 : _b.navigationStyle) === 'string') {
79
+ style = this.pageConfig.navigationStyle;
80
+ }
81
+ return style !== 'custom';
82
+ }
77
83
  isSamePage(page) {
78
84
  const routePath = stripBasename(this.pathname, this.basename);
79
85
  const pagePath = stripBasename(page === null || page === void 0 ? void 0 : page.path, this.basename);
@@ -112,40 +118,11 @@ export default class PageHandler {
112
118
  return Object.assign(Object.assign({}, query), options);
113
119
  }
114
120
  mount() {
115
- setHistoryMode(this.routerMode, this.router.basename);
121
+ setHistory(this.history, this.basename);
116
122
  this.pathname = history.location.pathname;
123
+ // Note: 注入页面样式
117
124
  this.animation && loadAnimateStyle(this.animationDuration);
118
- loadRouterStyle(this.usingWindowScroll);
119
- const appId = this.appId;
120
- let app = document.getElementById(appId);
121
- let isPosition = true;
122
- if (!app) {
123
- app = document.createElement('div');
124
- app.id = appId;
125
- isPosition = false;
126
- }
127
- const appWrapper = (app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body;
128
- app.classList.add('taro_router');
129
- if (this.tabBarList.length > 1) {
130
- const container = document.createElement('div');
131
- container.classList.add('taro-tabbar__container');
132
- container.id = 'container';
133
- const panel = document.createElement('div');
134
- panel.classList.add('taro-tabbar__panel');
135
- panel.appendChild(app.cloneNode(true));
136
- container.appendChild(panel);
137
- if (!isPosition) {
138
- appWrapper.appendChild(container);
139
- }
140
- else {
141
- appWrapper.replaceChild(container, app);
142
- }
143
- initTabbar(this.config);
144
- }
145
- else {
146
- if (!isPosition)
147
- appWrapper.appendChild(app);
148
- }
125
+ loadRouterStyle(this.tabBarList.length > 1, this.usingWindowScroll);
149
126
  }
150
127
  onReady(page, onLoad = true) {
151
128
  var _a;
@@ -178,21 +155,26 @@ export default class PageHandler {
178
155
  const param = this.getQuery(stampId, '', page.options);
179
156
  let pageEl = this.getPageContainer(page);
180
157
  if (pageEl) {
181
- setDisplay(pageEl);
158
+ pageEl.classList.remove('taro_page_shade');
182
159
  this.isTabBar(this.pathname) && pageEl.classList.add('taro_tabbar_page');
160
+ this.isDefaultNavigationStyle() && pageEl.classList.add('taro_navigation_page');
183
161
  this.addAnimation(pageEl, pageNo === 0);
184
162
  (_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
163
+ this.navigationBarHandler.load();
185
164
  this.bindPageEvents(page, pageConfig);
186
165
  this.triggerRouterChange();
187
166
  }
188
167
  else {
168
+ // FIXME 在 iOS 端快速切换页面时,可能不会执行回调注入对应类名导致 TabBar 白屏
189
169
  (_b = page.onLoad) === null || _b === void 0 ? void 0 : _b.call(page, param, () => {
190
170
  var _a;
191
171
  pageEl = this.getPageContainer(page);
192
172
  this.isTabBar(this.pathname) && (pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.add('taro_tabbar_page'));
173
+ this.isDefaultNavigationStyle() && (pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.add('taro_navigation_page'));
193
174
  this.addAnimation(pageEl, pageNo === 0);
194
- this.onReady(page, true);
195
175
  (_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
176
+ this.navigationBarHandler.load();
177
+ this.onReady(page, true);
196
178
  this.bindPageEvents(page, pageConfig);
197
179
  this.triggerRouterChange();
198
180
  });
@@ -243,9 +225,10 @@ export default class PageHandler {
243
225
  const param = this.getQuery(page['$taroParams']['stamp'], '', page.options);
244
226
  let pageEl = this.getPageContainer(page);
245
227
  if (pageEl) {
246
- setDisplay(pageEl);
228
+ pageEl.classList.remove('taro_page_shade');
247
229
  this.addAnimation(pageEl, pageNo === 0);
248
230
  (_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
231
+ this.navigationBarHandler.load();
249
232
  this.bindPageEvents(page, pageConfig);
250
233
  this.triggerRouterChange();
251
234
  }
@@ -254,8 +237,9 @@ export default class PageHandler {
254
237
  var _a;
255
238
  pageEl = this.getPageContainer(page);
256
239
  this.addAnimation(pageEl, pageNo === 0);
257
- this.onReady(page, false);
258
240
  (_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
241
+ this.navigationBarHandler.load();
242
+ this.onReady(page, false);
259
243
  this.bindPageEvents(page, pageConfig);
260
244
  this.triggerRouterChange();
261
245
  });
@@ -271,12 +255,12 @@ export default class PageHandler {
271
255
  if (this.hideTimer) {
272
256
  clearTimeout(this.hideTimer);
273
257
  this.hideTimer = null;
274
- setDisplay(this.lastHidePage, 'none');
258
+ pageEl.classList.add('taro_page_shade');
275
259
  }
276
260
  this.lastHidePage = pageEl;
277
261
  this.hideTimer = setTimeout(() => {
278
262
  this.hideTimer = null;
279
- setDisplay(this.lastHidePage, 'none');
263
+ pageEl.classList.add('taro_page_shade');
280
264
  }, this.animationDuration + this.animationDelay);
281
265
  (_a = page.onHide) === null || _a === void 0 ? void 0 : _a.call(page);
282
266
  }
@@ -339,3 +323,5 @@ export default class PageHandler {
339
323
  }, 0);
340
324
  }
341
325
  }
326
+
327
+ export { PageHandler as default };
@@ -1,3 +1,5 @@
1
- import type { AppInstance } from '@tarojs/runtime';
2
- import type { SpaRouterConfig } from '../../types/router';
3
- export declare function createRouter(app: AppInstance, config: SpaRouterConfig, framework?: string): () => void;
1
+ import { AppInstance } from '@tarojs/runtime';
2
+ import { History } from "../history.js";
3
+ import { SpaRouterConfig } from '../../types/router';
4
+ declare function createRouter(history: History, app: AppInstance, config: SpaRouterConfig, framework?: string): () => void;
5
+ export { createRouter };
@@ -1,31 +1,22 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- /* eslint-disable dot-notation */
11
- import { createPageConfig, Current, eventCenter, hooks, incrementId, stringify, } from '@tarojs/runtime';
12
- import { Action as LocationAction } from 'history';
1
+ import { __awaiter } from 'tslib';
2
+ import { incrementId, addLeadingSlash, eventCenter, stripBasename, Current, createPageConfig, hooks, stringify } from '@tarojs/runtime';
3
+ import { Action } from 'history';
13
4
  import UniversalRouter from 'universal-router';
14
- import { history, prependBasename } from '../history';
15
- import { addLeadingSlash, routesAlias, stripBasename } from '../utils';
16
- import { setTitle } from '../utils/navigate';
17
- import { RouterConfig } from '.';
18
- import PageHandler from './page';
19
- import stacks from './stack';
5
+ import { prependBasename } from '../history.js';
6
+ import { routesAlias } from '../utils/index.js';
7
+ import { RouterConfig } from './index.js';
8
+ import PageHandler from './page.js';
9
+ import stacks from './stack.js';
10
+
20
11
  const createStampId = incrementId();
21
12
  let launchStampId = createStampId();
22
- export function createRouter(app, config, framework) {
13
+ function createRouter(history, app, config, framework) {
23
14
  var _a, _b;
24
15
  if (typeof app.onUnhandledRejection === 'function') {
25
16
  window.addEventListener('unhandledrejection', app.onUnhandledRejection);
26
17
  }
27
18
  RouterConfig.config = config;
28
- const handler = new PageHandler(config);
19
+ const handler = new PageHandler(config, history);
29
20
  routesAlias.set(handler.router.customRoutes);
30
21
  const basename = handler.router.basename;
31
22
  const routes = handler.routes.map(route => {
@@ -48,7 +39,7 @@ export function createRouter(app, config, framework) {
48
39
  (_a = app.onLaunch) === null || _a === void 0 ? void 0 : _a.call(app, launchParam);
49
40
  app.onError && window.addEventListener('error', e => { var _a; return (_a = app.onError) === null || _a === void 0 ? void 0 : _a.call(app, e.message); });
50
41
  const render = ({ location, action }) => __awaiter(this, void 0, void 0, function* () {
51
- var _c, _d, _e, _f, _g, _h;
42
+ var _c, _d, _e, _f, _g, _h, _j, _k;
52
43
  handler.pathname = decodeURI(location.pathname);
53
44
  if ((_c = window.__taroAppConfig) === null || _c === void 0 ? void 0 : _c.usingWindowScroll)
54
45
  window.scrollTo(0, 0);
@@ -77,22 +68,34 @@ export function createRouter(app, config, framework) {
77
68
  window.location.reload();
78
69
  }
79
70
  else {
80
- throw new Error(error);
71
+ throw error;
81
72
  }
82
73
  }
83
74
  if (!element)
84
75
  return;
85
76
  const pageConfig = handler.pageConfig;
86
77
  let enablePullDownRefresh = ((_e = config === null || config === void 0 ? void 0 : config.window) === null || _e === void 0 ? void 0 : _e.enablePullDownRefresh) || false;
78
+ let navigationStyle = ((_f = config === null || config === void 0 ? void 0 : config.window) === null || _f === void 0 ? void 0 : _f.navigationStyle) || 'default';
79
+ let navigationBarTextStyle = ((_g = config === null || config === void 0 ? void 0 : config.window) === null || _g === void 0 ? void 0 : _g.navigationBarTextStyle) || 'white';
80
+ let navigationBarBackgroundColor = ((_h = config === null || config === void 0 ? void 0 : config.window) === null || _h === void 0 ? void 0 : _h.navigationBarBackgroundColor) || '#000000';
87
81
  if (pageConfig) {
88
- setTitle((_f = pageConfig.navigationBarTitleText) !== null && _f !== void 0 ? _f : document.title);
89
82
  if (typeof pageConfig.enablePullDownRefresh === 'boolean') {
90
83
  enablePullDownRefresh = pageConfig.enablePullDownRefresh;
91
84
  }
85
+ if (typeof pageConfig.navigationStyle === 'string') {
86
+ navigationStyle = pageConfig.navigationStyle;
87
+ }
88
+ if (typeof pageConfig.navigationBarTextStyle === 'string') {
89
+ navigationBarTextStyle = pageConfig.navigationBarTextStyle;
90
+ }
91
+ if (typeof pageConfig.navigationBarBackgroundColor === 'string') {
92
+ navigationBarBackgroundColor = pageConfig.navigationBarBackgroundColor;
93
+ }
92
94
  }
95
+ eventCenter.trigger('__taroSetNavigationStyle', navigationStyle, navigationBarTextStyle, navigationBarBackgroundColor);
93
96
  const currentPage = Current.page;
94
97
  const pathname = handler.pathname;
95
- const methodName = (_g = stacks.method) !== null && _g !== void 0 ? _g : '';
98
+ const methodName = (_j = stacks.method) !== null && _j !== void 0 ? _j : '';
96
99
  const cacheTabs = stacks.getTabs();
97
100
  let shouldLoad = false;
98
101
  stacks.method = '';
@@ -158,7 +161,7 @@ export function createRouter(app, config, framework) {
158
161
  shouldLoad = true;
159
162
  }
160
163
  if (shouldLoad || stacks.length < 1) {
161
- const el = (_h = element.default) !== null && _h !== void 0 ? _h : element;
164
+ const el = (_k = element.default) !== null && _k !== void 0 ? _k : element;
162
165
  const loadConfig = Object.assign({}, pageConfig);
163
166
  const stacksIndex = stacks.length;
164
167
  delete loadConfig['path'];
@@ -181,7 +184,18 @@ export function createRouter(app, config, framework) {
181
184
  if (routePath === '/') {
182
185
  history.replace(prependBasename(handler.homePage + history.location.search));
183
186
  }
184
- render({ location: history.location, action: LocationAction.Push });
187
+ render({ location: history.location, action: Action.Push });
185
188
  (_b = app.onShow) === null || _b === void 0 ? void 0 : _b.call(app, launchParam);
189
+ window.addEventListener('visibilitychange', () => {
190
+ var _a, _b;
191
+ if (document.visibilityState === 'visible') {
192
+ (_a = app.onShow) === null || _a === void 0 ? void 0 : _a.call(app, launchParam);
193
+ }
194
+ else {
195
+ (_b = app.onHide) === null || _b === void 0 ? void 0 : _b.call(app, launchParam);
196
+ }
197
+ });
186
198
  return history.listen(render);
187
199
  }
200
+
201
+ export { createRouter };
@@ -23,4 +23,4 @@ declare class Stacks {
23
23
  removeTab(path: string): void;
24
24
  }
25
25
  declare const stacks: Stacks;
26
- export default stacks;
26
+ export { stacks as default };
@@ -78,4 +78,5 @@ class Stacks {
78
78
  }
79
79
  }
80
80
  const stacks = new Stacks();
81
- export default stacks;
81
+
82
+ export { stacks as default };
package/dist/style.d.ts CHANGED
@@ -1,8 +1,14 @@
1
1
  /**
2
2
  * 插入页面动画需要的样式
3
3
  */
4
- export declare function loadAnimateStyle(ms?: number): void;
4
+ declare function loadAnimateStyle(ms?: number): void;
5
5
  /**
6
6
  * 插入路由相关样式
7
7
  */
8
- export declare function loadRouterStyle(usingWindowScroll: any): void;
8
+ declare function loadRouterStyle(enableTabBar: boolean, enableWindowScroll: boolean): void;
9
+ /**
10
+ * 插入导航栏相关的样式
11
+ */
12
+ declare function loadNavigationBarStyle(): void;
13
+ declare function addStyle(css: any): void;
14
+ export { loadAnimateStyle, loadRouterStyle, loadNavigationBarStyle, addStyle };
package/dist/style.js CHANGED
@@ -1,9 +1,12 @@
1
1
  /**
2
2
  * 插入页面动画需要的样式
3
3
  */
4
- export function loadAnimateStyle(ms = 300) {
4
+ function loadAnimateStyle(ms = 300) {
5
5
  const css = `
6
- .taro_router .taro_page {
6
+ body {
7
+ overflow: hidden; // 防止 iOS 页面滚动
8
+ }
9
+ .taro_router > .taro_page {
7
10
  position: absolute;
8
11
  left: 0;
9
12
  top: 0;
@@ -15,52 +18,109 @@ export function loadAnimateStyle(ms = 300) {
15
18
  z-index: 0;
16
19
  }
17
20
 
18
- .taro_router .taro_page.taro_tabbar_page,
19
- .taro_router .taro_page.taro_page_show.taro_page_stationed {
21
+ .taro_router > .taro_page.taro_tabbar_page,
22
+ .taro_router > .taro_page.taro_page_show.taro_page_stationed {
20
23
  transform: none;
21
24
  }
22
25
 
23
- .taro_router .taro_page.taro_page_show {
26
+ .taro_router > .taro_page.taro_page_show {
24
27
  transform: translate(0, 0);
25
- }`;
28
+ }
29
+ `;
26
30
  addStyle(css);
27
31
  }
28
32
  /**
29
33
  * 插入路由相关样式
30
34
  */
31
- export function loadRouterStyle(usingWindowScroll) {
35
+ function loadRouterStyle(enableTabBar, enableWindowScroll) {
32
36
  const css = `
33
37
  .taro_router {
34
38
  position: relative;
35
39
  width: 100%;
36
40
  height: 100%;
37
- min-height: 100vh;
38
- }
39
-
40
- .taro-tabbar__container .taro_router {
41
- min-height: calc(100vh - 50px);
42
41
  }
43
42
 
44
43
  .taro_page {
45
44
  width: 100%;
46
45
  height: 100%;
47
- ${usingWindowScroll ? '' : `
46
+ ${enableWindowScroll ? '' : `
48
47
  overflow-x: hidden;
49
48
  overflow-y: scroll;
50
49
  max-height: 100vh;
51
- `}
50
+ `}
52
51
  }
53
-
54
- .taro-tabbar__container .taro-tabbar__panel {
52
+ ${enableTabBar ? `
53
+ .taro-tabbar__container > .taro-tabbar__panel {
55
54
  overflow: hidden;
56
55
  }
57
56
 
58
- .taro-tabbar__container .taro_page.taro_tabbar_page {
59
- max-height: calc(100vh - 50px);
57
+ .taro-tabbar__container > .taro-tabbar__panel > .taro_page.taro_tabbar_page {
58
+ max-height: calc(100vh - var(--taro-tabbar-height) - constant(safe-area-inset-bottom));
59
+ max-height: calc(100vh - var(--taro-tabbar-height) - env(safe-area-inset-bottom));
60
+ }
61
+
62
+ ` : ''}
63
+ .taro_page_shade,
64
+ .taro_router > .taro_page.taro_page_show.taro_page_stationed:not(.taro_page_shade):not(.taro_tabbar_page):not(:last-child) {
65
+ display: none;
60
66
  }
61
67
  `;
62
68
  addStyle(css);
63
69
  }
70
+ /**
71
+ * 插入导航栏相关的样式
72
+ */
73
+ function loadNavigationBarStyle() {
74
+ const css = `
75
+ .taro-navigation-bar-show {
76
+ background: white;
77
+ position: sticky;
78
+ z-index: 500;
79
+ top: 0;
80
+ padding-bottom: 8px;
81
+ padding-top: calc(env(safe-area-inset-top) + 8px);
82
+ display: flex;
83
+ justify-content: center;
84
+ align-items: center;
85
+ }
86
+
87
+ .taro-navigation-bar-hide {
88
+ display: none;
89
+ }
90
+
91
+ taro-navigation-bar-title {
92
+ font-size: 24px;
93
+ height: 24px;
94
+ line-height: 24px;
95
+ }
96
+
97
+ .taro-navigation-bar-no-icon > taro-navigation-bar-home {
98
+ display: none;
99
+ }
100
+
101
+ .taro-navigation-bar-no-icon > taro-navigation-bar-back {
102
+ display: none;
103
+ }
104
+
105
+ .taro-navigation-bar-home > taro-navigation-bar-home {
106
+ display: block;
107
+ left: 8px;
108
+ position: absolute;
109
+ width: 24px;
110
+ height: 24px;
111
+ }
112
+
113
+ .taro-navigation-bar-back > taro-navigation-bar-back {
114
+ display: block;
115
+ left: 8px;
116
+ position: absolute;
117
+ width: 24px;
118
+ height: 24px;
119
+ }
120
+
121
+ `;
122
+ addStyle(css);
123
+ }
64
124
  function addStyle(css) {
65
125
  if (!css)
66
126
  return;
@@ -68,3 +128,5 @@ function addStyle(css) {
68
128
  style.innerHTML = css;
69
129
  document.getElementsByTagName('head')[0].appendChild(style);
70
130
  }
131
+
132
+ export { addStyle, loadAnimateStyle, loadNavigationBarStyle, loadRouterStyle };
package/dist/tabbar.d.ts CHANGED
@@ -1,2 +1,4 @@
1
1
  import { AppConfig } from '@tarojs/taro';
2
- export declare function initTabbar(config: AppConfig): void;
2
+ import { History } from "./history.js";
3
+ declare function initTabbar(config: AppConfig, history: History): void;
4
+ export { initTabbar };
package/dist/tabbar.js CHANGED
@@ -1,9 +1,8 @@
1
- // @ts-nocheck
2
1
  import { defineCustomElementTaroTabbar } from '@tarojs/components/dist/components';
3
2
  import { initTabBarApis } from '@tarojs/taro';
4
- import { history } from './history';
5
- export function initTabbar(config) {
6
- if (config.tabBar == null) {
3
+
4
+ function initTabbar(config, history) {
5
+ if (config.tabBar == null || config.tabBar.custom) {
7
6
  return;
8
7
  }
9
8
  // TODO: custom-tab-bar
@@ -29,3 +28,5 @@ export function initTabbar(config) {
29
28
  container === null || container === void 0 ? void 0 : container.appendChild(tabbar);
30
29
  initTabBarApis(config);
31
30
  }
31
+
32
+ export { initTabbar };
@@ -1,10 +1,3 @@
1
- export declare const addLeadingSlash: (url?: string) => string;
2
- export declare const hasBasename: (path?: string, prefix?: string) => boolean;
3
- export declare const stripBasename: (path?: string, prefix?: string) => string;
4
- export declare const stripTrailing: (str?: string) => string;
5
- export declare const stripSuffix: (path?: string, suffix?: string) => string;
6
- export declare const getHomePage: (path?: string, basename?: string, customRoutes?: Record<string, string | string[]>, entryPagePath?: string) => string;
7
- export declare const getCurrentPage: (routerMode?: string, basename?: string) => string;
8
1
  declare class RoutesAlias {
9
2
  conf: Array<string[]>;
10
3
  set(customRoutes?: Record<string, string | string[]>): void;
@@ -13,5 +6,6 @@ declare class RoutesAlias {
13
6
  getAlias: (url?: string) => string;
14
7
  getAll: (url?: string) => string[];
15
8
  }
16
- export declare const routesAlias: RoutesAlias;
17
- export {};
9
+ declare const routesAlias: RoutesAlias;
10
+ export { routesAlias };
11
+ export * from "./navigate.js";
@@ -1,22 +1,5 @@
1
- // export const removeLeadingSlash = (str = '') => str.replace(/^\.?\//, '')
2
- // export const removeTrailingSearch = (str = '') => str.replace(/\?[\s\S]*$/, '')
3
- export const addLeadingSlash = (url = '') => (url.charAt(0) === '/' ? url : '/' + url);
4
- export const hasBasename = (path = '', prefix = '') => new RegExp('^' + prefix + '(\\/|\\?|#|$)', 'i').test(path) || path === prefix;
5
- export const stripBasename = (path = '', prefix = '') => hasBasename(path, prefix) ? path.substring(prefix.length) : path;
6
- export const stripTrailing = (str = '') => str.replace(/[?#][\s\S]*$/, '');
7
- export const stripSuffix = (path = '', suffix = '') => path.includes(suffix) ? path.substring(0, path.length - suffix.length) : path;
8
- export const getHomePage = (path = '', basename = '', customRoutes = {}, entryPagePath = '') => {
9
- var _a;
10
- const routePath = addLeadingSlash(stripBasename(path, basename));
11
- const alias = ((_a = Object.entries(customRoutes).find(([key]) => key === routePath)) === null || _a === void 0 ? void 0 : _a[1]) || routePath;
12
- return entryPagePath || (typeof alias === 'string' ? alias : alias[0]) || basename;
13
- };
14
- export const getCurrentPage = (routerMode = 'hash', basename = '/') => {
15
- const pagePath = routerMode === 'hash'
16
- ? location.hash.slice(1).split('?')[0]
17
- : location.pathname;
18
- return addLeadingSlash(stripBasename(pagePath, basename));
19
- };
1
+ import { addLeadingSlash } from '@tarojs/runtime';
2
+
20
3
  class RoutesAlias {
21
4
  constructor() {
22
5
  this.conf = [];
@@ -56,4 +39,6 @@ class RoutesAlias {
56
39
  }
57
40
  }
58
41
  }
59
- export const routesAlias = new RoutesAlias();
42
+ const routesAlias = new RoutesAlias();
43
+
44
+ export { routesAlias };
@@ -1,5 +1,9 @@
1
- import MobileDetect from 'mobile-detect';
2
- export declare function getMobileDetect(): MobileDetect;
3
- export declare function setTitle(title: string): Promise<string>;
4
- export declare function isWeixin(): boolean;
5
- export declare function isDingTalk(): boolean;
1
+ declare const isWeixin: () => boolean;
2
+ declare const isDingTalk: () => boolean;
3
+ declare function setMpaTitle(title: string): void;
4
+ declare function setTitle(title: string): void;
5
+ declare function setNavigationBarStyle(option: {
6
+ backgroundColor: string;
7
+ frontColor: string;
8
+ }): void;
9
+ export { isWeixin, isDingTalk, setMpaTitle, setTitle, setNavigationBarStyle };
@@ -1,44 +1,28 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import MobileDetect from 'mobile-detect';
11
- let md;
1
+ import { eventCenter } from '@tarojs/runtime';
2
+
3
+ const isWeixin = () => !!navigator.userAgent.match(/\bMicroMessenger\b/ig);
4
+ const isDingTalk = () => !!navigator.userAgent.match(/\bDingTalk\b/ig);
12
5
  let preTitle = document.title;
13
6
  let isLoadDdEntry = false;
14
- export function getMobileDetect() {
15
- if (!md) {
16
- md = new MobileDetect(navigator.userAgent);
17
- }
18
- return md;
19
- }
20
- export function setTitle(title) {
21
- return __awaiter(this, void 0, void 0, function* () {
22
- if (preTitle === title)
23
- return title;
24
- document.title = title;
25
- preTitle = title;
26
- if (process.env.SUPPORT_DINGTALK_NAVIGATE !== 'disabled' && isDingTalk()) {
27
- if (!isLoadDdEntry) {
28
- isLoadDdEntry = true;
29
- require('dingtalk-jsapi/platform');
30
- }
31
- const setDingTitle = require('dingtalk-jsapi/api/biz/navigation/setTitle').default;
32
- setDingTitle({ title });
7
+ function setMpaTitle(title) {
8
+ if (preTitle === title)
9
+ return;
10
+ document.title = title;
11
+ preTitle = title;
12
+ if (process.env.SUPPORT_DINGTALK_NAVIGATE !== 'disabled' && isDingTalk()) {
13
+ if (!isLoadDdEntry) {
14
+ isLoadDdEntry = true;
15
+ require('dingtalk-jsapi/platform');
33
16
  }
34
- return title;
35
- });
17
+ const setDingTitle = require('dingtalk-jsapi/api/biz/navigation/setTitle').default;
18
+ setDingTitle({ title });
19
+ }
36
20
  }
37
- export function isWeixin() {
38
- const md = getMobileDetect();
39
- return md.match(/MicroMessenger/ig);
21
+ function setTitle(title) {
22
+ eventCenter.trigger('__taroH5SetNavigationTitle', title);
40
23
  }
41
- export function isDingTalk() {
42
- const md = getMobileDetect();
43
- return md.match(/DingTalk/ig);
24
+ function setNavigationBarStyle(option) {
25
+ eventCenter.trigger('__taroH5setNavigationBarColor', option);
44
26
  }
27
+
28
+ export { isDingTalk, isWeixin, setMpaTitle, setNavigationBarStyle, setTitle };