react-native-marcus 0.1.0

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 (304) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +227 -0
  3. package/RNMarcus.podspec +78 -0
  4. package/android/build.gradle +220 -0
  5. package/android/proguard-rules.pro +1 -0
  6. package/android/src/main/AndroidManifest.xml +3 -0
  7. package/android/src/main/AndroidManifestNew.xml +2 -0
  8. package/android/src/main/cpp/CMakeLists.txt +41 -0
  9. package/android/src/main/cpp/MarkdownParser.cpp +49 -0
  10. package/android/src/main/cpp/MarkdownParser.h +56 -0
  11. package/android/src/main/cpp/OnLoad.cpp +17 -0
  12. package/android/src/main/java/app/getbullet/marcus/MarcusModule.kt +28 -0
  13. package/android/src/main/java/app/getbullet/marcus/MarcusPackage.kt +31 -0
  14. package/android/src/main/java/app/getbullet/marcus/MarcusTextInputDecoratorView.kt +63 -0
  15. package/android/src/main/java/app/getbullet/marcus/MarcusTextInputDecoratorViewManager.kt +32 -0
  16. package/android/src/main/java/app/getbullet/marcus/MarcusTextInputDecoratorViewManagerSpec.kt +21 -0
  17. package/android/src/main/java/app/getbullet/marcus/MarkdownFormatter.kt +333 -0
  18. package/android/src/main/java/app/getbullet/marcus/MarkdownParseResult.kt +12 -0
  19. package/android/src/main/java/app/getbullet/marcus/MarkdownParser.kt +89 -0
  20. package/android/src/main/java/app/getbullet/marcus/MarkdownRange.kt +11 -0
  21. package/android/src/main/java/app/getbullet/marcus/MarkdownStyle.kt +81 -0
  22. package/android/src/main/java/app/getbullet/marcus/MarkdownTextWatcher.kt +17 -0
  23. package/android/src/main/java/app/getbullet/marcus/MarkdownUtils.kt +84 -0
  24. package/android/src/main/java/app/getbullet/marcus/ReactLineHeight.java +29 -0
  25. package/android/src/main/java/app/getbullet/marcus/spans/MarkdownBackgroundColorSpan.kt +6 -0
  26. package/android/src/main/java/app/getbullet/marcus/spans/MarkdownBackgroundSpan.kt +105 -0
  27. package/android/src/main/java/app/getbullet/marcus/spans/MarkdownBlockIndentSpan.kt +67 -0
  28. package/android/src/main/java/app/getbullet/marcus/spans/MarkdownBoldSpan.kt +6 -0
  29. package/android/src/main/java/app/getbullet/marcus/spans/MarkdownFontFamilySpan.kt +28 -0
  30. package/android/src/main/java/app/getbullet/marcus/spans/MarkdownFontSizeSpan.kt +7 -0
  31. package/android/src/main/java/app/getbullet/marcus/spans/MarkdownForegroundColorSpan.kt +6 -0
  32. package/android/src/main/java/app/getbullet/marcus/spans/MarkdownGapSpan.kt +57 -0
  33. package/android/src/main/java/app/getbullet/marcus/spans/MarkdownItalicSpan.kt +6 -0
  34. package/android/src/main/java/app/getbullet/marcus/spans/MarkdownLineHeightSpan.kt +21 -0
  35. package/android/src/main/java/app/getbullet/marcus/spans/MarkdownSpan.kt +7 -0
  36. package/android/src/main/java/app/getbullet/marcus/spans/MarkdownStrikethroughSpan.kt +5 -0
  37. package/android/src/main/java/app/getbullet/marcus/spans/MarkdownUnderlineSpan.kt +5 -0
  38. package/android/src/main/new_arch/CMakeLists.txt +70 -0
  39. package/android/src/main/new_arch/RNMarcusSpec.cpp +43 -0
  40. package/android/src/main/new_arch/RNMarcusSpec.h +36 -0
  41. package/android/src/main/new_arch/react/renderer/components/RNMarcusSpec/MarcusTextInputDecoratorShadowNode.cpp +218 -0
  42. package/android/src/main/new_arch/react/renderer/components/RNMarcusSpec/MarcusTextInputDecoratorShadowNode.h +54 -0
  43. package/android/src/reactNativeVersionPatch/CustomMountingManager/81/app/getbullet/marcus/CustomFabricUIManager.java +156 -0
  44. package/android/src/reactNativeVersionPatch/CustomMountingManager/latest/app/getbullet/marcus/CustomFabricUIManager.java +130 -0
  45. package/android/src/test/java/app/getbullet/marcus/MarkdownFormatterTest.kt +205 -0
  46. package/android/src/test/java/app/getbullet/marcus/RenderModel.kt +78 -0
  47. package/android/src/test/resources/render-model.txt +583 -0
  48. package/apple/MarcusModule.h +8 -0
  49. package/apple/MarcusModule.mm +26 -0
  50. package/apple/MarcusRange.h +15 -0
  51. package/apple/MarcusRange.mm +15 -0
  52. package/apple/MarcusTextInputDecoratorComponentView.h +12 -0
  53. package/apple/MarcusTextInputDecoratorComponentView.mm +121 -0
  54. package/apple/MarcusTextInputDecoratorShadowNode.cpp +251 -0
  55. package/apple/MarcusTextInputDecoratorShadowNode.h +65 -0
  56. package/apple/MarcusTextInputDecoratorShadowNode.mm +204 -0
  57. package/apple/MarcusTextInputDecoratorViewManager.h +8 -0
  58. package/apple/MarcusTextInputDecoratorViewManager.mm +11 -0
  59. package/apple/MarkdownAdaptiveImageGlyph.swift +44 -0
  60. package/apple/MarkdownAttributes.h +31 -0
  61. package/apple/MarkdownAttributes.m +9 -0
  62. package/apple/MarkdownBackedTextInputDelegate.swift +117 -0
  63. package/apple/MarkdownDecorator.swift +316 -0
  64. package/apple/MarkdownFonts.swift +21 -0
  65. package/apple/MarkdownFormatter+React.swift +51 -0
  66. package/apple/MarkdownFormatter.swift +509 -0
  67. package/apple/MarkdownLog.h +10 -0
  68. package/apple/MarkdownLog.mm +6 -0
  69. package/apple/MarkdownParser.swift +200 -0
  70. package/apple/MarkdownSwiftInterop.h +23 -0
  71. package/apple/MarkdownTextBackground.swift +17 -0
  72. package/apple/MarkdownTextFieldObserver.swift +90 -0
  73. package/apple/MarkdownTextLayoutFragment.swift +205 -0
  74. package/apple/MarkdownTextLayoutManagerDelegate.swift +84 -0
  75. package/apple/MarkdownTextStorageDelegate.swift +32 -0
  76. package/apple/MarkdownTextViewObserver.swift +30 -0
  77. package/apple/RCTMarcusStyle+Codegen.h +18 -0
  78. package/apple/RCTMarcusStyle+Codegen.mm +64 -0
  79. package/apple/RCTMarcusStyle.h +41 -0
  80. package/apple/RCTMarcusStyle.m +5 -0
  81. package/apple/RCTMarcusUtils.h +26 -0
  82. package/apple/RCTMarcusUtils.mm +26 -0
  83. package/apple/RCTTextInput+AdaptiveImageGlyph.h +16 -0
  84. package/apple/RCTTextInput+AdaptiveImageGlyph.mm +79 -0
  85. package/apple/RCTTextInputComponentView+Marcus.h +11 -0
  86. package/apple/RCTTextInputComponentView+Marcus.mm +79 -0
  87. package/cpp/MarkdownCxx.modulemap +8 -0
  88. package/cpp/MarkdownGlobal.cpp +48 -0
  89. package/cpp/MarkdownGlobal.h +33 -0
  90. package/cpp/MarkdownWorkletParser.cpp +93 -0
  91. package/cpp/MarkdownWorkletParser.h +45 -0
  92. package/cpp/RuntimeDecorator.cpp +39 -0
  93. package/cpp/RuntimeDecorator.h +14 -0
  94. package/cpp/react/renderer/components/RNMarcusSpec/MarcusTextInputDecoratorState.h +33 -0
  95. package/cpp/react/renderer/components/RNMarcusSpec/MarcusTextInputDecoratorViewComponentDescriptor.h +17 -0
  96. package/lib/commonjs/MarcusTextInputDecoratorViewNativeComponent.ts +77 -0
  97. package/lib/commonjs/MarkdownTextInput.js +99 -0
  98. package/lib/commonjs/MarkdownTextInput.js.map +1 -0
  99. package/lib/commonjs/MarkdownTextInput.web.js +618 -0
  100. package/lib/commonjs/MarkdownTextInput.web.js.map +1 -0
  101. package/lib/commonjs/NativeMarcusModule.js +9 -0
  102. package/lib/commonjs/NativeMarcusModule.js.map +1 -0
  103. package/lib/commonjs/commonTypes.js +2 -0
  104. package/lib/commonjs/commonTypes.js.map +1 -0
  105. package/lib/commonjs/global.d.js +2 -0
  106. package/lib/commonjs/global.d.js.map +1 -0
  107. package/lib/commonjs/index.js +27 -0
  108. package/lib/commonjs/index.js.map +1 -0
  109. package/lib/commonjs/package.json +1 -0
  110. package/lib/commonjs/parser/index.js +7030 -0
  111. package/lib/commonjs/parser/index.js.map +7 -0
  112. package/lib/commonjs/rangeUtils.js +71 -0
  113. package/lib/commonjs/rangeUtils.js.map +1 -0
  114. package/lib/commonjs/react-native-web.d.js +2 -0
  115. package/lib/commonjs/react-native-web.d.js.map +1 -0
  116. package/lib/commonjs/styleUtils.js +91 -0
  117. package/lib/commonjs/styleUtils.js.map +1 -0
  118. package/lib/commonjs/web/InputHistory.js +111 -0
  119. package/lib/commonjs/web/InputHistory.js.map +1 -0
  120. package/lib/commonjs/web/MarkdownTextInput.css +72 -0
  121. package/lib/commonjs/web/utils/blockLayout.js +132 -0
  122. package/lib/commonjs/web/utils/blockLayout.js.map +1 -0
  123. package/lib/commonjs/web/utils/blockUtils.js +219 -0
  124. package/lib/commonjs/web/utils/blockUtils.js.map +1 -0
  125. package/lib/commonjs/web/utils/browserUtils.js +40 -0
  126. package/lib/commonjs/web/utils/browserUtils.js.map +1 -0
  127. package/lib/commonjs/web/utils/cursorUtils.js +157 -0
  128. package/lib/commonjs/web/utils/cursorUtils.js.map +1 -0
  129. package/lib/commonjs/web/utils/inputUtils.js +152 -0
  130. package/lib/commonjs/web/utils/inputUtils.js.map +1 -0
  131. package/lib/commonjs/web/utils/measureUtils.js +0 -0
  132. package/lib/commonjs/web/utils/measureUtils.js.map +1 -0
  133. package/lib/commonjs/web/utils/parserUtils.js +552 -0
  134. package/lib/commonjs/web/utils/parserUtils.js.map +1 -0
  135. package/lib/commonjs/web/utils/treeUtils.js +109 -0
  136. package/lib/commonjs/web/utils/treeUtils.js.map +1 -0
  137. package/lib/commonjs/web/utils/webStyleUtils.js +59 -0
  138. package/lib/commonjs/web/utils/webStyleUtils.js.map +1 -0
  139. package/lib/module/MarcusTextInputDecoratorViewNativeComponent.ts +77 -0
  140. package/lib/module/MarkdownTextInput.js +94 -0
  141. package/lib/module/MarkdownTextInput.js.map +1 -0
  142. package/lib/module/MarkdownTextInput.web.js +612 -0
  143. package/lib/module/MarkdownTextInput.web.js.map +1 -0
  144. package/lib/module/NativeMarcusModule.js +5 -0
  145. package/lib/module/NativeMarcusModule.js.map +1 -0
  146. package/lib/module/commonTypes.js +2 -0
  147. package/lib/module/commonTypes.js.map +1 -0
  148. package/lib/module/global.d.js +2 -0
  149. package/lib/module/global.d.js.map +1 -0
  150. package/lib/module/index.js +5 -0
  151. package/lib/module/index.js.map +1 -0
  152. package/lib/module/package.json +1 -0
  153. package/lib/module/parser/index.js +7029 -0
  154. package/lib/module/parser/index.js.map +7 -0
  155. package/lib/module/rangeUtils.js +66 -0
  156. package/lib/module/rangeUtils.js.map +1 -0
  157. package/lib/module/react-native-web.d.js +2 -0
  158. package/lib/module/react-native-web.d.js.map +1 -0
  159. package/lib/module/styleUtils.js +88 -0
  160. package/lib/module/styleUtils.js.map +1 -0
  161. package/lib/module/web/InputHistory.js +106 -0
  162. package/lib/module/web/InputHistory.js.map +1 -0
  163. package/lib/module/web/MarkdownTextInput.css +72 -0
  164. package/lib/module/web/utils/blockLayout.js +128 -0
  165. package/lib/module/web/utils/blockLayout.js.map +1 -0
  166. package/lib/module/web/utils/blockUtils.js +210 -0
  167. package/lib/module/web/utils/blockUtils.js.map +1 -0
  168. package/lib/module/web/utils/browserUtils.js +36 -0
  169. package/lib/module/web/utils/browserUtils.js.map +1 -0
  170. package/lib/module/web/utils/cursorUtils.js +150 -0
  171. package/lib/module/web/utils/cursorUtils.js.map +1 -0
  172. package/lib/module/web/utils/inputUtils.js +144 -0
  173. package/lib/module/web/utils/inputUtils.js.map +1 -0
  174. package/lib/module/web/utils/measureUtils.js +0 -0
  175. package/lib/module/web/utils/measureUtils.js.map +1 -0
  176. package/lib/module/web/utils/parserUtils.js +547 -0
  177. package/lib/module/web/utils/parserUtils.js.map +1 -0
  178. package/lib/module/web/utils/treeUtils.js +103 -0
  179. package/lib/module/web/utils/treeUtils.js.map +1 -0
  180. package/lib/module/web/utils/webStyleUtils.js +54 -0
  181. package/lib/module/web/utils/webStyleUtils.js.map +1 -0
  182. package/lib/typescript/commonjs/e2e/checks.test.d.ts +2 -0
  183. package/lib/typescript/commonjs/e2e/checks.test.d.ts.map +1 -0
  184. package/lib/typescript/commonjs/e2e/editing.test.d.ts +2 -0
  185. package/lib/typescript/commonjs/e2e/editing.test.d.ts.map +1 -0
  186. package/lib/typescript/commonjs/e2e/helpers.d.ts +23 -0
  187. package/lib/typescript/commonjs/e2e/helpers.d.ts.map +1 -0
  188. package/lib/typescript/commonjs/e2e/smoke.test.d.ts +2 -0
  189. package/lib/typescript/commonjs/e2e/smoke.test.d.ts.map +1 -0
  190. package/lib/typescript/commonjs/package.json +1 -0
  191. package/lib/typescript/commonjs/src/MarcusTextInputDecoratorViewNativeComponent.d.ts +63 -0
  192. package/lib/typescript/commonjs/src/MarcusTextInputDecoratorViewNativeComponent.d.ts.map +1 -0
  193. package/lib/typescript/commonjs/src/MarkdownTextInput.d.ts +22 -0
  194. package/lib/typescript/commonjs/src/MarkdownTextInput.d.ts.map +1 -0
  195. package/lib/typescript/commonjs/src/MarkdownTextInput.web.d.ts +41 -0
  196. package/lib/typescript/commonjs/src/MarkdownTextInput.web.d.ts.map +1 -0
  197. package/lib/typescript/commonjs/src/NativeMarcusModule.d.ts +7 -0
  198. package/lib/typescript/commonjs/src/NativeMarcusModule.d.ts.map +1 -0
  199. package/lib/typescript/commonjs/src/commonTypes.d.ts +10 -0
  200. package/lib/typescript/commonjs/src/commonTypes.d.ts.map +1 -0
  201. package/lib/typescript/commonjs/src/index.d.ts +5 -0
  202. package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
  203. package/lib/typescript/commonjs/src/parser/index.d.ts +8 -0
  204. package/lib/typescript/commonjs/src/parser/index.d.ts.map +1 -0
  205. package/lib/typescript/commonjs/src/parser/micromark-extension-mentions.d.ts +8 -0
  206. package/lib/typescript/commonjs/src/parser/micromark-extension-mentions.d.ts.map +1 -0
  207. package/lib/typescript/commonjs/src/rangeUtils.d.ts +6 -0
  208. package/lib/typescript/commonjs/src/rangeUtils.d.ts.map +1 -0
  209. package/lib/typescript/commonjs/src/styleUtils.d.ts +8 -0
  210. package/lib/typescript/commonjs/src/styleUtils.d.ts.map +1 -0
  211. package/lib/typescript/commonjs/src/web/InputHistory.d.ts +24 -0
  212. package/lib/typescript/commonjs/src/web/InputHistory.d.ts.map +1 -0
  213. package/lib/typescript/commonjs/src/web/utils/blockLayout.d.ts +41 -0
  214. package/lib/typescript/commonjs/src/web/utils/blockLayout.d.ts.map +1 -0
  215. package/lib/typescript/commonjs/src/web/utils/blockUtils.d.ts +33 -0
  216. package/lib/typescript/commonjs/src/web/utils/blockUtils.d.ts.map +1 -0
  217. package/lib/typescript/commonjs/src/web/utils/browserUtils.d.ts +7 -0
  218. package/lib/typescript/commonjs/src/web/utils/browserUtils.d.ts.map +1 -0
  219. package/lib/typescript/commonjs/src/web/utils/cursorUtils.d.ts +12 -0
  220. package/lib/typescript/commonjs/src/web/utils/cursorUtils.d.ts.map +1 -0
  221. package/lib/typescript/commonjs/src/web/utils/inputUtils.d.ts +12 -0
  222. package/lib/typescript/commonjs/src/web/utils/inputUtils.d.ts.map +1 -0
  223. package/lib/typescript/commonjs/src/web/utils/measureUtils.d.ts +22 -0
  224. package/lib/typescript/commonjs/src/web/utils/measureUtils.d.ts.map +1 -0
  225. package/lib/typescript/commonjs/src/web/utils/parserUtils.d.ts +44 -0
  226. package/lib/typescript/commonjs/src/web/utils/parserUtils.d.ts.map +1 -0
  227. package/lib/typescript/commonjs/src/web/utils/treeUtils.d.ts +25 -0
  228. package/lib/typescript/commonjs/src/web/utils/treeUtils.d.ts.map +1 -0
  229. package/lib/typescript/commonjs/src/web/utils/webStyleUtils.d.ts +7 -0
  230. package/lib/typescript/commonjs/src/web/utils/webStyleUtils.d.ts.map +1 -0
  231. package/lib/typescript/module/e2e/checks.test.d.ts +2 -0
  232. package/lib/typescript/module/e2e/checks.test.d.ts.map +1 -0
  233. package/lib/typescript/module/e2e/editing.test.d.ts +2 -0
  234. package/lib/typescript/module/e2e/editing.test.d.ts.map +1 -0
  235. package/lib/typescript/module/e2e/helpers.d.ts +23 -0
  236. package/lib/typescript/module/e2e/helpers.d.ts.map +1 -0
  237. package/lib/typescript/module/e2e/smoke.test.d.ts +2 -0
  238. package/lib/typescript/module/e2e/smoke.test.d.ts.map +1 -0
  239. package/lib/typescript/module/package.json +1 -0
  240. package/lib/typescript/module/src/MarcusTextInputDecoratorViewNativeComponent.d.ts +63 -0
  241. package/lib/typescript/module/src/MarcusTextInputDecoratorViewNativeComponent.d.ts.map +1 -0
  242. package/lib/typescript/module/src/MarkdownTextInput.d.ts +22 -0
  243. package/lib/typescript/module/src/MarkdownTextInput.d.ts.map +1 -0
  244. package/lib/typescript/module/src/MarkdownTextInput.web.d.ts +41 -0
  245. package/lib/typescript/module/src/MarkdownTextInput.web.d.ts.map +1 -0
  246. package/lib/typescript/module/src/NativeMarcusModule.d.ts +7 -0
  247. package/lib/typescript/module/src/NativeMarcusModule.d.ts.map +1 -0
  248. package/lib/typescript/module/src/commonTypes.d.ts +10 -0
  249. package/lib/typescript/module/src/commonTypes.d.ts.map +1 -0
  250. package/lib/typescript/module/src/index.d.ts +5 -0
  251. package/lib/typescript/module/src/index.d.ts.map +1 -0
  252. package/lib/typescript/module/src/parser/index.d.ts +8 -0
  253. package/lib/typescript/module/src/parser/index.d.ts.map +1 -0
  254. package/lib/typescript/module/src/parser/micromark-extension-mentions.d.ts +8 -0
  255. package/lib/typescript/module/src/parser/micromark-extension-mentions.d.ts.map +1 -0
  256. package/lib/typescript/module/src/rangeUtils.d.ts +6 -0
  257. package/lib/typescript/module/src/rangeUtils.d.ts.map +1 -0
  258. package/lib/typescript/module/src/styleUtils.d.ts +8 -0
  259. package/lib/typescript/module/src/styleUtils.d.ts.map +1 -0
  260. package/lib/typescript/module/src/web/InputHistory.d.ts +24 -0
  261. package/lib/typescript/module/src/web/InputHistory.d.ts.map +1 -0
  262. package/lib/typescript/module/src/web/utils/blockLayout.d.ts +41 -0
  263. package/lib/typescript/module/src/web/utils/blockLayout.d.ts.map +1 -0
  264. package/lib/typescript/module/src/web/utils/blockUtils.d.ts +33 -0
  265. package/lib/typescript/module/src/web/utils/blockUtils.d.ts.map +1 -0
  266. package/lib/typescript/module/src/web/utils/browserUtils.d.ts +7 -0
  267. package/lib/typescript/module/src/web/utils/browserUtils.d.ts.map +1 -0
  268. package/lib/typescript/module/src/web/utils/cursorUtils.d.ts +12 -0
  269. package/lib/typescript/module/src/web/utils/cursorUtils.d.ts.map +1 -0
  270. package/lib/typescript/module/src/web/utils/inputUtils.d.ts +12 -0
  271. package/lib/typescript/module/src/web/utils/inputUtils.d.ts.map +1 -0
  272. package/lib/typescript/module/src/web/utils/measureUtils.d.ts +22 -0
  273. package/lib/typescript/module/src/web/utils/measureUtils.d.ts.map +1 -0
  274. package/lib/typescript/module/src/web/utils/parserUtils.d.ts +44 -0
  275. package/lib/typescript/module/src/web/utils/parserUtils.d.ts.map +1 -0
  276. package/lib/typescript/module/src/web/utils/treeUtils.d.ts +25 -0
  277. package/lib/typescript/module/src/web/utils/treeUtils.d.ts.map +1 -0
  278. package/lib/typescript/module/src/web/utils/webStyleUtils.d.ts +7 -0
  279. package/lib/typescript/module/src/web/utils/webStyleUtils.d.ts.map +1 -0
  280. package/package.json +167 -0
  281. package/react-native.config.js +10 -0
  282. package/src/MarcusTextInputDecoratorViewNativeComponent.ts +77 -0
  283. package/src/MarkdownTextInput.tsx +139 -0
  284. package/src/MarkdownTextInput.web.tsx +958 -0
  285. package/src/NativeMarcusModule.ts +8 -0
  286. package/src/commonTypes.ts +30 -0
  287. package/src/global.d.ts +1 -0
  288. package/src/index.tsx +4 -0
  289. package/src/parser/index.ts +556 -0
  290. package/src/parser/micromark-extension-mentions.ts +82 -0
  291. package/src/rangeUtils.ts +68 -0
  292. package/src/react-native-web.d.ts +1 -0
  293. package/src/styleUtils.ts +100 -0
  294. package/src/web/InputHistory.ts +137 -0
  295. package/src/web/MarkdownTextInput.css +72 -0
  296. package/src/web/utils/blockLayout.ts +163 -0
  297. package/src/web/utils/blockUtils.ts +245 -0
  298. package/src/web/utils/browserUtils.ts +41 -0
  299. package/src/web/utils/cursorUtils.ts +204 -0
  300. package/src/web/utils/inputUtils.ts +206 -0
  301. package/src/web/utils/measureUtils.ts +0 -0
  302. package/src/web/utils/parserUtils.ts +813 -0
  303. package/src/web/utils/treeUtils.ts +149 -0
  304. package/src/web/utils/webStyleUtils.ts +69 -0
