react-native-marcus 0.1.1 → 0.2.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 (294) hide show
  1. package/README.md +220 -63
  2. package/RNMarcus.podspec +6 -0
  3. package/android/src/main/java/app/getbullet/marcus/MarcusPackage.kt +2 -1
  4. package/android/src/main/java/app/getbullet/marcus/MarcusTextDecoratorView.kt +168 -0
  5. package/android/src/main/java/app/getbullet/marcus/MarcusTextDecoratorViewManager.kt +38 -0
  6. package/android/src/main/java/app/getbullet/marcus/MarcusTextDecoratorViewManagerSpec.kt +19 -0
  7. package/android/src/main/java/app/getbullet/marcus/MarcusTextInputDecoratorView.kt +23 -1
  8. package/android/src/main/java/app/getbullet/marcus/MarkdownBackgroundPainter.kt +147 -0
  9. package/android/src/main/java/app/getbullet/marcus/MarkdownBackgroundPass.kt +19 -0
  10. package/android/src/main/java/app/getbullet/marcus/MarkdownCopy.kt +87 -0
  11. package/android/src/main/java/app/getbullet/marcus/MarkdownFormatter.kt +652 -113
  12. package/android/src/main/java/app/getbullet/marcus/MarkdownRanges.kt +47 -0
  13. package/android/src/main/java/app/getbullet/marcus/MarkdownStyle.kt +140 -61
  14. package/android/src/main/java/app/getbullet/marcus/MarkdownUtils.kt +37 -7
  15. package/android/src/main/java/app/getbullet/marcus/spans/MarkdownAbsoluteLineHeightSpan.kt +48 -0
  16. package/android/src/main/java/app/getbullet/marcus/spans/MarkdownBackgroundSpan.kt +102 -48
  17. package/android/src/main/java/app/getbullet/marcus/spans/MarkdownBlockIndentSpan.kt +22 -4
  18. package/android/src/main/java/app/getbullet/marcus/spans/MarkdownBulletSpan.kt +78 -0
  19. package/android/src/main/java/app/getbullet/marcus/spans/MarkdownCodeBlockSpan.kt +177 -0
  20. package/android/src/main/java/app/getbullet/marcus/spans/MarkdownFontStyleSpan.kt +32 -0
  21. package/android/src/main/java/app/getbullet/marcus/spans/MarkdownFontWeightSpan.kt +34 -0
  22. package/android/src/main/java/app/getbullet/marcus/spans/MarkdownGapSpan.kt +24 -11
  23. package/android/src/main/java/app/getbullet/marcus/spans/MarkdownLetterSpacingSpan.kt +32 -0
  24. package/android/src/main/java/app/getbullet/marcus/spans/MarkdownTextShadowSpan.kt +32 -0
  25. package/android/src/main/new_arch/CMakeLists.txt +17 -0
  26. package/android/src/main/new_arch/RNMarcusSpec.h +1 -0
  27. package/android/src/main/new_arch/react/renderer/components/RNMarcusSpec/MarcusTextDecoratorShadowNode.cpp +235 -0
  28. package/android/src/main/new_arch/react/renderer/components/RNMarcusSpec/MarcusTextDecoratorShadowNode.h +62 -0
  29. package/android/src/reactNativeVersionPatch/CustomMountingManager/81/app/getbullet/marcus/CustomFabricUIManager.java +22 -3
  30. package/android/src/reactNativeVersionPatch/CustomMountingManager/latest/app/getbullet/marcus/CustomFabricUIManager.java +22 -3
  31. package/android/src/test/java/app/getbullet/marcus/MarkdownCopyTest.kt +69 -0
  32. package/android/src/test/java/app/getbullet/marcus/MarkdownFormatterTest.kt +170 -25
  33. package/android/src/test/java/app/getbullet/marcus/RenderModel.kt +22 -5
  34. package/android/src/test/java/app/getbullet/marcus/spans/MarkdownCodeBlockSpanTest.kt +91 -0
  35. package/android/src/test/resources/render-model.txt +221 -16
  36. package/apple/MarcusSwizzle.h +25 -0
  37. package/apple/MarcusTextDecoratorComponentView.h +22 -0
  38. package/apple/MarcusTextDecoratorComponentView.mm +72 -0
  39. package/apple/MarcusTextDecoratorShadowNode.h +62 -0
  40. package/apple/MarcusTextDecoratorShadowNode.mm +192 -0
  41. package/apple/MarcusTextDecoratorViewManager.h +4 -0
  42. package/apple/MarcusTextDecoratorViewManager.mm +11 -0
  43. package/apple/MarcusTextInputDecoratorComponentView.mm +1 -1
  44. package/apple/MarcusTextInputDecoratorShadowNode.mm +1 -1
  45. package/apple/MarcusTextLayoutManager.h +40 -0
  46. package/apple/MarcusTextLayoutManager.mm +173 -0
  47. package/apple/MarkdownAttributes.h +23 -2
  48. package/apple/MarkdownAttributes.m +6 -0
  49. package/apple/MarkdownCopy.swift +63 -0
  50. package/apple/MarkdownDecorator.swift +2 -2
  51. package/apple/MarkdownFormatter+React.swift +23 -0
  52. package/apple/MarkdownFormatter.swift +869 -148
  53. package/apple/MarkdownParagraphLayoutManager.swift +455 -0
  54. package/apple/MarkdownSwiftInterop.h +0 -1
  55. package/apple/MarkdownTextBackground.swift +59 -1
  56. package/apple/MarkdownTextFieldObserver.swift +2 -2
  57. package/apple/MarkdownTextLayoutFragment.swift +159 -33
  58. package/apple/MarkdownTextLayoutManagerDelegate.swift +67 -3
  59. package/apple/MarkdownTextStorageDelegate.swift +2 -2
  60. package/apple/MarkdownTextViewObserver.swift +2 -2
  61. package/apple/MarkdownUtils.swift +38 -0
  62. package/apple/MarkdownWritingDirection.swift +132 -0
  63. package/apple/RCTMarcusStyle+Codegen.h +115 -9
  64. package/apple/RCTMarcusStyle.h +128 -31
  65. package/apple/RCTMarcusStyle.m +48 -0
  66. package/apple/RCTParagraphComponentView+Marcus.h +17 -0
  67. package/apple/RCTParagraphComponentView+Marcus.mm +38 -0
  68. package/apple/RCTTextInputComponentView+Marcus.mm +1 -25
  69. package/cpp/react/renderer/components/RNMarcusSpec/MarcusTextDecoratorState.h +37 -0
  70. package/cpp/react/renderer/components/RNMarcusSpec/MarcusTextDecoratorViewComponentDescriptor.h +17 -0
  71. package/lib/commonjs/MarcusTextDecoratorViewNativeComponent.ts +199 -0
  72. package/lib/commonjs/MarcusTextInputDecoratorViewNativeComponent.ts +145 -58
  73. package/lib/commonjs/MarkdownText.js +330 -0
  74. package/lib/commonjs/MarkdownText.js.map +1 -0
  75. package/lib/commonjs/MarkdownText.web.js +529 -0
  76. package/lib/commonjs/MarkdownText.web.js.map +1 -0
  77. package/lib/commonjs/MarkdownTextInput.js +22 -27
  78. package/lib/commonjs/MarkdownTextInput.js.map +1 -1
  79. package/lib/commonjs/MarkdownTextInput.web.js +12 -7
  80. package/lib/commonjs/MarkdownTextInput.web.js.map +1 -1
  81. package/lib/commonjs/atomUtils.js +112 -0
  82. package/lib/commonjs/atomUtils.js.map +1 -0
  83. package/lib/commonjs/childrenUtils.js +36 -0
  84. package/lib/commonjs/childrenUtils.js.map +1 -0
  85. package/lib/commonjs/index.js +8 -7
  86. package/lib/commonjs/index.js.map +1 -1
  87. package/lib/commonjs/math/environment.js +69 -0
  88. package/lib/commonjs/math/environment.js.map +1 -0
  89. package/lib/commonjs/math/index.js +61 -0
  90. package/lib/commonjs/math/index.js.map +1 -0
  91. package/lib/commonjs/math/mathjax.js +548 -0
  92. package/lib/commonjs/math/mathjax.js.map +1 -0
  93. package/lib/commonjs/metro.js +172 -0
  94. package/lib/commonjs/metro.js.map +1 -0
  95. package/lib/commonjs/parser/index.d.ts +3 -0
  96. package/lib/commonjs/parser/index.js +450 -42
  97. package/lib/commonjs/parser/index.js.map +4 -4
  98. package/lib/commonjs/stripUtils.js +743 -0
  99. package/lib/commonjs/stripUtils.js.map +1 -0
  100. package/lib/commonjs/styleUtils.js +194 -23
  101. package/lib/commonjs/styleUtils.js.map +1 -1
  102. package/lib/commonjs/web/MarkdownElements.css +67 -0
  103. package/lib/commonjs/web/MarkdownTextInput.css +9 -7
  104. package/lib/commonjs/web/utils/blockLayout.js +95 -7
  105. package/lib/commonjs/web/utils/blockLayout.js.map +1 -1
  106. package/lib/commonjs/web/utils/blockUtils.js +327 -54
  107. package/lib/commonjs/web/utils/blockUtils.js.map +1 -1
  108. package/lib/commonjs/web/utils/elementUtils.js +80 -0
  109. package/lib/commonjs/web/utils/elementUtils.js.map +1 -0
  110. package/lib/commonjs/web/utils/parserUtils.js +84 -28
  111. package/lib/commonjs/web/utils/parserUtils.js.map +1 -1
  112. package/lib/commonjs/web/utils/treeUtils.js +6 -0
  113. package/lib/commonjs/web/utils/treeUtils.js.map +1 -1
  114. package/lib/commonjs/web/utils/webStyleUtils.js +25 -5
  115. package/lib/commonjs/web/utils/webStyleUtils.js.map +1 -1
  116. package/lib/module/MarcusTextDecoratorViewNativeComponent.ts +199 -0
  117. package/lib/module/MarcusTextInputDecoratorViewNativeComponent.ts +145 -58
  118. package/lib/module/MarkdownText.js +325 -0
  119. package/lib/module/MarkdownText.js.map +1 -0
  120. package/lib/module/MarkdownText.web.js +524 -0
  121. package/lib/module/MarkdownText.web.js.map +1 -0
  122. package/lib/module/MarkdownTextInput.js +24 -29
  123. package/lib/module/MarkdownTextInput.js.map +1 -1
  124. package/lib/module/MarkdownTextInput.web.js +12 -7
  125. package/lib/module/MarkdownTextInput.web.js.map +1 -1
  126. package/lib/module/atomUtils.js +106 -0
  127. package/lib/module/atomUtils.js.map +1 -0
  128. package/lib/module/childrenUtils.js +33 -0
  129. package/lib/module/childrenUtils.js.map +1 -0
  130. package/lib/module/index.js +1 -1
  131. package/lib/module/index.js.map +1 -1
  132. package/lib/module/math/environment.js +67 -0
  133. package/lib/module/math/environment.js.map +1 -0
  134. package/lib/module/math/index.js +56 -0
  135. package/lib/module/math/index.js.map +1 -0
  136. package/lib/module/math/mathjax.js +541 -0
  137. package/lib/module/math/mathjax.js.map +1 -0
  138. package/lib/module/metro.js +169 -0
  139. package/lib/module/metro.js.map +1 -0
  140. package/lib/module/parser/index.d.ts +3 -0
  141. package/lib/module/parser/index.js +450 -42
  142. package/lib/module/parser/index.js.map +4 -4
  143. package/lib/module/stripUtils.js +739 -0
  144. package/lib/module/stripUtils.js.map +1 -0
  145. package/lib/module/styleUtils.js +196 -25
  146. package/lib/module/styleUtils.js.map +1 -1
  147. package/lib/module/web/MarkdownElements.css +67 -0
  148. package/lib/module/web/MarkdownTextInput.css +9 -7
  149. package/lib/module/web/utils/blockLayout.js +94 -8
  150. package/lib/module/web/utils/blockLayout.js.map +1 -1
  151. package/lib/module/web/utils/blockUtils.js +328 -56
  152. package/lib/module/web/utils/blockUtils.js.map +1 -1
  153. package/lib/module/web/utils/elementUtils.js +75 -0
  154. package/lib/module/web/utils/elementUtils.js.map +1 -0
  155. package/lib/module/web/utils/parserUtils.js +86 -30
  156. package/lib/module/web/utils/parserUtils.js.map +1 -1
  157. package/lib/module/web/utils/treeUtils.js +6 -0
  158. package/lib/module/web/utils/treeUtils.js.map +1 -1
  159. package/lib/module/web/utils/webStyleUtils.js +25 -5
  160. package/lib/module/web/utils/webStyleUtils.js.map +1 -1
  161. package/lib/typescript/commonjs/e2e/links.test.d.ts +2 -0
  162. package/lib/typescript/commonjs/e2e/links.test.d.ts.map +1 -0
  163. package/lib/typescript/commonjs/src/MarcusTextDecoratorViewNativeComponent.d.ts +93 -0
  164. package/lib/typescript/commonjs/src/MarcusTextDecoratorViewNativeComponent.d.ts.map +1 -0
  165. package/lib/typescript/commonjs/src/MarcusTextInputDecoratorViewNativeComponent.d.ts +64 -51
  166. package/lib/typescript/commonjs/src/MarcusTextInputDecoratorViewNativeComponent.d.ts.map +1 -1
  167. package/lib/typescript/commonjs/src/MarkdownText.d.ts +127 -0
  168. package/lib/typescript/commonjs/src/MarkdownText.d.ts.map +1 -0
  169. package/lib/typescript/commonjs/src/MarkdownText.web.d.ts +126 -0
  170. package/lib/typescript/commonjs/src/MarkdownText.web.d.ts.map +1 -0
  171. package/lib/typescript/commonjs/src/MarkdownTextInput.d.ts +23 -1
  172. package/lib/typescript/commonjs/src/MarkdownTextInput.d.ts.map +1 -1
  173. package/lib/typescript/commonjs/src/MarkdownTextInput.web.d.ts +26 -4
  174. package/lib/typescript/commonjs/src/MarkdownTextInput.web.d.ts.map +1 -1
  175. package/lib/typescript/commonjs/src/atomUtils.d.ts +58 -0
  176. package/lib/typescript/commonjs/src/atomUtils.d.ts.map +1 -0
  177. package/lib/typescript/commonjs/src/childrenUtils.d.ts +12 -0
  178. package/lib/typescript/commonjs/src/childrenUtils.d.ts.map +1 -0
  179. package/lib/typescript/commonjs/src/commonTypes.d.ts +39 -3
  180. package/lib/typescript/commonjs/src/commonTypes.d.ts.map +1 -1
  181. package/lib/typescript/commonjs/src/index.d.ts +2 -1
  182. package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
  183. package/lib/typescript/commonjs/src/math/environment.d.ts +7 -0
  184. package/lib/typescript/commonjs/src/math/environment.d.ts.map +1 -0
  185. package/lib/typescript/commonjs/src/math/index.d.ts +64 -0
  186. package/lib/typescript/commonjs/src/math/index.d.ts.map +1 -0
  187. package/lib/typescript/commonjs/src/math/mathjax.d.ts +63 -0
  188. package/lib/typescript/commonjs/src/math/mathjax.d.ts.map +1 -0
  189. package/lib/typescript/commonjs/src/metro.d.ts +59 -0
  190. package/lib/typescript/commonjs/src/metro.d.ts.map +1 -0
  191. package/lib/typescript/commonjs/src/parser/index.d.ts +3 -3
  192. package/lib/typescript/commonjs/src/parser/index.d.ts.map +1 -1
  193. package/lib/typescript/commonjs/src/parser/micromark-extension-mentions.d.ts.map +1 -1
  194. package/lib/typescript/commonjs/src/rangeUtils.d.ts +1 -1
  195. package/lib/typescript/commonjs/src/stripUtils.d.ts +108 -0
  196. package/lib/typescript/commonjs/src/stripUtils.d.ts.map +1 -0
  197. package/lib/typescript/commonjs/src/styleUtils.d.ts +62 -4
  198. package/lib/typescript/commonjs/src/styleUtils.d.ts.map +1 -1
  199. package/lib/typescript/commonjs/src/web/utils/blockLayout.d.ts +32 -4
  200. package/lib/typescript/commonjs/src/web/utils/blockLayout.d.ts.map +1 -1
  201. package/lib/typescript/commonjs/src/web/utils/blockUtils.d.ts +20 -8
  202. package/lib/typescript/commonjs/src/web/utils/blockUtils.d.ts.map +1 -1
  203. package/lib/typescript/commonjs/src/web/utils/elementUtils.d.ts +37 -0
  204. package/lib/typescript/commonjs/src/web/utils/elementUtils.d.ts.map +1 -0
  205. package/lib/typescript/commonjs/src/web/utils/parserUtils.d.ts +5 -5
  206. package/lib/typescript/commonjs/src/web/utils/parserUtils.d.ts.map +1 -1
  207. package/lib/typescript/commonjs/src/web/utils/treeUtils.d.ts +6 -1
  208. package/lib/typescript/commonjs/src/web/utils/treeUtils.d.ts.map +1 -1
  209. package/lib/typescript/commonjs/src/web/utils/webStyleUtils.d.ts +2 -2
  210. package/lib/typescript/commonjs/src/web/utils/webStyleUtils.d.ts.map +1 -1
  211. package/lib/typescript/module/e2e/links.test.d.ts +2 -0
  212. package/lib/typescript/module/e2e/links.test.d.ts.map +1 -0
  213. package/lib/typescript/module/src/MarcusTextDecoratorViewNativeComponent.d.ts +93 -0
  214. package/lib/typescript/module/src/MarcusTextDecoratorViewNativeComponent.d.ts.map +1 -0
  215. package/lib/typescript/module/src/MarcusTextInputDecoratorViewNativeComponent.d.ts +64 -51
  216. package/lib/typescript/module/src/MarcusTextInputDecoratorViewNativeComponent.d.ts.map +1 -1
  217. package/lib/typescript/module/src/MarkdownText.d.ts +127 -0
  218. package/lib/typescript/module/src/MarkdownText.d.ts.map +1 -0
  219. package/lib/typescript/module/src/MarkdownText.web.d.ts +126 -0
  220. package/lib/typescript/module/src/MarkdownText.web.d.ts.map +1 -0
  221. package/lib/typescript/module/src/MarkdownTextInput.d.ts +23 -1
  222. package/lib/typescript/module/src/MarkdownTextInput.d.ts.map +1 -1
  223. package/lib/typescript/module/src/MarkdownTextInput.web.d.ts +26 -4
  224. package/lib/typescript/module/src/MarkdownTextInput.web.d.ts.map +1 -1
  225. package/lib/typescript/module/src/atomUtils.d.ts +58 -0
  226. package/lib/typescript/module/src/atomUtils.d.ts.map +1 -0
  227. package/lib/typescript/module/src/childrenUtils.d.ts +12 -0
  228. package/lib/typescript/module/src/childrenUtils.d.ts.map +1 -0
  229. package/lib/typescript/module/src/commonTypes.d.ts +39 -3
  230. package/lib/typescript/module/src/commonTypes.d.ts.map +1 -1
  231. package/lib/typescript/module/src/index.d.ts +2 -1
  232. package/lib/typescript/module/src/index.d.ts.map +1 -1
  233. package/lib/typescript/module/src/math/environment.d.ts +7 -0
  234. package/lib/typescript/module/src/math/environment.d.ts.map +1 -0
  235. package/lib/typescript/module/src/math/index.d.ts +64 -0
  236. package/lib/typescript/module/src/math/index.d.ts.map +1 -0
  237. package/lib/typescript/module/src/math/mathjax.d.ts +63 -0
  238. package/lib/typescript/module/src/math/mathjax.d.ts.map +1 -0
  239. package/lib/typescript/module/src/metro.d.ts +59 -0
  240. package/lib/typescript/module/src/metro.d.ts.map +1 -0
  241. package/lib/typescript/module/src/parser/index.d.ts +3 -3
  242. package/lib/typescript/module/src/parser/index.d.ts.map +1 -1
  243. package/lib/typescript/module/src/parser/micromark-extension-mentions.d.ts.map +1 -1
  244. package/lib/typescript/module/src/rangeUtils.d.ts +1 -1
  245. package/lib/typescript/module/src/stripUtils.d.ts +108 -0
  246. package/lib/typescript/module/src/stripUtils.d.ts.map +1 -0
  247. package/lib/typescript/module/src/styleUtils.d.ts +62 -4
  248. package/lib/typescript/module/src/styleUtils.d.ts.map +1 -1
  249. package/lib/typescript/module/src/web/utils/blockLayout.d.ts +32 -4
  250. package/lib/typescript/module/src/web/utils/blockLayout.d.ts.map +1 -1
  251. package/lib/typescript/module/src/web/utils/blockUtils.d.ts +20 -8
  252. package/lib/typescript/module/src/web/utils/blockUtils.d.ts.map +1 -1
  253. package/lib/typescript/module/src/web/utils/elementUtils.d.ts +37 -0
  254. package/lib/typescript/module/src/web/utils/elementUtils.d.ts.map +1 -0
  255. package/lib/typescript/module/src/web/utils/parserUtils.d.ts +5 -5
  256. package/lib/typescript/module/src/web/utils/parserUtils.d.ts.map +1 -1
  257. package/lib/typescript/module/src/web/utils/treeUtils.d.ts +6 -1
  258. package/lib/typescript/module/src/web/utils/treeUtils.d.ts.map +1 -1
  259. package/lib/typescript/module/src/web/utils/webStyleUtils.d.ts +2 -2
  260. package/lib/typescript/module/src/web/utils/webStyleUtils.d.ts.map +1 -1
  261. package/package.json +29 -2
  262. package/react-native.config.js +8 -1
  263. package/src/MarcusTextDecoratorViewNativeComponent.ts +199 -0
  264. package/src/MarcusTextInputDecoratorViewNativeComponent.ts +145 -58
  265. package/src/MarkdownText.tsx +472 -0
  266. package/src/MarkdownText.web.tsx +668 -0
  267. package/src/MarkdownTextInput.tsx +42 -38
  268. package/src/MarkdownTextInput.web.tsx +36 -13
  269. package/src/atomUtils.ts +112 -0
  270. package/src/childrenUtils.ts +39 -0
  271. package/src/commonTypes.ts +69 -9
  272. package/src/index.tsx +2 -1
  273. package/src/math/environment.ts +68 -0
  274. package/src/math/index.ts +78 -0
  275. package/src/math/mathjax.ts +604 -0
  276. package/src/metro.ts +238 -0
  277. package/src/parser/index.ts +175 -10
  278. package/src/parser/micromark-extension-mentions.ts +104 -11
  279. package/src/stripUtils.ts +919 -0
  280. package/src/styleUtils.ts +290 -26
  281. package/src/web/MarkdownElements.css +67 -0
  282. package/src/web/MarkdownTextInput.css +9 -7
  283. package/src/web/utils/blockLayout.ts +124 -14
  284. package/src/web/utils/blockUtils.ts +365 -59
  285. package/src/web/utils/elementUtils.ts +87 -0
  286. package/src/web/utils/parserUtils.ts +119 -31
  287. package/src/web/utils/treeUtils.ts +6 -1
  288. package/src/web/utils/webStyleUtils.ts +32 -8
  289. package/android/src/main/java/app/getbullet/marcus/spans/MarkdownBackgroundColorSpan.kt +0 -6
  290. package/android/src/main/java/app/getbullet/marcus/spans/MarkdownBoldSpan.kt +0 -6
  291. package/android/src/main/java/app/getbullet/marcus/spans/MarkdownItalicSpan.kt +0 -6
  292. package/apple/RCTMarcusStyle+Codegen.mm +0 -64
  293. package/apple/RCTMarcusUtils.h +0 -26
  294. package/apple/RCTMarcusUtils.mm +0 -26
