react-native-marked 8.2.0 → 8.3.1

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.
Files changed (94) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +374 -354
  3. package/dist/commonjs/components/MDImage.js +3 -3
  4. package/dist/commonjs/components/MDImage.js.map +1 -1
  5. package/dist/commonjs/components/MDList.js.map +1 -1
  6. package/dist/commonjs/components/MDSvg.js.map +1 -1
  7. package/dist/commonjs/components/MDTable.js.map +1 -1
  8. package/dist/commonjs/hooks/useMarkdown.js +4 -2
  9. package/dist/commonjs/hooks/useMarkdown.js.map +1 -1
  10. package/dist/commonjs/hooks/useMarkdownWithComponents.js +7 -1
  11. package/dist/commonjs/hooks/useMarkdownWithComponents.js.map +1 -1
  12. package/dist/commonjs/index.js.map +1 -1
  13. package/dist/commonjs/lib/Markdown.js +4 -2
  14. package/dist/commonjs/lib/Markdown.js.map +1 -1
  15. package/dist/commonjs/lib/Parser.js +7 -7
  16. package/dist/commonjs/lib/Parser.js.map +1 -1
  17. package/dist/commonjs/lib/ReactComponentRegistry.js.map +1 -1
  18. package/dist/commonjs/lib/ReactComponentTokenizer.js.map +1 -1
  19. package/dist/commonjs/lib/Renderer.js +7 -5
  20. package/dist/commonjs/lib/Renderer.js.map +1 -1
  21. package/dist/commonjs/lib/types.js.map +1 -1
  22. package/dist/commonjs/theme/colors.js.map +1 -1
  23. package/dist/commonjs/theme/spacing.js.map +1 -1
  24. package/dist/commonjs/theme/styles.js +4 -0
  25. package/dist/commonjs/theme/styles.js.map +1 -1
  26. package/dist/commonjs/theme/types.js.map +1 -1
  27. package/dist/commonjs/utils/handlers.js.map +1 -1
  28. package/dist/commonjs/utils/svg.js.map +1 -1
  29. package/dist/commonjs/utils/table.js.map +1 -1
  30. package/dist/commonjs/utils/url.js.map +1 -1
  31. package/dist/module/components/MDImage.js +3 -3
  32. package/dist/module/components/MDImage.js.map +1 -1
  33. package/dist/module/components/MDList.js.map +1 -1
  34. package/dist/module/components/MDSvg.js.map +1 -1
  35. package/dist/module/components/MDTable.js.map +1 -1
  36. package/dist/module/hooks/useMarkdown.js +4 -2
  37. package/dist/module/hooks/useMarkdown.js.map +1 -1
  38. package/dist/module/hooks/useMarkdownWithComponents.js +7 -1
  39. package/dist/module/hooks/useMarkdownWithComponents.js.map +1 -1
  40. package/dist/module/index.js.map +1 -1
  41. package/dist/module/lib/Markdown.js +4 -2
  42. package/dist/module/lib/Markdown.js.map +1 -1
  43. package/dist/module/lib/Parser.js +7 -7
  44. package/dist/module/lib/Parser.js.map +1 -1
  45. package/dist/module/lib/ReactComponentRegistry.js.map +1 -1
  46. package/dist/module/lib/ReactComponentTokenizer.js.map +1 -1
  47. package/dist/module/lib/Renderer.js +7 -5
  48. package/dist/module/lib/Renderer.js.map +1 -1
  49. package/dist/module/lib/types.js.map +1 -1
  50. package/dist/module/theme/colors.js.map +1 -1
  51. package/dist/module/theme/spacing.js.map +1 -1
  52. package/dist/module/theme/styles.js +4 -0
  53. package/dist/module/theme/styles.js.map +1 -1
  54. package/dist/module/theme/types.js.map +1 -1
  55. package/dist/module/utils/handlers.js.map +1 -1
  56. package/dist/module/utils/svg.js.map +1 -1
  57. package/dist/module/utils/table.js.map +1 -1
  58. package/dist/module/utils/url.js.map +1 -1
  59. package/dist/typescript/hooks/useMarkdown.d.ts +3 -0
  60. package/dist/typescript/hooks/useMarkdown.d.ts.map +1 -1
  61. package/dist/typescript/hooks/useMarkdownWithComponents.d.ts.map +1 -1
  62. package/dist/typescript/index.d.ts +2 -2
  63. package/dist/typescript/index.d.ts.map +1 -1
  64. package/dist/typescript/lib/Markdown.d.ts +1 -1
  65. package/dist/typescript/lib/Markdown.d.ts.map +1 -1
  66. package/dist/typescript/lib/Renderer.d.ts +8 -1
  67. package/dist/typescript/lib/Renderer.d.ts.map +1 -1
  68. package/dist/typescript/lib/types.d.ts +6 -0
  69. package/dist/typescript/lib/types.d.ts.map +1 -1
  70. package/dist/typescript/theme/styles.d.ts.map +1 -1
  71. package/dist/typescript/theme/types.d.ts +1 -0
  72. package/dist/typescript/theme/types.d.ts.map +1 -1
  73. package/package.json +178 -175
  74. package/src/components/MDImage.tsx +90 -90
  75. package/src/components/MDList.tsx +46 -46
  76. package/src/components/MDSvg.tsx +108 -108
  77. package/src/components/MDTable.tsx +60 -60
  78. package/src/hooks/useMarkdown.ts +56 -51
  79. package/src/hooks/useMarkdownWithComponents.tsx +94 -89
  80. package/src/index.ts +44 -43
  81. package/src/lib/Markdown.tsx +55 -53
  82. package/src/lib/Parser.tsx +316 -316
  83. package/src/lib/ReactComponentRegistry.tsx +52 -52
  84. package/src/lib/ReactComponentTokenizer.ts +149 -149
  85. package/src/lib/Renderer.tsx +247 -238
  86. package/src/lib/types.ts +93 -87
  87. package/src/theme/colors.ts +31 -31
  88. package/src/theme/spacing.ts +10 -10
  89. package/src/theme/styles.ts +206 -198
  90. package/src/theme/types.ts +34 -33
  91. package/src/utils/handlers.ts +9 -9
  92. package/src/utils/svg.ts +14 -14
  93. package/src/utils/table.ts +29 -29
  94. package/src/utils/url.ts +22 -22
