@tarojs/taro-h5 3.4.0-beta.2 → 3.4.0-beta.3

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 (147) 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 +4626 -6915
  131. package/dist/index.js +4 -10767
  132. package/dist/types/type.js +2 -0
  133. package/package.json +10 -13
  134. package/src/api/canvas/CanvasContext.ts +35 -32
  135. package/src/api/canvas/createCanvasContext.ts +2 -2
  136. package/src/api/location/chooseLocation.ts +2 -2
  137. package/src/api/media/audio/index.ts +16 -16
  138. package/src/api/media/image/previewImage.ts +4 -25
  139. package/src/api/network/download.ts +5 -5
  140. package/src/api/network/upload.ts +5 -5
  141. package/src/api/network/websocket/index.ts +1 -1
  142. package/src/api/ui/animation/index.ts +1 -6
  143. package/src/api/ui/interaction/index.ts +6 -4
  144. package/src/api/ui/navigation-bar/index.ts +1 -1
  145. package/src/api/wxml/nodesRef.ts +10 -3
  146. package/src/api/wxml/selectorQuery.ts +68 -23
  147. package/src/index.ts +2 -2
@@ -0,0 +1,2 @@
1
+ const TaroH5 = {};
2
+ export default TaroH5;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tarojs/taro-h5",
3
- "version": "3.4.0-beta.2",
3
+ "version": "3.4.0-beta.3",
4
4
  "description": "Taro h5 framework",
5
5
  "main:h5": "dist/index.js",
6
6
  "main": "dist/index.cjs.js",
@@ -10,17 +10,14 @@
10
10
  "src",
11
11
  "index.js"
12
12
  ],
13
- "sideEffects": [
14
- "*.scss",
15
- "*.css",
16
- "./src/taro/index.js"
17
- ],
13
+ "sideEffects": false,
18
14
  "scripts": {
19
15
  "test": "jest",
20
16
  "test:dev": "jest --watch",
21
17
  "test:coverage": "jest --coverage",
22
- "build": "rollup -c",
23
- "dev": "rollup -cw"
18
+ "copy:assets": "copy src/**/*.css dist",
19
+ "build": "tsc & npm run copy:assets & rollup -c",
20
+ "dev": "tsc -w & npm run copy:assets"
24
21
  },
25
22
  "repository": {
26
23
  "type": "git",
@@ -32,14 +29,14 @@
32
29
  "author": "O2Team",
33
30
  "license": "MIT",
34
31
  "dependencies": {
35
- "@tarojs/api": "3.4.0-beta.2",
36
- "@tarojs/router": "3.4.0-beta.2",
37
- "@tarojs/runtime": "3.4.0-beta.2",
38
- "@tarojs/taro": "3.4.0-beta.2",
32
+ "@tarojs/api": "3.4.0-beta.3",
33
+ "@tarojs/router": "3.4.0-beta.3",
34
+ "@tarojs/runtime": "3.4.0-beta.3",
35
+ "@tarojs/taro": "3.4.0-beta.3",
39
36
  "base64-js": "^1.3.0",
40
37
  "jsonp-retry": "^1.0.3",
41
38
  "mobile-detect": "^1.4.2",
42
39
  "whatwg-fetch": "^3.4.0"
43
40
  },
44
- "gitHead": "ac3eb29f11aec15d25e061775d9e970efabc2c98"
41
+ "gitHead": "2ef7e8c10c9e5784e98bb1ad3a803d5fd6a46c8b"
45
42
  }
