@tarojs/taro-h5 3.3.12 → 3.3.16

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
  }));
@@ -1249,46 +1263,112 @@ function prependBasename() {
1249
1263
  return basename.replace(/\/$/, '') + '/' + url.replace(/^\//, '');
1250
1264
  }
1251
1265
 
1252
- var stacks = [];
1253
- var routesAlias = {};
1266
+ var hasBasename = function hasBasename(path, prefix) {
1267
+ return new RegExp('^' + prefix + '(\\/|\\?|#|$)', 'i').test(path);
1268
+ };
1254
1269
 
1255
- function setRoutesAlias(alias) {
1256
- routesAlias = alias;
1257
- }
1270
+ var stripBasename = function stripBasename(path, prefix) {
1271
+ return hasBasename(path, prefix) ? path.substr(prefix.length) : path;
1272
+ };
1258
1273
 
1259
- function addLeadingSlash(path) {
1260
- if (path == null) {
1261
- return '';
1274
+ var Stacks = /*#__PURE__*/function () {
1275
+ function Stacks() {
1276
+ _classCallCheck$1(this, Stacks);
1277
+
1278
+ this.stacks = [];
1279
+ this.backDelta = 0;
1262
1280
  }
1263
1281
 
1264
- return path.charAt(0) === '/' ? path : '/' + path;
1265
- } // 解决navigateBack调用delta>1时,路由栈异常问题
1266
- // 比如:A->B->C,navigateBack({delta: 2}),此时路由栈中还存在B页面
1267
- // 原因:主要是由于一次性退出多层级页面时,此action只会执行一次,此处进行手动处理
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: "getLastIndex",
1313
+ value: function getLastIndex(pathname) {
1314
+ var list = _toConsumableArray(this.stacks).reverse();
1268
1315
 
1316
+ return list.findIndex(function (page) {
1317
+ var _a;
1269
1318
 
1270
- var historyBackDelta = 1;
1319
+ return ((_a = page.path) === null || _a === void 0 ? void 0 : _a.replace(/\?.*/g, '')) === pathname;
1320
+ });
1321
+ }
1322
+ }, {
1323
+ key: "getDelta",
1324
+ value: function getDelta(pathname) {
1325
+ if (this.backDelta >= 1) {
1326
+ return this.backDelta;
1327
+ } // NOTE: 此处为了修复浏览器后退多级页面,在大量重复路由状况下可能出现判断错误的情况 (增强判断能力只能考虑在 query 中新增参数来判断,暂时搁置)
1271
1328
 
1272
- function setHistoryBackDelta(delta) {
1273
- historyBackDelta = delta;
1274
- } // eslint-disable-next-line @typescript-eslint/ban-types
1275
1329
 
1330
+ return this.getLastIndex(pathname) || 1;
1331
+ }
1332
+ }, {
1333
+ key: "getPrevIndex",
1334
+ value: function getPrevIndex(pathname) {
1335
+ var lastIndex = this.getLastIndex(pathname);
1276
1336
 
1277
- var throttle = function throttle(fn, threshold) {
1278
- var lastTime = 0;
1279
- return function () {
1280
- var now = Date.now();
1337
+ if (lastIndex < 0) {
1338
+ return -1;
1339
+ }
1281
1340
 
1282
- if (now - lastTime > threshold) {
1283
- fn.apply(this, arguments);
1284
- lastTime = now;
1341
+ return this.length - 1 - lastIndex;
1285
1342
  }
1286
- };
1287
- };
1343
+ }, {
1344
+ key: "pop",
1345
+ value: function pop() {
1346
+ return this.stacks.pop();
1347
+ }
1348
+ }, {
1349
+ key: "push",
1350
+ value: function push(page) {
1351
+ return this.stacks.push(page);
1352
+ }
1353
+ }]);
1288
1354
 
1289
- var stripBasename = function stripBasename(path, basename) {
1290
- return path.startsWith(basename) ? path.replace(basename, '') : path;
1291
- };
1355
+ return Stacks;
1356
+ }();
1357
+
1358
+ var stacks = new Stacks();
1359
+ var routesAlias = {};
1360
+
1361
+ function setRoutesAlias(alias) {
1362
+ routesAlias = alias;
1363
+ }
1364
+
1365
+ function addLeadingSlash(path) {
1366
+ if (path == null) {
1367
+ return '';
1368
+ }
1369
+
1370
+ return path.charAt(0) === '/' ? path : '/' + path;
1371
+ }
1292
1372
 
1293
1373
  var isTabBar = function isTabBar(config) {
1294
1374
  var _a, _b;
@@ -1312,13 +1392,29 @@ var isTabBar = function isTabBar(config) {
1312
1392
  };
1313
1393
 
1314
1394
  function processNavigateUrl(option) {
1395
+ var _a;
1396
+
1315
1397
  var pathPieces = J(option.url); // 处理自定义路由
1316
1398
 
1317
1399
  Object.keys(routesAlias).forEach(function (key) {
1318
1400
  if (addLeadingSlash(key) === addLeadingSlash(pathPieces.pathname)) {
1319
1401
  pathPieces.pathname = routesAlias[key];
1320
1402
  }
1321
- }); // 处理 basename
1403
+ }); // 处理相对路径
1404
+
1405
+ if ((_a = pathPieces === null || pathPieces === void 0 ? void 0 : pathPieces.pathname) === null || _a === void 0 ? void 0 : _a.includes('./')) {
1406
+ var parts = exports.history.location.pathname.split('/');
1407
+ parts.pop();
1408
+ pathPieces.pathname.split('/').forEach(function (item) {
1409
+ if (item === '.') {
1410
+ return;
1411
+ }
1412
+
1413
+ item === '..' ? parts.pop() : parts.push(item);
1414
+ });
1415
+ pathPieces.pathname = parts.join('/');
1416
+ } // 处理 basename
1417
+
1322
1418
 
