@tarojs/taro-h5 3.3.11 → 3.3.15

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
@@ -249,7 +249,8 @@ var ENV_TYPE = {
249
249
  ALIPAY: 'ALIPAY',
250
250
  TT: 'TT',
251
251
  QQ: 'QQ',
252
- JD: 'JD'
252
+ JD: 'JD',
253
+ KWAI: 'KWAI'
253
254
  };
254
255
  var _env = null; // 一个taro项目肯定运行同样的环境
255
256
 
@@ -286,6 +287,11 @@ function getEnv() {
286
287
  return ENV_TYPE.ALIPAY;
287
288
  }
288
289
 
290
+ if (typeof ks !== 'undefined' && ks.getSystemInfo) {
291
+ _env = ENV_TYPE.KWAI;
292
+ return ENV_TYPE.KWAI;
293
+ }
294
+
289
295
  if (typeof global !== 'undefined' && global.__fbGenNativeModule) {
290
296
  _env = ENV_TYPE.RN;
291
297
  return ENV_TYPE.RN;
@@ -919,7 +925,11 @@ function createBrowserHistory(b) {
919
925
 
920
926
  function x(c, a) {
921
927
  void 0 === a && (a = null);
922
- return C(_extends({}, q, "string" === typeof c ? J(c) : c, {
928
+ return C(_extends({
929
+ pathname: q.pathname,
930
+ hash: "",
931
+ search: ""
932
+ }, "string" === typeof c ? J(c) : c, {
923
933
  state: a,
924
934
  key: H()
925
935
  }));
@@ -1102,7 +1112,11 @@ function createHashHistory(b) {
1102
1112
 
1103
1113
  function z(a, e) {
1104
1114
  void 0 === e && (e = null);
1105
- return C(_extends({}, d, "string" === typeof a ? J(a) : a, {
1115
+ return C(_extends({
1116
+ pathname: d.pathname,
1117
+ hash: "",
1118
+ search: ""
1119
+ }, "string" === typeof a ? J(a) : a, {
1106
1120
  state: e,
1107
1121
  key: H()
1108
1122
  }));
@@ -1244,12 +1258,92 @@ function setHistoryMode(mode) {
1244
1258
  }
1245
1259
  }
1246
1260
 
1247
- function parsePath() {
1261
+ function prependBasename() {
1248
1262
  var url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
1249
1263
  return basename.replace(/\/$/, '') + '/' + url.replace(/^\//, '');
1250
1264
  }
1251
1265
 
1252
- var stacks = [];
1266
+ var hasBasename = function hasBasename(path, prefix) {
1267
+ return new RegExp('^' + prefix + '(\\/|\\?|#|$)', 'i').test(path);
1268
+ };
1269
+
1270
+ var stripBasename = function stripBasename(path, prefix) {
1271
+ return hasBasename(path, prefix) ? path.substr(prefix.length) : path;
1272
+ };
1273
+
1274
+ var Stacks = /*#__PURE__*/function () {
1275
+ function Stacks() {
1276
+ _classCallCheck$1(this, Stacks);
1277
+
1278
+ this.stacks = [];
1279
+ this.backDelta = 0;
1280
+ }
1281
+
1282
+ _createClass$1(Stacks, [{
1283
+ key: "delta",
1284
+ set: function set(delta) {
1285
+ if (delta > 0) {
1286
+ this.backDelta = delta;
1287
+ } else {
1288
+ --this.backDelta;
1289
+ }
1290
+ }
1291
+ }, {
1292
+ key: "length",
1293
+ get: function get() {
1294
+ return this.stacks.length;
1295
+ }
1296
+ }, {
1297
+ key: "last",
1298
+ get: function get() {
1299
+ return this.stacks[this.length - 1];
1300
+ }
1301
+ }, {
1302
+ key: "get",
1303
+ value: function get() {
1304
+ return this.stacks;
1305
+ }
1306
+ }, {
1307
+ key: "getItem",
1308
+ value: function getItem(index) {
1309
+ return this.stacks[index];
1310
+ }
1311
+ }, {
1312
+ key: "getDelta",
1313
+ value: function getDelta(pathname) {
1314
+ if (this.backDelta >= 1) {
1315
+ return this.backDelta;
1316
+ } // NOTE: 此处为了修复浏览器后退多级页面,在大量重复路由状况下可能出现判断错误的情况 (增强判断能力只能考虑在 query 中新增参数来判断,暂时搁置)
1317
+
1318
+
1319
+ var prevIndex = this.stacks.findIndex(function (r) {
1320
+ var _a;
1321
+
1322
+ return ((_a = r.path) === null || _a === void 0 ? void 0 : _a.replace(/\?.*/g, '')) === pathname;
1323
+ });
1324
+ return this.length - 1 - prevIndex;
1325
+ }
1326
+ }, {
1327
+ key: "getPrevIndex",
1328
+ value: function getPrevIndex(pathname) {
1329
+ return this.length - 1 - this.getDelta(pathname);
1330
+ }
1331
+ }, {
1332
+ key: "pop",
1333
+ value: function pop() {
1334
+ return this.stacks.pop();
1335
+ }
1336
+ }, {
1337
+ key: "push",
1338
+ value: function push(page) {
1339
+ return this.stacks.push(page);
1340
+ }
1341
+ }]);
1342
+
1343
+ return Stacks;
1344
+ }();
1345
+
1346
+ var stacks = new Stacks();
1253
1347
  var routesAlias = {};
1254
1348
 
1255
1349
  function setRoutesAlias(alias) {
@@ -1262,89 +1356,112 @@ function addLeadingSlash(path) {
1262
1356
  }
1263
1357
 
1264
1358
  return path.charAt(0) === '/' ? path : '/' + path;
1265
- } // 解决navigateBack调用delta>1时,路由栈异常问题
1266
- // 比如:A->B->C,navigateBack({delta: 2}),此时路由栈中还存在B页面
1267
- // 原因:主要是由于一次性退出多层级页面时,此action只会执行一次,此处进行手动处理
1359
+ }
1268
1360
 
1361
+ var isTabBar = function isTabBar(config) {
1362
+ var _a, _b;
1363
+
1364
+ var _config$router = config.router,
1365
+ _config$router$custom = _config$router.customRoutes,
1366
+ customRoutes = _config$router$custom === void 0 ? {} : _config$router$custom,
1367
+ _config$router$basena = _config$router.basename,
1368
+ basename = _config$router$basena === void 0 ? '' : _config$router$basena,
1369
+ pathname = _config$router.pathname;
1370
+ var routePath = stripBasename(pathname, basename);
1371
+ var pagePath = ((_a = Object.entries(customRoutes).find(function (_ref) {
1372
+ var _ref2 = _slicedToArray(_ref, 2),
1373
+ target = _ref2[1];
1374
+
1375
+ return target === routePath;
1376
+ })) === null || _a === void 0 ? void 0 : _a[0]) || routePath;
1377
+ return !!pagePath && (((_b = config.tabBar) === null || _b === void 0 ? void 0 : _b.list) || []).some(function (t) {
1378
+ return t.pagePath === pagePath;
1379
+ });
1380
+ };
1269
1381
 
1270
- var historyBackDelta = 1;
1382
+ function processNavigateUrl(option) {
1383
+ var _a;
1271
1384
 
1272
- function setHistoryBackDelta(delta) {
1273
- historyBackDelta = delta;
1274
- } // eslint-disable-next-line @typescript-eslint/ban-types
1385
+ var pathPieces = J(option.url); // 处理自定义路由
1275
1386
 
1387
+ Object.keys(routesAlias).forEach(function (key) {
1388
+ if (addLeadingSlash(key) === addLeadingSlash(pathPieces.pathname)) {
1389
+ pathPieces.pathname = routesAlias[key];
1390
+ }
1391
+ }); // 处理相对路径
1276
1392
 
1277
- var throttle = function throttle(fn, threshold) {
1278
- var lastTime = 0;
1279
- return function () {
1280
- var now = Date.now();
1393
+ if ((_a = pathPieces === null || pathPieces === void 0 ? void 0 : pathPieces.pathname) === null || _a === void 0 ? void 0 : _a.includes('./')) {
1394
+ var parts = exports.history.location.pathname.split('/');
1395
+ parts.pop();
1396
+ pathPieces.pathname.split('/').forEach(function (item) {
1397
+ if (item === '.') {
1398
+ return;
1399
+ }
1281
1400
 
1282
- if (now - lastTime > threshold) {
1283
- fn.apply(this, arguments);
1284
- lastTime = now;
1285
- }
1286
- };
1287
- };
1401
+ item === '..' ? parts.pop() : parts.push(item);
1402
+ });
1403
+ pathPieces.pathname = parts.join('/');
1404
+ } // 处理 basename
1288
1405
 
1289
- function processNavigateUrl(option) {
1290
- var url = option.url;
1291
- var matches = option.url.match(/[?&?].*/);
1292
- var parameters = '';
1293
1406
 
1294
- if (matches && matches.length) {
1295
- parameters = matches[0];
1296
- url = url.replace(parameters, '');
1297
- }
1407
+ pathPieces.pathname = prependBasename(pathPieces.pathname); // hack fix history v5 bug: https://github.com/remix-run/history/issues/814
1298
1408
 
1299
- Object.keys(routesAlias).forEach(function (key) {
1300
- if (addLeadingSlash(key) === addLeadingSlash(url)) {
1301
- option.url = routesAlias[key] + parameters;
1302
- }
1303
- });
1409
+ if (!pathPieces.search) pathPieces.search = '';
1410
+ return pathPieces;
1304
1411
  }
1305
1412
 
1306
- function navigate(option, method) {
1307
- var success = option.success,
1308
- complete = option.complete,
1309
- fail = option.fail;
1310
- var failReason;
1311
-
1312
- if (option.url) {
1313
- processNavigateUrl(option);
1314
- }
1413
+ function navigate(_x, _x2) {
1414
+ return _navigate.apply(this, arguments);
1415
+ }
1315
1416
 
1316
- try {
1317
- if (method === 'navigateTo') {
1318
- exports.history.push(parsePath(option.url), {
1319
- timestamp: Date.now()
1320
- });
1321
- } else if (method === 'redirectTo') {
1322
- exports.history.replace(parsePath(option.url), {
1323
- timestamp: Date.now()
1324
- });
1325
- } else if (method === 'navigateBack') {
1326
- setHistoryBackDelta(option.delta);
1327
- exports.history.go(-option.delta);
1328
- }
1329
- } catch (error) {
1330
- failReason = error;
1331
- }
1417
+ function _navigate() {
1418
+ _navigate = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(option, method) {
1419
+ return regeneratorRuntime.wrap(function _callee2$(_context2) {
1420
+ while (1) {
1421
+ switch (_context2.prev = _context2.next) {
1422
+ case 0:
1423
+ return _context2.abrupt("return", new Promise(function (resolve, reject) {
1424
+ var success = option.success,
1425
+ complete = option.complete,
1426
+ fail = option.fail;
1427
+ var unListen = exports.history.listen(function () {
1428
+ success === null || success === void 0 ? void 0 : success();
1429
+ complete === null || complete === void 0 ? void 0 : complete();
1430
+ resolve();
1431
+ unListen();
1432
+ });
1332
1433
 
1333
- return new Promise(function (resolve, reject) {
1334
- if (failReason) {
1335
- fail && fail(failReason);
1336
- complete && complete();
1337
- reject(failReason);
1338
- return;
1339
- }
1434
+ try {
1435
+ if ('url' in option) {
1436
+ var pathPieces = processNavigateUrl(option);
1437
+ var state = {
1438
+ timestamp: Date.now()
1439
+ };
1440
+
1441
+ if (method === 'navigateTo') {
1442
+ exports.history.push(pathPieces, state);
1443
+ } else if (method === 'redirectTo') {
1444
+ exports.history.replace(pathPieces, state);
1445
+ }
1446
+ } else if (method === 'navigateBack') {
1447
+ stacks.delta = option.delta;
1448
+ exports.history.go(-option.delta);
1449
+ }
1450
+ } catch (error) {
1451
+ fail === null || fail === void 0 ? void 0 : fail(error);
1452
+ complete === null || complete === void 0 ? void 0 : complete();
1453
+ reject(error);
1454
+ }
1455
+ }));
1340
1456
 
1341
- var unlisten = exports.history.listen(function () {
1342
- success && success();
1343
- complete && complete();
1344
- resolve();
1345
- unlisten();
1346
- });
1347
- });
1457
+ case 1:
1458
+ case "end":
1459
+ return _context2.stop();
1460
+ }
1461
+ }
1462
+ }, _callee2);
1463
+ }));
1464
+ return _navigate.apply(this, arguments);
1348
1465
  }
1349
1466
 
1350
1467
  function navigateTo(option) {
@@ -1368,15 +1485,17 @@ function navigateBack() {
1368
1485
  }
1369
1486
 
1370
1487
  function switchTab(option) {
1371
- return navigateTo(option);
1488
+ // TODO: 清除掉所有的栈去目标页面
1489
+ return redirectTo(option);
1372
1490
  }
1373
1491
 
1374
1492
  function reLaunch(option) {
1493
+ // TODO: 清除掉所有的栈去目标页面
1375
1494
  return redirectTo(option);
1376
1495
  }
1377
1496
 
1378
1497
  function getCurrentPages() {
1379
- return stacks;
1498
+ return stacks.get();
1380
1499
  }
1381
1500
  /**
1382
1501
  * Expose `pathToRegexp`.
@@ -2021,6 +2140,8 @@ var UniversalRouter = function () {
2021
2140
 
2022
2141
  UniversalRouter.pathToRegexp = pathToRegexp_1;
2023
2142
 
2143
+ var Taro$1 = require('@tarojs/taro-h5');
2144
+
2024
2145
  function initTabbar(config) {
2025
2146
  if (config.tabBar == null) {
2026
2147
  return;
@@ -2033,7 +2154,6 @@ function initTabbar(config) {
2033
2154
  tabbar.conf.homePage = exports.history.location.pathname === '/' ? homePage : exports.history.location.pathname;
2034
2155
  var routerConfig = config.router;
2035
2156
  tabbar.conf.mode = routerConfig && routerConfig.mode ? routerConfig.mode : 'hash';
2036
- tabbar.conf.custom = !!routerConfig.customRoutes;
2037
2157
 
2038
2158
  if (routerConfig.customRoutes) {
2039
2159
  tabbar.conf.custom = true;
@@ -2043,9 +2163,14 @@ function initTabbar(config) {
2043
2163
  tabbar.conf.customRoutes = {};
2044
2164
  }
2045
2165
 
2166
+ if (typeof routerConfig.basename !== 'undefined') {
2167
+ tabbar.conf.basename = routerConfig.basename;
2168
+ }
2169
+
2046
2170
  var container = document.getElementById('container'); // eslint-disable-next-line no-unused-expressions
2047
2171
 
2048
2172
  container === null || container === void 0 ? void 0 : container.appendChild(tabbar);
2173
+ Taro$1.initTabBarApis(config);
2049
2174
  }
2050
2175
 
2051
2176
  var routerConfig = Object.create(null);
@@ -2071,6 +2196,64 @@ function init(config) {
2071
2196
  initTabbar(config);
2072
2197
  }
2073
2198
 
2199
+ var pageScrollFn;
2200
+ var pageDOM = window;
2201
+
2202
+ function bindPageScroll(page, config) {
2203
+ pageDOM.removeEventListener('scroll', pageScrollFn);
2204
+ pageDOM = getScrollContainer();
2205
+ var distance = config.onReachBottomDistance || 50;
2206
+ var isReachBottom = false;
2207
+
2208
+ pageScrollFn = function pageScrollFn() {
2209
+ page.onPageScroll && page.onPageScroll({
2210
+ scrollTop: pageDOM instanceof Window ? window.scrollY : pageDOM.scrollTop
2211
+ });
2212
+
2213
+ if (isReachBottom && getOffset() > distance) {
2214
+ isReachBottom = false;
2215
+ }
2216
+
2217
+ if (page.onReachBottom && !isReachBottom && getOffset() < distance) {
2218
+ isReachBottom = true;
2219
+ page.onReachBottom();
2220
+ }
2221
+ };
2222
+
2223
+ pageDOM.addEventListener('scroll', pageScrollFn, false);
2224
+ }
2225
+
2226
+ window.addEventListener('DOMSubtreeModified', function (e) {
2227
+ var _a; // @ts-ignore
2228
+
2229
+
2230
+ var className = (_a = e.target) === null || _a === void 0 ? void 0 : _a.className;
2231
+
2232
+ if (className && /taro-tabbar__/.test(className)) {
2233
+ pageDOM.removeEventListener('scroll', pageScrollFn);
2234
+ pageDOM = getScrollContainer();
2235
+ pageDOM.addEventListener('scroll', pageScrollFn, false);
2236
+ }
2237
+ }, false);
2238
+
2239
+ function getScrollContainer() {
2240
+ if (document.querySelector('.taro-tabbar__tabbar') === null) {
2241
+ // 没设置tabbar
2242
+ return window;
2243
+ } else {
2244
+ // 有设置tabbar
2245
+ return document.querySelector('.taro-tabbar__panel') || window;
2246
+ }
2247
+ }
2248
+
2249
+ function getOffset() {
2250
+ if (pageDOM instanceof Window) {
2251
+ return document.documentElement.scrollHeight - window.scrollY - window.innerHeight;
2252
+ } else {
2253
+ return pageDOM.scrollHeight - pageDOM.scrollTop - pageDOM.clientHeight;
2254
+ }
2255
+ }
2256
+
2074
2257
  function createCommonjsModule$1(fn, module) {
2075
2258
  return module = {
2076
2259
  exports: {}
@@ -2640,10 +2823,26 @@ var queryString_5 = queryString.stringifyUrl;
2640
2823
  var queryString_6 = queryString.pick;
2641
2824
  var queryString_7 = queryString.exclude;
2642
2825
 
2826
+ function getSearch() {
2827
+ var search = '?';
2828
+
2829
+ if (routerConfig.router.mode === 'hash') {
2830
+ var idx = location.hash.indexOf('?');
2831
+
2832
+ if (idx > -1) {
2833
+ search = location.hash.slice(idx);
2834
+ }
2835
+ } else {
2836
+ search = location.search;
2837
+ }
2838
+
2839
+ return search.substr(1);
2840
+ }
2841
+
2643
2842
  var qs = function qs() {
2644
2843
  var stamp = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
2645
- var search = routerConfig.router.mode === 'hash' ? location.hash.slice(routerConfig.router.pathname.length + 1) : location.search;
2646
- var query = search ? queryString.parse(search.substr(1)) : {};
2844
+ var search = getSearch();
2845
+ var query = search ? queryString.parse(search) : {};
2647
2846
 
2648
2847
  if (stamp) {
2649
2848
  query.stamp = stamp.toString();
@@ -2651,142 +2850,90 @@ var qs = function qs() {
2651
2850
 
2652
2851
  return query;
2653
2852
  };
2853
+ /* eslint-disable dot-notation */
2654
2854
 
2655
- var pageScrollFn;
2656
- var pageDOM = window;
2657
2855
 
2658
- function bindPageScroll(page, config) {
2659
- pageDOM.removeEventListener('scroll', pageScrollFn);
2660
- pageDOM = getScrollContainer();
2661
- var distance = config.onReachBottomDistance || 50;
2662
- var isReachBottom = false;
2663
-
2664
- pageScrollFn = function pageScrollFn() {
2665
- page.onPageScroll && page.onPageScroll({
2666
- scrollTop: pageDOM instanceof Window ? window.scrollY : pageDOM.scrollTop
2667
- });
2856
+ function pageOnReady(page) {
2857
+ var onLoad = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
2668
2858
 
2669
- if (isReachBottom && getOffset() > distance) {
2670
- isReachBottom = false;
2671
- }
2859
+ var _a;
2672
2860
 
2673
- if (page.onReachBottom && !isReachBottom && getOffset() < distance) {
2674
- isReachBottom = true;
2675
- page.onReachBottom();
2676
- }
2677
- };
2861
+ var pageEl = document.getElementById(page.path);
2678
2862
 
2679
- pageDOM.addEventListener('scroll', pageScrollFn, false);
2863
+ if (pageEl && !(pageEl === null || pageEl === void 0 ? void 0 : pageEl['__isReady'])) {
2864
+ var el = pageEl.firstElementChild;
2865
+ (_a = el === null || el === void 0 ? void 0 : el['componentOnReady']) === null || _a === void 0 ? void 0 : _a.call(el).then(function () {
2866
+ runtime.requestAnimationFrame(function () {
2867
+ page.onReady();
2868
+ pageEl['__isReady'] = true;
2869
+ });
2870
+ });
2871
+ onLoad && (pageEl['__page'] = page);
2872
+ }
2680
2873
  }
2681
2874
 
2682
- window.addEventListener('DOMSubtreeModified', function (e) {
2683
- var _a; // @ts-ignore
2684
-
2685
-
2686
- var className = (_a = e.target) === null || _a === void 0 ? void 0 : _a.className;
2687
-
2688
- if (className && /taro-tabbar__/.test(className)) {
2689
- pageDOM.removeEventListener('scroll', pageScrollFn);
2690
- pageDOM = getScrollContainer();
2691
- pageDOM.addEventListener('scroll', pageScrollFn, false);
2692
- }
2693
- }, false);
2875
+ function loadPage(page) {
2876
+ var pageConfig = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2877
+ var stacksIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
2878
+ if (!page) return;
2879
+ var pageEl = document.getElementById(page.path);
2694
2880
 
2695
- function getScrollContainer() {
2696
- if (document.querySelector('.taro-tabbar__tabbar') === null) {
2697
- // 没设置tabbar
2698
- return window;
2881
+ if (pageEl) {
2882
+ pageEl.style.display = 'block';
2699
2883
  } else {
2700
- // 有设置tabbar
2701
- return document.querySelector('.taro-tabbar__panel') || window;
2884
+ page.onLoad(qs(stacksIndex), function () {
2885
+ return pageOnReady(page, true);
2886
+ });
2702
2887
  }
2703
- }
2704
2888
 
2705
- function getOffset() {
2706
- if (pageDOM instanceof Window) {
2707
- return document.documentElement.scrollHeight - window.scrollY - window.innerHeight;
2708
- } else {
2709
- return pageDOM.scrollHeight - pageDOM.scrollTop - pageDOM.clientHeight;
2710
- }
2889
+ stacks.push(page);
2890
+ page.onShow();
2891
+ bindPageScroll(page, pageConfig);
2711
2892
  }
2712
- /* eslint-disable dot-notation */
2713
-
2714
2893
 
2715
- function hidePage(page) {
2716
- if (page != null) {
2717
- page.onHide();
2718
- var pageEl = document.getElementById(page.path);
2719
-
2720
- if (pageEl) {
2721
- pageEl.style.display = 'none';
2722
- }
2723
- }
2894
+ function unloadPage(page) {
2895
+ var delta = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
2896
+ if (!page) return;
2897
+ stacks.delta = --delta;
2898
+ stacks.pop();
2899
+ page.onUnload();
2900
+ if (delta >= 1) unloadPage(stacks.last, delta);
2724
2901
  }
2725
2902
 
2726
- function showPage(page, pageConfig) {
2903
+ function showPage(page) {
2904
+ var pageConfig = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2727
2905
  var stacksIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
2906
+ if (!page) return;
2907
+ page.onShow();
2908
+ var pageEl = document.getElementById(page.path);
2728
2909
 
2729
- if (page != null) {
2730
- page.onShow();
2731
- var pageEl = document.getElementById(page.path);
2732
-
2733
- if (pageEl) {
2734
- pageEl.style.display = 'block';
2735
- } else {
2736
- page.onLoad(qs(stacksIndex));
2737
- pageEl = document.getElementById(page.path);
2738
- pageOnReady(pageEl, page, false);
2739
- }
2740
-
2741
- bindPageScroll(page, pageConfig || {});
2910
+ if (pageEl) {
2911
+ pageEl.style.display = 'block';
2912
+ } else {
2913
+ page.onLoad(qs(stacksIndex), function () {
2914
+ return pageOnReady(page, false);
2915
+ });
2742
2916
  }
2743
- }
2744
2917
 
2745
- function unloadPage(page) {
2746
- if (page != null) {
2747
- stacks.pop();
2748
- page.onUnload();
2749
- }
2918
+ bindPageScroll(page, pageConfig);
2750
2919
  }
2751
2920
 
2752
- function pageOnReady(pageEl, page) {
2753
- var onLoad = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
2754
-
2755
- var _a;
2921
+ function hidePage(page) {
2922
+ if (!page) return; // NOTE: 修复多页并发问题,此处可能因为路由跳转过快,执行时页面可能还没有创建成功
2756
2923
 
2757
- if (pageEl && !(pageEl === null || pageEl === void 0 ? void 0 : pageEl['__isReady'])) {
2758
- var el = pageEl.firstElementChild; // eslint-disable-next-line no-unused-expressions
2924
+ var pageEl = document.getElementById(page.path);
2759
2925
 
2760
- (_a = el === null || el === void 0 ? void 0 : el['componentOnReady']) === null || _a === void 0 ? void 0 : _a.call(el).then(function () {
2761
- runtime.requestAnimationFrame(function () {
2762
- page.onReady();
2763
- pageEl['__isReady'] = true;
2764
- });
2765
- });
2766
- onLoad && (pageEl['__page'] = page);
2926
+ if (pageEl) {
2927
+ pageEl.style.display = 'none';
2928
+ page.onHide();
2929
+ } else {
2930
+ setTimeout(function () {
2931
+ return hidePage(page);
2932
+ }, 0);
2767
2933
  }
2768
2934
  }
2935
+ /* eslint-disable dot-notation */
2769
2936
 
2770
- function loadPage(page, pageConfig) {
2771
- var stacksIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
2772
-
2773
- if (page !== null) {
2774
- var pageEl = document.getElementById(page.path);
2775
-
2776
- if (pageEl) {
2777
- pageEl.style.display = 'block';
2778
- } else {
2779
- page.onLoad(qs(stacksIndex), function () {
2780
- pageEl = document.getElementById(page.path);
2781
- pageOnReady(pageEl, page);
2782
- });
2783
- }
2784
-
2785
- stacks.push(page);
2786
- page.onShow();
2787
- bindPageScroll(page, pageConfig || {});
2788
- }
2789
- }
2790
2937
 
2791
2938
  function createRouter(app, config, framework) {
2792
2939
  var _a;
@@ -2811,15 +2958,16 @@ function createRouter(app, config, framework) {
2811
2958
  baseUrl: basename || ''
2812
2959
  });
2813
2960
  app.onLaunch();
2814
- var render = throttle( /*#__PURE__*/function () {
2815
- var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(_ref) {
2816
- var location, action, _a, _b, _c, _d, _e, element, pageConfig, enablePullDownRefresh, shouldLoad, delta, prevIndex, prev, el, _config, pathname, routerIndex, isTabBar, page;
2961
+
2962
+ var render = /*#__PURE__*/function () {
2963
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(_ref3) {
2964
+ var location, action, _a, _b, _c, _d, element, pageConfig, enablePullDownRefresh, currentPage, pathname, shouldLoad, prevIndex, delta, _prevIndex, el, loadConfig, stacksIndex, page;
2817
2965
 
2818
2966
  return regeneratorRuntime.wrap(function _callee$(_context) {
2819
2967
  while (1) {
2820
2968
  switch (_context.prev = _context.next) {
2821
2969
  case 0:
2822
- location = _ref.location, action = _ref.action;
2970
+ location = _ref3.location, action = _ref3.action;
2823
2971
  routerConfig.router.pathname = location.pathname;
2824
2972
  _context.prev = 2;
2825
2973
  _context.next = 5;
@@ -2873,62 +3021,86 @@ function createRouter(app, config, framework) {
2873
3021
  enablePullDownRefresh = pageConfig.enablePullDownRefresh;
2874
3022
  }
2875
3023
 
3024
+ currentPage = runtime.Current.page;
3025
+ pathname = location.pathname;
2876
3026
  shouldLoad = false;
2877
3027
 
2878
- if (action === 'POP') {
2879
- unloadPage(runtime.Current.page);
2880
- delta = historyBackDelta;
3028
+ if (!(action === 'POP')) {
3029
+ _context.next = 31;
3030
+ break;
3031
+ }
2881
3032
 
2882
- while (delta-- > 1) {
2883
- unloadPage(stacks.slice(-1)[0]);
2884
- } // 最终必须重置为 1
3033
+ // NOTE: 浏览器事件退后多次时,该事件只会被触发一次
3034
+ prevIndex = stacks.getPrevIndex(pathname);
3035
+ delta = stacks.getDelta(pathname);
3036
+ unloadPage(currentPage, delta);
2885
3037
 
3038
+ if (prevIndex > -1) {
3039
+ showPage(stacks.getItem(prevIndex), pageConfig, prevIndex);
3040
+ } else {
3041
+ shouldLoad = true;
3042
+ }
2886
3043
 
2887
- setHistoryBackDelta(1);
2888
- prevIndex = stacks.reduceRight(function (p, s, i) {
2889
- if (p !== 0) return p;else if (s.path === location.pathname + runtime.stringify(qs(i))) return i;else return 0;
2890
- }, 0);
2891
- prev = stacks[prevIndex];
3044
+ _context.next = 46;
3045
+ break;
2892
3046
 
2893
- if (prev) {
2894
- showPage(prev, pageConfig, prevIndex);
2895
- } else {
2896
- shouldLoad = true;
2897
- }
2898
- } else if (action === 'PUSH') {
2899
- hidePage(runtime.Current.page);
2900
- shouldLoad = true;
2901
- } else if (action === 'REPLACE') {
2902
- unloadPage(runtime.Current.page);
2903
- shouldLoad = true;
3047
+ case 31:
3048
+ if (!(action === 'PUSH')) {
3049
+ _context.next = 36;
3050
+ break;
3051
+ }
3052
+
3053
+ hidePage(currentPage);
3054
+ shouldLoad = true;
3055
+ _context.next = 46;
3056
+ break;
3057
+
3058
+ case 36:
3059
+ if (!(action === 'REPLACE')) {
3060
+ _context.next = 46;
3061
+ break;
2904
3062
  }
2905
3063
 
2906
- if (shouldLoad) {
2907
- el = (_c = element["default"]) !== null && _c !== void 0 ? _c : element;
2908
- _config = Object.assign({}, pageConfig);
2909
- delete _config['path'];
2910
- delete _config['load'];
2911
- pathname = basename ? location.pathname.replace(basename, '') : location.pathname;
2912
- isTabBar = (_d = routerConfig.tabBar) === null || _d === void 0 ? void 0 : _d.list.some(function (TabBarItem) {
2913
- var _a;
3064
+ if (!isTabBar(config)) {
3065
+ _context.next = 44;
3066
+ break;
3067
+ }
2914
3068
 
2915
- return ((_a = TabBarItem.pagePath) === null || _a === void 0 ? void 0 : _a.replace(/\?.*/g, '')) === pathname;
2916
- });
3069
+ hidePage(currentPage);
3070
+ _prevIndex = stacks.getPrevIndex(pathname);
2917
3071
 
2918
- if ((stacks === null || stacks === void 0 ? void 0 : stacks.length) > 0 && isTabBar) {
2919
- routerIndex = stacks.findIndex(function (r) {
2920
- var _a;
3072
+ if (!(_prevIndex > -1)) {
3073
+ _context.next = 42;
3074
+ break;
3075
+ }
2921
3076
 
2922
- return ((_a = r.path) === null || _a === void 0 ? void 0 : _a.replace(/\?.*/g, '')) === pathname;
2923
- });
2924
- }
3077
+ return _context.abrupt("return", showPage(stacks.getItem(_prevIndex), pageConfig, _prevIndex));
3078
+
3079
+ case 42:
3080
+ _context.next = 45;
3081
+ break;
2925
3082
 
2926
- routerIndex = (routerIndex || routerIndex === 0) && routerIndex !== -1 ? routerIndex : stacks.length;
2927
- page = runtime.createPageConfig(enablePullDownRefresh ? (_e = runtimeHooks.createPullDownComponent) === null || _e === void 0 ? void 0 : _e.call(runtimeHooks, el, location.pathname, framework, routerConfig.PullDownRefresh) : el, pathname + runtime.stringify(qs(routerIndex)), {}, _config);
2928
- loadPage(page, pageConfig, routerIndex);
3083
+ case 44:
3084
+ unloadPage(currentPage);
3085
+
3086
+ case 45:
3087
+ shouldLoad = true;
3088
+
3089
+ case 46:
3090
+ if (!shouldLoad) {
3091
+ _context.next = 54;
3092
+ break;
2929
3093
  }
2930
3094
 
2931
- case 24:
3095
+ el = (_c = element["default"]) !== null && _c !== void 0 ? _c : element;
3096
+ loadConfig = Object.assign({}, pageConfig);
3097
+ stacksIndex = stacks.length;
3098
+ delete loadConfig['path'];
3099
+ delete loadConfig['load'];
3100
+ page = runtime.createPageConfig(enablePullDownRefresh ? (_d = runtimeHooks.createPullDownComponent) === null || _d === void 0 ? void 0 : _d.call(runtimeHooks, el, location.pathname, framework, routerConfig.PullDownRefresh) : el, pathname + runtime.stringify(qs(stacksIndex)), {}, loadConfig);
3101
+ return _context.abrupt("return", loadPage(page, pageConfig, stacksIndex));
3102
+
3103
+ case 54:
2932
3104
  case "end":
2933
3105
  return _context.stop();
2934
3106
  }
@@ -2936,13 +3108,13 @@ function createRouter(app, config, framework) {
2936
3108
  }, _callee, null, [[2, 8]]);
2937
3109
  }));
2938
3110
 
2939
- return function (_x) {
2940
- return _ref2.apply(this, arguments);
3111
+ return function render(_x3) {
3112
+ return _ref4.apply(this, arguments);
2941
3113
  };
2942
- }(), 500);
3114
+ }();
2943
3115
 
2944
3116
  if (exports.history.location.pathname === '/') {
2945
- exports.history.replace(parsePath(routes[0].path + exports.history.location.search));
3117
+ exports.history.replace(prependBasename(routes[0].path + exports.history.location.search));
2946
3118
  }
2947
3119
 
2948
3120
  render({
@@ -2953,7 +3125,7 @@ function createRouter(app, config, framework) {
2953
3125
  return exports.history.listen(render);
2954
3126
  }
2955
3127
 
2956
- function shouleBeObject(target) {
3128
+ function shouldBeObject(target) {
2957
3129
  if (target && _typeof$1(target) === 'object') return {
2958
3130
  res: true
2959
3131
  };
@@ -3291,7 +3463,7 @@ var initPxTransform = getInitPxTransform$1(taro);
3291
3463
  var requirePlugin = permanentlyNotSupport('requirePlugin');
3292
3464
 
3293
3465
  var getApp = function getApp() {
3294
- return taro._$app;
3466
+ return getCurrentInstance().app;
3295
3467
  };
3296
3468
 
3297
3469
  var pxTransform = function pxTransform(size) {
@@ -4311,7 +4483,7 @@ var createCanvasContext = function createCanvasContext(canvasId, inst) {
4311
4483
 
4312
4484
  function setStorage(options) {
4313
4485
  // options must be an Object
4314
- var isObject = shouleBeObject(options);
4486
+ var isObject = shouldBeObject(options);
4315
4487
 
4316
4488
  if (!isObject.res) {
4317
4489
  var _res = {
@@ -4380,7 +4552,7 @@ function setStorageSync(key) {
4380
4552
 
4381
4553
  function getStorage(options) {
4382
4554
  // options must be an Object
4383
- var isObject = shouleBeObject(options);
4555
+ var isObject = shouldBeObject(options);
4384
4556
 
4385
4557
  if (!isObject.res) {
4386
4558
  var _res2 = {
@@ -4488,7 +4660,7 @@ function getStorageInfoSync() {
4488
4660
 
4489
4661
  function removeStorage(options) {
4490
4662
  // options must be an Object
4491
- var isObject = shouleBeObject(options);
4663
+ var isObject = shouldBeObject(options);
4492
4664
 
4493
4665
  if (!isObject.res) {
4494
4666
  var _res3 = {
@@ -6055,7 +6227,7 @@ var uploadFile = function uploadFile(_ref2) {
6055
6227
 
6056
6228
  var chooseImage = function chooseImage(options) {
6057
6229
  // options must be an Object
6058
- var isObject = shouleBeObject(options);
6230
+ var isObject = shouldBeObject(options);
6059
6231
 
6060
6232
  if (!isObject.res) {
6061
6233
  var _res = {
@@ -6306,11 +6478,14 @@ function _previewImage() {
6306
6478
  function loadImage(url, fail) {
6307
6479
  return new Promise(function (resolve) {
6308
6480
  var item = document.createElement('taro-swiper-item-core');
6309
- item.style.cssText = "\n display: flex;\n align-items: center;\n justify-content: center;\n ";
6481
+ item.style.cssText = "\n display: flex;\n align-items: start;\n justify-content: center;\n overflow-y: scroll;\n ";
6310
6482
  var image = new Image();
6311
6483
  image.style.maxWidth = '100%';
6312
6484
  image.src = url;
6313
- item.appendChild(image); // Note: 等待图片加载完后返回,会导致轮播被卡住
6485
+ var div = document.createElement('div');
6486
+ div.style.cssText = "\n display: flex;\n align-items: center;\n justify-content: center;\n max-width: 100%;\n min-height: 100%;\n ";
6487
+ div.appendChild(image);
6488
+ item.appendChild(div); // Note: 等待图片加载完后返回,会导致轮播被卡住
6314
6489
 
6315
6490
  resolve(item);
6316
6491
 
@@ -7494,7 +7669,7 @@ var openLocation = processOpenapi('openLocation', {
7494
7669
 
7495
7670
  function setNavigationBarTitle(options) {
7496
7671
  // options must be an Object
7497
- var isObject = shouleBeObject(options);
7672
+ var isObject = shouldBeObject(options);
7498
7673
 
7499
7674
  if (!isObject.res) {
7500
7675
  var _res = {
@@ -7678,7 +7853,7 @@ function base64ToArrayBuffer(base64) {
7678
7853
  }
7679
7854
  function makePhoneCall(options) {
7680
7855
  // options must be an Object
7681
- var isObject = shouleBeObject(options);
7856
+ var isObject = shouldBeObject(options);
7682
7857
 
7683
7858
  if (!isObject.res) {
7684
7859
  var _res = {
@@ -10251,12 +10426,9 @@ var scanCode = processOpenapi('scanQRCode', {
10251
10426
  });
10252
10427
 
10253
10428
  var tabConf;
10254
- var App;
10255
10429
  function initTabBarApis() {
10256
- var _App = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
10257
-
10258
- tabConf = _App.state.__tabs;
10259
- App = _App;
10430
+ var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
10431
+ tabConf = config.tabBar;
10260
10432
  }
10261
10433
  /**
10262
10434
  * 为 tabBar 某一项的右上角添加文本
@@ -10271,7 +10443,7 @@ function initTabBarApis() {
10271
10443
  function setTabBarBadge() {
10272
10444
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
10273
10445
  // options must be an Object
10274
- var isObject = shouleBeObject(options);
10446
+ var isObject = shouldBeObject(options);
10275
10447
 
10276
10448
  if (!isObject.res) {
10277
10449
  var _res = {
@@ -10318,7 +10490,6 @@ function setTabBarBadge() {
10318
10490
  successHandler: successHandler(success, complete),
10319
10491
  errorHandler: errorHandler(fail, complete)
10320
10492
  });
10321
- return successHandler(success, complete)(res);
10322
10493
  }
10323
10494
  /**
10324
10495
  * 移除 tabBar 某一项右上角的文本
@@ -10332,7 +10503,7 @@ function setTabBarBadge() {
10332
10503
  function removeTabBarBadge() {
10333
10504
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
10334
10505
  // options must be an Object
10335
- var isObject = shouleBeObject(options);
10506
+ var isObject = shouldBeObject(options);
10336
10507
 
10337
10508
  if (!isObject.res) {
10338
10509
  var _res2 = {
@@ -10366,7 +10537,6 @@ function removeTabBarBadge() {
10366
10537
  successHandler: successHandler(success, complete),
10367
10538
  errorHandler: errorHandler(fail, complete)
10368
10539
  });
10369
- return successHandler(success, complete)(res);
10370
10540
  }
10371
10541
  /**
10372
10542
  * 显示 tabBar 某一项的右上角的红点
@@ -10380,7 +10550,7 @@ function removeTabBarBadge() {
10380
10550
  function showTabBarRedDot() {
10381
10551
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
10382
10552
  // options must be an Object
10383
- var isObject = shouleBeObject(options);
10553
+ var isObject = shouldBeObject(options);
10384
10554
 
10385
10555
  if (!isObject.res) {
10386
10556
  var _res3 = {
@@ -10414,7 +10584,6 @@ function showTabBarRedDot() {
10414
10584
  successHandler: successHandler(success, complete),
10415
10585
  errorHandler: errorHandler(fail, complete)
10416
10586
  });
10417
- return successHandler(success, complete)(res);
10418
10587
  }
10419
10588
  /**
10420
10589
  * 隐藏 tabBar 某一项的右上角的红点
@@ -10428,7 +10597,7 @@ function showTabBarRedDot() {
10428
10597
  function hideTabBarRedDot() {
10429
10598
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
10430
10599
  // options must be an Object
10431
- var isObject = shouleBeObject(options);
10600
+ var isObject = shouldBeObject(options);
10432
10601
 
10433
10602
  if (!isObject.res) {
10434
10603
  var _res4 = {
@@ -10462,7 +10631,6 @@ function hideTabBarRedDot() {
10462
10631
  successHandler: successHandler(success, complete),
10463
10632
  errorHandler: errorHandler(fail, complete)
10464
10633
  });
10465
- return successHandler(success, complete)(res);
10466
10634
  }
10467
10635
  /**
10468
10636
  * 显示 tabBar
@@ -10476,7 +10644,7 @@ function hideTabBarRedDot() {
10476
10644
  function showTabBar() {
10477
10645
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
10478
10646
  // options must be an Object
10479
- var isObject = shouleBeObject(options);
10647
+ var isObject = shouldBeObject(options);
10480
10648
 
10481
10649
  if (!isObject.res) {
10482
10650
  var _res5 = {
@@ -10510,7 +10678,6 @@ function showTabBar() {
10510
10678
  successHandler: successHandler(success, complete),
10511
10679
  errorHandler: errorHandler(success, complete)
10512
10680
  });
10513
- return successHandler(success, complete)(res);
10514
10681
  }
10515
10682
  /**
10516
10683
  * 隐藏 tabBar
@@ -10524,7 +10691,7 @@ function showTabBar() {
10524
10691
  function hideTabBar() {
10525
10692
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
10526
10693
  // options must be an Object
10527
- var isObject = shouleBeObject(options);
10694
+ var isObject = shouldBeObject(options);
10528
10695
 
10529
10696
  if (!isObject.res) {
10530
10697
  var _res6 = {
@@ -10558,7 +10725,6 @@ function hideTabBar() {
10558
10725
  successHandler: successHandler(success, complete),
10559
10726
  errorHandler: errorHandler(success, complete)
10560
10727
  });
10561
- return successHandler(success, complete)(res);
10562
10728
  }
10563
10729
  /**
10564
10730
  * 动态设置 tabBar 的整体样式
@@ -10575,7 +10741,7 @@ function hideTabBar() {
10575
10741
  function setTabBarStyle() {
10576
10742
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
10577
10743
  // options must be an Object
10578
- var isObject = shouleBeObject(options);
10744
+ var isObject = shouldBeObject(options);
10579
10745
 
10580
10746
  if (!isObject.res) {
10581
10747
  var _res7 = {
@@ -10616,17 +10782,14 @@ function setTabBarStyle() {
10616
10782
  res.errMsg = 'setTabBarStyle:fail';
10617
10783
  return Promise.reject(res);
10618
10784
  }
10619
-
10620
- var obj = {};
10621
- if (color) obj.color = color;
10622
- if (selectedColor) obj.selectedColor = selectedColor;
10623
- if (backgroundColor) obj.backgroundColor = backgroundColor;
10624
- if (borderStyle) obj.borderStyle = borderStyle;
10625
- var temp = Object.assign({}, tabConf, obj);
10626
- App.setState && App.setState({
10627
- __tabs: temp
10785
+ Taro.eventCenter.trigger('__taroSetTabBarStyle', {
10786
+ color: color,
10787
+ selectedColor: selectedColor,
10788
+ backgroundColor: backgroundColor,
10789
+ borderStyle: borderStyle,
10790
+ successHandler: successHandler(success, complete),
10791
+ errorHandler: errorHandler(success, complete)
10628
10792
  });
10629
- return successHandler(success, complete)(res);
10630
10793
  }
10631
10794
  /**
10632
10795
  * 动态设置 tabBar 某一项的内容
@@ -10643,7 +10806,7 @@ function setTabBarStyle() {
10643
10806
  function setTabBarItem() {
10644
10807
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
10645
10808
  // options must be an Object
10646
- var isObject = shouleBeObject(options);
10809
+ var isObject = shouldBeObject(options);
10647
10810
 
10648
10811
  if (!isObject.res) {
10649
10812
  var _res8 = {
@@ -10675,21 +10838,14 @@ function setTabBarItem() {
10675
10838
  return errorHandler(fail, complete)(res);
10676
10839
  }
10677
10840
 
10678
- if (!tabConf || !tabConf.list || !tabConf.list[index]) {
10679
- res.errMsg = 'setTabBarItem:fail tabbar item not found';
10680
- return errorHandler(fail, complete)(res);
10681
- }
10682
-
10683
- var obj = {};
10684
- if (text) obj.text = text;
10685
- if (iconPath) obj.iconPath = iconPath;
10686
- if (selectedIconPath) obj.selectedIconPath = selectedIconPath;
10687
- var temp = Object.assign({}, tabConf);
10688
- temp.list[index] = Object.assign({}, temp.list[index], obj);
10689
- App.setState && App.setState({
10690
- __tabs: temp
10841
+ Taro.eventCenter.trigger('__taroSetTabBarItem', {
10842
+ index: index,
10843
+ text: text,
10844
+ iconPath: iconPath,
10845
+ selectedIconPath: selectedIconPath,
10846
+ successHandler: successHandler(success, complete),
10847
+ errorHandler: errorHandler(success, complete)
10691
10848
  });
10692
- return successHandler(success, complete)(res);
10693
10849
  }
10694
10850
 
10695
10851
  var vibrator = function vibrator(mm) {
@@ -10769,7 +10925,7 @@ var vibrateLong = function vibrateLong() {
10769
10925
 
10770
10926
  function chooseVideo(options) {
10771
10927
  // options must be an Object
10772
- var isObject = shouleBeObject(options);
10928
+ var isObject = shouldBeObject(options);
10773
10929
 
10774
10930
  if (!isObject.res) {
10775
10931
  var _res = {
@@ -10968,7 +11124,7 @@ function connectSocket(options) {
10968
11124
  var name = 'connectSocket';
10969
11125
  return new Promise(function (resolve, reject) {
10970
11126
  // options must be an Object
10971
- var isObject = shouleBeObject(options);
11127
+ var isObject = shouldBeObject(options);
10972
11128
 
10973
11129
  if (!isObject.res) {
10974
11130
  var _res = {