vhall-mini-sdk 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (261) hide show
  1. package/lib/components/player/components/online-hot/index.js +2 -2
  2. package/lib/sdk/main/index.js +1 -0
  3. package/package.json +2 -4
  4. package/postinstall.js +21 -51
  5. package/dist/components/chat/chat-edit/chat-edit.js +0 -127
  6. package/dist/components/chat/chat-edit/chat-edit.json +0 -4
  7. package/dist/components/chat/chat-edit/chat-edit.wxml +0 -7
  8. package/dist/components/chat/chat-edit/chat-edit.wxss +0 -1
  9. package/dist/components/chat/chat-item/chat-item.js +0 -253
  10. package/dist/components/chat/chat-item/chat-item.json +0 -3
  11. package/dist/components/chat/chat-item/chat-item.wxml +0 -96
  12. package/dist/components/chat/chat-item/chat-item.wxss +0 -1
  13. package/dist/components/chat/chat-list/chat-list.js +0 -216
  14. package/dist/components/chat/chat-list/chat-list.json +0 -6
  15. package/dist/components/chat/chat-list/chat-list.wxml +0 -9
  16. package/dist/components/chat/chat-list/chat-list.wxss +0 -1
  17. package/dist/components/chat/chat.js +0 -98
  18. package/dist/components/chat/chat.json +0 -7
  19. package/dist/components/chat/chat.wxml +0 -7
  20. package/dist/components/chat/chat.wxss +0 -1
  21. package/dist/components/gift/gift-display/gift-display.js +0 -118
  22. package/dist/components/gift/gift-display/gift-display.json +0 -3
  23. package/dist/components/gift/gift-display/gift-display.wxml +0 -16
  24. package/dist/components/gift/gift-display/gift-display.wxss +0 -1
  25. package/dist/components/gift/gift-sender/gift-sender.js +0 -63
  26. package/dist/components/gift/gift-sender/gift-sender.json +0 -6
  27. package/dist/components/gift/gift-sender/gift-sender.wxml +0 -19
  28. package/dist/components/gift/gift-sender/gift-sender.wxss +0 -1
  29. package/dist/components/introduction/introduction.js +0 -43
  30. package/dist/components/introduction/introduction.json +0 -3
  31. package/dist/components/introduction/introduction.wxml +0 -8
  32. package/dist/components/introduction/introduction.wxss +0 -1
  33. package/dist/components/invite-rank/img/bronze.png +0 -0
  34. package/dist/components/invite-rank/img/gold.png +0 -0
  35. package/dist/components/invite-rank/img/silver.png +0 -0
  36. package/dist/components/invite-rank/index.js +0 -135
  37. package/dist/components/invite-rank/index.json +0 -8
  38. package/dist/components/invite-rank/index.wxml +0 -42
  39. package/dist/components/invite-rank/index.wxss +0 -1
  40. package/dist/components/invite-rank/invite-rank-item.js +0 -12
  41. package/dist/components/invite-rank/invite-rank-item.json +0 -4
  42. package/dist/components/invite-rank/invite-rank-item.wxml +0 -21
  43. package/dist/components/invite-rank/invite-rank-item.wxss +0 -1
  44. package/dist/components/invite-rank/my-invite-detail.js +0 -82
  45. package/dist/components/invite-rank/my-invite-detail.json +0 -7
  46. package/dist/components/invite-rank/my-invite-detail.wxml +0 -27
  47. package/dist/components/invite-rank/my-invite-detail.wxss +0 -1
  48. package/dist/components/invite-rank/util.wxs +0 -21
  49. package/dist/components/live-landscape/live-landscape.js +0 -216
  50. package/dist/components/live-landscape/live-landscape.json +0 -39
  51. package/dist/components/live-landscape/live-landscape.wxml +0 -73
  52. package/dist/components/live-landscape/live-landscape.wxss +0 -1
  53. package/dist/components/live-portrait/live-portrait.js +0 -274
  54. package/dist/components/live-portrait/live-portrait.json +0 -38
  55. package/dist/components/live-portrait/live-portrait.wxml +0 -106
  56. package/dist/components/live-portrait/live-portrait.wxss +0 -1
  57. package/dist/components/lottery/lottery-accept/index.js +0 -249
  58. package/dist/components/lottery/lottery-accept/index.json +0 -4
  59. package/dist/components/lottery/lottery-accept/index.wxml +0 -49
  60. package/dist/components/lottery/lottery-accept/index.wxss +0 -1
  61. package/dist/components/lottery/lottery-history/index.js +0 -36
  62. package/dist/components/lottery/lottery-history/index.json +0 -3
  63. package/dist/components/lottery/lottery-history/index.wxml +0 -28
  64. package/dist/components/lottery/lottery-history/index.wxss +0 -1
  65. package/dist/components/lottery/lottery-shake/lottery-shake.js +0 -328
  66. package/dist/components/lottery/lottery-shake/lottery-shake.json +0 -1
  67. package/dist/components/lottery/lottery-shake/lottery-shake.wxml +0 -52
  68. package/dist/components/lottery/lottery-shake/lottery-shake.wxss +0 -1
  69. package/dist/components/lottery/lottery-slot/lottery-slot.js +0 -230
  70. package/dist/components/lottery/lottery-slot/lottery-slot.json +0 -1
  71. package/dist/components/lottery/lottery-slot/lottery-slot.wxml +0 -62
  72. package/dist/components/lottery/lottery-slot/lottery-slot.wxss +0 -1
  73. package/dist/components/lottery/lottery-wheel/lottery-wheel.js +0 -153
  74. package/dist/components/lottery/lottery-wheel/lottery-wheel.json +0 -4
  75. package/dist/components/lottery/lottery-wheel/lottery-wheel.wxml +0 -91
  76. package/dist/components/lottery/lottery-wheel/lottery-wheel.wxss +0 -1
  77. package/dist/components/lottery/lottery-winners/index.js +0 -101
  78. package/dist/components/lottery/lottery-winners/index.json +0 -4
  79. package/dist/components/lottery/lottery-winners/index.wxml +0 -39
  80. package/dist/components/lottery/lottery-winners/index.wxss +0 -1
  81. package/dist/components/lottery/lottery.js +0 -388
  82. package/dist/components/lottery/lottery.json +0 -11
  83. package/dist/components/lottery/lottery.wxml +0 -78
  84. package/dist/components/lottery/lottery.wxss +0 -1
  85. package/dist/components/lottery/wheel.json +0 -49
  86. package/dist/components/mall-reward/common/reward-card.wxss +0 -0
  87. package/dist/components/mall-reward/duration-icon/index.js +0 -101
  88. package/dist/components/mall-reward/duration-icon/index.json +0 -3
  89. package/dist/components/mall-reward/duration-icon/index.wxml +0 -7
  90. package/dist/components/mall-reward/duration-icon/index.wxss +0 -1
  91. package/dist/components/mall-reward/f-count-down/index.js +0 -61
  92. package/dist/components/mall-reward/f-count-down/index.json +0 -3
  93. package/dist/components/mall-reward/f-count-down/index.wxml +0 -9
  94. package/dist/components/mall-reward/f-count-down/index.wxss +0 -1
  95. package/dist/components/mall-reward/f-empty/index.js +0 -11
  96. package/dist/components/mall-reward/f-empty/index.json +0 -3
  97. package/dist/components/mall-reward/f-empty/index.wxml +0 -8
  98. package/dist/components/mall-reward/f-empty/index.wxss +0 -1
  99. package/dist/components/mall-reward/f-history/index.js +0 -84
  100. package/dist/components/mall-reward/f-history/index.json +0 -4
  101. package/dist/components/mall-reward/f-history/index.wxml +0 -38
  102. package/dist/components/mall-reward/f-history/index.wxss +0 -1
  103. package/dist/components/mall-reward/f-open/index.js +0 -36
  104. package/dist/components/mall-reward/f-open/index.json +0 -3
  105. package/dist/components/mall-reward/f-open/index.wxml +0 -10
  106. package/dist/components/mall-reward/f-open/index.wxss +0 -1
  107. package/dist/components/mall-reward/f-receive/index.js +0 -36
  108. package/dist/components/mall-reward/f-receive/index.json +0 -3
  109. package/dist/components/mall-reward/f-receive/index.wxml +0 -9
  110. package/dist/components/mall-reward/f-receive/index.wxss +0 -1
  111. package/dist/components/mall-reward/index.js +0 -374
  112. package/dist/components/mall-reward/index.json +0 -8
  113. package/dist/components/mall-reward/index.wxml +0 -4
  114. package/dist/components/mall-reward/index.wxss +0 -0
  115. package/dist/components/mall-reward/main-popup/index.js +0 -46
  116. package/dist/components/mall-reward/main-popup/index.json +0 -12
  117. package/dist/components/mall-reward/main-popup/index.wxml +0 -16
  118. package/dist/components/mall-reward/main-popup/index.wxss +0 -1
  119. package/dist/components/player/assets/image/arrow-left.png +0 -0
  120. package/dist/components/player/assets/image/arrow-right.png +0 -0
  121. package/dist/components/player/assets/image/enterFullScreen.png +0 -0
  122. package/dist/components/player/assets/image/exitFullScreen.png +0 -0
  123. package/dist/components/player/assets/image/fullscreen_1.png +0 -0
  124. package/dist/components/player/assets/image/fullscreen_2.png +0 -0
  125. package/dist/components/player/assets/image/pause.png +0 -0
  126. package/dist/components/player/assets/image/pause_1.png +0 -0
  127. package/dist/components/player/assets/image/play.png +0 -0
  128. package/dist/components/player/assets/image/play_1.png +0 -0
  129. package/dist/components/player/assets/image/refresh.png +0 -0
  130. package/dist/components/player/assets/image/refresh_1.png +0 -0
  131. package/dist/components/player/assets/image/subtitle_close.png +0 -0
  132. package/dist/components/player/assets/image/subtitle_default.png +0 -0
  133. package/dist/components/player/assets/image/volume-off.png +0 -0
  134. package/dist/components/player/assets/image/volume-on.png +0 -0
  135. package/dist/components/player/common/config.js +0 -7
  136. package/dist/components/player/common/veComponent.js +0 -4
  137. package/dist/components/player/components/barrage/barrage-canvas.js +0 -488
  138. package/dist/components/player/components/barrage/barrage-dom.js +0 -471
  139. package/dist/components/player/components/barrage/index.js +0 -62
  140. package/dist/components/player/components/barrage/index.json +0 -4
  141. package/dist/components/player/components/barrage/index.wxml +0 -39
  142. package/dist/components/player/components/barrage/index.wxss +0 -1
  143. package/dist/components/player/components/barrage/utils.js +0 -71
  144. package/dist/components/player/components/controls/controls.js +0 -93
  145. package/dist/components/player/components/controls/controls.json +0 -6
  146. package/dist/components/player/components/controls/controls.wxml +0 -60
  147. package/dist/components/player/components/controls/controls.wxss +0 -1
  148. package/dist/components/player/components/danmaku/danmaku.js +0 -23
  149. package/dist/components/player/components/danmaku/danmaku.json +0 -4
  150. package/dist/components/player/components/danmaku/danmaku.wxml +0 -1
  151. package/dist/components/player/components/danmaku/danmaku.wxss +0 -0
  152. package/dist/components/player/components/error/error.js +0 -15
  153. package/dist/components/player/components/error/error.json +0 -3
  154. package/dist/components/player/components/error/error.wxml +0 -6
  155. package/dist/components/player/components/error/error.wxss +0 -1
  156. package/dist/components/player/components/loading/loading.js +0 -9
  157. package/dist/components/player/components/loading/loading.json +0 -3
  158. package/dist/components/player/components/loading/loading.wxml +0 -4
  159. package/dist/components/player/components/loading/loading.wxss +0 -1
  160. package/dist/components/player/components/main/extensions/data.js +0 -8
  161. package/dist/components/player/components/main/extensions/export.js +0 -83
  162. package/dist/components/player/components/main/extensions/methods.js +0 -110
  163. package/dist/components/player/components/main/extensions/observers.js +0 -41
  164. package/dist/components/player/components/main/extensions/props.js +0 -177
  165. package/dist/components/player/components/main/index.js +0 -44
  166. package/dist/components/player/components/main/index.json +0 -4
  167. package/dist/components/player/components/main/index.wxml +0 -7
  168. package/dist/components/player/components/main/index.wxss +0 -1
  169. package/dist/components/player/components/marquee/marquee.js +0 -304
  170. package/dist/components/player/components/marquee/marquee.json +0 -4
  171. package/dist/components/player/components/marquee/marquee.wxml +0 -14
  172. package/dist/components/player/components/marquee/marquee.wxss +0 -1
  173. package/dist/components/player/components/online-hot/assets/line-hot.png +0 -0
  174. package/dist/components/player/components/online-hot/assets/line-user.png +0 -0
  175. package/dist/components/player/components/online-hot/index.js +0 -66
  176. package/dist/components/player/components/online-hot/index.json +0 -3
  177. package/dist/components/player/components/online-hot/index.wxml +0 -15
  178. package/dist/components/player/components/online-hot/index.wxss +0 -1
  179. package/dist/components/player/components/poster/poster.js +0 -12
  180. package/dist/components/player/components/poster/poster.json +0 -3
  181. package/dist/components/player/components/poster/poster.wxml +0 -5
  182. package/dist/components/player/components/poster/poster.wxss +0 -1
  183. package/dist/components/player/components/watermark/watermark.js +0 -52
  184. package/dist/components/player/components/watermark/watermark.json +0 -4
  185. package/dist/components/player/components/watermark/watermark.wxml +0 -8
  186. package/dist/components/player/components/watermark/watermark.wxss +0 -1
  187. package/dist/components/player/extensions/data.js +0 -63
  188. package/dist/components/player/extensions/export.js +0 -325
  189. package/dist/components/player/extensions/methods.js +0 -406
  190. package/dist/components/player/extensions/observers.js +0 -114
  191. package/dist/components/player/extensions/props.js +0 -162
  192. package/dist/components/player/player.js +0 -83
  193. package/dist/components/player/player.json +0 -33
  194. package/dist/components/player/player.wxml +0 -48
  195. package/dist/components/player/player.wxss +0 -1
  196. package/dist/components/praise/praise.js +0 -150
  197. package/dist/components/praise/praise.json +0 -5
  198. package/dist/components/praise/praise.wxml +0 -17
  199. package/dist/components/praise/praise.wxss +0 -1
  200. package/dist/components/product/product-card/product-card.js +0 -109
  201. package/dist/components/product/product-card/product-card.json +0 -3
  202. package/dist/components/product/product-card/product-card.wxml +0 -47
  203. package/dist/components/product/product-card/product-card.wxss +0 -1
  204. package/dist/components/product/product-detail/product-detail.js +0 -127
  205. package/dist/components/product/product-detail/product-detail.json +0 -3
  206. package/dist/components/product/product-detail/product-detail.wxml +0 -57
  207. package/dist/components/product/product-detail/product-detail.wxss +0 -1
  208. package/dist/components/product/product-item/product-item.js +0 -56
  209. package/dist/components/product/product-item/product-item.json +0 -3
  210. package/dist/components/product/product-item/product-item.wxml +0 -35
  211. package/dist/components/product/product-item/product-item.wxss +0 -1
  212. package/dist/components/product/product-list/product-list.js +0 -67
  213. package/dist/components/product/product-list/product-list.json +0 -6
  214. package/dist/components/product/product-list/product-list.wxml +0 -16
  215. package/dist/components/product/product-list/product-list.wxss +0 -1
  216. package/dist/components/product/product-order/product-order.js +0 -394
  217. package/dist/components/product/product-order/product-order.json +0 -3
  218. package/dist/components/product/product-order/product-order.wxml +0 -75
  219. package/dist/components/product/product-order/product-order.wxss +0 -1
  220. package/dist/components/signin/signin-dialog.js +0 -305
  221. package/dist/components/signin/signin-dialog.json +0 -7
  222. package/dist/components/signin/signin-dialog.wxml +0 -19
  223. package/dist/components/signin/signin-dialog.wxss +0 -1
  224. package/dist/components/top-notify/index.js +0 -14
  225. package/dist/components/top-notify/index.json +0 -3
  226. package/dist/components/top-notify/index.wxml +0 -2
  227. package/dist/components/top-notify/index.wxss +0 -1
  228. package/dist/pubComponents/countdown/countdown.js +0 -97
  229. package/dist/pubComponents/countdown/countdown.json +0 -5
  230. package/dist/pubComponents/countdown/countdown.wxml +0 -19
  231. package/dist/pubComponents/countdown/countdown.wxss +0 -1
  232. package/dist/pubComponents/error-page/index.js +0 -146
  233. package/dist/pubComponents/error-page/index.json +0 -5
  234. package/dist/pubComponents/error-page/index.wxml +0 -37
  235. package/dist/pubComponents/error-page/index.wxss +0 -1
  236. package/dist/pubComponents/popup/popup.js +0 -161
  237. package/dist/pubComponents/popup/popup.json +0 -5
  238. package/dist/pubComponents/popup/popup.wxml +0 -17
  239. package/dist/pubComponents/popup/popup.wxss +0 -1
  240. package/dist/pubComponents/tabs/index.js +0 -95
  241. package/dist/pubComponents/tabs/index.json +0 -4
  242. package/dist/pubComponents/tabs/index.wxml +0 -22
  243. package/dist/pubComponents/tabs/index.wxss +0 -1
  244. package/dist/sdk/config/index.js +0 -1
  245. package/dist/sdk/main/index.js +0 -1
  246. package/dist/sdk/player/index.js +0 -1
  247. package/dist/sdk/plugins/ChatServer.js +0 -1
  248. package/dist/sdk/plugins/CustomMenuServer.js +0 -1
  249. package/dist/sdk/plugins/InteractServer.js +0 -1
  250. package/dist/sdk/plugins/InviteCardServer.js +0 -1
  251. package/dist/sdk/plugins/LotteryServer.js +0 -1
  252. package/dist/sdk/plugins/MallRewardServer.js +0 -1
  253. package/dist/sdk/plugins/ProductServer.js +0 -1
  254. package/dist/shared/RequestUtil.js +0 -1
  255. package/dist/shared/SerializableMap.js +0 -1
  256. package/dist/shared/base.server.js +0 -1
  257. package/dist/shared/cacheUtil.js +0 -1
  258. package/dist/shared/dateUtil.js +0 -1
  259. package/dist/shared/logger.js +0 -1
  260. package/dist/shared/mpUtils.js +0 -1
  261. package/dist/shared/utils.js +0 -1
