@tarojs/taro-h5 3.5.10 → 3.5.12

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
@@ -4,6 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var Taro = require('@tarojs/api');
6
6
  var router = require('@tarojs/router');
7
+ var utils = require('@tarojs/router/dist/utils');
7
8
  var runtime = require('@tarojs/runtime');
8
9
  var base64Js = require('base64-js');
9
10
  var navigate = require('@tarojs/router/dist/utils/navigate');
@@ -13,6 +14,24 @@ var jsonpRetry = require('jsonp-retry');
13
14
 
14
15
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
15
16
 
17
+ function _interopNamespace(e) {
18
+ if (e && e.__esModule) return e;
19
+ var n = Object.create(null);
20
+ if (e) {
21
+ Object.keys(e).forEach(function (k) {
22
+ if (k !== 'default') {
23
+ var d = Object.getOwnPropertyDescriptor(e, k);
24
+ Object.defineProperty(n, k, d.get ? d : {
25
+ enumerable: true,
26
+ get: function () { return e[k]; }
27
+ });
28
+ }
29
+ });
30
+ }
31
+ n["default"] = e;
32
+ return Object.freeze(n);
33
+ }
34
+
16
35
  var Taro__default = /*#__PURE__*/_interopDefaultLegacy(Taro);
17
36
  var jsonpRetry__default = /*#__PURE__*/_interopDefaultLegacy(jsonpRetry);
18
37
 
@@ -195,6 +214,9 @@ function upperCaseFirstLetter(string) {
195
214
  string = string.replace(/^./, match => match.toUpperCase());
196
215
  return string;
197
216
  }
217
+ const toKebabCase = function (string) {
218
+ return string.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
219
+ };
198
220
  function inlineStyle(style) {
199
221
  let res = '';
200
222
  for (const attr in style)
@@ -311,6 +333,30 @@ function processOpenApi({ name, defaultOptions, standardMethod, formatOptions =
311
333
  }
312
334
  };
313
335
  }