1323
1419
  pathPieces.pathname = prependBasename(pathPieces.pathname); // hack fix history v5 bug: https://github.com/remix-run/history/issues/814
1324
1420
 
@@ -1326,47 +1422,58 @@ function processNavigateUrl(option) {
1326
1422
  return pathPieces;
1327
1423
  }
1328
1424
 
1329
- function navigate(option, method) {
1330
- var success = option.success,
1331
- complete = option.complete,
1332
- fail = option.fail;
1333
- var failReason;
1334
-
1335
- try {
1336
- if ('url' in option) {
1337
- var pathPieces = processNavigateUrl(option);
1338
- var state = {
1339
- timestamp: Date.now()
1340
- };
1425
+ function navigate(_x, _x2) {
1426
+ return _navigate.apply(this, arguments);
1427
+ }
1341
1428
 
1342
- if (method === 'navigateTo') {
1343
- exports.history.push(pathPieces, state);
1344
- } else if (method === 'redirectTo') {
1345
- exports.history.replace(pathPieces, state);
1346
- }
1347
- } else if (method === 'navigateBack') {
1348
- setHistoryBackDelta(option.delta);
1349
- exports.history.go(-option.delta);
1350
- }
1351
- } catch (error) {
1352
- failReason = error;
1353
- }
1429
+ function _navigate() {
1430
+ _navigate = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(option, method) {
1431
+ return regeneratorRuntime.wrap(function _callee2$(_context2) {
1432
+ while (1) {
1433
+ switch (_context2.prev = _context2.next) {
1434
+ case 0:
1435
+ return _context2.abrupt("return", new Promise(function (resolve, reject) {
1436
+ var success = option.success,
1437
+ complete = option.complete,
1438
+ fail = option.fail;
1439
+ var unListen = exports.history.listen(function () {
1440
+ success === null || success === void 0 ? void 0 : success();
1441
+ complete === null || complete === void 0 ? void 0 : complete();
1442
+ resolve();
1443
+ unListen();
1444
+ });
1354
1445
 
1355
- return new Promise(function (resolve, reject) {
1356
- if (failReason) {
1357
- fail && fail(failReason);
1358
- complete && complete();
1359
- reject(failReason);
1360
- return;
1361
- }
1446
+ try {
1447
+ if ('url' in option) {
1448
+ var pathPieces = processNavigateUrl(option);
1449
+ var state = {
1450
+ timestamp: Date.now()
1451
+ };
1452
+
1453
+ if (method === 'navigateTo') {
1454
+ exports.history.push(pathPieces, state);
1455
+ } else if (method === 'redirectTo') {
1456
+ exports.history.replace(pathPieces, state);
1457
+ }
1458
+ } else if (method === 'navigateBack') {
1459
+ stacks.delta = option.delta;
1460
+ exports.history.go(-option.delta);
1461
+ }
1462
+ } catch (error) {
1463
+ fail === null || fail === void 0 ? void 0 : fail(error);
1464
+ complete === null || complete === void 0 ? void 0 : complete();
1465
+ reject(error);
1466
+ }
1467
+ }));
1362
1468
 
1363
- var unlisten = exports.history.listen(function () {
1364
- success && success();
1365
- complete && complete();
1366
- resolve();
1367
- unlisten();
1368
- });
1369
- });
1469
+ case 1:
1470
+ case "end":
1471
+ return _context2.stop();
1472
+ }
1473
+ }
1474
+ }, _callee2);
1475
+ }));
1476
+ return _navigate.apply(this, arguments);
1370
1477
  }
1371
1478
 
