@tarojs/taro-h5 3.5.10 → 3.5.11
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/api/ui/interaction/index.js +10 -4
- package/dist/api/ui/interaction/modal.d.ts +1 -0
- package/dist/api/ui/interaction/modal.js +9 -1
- package/dist/api/ui/interaction/toast.d.ts +1 -0
- package/dist/api/ui/interaction/toast.js +9 -1
- package/dist/api/wxml/IntersectionObserver.d.ts +20 -0
- package/dist/api/wxml/IntersectionObserver.js +104 -0
- package/dist/api/wxml/MediaQueryObserver.d.ts +7 -0
- package/dist/api/wxml/MediaQueryObserver.js +49 -0
- package/dist/api/wxml/index.d.ts +2 -1
- package/dist/api/wxml/index.js +8 -2
- package/dist/index.cjs.d.ts +3 -2
- package/dist/index.cjs.js +229 -5
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.d.ts +3 -2
- package/dist/index.esm.js +211 -6
- package/dist/index.esm.js.map +1 -1
- package/dist/taroApis.d.ts +3 -2
- package/dist/taroApis.js +1 -1
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/index.js +28 -0
- package/package.json +9 -5
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');
|
|
@@ -3926,6 +3972,7 @@ class Modal {
|
|
|
3926
3972
|
}
|
|
3927
3973
|
create(options = {}) {
|
|
3928
3974
|
return new Promise((resolve) => {
|
|
3975
|
+
var _a, _b;
|
|
3929
3976
|
// style
|
|
3930
3977
|
const { maskStyle, modalStyle, titleStyle, textStyle, footStyle, btnStyle } = this.style;
|
|
3931
3978
|
// configuration
|
|
@@ -3990,10 +4037,13 @@ class Modal {
|
|
|
3990
4037
|
// show immediately
|
|
3991
4038
|
document.body.appendChild(this.el);
|
|
3992
4039
|
setTimeout(() => { this.el.style.opacity = '1'; }, 0);
|
|
4040
|
+
// Current.page不存在时说明路由还未挂载,此时需根据url来分配将要渲染的页面path
|
|
4041
|
+
this.currentPath = (_b = (_a = runtime.Current.page) === null || _a === void 0 ? void 0 : _a.path) !== null && _b !== void 0 ? _b : getLaunchPage();
|
|
3993
4042
|
});
|
|
3994
4043
|
}
|
|
3995
4044
|
show(options = {}) {
|
|
3996
4045
|
return new Promise((resolve) => {
|
|
4046
|
+
var _a, _b;
|
|
3997
4047
|
const config = Object.assign(Object.assign({}, this.options), options);
|
|
3998
4048
|
if (this.hideOpacityTimer)
|
|
3999
4049
|
clearTimeout(this.hideOpacityTimer);
|
|
@@ -4037,6 +4087,8 @@ class Modal {
|
|
|
4037
4087
|
// show
|
|
4038
4088
|
this.el.style.display = 'block';
|
|
4039
4089
|
setTimeout(() => { this.el.style.opacity = '1'; }, 0);
|
|
4090
|
+
// Current.page不存在时说明路由还未挂载,此时需根据url来分配将要渲染的页面path
|
|
4091
|
+
this.currentPath = (_b = (_a = runtime.Current.page) === null || _a === void 0 ? void 0 : _a.path) !== null && _b !== void 0 ? _b : getLaunchPage();
|
|
4040
4092
|
});
|
|
4041
4093
|
}
|
|
4042
4094
|
hide() {
|
|
@@ -4044,6 +4096,7 @@ class Modal {
|
|
|
4044
4096
|
clearTimeout(this.hideOpacityTimer);
|
|
4045
4097
|
if (this.hideDisplayTimer)
|
|
4046
4098
|
clearTimeout(this.hideDisplayTimer);
|
|
4099
|
+
this.currentPath = null;
|
|
4047
4100
|
this.hideOpacityTimer = setTimeout(() => {
|
|
4048
4101
|
this.el.style.opacity = '0';
|
|
4049
4102
|
this.hideDisplayTimer = setTimeout(() => { this.el.style.display = 'none'; }, 200);
|
|
@@ -4127,6 +4180,7 @@ class Toast {
|
|
|
4127
4180
|
};
|
|
4128
4181
|
}
|
|
4129
4182
|
create(options = {}, _type = 'toast') {
|
|
4183
|
+
var _a, _b;
|
|
4130
4184
|
// style
|
|
4131
4185
|
const { maskStyle, toastStyle, successStyle, errrorStyle, loadingStyle, imageStyle, textStyle } = this.style;
|
|
4132
4186
|
// configuration
|
|
@@ -4170,9 +4224,12 @@ class Toast {
|
|
|
4170
4224
|
this.type = config._type;
|
|
4171
4225
|
// disappear after duration
|
|
4172
4226
|
config.duration >= 0 && this.hide(config.duration, this.type);
|
|
4227
|
+
// Current.page不存在时说明路由还未挂载,此时需根据url来分配将要渲染的页面path
|
|
4228
|
+
this.currentPath = (_b = (_a = runtime.Current.page) === null || _a === void 0 ? void 0 : _a.path) !== null && _b !== void 0 ? _b : getLaunchPage();
|
|
4173
4229
|
return '';
|
|
4174
4230
|
}
|
|
4175
4231
|
show(options = {}, _type = 'toast') {
|
|
4232
|
+
var _a, _b;
|
|
4176
4233
|
const config = Object.assign(Object.assign(Object.assign({}, this.options), options), { _type });
|
|
4177
4234
|
if (this.hideOpacityTimer)
|
|
4178
4235
|
clearTimeout(this.hideOpacityTimer);
|
|
@@ -4204,6 +4261,8 @@ class Toast {
|
|
|
4204
4261
|
this.type = config._type;
|
|
4205
4262
|
// disappear after duration
|
|
4206
4263
|
config.duration >= 0 && this.hide(config.duration, this.type);
|
|
4264
|
+
// Current.page不存在时说明路由还未挂载,此时需根据url来分配将要渲染的页面path
|
|
4265
|
+
this.currentPath = (_b = (_a = runtime.Current.page) === null || _a === void 0 ? void 0 : _a.path) !== null && _b !== void 0 ? _b : getLaunchPage();
|
|
4207
4266
|
return '';
|
|
4208
4267
|
}
|
|
4209
4268
|
hide(duration = 0, type) {
|
|
@@ -4213,6 +4272,7 @@ class Toast {
|
|
|
4213
4272
|
clearTimeout(this.hideOpacityTimer);
|
|
4214
4273
|
if (this.hideDisplayTimer)
|
|
4215
4274
|
clearTimeout(this.hideDisplayTimer);
|
|
4275
|
+
this.currentPath = null;
|
|
4216
4276
|
this.hideOpacityTimer = setTimeout(() => {
|
|
4217
4277
|
this.el.style.opacity = '0';
|
|
4218
4278
|
this.hideDisplayTimer = setTimeout(() => { this.el.style.display = 'none'; }, 100);
|
|
@@ -4474,10 +4534,15 @@ const showActionSheet = (options = { itemList: [] }) => __awaiter(void 0, void 0
|
|
|
4474
4534
|
return handle.success(({ tapIndex: result }));
|
|
4475
4535
|
}
|
|
4476
4536
|
});
|
|
4477
|
-
Taro__default["default"].eventCenter.on('
|
|
4478
|
-
|
|
4479
|
-
|
|
4480
|
-
|
|
4537
|
+
Taro__default["default"].eventCenter.on('__afterTaroRouterChange', () => {
|
|
4538
|
+
var _a, _b;
|
|
4539
|
+
if (toast.currentPath && toast.currentPath !== ((_a = runtime.Current.page) === null || _a === void 0 ? void 0 : _a.path)) {
|
|
4540
|
+
hideToast();
|
|
4541
|
+
hideLoading();
|
|
4542
|
+
}
|
|
4543
|
+
if (modal.currentPath && modal.currentPath !== ((_b = runtime.Current.page) === null || _b === void 0 ? void 0 : _b.path)) {
|
|
4544
|
+
hideModal();
|
|
4545
|
+
}
|
|
4481
4546
|
});
|
|
4482
4547
|
const enableAlertBeforeUnload = temporarilyNotSupport('enableAlertBeforeUnload');
|
|
4483
4548
|
const disableAlertBeforeUnload = temporarilyNotSupport('disableAlertBeforeUnload');
|
|
@@ -4946,6 +5011,159 @@ const offWindowResize = callback => {
|
|
|
4946
5011
|
// Worker
|
|
4947
5012
|
const createWorker = temporarilyNotSupport('createWorker');
|
|
4948
5013
|
|
|
5014
|
+
// pollify
|
|
5015
|
+
Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('intersection-observer')); });
|
|
5016
|
+
class TaroH5IntersectionObserver {
|
|
5017
|
+
constructor(component, options = {}) {
|
|
5018
|
+
// 选项
|
|
5019
|
+
this._options = {
|
|
5020
|
+
thresholds: [0],
|
|
5021
|
+
initialRatio: 0,
|
|
5022
|
+
observeAll: false
|
|
5023
|
+
};
|
|
5024
|
+
// 监控中的选择器
|
|
5025
|
+
this._listeners = [];
|
|
5026
|
+
// 用来扩展(或收缩)参照节点布局区域的边界
|
|
5027
|
+
this._rootMargin = {};
|
|
5028
|
+
// 是否已初始化
|
|
5029
|
+
this._isInited = false;
|
|
5030
|
+
this._component = component;
|
|
5031
|
+
Object.assign(this._options, options);
|
|
5032
|
+
}
|
|
5033
|
+
// selector 的容器节点
|
|
5034
|
+
get container() {
|
|
5035
|
+
const container = (this._component !== null
|
|
5036
|
+
? (findDOM(this._component) || document)
|
|
5037
|
+
: document);
|
|
5038
|
+
return container;
|
|
5039
|
+
}
|
|
5040
|
+
createInst() {
|
|
5041
|
+
// 去除原本的实例
|
|
5042
|
+
this.disconnect();
|
|
5043
|
+
const { left = 0, top = 0, bottom = 0, right = 0 } = this._rootMargin;
|
|
5044
|
+
return new IntersectionObserver(entries => {
|
|
5045
|
+
entries.forEach(entry => {
|
|
5046
|
+
const _callback = this._getCallbackByElement(entry.target);
|
|
5047
|
+
const result = {
|
|
5048
|
+
boundingClientRect: entry.boundingClientRect,
|
|
5049
|
+
intersectionRatio: entry.intersectionRatio,
|
|
5050
|
+
intersectionRect: entry.intersectionRect,
|
|
5051
|
+
relativeRect: entry.rootBounds || { left: 0, right: 0, top: 0, bottom: 0 },
|
|
5052
|
+
time: entry.time
|
|
5053
|
+
};
|
|
5054
|
+
// web端会默认首次触发
|
|
5055
|
+
if (!this._isInited && this._options.initialRatio <= Math.min.apply(Math, this._options.thresholds)) {
|
|
5056
|
+
// 初始的相交比例,如果调用时检测到的相交比例与这个值不相等且达到阈值,则会触发一次监听器的回调函数。
|
|
5057
|
+
return;
|
|
5058
|
+
}
|
|
5059
|
+
_callback && _callback.call(this, result);
|
|
5060
|
+
});
|
|
5061
|
+
this._isInited = true;
|
|
5062
|
+
}, {
|
|
5063
|
+
root: this._root,
|
|
5064
|
+
rootMargin: [`${top}px`, `${right}px`, `${bottom}px`, `${left}px`].join(' '),
|
|
5065
|
+
threshold: this._options.thresholds
|
|
5066
|
+
});
|
|
5067
|
+
}
|
|
5068
|
+
disconnect() {
|
|
5069
|
+
if (this._observerInst) {
|
|
5070
|
+
let listener;
|
|
5071
|
+
while ((listener = this._listeners.pop())) {
|
|
5072
|
+
this._observerInst.unobserve(listener.element);
|
|
5073
|
+
}
|
|
5074
|
+
this._observerInst.disconnect();
|
|
5075
|
+
}
|
|
5076
|
+
}
|
|
5077
|
+
observe(targetSelector, callback) {
|
|
5078
|
+
// 同wx小程序效果一致,每个实例监听一个Selector
|
|
5079
|
+
if (this._listeners.length)
|
|
5080
|
+
return;
|
|
5081
|
+
// 监听前没有设置关联的节点
|
|
5082
|
+
if (!this._observerInst) {
|
|
5083
|
+
console.warn('Intersection observer will be ignored because no relative nodes are found.');
|
|
5084
|
+
return;
|
|
5085
|
+
}
|
|
5086
|
+
const nodeList = this._options.observeAll
|
|
5087
|
+
? this.container.querySelectorAll(targetSelector)
|
|
5088
|
+
: [this.container.querySelector(targetSelector)];
|
|
5089
|
+
nodeList.forEach(element => {
|
|
5090
|
+
if (!element)
|
|
5091
|
+
return;
|
|
5092
|
+
this._observerInst.observe(element);
|
|
5093
|
+
this._listeners.push({ element, callback });
|
|
5094
|
+
});
|
|
5095
|
+
}
|
|
5096
|
+
relativeTo(selector, margins) {
|
|
5097
|
+
// 已设置observe监听后,重新关联节点
|
|
5098
|
+
if (this._listeners.length) {
|
|
5099
|
+
console.error('Relative nodes cannot be added after "observe" call in IntersectionObserver');
|
|
5100
|
+
return this;
|
|
5101
|
+
}
|
|
5102
|
+
this._root = this.container.querySelector(selector) || null;
|
|
5103
|
+
if (margins) {
|
|
5104
|
+
this._rootMargin = margins;
|
|
5105
|
+
}
|
|
5106
|
+
this._observerInst = this.createInst();
|
|
5107
|
+
return this;
|
|
5108
|
+
}
|
|
5109
|
+
relativeToViewport(margins) {
|
|
5110
|
+
return this.relativeTo('.taro_page', margins);
|
|
5111
|
+
}
|
|
5112
|
+
_getCallbackByElement(element) {
|
|
5113
|
+
const listener = this._listeners.find(listener => listener.element === element);
|
|
5114
|
+
return listener ? listener.callback : null;
|
|
5115
|
+
}
|
|
5116
|
+
}
|
|
5117
|
+
|
|
5118
|
+
function generateMediaQueryStr(descriptor) {
|
|
5119
|
+
const mediaQueryArr = [];
|
|
5120
|
+
const descriptorMenu = ['width', 'minWidth', 'maxWidth', 'height', 'minHeight', 'maxHeight', 'orientation'];
|
|
5121
|
+
for (const item of descriptorMenu) {
|
|
5122
|
+
if (item !== 'orientation' &&
|
|
5123
|
+
descriptor[item] &&
|
|
5124
|
+
Number(descriptor[item]) >= 0) {
|
|
5125
|
+
mediaQueryArr.push(`(${(toKebabCase(item))}: ${Number(descriptor[item])}px)`);
|
|
5126
|
+
}
|
|
5127
|
+
if (item === 'orientation' && descriptor[item]) {
|
|
5128
|
+
mediaQueryArr.push(`(${toKebabCase(item)}: ${descriptor[item]})`);
|
|
5129
|
+
}
|
|
5130
|
+
}
|
|
5131
|
+
return mediaQueryArr.join(' and ');
|
|
5132
|
+
}
|
|
5133
|
+
class MediaQueryObserver {
|
|
5134
|
+
// 监听页面媒体查询变化情况
|
|
5135
|
+
observe(descriptor, callback) {
|
|
5136
|
+
if (isFunction(callback)) {
|
|
5137
|
+
// 创建媒体查询对象
|
|
5138
|
+
this._mediaQueryObserver = window.matchMedia(generateMediaQueryStr(descriptor));
|
|
5139
|
+
// 监听器
|
|
5140
|
+
this._listener = (ev) => {
|
|
5141
|
+
callback({ matches: ev.matches });
|
|
5142
|
+
};
|
|
5143
|
+
callback({ matches: this._mediaQueryObserver.matches });
|
|
5144
|
+
// 兼容旧浏览器中MediaQueryList尚未继承于EventTarget导致不存在'addEventListener'
|
|
5145
|
+
if ('addEventListener' in this._mediaQueryObserver) {
|
|
5146
|
+
this._mediaQueryObserver.addEventListener('change', this._listener);
|
|
5147
|
+
}
|
|
5148
|
+
else {
|
|
5149
|
+
this._mediaQueryObserver.addListener(this._listener);
|
|
5150
|
+
}
|
|
5151
|
+
}
|
|
5152
|
+
}
|
|
5153
|
+
// 停止监听,销毁媒体查询对象
|
|
5154
|
+
disconnect() {
|
|
5155
|
+
if (this._mediaQueryObserver && this._listener) {
|
|
5156
|
+
// 兼容旧浏览器中MediaQueryList尚未继承于EventTarget导致不存在'removeEventListener'
|
|
5157
|
+
if ('removeEventListener' in this._mediaQueryObserver) {
|
|
5158
|
+
this._mediaQueryObserver.removeEventListener('change', this._listener);
|
|
5159
|
+
}
|
|
5160
|
+
else {
|
|
5161
|
+
this._mediaQueryObserver.removeListener(this._listener);
|
|
5162
|
+
}
|
|
5163
|
+
}
|
|
5164
|
+
}
|
|
5165
|
+
}
|
|
5166
|
+
|
|
4949
5167
|
class NodesRef {
|
|
4950
5168
|
constructor(selector, querySelectorQuery, single) {
|
|
4951
5169
|
this._component = querySelectorQuery._component;
|
|
@@ -5191,7 +5409,12 @@ class SelectorQuery {
|
|
|
5191
5409
|
const createSelectorQuery = () => {
|
|
5192
5410
|
return new SelectorQuery();
|
|
5193
5411
|
};
|
|
5194
|
-
const createIntersectionObserver =
|
|
5412
|
+
const createIntersectionObserver = (component, options) => {
|
|
5413
|
+
return new TaroH5IntersectionObserver(component, options);
|
|
5414
|
+
};
|
|
5415
|
+
const createMediaQueryObserver = () => {
|
|
5416
|
+
return new MediaQueryObserver();
|
|
5417
|
+
};
|
|
5195
5418
|
|
|
5196
5419
|
const { Behavior, getEnv, ENV_TYPE, Link, interceptors, getInitPxTransform, Current, options, eventCenter, Events, preload } = Taro__default["default"];
|
|
5197
5420
|
const taro = {
|
|
@@ -5332,6 +5555,7 @@ exports.createLivePusherContext = createLivePusherContext;
|
|
|
5332
5555
|
exports.createMapContext = createMapContext;
|
|
5333
5556
|
exports.createMediaAudioPlayer = createMediaAudioPlayer;
|
|
5334
5557
|
exports.createMediaContainer = createMediaContainer;
|
|
5558
|
+
exports.createMediaQueryObserver = createMediaQueryObserver;
|
|
5335
5559
|
exports.createMediaRecorder = createMediaRecorder;
|
|
5336
5560
|
exports.createOffscreenCanvas = createOffscreenCanvas;
|
|
5337
5561
|
exports.createRewardedVideoAd = createRewardedVideoAd;
|