@tarojs/taro-h5 3.4.0-beta.1 → 3.4.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.
Files changed (158) hide show
  1. package/dist/api/ad/index.js +4 -0
  2. package/dist/api/ai/facial.js +5 -0
  3. package/dist/api/ai/index.js +2 -0
  4. package/dist/api/ai/visual.js +3 -0
  5. package/dist/api/alipay/index.js +3 -0
  6. package/dist/api/base/crypto.js +3 -0
  7. package/dist/api/base/debug.js +4 -0
  8. package/dist/api/base/index.js +17 -0
  9. package/dist/api/base/performance.js +4 -0
  10. package/dist/api/base/system/index.js +2 -0
  11. package/dist/api/base/system/info.js +57 -0
  12. package/dist/api/base/system/network.js +63 -0
  13. package/dist/api/base/update.js +4 -0
  14. package/dist/api/base/weapp/app-event.js +18 -0
  15. package/dist/api/base/weapp/life-cycle.js +4 -0
  16. package/dist/api/canvas/CanvasContext.js +191 -0
  17. package/dist/api/canvas/canvasGetImageData.js +25 -0
  18. package/dist/api/canvas/canvasPutImageData.js +22 -0
  19. package/dist/api/canvas/canvasToTempFilePath.js +22 -0
  20. package/dist/api/canvas/createCanvasContext.js +16 -0
  21. package/dist/api/canvas/index.js +8 -0
  22. package/dist/api/cloud/index.js +21 -0
  23. package/dist/api/data-analysis/index.js +5 -0
  24. package/dist/api/device/accelerometer.js +83 -0
  25. package/dist/api/device/accessibility.js +3 -0
  26. package/dist/api/device/battery.js +4 -0
  27. package/dist/api/device/bluetooth-ble.js +18 -0
  28. package/dist/api/device/bluetooth-peripheral.js +5 -0
  29. package/dist/api/device/bluetooth.js +15 -0
  30. package/dist/api/device/calendar.js +4 -0
  31. package/dist/api/device/clipboard.js +65 -0
  32. package/dist/api/device/compass.js +64 -0
  33. package/dist/api/device/contact.js +4 -0
  34. package/dist/api/device/crypto.js +3 -0
  35. package/dist/api/device/gyroscope.js +6 -0
  36. package/dist/api/device/iBeacon.js +9 -0
  37. package/dist/api/device/index.js +22 -0
  38. package/dist/api/device/keyboard.js +6 -0
  39. package/dist/api/device/memory.js +4 -0
  40. package/dist/api/device/motion.js +81 -0
  41. package/dist/api/device/nfc.js +9 -0
  42. package/dist/api/device/phone.js +24 -0
  43. package/dist/api/device/scan.js +6 -0
  44. package/dist/api/device/screen.js +8 -0
  45. package/dist/api/device/vibrate.js +35 -0
  46. package/dist/api/device/wifi.js +12 -0
  47. package/dist/api/ext/index.js +4 -0
  48. package/dist/api/files/index.js +10 -0
  49. package/dist/api/framework/index.js +7 -0
  50. package/dist/api/index.js +24 -0
  51. package/dist/api/location/chooseLocation.js +93 -0
  52. package/dist/api/location/index.js +13 -0
  53. package/dist/api/location/style.css +79 -0
  54. package/dist/api/media/EditorContext.js +18 -0
  55. package/dist/api/media/audio/InnerAudioContext.js +84 -0
  56. package/dist/api/media/audio/index.js +15 -0
  57. package/dist/api/media/background-audio/BackgroundAudioManager.js +86 -0
  58. package/dist/api/media/background-audio/index.js +15 -0
  59. package/dist/api/media/camera.js +3 -0
  60. package/dist/api/media/image/chooseImage.js +74 -0
  61. package/dist/api/media/image/getImageInfo.js +31 -0
  62. package/dist/api/media/image/index.js +9 -0
  63. package/dist/api/media/image/previewImage.js +67 -0
  64. package/dist/api/media/index.js +12 -0
  65. package/dist/api/media/live.js +4 -0
  66. package/dist/api/media/map.js +3 -0
  67. package/dist/api/media/media-recorder.js +3 -0
  68. package/dist/api/media/recorder.js +5 -0
  69. package/dist/api/media/video/index.js +74 -0
  70. package/dist/api/media/video-decoder.js +3 -0
  71. package/dist/api/media/video-processing.js +3 -0
  72. package/dist/api/media/voip.js +16 -0
  73. package/dist/api/navigate/index.js +6 -0
  74. package/dist/api/network/download.js +124 -0
  75. package/dist/api/network/index.js +7 -0
  76. package/dist/api/network/mdns.js +12 -0
  77. package/dist/api/network/request/index.js +125 -0
  78. package/dist/api/network/tcp.js +3 -0
  79. package/dist/api/network/udp.js +3 -0
  80. package/dist/api/network/upload.js +151 -0
  81. package/dist/api/network/utils.js +65 -0
  82. package/dist/api/network/websocket/index.js +70 -0
  83. package/dist/api/network/websocket/socketTask.js +63 -0
  84. package/dist/api/open-api/account.js +3 -0
  85. package/dist/api/open-api/address.js +3 -0
  86. package/dist/api/open-api/authorize.js +4 -0
  87. package/dist/api/open-api/card.js +4 -0
  88. package/dist/api/open-api/channels-live.js +8 -0
  89. package/dist/api/open-api/customer-service.js +3 -0
  90. package/dist/api/open-api/facial.js +6 -0
  91. package/dist/api/open-api/favorites.js +4 -0
  92. package/dist/api/open-api/group.js +3 -0
  93. package/dist/api/open-api/index.js +18 -0
  94. package/dist/api/open-api/invoice.js +4 -0
  95. package/dist/api/open-api/license-plate.js +3 -0
  96. package/dist/api/open-api/login.js +5 -0
  97. package/dist/api/open-api/red-package.js +3 -0
  98. package/dist/api/open-api/settings.js +4 -0
  99. package/dist/api/open-api/soter.js +5 -0
  100. package/dist/api/open-api/subscribe-message.js +3 -0
  101. package/dist/api/open-api/user-info.js +4 -0
  102. package/dist/api/open-api/werun.js +4 -0
  103. package/dist/api/payment/index.js +4 -0
  104. package/dist/api/route/index.js +3 -0
  105. package/dist/api/share/index.js +12 -0
  106. package/dist/api/storage/background-fetch.js +6 -0
  107. package/dist/api/storage/index.js +157 -0
  108. package/dist/api/swan/index.js +26 -0
  109. package/dist/api/taro.js +47 -0
  110. package/dist/api/ui/animation/index.js +288 -0
  111. package/dist/api/ui/background.js +4 -0
  112. package/dist/api/ui/custom-component.js +3 -0
  113. package/dist/api/ui/fonts.js +3 -0
  114. package/dist/api/ui/index.js +12 -0
  115. package/dist/api/ui/interaction/actionSheet.js +188 -0
  116. package/dist/api/ui/interaction/index.js +268 -0
  117. package/dist/api/ui/interaction/modal.js +207 -0
  118. package/dist/api/ui/interaction/toast.js +195 -0
  119. package/dist/api/ui/menu.js +3 -0
  120. package/dist/api/ui/navigation-bar/index.js +42 -0
  121. package/dist/api/ui/pull-down-refresh.js +26 -0
  122. package/dist/api/ui/scroll/index.js +83 -0
  123. package/dist/api/ui/sticky.js +3 -0
  124. package/dist/api/ui/tab-bar.js +282 -0
  125. package/dist/api/ui/window.js +31 -0
  126. package/dist/api/utils/handler.js +80 -0
  127. package/dist/api/utils/index.js +172 -0
  128. package/dist/api/worker/index.js +3 -0
  129. package/dist/api/wxml/index.js +6 -0
  130. package/dist/api/wxml/nodesRef.js +42 -0
  131. package/dist/api/wxml/selectorQuery.js +201 -0
  132. package/dist/index.cjs.js +4756 -6934
  133. package/dist/index.js +4 -10767
  134. package/dist/taroApis.js +1 -1
  135. package/dist/types/type.js +2 -0
  136. package/package.json +11 -13
  137. package/src/api/canvas/CanvasContext.ts +36 -33
  138. package/src/api/canvas/createCanvasContext.ts +2 -2
  139. package/src/api/cloud/index.ts +4 -0
  140. package/src/api/location/chooseLocation.ts +2 -2
  141. package/src/api/media/{editor.ts → EditorContext.ts} +0 -0
  142. package/src/api/media/audio/InnerAudioContext.ts +98 -0
  143. package/src/api/media/audio/index.ts +1 -86
  144. package/src/api/media/background-audio/BackgroundAudioManager.ts +103 -0
  145. package/src/api/media/{background-audio.ts → background-audio/index.ts} +7 -2
  146. package/src/api/media/image/previewImage.ts +4 -25
  147. package/src/api/media/index.ts +0 -1
  148. package/src/api/network/download.ts +5 -5
  149. package/src/api/network/upload.ts +6 -6
  150. package/src/api/network/websocket/index.ts +1 -1
  151. package/src/api/ui/animation/index.ts +11 -12
  152. package/src/api/ui/interaction/index.ts +12 -10
  153. package/src/api/ui/navigation-bar/index.ts +2 -2
  154. package/src/api/ui/scroll/index.ts +3 -3
  155. package/src/api/utils/index.ts +34 -13
  156. package/src/api/wxml/nodesRef.ts +10 -3
  157. package/src/api/wxml/selectorQuery.ts +68 -23
  158. package/src/index.ts +2 -2