1372
1479
  function navigateTo(option) {
@@ -1400,7 +1507,7 @@ function reLaunch(option) {
1400
1507
  }
1401
1508
 
1402
1509
  function getCurrentPages() {
1403
- return stacks;
1510
+ return stacks.get();
1404
1511
  }
1405
1512
  /**
1406
1513
  * Expose `pathToRegexp`.
@@ -2045,6 +2152,8 @@ var UniversalRouter = function () {
2045
2152
 
2046
2153
  UniversalRouter.pathToRegexp = pathToRegexp_1;
2047
2154
 
2155
+ var Taro$1 = require('@tarojs/taro-h5');
2156
+
2048
2157
  function initTabbar(config) {
2049
2158
  if (config.tabBar == null) {
2050
2159
  return;
@@ -2057,7 +2166,6 @@ function initTabbar(config) {
2057
2166
  tabbar.conf.homePage = exports.history.location.pathname === '/' ? homePage : exports.history.location.pathname;
2058
2167
  var routerConfig = config.router;
2059
2168
  tabbar.conf.mode = routerConfig && routerConfig.mode ? routerConfig.mode : 'hash';
2060
- tabbar.conf.custom = !!routerConfig.customRoutes;
2061
2169
 
2062
2170
  if (routerConfig.customRoutes) {
2063
2171
  tabbar.conf.custom = true;
@@ -2074,6 +2182,7 @@ function initTabbar(config) {
2074
2182
  var container = document.getElementById('container'); // eslint-disable-next-line no-unused-expressions
2075
2183
 
2076
2184
  container === null || container === void 0 ? void 0 : container.appendChild(tabbar);
2185
+ Taro$1.initTabBarApis(config);
2077
2186
  }
2078
2187
 
2079
2188
  var routerConfig = Object.create(null);
@@ -2099,6 +2208,64 @@ function init(config) {
2099
2208
  initTabbar(config);
2100
2209
  }
2101
2210
 
2211
+ var pageScrollFn;
2212
+ var pageDOM = window;
2213
+
2214
+ function bindPageScroll(page, config) {
2215
+ pageDOM.removeEventListener('scroll', pageScrollFn);
2216
+ pageDOM = getScrollContainer();
2217
+ var distance = config.onReachBottomDistance || 50;
2218
+ var isReachBottom = false;
2219
+
2220
+ pageScrollFn = function pageScrollFn() {
2221
+ page.onPageScroll && page.onPageScroll({
2222
+ scrollTop: pageDOM instanceof Window ? window.scrollY : pageDOM.scrollTop
2223
+ });
2224
+
2225
+ if (isReachBottom && getOffset() > distance) {
2226
+ isReachBottom = false;
2227
+ }
2228
+
2229
+ if (page.onReachBottom && !isReachBottom && getOffset() < distance) {
2230
+ isReachBottom = true;
2231
+ page.onReachBottom();
2232
+ }
2233
+ };
2234
+
2235
+ pageDOM.addEventListener('scroll', pageScrollFn, false);
2236
+ }
2237
+
2238
+ window.addEventListener('DOMSubtreeModified', function (e) {
2239
+ var _a; // @ts-ignore
2240
+
2241
+
2242
+ var className = (_a = e.target) === null || _a === void 0 ? void 0 : _a.className;
2243
+
2244
+ if (className && /taro-tabbar__/.test(className)) {
2245
+ pageDOM.removeEventListener('scroll', pageScrollFn);
2246
+ pageDOM = getScrollContainer();
2247
+ pageDOM.addEventListener('scroll', pageScrollFn, false);
2248
+ }
2249
+ }, false);
2250
+
2251
+ function getScrollContainer() {
2252
+ if (document.querySelector('.taro-tabbar__tabbar') === null) {
2253
+ // 没设置tabbar
2254
+ return window;
2255
+ } else {
2256
+ // 有设置tabbar
2257
+ return document.querySelector('.taro-tabbar__panel') || window;
2258
+ }
2259
+ }
2260
+
2261
+ function getOffset() {
2262
+ if (pageDOM instanceof Window) {
2263
+ return document.documentElement.scrollHeight - window.scrollY - window.innerHeight;
2264
+ } else {
2265
+ return pageDOM.scrollHeight - pageDOM.scrollTop - pageDOM.clientHeight;
2266
+ }
2267
+ }
2268
+
2102
2269
  function createCommonjsModule$1(fn, module) {
2103
2270
  return module = {
2104
2271
  exports: {}
@@ -2668,10 +2835,26 @@ var queryString_5 = queryString.stringifyUrl;
2668
2835
  var queryString_6 = queryString.pick;
2669
2836
  var queryString_7 = queryString.exclude;
2670
2837
 
2838
+ function getSearch() {
2839
+ var search = '?';
2840
+
2841
+ if (routerConfig.router.mode === 'hash') {
2842
+ var idx = location.hash.indexOf('?');
2843
+
2844
+ if (idx > -1) {
2845
+ search = location.hash.slice(idx);
2846
+ }
2847
+ } else {
2848
+ search = location.search;
2849
+ }
2850
+
2851
+ return search.substr(1);
2852
+ }
2853
+
2671
2854
  var qs = function qs() {
2672
2855
  var stamp = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
2673
- var search = routerConfig.router.mode === 'hash' ? location.hash.slice(routerConfig.router.pathname.length + 1) : location.search;
2674
- var query = search ? queryString.parse(search.substr(1)) : {};
2856
+ var search = getSearch();
2857
+ var query = search ? queryString.parse(search) : {};
2675
2858
 
2676
2859
  if (stamp) {
2677
2860
  query.stamp = stamp.toString();
@@ -2679,142 +2862,90 @@ var qs = function qs() {
2679
2862
 
2680
2863
  return query;
2681
2864
  };
2865
+ /* eslint-disable dot-notation */
2682
2866
 
2683
- var pageScrollFn;
2684
- var pageDOM = window;
2685
-
2686
- function bindPageScroll(page, config) {
2687
- pageDOM.removeEventListener('scroll', pageScrollFn);
2688
- pageDOM = getScrollContainer();
2689
- var distance = config.onReachBottomDistance || 50;
2690
- var isReachBottom = false;
2691
2867
 
2692
- pageScrollFn = function pageScrollFn() {
2693
- page.onPageScroll && page.onPageScroll({
2694
- scrollTop: pageDOM instanceof Window ? window.scrollY : pageDOM.scrollTop
2695
- });
2868
+ function pageOnReady(page) {
2869
+ var onLoad = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
2696
2870
 
2697
- if (isReachBottom && getOffset() > distance) {
2698
- isReachBottom = false;
2699
- }
2871
+ var _a, _b;
2700
2872
 
2701
- if (page.onReachBottom && !isReachBottom && getOffset() < distance) {
2702
- isReachBottom = true;
2703
- page.onReachBottom();
2704
- }
2705
- };
2873
+ var pageEl = document.getElementById(page.path);
2706
2874
 
2707
- pageDOM.addEventListener('scroll', pageScrollFn, false);
2875
+ if (pageEl && !(pageEl === null || pageEl === void 0 ? void 0 : pageEl['__isReady'])) {
2876
+ var el = pageEl.firstElementChild;
2877
+ (_b = (_a = el === null || el === void 0 ? void 0 : el['componentOnReady']) === null || _a === void 0 ? void 0 : _a.call(el)) === null || _b === void 0 ? void 0 : _b.then(function () {
2878
+ runtime.requestAnimationFrame(function () {
2879
+ page.onReady();
2880
+ pageEl['__isReady'] = true;
2881
+ });
2882
+ });
2883
+ onLoad && (pageEl['__page'] = page);
2884
+ }
2708
2885
  }
2709
2886
 
2710
- window.addEventListener('DOMSubtreeModified', function (e) {
2711
- var _a; // @ts-ignore
2712
-
2713
-
2714
- var className = (_a = e.target) === null || _a === void 0 ? void 0 : _a.className;
2715
-
2716
- if (className && /taro-tabbar__/.test(className)) {
2717
- pageDOM.removeEventListener('scroll', pageScrollFn);
2718
- pageDOM = getScrollContainer();
2719
- pageDOM.addEventListener('scroll', pageScrollFn, false);
2720
- }
2721
- }, false);
2887
+ function loadPage(page) {
2888
+ var pageConfig = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2889
+ var stacksIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
2890
+ if (!page) return;
2891
+ var pageEl = document.getElementById(page.path);
2722
2892
 
2723
- function getScrollContainer() {
2724
- if (document.querySelector('.taro-tabbar__tabbar') === null) {
2725
- // 没设置tabbar
2726
- return window;
2893
+ if (pageEl) {
2894
+ pageEl.style.display = 'block';
2727
2895
  } else {
2728
- // 有设置tabbar
2729
- return document.querySelector('.taro-tabbar__panel') || window;
2896
+ page.onLoad(qs(stacksIndex), function () {
2897
+ return pageOnReady(page, true);
2898
+ });
2730
2899
  }
2731
- }
2732
2900
 
2733
- function getOffset() {
2734
- if (pageDOM instanceof Window) {
2735
- return document.documentElement.scrollHeight - window.scrollY - window.innerHeight;
2736
- } else {
2737
- return pageDOM.scrollHeight - pageDOM.scrollTop - pageDOM.clientHeight;
2738
- }
2901
+ stacks.push(page);
2902
+ page.onShow();
2903
+ bindPageScroll(page, pageConfig);
2739
2904
  }
2740
- /* eslint-disable dot-notation */
2741
-
2742
-
2743
- function hidePage(page) {
2744
- if (page != null) {
2745
- page.onHide();
2746
- var pageEl = document.getElementById(page.path);
2747
2905
 
2748
- if (pageEl) {
2749
- pageEl.style.display = 'none';
2750
- }
2751
- }
2906
+ function unloadPage(page) {
2907
+ var delta = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
2908
+ if (!page) return;
2909
+ stacks.delta = --delta;
2910
+ stacks.pop();
2911
+ page.onUnload();
2912
+ if (delta >= 1) unloadPage(stacks.last, delta);
2752
2913
  }
2753
2914
 
2754
- function showPage(page, pageConfig) {
2915
+ function showPage(page) {
2916
+ var pageConfig = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2755
2917
  var stacksIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
2918
+ if (!page) return;
2919
+ page.onShow();
2920
+ var pageEl = document.getElementById(page.path);
2756
2921
 
2757
- if (page != null) {
2758
- page.onShow();
2759
- var pageEl = document.getElementById(page.path);
2760
-
2761
- if (pageEl) {
2762
- pageEl.style.display = 'block';
2763
- } else {
2764
- page.onLoad(qs(stacksIndex));
2765
- pageEl = document.getElementById(page.path);
2766
- pageOnReady(pageEl, page, false);
2767
- }
2768
-
2769
- bindPageScroll(page, pageConfig || {});
2922
+ if (pageEl) {
2923
+ pageEl.style.display = 'block';
2924
+ } else {
2925
+ page.onLoad(qs(stacksIndex), function () {
2926
+ return pageOnReady(page, false);
2927
+ });
2770
2928
  }
2771
- }
2772
2929
 
2773
- function unloadPage(page) {
2774
- if (page != null) {
2775
- stacks.pop();
2776
- page.onUnload();
2777
- }
2930
+ bindPageScroll(page, pageConfig);
2778
2931
  }
2779
2932
 
2780
- function pageOnReady(pageEl, page) {
2781
- var onLoad = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
2782
-
2783
- var _a;
2933
+ function hidePage(page) {
2934
+ if (!page) return; // NOTE: 修复多页并发问题,此处可能因为路由跳转过快,执行时页面可能还没有创建成功
2784
2935
 
2785
- if (pageEl && !(pageEl === null || pageEl === void 0 ? void 0 : pageEl['__isReady'])) {
2786
- var el = pageEl.firstElementChild; // eslint-disable-next-line no-unused-expressions
2936
+ var pageEl = document.getElementById(page.path);
2787
2937
 
2788
- (_a = el === null || el === void 0 ? void 0 : el['componentOnReady']) === null || _a === void 0 ? void 0 : _a.call(el).then(function () {
2789
- runtime.requestAnimationFrame(function () {
2790
- page.onReady();
2791
- pageEl['__isReady'] = true;
2792
- });
2793
- });
2794
- onLoad && (pageEl['__page'] = page);
2938
+ if (pageEl) {
2939
+ pageEl.style.display = 'none';
2940
+ page.onHide();
2941
+ } else {
2942
+ setTimeout(function () {
2943
+ return hidePage(page);
2944
+ }, 0);
2795
2945
  }
2796
2946
  }
2947
+ /* eslint-disable dot-notation */
2797
2948
 
2798
- function loadPage(page, pageConfig) {
2799
- var stacksIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
2800
-
2801
- if (page !== null) {
2802
- var pageEl = document.getElementById(page.path);
2803
-
2804
- if (pageEl) {
2805
- pageEl.style.display = 'block';
2806
- } else {
2807
- page.onLoad(qs(stacksIndex), function () {
2808
- pageEl = document.getElementById(page.path);
2809
- pageOnReady(pageEl, page);
2810
- });
2811
- }
2812
-
2813
- stacks.push(page);
2814
- page.onShow();
2815
- bindPageScroll(page, pageConfig || {});
2816
- }
2817
- }
2818
2949
 
2819
2950
  function createRouter(app, config, framework) {
2820
2951
  var _a;
@@ -2839,9 +2970,10 @@ function createRouter(app, config, framework) {
2839
2970
  baseUrl: basename || ''
2840
2971
  });
2841
2972
  app.onLaunch();
2842
- var render = throttle( /*#__PURE__*/function () {
2973
+
2974
+ var render = /*#__PURE__*/function () {
2843
2975
  var _ref4 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(_ref3) {
2844
- var location, action, _a, _b, _c, _d, element, pageConfig, enablePullDownRefresh, shouldLoad, delta, prevIndex, prev, pathname, _prevIndex, _prev, el, loadConfig, _pathname, routerIndex, page;
2976
+ var location, action, _a, _b, _c, _d, element, pageConfig, enablePullDownRefresh, currentPage, pathname, shouldLoad, prevIndex, delta, _prevIndex, el, loadConfig, stacksIndex, page;
2845
2977
 
2846
2978
  return regeneratorRuntime.wrap(function _callee$(_context) {
2847
2979
  while (1) {
@@ -2901,98 +3033,86 @@ function createRouter(app, config, framework) {
2901
3033
  enablePullDownRefresh = pageConfig.enablePullDownRefresh;
2902
3034
  }
2903
3035
 
3036
+ currentPage = runtime.Current.page;
3037
+ pathname = location.pathname;
2904
3038
  shouldLoad = false;
2905
3039
 
2906
3040
  if (!(action === 'POP')) {
2907
- _context.next = 32;
3041
+ _context.next = 31;
2908
3042
  break;
2909
3043
  }
2910
3044
 
2911
- unloadPage(runtime.Current.page);
2912
- delta = historyBackDelta;
2913
-
2914
- while (delta-- > 1) {
2915
- unloadPage(stacks.slice(-1)[0]);
2916
- } // 最终必须重置为 1
2917
-
3045
+ // NOTE: 浏览器事件退后多次时,该事件只会被触发一次
3046
+ prevIndex = stacks.getPrevIndex(pathname);
3047
+ delta = stacks.getDelta(pathname);
3048
+ unloadPage(currentPage, delta);
2918
3049
 
2919
- setHistoryBackDelta(1);
2920
- prevIndex = stacks.reduceRight(function (p, s, i) {
2921
- if (p !== 0) return p;else if (s.path === location.pathname + runtime.stringify(qs(i))) return i;else return 0;
2922
- }, 0);
2923
- prev = stacks[prevIndex];
2924
-
2925
- if (prev) {
2926
- showPage(prev, pageConfig, prevIndex);
3050
+ if (prevIndex > -1) {
3051
+ showPage(stacks.getItem(prevIndex), pageConfig, prevIndex);
2927
3052
  } else {
2928
3053
  shouldLoad = true;
2929
3054
  }
2930
3055
 
2931
- _context.next = 49;
3056
+ _context.next = 46;
2932
3057
  break;
2933
3058
 
2934
- case 32:
3059
+ case 31:
2935
3060
  if (!(action === 'PUSH')) {
2936
- _context.next = 37;
3061
+ _context.next = 36;
2937
3062
  break;
2938
3063
  }
2939
3064
 
2940
- hidePage(runtime.Current.page);
3065
+ hidePage(currentPage);
2941
3066
  shouldLoad = true;
2942
- _context.next = 49;
3067
+ _context.next = 46;
2943
3068
  break;
2944
3069
 
2945
- case 37:
3070
+ case 36:
2946
3071
  if (!(action === 'REPLACE')) {
2947
- _context.next = 49;
3072
+ _context.next = 46;
2948
3073
  break;
2949
3074
  }
2950
3075
 
2951
3076
  if (!isTabBar(config)) {
2952
- _context.next = 47;
3077
+ _context.next = 44;
2953
3078
  break;
2954
3079
  }
2955
3080
 
2956
- hidePage(runtime.Current.page);
2957
- pathname = stripBasename(config.router.pathname, basename);
2958
- _prevIndex = stacks.findIndex(function (r) {
2959
- var _a;
2960
-
2961
- return ((_a = r.path) === null || _a === void 0 ? void 0 : _a.replace(/\?.*/g, '')) === pathname;
2962
- });
3081
+ hidePage(currentPage);
3082
+ _prevIndex = stacks.getPrevIndex(pathname);
2963
3083
 
2964
3084
  if (!(_prevIndex > -1)) {
2965
- _context.next = 45;
3085
+ _context.next = 42;
2966
3086
  break;
2967
3087
  }
2968
3088
 
2969
- // tabbar 页且之前出现过,直接复用
2970
- _prev = stacks[_prevIndex];
2971
- return _context.abrupt("return", showPage(_prev, pageConfig, _prevIndex));
3089
+ return _context.abrupt("return", showPage(stacks.getItem(_prevIndex), pageConfig, _prevIndex));
2972
3090
 
2973
- case 45:
2974
- _context.next = 48;
3091
+ case 42:
3092
+ _context.next = 45;
2975
3093
  break;
2976
3094
 
2977
- case 47:
2978
- unloadPage(runtime.Current.page);
3095
+ case 44:
3096
+ unloadPage(currentPage);
2979
3097
 
2980
- case 48:
3098
+ case 45:
2981
3099
  shouldLoad = true;
2982
3100
 
2983
- case 49:
2984
- if (shouldLoad) {
2985
- el = (_c = element["default"]) !== null && _c !== void 0 ? _c : element;
2986
- loadConfig = Object.assign({}, pageConfig);
2987
- delete loadConfig['path'];
2988
- delete loadConfig['load'];
2989
- _pathname = stripBasename(config.router.pathname, basename);
2990
- routerIndex = stacks.length;
2991
- 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(routerIndex)), {}, loadConfig);
2992
- loadPage(page, pageConfig, routerIndex);
3101
+ case 46:
3102
+ if (!(shouldLoad || stacks.length < 1)) {
3103
+ _context.next = 54;
3104
+ break;
2993
3105
  }
2994
3106
 
2995
- case 50:
3107
+ el = (_c = element["default"]) !== null && _c !== void 0 ? _c : element;
3108
+ loadConfig = Object.assign({}, pageConfig);
3109
+ stacksIndex = stacks.length;
3110
+ delete loadConfig['path'];
3111
+ delete loadConfig['load'];
3112
+ 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);
3113
+ return _context.abrupt("return", loadPage(page, pageConfig, stacksIndex));
3114
+
3115
+ case 54:
2996
3116
  case "end":
2997
3117
  return _context.stop();
2998
3118
  }
@@ -3000,10 +3120,10 @@ function createRouter(app, config, framework) {
3000
3120
  }, _callee, null, [[2, 8]]);
3001
3121
  }));
3002
3122
 
3003
- return function (_x) {
3123
+ return function render(_x3) {
3004
3124
  return _ref4.apply(this, arguments);
3005
3125
  };
3006
- }(), 500);
3126
+ }();
3007
3127
 
3008
3128
  if (exports.history.location.pathname === '/') {
3009
3129
  exports.history.replace(prependBasename(routes[0].path + exports.history.location.search));
@@ -3017,7 +3137,7 @@ function createRouter(app, config, framework) {
3017
3137
  return exports.history.listen(render);
3018
3138
  }
3019
3139
 
3020
- function shouleBeObject(target) {
3140
+ function shouldBeObject(target) {
3021
3141
  if (target && _typeof$1(target) === 'object') return {
3022
3142
  res: true
3023
3143
  };
@@ -3355,7 +3475,7 @@ var initPxTransform = getInitPxTransform$1(taro);
3355
3475
  var requirePlugin = permanentlyNotSupport('requirePlugin');
3356
3476
 
3357
3477
  var getApp = function getApp() {
3358
- return taro._$app;
3478
+ return getCurrentInstance().app;
3359
3479
  };
3360
3480
 
3361
3481
  var pxTransform = function pxTransform(size) {
@@ -4375,7 +4495,7 @@ var createCanvasContext = function createCanvasContext(canvasId, inst) {
4375
4495
 
4376
4496
  function setStorage(options) {
4377
4497
  // options must be an Object
4378
- var isObject = shouleBeObject(options);
4498
+ var isObject = shouldBeObject(options);
4379
4499
 
4380
4500
  if (!isObject.res) {
4381
4501
  var _res = {
@@ -4444,7 +4564,7 @@ function setStorageSync(key) {
4444
4564
 
4445
4565
  function getStorage(options) {
4446
4566
  // options must be an Object
4447
- var isObject = shouleBeObject(options);
4567
+ var isObject = shouldBeObject(options);
4448
4568
 
4449
4569
  if (!isObject.res) {
4450
4570
  var _res2 = {
@@ -4552,7 +4672,7 @@ function getStorageInfoSync() {
4552
4672
 
4553
4673
  function removeStorage(options) {
4554
4674
  // options must be an Object
4555
- var isObject = shouleBeObject(options);
4675
+ var isObject = shouldBeObject(options);
4556
4676
 
4557
4677
  if (!isObject.res) {
4558
4678
  var _res3 = {
@@ -6119,7 +6239,7 @@ var uploadFile = function uploadFile(_ref2) {
6119
6239
 
6120
6240
  var chooseImage = function chooseImage(options) {
6121
6241
  // options must be an Object
6122
- var isObject = shouleBeObject(options);
6242
+ var isObject = shouldBeObject(options);
6123
6243
 
6124
6244
  if (!isObject.res) {
6125
6245
  var _res = {
@@ -6370,11 +6490,14 @@ function _previewImage() {
6370
6490
  function loadImage(url, fail) {
6371
6491
  return new Promise(function (resolve) {
6372
6492
  var item = document.createElement('taro-swiper-item-core');
6373
- item.style.cssText = "\n display: flex;\n align-items: center;\n justify-content: center;\n ";
6493
+ item.style.cssText = "\n display: flex;\n align-items: start;\n justify-content: center;\n overflow-y: scroll;\n ";
6374
6494
  var image = new Image();
6375
6495
  image.style.maxWidth = '100%';
6376
6496
  image.src = url;
6377
- item.appendChild(image); // Note: 等待图片加载完后返回,会导致轮播被卡住
6497
+ var div = document.createElement('div');
6498
+ div.style.cssText = "\n display: flex;\n align-items: center;\n justify-content: center;\n max-width: 100%;\n min-height: 100%;\n ";
6499
+ div.appendChild(image);
6500
+ item.appendChild(div); // Note: 等待图片加载完后返回,会导致轮播被卡住
6378
6501
 
6379
6502
  resolve(item);
6380
6503
 
@@ -7558,7 +7681,7 @@ var openLocation = processOpenapi('openLocation', {
7558
7681
 
7559
7682
  function setNavigationBarTitle(options) {
7560
7683
  // options must be an Object
7561
- var isObject = shouleBeObject(options);
7684
+ var isObject = shouldBeObject(options);
7562
7685
 
7563
7686
  if (!isObject.res) {
7564
7687
  var _res = {
@@ -7742,7 +7865,7 @@ function base64ToArrayBuffer(base64) {
7742
7865
  }
7743
7866
  function makePhoneCall(options) {
7744
7867
  // options must be an Object
7745
- var isObject = shouleBeObject(options);
7868
+ var isObject = shouldBeObject(options);
7746
7869
 
7747
7870
  if (!isObject.res) {
7748
7871
  var _res = {
@@ -10315,12 +10438,9 @@ var scanCode = processOpenapi('scanQRCode', {
10315
10438
  });
10316
10439
 
10317
10440
  var tabConf;
10318
- var App;
10319
10441
  function initTabBarApis() {
10320
- var _App = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
10321
-
10322
- tabConf = _App.state.__tabs;
10323
- App = _App;
10442
+ var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
10443
+ tabConf = config.tabBar;
10324
10444
  }
10325
10445
  /**
10326
10446
  * 为 tabBar 某一项的右上角添加文本
@@ -10335,7 +10455,7 @@ function initTabBarApis() {
10335
10455
  function setTabBarBadge() {
10336
10456
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
10337
10457
  // options must be an Object
10338
- var isObject = shouleBeObject(options);
10458
+ var isObject = shouldBeObject(options);
10339
10459
 
10340
10460
  if (!isObject.res) {
10341
10461
  var _res = {
@@ -10382,7 +10502,6 @@ function setTabBarBadge() {
10382
10502
  successHandler: successHandler(success, complete),
10383
10503
  errorHandler: errorHandler(fail, complete)
10384
10504
  });
10385
- return successHandler(success, complete)(res);
10386
10505
  }
10387
10506
  /**
10388
10507
  * 移除 tabBar 某一项右上角的文本
@@ -10396,7 +10515,7 @@ function setTabBarBadge() {
10396
10515
  function removeTabBarBadge() {
10397
10516
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
10398
10517
  // options must be an Object
10399
- var isObject = shouleBeObject(options);
10518
+ var isObject = shouldBeObject(options);
10400
10519
 
10401
10520
  if (!isObject.res) {
10402
10521
  var _res2 = {
@@ -10430,7 +10549,6 @@ function removeTabBarBadge() {
10430
10549
  successHandler: successHandler(success, complete),
10431
10550
  errorHandler: errorHandler(fail, complete)
10432
10551
  });
10433
- return successHandler(success, complete)(res);
10434
10552
  }
10435
10553
  /**
10436
10554
  * 显示 tabBar 某一项的右上角的红点
@@ -10444,7 +10562,7 @@ function removeTabBarBadge() {
10444
10562
  function showTabBarRedDot() {
10445
10563
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
10446
10564
  // options must be an Object
10447
- var isObject = shouleBeObject(options);
10565
+ var isObject = shouldBeObject(options);
10448
10566
 
10449
10567
  if (!isObject.res) {
10450
10568
  var _res3 = {
@@ -10478,7 +10596,6 @@ function showTabBarRedDot() {
10478
10596
  successHandler: successHandler(success, complete),
10479
10597
  errorHandler: errorHandler(fail, complete)
10480
10598
  });
10481
- return successHandler(success, complete)(res);
10482
10599
  }
10483
10600
  /**
10484
10601
  * 隐藏 tabBar 某一项的右上角的红点
@@ -10492,7 +10609,7 @@ function showTabBarRedDot() {
10492
10609
  function hideTabBarRedDot() {
10493
10610
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
10494
10611
  // options must be an Object
10495
- var isObject = shouleBeObject(options);
10612
+ var isObject = shouldBeObject(options);
10496
10613
 
10497
10614
  if (!isObject.res) {
10498
10615
  var _res4 = {
@@ -10526,7 +10643,6 @@ function hideTabBarRedDot() {
10526
10643
  successHandler: successHandler(success, complete),
10527
10644
  errorHandler: errorHandler(fail, complete)
10528
10645
  });
10529
- return successHandler(success, complete)(res);
10530
10646
  }
10531
10647
  /**
10532
10648
  * 显示 tabBar
@@ -10540,7 +10656,7 @@ function hideTabBarRedDot() {
10540
10656
  function showTabBar() {
10541
10657
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
10542
10658
  // options must be an Object
10543
- var isObject = shouleBeObject(options);
10659
+ var isObject = shouldBeObject(options);
10544
10660
 
10545
10661
  if (!isObject.res) {
10546
10662
  var _res5 = {
@@ -10574,7 +10690,6 @@ function showTabBar() {
10574
10690
  successHandler: successHandler(success, complete),
10575
10691
  errorHandler: errorHandler(success, complete)
10576
10692
  });
10577
- return successHandler(success, complete)(res);
10578
10693
  }
10579
10694
  /**
10580
10695
  * 隐藏 tabBar
@@ -10588,7 +10703,7 @@ function showTabBar() {
10588
10703
  function hideTabBar() {
10589
10704
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
10590
10705
  // options must be an Object
10591
- var isObject = shouleBeObject(options);
10706
+ var isObject = shouldBeObject(options);
10592
10707
 
10593
10708
  if (!isObject.res) {
10594
10709
  var _res6 = {
@@ -10622,7 +10737,6 @@ function hideTabBar() {
10622
10737
  successHandler: successHandler(success, complete),
10623
10738
  errorHandler: errorHandler(success, complete)
10624
10739
  });
10625
- return successHandler(success, complete)(res);
10626
10740
  }
10627
10741
  /**
10628
10742
  * 动态设置 tabBar 的整体样式
@@ -10639,7 +10753,7 @@ function hideTabBar() {
10639
10753
  function setTabBarStyle() {
10640
10754
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
10641
10755
  // options must be an Object
10642
- var isObject = shouleBeObject(options);
10756
+ var isObject = shouldBeObject(options);
10643
10757
 
10644
10758
  if (!isObject.res) {
10645
10759
  var _res7 = {
@@ -10680,17 +10794,14 @@ function setTabBarStyle() {
10680
10794
  res.errMsg = 'setTabBarStyle:fail';
10681
10795
  return Promise.reject(res);
10682
10796
  }
10683
-
10684
- var obj = {};
10685
- if (color) obj.color = color;
10686
- if (selectedColor) obj.selectedColor = selectedColor;
10687
- if (backgroundColor) obj.backgroundColor = backgroundColor;
10688
- if (borderStyle) obj.borderStyle = borderStyle;
10689
- var temp = Object.assign({}, tabConf, obj);
10690
- App.setState && App.setState({
10691
- __tabs: temp
10797
+ Taro.eventCenter.trigger('__taroSetTabBarStyle', {
10798
+ color: color,
10799
+ selectedColor: selectedColor,
10800
+ backgroundColor: backgroundColor,
10801
+ borderStyle: borderStyle,
10802
+ successHandler: successHandler(success, complete),
10803
+ errorHandler: errorHandler(success, complete)
10692
10804
  });
10693
- return successHandler(success, complete)(res);
10694
10805
  }
10695
10806
  /**
10696
10807
  * 动态设置 tabBar 某一项的内容
@@ -10707,7 +10818,7 @@ function setTabBarStyle() {
10707
10818
  function setTabBarItem() {
10708
10819
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
10709
10820
  // options must be an Object
10710
- var isObject = shouleBeObject(options);
10821
+ var isObject = shouldBeObject(options);
10711
10822
 
10712
10823
  if (!isObject.res) {
10713
10824
  var _res8 = {
@@ -10739,21 +10850,14 @@ function setTabBarItem() {
10739
10850
  return errorHandler(fail, complete)(res);
10740
10851
  }
10741
10852
 
10742
- if (!tabConf || !tabConf.list || !tabConf.list[index]) {
10743
- res.errMsg = 'setTabBarItem:fail tabbar item not found';
10744
- return errorHandler(fail, complete)(res);
10745
- }
10746
-
10747
- var obj = {};
10748
- if (text) obj.text = text;
10749
- if (iconPath) obj.iconPath = iconPath;
10750
- if (selectedIconPath) obj.selectedIconPath = selectedIconPath;
10751
- var temp = Object.assign({}, tabConf);
10752
- temp.list[index] = Object.assign({}, temp.list[index], obj);
10753
- App.setState && App.setState({
10754
- __tabs: temp
10853
+ Taro.eventCenter.trigger('__taroSetTabBarItem', {
10854
+ index: index,
10855
+ text: text,
10856
+ iconPath: iconPath,
10857
+ selectedIconPath: selectedIconPath,
10858
+ successHandler: successHandler(success, complete),
10859
+ errorHandler: errorHandler(success, complete)
10755
10860
  });
10756
- return successHandler(success, complete)(res);
10757
10861
  }
10758
10862
 
10759
10863
  var vibrator = function vibrator(mm) {
@@ -10833,7 +10937,7 @@ var vibrateLong = function vibrateLong() {
10833
10937
 
10834
10938
  function chooseVideo(options) {
10835
10939
  // options must be an Object
10836
- var isObject = shouleBeObject(options);
10940
+ var isObject = shouldBeObject(options);
10837
10941
 
10838
10942
  if (!isObject.res) {
10839
10943
  var _res = {
@@ -11032,7 +11136,7 @@ function connectSocket(options) {
11032
11136
  var name = 'connectSocket';
11033
11137
  return new Promise(function (resolve, reject) {
11034
11138
  // options must be an Object
11035
- var isObject = shouleBeObject(options);
11139
+ var isObject = shouldBeObject(options);
11036
11140
 
11037
11141
  if (!isObject.res) {
11038
11142
  var _res = {