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,105 @@
1
+ package app.getbullet.marcus.spans
2
+
3
+ import android.graphics.Canvas
4
+ import android.graphics.Paint
5
+ import android.graphics.Path
6
+ import android.graphics.RectF
7
+ import android.text.StaticLayout
8
+ import android.text.TextPaint
9
+ import android.text.style.LineBackgroundSpan
10
+ import androidx.annotation.ColorInt
11
+
12
+ class MarkdownBackgroundSpan(
13
+ @ColorInt private val backgroundColor: Int,
14
+ private val borderRadius: Float,
15
+ private val mentionStart: Int,
16
+ private val mentionEnd: Int
17
+ ) : MarkdownSpan, LineBackgroundSpan {
18
+
19
+ private var layout: StaticLayout? = null
20
+ private val backgroundPath = Path()
21
+
22
+ override fun drawBackground(
23
+ canvas: Canvas,
24
+ paint: Paint,
25
+ left: Int,
26
+ right: Int,
27
+ top: Int,
28
+ baseline: Int,
29
+ bottom: Int,
30
+ text: CharSequence,
31
+ start: Int,
32
+ end: Int,
33
+ lnum: Int
34
+ ) {
35
+ val lineText = text.subSequence(start, end)
36
+ val cachedLayout = layout
37
+ // `!==` on purpose: the Java this replaces compared the layout's text by
38
+ // reference, not by value.
39
+ if (cachedLayout == null ||
40
+ cachedLayout.text !== lineText ||
41
+ cachedLayout.width != right ||
42
+ cachedLayout.getLineEnd(0) != lineText.length
43
+ ) {
44
+ val currentLineStart = 0
45
+ val currentLineEnd = lineText.length
46
+ // Create layout for the current line only
47
+ val newLayout = StaticLayout.Builder
48
+ .obtain(lineText, currentLineStart, currentLineEnd, paint as TextPaint, right)
49
+ .build()
50
+ layout = newLayout
51
+
52
+ val relativeMentionStart = mentionStart - start
53
+ val relativeMentionEnd = mentionEnd - start
54
+
55
+ val mentionStartsInCurrentLine = currentLineStart <= relativeMentionStart
56
+ val mentionEndsInCurrentLine = currentLineEnd >= relativeMentionEnd
57
+
58
+ val startX = newLayout.getPrimaryHorizontal(
59
+ if (mentionStartsInCurrentLine) relativeMentionStart else currentLineStart
60
+ )
61
+ val endX = newLayout.getPrimaryHorizontal(
62
+ if (mentionEndsInCurrentLine) relativeMentionEnd else currentLineEnd
63
+ )
64
+
65
+ val fm = paint.getFontMetrics()
66
+ val startY = baseline + fm.ascent
67
+ val endY = baseline + fm.descent
68
+
69
+ val lineRect = RectF(startX, startY, endX, endY)
70
+ backgroundPath.reset()
71
+ backgroundPath.addRoundRect(
72
+ lineRect,
73
+ createRadii(mentionStartsInCurrentLine, mentionEndsInCurrentLine),
74
+ Path.Direction.CW
75
+ )
76
+ }
77
+
78
+ val originalColor = paint.color
79
+ paint.color = backgroundColor
80
+
81
+ canvas.drawPath(backgroundPath, paint)
82
+
83
+ paint.color = originalColor
84
+ }
85
+
86
+ private fun createRadii(roundedLeft: Boolean, roundedRight: Boolean): FloatArray {
87
+ val radii = FloatArray(8)
88
+
89
+ if (roundedLeft) {
90
+ radii[1] = borderRadius // top-left
91
+ radii[0] = radii[1]
92
+ radii[7] = borderRadius // bottom-left
93
+ radii[6] = radii[7]
94
+ }
95
+
96
+ if (roundedRight) {
97
+ radii[3] = borderRadius // top-right
98
+ radii[2] = radii[3]
99
+ radii[5] = borderRadius // bottom-right
100
+ radii[4] = radii[5]
101
+ }
102
+
103
+ return radii
104
+ }
105
+ }
@@ -0,0 +1,67 @@
1
+ package app.getbullet.marcus.spans
2
+
3
+ import android.graphics.Canvas
4
+ import android.graphics.Paint
5
+ import android.text.Layout
6
+ import android.text.style.LeadingMarginSpan
7
+ import androidx.annotation.ColorInt
8
+
9
+ /**
10
+ * Indents one line by the containers it sits in, and draws a blockquote's
11
+ * ribbons in the gutter reserved for them.
12
+ *
13
+ * One span per line rather than one per container: where a container's gutter
14
+ * goes depends on the markers of the containers around it, so the offsets are
15
+ * worked out together by the formatter and handed over already in pixels.
16
+ */
17
+ class MarkdownBlockIndentSpan(
18
+ @ColorInt private val borderColor: Int,
19
+ private val borderWidth: Float,
20
+ private val borderSpacing: Float
21
+ ) : MarkdownSpan, LeadingMarginSpan {
22
+
23
+ /** Where the line's text starts, and where it resumes when it wraps. */
24
+ var firstLineIndent = 0f
25
+ var indent = 0f
26
+
27
+ /** Left edge of the blockquote's gutter, and how many ribbons fill it. */
28
+ var ribbonOffset = 0f
29
+ var depth = 0
30
+
31
+ override fun getLeadingMargin(first: Boolean): Int {
32
+ return (if (first) firstLineIndent else indent).toInt()
33
+ }
34
+
35
+ override fun drawLeadingMargin(
36
+ c: Canvas,
37
+ p: Paint,
38
+ x: Int,
39
+ dir: Int,
40
+ top: Int,
41
+ baseline: Int,
42
+ bottom: Int,
43
+ text: CharSequence?,
44
+ start: Int,
45
+ end: Int,
46
+ first: Boolean,
47
+ layout: Layout?
48
+ ) {
49
+ if (depth == 0) {
50
+ return
51
+ }
52
+
53
+ val originalStyle = p.style
54
+ val originalColor = p.color
55
+
56
+ p.style = Paint.Style.FILL
57
+ p.color = borderColor
58
+
59
+ for (level in 0 until depth) {
60
+ val left = x + dir * (ribbonOffset + borderSpacing * level)
61
+ c.drawRect(left, top.toFloat(), left + dir * borderWidth, bottom.toFloat(), p)
62
+ }
63
+
64
+ p.style = originalStyle
65
+ p.color = originalColor
66
+ }
67
+ }
@@ -0,0 +1,6 @@
1
+ package app.getbullet.marcus.spans
2
+
3
+ import android.graphics.Typeface
4
+ import android.text.style.StyleSpan
5
+
6
+ class MarkdownBoldSpan : StyleSpan(Typeface.BOLD), MarkdownSpan
@@ -0,0 +1,28 @@
1
+ package app.getbullet.marcus.spans
2
+
3
+ import android.content.res.AssetManager
4
+ import android.graphics.Paint
5
+ import android.text.TextPaint
6
+ import android.text.style.MetricAffectingSpan
7
+ import com.facebook.react.common.assets.ReactFontManager
8
+
9
+ class MarkdownFontFamilySpan(
10
+ private val fontFamily: String,
11
+ private val assetManager: AssetManager
12
+ ) : MetricAffectingSpan(), MarkdownSpan {
13
+
14
+ override fun updateMeasureState(textPaint: TextPaint) {
15
+ apply(textPaint)
16
+ }
17
+
18
+ override fun updateDrawState(tp: TextPaint) {
19
+ apply(tp)
20
+ }
21
+
22
+ private fun apply(textPaint: TextPaint) {
23
+ val style = textPaint.typeface?.style ?: ReactFontManager.TypefaceStyle.NORMAL
24
+ val typeface = ReactFontManager.getInstance().getTypeface(fontFamily, style, assetManager)
25
+ textPaint.typeface = typeface
26
+ textPaint.flags = textPaint.flags or Paint.SUBPIXEL_TEXT_FLAG
27
+ }
28
+ }
@@ -0,0 +1,7 @@
1
+ package app.getbullet.marcus.spans
2
+
3
+ import android.text.style.AbsoluteSizeSpan
4
+ import com.facebook.react.uimanager.PixelUtil
5
+
6
+ class MarkdownFontSizeSpan(fontSize: Float) :
7
+ AbsoluteSizeSpan(PixelUtil.toPixelFromDIP(fontSize).toInt(), false), MarkdownSpan
@@ -0,0 +1,6 @@
1
+ package app.getbullet.marcus.spans
2
+
3
+ import android.text.style.ForegroundColorSpan
4
+ import androidx.annotation.ColorInt
5
+
6
+ class MarkdownForegroundColorSpan(@ColorInt color: Int) : ForegroundColorSpan(color), MarkdownSpan
@@ -0,0 +1,57 @@
1
+ package app.getbullet.marcus.spans
2
+
3
+ import android.graphics.Canvas
4
+ import android.graphics.Paint
5
+ import android.text.style.ReplacementSpan
6
+ import androidx.annotation.ColorInt
7
+
8
+ /**
9
+ * Widens the character it covers by [gap] pixels, leaving the glyph where it is.
10
+ *
11
+ * Applied to the last character of a container's marker so that the container
12
+ * nested inside it can put its gutter between that marker and the next one.
13
+ */
14
+ class MarkdownGapSpan(
15
+ private val gap: Float,
16
+ @ColorInt private val syntaxColor: Int
17
+ ) : ReplacementSpan(), MarkdownSpan {
18
+
19
+ override fun getSize(
20
+ paint: Paint,
21
+ text: CharSequence,
22
+ start: Int,
23
+ end: Int,
24
+ fm: Paint.FontMetricsInt?
25
+ ): Int {
26
+ if (fm != null) {
27
+ val metrics = paint.fontMetricsInt
28
+ fm.top = metrics.top
29
+ fm.ascent = metrics.ascent
30
+ fm.descent = metrics.descent
31
+ fm.bottom = metrics.bottom
32
+ fm.leading = metrics.leading
33
+ }
34
+
35
+ return (paint.measureText(text, start, end) + gap).toInt()
36
+ }
37
+
38
+ override fun draw(
39
+ canvas: Canvas,
40
+ text: CharSequence,
41
+ start: Int,
42
+ end: Int,
43
+ x: Float,
44
+ top: Int,
45
+ y: Int,
46
+ bottom: Int,
47
+ paint: Paint
48
+ ) {
49
+ // Spans inside a replacement are not applied, so the one colour a marker's
50
+ // last character can have is restored by hand. It is whitespace whenever the
51
+ // marker is followed by any, and a syntax character otherwise.
52
+ val originalColor = paint.color
53
+ paint.color = syntaxColor
54
+ canvas.drawText(text, start, end, x, y.toFloat(), paint)
55
+ paint.color = originalColor
56
+ }
57
+ }
@@ -0,0 +1,6 @@
1
+ package app.getbullet.marcus.spans
2
+
3
+ import android.graphics.Typeface
4
+ import android.text.style.StyleSpan
5
+
6
+ class MarkdownItalicSpan : StyleSpan(Typeface.ITALIC), MarkdownSpan
@@ -0,0 +1,21 @@
1
+ package app.getbullet.marcus.spans
2
+
3
+ import android.graphics.Paint
4
+ import android.text.style.LineHeightSpan
5
+
6
+ class MarkdownLineHeightSpan(private val lineHeight: Float) : MarkdownSpan, LineHeightSpan {
7
+ override fun chooseHeight(
8
+ text: CharSequence?,
9
+ start: Int,
10
+ end: Int,
11
+ spanstartv: Int,
12
+ lineHeight: Int,
13
+ fm: Paint.FontMetricsInt
14
+ ) {
15
+ // Java's `fm.top -= this.lineHeight / 4` performs the subtraction in float and
16
+ // narrows the result, so the truncation has to happen after the subtraction.
17
+ // Truncating the quotient first would shift the value by up to one pixel.
18
+ fm.top = (fm.top - this.lineHeight / 4).toInt()
19
+ fm.ascent = (fm.ascent - this.lineHeight / 4).toInt()
20
+ }
21
+ }
@@ -0,0 +1,7 @@
1
+ package app.getbullet.marcus.spans
2
+
3
+ /*
4
+ * Enables us to distinguish between spans that were added by Marcus and spans that were
5
+ * added by something else. All spans that Marcus adds should implement this interface.
6
+ */
7
+ interface MarkdownSpan
@@ -0,0 +1,5 @@
1
+ package app.getbullet.marcus.spans
2
+
3
+ import android.text.style.StrikethroughSpan
4
+
5
+ class MarkdownStrikethroughSpan : StrikethroughSpan(), MarkdownSpan
@@ -0,0 +1,5 @@
1
+ package app.getbullet.marcus.spans
2
+
3
+ import android.text.style.UnderlineSpan
4
+
5
+ class MarkdownUnderlineSpan : UnderlineSpan(), MarkdownSpan
@@ -0,0 +1,70 @@
1
+ cmake_minimum_required(VERSION 3.13)
2
+ set(CMAKE_VERBOSE_MAKEFILE ON)
3
+ set(CMAKE_CXX_STANDARD 20)
4
+
5
+ set(LIB_LITERAL RNMarcusSpec)
6
+ set(LIB_TARGET_NAME react_codegen_${LIB_LITERAL})
7
+
8
+ set(LIB_ANDROID_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
9
+ set(LIB_CPP_DIR ${LIB_ANDROID_DIR}/../cpp)
10
+ set(LIB_CUSTOM_SOURCES_DIR ${LIB_CPP_DIR}/react/renderer/components/${LIB_LITERAL})
11
+ set(LIB_ANDROID_GENERATED_JNI_DIR ${LIB_ANDROID_DIR}/build/generated/source/codegen/jni)
12
+ set(LIB_ANDROID_GENERATED_COMPONENTS_DIR ${LIB_ANDROID_GENERATED_JNI_DIR}/react/renderer/components/${LIB_LITERAL})
13
+
14
+ file(GLOB LIB_MODULE_SRCS CONFIGURE_DEPENDS *.cpp react/renderer/components/RNMarcusSpec/*.cpp)
15
+ file(GLOB LIB_CUSTOM_SRCS CONFIGURE_DEPENDS ${LIB_CUSTOM_SOURCES_DIR}/*.cpp)
16
+ file(GLOB LIB_CODEGEN_SRCS CONFIGURE_DEPENDS ${LIB_ANDROID_GENERATED_COMPONENTS_DIR}/*.cpp)
17
+
18
+ add_library(
19
+ ${LIB_TARGET_NAME}
20
+ SHARED
21
+ ${LIB_MODULE_SRCS}
22
+ ${LIB_CUSTOM_SRCS}
23
+ ${LIB_CODEGEN_SRCS}
24
+ )
25
+
26
+ target_include_directories(
27
+ ${LIB_TARGET_NAME}
28
+ PUBLIC
29
+ .
30
+ ./react/renderer/components/RNMarcusSpec
31
+ ${LIB_ANDROID_GENERATED_JNI_DIR}
32
+ ${LIB_ANDROID_GENERATED_COMPONENTS_DIR}
33
+ ${LIB_CPP_DIR}
34
+ )
35
+
36
+ find_package(fbjni REQUIRED CONFIG)
37
+ find_package(ReactAndroid REQUIRED CONFIG)
38
+
39
+ target_link_libraries(
40
+ ${LIB_TARGET_NAME}
41
+ fbjni::fbjni
42
+ ReactAndroid::jsi
43
+ ReactAndroid::reactnative
44
+ )
45
+
46
+ if (ReactAndroid_VERSION_MINOR LESS_EQUAL 80)
47
+ target_compile_options(
48
+ ${LIB_TARGET_NAME}
49
+ PRIVATE
50
+ -DLOG_TAG=\"ReactNative\"
51
+ -fexceptions
52
+ -frtti
53
+ -Wall
54
+ -std=c++20
55
+ )
56
+ else()
57
+ target_compile_reactnative_options(${LIB_TARGET_NAME} PRIVATE)
58
+ endif()
59
+
60
+ target_compile_options(
61
+ ${LIB_TARGET_NAME}
62
+ PRIVATE
63
+ -DREACT_NATIVE_MINOR_VERSION=${ReactAndroid_VERSION_MINOR}
64
+ )
65
+
66
+ target_include_directories(
67
+ ${CMAKE_PROJECT_NAME}
68
+ PUBLIC
69
+ ${CMAKE_CURRENT_SOURCE_DIR}
70
+ )
@@ -0,0 +1,43 @@
1
+
2
+ /**
3
+ * This code was generated by
4
+ * [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
5
+ *
6
+ * Do not edit this file as changes may cause incorrect behavior and will be
7
+ * lost once the code is regenerated.
8
+ *
9
+ * @generated by codegen project: GenerateModuleJniCpp.js
10
+ */
11
+
12
+ #include "RNMarcusSpec.h"
13
+
14
+ namespace facebook {
15
+ namespace react {
16
+
17
+ static facebook::jsi::Value
18
+ __hostFunction_NativeMarcusModuleSpecJSI_install(
19
+ facebook::jsi::Runtime &rt, TurboModule &turboModule, const facebook::jsi::Value *args, size_t count
20
+ ) {
21
+ static jmethodID cachedMethodId = nullptr;
22
+ return static_cast<JavaTurboModule &>(turboModule)
23
+ .invokeJavaMethod(rt, BooleanKind, "install", "()Z", args, count, cachedMethodId);
24
+ }
25
+
26
+ NativeMarcusModuleSpecJSI::NativeMarcusModuleSpecJSI(
27
+ const JavaTurboModule::InitParams &params
28
+ )
29
+ : JavaTurboModule(params) {
30
+ methodMap_["install"] =
31
+ MethodMetadata{0, __hostFunction_NativeMarcusModuleSpecJSI_install};
32
+ }
33
+
34
+ std::shared_ptr<TurboModule>
35
+ RNMarcusSpec_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams &params) {
36
+ if (moduleName == "MarcusModule") {
37
+ return std::make_shared<NativeMarcusModuleSpecJSI>(params);
38
+ }
39
+ return nullptr;
40
+ }
41
+
42
+ } // namespace react
43
+ } // namespace facebook
@@ -0,0 +1,36 @@
1
+
2
+ /**
3
+ * This code was generated by
4
+ * [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
5
+ *
6
+ * Do not edit this file as changes may cause incorrect behavior and will be
7
+ * lost once the code is regenerated.
8
+ *
9
+ * @generated by codegen project: GenerateModuleJniH.js
10
+ */
11
+
12
+ #pragma once
13
+
14
+ #include <ReactCommon/JavaTurboModule.h>
15
+ #include <ReactCommon/TurboModule.h>
16
+ #include <jsi/jsi.h>
17
+
18
+ #include <react/renderer/components/RNMarcusSpec/MarcusTextInputDecoratorViewComponentDescriptor.h>
19
+
20
+ namespace facebook {
21
+ namespace react {
22
+
23
+ /**
24
+ * JNI C++ class for module 'NativeMarcusModule'
25
+ */
26
+ class JSI_EXPORT NativeMarcusModuleSpecJSI : public JavaTurboModule {
27
+ public:
28
+ NativeMarcusModuleSpecJSI(const JavaTurboModule::InitParams &params);
29
+ };
30
+
31
+ JSI_EXPORT
32
+ std::shared_ptr<TurboModule>
33
+ RNMarcusSpec_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams &params);
34
+
35
+ } // namespace react
36
+ } // namespace facebook