@@ -0,0 +1,44 @@
1
+ import type { HTMLMarkdownElement, MarkdownTextInputElement } from "../../MarkdownTextInput.web.js";
2
+ import type { TreeNode } from "./treeUtils.js";
3
+ import type { PartialMarkdownStyle } from "../../styleUtils.js";
4
+ import type { LineLayout } from "./blockLayout.js";
5
+ import type { TextMeasurer } from "./measureUtils.js";
6
+ import type { MarkdownRange } from "../../commonTypes.js";
7
+ type Paragraph = {
8
+ text: string;
9
+ start: number;
10
+ length: number;
11
+ markdownRanges: MarkdownRange[];
12
+ /** Where the containers this line sits in put its text, once they are all placed. */
13
+ layout?: LineLayout;
14
+ };
15
+ /**
16
+ * For singleline markdown types, the function splits markdown ranges that spread beyond the line length into separate lines.
17
+ * For multiline markdown types (like `pre`), it merges them and corresponding text into one line.
18
+ */
19
+ declare function normalizeLines(lines: Paragraph[], ranges: MarkdownRange[]): Paragraph[];
20
+ /** Builds HTML DOM structure based on passed text and markdown ranges */
21
+ declare function parseRangesToHTMLNodes(text: string, ranges: MarkdownRange[], isMultiline?: boolean, markdownStyle?: PartialMarkdownStyle, disableInlineStyles?: boolean, measure?: TextMeasurer): {
22
+ dom: HTMLMarkdownElement;
23
+ tree: TreeNode;
24
+ };
25
+ /**
26
+ * A line as it was last rendered: what it was built from, the markup it produced, and its subtree.
27
+ */
28
+ type CachedLine = {
29
+ signature: string;
30
+ html: string;
31
+ node: TreeNode;
32
+ };
33
+ type LineCache = {
34
+ markdownStyle: PartialMarkdownStyle;
35
+ isMultiline: boolean;
36
+ lines: CachedLine[];
37
+ };
38
+ declare function updateInputStructure(parserFunction: (input: string) => MarkdownRange[], target: MarkdownTextInputElement, text: string, cursorPositionIndex: number | null, isMultiline?: boolean, markdownStyle?: PartialMarkdownStyle, alwaysMoveCursorToTheEnd?: boolean, shouldForceDOMUpdate?: boolean, shouldScrollIntoView?: boolean): {
39
+ text: string;
40
+ cursorPosition: number;
41
+ };
42
+ export { updateInputStructure, parseRangesToHTMLNodes, normalizeLines };
43
+ export type { Paragraph, LineCache };
44
+ //# sourceMappingURL=parserUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parserUtils.d.ts","sourceRoot":"","sources":["../../../../../../src/web/utils/parserUtils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,MAAM,gCAA6B,CAAA;AAEhG,OAAO,KAAK,EAAY,QAAQ,EAAE,MAAM,gBAAa,CAAA;AACrD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAkB,CAAA;AAS5D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAe,CAAA;AAE/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAgB,CAAA;AAClD,OAAO,KAAK,EAAE,aAAa,EAAgB,MAAM,sBAAmB,CAAA;AAGpE,KAAK,SAAS,GAAG;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,cAAc,EAAE,aAAa,EAAE,CAAA;IAC/B,qFAAqF;IACrF,MAAM,CAAC,EAAE,UAAU,CAAA;CACpB,CAAA;AAmFD;;;GAGG;AACH,iBAAS,cAAc,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,MAAM,EAAE,aAAa,EAAE,eA2BlE;AA2SD,yEAAyE;AACzE,iBAAS,sBAAsB,CAC7B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,aAAa,EAAE,EACvB,WAAW,UAAO,EAClB,aAAa,GAAE,oBAAyB,EACxC,mBAAmB,UAAQ,EAC3B,OAAO,GAAE,YAAuC;;;EAyBjD;AAED;;GAEG;AACH,KAAK,UAAU,GAAG;IAChB,SAAS,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,QAAQ,CAAA;CACf,CAAA;AAED,KAAK,SAAS,GAAG;IACf,aAAa,EAAE,oBAAoB,CAAA;IACnC,WAAW,EAAE,OAAO,CAAA;IACpB,KAAK,EAAE,UAAU,EAAE,CAAA;CACpB,CAAA;AA0QD,iBAAS,oBAAoB,CAC3B,cAAc,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,aAAa,EAAE,EAClD,MAAM,EAAE,wBAAwB,EAChC,IAAI,EAAE,MAAM,EACZ,mBAAmB,EAAE,MAAM,GAAG,IAAI,EAClC,WAAW,UAAO,EAClB,aAAa,GAAE,oBAAyB,EACxC,wBAAwB,UAAQ,EAChC,oBAAoB,UAAQ,EAC5B,oBAAoB,UAAQ;;;EAiD7B;AAED,OAAO,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,cAAc,EAAE,CAAA;AACvE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,CAAA"}
@@ -0,0 +1,25 @@
1
+ import type { HTMLMarkdownElement } from "../../MarkdownTextInput.web.js";
2
+ import type { MarkdownRange, MarkdownType } from "../../commonTypes.js";
3
+ type NodeType = MarkdownType | "line" | "text" | "br" | "root";
4
+ type TreeNode = Omit<MarkdownRange, "type"> & {
5
+ element: HTMLMarkdownElement;
6
+ parentNode: TreeNode | null;
7
+ childNodes: TreeNode[];
8
+ type: NodeType;
9
+ orderIndex: string;
10
+ isGeneratingNewline: boolean;
11
+ };
12
+ declare function createRootTreeNode(target: HTMLMarkdownElement, length?: number, start?: number): TreeNode;
13
+ /**
14
+ * @param start Where the node begins in the text, when the caller knows it. A markdown range
15
+ * carries its own offset, and taking it is the only way to be right when ranges do not tile the
16
+ * line -- overlapping emphasis split across lines leaves gaps, and a node placed at wherever its
17
+ * previous sibling happened to end then reports an offset the text never had. Text and line breaks
18
+ * genuinely do follow on from what precedes them, so they still accumulate.
19
+ */
20
+ declare function addNodeToTree(element: HTMLMarkdownElement, parentTreeNode: TreeNode, type: NodeType, length?: number | null, start?: number | null): TreeNode;
21
+ declare function findHTMLElementInTree(treeRoot: TreeNode, element: HTMLElement): TreeNode | null;
22
+ declare function getTreeNodeByIndex(treeRoot: TreeNode, index: number): TreeNode | null;
23
+ export { addNodeToTree, findHTMLElementInTree, getTreeNodeByIndex, createRootTreeNode };
24
+ export type { TreeNode, NodeType };
25
+ //# sourceMappingURL=treeUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"treeUtils.d.ts","sourceRoot":"","sources":["../../../../../../src/web/utils/treeUtils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gCAA6B,CAAA;AACtE,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,sBAAmB,CAAA;AAEpE,KAAK,QAAQ,GAAG,YAAY,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,MAAM,CAAA;AAE9D,KAAK,QAAQ,GAAG,IAAI,CAAC,aAAa,EAAE,MAAM,CAAC,GAAG;IAC5C,OAAO,EAAE,mBAAmB,CAAA;IAC5B,UAAU,EAAE,QAAQ,GAAG,IAAI,CAAA;IAC3B,UAAU,EAAE,QAAQ,EAAE,CAAA;IACtB,IAAI,EAAE,QAAQ,CAAA;IACd,UAAU,EAAE,MAAM,CAAA;IAClB,mBAAmB,EAAE,OAAO,CAAA;CAC7B,CAAA;AAED,iBAAS,kBAAkB,CAAC,MAAM,EAAE,mBAAmB,EAAE,MAAM,SAAI,EAAE,KAAK,SAAI,GAAG,QAAQ,CAWxF;AAED;;;;;;GAMG;AACH,iBAAS,aAAa,CACpB,OAAO,EAAE,mBAAmB,EAC5B,cAAc,EAAE,QAAQ,EACxB,IAAI,EAAE,QAAQ,EACd,MAAM,GAAE,MAAM,GAAG,IAAW,EAC5B,KAAK,GAAE,MAAM,GAAG,IAAW,YAyC5B;AAED,iBAAS,qBAAqB,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,WAAW,GAAG,QAAQ,GAAG,IAAI,CAuBxF;AAED,iBAAS,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,GAAG,QAAQ,GAAG,IAAI,CAqC9E;AAED,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,CAAA;AAEvF,YAAY,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAA"}
@@ -0,0 +1,7 @@
1
+ import type { TextStyle } from "react-native";
2
+ import type { MarkdownStyle } from "../../MarcusTextInputDecoratorViewNativeComponent";
3
+ declare function processMarkdownStyle(input: MarkdownStyle | undefined): MarkdownStyle;
4
+ declare function parseToReactDOMStyle(style: TextStyle): any;
5
+ declare const idGenerator: Generator<string, void, unknown>;
6
+ export { parseToReactDOMStyle, processMarkdownStyle, idGenerator };
7
+ //# sourceMappingURL=webStyleUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webStyleUtils.d.ts","sourceRoot":"","sources":["../../../../../../src/web/utils/webStyleUtils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mDAAmD,CAAA;AAiDtF,iBAAS,oBAAoB,CAAC,KAAK,EAAE,aAAa,GAAG,SAAS,GAAG,aAAa,CAE7E;AAED,iBAAS,oBAAoB,CAAC,KAAK,EAAE,SAAS,GAAG,GAAG,CAEnD;AASD,QAAA,MAAM,WAAW,kCAAqB,CAAA;AAEtC,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,WAAW,EAAE,CAAA"}
package/package.json ADDED
@@ -0,0 +1,167 @@
1
+ {
2
+ "name": "react-native-marcus",
3
+ "version": "0.1.0",
4
+ "description": "Drop-in replacement for React Native's TextInput component with Markdown formatting.",
5
+ "author": {
6
+ "name": "Tomas Ravinskas",
7
+ "email": "tomas@tomasrav.me",
8
+ "url": "https://tomasrav.me/"
9
+ },
10
+ "contributors": [
11
+ "Expensify, Inc."
12
+ ],
13
+ "license": "Apache-2.0",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git@github.com:getbullet-app/react-native-marcus.git"
17
+ },
18
+ "bugs": {
19
+ "url": "https://github.com/getbullet-app/react-native-marcus/issues"
20
+ },
21
+ "homepage": "https://github.com/getbullet-app/react-native-marcus",
22
+ "main": "./lib/commonjs/index.js",
23
+ "module": "./lib/module/index.js",
24
+ "types": "./lib/typescript/commonjs/src/index.d.ts",
25
+ "exports": {
26
+ ".": {
27
+ "import": {
28
+ "types": "./lib/typescript/module/src/index.d.ts",
29
+ "default": "./lib/module/index.js"
30
+ },
31
+ "require": {
32
+ "types": "./lib/typescript/commonjs/src/index.d.ts",
33
+ "default": "./lib/commonjs/index.js"
34
+ }
35
+ },
36
+ "./package.json": "./package.json"
37
+ },
38
+ "scripts": {
39
+ "clean": "del-cli '{.,example}/{android,ios}/**/{build,.cxx}' lib",
40
+ "clean:codegen": "del-cli '{.,example}/{android,ios}/**/build/generated' '{.,example}/ios/Pod{s,file.lock}' && npx --workspace=marcus-example pod-install",
41
+ "example": "npm run --workspace=marcus-example",
42
+ "prepare": "patch-package && bob build && node scripts/bundle-parser.mjs",
43
+ "watch": "nodemon --watch src --ext 'ts tsx js jsx json' --exec npm run prepare",
44
+ "fixtures": "tsx scripts/emit-fixtures.mts",
45
+ "fixtures:check": "tsx scripts/emit-fixtures.mts --check",
46
+ "web:build": "npm run --workspace=marcus-example export:web",
47
+ "web:serve": "npm run --workspace=marcus-example serve:web",
48
+ "test": "npm run fixtures:check && tsc --noEmit && npm run test:unit && npm run web:build && npm run test:web && npm run test:android && npm run test:ios",
49
+ "test:unit": "jest",
50
+ "test:unit:watch": "jest --watch",
51
+ "test:update": "npm run fixtures && npm run test:unit -- -u && npm run web:build && npm run test:web -- -u && npm run test:android:update && npm run test:ios:update",
52
+ "test:web": "playwright test",
53
+ "test:e2e": "npm run test:e2e:ios && npm run test:e2e:android",
54
+ "test:e2e:ios": "detox build-framework-cache && detox build -c ios && detox test -c ios",
55
+ "test:e2e:android": "detox build -c android && detox test -c android",
56
+ "test:android": "cd example/android && ./gradlew :react-native-marcus:testDebugUnitTest",
57
+ "test:android:update": "rm -f android/src/test/resources/render-model.txt && npm run test:android",
58
+ "test:ios": "node scripts/ios-test.mjs -quiet",
59
+ "test:ios:update": "rm -f ios-tests/Tests/MarcusFormatterTests/__baselines__/render-model.txt && npm run test:ios"
60
+ },
61
+ "workspaces": [
62
+ "./example"
63
+ ],
64
+ "files": [
65
+ "src",
66
+ "lib",
67
+ "android",
68
+ "apple",
69
+ "cpp",
70
+ "*.podspec",
71
+ "react-native.config.js",
72
+ "!apple/build",
73
+ "!android/build",
74
+ "!android/gradle",
75
+ "!android/gradlew",
76
+ "!android/gradlew.bat",
77
+ "!android/local.properties",
78
+ "!**/__tests__",
79
+ "!**/__fixtures__",
80
+ "!**/__mocks__",
81
+ "!**/.*"
82
+ ],
83
+ "keywords": [
84
+ "react-native",
85
+ "ios",
86
+ "android",
87
+ "web",
88
+ "markdown"
89
+ ],
90
+ "peerDependencies": {
91
+ "react": "*",
92
+ "react-native": ">=0.81",
93
+ "react-native-web": "^0.21.0",
94
+ "react-native-worklets": ">=0.7.0"
95
+ },
96
+ "peerDependenciesMeta": {
97
+ "react-native-web": {
98
+ "optional": true
99
+ }
100
+ },
101
+ "devDependencies": {
102
+ "@playwright/test": "^1.62.1",
103
+ "@react-native/babel-preset": "^0.86.3",
104
+ "@react-native/jest-preset": "^0.86.3",
105
+ "@types/jest": "^29.5.14",
106
+ "@types/react": "^19.2.0",
107
+ "del-cli": "^7.0.0",
108
+ "detox": "^20.51.4",
109
+ "emoji-regex": "^10.6.0",
110
+ "esbuild": "^0.25.0",
111
+ "fast-check": "^4.9.0",
112
+ "jest": "^29.6.3",
113
+ "jest-environment-jsdom": "^29.7.0",
114
+ "kleur": "^4.1.5",
115
+ "mdast-util-from-markdown": "^2.0.3",
116
+ "micromark-extension-gfm-autolink-literal": "^2.1.0",
117
+ "micromark-extension-gfm-strikethrough": "^2.1.0",
118
+ "nodemon": "^3.1.14",
119
+ "patch-package": "^8.0.0",
120
+ "prettier": "2.8.8",
121
+ "react": "19.2.3",
122
+ "react-dom": "19.2.3",
123
+ "react-native": "^0.86.3",
124
+ "react-native-builder-bob": "^0.43.0",
125
+ "react-native-web": "^0.21.2",
126
+ "react-native-worklets": "0.10.1",
127
+ "tsx": "^4.23.13",
128
+ "typescript": "~6.0.3"
129
+ },
130
+ "overrides": {
131
+ "react": "19.2.3",
132
+ "react-dom": "19.2.3"
133
+ },
134
+ "react-native-builder-bob": {
135
+ "source": "src",
136
+ "output": "lib",
137
+ "targets": [
138
+ [
139
+ "module",
140
+ {
141
+ "esm": true
142
+ }
143
+ ],
144
+ [
145
+ "commonjs",
146
+ {
147
+ "esm": true
148
+ }
149
+ ],
150
+ "typescript"
151
+ ],
152
+ "exclude": "**/{__tests__,__fixtures__,__mocks__,parser}/**"
153
+ },
154
+ "codegenConfig": {
155
+ "name": "RNMarcusSpec",
156
+ "type": "all",
157
+ "jsSrcsDir": "src",
158
+ "android": {
159
+ "javaPackageName": "app.getbullet.marcus"
160
+ },
161
+ "ios": {
162
+ "componentProvider": {
163
+ "MarcusTextInputDecoratorView": "MarcusTextInputDecoratorComponentView"
164
+ }
165
+ }
166
+ }
167
+ }
@@ -0,0 +1,10 @@
1
+ module.exports = {
2
+ dependency: {
3
+ platforms: {
4
+ android: {
5
+ componentDescriptors: ["MarcusTextInputDecoratorViewComponentDescriptor"],
6
+ cmakeListsPath: "../android/src/main/new_arch/CMakeLists.txt",
7
+ },
8
+ },
9
+ },
10
+ }
@@ -0,0 +1,77 @@
1
+ import { codegenNativeComponent } from "react-native"
2
+ import type { ColorValue, ViewProps } from "react-native"
3
+
4
+ import type { Float, Int32 } from "react-native/Libraries/Types/CodegenTypes"
5
+
6
+ // Font, colour and background, and nothing else: neither formatter draws a
7
+ // border or reserves padding around a code run, so there is nothing to
8
+ // configure.
9
+ interface CodeBlockStyle {
10
+ fontFamily: string
11
+ fontSize: Float
12
+ color: ColorValue
13
+ backgroundColor: ColorValue
14
+ }
15
+
16
+ interface MarkdownStyle {
17
+ syntax: {
18
+ color: ColorValue
19
+ }
20
+ emoji: {
21
+ fontSize: Float
22
+ fontFamily: string
23
+ }
24
+ link: {
25
+ color: ColorValue
26
+ }
27
+ heading: {
28
+ fontSize: Float
29
+ // Each level down multiplies the one above, so level N is
30
+ // fontSize * scale^(N - 1). Six levels, matching HTML.
31
+ scale: Float
32
+ }
33
+ blockquote: {
34
+ borderColor: ColorValue
35
+ borderWidth: Float
36
+ marginLeft: Float
37
+ paddingLeft: Float
38
+ }
39
+ // Indent only, no gutter decoration. Kept as two separate entries so a
40
+ // renderer can style ordered and unordered lists differently.
41
+ orderedList: {
42
+ marginLeft: Float
43
+ paddingLeft: Float
44
+ }
45
+ unorderedList: {
46
+ marginLeft: Float
47
+ paddingLeft: Float
48
+ }
49
+ code: CodeBlockStyle
50
+ pre: CodeBlockStyle
51
+ mentionHere: {
52
+ color: ColorValue
53
+ backgroundColor: ColorValue
54
+ borderRadius?: Float
55
+ }
56
+ mentionUser: {
57
+ color: ColorValue
58
+ backgroundColor: ColorValue
59
+ borderRadius?: Float
60
+ }
61
+ mentionReport: {
62
+ color: ColorValue
63
+ backgroundColor: ColorValue
64
+ borderRadius?: Float
65
+ }
66
+ }
67
+
68
+ interface NativeProps extends ViewProps {
69
+ markdownStyle: MarkdownStyle
70
+ parserId: Int32
71
+ }
72
+
73
+ export default codegenNativeComponent<NativeProps>("MarcusTextInputDecoratorView", {
74
+ interfaceOnly: true,
75
+ })
76
+
77
+ export type { MarkdownStyle }
@@ -0,0 +1,139 @@
1
+ import { StyleSheet, TextInput, processColor } from "react-native"
2
+ import React from "react"
3
+ import type { TextInputProps } from "react-native"
4
+ import { createSerializable, createWorkletRuntime } from "react-native-worklets"
5
+ import type { SerializableRef, WorkletFunction, WorkletRuntime } from "react-native-worklets"
6
+ import MarcusTextInputDecoratorViewNativeComponent from "./MarcusTextInputDecoratorViewNativeComponent"
7
+ import type { MarkdownStyle } from "./MarcusTextInputDecoratorViewNativeComponent"
8
+ import NativeMarcusModule from "./NativeMarcusModule"
9
+ import { mergeMarkdownStyleWithDefault } from "./styleUtils"
10
+ import type { PartialMarkdownStyle } from "./styleUtils"
11
+ import type { MarkdownRange } from "./commonTypes"
12
+
13
+ declare global {
14
+ // eslint-disable-next-line no-var
15
+ var jsi_setMarcusRuntime: (runtime: WorkletRuntime) => void
16
+ // eslint-disable-next-line no-var
17
+ var jsi_registerMarcusWorklet: (
18
+ shareableWorklet: SerializableRef<WorkletFunction<[string], MarkdownRange[]>>,
19
+ ) => number
20
+ // eslint-disable-next-line no-var
21
+ var jsi_unregisterMarcusWorklet: (parserId: number) => void
22
+ }
23
+
24
+ let initialized = false
25
+ let workletRuntime: WorkletRuntime | undefined
26
+
27
+ function getWorkletRuntime(): WorkletRuntime {
28
+ if (workletRuntime === undefined) {
29
+ throw new Error(
30
+ "[react-native-marcus] Worklet runtime hasn't been created yet. Please avoid calling `getWorkletRuntime()` in top-level scope. Instead, call `getWorkletRuntime()` directly in `runOnRuntime` arguments list.",
31
+ )
32
+ }
33
+ return workletRuntime
34
+ }
35
+
36
+ function initializeMarcusIfNeeded() {
37
+ if (initialized) {
38
+ return
39
+ }
40
+ if (NativeMarcusModule) {
41
+ NativeMarcusModule.install()
42
+ }
43
+ if (!global.jsi_setMarcusRuntime) {
44
+ throw new Error("[react-native-marcus] global.jsi_setMarcusRuntime is not available")
45
+ }
46
+ workletRuntime = createWorkletRuntime({ name: "MarcusRuntime" })
47
+ global.jsi_setMarcusRuntime(workletRuntime)
48
+ initialized = true
49
+ }
50
+
51
+ function registerParser(parser: (input: string) => MarkdownRange[]): number {
52
+ initializeMarcusIfNeeded()
53
+ const serializableWorklet = createSerializable(
54
+ parser as WorkletFunction<[string], MarkdownRange[]>,
55
+ )
56
+ const parserId = global.jsi_registerMarcusWorklet(serializableWorklet)
57
+ return parserId
58
+ }
59
+
60
+ function unregisterParser(parserId: number) {
61
+ global.jsi_unregisterMarcusWorklet(parserId)
62
+ }
63
+
64
+ interface MarkdownTextInputProps extends TextInputProps {
65
+ markdownStyle?: PartialMarkdownStyle
66
+ parser: (value: string) => MarkdownRange[]
67
+ }
68
+
69
+ type MarkdownTextInput = TextInput & React.Component<MarkdownTextInputProps>
70
+
71
+ function processColorsInMarkdownStyle(input: MarkdownStyle): MarkdownStyle {
72
+ const output = JSON.parse(JSON.stringify(input))
73
+
74
+ Object.keys(output).forEach((key) => {
75
+ const obj = output[key]
76
+ Object.keys(obj).forEach((prop) => {
77
+ // TODO: use ReactNativeStyleAttributes from 'react-native/Libraries/Components/View/ReactNativeStyleAttributes'
78
+ if (!(prop === "color" || prop.endsWith("Color"))) {
79
+ return
80
+ }
81
+ obj[prop] = processColor(obj[prop])
82
+ })
83
+ })
84
+
85
+ return output as MarkdownStyle
86
+ }
87
+
88
+ function processMarkdownStyle(input: PartialMarkdownStyle | undefined): MarkdownStyle {
89
+ return processColorsInMarkdownStyle(mergeMarkdownStyleWithDefault(input))
90
+ }
91
+
92
+ const MarkdownTextInput = React.forwardRef<MarkdownTextInput, MarkdownTextInputProps>(
93
+ (props, ref) => {
94
+ const markdownStyle = React.useMemo(
95
+ () => processMarkdownStyle(props.markdownStyle),
96
+ [props.markdownStyle],
97
+ )
98
+
99
+ if (props.parser === undefined) {
100
+ throw new Error("[react-native-marcus] `parser` is undefined")
101
+ }
102
+
103
+ // eslint-disable-next-line no-underscore-dangle
104
+ const workletHash = (props.parser as { __workletHash?: number }).__workletHash
105
+ if (workletHash === undefined) {
106
+ throw new Error("[react-native-marcus] `parser` is not a worklet")
107
+ }
108
+
109
+ const parserId = React.useMemo(() => {
110
+ return registerParser(props.parser)
111
+ }, [props.parser])
112
+
113
+ React.useEffect(() => {
114
+ return () => unregisterParser(parserId)
115
+ }, [parserId])
116
+
117
+ return (
118
+ <MarcusTextInputDecoratorViewNativeComponent
119
+ style={styles.displayContents}
120
+ markdownStyle={markdownStyle}
121
+ parserId={parserId}
122
+ >
123
+ <TextInput {...props} ref={ref} />
124
+ </MarcusTextInputDecoratorViewNativeComponent>
125
+ )
126
+ },
127
+ )
128
+
129
+ const styles = StyleSheet.create({
130
+ displayContents: {
131
+ display: "contents",
132
+ },
133
+ })
134
+
135
+ export type { PartialMarkdownStyle as MarkdownStyle, MarkdownTextInputProps }
136
+
137
+ export default MarkdownTextInput
138
+
139
+ export { getWorkletRuntime }