pixuireactcomponents 1.1.23 → 1.2.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.
- package/README.md +3 -0
- package/cmdAfterTsBuild.js +8 -0
- package/index.js +20 -16
- package/package.json +9 -9
- package/tools/EventDispatcherJs.tsx +74 -0
- package/tools/Logger.tsx +161 -0
- package/tools/img/logger.png +0 -0
- package/tsconfig.json +45 -0
- package/ui/components/bulletscreen/BulletItemAnimation.tsx +117 -0
- package/ui/components/bulletscreen/BulletScreenAnimation.tsx +278 -0
- package/ui/components/bulletscreen/bullet.less +17 -0
- package/ui/components/button/Button.tsx +18 -0
- package/ui/components/carousel/Carousel.tsx +279 -0
- package/ui/components/checkBox/CheckBox.tsx +40 -0
- package/ui/components/dropdown/Dropdown.tsx +126 -0
- package/ui/components/dropdown/DropdownOptionUI.tsx +14 -0
- package/ui/components/dropdown/DropdownSpreadMainUI.tsx +11 -0
- package/ui/components/dropdown/DropdownUnspreadMainUI.tsx +11 -0
- package/ui/components/gradient/{GradientText.js → GradientText.tsx} +183 -174
- package/ui/components/outlinetext/OutlineText.tsx +184 -0
- package/ui/components/progress/Progress.tsx +174 -0
- package/ui/components/slapface/Slapface.tsx +284 -0
- package/ui/components/slider/Slider.tsx +366 -0
- package/ui/components/tab/Tab.tsx +12 -0
- package/ui/components/tab/Tabs.tsx +56 -0
- package/ui/components/togglegroup/ToggleGroup.tsx +105 -0
- package/ui/components/videoplayer/VideoPlayer.tsx +200 -0
- package/ui/components/waterfallcomponent/WaterfallComponent.jsx +687 -0
- package/ui/components/waterfallcomponent/less/WaterfallComponent.less +13 -0
- package/ui/sample/Images.tsx +60 -0
- package/ui/sample/OutlineText/OutlineDemo.tsx +61 -0
- package/ui/sample/Slapface/SlapfaceDemo.tsx +30 -0
- package/ui/sample/asset/btn_close.png +0 -0
- package/ui/sample/asset/changtai_button.jpg +0 -0
- package/ui/sample/asset/checkbox0.png +0 -0
- package/ui/sample/asset/checkbox1.png +0 -0
- package/ui/sample/asset/data_arrow_down.png +0 -0
- package/ui/sample/asset/data_arrow_up.png +0 -0
- package/ui/sample/asset/dot.png +0 -0
- package/ui/sample/asset/inner.png +0 -0
- package/ui/sample/asset/item_reddot.png +0 -0
- package/ui/sample/asset/loading.png +0 -0
- package/ui/sample/asset/money_dropdown.png +0 -0
- package/ui/sample/asset/money_dropdownall.png +0 -0
- package/ui/sample/asset/outer.png +0 -0
- package/ui/sample/asset/slapface_samplepic1.png +0 -0
- package/ui/sample/asset/slapface_samplepic2.png +0 -0
- package/ui/sample/asset/slapface_samplepic3.png +0 -0
- package/ui/sample/asset/slapface_samplepic4.png +0 -0
- package/ui/sample/asset/slapface_samplepic5.png +0 -0
- package/ui/sample/asset/slapface_samplepic6.png +0 -0
- package/ui/sample/asset/tab_choosed.png +0 -0
- package/ui/sample/asset/tabs_bg.png +0 -0
- package/ui/sample/asset/video_pause.png +0 -0
- package/ui/sample/asset/video_play.png +0 -0
- package/ui/sample/asset/video_reload.png +0 -0
- package/ui/sample/asset/xuanfu_button.jpg +0 -0
- package/ui/sample/asset/yaxia_button.jpg +0 -0
- package/ui/sample/bulletscreen/BulletDemo.tsx +84 -0
- package/ui/sample/button/ButtonDemo.tsx +19 -0
- package/ui/sample/carousel/carouselDemo.tsx +52 -0
- package/ui/sample/checkBox/checkBoxDemo.tsx +7 -0
- package/ui/sample/dropdown/DropdownDemo.tsx +65 -0
- package/ui/sample/dropdown/MoneyDropdownOption.tsx +50 -0
- package/ui/sample/dropdown/MoneyDropdownSpreadMain.tsx +42 -0
- package/ui/sample/dropdown/MoneyDropdownUnspreadMain.tsx +44 -0
- package/ui/sample/gradient/GradientDemo.tsx +51 -0
- package/ui/sample/less/video.less +144 -0
- package/ui/sample/progress/ProgressDemo.tsx +74 -0
- package/ui/sample/slider/SliderDemo.tsx +116 -0
- package/ui/sample/tab/TabDemo.tsx +67 -0
- package/ui/sample/tab/TopTab.tsx +74 -0
- package/ui/sample/togglegroup/ToggleGroupDemo.tsx +35 -0
- package/ui/sample/videoplayer/VideoPlayerDemo.tsx +57 -0
- package/ui/sample/waterfallcomponent/WaterfallComponentDemo.jsx +137 -0
- package/index.d.ts +0 -15
- package/tools/EventDispatcherJs.d.ts +0 -10
- package/tools/EventDispatcherJs.js +0 -71
- package/tools/Logger.d.ts +0 -6
- package/tools/Logger.js +0 -138
- package/ui/components/button/Button.d.ts +0 -5
- package/ui/components/button/Button.js +0 -37
- package/ui/components/carousel/Carousel.d.ts +0 -5
- package/ui/components/carousel/Carousel.js +0 -219
- package/ui/components/dropdown/Dropdown.d.ts +0 -30
- package/ui/components/dropdown/Dropdown.js +0 -92
- package/ui/components/dropdown/DropdownOptionUI.d.ts +0 -11
- package/ui/components/dropdown/DropdownOptionUI.js +0 -28
- package/ui/components/dropdown/DropdownSpreadMainUI.d.ts +0 -9
- package/ui/components/dropdown/DropdownSpreadMainUI.js +0 -27
- package/ui/components/dropdown/DropdownUnspreadMainUI.d.ts +0 -9
- package/ui/components/dropdown/DropdownUnspreadMainUI.js +0 -27
- package/ui/components/gradient/GradientText.d.ts +0 -63
- package/ui/components/outlinetext/OutlineText.d.ts +0 -73
- package/ui/components/outlinetext/OutlineText.js +0 -157
- package/ui/components/progress/Progress.d.ts +0 -34
- package/ui/components/progress/Progress.js +0 -142
- package/ui/components/slapface/Slapface.d.ts +0 -12
- package/ui/components/slapface/Slapface.js +0 -233
- package/ui/components/slider/Slider.d.ts +0 -57
- package/ui/components/slider/Slider.js +0 -289
- package/ui/components/tab/Tab.d.ts +0 -6
- package/ui/components/tab/Tab.js +0 -27
- package/ui/components/tab/Tabs.d.ts +0 -12
- package/ui/components/tab/Tabs.js +0 -54
package/README.md
CHANGED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const { copyFile, copyFileSync } = require("fs");
|
|
2
|
+
|
|
3
|
+
const PUBLISH_PATH = "publish_components"
|
|
4
|
+
|
|
5
|
+
copyFileSync("./ui/ui.md", `./../${PUBLISH_PATH}/ui/ui.md`, )
|
|
6
|
+
copyFileSync("./tools/tools.md", `./../${PUBLISH_PATH}/tools/tools.md`)
|
|
7
|
+
copyFileSync("./README.md", `./../${PUBLISH_PATH}/README.md`)
|
|
8
|
+
|
package/index.js
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export
|
|
11
|
-
export
|
|
12
|
-
export
|
|
13
|
-
export {
|
|
14
|
-
export {
|
|
15
|
-
export {
|
|
16
|
-
|
|
1
|
+
export {Tabs} from "./ui/components/tab/Tabs"
|
|
2
|
+
export {Tab} from "./ui/components/tab/Tab"
|
|
3
|
+
export {Slider} from "./ui/components/slider/Slider"
|
|
4
|
+
export {Progress} from "./ui/components/progress/Progress"
|
|
5
|
+
export{ Dropdown, DropdownConfig} from "./ui/components/dropdown/Dropdown"
|
|
6
|
+
export{DropdownOptionUI} from "./ui/components/dropdown/DropdownOptionUI"
|
|
7
|
+
export{DropdownSpreadMainUI} from "./ui/components/dropdown/DropdownSpreadMainUI"
|
|
8
|
+
export{DropdownUnspreadMainUI} from "./ui/components/dropdown/DropdownUnspreadMainUI"
|
|
9
|
+
export{GradientText} from "./ui/components/gradient/GradientText"
|
|
10
|
+
export{OutlineText} from "./ui/components/outlinetext/OutlineText"
|
|
11
|
+
export{Logger} from "./tools/Logger"
|
|
12
|
+
export{EventDispatcherJs} from "./tools/EventDispatcherJs"
|
|
13
|
+
export {Carousel} from "./ui/components/carousel/Carousel"
|
|
14
|
+
export {Slapface} from "./ui/components/slapface/Slapface"
|
|
15
|
+
export {Button} from "./ui/components/button/Button"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
console.log("Hello, 欢迎使用PixUI React Components")
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
"name": "pixuireactcomponents",
|
|
3
|
+
"version": "1.2.1",
|
|
4
|
+
"description": "pixui react components",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"author": "hardenzheng",
|
|
10
|
+
"license": "ISC"
|
|
11
11
|
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
class EventDispatcherCls { //变量在对象实例上,方法在原型上
|
|
2
|
+
private listeners = {};
|
|
3
|
+
|
|
4
|
+
AddEventListener(eventName:string, listener:any, ...args)
|
|
5
|
+
{
|
|
6
|
+
if (listener == undefined){
|
|
7
|
+
console.warn("listener为空, eventName: "+ eventName);
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
let listeners = this.listeners;
|
|
12
|
+
if (listeners[eventName] == undefined) {
|
|
13
|
+
listeners[eventName] = [];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
let eventList:Array<Object> = listeners[eventName];
|
|
17
|
+
eventList.forEach(function (v:any) {
|
|
18
|
+
if (v.eventName == eventName && v.listener == listener){
|
|
19
|
+
console.warn("重复添加的事件监听, eventName: " + eventName);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
eventList.push({"eventName":eventName,"listener":listener,"args":args,});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
HasEventListener(eventName:string){
|
|
28
|
+
if (this.listeners[eventName] == undefined || this.listeners[eventName].length == 0){
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
RemoveEventListener(eventName:string, listener){
|
|
36
|
+
if (this.HasEventListener(eventName) == false){
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
let eventList:Array<Object> = this.listeners[eventName];
|
|
41
|
+
for (let i = eventList.length - 1; i >=0; --i) {
|
|
42
|
+
let event:any = eventList[i];
|
|
43
|
+
if (event.eventName == eventName && event.listener == listener) {
|
|
44
|
+
eventList.splice(i, 1);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (eventList.length == 0){
|
|
49
|
+
this.listeners[eventName] = null;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
RemoveEventAllListener(eventName:string){
|
|
54
|
+
if (this.HasEventListener(eventName)){
|
|
55
|
+
this.listeners[eventName] = null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
DispatchEvent(eventName:string, ...args){
|
|
60
|
+
if (eventName == undefined || this.HasEventListener(eventName) == false){
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
let eventList:Array<Object> = this.listeners[eventName].slice(0);
|
|
65
|
+
for (let i = 0; i < eventList.length; ++i) {
|
|
66
|
+
let obj:any = eventList[i];
|
|
67
|
+
let listener:any = obj.listener;
|
|
68
|
+
// listener.apply(this, obj.args.concat(args));
|
|
69
|
+
listener(...obj.args.concat(args))
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export let EventDispatcherJs = Object.freeze(new EventDispatcherCls());
|
package/tools/Logger.tsx
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
export function Logger(){
|
|
2
|
+
}
|
|
3
|
+
|
|
4
|
+
// 移除最后一个(key, value)后面的 ','
|
|
5
|
+
let regex = new RegExp("(,)(\n$)");
|
|
6
|
+
/**
|
|
7
|
+
* printer1: 完整打印,用4个空格缩进
|
|
8
|
+
* @param object Object
|
|
9
|
+
* @param name string
|
|
10
|
+
*/
|
|
11
|
+
Logger.ObjectPrinter = function(object, name){
|
|
12
|
+
let strResult = "";
|
|
13
|
+
strResult += name + " = ";
|
|
14
|
+
strResult += getTreeStyleStr(object, 1);
|
|
15
|
+
|
|
16
|
+
strResult = strResult.replace(regex, "$2");
|
|
17
|
+
console.warn(strResult);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function getTreeStyleStr(object, level){
|
|
21
|
+
const isArray = object instanceof Array
|
|
22
|
+
let str = isArray ? "[\n" : "{\n";
|
|
23
|
+
for (const key in object) {
|
|
24
|
+
let value = object[key];
|
|
25
|
+
let curSeparation = getSeparation1(level);
|
|
26
|
+
|
|
27
|
+
if(typeof(value) != 'object'){
|
|
28
|
+
str += curSeparation + key + " : " + value + ",\n";
|
|
29
|
+
}
|
|
30
|
+
else{
|
|
31
|
+
str += curSeparation + key + " : " + getTreeStyleStr(value, level + 1);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
str = str.replace(regex, "$2");
|
|
36
|
+
str += getSeparation1(level - 1) + (isArray ? "],\n" : "},\n");
|
|
37
|
+
return str;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const SEPARARION1 = " ";
|
|
41
|
+
function getSeparation1(level){
|
|
42
|
+
let totalSeparation = "";
|
|
43
|
+
while(level > 0){
|
|
44
|
+
totalSeparation += SEPARARION1;
|
|
45
|
+
level--;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return totalSeparation;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
let regexForLine = new RegExp(",$")
|
|
53
|
+
/**
|
|
54
|
+
* printer2: 完整打印,用\t
|
|
55
|
+
* @param object Object
|
|
56
|
+
* @param name sring
|
|
57
|
+
*/
|
|
58
|
+
Logger.ObjectPrinter2 = function(object, name){
|
|
59
|
+
let lines: string[] = []
|
|
60
|
+
lines.push(`${name} = `)
|
|
61
|
+
getTreeStyleLines(object, 1, lines)
|
|
62
|
+
|
|
63
|
+
console.warn(lines.join("\n"))
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function getTreeStyleLines(object: Object, level: number, lines: string[]){
|
|
67
|
+
const isArray = object instanceof Array
|
|
68
|
+
let linePostFix = isArray ? "[" : "{"
|
|
69
|
+
|
|
70
|
+
let lastLine = lines.pop()
|
|
71
|
+
lines.push(lastLine + linePostFix)
|
|
72
|
+
|
|
73
|
+
for (const key in object) {
|
|
74
|
+
const value = object[key];
|
|
75
|
+
const curSeparation = getSeparation2(level);
|
|
76
|
+
|
|
77
|
+
if(typeof(value) != 'object'){
|
|
78
|
+
let curLine = curSeparation + key + " : " + value + ",";
|
|
79
|
+
lines.push(curLine)
|
|
80
|
+
}
|
|
81
|
+
else{
|
|
82
|
+
let curLinePreFix = curSeparation + key + " : "
|
|
83
|
+
lines.push(curLinePreFix)
|
|
84
|
+
getTreeStyleLines(value, level + 1, lines);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
lastLine = lines.pop()
|
|
89
|
+
if(lastLine) lines.push(lastLine.replace(regexForLine, "")) // 一定执行
|
|
90
|
+
|
|
91
|
+
lines.push(getSeparation2(level - 1) + (isArray ? "]" : "}"))
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const SEPARARION2 = "\t";
|
|
95
|
+
function getSeparation2(level){
|
|
96
|
+
let totalSeparation = "";
|
|
97
|
+
while(level > 0){
|
|
98
|
+
totalSeparation += SEPARARION2;
|
|
99
|
+
level--;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return totalSeparation;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
*
|
|
107
|
+
printer3: 打印关键层级信息,如果是数组,只打印第一个,后续用 ...len 代替(PS: 假定数组中每个元素都是一样的格式)
|
|
108
|
+
* @param object Object
|
|
109
|
+
* @param name string
|
|
110
|
+
*/
|
|
111
|
+
Logger.HierarchyPrinter = function(object, name){
|
|
112
|
+
let lines: string[] = []
|
|
113
|
+
lines.push(`${name} = `)
|
|
114
|
+
getTreeStyleHierarchyLines(object, 1, lines)
|
|
115
|
+
|
|
116
|
+
console.warn(lines.join("\n"))
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function getTreeStyleHierarchyLines(object, level: number, lines: string[]){
|
|
120
|
+
const isArray = object instanceof Array
|
|
121
|
+
let linePostFix = isArray ? "[" : "{"
|
|
122
|
+
let lastLine = lines.pop()
|
|
123
|
+
lines.push(lastLine + linePostFix)
|
|
124
|
+
|
|
125
|
+
if(isArray){
|
|
126
|
+
const key = 0
|
|
127
|
+
const value = object[key];
|
|
128
|
+
const curSeparation = getSeparation2(level);
|
|
129
|
+
|
|
130
|
+
if(typeof(value) != 'object'){
|
|
131
|
+
let curLine = curSeparation + key + " : " + value + ",";
|
|
132
|
+
lines.push(curLine)
|
|
133
|
+
}
|
|
134
|
+
else{
|
|
135
|
+
let curLinePreFix = curSeparation + key + " : "
|
|
136
|
+
lines.push(curLinePreFix)
|
|
137
|
+
getTreeStyleHierarchyLines(value, level + 1, lines);
|
|
138
|
+
}
|
|
139
|
+
lines.push(curSeparation + "...len=" + object.length)
|
|
140
|
+
}
|
|
141
|
+
else{
|
|
142
|
+
for (const key in object) {
|
|
143
|
+
const value = object[key];
|
|
144
|
+
const curSeparation = getSeparation2(level);
|
|
145
|
+
|
|
146
|
+
if(typeof(value) != 'object'){
|
|
147
|
+
let curLine = curSeparation + key + " : " + value + ",";
|
|
148
|
+
lines.push(curLine)
|
|
149
|
+
}
|
|
150
|
+
else{
|
|
151
|
+
let curLinePreFix = curSeparation + key + " : "
|
|
152
|
+
lines.push(curLinePreFix)
|
|
153
|
+
getTreeStyleHierarchyLines(value, level + 1, lines);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
lastLine = lines.pop()
|
|
157
|
+
if(lastLine) lines.push(lastLine.replace(regexForLine, "")) // 一定执行
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
lines.push(getSeparation2(level - 1) + (isArray ? "]" : "}"))
|
|
161
|
+
}
|
|
Binary file
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es5",
|
|
4
|
+
"module": "ES6",
|
|
5
|
+
"baseUrl": ".",
|
|
6
|
+
"paths": {
|
|
7
|
+
"preact": ["../../lib/preact/src"],
|
|
8
|
+
},
|
|
9
|
+
"outDir": "../publish_components",
|
|
10
|
+
"allowJs": true,
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"esModuleInterop": true,
|
|
13
|
+
"allowSyntheticDefaultImports": true,
|
|
14
|
+
"strict": true,
|
|
15
|
+
"forceConsistentCasingInFileNames": true,
|
|
16
|
+
"moduleResolution":"node",
|
|
17
|
+
"resolveJsonModule": true,
|
|
18
|
+
"noImplicitAny": false,
|
|
19
|
+
"jsx":"react",
|
|
20
|
+
"jsxFactory": "h",
|
|
21
|
+
// "sourceMap": false,
|
|
22
|
+
"declaration": true,
|
|
23
|
+
"declarationDir": "../publish_components"
|
|
24
|
+
// "noEmit": true
|
|
25
|
+
},
|
|
26
|
+
"files":[
|
|
27
|
+
"index.js",
|
|
28
|
+
"package.json",
|
|
29
|
+
],
|
|
30
|
+
"include": [
|
|
31
|
+
"ui/components/tab/*",
|
|
32
|
+
"ui/components/slider/*",
|
|
33
|
+
"ui/components/progress/*",
|
|
34
|
+
"ui/components/dropdown/*",
|
|
35
|
+
"ui/components/gradient/*",
|
|
36
|
+
"ui/components/outlinetext",
|
|
37
|
+
"tools/*",
|
|
38
|
+
"ui/components/carousel/*",
|
|
39
|
+
"ui/components/slapface/*",
|
|
40
|
+
"ui/components/slapface/less/*",
|
|
41
|
+
"ui/components/button/*",
|
|
42
|
+
|
|
43
|
+
],
|
|
44
|
+
|
|
45
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { createRef } from 'lib/preact/src/create-element';
|
|
2
|
+
import { Component, CSSProperties } from 'preact';
|
|
3
|
+
|
|
4
|
+
// 弹幕相关个性化信息
|
|
5
|
+
export class BulletInfo {
|
|
6
|
+
key: number;
|
|
7
|
+
text: string;
|
|
8
|
+
channel: number;
|
|
9
|
+
color: string;
|
|
10
|
+
fontSize: number;
|
|
11
|
+
|
|
12
|
+
constructor(
|
|
13
|
+
key: number,
|
|
14
|
+
text: string,
|
|
15
|
+
channel: number,
|
|
16
|
+
color: string,
|
|
17
|
+
fontSize: number
|
|
18
|
+
) {
|
|
19
|
+
this.key = key;
|
|
20
|
+
this.text = text;
|
|
21
|
+
this.channel = channel;
|
|
22
|
+
this.color = color;
|
|
23
|
+
this.fontSize = fontSize;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// 同一行弹幕的间距
|
|
28
|
+
const BULLET_DISTANCE = 50;
|
|
29
|
+
// 弹幕超出屏幕后滑行距离
|
|
30
|
+
const BULLET_MAX_LEN = 400;
|
|
31
|
+
|
|
32
|
+
// 弹幕相关配置信息
|
|
33
|
+
export class BulletConfig {
|
|
34
|
+
screenWidth: number; //弹幕宽度
|
|
35
|
+
channelHeight: number; //弹幕高度
|
|
36
|
+
totalTime: number; //单条弹幕滑行时间
|
|
37
|
+
|
|
38
|
+
constructor(
|
|
39
|
+
screenWidth: number,
|
|
40
|
+
channelHeight: number,
|
|
41
|
+
totalTime: number
|
|
42
|
+
) {
|
|
43
|
+
this.screenWidth = screenWidth;
|
|
44
|
+
this.channelHeight = channelHeight;
|
|
45
|
+
this.totalTime = totalTime;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// 使用Animation
|
|
50
|
+
export class BulletItemAnimation extends Component<
|
|
51
|
+
{
|
|
52
|
+
bulletInfo: BulletInfo;
|
|
53
|
+
bulletConfig: BulletConfig;
|
|
54
|
+
onItemFree: Function;
|
|
55
|
+
onChannelFree: Function;
|
|
56
|
+
}, {}>{
|
|
57
|
+
|
|
58
|
+
private freeChannelTimer: any = undefined;
|
|
59
|
+
private refText = createRef()
|
|
60
|
+
|
|
61
|
+
constructor(props) {
|
|
62
|
+
super(props);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
componentDidMount() {
|
|
66
|
+
this.refText.current.addEventListener('animationstart', this.onAnimationStart);
|
|
67
|
+
this.refText.current.addEventListener('animationend', this.onAnimationEnd);
|
|
68
|
+
|
|
69
|
+
window.requestAnimationFrame(this.setFreeChannelTimer);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
onAnimationStart = () => {
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
onAnimationEnd = () => {
|
|
76
|
+
this.props.onItemFree();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
setFreeChannelTimer = () => {
|
|
80
|
+
let realWidthStr = window.getComputedStyle(this.refText.current, null).getPropertyValue('width');
|
|
81
|
+
let widthNum = parseInt(realWidthStr.substring(0, realWidthStr.length - 2));
|
|
82
|
+
this.freeChannelTimer = setTimeout(this.freeChannel, (widthNum + BULLET_DISTANCE) / (this.props.bulletConfig.screenWidth + BULLET_MAX_LEN) * this.props.bulletConfig.totalTime);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
freeChannel = () => {
|
|
86
|
+
this.props.onChannelFree(this.props.bulletInfo.channel);
|
|
87
|
+
clearTimeout(this.freeChannelTimer);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
render() {
|
|
91
|
+
|
|
92
|
+
let isMe = false;
|
|
93
|
+
|
|
94
|
+
const bulletStyle: CSSProperties = {
|
|
95
|
+
marginTop: (this.props.bulletInfo.channel * this.props.bulletConfig.channelHeight) + 'px',
|
|
96
|
+
height: this.props.bulletConfig.channelHeight + 'px',
|
|
97
|
+
left: this.props.bulletConfig.screenWidth + 'px',
|
|
98
|
+
animation: 'bulletKeyframe 10s linear 1',
|
|
99
|
+
|
|
100
|
+
position: 'absolute',
|
|
101
|
+
display: 'flex',
|
|
102
|
+
flexDirection: 'row',
|
|
103
|
+
justifyContent: 'flex-start',
|
|
104
|
+
alignItems: 'center',
|
|
105
|
+
border: isMe ? '1px solid ' + this.props.bulletInfo.color : '',
|
|
106
|
+
|
|
107
|
+
fontSize: this.props.bulletInfo.fontSize + 'px', //'16px',
|
|
108
|
+
color: this.props.bulletInfo.color,
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
return (
|
|
112
|
+
<div ref={this.refText} style={bulletStyle}>
|
|
113
|
+
<text>{this.props.bulletInfo.text}</text>
|
|
114
|
+
</div>
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
}
|