@@ -1,471 +0,0 @@
1
- const {
2
- substring,
3
- getRandom,
4
- getFontSize,
5
- isArray
6
- } = require('./utils')
7
-
8
- class Bullet {
9
- constructor(opt = {}) {
10
- this.bulletId = opt.bulletId
11
- this.addContent(opt)
12
- }
13
-
14
- /**
15
- * image 结构
16
- * {
17
- * head: {src, width, height},
18
- * tail: {src, width, height},
19
- * gap: 4 // 图片与文本间隔
20
- * }
21
- */
22
- addContent(opt = {}) {
23
- const defaultBulletOpt = {
24
- duration: 0, // 动画时长
25
- passtime: 0, // 弹幕穿越右边界耗时
26
- content: '', // 文本
27
- color: '#000000', // 默认黑色
28
- width: 0, // 弹幕宽度
29
- height: 0, // 弹幕高度
30
- image: {}, // 图片
31
- paused: false // 是否暂停
32
- }
33
- Object.assign(this, defaultBulletOpt, opt)
34
- }
35
-
36
- removeContent() {
37
- this.addContent({})
38
- }
39
- }
40
-
41
- // tunnel(轨道)
42
- class Tunnel {
43
- constructor(opt = {}) {
44
- const defaultTunnelOpt = {
45
- tunnelId: 0,
46
- height: 0, // 轨道高度
47
- width: 0, // 轨道宽度
48
- safeGap: 4, // 相邻弹幕安全间隔
49
- maxNum: 10, // 缓冲队列长度
50
- bullets: [], // 弹幕
51
- last: -1, // 上一条发送的弹幕序号
52
- bulletStatus: [], // 0 空闲,1 占用中
53
- disabled: false, // 禁用中
54
- sending: false, // 弹幕正在发送
55
- timer: null, // 定时器
56
- }
57
- Object.assign(this, defaultTunnelOpt, opt)
58
- this.bulletStatus = new Array(this.maxNum).fill(0)
59
- for (let i = 0; i < this.maxNum; i++) {
60
- this.bullets.push(new Bullet({
61
- bulletId: i,
62
- }))
63
- }
64
- }
65
-
66
- disable() {
67
- this.disabled = true
68
- this.last = -1
69
- this.sending = false
70
- this.bulletStatus = new Array(this.maxNum).fill(1)
71
- this.bullets.forEach(bullet => bullet.removeContent())
72
- }
73
-
74
- enable() {
75
- if (this.disabled) {
76
- this.bulletStatus = new Array(this.maxNum).fill(0)
77
- }
78
- this.disabled = false
79
- }
80
-
81
- clear() {
82
- this.last = -1
83
- this.sending = false
84
- this.bulletStatus = new Array(this.maxNum).fill(0)
85
- this.bullets.forEach(bullet => bullet.removeContent())
86
- if (this.timer) {
87
- clearTimeout(this.timer)
88
- }
89
- }
90
-
91
- getIdleBulletIdx() {
92
- let idle = this.bulletStatus.indexOf(0, this.last + 1)
93
- if (idle === -1) {
94
- idle = this.bulletStatus.indexOf(0)
95
- }
96
-
97
- return idle
98
- }
99
-
100
- getIdleBulletNum() {
101
- let count = 0
102
- this.bulletStatus.forEach(status => {
103
- if (status === 0) count++
104
- })
105
- return count
106
- }
107
-
108
- addBullet(opt) {
109
- if (this.disabled) return
110
- const idx = this.getIdleBulletIdx()
111
- if (idx >= 0) {
112
- this.bulletStatus[idx] = 1
113
- this.bullets[idx].addContent(opt)
114
- }
115
- }
116
-
117
- removeBullet(bulletId) {
118
- if (this.disabled) return
119
- this.bulletStatus[bulletId] = 0
120
- const bullet = this.bullets[bulletId]
121
- bullet.removeContent()
122
- }
123
- }
124
-
125
- // Barrage(控制中心)
126
- class Barrage {
127
- constructor(opt = {}) {
128
- const defaultBarrageOpt = {
129
- duration: 10, // 弹幕动画时长
130
- lineHeight: 1.2, // 弹幕行高
131
- padding: [0, 0, 0, 0], // 弹幕区四周留白
132
- alpha: 1, // 全局透明度
133
- font: '10px sans-serif', // 全局字体
134
- mode: 'separate', // 弹幕重叠 overlap 不重叠 separate
135
- range: [0, 1], // 弹幕显示的垂直范围,支持两个值。[0,1]表示弹幕整个随机分布,
136
- tunnelShow: false, // 显示轨道线
137
- tunnelMaxNum: 30, // 隧道最大缓冲长度
138
- maxLength: 30, // 弹幕最大字节长度,汉字算双字节
139
- safeGap: 4, // 发送时的安全间隔
140
- enableTap: false, // 点击弹幕停止动画高亮显示
141
- tunnelHeight: 0,
142
- tunnelNum: 0,
143
- tunnels: [],
144
- idleTunnels: null,
145
- enableTunnels: null,
146
- distance: 2000,
147
- comp: null, // 组件实例
148
- }
149
- Object.assign(this, defaultBarrageOpt, opt)
150
- this._ready = false
151
- this._deferred = []
152
-
153
- const query = this.comp.createSelectorQuery()
154
- query.select('.barrage-area').boundingClientRect((res) => {
155
- this.init(res)
156
- this.ready()
157
- }).exec()
158
- }
159
-
160
- ready() {
161
- this._ready = true
162
- this._deferred.forEach(item => {
163
- // eslint-disable-next-line prefer-spread
164
- this[item.callback].apply(this, item.args)
165
- })
166
-
167
- this._deferred = []
168
- }
169
-
170
- _delay(method, ...params) {
171
- this._deferred.push({
172
- callback: method,
173
- args: params
174
- })
175
- }
176
-
177
- init(opt) {
178
- this.width = opt.width
179
- this.height = opt.height
180
- this.fontSize = getFontSize(this.font)
181
- this.idleTunnels = new Set()
182
- this.enableTunnels = new Set()
183
- this.tunnels = []
184
- this.availableHeight = (this.height - this.padding[0] - this.padding[2])
185
- this.tunnelHeight = this.fontSize * this.lineHeight
186
- this.tunnelNum = Math.floor(this.availableHeight / this.tunnelHeight)
187
- for (let i = 0; i < this.tunnelNum; i++) {
188
- this.idleTunnels.add(i) // 空闲的隧道id集合
189
- this.enableTunnels.add(i) // 可用的隧道id集合
190
-
191
- this.tunnels.push(new Tunnel({ // 隧道集合
192
- width: this.width,
193
- height: this.tunnelHeight,
194
- safeGap: this.safeGap,
195
- maxNum: this.tunnelMaxNum,
196
- tunnelId: i,
197
- }))
198
- }
199
- this.comp.setData({
200
- fontSize: this.fontSize,
201
- tunnelShow: this.tunnelShow,
202
- tunnels: this.tunnels,
203
- font: this.font,
204
- alpha: this.alpha,
205
- padding: this.padding.map(item => item + 'px').join(' ')
206
- })
207
- // 筛选符合范围的隧道
208
- this.setRange()
209
- }
210
-
211
- // 设置显示范围 range: [0,1]
212
- setRange(range) {
213
- if (!this._ready) {
214
- this._delay('setRange', range)
215
- return
216
- }
217
-
218
- range = range || this.range
219
- const top = range[0] * this.tunnelNum
220
- const bottom = range[1] * this.tunnelNum
221
- // 释放符合要求的隧道
222
- // 找到目前空闲的隧道
223
- const idleTunnels = new Set()
224
- const enableTunnels = new Set()
225
- this.tunnels.forEach((tunnel, tunnelId) => {
226
- if (tunnelId >= top && tunnelId < bottom) {
227
- const disabled = tunnel.disabled
228
- tunnel.enable()
229
- enableTunnels.add(tunnelId)
230
-
231
- if (disabled || this.idleTunnels.has(tunnelId)) {
232
- idleTunnels.add(tunnelId)
233
- }
234
- } else {
235
- tunnel.disable()
236
- }
237
- })
238
- this.idleTunnels = idleTunnels
239
- this.enableTunnels = enableTunnels
240
- this.range = range
241
- this.comp.setData({tunnels: this.tunnels})
242
- }
243
-
244
- setFont(font) {
245
- if (!this._ready) {
246
- this._delay('setFont', font)
247
- return
248
- }
249
-
250
- if (typeof font !== 'string') return
251
- this.font = font
252
- this.comp.setData({font})
253
- }
254
-
255
- setAlpha(alpha) {
256
- if (!this._ready) {
257
- this._delay('setAlpha', alpha)
258
- return
259
- }
260
-
261
- if (typeof alpha !== 'number') return
262
- this.alpha = alpha
263
- this.comp.setData({alpha})
264
- }
265
-
266
- setDuration(duration) {
267
- if (!this._ready) {
268
- this._delay('setDuration', duration)
269
- return
270
- }
271
-
272
- if (typeof duration !== 'number') return
273
- this.duration = duration
274
- this.clear()
275
- }
276
-
277
- // 开启弹幕
278
- open() {
279
- if (!this._ready) {
280
- this._delay('open')
281
- return
282
- }
283
-
284
- this._isActive = true
285
- }
286
-
287
- // 关闭弹幕,清除所有数据
288
- close() {
289
- if (!this._ready) {
290
- this._delay('close')
291
- return
292
- }
293
-
294
- this._isActive = false
295
- this.clear()
296
- }
297
-
298
- clear() {
299
- this.tunnels.forEach(tunnel => tunnel.clear())
300
- this.idleTunnels = new Set(this.enableTunnels)
301
- this.comp.setData({tunnels: this.tunnels})
302
- }
303
-
304
- // 添加一批弹幕,轨道满时会被丢弃
305
- addData(data = []) {
306
- if (!isArray(data)) return
307
-
308
- if (!this._ready) {
309
- this._delay('addData', data)
310
- return
311
- }
312
-
313
- if (!this._isActive) return
314
-
315
- data.forEach(item => {
316
- item.content = substring(item.content, this.maxLength)
317
- this.addBullet2Tunnel(item)
318
- })
319
- this.comp.setData({
320
- tunnels: this.tunnels
321
- }, () => {
322
- this.updateBullets()
323
- })
324
- }
325
-
326
- // 发送一条弹幕
327
- send(opt = {}) {
328
- if (!this._ready) {
329
- this._delay('send', opt)
330
- return
331
- }
332
- const tunnel = this.getEnableTunnel()
333
- if (tunnel === null) return
334
-
335
- const timer = setInterval(() => {
336
- const tunnel = this.getIdleTunnel()
337
- if (tunnel) {
338
- this.addData([opt])
339
- clearInterval(timer)
340
- }
341
- }, 16)
342
- }
343
-
344
- // 添加至轨道
345
- addBullet2Tunnel(opt = {}) {
346
- const tunnel = this.getIdleTunnel()
347
- if (tunnel === null) return
348
-
349
- const tunnelId = tunnel.tunnelId
350
- tunnel.addBullet(opt)
351
- if (tunnel.getIdleBulletNum() === 0) this.removeIdleTunnel(tunnelId)
352
- }
353
-
354
- updateBullets() {
355
- const self = this
356
- const query = this.comp.createSelectorQuery()
357
- query.selectAll('.bullet-item').boundingClientRect((res) => {
358
- if (!this._isActive) return
359
-
360
- for (let i = 0; i < res.length; i++) {
361
- const {tunnelid, bulletid} = res[i].dataset
362
- const tunnel = self.tunnels[tunnelid]
363
- const bullet = tunnel.bullets[bulletid]
364
- bullet.width = res[i].width
365
- bullet.height = res[i].height
366
- }
367
- self.animate()
368
- }).exec()
369
- }
370
-
371
- animate() {
372
- this.tunnels.forEach(tunnel => {
373
- this.tunnelAnimate(tunnel)
374
- })
375
- }
376
-
377
- tunnelAnimate(tunnel) {
378
- if (tunnel.disabled || tunnel.sending || !this._isActive) return
379
-
380
- const next = (tunnel.last + 1) % tunnel.maxNum
381
- const bullet = tunnel.bullets[next]
382
-
383
- if (!bullet) return
384
-
385
- if (bullet.content || bullet.image.head || bullet.image.tail) {
386
- tunnel.sending = true
387
- tunnel.last = next
388
- let duration = this.duration
389
- if (this.mode === 'overlap') {
390
- duration = this.distance * this.duration / (this.distance + bullet.width)
391
- }
392
- const passDistance = bullet.width + tunnel.safeGap
393
- bullet.duration = duration
394
- // 等上一条通过右边界
395
- bullet.passtime = Math.ceil(passDistance * bullet.duration * 1000 / this.distance)
396
- this.comp.setData({
397
- [`tunnels[${tunnel.tunnelId}].bullets[${bullet.bulletId}]`]: bullet
398
- }, () => {
399
- tunnel.timer = setTimeout(() => {
400
- tunnel.sending = false
401
- this.tunnelAnimate(tunnel)
402
- }, bullet.passtime)
403
- })
404
- }
405
- }
406
-
407
- showTunnel() {
408
- this.comp.setData({
409
- tunnelShow: true
410
- })
411
- }
412
-
413
- hideTunnel() {
414
- this.comp.setData({
415
- tunnelShow: false
416
- })
417
- }
418
-
419
- removeIdleTunnel(tunnelId) {
420
- this.idleTunnels.delete(tunnelId)
421
- }
422
-
423
- addIdleTunnel(tunnelId) {
424
- this.idleTunnels.add(tunnelId)
425
- }
426
-
427
- // 从可用的隧道中随机挑选一个
428
- getEnableTunnel() {
429
- if (this.enableTunnels.size === 0) return null
430
- const enableTunnels = Array.from(this.enableTunnels)
431
- const index = getRandom(enableTunnels.length)
432
- return this.tunnels[enableTunnels[index]]
433
- }
434
-
435
- // 从还有余量的隧道中随机挑选一个
436
- getIdleTunnel() {
437
- if (this.idleTunnels.size === 0) return null
438
- const idleTunnels = Array.from(this.idleTunnels)
439
- const index = getRandom(idleTunnels.length)
440
- return this.tunnels[idleTunnels[index]]
441
- }
442
-
443
- animationend(opt) {
444
- const {tunnelId, bulletId} = opt
445
- const tunnel = this.tunnels[tunnelId]
446
- if (!tunnel) return
447
-
448
- const bullet = tunnel.bullets[bulletId]
449
- if (!bullet) return
450
-
451
- tunnel.removeBullet(bulletId)
452
- this.addIdleTunnel(tunnelId)
453
- this.comp.setData({
454
- [`tunnels[${tunnelId}].bullets[${bulletId}]`]: bullet
455
- })
456
- }
457
-
458
- tapBullet(opt) {
459
- if (!this.enableTap) return
460
-
461
- const {tunnelId, bulletId} = opt
462
- const tunnel = this.tunnels[tunnelId]
463
- const bullet = tunnel.bullets[bulletId]
464
- bullet.paused = !bullet.paused
465
- this.comp.setData({
466
- [`tunnels[${tunnelId}].bullets[${bulletId}]`]: bullet
467
- })
468
- }
469
- }
470
-
471
- export default Barrage
@@ -1,62 +0,0 @@
1
- import DomBarrage from './barrage-dom'
2
- import CanvasBarrage from './barrage-canvas'
3
- // https://github.com/wechat-miniprogram/miniprogram-barrage/tree/master/src
4
-
5
- Component({
6
- options: {
7
- addGlobalClass: true,
8
- },
9
-
10
- properties: {
11
- zIndex: {
12
- type: Number,
13
- value: 100
14
- },
15
-
16
- renderingMode: {
17
- type: String,
18
- value: 'canvas'
19
- }
20
- },
21
-
22
- lifetimes: {
23
- created() {
24
- console.log("barrage created")
25
- },
26
- attached() {
27
- console.log("barrage attached")
28
- },
29
- detached() {
30
- console.log("barrage detached")
31
- },
32
- ready() {
33
- console.log("barrage ready")
34
- }
35
- },
36
-
37
- methods: {
38
- getBarrageInstance(opt = {}) {
39
- opt.comp = this
40
- this.barrageInstance = this.data.renderingMode === 'dom'
41
- ? new DomBarrage(opt)
42
- : new CanvasBarrage(opt)
43
- return this.barrageInstance
44
- },
45
-
46
- onAnimationend(e) {
47
- const {tunnelid, bulletid} = e.currentTarget.dataset
48
- this.barrageInstance.animationend({
49
- tunnelId: tunnelid,
50
- bulletId: bulletid
51
- })
52
- },
53
-
54
- onTapBullet(e) {
55
- const {tunnelid, bulletid} = e.currentTarget.dataset
56
- this.barrageInstance.tapBullet({
57
- tunnelId: tunnelid,
58
- bulletId: bulletid
59
- })
60
- },
61
- }
62
- })
@@ -1,4 +0,0 @@
1
- {
2
- "component": true,
3
- "usingComponents": {}
4
- }
@@ -1,39 +0,0 @@
1
- <view wx:if="{{renderingMode === 'canvas'}}" class="barrage-area" style="z-index: {{zIndex}};">
2
- <canvas type="2d" id="weui-canvas" style="width: 100%; height: 100%;"></canvas>
3
- </view>
4
-
5
- <view wx:else class="barrage-area" style="opacity: {{alpha}}; font: {{font}}; padding: {{padding}}; z-index: {{zIndex}};">
6
- <block wx:for="{{tunnels}}" wx:key="tunnelId" wx:for-item="tunnel" wx:for-index="tunnelId">
7
- <view class="barrage-tunnel" style="height: {{tunnel.height}}px; border-top-width: {{tunnelShow ? 1 : 0}}px">
8
- <view class="tunnel-tips" hidden="{{!tunnelShow}}">轨道{{tunnelId}}</view>
9
- <block wx:for="{{tunnel.bullets}}" wx:key="bulletId" wx:for-item="bullet" wx:for-index="bulletId">
10
- <view
11
- class="bullet-item {{bullet.duration > 0 ? 'bullet-move' : ''}} {{bullet.paused ? 'paused' : ''}}"
12
- style="color: {{bullet.paused ? '#fff' : bullet.color}}; height: {{tunnel.height}}px; line-height: {{tunnel.height}}px; animation-duration: {{bullet.duration}}s; animation-play-state: {{bullet.paused ? 'paused' : 'running'}}"
13
- data-tunnelid="{{tunnelId}}"
14
- data-bulletid="{{bulletId}}"
15
- bindanimationend="onAnimationend"
16
- bindtap="onTapBullet"
17
- >
18
- <image
19
- wx:if="{{bullet.image.head}}"
20
- class="bullet-item_img"
21
- style="width: {{bullet.image.head.width || fontSize}}px; height: {{bullet.image.head.height}}px; margin-right: {{bullet.image.head.gap || 4}}px;"
22
- mode="aspectFit"
23
- src="{{bullet.image.head.src}}"
24
- ></image>
25
- <view class="bullet-item_text" style="opacity: 1;">
26
- <text>{{bullet.content}}</text>
27
- </view>
28
- <image
29
- wx:if="{{bullet.image.tail}}"
30
- class="bullet-item_img"
31
- style="width: {{bullet.image.tail.width || fontSize}}px; height: {{bullet.image.tail.height}}px; margin-left: {{bullet.image.tail.gap || 4}}px;"
32
- mode="aspectFit"
33
- src="{{bullet.image.tail.src}}"
34
- ></image>
35
- </view>
36
- </block>
37
- </view>
38
- </block>
39
- </view>
@@ -1 +0,0 @@
1
- .barrage-area{height:100%;pointer-events:auto}.barrage-area,.barrage-tunnel{box-sizing:border-box;position:relative;width:100%}.barrage-tunnel{align-items:center;border-top:1px dashed #ccb24d;display:flex}.tunnel-tips{color:#ccb24d;display:inline-block;margin-left:10px}.bullet-item{align-items:center;display:flex;left:100%;position:absolute;top:0;white-space:nowrap}.bullet-item.paused{background:#000;opacity:.6;padding:0 10px;z-index:1001}.bullet-item_img{display:inline-block;max-height:100%}.bullet-item_text{display:inline-block;margin:0}.bullet-move{animation:slidein 0s linear}@keyframes slidein{0%{transform:translateZ(0)}to{transform:translate3d(-2000px,0,0)}}
@@ -1,71 +0,0 @@
1
- // 获取字节长度,中文算2个字节
2
- function getStrLen(str) {
3
- // eslint-disable-next-line no-control-regex
4
- return str.replace(/[^\x00-\xff]/g, 'aa').length
5
- }
6
-
7
- // 截取指定字节长度的子串
8
- function substring(str, n) {
9
- if (!str) return ''
10
-
11
- const len = getStrLen(str)
12
- if (n >= len) return str
13
-
14
- let l = 0
15
- let result = ''
16
- for (let i = 0; i < str.length; i++) {
17
- const ch = str.charAt(i)
18
- // eslint-disable-next-line no-control-regex
19
- l = /[^\x00-\xff]/i.test(ch) ? l + 2 : l + 1
20
- result += ch
21
- if (l >= n) break
22
- }
23
- return result
24
- }
25
-
26
- function getRandom(max = 10, min = 0) {
27
- return Math.floor(Math.random() * (max - min) + min)
28
- }
29
-
30
- function getFontSize(font) {
31
- const reg = /(\d+)(px)/i
32
- const match = font.match(reg)
33
- return (match && match[1]) || 10
34
- }
35
-
36
- function compareVersion(v1, v2) {
37
- v1 = v1.split('.')
38
- v2 = v2.split('.')
39
- const len = Math.max(v1.length, v2.length)
40
-
41
- while (v1.length < len) {
42
- v1.push('0')
43
- }
44
- while (v2.length < len) {
45
- v2.push('0')
46
- }
47
-
48
- for (let i = 0; i < len; i++) {
49
- const num1 = parseInt(v1[i], 10)
50
- const num2 = parseInt(v2[i], 10)
51
-
52
- if (num1 > num2) {
53
- return 1
54
- } else if (num1 < num2) {
55
- return -1
56
- }
57
- }
58
- return 0
59
- }
60
-
61
- const getType = obj => Object.prototype.toString.call(obj).slice(8,-1)
62
- const isArray = obj => getType(obj) === 'Array'
63
-
64
- module.exports = {
65
- getStrLen,
66
- substring,
67
- getRandom,
68
- getFontSize,
69
- compareVersion,
70
- isArray
71
- }