@tarojs/router 3.6.22 → 3.6.23

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.
@@ -1,17 +1,9 @@
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, eventCenter, hooks, incrementId, stringify, } from '@tarojs/runtime';
12
- import { setTitle } from '../utils/navigate';
13
- import { RouterConfig } from '.';
14
- import MultiPageHandler from './multi-page';
1
+ import { __awaiter } from 'tslib';
2
+ import { incrementId, eventCenter, createPageConfig, hooks, stringify } from '@tarojs/runtime';
3
+ import { setTitle } from '../utils/navigate.js';
4
+ import { RouterConfig } from './index.js';
5
+ import MultiPageHandler from './multi-page.js';
6
+
15
7
  const createStampId = incrementId();
16
8
  const launchStampId = createStampId();
17
9
  // TODO 支持多路由 (APP 生命周期仅触发一次)
@@ -22,14 +14,14 @@ const launchStampId = createStampId();
22
14
  * - TabBar 会多次加载
23
15
  * - 不支持路由动画
24
16
  */
25
- export function createMultiRouter(app, config, framework) {
17
+ function createMultiRouter(history, app, config, framework) {
26
18
  var _a, _b, _c, _d, _e, _f;
27
19
  return __awaiter(this, void 0, void 0, function* () {
28
20
  if (typeof app.onUnhandledRejection === 'function') {
29
21
  window.addEventListener('unhandledrejection', app.onUnhandledRejection);
30
22
  }
31
23
  RouterConfig.config = config;
32
- const handler = new MultiPageHandler(config);
24
+ const handler = new MultiPageHandler(config, history);
33
25
  const launchParam = {
34
26
  path: config.pageName,
35
27
  query: handler.getQuery(launchStampId),
@@ -75,3 +67,5 @@ export function createMultiRouter(app, config, framework) {
75
67
  (_f = app.onShow) === null || _f === void 0 ? void 0 : _f.call(app, launchParam);
76
68
  });
77
69
  }
70
+
71
+ export { createMultiRouter };
@@ -1,11 +1,13 @@
1
1
  import { PageInstance } from '@tarojs/runtime';
2
- import type { PageConfig } from '@tarojs/taro';
3
- import type { MpaRouterConfig, Route } from '../../types/router';
4
- export default class MultiPageHandler {
2
+ import { PageConfig } from '@tarojs/taro';
3
+ import { History } from "../history.js";
4
+ import { MpaRouterConfig, Route } from '../../types/router';
5
+ declare class MultiPageHandler {
6
+ history: History;
5
7
  protected config: MpaRouterConfig;
6
- constructor(config: MpaRouterConfig);
8
+ constructor(config: MpaRouterConfig, history: History);
7
9
  get appId(): string;
8
- get router(): import("../../types/router").Router;
10
+ get router(): import("../types/router").Router;
9
11
  get routerMode(): "hash" | "browser" | "multi";
10
12
  get customRoutes(): Record<string, string | string[]>;
11
13
  get tabBarList(): import("@tarojs/taro").TabBarItem[];
@@ -25,6 +27,7 @@ export default class MultiPageHandler {
25
27
  onReady(page: PageInstance, onLoad?: boolean): void;
26
28
  load(page: PageInstance, pageConfig?: Route): void;
27
29
  getPageContainer(page?: PageInstance | null): HTMLElement | null;
28
- getScrollingElement(page?: PageInstance | null): (Window & typeof globalThis) | HTMLElement;
30
+ getScrollingElement(page?: PageInstance | null): HTMLElement | (Window & typeof globalThis);
29
31
  bindPageEvents(page: PageInstance, config?: Partial<PageConfig>): void;
30
32
  }
33
+ export { MultiPageHandler as default };
@@ -1,14 +1,14 @@
1
- /* eslint-disable dot-notation */
2
- import { Current } from '@tarojs/runtime';
1
+ import { addLeadingSlash, stripBasename, 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 { setHistoryMode } from '../history';
7
- import { loadRouterStyle } from '../style';
8
- import { initTabbar } from '../tabbar';
9
- import { addLeadingSlash, stripBasename } from '../utils';
10
- export default class MultiPageHandler {
11
- constructor(config) {
3
+ import { bindPageResize } from '../events/resize.js';
4
+ import { bindPageScroll } from '../events/scroll.js';
5
+ import { setHistory } from '../history.js';
6
+ import { loadRouterStyle } from '../style.js';
7
+
8
+ /* eslint-disable dot-notation */
9
+ class MultiPageHandler {
10
+ constructor(config, history) {
11
+ this.history = history;
12
12
  this.config = config;
13
13
  this.mount();
14
14
  }
@@ -64,38 +64,9 @@ export default class MultiPageHandler {
64
64
  return style !== 'custom';
65
65
  }
66
66
  mount() {
67
- setHistoryMode(this.routerMode, this.router.basename);
68
- loadRouterStyle(this.usingWindowScroll);
69
- const appId = this.appId;
70
- let app = document.getElementById(appId);
71
- let isPosition = true;
72
- if (!app) {
73
- app = document.createElement('div');
74
- app.id = appId;
75
- isPosition = false;
76
- }
77
- const appWrapper = (app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body;
78
- app.classList.add('taro_router');
79
- if (this.tabBarList.length > 1) {
80
- const container = document.createElement('div');
81
- container.classList.add('taro-tabbar__container');
82
- container.id = 'container';
83
- const panel = document.createElement('div');
84
- panel.classList.add('taro-tabbar__panel');
85
- panel.appendChild(app.cloneNode(true));
86
- container.appendChild(panel);
87
- if (!isPosition) {
88
- appWrapper.appendChild(container);
89
- }
90
- else {
91
- appWrapper.replaceChild(container, app);
92
- }
93
- initTabbar(this.config);
94
- }
95
- else {
96
- if (!isPosition)
97
- appWrapper.appendChild(app);
98
- }
67
+ setHistory(this.history, this.basename);
68
+ // Note: 注入页面样式
69
+ loadRouterStyle(this.tabBarList.length > 1, this.usingWindowScroll);
99
70
  }
100
71
  onReady(page, onLoad = true) {
101
72
  var _a;
@@ -163,3 +134,5 @@ export default class MultiPageHandler {
163
134
  bindPageResize(page);
164
135
  }
165
136
  }
137
+
138
+ export { MultiPageHandler as default };
@@ -1,7 +1,9 @@
1
1
  import { PageInstance } from '@tarojs/runtime';
2
- import type { PageConfig, RouterAnimate } from '@tarojs/taro';
3
- import type { Route, SpaRouterConfig } from '../../types/router';
4
- export default class PageHandler {
2
+ import { PageConfig, RouterAnimate } from '@tarojs/taro';
3
+ import { History } from "../history.js";
4
+ import { Route, SpaRouterConfig } from '../../types/router';
5
+ declare class PageHandler {
6
+ history: History;
5
7
  protected config: SpaRouterConfig;
6
8
  protected readonly defaultAnimation: RouterAnimate;
7
9
  protected unloadTimer: ReturnType<typeof setTimeout> | null;
@@ -9,10 +11,10 @@ export default class PageHandler {
9
11
  protected lastHidePage: HTMLElement | null;
10
12
  protected lastUnloadPage: PageInstance | null;
11
13
  homePage: string;
12
- constructor(config: SpaRouterConfig);
14
+ constructor(config: SpaRouterConfig, history: History);
13
15
  get currentPage(): string;
14
16
  get appId(): string;
15
- get router(): import("../../types/router").Router;
17
+ get router(): import("../types/router").Router;
16
18
  get routerMode(): "hash" | "browser" | "multi";
17
19
  get customRoutes(): Record<string, string | string[]>;
18
20
  get routes(): Route[];
@@ -41,7 +43,8 @@ export default class PageHandler {
41
43
  hide(page?: PageInstance | null): void;
42
44
  addAnimation(pageEl?: HTMLElement | null, first?: boolean): void;
43
45
  getPageContainer(page?: PageInstance | null): HTMLElement | null;
44
- getScrollingElement(page?: PageInstance | null): (Window & typeof globalThis) | HTMLElement;
46
+ getScrollingElement(page?: PageInstance | null): HTMLElement | (Window & typeof globalThis);
45
47
  bindPageEvents(page: PageInstance, config?: Partial<PageConfig>): void;
46
48
  triggerRouterChange(): void;
47
49
  }
50
+ export { PageHandler as default };
@@ -1,15 +1,16 @@
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 stacks from './stack.js';
9
+
10
+ /* eslint-disable dot-notation */
11
+ class PageHandler {
12
+ constructor(config, history) {
13
+ this.history = history;
13
14
  this.defaultAnimation = { duration: 300, delay: 50 };
14
15
  this.config = config;
15
16
  this.homePage = getHomePage(this.routes[0].path, this.basename, this.customRoutes, this.config.entryPagePath);
@@ -115,40 +116,11 @@ export default class PageHandler {
115
116
  return Object.assign(Object.assign({}, query), options);
116
117
  }
117
118
  mount() {
118
- setHistoryMode(this.routerMode, this.router.basename);
119
+ setHistory(this.history, this.basename);
119
120
  this.pathname = history.location.pathname;
121
+ // Note: 注入页面样式
120
122
  this.animation && loadAnimateStyle(this.animationDuration);
121
- loadRouterStyle(this.usingWindowScroll);
122
- const appId = this.appId;
123
- let app = document.getElementById(appId);
124
- let isPosition = true;
125
- if (!app) {
126
- app = document.createElement('div');
127
- app.id = appId;
128
- isPosition = false;
129
- }
130
- const appWrapper = (app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body;
131
- app.classList.add('taro_router');
132
- if (this.tabBarList.length > 1) {
133
- const container = document.createElement('div');
134
- container.classList.add('taro-tabbar__container');
135
- container.id = 'container';
136
- const panel = document.createElement('div');
137
- panel.classList.add('taro-tabbar__panel');
138
- panel.appendChild(app.cloneNode(true));
139
- container.appendChild(panel);
140
- if (!isPosition) {
141
- appWrapper.appendChild(container);
142
- }
143
- else {
144
- appWrapper.replaceChild(container, app);
145
- }
146
- initTabbar(this.config);
147
- }
148
- else {
149
- if (!isPosition)
150
- appWrapper.appendChild(app);
151
- }
123
+ loadRouterStyle(this.tabBarList.length > 1, this.usingWindowScroll);
152
124
  }
153
125
  onReady(page, onLoad = true) {
154
126
  var _a;
@@ -345,3 +317,5 @@ export default class PageHandler {
345
317
  }, 0);
346
318
  }
347
319
  }
320
+
321
+ 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,23 @@
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 { setTitle } from '../utils/navigate.js';
8
+ import { RouterConfig } from './index.js';
9
+ import PageHandler from './page.js';
10
+ import stacks from './stack.js';
11
+
20
12
  const createStampId = incrementId();
21
13
  let launchStampId = createStampId();
22
- export function createRouter(app, config, framework) {
14
+ function createRouter(history, app, config, framework) {
23
15
  var _a, _b;
24
16
  if (typeof app.onUnhandledRejection === 'function') {
25
17
  window.addEventListener('unhandledrejection', app.onUnhandledRejection);
26
18
  }
27
19
  RouterConfig.config = config;
28
- const handler = new PageHandler(config);
20
+ const handler = new PageHandler(config, history);
29
21
  routesAlias.set(handler.router.customRoutes);
30
22
  const basename = handler.router.basename;
31
23
  const routes = handler.routes.map(route => {
@@ -194,7 +186,9 @@ export function createRouter(app, config, framework) {
194
186
  if (routePath === '/') {
195
187
  history.replace(prependBasename(handler.homePage + history.location.search));
196
188
  }
197
- render({ location: history.location, action: LocationAction.Push });
189
+ render({ location: history.location, action: Action.Push });
198
190
  (_b = app.onShow) === null || _b === void 0 ? void 0 : _b.call(app, launchParam);
199
191
  return history.listen(render);
200
192
  }
193
+
194
+ 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,9 +1,10 @@
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: boolean): void;
9
- export declare function addStyle(css: any): void;
8
+ declare function loadRouterStyle(enableTabBar: boolean, enableWindowScroll: boolean): void;
9
+ declare function addStyle(css: any): void;
10
+ export { loadAnimateStyle, loadRouterStyle, addStyle };
package/dist/style.js CHANGED
@@ -1,8 +1,11 @@
1
1
  /**
2
2
  * 插入页面动画需要的样式
3
3
  */
4
- export function loadAnimateStyle(ms = 300) {
4
+ function loadAnimateStyle(ms = 300) {
5
5
  const css = `
6
+ body {
7
+ overflow: hidden; // 防止 iOS 页面滚动
8
+ }
6
9
  .taro_router > .taro_page {
7
10
  position: absolute;
8
11
  left: 0;
@@ -29,7 +32,7 @@ export function loadAnimateStyle(ms = 300) {
29
32
  /**
30
33
  * 插入路由相关样式
31
34
  */
32
- export function loadRouterStyle(usingWindowScroll) {
35
+ function loadRouterStyle(enableTabBar, enableWindowScroll) {
33
36
  const css = `
34
37
  .taro_router {
35
38
  position: relative;
@@ -40,13 +43,13 @@ export function loadRouterStyle(usingWindowScroll) {
40
43
  .taro_page {
41
44
  width: 100%;
42
45
  height: 100%;
43
- ${usingWindowScroll ? '' : `
46
+ ${enableWindowScroll ? '' : `
44
47
  overflow-x: hidden;
45
48
  overflow-y: scroll;
46
49
  max-height: 100vh;
47
- `}
50
+ `}
48
51
  }
49
-
52
+ ${enableTabBar ? `
50
53
  .taro-tabbar__container > .taro-tabbar__panel {
51
54
  overflow: hidden;
52
55
  }
@@ -56,6 +59,7 @@ export function loadRouterStyle(usingWindowScroll) {
56
59
  max-height: calc(100vh - var(--taro-tabbar-height) - env(safe-area-inset-bottom));
57
60
  }
58
61
 
62
+ ` : ''}
59
63
  .taro_page_shade,
60
64
  .taro_router > .taro_page.taro_page_show.taro_page_stationed:not(.taro_page_shade):not(.taro_tabbar_page):not(:last-child) {
61
65
  display: none;
@@ -63,10 +67,12 @@ export function loadRouterStyle(usingWindowScroll) {
63
67
  `;
64
68
  addStyle(css);
65
69
  }
66
- export function addStyle(css) {
70
+ function addStyle(css) {
67
71
  if (!css)
68
72
  return;
69
73
  const style = document.createElement('style');
70
74
  style.innerHTML = css;
71
75
  document.getElementsByTagName('head')[0].appendChild(style);
72
76
  }
77
+
78
+ export { addStyle, loadAnimateStyle, 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,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) {
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;
@@ -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,6 @@
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
+ import 'tslib';
3
+
20
4
  class RoutesAlias {
21
5
  constructor() {
22
6
  this.conf = [];
@@ -56,4 +40,6 @@ class RoutesAlias {
56
40
  }
57
41
  }
58
42
  }
59
- export const routesAlias = new RoutesAlias();
43
+ const routesAlias = new RoutesAlias();
44
+
45
+ export { routesAlias };
@@ -1,3 +1,4 @@
1
- export declare const isWeixin: () => boolean;
2
- export declare const isDingTalk: () => boolean;
3
- export declare function setTitle(title: string): Promise<string>;
1
+ declare const isWeixin: () => boolean;
2
+ declare const isDingTalk: () => boolean;
3
+ declare function setTitle(title: string): Promise<string>;
4
+ export { isWeixin, isDingTalk, setTitle };
@@ -1,17 +1,10 @@
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
- };
1
+ import { __awaiter } from 'tslib';
2
+
10
3
  let preTitle = document.title;
11
4
  let isLoadDdEntry = false;
12
- export const isWeixin = () => !!navigator.userAgent.match(/\bMicroMessenger\b/ig);
13
- export const isDingTalk = () => !!navigator.userAgent.match(/\bDingTalk\b/ig);
14
- export function setTitle(title) {
5
+ const isWeixin = () => !!navigator.userAgent.match(/\bMicroMessenger\b/ig);
6
+ const isDingTalk = () => !!navigator.userAgent.match(/\bDingTalk\b/ig);
7
+ function setTitle(title) {
15
8
  return __awaiter(this, void 0, void 0, function* () {
16
9
  if (preTitle === title)
17
10
  return title;
@@ -28,3 +21,5 @@ export function setTitle(title) {
28
21
  return title;
29
22
  });
30
23
  }
24
+
25
+ export { isDingTalk, isWeixin, setTitle };
package/package.json CHANGED
@@ -1,17 +1,18 @@
1
1
  {
2
2
  "name": "@tarojs/router",
3
- "version": "3.6.22",
3
+ "version": "3.6.23",
4
4
  "description": "Taro-router",
5
- "browser": "dist/index.esm.js",
6
- "main:h5": "dist/index.js",
5
+ "browser": "dist/index.js",
6
+ "main:h5": "dist/index.esm.js",
7
7
  "main": "dist/index.js",
8
8
  "module": "dist/index.cjs.js",
9
- "typings": "dist/index.d.ts",
9
+ "typings": "dist/index.esm.d.ts",
10
10
  "files": [
11
11
  "dist",
12
12
  "types",
13
13
  "index.js"
14
14
  ],
15
+ "sideEffects": [],
15
16
  "repository": {
16
17
  "type": "git",
17
18
  "url": "git+https://github.com/NervJS/taro.git"
@@ -26,29 +27,38 @@
26
27
  "history": "^5.1.0",
27
28
  "mobile-detect": "^1.4.2",
28
29
  "query-string": "^7.1.1",
29
- "universal-router": "^8.3.0",
30
- "@tarojs/runtime": "3.6.22",
31
- "@tarojs/taro": "3.6.22"
30
+ "tslib": "^2.6.2",
31
+ "universal-router": "^8.3.0"
32
32
  },
33
33
  "devDependencies": {
34
- "@rollup/plugin-commonjs": "^20.0.0",
35
- "@rollup/plugin-node-resolve": "^8.0.0",
34
+ "@rollup/plugin-commonjs": "^24.0.0",
35
+ "@rollup/plugin-node-resolve": "^15.0.0",
36
+ "@rollup/plugin-typescript": "^11.1.0",
36
37
  "@types/jest": "^29.4.0",
37
38
  "jest": "^29.3.1",
38
39
  "jest-cli": "^29.3.1",
39
40
  "jest-environment-jsdom": "^29.5.0",
40
41
  "jsdom": "^21.1.0",
41
- "rollup": "^2.79.0",
42
+ "rollup": "^3.8.1",
42
43
  "rollup-plugin-node-externals": "^5.0.0",
43
44
  "rollup-plugin-ts": "^3.0.2",
44
45
  "ts-jest": "^29.0.5",
45
- "typescript": "^4.7.4"
46
+ "typescript": "^4.7.4",
47
+ "@tarojs/runtime": "3.6.23",
48
+ "@tarojs/taro": "3.6.23"
49
+ },
50
+ "peerDependencies": {
51
+ "@tarojs/runtime": "3.6.23",
52
+ "@tarojs/taro": "3.6.23"
46
53
  },
47
54
  "scripts": {
48
- "build": "rimraf ./dist && tsc && rollup -c",
49
- "dev": "tsc -w",
55
+ "prebuild": "pnpm run clean",
56
+ "build": "pnpm run rollup --environment NODE_ENV:production",
57
+ "clean": "rimraf ./dist",
58
+ "dev": "pnpm run rollup --environment NODE_ENV:development -w",
59
+ "rollup": "rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript --bundleConfigAsCjs",
50
60
  "test": "cross-env NODE_ENV=jest jest",
51
- "test:ci": "cross-env NODE_ENV=jest jest --ci",
61
+ "test:ci": "cross-env NODE_ENV=jest jest --ci -i --coverage --silent",
52
62
  "test:dev": "cross-env NODE_ENV=jest jest --watch"
53
63
  }
54
64
  }
@@ -1,3 +1,8 @@
1
+ /**
2
+ * Note: @tarojs/router 不能依赖 @tarojs/components,
3
+ * 因为 @tarojs/components 依赖 @tarojs/router,
4
+ * 且仅通过 peerDependencies 引用依赖会在 pnpm publish 时抛出错误
5
+ */
1
6
  declare module '@tarojs/components/dist/components' {
2
7
  export function defineCustomElementTaroTabbar() {}
3
8
 
@@ -0,0 +1,8 @@
1
+ import Taro from '@tarojs/taro'
2
+
3
+ declare module '@tarojs/taro' {
4
+ interface TaroStatic {
5
+ initTabBarApis(config: AppConfig): void
6
+ }
7
+ }
8
+