pixuireactcomponents 1.5.47 → 1.5.48
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 +1 -1
- package/src/components/react/app/carousel/Carousel.js +53 -43
- package/src/components/react/app/lottery/LotteryComponent.d.ts +45 -0
- package/src/components/react/app/lottery/LotteryComponent.js +139 -0
- package/src/components/react/app/scrollingText/ScrollingText.d.ts +11 -0
- package/src/components/react/app/scrollingText/ScrollingText.js +76 -0
- package/src/components/react/app/videoPlayer/VideoPlayer.js +1 -5
package/package.json
CHANGED
|
@@ -23,28 +23,38 @@ import { useImperativeHandle, useState, useRef, useMemo, useEffect } from 'preac
|
|
|
23
23
|
// import { memo } from '../../../../../lib/preact/compat/src';
|
|
24
24
|
//组件优化,防止组件的props没有改变但父组件刷新时导致组件刷新
|
|
25
25
|
// export let Carousel = memo(Carouselinner, (prev, next) => {
|
|
26
|
-
// //
|
|
26
|
+
// // debugLog('prev', prev, 'next', next);
|
|
27
27
|
// let isSame = true;
|
|
28
28
|
// Object.keys(prev).forEach((key) => {
|
|
29
29
|
// if (key === 'children') {
|
|
30
|
-
//
|
|
30
|
+
// debugLog('kkk', prev.children.length, next.children.length);
|
|
31
31
|
// if (prev.children.length !== next.children.length) {
|
|
32
|
-
//
|
|
32
|
+
// debugLog('fffffffffffffffff children');
|
|
33
33
|
// isSame = false;
|
|
34
34
|
// }
|
|
35
35
|
// for (let i = 0; i < prev.children.length; i++) {
|
|
36
36
|
// if (prev.children[i].key !== next.children[i].key) {
|
|
37
|
-
//
|
|
37
|
+
// debugLog('fffffffffffffffff children nnn');
|
|
38
38
|
// isSame = false;
|
|
39
39
|
// }
|
|
40
40
|
// }
|
|
41
41
|
// } else if (prev[key] !== next[key]) {
|
|
42
|
-
//
|
|
42
|
+
// debugLog('fffffffffffff',prev[key]);
|
|
43
43
|
// isSame = false;
|
|
44
44
|
// }
|
|
45
45
|
// });
|
|
46
46
|
// return isSame;
|
|
47
47
|
// });
|
|
48
|
+
var enableCarouselLog = false;
|
|
49
|
+
var debugLog = function () {
|
|
50
|
+
var args = [];
|
|
51
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
52
|
+
args[_i] = arguments[_i];
|
|
53
|
+
}
|
|
54
|
+
if (enableCarouselLog) {
|
|
55
|
+
console.log.apply(console, __spreadArray(['[Carousel Debug]'], args, false));
|
|
56
|
+
}
|
|
57
|
+
};
|
|
48
58
|
/**
|
|
49
59
|
* 轮播组件
|
|
50
60
|
* @param cRef - 组件引用,其中导出了3个方法:handleNext,handlePrev,setShowIndex
|
|
@@ -66,7 +76,7 @@ export function Carousel(props) {
|
|
|
66
76
|
var _a = props.rootId, rootId = _a === void 0 ? '' : _a, _b = props.rootClassName, rootClassName = _b === void 0 ? '' : _b, _c = props.children, children = _c === void 0 ? [] : _c, _d = props.defaultIndex, defaultIndex = _d === void 0 ? 1 : _d, _e = props.compWidth, compWidth = _e === void 0 ? 100 : _e, _f = props.compHeight, compHeight = _f === void 0 ? 100 : _f, _g = props.autoplay, autoplay = _g === void 0 ? true : _g, _h = props.switchDuration, switchDuration = _h === void 0 ? 3000 : _h, _j = props.loop, loop = _j === void 0 ? true : _j, _k = props.isVertical, isVertical = _k === void 0 ? false : _k, _l = props.touchable, touchable = _l === void 0 ? true : _l, _m = props.onSlideChange, onSlideChange = _m === void 0 ? null : _m, _o = props.onClick, onClick = _o === void 0 ? null : _o, _p = props.touchSwitchDistance, touchSwitchDistance = _p === void 0 ? props.touchSwitchDistance && props.touchSwitchDistance > 0 && props.touchSwitchDistance < 1
|
|
67
77
|
? props.touchSwitchDistance
|
|
68
78
|
: 0.3 : _p;
|
|
69
|
-
//
|
|
79
|
+
// debugLog('children', children.length);
|
|
70
80
|
var safeNext = function () {
|
|
71
81
|
if (!canClickSwitch.current)
|
|
72
82
|
return;
|
|
@@ -98,7 +108,7 @@ export function Carousel(props) {
|
|
|
98
108
|
var _q = useState(defaultIndex), showIndex = _q[0], setShowIndex = _q[1];
|
|
99
109
|
// 监听 showIndex 变化
|
|
100
110
|
useEffect(function () {
|
|
101
|
-
|
|
111
|
+
debugLog('[Carousel Debug] showIndex变化: ' +
|
|
102
112
|
JSON.stringify({
|
|
103
113
|
showIndex: showIndex,
|
|
104
114
|
defaultIndex: defaultIndex,
|
|
@@ -123,7 +133,7 @@ export function Carousel(props) {
|
|
|
123
133
|
// 添加初始化保护标志
|
|
124
134
|
var isInitializing = useRef(true);
|
|
125
135
|
useEffect(function () {
|
|
126
|
-
|
|
136
|
+
debugLog('[Carousel Debug] showTransition变化: ' +
|
|
127
137
|
JSON.stringify({
|
|
128
138
|
showTransition: showTransition,
|
|
129
139
|
compWidth: compWidth,
|
|
@@ -131,7 +141,7 @@ export function Carousel(props) {
|
|
|
131
141
|
}));
|
|
132
142
|
}, [showTransition]);
|
|
133
143
|
useEffect(function () {
|
|
134
|
-
|
|
144
|
+
debugLog('[Carousel Debug] 尺寸变化检测: ' +
|
|
135
145
|
JSON.stringify({
|
|
136
146
|
compWidth: compWidth,
|
|
137
147
|
compHeight: compHeight,
|
|
@@ -143,7 +153,7 @@ export function Carousel(props) {
|
|
|
143
153
|
if (compWidth > 0 && compHeight > 0) {
|
|
144
154
|
// 只有在初始化期间才重置索引
|
|
145
155
|
if (isInitializing.current) {
|
|
146
|
-
|
|
156
|
+
debugLog('[Carousel Debug] 初始化期间,重置到默认索引: ' + defaultIndex);
|
|
147
157
|
setShowIndex(defaultIndex);
|
|
148
158
|
// 确保动画关闭,避免从错误位置过渡
|
|
149
159
|
setShowTransition(false);
|
|
@@ -151,14 +161,14 @@ export function Carousel(props) {
|
|
|
151
161
|
isInitializing.current = false;
|
|
152
162
|
// 延迟设置自动播放,避免立即触发动画开启逻辑
|
|
153
163
|
setTimeout(function () {
|
|
154
|
-
|
|
164
|
+
debugLog('[Carousel Debug] 初始化完成,延迟设置自动播放');
|
|
155
165
|
setNextInterval();
|
|
156
166
|
}, 100);
|
|
157
167
|
}
|
|
158
168
|
}
|
|
159
169
|
}, [compWidth, compHeight]);
|
|
160
170
|
// 添加调试日志
|
|
161
|
-
|
|
171
|
+
debugLog('[Carousel Debug] 组件渲染 - props: ' +
|
|
162
172
|
JSON.stringify({
|
|
163
173
|
compWidth: compWidth,
|
|
164
174
|
compHeight: compHeight,
|
|
@@ -168,7 +178,7 @@ export function Carousel(props) {
|
|
|
168
178
|
}));
|
|
169
179
|
var offset = useMemo(function () {
|
|
170
180
|
var calculatedOffset = -(isVertical ? compHeight : compWidth) * showIndex;
|
|
171
|
-
|
|
181
|
+
debugLog('[Carousel Debug] offset计算: ' +
|
|
172
182
|
JSON.stringify({
|
|
173
183
|
isVertical: isVertical,
|
|
174
184
|
compWidth: compWidth,
|
|
@@ -195,16 +205,16 @@ export function Carousel(props) {
|
|
|
195
205
|
useEffect(function () {
|
|
196
206
|
// 只有在初始化完成后才设置自动播放
|
|
197
207
|
if (!isInitializing.current) {
|
|
198
|
-
|
|
208
|
+
debugLog('[Carousel Debug] autoplay变化,设置自动播放');
|
|
199
209
|
setNextInterval();
|
|
200
210
|
}
|
|
201
211
|
else {
|
|
202
|
-
|
|
212
|
+
debugLog('[Carousel Debug] 初始化期间,跳过autoplay变化处理');
|
|
203
213
|
}
|
|
204
214
|
}, [autoplay]);
|
|
205
215
|
//组件展示内容长度改变的时候改回到第一个元素,刷新autoplay判断
|
|
206
216
|
useEffect(function () {
|
|
207
|
-
|
|
217
|
+
debugLog('[Carousel Debug] children变化: ' +
|
|
208
218
|
JSON.stringify({
|
|
209
219
|
childrenLength: children.length,
|
|
210
220
|
defaultIndex: defaultIndex,
|
|
@@ -217,16 +227,16 @@ export function Carousel(props) {
|
|
|
217
227
|
setNextInterval();
|
|
218
228
|
// 只有在尺寸有效时才重置索引,避免在初始化时干扰尺寸变化监听
|
|
219
229
|
if (compWidth > 0 && compHeight > 0) {
|
|
220
|
-
|
|
230
|
+
debugLog('[Carousel Debug] children变化时重置索引: ' + defaultIndex);
|
|
221
231
|
setShowIndex(defaultIndex);
|
|
222
232
|
}
|
|
223
233
|
}
|
|
224
234
|
else {
|
|
225
|
-
|
|
235
|
+
debugLog('[Carousel Debug] 初始化期间,跳过children变化处理');
|
|
226
236
|
}
|
|
227
237
|
}, [children]);
|
|
228
238
|
useEffect(function () {
|
|
229
|
-
|
|
239
|
+
debugLog('[Carousel Debug] showIndex useEffect触发: ' +
|
|
230
240
|
JSON.stringify({
|
|
231
241
|
showIndex: showIndex,
|
|
232
242
|
isLast: isLastCarouseItem(),
|
|
@@ -236,11 +246,11 @@ export function Carousel(props) {
|
|
|
236
246
|
//每次跳转前判断打开动画,否则动画关闭以后不会调用handleTransitionEnd
|
|
237
247
|
// 但在初始化期间不开启动画
|
|
238
248
|
if (!isLastCarouseItem() && !isFirstCarouseLastItem() && !isInitializing.current) {
|
|
239
|
-
|
|
249
|
+
debugLog('[Carousel Debug] 因showIndex变化开启动画');
|
|
240
250
|
setShowTransition(true);
|
|
241
251
|
}
|
|
242
252
|
else if (isInitializing.current) {
|
|
243
|
-
|
|
253
|
+
debugLog('[Carousel Debug] 初始化期间,跳过showIndex动画开启');
|
|
244
254
|
}
|
|
245
255
|
}, [showIndex]);
|
|
246
256
|
//更新handleNext的环境
|
|
@@ -248,7 +258,7 @@ export function Carousel(props) {
|
|
|
248
258
|
handleNextRef.current = handleNext;
|
|
249
259
|
});
|
|
250
260
|
var setNextInterval = function () {
|
|
251
|
-
|
|
261
|
+
debugLog('[Carousel Debug] setNextInterval调用: ' +
|
|
252
262
|
JSON.stringify({
|
|
253
263
|
childrenLength: children.length,
|
|
254
264
|
autoplay: autoplay,
|
|
@@ -260,13 +270,13 @@ export function Carousel(props) {
|
|
|
260
270
|
nextInterval.current && clearInterval(nextInterval.current);
|
|
261
271
|
// 只有在初始化完成后才设置自动播放
|
|
262
272
|
if (children.length > 1 && autoplay && !isInitializing.current) {
|
|
263
|
-
|
|
273
|
+
debugLog('[Carousel Debug] 设置自动播放定时器');
|
|
264
274
|
nextInterval.current = setInterval(function () {
|
|
265
275
|
handleNextRef.current();
|
|
266
276
|
}, duration);
|
|
267
277
|
}
|
|
268
278
|
else {
|
|
269
|
-
|
|
279
|
+
debugLog('[Carousel Debug] 跳过自动播放设置:', {
|
|
270
280
|
childrenLength: children.length,
|
|
271
281
|
autoplay: autoplay,
|
|
272
282
|
isInitializing: isInitializing.current,
|
|
@@ -275,7 +285,7 @@ export function Carousel(props) {
|
|
|
275
285
|
// 当组件开始正常工作时(有子元素且尺寸有效),开启动画
|
|
276
286
|
// 但避免在尺寸刚变为有效时立即开启,给尺寸重置逻辑一些时间
|
|
277
287
|
var shouldEnableTransition = children.length > 0 && compWidth > 0 && compHeight > 0;
|
|
278
|
-
|
|
288
|
+
debugLog('[Carousel Debug] 动画状态检查: ' +
|
|
279
289
|
JSON.stringify({
|
|
280
290
|
shouldEnableTransition: shouldEnableTransition,
|
|
281
291
|
currentShowTransition: showTransition,
|
|
@@ -287,16 +297,16 @@ export function Carousel(props) {
|
|
|
287
297
|
setTimeout(function () {
|
|
288
298
|
// 再次检查初始化状态,确保在延迟期间没有重新初始化
|
|
289
299
|
if (!isInitializing.current) {
|
|
290
|
-
|
|
300
|
+
debugLog('[Carousel Debug] 延迟开启动画过渡');
|
|
291
301
|
setShowTransition(true);
|
|
292
302
|
}
|
|
293
303
|
else {
|
|
294
|
-
|
|
304
|
+
debugLog('[Carousel Debug] 延迟期间仍在初始化,跳过动画开启');
|
|
295
305
|
}
|
|
296
306
|
}, 50);
|
|
297
307
|
}
|
|
298
308
|
else {
|
|
299
|
-
|
|
309
|
+
debugLog('[Carousel Debug] 跳过动画开启:', {
|
|
300
310
|
shouldEnableTransition: shouldEnableTransition,
|
|
301
311
|
showTransition: showTransition,
|
|
302
312
|
isInitializing: isInitializing.current,
|
|
@@ -304,18 +314,18 @@ export function Carousel(props) {
|
|
|
304
314
|
}
|
|
305
315
|
};
|
|
306
316
|
useEffect(function () {
|
|
307
|
-
|
|
308
|
-
|
|
317
|
+
debugLog('[Carousel Debug] 组件初始化开始');
|
|
318
|
+
debugLog('Carousel init');
|
|
309
319
|
// 初始化期间不设置自动播放
|
|
310
320
|
// setNextInterval();
|
|
311
321
|
window.addEventListener('close', function () {
|
|
312
|
-
|
|
322
|
+
debugLog('Carousel close');
|
|
313
323
|
nextInterval.current && clearInterval(nextInterval.current);
|
|
314
324
|
safeNextHandle.current && clearTimeout(safeNextHandle.current);
|
|
315
325
|
safePrevHandle.current && clearTimeout(safePrevHandle.current);
|
|
316
326
|
});
|
|
317
327
|
return function () {
|
|
318
|
-
|
|
328
|
+
debugLog('Carousel useEffect close');
|
|
319
329
|
nextInterval.current && clearInterval(nextInterval.current);
|
|
320
330
|
safeNextHandle.current && clearTimeout(safeNextHandle.current);
|
|
321
331
|
safePrevHandle.current && clearTimeout(safePrevHandle.current);
|
|
@@ -343,7 +353,7 @@ export function Carousel(props) {
|
|
|
343
353
|
setShowIndex(showIndex + 1);
|
|
344
354
|
};
|
|
345
355
|
var handleTransitionEnd = function () {
|
|
346
|
-
|
|
356
|
+
debugLog('[Carousel Debug] 动画结束: ' +
|
|
347
357
|
JSON.stringify({
|
|
348
358
|
showIndex: showIndex,
|
|
349
359
|
isLast: isLastCarouseItem(),
|
|
@@ -353,29 +363,29 @@ export function Carousel(props) {
|
|
|
353
363
|
//判断前后补位元素准备跳转
|
|
354
364
|
//在动画结束以后关掉,否则用鼠标拖动的时候不能补充剩下的offset
|
|
355
365
|
if (isLastCarouseItem() || isFirstCarouseLastItem()) {
|
|
356
|
-
|
|
366
|
+
debugLog('[Carousel Debug] 因首尾特殊情况关闭动画');
|
|
357
367
|
setShowTransition(false);
|
|
358
368
|
}
|
|
359
369
|
isMoving.current = false;
|
|
360
370
|
//触发onSlideChange
|
|
361
371
|
if (!isLastCarouseItem() && !isFirstCarouseLastItem() && onSlideChange && lastOnSlideChangeIndex.current !== showIndex) {
|
|
362
|
-
|
|
372
|
+
debugLog('[Carousel Debug] 触发onSlideChange: ' + (showIndex - 1));
|
|
363
373
|
onSlideChange(showIndex - 1);
|
|
364
374
|
lastOnSlideChangeIndex.current = showIndex;
|
|
365
375
|
}
|
|
366
376
|
// 处理首尾特殊case,但在初始化期间跳过
|
|
367
377
|
if (!isInitializing.current) {
|
|
368
378
|
if (isLastCarouseItem()) {
|
|
369
|
-
|
|
379
|
+
debugLog('[Carousel Debug] 处理末尾case,跳转到索引1');
|
|
370
380
|
setShowIndex(1);
|
|
371
381
|
}
|
|
372
382
|
if (isFirstCarouseLastItem()) {
|
|
373
|
-
|
|
383
|
+
debugLog('[Carousel Debug] 处理开头case,跳转到索引' + (carouselItems.length - 2));
|
|
374
384
|
setShowIndex(carouselItems.length - 2);
|
|
375
385
|
}
|
|
376
386
|
}
|
|
377
387
|
else {
|
|
378
|
-
|
|
388
|
+
debugLog('[Carousel Debug] 初始化期间,跳过首尾特殊情况处理');
|
|
379
389
|
}
|
|
380
390
|
};
|
|
381
391
|
var gestureUp = function () {
|
|
@@ -424,13 +434,13 @@ export function Carousel(props) {
|
|
|
424
434
|
if (showIndex == 1) {
|
|
425
435
|
if (!isVertical) {
|
|
426
436
|
if (x - mouseDownX.current > 0) {
|
|
427
|
-
//
|
|
437
|
+
// debugLog('stop x', x);
|
|
428
438
|
return;
|
|
429
439
|
}
|
|
430
440
|
}
|
|
431
441
|
else {
|
|
432
442
|
if (y - mouseDownY.current < 0) {
|
|
433
|
-
//
|
|
443
|
+
// debugLog('stop y', y);
|
|
434
444
|
return;
|
|
435
445
|
}
|
|
436
446
|
}
|
|
@@ -438,13 +448,13 @@ export function Carousel(props) {
|
|
|
438
448
|
else if (showIndex == carouselItems.length - 2) {
|
|
439
449
|
if (!isVertical) {
|
|
440
450
|
if (x - mouseDownX.current < 0) {
|
|
441
|
-
//
|
|
451
|
+
// debugLog('stop x', x);
|
|
442
452
|
return;
|
|
443
453
|
}
|
|
444
454
|
}
|
|
445
455
|
else {
|
|
446
456
|
if (y - mouseDownY.current < 0) {
|
|
447
|
-
//
|
|
457
|
+
// debugLog('stop y', y);
|
|
448
458
|
return;
|
|
449
459
|
}
|
|
450
460
|
}
|
|
@@ -480,7 +490,7 @@ export function Carousel(props) {
|
|
|
480
490
|
// 渲染时关键样式信息
|
|
481
491
|
var transformValue = isVertical ? "translate(0px, ".concat(offset + gestureoffset[1], "px)") : "translate(".concat(offset + gestureoffset[0], "px, 0px)");
|
|
482
492
|
var transitionValue = "transform ".concat(showTransition ? '0.4s' : '0s', " ease 0s");
|
|
483
|
-
|
|
493
|
+
debugLog('[Carousel Debug] 渲染样式: ' +
|
|
484
494
|
JSON.stringify({
|
|
485
495
|
transformValue: transformValue,
|
|
486
496
|
transitionValue: transitionValue,
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Component, h } from 'preact';
|
|
2
|
+
type LotteryProps = {
|
|
3
|
+
LotteryStyles: {
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
background?: string;
|
|
7
|
+
align?: "flex-start" | "center" | "flex-end";
|
|
8
|
+
type?: "rectangle" | "round";
|
|
9
|
+
};
|
|
10
|
+
RewardList: any[];
|
|
11
|
+
RewardStyles: {
|
|
12
|
+
width: number;
|
|
13
|
+
height: number;
|
|
14
|
+
};
|
|
15
|
+
animationConfig?: {
|
|
16
|
+
baseRollCount?: number;
|
|
17
|
+
speed?: number;
|
|
18
|
+
aniStyle: Object;
|
|
19
|
+
targetIndex: number;
|
|
20
|
+
speedDegree?: number;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
export default class Lottery extends Component<LotteryProps, any> {
|
|
24
|
+
constructor(props: LotteryProps);
|
|
25
|
+
timer: any;
|
|
26
|
+
speed: number;
|
|
27
|
+
count: number;
|
|
28
|
+
baseRollCount: number;
|
|
29
|
+
speedDegree: number;
|
|
30
|
+
componentWillUpdate(nextProps: Readonly<LotteryProps>, nextState: Readonly<any>, nextContext: any): void;
|
|
31
|
+
setLotteryStyles(): {
|
|
32
|
+
width: number;
|
|
33
|
+
height: number;
|
|
34
|
+
background: string;
|
|
35
|
+
};
|
|
36
|
+
setRewardStyles(index: any, total: any): {
|
|
37
|
+
width: number;
|
|
38
|
+
height: number;
|
|
39
|
+
marginRight: string;
|
|
40
|
+
marginBottom: string;
|
|
41
|
+
};
|
|
42
|
+
setAnimation(): void;
|
|
43
|
+
render(): h.JSX.Element;
|
|
44
|
+
}
|
|
45
|
+
export {};
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
var __extends = (this && this.__extends) || (function () {
|
|
2
|
+
var extendStatics = function (d, b) {
|
|
3
|
+
extendStatics = Object.setPrototypeOf ||
|
|
4
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
+
return extendStatics(d, b);
|
|
7
|
+
};
|
|
8
|
+
return function (d, b) {
|
|
9
|
+
if (typeof b !== "function" && b !== null)
|
|
10
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
+
extendStatics(d, b);
|
|
12
|
+
function __() { this.constructor = d; }
|
|
13
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
+
};
|
|
15
|
+
})();
|
|
16
|
+
var __assign = (this && this.__assign) || function () {
|
|
17
|
+
__assign = Object.assign || function(t) {
|
|
18
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
19
|
+
s = arguments[i];
|
|
20
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
21
|
+
t[p] = s[p];
|
|
22
|
+
}
|
|
23
|
+
return t;
|
|
24
|
+
};
|
|
25
|
+
return __assign.apply(this, arguments);
|
|
26
|
+
};
|
|
27
|
+
import { Component, h } from 'preact';
|
|
28
|
+
var Lottery = /** @class */ (function (_super) {
|
|
29
|
+
__extends(Lottery, _super);
|
|
30
|
+
function Lottery(props) {
|
|
31
|
+
var _a, _b, _c, _d;
|
|
32
|
+
var _this = _super.call(this, props) || this;
|
|
33
|
+
_this.timer = null;
|
|
34
|
+
_this.speed = ((_a = _this.props.animationConfig) === null || _a === void 0 ? void 0 : _a.speed) || 100;
|
|
35
|
+
_this.count = 0;
|
|
36
|
+
_this.baseRollCount = ((_b = _this.props.animationConfig) === null || _b === void 0 ? void 0 : _b.baseRollCount) || 30;
|
|
37
|
+
_this.speedDegree = ((_c = _this.props.animationConfig) === null || _c === void 0 ? void 0 : _c.speedDegree) || 10;
|
|
38
|
+
_this.state = {
|
|
39
|
+
activeIndex: -1,
|
|
40
|
+
targetIndex: ((_d = _this.props.animationConfig) === null || _d === void 0 ? void 0 : _d.targetIndex) || 0
|
|
41
|
+
};
|
|
42
|
+
_this.setAnimation = _this.setAnimation.bind(_this);
|
|
43
|
+
return _this;
|
|
44
|
+
}
|
|
45
|
+
Lottery.prototype.componentWillUpdate = function (nextProps, nextState, nextContext) {
|
|
46
|
+
var _a, _b, _c;
|
|
47
|
+
if (((_a = nextProps.animationConfig) === null || _a === void 0 ? void 0 : _a.targetIndex) !== ((_b = this.props.animationConfig) === null || _b === void 0 ? void 0 : _b.targetIndex)) {
|
|
48
|
+
this.setState({
|
|
49
|
+
targetIndex: ((_c = nextProps.animationConfig) === null || _c === void 0 ? void 0 : _c.targetIndex) || 0
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
Lottery.prototype.setLotteryStyles = function () {
|
|
54
|
+
var _a;
|
|
55
|
+
var baseStyles = {
|
|
56
|
+
width: this.props.LotteryStyles.width,
|
|
57
|
+
height: this.props.LotteryStyles.height,
|
|
58
|
+
background: ((_a = this.props.LotteryStyles) === null || _a === void 0 ? void 0 : _a.background) || "",
|
|
59
|
+
};
|
|
60
|
+
var typeStyles = {};
|
|
61
|
+
switch (this.props.LotteryStyles.type) {
|
|
62
|
+
case "rectangle":
|
|
63
|
+
default:
|
|
64
|
+
typeStyles = {
|
|
65
|
+
flexShrink: 0,
|
|
66
|
+
flexWrap: "wrap",
|
|
67
|
+
justifyContent: this.props.LotteryStyles.align || "flex-start"
|
|
68
|
+
};
|
|
69
|
+
break;
|
|
70
|
+
case "round":
|
|
71
|
+
typeStyles = {
|
|
72
|
+
borderRadius: '50%',
|
|
73
|
+
position: 'relative',
|
|
74
|
+
};
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
return __assign(__assign({}, baseStyles), typeStyles);
|
|
78
|
+
};
|
|
79
|
+
Lottery.prototype.setRewardStyles = function (index, total) {
|
|
80
|
+
var _a;
|
|
81
|
+
var baseStyles = {
|
|
82
|
+
width: this.props.RewardStyles.width,
|
|
83
|
+
height: this.props.RewardStyles.height,
|
|
84
|
+
marginRight: "12px",
|
|
85
|
+
marginBottom: "12px"
|
|
86
|
+
};
|
|
87
|
+
var typeStyles = {};
|
|
88
|
+
if (this.props.LotteryStyles.type == "round") {
|
|
89
|
+
var angle = (index * 360) / total - 90; // -90度让第一个在顶部
|
|
90
|
+
var radius = this.props.LotteryStyles.width * 0.5 - this.props.RewardStyles.width * 0.5;
|
|
91
|
+
var x = Math.cos((angle * Math.PI) / 180) * radius;
|
|
92
|
+
var y = Math.sin((angle * Math.PI) / 180) * radius;
|
|
93
|
+
typeStyles = {
|
|
94
|
+
position: 'absolute',
|
|
95
|
+
left: x + radius,
|
|
96
|
+
top: y + radius,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
var aniStyles = {};
|
|
100
|
+
if (this.state.activeIndex === index) {
|
|
101
|
+
aniStyles = ((_a = this.props.animationConfig) === null || _a === void 0 ? void 0 : _a.aniStyle) || {};
|
|
102
|
+
}
|
|
103
|
+
return __assign(__assign(__assign({}, baseStyles), typeStyles), aniStyles);
|
|
104
|
+
};
|
|
105
|
+
Lottery.prototype.setAnimation = function () {
|
|
106
|
+
var _this = this;
|
|
107
|
+
this.setState(function (prev) { return ({
|
|
108
|
+
activeIndex: (prev.activeIndex + 1) % _this.props.RewardList.length,
|
|
109
|
+
}); }, function () {
|
|
110
|
+
var _a;
|
|
111
|
+
_this.count++;
|
|
112
|
+
var currentIndex = _this.state.activeIndex;
|
|
113
|
+
// 控制停止条件:滚动次数超过一定阈值并达到目标位置
|
|
114
|
+
if (_this.count > _this.baseRollCount && currentIndex === _this.state.targetIndex) {
|
|
115
|
+
_this.timer && clearTimeout(_this.timer);
|
|
116
|
+
_this.setState({ isRolling: false });
|
|
117
|
+
_this.count = 0;
|
|
118
|
+
_this.speed = ((_a = _this.props.animationConfig) === null || _a === void 0 ? void 0 : _a.speed) || 100;
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
// 加速 → 匀速 → 减速
|
|
122
|
+
if (_this.count < _this.baseRollCount * 0.3) {
|
|
123
|
+
_this.speed -= _this.speedDegree; // 加速
|
|
124
|
+
}
|
|
125
|
+
else if (_this.count > _this.baseRollCount * 0.65) {
|
|
126
|
+
_this.speed += _this.speedDegree; // 减速
|
|
127
|
+
}
|
|
128
|
+
_this.timer = setTimeout(_this.setAnimation, _this.speed);
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
Lottery.prototype.render = function () {
|
|
133
|
+
var _this = this;
|
|
134
|
+
var _a = this.props, RewardList = _a.RewardList, children = _a.children;
|
|
135
|
+
return (h("div", { style: this.setLotteryStyles() }, RewardList.map(function (reward, index) { return (h("div", { style: _this.setRewardStyles(index, RewardList.length) }, Array.isArray(children) ? children[index] || null : null)); })));
|
|
136
|
+
};
|
|
137
|
+
return Lottery;
|
|
138
|
+
}(Component));
|
|
139
|
+
export default Lottery;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { h } from 'preact';
|
|
2
|
+
interface ScrollingTextProps {
|
|
3
|
+
text: string;
|
|
4
|
+
containerClassName?: string;
|
|
5
|
+
textClassName?: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* 一个当文本内容超出容器宽度时,会自动来回滚动的文本组件。
|
|
9
|
+
*/
|
|
10
|
+
export declare function ScrollingText({ text, containerClassName, textClassName }: ScrollingTextProps): h.JSX.Element;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// 文件路径: src/app/components/common/ScrollingText.tsx
|
|
2
|
+
import { h } from 'preact';
|
|
3
|
+
import { useState, useLayoutEffect, useRef, useEffect } from 'preact/hooks';
|
|
4
|
+
/**
|
|
5
|
+
* 一个当文本内容超出容器宽度时,会自动来回滚动的文本组件。
|
|
6
|
+
*/
|
|
7
|
+
export function ScrollingText(_a) {
|
|
8
|
+
var text = _a.text, _b = _a.containerClassName, containerClassName = _b === void 0 ? '' : _b, _c = _a.textClassName, textClassName = _c === void 0 ? '' : _c;
|
|
9
|
+
// 1. Refs 和 State 定义
|
|
10
|
+
var containerRef = useRef(null);
|
|
11
|
+
var textRef = useRef(null);
|
|
12
|
+
var _d = useState(false), isOverflowing = _d[0], setIsOverflowing = _d[1];
|
|
13
|
+
var _e = useState(0), scrollDistance = _e[0], setScrollDistance = _e[1];
|
|
14
|
+
var PAUSE_DURATION_MS = 1000; // 每次停留的时间 (1秒)
|
|
15
|
+
var INTERVAL_MS = 16; // 动画更新间隔 (约60fps)
|
|
16
|
+
var PAUSE_FRAMES = Math.round(PAUSE_DURATION_MS / INTERVAL_MS); // 计算出需要暂停的帧数
|
|
17
|
+
var animationRef = useRef({
|
|
18
|
+
intervalId: null,
|
|
19
|
+
position: 0,
|
|
20
|
+
direction: 1, // 1 表示向左移动, -1 表示向右移动
|
|
21
|
+
speed: 1, // 滚动速度
|
|
22
|
+
pauseCounter: PAUSE_FRAMES
|
|
23
|
+
});
|
|
24
|
+
useLayoutEffect(function () {
|
|
25
|
+
var container = containerRef.current;
|
|
26
|
+
var textElement = textRef.current;
|
|
27
|
+
if (!container || !textElement)
|
|
28
|
+
return;
|
|
29
|
+
setTimeout(function () {
|
|
30
|
+
var textWidth = textElement.clientWidth;
|
|
31
|
+
var containerWidth = container.clientWidth;
|
|
32
|
+
var overflowing = textWidth > containerWidth;
|
|
33
|
+
console.log(textWidth, containerWidth);
|
|
34
|
+
setIsOverflowing(overflowing);
|
|
35
|
+
if (overflowing) {
|
|
36
|
+
setScrollDistance(textWidth - containerWidth);
|
|
37
|
+
}
|
|
38
|
+
}, 10);
|
|
39
|
+
}, [text]);
|
|
40
|
+
useEffect(function () {
|
|
41
|
+
var textElement = textRef.current;
|
|
42
|
+
var container = containerRef.current;
|
|
43
|
+
var anim = animationRef.current;
|
|
44
|
+
if (anim.intervalId) {
|
|
45
|
+
clearInterval(anim.intervalId);
|
|
46
|
+
}
|
|
47
|
+
if (isOverflowing && textElement) {
|
|
48
|
+
anim.intervalId = setInterval(function () {
|
|
49
|
+
// 如果在暂停中,则直接返回,不执行后续移动
|
|
50
|
+
if (anim.pauseCounter > 0) {
|
|
51
|
+
anim.pauseCounter--;
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
anim.position += anim.speed * anim.direction;
|
|
55
|
+
if (anim.position < -scrollDistance) {
|
|
56
|
+
anim.position = -scrollDistance;
|
|
57
|
+
anim.direction = 1;
|
|
58
|
+
anim.pauseCounter = PAUSE_FRAMES;
|
|
59
|
+
}
|
|
60
|
+
else if (anim.position > 0) {
|
|
61
|
+
anim.position = 0;
|
|
62
|
+
anim.direction = -1;
|
|
63
|
+
anim.pauseCounter = PAUSE_FRAMES;
|
|
64
|
+
}
|
|
65
|
+
textElement.style.transform = "translateX(".concat(anim.position, "px)");
|
|
66
|
+
}, INTERVAL_MS);
|
|
67
|
+
}
|
|
68
|
+
return function () {
|
|
69
|
+
if (anim.intervalId) {
|
|
70
|
+
clearInterval(anim.intervalId);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}, [isOverflowing, scrollDistance]);
|
|
74
|
+
return (h("div", { ref: containerRef, style: { width: '100%', height: '100%', overflow: 'scroll', scrollbarColor: '#00000000', justifyContent: !isOverflowing ? 'center' : '', alignItems: !isOverflowing ? 'center' : '' }, className: containerClassName },
|
|
75
|
+
h("div", { ref: textRef, style: { flexShrink: 0 }, className: textClassName }, text)));
|
|
76
|
+
}
|
|
@@ -214,6 +214,7 @@ export var VideoPlayer = function (props) {
|
|
|
214
214
|
var onpause = function () {
|
|
215
215
|
videoLog('-----------onpause');
|
|
216
216
|
setVideoStatus(VideoStatus.Pause);
|
|
217
|
+
(playEvent === null || playEvent === void 0 ? void 0 : playEvent.onPause) && playEvent.onPause();
|
|
217
218
|
};
|
|
218
219
|
var onwaiting = function () {
|
|
219
220
|
videoLog('-----------onwaiting');
|
|
@@ -246,11 +247,6 @@ export var VideoPlayer = function (props) {
|
|
|
246
247
|
}
|
|
247
248
|
updateSliderHideTimmer();
|
|
248
249
|
};
|
|
249
|
-
var onPause = function () {
|
|
250
|
-
console.warn('onPause');
|
|
251
|
-
setVideoStatus(VideoStatus.Pause);
|
|
252
|
-
(playEvent === null || playEvent === void 0 ? void 0 : playEvent.onPause) && playEvent.onPause();
|
|
253
|
-
};
|
|
254
250
|
var onFirstFrame = function () {
|
|
255
251
|
console.warn('onFirstFrame');
|
|
256
252
|
(playEvent === null || playEvent === void 0 ? void 0 : playEvent.onFirstFrame) && playEvent.onFirstFrame();
|