@tarojs/taro-h5 3.3.15 → 3.3.19

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 (305) hide show
  1. package/dist/api/ad/index.js +3 -0
  2. package/dist/api/ai/facial.js +4 -0
  3. package/dist/api/ai/index.js +2 -0
  4. package/dist/api/ai/visual.js +2 -0
  5. package/dist/api/alipay/index.js +2 -0
  6. package/dist/api/base/crypto.js +2 -0
  7. package/dist/api/base/debug.js +4 -0
  8. package/dist/api/base/index.js +16 -0
  9. package/dist/api/base/performance.js +3 -0
  10. package/dist/api/base/system/index.js +2 -0
  11. package/dist/api/base/system/info.js +56 -0
  12. package/dist/api/base/system/network.js +52 -0
  13. package/dist/api/base/update.js +3 -0
  14. package/dist/api/base/weapp/app-event.js +17 -0
  15. package/dist/api/base/weapp/life-cycle.js +3 -0
  16. package/dist/api/canvas/CanvasContext.js +182 -0
  17. package/dist/api/canvas/canvasGetImageData.js +21 -0
  18. package/dist/api/canvas/canvasPutImageData.js +17 -0
  19. package/dist/api/canvas/canvasToTempFilePath.js +18 -0
  20. package/dist/api/canvas/createCanvasContext.js +13 -0
  21. package/dist/api/canvas/index.js +7 -0
  22. package/dist/api/cloud/index.js +14 -0
  23. package/dist/api/data-analysis/index.js +5 -0
  24. package/dist/api/device/accelerometer.js +71 -0
  25. package/dist/api/device/accessibility.js +2 -0
  26. package/dist/api/device/battery.js +3 -0
  27. package/dist/api/device/bluetooth-ble.js +17 -0
  28. package/dist/api/device/bluetooth-peripheral.js +4 -0
  29. package/dist/api/device/bluetooth.js +14 -0
  30. package/dist/api/device/calendar.js +3 -0
  31. package/dist/api/device/clipboard.js +48 -0
  32. package/dist/api/device/compass.js +52 -0
  33. package/dist/api/device/contact.js +3 -0
  34. package/dist/api/device/crypto.js +2 -0
  35. package/dist/api/device/gyroscope.js +5 -0
  36. package/dist/api/device/iBeacon.js +8 -0
  37. package/dist/api/device/index.js +22 -0
  38. package/dist/api/device/keyboard.js +5 -0
  39. package/dist/api/device/memory.js +3 -0
  40. package/dist/api/device/motion.js +69 -0
  41. package/dist/api/device/nfc.js +8 -0
  42. package/dist/api/device/phone.js +23 -0
  43. package/dist/api/device/scan.js +5 -0
  44. package/dist/api/device/screen.js +7 -0
  45. package/dist/api/device/vibrate.js +29 -0
  46. package/dist/api/device/wifi.js +11 -0
  47. package/dist/api/ext/index.js +3 -0
  48. package/dist/api/files/index.js +9 -0
  49. package/dist/api/framework/index.js +6 -0
  50. package/dist/api/index.js +24 -0
  51. package/dist/api/location/chooseLocation.js +88 -0
  52. package/dist/api/location/index.js +12 -0
  53. package/dist/api/location/style.css +79 -0
  54. package/dist/api/media/audio/index.js +81 -0
  55. package/dist/api/media/background-audio.js +10 -0
  56. package/dist/api/media/camera.js +2 -0
  57. package/dist/api/media/editor.js +17 -0
  58. package/dist/api/media/image/chooseImage.js +70 -0
  59. package/dist/api/media/image/getImageInfo.js +27 -0
  60. package/dist/api/media/image/index.js +8 -0
  61. package/dist/api/media/image/previewImage.js +78 -0
  62. package/dist/api/media/index.js +13 -0
  63. package/dist/api/media/live.js +3 -0
  64. package/dist/api/media/map.js +2 -0
  65. package/dist/api/media/media-recorder.js +2 -0
  66. package/dist/api/media/recorder.js +4 -0
  67. package/dist/api/media/video/index.js +65 -0
  68. package/dist/api/media/video-decoder.js +2 -0
  69. package/dist/api/media/video-processing.js +2 -0
  70. package/dist/api/media/voip.js +15 -0
  71. package/dist/api/navigate/index.js +5 -0
  72. package/dist/api/network/download.js +101 -0
  73. package/dist/api/network/index.js +7 -0
  74. package/dist/api/network/mdns.js +11 -0
  75. package/dist/api/network/request/index.js +123 -0
  76. package/dist/api/network/tcp.js +2 -0
  77. package/dist/api/network/udp.js +2 -0
  78. package/dist/api/network/upload.js +129 -0
  79. package/dist/api/network/utils.js +30 -0
  80. package/dist/api/network/websocket/index.js +65 -0
  81. package/dist/api/network/websocket/socketTask.js +61 -0
  82. package/dist/api/open-api/account.js +2 -0
  83. package/dist/api/open-api/address.js +2 -0
  84. package/dist/api/open-api/authorize.js +3 -0
  85. package/dist/api/open-api/card.js +3 -0
  86. package/dist/api/open-api/channels-live.js +7 -0
  87. package/dist/api/open-api/customer-service.js +2 -0
  88. package/dist/api/open-api/facial.js +5 -0
  89. package/dist/api/open-api/favorites.js +3 -0
  90. package/dist/api/open-api/group.js +2 -0
  91. package/dist/api/open-api/index.js +18 -0
  92. package/dist/api/open-api/invoice.js +3 -0
  93. package/dist/api/open-api/license-plate.js +2 -0
  94. package/dist/api/open-api/login.js +4 -0
  95. package/dist/api/open-api/red-package.js +2 -0
  96. package/dist/api/open-api/settings.js +3 -0
  97. package/dist/api/open-api/soter.js +4 -0
  98. package/dist/api/open-api/subscribe-message.js +2 -0
  99. package/dist/api/open-api/user-info.js +3 -0
  100. package/dist/api/open-api/werun.js +3 -0
  101. package/dist/api/payment/index.js +3 -0
  102. package/dist/api/route/index.js +1 -0
  103. package/dist/api/share/index.js +11 -0
  104. package/dist/api/storage/background-fetch.js +5 -0
  105. package/dist/api/storage/index.js +152 -0
  106. package/dist/api/swan/index.js +22 -0
  107. package/dist/api/taro.js +59 -0
  108. package/dist/api/ui/animation/index.js +255 -0
  109. package/dist/api/ui/background.js +3 -0
  110. package/dist/api/ui/custom-component.js +2 -0
  111. package/dist/api/ui/fonts.js +2 -0
  112. package/dist/api/ui/index.js +12 -0
  113. package/dist/api/ui/interaction/actionSheet.js +172 -0
  114. package/dist/api/ui/interaction/index.js +263 -0
  115. package/dist/api/ui/interaction/modal.js +185 -0
  116. package/dist/api/ui/interaction/toast.js +179 -0
  117. package/dist/api/ui/menu.js +2 -0
  118. package/dist/api/ui/navigation-bar/index.js +37 -0
  119. package/dist/api/ui/pull-down-refresh.js +20 -0
  120. package/dist/api/ui/scroll/index.js +80 -0
  121. package/dist/api/ui/sticky.js +2 -0
  122. package/dist/api/ui/tab-bar.js +250 -0
  123. package/dist/api/ui/window.js +22 -0
  124. package/dist/api/utils/handler.js +64 -0
  125. package/dist/api/utils/index.js +141 -0
  126. package/dist/api/worker/index.js +2 -0
  127. package/dist/api/wxml/index.js +6 -0
  128. package/dist/api/wxml/nodesRef.js +35 -0
  129. package/dist/api/wxml/selectorQuery.js +140 -0
  130. package/dist/index.cjs.js +7448 -10817
  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 +11 -14
  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 +230 -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 +101 -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} +133 -149
  242. package/src/api/{createAnimation/index.js → ui/animation/index.ts} +51 -35
  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} +93 -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 +49 -0
  263. package/src/api/{createSelectorQuery/index.js → wxml/selectorQuery.ts} +75 -94
  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/deviceMotion/index.js +0 -105
  279. package/src/api/fileTransfer/index.js +0 -2
  280. package/src/api/image/chooseImage.js +0 -87
  281. package/src/api/image/getImageInfo.js +0 -74
  282. package/src/api/image/index.js +0 -7
  283. package/src/api/image/previewImage.js +0 -94
  284. package/src/api/index.js +0 -29
  285. package/src/api/interactive/actionSheet.js +0 -214
  286. package/src/api/interactive/modal.js +0 -256
  287. package/src/api/location/chooseLocation.js +0 -143
  288. package/src/api/location/index.js +0 -5
  289. package/src/api/navigationBar/index.js +0 -57
  290. package/src/api/open/index.js +0 -5
  291. package/src/api/others/index.js +0 -43
  292. package/src/api/pullDownRefresh/index.js +0 -51
  293. package/src/api/scroll/index.js +0 -99
  294. package/src/api/storage/index.js +0 -211
  295. package/src/api/system/index.js +0 -9
  296. package/src/api/system/info.js +0 -36
  297. package/src/api/system/network.js +0 -68
  298. package/src/api/tabBar/index.js +0 -402
  299. package/src/api/unsupportedApi/index.js +0 -278
  300. package/src/api/vibrate/index.js +0 -49
  301. package/src/api/video/index.js +0 -87
  302. package/src/api/webSocket/index.js +0 -103
  303. package/src/api/window/index.js +0 -38
  304. package/src/index.cjs.js +0 -11
  305. package/src/index.js +0 -6
