pixuireactcomponents 1.3.81 → 1.3.83
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.3.
|
|
3
|
+
"version": "1.3.83",
|
|
4
4
|
"description": "pixui react components",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -12,7 +12,6 @@
|
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"animate.css": "^3.7.2",
|
|
14
14
|
"babel-plugin-transform-decorators-legacy": "^1.3.5",
|
|
15
|
-
"cheerio": "1.0.0-rc.12",
|
|
16
15
|
"cpx": "^1.5.0",
|
|
17
16
|
"gamelet-pixui-frame": "0.4.9",
|
|
18
17
|
"google-protobuf": "^3.8.0",
|
|
@@ -2,24 +2,26 @@ import { h } from 'preact';
|
|
|
2
2
|
export interface VideoPlayerProps {
|
|
3
3
|
playUrl: string;
|
|
4
4
|
autoPlay?: boolean;
|
|
5
|
-
|
|
5
|
+
isStreaming?: boolean;
|
|
6
|
+
playEvent?: {
|
|
6
7
|
onPlay?: () => void;
|
|
7
8
|
onPause?: () => void;
|
|
8
9
|
onEnded?: () => void;
|
|
9
10
|
onFirstFrame?: () => void;
|
|
10
11
|
};
|
|
11
|
-
elementClass
|
|
12
|
+
elementClass?: {
|
|
12
13
|
playIcon?: string;
|
|
13
14
|
pauseIcon?: string;
|
|
14
15
|
reloadIcon?: string;
|
|
15
16
|
};
|
|
16
|
-
sliderBG
|
|
17
|
+
sliderBG?: {
|
|
17
18
|
outerBG?: string;
|
|
18
19
|
innerBG?: string;
|
|
19
20
|
dotBG?: string;
|
|
20
21
|
};
|
|
21
|
-
durations
|
|
22
|
+
durations?: {
|
|
22
23
|
hideSliderDuration?: number;
|
|
23
24
|
};
|
|
25
|
+
videoDuration?: number;
|
|
24
26
|
}
|
|
25
27
|
export declare const VideoPlayer: (props: VideoPlayerProps) => h.JSX.Element;
|
|
@@ -9,6 +9,15 @@ var __assign = (this && this.__assign) || function () {
|
|
|
9
9
|
};
|
|
10
10
|
return __assign.apply(this, arguments);
|
|
11
11
|
};
|
|
12
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
13
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
14
|
+
if (ar || !(i in from)) {
|
|
15
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
16
|
+
ar[i] = from[i];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
20
|
+
};
|
|
12
21
|
import { createRef, h } from 'preact';
|
|
13
22
|
import { useEffect, useRef, useState } from 'preact/hooks';
|
|
14
23
|
import { Slider } from '../slider/Slider';
|
|
@@ -39,59 +48,71 @@ var VideoStatus;
|
|
|
39
48
|
VideoStatus[VideoStatus["Pause"] = 2] = "Pause";
|
|
40
49
|
VideoStatus[VideoStatus["End"] = 3] = "End";
|
|
41
50
|
})(VideoStatus || (VideoStatus = {}));
|
|
51
|
+
var openLog = false;
|
|
52
|
+
var videoLog = function () {
|
|
53
|
+
var msg = [];
|
|
54
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
55
|
+
msg[_i] = arguments[_i];
|
|
56
|
+
}
|
|
57
|
+
if (openLog) {
|
|
58
|
+
console.log.apply(console, __spreadArray(['VideoPlayer: '], msg, false));
|
|
59
|
+
}
|
|
60
|
+
};
|
|
42
61
|
export var VideoPlayer = function (props) {
|
|
43
|
-
var playUrl = props.playUrl, _a = props.autoPlay, autoPlay = _a === void 0 ? true : _a, playEvent = props.playEvent, elementClass = props.elementClass, _b = props.durations, durations = _b === void 0 ? { hideSliderDuration: 3000 } : _b, sliderBG = props.sliderBG;
|
|
62
|
+
var playUrl = props.playUrl, _a = props.autoPlay, autoPlay = _a === void 0 ? true : _a, playEvent = props.playEvent, elementClass = props.elementClass, _b = props.durations, durations = _b === void 0 ? { hideSliderDuration: 3000 } : _b, sliderBG = props.sliderBG, videoDuration = props.videoDuration, _c = props.isStreaming, isStreaming = _c === void 0 ? false : _c;
|
|
44
63
|
var refVideo = createRef();
|
|
45
|
-
|
|
46
|
-
var
|
|
47
|
-
var
|
|
48
|
-
var
|
|
49
|
-
var
|
|
64
|
+
// const hideSliderDuration = 1000;
|
|
65
|
+
var _d = useState(VideoStatus.Loading), videoStatus = _d[0], setVideoStatus = _d[1];
|
|
66
|
+
var _e = useState(0), currentTime = _e[0], setCurrentTime = _e[1];
|
|
67
|
+
var _f = useState(0), totalTime = _f[0], setTotalTime = _f[1];
|
|
68
|
+
var _g = useState(false), showSlider = _g[0], setShowSlider = _g[1];
|
|
50
69
|
var sliderTimmer = useRef(null);
|
|
51
|
-
var updateInfoTimmer = useRef(null);
|
|
52
70
|
var updatePlayTime = function () {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (videoStatus != VideoStatus.Playing)
|
|
71
|
+
// videoLog('updatePlayTime----------------');
|
|
72
|
+
// videoLog('updatePlayTime-----------------pp3', refVideo.current.duration);
|
|
73
|
+
if (videoStatus != VideoStatus.Playing || isStreaming)
|
|
57
74
|
return;
|
|
58
75
|
var playTime = refVideo.current.currentTime;
|
|
59
76
|
var currentSeconds = Math.floor(playTime / 1000 + 0.5);
|
|
60
|
-
var duration = refVideo.current.duration;
|
|
77
|
+
var duration = videoDuration || refVideo.current.duration;
|
|
61
78
|
var totalSeconds = Math.floor(duration / 1000 + 0.5);
|
|
62
79
|
setCurrentTime(currentSeconds);
|
|
63
80
|
setTotalTime(totalSeconds);
|
|
64
|
-
|
|
81
|
+
videoLog('updatePlayTime-----------------', 'currentSeconds:', currentSeconds, 'totalSeconds:', totalSeconds, Math.floor((currentTime / totalTime) * 100 + 0.5));
|
|
65
82
|
};
|
|
83
|
+
useEffect(function () {
|
|
84
|
+
videoLog('Video Status changed: ', videoStatus);
|
|
85
|
+
}, [videoStatus]);
|
|
66
86
|
//用于更新函数环境
|
|
67
|
-
var
|
|
87
|
+
var updatePlayTimeFunRef = useRef(updatePlayTime);
|
|
68
88
|
useEffect(function () {
|
|
69
|
-
|
|
89
|
+
updatePlayTimeFunRef.current = updatePlayTime;
|
|
70
90
|
});
|
|
71
91
|
useEffect(function () {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
92
|
+
updatePlayTimeFunRef.current = updatePlayTime;
|
|
93
|
+
var interval = setInterval(function () {
|
|
94
|
+
updatePlayTimeFunRef.current();
|
|
75
95
|
}, 1000);
|
|
76
96
|
return function () {
|
|
97
|
+
clearInterval(interval);
|
|
77
98
|
clearInterval(sliderTimmer.current);
|
|
78
99
|
};
|
|
79
100
|
}, []);
|
|
80
101
|
// 开始拖就长显Bar
|
|
81
102
|
var onSliderDragStart = function () {
|
|
82
|
-
|
|
103
|
+
videoLog('onDragStart-----------------');
|
|
83
104
|
clearTimeout(sliderTimmer.current);
|
|
84
105
|
refVideo.current.pause();
|
|
85
106
|
};
|
|
86
107
|
var onSliderDrag = function (value) {
|
|
87
108
|
console.warn('value: ========================', value);
|
|
88
|
-
var totlaTime = (value / 100) * refVideo.current.duration;
|
|
109
|
+
var totlaTime = (value / 100) * (videoDuration || refVideo.current.duration);
|
|
89
110
|
var playSeconds = Math.floor(totlaTime / 1000 + 0.5);
|
|
90
111
|
setCurrentTime(playSeconds);
|
|
91
112
|
};
|
|
92
113
|
// 结束拖就3秒隐藏Bar
|
|
93
114
|
var onSliderDragEnd = function () {
|
|
94
|
-
|
|
115
|
+
videoLog('onDragEnd-----------------');
|
|
95
116
|
clearTimeout(sliderTimmer.current);
|
|
96
117
|
sliderTimmer.current = setTimeout(function () {
|
|
97
118
|
setShowSlider(false);
|
|
@@ -100,31 +121,26 @@ export var VideoPlayer = function (props) {
|
|
|
100
121
|
};
|
|
101
122
|
var onplaying = function () {
|
|
102
123
|
// 加载第一帧画面
|
|
103
|
-
|
|
124
|
+
videoLog('-----------onplaying');
|
|
104
125
|
setVideoStatus(VideoStatus.Playing);
|
|
105
|
-
playEvent.onPlay && playEvent.onPlay();
|
|
106
|
-
clearInterval(updateInfoTimmer.current);
|
|
107
|
-
updateInfoTimmer.current = setInterval(function () {
|
|
108
|
-
updatePlayTimeRef.current();
|
|
109
|
-
}, 1000);
|
|
126
|
+
(playEvent === null || playEvent === void 0 ? void 0 : playEvent.onPlay) && playEvent.onPlay();
|
|
110
127
|
};
|
|
111
128
|
var onerror = function (error) {
|
|
112
129
|
console.error('----------onerror', JSON.stringify(error));
|
|
113
130
|
// 播放错误,比如给一个无法播放的url
|
|
114
131
|
};
|
|
115
132
|
var onpause = function () {
|
|
116
|
-
|
|
133
|
+
videoLog('-----------onpause');
|
|
117
134
|
setVideoStatus(VideoStatus.Pause);
|
|
118
135
|
};
|
|
119
136
|
var onended = function () {
|
|
120
137
|
// 视频播放结束
|
|
121
|
-
|
|
138
|
+
videoLog('-----------onended');
|
|
122
139
|
setVideoStatus(VideoStatus.End);
|
|
123
|
-
clearInterval(updateInfoTimmer.current);
|
|
124
140
|
setCurrentTime(0);
|
|
125
141
|
clearTimeout(sliderTimmer.current);
|
|
126
142
|
setShowSlider(true);
|
|
127
|
-
playEvent.onEnded && playEvent.onEnded();
|
|
143
|
+
(playEvent === null || playEvent === void 0 ? void 0 : playEvent.onEnded) && playEvent.onEnded();
|
|
128
144
|
};
|
|
129
145
|
var updateSliderHideTimmer = function () {
|
|
130
146
|
clearTimeout(sliderTimmer.current);
|
|
@@ -148,14 +164,14 @@ export var VideoPlayer = function (props) {
|
|
|
148
164
|
var onPause = function () {
|
|
149
165
|
console.warn('onPause');
|
|
150
166
|
setVideoStatus(VideoStatus.Pause);
|
|
151
|
-
playEvent.onPause && playEvent.onPause();
|
|
167
|
+
(playEvent === null || playEvent === void 0 ? void 0 : playEvent.onPause) && playEvent.onPause();
|
|
152
168
|
};
|
|
153
169
|
var onFirstFrame = function () {
|
|
154
170
|
console.warn('onFirstFrame');
|
|
155
|
-
playEvent.onFirstFrame && playEvent.onFirstFrame();
|
|
171
|
+
(playEvent === null || playEvent === void 0 ? void 0 : playEvent.onFirstFrame) && playEvent.onFirstFrame();
|
|
156
172
|
};
|
|
157
173
|
var switchPlayState = function () {
|
|
158
|
-
|
|
174
|
+
videoLog('switchPlayState ', videoStatus);
|
|
159
175
|
if (videoStatus == VideoStatus.Playing) {
|
|
160
176
|
refVideo.current.pause();
|
|
161
177
|
}
|
|
@@ -168,7 +184,7 @@ export var VideoPlayer = function (props) {
|
|
|
168
184
|
refVideo.current.load();
|
|
169
185
|
}
|
|
170
186
|
};
|
|
171
|
-
|
|
187
|
+
videoLog('currentTime', currentTime, 'totalTime', totalTime);
|
|
172
188
|
return (h("div", { style: {
|
|
173
189
|
width: '100%',
|
|
174
190
|
height: '100%',
|
|
@@ -183,18 +199,18 @@ export var VideoPlayer = function (props) {
|
|
|
183
199
|
//@ts-ignore
|
|
184
200
|
onfirstframe: onFirstFrame }),
|
|
185
201
|
h("div", { style: screenClickerStyle, onClick: function (e) {
|
|
186
|
-
|
|
202
|
+
videoLog('screenClickerStyle click');
|
|
187
203
|
e.stopPropagation();
|
|
188
204
|
onScreenClick();
|
|
189
205
|
} }, showSlider ? (h("div", { className: videoStatus == VideoStatus.Playing
|
|
190
|
-
? elementClass.pauseIcon
|
|
206
|
+
? elementClass === null || elementClass === void 0 ? void 0 : elementClass.pauseIcon
|
|
191
207
|
: videoStatus == VideoStatus.Pause
|
|
192
|
-
? elementClass.playIcon
|
|
193
|
-
: elementClass.reloadIcon, onClick: function (e) {
|
|
208
|
+
? elementClass === null || elementClass === void 0 ? void 0 : elementClass.playIcon
|
|
209
|
+
: elementClass === null || elementClass === void 0 ? void 0 : elementClass.reloadIcon, onClick: function (e) {
|
|
194
210
|
e.stopPropagation();
|
|
195
211
|
onIconClick();
|
|
196
212
|
} })) : null),
|
|
197
|
-
showSlider ? (h("div", { style: {
|
|
213
|
+
showSlider && !isStreaming ? (h("div", { style: {
|
|
198
214
|
width: '100%',
|
|
199
215
|
height: '15px',
|
|
200
216
|
fontSize: '18px',
|
|
@@ -209,7 +225,7 @@ export var VideoPlayer = function (props) {
|
|
|
209
225
|
} },
|
|
210
226
|
h("text", null, FormatSecondCountDownTime(currentTime)),
|
|
211
227
|
h("div", { style: { marginRight: '30px', marginLeft: '30px' } },
|
|
212
|
-
h(Slider, __assign({}, progressData, { outerBg: sliderBG.outerBG || '', innerBg: sliderBG.innerBG || '', dotBg: sliderBG.dotBG || '', onDrag: onSliderDrag, onDragEnd: onSliderDragEnd, onDragStart: onSliderDragStart, discrete: totalTime > 0 ? Math.floor((currentTime / totalTime) * 100 + 0.5) : 0 }))),
|
|
228
|
+
h(Slider, __assign({}, progressData, { outerBg: (sliderBG === null || sliderBG === void 0 ? void 0 : sliderBG.outerBG) || '', innerBg: (sliderBG === null || sliderBG === void 0 ? void 0 : sliderBG.innerBG) || '', dotBg: (sliderBG === null || sliderBG === void 0 ? void 0 : sliderBG.dotBG) || '', onDrag: onSliderDrag, onDragEnd: onSliderDragEnd, onDragStart: onSliderDragStart, discrete: totalTime > 0 ? Math.floor((currentTime / totalTime) * 100 + 0.5) : 0 }))),
|
|
213
229
|
h("text", null, FormatSecondCountDownTime(totalTime)))) : null));
|
|
214
230
|
};
|
|
215
231
|
var progressData = {
|
|
@@ -5,17 +5,4 @@ export declare namespace tools {
|
|
|
5
5
|
* 哈希生成一个长度20的字符串
|
|
6
6
|
*/
|
|
7
7
|
const getHashStr: (str: string) => string;
|
|
8
|
-
/**
|
|
9
|
-
* 旧的富文本组件,请使用ConvertRichTextToPixuiStyle
|
|
10
|
-
* @param str
|
|
11
|
-
* @returns
|
|
12
|
-
*/
|
|
13
|
-
const convertRichText: (str: string) => string;
|
|
14
|
-
/**
|
|
15
|
-
* 富文本组件,将富文本转换成pixui的innerHtml可以使用的格式
|
|
16
|
-
* @param str 管理端下发的富文本
|
|
17
|
-
* @param aLabelData 返回的富文本中的a标签的跳转数据,[id:string]:jumpdata
|
|
18
|
-
* @returns pixui的innerHtml可以使用的格式
|
|
19
|
-
*/
|
|
20
|
-
const convertRichTextToPixuiStyle: (str: string, aLabelData?: object[]) => string;
|
|
21
8
|
}
|
|
@@ -36,7 +36,6 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
};
|
|
37
37
|
import { GameletAPI } from 'gamelet-pixui-frame';
|
|
38
38
|
import { sha1 } from './Sha1';
|
|
39
|
-
import * as cheerio from 'cheerio';
|
|
40
39
|
export var tools;
|
|
41
40
|
(function (tools) {
|
|
42
41
|
tools.writeCookie = function (key, value) {
|
|
@@ -77,194 +76,4 @@ export var tools;
|
|
|
77
76
|
tools.getHashStr = function (str) {
|
|
78
77
|
return sha1(str).substring(0, 20);
|
|
79
78
|
};
|
|
80
|
-
/**
|
|
81
|
-
* 旧的富文本组件,请使用ConvertRichTextToPixuiStyle
|
|
82
|
-
* @param str
|
|
83
|
-
* @returns
|
|
84
|
-
*/
|
|
85
|
-
tools.convertRichText = function (str) {
|
|
86
|
-
var res = str
|
|
87
|
-
.replaceAll(/<img([^>]*)>/g, '<img$1></img>') //传过来的这两个标签会少结束标签
|
|
88
|
-
.replaceAll(/<h[1,2,3,4,5,6]><br><\/h[1,2,3,4,5,6]>/g, '<br /><div style = "width:50px;height:15px;" ></div>')
|
|
89
|
-
.replaceAll(/<p><br><\/p>/g, '<br /><div style = "width:50px;height:15px;" ></div>')
|
|
90
|
-
.replaceAll(/<p/g, '<text')
|
|
91
|
-
.replaceAll(/<\/p>/g, '</text>') //包text否则会丢break word
|
|
92
|
-
.replaceAll(/<span/g, '<text')
|
|
93
|
-
.replaceAll(/<\/span>/g, '</text>') //包text否则会丢break word
|
|
94
|
-
.replaceAll(/ /g, ' '); //单一行只有nbsp的时候,会整个解析不出来,pixui innerHtml bug
|
|
95
|
-
for (var i = 1; i <= 6; i++) {
|
|
96
|
-
res = res.replaceAll(/(<h${i}\s[^>]*>)([^<]*)(<\/h${i}>)/g, '$1<text>$2</text>$3'); //h1-h6的内容包 text
|
|
97
|
-
}
|
|
98
|
-
res = res.replaceAll(/<br>/g, '<br /><div style = "width:50px;height:15px;" ></div>');
|
|
99
|
-
for (var i = 1; i < 10; i++) {
|
|
100
|
-
res = res.replaceAll("class=\"ql-indent-".concat(i, "\""), " style=\"padding-left: ".concat(i * 2, "rem;\""));
|
|
101
|
-
}
|
|
102
|
-
return res;
|
|
103
|
-
};
|
|
104
|
-
/**
|
|
105
|
-
* 富文本组件,将富文本转换成pixui的innerHtml可以使用的格式
|
|
106
|
-
* @param str 管理端下发的富文本
|
|
107
|
-
* @param aLabelData 返回的富文本中的a标签的跳转数据,[id:string]:jumpdata
|
|
108
|
-
* @returns pixui的innerHtml可以使用的格式
|
|
109
|
-
*/
|
|
110
|
-
tools.convertRichTextToPixuiStyle = function (str, aLabelData) {
|
|
111
|
-
var $ = cheerio.load(str, null, false);
|
|
112
|
-
var _loop_1 = function (i) {
|
|
113
|
-
var indent = "ql-indent-".concat(i);
|
|
114
|
-
var extStyle = "padding-left: ".concat(i * 2, "rem;");
|
|
115
|
-
$(".".concat(indent)).each(function () {
|
|
116
|
-
var oriStyle = $(this).attr('style') || '';
|
|
117
|
-
$(this).attr('style', "".concat(oriStyle, " ").concat(extStyle));
|
|
118
|
-
$(this).removeClass(indent);
|
|
119
|
-
});
|
|
120
|
-
};
|
|
121
|
-
//合并ql-indent class到style中
|
|
122
|
-
for (var i = 1; i <= 10; i++) {
|
|
123
|
-
_loop_1(i);
|
|
124
|
-
}
|
|
125
|
-
//每个 p 节点后添加一个 br 节点
|
|
126
|
-
$('p').each(function () {
|
|
127
|
-
$(this).after('<br>');
|
|
128
|
-
});
|
|
129
|
-
//将所有的<p><br></p>改成<br>,否则之后 br 会被套在 div 里失效
|
|
130
|
-
$('p').each(function () {
|
|
131
|
-
if (($(this).html() || '').trim() === '<br>') {
|
|
132
|
-
$(this).replaceWith('<br>');
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
//找到所有的文字节点,外层包裹text标签
|
|
136
|
-
$('*').each(function () {
|
|
137
|
-
$(this)
|
|
138
|
-
.contents()
|
|
139
|
-
.each(function () {
|
|
140
|
-
if (this.type === 'text') {
|
|
141
|
-
var text = this.data.trim();
|
|
142
|
-
if (text.length > 0) {
|
|
143
|
-
$(this).replaceWith("<text style=\"word-break: break-word;flex-shrink: 0;\">".concat(text, "</text>"));
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
//将strong em u s标签替换成text标签
|
|
149
|
-
$('strong').each(function () {
|
|
150
|
-
var html = $(this).html();
|
|
151
|
-
var style = $(this).attr('style') || '';
|
|
152
|
-
$(this).replaceWith("<text style=\"".concat(style, " font-weight: bold;flex-shrink: 0;\">").concat(html, "</text>"));
|
|
153
|
-
});
|
|
154
|
-
$('em').each(function () {
|
|
155
|
-
var html = $(this).html();
|
|
156
|
-
var style = $(this).attr('style') || '';
|
|
157
|
-
$(this).replaceWith("<text style=\"".concat(style, " font-style: italic;flex-shrink: 0;\">").concat(html, "</text>"));
|
|
158
|
-
});
|
|
159
|
-
$('u').each(function () {
|
|
160
|
-
var html = $(this).html();
|
|
161
|
-
var style = $(this).attr('style') || '';
|
|
162
|
-
$(this).replaceWith("<text style=\"".concat(style, " text-decoration: underline;flex-shrink: 0;\">").concat(html, "</text>"));
|
|
163
|
-
});
|
|
164
|
-
$('s').each(function () {
|
|
165
|
-
var html = $(this).html();
|
|
166
|
-
var style = $(this).attr('style') || '';
|
|
167
|
-
$(this).replaceWith("<text style=\"".concat(style, " text-decoration: line-through;flex-shrink: 0;\">").concat(html, "</text>"));
|
|
168
|
-
});
|
|
169
|
-
$('span').each(function () {
|
|
170
|
-
var html = $(this).html();
|
|
171
|
-
var style = $(this).attr('style') || '';
|
|
172
|
-
$(this).replaceWith("<text style=\"".concat(style, " flex-shrink: 0;\">").concat(html, "</text>"));
|
|
173
|
-
});
|
|
174
|
-
//p换成div
|
|
175
|
-
$('p').each(function () {
|
|
176
|
-
var html = $(this).html();
|
|
177
|
-
var style = $(this).attr('style') || '';
|
|
178
|
-
$(this).replaceWith("<div style=\"".concat(style, " ;flex-shrink: 0;\">").concat(html, "</div>"));
|
|
179
|
-
});
|
|
180
|
-
//pixui 连续的 br 会被吃掉,用 div 占位
|
|
181
|
-
$('br').each(function () {
|
|
182
|
-
$(this).replaceWith("<br><div style = \"width:50px; height:15px; flex-shrink: 0;\" />");
|
|
183
|
-
});
|
|
184
|
-
//补充 flex-shrink: 0
|
|
185
|
-
['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'a', 'img'].forEach(function (tag) {
|
|
186
|
-
$("".concat(tag)).each(function () {
|
|
187
|
-
var style = $(this).attr('style') || '';
|
|
188
|
-
$(this).attr('style', "".concat(style, " flex-shrink: 0;"));
|
|
189
|
-
});
|
|
190
|
-
});
|
|
191
|
-
//将嵌套的text节点合并,同时合并内外的style
|
|
192
|
-
while ($('text > text').length > 0) {
|
|
193
|
-
$('text').each(function () {
|
|
194
|
-
var $this = $(this);
|
|
195
|
-
var parentStyle = $this.attr('style') || '';
|
|
196
|
-
$this.children('text').each(function () {
|
|
197
|
-
var $child = $(this);
|
|
198
|
-
var childStyle = $child.attr('style') || '';
|
|
199
|
-
// 合并style属性
|
|
200
|
-
var mergedStyle = "".concat(parentStyle, "; ").concat(childStyle);
|
|
201
|
-
// 更新子元素的style属性
|
|
202
|
-
$child.attr('style', mergedStyle);
|
|
203
|
-
});
|
|
204
|
-
//去掉父节点
|
|
205
|
-
if ($this.children('text').length > 0) {
|
|
206
|
-
$this.replaceWith($this.html() || '');
|
|
207
|
-
}
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
//去除空的text节点
|
|
211
|
-
$('text').each(function () {
|
|
212
|
-
var t = $(this).html() || '';
|
|
213
|
-
if (t.trim() == '') {
|
|
214
|
-
$(this).remove();
|
|
215
|
-
}
|
|
216
|
-
});
|
|
217
|
-
//!!并列的text节点在父节点为flexDirection:row时无法正确换行,将其修改为div,外层再包一个text节点
|
|
218
|
-
['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'div'].map(function (tag) {
|
|
219
|
-
$("".concat(tag)).each(function () {
|
|
220
|
-
$(this)
|
|
221
|
-
.children('text')
|
|
222
|
-
.each(function () {
|
|
223
|
-
var text = $(this).html();
|
|
224
|
-
var style = $(this).attr('style') || '';
|
|
225
|
-
$(this).replaceWith("<div style=\"".concat(style, "\">").concat(text, "</div>"));
|
|
226
|
-
});
|
|
227
|
-
var taghtml = $(this).html();
|
|
228
|
-
var tagstyle = $(this).attr('style') || '';
|
|
229
|
-
//自己的子节点外套一个text,自己不变
|
|
230
|
-
$(this).replaceWith("<".concat(tag, " style=\"").concat(tagstyle, "\"><text>").concat(taghtml, "</text></").concat(tag, ">"));
|
|
231
|
-
});
|
|
232
|
-
});
|
|
233
|
-
//pixui 的 line-height只在 text 上生效,所以将所有的 div 上的 line-height 转移到父 text 上
|
|
234
|
-
//当前的结构为 div > text > div,只处理一层就行
|
|
235
|
-
//遍历每个 text 的子 div,将其中最大的 line-height 转移到 text 上
|
|
236
|
-
$('text').each(function () {
|
|
237
|
-
var $text = $(this);
|
|
238
|
-
var maxLineHeight = 0;
|
|
239
|
-
$text.children('div').each(function () {
|
|
240
|
-
var lineHeight = $(this).css('line-height') || '0';
|
|
241
|
-
var lineHeightNum = parseInt(lineHeight);
|
|
242
|
-
if (lineHeightNum > maxLineHeight) {
|
|
243
|
-
maxLineHeight = lineHeightNum;
|
|
244
|
-
}
|
|
245
|
-
// $(this).css('line-height', '0');
|
|
246
|
-
});
|
|
247
|
-
if (maxLineHeight > 0) {
|
|
248
|
-
// pixui 中的实际显示的距离与网页中实际显示的距离差距较大,暂时*5rem
|
|
249
|
-
$text.css('line-height', maxLineHeight * 5 + 'rem');
|
|
250
|
-
}
|
|
251
|
-
});
|
|
252
|
-
if (aLabelData) {
|
|
253
|
-
$('a').each(function (i, ele) {
|
|
254
|
-
var id = "PA_RichTextATagId_".concat(i);
|
|
255
|
-
$(this).attr('id', id);
|
|
256
|
-
aLabelData[id] = $(this).attr('href');
|
|
257
|
-
$(this).attr('href', '');
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
//手动处理标签的结尾符
|
|
261
|
-
var res = $.html();
|
|
262
|
-
res = res
|
|
263
|
-
.replaceAll(/<br>/g, '<br />')
|
|
264
|
-
.replaceAll(/<img([^>]+)>/g, '<img$1 />')
|
|
265
|
-
.replaceAll(/ /g, ' ');
|
|
266
|
-
// console.log('rrrr', res);
|
|
267
|
-
res = "<div style=\"display:flex;flex-direction:column;width:100%;\">".concat(res, "</div>");
|
|
268
|
-
return res;
|
|
269
|
-
};
|
|
270
79
|
})(tools || (tools = {}));
|