@revenuecat/purchases-ui-js 0.0.16 → 0.0.18
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/dist/components/button/Button.svelte +0 -13
- package/dist/components/button/Button.svelte.d.ts +4 -2
- package/dist/components/button/ButtonNode.stories.svelte +16 -11
- package/dist/components/button/ButtonNode.svelte +26 -1
- package/dist/components/button/ButtonNode.svelte.d.ts +1 -0
- package/dist/components/button/button-utils.d.ts +2 -0
- package/dist/components/button/button-utils.js +19 -0
- package/dist/components/footer/Footer.stories.svelte +47 -155
- package/dist/components/footer/Footer.stories.svelte.d.ts +1 -2
- package/dist/components/footer/Footer.svelte +10 -1
- package/dist/components/footer/Footer.svelte.d.ts +1 -0
- package/dist/components/image/Image.stories.svelte +13 -7
- package/dist/components/image/Image.svelte +37 -19
- package/dist/components/image/Image.svelte.d.ts +1 -0
- package/dist/components/image/image-utils.d.ts +2 -12
- package/dist/components/image/image-utils.js +28 -11
- package/dist/components/package/Package.stories.svelte +5 -5
- package/dist/components/package/Package.svelte +15 -6
- package/dist/components/package/Package.svelte.d.ts +1 -0
- package/dist/components/paywall/Node.svelte +77 -17
- package/dist/components/paywall/Node.svelte.d.ts +21 -2
- package/dist/components/paywall/Paywall.stories.svelte +93 -15
- package/dist/components/paywall/Paywall.svelte +110 -88
- package/dist/components/paywall/Paywall.svelte.d.ts +4 -0
- package/dist/components/paywall/paywall-utils.d.ts +1 -1
- package/dist/components/paywall/paywall-utils.js +11 -9
- package/dist/components/purchase-button/PurchaseButton.stories.svelte +7 -8
- package/dist/components/purchase-button/PurchaseButton.svelte +24 -10
- package/dist/components/purchase-button/PurchaseButton.svelte.d.ts +1 -0
- package/dist/components/purchase-button/purchase-button-utils.d.ts +2 -0
- package/dist/components/purchase-button/purchase-button-utils.js +20 -0
- package/dist/components/stack/Stack.stories.svelte +1138 -6
- package/dist/components/stack/Stack.svelte +160 -42
- package/dist/components/stack/Stack.svelte.d.ts +1 -0
- package/dist/components/stack/stack-utils.d.ts +24 -24
- package/dist/components/stack/stack-utils.js +245 -12
- package/dist/components/text/Text.svelte +24 -19
- package/dist/components/text/Text.svelte.d.ts +4 -2
- package/dist/components/text/TextNode.stories.svelte +13 -13
- package/dist/components/text/TextNode.svelte +24 -34
- package/dist/components/text/TextNode.svelte.d.ts +1 -0
- package/dist/components/text/text-utils.d.ts +11 -14
- package/dist/components/text/text-utils.js +130 -15
- package/dist/components/timeline/Timeline.stories.svelte +640 -0
- package/dist/components/timeline/Timeline.stories.svelte.d.ts +19 -0
- package/dist/components/timeline/Timeline.svelte +40 -0
- package/dist/components/timeline/Timeline.svelte.d.ts +4 -0
- package/dist/components/timeline/TimelineItem.svelte +112 -0
- package/dist/components/timeline/TimelineItem.svelte.d.ts +4 -0
- package/dist/components/timeline/timeline-utils.d.ts +8 -0
- package/dist/components/timeline/timeline-utils.js +128 -0
- package/dist/data/entities.d.ts +89 -9
- package/dist/data/state.d.ts +2 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -2
- package/dist/stories/fixtures.d.ts +7 -1
- package/dist/stories/fixtures.js +6898 -7
- package/dist/stories/meta-templates.d.ts +0 -1
- package/dist/stories/meta-templates.js +0 -5
- package/dist/types.d.ts +16 -7
- package/dist/types.js +7 -0
- package/dist/utils/style-utils.d.ts +80 -41
- package/dist/utils/style-utils.js +157 -70
- package/dist/utils/variable-utils.d.ts +27 -0
- package/dist/utils/variable-utils.js +37 -0
- package/package.json +27 -25
- package/dist/components/paywall/global-styles.css +0 -9
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
import { defineMeta } from "@storybook/addon-svelte-csf";
|
|
3
3
|
import TextNode from "./TextNode.svelte";
|
|
4
4
|
import {
|
|
5
|
-
colorModeStoryMeta,
|
|
6
5
|
fontSizeStoryMeta,
|
|
7
6
|
fontWeightStoryMeta,
|
|
8
7
|
getColorStoryMeta,
|
|
@@ -10,6 +9,7 @@
|
|
|
10
9
|
getTextControlStoryMeta,
|
|
11
10
|
horizontalAlignmentStoryMeta,
|
|
12
11
|
} from "../../stories/meta-templates";
|
|
12
|
+
import type { VariableDictionary } from "../../utils/variable-utils";
|
|
13
13
|
|
|
14
14
|
/*
|
|
15
15
|
* Documentation for this component can be found in https://www.notion.so/revenuecat/Text-e257cb046e104351861f8364ede617be?pvs=4
|
|
@@ -25,7 +25,6 @@
|
|
|
25
25
|
"Font family to be used, uses GoogleFonts API",
|
|
26
26
|
),
|
|
27
27
|
font_weight: fontWeightStoryMeta,
|
|
28
|
-
colorMode: colorModeStoryMeta,
|
|
29
28
|
font_size: fontSizeStoryMeta,
|
|
30
29
|
color: getColorStoryMeta("Text color object"),
|
|
31
30
|
background_color: getColorStoryMeta("Background color object"),
|
|
@@ -53,6 +52,7 @@
|
|
|
53
52
|
purchaseState: {
|
|
54
53
|
locale: "en_US",
|
|
55
54
|
defaultLocale: "en_US",
|
|
55
|
+
colorMode: "light",
|
|
56
56
|
},
|
|
57
57
|
},
|
|
58
58
|
});
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
args={{
|
|
74
74
|
font_weight: "bold",
|
|
75
75
|
text_style: "normal",
|
|
76
|
-
horizontal_alignment: "
|
|
76
|
+
horizontal_alignment: "leading",
|
|
77
77
|
name: "hello world!",
|
|
78
78
|
}}
|
|
79
79
|
/>
|
|
@@ -95,7 +95,7 @@
|
|
|
95
95
|
args={{
|
|
96
96
|
font_weight: "regular",
|
|
97
97
|
text_style: "normal",
|
|
98
|
-
horizontal_alignment: "
|
|
98
|
+
horizontal_alignment: "leading",
|
|
99
99
|
color: {
|
|
100
100
|
dark: { type: "hex", value: "#3471eb" },
|
|
101
101
|
light: { type: "hex", value: "#3471eb" },
|
|
@@ -114,8 +114,8 @@
|
|
|
114
114
|
args={{
|
|
115
115
|
font_weight: "regular",
|
|
116
116
|
text_style: "normal",
|
|
117
|
-
horizontal_alignment: "
|
|
118
|
-
size: { width: { type: "fixed", value: 200 }, height: { type: "
|
|
117
|
+
horizontal_alignment: "leading",
|
|
118
|
+
size: { width: { type: "fixed", value: 200 }, height: { type: "fit" } },
|
|
119
119
|
padding: { top: 20, trailing: 20, bottom: 20, leading: 20 },
|
|
120
120
|
color: {
|
|
121
121
|
dark: {
|
|
@@ -170,8 +170,8 @@
|
|
|
170
170
|
args={{
|
|
171
171
|
font_weight: "regular",
|
|
172
172
|
text_style: "normal",
|
|
173
|
-
horizontal_alignment: "
|
|
174
|
-
size: { width: { type: "fixed", value: 200 }, height: { type: "
|
|
173
|
+
horizontal_alignment: "leading",
|
|
174
|
+
size: { width: { type: "fixed", value: 200 }, height: { type: "fit" } },
|
|
175
175
|
padding: { top: 20, trailing: 20, bottom: 20, leading: 20 },
|
|
176
176
|
color: {
|
|
177
177
|
dark: {
|
|
@@ -225,7 +225,7 @@
|
|
|
225
225
|
args={{
|
|
226
226
|
font_weight: "regular",
|
|
227
227
|
text_style: "normal",
|
|
228
|
-
horizontal_alignment: "
|
|
228
|
+
horizontal_alignment: "leading",
|
|
229
229
|
padding: { top: 16, trailing: 24, bottom: 16, leading: 24 },
|
|
230
230
|
margin: { top: 8, trailing: 0, bottom: 8, leading: 0 },
|
|
231
231
|
name: "hello world!",
|
|
@@ -238,11 +238,11 @@
|
|
|
238
238
|
args={{
|
|
239
239
|
font_weight: "regular",
|
|
240
240
|
text_style: "normal",
|
|
241
|
-
horizontal_alignment: "
|
|
241
|
+
horizontal_alignment: "leading",
|
|
242
242
|
padding: { top: 16, trailing: 24, bottom: 16, leading: 24 },
|
|
243
243
|
margin: { top: 8, trailing: 0, bottom: 8, leading: 0 },
|
|
244
244
|
name: "hello world!",
|
|
245
|
-
variableDictionary: mockVariableDictionary,
|
|
245
|
+
variableDictionary: mockVariableDictionary as VariableDictionary,
|
|
246
246
|
labels: {
|
|
247
247
|
en_US: {
|
|
248
248
|
lb123:
|
|
@@ -258,11 +258,11 @@
|
|
|
258
258
|
args={{
|
|
259
259
|
font_weight: "regular",
|
|
260
260
|
text_style: "normal",
|
|
261
|
-
horizontal_alignment: "
|
|
261
|
+
horizontal_alignment: "leading",
|
|
262
262
|
padding: { top: 16, trailing: 24, bottom: 16, leading: 24 },
|
|
263
263
|
margin: { top: 8, trailing: 0, bottom: 8, leading: 0 },
|
|
264
264
|
name: "hello world!",
|
|
265
|
-
variableDictionary: mockVariableDictionary,
|
|
265
|
+
variableDictionary: mockVariableDictionary as VariableDictionary,
|
|
266
266
|
labels: {
|
|
267
267
|
en_US: {
|
|
268
268
|
lb123:
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
getHtmlFromMarkdown,
|
|
4
|
+
getTextNodeStyles,
|
|
5
|
+
getTextWrapperStyles,
|
|
6
|
+
} from "./text-utils";
|
|
3
7
|
import Text from "./Text.svelte";
|
|
4
8
|
import type { TextNodeProps } from "../../data/entities";
|
|
5
|
-
import {
|
|
6
|
-
getComponentStyles,
|
|
7
|
-
getLabelById,
|
|
8
|
-
getSizeStyle,
|
|
9
|
-
stringifyStyles,
|
|
10
|
-
} from "../../utils/style-utils";
|
|
11
|
-
import { replaceVariables } from "../../utils/variable-utils";
|
|
9
|
+
import { getLabelAndReplaceVariables } from "../../utils/variable-utils";
|
|
12
10
|
|
|
13
11
|
const {
|
|
14
12
|
id,
|
|
@@ -22,7 +20,7 @@
|
|
|
22
20
|
}: TextNodeProps = $props();
|
|
23
21
|
|
|
24
22
|
const { tagToRender, textStyles } = $derived(
|
|
25
|
-
|
|
23
|
+
getTextNodeStyles({
|
|
26
24
|
id,
|
|
27
25
|
labels,
|
|
28
26
|
text_lid,
|
|
@@ -32,45 +30,37 @@
|
|
|
32
30
|
...restProps,
|
|
33
31
|
}),
|
|
34
32
|
);
|
|
33
|
+
|
|
35
34
|
const wrapperStyles = $derived(
|
|
36
|
-
|
|
37
|
-
...getComponentStyles({
|
|
38
|
-
backgroundColor: background_color,
|
|
39
|
-
...restProps,
|
|
40
|
-
}),
|
|
41
|
-
...getSizeStyle(size),
|
|
42
|
-
}),
|
|
35
|
+
getTextWrapperStyles(restProps, size, background_color),
|
|
43
36
|
);
|
|
44
|
-
const styles = $derived(stringifyStyles(textStyles));
|
|
45
37
|
|
|
46
|
-
const
|
|
47
|
-
|
|
38
|
+
const parsedLabel = $derived(
|
|
39
|
+
getLabelAndReplaceVariables({
|
|
48
40
|
text_lid,
|
|
49
|
-
purchaseState.locale,
|
|
50
|
-
purchaseState.defaultLocale,
|
|
41
|
+
locale: purchaseState.locale,
|
|
42
|
+
defaultLocale: purchaseState.defaultLocale,
|
|
51
43
|
labels,
|
|
52
|
-
),
|
|
53
|
-
);
|
|
54
|
-
const parsedLabel = $derived(
|
|
55
|
-
replaceVariables({
|
|
56
|
-
value: label,
|
|
57
44
|
variableDictionary,
|
|
58
45
|
}),
|
|
59
46
|
);
|
|
47
|
+
const markdownParsed = $derived(getHtmlFromMarkdown(parsedLabel));
|
|
60
48
|
</script>
|
|
61
49
|
|
|
62
|
-
<span style={wrapperStyles} class="text-wrapper">
|
|
63
|
-
<Text styleVariables={
|
|
64
|
-
{
|
|
50
|
+
<span style={wrapperStyles} class="rc-pw-text-wrapper">
|
|
51
|
+
<Text styleVariables={textStyles} component={tagToRender} {id}>
|
|
52
|
+
{@html markdownParsed}
|
|
65
53
|
</Text>
|
|
66
54
|
</span>
|
|
67
55
|
|
|
68
56
|
<style>
|
|
69
|
-
.text-wrapper {
|
|
57
|
+
.rc-pw-text-wrapper {
|
|
70
58
|
display: block;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
59
|
+
height: var(--text-height, initial);
|
|
60
|
+
width: var(--text-width, initial);
|
|
61
|
+
background: var(--text-background, none);
|
|
62
|
+
position: var(--text-position, relative);
|
|
63
|
+
inset: var(--text-inset, 0);
|
|
64
|
+
transform: var(--text-transform, initial);
|
|
75
65
|
}
|
|
76
66
|
</style>
|
|
@@ -1,22 +1,19 @@
|
|
|
1
|
-
import { type TextComponentTags } from "../../utils/style-utils";
|
|
2
1
|
import type { TextNodeProps } from "../../data/entities";
|
|
3
|
-
type
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
"--text-align": string;
|
|
7
|
-
"--font-weight": number | string;
|
|
8
|
-
"--font-size": string;
|
|
9
|
-
"--font-family": string;
|
|
10
|
-
"--background-clip": string;
|
|
11
|
-
"--text-fill-color": string;
|
|
12
|
-
};
|
|
2
|
+
import type { ColorType, SizeType } from "../../types";
|
|
3
|
+
export declare const defaultColor: ColorType;
|
|
4
|
+
export declare const defaultBackgroundColor: ColorType;
|
|
13
5
|
/**
|
|
14
6
|
* Generates comprehensive styles for text components by combining text, component and size styles
|
|
15
7
|
* @param props - Text component properties including font, color, background, spacing etc.
|
|
16
8
|
* @returns Object containing text style variables and the appropriate HTML tag to render
|
|
17
9
|
*/
|
|
18
10
|
export declare const getTextComponentStyles: (props: TextNodeProps) => {
|
|
19
|
-
textStyles:
|
|
20
|
-
tagToRender:
|
|
11
|
+
textStyles: Record<string, string | number>;
|
|
12
|
+
tagToRender: import("../../utils/style-utils").TextComponentTags;
|
|
13
|
+
};
|
|
14
|
+
export declare function getTextWrapperStyles(restProps: Partial<TextNodeProps>, size: SizeType, background_color?: ColorType): string;
|
|
15
|
+
export declare function getTextNodeStyles(props: TextNodeProps): {
|
|
16
|
+
tagToRender: import("../../utils/style-utils").TextComponentTags;
|
|
17
|
+
textStyles: string;
|
|
21
18
|
};
|
|
22
|
-
export
|
|
19
|
+
export declare function getHtmlFromMarkdown(text?: string): string;
|
|
@@ -1,35 +1,150 @@
|
|
|
1
|
-
import { getActiveStateProps, getComponentStyles, getSizeStyle, getTextComponentTag, getTextStyles, } from "../../utils/style-utils";
|
|
1
|
+
import { getActiveStateProps, getComponentStyles, getSizeStyle, getTextComponentTag, getTextStyles, prefixObject, stringifyStyles, } from "../../utils/style-utils";
|
|
2
|
+
export const defaultColor = {
|
|
3
|
+
light: { type: "hex", value: "#000000" },
|
|
4
|
+
};
|
|
5
|
+
export const defaultBackgroundColor = {
|
|
6
|
+
light: { type: "hex", value: "#FFFFFF" },
|
|
7
|
+
};
|
|
2
8
|
/**
|
|
3
9
|
* Generates comprehensive styles for text components by combining text, component and size styles
|
|
4
10
|
* @param props - Text component properties including font, color, background, spacing etc.
|
|
5
11
|
* @returns Object containing text style variables and the appropriate HTML tag to render
|
|
6
12
|
*/
|
|
7
13
|
export const getTextComponentStyles = (props) => {
|
|
8
|
-
const { font_size = "body_m", color =
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
const { font_size = "body_m", color = defaultColor, background_color = defaultBackgroundColor, padding, margin, size, purchaseState, } = props;
|
|
15
|
+
const styles = {
|
|
16
|
+
"--width": "unset",
|
|
17
|
+
"--height": "unset",
|
|
18
|
+
"--text-align": "initial",
|
|
19
|
+
"--font-weight": "initial",
|
|
20
|
+
"--font-size": "initial",
|
|
21
|
+
"--font-family": "sans-serif",
|
|
22
|
+
"--background-clip": "unset",
|
|
23
|
+
"--text-fill-color": "unset",
|
|
24
|
+
"--margin-block-start": "0px",
|
|
25
|
+
"--margin-inline-end": "0px",
|
|
26
|
+
"--margin-block-end": "0px",
|
|
27
|
+
"--margin-inline-start": "0px",
|
|
28
|
+
"--padding-block-start": "0px",
|
|
29
|
+
"--padding-inline-end": "0px",
|
|
30
|
+
"--padding-block-end": "0px",
|
|
31
|
+
"--padding-inline-start": "0px",
|
|
32
|
+
"--background": "transparent",
|
|
33
|
+
"--text-color": "inherit",
|
|
34
|
+
"--border": "none",
|
|
35
|
+
"--border-end-start-radius": "0px",
|
|
36
|
+
"--border-end-end-radius": "0px",
|
|
37
|
+
"--border-start-start-radius": "0px",
|
|
38
|
+
"--border-start-end-radius": "0px",
|
|
39
|
+
"--shadow": "none",
|
|
40
|
+
"--flex": "0 1 auto",
|
|
41
|
+
};
|
|
15
42
|
const activeStateProps = getActiveStateProps(props.overrides, props.componentState);
|
|
16
43
|
const tagToRender = getTextComponentTag(font_size);
|
|
17
|
-
const textStyles = getTextStyles({ ...props, ...activeStateProps }, colorMode);
|
|
44
|
+
const textStyles = getTextStyles({ ...props, ...activeStateProps }, purchaseState.colorMode);
|
|
18
45
|
const componentStyles = getComponentStyles({
|
|
19
46
|
backgroundColor: background_color,
|
|
20
47
|
textColor: color,
|
|
21
48
|
margin,
|
|
22
49
|
padding,
|
|
23
|
-
colorMode,
|
|
50
|
+
colorMode: purchaseState.colorMode,
|
|
24
51
|
...activeStateProps,
|
|
25
52
|
});
|
|
26
53
|
const sizeStyles = getSizeStyle({ ...size, ...activeStateProps });
|
|
54
|
+
const stylesObject = {
|
|
55
|
+
...styles,
|
|
56
|
+
...componentStyles,
|
|
57
|
+
...textStyles,
|
|
58
|
+
...sizeStyles,
|
|
59
|
+
};
|
|
27
60
|
return {
|
|
28
|
-
textStyles:
|
|
29
|
-
...componentStyles,
|
|
30
|
-
...textStyles,
|
|
31
|
-
...sizeStyles,
|
|
32
|
-
},
|
|
61
|
+
textStyles: prefixObject(stylesObject, "text"),
|
|
33
62
|
tagToRender,
|
|
34
63
|
};
|
|
35
64
|
};
|
|
65
|
+
export function getTextWrapperStyles(restProps, size, background_color) {
|
|
66
|
+
const styles = {
|
|
67
|
+
"--width": "unset",
|
|
68
|
+
"--height": "unset",
|
|
69
|
+
"--flex": "0 1 auto",
|
|
70
|
+
"--margin-block-start": "0px",
|
|
71
|
+
"--margin-inline-end": "0px",
|
|
72
|
+
"--margin-block-end": "0px",
|
|
73
|
+
"--margin-inline-start": "0px",
|
|
74
|
+
"--padding-block-start": "0px",
|
|
75
|
+
"--padding-inline-end": "0px",
|
|
76
|
+
"--padding-block-end": "0px",
|
|
77
|
+
"--padding-inline-start": "0px",
|
|
78
|
+
"--background": "transparent",
|
|
79
|
+
"--text-color": "inherit",
|
|
80
|
+
"--border": "none",
|
|
81
|
+
"--border-end-start-radius": "0px",
|
|
82
|
+
"--border-end-end-radius": "0px",
|
|
83
|
+
"--border-start-start-radius": "0px",
|
|
84
|
+
"--border-start-end-radius": "0px",
|
|
85
|
+
"--shadow": "none",
|
|
86
|
+
"--position": "relative",
|
|
87
|
+
"--inset": "0",
|
|
88
|
+
"--transform": "initial",
|
|
89
|
+
};
|
|
90
|
+
Object.assign(styles, getComponentStyles({
|
|
91
|
+
backgroundColor: background_color,
|
|
92
|
+
...restProps,
|
|
93
|
+
}), getSizeStyle(size));
|
|
94
|
+
Object.assign(styles, restProps.zStackChildStyles);
|
|
95
|
+
const prefixedStyles = prefixObject(styles, "text");
|
|
96
|
+
return stringifyStyles(prefixedStyles);
|
|
97
|
+
}
|
|
98
|
+
export function getTextNodeStyles(props) {
|
|
99
|
+
const styles = {
|
|
100
|
+
"--text-margin-block-start": "0px",
|
|
101
|
+
"--text-margin-inline-end": "0px",
|
|
102
|
+
"--text-margin-block-end": "0px",
|
|
103
|
+
"--text-margin-inline-start": "0px",
|
|
104
|
+
"--text-padding-block-start": "0px",
|
|
105
|
+
"--text-padding-inline-end": "0px",
|
|
106
|
+
"--text-padding-block-end": "0px",
|
|
107
|
+
"--text-padding-inline-start": "0px",
|
|
108
|
+
"--text-background": "transparent",
|
|
109
|
+
"--text-text-color": "inherit",
|
|
110
|
+
"--text-border": "none",
|
|
111
|
+
"--text-border-end-start-radius": "0px",
|
|
112
|
+
"--text-border-end-end-radius": "0px",
|
|
113
|
+
"--text-border-start-start-radius": "0px",
|
|
114
|
+
"--text-border-start-end-radius": "0px",
|
|
115
|
+
"--text-shadow": "none",
|
|
116
|
+
"--text-text-align": "initial",
|
|
117
|
+
"--text-font-weight": "initial",
|
|
118
|
+
"--text-font-size": "initial",
|
|
119
|
+
"--text-font-family": "sans-serif",
|
|
120
|
+
"--text-background-clip": "initial",
|
|
121
|
+
"--text-text-fill-color": "initial",
|
|
122
|
+
"--text-width": "unset",
|
|
123
|
+
"--text-height": "unset",
|
|
124
|
+
"--text-flex": "0 1 auto",
|
|
125
|
+
};
|
|
126
|
+
const { tagToRender, textStyles } = getTextComponentStyles(props);
|
|
127
|
+
Object.assign(styles, textStyles);
|
|
128
|
+
return { tagToRender, textStyles: stringifyStyles(styles) };
|
|
129
|
+
}
|
|
130
|
+
export function getHtmlFromMarkdown(text) {
|
|
131
|
+
if (!text)
|
|
132
|
+
return "";
|
|
133
|
+
const regexpDictionary = {
|
|
134
|
+
newLine: { regexp: /\\\n/g, output: "<br/>" },
|
|
135
|
+
bold: { regexp: /\*\*(.*?)\*\*/g, output: "<b>$1</b>" },
|
|
136
|
+
italic: { regexp: /\*(.*?)\*/g, output: "<i>$1</i>" },
|
|
137
|
+
strikethrough: { regexp: /~(.*?)~/g, output: "<s>$1</s>" },
|
|
138
|
+
code: {
|
|
139
|
+
regexp: /`(.*?)`/g,
|
|
140
|
+
output: "<span style='font-family: monospace'>$1</span>",
|
|
141
|
+
},
|
|
142
|
+
link: {
|
|
143
|
+
regexp: /\[(.*?)\]\((.*?)\)/g,
|
|
144
|
+
output: "<a href=$2 target='_blank' rel='noopener noreferrer'>$1</a>",
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
return Object.values(regexpDictionary).reduce((parsedText, { regexp, output }) => {
|
|
148
|
+
return parsedText.replaceAll(regexp, output);
|
|
149
|
+
}, text);
|
|
150
|
+
}
|