@@ -0,0 +1,3 @@
1
+ import { temporarilyNotSupport } from '../utils';
2
+ // 微信群
3
+ export const getGroupEnterInfo = temporarilyNotSupport('getGroupEnterInfo');
@@ -0,0 +1,18 @@
1
+ export * from './account';
2
+ export * from './address';
3
+ export * from './authorize';
4
+ export * from './card';
5
+ export * from './channels-live';
6
+ export * from './customer-service';
7
+ export * from './facial';
8
+ export * from './favorites';
9
+ export * from './group';
10
+ export * from './invoice';
11
+ export * from './license-plate';
12
+ export * from './login';
13
+ export * from './red-package';
14
+ export * from './settings';
15
+ export * from './soter';
16
+ export * from './subscribe-message';
17
+ export * from './user-info';
18
+ export * from './werun';
@@ -0,0 +1,4 @@
1
+ import { temporarilyNotSupport } from '../utils';
2
+ // 发票
3
+ export const chooseInvoiceTitle = temporarilyNotSupport('chooseInvoiceTitle');
4
+ export const chooseInvoice = temporarilyNotSupport('chooseInvoice');
@@ -0,0 +1,3 @@
1
+ import { temporarilyNotSupport } from '../utils';
2
+ // 车牌
3
+ export const chooseLicensePlate = temporarilyNotSupport('chooseLicensePlate');
@@ -0,0 +1,5 @@
1
+ import { temporarilyNotSupport } from '../utils';
2
+ // 帐号信息
3
+ export const pluginLogin = temporarilyNotSupport('pluginLogin');
4
+ export const login = temporarilyNotSupport('login');
5
+ export const checkSession = temporarilyNotSupport('checkSession');
@@ -0,0 +1,3 @@
1
+ import { temporarilyNotSupport } from '../utils';
2
+ // 微信红包
3
+ export const showRedPackage = temporarilyNotSupport('showRedPackage');
@@ -0,0 +1,4 @@
1
+ import { temporarilyNotSupport } from '../utils';
2
+ // 设置
3
+ export const openSetting = temporarilyNotSupport('openSetting');
4
+ export const getSetting = temporarilyNotSupport('getSetting');
@@ -0,0 +1,5 @@
1
+ import { temporarilyNotSupport } from '../utils';
2
+ // 生物认证
3
+ export const startSoterAuthentication = temporarilyNotSupport('startSoterAuthentication');
4
+ export const checkIsSupportSoterAuthentication = temporarilyNotSupport('checkIsSupportSoterAuthentication');
5
+ export const checkIsSoterEnrolledInDevice = temporarilyNotSupport('checkIsSoterEnrolledInDevice');
@@ -0,0 +1,3 @@
1
+ import { temporarilyNotSupport } from '../utils';
2
+ // 订阅消息
3
+ export const requestSubscribeMessage = temporarilyNotSupport('requestSubscribeMessage');
@@ -0,0 +1,4 @@
1
+ import { temporarilyNotSupport } from '../utils';
2
+ // 用户信息
3
+ export const getUserProfile = temporarilyNotSupport('getUserProfile');
4
+ export const getUserInfo = temporarilyNotSupport('getUserInfo');
@@ -0,0 +1,4 @@
1
+ import { temporarilyNotSupport } from '../utils';
2
+ // 微信运动
3
+ export const shareToWeRun = temporarilyNotSupport('shareToWeRun');
4
+ export const getWeRunData = temporarilyNotSupport('getWeRunData');
@@ -0,0 +1,4 @@
1
+ import { temporarilyNotSupport } from '../utils';
2
+ // 支付
3
+ export const requestPayment = temporarilyNotSupport('requestPayment');
4
+ export const requestOrderPayment = temporarilyNotSupport('requestOrderPayment');
@@ -0,0 +1,3 @@
1
+ // 路由
2
+ export { switchTab, reLaunch, redirectTo, navigateTo, navigateBack } from '@tarojs/router';
3
+ // FIXME 方法导出类型未对齐,后续修复
@@ -0,0 +1,12 @@
1
+ import { temporarilyNotSupport } from '../utils';
2
+ // 转发
3
+ export const updateShareMenu = temporarilyNotSupport('updateShareMenu');
4
+ export const showShareMenu = temporarilyNotSupport('showShareMenu');
5
+ export const showShareImageMenu = temporarilyNotSupport('showShareImageMenu');
6
+ export const shareVideoMessage = temporarilyNotSupport('shareVideoMessage');
7
+ export const shareFileMessage = temporarilyNotSupport('shareFileMessage');
8
+ export const onCopyUrl = temporarilyNotSupport('onCopyUrl');
9
+ export const offCopyUrl = temporarilyNotSupport('offCopyUrl');
10
+ export const hideShareMenu = temporarilyNotSupport('hideShareMenu');
11
+ export const getShareInfo = temporarilyNotSupport('getShareInfo');
12
+ export const authPrivateMessage = temporarilyNotSupport('authPrivateMessage');
@@ -0,0 +1,6 @@
1
+ import { temporarilyNotSupport } from '../utils';
2
+ // 周期性更新
3
+ export const setBackgroundFetchToken = temporarilyNotSupport('setBackgroundFetchToken');
4
+ export const onBackgroundFetchData = temporarilyNotSupport('onBackgroundFetchData');
5
+ export const getBackgroundFetchToken = temporarilyNotSupport('getBackgroundFetchToken');
6
+ export const getBackgroundFetchData = temporarilyNotSupport('getBackgroundFetchData');
@@ -0,0 +1,157 @@
1
+ import { shouldBeObject, getParameterError, temporarilyNotSupport } from '../utils';
2
+ import { MethodHandler } from '../utils/handler';
3
+ function getItem(key) {
4
+ let item;
5
+ try {
6
+ item = JSON.parse(localStorage.getItem(key) || '');
7
+ }
8
+ catch (e) { }
9
+ // 只返回使用 Taro.setStorage API 存储的数据
10
+ if (item && typeof item === 'object' && item.hasOwnProperty('data')) {
11
+ return { result: true, data: item.data };
12
+ }
13
+ else {
14
+ return { result: false };
15
+ }
16
+ }
17
+ // 数据缓存
18
+ export const setStorageSync = (key, data = '') => {
19
+ if (typeof key !== 'string') {
20
+ console.error(getParameterError({
21
+ name: 'setStorage',
22
+ correct: 'String',
23
+ wrong: key
24
+ }));
25
+ return;
26
+ }
27
+ const type = typeof data;
28
+ let obj = {};
29
+ if (type === 'symbol') {
30
+ obj = { data: '' };
31
+ }
32
+ else {
33
+ obj = { data };
34
+ }
35
+ localStorage.setItem(key, JSON.stringify(obj));
36
+ };
37
+ export const setStorage = (options) => {
38
+ // options must be an Object
39
+ const isObject = shouldBeObject(options);
40
+ if (!isObject.flag) {
41
+ const res = { errMsg: `setStorage:fail ${isObject.msg}` };
42
+ console.error(res.errMsg);
43
+ return Promise.reject(res);
44
+ }
45
+ const { key, data, success, fail, complete } = options;
46
+ const handle = new MethodHandler({ name: 'setStorage', success, fail, complete });
47
+ if (typeof key !== 'string') {
48
+ return handle.fail({
49
+ errMsg: getParameterError({
50
+ para: 'key',
51
+ correct: 'String',
52
+ wrong: key
53
+ })
54
+ });
55
+ }
56
+ setStorageSync(key, data);
57
+ return handle.success();
58
+ };
59
+ export const revokeBufferURL = temporarilyNotSupport('revokeBufferURL');
60
+ export const removeStorageSync = (key) => {
61
+ if (typeof key !== 'string') {
62
+ console.error(getParameterError({
63
+ name: 'removeStorage',
64
+ correct: 'String',
65
+ wrong: key
66
+ }));
67
+ return;
68
+ }
69
+ localStorage.removeItem(key);
70
+ };
71
+ export const removeStorage = (options) => {
72
+ // options must be an Object
73
+ const isObject = shouldBeObject(options);
74
+ if (!isObject.flag) {
75
+ const res = { errMsg: `removeStorage:fail ${isObject.msg}` };
76
+ console.error(res.errMsg);
77
+ return Promise.reject(res);
78
+ }
79
+ const { key, success, fail, complete } = options;
80
+ const handle = new MethodHandler({ name: 'removeStorage', success, fail, complete });
81
+ if (typeof key !== 'string') {
82
+ return handle.fail({
83
+ errMsg: getParameterError({
84
+ para: 'key',
85
+ correct: 'String',
86
+ wrong: key
87
+ })
88
+ });
89
+ }
90
+ removeStorageSync(key);
91
+ return handle.success();
92
+ };
93
+ export const getStorageSync = (key) => {
94
+ if (typeof key !== 'string') {
95
+ console.error(getParameterError({
96
+ name: 'getStorageSync',
97
+ correct: 'String',
98
+ wrong: key
99
+ }));
100
+ return;
101
+ }
102
+ const res = getItem(key);
103
+ if (res.result)
104
+ return res.data;
105
+ return '';
106
+ };
107
+ export const getStorageInfoSync = () => {
108
+ const res = {
109
+ keys: Object.keys(localStorage),
110
+ limitSize: NaN,
111
+ currentSize: NaN
112
+ };
113
+ return res;
114
+ };
115
+ export const getStorageInfo = ({ success, fail, complete } = {}) => {
116
+ const handle = new MethodHandler({ name: 'getStorageInfo', success, fail, complete });
117
+ return handle.success(getStorageInfoSync());
118
+ };
119
+ export const getStorage = (options) => {
120
+ // options must be an Object
121
+ const isObject = shouldBeObject(options);
122
+ if (!isObject.flag) {
123
+ const res = { errMsg: `getStorage:fail ${isObject.msg}` };
124
+ console.error(res.errMsg);
125
+ return Promise.reject(res);
126
+ }
127
+ const { key, success, fail, complete } = options;
128
+ const handle = new MethodHandler({ name: 'getStorage', success, fail, complete });
129
+ if (typeof key !== 'string') {
130
+ return handle.fail({
131
+ errMsg: getParameterError({
132
+ para: 'key',
133
+ correct: 'String',
134
+ wrong: key
135
+ })
136
+ });
137
+ }
138
+ const { result, data } = getItem(key);
139
+ if (result) {
140
+ return handle.success({ data });
141
+ }
142
+ else {
143
+ return handle.fail({
144
+ errMsg: 'data not found'
145
+ });
146
+ }
147
+ };
148
+ export const createBufferURL = temporarilyNotSupport('createBufferURL');
149
+ export const clearStorageSync = () => {
150
+ localStorage.clear();
151
+ };
152
+ export const clearStorage = ({ success, fail, complete } = {}) => {
153
+ const handle = new MethodHandler({ name: 'clearStorage', success, fail, complete });
154
+ clearStorageSync();
155
+ return handle.success();
156
+ };
157
+ export * from './background-fetch';
@@ -0,0 +1,26 @@
1
+ import { temporarilyNotSupport } from '../utils';
2
+ export const setPageInfo = temporarilyNotSupport('setPageInfo');
3
+ // 百度小程序 AI 相关
4
+ export const ocrIdCard = temporarilyNotSupport('ocrIdCard');
5
+ export const ocrBankCard = temporarilyNotSupport('ocrBankCard');
6
+ export const ocrDrivingLicense = temporarilyNotSupport('ocrDrivingLicense');
7
+ export const ocrVehicleLicense = temporarilyNotSupport('ocrVehicleLicense');
8
+ export const textReview = temporarilyNotSupport('textReview');
9
+ export const textToAudio = temporarilyNotSupport('textToAudio');
10
+ export const imageAudit = temporarilyNotSupport('imageAudit');
11
+ export const advancedGeneralIdentify = temporarilyNotSupport('advancedGeneralIdentify');
12
+ export const objectDetectIdentify = temporarilyNotSupport('objectDetectIdentify');
13
+ export const carClassify = temporarilyNotSupport('carClassify');
14
+ export const dishClassify = temporarilyNotSupport('dishClassify');
15
+ export const logoClassify = temporarilyNotSupport('logoClassify');
16
+ export const animalClassify = temporarilyNotSupport('animalClassify');
17
+ export const plantClassify = temporarilyNotSupport('plantClassify');
18
+ // 用户信息
19
+ export const getSwanId = temporarilyNotSupport('getSwanId');
20
+ // 百度收银台支付
21
+ export const requestPolymerPayment = temporarilyNotSupport('requestPolymerPayment');
22
+ // 打开小程序
23
+ export const navigateToSmartGameProgram = temporarilyNotSupport('navigateToSmartGameProgram');
24
+ export const navigateToSmartProgram = temporarilyNotSupport('navigateToSmartProgram');
25
+ export const navigateBackSmartProgram = temporarilyNotSupport('navigateBackSmartProgram');
26
+ export const preloadSubPackage = temporarilyNotSupport('preloadSubPackage');
@@ -0,0 +1,47 @@
1
+ import Taro from '@tarojs/api';
2
+ import { history, createRouter } from '@tarojs/router';
3
+ import { getApp, getCurrentInstance, getCurrentPages, nextTick, navigateBack, navigateTo, reLaunch, redirectTo, switchTab } from '../api';
4
+ import { permanentlyNotSupport } from '../api/utils';
5
+ const { Behavior, getEnv, ENV_TYPE, Link, interceptors, getInitPxTransform, Current, options, eventCenter, Events, preload } = Taro;
6
+ const taro = {
7
+ // @ts-ignore
8
+ Behavior,
9
+ getEnv,
10
+ ENV_TYPE,
11
+ Link,
12
+ interceptors,
13
+ Current,
14
+ getCurrentInstance,
15
+ options,
16
+ nextTick,
17
+ eventCenter,
18
+ Events,
19
+ preload,
20
+ history,
21
+ createRouter,
22
+ navigateBack,
23
+ navigateTo,
24
+ reLaunch,
25
+ redirectTo,
26
+ getCurrentPages,
27
+ switchTab
28
+ };
29
+ const initPxTransform = getInitPxTransform(taro);
30
+ const requirePlugin = permanentlyNotSupport('requirePlugin');
31
+ const pxTransform = function (size) {
32
+ // @ts-ignore
33
+ const { designWidth } = taro.config;
34
+ return Math.ceil((((parseInt(size, 10) / 40) * 640) / designWidth) * 10000) / 10000 + 'rem';
35
+ };
36
+ const canIUseWebp = function () {
37
+ const canvas = document.createElement('canvas');
38
+ return canvas.toDataURL('image/webp').indexOf('data:image/webp') === 0;
39
+ };
40
+ taro.requirePlugin = requirePlugin;
41
+ taro.getApp = getApp;
42
+ taro.pxTransform = pxTransform;
43
+ taro.initPxTransform = initPxTransform;
44
+ // @ts-ignore
45
+ taro.canIUseWebp = canIUseWebp;
46
+ export default taro;
47
+ export { Behavior, getEnv, ENV_TYPE, Link, interceptors, initPxTransform, Current, options, eventCenter, Events, preload, requirePlugin, pxTransform, canIUseWebp, history, createRouter };
@@ -0,0 +1,288 @@
1
+ /**
2
+ * H5 下的 styleSheet 操作
3
+ * @author leeenx
4
+ */
5
+ class StyleSheet {
6
+ constructor() {
7
+ this.$style = null;
8
+ this.sheet = null;
9
+ this.appendStyleSheet = () => {
10
+ if (this.$style) {
11
+ const head = document.getElementsByTagName('head')[0];
12
+ this.$style.setAttribute('type', 'text/css');
13
+ this.$style.setAttribute('data-type', 'Taro');
14
+ head.appendChild(this.$style);
15
+ this.sheet = this.$style.sheet;
16
+ }
17
+ if (this.sheet && !('insertRule' in this.sheet)) {
18
+ console.warn('当前浏览器不支持 stylesheet.insertRule 接口');
19
+ }
20
+ };
21
+ // 添加样式命令
22
+ this.add = (cssText, index = 0) => {
23
+ var _a;
24
+ if (this.sheet === null) {
25
+ // $style 未插入到 DOM
26
+ this.appendStyleSheet();
27
+ }
28
+ (_a = this.sheet) === null || _a === void 0 ? void 0 : _a.insertRule(cssText, index);
29
+ };
30
+ this.$style = document.createElement('style');
31
+ }
32
+ }
33
+ const styleSheet = new StyleSheet();
34
+ // 监听事件
35
+ let TRANSITION_END = 'transitionend';
36
+ let TRANSFORM = 'transform';
37
+ const $detect = document.createElement('div');
38
+ $detect.style.cssText = '-webkit-animation-name:webkit;-moz-animation-name:moz;-ms-animation-name:ms;animation-name:standard;';
39
+ if ($detect.style['animation-name'] === 'standard') {
40
+ // 支持标准写法
41
+ TRANSITION_END = 'transitionend';
42
+ TRANSFORM = 'transform';
43
+ }
44
+ else if ($detect.style['-webkit-animation-name'] === 'webkit') {
45
+ // webkit 前缀
46
+ TRANSITION_END = 'webkitTransitionEnd';
47
+ TRANSFORM = '-webkit-transform';
48
+ }
49
+ else if ($detect.style['-moz-animation-name'] === 'moz') {
50
+ // moz 前缀
51
+ TRANSITION_END = 'mozTransitionEnd';
52
+ TRANSFORM = '-moz-transform';
53
+ }
54
+ else if ($detect.style['-ms-animation-name'] === 'ms') {
55
+ // ms 前缀
56
+ TRANSITION_END = 'msTransitionEnd';
57
+ TRANSFORM = '-ms-transform';
58
+ }
59
+ let animId = 0;
60
+ class Animation {
61
+ constructor({ duration = 400, delay = 0, timingFunction = 'linear', transformOrigin = '50% 50% 0', unit = 'px' } = {}) {
62
+ // 属性组合
63
+ this.rules = [];
64
+ // transform 对象
65
+ this.transform = [`${TRANSFORM}:`];
66
+ // 组合动画
67
+ this.steps = [];
68
+ // 动画 map ----- 永久保留
69
+ this.animationMap = {};
70
+ // animationMap 的长度
71
+ this.animationMapCount = 0;
72
+ // 默认值
73
+ this.setDefault(duration, delay, timingFunction, transformOrigin);
74
+ this.unit = unit;
75
+ // atom 环境下,animation 属性不会显示,所以要改成 data-animation
76
+ let animAttr = 'animation';
77
+ // 动画 id
78
+ this.id = ++animId;
79
+ // 监听事件
80
+ document.body.addEventListener(TRANSITION_END, (e) => {
81
+ const target = e.target;
82
+ if (target.getAttribute(animAttr) === null) {
83
+ animAttr = 'data-animation';
84
+ }
85
+ const animData = target.getAttribute(animAttr);
86
+ // 没有动画存在
87
+ if (animData === null)
88
+ return;
89
+ const [animName, animPath] = animData.split('__');
90
+ if (animName === `taro-h5-poly-fill/${this.id}/create-animation`) {
91
+ const [animIndex, __stepIndex = 0] = animPath.split('--');
92
+ const stepIndex = Number(__stepIndex);
93
+ // 动画总的关键帧
94
+ const animStepsCount = this.animationMap[`${animName}__${animIndex}`];
95
+ const animStepsMaxIndex = animStepsCount - 1;
96
+ if (stepIndex < animStepsMaxIndex) {
97
+ // 播放下一个关键帧(因为 nerv 和 react 有差异所以 animation & data-animation 都需要写)
98
+ target.setAttribute(animAttr, `${animName}__${animIndex}--${stepIndex + 1}`);
99
+ if (animAttr === 'animation') {
100
+ // Nerv 环境,animation & data-animation 双重保险
101
+ target.setAttribute('data-animation', `${animName}__${animIndex}--${stepIndex + 1}`);
102
+ }
103
+ }
104
+ }
105
+ });
106
+ }
107
+ transformUnit(...args) {
108
+ const ret = [];
109
+ args.forEach(each => {
110
+ ret.push(isNaN(each) ? each : `${each}${this.unit}`);
111
+ });
112
+ return ret;
113
+ }
114
+ // 设置默认值
115
+ setDefault(duration, delay, timingFunction, transformOrigin) {
116
+ this.DEFAULT = { duration, delay, timingFunction, transformOrigin };
117
+ }
118
+ matrix(a, b, c, d, tx, ty) {
119
+ this.transform.push(`matrix(${a}, ${b}, ${c}, ${d}, ${tx}, ${ty})`);
120
+ return this;
121
+ }
122
+ matrix3d(a1, b1, c1, d1, a2, b2, c2, d2, a3, b3, c3, d3, a4, b4, c4, d4) {
123
+ this.transform.push(`matrix3d(${a1}, ${b1}, ${c1}, ${d1}, ${a2}, ${b2}, ${c2}, ${d2}, ${a3}, ${b3}, ${c3}, ${d3}, ${a4}, ${b4}, ${c4}, ${d4})`);
124
+ return this;
125
+ }
126
+ rotate(angle) {
127
+ this.transform.push(`rotate(${angle}deg)`);
128
+ return this;
129
+ }
130
+ rotate3d(x, y, z, angle) {
131
+ if (typeof y !== 'number') {
132
+ this.transform.push(`rotate3d(${x})`);
133
+ }
134
+ else {
135
+ this.transform.push(`rotate3d(${x}, ${y || 0}, ${z || 0}, ${angle || 0}deg)`);
136
+ }
137
+ return this;
138
+ }
139
+ rotateX(angle) {
140
+ this.transform.push(`rotateX(${angle}deg)`);
141
+ return this;
142
+ }
143
+ rotateY(angle) {
144
+ this.transform.push(`rotateY(${angle}deg)`);
145
+ return this;
146
+ }
147
+ rotateZ(angle) {
148
+ this.transform.push(`rotateZ(${angle}deg)`);
149
+ return this;
150
+ }
151
+ scale(x, y) {
152
+ this.transform.push(`scale(${x}, ${y})`);
153
+ return this;
154
+ }
155
+ scale3d(x, y, z) {
156
+ this.transform.push(`scale3d(${x}, ${y}, ${z})`);
157
+ return this;
158
+ }
159
+ scaleX(scale) {
160
+ this.transform.push(`scaleX(${scale})`);
161
+ return this;
162
+ }
163
+ scaleY(scale) {
164
+ this.transform.push(`scaleY(${scale})`);
165
+ return this;
166
+ }
167
+ scaleZ(scale) {
168
+ this.transform.push(`scaleZ(${scale})`);
169
+ return this;
170
+ }
171
+ skew(x, y) {
172
+ this.transform.push(`skew(${x}, ${y})`);
173
+ return this;
174
+ }
175
+ skewX(angle) {
176
+ this.transform.push(`skewX(${angle})`);
177
+ return this;
178
+ }
179
+ skewY(angle) {
180
+ this.transform.push(`skewY(${angle})`);
181
+ return this;
182
+ }
183
+ translate(x, y) {
184
+ [x, y] = this.transformUnit(x, y);
185
+ this.transform.push(`translate(${x}, ${y})`);
186
+ return this;
187
+ }
188
+ translate3d(x, y, z) {
189
+ [x, y, z] = this.transformUnit(x, y, z);
190
+ this.transform.push(`translate3d(${x}, ${y}, ${z})`);
191
+ return this;
192
+ }
193
+ translateX(translate) {
194
+ [translate] = this.transformUnit(translate);
195
+ this.transform.push(`translateX(${translate})`);
196
+ return this;
197
+ }
198
+ translateY(translate) {
199
+ [translate] = this.transformUnit(translate);
200
+ this.transform.push(`translateY(${translate})`);
201
+ return this;
202
+ }
203
+ translateZ(translate) {
204
+ [translate] = this.transformUnit(translate);
205
+ this.transform.push(`translateZ(${translate})`);
206
+ return this;
207
+ }
208
+ opacity(value) {
209
+ this.rules.push(`opacity: ${value}`);
210
+ return this;
211
+ }
212
+ backgroundColor(value) {
213
+ this.rules.push(`background-color: ${value}`);
214
+ return this;
215
+ }
216
+ width(value) {
217
+ [value] = this.transformUnit(value);
218
+ this.rules.push(`width: ${value}`);
219
+ return this;
220
+ }
221
+ height(value) {
222
+ [value] = this.transformUnit(value);
223
+ this.rules.push(`height: ${value}`);
224
+ return this;
225
+ }
226
+ top(value) {
227
+ [value] = this.transformUnit(value);
228
+ this.rules.push(`top: ${value}`);
229
+ return this;
230
+ }
231
+ right(value) {
232
+ [value] = this.transformUnit(value);
233
+ this.rules.push(`right: ${value}`);
234
+ return this;
235
+ }
236
+ bottom(value) {
237
+ [value] = this.transformUnit(value);
238
+ this.rules.push(`bottom: ${value}`);
239
+ return this;
240
+ }
241
+ left(value) {
242
+ [value] = this.transformUnit(value);
243
+ this.rules.push(`left: ${value}`);
244
+ return this;
245
+ }
246
+ // 关键帧载入
247
+ step(arg = {}) {
248
+ const { DEFAULT } = this;
249
+ const { duration = DEFAULT.duration, delay = DEFAULT.delay, timingFunction = DEFAULT.timingFunction, transformOrigin = DEFAULT.transformOrigin } = arg;
250
+ // 生成一条 transition 动画
251
+ this.steps.push([
252
+ this.rules.map(rule => `${rule}!important`).join(';'),
253
+ `${this.transform.join(' ')}!important`,
254
+ `${TRANSFORM}-origin: ${transformOrigin}`,
255
+ `transition: all ${duration}ms ${timingFunction} ${delay}ms`
256
+ ]
257
+ .filter(item => item !== '' && item !== `${TRANSFORM}:`)
258
+ .join(';'));
259
+ // 清空 rules 和 transform
260
+ this.rules = [];
261
+ this.transform = [`${TRANSFORM}:`];
262
+ return this;
263
+ }
264
+ // 创建底层数据
265
+ createAnimationData() {
266
+ const animIndex = `taro-h5-poly-fill/${this.id}/create-animation__${this.animationMapCount++}`;
267
+ // 记录动画分几个 step
268
+ this.animationMap[animIndex] = this.steps.length;
269
+ // 吐出 step
270
+ this.steps.forEach((step, index) => {
271
+ const selector = index === 0
272
+ ? `[animation="${animIndex}"], [data-animation="${animIndex}"]`
273
+ : `[animation="${animIndex}--${index}"], [data-animation="${animIndex}--${index}"]`;
274
+ styleSheet.add(`${selector} { ${step} }`);
275
+ });
276
+ // 清空 steps
277
+ this.steps = [];
278
+ return animIndex;
279
+ }
280
+ // 动画数据产出
281
+ export() {
282
+ return this.createAnimationData();
283
+ }
284
+ }
285
+ // h5 的 createAnimation
286
+ export const createAnimation = (option) => {
287
+ return new Animation(option);
288
+ };
@@ -0,0 +1,4 @@
1
+ import { temporarilyNotSupport } from '../utils';
2
+ // 背景
3
+ export const setBackgroundTextStyle = temporarilyNotSupport('setBackgroundTextStyle');
4
+ export const setBackgroundColor = temporarilyNotSupport('setBackgroundColor');
@@ -0,0 +1,3 @@
1
+ import Taro from '@tarojs/api';
2
+ // 自定义组件
3
+ export const nextTick = Taro.nextTick;
@@ -0,0 +1,3 @@
1
+ import { temporarilyNotSupport } from '../utils';
2
+ // 字体
3
+ export const loadFontFace = temporarilyNotSupport('loadFontFace');
@@ -0,0 +1,12 @@
1
+ export * from './animation';
2
+ export * from './background';
3
+ export * from './custom-component';
4
+ export * from './fonts';
5
+ export * from './menu';
6
+ export * from './navigation-bar';
7
+ export * from './pull-down-refresh';
8
+ export * from './scroll';
9
+ export * from './sticky';
10
+ export * from './tab-bar';
11
+ export * from './window';
12
+ export * from './interaction';