@@ -16,12 +16,17 @@ export class CanvasContext implements Taro.CanvasContext {
16
16
  __raw__: CanvasRenderingContext2D
17
17
  actions: IAction[] = []
18
18
 
19
+ constructor (canvas, ctx) {
20
+ this.canvas = canvas
21
+ this.ctx = ctx
22
+ }
23
+
19
24
  set ctx (e: CanvasRenderingContext2D) {
20
25
  this.__raw__ = e
21
26
  }
22
27
 
23
28
  get ctx () {
24
- return this.__raw__
29
+ return this.__raw__ || {}
25
30
  }
26
31
 
27
32
  canvas: HTMLCanvasElement
@@ -30,13 +35,11 @@ export class CanvasContext implements Taro.CanvasContext {
30
35
  this.actions.length = 0
31
36
  }
32
37
 
33
- protected enqueueActions (func: IAction['func']) {
34
- return (...args) => {
35
- this.actions.push({
36
- func,
37
- args
38
- })
39
- }
38
+ protected enqueueActions (func: IAction['func'], ...args) {
39
+ this.actions.push({
40
+ func,
41
+ args
42
+ })
40
43
  }
41
44
 
42
45
  set fillStyle (e) { this.enqueueActions(() => { this.ctx.fillStyle = e }) }
@@ -82,13 +85,13 @@ export class CanvasContext implements Taro.CanvasContext {
82
85
  get filter () { return this.ctx.filter }
83
86
  /** 小程序文档中不包括 ↑↑↑ */
84
87
 
85
- arc = this.enqueueActions(this.ctx.arc)
86
- arcTo = this.enqueueActions(this.ctx.arcTo)
87
- beginPath = this.enqueueActions(this.ctx.beginPath)
88
- bezierCurveTo = this.enqueueActions(this.ctx.bezierCurveTo)
89
- clearRect = this.enqueueActions(this.ctx.clearRect)
90
- clip = this.enqueueActions(this.ctx.clip)
91
- closePath = this.enqueueActions(this.ctx.closePath)
88
+ arc (...args) { return this.enqueueActions(this.ctx.arc, ...args) }
89
+ arcTo (...args) { return this.enqueueActions(this.ctx.arcTo, ...args) }
90
+ beginPath (...args) { return this.enqueueActions(this.ctx.beginPath, ...args) }
91
+ bezierCurveTo (...args) { return this.enqueueActions(this.ctx.bezierCurveTo, ...args) }
92
+ clearRect (...args) { return this.enqueueActions(this.ctx.clearRect, ...args) }
93
+ clip (...args) { return this.enqueueActions(this.ctx.clip, ...args) }
94
+ closePath (...args) { return this.enqueueActions(this.ctx.closePath, ...args) }
92
95
 
93
96
  createPattern (image: string, repetition: keyof Taro.CanvasContext.repetition): void {
94
97
  return this.createPattern(image, repetition)
@@ -139,17 +142,17 @@ export class CanvasContext implements Taro.CanvasContext {
139
142
  })
140
143
  }
141
144
 
142
- fill = this.enqueueActions(this.ctx.fill)
143
- fillRect = this.enqueueActions(this.ctx.fillRect)
144
- fillText = this.enqueueActions(this.ctx.fillText)
145
- lineTo = this.enqueueActions(this.ctx.lineTo)
146
- moveTo = this.enqueueActions(this.ctx.moveTo)
147
- quadraticCurveTo = this.enqueueActions(this.ctx.quadraticCurveTo)
148
- rect = this.enqueueActions(this.ctx.rect)
149
- restore = this.enqueueActions(this.ctx.restore)
150
- rotate = this.enqueueActions(this.ctx.rotate)
151
- save = this.enqueueActions(this.ctx.save)
152
- scale = this.enqueueActions(this.ctx.scale)
145
+ fill (...args) { return this.enqueueActions(this.ctx.fill, ...args) }
146
+ fillRect (...args) { return this.enqueueActions(this.ctx.fillRect, ...args) }
147
+ fillText (...args) { return this.enqueueActions(this.ctx.fillText, ...args) }
148
+ lineTo (...args) { return this.enqueueActions(this.ctx.lineTo, ...args) }
149
+ moveTo (...args) { return this.enqueueActions(this.ctx.moveTo, ...args) }
150
+ quadraticCurveTo (...args) { return this.enqueueActions(this.ctx.quadraticCurveTo, ...args) }
151
+ rect (...args) { return this.enqueueActions(this.ctx.rect, ...args) }
152
+ restore (...args) { return this.enqueueActions(this.ctx.restore, ...args) }
153
+ rotate (...args) { return this.enqueueActions(this.ctx.rotate, ...args) }
154
+ save (...args) { return this.enqueueActions(this.ctx.save, ...args) }
155
+ scale (...args) { return this.enqueueActions(this.ctx.scale, ...args) }
153
156
 
154
157
  setFillStyle (color: string | CanvasGradient): void {
155
158
  this.enqueueActions(() => { this.ctx.fillStyle = color })
@@ -207,12 +210,12 @@ export class CanvasContext implements Taro.CanvasContext {
207
210
  this.textBaseline = TextBaseLineMap[textBaseline] || 'alphabetic'
208
211
  }
209
212
 
210
- setTransform = this.enqueueActions(this.ctx.setTransform)
211
- stroke = this.enqueueActions(this.ctx.stroke)
212
- strokeRect = this.enqueueActions(this.ctx.strokeRect)
213
- strokeText = this.enqueueActions(this.ctx.strokeText)
214
- transform = this.enqueueActions(this.ctx.transform)
215
- translate = this.enqueueActions(this.ctx.translate)
213
+ setTransform (...args) { return this.enqueueActions(this.ctx.setTransform, ...args) }
214
+ stroke (...args) { return this.enqueueActions(this.ctx.stroke, ...args) }
215
+ strokeRect (...args) { return this.enqueueActions(this.ctx.strokeRect, ...args) }
216
+ strokeText (...args) { return this.enqueueActions(this.ctx.strokeText, ...args) }
217
+ transform (...args) { return this.enqueueActions(this.ctx.transform, ...args) }
218
+ translate (...args) { return this.enqueueActions(this.ctx.translate, ...args) }
216
219
 
217
220
  measureText (text: string): TextMetrics {
218
221
  return this.measureText(text)
@@ -6,10 +6,10 @@ import { CanvasContext } from './CanvasContext'
6
6
  * 创建 canvas 的绘图上下文 CanvasContext 对象
7
7
  */
8
8
  export const createCanvasContext: typeof Taro.createCanvasContext = (canvasId, inst) => {
9
- const context = new CanvasContext()
10
9
  const el = findDOM(inst) as HTMLElement
11
10
  const canvas = el?.querySelector(`canvas[canvas-id="${canvasId}"]`) as HTMLCanvasElement
12
- const ctx = canvas?.getContext('2d')
11
+ const ctx = canvas?.getContext('2d') as CanvasRenderingContext2D
12
+ const context = new CanvasContext(canvas, ctx)
13
13
  if (!ctx) return context
14
14
  context.canvas = canvas
15
15
  context.ctx = ctx
@@ -28,13 +28,13 @@ function createLocationChooser (handler, key = LOCATION_APIKEY) {
28
28
  }
29
29
 
30
30
  function back () {
31
- handler({ errMsg: 'cancel' })
32
31
  hide()
32
+ handler({ errMsg: 'cancel' })
33
33
  }
34
34
 
35
35
  function submit () {
36
- handler()
37
36
  hide()
37
+ handler()
38
38
  }
39
39
 
40
40
  function remove () {
@@ -67,26 +67,26 @@ class InnerAudioContext implements Taro.InnerAudioContext {
67
67
  }
68
68
  }
69
69
 
70
- onCanplay = (callback = () => {}) => this.Instance?.addEventListener('oncanplay', callback)
71
- onPlay = (callback = () => {}) => this.Instance?.addEventListener('onplay', callback)
72
- onPause = (callback = () => {}) => this.Instance?.addEventListener('onpause', callback)
70
+ onCanplay = (callback = () => {}) => this.Instance?.addEventListener('canplay', callback)
71
+ onPlay = (callback = () => {}) => this.Instance?.addEventListener('play', callback)
72
+ onPause = (callback = () => {}) => this.Instance?.addEventListener('pause', callback)
73
73
  onStop = (callback = () => {}) => this.stopStack.add(callback)
74
- onEnded = (callback = () => {}) => this.Instance?.addEventListener('onended', callback)
75
- onTimeUpdate = (callback = () => {}) => this.Instance?.addEventListener('ontimeUpdate', callback)
74
+ onEnded = (callback = () => {}) => this.Instance?.addEventListener('ended', callback)
75
+ onTimeUpdate = (callback = () => {}) => this.Instance?.addEventListener('timeupdate', callback)
76
76
  onError = (callback?: ((res: Taro.InnerAudioContext.onErrorDetail) => void)) => this.errorStack.add(callback)
77
- onWaiting = (callback = () => {}) => this.Instance?.addEventListener('onwaiting', callback)
78
- onSeeking = (callback = () => {}) => this.Instance?.addEventListener('onseeking', callback)
79
- onSeeked = (callback = () => {}) => this.Instance?.addEventListener('onseeked', callback)
80
- offCanplay = (callback = () => {}) => this.Instance?.removeEventListener('offcanplay', callback)
81
- offPlay = (callback = () => {}) => this.Instance?.removeEventListener('offplay', callback)
82
- offPause = (callback = () => {}) => this.Instance?.removeEventListener('offpause', callback)
77
+ onWaiting = (callback = () => {}) => this.Instance?.addEventListener('waiting', callback)
78
+ onSeeking = (callback = () => {}) => this.Instance?.addEventListener('seeking', callback)
79
+ onSeeked = (callback = () => {}) => this.Instance?.addEventListener('seeked', callback)
80
+ offCanplay = (callback = () => {}) => this.Instance?.removeEventListener('canplay', callback)
81
+ offPlay = (callback = () => {}) => this.Instance?.removeEventListener('play', callback)
82
+ offPause = (callback = () => {}) => this.Instance?.removeEventListener('pause', callback)
83
83
  offStop = (callback = () => {}) => this.stopStack.remove(callback)
84
- offEnded = (callback = () => {}) => this.Instance?.removeEventListener('offended', callback)
85
- offTimeUpdate = (callback = () => {}) => this.Instance?.removeEventListener('offtimeUpdate', callback)
84
+ offEnded = (callback = () => {}) => this.Instance?.removeEventListener('ended', callback)
85
+ offTimeUpdate = (callback = () => {}) => this.Instance?.removeEventListener('timeupdate', callback)
86
86
  offError = (callback = () => {}) => this.errorStack.remove(callback)
87
- offWaiting = (callback = () => {}) => this.Instance?.removeEventListener('offwaiting', callback)
88
- offSeeking = (callback = () => {}) => this.Instance?.removeEventListener('offseeking', callback)
89
- offSeeked = (callback = () => {}) => this.Instance?.removeEventListener('offseeked', callback)
87
+ offWaiting = (callback = () => {}) => this.Instance?.removeEventListener('waiting', callback)
88
+ offSeeking = (callback = () => {}) => this.Instance?.removeEventListener('seeking', callback)
89
+ offSeeked = (callback = () => {}) => this.Instance?.removeEventListener('seeked', callback)
90
90
  }
91
91
 
92
92
  export const stopVoice = temporarilyNotSupport('stopVoice')
@@ -1,4 +1,4 @@
1
- import Taro from '@tarojs/taro'
1
+ import Taro from '@tarojs/api'
2
2
 
3
3
  import { shouldBeObject } from '../../utils'
4
4
  import { MethodHandler } from '../../utils/handler'
@@ -14,23 +14,12 @@ export const previewImage: typeof Taro.previewImage = async (options) => {
14
14
  function loadImage (url: string, loadFail: typeof fail): Promise<Node> {
15
15
  return new Promise((resolve) => {
16
16
  const item = document.createElement('taro-swiper-item-core')
17
- item.style.cssText = `
18
- display: flex;
19
- align-items: start;
20
- justify-content: center;
21
- overflow-y: scroll;
22
- `
17
+ item.style.cssText = 'display:flex;align-items:start;justify-content:center;overflow-y:scroll;'
23
18
  const image = new Image()
24
19
  image.style.maxWidth = '100%'
25
20
  image.src = url
26
21
  const div = document.createElement('div')
27
- div.style.cssText = `
28
- display: flex;
29
- align-items: center;
30
- justify-content: center;
31
- max-width: 100%;
32
- min-height: 100%;
33
- `
22
+ div.style.cssText = 'display:flex;align-items:center;justify-content:center;max-width:100%;min-height:100%;'
34
23
  div.appendChild(image)
35
24
  item.appendChild(div)
36
25
  // Note: 等待图片加载完后返回,会导致轮播被卡住
@@ -55,17 +44,7 @@ export const previewImage: typeof Taro.previewImage = async (options) => {
55
44
  const handle = new MethodHandler({ name: 'previewImage', success, fail, complete })
56
45
  const container = document.createElement('div')
57
46
  container.classList.add('preview-image')
58
- container.style.cssText = `
59
- position: fixed;
60
- top: 0;
61
- left: 0;
62
- z-index: 1050;
63
- width: 100%;
64
- height: 100%;
65
- overflow: hidden;
66
- outline: 0;
67
- background-color: #111;
68
- `
47
+ container.style.cssText = 'position:fixed;top:0;left:0;z-index:1050;width:100%;height:100%;overflow:hidden;outline:0;background-color:#111;'
69
48
  container.addEventListener('click', () => {
70
49
  container.remove()
71
50
  })
@@ -114,7 +114,7 @@ const createDownloadTask = ({ url, header, success, error }): Taro.DownloadTask
114
114
  * 注意:请在服务端响应的 header 中指定合理的 Content-Type 字段,以保证客户端正确处理文件类型。
115
115
  */
116
116
  export const downloadFile: typeof Taro.downloadFile = ({ url, header, success, fail, complete }) => {
117
- let task: Taro.DownloadTask
117
+ let task!: Taro.DownloadTask
118
118
  const result: ReturnType<typeof Taro.downloadFile> = new Promise((resolve, reject) => {
119
119
  task = createDownloadTask({
120
120
  url,
@@ -130,11 +130,11 @@ export const downloadFile: typeof Taro.downloadFile = ({ url, header, success, f
130
130
  reject(res)
131
131
  }
132
132
  })
133
-
134
- result.headersReceive = task.onHeadersReceived
135
- result.progress = task.onProgressUpdate
136
- result.abort = task.abort
137
133
  }) as any
138
134
 
135
+ result.headersReceive = task.onHeadersReceived
136
+ result.progress = task.onProgressUpdate
137
+ result.abort = task.abort
138
+
139
139
  return result
140
140
  }
@@ -143,7 +143,7 @@ const createUploadTask = ({ url, filePath, formData, name, header, timeout, file
143
143
  * 将本地资源上传到服务器。客户端发起一个 HTTPS POST 请求,其中 content-type 为 multipart/form-data。使用前请注意阅读相关说明。
144
144
  */
145
145
  export const uploadFile: typeof Taro.uploadFile = ({ url, filePath, name, header, formData, timeout, fileName, success, fail, complete }) => {
146
- let task: Taro.UploadTask
146
+ let task!: Taro.UploadTask
147
147
  const result: ReturnType<typeof Taro.uploadFile> = new Promise((resolve, reject) => {
148
148
  task = createUploadTask({
149
149
  url,
@@ -164,11 +164,11 @@ export const uploadFile: typeof Taro.uploadFile = ({ url, filePath, name, header
164
164
  reject(res)
165
165
  }
166
166
  })
167
-
168
- result.headersReceive = task.onHeadersReceived
169
- result.progress = task.onProgressUpdate
170
- result.abort = task.abort
171
167
  }) as any
172
168
 
169
+ result.headersReceive = task.onHeadersReceived
170
+ result.progress = task.onProgressUpdate
171
+ result.abort = task.abort
172
+
173
173
  return result
174
174
  }
@@ -1,6 +1,6 @@
1
1
  import { SocketTask } from './socketTask'
2
2
  import { shouldBeObject, getParameterError } from '../../utils'
3
- import { MethodHandler } from 'src/api/utils/handler'
3
+ import { MethodHandler } from '../../utils/handler'
4
4
 
5
5
  let socketTasks: SocketTask[] = []
6
6
  let socketsCounter = 1
@@ -38,12 +38,7 @@ let TRANSITION_END = 'transitionend'
38
38
  let TRANSFORM = 'transform'
39
39
 
40
40
  const $detect = document.createElement('div')
41
- $detect.style.cssText = `
42
- -webkit-animation-name: webkit;
43
- -moz-animation-name: moz;
44
- -ms-animation-name: ms;
45
- animation-name: standard;
46
- `
41
+ $detect.style.cssText = '-webkit-animation-name:webkit;-moz-animation-name:moz;-ms-animation-name:ms;animation-name:standard;'
47
42
  if ($detect.style['animation-name'] === 'standard') {
48
43
  // 支持标准写法
49
44
  TRANSITION_END = 'transitionend'
@@ -209,13 +209,15 @@ const showModal: typeof Taro.showModal = async (options = {}) => {
209
209
 
210
210
  options.showCancel = !!options.showCancel
211
211
 
212
- let errMsg = ''
212
+ let result = ''
213
213
  if (!modal.el) {
214
- errMsg = await modal.create(options)
214
+ result = await modal.create(options)
215
215
  } else {
216
- errMsg = await modal.show(options)
216
+ result = await modal.show(options)
217
217
  }
218
- return handle.success({ errMsg })
218
+ const res = { cancel: !1, confirm: !1 }
219
+ res[result] = !0
220
+ return handle.success(res)
219
221
  }
220
222
 
221
223
  function hideModal () {
@@ -1,4 +1,4 @@
1
- import Taro from '@tarojs/taro'
1
+ import Taro from '@tarojs/api'
2
2
 
3
3
  import { MethodHandler } from '../../utils/handler'
4
4
  import { getParameterError, shouldBeObject, temporarilyNotSupport } from '../../utils'
@@ -1,4 +1,3 @@
1
- import { temporarilyNotSupport } from '../utils'
2
1
  import { SelectorQuery } from './selectorQuery'
3
2
 
4
3
  export class NodesRef implements Taro.NodesRef {
@@ -14,9 +13,17 @@ export class NodesRef implements Taro.NodesRef {
14
13
  this._single = single
15
14
  }
16
15
 
17
- context = temporarilyNotSupport('NodesRef.context') as unknown as Taro.NodesRef['context']
16
+ context (cb) {
17
+ const { _selector, _component, _single, _selectorQuery } = this
18
+ _selectorQuery._push(_selector, _component, _single, { context: !0 }, cb)
19
+ return _selectorQuery
20
+ }
18
21
 
19
- node = temporarilyNotSupport('NodesRef.node') as unknown as Taro.NodesRef['node']
22
+ node (cb) {
23
+ const { _selector, _component, _single, _selectorQuery } = this
24
+ _selectorQuery._push(_selector, _component, _single, { nodeCanvasType: !0, node: !0 }, cb)
25
+ return _selectorQuery
26
+ }
20
27
 
21
28
  boundingClientRect (cb) {
22
29
  const { _selector, _component, _single, _selectorQuery } = this
@@ -1,4 +1,5 @@
1
1
  import Taro from '@tarojs/api'
2
+ import { CanvasContext } from '../canvas/CanvasContext'
2
3
  import { findDOM } from '../utils'
3
4
  import { NodesRef } from './nodesRef'
4
5
 
@@ -16,33 +17,77 @@ type TSelectorQueryQueueCallback = (res: ISelectorQueryQueue) => void
16
17
  function filter (fields, dom?: HTMLElement, selector?: string) {
17
18
  if (!dom) return null
18
19
 
19
- const { id, dataset, rect, size, scrollOffset, properties = [], computedStyle = [] } = fields
20
- const { left, right, top, bottom, width, height } = dom.getBoundingClientRect()
21
- const isViewport = selector === 'html'
20
+ const isViewport = selector === '.taro_page'
21
+ const { id, dataset, rect, size, scrollOffset, properties = [], computedStyle = [], nodeCanvasType, node, context } = fields
22
22
  const res: any = {}
23
23
 
24
- if (id) res.id = dom.id
25
- if (dataset) res.dataset = Object.assign({}, dom.dataset)
26
- if (rect) {
27
- if (!isViewport) {
28
- res.left = left
29
- res.right = right
30
- res.top = top
31
- res.bottom = bottom
24
+ if (nodeCanvasType && node) {
25
+ const tagName = dom.tagName
26
+ res.node = {
27
+ id: dom.id,
28
+ $taroElement: dom
29
+ }
30
+ if (/^taro-canvas-core/i.test(tagName)) {
31
+ const type = (dom as any).type! || ''
32
+ res.nodeCanvasType = type
33
+ const canvas = dom.getElementsByTagName('canvas')[0]
34
+ if (/^(2d|webgl)/i.test(type) && canvas) {
35
+ res.node = canvas
36
+ } else {
37
+ res.node = null
38
+ }
32
39
  } else {
33
- res.left = 0
34
- res.right = 0
35
- res.top = 0
36
- res.bottom = 0
40
+ // TODO https://developers.weixin.qq.com/miniprogram/dev/component/scroll-view.html
41
+ // if (/^taro-scroll-view-core/i.test(tagName))
42
+ res.nodeCanvasType = ''
43
+ res.node = dom
37
44
  }
45
+ return res
38
46
  }
39
- if (size) {
40
- if (!isViewport) {
41
- res.width = width
42
- res.height = height
43
- } else {
44
- res.width = dom.clientWidth
45
- res.height = dom.clientHeight
47
+ if (context) {
48
+ const tagName = dom.tagName
49
+ if (/^taro-video-core/i.test(tagName)) {
50
+ // TODO HTMLVideoElement to VideoContext
51
+ return { context: dom as unknown as Taro.VideoContext }
52
+ } else if (/^taro-canvas-core/i.test(tagName)) {
53
+ const type = (dom as any).type! || '2d'
54
+ const canvas = dom?.querySelector('canvas') as HTMLCanvasElement
55
+ const ctx = canvas?.getContext(type) as CanvasRenderingContext2D
56
+ return { context: new CanvasContext(canvas, ctx) }
57
+ } else if (/^taro-live-player-core/i.test(tagName)) {
58
+ console.error('暂时不支持通过 NodesRef.context 获取 LivePlayerContext')
59
+ } else if (/^taro-editor-core/i.test(tagName)) {
60
+ console.error('暂时不支持通过 NodesRef.context 获取 EditorContext')
61
+ } else if (/^taro-map-core/i.test(tagName)) {
62
+ console.error('暂时不支持通过 NodesRef.context 获取 MapContext')
63
+ }
64
+ return
65
+ }
66
+ if (id) res.id = dom.id
67
+ if (dataset) res.dataset = Object.assign({}, dom.dataset)
68
+ if (rect || size) {
69
+ const { left, right, top, bottom, width, height } = dom.getBoundingClientRect()
70
+ if (rect) {
71
+ if (!isViewport) {
72
+ res.left = left
73
+ res.right = right
74
+ res.top = top
75
+ res.bottom = bottom
76
+ } else {
77
+ res.left = 0
78
+ res.right = 0
79
+ res.top = 0
80
+ res.bottom = 0
81
+ }
82
+ }
83
+ if (size) {
84
+ if (!isViewport) {
85
+ res.width = width
86
+ res.height = height
87
+ } else {
88
+ res.width = dom.clientWidth
89
+ res.height = dom.clientHeight
90
+ }
46
91
  }
47
92
  }
48
93
  if (scrollOffset) {
@@ -147,7 +192,7 @@ export class SelectorQuery implements Taro.SelectorQuery {
147
192
  }
148
193
 
149
194
  selectViewport () {
150
- return new NodesRef('html', this, true)
195
+ return new NodesRef('.taro_page', this, true)
151
196
  }
152
197
 
153
198
  exec (cb) {
package/src/index.ts CHANGED
@@ -1,6 +1,6 @@
1
- import Taro from './api/taro'
1
+ import taro from './api/taro'
2
2
 
3
3
  export * from './api/index'
4
4
  export * from './api/taro'
5
5
 
6
- export default Taro
6
+ export default taro