react-native-marcus 0.1.0 → 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,529 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _reactNative = require("react-native");
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _reactDom = require("react-dom");
10
+ require("./web/MarkdownElements.css");
11
+ var _atomUtils = require("./atomUtils.js");
12
+ var _index = require("./math/index.js");
13
+ var _childrenUtils = require("./childrenUtils.js");
14
+ var _stripUtils = require("./stripUtils.js");
15
+ var _measureUtils = require("./web/utils/measureUtils.js");
16
+ var _parserUtils = require("./web/utils/parserUtils.js");
17
+ var _webStyleUtils = require("./web/utils/webStyleUtils.js");
18
+ var _index2 = require("./parser/index.js");
19
+ var _jsxRuntime = require("react/jsx-runtime");
20
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
21
+ /**
22
+ * What to show in place of an image.
23
+ *
24
+ * The native contract asks for a view with a definite size, because the text
25
+ * layout has to know how much room to leave before it lays the line out. The
26
+ * web has no such requirement -- the browser reflows around whatever turns up
27
+ * -- but the same callback runs on both, so write it for the stricter one.
28
+ *
29
+ * `inline` says whether the image shares its line with anything else, which is
30
+ * usually what decides how big it should be: alone on a line it is a figure,
31
+ * and in the middle of a sentence it is a badge. A block marker does not count
32
+ * as company, and another image does.
33
+ *
34
+ * Every string is always a string: an image written without a title is handed
35
+ * an empty one rather than nothing, so a caller never has to tell the two
36
+ * apart.
37
+ */
38
+
39
+ /**
40
+ * What to draw an SVG with.
41
+ *
42
+ * Handed a complete SVG document and the box it belongs in, and expected to
43
+ * return a view of exactly that size. There is deliberately nothing else in the
44
+ * signature: everything a picture needs -- the colour, the glyph outlines, the
45
+ * baseline it sits on -- is either inside the XML already or has been taken
46
+ * care of by the time this is called, so `<SvgXml xml={xml} width={width}
47
+ * height={height} />` is the whole of a correct implementation.
48
+ *
49
+ * It exists because a renderer for SVG is a dependency, and which one is not
50
+ * this library's business: `react-native-svg` on native, whatever you like on
51
+ * the web.
52
+ *
53
+ * Returning nothing leaves the drawing out, and the span it stood for still
54
+ * costs its one character either way.
55
+ */
56
+
57
+ /**
58
+ * What to do when a link is pressed.
59
+ *
60
+ * The label is the text the link was rendered as, which is all a reader saw of
61
+ * it: the destination is not in the document any more. Reference links are not
62
+ * covered -- their destination is written somewhere else and is not resolved
63
+ * yet -- so they render as links and do nothing.
64
+ *
65
+ * Opening the URL is deliberately not done for you: what a link means is the
66
+ * application's to decide, and a message from a stranger is the last place to
67
+ * hand an arbitrary URL to `Linking.openURL` without looking at it first.
68
+ *
69
+ * Every string is always a string: a link written without a title is handed an
70
+ * empty one rather than nothing.
71
+ */
72
+
73
+ // `useLayoutEffect` warns when it runs during a server render, and there is no layout to be before
74
+ // on a server anyway. Same seam the input uses.
75
+ const useClientEffect = typeof window === "undefined" ? _react.default.useEffect : _react.default.useLayoutEffect;
76
+ const NO_SLOTS = [];
77
+
78
+ /**
79
+ * What maths is sized against when the caller set no size at all, matching what
80
+ * the native component assumes so the two agree.
81
+ */
82
+ const DEFAULT_FONT_SIZE = 14;
83
+
84
+ /**
85
+ * Replaces each placeholder character in the built markup with an empty element
86
+ * to render an embed or a maths span into.
87
+ *
88
+ * The elements have to be made here rather than rendered, because everything
89
+ * under the host is raw DOM this component built and React knows nothing about
90
+ * -- so the embeds are portalled into these afterwards, which is the one way to
91
+ * put a React subtree somewhere React did not put it.
92
+ *
93
+ * Text nodes are collected before any of them is split: splitting rewrites the
94
+ * tree the walker is walking.
95
+ */
96
+ function mountSlots(host) {
97
+ const walker = document.createTreeWalker(host, NodeFilter.SHOW_TEXT);
98
+ // `globalThis` because `Text` in this file is the react-native one.
99
+ const texts = [];
100
+ while (walker.nextNode()) {
101
+ texts.push(walker.currentNode);
102
+ }
103
+ const slots = [];
104
+ for (const text of texts) {
105
+ let node = text;
106
+ let index = node.data.indexOf(_stripUtils.OBJECT_REPLACEMENT);
107
+ while (index !== -1) {
108
+ const placeholder = node.splitText(index);
109
+ const rest = placeholder.splitText(_stripUtils.OBJECT_REPLACEMENT.length);
110
+ const slot = document.createElement("span");
111
+
112
+ // Inline-block so the embed sits in the line the way an attachment does
113
+ // on native, on the baseline and taking the width it asks for.
114
+ slot.style.display = "inline-block";
115
+ // `text-indent` is inherited, and an inline-block lays out its own first
116
+ // line -- so a list item's hanging indent, which is a negative
117
+ // `text-indent` on the item, shifted the drawing left out of its box and
118
+ // over the word before it. Nothing in here is a first line of anything.
119
+ slot.style.textIndent = "0";
120
+ slot.setAttribute("data-atom", String(slots.length));
121
+ placeholder.replaceWith(slot);
122
+ slots.push(slot);
123
+ node = rest;
124
+ index = node.data.indexOf(_stripUtils.OBJECT_REPLACEMENT);
125
+ }
126
+ }
127
+ return slots.length > 0 ? slots : NO_SLOTS;
128
+ }
129
+
130
+ /**
131
+ * How the list markers are drawn, read off the element they will be drawn in.
132
+ *
133
+ * A display renders them rather than showing them, and their size comes from the base font --
134
+ * whatever the wrapped `Text` resolved to, so it is asked rather than assumed.
135
+ */
136
+ function markerRendering(host) {
137
+ return {
138
+ display: true,
139
+ fontSize: parseFloat(window.getComputedStyle(host).fontSize) || 0
140
+ };
141
+ }
142
+
143
+ /** Anything with a scheme this does not name is left without an `href`. */
144
+ const SAFE_SCHEME = /^(?:https?|mailto|tel):/i;
145
+ const SCHEME = /^[a-z][a-z0-9+.\-]*:/i;
146
+
147
+ /**
148
+ * The destination as an `href`, or nothing if it must not become one.
149
+ *
150
+ * A browser strips whitespace and control characters before it reads a scheme,
151
+ * so `java\nscript:alert(1)` is `javascript:` as far as it is concerned, and it
152
+ * has to be here too. Anything carrying a scheme that is not one of the four
153
+ * safe ones is refused outright rather than guessed at; a destination with no
154
+ * scheme is a relative URL and is left to resolve the way any other relative
155
+ * link on the page does.
156
+ */
157
+ function hrefFor(uri) {
158
+ const bare = uri.replace(/[\u0000-\u0020]/g, "");
159
+ if (bare === "" || SCHEME.test(bare) && !SAFE_SCHEME.test(bare)) {
160
+ return null;
161
+ }
162
+ return uri;
163
+ }
164
+
165
+ /**
166
+ * Marks the elements a link was built into with the link they belong to, and hands them the
167
+ * destination when it is one a browser may follow.
168
+ *
169
+ * The markup is not one element per link: a label split over two lines is built
170
+ * into one element per line, and a label with emphasis in it is an element with
171
+ * more elements inside. So the press is caught on the host and walked back up to
172
+ * the nearest marked ancestor, and all this has to do is put the mark on every
173
+ * element that a link's own range produced.
174
+ *
175
+ * They are anchors already -- that is the tag `link` is built as, in the input
176
+ * too, where a link being typed has no destination yet. What is added here is
177
+ * the `href`, which comes from the document's destinations rather than from its
178
+ * ranges. With one, the browser shows the destination in the status bar, offers
179
+ * it to the context menu, opens it in a new tab on a modified click, and a
180
+ * screen reader announces it; the click handler stops it navigating, because
181
+ * what a link means is the application's to decide. A destination that cannot
182
+ * safely become an href gets none -- and an anchor without one is neither in the
183
+ * tab order nor a link to a screen reader, so those two are said outright.
184
+ */
185
+ function markLinks(node, links) {
186
+ if (node.type === "link") {
187
+ const index = links.findIndex(link => node.start >= link.start && node.start < link.start + link.length);
188
+
189
+ // A reference link has no destination yet, so its label is styled as a link
190
+ // and left inert rather than marked.
191
+ if (index !== -1) {
192
+ const link = links[index];
193
+ const href = hrefFor(link.uri);
194
+ const element = node.element;
195
+ if (href !== null) {
196
+ element.setAttribute("href", href);
197
+ // Untrusted markdown opened in a new tab has no business reaching back.
198
+ element.setAttribute("rel", "noopener noreferrer");
199
+ if (link.title !== "") {
200
+ element.setAttribute("title", link.title);
201
+ }
202
+ } else {
203
+ // Nothing else on the page is reachable by keyboard, and a link a
204
+ // pointer can press and a keyboard cannot is not a link.
205
+ element.setAttribute("role", "link");
206
+ element.setAttribute("tabindex", "0");
207
+ element.style.cursor = "pointer";
208
+ }
209
+ element.setAttribute("data-link", String(index));
210
+ }
211
+ }
212
+ node.childNodes.forEach(child => markLinks(child, links));
213
+ }
214
+
215
+ /**
216
+ * `Text`, with the markdown in its content rendered rather than shown.
217
+ *
218
+ * Built by the same DOM builder the input uses, from the same ranges, so a message and the composer
219
+ * it was typed in agree by construction -- which on the web means agreeing about indents, about
220
+ * ribbons drawn as background layers, and about the marker widths those are measured from. The only
221
+ * difference is the input, where the syntax is still there to be edited.
222
+ *
223
+ * Rendered as a real `Text` whose children are then replaced. React only ever writes the stripped
224
+ * string into the host element -- a lone string child is set with `textContent`, never as a node it
225
+ * holds on to -- so the effect below is free to put the built markup there instead, and a render
226
+ * that changes the text simply wipes it and lets the effect rebuild before the frame is painted.
227
+ * Rendering the plain string rather than nothing also means a prerendered page carries the prose:
228
+ * `expo export` runs every route through Node, where there is no DOM to build markup with.
229
+ */
230
+ const MarkdownText = /*#__PURE__*/_react.default.forwardRef((props, ref) => {
231
+ const {
232
+ markdownStyle: markdownStyleProp,
233
+ gfm,
234
+ mention,
235
+ math,
236
+ renderEmbed,
237
+ renderSVG,
238
+ mathAccessibilityLocale,
239
+ onLinkPress,
240
+ children,
241
+ ...textProps
242
+ } = props;
243
+ const hostRef = _react.default.useRef(null);
244
+ const [slots, setSlots] = _react.default.useState(NO_SLOTS);
245
+
246
+ // Whether there is a handler, not which one: a caller who writes the callback
247
+ // inline would otherwise re-parse the document on every render.
248
+ const withEmbeds = renderEmbed !== undefined;
249
+ // Maths is only taken out of the text when there is both something to draw it
250
+ // with and a backend to typeset it -- see `./math`. Left in, `$$x^2$$` is
251
+ // shown as it was written.
252
+ const withMath = renderSVG !== undefined && _index.available;
253
+ const withLinks = onLinkPress !== undefined;
254
+
255
+ // The same worklet for as long as the flavour is the same one, so the
256
+ // document is only re-parsed when the document itself changes.
257
+ const parser = (0, _index2.createParser)({
258
+ gfm,
259
+ mention,
260
+ math
261
+ });
262
+ const markdown = _react.default.useMemo(() => {
263
+ const text = (0, _childrenUtils.flattenText)(children);
264
+ return text === null ? null : (0, _stripUtils.stripSyntax)(text, parser(text), {
265
+ embeds: withEmbeds,
266
+ math: withMath,
267
+ links: withLinks
268
+ });
269
+ }, [children, parser, withEmbeds, withMath, withLinks]);
270
+
271
+ // Both kinds of placeholder in the order they stand in the text, which is the
272
+ // order `mountSlots` makes the slots in.
273
+ const atoms = _react.default.useMemo(() => markdown === null ? _atomUtils.NO_ATOMS : (0, _atomUtils.atomsOf)(markdown), [markdown]);
274
+
275
+ // Read off this element's own style rather than the computed one, so the
276
+ // numbers the maths is drawn at are the numbers the native component would
277
+ // draw it at.
278
+ const {
279
+ fontSize,
280
+ color
281
+ } = _react.default.useMemo(() => {
282
+ const flattened = _reactNative.StyleSheet.flatten(textProps.style);
283
+ return {
284
+ fontSize: typeof flattened?.fontSize === "number" ? flattened.fontSize : DEFAULT_FONT_SIZE,
285
+ color: typeof flattened?.color === "string" ? flattened.color : undefined
286
+ };
287
+ }, [textProps.style]);
288
+
289
+ // Drawn during render rather than at portal time, because the depth a maths
290
+ // span reports has to be on its slot before the frame is painted.
291
+ const drawn = _react.default.useMemo(() => atoms.map(atom => {
292
+ if (atom.kind === "embed") {
293
+ return {
294
+ element: renderEmbed?.(atom.uri, atom.alt, atom.title, atom.inline) ?? null,
295
+ depth: 0,
296
+ // Whatever the caller's element measures: only it knows how big an
297
+ // embed is, and that is what `renderEmbed` promises to say.
298
+ box: null,
299
+ // An image's `alt` is its accessible name by every spec there is,
300
+ // and left empty it declares the image decorative.
301
+ label: atom.alt,
302
+ role: "img",
303
+ // Nothing: an image's alt text is prose, written in the language
304
+ // the document is written in, and saying otherwise would have a
305
+ // screen reader read it in the wrong voice.
306
+ lang: "",
307
+ source: (0, _atomUtils.sourceOf)(atom)
308
+ };
309
+ }
310
+ const rendered = (0, _index.renderMath)(atom.tex, atom.display, fontSize, color);
311
+ return {
312
+ element: rendered === null ? null : renderSVG?.(rendered.svg, rendered.width, rendered.height),
313
+ depth: rendered?.depth ?? 0,
314
+ box: rendered === null ? null : {
315
+ width: rendered.width,
316
+ height: rendered.height
317
+ },
318
+ // What the picture says, rather than the TeX it was written as: a
319
+ // reader who asked for a document did not ask for its source code.
320
+ label: (0, _index.speakMath)(atom.tex, atom.display, mathAccessibilityLocale) ?? atom.tex,
321
+ role: "math",
322
+ // The language the label is in, which is the one thing on the page
323
+ // that may differ from the document's own: a screen reader picks its
324
+ // voice from this, and French read in an English voice is worse than
325
+ // no voice at all.
326
+ lang: mathAccessibilityLocale ?? "",
327
+ // What a copy puts on the clipboard in place of the picture: the
328
+ // markdown it was written as, so that pasting it back gives the
329
+ // document it came from rather than a hole where an equation was.
330
+ source: (0, _atomUtils.sourceOf)(atom)
331
+ };
332
+ }), [atoms, renderEmbed, renderSVG, fontSize, color, mathAccessibilityLocale]);
333
+ const markdownStyle = _react.default.useMemo(() => (0, _webStyleUtils.processMarkdownStyle)(markdownStyleProp), [markdownStyleProp]);
334
+
335
+ // What React writes into the host, and so what a prerendered page carries. The placeholders go:
336
+ // they only mean anything to the markup the effect builds, and a page rendered in Node -- where
337
+ // there is no DOM to build that markup with -- would otherwise show a row of tofu.
338
+ const content = _react.default.useMemo(() => {
339
+ if (markdown === null) {
340
+ return null;
341
+ }
342
+ return markdown.text.includes(_stripUtils.OBJECT_REPLACEMENT) ? markdown.text.split(_stripUtils.OBJECT_REPLACEMENT).join("") : markdown.text;
343
+ }, [markdown]);
344
+ useClientEffect(() => {
345
+ const host = hostRef.current;
346
+ if (!host || markdown === null) {
347
+ return;
348
+ }
349
+ const {
350
+ dom,
351
+ tree
352
+ } = (0, _parserUtils.parseRangesToHTMLNodes)(markdown.text, markdown.ranges, true, markdownStyle, false,
353
+ // Measured against this element, so marker widths come out in the font the text is actually
354
+ // drawn in rather than the document's default.
355
+ (0, _measureUtils.createTextMeasurer)(host),
356
+ // A display renders the list markers rather than showing them, sized from the font this
357
+ // element renders at: the base font, which is the wrapped `Text`'s own.
358
+ markerRendering(host));
359
+ if (markdown.links.length > 0) {
360
+ markLinks(tree, markdown.links);
361
+ }
362
+ host.replaceChildren(...Array.from(dom.childNodes));
363
+ const next = atoms.length > 0 ? mountSlots(host) : NO_SLOTS;
364
+
365
+ // Both empty is the overwhelmingly common case, and setting state there would re-render every
366
+ // document that has no embeds in it for nothing.
367
+ setSlots(previous => previous === NO_SLOTS && next === NO_SLOTS ? previous : next);
368
+ // React wipes the host with `textContent` whenever the string child changes, which is exactly
369
+ // when `markdown` does, so these two are all it takes to be sure the markup is back before the
370
+ // frame is painted.
371
+ }, [markdown, markdownStyle, atoms]);
372
+
373
+ // Everything about a slot that is the slot's own business rather than the
374
+ // caller's: it is the inline-level box, so aligning anything inside it would
375
+ // only move that box's contents, and it is the element in the accessibility
376
+ // tree, so it is the one thing that can be given a name. Its own effect, so
377
+ // that a caller redrawing from state brings all three with it.
378
+ useClientEffect(() => {
379
+ slots.forEach((slot, index) => {
380
+ const content = drawn[index];
381
+ const depth = content?.depth ?? 0;
382
+
383
+ // The depth the maths hangs below the baseline, which on the web is the
384
+ // same displacement by another name.
385
+ slot.style.verticalAlign = depth === 0 ? "" : `${-depth}px`;
386
+
387
+ // The box the drawing was measured for, stated rather than shrink-wrapped.
388
+ // An inline-block with no width of its own is shrink-to-fit, and
389
+ // shrink-to-fit is capped by what is left of the line -- so a wide
390
+ // expression near a margin got a box narrower than its own picture and the
391
+ // picture hung out of it, over the words beside it. Native reserves the
392
+ // measured box; this is the same thing said in CSS.
393
+ if (content?.box) {
394
+ slot.style.width = `${content.box.width}px`;
395
+ slot.style.height = `${content.box.height}px`;
396
+ } else {
397
+ slot.style.width = "";
398
+ slot.style.height = "";
399
+ }
400
+ if (content === undefined || content.label === "") {
401
+ slot.removeAttribute("role");
402
+ slot.removeAttribute("aria-label");
403
+ } else {
404
+ // `math` and `img` both take a name from the author, so the label wins
405
+ // over whatever glyph outlines are underneath it.
406
+ slot.setAttribute("role", content.role);
407
+ slot.setAttribute("aria-label", content.label);
408
+ }
409
+ if (content?.lang) {
410
+ slot.setAttribute("lang", content.lang);
411
+ } else {
412
+ slot.removeAttribute("lang");
413
+ }
414
+ if (content?.source) {
415
+ slot.setAttribute("data-tex", content.source);
416
+ } else {
417
+ slot.removeAttribute("data-tex");
418
+ }
419
+ });
420
+ }, [slots, drawn]);
421
+
422
+ // Copying maths gives back the markdown it was written as.
423
+ //
424
+ // A selection dragged across a drawing copies whatever text is under it,
425
+ // which for an SVG is nothing at all -- so a message copied out of a chat
426
+ // arrives with a hole where its equation was. The clipboard is the one place
427
+ // the source is worth more than the picture, and this is the only hook the
428
+ // web offers: the copy is intercepted, the fragment the browser was about to
429
+ // serialise is walked, and every slot in it is swapped for the `$$…$$` it
430
+ // stands for.
431
+ //
432
+ // On the document rather than the host, because that is where a copy lands
433
+ // when the selection reaches past this element. It is left alone unless the
434
+ // fragment actually holds one of these slots.
435
+ useClientEffect(() => {
436
+ const host = hostRef.current;
437
+ if (!host || !drawn.some(content => content.source !== "")) {
438
+ return undefined;
439
+ }
440
+ const onCopy = event => {
441
+ const selection = window.getSelection();
442
+ if (!selection || selection.isCollapsed || selection.rangeCount === 0) {
443
+ return;
444
+ }
445
+ const fragment = selection.getRangeAt(0).cloneContents();
446
+ const maths = fragment.querySelectorAll("[data-tex]");
447
+ if (maths.length === 0) {
448
+ return;
449
+ }
450
+ for (const element of Array.from(maths)) {
451
+ element.replaceWith(document.createTextNode(element.getAttribute("data-tex") ?? ""));
452
+ }
453
+ event.clipboardData?.setData("text/plain", fragment.textContent ?? "");
454
+ event.preventDefault();
455
+ };
456
+ document.addEventListener("copy", onCopy);
457
+ return () => document.removeEventListener("copy", onCopy);
458
+ }, [drawn]);
459
+
460
+ // On the host rather than on each link: the markup underneath is rebuilt from
461
+ // scratch whenever the text changes, and a listener per element would have to
462
+ // be attached again every time.
463
+ useClientEffect(() => {
464
+ const host = hostRef.current;
465
+ if (!host || markdown === null || onLinkPress === undefined || markdown.links.length === 0) {
466
+ return undefined;
467
+ }
468
+ const {
469
+ links
470
+ } = markdown;
471
+ const linkAt = target => {
472
+ const element = target instanceof Element ? target.closest("[data-link]") : null;
473
+ return element === null ? undefined : links[Number(element.getAttribute("data-link"))];
474
+ };
475
+ const press = event => {
476
+ const link = linkAt(event.target);
477
+ if (link === undefined) {
478
+ return;
479
+ }
480
+
481
+ // A modified click belongs to the browser: on an anchor it opens the
482
+ // destination in a new tab or a new window, which is what the reader
483
+ // asked for and something no callback can do for them.
484
+ if ("button" in event && (event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey)) {
485
+ return;
486
+ }
487
+ event.preventDefault();
488
+ onLinkPress(link.uri, link.label, link.title);
489
+ };
490
+ const onKeyDown = event => {
491
+ // Enter and not Space: Space activates a button, and scrolls everywhere
492
+ // else, which is what a reader who has tabbed onto a link expects of it.
493
+ if (event.key === "Enter") {
494
+ press(event);
495
+ }
496
+ };
497
+ host.addEventListener("click", press);
498
+ host.addEventListener("keydown", onKeyDown);
499
+ return () => {
500
+ host.removeEventListener("click", press);
501
+ host.removeEventListener("keydown", onKeyDown);
502
+ };
503
+ }, [markdown, onLinkPress]);
504
+ const setRef = _react.default.useCallback(node => {
505
+ hostRef.current = node;
506
+ if (typeof ref === "function") {
507
+ ref(node);
508
+ } else if (ref) {
509
+ // eslint-disable-next-line no-param-reassign
510
+ ref.current = node;
511
+ }
512
+ }, [ref]);
513
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
514
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
515
+ ...textProps,
516
+ ref: setRef,
517
+ children: markdown === null ? children : content
518
+ }), slots.map((slot, index) => {
519
+ const content = drawn[index];
520
+
521
+ // The slots were made from this very `markdown`, so they line up -- but a render between a
522
+ // text change and the effect that follows it can still see the previous set, one entry
523
+ // longer than the new document has placeholders.
524
+ return content?.element == null ? null : /*#__PURE__*/(0, _reactDom.createPortal)(content.element, slot, String(index));
525
+ })]
526
+ });
527
+ });
528
+ var _default = exports.default = MarkdownText;
529
+ //# sourceMappingURL=MarkdownText.web.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_reactNative","require","_react","_interopRequireDefault","_reactDom","_atomUtils","_index","_childrenUtils","_stripUtils","_measureUtils","_parserUtils","_webStyleUtils","_index2","_jsxRuntime","e","__esModule","default","useClientEffect","window","React","useEffect","useLayoutEffect","NO_SLOTS","DEFAULT_FONT_SIZE","mountSlots","host","walker","document","createTreeWalker","NodeFilter","SHOW_TEXT","texts","nextNode","push","currentNode","slots","text","node","index","data","indexOf","OBJECT_REPLACEMENT","placeholder","splitText","rest","length","slot","createElement","style","display","textIndent","setAttribute","String","replaceWith","markerRendering","fontSize","parseFloat","getComputedStyle","SAFE_SCHEME","SCHEME","hrefFor","uri","bare","replace","test","markLinks","links","type","findIndex","link","start","href","element","title","cursor","childNodes","forEach","child","MarkdownText","forwardRef","props","ref","markdownStyle","markdownStyleProp","gfm","mention","math","renderEmbed","renderSVG","mathAccessibilityLocale","onLinkPress","children","textProps","hostRef","useRef","setSlots","useState","withEmbeds","undefined","withMath","mathAvailable","withLinks","parser","createParser","markdown","useMemo","flattenText","stripSyntax","embeds","atoms","NO_ATOMS","atomsOf","color","flattened","StyleSheet","flatten","drawn","map","atom","kind","alt","inline","depth","box","label","role","lang","source","sourceOf","rendered","renderMath","tex","svg","width","height","speakMath","processMarkdownStyle","content","includes","split","join","current","dom","tree","parseRangesToHTMLNodes","ranges","createTextMeasurer","replaceChildren","Array","from","next","previous","verticalAlign","removeAttribute","some","onCopy","event","selection","getSelection","isCollapsed","rangeCount","fragment","getRangeAt","cloneContents","maths","querySelectorAll","createTextNode","getAttribute","clipboardData","setData","textContent","preventDefault","addEventListener","removeEventListener","linkAt","target","Element","closest","Number","press","button","metaKey","ctrlKey","shiftKey","altKey","onKeyDown","key","setRef","useCallback","jsxs","Fragment","jsx","Text","createPortal","_default","exports"],"sourceRoot":"../../src","sources":["MarkdownText.web.tsx"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,SAAA,GAAAH,OAAA;AAGAA,OAAA;AAEA,IAAAI,UAAA,GAAAJ,OAAA;AACA,IAAAK,MAAA,GAAAL,OAAA;AACA,IAAAM,cAAA,GAAAN,OAAA;AACA,IAAAO,WAAA,GAAAP,OAAA;AACA,IAAAQ,aAAA,GAAAR,OAAA;AACA,IAAAS,YAAA,GAAAT,OAAA;AACA,IAAAU,cAAA,GAAAV,OAAA;AACA,IAAAW,OAAA,GAAAX,OAAA;AAAuC,IAAAY,WAAA,GAAAZ,OAAA;AAAA,SAAAE,uBAAAW,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAKvC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAQA;AACA;AACA;AACA;A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MACA;MACA,OAAOmG,OAAO,EAAEjE,OAAO,IAAI,IAAI,GAC3B,IAAI,gBACJ,IAAAyH,sBAAY,EAACxD,OAAO,CAACjE,OAAO,EAAE1B,IAAI,EAAEM,MAAM,CAACd,KAAK,CAAC,CAAC;IACxD,CAAC,CAAC;EAAA,CACF,CAAC;AAEP,CAAC,CAAC;AAAA,IAAA4J,QAAA,GAAAC,OAAA,CAAAnL,OAAA,GAIa8D,YAAY","ignoreList":[]}
@@ -11,6 +11,7 @@ var _reactNativeWorklets = require("react-native-worklets");
11
11
  var _MarcusTextInputDecoratorViewNativeComponent = _interopRequireDefault(require("./MarcusTextInputDecoratorViewNativeComponent"));
