@tarojs/router 4.0.0-alpha.0 → 4.0.0-alpha.10

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 (43) hide show
  1. package/LICENSE +11 -4
  2. package/dist/api.js +30 -22
  3. package/dist/events/resize.d.ts +1 -1
  4. package/dist/events/resize.js +15 -7
  5. package/dist/events/scroll.d.ts +1 -1
  6. package/dist/events/scroll.js +4 -1
  7. package/dist/history.d.ts +22 -1
  8. package/dist/history.js +20 -8
  9. package/dist/index.cjs.js +767 -321
  10. package/dist/index.d.ts +6 -1
  11. package/dist/index.esm.js +727 -293
  12. package/dist/index.js +52 -4
  13. package/dist/navigationBar.d.ts +2 -0
  14. package/dist/navigationBar.js +44 -0
  15. package/dist/router/index.js +7 -3
  16. package/dist/router/mpa.d.ts +2 -1
  17. package/dist/router/mpa.js +29 -19
  18. package/dist/router/multi-page.d.ts +5 -2
  19. package/dist/router/multi-page.js +27 -43
  20. package/dist/router/navigation-bar.d.ts +36 -0
  21. package/dist/router/navigation-bar.js +252 -0
  22. package/dist/router/page.d.ts +11 -4
  23. package/dist/router/page.js +62 -59
  24. package/dist/router/spa.d.ts +2 -1
  25. package/dist/router/spa.js +57 -31
  26. package/dist/router/stack.d.ts +1 -1
  27. package/dist/router/stack.js +2 -1
  28. package/dist/style.d.ts +6 -1
  29. package/dist/style.js +106 -7
  30. package/dist/tabbar.d.ts +2 -1
  31. package/dist/tabbar.js +4 -3
  32. package/dist/utils/index.d.ts +1 -8
  33. package/dist/utils/index.js +5 -20
  34. package/dist/utils/navigate.d.ts +9 -5
  35. package/dist/utils/navigate.js +24 -37
  36. package/package.json +28 -27
  37. package/types/api.d.ts +5 -0
  38. package/types/component.d.ts +5 -0
  39. package/types/taro.d.ts +8 -0
  40. package/dist/index.cjs.d.ts +0 -22
  41. package/dist/index.cjs.js.map +0 -1
  42. package/dist/index.esm.d.ts +0 -22
  43. package/dist/index.esm.js.map +0 -1
@@ -1,15 +1,20 @@
1
- import { PageInstance } from '@tarojs/runtime';
1
+ import NavigationBarHandler from './navigation-bar';
2
+ import type { PageInstance } from '@tarojs/runtime';
2
3
  import type { PageConfig, RouterAnimate } from '@tarojs/taro';
4
+ import type { History } from 'history';
3
5
  import type { Route, SpaRouterConfig } from '../../types/router';
