@mpxjs/api-proxy 2.7.28 → 2.7.49

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/api-proxy",
3
- "version": "2.7.28",
3
+ "version": "2.7.49",
4
4
  "description": "convert miniprogram API at each end",
5
5
  "module": "src/index.js",
6
6
  "types": "@types/index.d.ts",
@@ -39,5 +39,5 @@
39
39
  "dependencies": {
40
40
  "axios": "^0.21.1"
41
41
  },
42
- "gitHead": "7f62d5dca1b523570369900d92ab1d86decba974"
42
+ "gitHead": "d24eb21aeb7b11087d5aaaffb1047e7344bfe9cf"
43
43
  }
@@ -27,7 +27,8 @@ const blackList = [
27
27
  'reportAnalytics',
28
28
  'getMenuButtonBoundingClientRect',
29
29
  'reportMonitor',
30
- 'createOffscreenCanvas'
30
+ 'createOffscreenCanvas',
31
+ 'reportEvent'
31
32
  ]
32
33
 
33
34
  function getMapFromList (list) {
@@ -0,0 +1,127 @@
1
+ import { nextTick } from '../next-tick'
2
+
3
+ let isInit = true
4
+
5
+ class WebIntersectionObserver {
6
+ constructor (_component, options) {
7
+ this._component = _component
8
+ this._options = options || {}
9
+ this._relativeInfo = []
10
+ this._callback = null
11
+ this._observer = null
12
+ this._root = null
13
+ this._rootMargin = ''
14
+ this._disconnected = false
15
+ this._minThreshold = this.getMinThreshold()
16
+ }
17
+
18
+ initObserver () {
19
+ if (this._observer) {
20
+ this._observer = null
21
+ }
22
+ this._disconnected = false
23
+ // eslint-disable-next-line no-undef
24
+ return new IntersectionObserver((entries, observer) => {
25
+ const initialRatio = this._options.initialRatio || 0
26
+ entries.forEach(entry => {
27
+ if (!isInit || (isInit && (entry.intersectionRatio !== initialRatio && (this._minThreshold <= entry.intersectionRatio)))) {
28
+ Object.defineProperties(entry, {
29
+ id: {
30
+ value: entry.target.getAttribute('id') || '',
31
+ writable: false,
32
+ enumerable: true,
33
+ configurable: true
34
+ },
35
+ dataset: {
36
+ value: entry.target.dataset || {},
37
+ writable: false,
38
+ enumerable: true,
39
+ configurable: true
40
+ },
41
+ relativeRect: {
42
+ value: entry.rootBounds || {},
43
+ writable: false,
44
+ enumerable: true,
45
+ configurable: true
46
+ },
47
+ time: {
48
+ value: new Date().valueOf(),
49
+ writable: false,
50
+ enumerable: true,
51
+ configurable: true
52
+ }
53
+ })
54
+ this._callback && this._callback(entry)
55
+ }
56
+ })
57
+ isInit = false
58
+ }, {
59
+ root: this._root || null,
60
+ rootMargin: this._rootMargin,
61
+ threshold: this._options.thresholds || [0]
62
+ })
63
+ }
64
+
65
+ observe (targetSelector, callback) {
66
+ nextTick(async () => {
67
+ if (!targetSelector) {
68
+ const res = { errMsg: 'observe:targetSelector can not be empty' }
69
+ return Promise.reject(res)
70
+ }
71
+ this._observer = await this.initObserver()
72
+ this._callback = callback
73
+ let targetElement = []
74
+ if (this._options.observeAll) {
75
+ targetElement = [...document.querySelectorAll(targetSelector)]
76
+ } else {
77
+ targetElement = [document.querySelector(targetSelector)]
78
+ }
79
+ targetElement.forEach((element) => {
80
+ this._observer && this._observer.observe(element)
81
+ })
82
+ })
83
+ }
84
+
85
+ relativeTo (selector, margins) {
86
+ nextTick(() => {
87
+ const marginsTemp = margins || {}
88
+ const { left = 0, right = 0, top = 0, bottom = 0 } = marginsTemp
89
+ this._root = document.querySelector(selector)
90
+ this._rootMargin = `${top}px ${right}px ${bottom}px ${left}px`
91
+ this._relativeInfo.push({ selector, margins })
92
+ })
93
+ return this
94
+ }
95
+
96
+ relativeToViewport (margins) {
97
+ nextTick(() => {
98
+ const marginsTemp = margins || {}
99
+ const { left = 0, right = 0, top = 0, bottom = 0 } = marginsTemp
100
+ this._root = document.querySelector('html')
101
+ const viewportWidth = window.innerWidth || document.documentElement.clientWidth
102
+ const viewportHeight = window.innerHeight || document.documentElement.clientHeight
103
+ const rootWidth = this._root.offsetWidth || 0
104
+ const rootHeight = this._root.offsetHeight || 0
105
+ if (rootHeight >= viewportHeight) {
106
+ this._rootMargin = `${top}px ${viewportWidth - rootWidth + right}px ${viewportHeight - rootHeight + bottom}px ${left}px`
107
+ } else {
108
+ this._rootMargin = `${top}px ${right}px ${bottom}px ${left}px`
109
+ }
110
+ this._relativeInfo.push({ selector: null, margins })
111
+ })
112
+ return this
113
+ }
114
+
115
+ disconnect () {
116
+ this._disconnected = true
117
+ this._observer.disconnect()
118
+ }
119
+
120
+ getMinThreshold () {
121
+ const thresholds = this._options.thresholds || [0]
122
+ const thresholdsSortArr = thresholds.sort((a, b) => a - b)
123
+ return thresholdsSortArr[0] || 0
124
+ }
125
+ }
126
+
127
+ export default WebIntersectionObserver
@@ -0,0 +1,9 @@
1
+ import WebIntersectionObserver from './IntersectionObserver'
2
+
3
+ function createIntersectionObserver (component, options) {
4
+ return new WebIntersectionObserver(component, options)
5
+ }
6
+
7
+ export {
8
+ createIntersectionObserver
9
+ }
@@ -38,29 +38,34 @@ class SelectQuery {
38
38
  const { selector, component, single, fields } = item
39
39
 
40
40
  let curComponent = document
41
-
42
41
  if (component && component.$el) {
43
42
  curComponent = component.$el
44
43
  } else if (component && component.nodeType === 1) {
45
44
  curComponent = component
46
45
  }
47
-
48
- const selectSelf =
49
- curComponent === document
50
- ? false
51
- : Array
52
- .from(curComponent.parentNode.querySelectorAll(selector))
53
- .every(item => item === curComponent)
54
-
55
- if (single) {
56
- const el = selectSelf ? curComponent : curComponent.querySelector(selector)
57
- res.push(handleFields(fields, el, selector))
46
+ if (this._isEl(selector)) {
47
+ if (single) {
48
+ res.push(handleFields(fields, selector, null))
49
+ } else {
50
+ res.push(selector.map(el => handleFields(fields, el, null)))
51
+ }
58
52
  } else {
59
- const els = selectSelf
60
- ? [curComponent]
61
- : curComponent.querySelectorAll(selector)
62
- const elsArr = Array.from(els).map(el => handleFields(fields, el, null))
63
- res.push(elsArr)
53
+ const selectSelf =
54
+ curComponent === document
55
+ ? false
56
+ : Array
57
+ .from(curComponent.parentNode.querySelectorAll(selector))
58
+ .every(item => item === curComponent)
59
+ if (single) {
60
+ const el = selectSelf ? curComponent : curComponent.querySelector(selector)
61
+ res.push(handleFields(fields, el, selector))
62
+ } else {
63
+ const els = selectSelf
64
+ ? [curComponent]
65
+ : curComponent.querySelectorAll(selector)
66
+ const elsArr = Array.from(els).map(el => handleFields(fields, el, null))
67
+ res.push(elsArr)
68
+ }
64
69
  }
65
70
  })
66
71
  res.forEach((item, idx) => {
@@ -162,6 +167,10 @@ class SelectQuery {
162
167
  })
163
168
  this._queueCb.push(callback)
164
169
  }
170
+ _isEl (selector) {
171
+ if (Array.isArray(selector)) return this._isEl(selector[0])
172
+ return selector && selector.nodeType === 1
173
+ }
165
174
  }
166
175
 
167
176
  export default SelectQuery
@@ -60,3 +60,6 @@ export * from './app'
60
60
 
61
61
  // createAnimation
62
62
  export * from './animation'
63
+
64
+ // createIntersectionObserver
65
+ export * from './create-intersection-observer'