pixuireactcomponents 1.5.48 → 1.5.49

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pixuireactcomponents",
3
- "version": "1.5.48",
3
+ "version": "1.5.49",
4
4
  "description": "pixui react components",
5
5
  "main": "index.js",
6
6
  "sideEffects": false,
@@ -18,7 +18,7 @@ export interface SliderProps {
18
18
  vertical?: boolean;
19
19
  range?: boolean | range;
20
20
  onChangeStart?: (value: any) => void;
21
- onChange?: (value: any) => void;
21
+ onChange?: (value: any, isClick?: any) => void;
22
22
  onChangeComplete?: (value: any) => void;
23
23
  element?: sliderElement;
24
24
  }
@@ -133,6 +133,9 @@ export var Slider = function (props) {
133
133
  if (status == 'move') {
134
134
  onChange && onChange(newValue);
135
135
  }
136
+ if (status == 'click') {
137
+ onChange && onChange(newValue, true);
138
+ }
136
139
  }
137
140
  // start和end一定要发
138
141
  if (status == 'start') {
@@ -155,6 +158,12 @@ export var Slider = function (props) {
155
158
  }
156
159
  return newValue;
157
160
  };
161
+ var onRailClick = function (event) {
162
+ event.stopPropagation();
163
+ if (!draging.current) { // 避免与drag冲突
164
+ setValueByPos(event.clientX, event.clientY, 'click');
165
+ }
166
+ };
158
167
  var onDragStart = function (event) {
159
168
  event.stopPropagation();
160
169
  draging.current = true;
@@ -179,7 +188,7 @@ export var Slider = function (props) {
179
188
  var elementStyleOrClass = getElementStyleOrClass();
180
189
  var handleStyle = __assign(__assign({}, (typeof elementStyleOrClass.handle === 'object' ? elementStyleOrClass.handle : undefined)), (vertical ? { top: -handleSize / 2 } : { left: '100%', marginLeft: -handleSize / 2 }));
181
190
  return (h("div", { id: id, className: rootClassName, style: __assign({}, rowCenterCenter) },
182
- h("div", { ref: refRail, className: typeof elementStyleOrClass.rail === 'string' ? elementStyleOrClass.rail : '', style: __assign({}, (typeof elementStyleOrClass.rail === 'object' ? elementStyleOrClass.rail : undefined)), draggable: true, onDragStart: onDragStart, onDrag: onDrag, onDragEnd: onDragEnd }, refRail.current &&
191
+ h("div", { ref: refRail, className: typeof elementStyleOrClass.rail === 'string' ? elementStyleOrClass.rail : '', style: __assign({}, (typeof elementStyleOrClass.rail === 'object' ? elementStyleOrClass.rail : undefined)), draggable: true, onDragStart: onDragStart, onDrag: onDrag, onDragEnd: onDragEnd, onClick: onRailClick }, refRail.current &&
183
192
  h("div", { className: typeof elementStyleOrClass.track === 'string' ? elementStyleOrClass.track : '', style: trackStyle },
184
193
  h("div", { ref: handleRef, className: typeof elementStyleOrClass.handle === 'string' ? elementStyleOrClass.handle : '', style: __assign(__assign({}, handleStyle), { position: 'absolute' }) })))));
185
194
  };
@@ -26,5 +26,6 @@ export interface VideoPlayerProps {
26
26
  videoDuration?: number;
27
27
  compRef?: any;
28
28
  maskComponent?: preact.ComponentChild | (() => preact.ComponentChild);
29
+ openLog?: boolean;
29
30
  }
30
31
  export declare const VideoPlayer: (props: VideoPlayerProps) => h.JSX.Element;
@@ -45,7 +45,7 @@ var defaultIconStyle = [
45
45
  position: 'relative', left: '-45%', top: '42%', width: '5%', paddingTop: '5%', backgroundImage: 'url(https://game.gtimg.cn/images/gamelet/cp/pixui-components/new_video_pause.png)', backgroundSize: '100% 100%'
46
46
  },
47
47
  {
48
- position: 'relative', left: '-45%', top: '42%', width: '5%', paddingTop: '5%', backgroundImage: 'url(https://game.gtimg.cn/images/gamelet/cp/pixui-components/video_loading.png)', backgroundSize: '100% 100%'
48
+ position: 'relative', left: '-45%', top: '42%', width: '5%', paddingTop: '5%', backgroundImage: 'url(https://game.gtimg.cn/images/gamelet/cp/pixui-components/new_video_loading.png)', backgroundSize: '100% 100%'
49
49
  },
50
50
  {
51
51
  position: 'relative', left: '-45%', top: '42%', width: '5%', paddingTop: '5%', backgroundImage: 'url(https://game.gtimg.cn/images/gamelet/cp/pixui-components/new_video_reload.png)', backgroundSize: '100% 100%'
@@ -76,29 +76,28 @@ var defaultSliderStyle = {
76
76
  height: '200%',
77
77
  },
78
78
  };
79
- var openLog = false;
80
- var videoLog = function () {
81
- var msg = [];
82
- for (var _i = 0; _i < arguments.length; _i++) {
83
- msg[_i] = arguments[_i];
84
- }
85
- if (openLog) {
86
- console.log.apply(console, __spreadArray(['VideoPlayer: '], msg, false));
87
- }
88
- };
89
79
  export var VideoPlayer = function (props) {
90
- var rootId = props.rootId, rootClassName = props.rootClassName, _a = props.playUrl, playUrl = _a === void 0 ? '' : _a, _b = props.autoPlay, autoPlay = _b === void 0 ? true : _b, playEvent = props.playEvent, iconElement = props.iconElement, _c = props.hideSliderDuration, hideSliderDuration = _c === void 0 ? 3000 : _c, sliderElement = props.sliderElement, videoDuration = props.videoDuration, compRef = props.compRef;
80
+ var rootId = props.rootId, rootClassName = props.rootClassName, _a = props.playUrl, playUrl = _a === void 0 ? '' : _a, _b = props.autoPlay, autoPlay = _b === void 0 ? true : _b, playEvent = props.playEvent, iconElement = props.iconElement, _c = props.hideSliderDuration, hideSliderDuration = _c === void 0 ? 3000 : _c, sliderElement = props.sliderElement, videoDuration = props.videoDuration, compRef = props.compRef, _d = props.openLog, openLog = _d === void 0 ? false : _d;
91
81
  var isStreaming = !playUrl.split('?')[0].endsWith('.mp4');
92
82
  var refVideo = useRef(null);
93
- var _d = useState(VideoStatus.Loading), videoStatus = _d[0], setVideoStatus = _d[1];
94
- var _e = useState(0), currentTime = _e[0], setCurrentTime = _e[1];
95
- var _f = useState(0), totalTime = _f[0], setTotalTime = _f[1];
96
- var _g = useState(false), showSlider = _g[0], setShowSlider = _g[1];
97
- var _h = useState(1.0), currentVolume = _h[0], setCurrentVolume = _h[1]; //视频音量范围0.0~1.0
98
- var _j = useState(false), isMuted = _j[0], setIsMuted = _j[1];
83
+ var _e = useState(VideoStatus.Loading), videoStatus = _e[0], setVideoStatus = _e[1];
84
+ var _f = useState(0), currentTime = _f[0], setCurrentTime = _f[1];
85
+ var _g = useState(0), totalTime = _g[0], setTotalTime = _g[1];
86
+ var _h = useState(false), showSlider = _h[0], setShowSlider = _h[1];
87
+ var _j = useState(1.0), currentVolume = _j[0], setCurrentVolume = _j[1]; //视频音量范围0.0~1.0
88
+ var _k = useState(false), isMuted = _k[0], setIsMuted = _k[1];
99
89
  var sliderTimmer = useRef(null);
100
90
  var rootRef = useRef();
101
91
  var isDragingRef = useRef(false);
92
+ var videoLog = function () {
93
+ var msg = [];
94
+ for (var _i = 0; _i < arguments.length; _i++) {
95
+ msg[_i] = arguments[_i];
96
+ }
97
+ if (openLog) {
98
+ console.log.apply(console, __spreadArray(['VideoPlayer: '], msg, false));
99
+ }
100
+ };
102
101
  // 在开发setCurrentTime功能时,发现seek视频后立刻pause, 视频会在onpause回调执行后,
103
102
  // 又执行一遍onwating, onplaying回调,导致videoStatus被错误设置成播放状态。
104
103
  // 暂时使用isPauseSeekingRef来标记是否在暂停状态下setCurrentTime触发,在onplaying中将状态设回Pause
@@ -163,14 +162,20 @@ export var VideoPlayer = function (props) {
163
162
  clearTimeout(sliderTimmer.current);
164
163
  refVideo.current.pause();
165
164
  };
166
- var onSliderDrag = function (value) {
167
- // console.warn('isDragingRef: ', isDragingRef.current)
165
+ var onSliderDrag = function (value, isClick) {
166
+ if (isClick && !isDragingRef.current) {
167
+ onSliderDragStart();
168
+ }
168
169
  if (isDragingRef.current) {
169
- console.log('value: ', value, getDuration());
170
+ videoLog('value: ', value, getDuration());
170
171
  var totalTime_1 = value * getDuration();
171
172
  var playSeconds = Math.floor(totalTime_1 / 1000 + 0.5);
172
173
  videoLog('onSliderDrag, set currentTime:', playSeconds);
173
174
  setCurrentTime(playSeconds);
175
+ // 如果是点击操作,立即完成
176
+ if (isClick) {
177
+ completeSliderAction(playSeconds);
178
+ }
174
179
  }
175
180
  };
176
181
  var setShowUI = function (show, direct) {
@@ -182,18 +187,25 @@ export var VideoPlayer = function (props) {
182
187
  };
183
188
  // 结束拖就3秒隐藏Bar
184
189
  var onSliderDragEnd = function (value) {
185
- console.log('onSliderDragEnd======');
190
+ videoLog('onSliderDragEnd======');
186
191
  if (isDragingRef.current) {
187
- isDragingRef.current = false;
188
- videoLog('onDragEnd-----------------, ', value * getDuration());
189
- if (hideSliderDuration > 0) {
190
- clearTimeout(sliderTimmer.current);
191
- sliderTimmer.current = setTimeout(function () {
192
- setShowUI(false);
193
- }, hideSliderDuration);
194
- }
195
- refVideo.current.seek(currentTime);
196
- refVideo.current.play();
192
+ var totalTime_2 = value * getDuration();
193
+ var playSeconds = Math.floor(totalTime_2 / 1000 + 0.5);
194
+ completeSliderAction(playSeconds);
195
+ }
196
+ };
197
+ var completeSliderAction = function (targetSeconds) {
198
+ videoLog('完成动作, 跳转到:', targetSeconds);
199
+ refVideo.current.seek(targetSeconds);
200
+ refVideo.current.play();
201
+ // 重置拖拽状态
202
+ isDragingRef.current = false;
203
+ // 设置UI隐藏计时器
204
+ if (hideSliderDuration > 0) {
205
+ clearTimeout(sliderTimmer.current);
206
+ sliderTimmer.current = setTimeout(function () {
207
+ setShowUI(false);
208
+ }, hideSliderDuration);
197
209
  }
198
210
  };
199
211
  var onplaying = function () {
@@ -248,7 +260,7 @@ export var VideoPlayer = function (props) {
248
260
  updateSliderHideTimmer();
249
261
  };
250
262
  var onFirstFrame = function () {
251
- console.warn('onFirstFrame');
263
+ videoLog('onFirstFrame');
252
264
  (playEvent === null || playEvent === void 0 ? void 0 : playEvent.onFirstFrame) && playEvent.onFirstFrame();
253
265
  };
254
266
  var switchPlayState = function () {
@@ -346,9 +358,9 @@ export var VideoPlayer = function (props) {
346
358
  var iconStyleOrClass = getIconStyleOrClass(videoStatus);
347
359
  return (h("div", { id: rootId, className: rootClassName, ref: rootRef },
348
360
  h("video", { ref: refVideo, src: playUrl, "object-fit": "no", autoPlay: autoPlay, style: { width: '100%', height: '100%' }, onPlaying: onplaying, onPlay: onplaying, onError: onerror, onEnded: onended, onPause: onpause, onWaiting: onwaiting, onLoadStart: function () {
349
- console.warn('onloadstart');
361
+ videoLog('onloadstart');
350
362
  }, onLoadedData: function () {
351
- console.warn('onloadeddata');
363
+ videoLog('onloadeddata');
352
364
  }, onCanPlay: onplaying,
353
365
  //@ts-ignore
354
366
  onfirstframe: onFirstFrame, controls: true }),