4
6
  export default class PageHandler {
5
- protected config: SpaRouterConfig;
7
+ history: History;
8
+ config: SpaRouterConfig;
6
9
  protected readonly defaultAnimation: RouterAnimate;
7
10
  protected unloadTimer: ReturnType<typeof setTimeout> | null;
8
11
  protected hideTimer: ReturnType<typeof setTimeout> | null;
9
12
  protected lastHidePage: HTMLElement | null;
10
13
  protected lastUnloadPage: PageInstance | null;
14
+ protected navigationBarHandler: NavigationBarHandler;
11
15
  homePage: string;
12
- constructor(config: SpaRouterConfig);
16
+ originHomePage: string;
17
+ constructor(config: SpaRouterConfig, history: History);
13
18
  get currentPage(): string;
14
19
  get appId(): string;
15
20
  get router(): import("../../types/router").Router;
@@ -23,9 +28,11 @@ export default class PageHandler {
23
28
  get animationDuration(): number;
24
29
  set pathname(p: string);
25
30
  get pathname(): string;
31
+ get originPathname(): string;
26
32
  get basename(): string;
27
33
  get pageConfig(): Route | undefined;
28
34
  isTabBar(pathname: string): boolean;
35
+ isDefaultNavigationStyle(): boolean;
29
36
  isSamePage(page?: PageInstance | null): boolean;
30
37
  get search(): string;
31
38
  get usingWindowScroll(): boolean;
@@ -37,7 +44,7 @@ export default class PageHandler {
37
44
  load(page: PageInstance, pageConfig: Route | undefined, stampId: string, pageNo?: number): void;
38
45
  unload(page?: PageInstance | null, delta?: number, top?: boolean): void;
39
46
  show(page?: PageInstance | null, pageConfig?: Route, pageNo?: number): void;
40
- hide(page?: PageInstance | null): void;
47
+ hide(page?: PageInstance | null, animation?: boolean): void;
41
48
  addAnimation(pageEl?: HTMLElement | null, first?: boolean): void;
42
49
  getPageContainer(page?: PageInstance | null): HTMLElement | null;
43
50
  getScrollingElement(page?: PageInstance | null): (Window & typeof globalThis) | HTMLElement;
@@ -1,19 +1,23 @@
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
- export default class PageHandler {
12
- 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;
13
15
  this.defaultAnimation = { duration: 300, delay: 50 };
14
16
  this.config = config;
15
17
  this.homePage = getHomePage(this.routes[0].path, this.basename, this.customRoutes, this.config.entryPagePath);
18
+ this.originHomePage = this.config.entryPagePath || this.routes[0].path || this.basename;
16
19
  this.mount();
20
+ this.navigationBarHandler = new NavigationBarHandler(this);
17
21
  }
18
22
  get currentPage() {
19
23
  const routePath = getCurrentPage(this.routerMode, this.basename);
@@ -45,14 +49,14 @@ export default class PageHandler {
45
49
  }
46
50
  set pathname(p) { this.router.pathname = p; }
47
51
  get pathname() { return this.router.pathname; }
52
+ // Note: 把 pathname 转换为原始路径,主要是处理 customRoutes 和 basename
53
+ get originPathname() { return routesAlias.getOrigin(addLeadingSlash(stripBasename(this.pathname, this.basename))); }
48
54
  get basename() { return this.router.basename || ''; }
49
55
  get pageConfig() {
50
- const routePath = addLeadingSlash(stripBasename(this.pathname, this.basename));
51
56
  const homePage = addLeadingSlash(this.homePage);
52
57
  return this.routes.find(r => {
53
- var _a;
54
58
  const pagePath = addLeadingSlash(r.path);
55
- return [pagePath, homePage].includes(routePath) || ((_a = routesAlias.getConfig(pagePath)) === null || _a === void 0 ? void 0 : _a.includes(routePath));
59
+ return [pagePath, homePage].includes(this.originPathname);
56
60
  });
57
61
  }
58
62
  isTabBar(pathname) {
@@ -69,6 +73,14 @@ export default class PageHandler {
69
73
  })) === null || _a === void 0 ? void 0 : _a[0]) || routePath;
70
74
  return !!pagePath && this.tabBarList.some(t => stripTrailing(t.pagePath) === pagePath);
71
75
  }
76
+ isDefaultNavigationStyle() {
77
+ var _a, _b;
78
+ let style = (_a = this.config.window) === null || _a === void 0 ? void 0 : _a.navigationStyle;
79
+ if (typeof ((_b = this.pageConfig) === null || _b === void 0 ? void 0 : _b.navigationStyle) === 'string') {
80
+ style = this.pageConfig.navigationStyle;
81
+ }
82
+ return style !== 'custom';
83
+ }
72
84
  isSamePage(page) {
73
85
  const routePath = stripBasename(this.pathname, this.basename);
74
86
  const pagePath = stripBasename(page === null || page === void 0 ? void 0 : page.path, this.basename);
@@ -107,40 +119,11 @@ export default class PageHandler {
107
119
  return Object.assign(Object.assign({}, query), options);
108
120
  }
109
121
  mount() {
110
- setHistoryMode(this.routerMode, this.router.basename);
122
+ setHistory(this.history, this.basename);
111
123
  this.pathname = history.location.pathname;
124
+ // Note: 注入页面样式
112
125
  this.animation && loadAnimateStyle(this.animationDuration);
113
- loadRouterStyle(this.usingWindowScroll);
114
- const appId = this.appId;
115
- let app = document.getElementById(appId);
116
- let isPosition = true;
117
- if (!app) {
118
- app = document.createElement('div');
119
- app.id = appId;
120
- isPosition = false;
121
- }
122
- const appWrapper = (app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body;
123
- app.classList.add('taro_router');
124
- if (this.tabBarList.length > 1) {
125
- const container = document.createElement('div');
126
- container.classList.add('taro-tabbar__container');
127
- container.id = 'container';
128
- const panel = document.createElement('div');
129
- panel.classList.add('taro-tabbar__panel');
130
- panel.appendChild(app.cloneNode(true));
131
- container.appendChild(panel);
132
- if (!isPosition) {
133
- appWrapper.appendChild(container);
134
- }
135
- else {
136
- appWrapper.replaceChild(container, app);
137
- }
138
- initTabbar(this.config);
139
- }
140
- else {
141
- if (!isPosition)
142
- appWrapper.appendChild(app);
143
- }
126
+ loadRouterStyle(this.tabBarList.length > 1, this.usingWindowScroll);
144
127
  }
145
128
  onReady(page, onLoad = true) {
146
129
  var _a;
@@ -175,19 +158,24 @@ export default class PageHandler {
175
158
  if (pageEl) {
176
159
  pageEl.classList.remove('taro_page_shade');
177
160
  this.isTabBar(this.pathname) && pageEl.classList.add('taro_tabbar_page');
161
+ this.isDefaultNavigationStyle() && pageEl.classList.add('taro_navigation_page');
178
162
  this.addAnimation(pageEl, pageNo === 0);
179
163
  (_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
164
+ this.navigationBarHandler.load();
180
165
  this.bindPageEvents(page, pageConfig);
181
166
  this.triggerRouterChange();
182
167
  }
183
168
  else {
169
+ // FIXME 在 iOS 端快速切换页面时,可能不会执行回调注入对应类名导致 TabBar 白屏
184
170
  (_b = page.onLoad) === null || _b === void 0 ? void 0 : _b.call(page, param, () => {
185
171
  var _a;
186
172
  pageEl = this.getPageContainer(page);
187
173
  this.isTabBar(this.pathname) && (pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.add('taro_tabbar_page'));
174
+ this.isDefaultNavigationStyle() && (pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.add('taro_navigation_page'));
188
175
  this.addAnimation(pageEl, pageNo === 0);
189
- this.onReady(page, true);
190
176
  (_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
177
+ this.navigationBarHandler.load();
178
+ this.onReady(page, true);
191
179
  this.bindPageEvents(page, pageConfig);
192
180
  this.triggerRouterChange();
193
181
  });
@@ -241,6 +229,7 @@ export default class PageHandler {
241
229
  pageEl.classList.remove('taro_page_shade');
242
230
  this.addAnimation(pageEl, pageNo === 0);
243
231
  (_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
232
+ this.navigationBarHandler.load();
244
233
  this.bindPageEvents(page, pageConfig);
245
234
  this.triggerRouterChange();
246
235
  }
@@ -249,31 +238,43 @@ export default class PageHandler {
249
238
  var _a;
250
239
  pageEl = this.getPageContainer(page);
251
240
  this.addAnimation(pageEl, pageNo === 0);
252
- this.onReady(page, false);
253
241
  (_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
242
+ this.navigationBarHandler.load();
243
+ this.onReady(page, false);
254
244
  this.bindPageEvents(page, pageConfig);
255
245
  this.triggerRouterChange();
256
246
  });
257
247
  }
258
248
  }
259
- hide(page) {
260
- var _a;
249
+ hide(page, animation = false) {
250
+ var _a, _b, _c, _d, _e, _f, _g;
261
251
  if (!page)
262
252
  return;
263
253
  // NOTE: 修复多页并发问题,此处可能因为路由跳转过快,执行时页面可能还没有创建成功
264
254
  const pageEl = this.getPageContainer(page);
265
255
  if (pageEl) {
266
- if (this.hideTimer) {
267
- clearTimeout(this.hideTimer);
268
- this.hideTimer = null;
269
- pageEl.classList.add('taro_page_shade');
256
+ if (animation) {
257
+ if (this.hideTimer) {
258
+ clearTimeout(this.hideTimer);
259
+ this.hideTimer = null;
260
+ (_c = (_b = (_a = this.lastHidePage) === null || _a === void 0 ? void 0 : _a.classList) === null || _b === void 0 ? void 0 : _b.add) === null || _c === void 0 ? void 0 : _c.call(_b, 'taro_page_shade');
261
+ }
262
+ this.lastHidePage = pageEl;
263
+ this.hideTimer = setTimeout(() => {
264
+ this.hideTimer = null;
265
+ pageEl.classList.add('taro_page_shade');
266
+ }, this.animationDuration + this.animationDelay);
267
+ (_d = page.onHide) === null || _d === void 0 ? void 0 : _d.call(page);
270
268
  }
271
- this.lastHidePage = pageEl;
272
- this.hideTimer = setTimeout(() => {
273
- this.hideTimer = null;
269
+ else {
270
+ if (this.hideTimer) {
271
+ clearTimeout(this.hideTimer);
272
+ this.hideTimer = null;
273
+ (_g = (_f = (_e = this.lastHidePage) === null || _e === void 0 ? void 0 : _e.classList) === null || _f === void 0 ? void 0 : _f.add) === null || _g === void 0 ? void 0 : _g.call(_f, 'taro_page_shade');
274
+ }
274
275
  pageEl.classList.add('taro_page_shade');
275
- }, this.animationDuration + this.animationDelay);
276
- (_a = page.onHide) === null || _a === void 0 ? void 0 : _a.call(page);
276
+ this.lastHidePage = pageEl;
277
+ }
277
278
  }
278
279
  else {
279
280
  setTimeout(() => this.hide(page), 0);
@@ -334,3 +335,5 @@ export default class PageHandler {
334
335
  }, 0);
335
336
  }
336
337
  }
338
+
339
+ export { PageHandler as default };
@@ -1,3 +1,4 @@
1
1
  import type { AppInstance } from '@tarojs/runtime';
2
+ import type { History } from 'history';
2
3
  import type { SpaRouterConfig } from '../../types/router';
3
- export declare function createRouter(app: AppInstance, config: SpaRouterConfig, framework?: string): () => void;
4
+ export declare function createRouter(history: History, app: AppInstance, config: SpaRouterConfig, framework?: string): () => void;
@@ -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, safeExecute, 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 => {
@@ -47,10 +38,10 @@ export function createRouter(app, config, framework) {
47
38
  eventCenter.trigger('__taroRouterLaunch', launchParam);
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
- const render = ({ location, action }) => __awaiter(this, void 0, void 0, function* () {
51
- var _c, _d, _e, _f, _g, _h;
41
+ const render = (_c) => __awaiter(this, [_c], void 0, function* ({ location, action }) {
42
+ var _d, _e, _f, _g, _h, _j, _k, _l;
52
43
  handler.pathname = decodeURI(location.pathname);
53
- if ((_c = window.__taroAppConfig) === null || _c === void 0 ? void 0 : _c.usingWindowScroll)
44
+ if ((_d = window.__taroAppConfig) === null || _d === void 0 ? void 0 : _d.usingWindowScroll)
54
45
  window.scrollTo(0, 0);
55
46
  eventCenter.trigger('__taroRouterChange', {
56
47
  toLocation: {
@@ -69,7 +60,7 @@ export function createRouter(app, config, framework) {
69
60
  path: handler.pathname,
70
61
  query: handler.getQuery(createStampId()),
71
62
  };
72
- (_d = app.onPageNotFound) === null || _d === void 0 ? void 0 : _d.call(app, notFoundEvent);
63
+ (_e = app.onPageNotFound) === null || _e === void 0 ? void 0 : _e.call(app, notFoundEvent);
73
64
  eventCenter.trigger('__taroRouterNotFound', notFoundEvent);
74
65
  }
75
66
  else if (/Loading hot update .* failed./.test(error.message)) {
@@ -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
- let enablePullDownRefresh = ((_e = config === null || config === void 0 ? void 0 : config.window) === null || _e === void 0 ? void 0 : _e.enablePullDownRefresh) || false;
77
+ let enablePullDownRefresh = ((_f = config === null || config === void 0 ? void 0 : config.window) === null || _f === void 0 ? void 0 : _f.enablePullDownRefresh) || false;
78
+ let navigationStyle = ((_g = config === null || config === void 0 ? void 0 : config.window) === null || _g === void 0 ? void 0 : _g.navigationStyle) || 'default';
79
+ let navigationBarTextStyle = ((_h = config === null || config === void 0 ? void 0 : config.window) === null || _h === void 0 ? void 0 : _h.navigationBarTextStyle) || 'white';
80
+ let navigationBarBackgroundColor = ((_j = config === null || config === void 0 ? void 0 : config.window) === null || _j === void 0 ? void 0 : _j.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 = (_k = stacks.method) !== null && _k !== void 0 ? _k : '';
96
99
  const cacheTabs = stacks.getTabs();
97
100
  let shouldLoad = false;
98
101
  stacks.method = '';
@@ -111,6 +114,7 @@ export function createRouter(app, config, framework) {
111
114
  if (handler.isSamePage(currentPage))
112
115
  return;
113
116
  if (handler.isTabBar(currentPage.path)) {
117
+ // NOTE: 从 tabBar 页面切换到 tabBar 页面
114
118
  handler.hide(currentPage);
115
119
  stacks.pushTab(currentPage.path.split('?')[0]);
116
120
  }
@@ -154,11 +158,11 @@ export function createRouter(app, config, framework) {
154
158
  shouldLoad = true;
155
159
  }
156
160
  else if (action === 'PUSH') {
157
- handler.hide(currentPage);
161
+ handler.hide(currentPage, true);
158
162
  shouldLoad = true;
159
163
  }
160
164
  if (shouldLoad || stacks.length < 1) {
161
- const el = (_h = element.default) !== null && _h !== void 0 ? _h : element;
165
+ const el = (_l = element.default) !== null && _l !== void 0 ? _l : element;
162
166
  const loadConfig = Object.assign({}, pageConfig);
163
167
  const stacksIndex = stacks.length;
164
168
  delete loadConfig['path'];
@@ -181,7 +185,29 @@ export function createRouter(app, config, framework) {
181
185
  if (routePath === '/') {
182
186
  history.replace(prependBasename(handler.homePage + history.location.search));
183
187
  }
184
- render({ location: history.location, action: LocationAction.Push });
188
+ render({ location: history.location, action: Action.Push });
185
189
  (_b = app.onShow) === null || _b === void 0 ? void 0 : _b.call(app, launchParam);
190
+ window.addEventListener('visibilitychange', () => {
191
+ var _a, _b, _c, _d, _e, _f, _g;
192
+ const currentPath = ((_a = Current.page) === null || _a === void 0 ? void 0 : _a.path) || '';
193
+ const path = currentPath.substring(0, currentPath.indexOf('?'));
194
+ const param = {};
195
+ // app的 onShow/onHide 生命周期的路径信息为当前页面的路径
196
+ Object.assign(param, launchParam, { path });
197
+ if (document.visibilityState === 'visible') {
198
+ (_b = app.onShow) === null || _b === void 0 ? void 0 : _b.call(app, param);
199
+ // 单页面app显示后一刻会触发当前 page.onShow 生命周期函数
200
+ (_d = (_c = Current.page) === null || _c === void 0 ? void 0 : _c.onShow) === null || _d === void 0 ? void 0 : _d.call(_c);
201
+ }
202
+ else {
203
+ // 单页面app隐藏前一刻会触发当前 page.onHide 生命周期函数
204
+ if ((_e = Current.page) === null || _e === void 0 ? void 0 : _e.path) {
205
+ safeExecute((_f = Current.page) === null || _f === void 0 ? void 0 : _f.path, 'onHide');
206
+ }
207
+ (_g = app.onHide) === null || _g === void 0 ? void 0 : _g.call(app, param);
208
+ }
209
+ });
186
210
  return history.listen(render);
187
211
  }
212
+
213
+ export { createRouter };
@@ -1,4 +1,4 @@
1
- import { PageInstance } from '@tarojs/runtime';
1
+ import type { PageInstance } from '@tarojs/runtime';
2
2
  declare class Stacks {
3
3
  stacks: PageInstance[];
4
4
  backDelta: number;
@@ -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
@@ -5,4 +5,9 @@ export declare function loadAnimateStyle(ms?: number): void;
5
5
  /**
6
6
  * 插入路由相关样式
7
7
  */
8
- export declare function loadRouterStyle(usingWindowScroll: boolean): void;
8
+ export declare function loadRouterStyle(enableTabBar: boolean, enableWindowScroll: boolean): void;
9
+ /**
10
+ * 插入导航栏相关的样式
11
+ */
12
+ export declare function loadNavigationBarStyle(): void;
13
+ export declare function addStyle(css: any): void;
package/dist/style.js CHANGED
@@ -1,8 +1,12 @@
1
1
  /**
2
2
  * 插入页面动画需要的样式
3
3
  */
4
- export function loadAnimateStyle(ms = 300) {
4
+ function loadAnimateStyle(ms = 300) {
5
5
  const css = `
6
+ body {
7
+ /* 防止 iOS 页面滚动 */
8
+ overflow: hidden;
9
+ }
6
10
  .taro_router > .taro_page {
7
11
  position: absolute;
8
12
  left: 0;
@@ -18,6 +22,7 @@ export function loadAnimateStyle(ms = 300) {
18
22
  .taro_router > .taro_page.taro_tabbar_page,
19
23
  .taro_router > .taro_page.taro_page_show.taro_page_stationed {
20
24
  transform: none;
25
+ transition: none;
21
26
  }
22
27
 
23
28
  .taro_router > .taro_page.taro_page_show {
@@ -29,7 +34,7 @@ export function loadAnimateStyle(ms = 300) {
29
34
  /**
30
35
  * 插入路由相关样式
31
36
  */
32
- export function loadRouterStyle(usingWindowScroll) {
37
+ function loadRouterStyle(enableTabBar, enableWindowScroll) {
33
38
  const css = `
34
39
  .taro_router {
35
40
  position: relative;
@@ -40,13 +45,13 @@ export function loadRouterStyle(usingWindowScroll) {
40
45
  .taro_page {
41
46
  width: 100%;
42
47
  height: 100%;
43
- ${usingWindowScroll ? '' : `
48
+ ${enableWindowScroll ? '' : `
44
49
  overflow-x: hidden;
45
50
  overflow-y: scroll;
46
51
  max-height: 100vh;
47
- `}
52
+ `}
48
53
  }
49
-
54
+ ${enableTabBar ? `
50
55
  .taro-tabbar__container > .taro-tabbar__panel {
51
56
  overflow: hidden;
52
57
  }
@@ -56,10 +61,102 @@ export function loadRouterStyle(usingWindowScroll) {
56
61
  max-height: calc(100vh - var(--taro-tabbar-height) - env(safe-area-inset-bottom));
57
62
  }
58
63
 
59
- .taro_page_shade,
60
- .taro_router > .taro_page.taro_page_show.taro_page_stationed:not(.taro_page_shade):not(.taro_tabbar_page):not(:last-child) {
64
+ ` : ''}
65
+ .taro_page_shade:has(+.taro_page_stationed),
66
+ .taro_page_shade.taro_tabbar_page,
67
+ .taro_router > .taro_page.taro_page_show.taro_page_stationed:not(.taro_page_shade):not(.taro_tabbar_page):not(:last-child):has(+.taro_page_stationed) {
68
+ display: none;
69
+ }
70
+ `;
71
+ addStyle(css);
72
+ }
73
+ /**
74
+ * 插入导航栏相关的样式
75
+ */
76
+ function loadNavigationBarStyle() {
77
+ const css = `
78
+ .taro-navigation-bar-show {
79
+ display: flex;
80
+ background: white;
81
+ position: sticky;
82
+ z-index: 500;
83
+ top: 0;
84
+ padding-bottom: 8px;
85
+ padding-top: calc(env(safe-area-inset-top) + 8px);
86
+ justify-content: center;
87
+ align-items: center;
88
+ }
89
+
90
+ .taro-navigation-bar-hide {
91
+ display: none;
92
+ }
93
+
94
+ .taro-navigation-bar-title-wrap {
95
+ display: flex;
96
+ height: 24px;
97
+ }
98
+
99
+ .taro-navigation-bar-title-wrap > .taro-navigation-bar-loading {
100
+ display: none;
101
+ animation: loading 2s linear infinite;
102
+ }
103
+
104
+ .taro-navigation-bar-title-wrap .taro-navigation-bar-loading.taro-navigation-bar-loading-show {
105
+ display: flex;
106
+ }
107
+
108
+ .taro-navigation-bar-title-wrap > .taro-navigation-bar-title {
109
+ font-size: 24px;
110
+ height: 24px;
111
+ line-height: 24px;
112
+ max-width: 100px;
113
+ white-space: nowrap;
114
+ overflow: hidden;
115
+ line-height: 24px;
116
+ text-overflow: ellipsis;
117
+ }
118
+
119
+ @keyframes loading {
120
+ from {
121
+ transform: rotate(0deg);
122
+ }
123
+ to {
124
+ transform: rotate(360deg);
125
+ }
126
+ }
127
+
128
+ @keyframes loading {
129
+ from {
130
+ transform: rotate(0deg);
131
+ }
132
+ to {
133
+ transform: rotate(360deg);
134
+ }
135
+ }
136
+
137
+ .taro-navigation-bar-no-icon > .taro-navigation-bar-home {
61
138
  display: none;
62
139
  }
140
+
141
+ .taro-navigation-bar-no-icon > .taro-navigation-bar-back {
142
+ display: none;
143
+ }
144
+
145
+ .taro-navigation-bar-home-icon > .taro-navigation-bar-home {
146
+ display: flex;
147
+ left: 8px;
148
+ position: absolute;
149
+ width: 24px;
150
+ height: 24px;
151
+ }
152
+
153
+ .taro-navigation-bar-back-icon > .taro-navigation-bar-back {
154
+ display: flex;
155
+ left: 8px;
156
+ position: absolute;
157
+ width: 24px;
158
+ height: 24px;
159
+ }
63
160
  `;
64
161
  addStyle(css);
65
162
  }
@@ -70,3 +167,5 @@ function addStyle(css) {
70
167
  style.innerHTML = css;
71
168
  document.getElementsByTagName('head')[0].appendChild(style);
72
169
  }
170
+
171
+ export { addStyle, loadAnimateStyle, loadNavigationBarStyle, loadRouterStyle };
package/dist/tabbar.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  import { AppConfig } from '@tarojs/taro';
2
- export declare function initTabbar(config: AppConfig): void;
2
+ import type { History } from 'history';
3
+ export declare function initTabbar(config: AppConfig, history: History): void;
package/dist/tabbar.js CHANGED
@@ -1,8 +1,7 @@
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) {
3
+
4
+ function initTabbar(config, history) {
6
5
  if (config.tabBar == null || config.tabBar.custom) {
7
6
  return;
8
7
  }
@@ -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;
@@ -14,4 +7,4 @@ declare class RoutesAlias {
14
7
  getAll: (url?: string) => string[];
15
8
  }
16
9
  export declare const routesAlias: RoutesAlias;
17
- export {};
10
+ export * from './navigate';