@tarojs/taro-h5 3.4.0-beta.0 → 3.4.0

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 (306) 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 +17 -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/audio/index.js +88 -0
  55. package/dist/api/media/background-audio.js +11 -0
  56. package/dist/api/media/camera.js +3 -0
  57. package/dist/api/media/editor.js +18 -0
  58. package/dist/api/media/image/chooseImage.js +74 -0
  59. package/dist/api/media/image/getImageInfo.js +31 -0
  60. package/dist/api/media/image/index.js +9 -0
  61. package/dist/api/media/image/previewImage.js +67 -0
  62. package/dist/api/media/index.js +13 -0
  63. package/dist/api/media/live.js +4 -0
  64. package/dist/api/media/map.js +3 -0
  65. package/dist/api/media/media-recorder.js +3 -0
  66. package/dist/api/media/recorder.js +5 -0
  67. package/dist/api/media/video/index.js +74 -0
  68. package/dist/api/media/video-decoder.js +3 -0
  69. package/dist/api/media/video-processing.js +3 -0
  70. package/dist/api/media/voip.js +16 -0
  71. package/dist/api/navigate/index.js +6 -0
  72. package/dist/api/network/download.js +124 -0
  73. package/dist/api/network/index.js +7 -0
  74. package/dist/api/network/mdns.js +12 -0
  75. package/dist/api/network/request/index.js +125 -0
  76. package/dist/api/network/tcp.js +3 -0
  77. package/dist/api/network/udp.js +3 -0
  78. package/dist/api/network/upload.js +151 -0
  79. package/dist/api/network/utils.js +65 -0
  80. package/dist/api/network/websocket/index.js +70 -0
  81. package/dist/api/network/websocket/socketTask.js +63 -0
  82. package/dist/api/open-api/account.js +3 -0
  83. package/dist/api/open-api/address.js +3 -0
  84. package/dist/api/open-api/authorize.js +4 -0
  85. package/dist/api/open-api/card.js +4 -0
  86. package/dist/api/open-api/channels-live.js +8 -0
  87. package/dist/api/open-api/customer-service.js +3 -0
  88. package/dist/api/open-api/facial.js +6 -0
  89. package/dist/api/open-api/favorites.js +4 -0
  90. package/dist/api/open-api/group.js +3 -0
  91. package/dist/api/open-api/index.js +18 -0
  92. package/dist/api/open-api/invoice.js +4 -0
  93. package/dist/api/open-api/license-plate.js +3 -0
  94. package/dist/api/open-api/login.js +5 -0
  95. package/dist/api/open-api/red-package.js +3 -0
  96. package/dist/api/open-api/settings.js +4 -0
  97. package/dist/api/open-api/soter.js +5 -0
  98. package/dist/api/open-api/subscribe-message.js +3 -0
  99. package/dist/api/open-api/user-info.js +4 -0
  100. package/dist/api/open-api/werun.js +4 -0
  101. package/dist/api/payment/index.js +4 -0
  102. package/dist/api/route/index.js +3 -0
  103. package/dist/api/share/index.js +12 -0
  104. package/dist/api/storage/background-fetch.js +6 -0
  105. package/dist/api/storage/index.js +157 -0
  106. package/dist/api/swan/index.js +26 -0
  107. package/dist/api/taro.js +47 -0
  108. package/dist/api/ui/animation/index.js +284 -0
  109. package/dist/api/ui/background.js +4 -0
  110. package/dist/api/ui/custom-component.js +3 -0
  111. package/dist/api/ui/fonts.js +3 -0
  112. package/dist/api/ui/index.js +12 -0
  113. package/dist/api/ui/interaction/actionSheet.js +188 -0
  114. package/dist/api/ui/interaction/index.js +268 -0
  115. package/dist/api/ui/interaction/modal.js +207 -0
  116. package/dist/api/ui/interaction/toast.js +195 -0
  117. package/dist/api/ui/menu.js +3 -0
  118. package/dist/api/ui/navigation-bar/index.js +42 -0
  119. package/dist/api/ui/pull-down-refresh.js +26 -0
  120. package/dist/api/ui/scroll/index.js +83 -0
  121. package/dist/api/ui/sticky.js +3 -0
  122. package/dist/api/ui/tab-bar.js +282 -0
  123. package/dist/api/ui/window.js +31 -0
  124. package/dist/api/utils/handler.js +80 -0
  125. package/dist/api/utils/index.js +148 -0
  126. package/dist/api/worker/index.js +3 -0
  127. package/dist/api/wxml/index.js +6 -0
  128. package/dist/api/wxml/nodesRef.js +42 -0
  129. package/dist/api/wxml/selectorQuery.js +201 -0
  130. package/dist/index.cjs.js +7852 -11638
  131. package/dist/index.js +4 -0
  132. package/dist/taroApis.js +1 -1
  133. package/dist/types/type.js +2 -0
  134. package/package.json +14 -16
  135. package/src/api/ad/index.ts +5 -0
  136. package/src/api/ai/facial.ts +6 -0
  137. package/src/api/ai/index.ts +2 -0
  138. package/src/api/ai/visual.ts +4 -0
  139. package/src/api/alipay/index.ts +4 -0
  140. package/src/api/base/crypto.ts +4 -0
  141. package/src/api/base/debug.ts +5 -0
  142. package/src/api/base/index.ts +23 -0
  143. package/src/api/base/performance.ts +5 -0
  144. package/src/api/base/system/index.ts +2 -0
  145. package/src/api/base/system/info.ts +64 -0
  146. package/src/api/base/system/network.ts +70 -0
  147. package/src/api/base/update.ts +5 -0
  148. package/src/api/base/weapp/app-event.ts +19 -0
  149. package/src/api/base/weapp/life-cycle.ts +5 -0
  150. package/src/api/canvas/CanvasContext.ts +233 -0
  151. package/src/api/canvas/canvasGetImageData.ts +27 -0
  152. package/src/api/canvas/canvasPutImageData.ts +24 -0
  153. package/src/api/canvas/canvasToTempFilePath.ts +24 -0
  154. package/src/api/canvas/createCanvasContext.ts +18 -0
  155. package/src/api/canvas/index.ts +10 -0
  156. package/src/api/cloud/index.ts +27 -0
  157. package/src/api/data-analysis/index.ts +6 -0
  158. package/src/api/device/accelerometer.ts +87 -0
  159. package/src/api/device/accessibility.ts +4 -0
  160. package/src/api/device/battery.ts +5 -0
  161. package/src/api/device/bluetooth-ble.ts +19 -0
  162. package/src/api/device/bluetooth-peripheral.ts +6 -0
  163. package/src/api/device/bluetooth.ts +16 -0
  164. package/src/api/device/calendar.ts +5 -0
  165. package/src/api/device/clipboard.ts +67 -0
  166. package/src/api/device/compass.ts +67 -0
  167. package/src/api/device/contact.ts +5 -0
  168. package/src/api/device/crypto.ts +4 -0
  169. package/src/api/device/gyroscope.ts +7 -0
  170. package/src/api/device/iBeacon.ts +10 -0
  171. package/src/api/device/index.ts +22 -0
  172. package/src/api/device/keyboard.ts +7 -0
  173. package/src/api/device/memory.ts +5 -0
  174. package/src/api/device/motion.ts +85 -0
  175. package/src/api/device/nfc.ts +10 -0
  176. package/src/api/device/phone.ts +30 -0
  177. package/src/api/device/scan.ts +7 -0
  178. package/src/api/device/screen.ts +9 -0
  179. package/src/api/device/vibrate.ts +36 -0
  180. package/src/api/device/wifi.ts +13 -0
  181. package/src/api/ext/index.ts +5 -0
  182. package/src/api/files/index.ts +11 -0
  183. package/src/api/framework/index.ts +10 -0
  184. package/src/api/index.ts +25 -0
  185. package/src/api/location/chooseLocation.ts +106 -0
  186. package/src/api/location/index.ts +19 -0
  187. package/src/api/location/style.css +8 -8
  188. package/src/api/media/audio/index.ts +105 -0
  189. package/src/api/media/background-audio.ts +12 -0
  190. package/src/api/media/camera.ts +4 -0
  191. package/src/api/media/editor.ts +29 -0
  192. package/src/api/media/image/chooseImage.ts +78 -0
  193. package/src/api/media/image/getImageInfo.ts +35 -0
  194. package/src/api/media/image/index.ts +13 -0
  195. package/src/api/media/image/previewImage.ts +80 -0
  196. package/src/api/media/index.ts +13 -0
  197. package/src/api/media/live.ts +5 -0
  198. package/src/api/media/map.ts +4 -0
  199. package/src/api/media/media-recorder.ts +4 -0
  200. package/src/api/media/recorder.ts +6 -0
  201. package/src/api/media/video/index.ts +82 -0
  202. package/src/api/media/video-decoder.ts +4 -0
  203. package/src/api/media/video-processing.ts +4 -0
  204. package/src/api/media/voip.ts +17 -0
  205. package/src/api/navigate/index.ts +7 -0
  206. package/src/api/{fileTransfer/downloadFile.js → network/download.ts} +16 -27
  207. package/src/api/network/index.ts +7 -0
  208. package/src/api/network/mdns.ts +13 -0
  209. package/src/api/{request/index.js → network/request/index.ts} +9 -6
  210. package/src/api/network/tcp.ts +4 -0
  211. package/src/api/network/udp.ts +4 -0
  212. package/src/api/{fileTransfer/uploadFile.js → network/upload.ts} +28 -32
  213. package/src/api/{fileTransfer/utils.js → network/utils.ts} +0 -0
  214. package/src/api/network/websocket/index.ts +88 -0
  215. package/src/api/{webSocket/socketTask.js → network/websocket/socketTask.ts} +17 -7
  216. package/src/api/open-api/account.ts +4 -0
  217. package/src/api/open-api/address.ts +4 -0
  218. package/src/api/open-api/authorize.ts +5 -0
  219. package/src/api/open-api/card.ts +5 -0
  220. package/src/api/open-api/channels-live.ts +9 -0
  221. package/src/api/open-api/customer-service.ts +4 -0
  222. package/src/api/open-api/facial.ts +7 -0
  223. package/src/api/open-api/favorites.ts +5 -0
  224. package/src/api/open-api/group.ts +4 -0
  225. package/src/api/open-api/index.ts +18 -0
  226. package/src/api/open-api/invoice.ts +5 -0
  227. package/src/api/open-api/license-plate.ts +4 -0
  228. package/src/api/open-api/login.ts +6 -0
  229. package/src/api/open-api/red-package.ts +4 -0
  230. package/src/api/open-api/settings.ts +5 -0
  231. package/src/api/open-api/soter.ts +6 -0
  232. package/src/api/open-api/subscribe-message.ts +4 -0
  233. package/src/api/open-api/user-info.ts +5 -0
  234. package/src/api/open-api/werun.ts +5 -0
  235. package/src/api/payment/index.ts +5 -0
  236. package/src/api/route/index.ts +10 -0
  237. package/src/api/share/index.ts +13 -0
  238. package/src/api/storage/background-fetch.ts +7 -0
  239. package/src/api/storage/index.ts +181 -0
  240. package/src/api/swan/index.ts +31 -0
  241. package/src/{taro/index.js → api/taro.ts} +89 -104
  242. package/src/api/{createAnimation/index.js → ui/animation/index.ts} +52 -41
  243. package/src/api/ui/background.ts +5 -0
  244. package/src/api/ui/custom-component.ts +4 -0
  245. package/src/api/ui/fonts.ts +4 -0
  246. package/src/api/ui/index.ts +12 -0
  247. package/src/api/ui/interaction/actionSheet.ts +212 -0
  248. package/src/api/{interactive/index.js → ui/interaction/index.ts} +95 -77
  249. package/src/api/ui/interaction/modal.ts +237 -0
  250. package/src/api/{interactive/toast.js → ui/interaction/toast.ts} +35 -33
  251. package/src/api/ui/menu.ts +4 -0
  252. package/src/api/ui/navigation-bar/index.ts +52 -0
  253. package/src/api/ui/pull-down-refresh.ts +27 -0
  254. package/src/api/ui/scroll/index.ts +85 -0
  255. package/src/api/ui/sticky.ts +4 -0
  256. package/src/api/ui/tab-bar.ts +326 -0
  257. package/src/api/ui/window.ts +37 -0
  258. package/src/api/utils/handler.ts +105 -0
  259. package/src/api/utils/{index.js → index.ts} +36 -115
  260. package/src/api/worker/index.ts +4 -0
  261. package/src/api/wxml/index.ts +9 -0
  262. package/src/api/wxml/nodesRef.ts +56 -0
  263. package/src/api/wxml/selectorQuery.ts +219 -0
  264. package/src/index.ts +6 -0
  265. package/src/types/api.d.ts +4 -0
  266. package/src/types/define.d.ts +2 -0
  267. package/{types → src/types}/index.d.ts +0 -0
  268. package/{types → src/types}/type.ts +1 -1
  269. package/src/api/accelerometer/index.js +0 -105
  270. package/src/api/audio/index.js +0 -137
  271. package/src/api/canvas/canvasGetImageData.js +0 -44
  272. package/src/api/canvas/canvasPutImageData.js +0 -45
  273. package/src/api/canvas/canvasToTempFilePath.js +0 -49
  274. package/src/api/canvas/createCanvasContext.js +0 -340
  275. package/src/api/canvas/index.js +0 -4
  276. package/src/api/clipboard/index.js +0 -113
  277. package/src/api/compass/index.js +0 -99
  278. package/src/api/createSelectorQuery/index.js +0 -193
  279. package/src/api/deviceMotion/index.js +0 -105
  280. package/src/api/fileTransfer/index.js +0 -2
  281. package/src/api/image/chooseImage.js +0 -87
  282. package/src/api/image/getImageInfo.js +0 -74
  283. package/src/api/image/index.js +0 -7
  284. package/src/api/image/previewImage.js +0 -94
  285. package/src/api/index.js +0 -29
  286. package/src/api/interactive/actionSheet.js +0 -214
  287. package/src/api/interactive/modal.js +0 -256
  288. package/src/api/location/chooseLocation.js +0 -143
  289. package/src/api/location/index.js +0 -5
  290. package/src/api/navigationBar/index.js +0 -57
  291. package/src/api/open/index.js +0 -5
  292. package/src/api/others/index.js +0 -43
  293. package/src/api/pullDownRefresh/index.js +0 -51
  294. package/src/api/scroll/index.js +0 -99
  295. package/src/api/storage/index.js +0 -211
  296. package/src/api/system/index.js +0 -9
  297. package/src/api/system/info.js +0 -36
  298. package/src/api/system/network.js +0 -68
  299. package/src/api/tabBar/index.js +0 -402
  300. package/src/api/unsupportedApi/index.js +0 -278
  301. package/src/api/vibrate/index.js +0 -49
  302. package/src/api/video/index.js +0 -87
  303. package/src/api/webSocket/index.js +0 -103
  304. package/src/api/window/index.js +0 -38
  305. package/src/index.cjs.js +0 -11
  306. package/src/index.js +0 -6
