react-native-nitro-markdown 0.1.2 → 0.2.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 (238) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +142 -84
  3. package/android/src/main/cpp/cpp-adapter.cpp +1 -1
  4. package/android/src/main/java/com/margelo/nitro/com/nitromarkdown/HybridMarkdownSession.kt +61 -0
  5. package/android/src/main/java/com/nitromarkdown/NitroMarkdownPackage.kt +5 -1
  6. package/cpp/bindings/HybridMarkdownParser.cpp +2 -2
  7. package/cpp/bindings/HybridMarkdownParser.hpp +2 -2
  8. package/cpp/bindings/HybridMarkdownSession.cpp +0 -0
  9. package/cpp/core/MarkdownSessionCore.cpp +0 -0
  10. package/ios/HybridMarkdownSession.swift +64 -0
  11. package/lib/commonjs/MarkdownContext.js +21 -0
  12. package/lib/commonjs/MarkdownContext.js.map +1 -0
  13. package/lib/commonjs/MarkdownSession.js +11 -0
  14. package/lib/commonjs/MarkdownSession.js.map +1 -0
  15. package/lib/commonjs/default-markdown-renderer.js +220 -0
  16. package/lib/commonjs/default-markdown-renderer.js.map +1 -0
  17. package/lib/commonjs/headless.js +50 -0
  18. package/lib/commonjs/headless.js.map +1 -0
  19. package/lib/commonjs/index.js +185 -13
  20. package/lib/commonjs/index.js.map +1 -1
  21. package/lib/commonjs/markdown-stream.js +32 -0
  22. package/lib/commonjs/markdown-stream.js.map +1 -0
  23. package/lib/commonjs/markdown.js +326 -0
  24. package/lib/commonjs/markdown.js.map +1 -0
  25. package/lib/commonjs/package.json +1 -0
  26. package/lib/commonjs/renderers/blockquote.js +36 -0
  27. package/lib/commonjs/renderers/blockquote.js.map +1 -0
  28. package/lib/commonjs/renderers/code.js +92 -0
  29. package/lib/commonjs/renderers/code.js.map +1 -0
  30. package/lib/commonjs/renderers/heading.js +62 -0
  31. package/lib/commonjs/renderers/heading.js.map +1 -0
  32. package/lib/commonjs/renderers/horizontal-rule.js +27 -0
  33. package/lib/commonjs/renderers/horizontal-rule.js.map +1 -0
  34. package/lib/commonjs/renderers/image.js +159 -0
  35. package/lib/commonjs/renderers/image.js.map +1 -0
  36. package/lib/commonjs/renderers/link.js +37 -0
  37. package/lib/commonjs/renderers/link.js.map +1 -0
  38. package/lib/commonjs/renderers/list.js +114 -0
  39. package/lib/commonjs/renderers/list.js.map +1 -0
  40. package/lib/commonjs/renderers/math.js +151 -0
  41. package/lib/commonjs/renderers/math.js.map +1 -0
  42. package/lib/commonjs/renderers/paragraph.js +44 -0
  43. package/lib/commonjs/renderers/paragraph.js.map +1 -0
  44. package/lib/commonjs/renderers/table.js +283 -0
  45. package/lib/commonjs/renderers/table.js.map +1 -0
  46. package/lib/commonjs/specs/MarkdownSession.nitro.js +6 -0
  47. package/lib/commonjs/specs/MarkdownSession.nitro.js.map +1 -0
  48. package/lib/commonjs/theme.js +58 -0
  49. package/lib/commonjs/theme.js.map +1 -0
  50. package/lib/commonjs/use-markdown-stream.js +71 -0
  51. package/lib/commonjs/use-markdown-stream.js.map +1 -0
  52. package/lib/module/MarkdownContext.js +17 -0
  53. package/lib/module/MarkdownContext.js.map +1 -0
  54. package/lib/module/MarkdownSession.js +7 -0
  55. package/lib/module/MarkdownSession.js.map +1 -0
  56. package/lib/module/default-markdown-renderer.js +215 -0
  57. package/lib/module/default-markdown-renderer.js.map +1 -0
  58. package/lib/module/headless.js +44 -0
  59. package/lib/module/headless.js.map +1 -0
  60. package/lib/module/index.js +36 -10
  61. package/lib/module/index.js.map +1 -1
  62. package/lib/module/markdown-stream.js +27 -0
  63. package/lib/module/markdown-stream.js.map +1 -0
  64. package/lib/module/markdown.js +321 -0
  65. package/lib/module/markdown.js.map +1 -0
  66. package/lib/module/package.json +1 -0
  67. package/lib/module/renderers/blockquote.js +31 -0
  68. package/lib/module/renderers/blockquote.js.map +1 -0
  69. package/lib/module/renderers/code.js +86 -0
  70. package/lib/module/renderers/code.js.map +1 -0
  71. package/lib/module/renderers/heading.js +57 -0
  72. package/lib/module/renderers/heading.js.map +1 -0
  73. package/lib/module/renderers/horizontal-rule.js +22 -0
  74. package/lib/module/renderers/horizontal-rule.js.map +1 -0
  75. package/lib/module/renderers/image.js +154 -0
  76. package/lib/module/renderers/image.js.map +1 -0
  77. package/lib/module/renderers/link.js +32 -0
  78. package/lib/module/renderers/link.js.map +1 -0
  79. package/lib/module/renderers/list.js +107 -0
  80. package/lib/module/renderers/list.js.map +1 -0
  81. package/lib/module/renderers/math.js +145 -0
  82. package/lib/module/renderers/math.js.map +1 -0
  83. package/lib/module/renderers/paragraph.js +39 -0
  84. package/lib/module/renderers/paragraph.js.map +1 -0
  85. package/lib/module/renderers/table.js +278 -0
  86. package/lib/module/renderers/table.js.map +1 -0
  87. package/lib/module/specs/MarkdownSession.nitro.js +4 -0
  88. package/lib/module/specs/MarkdownSession.nitro.js.map +1 -0
  89. package/lib/module/theme.js +54 -0
  90. package/lib/module/theme.js.map +1 -0
  91. package/lib/module/use-markdown-stream.js +66 -0
  92. package/lib/module/use-markdown-stream.js.map +1 -0
  93. package/lib/typescript/commonjs/Markdown.nitro.d.ts.map +1 -0
  94. package/lib/typescript/commonjs/MarkdownContext.d.ts +26 -0
  95. package/lib/typescript/commonjs/MarkdownContext.d.ts.map +1 -0
  96. package/lib/typescript/commonjs/MarkdownSession.d.ts +4 -0
  97. package/lib/typescript/commonjs/MarkdownSession.d.ts.map +1 -0
  98. package/lib/typescript/commonjs/default-markdown-renderer.d.ts +10 -0
  99. package/lib/typescript/commonjs/default-markdown-renderer.d.ts.map +1 -0
  100. package/lib/typescript/commonjs/headless.d.ts +50 -0
  101. package/lib/typescript/commonjs/headless.d.ts.map +1 -0
  102. package/lib/typescript/commonjs/index.d.ts +34 -0
  103. package/lib/typescript/commonjs/index.d.ts.map +1 -0
  104. package/lib/typescript/commonjs/markdown-stream.d.ts +15 -0
  105. package/lib/typescript/commonjs/markdown-stream.d.ts.map +1 -0
  106. package/lib/typescript/commonjs/markdown.d.ts +29 -0
  107. package/lib/typescript/commonjs/markdown.d.ts.map +1 -0
  108. package/lib/typescript/commonjs/package.json +1 -0
  109. package/lib/typescript/commonjs/renderers/blockquote.d.ts +9 -0
  110. package/lib/typescript/commonjs/renderers/blockquote.d.ts.map +1 -0
  111. package/lib/typescript/commonjs/renderers/code.d.ts +15 -0
  112. package/lib/typescript/commonjs/renderers/code.d.ts.map +1 -0
  113. package/lib/typescript/commonjs/renderers/heading.d.ts +10 -0
  114. package/lib/typescript/commonjs/renderers/heading.d.ts.map +1 -0
  115. package/lib/typescript/commonjs/renderers/horizontal-rule.d.ts +3 -0
  116. package/lib/typescript/commonjs/renderers/horizontal-rule.d.ts.map +1 -0
  117. package/lib/typescript/commonjs/renderers/image.d.ts +11 -0
  118. package/lib/typescript/commonjs/renderers/image.d.ts.map +1 -0
  119. package/lib/typescript/commonjs/renderers/link.d.ts +10 -0
  120. package/lib/typescript/commonjs/renderers/link.d.ts.map +1 -0
  121. package/lib/typescript/commonjs/renderers/list.d.ts +22 -0
  122. package/lib/typescript/commonjs/renderers/list.d.ts.map +1 -0
  123. package/lib/typescript/commonjs/renderers/math.d.ts +15 -0
  124. package/lib/typescript/commonjs/renderers/math.d.ts.map +1 -0
  125. package/lib/typescript/commonjs/renderers/paragraph.d.ts +15 -0
  126. package/lib/typescript/commonjs/renderers/paragraph.d.ts.map +1 -0
  127. package/lib/typescript/commonjs/renderers/table.d.ts +10 -0
  128. package/lib/typescript/commonjs/renderers/table.d.ts.map +1 -0
  129. package/lib/typescript/commonjs/specs/MarkdownSession.nitro.d.ts +12 -0
  130. package/lib/typescript/commonjs/specs/MarkdownSession.nitro.d.ts.map +1 -0
  131. package/lib/typescript/commonjs/theme.d.ts +52 -0
  132. package/lib/typescript/commonjs/theme.d.ts.map +1 -0
  133. package/lib/typescript/commonjs/use-markdown-stream.d.ts +22 -0
  134. package/lib/typescript/commonjs/use-markdown-stream.d.ts.map +1 -0
  135. package/lib/typescript/module/Markdown.nitro.d.ts +13 -0
  136. package/lib/typescript/module/Markdown.nitro.d.ts.map +1 -0
  137. package/lib/typescript/module/MarkdownContext.d.ts +26 -0
  138. package/lib/typescript/module/MarkdownContext.d.ts.map +1 -0
  139. package/lib/typescript/module/MarkdownSession.d.ts +4 -0
  140. package/lib/typescript/module/MarkdownSession.d.ts.map +1 -0
  141. package/lib/typescript/module/default-markdown-renderer.d.ts +10 -0
  142. package/lib/typescript/module/default-markdown-renderer.d.ts.map +1 -0
  143. package/lib/typescript/module/headless.d.ts +50 -0
  144. package/lib/typescript/module/headless.d.ts.map +1 -0
  145. package/lib/typescript/module/index.d.ts +34 -0
  146. package/lib/typescript/module/index.d.ts.map +1 -0
  147. package/lib/typescript/module/markdown-stream.d.ts +15 -0
  148. package/lib/typescript/module/markdown-stream.d.ts.map +1 -0
  149. package/lib/typescript/module/markdown.d.ts +29 -0
  150. package/lib/typescript/module/markdown.d.ts.map +1 -0
  151. package/lib/typescript/module/package.json +1 -0
  152. package/lib/typescript/module/renderers/blockquote.d.ts +9 -0
  153. package/lib/typescript/module/renderers/blockquote.d.ts.map +1 -0
  154. package/lib/typescript/module/renderers/code.d.ts +15 -0
  155. package/lib/typescript/module/renderers/code.d.ts.map +1 -0
  156. package/lib/typescript/module/renderers/heading.d.ts +10 -0
  157. package/lib/typescript/module/renderers/heading.d.ts.map +1 -0
  158. package/lib/typescript/module/renderers/horizontal-rule.d.ts +3 -0
  159. package/lib/typescript/module/renderers/horizontal-rule.d.ts.map +1 -0
  160. package/lib/typescript/module/renderers/image.d.ts +11 -0
  161. package/lib/typescript/module/renderers/image.d.ts.map +1 -0
  162. package/lib/typescript/module/renderers/link.d.ts +10 -0
  163. package/lib/typescript/module/renderers/link.d.ts.map +1 -0
  164. package/lib/typescript/module/renderers/list.d.ts +22 -0
  165. package/lib/typescript/module/renderers/list.d.ts.map +1 -0
  166. package/lib/typescript/module/renderers/math.d.ts +15 -0
  167. package/lib/typescript/module/renderers/math.d.ts.map +1 -0
  168. package/lib/typescript/module/renderers/paragraph.d.ts +15 -0
  169. package/lib/typescript/module/renderers/paragraph.d.ts.map +1 -0
  170. package/lib/typescript/module/renderers/table.d.ts +10 -0
  171. package/lib/typescript/module/renderers/table.d.ts.map +1 -0
  172. package/lib/typescript/module/specs/MarkdownSession.nitro.d.ts +12 -0
  173. package/lib/typescript/module/specs/MarkdownSession.nitro.d.ts.map +1 -0
  174. package/lib/typescript/module/theme.d.ts +52 -0
  175. package/lib/typescript/module/theme.d.ts.map +1 -0
  176. package/lib/typescript/module/use-markdown-stream.d.ts +22 -0
  177. package/lib/typescript/module/use-markdown-stream.d.ts.map +1 -0
  178. package/nitro.json +5 -2
  179. package/nitrogen/generated/android/NitroMarkdown+autolinking.cmake +3 -2
  180. package/nitrogen/generated/android/NitroMarkdown+autolinking.gradle +1 -1
  181. package/nitrogen/generated/android/NitroMarkdownOnLoad.cpp +17 -5
  182. package/nitrogen/generated/android/NitroMarkdownOnLoad.hpp +4 -4
  183. package/nitrogen/generated/android/c++/JFunc_void.hpp +75 -0
  184. package/nitrogen/generated/android/c++/JHybridMarkdownSessionSpec.cpp +91 -0
  185. package/nitrogen/generated/android/c++/JHybridMarkdownSessionSpec.hpp +70 -0
  186. package/nitrogen/generated/android/kotlin/com/margelo/nitro/com/nitromarkdown/Func_void.kt +80 -0
  187. package/nitrogen/generated/android/kotlin/com/margelo/nitro/com/nitromarkdown/HybridMarkdownSessionSpec.kt +78 -0
  188. package/nitrogen/generated/android/kotlin/com/margelo/nitro/com/nitromarkdown/NitroMarkdownOnLoad.kt +1 -1
  189. package/nitrogen/generated/ios/NitroMarkdown+autolinking.rb +2 -2
  190. package/nitrogen/generated/ios/NitroMarkdown-Swift-Cxx-Bridge.cpp +28 -4
  191. package/nitrogen/generated/ios/NitroMarkdown-Swift-Cxx-Bridge.hpp +72 -6
  192. package/nitrogen/generated/ios/NitroMarkdown-Swift-Cxx-Umbrella.hpp +11 -4
  193. package/nitrogen/generated/ios/NitroMarkdownAutolinking.mm +11 -3
  194. package/nitrogen/generated/ios/NitroMarkdownAutolinking.swift +16 -3
  195. package/nitrogen/generated/ios/c++/HybridMarkdownSessionSpecSwift.cpp +11 -0
  196. package/nitrogen/generated/ios/c++/HybridMarkdownSessionSpecSwift.hpp +108 -0
  197. package/nitrogen/generated/ios/swift/Func_void.swift +47 -0
  198. package/nitrogen/generated/ios/swift/HybridMarkdownSessionSpec.swift +59 -0
  199. package/nitrogen/generated/ios/swift/HybridMarkdownSessionSpec_cxx.swift +190 -0
  200. package/nitrogen/generated/shared/c++/HybridMarkdownParserSpec.cpp +3 -3
  201. package/nitrogen/generated/shared/c++/HybridMarkdownParserSpec.hpp +4 -4
  202. package/nitrogen/generated/shared/c++/HybridMarkdownSessionSpec.cpp +26 -0
  203. package/nitrogen/generated/shared/c++/HybridMarkdownSessionSpec.hpp +67 -0
  204. package/nitrogen/generated/shared/c++/ParserOptions.hpp +22 -14
  205. package/package.json +45 -7
  206. package/react-native-nitro-markdown.podspec +5 -5
  207. package/src/MarkdownContext.ts +41 -0
  208. package/src/MarkdownSession.ts +8 -0
  209. package/src/default-markdown-renderer.tsx +266 -0
  210. package/src/headless.ts +106 -0
  211. package/src/index.ts +41 -59
  212. package/src/markdown-stream.tsx +32 -0
  213. package/src/markdown.tsx +415 -0
  214. package/src/renderers/blockquote.tsx +31 -0
  215. package/src/renderers/code.tsx +88 -0
  216. package/src/renderers/heading.tsx +66 -0
  217. package/src/renderers/horizontal-rule.tsx +20 -0
  218. package/src/renderers/image.tsx +160 -0
  219. package/src/renderers/link.tsx +38 -0
  220. package/src/renderers/list.tsx +125 -0
  221. package/src/renderers/math.tsx +164 -0
  222. package/src/renderers/paragraph.tsx +53 -0
  223. package/src/renderers/table.tsx +345 -0
  224. package/src/specs/MarkdownSession.nitro.ts +16 -0
  225. package/src/theme.ts +52 -0
  226. package/src/use-markdown-stream.ts +83 -0
  227. package/ios/NitroMarkdown-Bridging-Header.h +0 -14
  228. package/lib/commonjs/MarkdownJS.reference.js +0 -114
  229. package/lib/commonjs/MarkdownJS.reference.js.map +0 -1
  230. package/lib/module/MarkdownJS.reference.js +0 -107
  231. package/lib/module/MarkdownJS.reference.js.map +0 -1
  232. package/lib/typescript/Markdown.nitro.d.ts.map +0 -1
  233. package/lib/typescript/MarkdownJS.reference.d.ts +0 -33
  234. package/lib/typescript/MarkdownJS.reference.d.ts.map +0 -1
  235. package/lib/typescript/index.d.ts +0 -22
  236. package/lib/typescript/index.d.ts.map +0 -1
  237. package/src/MarkdownJS.reference.ts +0 -122
  238. /package/lib/typescript/{Markdown.nitro.d.ts → commonjs/Markdown.nitro.d.ts} +0 -0
