vhall-mini-sdk 0.1.0 → 0.1.2

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 (280) hide show
  1. package/lib/components/chat/chat-edit/chat-edit.js +7 -4
  2. package/lib/components/chat/chat-list/chat-list.js +1 -1
  3. package/lib/components/live-landscape/live-landscape.js +11 -7
  4. package/lib/components/live-landscape/live-landscape.wxml +2 -2
  5. package/lib/components/live-portrait/live-portrait.js +11 -7
  6. package/lib/components/live-portrait/live-portrait.wxml +3 -3
  7. package/lib/components/live-portrait/live-portrait.wxss +1 -1
  8. package/lib/components/lottery/lottery.wxml +2 -2
  9. package/lib/components/player/components/online-hot/index.js +2 -2
  10. package/lib/components/player/extensions/observers.js +5 -5
  11. package/lib/components/player/player.js +5 -0
  12. package/lib/components/player/player.wxml +3 -3
  13. package/lib/components/product/product-list/product-list.wxml +3 -11
  14. package/lib/components/signin/signin-dialog.js +1 -0
  15. package/lib/sdk/main/index.js +2 -1
  16. package/lib/sdk/player/index.js +1 -1
  17. package/lib/sdk/plugins/InviteCardServer.js +1 -1
  18. package/lib/sdk/plugins/MallRewardServer.js +1 -1
  19. package/lib/sdk/plugins/ProductServer.js +1 -1
  20. package/lib/shared/RequestUtil.js +1 -1
  21. package/lib/shared/logger.js +1 -1
  22. package/package.json +2 -4
  23. package/postinstall.js +21 -51
  24. package/dist/components/chat/chat-edit/chat-edit.js +0 -127
  25. package/dist/components/chat/chat-edit/chat-edit.json +0 -4
  26. package/dist/components/chat/chat-edit/chat-edit.wxml +0 -7
  27. package/dist/components/chat/chat-edit/chat-edit.wxss +0 -1
  28. package/dist/components/chat/chat-item/chat-item.js +0 -253
  29. package/dist/components/chat/chat-item/chat-item.json +0 -3
  30. package/dist/components/chat/chat-item/chat-item.wxml +0 -96
  31. package/dist/components/chat/chat-item/chat-item.wxss +0 -1
  32. package/dist/components/chat/chat-list/chat-list.js +0 -216
  33. package/dist/components/chat/chat-list/chat-list.json +0 -6
  34. package/dist/components/chat/chat-list/chat-list.wxml +0 -9
  35. package/dist/components/chat/chat-list/chat-list.wxss +0 -1
  36. package/dist/components/chat/chat.js +0 -98
  37. package/dist/components/chat/chat.json +0 -7
  38. package/dist/components/chat/chat.wxml +0 -7
  39. package/dist/components/chat/chat.wxss +0 -1
  40. package/dist/components/gift/gift-display/gift-display.js +0 -118
  41. package/dist/components/gift/gift-display/gift-display.json +0 -3
  42. package/dist/components/gift/gift-display/gift-display.wxml +0 -16
  43. package/dist/components/gift/gift-display/gift-display.wxss +0 -1
  44. package/dist/components/gift/gift-sender/gift-sender.js +0 -63
  45. package/dist/components/gift/gift-sender/gift-sender.json +0 -6
  46. package/dist/components/gift/gift-sender/gift-sender.wxml +0 -19
  47. package/dist/components/gift/gift-sender/gift-sender.wxss +0 -1
  48. package/dist/components/introduction/introduction.js +0 -43
  49. package/dist/components/introduction/introduction.json +0 -3
  50. package/dist/components/introduction/introduction.wxml +0 -8
  51. package/dist/components/introduction/introduction.wxss +0 -1
  52. package/dist/components/invite-rank/img/bronze.png +0 -0
  53. package/dist/components/invite-rank/img/gold.png +0 -0
  54. package/dist/components/invite-rank/img/silver.png +0 -0
  55. package/dist/components/invite-rank/index.js +0 -135
  56. package/dist/components/invite-rank/index.json +0 -8
  57. package/dist/components/invite-rank/index.wxml +0 -42
  58. package/dist/components/invite-rank/index.wxss +0 -1
  59. package/dist/components/invite-rank/invite-rank-item.js +0 -12
  60. package/dist/components/invite-rank/invite-rank-item.json +0 -4
  61. package/dist/components/invite-rank/invite-rank-item.wxml +0 -21
  62. package/dist/components/invite-rank/invite-rank-item.wxss +0 -1
  63. package/dist/components/invite-rank/my-invite-detail.js +0 -82
  64. package/dist/components/invite-rank/my-invite-detail.json +0 -7
  65. package/dist/components/invite-rank/my-invite-detail.wxml +0 -27
  66. package/dist/components/invite-rank/my-invite-detail.wxss +0 -1
  67. package/dist/components/invite-rank/util.wxs +0 -21
  68. package/dist/components/live-landscape/live-landscape.js +0 -216
  69. package/dist/components/live-landscape/live-landscape.json +0 -39
  70. package/dist/components/live-landscape/live-landscape.wxml +0 -73
  71. package/dist/components/live-landscape/live-landscape.wxss +0 -1
  72. package/dist/components/live-portrait/live-portrait.js +0 -274
  73. package/dist/components/live-portrait/live-portrait.json +0 -38
  74. package/dist/components/live-portrait/live-portrait.wxml +0 -106
  75. package/dist/components/live-portrait/live-portrait.wxss +0 -1
  76. package/dist/components/lottery/lottery-accept/index.js +0 -249
  77. package/dist/components/lottery/lottery-accept/index.json +0 -4
  78. package/dist/components/lottery/lottery-accept/index.wxml +0 -49
  79. package/dist/components/lottery/lottery-accept/index.wxss +0 -1
  80. package/dist/components/lottery/lottery-history/index.js +0 -36
  81. package/dist/components/lottery/lottery-history/index.json +0 -3
  82. package/dist/components/lottery/lottery-history/index.wxml +0 -28
  83. package/dist/components/lottery/lottery-history/index.wxss +0 -1
  84. package/dist/components/lottery/lottery-shake/lottery-shake.js +0 -328
  85. package/dist/components/lottery/lottery-shake/lottery-shake.json +0 -1
  86. package/dist/components/lottery/lottery-shake/lottery-shake.wxml +0 -52
  87. package/dist/components/lottery/lottery-shake/lottery-shake.wxss +0 -1
  88. package/dist/components/lottery/lottery-slot/lottery-slot.js +0 -230
  89. package/dist/components/lottery/lottery-slot/lottery-slot.json +0 -1
  90. package/dist/components/lottery/lottery-slot/lottery-slot.wxml +0 -62
  91. package/dist/components/lottery/lottery-slot/lottery-slot.wxss +0 -1
  92. package/dist/components/lottery/lottery-wheel/lottery-wheel.js +0 -153
  93. package/dist/components/lottery/lottery-wheel/lottery-wheel.json +0 -4
  94. package/dist/components/lottery/lottery-wheel/lottery-wheel.wxml +0 -91
  95. package/dist/components/lottery/lottery-wheel/lottery-wheel.wxss +0 -1
  96. package/dist/components/lottery/lottery-winners/index.js +0 -101
  97. package/dist/components/lottery/lottery-winners/index.json +0 -4
  98. package/dist/components/lottery/lottery-winners/index.wxml +0 -39
  99. package/dist/components/lottery/lottery-winners/index.wxss +0 -1
  100. package/dist/components/lottery/lottery.js +0 -388
  101. package/dist/components/lottery/lottery.json +0 -11
  102. package/dist/components/lottery/lottery.wxml +0 -78
  103. package/dist/components/lottery/lottery.wxss +0 -1
  104. package/dist/components/lottery/wheel.json +0 -49
  105. package/dist/components/mall-reward/common/reward-card.wxss +0 -0
  106. package/dist/components/mall-reward/duration-icon/index.js +0 -101
  107. package/dist/components/mall-reward/duration-icon/index.json +0 -3
  108. package/dist/components/mall-reward/duration-icon/index.wxml +0 -7
  109. package/dist/components/mall-reward/duration-icon/index.wxss +0 -1
  110. package/dist/components/mall-reward/f-count-down/index.js +0 -61
  111. package/dist/components/mall-reward/f-count-down/index.json +0 -3
  112. package/dist/components/mall-reward/f-count-down/index.wxml +0 -9
  113. package/dist/components/mall-reward/f-count-down/index.wxss +0 -1
  114. package/dist/components/mall-reward/f-empty/index.js +0 -11
  115. package/dist/components/mall-reward/f-empty/index.json +0 -3
  116. package/dist/components/mall-reward/f-empty/index.wxml +0 -8
  117. package/dist/components/mall-reward/f-empty/index.wxss +0 -1
  118. package/dist/components/mall-reward/f-history/index.js +0 -84
  119. package/dist/components/mall-reward/f-history/index.json +0 -4
  120. package/dist/components/mall-reward/f-history/index.wxml +0 -38
  121. package/dist/components/mall-reward/f-history/index.wxss +0 -1
  122. package/dist/components/mall-reward/f-open/index.js +0 -36
  123. package/dist/components/mall-reward/f-open/index.json +0 -3
  124. package/dist/components/mall-reward/f-open/index.wxml +0 -10
  125. package/dist/components/mall-reward/f-open/index.wxss +0 -1
  126. package/dist/components/mall-reward/f-receive/index.js +0 -36
  127. package/dist/components/mall-reward/f-receive/index.json +0 -3
  128. package/dist/components/mall-reward/f-receive/index.wxml +0 -9
  129. package/dist/components/mall-reward/f-receive/index.wxss +0 -1
  130. package/dist/components/mall-reward/index.js +0 -374
  131. package/dist/components/mall-reward/index.json +0 -8
  132. package/dist/components/mall-reward/index.wxml +0 -4
  133. package/dist/components/mall-reward/index.wxss +0 -0
  134. package/dist/components/mall-reward/main-popup/index.js +0 -46
  135. package/dist/components/mall-reward/main-popup/index.json +0 -12
  136. package/dist/components/mall-reward/main-popup/index.wxml +0 -16
  137. package/dist/components/mall-reward/main-popup/index.wxss +0 -1
  138. package/dist/components/player/assets/image/arrow-left.png +0 -0
  139. package/dist/components/player/assets/image/arrow-right.png +0 -0
  140. package/dist/components/player/assets/image/enterFullScreen.png +0 -0
  141. package/dist/components/player/assets/image/exitFullScreen.png +0 -0
  142. package/dist/components/player/assets/image/fullscreen_1.png +0 -0
  143. package/dist/components/player/assets/image/fullscreen_2.png +0 -0
  144. package/dist/components/player/assets/image/pause.png +0 -0
  145. package/dist/components/player/assets/image/pause_1.png +0 -0
  146. package/dist/components/player/assets/image/play.png +0 -0
  147. package/dist/components/player/assets/image/play_1.png +0 -0
  148. package/dist/components/player/assets/image/refresh.png +0 -0
  149. package/dist/components/player/assets/image/refresh_1.png +0 -0
  150. package/dist/components/player/assets/image/subtitle_close.png +0 -0
  151. package/dist/components/player/assets/image/subtitle_default.png +0 -0
  152. package/dist/components/player/assets/image/volume-off.png +0 -0
  153. package/dist/components/player/assets/image/volume-on.png +0 -0
  154. package/dist/components/player/common/config.js +0 -7
  155. package/dist/components/player/common/veComponent.js +0 -4
  156. package/dist/components/player/components/barrage/barrage-canvas.js +0 -488
  157. package/dist/components/player/components/barrage/barrage-dom.js +0 -471
  158. package/dist/components/player/components/barrage/index.js +0 -62
  159. package/dist/components/player/components/barrage/index.json +0 -4
  160. package/dist/components/player/components/barrage/index.wxml +0 -39
  161. package/dist/components/player/components/barrage/index.wxss +0 -1
  162. package/dist/components/player/components/barrage/utils.js +0 -71
  163. package/dist/components/player/components/controls/controls.js +0 -93
  164. package/dist/components/player/components/controls/controls.json +0 -6
  165. package/dist/components/player/components/controls/controls.wxml +0 -60
  166. package/dist/components/player/components/controls/controls.wxss +0 -1
  167. package/dist/components/player/components/danmaku/danmaku.js +0 -23
  168. package/dist/components/player/components/danmaku/danmaku.json +0 -4
  169. package/dist/components/player/components/danmaku/danmaku.wxml +0 -1
  170. package/dist/components/player/components/danmaku/danmaku.wxss +0 -0
  171. package/dist/components/player/components/error/error.js +0 -15
  172. package/dist/components/player/components/error/error.json +0 -3
  173. package/dist/components/player/components/error/error.wxml +0 -6
  174. package/dist/components/player/components/error/error.wxss +0 -1
  175. package/dist/components/player/components/loading/loading.js +0 -9
  176. package/dist/components/player/components/loading/loading.json +0 -3
  177. package/dist/components/player/components/loading/loading.wxml +0 -4
  178. package/dist/components/player/components/loading/loading.wxss +0 -1
  179. package/dist/components/player/components/main/extensions/data.js +0 -8
  180. package/dist/components/player/components/main/extensions/export.js +0 -83
  181. package/dist/components/player/components/main/extensions/methods.js +0 -110
  182. package/dist/components/player/components/main/extensions/observers.js +0 -41
  183. package/dist/components/player/components/main/extensions/props.js +0 -177
  184. package/dist/components/player/components/main/index.js +0 -44
  185. package/dist/components/player/components/main/index.json +0 -4
  186. package/dist/components/player/components/main/index.wxml +0 -7
  187. package/dist/components/player/components/main/index.wxss +0 -1
  188. package/dist/components/player/components/marquee/marquee.js +0 -304
  189. package/dist/components/player/components/marquee/marquee.json +0 -4
  190. package/dist/components/player/components/marquee/marquee.wxml +0 -14
  191. package/dist/components/player/components/marquee/marquee.wxss +0 -1
  192. package/dist/components/player/components/online-hot/assets/line-hot.png +0 -0
  193. package/dist/components/player/components/online-hot/assets/line-user.png +0 -0
  194. package/dist/components/player/components/online-hot/index.js +0 -66
  195. package/dist/components/player/components/online-hot/index.json +0 -3
  196. package/dist/components/player/components/online-hot/index.wxml +0 -15
  197. package/dist/components/player/components/online-hot/index.wxss +0 -1
  198. package/dist/components/player/components/poster/poster.js +0 -12
  199. package/dist/components/player/components/poster/poster.json +0 -3
  200. package/dist/components/player/components/poster/poster.wxml +0 -5
  201. package/dist/components/player/components/poster/poster.wxss +0 -1
  202. package/dist/components/player/components/watermark/watermark.js +0 -52
  203. package/dist/components/player/components/watermark/watermark.json +0 -4
  204. package/dist/components/player/components/watermark/watermark.wxml +0 -8
  205. package/dist/components/player/components/watermark/watermark.wxss +0 -1
  206. package/dist/components/player/extensions/data.js +0 -63
  207. package/dist/components/player/extensions/export.js +0 -325
  208. package/dist/components/player/extensions/methods.js +0 -406
  209. package/dist/components/player/extensions/observers.js +0 -114
  210. package/dist/components/player/extensions/props.js +0 -162
  211. package/dist/components/player/player.js +0 -83
  212. package/dist/components/player/player.json +0 -33
  213. package/dist/components/player/player.wxml +0 -48
  214. package/dist/components/player/player.wxss +0 -1
  215. package/dist/components/praise/praise.js +0 -150
  216. package/dist/components/praise/praise.json +0 -5
  217. package/dist/components/praise/praise.wxml +0 -17
  218. package/dist/components/praise/praise.wxss +0 -1
  219. package/dist/components/product/product-card/product-card.js +0 -109
  220. package/dist/components/product/product-card/product-card.json +0 -3
  221. package/dist/components/product/product-card/product-card.wxml +0 -47
  222. package/dist/components/product/product-card/product-card.wxss +0 -1
  223. package/dist/components/product/product-detail/product-detail.js +0 -127
  224. package/dist/components/product/product-detail/product-detail.json +0 -3
  225. package/dist/components/product/product-detail/product-detail.wxml +0 -57
  226. package/dist/components/product/product-detail/product-detail.wxss +0 -1
  227. package/dist/components/product/product-item/product-item.js +0 -56
  228. package/dist/components/product/product-item/product-item.json +0 -3
  229. package/dist/components/product/product-item/product-item.wxml +0 -35
  230. package/dist/components/product/product-item/product-item.wxss +0 -1
  231. package/dist/components/product/product-list/product-list.js +0 -67
  232. package/dist/components/product/product-list/product-list.json +0 -6
  233. package/dist/components/product/product-list/product-list.wxml +0 -16
  234. package/dist/components/product/product-list/product-list.wxss +0 -1
  235. package/dist/components/product/product-order/product-order.js +0 -394
  236. package/dist/components/product/product-order/product-order.json +0 -3
  237. package/dist/components/product/product-order/product-order.wxml +0 -75
  238. package/dist/components/product/product-order/product-order.wxss +0 -1
  239. package/dist/components/signin/signin-dialog.js +0 -305
  240. package/dist/components/signin/signin-dialog.json +0 -7
  241. package/dist/components/signin/signin-dialog.wxml +0 -19
  242. package/dist/components/signin/signin-dialog.wxss +0 -1
  243. package/dist/components/top-notify/index.js +0 -14
  244. package/dist/components/top-notify/index.json +0 -3
  245. package/dist/components/top-notify/index.wxml +0 -2
  246. package/dist/components/top-notify/index.wxss +0 -1
  247. package/dist/pubComponents/countdown/countdown.js +0 -97
  248. package/dist/pubComponents/countdown/countdown.json +0 -5
  249. package/dist/pubComponents/countdown/countdown.wxml +0 -19
  250. package/dist/pubComponents/countdown/countdown.wxss +0 -1
  251. package/dist/pubComponents/error-page/index.js +0 -146
  252. package/dist/pubComponents/error-page/index.json +0 -5
  253. package/dist/pubComponents/error-page/index.wxml +0 -37
  254. package/dist/pubComponents/error-page/index.wxss +0 -1
  255. package/dist/pubComponents/popup/popup.js +0 -161
  256. package/dist/pubComponents/popup/popup.json +0 -5
  257. package/dist/pubComponents/popup/popup.wxml +0 -17
  258. package/dist/pubComponents/popup/popup.wxss +0 -1
  259. package/dist/pubComponents/tabs/index.js +0 -95
  260. package/dist/pubComponents/tabs/index.json +0 -4
  261. package/dist/pubComponents/tabs/index.wxml +0 -22
  262. package/dist/pubComponents/tabs/index.wxss +0 -1
  263. package/dist/sdk/config/index.js +0 -1
  264. package/dist/sdk/main/index.js +0 -1
  265. package/dist/sdk/player/index.js +0 -1
  266. package/dist/sdk/plugins/ChatServer.js +0 -1
  267. package/dist/sdk/plugins/CustomMenuServer.js +0 -1
  268. package/dist/sdk/plugins/InteractServer.js +0 -1
  269. package/dist/sdk/plugins/InviteCardServer.js +0 -1
  270. package/dist/sdk/plugins/LotteryServer.js +0 -1
  271. package/dist/sdk/plugins/MallRewardServer.js +0 -1
  272. package/dist/sdk/plugins/ProductServer.js +0 -1
  273. package/dist/shared/RequestUtil.js +0 -1
  274. package/dist/shared/SerializableMap.js +0 -1
  275. package/dist/shared/base.server.js +0 -1
  276. package/dist/shared/cacheUtil.js +0 -1
  277. package/dist/shared/dateUtil.js +0 -1
  278. package/dist/shared/logger.js +0 -1
  279. package/dist/shared/mpUtils.js +0 -1
  280. package/dist/shared/utils.js +0 -1