@@ -1,87 +0,0 @@
1
- import { shouldBeObject, getParameterError } from '../utils'
2
-
3
- /**
4
- * 从本地相册选择图片或使用相机拍照。
5
- * @param {Object} object 参数
6
- * @param {string[]} [object.sourceType=['album', 'camera']] 选择图片的来源(h5端未实现)
7
- * @param {string[]} [object.sizeType=['original', 'compressed']] 所选的图片的尺寸(h5端未实现)
8
- * @param {number} [object.count=9] 最多可以选择的图片张数
9
- * @param {function} [object.success] 接口调用成功的回调函数
10
- * @param {function} [object.fail] 接口调用失败的回调函数
11
- * @param {function} [object.complete] 接口调用结束的回调函数(调用成功、失败都会执行)
12
- * @param {string} [object.imageId] 用来上传的input元素ID(仅h5端)
13
- */
14
- const chooseImage = function (options) {
15
- // options must be an Object
16
- const isObject = shouldBeObject(options)
17
- if (!isObject.res) {
18
- const res = { errMsg: `chooseImage${isObject.msg}` }
19
- console.error(res.errMsg)
20
- return Promise.reject(res)
21
- }
22
-
23
- const { count = 1, success, fail, complete, imageId = 'taroChooseImage' } = options
24
- const res = {
25
- errMsg: 'chooseImage:ok',
26
- tempFilePaths: [],
27
- tempFiles: []
28
- }
29
-
30
- if (count && typeof count !== 'number') {
31
- res.errMsg = getParameterError({
32
- name: 'chooseImage',
33
- para: 'count',
34
- correct: 'Number',
35
- wrong: count
36
- })
37
- console.error(res.errMsg)
38
- typeof fail === 'function' && fail(res)
39
- typeof complete === 'function' && complete(res)
40
- return Promise.reject(res)
41
- }
42
-
43
- let taroChooseImageId = document.getElementById(imageId)
44
- if (!taroChooseImageId) {
45
- const obj = document.createElement('input')
46
- obj.setAttribute('type', 'file')
47
- obj.setAttribute('id', imageId)
48
- if (count > 1) {
49
- obj.setAttribute('multiple', 'multiple')
50
- }
51
- obj.setAttribute('accept', 'image/*')
52
- obj.setAttribute('style', 'position: fixed; top: -4000px; left: -3000px; z-index: -300;')
53
- document.body.appendChild(obj)
54
- taroChooseImageId = document.getElementById(imageId)
55
- } else {
56
- if (count > 1) {
57
- taroChooseImageId.setAttribute('multiple', 'multiple')
58
- } else {
59
- taroChooseImageId.removeAttribute('multiple')
60
- }
61
- }
62
- let taroChooseImageCallback
63
- const taroChooseImagePromise = new Promise(resolve => {
64
- taroChooseImageCallback = resolve
65
- })
66
- const TaroMouseEvents = document.createEvent('MouseEvents')
67
- TaroMouseEvents.initEvent('click', true, true)
68
- taroChooseImageId.dispatchEvent(TaroMouseEvents)
69
- taroChooseImageId.onchange = function (e) {
70
- const arr = [...e.target.files]
71
- arr && arr.forEach(item => {
72
- const blob = new Blob([item], {
73
- type: item.type
74
- })
75
- const url = URL.createObjectURL(blob)
76
- res.tempFilePaths.push(url)
77
- res.tempFiles.push({ path: url, size: item.size, type: item.type, originalFileObj: item })
78
- })
79
- typeof success === 'function' && success(res)
80
- typeof complete === 'function' && complete(res)
81
- taroChooseImageCallback(res)
82
- e.target.value = ''
83
- }
84
- return taroChooseImagePromise
85
- }
86
-
87
- export default chooseImage
@@ -1,74 +0,0 @@
1
- // const ORIENTATION_MAP = {
2
- // // up 默认方向(手机横持拍照),对应 Exif 中的 1。或无 orientation 信息。
3
- // 1: 'up',
4
-
5
- // // up-mirrored 同 up,但镜像翻转,对应 Exif 中的 2
6
- // 2: 'up-mirrored',
7
-
8
- // // down 旋转180度,对应 Exif 中的 3
9
- // 3: 'down',
10
-
11
- // // down-mirrored 同 down,但镜像翻转,对应 Exif 中的 4
12
- // 4: 'down-mirrored',
13
-
14
- // // left-mirrored 同 left,但镜像翻转,对应 Exif 中的 5
15
- // 5: 'left-mirrored',
16
-
17
- // // right 顺时针旋转90度,对应 Exif 中的 6
18
- // 6: 'right',
19
-
20
- // // right-mirrored 同 right,但镜像翻转,对应 Exif 中的 7
21
- // 7: 'right-mirrored',
22
-
23
- // // left 逆时针旋转90度,对应 Exif 中的 8
24
- // 8: 'left'
25
- // }
26
-
27
- /**
28
- * @typedef {'up'|'up-mirrored'|'down'|'down-mirrored'|'left-mirrored'|'right'|'right-mirrored'|'left'} Orientation
29
- * @typedef ImageInfo object.success 回调函数的参数
30
- * @property {number} width 图片原始宽度,单位px。不考虑旋转。
31
- * @property {number} height 图片原始高度,单位px。不考虑旋转。
32
- * @property {string} path 图片的本地路径
33
- * @property {Orientation} orientation 拍照时设备方向
34
- * @property {string} type 图片格式
35
- */
36
-
37
- /**
38
- * 获取图片信息。网络图片需先配置download域名才能生效。
39
- * @param {Object} object 参数
40
- * @param {string} object.src 图片的路径,可以是相对路径、临时文件路径、存储文件路径、网络图片路径
41
- * @param {(res: ImageInfo) => void} [object.success] 接口调用成功的回调函数
42
- * @param {function} [object.fail] 接口调用失败的回调函数
43
- * @param {function} [object.complete] 接口调用结束的回调函数(调用成功、失败都会执行)
44
- */
45
- const getImageInfo = ({ src, success, fail, complete } = {}) => {
46
- return new Promise((resolve, reject) => {
47
- const onSuccess = res => {
48
- success && success(res)
49
- complete && complete()
50
- resolve(res)
51
- }
52
- const onError = res => {
53
- fail && fail(res)
54
- complete && complete()
55
- reject(res)
56
- }
57
- const image = new Image()
58
- image.onload = () => {
59
- onSuccess({
60
- errMsg: 'getImageInfo:ok',
61
- width: image.naturalWidth,
62
- height: image.naturalHeight
63
- })
64
- }
65
- image.onerror = e => {
66
- onError({
67
- errMsg: `getImageInfo:fail ${e.message}`
68
- })
69
- }
70
- image.src = src
71
- })
72
- }
73
-
74
- export default getImageInfo
@@ -1,7 +0,0 @@
1
- /**
2
- * previewImage api基于开源的React组件[react-wx-images-viewer](https://github.com/react-ld/react-wx-images-viewer)开发,感谢!
3
- */
4
-
5
- export { default as chooseImage } from './chooseImage'
6
- export { default as getImageInfo } from './getImageInfo'
7
- export { previewImage } from './previewImage'
@@ -1,94 +0,0 @@
1
- /**
2
- * 在新页面中全屏预览图片。预览的过程中用户可以进行保存图片、发送给朋友等操作。
3
- * @param {Object} options
4
- * @param {Array.<string>} options.urls 需要预览的图片链接列表。2.2.3 起支持云文件ID。
5
- * @param {string} [options.current=options.urls[0]] urls的第一张 当前显示图片的链接
6
- * @param {function} [options.success] 接口调用成功的回调函数
7
- * @param {function} [options.fail] 接口调用失败的回调函数
8
- * @param {function} [options.complete] 接口调用结束的回调函数(调用成功、失败都会执行)
9
- */
10
- export async function previewImage (options) {
11
- const container = document.createElement('div')
12
- container.classList.add('preview-image')
13
- container.style.cssText = `
14
- position: fixed;
15
- top: 0;
16
- left: 0;
17
- z-index: 1050;
18
- width: 100%;
19
- height: 100%;
20
- overflow: hidden;
21
- outline: 0;
22
- background-color: #111;
23
- `
24
- container.addEventListener('click', () => {
25
- container.remove()
26
- })
27
-
28
- const swiper = document.createElement('taro-swiper-core')
29
- swiper.full = true
30
-
31
- const { urls = [], current = '' } = options
32
-
33
- let children = []
34
- try {
35
- children = await Promise.all(
36
- urls.map(e => loadImage(e, options.fail))
37
- )
38
- } catch (error) {
39
- if (options.fail) {
40
- options.fail(error)
41
- }
42
- }
43
-
44
- for (let i = 0; i < children.length; i++) {
45
- const child = children[i]
46
- swiper.appendChild(child)
47
- }
48
-
49
- const currentIndex = urls.indexOf(current)
50
- swiper.current = currentIndex
51
-
52
- container.appendChild(swiper)
53
- document.body.appendChild(container)
54
-
55
- if (options.success) {
56
- options.success()
57
- }
58
-
59
- if (options.complete) {
60
- options.complete()
61
- }
62
- }
63
-
64
- function loadImage (url, fail) {
65
- return new Promise((resolve) => {
66
- const item = document.createElement('taro-swiper-item-core')
67
- item.style.cssText = `
68
- display: flex;
69
- align-items: start;
70
- justify-content: center;
71
- overflow-y: scroll;
72
- `
73
- const image = new Image()
74
- image.style.maxWidth = '100%'
75
- image.src = url
76
- const div = document.createElement('div')
77
- div.style.cssText = `
78
- display: flex;
79
- align-items: center;
80
- justify-content: center;
81
- max-width: 100%;
82
- min-height: 100%;
83
- `
84
- div.appendChild(image)
85
- item.appendChild(div)
86
- // Note: 等待图片加载完后返回,会导致轮播被卡住
87
- resolve(item)
88
- if (typeof fail === 'function') {
89
- image.addEventListener('error', (err) => {
90
- fail(err)
91
- })
92
- }
93
- })
94
- }
package/src/api/index.js DELETED
@@ -1,29 +0,0 @@
1
- /* 未支持的api */
2
- export * from './unsupportedApi'
3
-
4
- /* 已实现api */
5
- export * from './accelerometer'
6
- export * from './audio'
7
- export * from './canvas'
8
- export * from './clipboard'
9
- export * from './compass'
10
- export * from './createAnimation'
11
- export * from './createSelectorQuery'
12
- export * from './deviceMotion'
13
- export * from './fileTransfer'
14
- export * from './image'
15
- export * from './interactive'
16
- export * from './location'
17
- export * from './navigationBar'
18
- export * from './open'
19
- export * from './others'
20
- export * from './pullDownRefresh'
21
- export * from './request'
22
- export * from './scroll'
23
- export * from './storage'
24
- export * from './system'
25
- export * from './tabBar'
26
- export * from './vibrate'
27
- export * from './video'
28
- export * from './webSocket'
29
- export * from './window'
@@ -1,214 +0,0 @@
1
- import { inlineStyle, setTransform } from '../utils'
2
-
3
- const noop = function () {}
4
- export default class ActionSheet {
5
- options = {
6
- itemList: [],
7
- itemColor: '#000000',
8
- success: noop,
9
- fail: noop,
10
- complete: noop
11
- }
12
-
13
- style = {
14
- maskStyle: {
15
- position: 'fixed',
16
- 'z-index': '1000',
17
- top: '0',
18
- right: '0',
19
- left: '0',
20
- bottom: '0',
21
- background: 'rgba(0,0,0,0.6)'
22
- },
23
- actionSheetStyle: {
24
- 'z-index': '4999',
25
- position: 'fixed',
26
- left: '0',
27
- bottom: '0',
28
- '-webkit-transform': 'translate(0, 100%)',
29
- transform: 'translate(0, 100%)',
30
- width: '100%',
31
- 'line-height': '1.6',
32
- background: '#EFEFF4',
33
- '-webkit-transition': '-webkit-transform .3s',
34
- transition: 'transform .3s'
35
- },
36
- menuStyle: {
37
- 'background-color': '#FCFCFD'
38
- },
39
- cellStyle: {
40
- position: 'relative',
41
- padding: '10px 0',
42
- 'text-align': 'center',
43
- 'font-size': '18px'
44
- },
45
- cancelStyle: {
46
- 'margin-top': '6px',
47
- padding: '10px 0',
48
- 'text-align': 'center',
49
- 'font-size': '18px',
50
- color: '#000000',
51
- 'background-color': '#FCFCFD'
52
- }
53
- }
54
-
55
- lastConfig = {}
56
-
57
- create (options = {}) {
58
- // style
59
- const { maskStyle, actionSheetStyle, menuStyle, cellStyle, cancelStyle } = this.style
60
-
61
- // configuration
62
- const config = {
63
- ...this.options,
64
- ...options
65
- }
66
-
67
- this.lastConfig = config
68
-
69
- // wrapper
70
- this.el = document.createElement('div')
71
- this.el.className = 'taro__actionSheet'
72
- this.el.style.opacity = '0'
73
- this.el.style.transition = 'opacity 0.2s linear'
74
-
75
- // mask
76
- const mask = document.createElement('div')
77
- mask.setAttribute('style', inlineStyle(maskStyle))
78
-
79
- // actionSheet
80
- this.actionSheet = document.createElement('div')
81
- this.actionSheet.setAttribute('style', inlineStyle(actionSheetStyle))
82
-
83
- // menu
84
- this.menu = document.createElement('div')
85
- this.menu.setAttribute('style', inlineStyle({
86
- ...menuStyle,
87
- color: config.itemColor
88
- }))
89
-
90
- // cells
91
- this.cells = config.itemList.map((item, index) => {
92
- const cell = document.createElement('div')
93
- cell.className = 'taro-actionsheet__cell'
94
- cell.setAttribute('style', inlineStyle(cellStyle))
95
- cell.textContent = item
96
- cell.dataset.tapIndex = index
97
- cell.onclick = e => this.onCellClick(e)
98
- return cell
99
- })
100
-
101
- // cancel
102
- this.cancel = document.createElement('div')
103
- this.cancel.setAttribute('style', inlineStyle(cancelStyle))
104
- this.cancel.textContent = '取消'
105
-
106
- // result
107
- this.cells.forEach(item => this.menu.appendChild(item))
108
- this.actionSheet.appendChild(this.menu)
109
- this.actionSheet.appendChild(this.cancel)
110
- this.el.appendChild(mask)
111
- this.el.appendChild(this.actionSheet)
112
-
113
- // callbacks
114
- const cb = () => {
115
- this.hide()
116
- const res = { errMsg: 'showActionSheet:fail cancel' }
117
- config.fail(res)
118
- config.complete(res)
119
- this.rejectHandler(res)
120
- }
121
- mask.onclick = cb
122
- this.cancel.onclick = cb
123
-
124
- // show immediately
125
- document.body.appendChild(this.el)
126
- setTimeout(() => {
127
- this.el.style.opacity = '1'
128
- setTransform(this.actionSheet, 'translate(0, 0)')
129
- }, 0)
130
-
131
- return new Promise((resolve, reject) => {
132
- this.resolveHandler = resolve
133
- this.rejectHandler = reject
134
- })
135
- }
136
-
137
- show (options = {}) {
138
- const config = {
139
- ...this.options,
140
- ...options
141
- }
142
-
143
- this.lastConfig = config
144
-
145
- if (this.hideOpacityTimer) clearTimeout(this.hideOpacityTimer)
146
- if (this.hideDisplayTimer) clearTimeout(this.hideDisplayTimer)
147
-
148
- // itemColor
149
- if (config.itemColor) this.menu.style.color = config.itemColor
150
-
151
- // cells
152
- const { cellStyle } = this.style
153
-
154
- config.itemList.forEach((item, index) => {
155
- let cell
156
- if (this.cells[index]) {
157
- // assign new content
158
- cell = this.cells[index]
159
- } else {
160
- // create new cell
161
- cell = document.createElement('div')
162
- cell.className = 'taro-actionsheet__cell'
163
- cell.setAttribute('style', inlineStyle(cellStyle))
164
- cell.dataset.tapIndex = index
165
- this.cells.push(cell)
166
- this.menu.appendChild(cell)
167
- }
168
- cell.textContent = item
169
- cell.onclick = e => this.onCellClick(e)
170
- })
171
- const cellsLen = this.cells.length
172
- const itemListLen = config.itemList.length
173
- if (cellsLen > itemListLen) {
174
- for (let i = itemListLen; i < cellsLen; i++) {
175
- this.menu.removeChild(this.cells[i])
176
- }
177
- this.cells.splice(itemListLen)
178
- }
179
-
180
- // show
181
- this.el.style.display = 'block'
182
- setTimeout(() => {
183
- this.el.style.opacity = '1'
184
- setTransform(this.actionSheet, 'translate(0, 0)')
185
- }, 0)
186
-
187
- return new Promise((resolve, reject) => {
188
- this.resolveHandler = resolve
189
- this.rejectHandler = reject
190
- })
191
- }
192
-
193
- onCellClick (e) {
194
- this.hide()
195
- const res = {
196
- errMsg: 'showActionSheet:ok',
197
- tapIndex: +e.currentTarget.dataset.tapIndex
198
- }
199
- this.lastConfig.success && this.lastConfig.success(res)
200
- this.lastConfig.complete && this.lastConfig.complete(res)
201
- this.resolveHandler(res)
202
- }
203
-
204
- hide () {
205
- if (this.hideOpacityTimer) clearTimeout(this.hideOpacityTimer)
206
- if (this.hideDisplayTimer) clearTimeout(this.hideDisplayTimer)
207
-
208
- this.hideOpacityTimer = setTimeout(() => {
209
- this.el.style.opacity = '0'
210
- setTransform(this.actionSheet, 'translate(0, 100%)')
211
- this.hideDisplayTimer = setTimeout(() => { this.el.style.display = 'none' }, 200)
212
- }, 0)
213
- }
214
- }