esoftplay-event 0.0.2-t → 0.0.2-v

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.
@@ -9,15 +9,11 @@ export interface EventHtmltextProps extends TextProps {
9
9
  export default function m({ style, children, ...props }: EventHtmltextProps): JSX.Element {
10
10
  const renderChildren = (child: ReactNode) => {
11
11
  if (typeof child === 'string') {
12
- return parseHtmlText(child).map((part, index) => (
12
+ return parseRecursive(child).map((part, index) => (
13
13
  <Text key={index} style={[style, part.style]}>
14
- {part.text}
14
+ {part.children}
15
15
  </Text>
16
16
  ));
17
- } else if (React.isValidElement(child)) {
18
- return React.cloneElement(child, {
19
- style: [style, child.props.style], // Merge styles properly
20
- });
21
17
  } else if (Array.isArray(child)) {
22
18
  return child.map((nestedChild, index) => (
23
19
  <React.Fragment key={index}>{renderChildren(nestedChild)}</React.Fragment>
@@ -29,32 +25,48 @@ export default function m({ style, children, ...props }: EventHtmltextProps): JS
29
25
  return <Text {...props}>{renderChildren(children)}</Text>;
30
26
  }
31
27
 
32
- const parseHtmlText = (htmlString: string) => {
33
- const regex = /(<b>(.*?)<\/b>)|(<i>(.*?)<\/i>)|(<u>(.*?)<\/u>)|(<br\s*\/?>)/g;
34
- let parts = [];
35
- let lastIndex = 0;
28
+ interface ParsedPart {
29
+ children: ReactNode;
30
+ style: TextStyle;
31
+ }
36
32
 
37
- htmlString.replace(regex, (match, bold, boldText, italic, italicText, underline, underlineText, br, index) => {
38
- if (index > lastIndex) {
39
- parts.push({ text: htmlString.substring(lastIndex, index), style: {} });
40
- }
33
+ const parseRecursive = (htmlString: string): ParsedPart[] => {
34
+ const regex = /<(b|i|u|span|br)(?:\s+style=["']color:\s*(.*?)["'])?\s*>(.*?)<\/\1>|<br\s*\/?>/i;
35
+ const match = htmlString.match(regex);
41
36
 
42
- if (boldText) {
43
- parts.push({ text: boldText, style: { fontWeight: 'bold' } });
44
- } else if (italicText) {
45
- parts.push({ text: italicText, style: { fontStyle: 'italic' } });
46
- } else if (underlineText) {
47
- parts.push({ text: underlineText, style: { textDecorationLine: 'underline' } });
48
- } else if (br) {
49
- parts.push({ text: '\n', style: {} });
50
- }
37
+ if (!match) {
38
+ return [{ children: htmlString, style: {} }];
39
+ }
40
+
41
+ const parts: ParsedPart[] = [];
42
+ const [fullMatch, tag, color, content] = match;
43
+ const index = match.index!;
51
44
 
52
- lastIndex = index + match.length;
53
- return match;
54
- });
45
+ if (index > 0) {
46
+ parts.push({ children: htmlString.substring(0, index), style: {} });
47
+ }
48
+ let currentStyle: TextStyle = {};
49
+ switch (tag?.toLowerCase()) {
50
+ case 'b': currentStyle.fontWeight = 'bold'; break;
51
+ case 'i': currentStyle.fontStyle = 'italic'; break;
52
+ case 'u': currentStyle.textDecorationLine = 'underline'; break;
53
+ case 'span': if (color) currentStyle.color = color.trim(); break;
54
+ case 'br':
55
+ parts.push({ children: '\n', style: {} });
56
+ break;
57
+ }
58
+
59
+ if (tag !== 'br' && content !== undefined) {
60
+ const nestedParts = parseRecursive(content).map(p => ({
61
+ ...p,
62
+ style: { ...currentStyle, ...p.style }
63
+ }));
64
+ parts.push(...nestedParts);
65
+ }
55
66
 
56
- if (lastIndex < htmlString.length) {
57
- parts.push({ text: htmlString.substring(lastIndex), style: {} });
67
+ const remaining = htmlString.substring(index + fullMatch.length);
68
+ if (remaining) {
69
+ parts.push(...parseRecursive(remaining));
58
70
  }
59
71
 
60
72
  return parts;
package/event/message.tsx CHANGED
@@ -21,8 +21,8 @@ export default function m(props: EventMessageProps): any {
21
21
  return (
22
22
  <View style={[{ flex: 1, alignItems: 'center', justifyContent: 'center' }, props.style]}>
23
23
  <View style={{ justifyContent: 'center', alignItems: 'center', padding: 10 }}>
24
- <LibPicture source={esp.assets('img_failed_msg.png')} style={{ width: LibStyle.width * 0.8, height: 200, resizeMode: 'contain' }} />
25
- <View style={{ width: LibStyle.width - 40, justifyContent: 'center', alignItems: 'center', padding: 15, borderRadius: 10, marginTop: 20 }}>
24
+ <LibPicture source={esp.assets('img_failed_msg.png')} style={{ width: LibStyle.width * 0.8, height: 150, resizeMode: 'contain' }} />
25
+ <View style={{ width: LibStyle.width - 40, justifyContent: 'center', alignItems: 'center', padding: 10, borderRadius: 10, marginTop: 10 }}>
26
26
  <Text allowFontScaling={false} style={[{ flexWrap: 'wrap', fontSize: 14, lineHeight: 20, fontWeight: "bold", marginBottom: 5, color: "#4a4a4a", textAlign: "center" }, props.textStyle]}>{props.message}</Text>
27
27
  </View>
28
28
  </View>