@@ -1,488 +0,0 @@
1
- import {substring, getFontSize, getRandom} from './utils'
2
-
3
- class Bullet {
4
- constructor(barrage, opt = {}) {
5
- const defaultBulletOpt = {
6
- color: '#000000', // 默认黑色
7
- font: '10px sans-serif',
8
- fontSize: 10, // 全局字体大小
9
- content: '',
10
- textWidth: 0,
11
- speed: 0, // 根据屏幕停留时长计算
12
- x: 0,
13
- y: 0,
14
- tunnelId: 0,
15
- // image: {
16
- // head: {src, width, height}, // 弹幕头部添加图片
17
- // tail: {src, width, height}, // 弹幕尾部添加图片
18
- // gap: 4 // 图片与文本间隔
19
- // }
20
- image: {},
21
- imageHead: null, // Image 对象
22
- imageTail: null,
23
- // status: 0 //0:待播放 1: 未完全进入屏幕 2: 完全进入屏幕 3: 完全退出屏幕
24
- }
25
- Object.assign(this, defaultBulletOpt, opt)
26
-
27
- this.barrage = barrage
28
- this.ctx = barrage.ctx
29
- this.canvas = barrage.canvas
30
- }
31
-
32
- move() {
33
- if (this.image.head && !this.imageHead) {
34
- const Image = this.canvas.createImage()
35
- Image.src = this.image.head.src
36
- Image.onload = () => {
37
- this.imageHead = Image
38
- }
39
- Image.onerror = () => {
40
- // eslint-disable-next-line no-console
41
- console.log(`Fail to load image: ${this.image.head.src}`)
42
- }
43
- }
44
-
45
- if (this.image.tail && !this.imageTail) {
46
- const Image = this.canvas.createImage()
47
- Image.src = this.image.tail.src
48
- Image.onload = () => {
49
- this.imageTail = Image
50
- }
51
- Image.onerror = () => {
52
- // eslint-disable-next-line no-console
53
- console.log(`Fail to load image: ${this.image.tail.src}`)
54
- }
55
- }
56
-
57
- if (this.imageHead) {
58
- const {
59
- width = this.fontSize,
60
- height = this.fontSize,
61
- gap = 4
62
- } = this.image.head
63
- const x = this.x - gap - width
64
- const y = this.y - 0.5 * height
65
- this.ctx.drawImage(this.imageHead, x, y, width, height)
66
- }
67
-
68
- if (this.imageTail) {
69
- const {
70
- width = this.fontSize,
71
- height = this.fontSize,
72
- gap = 4
73
- } = this.image.tail
74
- const x = this.x + this.textWidth + gap
75
- const y = this.y - 0.5 * height
76
- this.ctx.drawImage(this.imageTail, x, y, width, height)
77
- }
78
-
79
- this.x = this.x - this.speed
80
- this.ctx.fillStyle = this.color
81
- this.ctx.fillText(this.content, this.x, this.y)
82
- }
83
- }
84
-
85
- // tunnel(轨道)
86
- class Tunnel {
87
- constructor(barrage, opt = {}) {
88
- const defaultTunnelOpt = {
89
- activeQueue: [], // 正在屏幕中列表
90
- nextQueue: [], // 待播放列表
91
- maxNum: 30,
92
- freeNum: 30, // 剩余可添加量
93
- height: 0,
94
- width: 0,
95
- disabled: false,
96
- tunnelId: 0,
97
- safeArea: 4,
98
- sending: false, // 弹幕正在发送
99
- }
100
- Object.assign(this, defaultTunnelOpt, opt)
101
-
102
- this.freeNum = this.maxNum
103
- this.barrage = barrage // 控制中心
104
- this.ctx = barrage.ctx
105
- }
106
-
107
- disable() {
108
- this.disabled = true
109
- }
110
-
111
- enable() {
112
- this.disabled = false
113
- }
114
-
115
- clear() {
116
- this.activeQueue = []
117
- this.nextQueue = []
118
- this.sending = false
119
- this.freeNum = this.maxNum
120
- this.barrage.addIdleTunnel(this.tunnelId)
121
- }
122
-
123
- addBullet(bullet) {
124
- if (this.disabled) return
125
- if (this.freeNum === 0) return
126
- this.nextQueue.push(bullet)
127
- this.freeNum--
128
- if (this.freeNum === 0) {
129
- this.barrage.removeIdleTunnel(this.tunnelId)
130
- }
131
- }
132
-
133
- animate() {
134
- if (this.disabled) return
135
- // 无正在发送弹幕,添加一条
136
- const nextQueue = this.nextQueue
137
- const activeQueue = this.activeQueue
138
- if (!this.sending && nextQueue.length > 0) {
139
- const bullet = nextQueue.shift()
140
- activeQueue.push(bullet)
141
- this.freeNum++
142
- this.sending = true
143
- this.barrage.addIdleTunnel(this.tunnelId)
144
- }
145
-
146
- if (activeQueue.length > 0) {
147
- activeQueue.forEach(bullet => bullet.move())
148
- const head = activeQueue[0]
149
- const tail = activeQueue[activeQueue.length - 1]
150
- // 队首移出屏幕
151
- if (head.x + head.textWidth < 0) {
152
- activeQueue.shift()
153
- }
154
- // 队尾离开超过安全区
155
- if (tail.x + tail.textWidth + this.safeArea < this.width) {
156
- this.sending = false
157
- }
158
- }
159
- }
160
- }
161
-
162
- class Barrage {
163
- constructor(opt = {}) {
164
- const defaultBarrageOpt = {
165
- font: '10px sans-serif',
166
- duration: 15, // 弹幕屏幕停留时长
167
- lineHeight: 1.2,
168
- padding: [0, 0, 0, 0],
169
- tunnelHeight: 0,
170
- tunnelNum: 0,
171
- tunnelMaxNum: 30, // 隧道最大缓冲长度
172
- maxLength: 30, // 最大字节长度,汉字算双字节
173
- safeArea: 4, // 发送时的安全间隔
174
- tunnels: [],
175
- idleTunnels: [],
176
- enableTunnels: [],
177
- alpha: 1, // 全局透明度
178
- mode: 'separate', // 弹幕重叠 overlap 不重叠 separate
179
- range: [0, 1], // 弹幕显示的垂直范围,支持两个值。[0,1]表示弹幕整个随机分布,
180
- fps: 60, // 刷新率
181
- tunnelShow: false, // 显示轨道线
182
- comp: null, // 组件实例
183
- }
184
- Object.assign(this, defaultBarrageOpt, opt)
185
- const systemInfo = wx.getSystemInfoSync()
186
- this.ratio = systemInfo.pixelRatio
187
- this.selector = '#weui-canvas'
188
- this._ready = false
189
- this._deferred = []
190
-
191
- const query = this.comp.createSelectorQuery()
192
- query.select(this.selector).boundingClientRect()
193
- query.select(this.selector).node()
194
- query.exec((res) => {
195
- this.canvas = res[1].node
196
- this.init(res[0])
197
- this.ready()
198
- })
199
- console.log("cccccccccccc")
200
- }
201
-
202
- ready() {
203
- this._ready = true
204
- this._deferred.forEach(item => {
205
- // eslint-disable-next-line prefer-spread
206
- this[item.callback].apply(this, item.args)
207
- })
208
-
209
- this._deferred = []
210
- }
211
-
212
- _delay(method, args) {
213
- this._deferred.push({
214
- callback: method,
215
- args
216
- })
217
- }
218
-
219
- init(opt = {}) {
220
- this.width = opt.width
221
- this.height = opt.height
222
- this.fontSize = getFontSize(this.font)
223
- this.innerDuration = this.transfromDuration2Canvas(this.duration)
224
-
225
- const ratio = this.ratio// 设备像素比
226
- this.canvas.width = this.width * ratio
227
- this.canvas.height = this.height * ratio
228
- this.ctx = this.canvas.getContext('2d')
229
- this.ctx.scale(ratio, ratio)
230
-
231
- this.ctx.textBaseline = 'middle'
232
- this.ctx.globalAlpha = this.alpha
233
- this.ctx.font = this.font
234
-
235
- this.idleTunnels = []
236
- this.enableTunnels = []
237
- this.tunnels = []
238
-
239
- this.availableHeight = (this.height - this.padding[0] - this.padding[2])
240
- this.tunnelHeight = this.fontSize * this.lineHeight
241
- this.tunnelNum = Math.floor(this.availableHeight / this.tunnelHeight)
242
- for (let i = 0; i < this.tunnelNum; i++) {
243
- this.idleTunnels.push(i) // 空闲的隧道id集合
244
- this.enableTunnels.push(i) // 可用的隧道id集合
245
- this.tunnels.push(new Tunnel(this, { // 隧道集合
246
- width: this.width,
247
- height: this.tunnelHeight,
248
- safeArea: this.safeArea,
249
- maxNum: this.tunnelMaxNum,
250
- tunnelId: i,
251
- }))
252
- }
253
- // 筛选符合范围的隧道
254
- this.setRange()
255
- this._isActive = false
256
- }
257
-
258
- transfromDuration2Canvas(duration) {
259
- // 2000 是 dom 中移动的距离
260
- return duration * this.width / 2000
261
- }
262
-
263
- // 设置显示范围 range: [0,1]
264
- setRange(range) {
265
- if (!this._ready) {
266
- this._delay('setRange', range)
267
- return
268
- }
269
-
270
- range = range || this.range
271
- const top = range[0] * this.tunnelNum
272
- const bottom = range[1] * this.tunnelNum
273
-
274
- // 释放符合要求的隧道
275
- // 找到目前空闲的隧道
276
- const idleTunnels = []
277
- const enableTunnels = []
278
- this.tunnels.forEach((tunnel, tunnelId) => {
279
- if (tunnelId >= top && tunnelId < bottom) {
280
- tunnel.enable()
281
- enableTunnels.push(tunnelId)
282
- if (this.idleTunnels.indexOf(tunnelId) >= 0) {
283
- idleTunnels.push(tunnelId)
284
- }
285
- } else {
286
- tunnel.disable()
287
- }
288
- })
289
- this.idleTunnels = idleTunnels
290
- this.enableTunnels = enableTunnels
291
- this.range = range
292
- }
293
-
294
- setFont(font) {
295
- if (!this._ready) {
296
- this._delay('setFont', font)
297
- return
298
- }
299
-
300
- this.font = font
301
- this.fontSize = getFontSize(this.font)
302
- this.ctx.font = font
303
- }
304
-
305
- setAlpha(alpha) {
306
- if (!this._ready) {
307
- this._delay('setAlpha', alpha)
308
- return
309
- }
310
-
311
- this.alpha = alpha
312
- this.ctx.globalAlpha = alpha
313
- }
314
-
315
- setDuration(duration) {
316
- if (!this._ready) {
317
- this._delay('setDuration', duration)
318
- return
319
- }
320
-
321
- this.clear()
322
- this.duration = duration
323
- this.innerDuration = this.transfromDuration2Canvas(duration)
324
- }
325
-
326
- // 开启弹幕
327
- open() {
328
- if (!this._ready) {
329
- this._delay('open')
330
- return
331
- }
332
-
333
- if (this._isActive) return
334
- this._isActive = true
335
- this.play()
336
- }
337
-
338
- // 关闭弹幕,清除所有数据
339
- close() {
340
- if (!this._ready) {
341
- this._delay('close')
342
- return
343
- }
344
-
345
- if (!this._isActive) return
346
- this._isActive = false
347
- this.pause()
348
- this.clear()
349
- }
350
-
351
- // 开启弹幕滚动
352
- play() {
353
- this._rAFId = this.canvas.requestAnimationFrame(() => {
354
- this.animate()
355
- this.play()
356
- })
357
- }
358
-
359
- // 停止弹幕滚动
360
- pause() {
361
- if (typeof this._rAFId === 'number') {
362
- this.canvas.cancelAnimationFrame(this._rAFId)
363
- }
364
- }
365
-
366
- // 清空屏幕和缓冲的数据
367
- clear() {
368
- this.ctx.clearRect(0, 0, this.width, this.height)
369
- this.tunnels.forEach(tunnel => tunnel.clear())
370
- }
371
-
372
- // 添加一批弹幕,轨道满时会被丢弃
373
- addData(data = []) {
374
- if (!this._ready) {
375
- this._delay('addData', data)
376
- return
377
- }
378
-
379
- if (!this._isActive) return
380
- data.forEach(item => this.addBullet2Tunnel(item))
381
- }
382
-
383
- // 发送一条弹幕
384
- // 为保证发送成功,选取一条可用隧道,替换待发送队列队头元素
385
- send(opt = {}) {
386
- if (!this._ready) {
387
- this._delay('send', opt)
388
- return
389
- }
390
-
391
- const tunnel = this.getEnableTunnel()
392
- if (tunnel === null) return
393
-
394
- opt.tunnelId = tunnel.tunnelId
395
- const bullet = this.registerBullet(opt)
396
- tunnel.nextQueue[0] = bullet
397
- }
398
-
399
- // 添加至轨道 {content, color}
400
- addBullet2Tunnel(opt = {}) {
401
- const tunnel = this.getIdleTunnel()
402
- if (tunnel === null) return
403
-
404
- opt.tunnelId = tunnel.tunnelId
405
- const bullet = this.registerBullet(opt)
406
- tunnel.addBullet(bullet)
407
- }
408
-
409
- registerBullet(opt = {}) {
410
- opt.tunnelId = opt.tunnelId || 0
411
- opt.content = substring(opt.content, this.maxLength)
412
- const textWidth = this.getTextWidth(opt.content)
413
- const distance = this.mode === 'overlap' ? this.width + textWidth : this.width
414
- opt.textWidth = textWidth
415
- opt.speed = distance / (this.innerDuration * this.fps)
416
- opt.fontSize = this.fontSize
417
- opt.x = this.width
418
- opt.y = this.tunnelHeight * (opt.tunnelId + 0.5) + this.padding[0]
419
- return new Bullet(this, opt)
420
- }
421
-
422
- // 每帧执行的操作
423
- animate() {
424
- // 清空画面后重绘
425
- this.ctx.clearRect(0, 0, this.width, this.height)
426
- if (this.tunnelShow) {
427
- this.drawTunnel()
428
- }
429
- this.tunnels.forEach(tunnel => tunnel.animate())
430
- }
431
-
432
- showTunnel() {
433
- this.tunnelShow = true
434
- }
435
-
436
- hideTunnel() {
437
- this.tunnelShow = false
438
- }
439
-
440
- removeIdleTunnel(tunnelId) {
441
- const idx = this.idleTunnels.indexOf(tunnelId)
442
- if (idx >= 0) this.idleTunnels.splice(idx, 1)
443
- }
444
-
445
- addIdleTunnel(tunnelId) {
446
- const idx = this.idleTunnels.indexOf(tunnelId)
447
- if (idx < 0) this.idleTunnels.push(tunnelId)
448
- }
449
-
450
- // 从可用的隧道中随机挑选一个
451
- getEnableTunnel() {
452
- if (this.enableTunnels.length === 0) return null
453
- const index = getRandom(this.enableTunnels.length)
454
- return this.tunnels[this.enableTunnels[index]]
455
- }
456
-
457
- // 从还有余量的隧道中随机挑选一个
458
- getIdleTunnel() {
459
- if (this.idleTunnels.length === 0) return null
460
- const index = getRandom(this.idleTunnels.length)
461
- return this.tunnels[this.idleTunnels[index]]
462
- }
463
-
464
- getTextWidth(content) {
465
- this.ctx.font = this.font
466
- return Math.ceil(this.ctx.measureText(content).width)
467
- }
468
-
469
- drawTunnel() {
470
- const ctx = this.ctx
471
- const tunnelColor = '#CCB24D'
472
- for (let i = 0; i <= this.tunnelNum; i++) {
473
- const y = this.padding[0] + i * this.tunnelHeight
474
- ctx.beginPath()
475
- ctx.strokeStyle = tunnelColor
476
- ctx.setLineDash([5, 10])
477
- ctx.moveTo(0, y)
478
- ctx.lineTo(this.width, y)
479
- ctx.stroke()
480
- if (i < this.tunnelNum) {
481
- ctx.fillStyle = tunnelColor
482
- ctx.fillText(`弹道${i + 1}`, 10, this.tunnelHeight / 2 + y)
483
- }
484
- }
485
- }
486
- }
487
-
488
- export default Barrage