@@ -0,0 +1,283 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.TableRenderer = void 0;
7
+ var _react = require("react");
8
+ var _reactNative = require("react-native");
9
+ var _MarkdownContext = require("../MarkdownContext.js");
10
+ var _jsxRuntime = require("react/jsx-runtime");
11
+ const extractTableData = node => {
12
+ const headers = [];
13
+ const rows = [];
14
+ const alignments = [];
15
+ const head = node.children?.find(c => c.type === "table_head");
16
+ const body = node.children?.find(c => c.type === "table_body");
17
+
18
+ // Extract Headers
19
+ head?.children?.forEach(row => {
20
+ if (row.type === "table_row") {
21
+ row.children?.forEach(cell => {
22
+ if (cell.type === "table_cell") {
23
+ headers.push(cell);
24
+ alignments.push(cell.align);
25
+ }
26
+ });
27
+ }
28
+ });
29
+
30
+ // Extract Body Rows
31
+ body?.children?.forEach(row => {
32
+ if (row.type === "table_row") {
33
+ const rowCells = [];
34
+ row.children?.forEach(cell => {
35
+ if (cell.type === "table_cell") {
36
+ rowCells.push(cell);
37
+ }
38
+ });
39
+ if (rowCells.length > 0) rows.push(rowCells);
40
+ }
41
+ });
42
+ return {
43
+ headers,
44
+ rows,
45
+ alignments
46
+ };
47
+ };
48
+ const TableRenderer = ({
49
+ node,
50
+ Renderer
51
+ }) => {
52
+ const {
53
+ theme
54
+ } = (0, _MarkdownContext.useMarkdownContext)();
55
+ const {
56
+ headers,
57
+ rows,
58
+ alignments
59
+ } = (0, _react.useMemo)(() => extractTableData(node), [node]);
60
+ const columnCount = headers.length;
61
+ const styles = (0, _react.useMemo)(() => createTableStyles(theme), [theme]);
62
+ const [columnWidths, setColumnWidths] = (0, _react.useState)([]);
63
+ const measuredWidths = (0, _react.useRef)(new Map());
64
+ const hasAppliedWidths = (0, _react.useRef)(false);
65
+ const calculateAndApplyWidths = (0, _react.useCallback)(() => {
66
+ if (columnCount === 0) return;
67
+ const finalWidths = new Array(columnCount).fill(0);
68
+ for (let col = 0; col < columnCount; col++) {
69
+ let maxWidth = measuredWidths.current.get(`h-${col}`) || 0;
70
+ for (let row = 0; row < rows.length; row++) {
71
+ const cellWidth = measuredWidths.current.get(`c-${row}-${col}`) || 0;
72
+ if (cellWidth > maxWidth) maxWidth = cellWidth;
73
+ }
74
+ // Apply padding and min-width
75
+ finalWidths[col] = Math.max(maxWidth + 32, 100);
76
+ }
77
+ setColumnWidths(finalWidths);
78
+ hasAppliedWidths.current = true;
79
+ }, [columnCount, rows.length]);
80
+ (0, _react.useEffect)(() => {
81
+ if (columnCount === 0) return;
82
+ const timer = setTimeout(() => {
83
+ if (!hasAppliedWidths.current) {
84
+ calculateAndApplyWidths();
85
+ }
86
+ }, 400);
87
+ return () => clearTimeout(timer);
88
+ }, [columnCount, rows.length, calculateAndApplyWidths]);
89
+ const onLayout = (key, width) => {
90
+ if (hasAppliedWidths.current) return;
91
+ measuredWidths.current.set(key, width);
92
+ const expectedCount = columnCount + rows.length * columnCount;
93
+ if (measuredWidths.current.size >= expectedCount) {
94
+ calculateAndApplyWidths();
95
+ }
96
+ };
97
+ const getAlignStyle = index => {
98
+ const align = alignments[index];
99
+ if (align === "center") return {
100
+ alignItems: "center",
101
+ textAlign: "center"
102
+ };
103
+ if (align === "right") return {
104
+ alignItems: "flex-end",
105
+ textAlign: "right"
106
+ };
107
+ return {
108
+ alignItems: "flex-start",
109
+ textAlign: "left"
110
+ };
111
+ };
112
+ if (columnCount === 0) return null;
113
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
114
+ style: styles.container,
115
+ children: [!hasAppliedWidths.current && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
116
+ style: styles.measurementWrapper,
117
+ pointerEvents: "none",
118
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
119
+ style: styles.row,
120
+ children: headers.map((cell, i) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
121
+ onLayout: e => onLayout(`h-${i}`, e.nativeEvent.layout.width),
122
+ style: styles.measuringCell,
123
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(CellContent, {
124
+ node: cell,
125
+ Renderer: Renderer,
126
+ styles: styles
127
+ })
128
+ }, `m-h-${i}`))
129
+ }), rows.map((row, ri) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
130
+ style: styles.row,
131
+ children: row.map((cell, ci) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
132
+ onLayout: e => onLayout(`c-${ri}-${ci}`, e.nativeEvent.layout.width),
133
+ style: styles.measuringCell,
134
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(CellContent, {
135
+ node: cell,
136
+ Renderer: Renderer,
137
+ styles: styles
138
+ })
139
+ }, `m-c-${ri}-${ci}`))
140
+ }, `m-r-${ri}`))]
141
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.ScrollView, {
142
+ horizontal: true,
143
+ showsHorizontalScrollIndicator: true,
144
+ bounces: false,
145
+ style: styles.tableScroll,
146
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
147
+ style: styles.table,
148
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
149
+ style: styles.headerRow,
150
+ children: headers.map((cell, i) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
151
+ style: [styles.headerCell, {
152
+ width: columnWidths[i] || 120
153
+ }, getAlignStyle(i), i === columnCount - 1 && styles.lastCell],
154
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(CellContent, {
155
+ node: cell,
156
+ Renderer: Renderer,
157
+ styles: styles,
158
+ textStyle: styles.headerText
159
+ })
160
+ }, `h-${i}`))
161
+ }), rows.map((row, ri) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
162
+ style: [styles.bodyRow, ri === rows.length - 1 && styles.lastRow, ri % 2 === 1 && styles.oddRow],
163
+ children: row.map((cell, ci) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
164
+ style: [styles.bodyCell, {
165
+ width: columnWidths[ci] || 120
166
+ }, getAlignStyle(ci), ci === columnCount - 1 && styles.lastCell],
167
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(CellContent, {
168
+ node: cell,
169
+ Renderer: Renderer,
170
+ styles: styles,
171
+ textStyle: styles.cellText
172
+ })
173
+ }, `c-${ri}-${ci}`))
174
+ }, `r-${ri}`))]
175
+ })
176
+ })]
177
+ });
178
+ };
179
+ exports.TableRenderer = TableRenderer;
180
+ const CellContent = ({
181
+ node,
182
+ Renderer,
183
+ styles,
184
+ textStyle
185
+ }) => {
186
+ if (!node.children || node.children.length === 0) {
187
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
188
+ style: textStyle,
189
+ children: node.content ?? ""
190
+ });
191
+ }
192
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
193
+ style: styles.cellContentWrapper,
194
+ children: node.children.map((child, idx) => /*#__PURE__*/(0, _jsxRuntime.jsx)(Renderer, {
195
+ node: child,
196
+ depth: 0,
197
+ inListItem: false,
198
+ parentIsText: false
199
+ }, idx))
200
+ });
201
+ };
202
+ const createTableStyles = theme => {
203
+ const colors = theme?.colors || {};
204
+ return _reactNative.StyleSheet.create({
205
+ container: {
206
+ marginVertical: 12
207
+ },
208
+ measurementWrapper: {
209
+ position: "absolute",
210
+ top: 0,
211
+ left: 0,
212
+ opacity: 0,
213
+ zIndex: -1
214
+ },
215
+ measuringCell: {
216
+ paddingHorizontal: 16,
217
+ paddingVertical: 12,
218
+ alignSelf: "flex-start"
219
+ },
220
+ tableScroll: {
221
+ borderRadius: 12,
222
+ borderWidth: 1,
223
+ borderColor: colors.tableBorder || "#374151"
224
+ },
225
+ table: {
226
+ backgroundColor: colors.surface || "#111827"
227
+ },
228
+ row: {
229
+ flexDirection: "row"
230
+ },
231
+ headerRow: {
232
+ flexDirection: "row",
233
+ backgroundColor: colors.tableHeader || "#1f2937",
234
+ borderBottomWidth: 2,
235
+ borderBottomColor: colors.tableBorder || "#374151"
236
+ },
237
+ bodyRow: {
238
+ flexDirection: "row",
239
+ borderBottomWidth: 1,
240
+ borderBottomColor: colors.tableBorder || "#374151"
241
+ },
242
+ oddRow: {
243
+ backgroundColor: colors.tableRowOdd || "rgba(255,255,255,0.02)"
244
+ },
245
+ lastRow: {
246
+ borderBottomWidth: 0
247
+ },
248
+ headerCell: {
249
+ paddingVertical: 14,
250
+ paddingHorizontal: 16,
251
+ borderRightWidth: 1,
252
+ borderRightColor: colors.tableBorder || "#374151"
253
+ },
254
+ bodyCell: {
255
+ paddingVertical: 12,
256
+ paddingHorizontal: 16,
257
+ borderRightWidth: 1,
258
+ borderRightColor: colors.tableBorder || "#374151",
259
+ justifyContent: "center"
260
+ },
261
+ lastCell: {
262
+ borderRightWidth: 0
263
+ },
264
+ headerText: {
265
+ color: colors.tableHeaderText || "#9ca3af",
266
+ fontSize: 12,
267
+ fontWeight: "700",
268
+ textTransform: "uppercase",
269
+ letterSpacing: 1
270
+ },
271
+ cellText: {
272
+ color: colors.text || "#e5e7eb",
273
+ fontSize: 14,
274
+ lineHeight: 20
275
+ },
276
+ cellContentWrapper: {
277
+ flexDirection: "row",
278
+ flexWrap: "wrap",
279
+ alignItems: "center"
280
+ }
281
+ });
282
+ };
283
+ //# sourceMappingURL=table.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_react","require","_reactNative","_MarkdownContext","_jsxRuntime","extractTableData","node","headers","rows","alignments","head","children","find","c","type","body","forEach","row","cell","push","align","rowCells","length","TableRenderer","Renderer","theme","useMarkdownContext","useMemo","columnCount","styles","createTableStyles","columnWidths","setColumnWidths","useState","measuredWidths","useRef","Map","hasAppliedWidths","calculateAndApplyWidths","useCallback","finalWidths","Array","fill","col","maxWidth","current","get","cellWidth","Math","max","useEffect","timer","setTimeout","clearTimeout","onLayout","key","width","set","expectedCount","size","getAlignStyle","index","alignItems","textAlign","jsxs","View","style","container","measurementWrapper","pointerEvents","jsx","map","i","e","nativeEvent","layout","measuringCell","CellContent","ri","ci","ScrollView","horizontal","showsHorizontalScrollIndicator","bounces","tableScroll","table","headerRow","headerCell","lastCell","textStyle","headerText","bodyRow","lastRow","oddRow","bodyCell","cellText","exports","Text","content","cellContentWrapper","child","idx","depth","inListItem","parentIsText","colors","StyleSheet","create","marginVertical","position","top","left","opacity","zIndex","paddingHorizontal","paddingVertical","alignSelf","borderRadius","borderWidth","borderColor","tableBorder","backgroundColor","surface","flexDirection","tableHeader","borderBottomWidth","borderBottomColor","tableRowOdd","borderRightWidth","borderRightColor","justifyContent","color","tableHeaderText","fontSize","fontWeight","textTransform","letterSpacing","text","lineHeight","flexWrap"],"sourceRoot":"../../../src","sources":["renderers/table.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AASA,IAAAC,YAAA,GAAAD,OAAA;AAUA,IAAAE,gBAAA,GAAAF,OAAA;AAAgF,IAAAG,WAAA,GAAAH,OAAA;AAShF,MAAMI,gBAAgB,GAAIC,IAAkB,IAAgB;EAC1D,MAAMC,OAAuB,GAAG,EAAE;EAClC,MAAMC,IAAsB,GAAG,EAAE;EACjC,MAAMC,UAAkC,GAAG,EAAE;EAE7C,MAAMC,IAAI,GAAGJ,IAAI,CAACK,QAAQ,EAAEC,IAAI,CAAEC,CAAC,IAAKA,CAAC,CA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E1B,MAAM,CAAC2B,eAAe,IAAI,SAAS;MAC1CC,QAAQ,EAAE,EAAE;MACZC,UAAU,EAAE,KAAK;MACjBC,aAAa,EAAE,WAAW;MAC1BC,aAAa,EAAE;IACjB,CAAC;IACDzC,QAAQ,EAAE;MACRoC,KAAK,EAAE1B,MAAM,CAACgC,IAAI,IAAI,SAAS;MAC/BJ,QAAQ,EAAE,EAAE;MACZK,UAAU,EAAE;IACd,CAAC;IACDvC,kBAAkB,EAAE;MAClBwB,aAAa,EAAE,KAAK;MACpBgB,QAAQ,EAAE,MAAM;MAChB7E,UAAU,EAAE;IACd;EACF,CAAC,CAAC;AACJ,CAAC","ignoreList":[]}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ //# sourceMappingURL=MarkdownSession.nitro.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../../src","sources":["specs/MarkdownSession.nitro.ts"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.defaultMarkdownTheme = void 0;
7
+ /**
8
+ * Default theme configuration for the Markdown components.
9
+ * Optimized for a modern dark mode aesthetic.
10
+ */
11
+ const defaultMarkdownTheme = exports.defaultMarkdownTheme = {
12
+ /** Colors used throughout the markdown renderer */
13
+ colors: {
14
+ text: "#e0e0e0",
15
+ textMuted: "#888",
16
+ heading: "#f0f0f0",
17
+ link: "#60a5fa",
18
+ code: "#fbbf24",
19
+ codeBackground: "#1a1a2e",
20
+ blockquote: "#3b82f6",
21
+ border: "#252525",
22
+ surface: "#151515",
23
+ surfaceLight: "#1a1a1a",
24
+ accent: "#4ade80",
25
+ tableBorder: "#334155",
26
+ tableHeader: "#0f172a",
27
+ tableHeaderText: "#94a3b8",
28
+ tableRowEven: "#0f172a",
29
+ tableRowOdd: "#1e293b"
30
+ },
31
+ /** Standard spacing increments */
32
+ spacing: {
33
+ xs: 4,
34
+ s: 8,
35
+ m: 12,
36
+ l: 16,
37
+ xl: 24
38
+ },
39
+ /** Font sizes for different text elements */
40
+ fontSizes: {
41
+ xs: 12,
42
+ s: 14,
43
+ m: 16,
44
+ l: 18,
45
+ xl: 22,
46
+ h1: 32,
47
+ h2: 26,
48
+ h3: 22,
49
+ h4: 18,
50
+ h5: 16,
51
+ h6: 14
52
+ }
53
+ };
54
+
55
+ /**
56
+ * Type definition for the Markdown theme.
57
+ */
58
+ //# sourceMappingURL=theme.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["defaultMarkdownTheme","exports","colors","text","textMuted","heading","link","code","codeBackground","blockquote","border","surface","surfaceLight","accent","tableBorder","tableHeader","tableHeaderText","tableRowEven","tableRowOdd","spacing","xs","s","m","l","xl","fontSizes","h1","h2","h3","h4","h5","h6"],"sourceRoot":"../../src","sources":["theme.ts"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACO,MAAMA,oBAAoB,GAAAC,OAAA,CAAAD,oBAAA,GAAG;EAClC;EACAE,MAAM,EAAE;IACNC,IAAI,EAAE,SAAS;IACfC,SAAS,EAAE,MAAM;IACjBC,OAAO,EAAE,SAAS;IAClBC,IAAI,EAAE,SAAS;IACfC,IAAI,EAAE,SAAS;IACfC,cAAc,EAAE,SAAS;IACzBC,UAAU,EAAE,SAAS;IACrBC,MAAM,EAAE,SAAS;IACjBC,OAAO,EAAE,SAAS;IAClBC,YAAY,EAAE,SAAS;IACvBC,MAAM,EAAE,SAAS;IACjBC,WAAW,EAAE,SAAS;IACtBC,WAAW,EAAE,SAAS;IACtBC,eAAe,EAAE,SAAS;IAC1BC,YAAY,EAAE,SAAS;IACvBC,WAAW,EAAE;EACf,CAAC;EACD;EACAC,OAAO,EAAE;IACPC,EAAE,EAAE,CAAC;IACLC,CAAC,EAAE,CAAC;IACJC,CAAC,EAAE,EAAE;IACLC,CAAC,EAAE,EAAE;IACLC,EAAE,EAAE;EACN,CAAC;EACD;EACAC,SAAS,EAAE;IACTL,EAAE,EAAE,EAAE;IACNC,CAAC,EAAE,EAAE;IACLC,CAAC,EAAE,EAAE;IACLC,CAAC,EAAE,EAAE;IACLC,EAAE,EAAE,EAAE;IACNE,EAAE,EAAE,EAAE;IACNC,EAAE,EAAE,EAAE;IACNC,EAAE,EAAE,EAAE;IACNC,EAAE,EAAE,EAAE;IACNC,EAAE,EAAE,EAAE;IACNC,EAAE,EAAE;EACN;AACF,CAAC;;AAED;AACA;AACA","ignoreList":[]}
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useMarkdownSession = useMarkdownSession;
7
+ exports.useStream = useStream;
8
+ var _react = require("react");
9
+ var _MarkdownSession = require("./MarkdownSession.js");
10
+ function useMarkdownSession() {
11
+ const sessionRef = (0, _react.useRef)(null);
12
+ if (sessionRef.current === null) {
13
+ sessionRef.current = (0, _MarkdownSession.createMarkdownSession)();
14
+ }
15
+ const [isStreaming, setIsStreaming] = (0, _react.useState)(false);
16
+ (0, _react.useEffect)(() => {
17
+ const session = sessionRef.current;
18
+ return () => {
19
+ session.clear();
20
+ };
21
+ }, []);
22
+ const stop = (0, _react.useCallback)(() => {
23
+ setIsStreaming(false);
24
+ }, []);
25
+ const clear = (0, _react.useCallback)(() => {
26
+ stop();
27
+ sessionRef.current.clear();
28
+ sessionRef.current.highlightPosition = 0;
29
+ }, [stop]);
30
+ const setHighlight = (0, _react.useCallback)(position => {
31
+ sessionRef.current.highlightPosition = position;
32
+ }, []);
33
+ const getSession = (0, _react.useCallback)(() => sessionRef.current, []);
34
+ return {
35
+ getSession,
36
+ isStreaming,
37
+ setIsStreaming,
38
+ stop,
39
+ clear,
40
+ setHighlight
41
+ };
42
+ }
43
+ function useStream(timestamps) {
44
+ const engine = useMarkdownSession();
45
+ const [isPlaying, setIsPlaying] = (0, _react.useState)(false);
46
+ const sortedKeys = (0, _react.useRef)([]);
47
+ (0, _react.useEffect)(() => {
48
+ if (timestamps) {
49
+ sortedKeys.current = Object.keys(timestamps).map(Number).sort((a, b) => a - b);
50
+ }
51
+ }, [timestamps]);
52
+ const sync = (0, _react.useCallback)(currentTimeMs => {
53
+ if (!timestamps) return;
54
+ let wordIdx = 0;
55
+ for (const idx of sortedKeys.current) {
56
+ if (currentTimeMs >= timestamps[idx]) {
57
+ wordIdx = idx + 1;
58
+ } else {
59
+ break;
60
+ }
61
+ }
62
+ engine.setHighlight(wordIdx);
63
+ }, [timestamps, engine]);
64
+ return {
65
+ ...engine,
66
+ isPlaying,
67
+ setIsPlaying,
68
+ sync
69
+ };
70
+ }
71
+ //# sourceMappingURL=use-markdown-stream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_react","require","_MarkdownSession","useMarkdownSession","sessionRef","useRef","current","createMarkdownSession","isStreaming","setIsStreaming","useState","useEffect","session","clear","stop","useCallback","highlightPosition","setHighlight","position","getSession","useStream","timestamps","engine","isPlaying","setIsPlaying","sortedKeys","Object","keys","map","Number","sort","a","b","sync","currentTimeMs","wordIdx","idx"],"sourceRoot":"../../src","sources":["use-markdown-stream.ts"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,gBAAA,GAAAD,OAAA;AAIO,SAASE,kBAAkBA,CAAA,EAAG;EACnC,MAAMC,UAAU,GAAG,IAAAC,aAAM,EAAyB,IAAI,CAAC;EACvD,IAAID,UAAU,CAACE,OAAO,KAAK,IAAI,EAAE;IAC/BF,UAAU,CAACE,OAAO,GAAG,IAAAC,sCAAqB,EAAC,CAAC;EAC9C;EAEA,MAAM,CAACC,WAAW,EAAEC,cAAc,CAAC,GAAG,IAAAC,eAAQ,EAAC,KAAK,CAAC;EAErD,IAAAC,gBAAS,EAAC,MAAM;IACd,MAAMC,OAAO,GAAGR,UAAU,CAACE,OAAQ;IACnC,OAAO,MAAM;MACXM,OAAO,CAACC,KAAK,CAAC,CAAC;I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Y,IAAI,GAAG,IAAAlB,kBAAW,EACrBmB,aAAqB,IAAK;IACzB,IAAI,CAACb,UAAU,EAAE;IAEjB,IAAIc,OAAO,GAAG,CAAC;IACf,KAAK,MAAMC,GAAG,IAAIX,UAAU,CAACnB,OAAO,EAAE;MACpC,IAAI4B,aAAa,IAAIb,UAAU,CAACe,GAAG,CAAC,EAAE;QACpCD,OAAO,GAAGC,GAAG,GAAG,CAAC;MACnB,CAAC,MAAM;QACL;MACF;IACF;IACAd,MAAM,CAACL,YAAY,CAACkB,OAAO,CAAC;EAC9B,CAAC,EACD,CAACd,UAAU,EAAEC,MAAM,CACrB,CAAC;EAED,OAAO;IACL,GAAGA,MAAM;IACTC,SAAS;IACTC,YAAY;IACZS;EACF,CAAC;AACH","ignoreList":[]}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ import { createContext, useContext } from "react";
4
+ import { defaultMarkdownTheme } from "./theme.js";
5
+
6
+ /**
7
+ * Object mapping node types to custom renderers.
8
+ */
9
+
10
+ // Context for custom renderers and theme
11
+
12
+ export const MarkdownContext = /*#__PURE__*/createContext({
13
+ renderers: {},
14
+ theme: defaultMarkdownTheme
15
+ });
16
+ export const useMarkdownContext = () => useContext(MarkdownContext);
17
+ //# sourceMappingURL=MarkdownContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createContext","useContext","defaultMarkdownTheme","MarkdownContext","renderers","theme","useMarkdownContext"],"sourceRoot":"../../src","sources":["MarkdownContext.ts"],"mappings":";;AAAA,SAASA,aAAa,EAAEC,UAAU,QAA4C,OAAO;AACrF,SAASC,oBAAoB,QAA4B,YAAS;;AAoBlE;AACA;AACA;;AAKA;;AAMA,OAAO,MAAMC,eAAe,gBAAGH,aAAa,CAAuB;EACjEI,SAAS,EAAE,CAAC,CAAC;EACbC,KAAK,EAAEH;AACT,CAAC,CAAC;AAEF,OAAO,MAAMI,kBAAkB,GAAGA,CAAA,KAAML,UAAU,CAACE,eAAe,CAAC","ignoreList":[]}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+
3
+ import { NitroModules } from "react-native-nitro-modules";
4
+ export function createMarkdownSession() {
5
+ return NitroModules.createHybridObject("MarkdownSession");
6
+ }
7
+ //# sourceMappingURL=MarkdownSession.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["NitroModules","createMarkdownSession","createHybridObject"],"sourceRoot":"../../src","sources":["MarkdownSession.ts"],"mappings":";;AAAA,SAASA,YAAY,QAAQ,4BAA4B;AAKzD,OAAO,SAASC,qBAAqBA,CAAA,EAAoB;EACvD,OAAOD,YAAY,CAACE,kBAAkB,CAAkB,iBAAiB,CAAC;AAC5E","ignoreList":[]}