336
+ /**
337
+ * 根据url获取应用的启动页面
338
+ * @returns
339
+ */
340
+ function getLaunchPage() {
341
+ var _a, _b, _c, _d, _e, _f, _g;
342
+ const appConfig = window.__taroAppConfig || {};
343
+ // createPageConfig时根据stack的长度来设置stamp以保证页面path的唯一,此函数是在createPageConfig之前调用,预先设置stamp=1
344
+ const stamp = '?stamp=1';
345
+ let entryPath = '';
346
+ if (((_a = appConfig.router) === null || _a === void 0 ? void 0 : _a.mode) === 'browser' || ((_b = appConfig.router) === null || _b === void 0 ? void 0 : _b.mode) === 'multi') {
347
+ entryPath = location.pathname;
348
+ }
349
+ else {
350
+ entryPath = location.hash.slice(1).split('?')[0];
351
+ }
352
+ const routePath = utils.addLeadingSlash(utils.stripBasename(entryPath, (_c = appConfig.router) === null || _c === void 0 ? void 0 : _c.basename));
353
+ const homePath = utils.addLeadingSlash(utils.getHomePage((_e = (_d = appConfig.routes) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.path, (_f = appConfig.router) === null || _f === void 0 ? void 0 : _f.basename, (_g = appConfig.router) === null || _g === void 0 ? void 0 : _g.customRoutes, appConfig.entryPagePath));
354
+ // url上没有指定应用的启动页面时使用homePath
355
+ if (routePath === '/') {
356
+ return homePath + stamp;
357
+ }
358
+ return routePath + stamp;
359
+ }
314
360
 
315
361
  // 广告
316
362
  const createRewardedVideoAd = temporarilyNotSupport('createRewardedVideoAd');
@@ -611,6 +657,8 @@ const getDeviceInfo = () => {
611
657
  const info = {
612
658
  /** 应用二进制接口类型(仅 Android 支持) */
613
659
  abi: '',
660
+ /** 设备二进制接口类型(仅 Android 支持) */
661
+ deviceAbi: '',
614
662
  /** 设备性能等级(仅Android小游戏)。取值为:-2 或 0(该设备无法运行小游戏),-1(性能未知),>=1(设备性能值,该值越高,设备性能越好,目前最高不到50) */
615
663
  benchmarkLevel: -1,
616
664
  /** 设备品牌 */
@@ -620,7 +668,9 @@ const getDeviceInfo = () => {
620
668
  /** 操作系统及版本 */
621
669
  system: md.os(),
622
670
  /** 客户端平台 */
623
- platform: navigator.platform
671
+ platform: navigator.platform,
672
+ /** 设备二进制接口类型(仅 Android 支持) */
673
+ CPUType: '',
624
674
  };
625
675
  return info;
626
676
  };
@@ -3926,6 +3976,7 @@ class Modal {
3926
3976
  }
3927
3977
  create(options = {}) {
3928
3978
  return new Promise((resolve) => {
3979
+ var _a, _b;
3929
3980
  // style
3930
3981
  const { maskStyle, modalStyle, titleStyle, textStyle, footStyle, btnStyle } = this.style;
3931
3982
  // configuration
@@ -3990,10 +4041,13 @@ class Modal {
3990
4041
  // show immediately
3991
4042
  document.body.appendChild(this.el);
3992
4043
  setTimeout(() => { this.el.style.opacity = '1'; }, 0);
4044
+ // Current.page不存在时说明路由还未挂载,此时需根据url来分配将要渲染的页面path
4045
+ this.currentPath = (_b = (_a = runtime.Current.page) === null || _a === void 0 ? void 0 : _a.path) !== null && _b !== void 0 ? _b : getLaunchPage();
3993
4046
  });
3994
4047
  }
3995
4048
  show(options = {}) {
3996
4049
  return new Promise((resolve) => {
4050
+ var _a, _b;
3997
4051
  const config = Object.assign(Object.assign({}, this.options), options);
3998
4052
  if (this.hideOpacityTimer)
3999
4053
  clearTimeout(this.hideOpacityTimer);
@@ -4037,6 +4091,8 @@ class Modal {
4037
4091
  // show
4038
4092
  this.el.style.display = 'block';
4039
4093
  setTimeout(() => { this.el.style.opacity = '1'; }, 0);
4094
+ // Current.page不存在时说明路由还未挂载,此时需根据url来分配将要渲染的页面path
4095
+ this.currentPath = (_b = (_a = runtime.Current.page) === null || _a === void 0 ? void 0 : _a.path) !== null && _b !== void 0 ? _b : getLaunchPage();
4040
4096
  });
4041
4097
  }
4042
4098
  hide() {
@@ -4044,6 +4100,7 @@ class Modal {
4044
4100
  clearTimeout(this.hideOpacityTimer);
4045
4101
  if (this.hideDisplayTimer)
4046
4102
  clearTimeout(this.hideDisplayTimer);
4103
+ this.currentPath = null;
4047
4104
  this.hideOpacityTimer = setTimeout(() => {
4048
4105
  this.el.style.opacity = '0';
4049
4106
  this.hideDisplayTimer = setTimeout(() => { this.el.style.display = 'none'; }, 200);
@@ -4127,6 +4184,7 @@ class Toast {
4127
4184
  };
4128
4185
  }
4129
4186
  create(options = {}, _type = 'toast') {
4187
+ var _a, _b;
4130
4188
  // style
4131
4189
  const { maskStyle, toastStyle, successStyle, errrorStyle, loadingStyle, imageStyle, textStyle } = this.style;
4132
4190
  // configuration
@@ -4170,9 +4228,12 @@ class Toast {
4170
4228
  this.type = config._type;
4171
4229
  // disappear after duration
4172
4230
  config.duration >= 0 && this.hide(config.duration, this.type);
4231
+ // Current.page不存在时说明路由还未挂载,此时需根据url来分配将要渲染的页面path
4232
+ this.currentPath = (_b = (_a = runtime.Current.page) === null || _a === void 0 ? void 0 : _a.path) !== null && _b !== void 0 ? _b : getLaunchPage();
4173
4233
  return '';
4174
4234
  }
4175
4235
  show(options = {}, _type = 'toast') {
4236
+ var _a, _b;
4176
4237
  const config = Object.assign(Object.assign(Object.assign({}, this.options), options), { _type });
4177
4238
  if (this.hideOpacityTimer)
4178
4239
  clearTimeout(this.hideOpacityTimer);
@@ -4204,6 +4265,8 @@ class Toast {
4204
4265
  this.type = config._type;
4205
4266
  // disappear after duration
4206
4267
  config.duration >= 0 && this.hide(config.duration, this.type);
4268
+ // Current.page不存在时说明路由还未挂载,此时需根据url来分配将要渲染的页面path
4269
+ this.currentPath = (_b = (_a = runtime.Current.page) === null || _a === void 0 ? void 0 : _a.path) !== null && _b !== void 0 ? _b : getLaunchPage();
4207
4270
  return '';
4208
4271
  }
4209
4272
  hide(duration = 0, type) {
@@ -4213,6 +4276,7 @@ class Toast {
4213
4276
  clearTimeout(this.hideOpacityTimer);
4214
4277
  if (this.hideDisplayTimer)
4215
4278
  clearTimeout(this.hideDisplayTimer);
4279
+ this.currentPath = null;
4216
4280
  this.hideOpacityTimer = setTimeout(() => {
4217
4281
  this.el.style.opacity = '0';
4218
4282
  this.hideDisplayTimer = setTimeout(() => { this.el.style.display = 'none'; }, 100);
@@ -4474,10 +4538,15 @@ const showActionSheet = (options = { itemList: [] }) => __awaiter(void 0, void 0
4474
4538
  return handle.success(({ tapIndex: result }));
4475
4539
  }
4476
4540
  });
4477
- Taro__default["default"].eventCenter.on('__taroRouterChange', () => {
4478
- hideToast();
4479
- hideLoading();
4480
- hideModal();
4541
+ Taro__default["default"].eventCenter.on('__afterTaroRouterChange', () => {
4542
+ var _a, _b;
4543
+ if (toast.currentPath && toast.currentPath !== ((_a = runtime.Current.page) === null || _a === void 0 ? void 0 : _a.path)) {
4544
+ hideToast();
4545
+ hideLoading();
4546
+ }
4547
+ if (modal.currentPath && modal.currentPath !== ((_b = runtime.Current.page) === null || _b === void 0 ? void 0 : _b.path)) {
4548
+ hideModal();
4549
+ }
4481
4550
  });
4482
4551
  const enableAlertBeforeUnload = temporarilyNotSupport('enableAlertBeforeUnload');
4483
4552
  const disableAlertBeforeUnload = temporarilyNotSupport('disableAlertBeforeUnload');
@@ -4946,6 +5015,159 @@ const offWindowResize = callback => {
4946
5015
  // Worker
4947
5016
  const createWorker = temporarilyNotSupport('createWorker');
4948
5017
 
5018
+ // pollify
5019
+ Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('intersection-observer')); });
5020
+ class TaroH5IntersectionObserver {
5021
+ constructor(component, options = {}) {
5022
+ // 选项
5023
+ this._options = {
5024
+ thresholds: [0],
5025
+ initialRatio: 0,
5026
+ observeAll: false
5027
+ };
5028
+ // 监控中的选择器
5029
+ this._listeners = [];
5030
+ // 用来扩展(或收缩)参照节点布局区域的边界
5031
+ this._rootMargin = {};
5032
+ // 是否已初始化
5033
+ this._isInited = false;
5034
+ this._component = component;
5035
+ Object.assign(this._options, options);
5036
+ }
5037
+ // selector 的容器节点
5038
+ get container() {
5039
+ const container = (this._component !== null
5040
+ ? (findDOM(this._component) || document)
5041
+ : document);
5042
+ return container;
5043
+ }
5044
+ createInst() {
5045
+ // 去除原本的实例
5046
+ this.disconnect();
5047
+ const { left = 0, top = 0, bottom = 0, right = 0 } = this._rootMargin;
5048
+ return new IntersectionObserver(entries => {
5049
+ entries.forEach(entry => {
5050
+ const _callback = this._getCallbackByElement(entry.target);
5051
+ const result = {
5052
+ boundingClientRect: entry.boundingClientRect,
5053
+ intersectionRatio: entry.intersectionRatio,
5054
+ intersectionRect: entry.intersectionRect,
5055
+ relativeRect: entry.rootBounds || { left: 0, right: 0, top: 0, bottom: 0 },
5056
+ time: entry.time
5057
+ };
5058
+ // web端会默认首次触发
5059
+ if (!this._isInited && this._options.initialRatio <= Math.min.apply(Math, this._options.thresholds)) {
5060
+ // 初始的相交比例,如果调用时检测到的相交比例与这个值不相等且达到阈值,则会触发一次监听器的回调函数。
5061
+ return;
5062
+ }
5063
+ _callback && _callback.call(this, result);
5064
+ });
5065
+ this._isInited = true;
5066
+ }, {
5067
+ root: this._root,
5068
+ rootMargin: [`${top}px`, `${right}px`, `${bottom}px`, `${left}px`].join(' '),
5069
+ threshold: this._options.thresholds
5070
+ });
5071
+ }
5072
+ disconnect() {
5073
+ if (this._observerInst) {
5074
+ let listener;
5075
+ while ((listener = this._listeners.pop())) {
5076
+ this._observerInst.unobserve(listener.element);
5077
+ }
5078
+ this._observerInst.disconnect();
5079
+ }
5080
+ }
5081
+ observe(targetSelector, callback) {
5082
+ // 同wx小程序效果一致,每个实例监听一个Selector
5083
+ if (this._listeners.length)
5084
+ return;
5085
+ // 监听前没有设置关联的节点
5086
+ if (!this._observerInst) {
5087
+ console.warn('Intersection observer will be ignored because no relative nodes are found.');
5088
+ return;
5089
+ }
5090
+ const nodeList = this._options.observeAll
5091
+ ? this.container.querySelectorAll(targetSelector)
5092
+ : [this.container.querySelector(targetSelector)];
5093
+ nodeList.forEach(element => {
5094
+ if (!element)
5095
+ return;
5096
+ this._observerInst.observe(element);
5097
+ this._listeners.push({ element, callback });
5098
+ });
5099
+ }
5100
+ relativeTo(selector, margins) {
5101
+ // 已设置observe监听后,重新关联节点
5102
+ if (this._listeners.length) {
5103
+ console.error('Relative nodes cannot be added after "observe" call in IntersectionObserver');
5104
+ return this;
5105
+ }
5106
+ this._root = this.container.querySelector(selector) || null;
5107
+ if (margins) {
5108
+ this._rootMargin = margins;
5109
+ }
5110
+ this._observerInst = this.createInst();
5111
+ return this;
5112
+ }
5113
+ relativeToViewport(margins) {
5114
+ return this.relativeTo('.taro_page', margins);
5115
+ }
5116
+ _getCallbackByElement(element) {
5117
+ const listener = this._listeners.find(listener => listener.element === element);
5118
+ return listener ? listener.callback : null;
5119
+ }
5120
+ }
5121
+
5122
+ function generateMediaQueryStr(descriptor) {
5123
+ const mediaQueryArr = [];
5124
+ const descriptorMenu = ['width', 'minWidth', 'maxWidth', 'height', 'minHeight', 'maxHeight', 'orientation'];
5125
+ for (const item of descriptorMenu) {
5126
+ if (item !== 'orientation' &&
5127
+ descriptor[item] &&
5128
+ Number(descriptor[item]) >= 0) {
5129
+ mediaQueryArr.push(`(${(toKebabCase(item))}: ${Number(descriptor[item])}px)`);
5130
+ }
5131
+ if (item === 'orientation' && descriptor[item]) {
5132
+ mediaQueryArr.push(`(${toKebabCase(item)}: ${descriptor[item]})`);
5133
+ }
5134
+ }
5135
+ return mediaQueryArr.join(' and ');
5136
+ }
5137
+ class MediaQueryObserver {
5138
+ // 监听页面媒体查询变化情况
5139
+ observe(descriptor, callback) {
5140
+ if (isFunction(callback)) {
5141
+ // 创建媒体查询对象
5142
+ this._mediaQueryObserver = window.matchMedia(generateMediaQueryStr(descriptor));
5143
+ // 监听器
5144
+ this._listener = (ev) => {
5145
+ callback({ matches: ev.matches });
5146
+ };
5147
+ callback({ matches: this._mediaQueryObserver.matches });
5148
+ // 兼容旧浏览器中MediaQueryList尚未继承于EventTarget导致不存在'addEventListener'
5149
+ if ('addEventListener' in this._mediaQueryObserver) {
5150
+ this._mediaQueryObserver.addEventListener('change', this._listener);
5151
+ }
5152
+ else {
5153
+ this._mediaQueryObserver.addListener(this._listener);
5154
+ }
5155
+ }
5156
+ }
5157
+ // 停止监听,销毁媒体查询对象
5158
+ disconnect() {
5159
+ if (this._mediaQueryObserver && this._listener) {
5160
+ // 兼容旧浏览器中MediaQueryList尚未继承于EventTarget导致不存在'removeEventListener'
5161
+ if ('removeEventListener' in this._mediaQueryObserver) {
5162
+ this._mediaQueryObserver.removeEventListener('change', this._listener);
5163
+ }
5164
+ else {
5165
+ this._mediaQueryObserver.removeListener(this._listener);
5166
+ }
5167
+ }
5168
+ }
5169
+ }
5170
+
4949
5171
  class NodesRef {
4950
5172
  constructor(selector, querySelectorQuery, single) {
4951
5173
  this._component = querySelectorQuery._component;
@@ -5191,7 +5413,12 @@ class SelectorQuery {
5191
5413
  const createSelectorQuery = () => {
5192
5414
  return new SelectorQuery();
5193
5415
  };
5194
- const createIntersectionObserver = temporarilyNotSupport('createIntersectionObserver');
5416
+ const createIntersectionObserver = (component, options) => {
5417
+ return new TaroH5IntersectionObserver(component, options);
5418
+ };
5419
+ const createMediaQueryObserver = () => {
5420
+ return new MediaQueryObserver();
5421
+ };
5195
5422
 
5196
5423
  const { Behavior, getEnv, ENV_TYPE, Link, interceptors, getInitPxTransform, Current, options, eventCenter, Events, preload } = Taro__default["default"];
5197
5424
  const taro = {
@@ -5332,6 +5559,7 @@ exports.createLivePusherContext = createLivePusherContext;
5332
5559
  exports.createMapContext = createMapContext;
5333
5560
  exports.createMediaAudioPlayer = createMediaAudioPlayer;
5334
5561
  exports.createMediaContainer = createMediaContainer;
5562
+ exports.createMediaQueryObserver = createMediaQueryObserver;
5335
5563
  exports.createMediaRecorder = createMediaRecorder;
5336
5564
  exports.createOffscreenCanvas = createOffscreenCanvas;
5337
5565
  exports.createRewardedVideoAd = createRewardedVideoAd;