pixuireactcomponents 1.5.46 → 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 +224 -31
- 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;
|
|
@@ -96,6 +106,15 @@ export function Carousel(props) {
|
|
|
96
106
|
}); });
|
|
97
107
|
var duration = switchDuration < 1100 ? 1100 : switchDuration;
|
|
98
108
|
var _q = useState(defaultIndex), showIndex = _q[0], setShowIndex = _q[1];
|
|
109
|
+
// 监听 showIndex 变化
|
|
110
|
+
useEffect(function () {
|
|
111
|
+
debugLog('[Carousel Debug] showIndex变化: ' +
|
|
112
|
+
JSON.stringify({
|
|
113
|
+
showIndex: showIndex,
|
|
114
|
+
defaultIndex: defaultIndex,
|
|
115
|
+
carouselItemsLength: children.length + 2, // 加上首尾补位
|
|
116
|
+
}));
|
|
117
|
+
}, [showIndex]);
|
|
99
118
|
//轮播元素正在滚动
|
|
100
119
|
var isMoving = useRef(false);
|
|
101
120
|
//鼠标手势信息
|
|
@@ -108,9 +127,67 @@ export function Carousel(props) {
|
|
|
108
127
|
var safeNextHandle = useRef();
|
|
109
128
|
var safePrevHandle = useRef();
|
|
110
129
|
var nextInterval = useRef();
|
|
111
|
-
|
|
130
|
+
// 初始化时关闭动画,避免初始化时尺寸变化导致的闪烁
|
|
131
|
+
var _r = useState(false), showTransition = _r[0], setShowTransition = _r[1];
|
|
112
132
|
var _s = useState([0, 0]), gestureoffset = _s[0], setGestureoffset = _s[1];
|
|
113
|
-
|
|
133
|
+
// 添加初始化保护标志
|
|
134
|
+
var isInitializing = useRef(true);
|
|
135
|
+
useEffect(function () {
|
|
136
|
+
debugLog('[Carousel Debug] showTransition变化: ' +
|
|
137
|
+
JSON.stringify({
|
|
138
|
+
showTransition: showTransition,
|
|
139
|
+
compWidth: compWidth,
|
|
140
|
+
compHeight: compHeight,
|
|
141
|
+
}));
|
|
142
|
+
}, [showTransition]);
|
|
143
|
+
useEffect(function () {
|
|
144
|
+
debugLog('[Carousel Debug] 尺寸变化检测: ' +
|
|
145
|
+
JSON.stringify({
|
|
146
|
+
compWidth: compWidth,
|
|
147
|
+
compHeight: compHeight,
|
|
148
|
+
currentShowIndex: showIndex,
|
|
149
|
+
defaultIndex: defaultIndex,
|
|
150
|
+
isInitializing: isInitializing.current,
|
|
151
|
+
}));
|
|
152
|
+
// 当尺寸从无效变为有效时,重置到默认索引
|
|
153
|
+
if (compWidth > 0 && compHeight > 0) {
|
|
154
|
+
// 只有在初始化期间才重置索引
|
|
155
|
+
if (isInitializing.current) {
|
|
156
|
+
debugLog('[Carousel Debug] 初始化期间,重置到默认索引: ' + defaultIndex);
|
|
157
|
+
setShowIndex(defaultIndex);
|
|
158
|
+
// 确保动画关闭,避免从错误位置过渡
|
|
159
|
+
setShowTransition(false);
|
|
160
|
+
// 标记初始化完成
|
|
161
|
+
isInitializing.current = false;
|
|
162
|
+
// 延迟设置自动播放,避免立即触发动画开启逻辑
|
|
163
|
+
setTimeout(function () {
|
|
164
|
+
debugLog('[Carousel Debug] 初始化完成,延迟设置自动播放');
|
|
165
|
+
setNextInterval();
|
|
166
|
+
}, 100);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}, [compWidth, compHeight]);
|
|
170
|
+
// 添加调试日志
|
|
171
|
+
debugLog('[Carousel Debug] 组件渲染 - props: ' +
|
|
172
|
+
JSON.stringify({
|
|
173
|
+
compWidth: compWidth,
|
|
174
|
+
compHeight: compHeight,
|
|
175
|
+
defaultIndex: defaultIndex,
|
|
176
|
+
autoplay: autoplay,
|
|
177
|
+
children: children.length,
|
|
178
|
+
}));
|
|
179
|
+
var offset = useMemo(function () {
|
|
180
|
+
var calculatedOffset = -(isVertical ? compHeight : compWidth) * showIndex;
|
|
181
|
+
debugLog('[Carousel Debug] offset计算: ' +
|
|
182
|
+
JSON.stringify({
|
|
183
|
+
isVertical: isVertical,
|
|
184
|
+
compWidth: compWidth,
|
|
185
|
+
compHeight: compHeight,
|
|
186
|
+
showIndex: showIndex,
|
|
187
|
+
calculatedOffset: calculatedOffset,
|
|
188
|
+
}));
|
|
189
|
+
return calculatedOffset;
|
|
190
|
+
}, [showIndex, compHeight, compWidth]);
|
|
114
191
|
var itemBoxStyle = {
|
|
115
192
|
minWidth: compWidth + 'px',
|
|
116
193
|
minHeight: compHeight + 'px',
|
|
@@ -124,43 +201,131 @@ export function Carousel(props) {
|
|
|
124
201
|
}, [children]);
|
|
125
202
|
var isLastCarouseItem = function () { return showIndex === carouselItems.length - 1; };
|
|
126
203
|
var isFirstCarouseLastItem = function () { return showIndex === 0; };
|
|
204
|
+
var lastOnSlideChangeIndex = useRef(-1); //上一次onSlideChange的index,避免重复触发
|
|
127
205
|
useEffect(function () {
|
|
128
|
-
|
|
206
|
+
// 只有在初始化完成后才设置自动播放
|
|
207
|
+
if (!isInitializing.current) {
|
|
208
|
+
debugLog('[Carousel Debug] autoplay变化,设置自动播放');
|
|
209
|
+
setNextInterval();
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
debugLog('[Carousel Debug] 初始化期间,跳过autoplay变化处理');
|
|
213
|
+
}
|
|
129
214
|
}, [autoplay]);
|
|
130
215
|
//组件展示内容长度改变的时候改回到第一个元素,刷新autoplay判断
|
|
131
216
|
useEffect(function () {
|
|
132
|
-
|
|
133
|
-
|
|
217
|
+
debugLog('[Carousel Debug] children变化: ' +
|
|
218
|
+
JSON.stringify({
|
|
219
|
+
childrenLength: children.length,
|
|
220
|
+
defaultIndex: defaultIndex,
|
|
221
|
+
compWidth: compWidth,
|
|
222
|
+
compHeight: compHeight,
|
|
223
|
+
isInitializing: isInitializing.current,
|
|
224
|
+
}));
|
|
225
|
+
// 只有在初始化完成后才设置自动播放和重置索引
|
|
226
|
+
if (!isInitializing.current) {
|
|
227
|
+
setNextInterval();
|
|
228
|
+
// 只有在尺寸有效时才重置索引,避免在初始化时干扰尺寸变化监听
|
|
229
|
+
if (compWidth > 0 && compHeight > 0) {
|
|
230
|
+
debugLog('[Carousel Debug] children变化时重置索引: ' + defaultIndex);
|
|
231
|
+
setShowIndex(defaultIndex);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
debugLog('[Carousel Debug] 初始化期间,跳过children变化处理');
|
|
236
|
+
}
|
|
134
237
|
}, [children]);
|
|
135
238
|
useEffect(function () {
|
|
239
|
+
debugLog('[Carousel Debug] showIndex useEffect触发: ' +
|
|
240
|
+
JSON.stringify({
|
|
241
|
+
showIndex: showIndex,
|
|
242
|
+
isLast: isLastCarouseItem(),
|
|
243
|
+
isFirst: isFirstCarouseLastItem(),
|
|
244
|
+
isInitializing: isInitializing.current,
|
|
245
|
+
}));
|
|
136
246
|
//每次跳转前判断打开动画,否则动画关闭以后不会调用handleTransitionEnd
|
|
137
|
-
|
|
247
|
+
// 但在初始化期间不开启动画
|
|
248
|
+
if (!isLastCarouseItem() && !isFirstCarouseLastItem() && !isInitializing.current) {
|
|
249
|
+
debugLog('[Carousel Debug] 因showIndex变化开启动画');
|
|
138
250
|
setShowTransition(true);
|
|
139
251
|
}
|
|
252
|
+
else if (isInitializing.current) {
|
|
253
|
+
debugLog('[Carousel Debug] 初始化期间,跳过showIndex动画开启');
|
|
254
|
+
}
|
|
140
255
|
}, [showIndex]);
|
|
141
256
|
//更新handleNext的环境
|
|
142
257
|
useEffect(function () {
|
|
143
258
|
handleNextRef.current = handleNext;
|
|
144
259
|
});
|
|
145
260
|
var setNextInterval = function () {
|
|
261
|
+
debugLog('[Carousel Debug] setNextInterval调用: ' +
|
|
262
|
+
JSON.stringify({
|
|
263
|
+
childrenLength: children.length,
|
|
264
|
+
autoplay: autoplay,
|
|
265
|
+
compWidth: compWidth,
|
|
266
|
+
compHeight: compHeight,
|
|
267
|
+
duration: duration,
|
|
268
|
+
isInitializing: isInitializing.current,
|
|
269
|
+
}));
|
|
146
270
|
nextInterval.current && clearInterval(nextInterval.current);
|
|
147
|
-
|
|
271
|
+
// 只有在初始化完成后才设置自动播放
|
|
272
|
+
if (children.length > 1 && autoplay && !isInitializing.current) {
|
|
273
|
+
debugLog('[Carousel Debug] 设置自动播放定时器');
|
|
148
274
|
nextInterval.current = setInterval(function () {
|
|
149
275
|
handleNextRef.current();
|
|
150
276
|
}, duration);
|
|
151
277
|
}
|
|
278
|
+
else {
|
|
279
|
+
debugLog('[Carousel Debug] 跳过自动播放设置:', {
|
|
280
|
+
childrenLength: children.length,
|
|
281
|
+
autoplay: autoplay,
|
|
282
|
+
isInitializing: isInitializing.current,
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
// 当组件开始正常工作时(有子元素且尺寸有效),开启动画
|
|
286
|
+
// 但避免在尺寸刚变为有效时立即开启,给尺寸重置逻辑一些时间
|
|
287
|
+
var shouldEnableTransition = children.length > 0 && compWidth > 0 && compHeight > 0;
|
|
288
|
+
debugLog('[Carousel Debug] 动画状态检查: ' +
|
|
289
|
+
JSON.stringify({
|
|
290
|
+
shouldEnableTransition: shouldEnableTransition,
|
|
291
|
+
currentShowTransition: showTransition,
|
|
292
|
+
isInitializing: isInitializing.current,
|
|
293
|
+
}));
|
|
294
|
+
// 只有在初始化完成后且当前没有动画时才开启动画
|
|
295
|
+
if (shouldEnableTransition && showTransition === false && !isInitializing.current) {
|
|
296
|
+
// 延迟开启动画,确保尺寸重置完成
|
|
297
|
+
setTimeout(function () {
|
|
298
|
+
// 再次检查初始化状态,确保在延迟期间没有重新初始化
|
|
299
|
+
if (!isInitializing.current) {
|
|
300
|
+
debugLog('[Carousel Debug] 延迟开启动画过渡');
|
|
301
|
+
setShowTransition(true);
|
|
302
|
+
}
|
|
303
|
+
else {
|
|
304
|
+
debugLog('[Carousel Debug] 延迟期间仍在初始化,跳过动画开启');
|
|
305
|
+
}
|
|
306
|
+
}, 50);
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
debugLog('[Carousel Debug] 跳过动画开启:', {
|
|
310
|
+
shouldEnableTransition: shouldEnableTransition,
|
|
311
|
+
showTransition: showTransition,
|
|
312
|
+
isInitializing: isInitializing.current,
|
|
313
|
+
});
|
|
314
|
+
}
|
|
152
315
|
};
|
|
153
316
|
useEffect(function () {
|
|
154
|
-
|
|
155
|
-
|
|
317
|
+
debugLog('[Carousel Debug] 组件初始化开始');
|
|
318
|
+
debugLog('Carousel init');
|
|
319
|
+
// 初始化期间不设置自动播放
|
|
320
|
+
// setNextInterval();
|
|
156
321
|
window.addEventListener('close', function () {
|
|
157
|
-
|
|
322
|
+
debugLog('Carousel close');
|
|
158
323
|
nextInterval.current && clearInterval(nextInterval.current);
|
|
159
324
|
safeNextHandle.current && clearTimeout(safeNextHandle.current);
|
|
160
325
|
safePrevHandle.current && clearTimeout(safePrevHandle.current);
|
|
161
326
|
});
|
|
162
327
|
return function () {
|
|
163
|
-
|
|
328
|
+
debugLog('Carousel useEffect close');
|
|
164
329
|
nextInterval.current && clearInterval(nextInterval.current);
|
|
165
330
|
safeNextHandle.current && clearTimeout(safeNextHandle.current);
|
|
166
331
|
safePrevHandle.current && clearTimeout(safePrevHandle.current);
|
|
@@ -188,21 +353,39 @@ export function Carousel(props) {
|
|
|
188
353
|
setShowIndex(showIndex + 1);
|
|
189
354
|
};
|
|
190
355
|
var handleTransitionEnd = function () {
|
|
356
|
+
debugLog('[Carousel Debug] 动画结束: ' +
|
|
357
|
+
JSON.stringify({
|
|
358
|
+
showIndex: showIndex,
|
|
359
|
+
isLast: isLastCarouseItem(),
|
|
360
|
+
isFirst: isFirstCarouseLastItem(),
|
|
361
|
+
isInitializing: isInitializing.current,
|
|
362
|
+
}));
|
|
191
363
|
//判断前后补位元素准备跳转
|
|
192
364
|
//在动画结束以后关掉,否则用鼠标拖动的时候不能补充剩下的offset
|
|
193
365
|
if (isLastCarouseItem() || isFirstCarouseLastItem()) {
|
|
366
|
+
debugLog('[Carousel Debug] 因首尾特殊情况关闭动画');
|
|
194
367
|
setShowTransition(false);
|
|
195
368
|
}
|
|
196
369
|
isMoving.current = false;
|
|
197
370
|
//触发onSlideChange
|
|
198
|
-
if (!isLastCarouseItem() && !isFirstCarouseLastItem() && onSlideChange &&
|
|
371
|
+
if (!isLastCarouseItem() && !isFirstCarouseLastItem() && onSlideChange && lastOnSlideChangeIndex.current !== showIndex) {
|
|
372
|
+
debugLog('[Carousel Debug] 触发onSlideChange: ' + (showIndex - 1));
|
|
199
373
|
onSlideChange(showIndex - 1);
|
|
200
|
-
|
|
201
|
-
if (isLastCarouseItem()) {
|
|
202
|
-
setShowIndex(1);
|
|
374
|
+
lastOnSlideChangeIndex.current = showIndex;
|
|
203
375
|
}
|
|
204
|
-
|
|
205
|
-
|
|
376
|
+
// 处理首尾特殊case,但在初始化期间跳过
|
|
377
|
+
if (!isInitializing.current) {
|
|
378
|
+
if (isLastCarouseItem()) {
|
|
379
|
+
debugLog('[Carousel Debug] 处理末尾case,跳转到索引1');
|
|
380
|
+
setShowIndex(1);
|
|
381
|
+
}
|
|
382
|
+
if (isFirstCarouseLastItem()) {
|
|
383
|
+
debugLog('[Carousel Debug] 处理开头case,跳转到索引' + (carouselItems.length - 2));
|
|
384
|
+
setShowIndex(carouselItems.length - 2);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
else {
|
|
388
|
+
debugLog('[Carousel Debug] 初始化期间,跳过首尾特殊情况处理');
|
|
206
389
|
}
|
|
207
390
|
};
|
|
208
391
|
var gestureUp = function () {
|
|
@@ -251,13 +434,13 @@ export function Carousel(props) {
|
|
|
251
434
|
if (showIndex == 1) {
|
|
252
435
|
if (!isVertical) {
|
|
253
436
|
if (x - mouseDownX.current > 0) {
|
|
254
|
-
//
|
|
437
|
+
// debugLog('stop x', x);
|
|
255
438
|
return;
|
|
256
439
|
}
|
|
257
440
|
}
|
|
258
441
|
else {
|
|
259
442
|
if (y - mouseDownY.current < 0) {
|
|
260
|
-
//
|
|
443
|
+
// debugLog('stop y', y);
|
|
261
444
|
return;
|
|
262
445
|
}
|
|
263
446
|
}
|
|
@@ -265,13 +448,13 @@ export function Carousel(props) {
|
|
|
265
448
|
else if (showIndex == carouselItems.length - 2) {
|
|
266
449
|
if (!isVertical) {
|
|
267
450
|
if (x - mouseDownX.current < 0) {
|
|
268
|
-
//
|
|
451
|
+
// debugLog('stop x', x);
|
|
269
452
|
return;
|
|
270
453
|
}
|
|
271
454
|
}
|
|
272
455
|
else {
|
|
273
456
|
if (y - mouseDownY.current < 0) {
|
|
274
|
-
//
|
|
457
|
+
// debugLog('stop y', y);
|
|
275
458
|
return;
|
|
276
459
|
}
|
|
277
460
|
}
|
|
@@ -304,6 +487,18 @@ export function Carousel(props) {
|
|
|
304
487
|
onClick(showIndex - 1);
|
|
305
488
|
}
|
|
306
489
|
};
|
|
490
|
+
// 渲染时关键样式信息
|
|
491
|
+
var transformValue = isVertical ? "translate(0px, ".concat(offset + gestureoffset[1], "px)") : "translate(".concat(offset + gestureoffset[0], "px, 0px)");
|
|
492
|
+
var transitionValue = "transform ".concat(showTransition ? '0.4s' : '0s', " ease 0s");
|
|
493
|
+
debugLog('[Carousel Debug] 渲染样式: ' +
|
|
494
|
+
JSON.stringify({
|
|
495
|
+
transformValue: transformValue,
|
|
496
|
+
transitionValue: transitionValue,
|
|
497
|
+
showTransition: showTransition,
|
|
498
|
+
offset: offset,
|
|
499
|
+
gestureoffset: gestureoffset,
|
|
500
|
+
carouselItemsLength: carouselItems.length,
|
|
501
|
+
}));
|
|
307
502
|
return (h("div", { style: { flexDirection: 'column', width: compWidth, height: compHeight }, id: rootId, className: rootClassName },
|
|
308
503
|
h("div", { draggable: true, style: __assign(__assign({}, itemBoxStyle), { position: 'absolute' }), onClick: function (ev) {
|
|
309
504
|
gestureClick(props);
|
|
@@ -325,10 +520,8 @@ export function Carousel(props) {
|
|
|
325
520
|
display: 'flex',
|
|
326
521
|
width: isVertical ? compWidth : compWidth * carouselItems.length + 'px',
|
|
327
522
|
height: isVertical ? compHeight * carouselItems.length : compHeight + 'px',
|
|
328
|
-
transition:
|
|
329
|
-
transform:
|
|
330
|
-
? "translate(0px, ".concat(offset + gestureoffset[1], "px)")
|
|
331
|
-
: "translate(".concat(offset + gestureoffset[0], "px, 0px)"),
|
|
523
|
+
transition: transitionValue,
|
|
524
|
+
transform: transformValue,
|
|
332
525
|
flexDirection: isVertical ? 'column' : 'row',
|
|
333
526
|
flexShrink: 0,
|
|
334
527
|
}, class: "wrapper", onTransitionEnd: handleTransitionEnd }, carouselItems.map(function (child) { return child; }))))));
|
|
@@ -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();
|