@@ -1,31 +1,31 @@
1
- import type { ColorValue } from "react-native";
2
-
3
- export interface ColorsPropType {
4
- code: ColorValue;
5
- link: ColorValue;
6
- text: ColorValue;
7
- border: ColorValue;
8
- /**
9
- * @deprecated Use flatlist containerStyle or style prop for setting background color
10
- */
11
- background?: ColorValue;
12
- }
13
-
14
- const colors: Record<"light" | "dark", ColorsPropType> = {
15
- light: {
16
- background: "#ffffff",
17
- code: "#f6f8fa",
18
- link: "#58a6ff",
19
- text: "#333333",
20
- border: "#d0d7de",
21
- },
22
- dark: {
23
- background: "#000000",
24
- code: "#161b22",
25
- link: "#58a6ff",
26
- text: "#ffffff",
27
- border: "#30363d",
28
- },
29
- };
30
-
31
- export default colors;
1
+ import type { ColorValue } from "react-native";
2
+
3
+ export interface ColorsPropType {
4
+ code: ColorValue;
5
+ link: ColorValue;
6
+ text: ColorValue;
7
+ border: ColorValue;
8
+ /**
9
+ * @deprecated Use flatlist containerStyle or style prop for setting background color
10
+ */
11
+ background?: ColorValue;
12
+ }
13
+
14
+ const colors: Record<"light" | "dark", ColorsPropType> = {
15
+ light: {
16
+ background: "#ffffff",
17
+ code: "#f6f8fa",
18
+ link: "#58a6ff",
19
+ text: "#333333",
20
+ border: "#d0d7de",
21
+ },
22
+ dark: {
23
+ background: "#000000",
24
+ code: "#161b22",
25
+ link: "#58a6ff",
26
+ text: "#ffffff",
27
+ border: "#30363d",
28
+ },
29
+ };
30
+
31
+ export default colors;
@@ -1,10 +1,10 @@
1
- export type SpacingKeysType = "xs" | "s" | "m" | "l";
2
-
3
- const padding: Record<SpacingKeysType, number> = {
4
- xs: 2,
5
- s: 4,
6
- m: 8,
7
- l: 16,
8
- };
9
-
10
- export default padding;
1
+ export type SpacingKeysType = "xs" | "s" | "m" | "l";
2
+
3
+ const padding: Record<SpacingKeysType, number> = {
4
+ xs: 2,
5
+ s: 4,
6
+ m: 8,
7
+ l: 16,
8
+ };
9
+
10
+ export default padding;
@@ -1,198 +1,206 @@
1
- import { type ColorSchemeName, StyleSheet } from "react-native";
2
- import colors, { type ColorsPropType } from "./colors";
3
- import spacing from "./spacing";
4
- import type { MarkedStyles, UserTheme } from "./types";
5
-
6
- const getFontStyles = (mdColors: ColorsPropType) => {
7
- return StyleSheet.create({
8
- regular: {
9
- fontSize: 16,
10
- lineHeight: 24,
11
- color: mdColors.text,
12
- },
13
- heading: {
14
- fontWeight: "500",
15
- color: mdColors.text,
16
- },
17
- });
18
- };
19
-
20
- const getStyles = (
21
- userStyles?: MarkedStyles,
22
- colorScheme?: ColorSchemeName,
23
- userTheme?: UserTheme,
24
- ): MarkedStyles => {
25
- const mdColors = { ...colors[colorScheme || "light"], ...userTheme?.colors };
26
- const mdSpacing = { ...spacing, ...userTheme?.spacing };
27
-
28
- const fontStyle = getFontStyles(mdColors);
29
- return StyleSheet.create<MarkedStyles>({
30
- em: StyleSheet.flatten([
31
- fontStyle.regular,
32
- {
33
- fontStyle: "italic",
34
- },
35
- userStyles?.em,
36
- ]),
37
- strong: StyleSheet.flatten([
38
- fontStyle.regular,
39
- {
40
- fontWeight: "bold",
41
- },
42
- userStyles?.strong,
43
- ]),
44
- strikethrough: StyleSheet.flatten([
45
- fontStyle.regular,
46
- {
47
- textDecorationLine: "line-through",
48
- textDecorationStyle: "solid",
49
- },
50
- userStyles?.strikethrough,
51
- ]),
52
- text: StyleSheet.flatten([fontStyle.regular, userStyles?.text]),
53
- paragraph: StyleSheet.flatten([
54
- {
55
- paddingVertical: mdSpacing.m,
56
- },
57
- userStyles?.paragraph,
58
- ]),
59
- link: StyleSheet.flatten([
60
- fontStyle.regular,
61
- {
62
- fontStyle: "italic",
63
- color: mdColors.link,
64
- },
65
- userStyles?.link,
66
- ]),
67
- blockquote: StyleSheet.flatten([
68
- {
69
- borderLeftColor: mdColors.border,
70
- paddingLeft: mdSpacing.l,
71
- borderLeftWidth: mdSpacing.s,
72
- opacity: 0.8,
73
- },
74
- userStyles?.blockquote,
75
- ]),
76
- h1: StyleSheet.flatten([
77
- fontStyle.heading,
78
- {
79
- fontSize: 32,
80
- lineHeight: 40,
81
- fontWeight: "bold",
82
- marginVertical: mdSpacing.m,
83
- letterSpacing: 0,
84
- paddingBottom: mdSpacing.s,
85
- borderBottomColor: mdColors.border,
86
- borderBottomWidth: 1,
87
- },
88
- userStyles?.h1,
89
- ]),
90
- h2: StyleSheet.flatten([
91
- fontStyle.heading,
92
- {
93
- fontSize: 28,
94
- lineHeight: 36,
95
- marginVertical: mdSpacing.m,
96
- paddingBottom: mdSpacing.s,
97
- borderBottomColor: mdColors.border,
98
- borderBottomWidth: 1,
99
- },
100
- userStyles?.h2,
101
- ]),
102
- h3: StyleSheet.flatten([
103
- fontStyle.heading,
104
- {
105
- fontSize: 24,
106
- lineHeight: 32,
107
- marginVertical: mdSpacing.s,
108
- },
109
- userStyles?.h3,
110
- ]),
111
- h4: StyleSheet.flatten([
112
- fontStyle.heading,
113
- {
114
- fontSize: 22,
115
- lineHeight: 28,
116
- marginVertical: mdSpacing.s,
117
- },
118
- userStyles?.h4,
119
- ]),
120
- h5: StyleSheet.flatten([
121
- fontStyle.regular,
122
- fontStyle.heading,
123
- {
124
- marginVertical: mdSpacing.xs,
125
- },
126
- userStyles?.h5,
127
- ]),
128
- h6: StyleSheet.flatten([
129
- fontStyle.heading,
130
- {
131
- fontSize: 14,
132
- lineHeight: 20,
133
- marginVertical: mdSpacing.xs,
134
- },
135
- userStyles?.h6,
136
- ]),
137
- codespan: StyleSheet.flatten([
138
- fontStyle.regular,
139
- {
140
- fontStyle: "italic",
141
- backgroundColor: mdColors.code,
142
- fontWeight: "300",
143
- },
144
- userStyles?.codespan,
145
- ]),
146
- code: StyleSheet.flatten([
147
- {
148
- padding: mdSpacing.l,
149
- backgroundColor: mdColors.code,
150
- minWidth: "100%",
151
- },
152
- userStyles?.code,
153
- ]),
154
- hr: StyleSheet.flatten([
155
- {
156
- borderBottomWidth: 1,
157
- borderBottomColor: mdColors.border,
158
- marginVertical: mdSpacing.s,
159
- },
160
- userStyles?.hr,
161
- ]),
162
- list: StyleSheet.flatten([userStyles?.list]),
163
- li: StyleSheet.flatten([
164
- fontStyle.regular,
165
- {
166
- flexShrink: 1,
167
- },
168
- userStyles?.li,
169
- ]),
170
- image: StyleSheet.flatten([
171
- {
172
- resizeMode: "cover",
173
- },
174
- userStyles?.image,
175
- ]),
176
- table: StyleSheet.flatten([
177
- {
178
- borderWidth: 1,
179
- borderColor: mdColors.border,
180
- },
181
- userStyles?.table,
182
- ]),
183
- tableRow: StyleSheet.flatten([
184
- {
185
- flexDirection: "row",
186
- },
187
- userStyles?.tableRow,
188
- ]),
189
- tableCell: StyleSheet.flatten([
190
- {
191
- padding: mdSpacing.s,
192
- },
193
- userStyles?.tableCell,
194
- ]),
195
- });
196
- };
197
-
198
- export default getStyles;
1
+ import { type ColorSchemeName, StyleSheet } from "react-native";
2
+ import colors, { type ColorsPropType } from "./colors";
3
+ import spacing from "./spacing";
4
+ import type { MarkedStyles, UserTheme } from "./types";
5
+
6
+ const getFontStyles = (mdColors: ColorsPropType) => {
7
+ return StyleSheet.create({
8
+ regular: {
9
+ fontSize: 16,
10
+ lineHeight: 24,
11
+ color: mdColors.text,
12
+ },
13
+ heading: {
14
+ fontWeight: "500",
15
+ color: mdColors.text,
16
+ },
17
+ });
18
+ };
19
+
20
+ const getStyles = (
21
+ userStyles?: MarkedStyles,
22
+ colorScheme?: ColorSchemeName,
23
+ userTheme?: UserTheme,
24
+ ): MarkedStyles => {
25
+ const mdColors = { ...colors[colorScheme || "light"], ...userTheme?.colors };
26
+ const mdSpacing = { ...spacing, ...userTheme?.spacing };
27
+
28
+ const fontStyle = getFontStyles(mdColors);
29
+ return StyleSheet.create<MarkedStyles>({
30
+ em: StyleSheet.flatten([
31
+ fontStyle.regular,
32
+ {
33
+ fontStyle: "italic",
34
+ },
35
+ userStyles?.em,
36
+ ]),
37
+ strong: StyleSheet.flatten([
38
+ fontStyle.regular,
39
+ {
40
+ fontWeight: "bold",
41
+ },
42
+ userStyles?.strong,
43
+ ]),
44
+ strikethrough: StyleSheet.flatten([
45
+ fontStyle.regular,
46
+ {
47
+ textDecorationLine: "line-through",
48
+ textDecorationStyle: "solid",
49
+ },
50
+ userStyles?.strikethrough,
51
+ ]),
52
+ text: StyleSheet.flatten([fontStyle.regular, userStyles?.text]),
53
+ paragraph: StyleSheet.flatten([
54
+ {
55
+ paddingVertical: mdSpacing.m,
56
+ },
57
+ userStyles?.paragraph,
58
+ ]),
59
+ link: StyleSheet.flatten([
60
+ fontStyle.regular,
61
+ {
62
+ fontStyle: "italic",
63
+ color: mdColors.link,
64
+ },
65
+ userStyles?.link,
66
+ ]),
67
+ blockquote: StyleSheet.flatten([
68
+ {
69
+ borderLeftColor: mdColors.border,
70
+ paddingLeft: mdSpacing.l,
71
+ borderLeftWidth: mdSpacing.s,
72
+ opacity: 0.8,
73
+ },
74
+ userStyles?.blockquote,
75
+ ]),
76
+ h1: StyleSheet.flatten([
77
+ fontStyle.heading,
78
+ {
79
+ fontSize: 32,
80
+ lineHeight: 40,
81
+ fontWeight: "bold",
82
+ marginVertical: mdSpacing.m,
83
+ letterSpacing: 0,
84
+ paddingBottom: mdSpacing.s,
85
+ borderBottomColor: mdColors.border,
86
+ borderBottomWidth: 1,
87
+ },
88
+ userStyles?.h1,
89
+ ]),
90
+ h2: StyleSheet.flatten([
91
+ fontStyle.heading,
92
+ {
93
+ fontSize: 28,
94
+ lineHeight: 36,
95
+ marginVertical: mdSpacing.m,
96
+ paddingBottom: mdSpacing.s,
97
+ borderBottomColor: mdColors.border,
98
+ borderBottomWidth: 1,
99
+ },
100
+ userStyles?.h2,
101
+ ]),
102
+ h3: StyleSheet.flatten([
103
+ fontStyle.heading,
104
+ {
105
+ fontSize: 24,
106
+ lineHeight: 32,
107
+ marginVertical: mdSpacing.s,
108
+ },
109
+ userStyles?.h3,
110
+ ]),
111
+ h4: StyleSheet.flatten([
112
+ fontStyle.heading,
113
+ {
114
+ fontSize: 22,
115
+ lineHeight: 28,
116
+ marginVertical: mdSpacing.s,
117
+ },
118
+ userStyles?.h4,
119
+ ]),
120
+ h5: StyleSheet.flatten([
121
+ fontStyle.regular,
122
+ fontStyle.heading,
123
+ {
124
+ marginVertical: mdSpacing.xs,
125
+ },
126
+ userStyles?.h5,
127
+ ]),
128
+ h6: StyleSheet.flatten([
129
+ fontStyle.heading,
130
+ {
131
+ fontSize: 14,
132
+ lineHeight: 20,
133
+ marginVertical: mdSpacing.xs,
134
+ },
135
+ userStyles?.h6,
136
+ ]),
137
+ codespan: StyleSheet.flatten([
138
+ fontStyle.regular,
139
+ {
140
+ fontStyle: "italic",
141
+ backgroundColor: mdColors.code,
142
+ fontWeight: "300",
143
+ },
144
+ userStyles?.codespan,
145
+ ]),
146
+ code: StyleSheet.flatten([
147
+ {
148
+ padding: mdSpacing.l,
149
+ backgroundColor: mdColors.code,
150
+ minWidth: "100%",
151
+ },
152
+ userStyles?.code,
153
+ ]),
154
+ codeText: StyleSheet.flatten([
155
+ fontStyle.regular,
156
+ {
157
+ fontStyle: "normal",
158
+ fontWeight: "400",
159
+ },
160
+ userStyles?.codeText,
161
+ ]),
162
+ hr: StyleSheet.flatten([
163
+ {
164
+ borderBottomWidth: 1,
165
+ borderBottomColor: mdColors.border,
166
+ marginVertical: mdSpacing.s,
167
+ },
168
+ userStyles?.hr,
169
+ ]),
170
+ list: StyleSheet.flatten([userStyles?.list]),
171
+ li: StyleSheet.flatten([
172
+ fontStyle.regular,
173
+ {
174
+ flexShrink: 1,
175
+ },
176
+ userStyles?.li,
177
+ ]),
178
+ image: StyleSheet.flatten([
179
+ {
180
+ resizeMode: "cover",
181
+ },
182
+ userStyles?.image,
183
+ ]),
184
+ table: StyleSheet.flatten([
185
+ {
186
+ borderWidth: 1,
187
+ borderColor: mdColors.border,
188
+ },
189
+ userStyles?.table,
190
+ ]),
191
+ tableRow: StyleSheet.flatten([
192
+ {
193
+ flexDirection: "row",
194
+ },
195
+ userStyles?.tableRow,
196
+ ]),
197
+ tableCell: StyleSheet.flatten([
198
+ {
199
+ padding: mdSpacing.s,
200
+ },
201
+ userStyles?.tableCell,
202
+ ]),
203
+ });
204
+ };
205
+
206
+ export default getStyles;
@@ -1,33 +1,34 @@
1
- import type { ImageStyle, TextStyle, ViewStyle } from "react-native";
2
- import type { ColorsPropType } from "./colors";
3
- import type { SpacingKeysType } from "./spacing";
4
-
5
- export interface MarkedStyles {
6
- em?: TextStyle;
7
- strong?: TextStyle;
8
- strikethrough?: TextStyle;
9
- text?: TextStyle;
10
- paragraph?: ViewStyle;
11
- link?: TextStyle;
12
- blockquote?: ViewStyle;
13
- h1?: TextStyle;
14
- h2?: TextStyle;
15
- h3?: TextStyle;
16
- h4?: TextStyle;
17
- h5?: TextStyle;
18
- h6?: TextStyle;
19
- codespan?: TextStyle;
20
- code?: ViewStyle;
21
- hr?: ViewStyle;
22
- list?: ViewStyle;
23
- li?: TextStyle;
24
- image?: ImageStyle;
25
- table?: ViewStyle;
26
- tableRow?: ViewStyle;
27
- tableCell?: ViewStyle;
28
- }
29
-
30
- export interface UserTheme {
31
- colors?: ColorsPropType;
32
- spacing?: Record<SpacingKeysType, number>;
33
- }
1
+ import type { ImageStyle, TextStyle, ViewStyle } from "react-native";
2
+ import type { ColorsPropType } from "./colors";
3
+ import type { SpacingKeysType } from "./spacing";
4
+
5
+ export interface MarkedStyles {
6
+ em?: TextStyle;
7
+ strong?: TextStyle;
8
+ strikethrough?: TextStyle;
9
+ text?: TextStyle;
10
+ paragraph?: ViewStyle;
11
+ link?: TextStyle;
12
+ blockquote?: ViewStyle;
13
+ h1?: TextStyle;
14
+ h2?: TextStyle;
15
+ h3?: TextStyle;
16
+ h4?: TextStyle;
17
+ h5?: TextStyle;
18
+ h6?: TextStyle;
19
+ codespan?: TextStyle;
20
+ code?: ViewStyle;
21
+ codeText?: TextStyle;
22
+ hr?: ViewStyle;
23
+ list?: ViewStyle;
24
+ li?: TextStyle;
25
+ image?: ImageStyle;
26
+ table?: ViewStyle;
27
+ tableRow?: ViewStyle;
28
+ tableCell?: ViewStyle;
29
+ }
30
+
31
+ export interface UserTheme {
32
+ colors?: ColorsPropType;
33
+ spacing?: Record<SpacingKeysType, number>;
34
+ }
@@ -1,9 +1,9 @@
1
- import { Linking } from "react-native";
2
-
3
- export const onLinkPress = (url: string) => () => {
4
- Linking.openURL(url)
5
- .then(() => null)
6
- .catch((e) => {
7
- console.warn("URL can't be opened", e);
8
- });
9
- };
1
+ import { Linking } from "react-native";
2
+
3
+ export const onLinkPress = (url: string) => () => {
4
+ Linking.openURL(url)
5
+ .then(() => null)
6
+ .catch((e) => {
7
+ console.warn("URL can't be opened", e);
8
+ });
9
+ };
package/src/utils/svg.ts CHANGED
@@ -1,14 +1,14 @@
1
- import type { ElementNode } from "svg-parser";
2
- import { parse } from "svg-parser";
3
-
4
- export const getSvgDimensions = (svg: string) => {
5
- const parsed = parse(svg);
6
-
7
- const rootChild = parsed.children[0] as ElementNode;
8
-
9
- return {
10
- width: Number.parseInt(String(rootChild.properties?.width ?? "0"), 10),
11
- height: Number.parseInt(String(rootChild.properties?.height ?? "0"), 10),
12
- viewBox: String(rootChild.properties?.viewBox ?? ""),
13
- };
14
- };
1
+ import type { ElementNode } from "svg-parser";
2
+ import { parse } from "svg-parser";
3
+
4
+ export const getSvgDimensions = (svg: string) => {
5
+ const parsed = parse(svg);
6
+
7
+ const rootChild = parsed.children[0] as ElementNode;
8
+
9
+ return {
10
+ width: Number.parseInt(String(rootChild.properties?.width ?? "0"), 10),
11
+ height: Number.parseInt(String(rootChild.properties?.height ?? "0"), 10),
12
+ viewBox: String(rootChild.properties?.viewBox ?? ""),
13
+ };
14
+ };
@@ -1,29 +1,29 @@
1
- import type { TextStyle } from "react-native";
2
- import type { TableColAlignment } from "../lib/types";
3
-
4
- export const getTableWidthArr = (totalCols: number, windowWidth: number) => {
5
- if (totalCols < 1) {
6
- return [];
7
- }
8
-
9
- return Array(totalCols)
10
- .fill(0)
11
- .map(() => {
12
- return Math.floor(windowWidth * (1.3 / 3));
13
- });
14
- };
15
-
16
- export const getTableColAlignmentStyle = (
17
- alignment?: TableColAlignment,
18
- ): TextStyle => {
19
- switch (alignment) {
20
- case "center":
21
- return { textAlign: "center" };
22
- case "left":
23
- return { textAlign: "left" };
24
- case "right":
25
- return { textAlign: "right" };
26
- default:
27
- return { textAlign: "left" };
28
- }
29
- };
1
+ import type { TextStyle } from "react-native";
2
+ import type { TableColAlignment } from "../lib/types";
3
+
4
+ export const getTableWidthArr = (totalCols: number, windowWidth: number) => {
5
+ if (totalCols < 1) {
6
+ return [];
7
+ }
8
+
9
+ return Array(totalCols)
10
+ .fill(0)
11
+ .map(() => {
12
+ return Math.floor(windowWidth * (1.3 / 3));
13
+ });
14
+ };
15
+
16
+ export const getTableColAlignmentStyle = (
17
+ alignment?: TableColAlignment,
18
+ ): TextStyle => {
19
+ switch (alignment) {
20
+ case "center":
21
+ return { textAlign: "center" };
22
+ case "left":
23
+ return { textAlign: "left" };
24
+ case "right":
25
+ return { textAlign: "right" };
26
+ default:
27
+ return { textAlign: "left" };
28
+ }
29
+ };