@@ -0,0 +1,199 @@
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
+ import type { MarkdownStyle as TextInputMarkdownStyle } from "./MarcusTextInputDecoratorViewNativeComponent"
7
+
8
+ // Codegen parses each `*NativeComponent` file on its own and does not follow
9
+ // imports, so the style has to be spelled out again rather than shared with
10
+ // `MarcusTextInputDecoratorViewNativeComponent`. The assertion further down is
11
+ // what keeps the copy honest: the two have to stay assignable in both
12
+ // directions or `tsc --noEmit` fails.
13
+
14
+ // The text attributes one styled run can carry: the subset of React Native's
15
+ // `TextStyle` that survives as an `NSAttributedString` attribute on iOS, as a
16
+ // span on Android, and as a declaration on an inline element on the web.
17
+ //
18
+ // Everything here is optional and everything unset is inherited, which is what a
19
+ // run of markdown wants -- a mention that only names a colour keeps the face,
20
+ // the size and the weight of the prose it sits in. Native reads "unset" off the
21
+ // zero value: an empty string, a null colour, a zero length. That costs nothing,
22
+ // because a zero-length `letterSpacing`, `lineHeight` or `fontSize` means the
23
+ // same as leaving it out.
24
+ //
25
+ // `fontWeight`, `fontStyle`, `textDecorationLine` and `textDecorationStyle`
26
+ // arrive as plain strings rather than as unions. Codegen turns a union of string
27
+ // literals into an enum named after the prop it was found on, so the same
28
+ // spelling on twelve entries would become twelve unrelated C++ types and the one
29
+ // conversion template in `RCTMarcusStyle+Codegen.h` could not read any of them.
30
+ // The public type in `styleUtils` is the narrow one; this is the wire.
31
+ interface MarkdownTextStyle {
32
+ color?: ColorValue
33
+ fontFamily?: string
34
+ fontSize?: Float
35
+ fontStyle?: string
36
+ fontWeight?: string
37
+ letterSpacing?: Float
38
+ // Applies to whole lines: the platforms set it on the paragraph, so a range
39
+ // covering part of a line raises the height of all of it.
40
+ lineHeight?: Float
41
+ textDecorationLine?: string
42
+ // iOS and web only. Android draws an underline and a strikethrough in the text
43
+ // colour and offers no way to say otherwise.
44
+ textDecorationColor?: ColorValue
45
+ textDecorationStyle?: string
46
+ textShadowColor?: ColorValue
47
+ textShadowOffset?: { width: Float; height: Float }
48
+ textShadowRadius?: Float
49
+ }
50
+
51
+ // A run drawn as a box rather than as a background behind the glyphs: an inline
52
+ // or fenced run of code, or a mention's pill. Rounded, optionally bordered, with
53
+ // room inside it and around it, on top of whatever text attributes it carries.
54
+ //
55
+ // What the room holds open differs, because a block owns its lines and a run
56
+ // shares one. A block's padding and margin are held open on the leading edge and
57
+ // vertically, and a line long enough to wrap reaches the padding on the trailing
58
+ // edge rather than stopping in front of it: neither platform can reserve a
59
+ // trailing indent per paragraph. An inline run holds its padding and margin open
60
+ // on both sides, by widening the characters it starts and ends with, and grows
61
+ // into the line's own spacing above and below rather than pushing the lines
62
+ // apart.
63
+ //
64
+ // `padding` is the fallback for both axes; `paddingHorizontal` and
65
+ // `paddingVertical` win over it where they are set, and `margin` the same. A
66
+ // fenced block usually wants more room above and below than beside it, and one
67
+ // number cannot say that.
68
+ interface MarkdownBoxStyle extends MarkdownTextStyle {
69
+ backgroundColor?: ColorValue
70
+ borderColor?: ColorValue
71
+ borderWidth?: Float
72
+ borderRadius?: Float
73
+ padding?: Float
74
+ paddingHorizontal?: Float
75
+ paddingVertical?: Float
76
+ margin?: Float
77
+ marginHorizontal?: Float
78
+ marginVertical?: Float
79
+ }
80
+
81
+ interface MarkdownHeadingStyle extends MarkdownTextStyle {
82
+ // Each level down multiplies the one above, so level N is
83
+ // fontSize * scale^(N - 1). Six levels, matching HTML.
84
+ scale?: Float
85
+ }
86
+
87
+ // The bar beside a quoted block, the indent it opens, and the text inside it.
88
+ //
89
+ // `marginStart` and `paddingStart` rather than `marginLeft`/`paddingLeft`
90
+ // because the gutter opens on the line's leading edge, which is the right-hand
91
+ // side of a right-to-left paragraph. Both platforms already indent from the
92
+ // leading edge -- `NSParagraphStyle`'s head indent and Android's leading margin
93
+ // are both writing-direction relative -- so the names now say what was always
94
+ // drawn, and the web builder resolves them to `padding-inline-start`.
95
+ interface MarkdownBlockquoteStyle extends MarkdownTextStyle {
96
+ borderColor?: ColorValue
97
+ borderWidth?: Float
98
+ // Rounds the bar's ends. A bar whose radius is half its width comes out a
99
+ // capsule.
100
+ borderRadius?: Float
101
+ marginStart?: Float
102
+ paddingStart?: Float
103
+ }
104
+
105
+ // Indent, and the marker that sits in the gutter it opens. Kept as two separate
106
+ // entries so a renderer can style ordered and unordered lists differently, which
107
+ // is exactly what `markerScale` ends up meaning: an ordered item's number is
108
+ // text, an unordered item's bullet is a shape.
109
+ //
110
+ // Both markers are sized from the base font -- the size the wrapped `Text`
111
+ // renders at -- rather than from a size of their own, so a list marks itself in
112
+ // proportion to the prose it marks however that prose is sized. `marker` styles
113
+ // the marker itself, and what it leaves unset falls back to `syntax`, which is
114
+ // where a marker's colour came from before this entry existed.
115
+ //
116
+ // Only `MarkdownText` draws them. An input shows the marker you typed, in the
117
+ // base font, because it is text you are editing rather than a rendering of it.
118
+ interface MarkdownListStyle {
119
+ marginStart?: Float
120
+ paddingStart?: Float
121
+ // An ordered item's number is drawn at this fraction of the base font size; an
122
+ // unordered item's bullet takes it as a diameter, as a fraction of the same.
123
+ markerScale?: Float
124
+ // Room held open either side of the marker, between the gutter and the text.
125
+ markerPadding?: Float
126
+ marker?: MarkdownTextStyle
127
+ }
128
+
129
+ // Left as the two values it always was rather than folded into
130
+ // `MarkdownTextStyle`: an emoji run is swapped onto a font that has the glyph
131
+ // and sized to sit with the prose, and nothing else about it is worth saying.
132
+ interface MarkdownEmojiStyle {
133
+ fontSize?: Float
134
+ fontFamily?: string
135
+ }
136
+
137
+ interface MarkdownStyle {
138
+ syntax: MarkdownTextStyle
139
+ emoji: MarkdownEmojiStyle
140
+ link: MarkdownTextStyle
141
+ strong: MarkdownTextStyle
142
+ emphasis: MarkdownTextStyle
143
+ strikethrough: MarkdownTextStyle
144
+ heading: MarkdownHeadingStyle
145
+ blockquote: MarkdownBlockquoteStyle
146
+ orderedList: MarkdownListStyle
147
+ unorderedList: MarkdownListStyle
148
+ code: MarkdownBoxStyle
149
+ pre: MarkdownBoxStyle
150
+ // A name with an `@` in front of it, drawn as a pill: the same inline box an
151
+ // inline run of code sits in, and so the same lengths.
152
+ mention: MarkdownBoxStyle
153
+ }
154
+
155
+ // `MarkdownRange` with `depth` filled in: codegen has no optional numbers, and
156
+ // the formatters read a missing depth as zero anyway.
157
+ interface MarkdownRangeStruct {
158
+ type: string
159
+ start: Int32
160
+ length: Int32
161
+ depth: Int32
162
+ }
163
+
164
+ // What one placeholder character copies as. `index` is its offset in the
165
+ // stripped text -- the same string the ranges are measured against -- and
166
+ // `text` is the markdown it was written as, which is what the platform puts on
167
+ // the clipboard in its place.
168
+ interface MarkdownSubstitutionStruct {
169
+ index: Int32
170
+ text: string
171
+ }
172
+
173
+ interface NativeProps extends ViewProps {
174
+ markdownStyle: MarkdownStyle
175
+ // The parse result, already stripped of syntax and remapped onto the text the
176
+ // child `Text` is rendering. Unlike the input decorator there is no parser to
177
+ // register: a `Text`'s content only ever changes by a re-render, so JS always
178
+ // knows the string and can hand over finished ranges.
179
+ ranges: ReadonlyArray<MarkdownRangeStruct>
180
+ // Every drawing in the text, and the source it copies as. A view mounted in a
181
+ // `Text` is one U+FFFC in the string the platform lays out, and that is what
182
+ // both platforms would otherwise hand to the clipboard: an equation copies as
183
+ // an empty box. Only the display needs this -- an input has the source on the
184
+ // screen already, and copies it by doing nothing.
185
+ substitutions: ReadonlyArray<MarkdownSubstitutionStruct>
186
+ }
187
+
188
+ type Assignable<A extends B, B> = A
189
+
190
+ type StyleMatchesTextInput = [
191
+ Assignable<MarkdownStyle, TextInputMarkdownStyle>,
192
+ Assignable<TextInputMarkdownStyle, MarkdownStyle>,
193
+ ]
194
+
195
+ export default codegenNativeComponent<NativeProps>("MarcusTextDecoratorView", {
196
+ interfaceOnly: true,
197
+ })
198
+
199
+ export type { MarkdownRangeStruct, MarkdownSubstitutionStruct, StyleMatchesTextInput }
@@ -3,66 +3,145 @@ import type { ColorValue, ViewProps } from "react-native"
3
3
 