12
12
  var _NativeMarcusModule = _interopRequireDefault(require("./NativeMarcusModule.js"));
13
13
  var _styleUtils = require("./styleUtils.js");
14
+ var _index = require("./parser/index.js");
14
15
  var _jsxRuntime = require("react/jsx-runtime");
15
16
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
16
17
  let initialized = false;
@@ -46,37 +47,31 @@ function registerParser(parser) {
46
47
  function unregisterParser(parserId) {
47
48
  global.jsi_unregisterMarcusWorklet(parserId);
48
49
  }
49
- function processColorsInMarkdownStyle(input) {
50
- const output = JSON.parse(JSON.stringify(input));
51
- Object.keys(output).forEach(key => {
52
- const obj = output[key];
53
- Object.keys(obj).forEach(prop => {
54
- // TODO: use ReactNativeStyleAttributes from 'react-native/Libraries/Components/View/ReactNativeStyleAttributes'
55
- if (!(prop === "color" || prop.endsWith("Color"))) {
56
- return;
57
- }
58
- obj[prop] = (0, _reactNative.processColor)(obj[prop]);
59
- });
60
- });
61
- return output;
62
- }
63
- function processMarkdownStyle(input) {
64
- return processColorsInMarkdownStyle((0, _styleUtils.mergeMarkdownStyleWithDefault)(input));
65
- }
66
50
  const MarkdownTextInput = /*#__PURE__*/_react.default.forwardRef((props, ref) => {
67
- const markdownStyle = _react.default.useMemo(() => processMarkdownStyle(props.markdownStyle), [props.markdownStyle]);
68
- if (props.parser === undefined) {
69
- throw new Error("[react-native-marcus] `parser` is undefined");
70
- }
51
+ const {
52
+ markdownStyle: markdownStyleProp,
53
+ gfm,
54
+ mention,
55
+ math,
56
+ ...textInputProps
57
+ } = props;
58
+ const markdownStyle = _react.default.useMemo(() => (0, _styleUtils.processMarkdownStyle)(markdownStyleProp), [markdownStyleProp]);
59
+
60
+ // The same worklet for as long as the flavour is the same one, so the id
61
+ // below is registered once and the native side keeps the parser it has.
62
+ const parser = (0, _index.createParser)({
63
+ gfm,
64
+ mention,
65
+ math
66
+ });
71
67
 
72
68
  // eslint-disable-next-line no-underscore-dangle
73
- const workletHash = props.parser.__workletHash;
74
- if (workletHash === undefined) {
75
- throw new Error("[react-native-marcus] `parser` is not a worklet");
69
+ if (parser.__workletHash === undefined) {
70
+ throw new Error("[react-native-marcus] the parser is not a worklet. Add `react-native-worklets/plugin` to the project's Babel config.");
76
71
  }
77
72
  const parserId = _react.default.useMemo(() => {
78
- return registerParser(props.parser);
79
- }, [props.parser]);
73
+ return registerParser(parser);
74
+ }, [parser]);
80
75
  _react.default.useEffect(() => {
81
76
  return () => unregisterParser(parserId);
82
77
  }, [parserId]);
@@ -85,7 +80,7 @@ const MarkdownTextInput = /*#__PURE__*/_react.default.forwardRef((props, ref) =>
85
80
  markdownStyle: markdownStyle,
86
81
  parserId: parserId,
87
82
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.TextInput, {
88
- ...props,
83
+ ...textInputProps,
89
84
  ref: ref
90
85
  })
91
86
  });
