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.
- package/README.md +220 -63
- package/RNMarcus.podspec +6 -0
- package/android/src/main/java/app/getbullet/marcus/MarcusPackage.kt +2 -1
- package/android/src/main/java/app/getbullet/marcus/MarcusTextDecoratorView.kt +168 -0
- package/android/src/main/java/app/getbullet/marcus/MarcusTextDecoratorViewManager.kt +38 -0
- package/android/src/main/java/app/getbullet/marcus/MarcusTextDecoratorViewManagerSpec.kt +19 -0
- package/android/src/main/java/app/getbullet/marcus/MarcusTextInputDecoratorView.kt +23 -1
- package/android/src/main/java/app/getbullet/marcus/MarkdownBackgroundPainter.kt +147 -0
- package/android/src/main/java/app/getbullet/marcus/MarkdownBackgroundPass.kt +19 -0
- package/android/src/main/java/app/getbullet/marcus/MarkdownCopy.kt +87 -0
- package/android/src/main/java/app/getbullet/marcus/MarkdownFormatter.kt +652 -113
- package/android/src/main/java/app/getbullet/marcus/MarkdownRanges.kt +47 -0
- package/android/src/main/java/app/getbullet/marcus/MarkdownStyle.kt +140 -61
- package/android/src/main/java/app/getbullet/marcus/MarkdownUtils.kt +37 -7
- package/android/src/main/java/app/getbullet/marcus/spans/MarkdownAbsoluteLineHeightSpan.kt +48 -0
- package/android/src/main/java/app/getbullet/marcus/spans/MarkdownBackgroundSpan.kt +102 -48
- package/android/src/main/java/app/getbullet/marcus/spans/MarkdownBlockIndentSpan.kt +22 -4
- package/android/src/main/java/app/getbullet/marcus/spans/MarkdownBulletSpan.kt +78 -0
- package/android/src/main/java/app/getbullet/marcus/spans/MarkdownCodeBlockSpan.kt +177 -0
- package/android/src/main/java/app/getbullet/marcus/spans/MarkdownFontStyleSpan.kt +32 -0
- package/android/src/main/java/app/getbullet/marcus/spans/MarkdownFontWeightSpan.kt +34 -0
- package/android/src/main/java/app/getbullet/marcus/spans/MarkdownGapSpan.kt +24 -11
- package/android/src/main/java/app/getbullet/marcus/spans/MarkdownLetterSpacingSpan.kt +32 -0
- package/android/src/main/java/app/getbullet/marcus/spans/MarkdownTextShadowSpan.kt +32 -0
- package/android/src/main/new_arch/CMakeLists.txt +17 -0
- package/android/src/main/new_arch/RNMarcusSpec.h +1 -0
- package/android/src/main/new_arch/react/renderer/components/RNMarcusSpec/MarcusTextDecoratorShadowNode.cpp +235 -0
- package/android/src/main/new_arch/react/renderer/components/RNMarcusSpec/MarcusTextDecoratorShadowNode.h +62 -0
- package/android/src/reactNativeVersionPatch/CustomMountingManager/81/app/getbullet/marcus/CustomFabricUIManager.java +22 -3
- package/android/src/reactNativeVersionPatch/CustomMountingManager/latest/app/getbullet/marcus/CustomFabricUIManager.java +22 -3
- package/android/src/test/java/app/getbullet/marcus/MarkdownCopyTest.kt +69 -0
- package/android/src/test/java/app/getbullet/marcus/MarkdownFormatterTest.kt +170 -25
- package/android/src/test/java/app/getbullet/marcus/RenderModel.kt +22 -5
- package/android/src/test/java/app/getbullet/marcus/spans/MarkdownCodeBlockSpanTest.kt +91 -0
- package/android/src/test/resources/render-model.txt +221 -16
- package/apple/MarcusSwizzle.h +25 -0
- package/apple/MarcusTextDecoratorComponentView.h +22 -0
- package/apple/MarcusTextDecoratorComponentView.mm +72 -0
- package/apple/MarcusTextDecoratorShadowNode.h +62 -0
- package/apple/MarcusTextDecoratorShadowNode.mm +192 -0
- package/apple/MarcusTextDecoratorViewManager.h +4 -0
- package/apple/MarcusTextDecoratorViewManager.mm +11 -0
- package/apple/MarcusTextInputDecoratorComponentView.mm +1 -1
- package/apple/MarcusTextInputDecoratorShadowNode.mm +1 -1
- package/apple/MarcusTextLayoutManager.h +40 -0
- package/apple/MarcusTextLayoutManager.mm +173 -0
- package/apple/MarkdownAttributes.h +23 -2
- package/apple/MarkdownAttributes.m +6 -0
- package/apple/MarkdownCopy.swift +63 -0
- package/apple/MarkdownDecorator.swift +2 -2
- package/apple/MarkdownFormatter+React.swift +23 -0
- package/apple/MarkdownFormatter.swift +869 -148
- package/apple/MarkdownParagraphLayoutManager.swift +455 -0
- package/apple/MarkdownSwiftInterop.h +0 -1
- package/apple/MarkdownTextBackground.swift +59 -1
- package/apple/MarkdownTextFieldObserver.swift +2 -2
- package/apple/MarkdownTextLayoutFragment.swift +159 -33
- package/apple/MarkdownTextLayoutManagerDelegate.swift +67 -3
- package/apple/MarkdownTextStorageDelegate.swift +2 -2
- package/apple/MarkdownTextViewObserver.swift +2 -2
- package/apple/MarkdownUtils.swift +38 -0
- package/apple/MarkdownWritingDirection.swift +132 -0
- package/apple/RCTMarcusStyle+Codegen.h +115 -9
- package/apple/RCTMarcusStyle.h +128 -31
- package/apple/RCTMarcusStyle.m +48 -0
- package/apple/RCTParagraphComponentView+Marcus.h +17 -0
- package/apple/RCTParagraphComponentView+Marcus.mm +38 -0
- package/apple/RCTTextInputComponentView+Marcus.mm +1 -25
- package/cpp/react/renderer/components/RNMarcusSpec/MarcusTextDecoratorState.h +37 -0
- package/cpp/react/renderer/components/RNMarcusSpec/MarcusTextDecoratorViewComponentDescriptor.h +17 -0
- package/lib/commonjs/MarcusTextDecoratorViewNativeComponent.ts +199 -0
- package/lib/commonjs/MarcusTextInputDecoratorViewNativeComponent.ts +145 -58
- package/lib/commonjs/MarkdownText.js +330 -0
- package/lib/commonjs/MarkdownText.js.map +1 -0
- package/lib/commonjs/MarkdownText.web.js +529 -0
- package/lib/commonjs/MarkdownText.web.js.map +1 -0
- package/lib/commonjs/MarkdownTextInput.js +22 -27
- package/lib/commonjs/MarkdownTextInput.js.map +1 -1
- package/lib/commonjs/MarkdownTextInput.web.js +12 -7
- package/lib/commonjs/MarkdownTextInput.web.js.map +1 -1
- package/lib/commonjs/atomUtils.js +112 -0
- package/lib/commonjs/atomUtils.js.map +1 -0
- package/lib/commonjs/childrenUtils.js +36 -0
- package/lib/commonjs/childrenUtils.js.map +1 -0
- package/lib/commonjs/index.js +8 -7
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/math/environment.js +69 -0
- package/lib/commonjs/math/environment.js.map +1 -0
- package/lib/commonjs/math/index.js +61 -0
- package/lib/commonjs/math/index.js.map +1 -0
- package/lib/commonjs/math/mathjax.js +548 -0
- package/lib/commonjs/math/mathjax.js.map +1 -0
- package/lib/commonjs/metro.js +172 -0
- package/lib/commonjs/metro.js.map +1 -0
- package/lib/commonjs/parser/index.d.ts +3 -0
- package/lib/commonjs/parser/index.js +450 -42
- package/lib/commonjs/parser/index.js.map +4 -4
- package/lib/commonjs/stripUtils.js +743 -0
- package/lib/commonjs/stripUtils.js.map +1 -0
- package/lib/commonjs/styleUtils.js +194 -23
- package/lib/commonjs/styleUtils.js.map +1 -1
- package/lib/commonjs/web/MarkdownElements.css +67 -0
- package/lib/commonjs/web/MarkdownTextInput.css +9 -7
- package/lib/commonjs/web/utils/blockLayout.js +95 -7
- package/lib/commonjs/web/utils/blockLayout.js.map +1 -1
- package/lib/commonjs/web/utils/blockUtils.js +327 -54
- package/lib/commonjs/web/utils/blockUtils.js.map +1 -1
- package/lib/commonjs/web/utils/elementUtils.js +80 -0
- package/lib/commonjs/web/utils/elementUtils.js.map +1 -0
- package/lib/commonjs/web/utils/parserUtils.js +84 -28
- package/lib/commonjs/web/utils/parserUtils.js.map +1 -1
- package/lib/commonjs/web/utils/treeUtils.js +6 -0
- package/lib/commonjs/web/utils/treeUtils.js.map +1 -1
- package/lib/commonjs/web/utils/webStyleUtils.js +25 -5
- package/lib/commonjs/web/utils/webStyleUtils.js.map +1 -1
- package/lib/module/MarcusTextDecoratorViewNativeComponent.ts +199 -0
- package/lib/module/MarcusTextInputDecoratorViewNativeComponent.ts +145 -58
- package/lib/module/MarkdownText.js +325 -0
- package/lib/module/MarkdownText.js.map +1 -0
- package/lib/module/MarkdownText.web.js +524 -0
- package/lib/module/MarkdownText.web.js.map +1 -0
- package/lib/module/MarkdownTextInput.js +24 -29
- package/lib/module/MarkdownTextInput.js.map +1 -1
- package/lib/module/MarkdownTextInput.web.js +12 -7
- package/lib/module/MarkdownTextInput.web.js.map +1 -1
- package/lib/module/atomUtils.js +106 -0
- package/lib/module/atomUtils.js.map +1 -0
- package/lib/module/childrenUtils.js +33 -0
- package/lib/module/childrenUtils.js.map +1 -0
- package/lib/module/index.js +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/math/environment.js +67 -0
- package/lib/module/math/environment.js.map +1 -0
- package/lib/module/math/index.js +56 -0
- package/lib/module/math/index.js.map +1 -0
- package/lib/module/math/mathjax.js +541 -0
- package/lib/module/math/mathjax.js.map +1 -0
- package/lib/module/metro.js +169 -0
- package/lib/module/metro.js.map +1 -0
- package/lib/module/parser/index.d.ts +3 -0
- package/lib/module/parser/index.js +450 -42
- package/lib/module/parser/index.js.map +4 -4
- package/lib/module/stripUtils.js +739 -0
- package/lib/module/stripUtils.js.map +1 -0
- package/lib/module/styleUtils.js +196 -25
- package/lib/module/styleUtils.js.map +1 -1
- package/lib/module/web/MarkdownElements.css +67 -0
- package/lib/module/web/MarkdownTextInput.css +9 -7
- package/lib/module/web/utils/blockLayout.js +94 -8
- package/lib/module/web/utils/blockLayout.js.map +1 -1
- package/lib/module/web/utils/blockUtils.js +328 -56
- package/lib/module/web/utils/blockUtils.js.map +1 -1
- package/lib/module/web/utils/elementUtils.js +75 -0
- package/lib/module/web/utils/elementUtils.js.map +1 -0
- package/lib/module/web/utils/parserUtils.js +86 -30
- package/lib/module/web/utils/parserUtils.js.map +1 -1
- package/lib/module/web/utils/treeUtils.js +6 -0
- package/lib/module/web/utils/treeUtils.js.map +1 -1
- package/lib/module/web/utils/webStyleUtils.js +25 -5
- package/lib/module/web/utils/webStyleUtils.js.map +1 -1
- package/lib/typescript/commonjs/e2e/links.test.d.ts +2 -0
- package/lib/typescript/commonjs/e2e/links.test.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/MarcusTextDecoratorViewNativeComponent.d.ts +93 -0
- package/lib/typescript/commonjs/src/MarcusTextDecoratorViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/MarcusTextInputDecoratorViewNativeComponent.d.ts +64 -51
- package/lib/typescript/commonjs/src/MarcusTextInputDecoratorViewNativeComponent.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/MarkdownText.d.ts +127 -0
- package/lib/typescript/commonjs/src/MarkdownText.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/MarkdownText.web.d.ts +126 -0
- package/lib/typescript/commonjs/src/MarkdownText.web.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/MarkdownTextInput.d.ts +23 -1
- package/lib/typescript/commonjs/src/MarkdownTextInput.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/MarkdownTextInput.web.d.ts +26 -4
- package/lib/typescript/commonjs/src/MarkdownTextInput.web.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/atomUtils.d.ts +58 -0
- package/lib/typescript/commonjs/src/atomUtils.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/childrenUtils.d.ts +12 -0
- package/lib/typescript/commonjs/src/childrenUtils.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/commonTypes.d.ts +39 -3
- package/lib/typescript/commonjs/src/commonTypes.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/index.d.ts +2 -1
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/math/environment.d.ts +7 -0
- package/lib/typescript/commonjs/src/math/environment.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/math/index.d.ts +64 -0
- package/lib/typescript/commonjs/src/math/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/math/mathjax.d.ts +63 -0
- package/lib/typescript/commonjs/src/math/mathjax.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/metro.d.ts +59 -0
- package/lib/typescript/commonjs/src/metro.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/parser/index.d.ts +3 -3
- package/lib/typescript/commonjs/src/parser/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/parser/micromark-extension-mentions.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/rangeUtils.d.ts +1 -1
- package/lib/typescript/commonjs/src/stripUtils.d.ts +108 -0
- package/lib/typescript/commonjs/src/stripUtils.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/styleUtils.d.ts +62 -4
- package/lib/typescript/commonjs/src/styleUtils.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/web/utils/blockLayout.d.ts +32 -4
- package/lib/typescript/commonjs/src/web/utils/blockLayout.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/web/utils/blockUtils.d.ts +20 -8
- package/lib/typescript/commonjs/src/web/utils/blockUtils.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/web/utils/elementUtils.d.ts +37 -0
- package/lib/typescript/commonjs/src/web/utils/elementUtils.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/web/utils/parserUtils.d.ts +5 -5
- package/lib/typescript/commonjs/src/web/utils/parserUtils.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/web/utils/treeUtils.d.ts +6 -1
- package/lib/typescript/commonjs/src/web/utils/treeUtils.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/web/utils/webStyleUtils.d.ts +2 -2
- package/lib/typescript/commonjs/src/web/utils/webStyleUtils.d.ts.map +1 -1
- package/lib/typescript/module/e2e/links.test.d.ts +2 -0
- package/lib/typescript/module/e2e/links.test.d.ts.map +1 -0
- package/lib/typescript/module/src/MarcusTextDecoratorViewNativeComponent.d.ts +93 -0
- package/lib/typescript/module/src/MarcusTextDecoratorViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/module/src/MarcusTextInputDecoratorViewNativeComponent.d.ts +64 -51
- package/lib/typescript/module/src/MarcusTextInputDecoratorViewNativeComponent.d.ts.map +1 -1
- package/lib/typescript/module/src/MarkdownText.d.ts +127 -0
- package/lib/typescript/module/src/MarkdownText.d.ts.map +1 -0
- package/lib/typescript/module/src/MarkdownText.web.d.ts +126 -0
- package/lib/typescript/module/src/MarkdownText.web.d.ts.map +1 -0
- package/lib/typescript/module/src/MarkdownTextInput.d.ts +23 -1
- package/lib/typescript/module/src/MarkdownTextInput.d.ts.map +1 -1
- package/lib/typescript/module/src/MarkdownTextInput.web.d.ts +26 -4
- package/lib/typescript/module/src/MarkdownTextInput.web.d.ts.map +1 -1
- package/lib/typescript/module/src/atomUtils.d.ts +58 -0
- package/lib/typescript/module/src/atomUtils.d.ts.map +1 -0
- package/lib/typescript/module/src/childrenUtils.d.ts +12 -0
- package/lib/typescript/module/src/childrenUtils.d.ts.map +1 -0
- package/lib/typescript/module/src/commonTypes.d.ts +39 -3
- package/lib/typescript/module/src/commonTypes.d.ts.map +1 -1
- package/lib/typescript/module/src/index.d.ts +2 -1
- package/lib/typescript/module/src/index.d.ts.map +1 -1
- package/lib/typescript/module/src/math/environment.d.ts +7 -0
- package/lib/typescript/module/src/math/environment.d.ts.map +1 -0
- package/lib/typescript/module/src/math/index.d.ts +64 -0
- package/lib/typescript/module/src/math/index.d.ts.map +1 -0
- package/lib/typescript/module/src/math/mathjax.d.ts +63 -0
- package/lib/typescript/module/src/math/mathjax.d.ts.map +1 -0
- package/lib/typescript/module/src/metro.d.ts +59 -0
- package/lib/typescript/module/src/metro.d.ts.map +1 -0
- package/lib/typescript/module/src/parser/index.d.ts +3 -3
- package/lib/typescript/module/src/parser/index.d.ts.map +1 -1
- package/lib/typescript/module/src/parser/micromark-extension-mentions.d.ts.map +1 -1
- package/lib/typescript/module/src/rangeUtils.d.ts +1 -1
- package/lib/typescript/module/src/stripUtils.d.ts +108 -0
- package/lib/typescript/module/src/stripUtils.d.ts.map +1 -0
- package/lib/typescript/module/src/styleUtils.d.ts +62 -4
- package/lib/typescript/module/src/styleUtils.d.ts.map +1 -1
- package/lib/typescript/module/src/web/utils/blockLayout.d.ts +32 -4
- package/lib/typescript/module/src/web/utils/blockLayout.d.ts.map +1 -1
- package/lib/typescript/module/src/web/utils/blockUtils.d.ts +20 -8
- package/lib/typescript/module/src/web/utils/blockUtils.d.ts.map +1 -1
- package/lib/typescript/module/src/web/utils/elementUtils.d.ts +37 -0
- package/lib/typescript/module/src/web/utils/elementUtils.d.ts.map +1 -0
- package/lib/typescript/module/src/web/utils/parserUtils.d.ts +5 -5
- package/lib/typescript/module/src/web/utils/parserUtils.d.ts.map +1 -1
- package/lib/typescript/module/src/web/utils/treeUtils.d.ts +6 -1
- package/lib/typescript/module/src/web/utils/treeUtils.d.ts.map +1 -1
- package/lib/typescript/module/src/web/utils/webStyleUtils.d.ts +2 -2
- package/lib/typescript/module/src/web/utils/webStyleUtils.d.ts.map +1 -1
- package/package.json +29 -2
- package/react-native.config.js +8 -1
- package/src/MarcusTextDecoratorViewNativeComponent.ts +199 -0
- package/src/MarcusTextInputDecoratorViewNativeComponent.ts +145 -58
- package/src/MarkdownText.tsx +472 -0
- package/src/MarkdownText.web.tsx +668 -0
- package/src/MarkdownTextInput.tsx +42 -38
- package/src/MarkdownTextInput.web.tsx +36 -13
- package/src/atomUtils.ts +112 -0
- package/src/childrenUtils.ts +39 -0
- package/src/commonTypes.ts +69 -9
- package/src/index.tsx +2 -1
- package/src/math/environment.ts +68 -0
- package/src/math/index.ts +78 -0
- package/src/math/mathjax.ts +604 -0
- package/src/metro.ts +238 -0
- package/src/parser/index.ts +175 -10
- package/src/parser/micromark-extension-mentions.ts +104 -11
- package/src/stripUtils.ts +919 -0
- package/src/styleUtils.ts +290 -26
- package/src/web/MarkdownElements.css +67 -0
- package/src/web/MarkdownTextInput.css +9 -7
- package/src/web/utils/blockLayout.ts +124 -14
- package/src/web/utils/blockUtils.ts +365 -59
- package/src/web/utils/elementUtils.ts +87 -0
- package/src/web/utils/parserUtils.ts +119 -31
- package/src/web/utils/treeUtils.ts +6 -1
- package/src/web/utils/webStyleUtils.ts +32 -8
- package/android/src/main/java/app/getbullet/marcus/spans/MarkdownBackgroundColorSpan.kt +0 -6
- package/android/src/main/java/app/getbullet/marcus/spans/MarkdownBoldSpan.kt +0 -6
- package/android/src/main/java/app/getbullet/marcus/spans/MarkdownItalicSpan.kt +0 -6
- package/apple/RCTMarcusStyle+Codegen.mm +0 -64
- package/apple/RCTMarcusUtils.h +0 -26
- 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
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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 {
|
|
156
|
+
export type {
|
|
157
|
+
MarkdownStyle,
|
|
158
|
+
MarkdownTextStyle,
|
|
159
|
+
MarkdownEmojiStyle,
|
|
160
|
+
MarkdownBoxStyle,
|
|
161
|
+
MarkdownHeadingStyle,
|
|
162
|
+
MarkdownBlockquoteStyle,
|
|
163
|
+
MarkdownListStyle,
|
|
164
|
+
}
|