4
4
  import type { Float, Int32 } from "react-native/Libraries/Types/CodegenTypes"
5
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
6
+ // The text attributes one styled run can carry: the subset of React Native's
7
+ // `TextStyle` that survives as an `NSAttributedString` attribute on iOS, as a
8
+ // span on Android, and as a declaration on an inline element on the web.
9
+ //
10
+ // Everything here is optional and everything unset is inherited, which is what a
11
+ // run of markdown wants -- a mention that only names a colour keeps the face,
12
+ // the size and the weight of the prose it sits in. Native reads "unset" off the
13
+ // zero value: an empty string, a null colour, a zero length. That costs nothing,
14
+ // because a zero-length `letterSpacing`, `lineHeight` or `fontSize` means the
15
+ // same as leaving it out.
16
+ //
17
+ // `fontWeight`, `fontStyle`, `textDecorationLine` and `textDecorationStyle`
18
+ // arrive as plain strings rather than as unions. Codegen turns a union of string
19
+ // literals into an enum named after the prop it was found on, so the same
20
+ // spelling on twelve entries would become twelve unrelated C++ types and the one
21
+ // conversion template in `RCTMarcusStyle+Codegen.h` could not read any of them.
22
+ // The public type in `styleUtils` is the narrow one; this is the wire.
23
+ interface MarkdownTextStyle {
24
+ color?: ColorValue
25
+ fontFamily?: string
26
+ fontSize?: Float
27
+ fontStyle?: string
28
+ fontWeight?: string
29
+ letterSpacing?: Float
30
+ // Applies to whole lines: the platforms set it on the paragraph, so a range
31
+ // covering part of a line raises the height of all of it.
32
+ lineHeight?: Float
33
+ textDecorationLine?: string
34
+ // iOS and web only. Android draws an underline and a strikethrough in the text
35
+ // colour and offers no way to say otherwise.
36
+ textDecorationColor?: ColorValue
37
+ textDecorationStyle?: string
38
+ textShadowColor?: ColorValue
39
+ textShadowOffset?: { width: Float; height: Float }
40
+ textShadowRadius?: Float
41
+ }
42
+
43
+ // A run drawn as a box rather than as a background behind the glyphs: an inline
44
+ // or fenced run of code, or a mention's pill. Rounded, optionally bordered, with
45
+ // room inside it and around it, on top of whatever text attributes it carries.
46
+ //
47
+ // What the room holds open differs, because a block owns its lines and a run
48
+ // shares one. A block's padding and margin are held open on the leading edge and
49
+ // vertically, and a line long enough to wrap reaches the padding on the trailing
50
+ // edge rather than stopping in front of it: neither platform can reserve a
51
+ // trailing indent per paragraph. An inline run holds its padding and margin open
52
+ // on both sides, by widening the characters it starts and ends with, and grows
53
+ // into the line's own spacing above and below rather than pushing the lines
54
+ // apart.
55
+ //
56
+ // `padding` is the fallback for both axes; `paddingHorizontal` and
57
+ // `paddingVertical` win over it where they are set, and `margin` the same. A
58
+ // fenced block usually wants more room above and below than beside it, and one
59
+ // number cannot say that.
60
+ interface MarkdownBoxStyle extends MarkdownTextStyle {
61
+ backgroundColor?: ColorValue
62
+ borderColor?: ColorValue
63
+ borderWidth?: Float
64
+ borderRadius?: Float
65
+ padding?: Float
66
+ paddingHorizontal?: Float
67
+ paddingVertical?: Float
68
+ margin?: Float
69
+ marginHorizontal?: Float
70
+ marginVertical?: Float
71
+ }
72
+
73
+ interface MarkdownHeadingStyle extends MarkdownTextStyle {
74
+ // Each level down multiplies the one above, so level N is
75
+ // fontSize * scale^(N - 1). Six levels, matching HTML.
76
+ scale?: Float
77
+ }
78
+
79
+ // The bar beside a quoted block, the indent it opens, and the text inside it.
80
+ //
81
+ // `marginStart` and `paddingStart` rather than `marginLeft`/`paddingLeft`
82
+ // because the gutter opens on the line's leading edge, which is the right-hand
83
+ // side of a right-to-left paragraph. Both platforms already indent from the
84
+ // leading edge -- `NSParagraphStyle`'s head indent and Android's leading margin
85
+ // are both writing-direction relative -- so the names now say what was always
86
+ // drawn, and the web builder resolves them to `padding-inline-start`.
87
+ interface MarkdownBlockquoteStyle extends MarkdownTextStyle {
88
+ borderColor?: ColorValue
89
+ borderWidth?: Float
90
+ // Rounds the bar's ends. A bar whose radius is half its width comes out a
91
+ // capsule.
92
+ borderRadius?: Float
93
+ marginStart?: Float
94
+ paddingStart?: Float
95
+ }
96
+
97
+ // Indent, and the marker that sits in the gutter it opens. Kept as two separate
98
+ // entries so a renderer can style ordered and unordered lists differently, which
99
+ // is exactly what `markerScale` ends up meaning: an ordered item's number is
100
+ // text, an unordered item's bullet is a shape.
101
+ //
102
+ // Both markers are sized from the base font -- the size the wrapped `Text`
103
+ // renders at -- rather than from a size of their own, so a list marks itself in
104
+ // proportion to the prose it marks however that prose is sized. `marker` styles
105
+ // the marker itself, and what it leaves unset falls back to `syntax`, which is
106
+ // where a marker's colour came from before this entry existed.
107
+ //
108
+ // Only `MarkdownText` draws them. An input shows the marker you typed, in the
109
+ // base font, because it is text you are editing rather than a rendering of it.
110
+ interface MarkdownListStyle {
111
+ marginStart?: Float
112
+ paddingStart?: Float
113
+ // An ordered item's number is drawn at this fraction of the base font size; an
114
+ // unordered item's bullet takes it as a diameter, as a fraction of the same.
115
+ markerScale?: Float
116
+ // Room held open either side of the marker, between the gutter and the text.
117
+ markerPadding?: Float
118
+ marker?: MarkdownTextStyle
119
+ }
120
+
121
+ // Left as the two values it always was rather than folded into
122
+ // `MarkdownTextStyle`: an emoji run is swapped onto a font that has the glyph
123
+ // and sized to sit with the prose, and nothing else about it is worth saying.
124
+ interface MarkdownEmojiStyle {
125
+ fontSize?: Float
126
+ fontFamily?: string
14
127
  }