@@ -0,0 +1,80 @@
1
+ export class MethodHandler {
2
+ constructor({ name, success, fail, complete }) {
3
+ this.methodName = name;
4
+ this.__success = success;
5
+ this.__fail = fail;
6
+ this.__complete = complete;
7
+ }
8
+ success(res = {}, resolve = Promise.resolve.bind(Promise)) {
9
+ if (!res.errMsg) {
10
+ res.errMsg = `${this.methodName}:ok`;
11
+ }
12
+ typeof this.__success === 'function' && this.__success(res);
13
+ typeof this.__complete === 'function' && this.__complete(res);
14
+ return resolve(res);
15
+ }
16
+ fail(res = {}, reject = Promise.reject.bind(Promise)) {
17
+ if (!res.errMsg) {
18
+ res.errMsg = `${this.methodName}:fail`;
19
+ }
20
+ else {
21
+ res.errMsg = `${this.methodName}:fail ${res.errMsg}`;
22
+ }
23
+ console.error(res.errMsg);
24
+ typeof this.__fail === 'function' && this.__fail(res);
25
+ typeof this.__complete === 'function' && this.__complete(res);
26
+ return reject(res);
27
+ }
28
+ }
29
+ export class CallbackManager {
30
+ constructor() {
31
+ this.callbacks = [];
32
+ }
33
+ /**
34
+ * 添加回调
35
+ * @param {{ callback: function, ctx: any } | function} opt
36
+ */
37
+ add(opt) {
38
+ if (opt)
39
+ this.callbacks.push(opt);
40
+ }
41
+ /**
42
+ * 移除回调
43
+ * @param {{ callback: function, ctx: any } | function} opt
44
+ */
45
+ remove(opt) {
46
+ if (opt) {
47
+ let pos = -1;
48
+ this.callbacks.forEach((callback, k) => {
49
+ if (callback === opt) {
50
+ pos = k;
51
+ }
52
+ });
53
+ if (pos > -1) {
54
+ this.callbacks.splice(pos, 1);
55
+ }
56
+ }
57
+ }
58
+ /**
59
+ * 获取回调函数数量
60
+ * @return {number}
61
+ */
62
+ count() {
63
+ return this.callbacks.length;
64
+ }
65
+ /**
66
+ * 触发回调
67
+ * @param {...any} args 回调的调用参数
68
+ */
69
+ trigger(...args) {
70
+ this.callbacks.forEach(opt => {
71
+ if (typeof opt === 'function') {
72
+ opt(...args);
73
+ }
74
+ else {
75
+ const { callback, ctx } = opt;
76
+ typeof callback === 'function' && callback.call(ctx, ...args);
77
+ }
78
+ });
79
+ }
80
+ }
@@ -0,0 +1,148 @@
1
+ /* eslint-disable prefer-promise-reject-errors */
2
+ import { Current, container, SERVICE_IDENTIFIER } from '@tarojs/runtime';
3
+ export function shouldBeObject(target) {
4
+ if (target && typeof target === 'object')
5
+ return { flag: true };
6
+ return {
7
+ flag: false,
8
+ msg: getParameterError({
9
+ correct: 'Object',
10
+ wrong: target
11
+ })
12
+ };
13
+ }
14
+ export function findDOM(inst) {
15
+ const runtimeHooks = container.get(SERVICE_IDENTIFIER.Hooks);
16
+ if (inst) {
17
+ const find = runtimeHooks.getDOMNode;
18
+ if (typeof find === 'function') {
19
+ return find(inst);
20
+ }
21
+ }
22
+ const page = Current.page;
23
+ const path = page === null || page === void 0 ? void 0 : page.path;
24
+ const msg = '没有找到已经加载了的页面,请在页面加载完成后时候此 API。';
25
+ if (path == null) {
26
+ throw new Error(msg);
27
+ }
28
+ const el = document.getElementById(path);
29
+ if (el == null) {
30
+ throw new Error('在已加载页面中没有找到对应的容器元素。');
31
+ }
32
+ return el;
33
+ }
34
+ export function getParameterError({ name = '', para, correct, wrong }) {
35
+ const parameter = para ? `parameter.${para}` : 'parameter';
36
+ const errorType = upperCaseFirstLetter(wrong === null ? 'Null' : typeof wrong);
37
+ if (name) {
38
+ return `${name}:fail parameter error: ${parameter} should be ${correct} instead of ${errorType}`;
39
+ }
40
+ else {
41
+ return `parameter error: ${parameter} should be ${correct} instead of ${errorType}`;
42
+ }
43
+ }
44
+ function upperCaseFirstLetter(string) {
45
+ if (typeof string !== 'string')
46
+ return string;
47
+ string = string.replace(/^./, match => match.toUpperCase());
48
+ return string;
49
+ }
50
+ export function inlineStyle(style) {
51
+ let res = '';
52
+ for (const attr in style)
53
+ res += `${attr}: ${style[attr]};`;
54
+ if (res.indexOf('display: flex;') >= 0)
55
+ res += 'display: -webkit-box;display: -webkit-flex;';
56
+ res = res.replace(/transform:(.+?);/g, (s, $1) => `${s}-webkit-transform:${$1};`);
57
+ res = res.replace(/flex-direction:(.+?);/g, (s, $1) => `${s}-webkit-flex-direction:${$1};`);
58
+ return res;
59
+ }
60
+ export function setTransform(el, val) {
61
+ el.style.webkitTransform = val;
62
+ el.style.transform = val;
63
+ }
64
+ export function serializeParams(params) {
65
+ if (!params) {
66
+ return '';
67
+ }
68
+ return Object.keys(params)
69
+ .map(key => (`${encodeURIComponent(key)}=${typeof (params[key]) === 'object'
70
+ ? encodeURIComponent(JSON.stringify(params[key]))
71
+ : encodeURIComponent(params[key])}`))
72
+ .join('&');
73
+ }
74
+ export function temporarilyNotSupport(apiName) {
75
+ return () => {
76
+ const errMsg = `暂时不支持 API ${apiName}`;
77
+ console.error(errMsg);
78
+ return Promise.reject({
79
+ errMsg
80
+ });
81
+ };
82
+ }
83
+ export function weixinCorpSupport(apiName) {
84
+ return () => {
85
+ const errMsg = `h5端仅在微信公众号中支持 API ${apiName}`;
86
+ console.error(errMsg);
87
+ return Promise.reject({
88
+ errMsg
89
+ });
90
+ };
91
+ }
92
+ export function permanentlyNotSupport(apiName) {
93
+ return () => {
94
+ const errMsg = `不支持 API ${apiName}`;
95
+ console.error(errMsg);
96
+ return Promise.reject({
97
+ errMsg
98
+ });
99
+ };
100
+ }
101
+ export function isFunction(obj) {
102
+ return typeof obj === 'function';
103
+ }
104
+ const VALID_COLOR_REG = /^#[0-9a-fA-F]{6}$/;
105
+ export const isValidColor = (color) => {
106
+ return VALID_COLOR_REG.test(color);
107
+ };
108
+ export function processOpenApi(apiName, defaultOptions, formatResult = res => res, formatParams = options => options) {
109
+ // @ts-ignore
110
+ if (!window.wx) {
111
+ return weixinCorpSupport(apiName);
112
+ }
113
+ return options => {
114
+ options = options || {};
115
+ const obj = Object.assign({}, defaultOptions, options);
116
+ const p = new Promise((resolve, reject) => {
117
+ ['fail', 'success', 'complete'].forEach(k => {
118
+ obj[k] = oriRes => {
119
+ const res = formatResult(oriRes);
120
+ options[k] && options[k](res);
121
+ if (k === 'success') {
122
+ resolve(res);
123
+ }
124
+ else if (k === 'fail') {
125
+ reject(res);
126
+ }
127
+ };
128
+ });
129
+ // @ts-ignore
130
+ wx[apiName](formatParams(obj));
131
+ });
132
+ return p;
133
+ };
134
+ }
135
+ /**
136
+ * ease-in-out的函数
137
+ * @param t 0-1的数字
138
+ */
139
+ export const easeInOut = (t) => t < 0.5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1;
140
+ export const getTimingFunc = (easeFunc, frameCnt) => {
141
+ return x => {
142
+ if (frameCnt <= 1) {
143
+ return easeFunc(1);
144
+ }
145
+ const t = x / (frameCnt - 1);
146
+ return easeFunc(t);
147
+ };
148
+ };
@@ -0,0 +1,3 @@
1
+ import { temporarilyNotSupport } from '../utils';
2
+ // Worker
3
+ export const createWorker = temporarilyNotSupport('createWorker');
@@ -0,0 +1,6 @@
1
+ import { temporarilyNotSupport } from '../utils';
2
+ import { SelectorQuery } from './selectorQuery';
3
+ export const createSelectorQuery = () => {
4
+ return new SelectorQuery();
5
+ };
6
+ export const createIntersectionObserver = temporarilyNotSupport('createIntersectionObserver');
@@ -0,0 +1,42 @@
1
+ export class NodesRef {
2
+ constructor(selector, querySelectorQuery, single) {
3
+ this._component = querySelectorQuery._component;
4
+ this._selector = selector;
5
+ this._selectorQuery = querySelectorQuery;
6
+ this._single = single;
7
+ }
8
+ context(cb) {
9
+ const { _selector, _component, _single, _selectorQuery } = this;
10
+ _selectorQuery._push(_selector, _component, _single, { context: !0 }, cb);
11
+ return _selectorQuery;
12
+ }
13
+ node(cb) {
14
+ const { _selector, _component, _single, _selectorQuery } = this;
15
+ _selectorQuery._push(_selector, _component, _single, { nodeCanvasType: !0, node: !0 }, cb);
16
+ return _selectorQuery;
17
+ }
18
+ boundingClientRect(cb) {
19
+ const { _selector, _component, _single, _selectorQuery } = this;
20
+ _selectorQuery._push(_selector, _component, _single, { id: !0, dataset: !0, rect: !0, size: !0 }, cb);
21
+ return _selectorQuery;
22
+ }
23
+ scrollOffset(cb) {
24
+ const { _selector, _component, _single, _selectorQuery } = this;
25
+ _selectorQuery._push(_selector, _component, _single, { id: !0, dataset: !0, scrollOffset: !0 }, cb);
26
+ return _selectorQuery;
27
+ }
28
+ fields(fields, cb) {
29
+ const { _selector, _component, _single, _selectorQuery } = this;
30
+ const { id, dataset, rect, size, scrollOffset, properties = [], computedStyle = [] } = fields;
31
+ _selectorQuery._push(_selector, _component, _single, {
32
+ id,
33
+ dataset,
34
+ rect,
35
+ size,
36
+ scrollOffset,
37
+ properties,
38
+ computedStyle
39
+ }, cb);
40
+ return _selectorQuery;
41
+ }
42
+ }
@@ -0,0 +1,201 @@
1
+ import { CanvasContext } from '../canvas/CanvasContext';
2
+ import { findDOM } from '../utils';
3
+ import { NodesRef } from './nodesRef';
4
+ function filter(fields, dom, selector) {
5
+ if (!dom)
6
+ return null;
7
+ const isViewport = selector === '.taro_page';
8
+ const { id, dataset, rect, size, scrollOffset, properties = [], computedStyle = [], nodeCanvasType, node, context } = fields;
9
+ const res = {};
10
+ if (nodeCanvasType && node) {
11
+ const tagName = dom.tagName;
12
+ res.node = {
13
+ id: dom.id,
14
+ $taroElement: dom
15
+ };
16
+ if (/^taro-canvas-core/i.test(tagName)) {
17
+ const type = dom.type || '';
18
+ res.nodeCanvasType = type;
19
+ const canvas = dom.getElementsByTagName('canvas')[0];
20
+ if (/^(2d|webgl)/i.test(type) && canvas) {
21
+ res.node = canvas;
22
+ }
23
+ else {
24
+ res.node = null;
25
+ }
26
+ }
27
+ else {
28
+ // TODO https://developers.weixin.qq.com/miniprogram/dev/component/scroll-view.html
29
+ // if (/^taro-scroll-view-core/i.test(tagName))
30
+ res.nodeCanvasType = '';
31
+ res.node = dom;
32
+ }
33
+ return res;
34
+ }
35
+ if (context) {
36
+ const tagName = dom.tagName;
37
+ if (/^taro-video-core/i.test(tagName)) {
38
+ // TODO HTMLVideoElement to VideoContext
39
+ return { context: dom };
40
+ }
41
+ else if (/^taro-canvas-core/i.test(tagName)) {
42
+ const type = dom.type || '2d';
43
+ const canvas = dom === null || dom === void 0 ? void 0 : dom.querySelector('canvas');
44
+ const ctx = canvas === null || canvas === void 0 ? void 0 : canvas.getContext(type);
45
+ return { context: new CanvasContext(canvas, ctx) };
46
+ }
47
+ else if (/^taro-live-player-core/i.test(tagName)) {
48
+ console.error('暂时不支持通过 NodesRef.context 获取 LivePlayerContext');
49
+ }
50
+ else if (/^taro-editor-core/i.test(tagName)) {
51
+ console.error('暂时不支持通过 NodesRef.context 获取 EditorContext');
52
+ }
53
+ else if (/^taro-map-core/i.test(tagName)) {
54
+ console.error('暂时不支持通过 NodesRef.context 获取 MapContext');
55
+ }
56
+ return;
57
+ }
58
+ if (id)
59
+ res.id = dom.id;
60
+ if (dataset)
61
+ res.dataset = Object.assign({}, dom.dataset);
62
+ if (rect || size) {
63
+ const { left, right, top, bottom, width, height } = dom.getBoundingClientRect();
64
+ if (rect) {
65
+ if (!isViewport) {
66
+ res.left = left;
67
+ res.right = right;
68
+ res.top = top;
69
+ res.bottom = bottom;
70
+ }
71
+ else {
72
+ res.left = 0;
73
+ res.right = 0;
74
+ res.top = 0;
75
+ res.bottom = 0;
76
+ }
77
+ }
78
+ if (size) {
79
+ if (!isViewport) {
80
+ res.width = width;
81
+ res.height = height;
82
+ }
83
+ else {
84
+ res.width = dom.clientWidth;
85
+ res.height = dom.clientHeight;
86
+ }
87
+ }
88
+ }
89
+ if (scrollOffset) {
90
+ res.scrollLeft = dom.scrollLeft;
91
+ res.scrollTop = dom.scrollTop;
92
+ }
93
+ if (properties.length) {
94
+ properties.forEach(prop => {
95
+ const attr = dom.getAttribute(prop);
96
+ if (attr)
97
+ res[prop] = attr;
98
+ });
99
+ }
100
+ if (computedStyle.length) {
101
+ const styles = window.getComputedStyle(dom);
102
+ computedStyle.forEach(key => {
103
+ const value = styles.getPropertyValue(key) || styles[key];
104
+ if (value)
105
+ res[key] = value;
106
+ });
107
+ }
108
+ return res;
109
+ }
110
+ /**
111
+ * WXML节点信息API
112
+ * @return {Object} SelectorQuery 对象实例
113
+ */
114
+ function queryBat(queue, cb) {
115
+ const result = [];
116
+ queue.forEach(item => {
117
+ var _a;
118
+ const { selector, single, fields, component } = item;
119
+ // selector 的容器节点
120
+ /* eslint-disable */
121
+ const container = (component !== null ?
122
+ (findDOM(component) || document) :
123
+ document);
124
+ /* eslint-enable */
125
+ // 特殊处理 ---- 选自己
126
+ let selectSelf = false;
127
+ if (container !== document) {
128
+ const $nodeList = (_a = container.parentNode) === null || _a === void 0 ? void 0 : _a.querySelectorAll(selector);
129
+ if ($nodeList) {
130
+ for (let i = 0, len = $nodeList.length; i < len; ++i) {
131
+ if (container === $nodeList[i]) {
132
+ selectSelf = true;
133
+ break;
134
+ }
135
+ }
136
+ }
137
+ }
138
+ if (single) {
139
+ const el = selectSelf === true ? container : container.querySelector(selector);
140
+ result.push(filter(fields, el, selector));
141
+ }
142
+ else {
143
+ const $children = container.querySelectorAll(selector);
144
+ const children = [];
145
+ selectSelf === true && children.push(container);
146
+ for (let i = 0, len = $children.length; i < len; ++i) {
147
+ children.push($children[i]);
148
+ }
149
+ result.push(children.map(dom => filter(fields, dom)));
150
+ }
151
+ });
152
+ cb(result);
153
+ }
154
+ export class SelectorQuery {
155
+ constructor() {
156
+ this._defaultWebviewId = null;
157
+ this._webviewId = null;
158
+ this._queue = [];
159
+ this._queueCb = [];
160
+ this._component;
161
+ }
162
+ in(component) {
163
+ this._component = component;
164
+ return this;
165
+ }
166
+ select(selector) {
167
+ // 小程序里跨自定义组件的后代选择器 '>>>' 在 h5 替换为普通后代选择器 '>'
168
+ if (typeof selector === 'string')
169
+ selector = selector.replace('>>>', '>');
170
+ return new NodesRef(selector, this, true);
171
+ }
172
+ selectAll(selector) {
173
+ // 小程序里跨自定义组件的后代选择器 '>>>' 在 h5 替换为普通后代选择器 '>'
174
+ if (typeof selector === 'string')
175
+ selector = selector.replace('>>>', '>');
176
+ return new NodesRef(selector, this, false);
177
+ }
178
+ selectViewport() {
179
+ return new NodesRef('.taro_page', this, true);
180
+ }
181
+ exec(cb) {
182
+ queryBat(this._queue, res => {
183
+ const _queueCb = this._queueCb;
184
+ res.forEach((item, index) => {
185
+ const cb = _queueCb[index];
186
+ typeof cb === 'function' && cb.call(this, item);
187
+ });
188
+ typeof cb === 'function' && cb.call(this, res);
189
+ });
190
+ return this;
191
+ }
192
+ _push(selector, component, single, fields, callback = null) {
193
+ this._queue.push({
194
+ component,
195
+ selector,
196
+ single,
197
+ fields
198
+ });
199
+ this._queueCb.push(callback);
200
+ }
201
+ }