@@ -1 +1 @@
1
- {"version":3,"names":["_reactNative","require","_react","_interopRequireDefault","_reactNativeWorklets","_MarcusTextInputDecoratorViewNativeComponent","_NativeMarcusModule","_styleUtils","_jsxRuntime","e","__esModule","default","initialized","workletRuntime","getWorkletRuntime","undefined","Error","initializeMarcusIfNeeded","NativeMarcusModule","install","global","jsi_setMarcusRuntime","createWorkletRuntime","name","registerParser","parser","serializableWorklet","createSerializable","parserId","jsi_registerMarcusWorklet","unregisterParser","jsi_unregisterMarcusWorklet","processColorsInMarkdownStyle","input","output","JSON","parse","stringify","Object","keys","forEach","key","obj","prop","endsWith","processColor","processMarkdownStyle","mergeMarkdownStyleWithDefault","MarkdownTextInput","React","forwardRef","props","ref","markdownStyle","useMemo","workletHash","__workletHash","useEffect","jsx","style","styles","displayContents","children","TextInput","StyleSheet","create","display","_default","exports"],"sourceRoot":"../../src","sources":["MarkdownTextInput.tsx"],"mappings":";;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAC,sBAAA,CAAAF,OAAA;AAEA,IAAAG,oBAAA,GAAAH,OAAA;AAEA,IAAAI,4CAAA,GAAAF,sBAAA,CAAAF,OAAA;AAEA,IAAAK,mBAAA,GAAAH,sBAAA,CAAAF,OAAA;AACA,IAAAM,WAAA,GAAAN,OAAA;AAA4D,IAAAO,WAAA,GAAAP,OAAA;AAAA,SAAAE,uBAAAM,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAe5D,IAAIG,WAAW,GAAG,KAAK;AACvB,IAAIC,cAA0C;AAE9C,SAASC,iBAAiBA,CAAA,EAAmB;EAC3C,IAAID,cAAc,KAAKE,SAAS,EAAE;IAChC,MAAM,IAAIC,KAAK,CACb,8MACF,CAAC;EACH;EACA,OAAOH,cAAc;AACvB;AAEA,SAASI,wBAAwBA,CAAA,EAAG;EAClC,IAAIL,WAAW,EAAE;IACf;EACF;EACA,IAAIM,2BAAkB,EAAE;IACtBA,2BAAkB,CAACC,OAAO,CAAC,CAAC;EAC9B;EACA,IAAI,CAACC,MAAM,CAACC,oBAAoB,EAAE;IAChC,MAAM,IAAIL,KAAK,CAAC,oEAAoE,CAAC;EACvF;EACAH,cAAc,GAAG,IAAAS,yCAAoB,EAAC;IAAEC,IAAI,EAAE;EAAgB,CAAC,CAAC;EAChEH,MAAM,CAACC,oBAAoB,CAACR,cAAc,CAAC;EAC3CD,W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C,EAC/C,CAACF,KAAK,CAACE,aAAa,CACtB,CAAC;EAED,IAAIF,KAAK,CAAC1B,MAAM,KAAKV,SAAS,EAAE;IAC9B,MAAM,IAAIC,KAAK,CAAC,6CAA6C,CAAC;EAChE;;EAEA;EACA,MAAMuC,WAAW,GAAIJ,KAAK,CAAC1B,MAAM,CAAgC+B,aAAa;EAC9E,IAAID,WAAW,KAAKxC,SAAS,EAAE;IAC7B,MAAM,IAAIC,KAAK,CAAC,iDAAiD,CAAC;EACpE;EAEA,MAAMY,QAAQ,GAAGqB,cAAK,CAACK,OAAO,CAAC,MAAM;IACnC,OAAO9B,cAAc,CAAC2B,KAAK,CAAC1B,MAAM,CAAC;EACrC,CAAC,EAAE,CAAC0B,KAAK,CAAC1B,MAAM,CAAC,CAAC;EAElBwB,cAAK,CAACQ,SAAS,CAAC,MAAM;IACpB,OAAO,MAAM3B,gBAAgB,CAACF,QAAQ,CAAC;EACzC,CAAC,EAAE,CAACA,QAAQ,CAAC,CAAC;EAEd,oBACE,IAAApB,WAAA,CAAAkD,GAAA,EAACrD,4CAAA,CAAAM,OAA2C;IAC1CgD,KAAK,EAAEC,MAAM,CAACC,eAAgB;IAC9BR,aAAa,EAAEA,aAAc;IAC7BzB,QAAQ,EAAEA,QAAS;IAAAkC,QAAA,eAEnB,IAAAtD,WAAA,CAAAkD,GAAA,EAAC1D,YAAA,CAAA+D,SAAS;MAAA,GAAKZ,KAAK;MAAEC,GAAG,EAAEA;IAAI,CAAE;EAAC,CACS,CAAC;AAElD,CACF,CAAC;AAED,MAAMQ,MAAM,GAAGI,uBAAU,CAACC,MAAM,CAAC;EAC/BJ,eAAe,EAAE;IACfK,OAAO,EAAE;EACX;AACF,CAAC,CAAC;AAAA,IAAAC,QAAA,GAAAC,OAAA,CAAAzD,OAAA,GAIaqC,iBAAiB","ignoreList":[]}
1
+ {"version":3,"names":["_reactNative","require","_react","_interopRequireDefault","_reactNativeWorklets","_MarcusTextInputDecoratorViewNativeComponent","_NativeMarcusModule","_styleUtils","_index","_jsxRuntime","e","__esModule","default","initialized","workletRuntime","getWorkletRuntime","undefined","Error","initializeMarcusIfNeeded","NativeMarcusModule","install","global","jsi_setMarcusRuntime","createWorkletRuntime","name","registerParser","parser","serializableWorklet","createSerializable","parserId","jsi_registerMarcusWorklet","unregisterParser","jsi_unregisterMarcusWorklet","MarkdownTextInput","React","forwardRef","props","ref","markdownStyle","markdownStyleProp","gfm","mention","math","textInputProps","useMemo","processMarkdownStyle","createParser","__workletHash","useEffect","jsx","style","styles","displayContents","children","TextInput","StyleSheet","create","display","_default","exports"],"sourceRoot":"../../src","sources":["MarkdownTextInput.tsx"],"mappings":";;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAC,sBAAA,CAAAF,OAAA;AAEA,IAAAG,oBAAA,GAAAH,OAAA;AAEA,IAAAI,4CAAA,GAAAF,sBAAA,CAAAF,OAAA;AACA,IAAAK,mBAAA,GAAAH,sBAAA,CAAAF,OAAA;AACA,IAAAM,WAAA,GAAAN,OAAA;AAEA,IAAAO,MAAA,GAAAP,OAAA;AAAuC,IAAAQ,WAAA,GAAAR,OAAA;AAAA,SAAAE,uBAAAO,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAcvC,IAAIG,WAAW,GAAG,KAAK;AACvB,IAAIC,cAA0C;AAE9C,SAASC,iBAAiBA,CAAA,EAAmB;EAC3C,IAAID,cAAc,KAAKE,SAAS,EAAE;IAChC,MAAM,IAAIC,KAAK,CACb,8MACF,CAAC;EACH;EACA,OAAOH,cAAc;AACvB;AAEA,SAASI,wBAAwBA,CAAA,EAAG;EAClC,IAAIL,WAAW,EAAE;IACf;EACF;EACA,IAAIM,2BAAkB,EAAE;IACtBA,2BAAkB,CAACC,OAAO,CAAC,CAAC;EAC9B;EACA,IAAI,CAACC,MAAM,CAACC,oBAAoB,EAAE;IAChC,MAAM,IAAIL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