15
128
 
16
129
  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
- }
130
+ syntax: MarkdownTextStyle
131
+ emoji: MarkdownEmojiStyle
132
+ link: MarkdownTextStyle
133
+ strong: MarkdownTextStyle
134
+ emphasis: MarkdownTextStyle
135
+ strikethrough: MarkdownTextStyle
136
+ heading: MarkdownHeadingStyle
137
+ blockquote: MarkdownBlockquoteStyle
138
+ orderedList: MarkdownListStyle
139
+ unorderedList: MarkdownListStyle
140
+ code: MarkdownBoxStyle
141
+ pre: MarkdownBoxStyle
142
+ // A name with an `@` in front of it, drawn as a pill: the same inline box an
143
+ // inline run of code sits in, and so the same lengths.
144
+ mention: MarkdownBoxStyle
66
145
  }
67
146
 
68
147
  interface NativeProps extends ViewProps {
@@ -74,4 +153,12 @@ export default codegenNativeComponent<NativeProps>("MarcusTextInputDecoratorView
74
153
  interfaceOnly: true,
75
154
  })
76
155
 
77
- export type { MarkdownStyle }
156
+ export type {
157
+ MarkdownStyle,
158
+ MarkdownTextStyle,
159
+ MarkdownEmojiStyle,
160
+ MarkdownBoxStyle,
161
+ MarkdownHeadingStyle,
162
+ MarkdownBlockquoteStyle,
163
+ MarkdownListStyle,
164
+ }