@tarojs/taro-h5 3.6.0-beta.0 → 3.6.0-beta.1
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/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 +50 -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 +181 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.d.ts +3 -2
- package/dist/index.esm.js +163 -2
- 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 +1 -0
- package/dist/utils/index.js +3 -0
- package/package.json +10 -6
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import Taro from '@tarojs/taro';
|
|
2
|
+
declare type TElement = Document | HTMLElement | Element;
|
|
3
|
+
export declare class TaroH5IntersectionObserver implements Taro.IntersectionObserver {
|
|
4
|
+
private _component;
|
|
5
|
+
private _options;
|
|
6
|
+
private _observerInst;
|
|
7
|
+
private _listeners;
|
|
8
|
+
private _root;
|
|
9
|
+
private _rootMargin;
|
|
10
|
+
private _isInited;
|
|
11
|
+
protected get container(): TElement;
|
|
12
|
+
constructor(component: TaroGeneral.IAnyObject, options?: Taro.createIntersectionObserver.Option);
|
|
13
|
+
private createInst;
|
|
14
|
+
disconnect(): void;
|
|
15
|
+
observe(targetSelector: string, callback: Taro.IntersectionObserver.ObserveCallback): void;
|
|
16
|
+
relativeTo(selector: string, margins?: Taro.IntersectionObserver.RelativeToMargins | undefined): Taro.IntersectionObserver;
|
|
17
|
+
relativeToViewport(margins?: Taro.IntersectionObserver.RelativeToViewportMargins | undefined): Taro.IntersectionObserver;
|
|
18
|
+
private _getCallbackByElement;
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { findDOM } from '../../utils';
|
|
2
|
+
// pollify
|
|
3
|
+
import('intersection-observer');
|
|
4
|
+
export class TaroH5IntersectionObserver {
|
|
5
|
+
constructor(component, options = {}) {
|
|
6
|
+
// 选项
|
|
7
|
+
this._options = {
|
|
8
|
+
thresholds: [0],
|
|
9
|
+
initialRatio: 0,
|
|
10
|
+
observeAll: false
|
|
11
|
+
};
|
|
12
|
+
// 监控中的选择器
|
|
13
|
+
this._listeners = [];
|
|
14
|
+
// 用来扩展(或收缩)参照节点布局区域的边界
|
|
15
|
+
this._rootMargin = {};
|
|
16
|
+
// 是否已初始化
|
|
17
|
+
this._isInited = false;
|
|
18
|
+
this._component = component;
|
|
19
|
+
Object.assign(this._options, options);
|
|
20
|
+
}
|
|
21
|
+
// selector 的容器节点
|
|
22
|
+
get container() {
|
|
23
|
+
const container = (this._component !== null
|
|
24
|
+
? (findDOM(this._component) || document)
|
|
25
|
+
: document);
|
|
26
|
+
return container;
|
|
27
|
+
}
|
|
28
|
+
createInst() {
|
|
29
|
+
// 去除原本的实例
|
|
30
|
+
this.disconnect();
|
|
31
|
+
const { left = 0, top = 0, bottom = 0, right = 0 } = this._rootMargin;
|
|
32
|
+
return new IntersectionObserver(entries => {
|
|
33
|
+
entries.forEach(entry => {
|
|
34
|
+
const _callback = this._getCallbackByElement(entry.target);
|
|
35
|
+
const result = {
|
|
36
|
+
boundingClientRect: entry.boundingClientRect,
|
|
37
|
+
intersectionRatio: entry.intersectionRatio,
|
|
38
|
+
intersectionRect: entry.intersectionRect,
|
|
39
|
+
relativeRect: entry.rootBounds || { left: 0, right: 0, top: 0, bottom: 0 },
|
|
40
|
+
time: entry.time
|
|
41
|
+
};
|
|
42
|
+
// web端会默认首次触发
|
|
43
|
+
if (!this._isInited && this._options.initialRatio <= Math.min.apply(Math, this._options.thresholds)) {
|
|
44
|
+
// 初始的相交比例,如果调用时检测到的相交比例与这个值不相等且达到阈值,则会触发一次监听器的回调函数。
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
_callback && _callback.call(this, result);
|
|
48
|
+
});
|
|
49
|
+
this._isInited = true;
|
|
50
|
+
}, {
|
|
51
|
+
root: this._root,
|
|
52
|
+
rootMargin: [`${top}px`, `${right}px`, `${bottom}px`, `${left}px`].join(' '),
|
|
53
|
+
threshold: this._options.thresholds
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
disconnect() {
|
|
57
|
+
if (this._observerInst) {
|
|
58
|
+
let listener;
|
|
59
|
+
while ((listener = this._listeners.pop())) {
|
|
60
|
+
this._observerInst.unobserve(listener.element);
|
|
61
|
+
}
|
|
62
|
+
this._observerInst.disconnect();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
observe(targetSelector, callback) {
|
|
66
|
+
// 同wx小程序效果一致,每个实例监听一个Selector
|
|
67
|
+
if (this._listeners.length)
|
|
68
|
+
return;
|
|
69
|
+
// 监听前没有设置关联的节点
|
|
70
|
+
if (!this._observerInst) {
|
|
71
|
+
console.warn('Intersection observer will be ignored because no relative nodes are found.');
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const nodeList = this._options.observeAll
|
|
75
|
+
? this.container.querySelectorAll(targetSelector)
|
|
76
|
+
: [this.container.querySelector(targetSelector)];
|
|
77
|
+
nodeList.forEach(element => {
|
|
78
|
+
if (!element)
|
|
79
|
+
return;
|
|
80
|
+
this._observerInst.observe(element);
|
|
81
|
+
this._listeners.push({ element, callback });
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
relativeTo(selector, margins) {
|
|
85
|
+
// 已设置observe监听后,重新关联节点
|
|
86
|
+
if (this._listeners.length) {
|
|
87
|
+
console.error('Relative nodes cannot be added after "observe" call in IntersectionObserver');
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
90
|
+
this._root = this.container.querySelector(selector) || null;
|
|
91
|
+
if (margins) {
|
|
92
|
+
this._rootMargin = margins;
|
|
93
|
+
}
|
|
94
|
+
this._observerInst = this.createInst();
|
|
95
|
+
return this;
|
|
96
|
+
}
|
|
97
|
+
relativeToViewport(margins) {
|
|
98
|
+
return this.relativeTo('.taro_page', margins);
|
|
99
|
+
}
|
|
100
|
+
_getCallbackByElement(element) {
|
|
101
|
+
const listener = this._listeners.find(listener => listener.element === element);
|
|
102
|
+
return listener ? listener.callback : null;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import Taro from '@tarojs/taro';
|
|
2
|
+
export declare class MediaQueryObserver implements Taro.MediaQueryObserver {
|
|
3
|
+
private _mediaQueryObserver;
|
|
4
|
+
private _listener;
|
|
5
|
+
observe(descriptor: Taro.MediaQueryObserver.descriptor, callback: Taro.MediaQueryObserver.observeCallback): void;
|
|
6
|
+
disconnect(): void;
|
|
7
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { isFunction } from '@tarojs/shared';
|
|
2
|
+
import { toKebabCase } from '../../utils';
|
|
3
|
+
function generateMediaQueryStr(descriptor) {
|
|
4
|
+
const mediaQueryArr = [];
|
|
5
|
+
const descriptorMenu = ['width', 'minWidth', 'maxWidth', 'height', 'minHeight', 'maxHeight', 'orientation'];
|
|
6
|
+
for (const item of descriptorMenu) {
|
|
7
|
+
if (item !== 'orientation' &&
|
|
8
|
+
descriptor[item] &&
|
|
9
|
+
Number(descriptor[item]) >= 0) {
|
|
10
|
+
mediaQueryArr.push(`(${(toKebabCase(item))}: ${Number(descriptor[item])}px)`);
|
|
11
|
+
}
|
|
12
|
+
if (item === 'orientation' && descriptor[item]) {
|
|
13
|
+
mediaQueryArr.push(`(${toKebabCase(item)}: ${descriptor[item]})`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return mediaQueryArr.join(' and ');
|
|
17
|
+
}
|
|
18
|
+
export class MediaQueryObserver {
|
|
19
|
+
// 监听页面媒体查询变化情况
|
|
20
|
+
observe(descriptor, callback) {
|
|
21
|
+
if (isFunction(callback)) {
|
|
22
|
+
// 创建媒体查询对象
|
|
23
|
+
this._mediaQueryObserver = window.matchMedia(generateMediaQueryStr(descriptor));
|
|
24
|
+
// 监听器
|
|
25
|
+
this._listener = (ev) => {
|
|
26
|
+
callback({ matches: ev.matches });
|
|
27
|
+
};
|
|
28
|
+
callback({ matches: this._mediaQueryObserver.matches });
|
|
29
|
+
// 兼容旧浏览器中 MediaQueryList 尚未继承于 EventTarget 导致不存在 'addEventListener'
|
|
30
|
+
if ('addEventListener' in this._mediaQueryObserver) {
|
|
31
|
+
this._mediaQueryObserver.addEventListener('change', this._listener);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
this._mediaQueryObserver.addListener(this._listener);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
// 停止监听,销毁媒体查询对象
|
|
39
|
+
disconnect() {
|
|
40
|
+
if (this._mediaQueryObserver && this._listener) {
|
|
41
|
+
// 兼容旧浏览器中 MediaQueryList 尚未继承于 EventTarget 导致不存在 'removeEventListener'
|
|
42
|
+
if ('removeEventListener' in this._mediaQueryObserver) {
|
|
43
|
+
this._mediaQueryObserver.removeEventListener('change', this._listener);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
this._mediaQueryObserver.removeListener(this._listener);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
package/dist/api/wxml/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import Taro from '@tarojs/api';
|
|
2
2
|
export declare const createSelectorQuery: typeof Taro.createSelectorQuery;
|
|
3
|
-
export declare const createIntersectionObserver:
|
|
3
|
+
export declare const createIntersectionObserver: typeof Taro.createIntersectionObserver;
|
|
4
|
+
export declare const createMediaQueryObserver: typeof Taro.createMediaQueryObserver;
|
package/dist/api/wxml/index.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TaroH5IntersectionObserver } from './IntersectionObserver';
|
|
2
|
+
import { MediaQueryObserver } from './MediaQueryObserver';
|
|
2
3
|
import { SelectorQuery } from './selectorQuery';
|
|
3
4
|
export const createSelectorQuery = () => {
|
|
4
5
|
return new SelectorQuery();
|
|
5
6
|
};
|
|
6
|
-
export const createIntersectionObserver =
|
|
7
|
+
export const createIntersectionObserver = (component, options) => {
|
|
8
|
+
return new TaroH5IntersectionObserver(component, options);
|
|
9
|
+
};
|
|
10
|
+
export const createMediaQueryObserver = () => {
|
|
11
|
+
return new MediaQueryObserver();
|
|
12
|
+
};
|
package/dist/index.cjs.d.ts
CHANGED
|
@@ -755,6 +755,7 @@ declare const offWindowResize: typeof Taro.offWindowResize;
|
|
|
755
755
|
// Worker
|
|
756
756
|
declare const createWorker: (option?: {}, ...args: any[]) => Promise<Partial<TaroGeneral.CallbackResult> & Record<string, unknown> & TaroGeneral.CallbackResult>;
|
|
757
757
|
declare const createSelectorQuery: typeof Taro.createSelectorQuery;
|
|
758
|
-
declare const createIntersectionObserver:
|
|
759
|
-
|
|
758
|
+
declare const createIntersectionObserver: typeof Taro.createIntersectionObserver;
|
|
759
|
+
declare const createMediaQueryObserver: typeof Taro.createMediaQueryObserver;
|
|
760
|
+
export { taro as default, taro, createRewardedVideoAd, createInterstitialAd, stopFaceDetect, initFaceDetect, faceDetect, isVKSupport, createVKSession, getOpenUserInfo, canIUse, arrayBufferToBase64, base64ToArrayBuffer, getUserCryptoManager, setEnableDebug, getRealtimeLogManager, getLogManager, reportPerformance, getPerformance, openSystemBluetoothSetting, openAppAuthorizeSetting, getWindowInfo, getSystemSetting, getDeviceInfo, getAppBaseInfo, getAppAuthorizeSetting, getSystemInfoSync, getSystemInfoAsync, getSystemInfo, updateWeChatApp, getUpdateManager, onUnhandledRejection, onThemeChange, onPageNotFound, onError, onAudioInterruptionEnd, onAudioInterruptionBegin, onAppShow, onAppHide, offUnhandledRejection, offThemeChange, offPageNotFound, offError, offAudioInterruptionEnd, offAudioInterruptionBegin, offAppShow, offAppHide, getLaunchOptionsSync, getEnterOptionsSync, createOffscreenCanvas, createCanvasContext, canvasToTempFilePath, canvasPutImageData, canvasGetImageData, cloud, reportMonitor, reportAnalytics, reportEvent, getExptInfoSync, stopAccelerometer, startAccelerometer, onAccelerometerChange, offAccelerometerChange, checkIsOpenAccessibility, getBatteryInfoSync, getBatteryInfo, stopBluetoothDevicesDiscovery, startBluetoothDevicesDiscovery, openBluetoothAdapter, onBluetoothDeviceFound, onBluetoothAdapterStateChange, offBluetoothDeviceFound, offBluetoothAdapterStateChange, makeBluetoothPair, isBluetoothDevicePaired, getConnectedBluetoothDevices, getBluetoothDevices, getBluetoothAdapterState, closeBluetoothAdapter, writeBLECharacteristicValue, setBLEMTU, readBLECharacteristicValue, onBLEMTUChange, onBLEConnectionStateChange, onBLECharacteristicValueChange, offBLEMTUChange, offBLEConnectionStateChange, offBLECharacteristicValueChange, notifyBLECharacteristicValueChange, getBLEMTU, getBLEDeviceServices, getBLEDeviceRSSI, getBLEDeviceCharacteristics, createBLEConnection, closeBLEConnection, onBLEPeripheralConnectionStateChanged, offBLEPeripheralConnectionStateChanged, createBLEPeripheralServer, addPhoneRepeatCalendar, addPhoneCalendar, setClipboardData, getClipboardData, stopCompass, startCompass, onCompassChange, offCompassChange, chooseContact, addPhoneContact, getRandomValues, stopGyroscope, startGyroscope, onGyroscopeChange, offGyroscopeChange, stopBeaconDiscovery, startBeaconDiscovery, onBeaconUpdate, onBeaconServiceChange, offBeaconUpdate, offBeaconServiceChange, getBeacons, onKeyboardHeightChange, offKeyboardHeightChange, hideKeyboard, getSelectedTextRange, onMemoryWarning, offMemoryWarning, stopDeviceMotionListening, startDeviceMotionListening, onDeviceMotionChange, offDeviceMotionChange, getNetworkType, onNetworkWeakChange, onNetworkStatusChange, offNetworkWeakChange, offNetworkStatusChange, getLocalIPAddress, stopHCE, startHCE, sendHCEMessage, onHCEMessage, offHCEMessage, getNFCAdapter, getHCEState, makePhoneCall, scanCode, setVisualEffectOnCapture, setScreenBrightness, setKeepScreenOn, onUserCaptureScreen, offUserCaptureScreen, getScreenBrightness, vibrateShort, vibrateLong, stopWifi, startWifi, setWifiList, onWifiConnectedWithPartialInfo, onWifiConnected, onGetWifiList, offWifiConnected, offGetWifiList, getWifiList, getConnectedWifi, connectWifi, getExtConfigSync, getExtConfig, saveFileToDisk, saveFile, removeSavedFile, openDocument, getSavedFileList, getSavedFileInfo, getFileSystemManager, getFileInfo, getApp, getCurrentInstance, stopLocationUpdate, startLocationUpdateBackground, startLocationUpdate, openLocation, onLocationChangeError, onLocationChange, offLocationChangeError, offLocationChange, getLocation, choosePoi, getFuzzyLocation, chooseLocation, stopVoice, setInnerAudioOption, playVoice, pauseVoice, getAvailableAudioSources, createWebAudioContext, createMediaAudioPlayer, createInnerAudioContext, createAudioContext, stopBackgroundAudio, seekBackgroundAudio, playBackgroundAudio, pauseBackgroundAudio, onBackgroundAudioStop, onBackgroundAudioPlay, onBackgroundAudioPause, getBackgroundAudioPlayerState, getBackgroundAudioManager, createCameraContext, saveImageToPhotosAlbum, previewMedia, getImageInfo, previewImage, compressImage, chooseMessageFile, chooseImage, createLivePusherContext, createLivePlayerContext, createMapContext, createMediaRecorder, stopRecord, startRecord, getRecorderManager, saveVideoToPhotosAlbum, openVideoEditor, getVideoInfo, createVideoContext, compressVideo, chooseVideo, chooseMedia, createVideoDecoder, createMediaContainer, updateVoIPChatMuteConfig, subscribeVoIPVideoMembers, setEnable1v1Chat, onVoIPVideoMembersChanged, onVoIPChatStateChanged, onVoIPChatSpeakersChanged, onVoIPChatMembersChanged, onVoIPChatInterrupted, offVoIPVideoMembersChanged, offVoIPChatStateChanged, offVoIPChatMembersChanged, offVoIPChatInterrupted, joinVoIPChat, exitVoIPChat, openEmbeddedMiniProgram, navigateToMiniProgram, navigateBackMiniProgram, exitMiniProgram, openBusinessView, downloadFile, stopLocalServiceDiscovery, startLocalServiceDiscovery, onLocalServiceResolveFail, onLocalServiceLost, onLocalServiceFound, onLocalServiceDiscoveryStop, offLocalServiceResolveFail, offLocalServiceLost, offLocalServiceFound, offLocalServiceDiscoveryStop, request, addInterceptor, createTCPSocket, createUDPSocket, uploadFile, sendSocketMessage, onSocketOpen, onSocketMessage, onSocketError, onSocketClose, connectSocket, closeSocket, getAccountInfoSync, chooseAddress, authorizeForMiniProgram, authorize, openCard, addCard, reserveChannelsLive, openChannelsLive, openChannelsEvent, openChannelsActivity, getChannelsLiveNoticeInfo, getChannelsLiveInfo, openCustomerServiceChat, checkIsSupportFacialRecognition, startFacialRecognitionVerify, startFacialRecognitionVerifyAndUploadVideo, faceVerifyForPay, addVideoToFavorites, addFileToFavorites, getGroupEnterInfo, chooseInvoiceTitle, chooseInvoice, chooseLicensePlate, pluginLogin, login, checkSession, showRedPackage, openSetting, getSetting, startSoterAuthentication, checkIsSupportSoterAuthentication, checkIsSoterEnrolledInDevice, requestSubscribeMessage, getUserProfile, getUserInfo, shareToWeRun, getWeRunData, requestPayment, requestOrderPayment, updateShareMenu, showShareMenu, showShareImageMenu, shareVideoMessage, shareFileMessage, onCopyUrl, offCopyUrl, hideShareMenu, getShareInfo, authPrivateMessage, setStorageSync, setStorage, revokeBufferURL, removeStorageSync, removeStorage, getStorageSync, getStorageInfoSync, getStorageInfo, getStorage, createBufferURL, clearStorageSync, clearStorage, setBackgroundFetchToken, onBackgroundFetchData, getBackgroundFetchToken, getBackgroundFetchData, setPageInfo, ocrIdCard, ocrBankCard, ocrDrivingLicense, ocrVehicleLicense, textReview, textToAudio, imageAudit, advancedGeneralIdentify, objectDetectIdentify, carClassify, dishClassify, logoClassify, animalClassify, plantClassify, getSwanId, requestPolymerPayment, navigateToSmartGameProgram, navigateToSmartProgram, navigateBackSmartProgram, preloadSubPackage, createAnimation, setBackgroundTextStyle, setBackgroundColor, nextTick, loadFontFace, disableAlertBeforeUnload, enableAlertBeforeUnload, hideLoading, hideToast, showActionSheet, showLoading, showModal, showToast, getMenuButtonBoundingClientRect, showNavigationBarLoading, setNavigationBarTitle, setNavigationBarColor, hideNavigationBarLoading, hideHomeButton, startPullDownRefresh, stopPullDownRefresh, pageScrollTo, setTopBarText, initTabBarApis, showTabBarRedDot, showTabBar, setTabBarStyle, setTabBarItem, setTabBarBadge, removeTabBarBadge, hideTabBarRedDot, hideTabBar, setWindowSize, onWindowResize, offWindowResize, createWorker, createSelectorQuery, createIntersectionObserver, createMediaQueryObserver, Behavior, canIUseWebp, Current, ENV_TYPE, eventCenter, Events, getEnv, history, initPxTransform, interceptors, Link, options, preload, pxTransform, requirePlugin };
|
|
760
761
|
export { getCurrentPages, navigateBack, navigateTo, redirectTo, reLaunch, switchTab } from "@tarojs/router";
|
package/dist/index.cjs.js
CHANGED
|
@@ -15,6 +15,24 @@ var jsonpRetry = require('jsonp-retry');
|
|
|
15
15
|
|
|
16
16
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
17
17
|
|
|
18
|
+
function _interopNamespace(e) {
|
|
19
|
+
if (e && e.__esModule) return e;
|
|
20
|
+
var n = Object.create(null);
|
|
21
|
+
if (e) {
|
|
22
|
+
Object.keys(e).forEach(function (k) {
|
|
23
|
+
if (k !== 'default') {
|
|
24
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
25
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () { return e[k]; }
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
n["default"] = e;
|
|
33
|
+
return Object.freeze(n);
|
|
34
|
+
}
|
|
35
|
+
|
|
18
36
|
var Taro__default = /*#__PURE__*/_interopDefaultLegacy(Taro);
|
|
19
37
|
var jsonpRetry__default = /*#__PURE__*/_interopDefaultLegacy(jsonpRetry);
|
|
20
38
|
|
|
@@ -202,6 +220,9 @@ function upperCaseFirstLetter(string) {
|
|
|
202
220
|
string = string.replace(/^./, match => match.toUpperCase());
|
|
203
221
|
return string;
|
|
204
222
|
}
|
|
223
|
+
const toKebabCase = function (string) {
|
|
224
|
+
return string.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
|
|
225
|
+
};
|
|
205
226
|
function inlineStyle(style) {
|
|
206
227
|
let res = '';
|
|
207
228
|
for (const attr in style)
|
|
@@ -4996,6 +5017,159 @@ const offWindowResize = callback => {
|
|
|
4996
5017
|
// Worker
|
|
4997
5018
|
const createWorker = temporarilyNotSupport('createWorker');
|
|
4998
5019
|
|
|
5020
|
+
// pollify
|
|
5021
|
+
Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('intersection-observer')); });
|
|
5022
|
+
class TaroH5IntersectionObserver {
|
|
5023
|
+
constructor(component, options = {}) {
|
|
5024
|
+
// 选项
|
|
5025
|
+
this._options = {
|
|
5026
|
+
thresholds: [0],
|
|
5027
|
+
initialRatio: 0,
|
|
5028
|
+
observeAll: false
|
|
5029
|
+
};
|
|
5030
|
+
// 监控中的选择器
|
|
5031
|
+
this._listeners = [];
|
|
5032
|
+
// 用来扩展(或收缩)参照节点布局区域的边界
|
|
5033
|
+
this._rootMargin = {};
|
|
5034
|
+
// 是否已初始化
|
|
5035
|
+
this._isInited = false;
|
|
5036
|
+
this._component = component;
|
|
5037
|
+
Object.assign(this._options, options);
|
|
5038
|
+
}
|
|
5039
|
+
// selector 的容器节点
|
|
5040
|
+
get container() {
|
|
5041
|
+
const container = (this._component !== null
|
|
5042
|
+
? (findDOM(this._component) || document)
|
|
5043
|
+
: document);
|
|
5044
|
+
return container;
|
|
5045
|
+
}
|
|
5046
|
+
createInst() {
|
|
5047
|
+
// 去除原本的实例
|
|
5048
|
+
this.disconnect();
|
|
5049
|
+
const { left = 0, top = 0, bottom = 0, right = 0 } = this._rootMargin;
|
|
5050
|
+
return new IntersectionObserver(entries => {
|
|
5051
|
+
entries.forEach(entry => {
|
|
5052
|
+
const _callback = this._getCallbackByElement(entry.target);
|
|
5053
|
+
const result = {
|
|
5054
|
+
boundingClientRect: entry.boundingClientRect,
|
|
5055
|
+
intersectionRatio: entry.intersectionRatio,
|
|
5056
|
+
intersectionRect: entry.intersectionRect,
|
|
5057
|
+
relativeRect: entry.rootBounds || { left: 0, right: 0, top: 0, bottom: 0 },
|
|
5058
|
+
time: entry.time
|
|
5059
|
+
};
|
|
5060
|
+
// web端会默认首次触发
|
|
5061
|
+
if (!this._isInited && this._options.initialRatio <= Math.min.apply(Math, this._options.thresholds)) {
|
|
5062
|
+
// 初始的相交比例,如果调用时检测到的相交比例与这个值不相等且达到阈值,则会触发一次监听器的回调函数。
|
|
5063
|
+
return;
|
|
5064
|
+
}
|
|
5065
|
+
_callback && _callback.call(this, result);
|
|
5066
|
+
});
|
|
5067
|
+
this._isInited = true;
|
|
5068
|
+
}, {
|
|
5069
|
+
root: this._root,
|
|
5070
|
+
rootMargin: [`${top}px`, `${right}px`, `${bottom}px`, `${left}px`].join(' '),
|
|
5071
|
+
threshold: this._options.thresholds
|
|
5072
|
+
});
|
|
5073
|
+
}
|
|
5074
|
+
disconnect() {
|
|
5075
|
+
if (this._observerInst) {
|
|
5076
|
+
let listener;
|
|
5077
|
+
while ((listener = this._listeners.pop())) {
|
|
5078
|
+
this._observerInst.unobserve(listener.element);
|
|
5079
|
+
}
|
|
5080
|
+
this._observerInst.disconnect();
|
|
5081
|
+
}
|
|
5082
|
+
}
|
|
5083
|
+
observe(targetSelector, callback) {
|
|
5084
|
+
// 同wx小程序效果一致,每个实例监听一个Selector
|
|
5085
|
+
if (this._listeners.length)
|
|
5086
|
+
return;
|
|
5087
|
+
// 监听前没有设置关联的节点
|
|
5088
|
+
if (!this._observerInst) {
|
|
5089
|
+
console.warn('Intersection observer will be ignored because no relative nodes are found.');
|
|
5090
|
+
return;
|
|
5091
|
+
}
|
|
5092
|
+
const nodeList = this._options.observeAll
|
|
5093
|
+
? this.container.querySelectorAll(targetSelector)
|
|
5094
|
+
: [this.container.querySelector(targetSelector)];
|
|
5095
|
+
nodeList.forEach(element => {
|
|
5096
|
+
if (!element)
|
|
5097
|
+
return;
|
|
5098
|
+
this._observerInst.observe(element);
|
|
5099
|
+
this._listeners.push({ element, callback });
|
|
5100
|
+
});
|
|
5101
|
+
}
|
|
5102
|
+
relativeTo(selector, margins) {
|
|
5103
|
+
// 已设置observe监听后,重新关联节点
|
|
5104
|
+
if (this._listeners.length) {
|
|
5105
|
+
console.error('Relative nodes cannot be added after "observe" call in IntersectionObserver');
|
|
5106
|
+
return this;
|
|
5107
|
+
}
|
|
5108
|
+
this._root = this.container.querySelector(selector) || null;
|
|
5109
|
+
if (margins) {
|
|
5110
|
+
this._rootMargin = margins;
|
|
5111
|
+
}
|
|
5112
|
+
this._observerInst = this.createInst();
|
|
5113
|
+
return this;
|
|
5114
|
+
}
|
|
5115
|
+
relativeToViewport(margins) {
|
|
5116
|
+
return this.relativeTo('.taro_page', margins);
|
|
5117
|
+
}
|
|
5118
|
+
_getCallbackByElement(element) {
|
|
5119
|
+
const listener = this._listeners.find(listener => listener.element === element);
|
|
5120
|
+
return listener ? listener.callback : null;
|
|
5121
|
+
}
|
|
5122
|
+
}
|
|
5123
|
+
|
|
5124
|
+
function generateMediaQueryStr(descriptor) {
|
|
5125
|
+
const mediaQueryArr = [];
|
|
5126
|
+
const descriptorMenu = ['width', 'minWidth', 'maxWidth', 'height', 'minHeight', 'maxHeight', 'orientation'];
|
|
5127
|
+
for (const item of descriptorMenu) {
|
|
5128
|
+
if (item !== 'orientation' &&
|
|
5129
|
+
descriptor[item] &&
|
|
5130
|
+
Number(descriptor[item]) >= 0) {
|
|
5131
|
+
mediaQueryArr.push(`(${(toKebabCase(item))}: ${Number(descriptor[item])}px)`);
|
|
5132
|
+
}
|
|
5133
|
+
if (item === 'orientation' && descriptor[item]) {
|
|
5134
|
+
mediaQueryArr.push(`(${toKebabCase(item)}: ${descriptor[item]})`);
|
|
5135
|
+
}
|
|
5136
|
+
}
|
|
5137
|
+
return mediaQueryArr.join(' and ');
|
|
5138
|
+
}
|
|
5139
|
+
class MediaQueryObserver {
|
|
5140
|
+
// 监听页面媒体查询变化情况
|
|
5141
|
+
observe(descriptor, callback) {
|
|
5142
|
+
if (shared.isFunction(callback)) {
|
|
5143
|
+
// 创建媒体查询对象
|
|
5144
|
+
this._mediaQueryObserver = window.matchMedia(generateMediaQueryStr(descriptor));
|
|
5145
|
+
// 监听器
|
|
5146
|
+
this._listener = (ev) => {
|
|
5147
|
+
callback({ matches: ev.matches });
|
|
5148
|
+
};
|
|
5149
|
+
callback({ matches: this._mediaQueryObserver.matches });
|
|
5150
|
+
// 兼容旧浏览器中 MediaQueryList 尚未继承于 EventTarget 导致不存在 'addEventListener'
|
|
5151
|
+
if ('addEventListener' in this._mediaQueryObserver) {
|
|
5152
|
+
this._mediaQueryObserver.addEventListener('change', this._listener);
|
|
5153
|
+
}
|
|
5154
|
+
else {
|
|
5155
|
+
this._mediaQueryObserver.addListener(this._listener);
|
|
5156
|
+
}
|
|
5157
|
+
}
|
|
5158
|
+
}
|
|
5159
|
+
// 停止监听,销毁媒体查询对象
|
|
5160
|
+
disconnect() {
|
|
5161
|
+
if (this._mediaQueryObserver && this._listener) {
|
|
5162
|
+
// 兼容旧浏览器中 MediaQueryList 尚未继承于 EventTarget 导致不存在 'removeEventListener'
|
|
5163
|
+
if ('removeEventListener' in this._mediaQueryObserver) {
|
|
5164
|
+
this._mediaQueryObserver.removeEventListener('change', this._listener);
|
|
5165
|
+
}
|
|
5166
|
+
else {
|
|
5167
|
+
this._mediaQueryObserver.removeListener(this._listener);
|
|
5168
|
+
}
|
|
5169
|
+
}
|
|
5170
|
+
}
|
|
5171
|
+
}
|
|
5172
|
+
|
|
4999
5173
|
class NodesRef {
|
|
5000
5174
|
constructor(selector, querySelectorQuery, single) {
|
|
5001
5175
|
this._component = querySelectorQuery._component;
|
|
@@ -5241,7 +5415,12 @@ class SelectorQuery {
|
|
|
5241
5415
|
const createSelectorQuery = () => {
|
|
5242
5416
|
return new SelectorQuery();
|
|
5243
5417
|
};
|
|
5244
|
-
const createIntersectionObserver =
|
|
5418
|
+
const createIntersectionObserver = (component, options) => {
|
|
5419
|
+
return new TaroH5IntersectionObserver(component, options);
|
|
5420
|
+
};
|
|
5421
|
+
const createMediaQueryObserver = () => {
|
|
5422
|
+
return new MediaQueryObserver();
|
|
5423
|
+
};
|
|
5245
5424
|
|
|
5246
5425
|
const { Behavior, getEnv, ENV_TYPE, Link, interceptors, getInitPxTransform, Current, options, eventCenter, Events, preload } = Taro__default["default"];
|
|
5247
5426
|
const taro = {
|
|
@@ -5382,6 +5561,7 @@ exports.createLivePusherContext = createLivePusherContext;
|
|
|
5382
5561
|
exports.createMapContext = createMapContext;
|
|
5383
5562
|
exports.createMediaAudioPlayer = createMediaAudioPlayer;
|
|
5384
5563
|
exports.createMediaContainer = createMediaContainer;
|
|
5564
|
+
exports.createMediaQueryObserver = createMediaQueryObserver;
|
|
5385
5565
|
exports.createMediaRecorder = createMediaRecorder;
|
|
5386
5566
|
exports.createOffscreenCanvas = createOffscreenCanvas;
|
|
5387
5567
|
exports.createRewardedVideoAd = createRewardedVideoAd;
|