react-native-marcus 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +227 -0
- package/RNMarcus.podspec +78 -0
- package/android/build.gradle +220 -0
- package/android/proguard-rules.pro +1 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/AndroidManifestNew.xml +2 -0
- package/android/src/main/cpp/CMakeLists.txt +41 -0
- package/android/src/main/cpp/MarkdownParser.cpp +49 -0
- package/android/src/main/cpp/MarkdownParser.h +56 -0
- package/android/src/main/cpp/OnLoad.cpp +17 -0
- package/android/src/main/java/app/getbullet/marcus/MarcusModule.kt +28 -0
- package/android/src/main/java/app/getbullet/marcus/MarcusPackage.kt +31 -0
- package/android/src/main/java/app/getbullet/marcus/MarcusTextInputDecoratorView.kt +63 -0
- package/android/src/main/java/app/getbullet/marcus/MarcusTextInputDecoratorViewManager.kt +32 -0
- package/android/src/main/java/app/getbullet/marcus/MarcusTextInputDecoratorViewManagerSpec.kt +21 -0
- package/android/src/main/java/app/getbullet/marcus/MarkdownFormatter.kt +333 -0
- package/android/src/main/java/app/getbullet/marcus/MarkdownParseResult.kt +12 -0
- package/android/src/main/java/app/getbullet/marcus/MarkdownParser.kt +89 -0
- package/android/src/main/java/app/getbullet/marcus/MarkdownRange.kt +11 -0
- package/android/src/main/java/app/getbullet/marcus/MarkdownStyle.kt +81 -0
- package/android/src/main/java/app/getbullet/marcus/MarkdownTextWatcher.kt +17 -0
- package/android/src/main/java/app/getbullet/marcus/MarkdownUtils.kt +84 -0
- package/android/src/main/java/app/getbullet/marcus/ReactLineHeight.java +29 -0
- package/android/src/main/java/app/getbullet/marcus/spans/MarkdownBackgroundColorSpan.kt +6 -0
- package/android/src/main/java/app/getbullet/marcus/spans/MarkdownBackgroundSpan.kt +105 -0
- package/android/src/main/java/app/getbullet/marcus/spans/MarkdownBlockIndentSpan.kt +67 -0
- package/android/src/main/java/app/getbullet/marcus/spans/MarkdownBoldSpan.kt +6 -0
- package/android/src/main/java/app/getbullet/marcus/spans/MarkdownFontFamilySpan.kt +28 -0
- package/android/src/main/java/app/getbullet/marcus/spans/MarkdownFontSizeSpan.kt +7 -0
- package/android/src/main/java/app/getbullet/marcus/spans/MarkdownForegroundColorSpan.kt +6 -0
- package/android/src/main/java/app/getbullet/marcus/spans/MarkdownGapSpan.kt +57 -0
- package/android/src/main/java/app/getbullet/marcus/spans/MarkdownItalicSpan.kt +6 -0
- package/android/src/main/java/app/getbullet/marcus/spans/MarkdownLineHeightSpan.kt +21 -0
- package/android/src/main/java/app/getbullet/marcus/spans/MarkdownSpan.kt +7 -0
- package/android/src/main/java/app/getbullet/marcus/spans/MarkdownStrikethroughSpan.kt +5 -0
- package/android/src/main/java/app/getbullet/marcus/spans/MarkdownUnderlineSpan.kt +5 -0
- package/android/src/main/new_arch/CMakeLists.txt +70 -0
- package/android/src/main/new_arch/RNMarcusSpec.cpp +43 -0
- package/android/src/main/new_arch/RNMarcusSpec.h +36 -0
- package/android/src/main/new_arch/react/renderer/components/RNMarcusSpec/MarcusTextInputDecoratorShadowNode.cpp +218 -0
- package/android/src/main/new_arch/react/renderer/components/RNMarcusSpec/MarcusTextInputDecoratorShadowNode.h +54 -0
- package/android/src/reactNativeVersionPatch/CustomMountingManager/81/app/getbullet/marcus/CustomFabricUIManager.java +156 -0
- package/android/src/reactNativeVersionPatch/CustomMountingManager/latest/app/getbullet/marcus/CustomFabricUIManager.java +130 -0
- package/android/src/test/java/app/getbullet/marcus/MarkdownFormatterTest.kt +205 -0
- package/android/src/test/java/app/getbullet/marcus/RenderModel.kt +78 -0
- package/android/src/test/resources/render-model.txt +583 -0
- package/apple/MarcusModule.h +8 -0
- package/apple/MarcusModule.mm +26 -0
- package/apple/MarcusRange.h +15 -0
- package/apple/MarcusRange.mm +15 -0
- package/apple/MarcusTextInputDecoratorComponentView.h +12 -0
- package/apple/MarcusTextInputDecoratorComponentView.mm +121 -0
- package/apple/MarcusTextInputDecoratorShadowNode.cpp +251 -0
- package/apple/MarcusTextInputDecoratorShadowNode.h +65 -0
- package/apple/MarcusTextInputDecoratorShadowNode.mm +204 -0
- package/apple/MarcusTextInputDecoratorViewManager.h +8 -0
- package/apple/MarcusTextInputDecoratorViewManager.mm +11 -0
- package/apple/MarkdownAdaptiveImageGlyph.swift +44 -0
- package/apple/MarkdownAttributes.h +31 -0
- package/apple/MarkdownAttributes.m +9 -0
- package/apple/MarkdownBackedTextInputDelegate.swift +117 -0
- package/apple/MarkdownDecorator.swift +316 -0
- package/apple/MarkdownFonts.swift +21 -0
- package/apple/MarkdownFormatter+React.swift +51 -0
- package/apple/MarkdownFormatter.swift +509 -0
- package/apple/MarkdownLog.h +10 -0
- package/apple/MarkdownLog.mm +6 -0
- package/apple/MarkdownParser.swift +200 -0
- package/apple/MarkdownSwiftInterop.h +23 -0
- package/apple/MarkdownTextBackground.swift +17 -0
- package/apple/MarkdownTextFieldObserver.swift +90 -0
- package/apple/MarkdownTextLayoutFragment.swift +205 -0
- package/apple/MarkdownTextLayoutManagerDelegate.swift +84 -0
- package/apple/MarkdownTextStorageDelegate.swift +32 -0
- package/apple/MarkdownTextViewObserver.swift +30 -0
- package/apple/RCTMarcusStyle+Codegen.h +18 -0
- package/apple/RCTMarcusStyle+Codegen.mm +64 -0
- package/apple/RCTMarcusStyle.h +41 -0
- package/apple/RCTMarcusStyle.m +5 -0
- package/apple/RCTMarcusUtils.h +26 -0
- package/apple/RCTMarcusUtils.mm +26 -0
- package/apple/RCTTextInput+AdaptiveImageGlyph.h +16 -0
- package/apple/RCTTextInput+AdaptiveImageGlyph.mm +79 -0
- package/apple/RCTTextInputComponentView+Marcus.h +11 -0
- package/apple/RCTTextInputComponentView+Marcus.mm +79 -0
- package/cpp/MarkdownCxx.modulemap +8 -0
- package/cpp/MarkdownGlobal.cpp +48 -0
- package/cpp/MarkdownGlobal.h +33 -0
- package/cpp/MarkdownWorkletParser.cpp +93 -0
- package/cpp/MarkdownWorkletParser.h +45 -0
- package/cpp/RuntimeDecorator.cpp +39 -0
- package/cpp/RuntimeDecorator.h +14 -0
- package/cpp/react/renderer/components/RNMarcusSpec/MarcusTextInputDecoratorState.h +33 -0
- package/cpp/react/renderer/components/RNMarcusSpec/MarcusTextInputDecoratorViewComponentDescriptor.h +17 -0
- package/lib/commonjs/MarcusTextInputDecoratorViewNativeComponent.ts +77 -0
- package/lib/commonjs/MarkdownTextInput.js +99 -0
- package/lib/commonjs/MarkdownTextInput.js.map +1 -0
- package/lib/commonjs/MarkdownTextInput.web.js +618 -0
- package/lib/commonjs/MarkdownTextInput.web.js.map +1 -0
- package/lib/commonjs/NativeMarcusModule.js +9 -0
- package/lib/commonjs/NativeMarcusModule.js.map +1 -0
- package/lib/commonjs/commonTypes.js +2 -0
- package/lib/commonjs/commonTypes.js.map +1 -0
- package/lib/commonjs/global.d.js +2 -0
- package/lib/commonjs/global.d.js.map +1 -0
- package/lib/commonjs/index.js +27 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/parser/index.js +7030 -0
- package/lib/commonjs/parser/index.js.map +7 -0
- package/lib/commonjs/rangeUtils.js +71 -0
- package/lib/commonjs/rangeUtils.js.map +1 -0
- package/lib/commonjs/react-native-web.d.js +2 -0
- package/lib/commonjs/react-native-web.d.js.map +1 -0
- package/lib/commonjs/styleUtils.js +91 -0
- package/lib/commonjs/styleUtils.js.map +1 -0
- package/lib/commonjs/web/InputHistory.js +111 -0
- package/lib/commonjs/web/InputHistory.js.map +1 -0
- package/lib/commonjs/web/MarkdownTextInput.css +72 -0
- package/lib/commonjs/web/utils/blockLayout.js +132 -0
- package/lib/commonjs/web/utils/blockLayout.js.map +1 -0
- package/lib/commonjs/web/utils/blockUtils.js +219 -0
- package/lib/commonjs/web/utils/blockUtils.js.map +1 -0
- package/lib/commonjs/web/utils/browserUtils.js +40 -0
- package/lib/commonjs/web/utils/browserUtils.js.map +1 -0
- package/lib/commonjs/web/utils/cursorUtils.js +157 -0
- package/lib/commonjs/web/utils/cursorUtils.js.map +1 -0
- package/lib/commonjs/web/utils/inputUtils.js +152 -0
- package/lib/commonjs/web/utils/inputUtils.js.map +1 -0
- package/lib/commonjs/web/utils/measureUtils.js +0 -0
- package/lib/commonjs/web/utils/measureUtils.js.map +1 -0
- package/lib/commonjs/web/utils/parserUtils.js +552 -0
- package/lib/commonjs/web/utils/parserUtils.js.map +1 -0
- package/lib/commonjs/web/utils/treeUtils.js +109 -0
- package/lib/commonjs/web/utils/treeUtils.js.map +1 -0
- package/lib/commonjs/web/utils/webStyleUtils.js +59 -0
- package/lib/commonjs/web/utils/webStyleUtils.js.map +1 -0
- package/lib/module/MarcusTextInputDecoratorViewNativeComponent.ts +77 -0
- package/lib/module/MarkdownTextInput.js +94 -0
- package/lib/module/MarkdownTextInput.js.map +1 -0
- package/lib/module/MarkdownTextInput.web.js +612 -0
- package/lib/module/MarkdownTextInput.web.js.map +1 -0
- package/lib/module/NativeMarcusModule.js +5 -0
- package/lib/module/NativeMarcusModule.js.map +1 -0
- package/lib/module/commonTypes.js +2 -0
- package/lib/module/commonTypes.js.map +1 -0
- package/lib/module/global.d.js +2 -0
- package/lib/module/global.d.js.map +1 -0
- package/lib/module/index.js +5 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/parser/index.js +7029 -0
- package/lib/module/parser/index.js.map +7 -0
- package/lib/module/rangeUtils.js +66 -0
- package/lib/module/rangeUtils.js.map +1 -0
- package/lib/module/react-native-web.d.js +2 -0
- package/lib/module/react-native-web.d.js.map +1 -0
- package/lib/module/styleUtils.js +88 -0
- package/lib/module/styleUtils.js.map +1 -0
- package/lib/module/web/InputHistory.js +106 -0
- package/lib/module/web/InputHistory.js.map +1 -0
- package/lib/module/web/MarkdownTextInput.css +72 -0
- package/lib/module/web/utils/blockLayout.js +128 -0
- package/lib/module/web/utils/blockLayout.js.map +1 -0
- package/lib/module/web/utils/blockUtils.js +210 -0
- package/lib/module/web/utils/blockUtils.js.map +1 -0
- package/lib/module/web/utils/browserUtils.js +36 -0
- package/lib/module/web/utils/browserUtils.js.map +1 -0
- package/lib/module/web/utils/cursorUtils.js +150 -0
- package/lib/module/web/utils/cursorUtils.js.map +1 -0
- package/lib/module/web/utils/inputUtils.js +144 -0
- package/lib/module/web/utils/inputUtils.js.map +1 -0
- package/lib/module/web/utils/measureUtils.js +0 -0
- package/lib/module/web/utils/measureUtils.js.map +1 -0
- package/lib/module/web/utils/parserUtils.js +547 -0
- package/lib/module/web/utils/parserUtils.js.map +1 -0
- package/lib/module/web/utils/treeUtils.js +103 -0
- package/lib/module/web/utils/treeUtils.js.map +1 -0
- package/lib/module/web/utils/webStyleUtils.js +54 -0
- package/lib/module/web/utils/webStyleUtils.js.map +1 -0
- package/lib/typescript/commonjs/e2e/checks.test.d.ts +2 -0
- package/lib/typescript/commonjs/e2e/checks.test.d.ts.map +1 -0
- package/lib/typescript/commonjs/e2e/editing.test.d.ts +2 -0
- package/lib/typescript/commonjs/e2e/editing.test.d.ts.map +1 -0
- package/lib/typescript/commonjs/e2e/helpers.d.ts +23 -0
- package/lib/typescript/commonjs/e2e/helpers.d.ts.map +1 -0
- package/lib/typescript/commonjs/e2e/smoke.test.d.ts +2 -0
- package/lib/typescript/commonjs/e2e/smoke.test.d.ts.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/src/MarcusTextInputDecoratorViewNativeComponent.d.ts +63 -0
- package/lib/typescript/commonjs/src/MarcusTextInputDecoratorViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/MarkdownTextInput.d.ts +22 -0
- package/lib/typescript/commonjs/src/MarkdownTextInput.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/MarkdownTextInput.web.d.ts +41 -0
- package/lib/typescript/commonjs/src/MarkdownTextInput.web.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/NativeMarcusModule.d.ts +7 -0
- package/lib/typescript/commonjs/src/NativeMarcusModule.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/commonTypes.d.ts +10 -0
- package/lib/typescript/commonjs/src/commonTypes.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/index.d.ts +5 -0
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/parser/index.d.ts +8 -0
- package/lib/typescript/commonjs/src/parser/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/parser/micromark-extension-mentions.d.ts +8 -0
- package/lib/typescript/commonjs/src/parser/micromark-extension-mentions.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/rangeUtils.d.ts +6 -0
- package/lib/typescript/commonjs/src/rangeUtils.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/styleUtils.d.ts +8 -0
- package/lib/typescript/commonjs/src/styleUtils.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/web/InputHistory.d.ts +24 -0
- package/lib/typescript/commonjs/src/web/InputHistory.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/web/utils/blockLayout.d.ts +41 -0
- package/lib/typescript/commonjs/src/web/utils/blockLayout.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/web/utils/blockUtils.d.ts +33 -0
- package/lib/typescript/commonjs/src/web/utils/blockUtils.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/web/utils/browserUtils.d.ts +7 -0
- package/lib/typescript/commonjs/src/web/utils/browserUtils.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/web/utils/cursorUtils.d.ts +12 -0
- package/lib/typescript/commonjs/src/web/utils/cursorUtils.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/web/utils/inputUtils.d.ts +12 -0
- package/lib/typescript/commonjs/src/web/utils/inputUtils.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/web/utils/measureUtils.d.ts +22 -0
- package/lib/typescript/commonjs/src/web/utils/measureUtils.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/web/utils/parserUtils.d.ts +44 -0
- package/lib/typescript/commonjs/src/web/utils/parserUtils.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/web/utils/treeUtils.d.ts +25 -0
- package/lib/typescript/commonjs/src/web/utils/treeUtils.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/web/utils/webStyleUtils.d.ts +7 -0
- package/lib/typescript/commonjs/src/web/utils/webStyleUtils.d.ts.map +1 -0
- package/lib/typescript/module/e2e/checks.test.d.ts +2 -0
- package/lib/typescript/module/e2e/checks.test.d.ts.map +1 -0
- package/lib/typescript/module/e2e/editing.test.d.ts +2 -0
- package/lib/typescript/module/e2e/editing.test.d.ts.map +1 -0
- package/lib/typescript/module/e2e/helpers.d.ts +23 -0
- package/lib/typescript/module/e2e/helpers.d.ts.map +1 -0
- package/lib/typescript/module/e2e/smoke.test.d.ts +2 -0
- package/lib/typescript/module/e2e/smoke.test.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/src/MarcusTextInputDecoratorViewNativeComponent.d.ts +63 -0
- package/lib/typescript/module/src/MarcusTextInputDecoratorViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/module/src/MarkdownTextInput.d.ts +22 -0
- package/lib/typescript/module/src/MarkdownTextInput.d.ts.map +1 -0
- package/lib/typescript/module/src/MarkdownTextInput.web.d.ts +41 -0
- package/lib/typescript/module/src/MarkdownTextInput.web.d.ts.map +1 -0
- package/lib/typescript/module/src/NativeMarcusModule.d.ts +7 -0
- package/lib/typescript/module/src/NativeMarcusModule.d.ts.map +1 -0
- package/lib/typescript/module/src/commonTypes.d.ts +10 -0
- package/lib/typescript/module/src/commonTypes.d.ts.map +1 -0
- package/lib/typescript/module/src/index.d.ts +5 -0
- package/lib/typescript/module/src/index.d.ts.map +1 -0
- package/lib/typescript/module/src/parser/index.d.ts +8 -0
- package/lib/typescript/module/src/parser/index.d.ts.map +1 -0
- package/lib/typescript/module/src/parser/micromark-extension-mentions.d.ts +8 -0
- package/lib/typescript/module/src/parser/micromark-extension-mentions.d.ts.map +1 -0
- package/lib/typescript/module/src/rangeUtils.d.ts +6 -0
- package/lib/typescript/module/src/rangeUtils.d.ts.map +1 -0
- package/lib/typescript/module/src/styleUtils.d.ts +8 -0
- package/lib/typescript/module/src/styleUtils.d.ts.map +1 -0
- package/lib/typescript/module/src/web/InputHistory.d.ts +24 -0
- package/lib/typescript/module/src/web/InputHistory.d.ts.map +1 -0
- package/lib/typescript/module/src/web/utils/blockLayout.d.ts +41 -0
- package/lib/typescript/module/src/web/utils/blockLayout.d.ts.map +1 -0
- package/lib/typescript/module/src/web/utils/blockUtils.d.ts +33 -0
- package/lib/typescript/module/src/web/utils/blockUtils.d.ts.map +1 -0
- package/lib/typescript/module/src/web/utils/browserUtils.d.ts +7 -0
- package/lib/typescript/module/src/web/utils/browserUtils.d.ts.map +1 -0
- package/lib/typescript/module/src/web/utils/cursorUtils.d.ts +12 -0
- package/lib/typescript/module/src/web/utils/cursorUtils.d.ts.map +1 -0
- package/lib/typescript/module/src/web/utils/inputUtils.d.ts +12 -0
- package/lib/typescript/module/src/web/utils/inputUtils.d.ts.map +1 -0
- package/lib/typescript/module/src/web/utils/measureUtils.d.ts +22 -0
- package/lib/typescript/module/src/web/utils/measureUtils.d.ts.map +1 -0
- package/lib/typescript/module/src/web/utils/parserUtils.d.ts +44 -0
- package/lib/typescript/module/src/web/utils/parserUtils.d.ts.map +1 -0
- package/lib/typescript/module/src/web/utils/treeUtils.d.ts +25 -0
- package/lib/typescript/module/src/web/utils/treeUtils.d.ts.map +1 -0
- package/lib/typescript/module/src/web/utils/webStyleUtils.d.ts +7 -0
- package/lib/typescript/module/src/web/utils/webStyleUtils.d.ts.map +1 -0
- package/package.json +167 -0
- package/react-native.config.js +10 -0
- package/src/MarcusTextInputDecoratorViewNativeComponent.ts +77 -0
- package/src/MarkdownTextInput.tsx +139 -0
- package/src/MarkdownTextInput.web.tsx +958 -0
- package/src/NativeMarcusModule.ts +8 -0
- package/src/commonTypes.ts +30 -0
- package/src/global.d.ts +1 -0
- package/src/index.tsx +4 -0
- package/src/parser/index.ts +556 -0
- package/src/parser/micromark-extension-mentions.ts +82 -0
- package/src/rangeUtils.ts +68 -0
- package/src/react-native-web.d.ts +1 -0
- package/src/styleUtils.ts +100 -0
- package/src/web/InputHistory.ts +137 -0
- package/src/web/MarkdownTextInput.css +72 -0
- package/src/web/utils/blockLayout.ts +163 -0
- package/src/web/utils/blockUtils.ts +245 -0
- package/src/web/utils/browserUtils.ts +41 -0
- package/src/web/utils/cursorUtils.ts +204 -0
- package/src/web/utils/inputUtils.ts +206 -0
- package/src/web/utils/measureUtils.ts +0 -0
- package/src/web/utils/parserUtils.ts +813 -0
- package/src/web/utils/treeUtils.ts +149 -0
- package/src/web/utils/webStyleUtils.ts +69 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
package app.getbullet.marcus.spans
|
|
2
|
+
|
|
3
|
+
import android.graphics.Canvas
|
|
4
|
+
import android.graphics.Paint
|
|
5
|
+
import android.graphics.Path
|
|
6
|
+
import android.graphics.RectF
|
|
7
|
+
import android.text.StaticLayout
|
|
8
|
+
import android.text.TextPaint
|
|
9
|
+
import android.text.style.LineBackgroundSpan
|
|
10
|
+
import androidx.annotation.ColorInt
|
|
11
|
+
|
|
12
|
+
class MarkdownBackgroundSpan(
|
|
13
|
+
@ColorInt private val backgroundColor: Int,
|
|
14
|
+
private val borderRadius: Float,
|
|
15
|
+
private val mentionStart: Int,
|
|
16
|
+
private val mentionEnd: Int
|
|
17
|
+
) : MarkdownSpan, LineBackgroundSpan {
|
|
18
|
+
|
|
19
|
+
private var layout: StaticLayout? = null
|
|
20
|
+
private val backgroundPath = Path()
|
|
21
|
+
|
|
22
|
+
override fun drawBackground(
|
|
23
|
+
canvas: Canvas,
|
|
24
|
+
paint: Paint,
|
|
25
|
+
left: Int,
|
|
26
|
+
right: Int,
|
|
27
|
+
top: Int,
|
|
28
|
+
baseline: Int,
|
|
29
|
+
bottom: Int,
|
|
30
|
+
text: CharSequence,
|
|
31
|
+
start: Int,
|
|
32
|
+
end: Int,
|
|
33
|
+
lnum: Int
|
|
34
|
+
) {
|
|
35
|
+
val lineText = text.subSequence(start, end)
|
|
36
|
+
val cachedLayout = layout
|
|
37
|
+
// `!==` on purpose: the Java this replaces compared the layout's text by
|
|
38
|
+
// reference, not by value.
|
|
39
|
+
if (cachedLayout == null ||
|
|
40
|
+
cachedLayout.text !== lineText ||
|
|
41
|
+
cachedLayout.width != right ||
|
|
42
|
+
cachedLayout.getLineEnd(0) != lineText.length
|
|
43
|
+
) {
|
|
44
|
+
val currentLineStart = 0
|
|
45
|
+
val currentLineEnd = lineText.length
|
|
46
|
+
// Create layout for the current line only
|
|
47
|
+
val newLayout = StaticLayout.Builder
|
|
48
|
+
.obtain(lineText, currentLineStart, currentLineEnd, paint as TextPaint, right)
|
|
49
|
+
.build()
|
|
50
|
+
layout = newLayout
|
|
51
|
+
|
|
52
|
+
val relativeMentionStart = mentionStart - start
|
|
53
|
+
val relativeMentionEnd = mentionEnd - start
|
|
54
|
+
|
|
55
|
+
val mentionStartsInCurrentLine = currentLineStart <= relativeMentionStart
|
|
56
|
+
val mentionEndsInCurrentLine = currentLineEnd >= relativeMentionEnd
|
|
57
|
+
|
|
58
|
+
val startX = newLayout.getPrimaryHorizontal(
|
|
59
|
+
if (mentionStartsInCurrentLine) relativeMentionStart else currentLineStart
|
|
60
|
+
)
|
|
61
|
+
val endX = newLayout.getPrimaryHorizontal(
|
|
62
|
+
if (mentionEndsInCurrentLine) relativeMentionEnd else currentLineEnd
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
val fm = paint.getFontMetrics()
|
|
66
|
+
val startY = baseline + fm.ascent
|
|
67
|
+
val endY = baseline + fm.descent
|
|
68
|
+
|
|
69
|
+
val lineRect = RectF(startX, startY, endX, endY)
|
|
70
|
+
backgroundPath.reset()
|
|
71
|
+
backgroundPath.addRoundRect(
|
|
72
|
+
lineRect,
|
|
73
|
+
createRadii(mentionStartsInCurrentLine, mentionEndsInCurrentLine),
|
|
74
|
+
Path.Direction.CW
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
val originalColor = paint.color
|
|
79
|
+
paint.color = backgroundColor
|
|
80
|
+
|
|
81
|
+
canvas.drawPath(backgroundPath, paint)
|
|
82
|
+
|
|
83
|
+
paint.color = originalColor
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
private fun createRadii(roundedLeft: Boolean, roundedRight: Boolean): FloatArray {
|
|
87
|
+
val radii = FloatArray(8)
|
|
88
|
+
|
|
89
|
+
if (roundedLeft) {
|
|
90
|
+
radii[1] = borderRadius // top-left
|
|
91
|
+
radii[0] = radii[1]
|
|
92
|
+
radii[7] = borderRadius // bottom-left
|
|
93
|
+
radii[6] = radii[7]
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (roundedRight) {
|
|
97
|
+
radii[3] = borderRadius // top-right
|
|
98
|
+
radii[2] = radii[3]
|
|
99
|
+
radii[5] = borderRadius // bottom-right
|
|
100
|
+
radii[4] = radii[5]
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return radii
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
package app.getbullet.marcus.spans
|
|
2
|
+
|
|
3
|
+
import android.graphics.Canvas
|
|
4
|
+
import android.graphics.Paint
|
|
5
|
+
import android.text.Layout
|
|
6
|
+
import android.text.style.LeadingMarginSpan
|
|
7
|
+
import androidx.annotation.ColorInt
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Indents one line by the containers it sits in, and draws a blockquote's
|
|
11
|
+
* ribbons in the gutter reserved for them.
|
|
12
|
+
*
|
|
13
|
+
* One span per line rather than one per container: where a container's gutter
|
|
14
|
+
* goes depends on the markers of the containers around it, so the offsets are
|
|
15
|
+
* worked out together by the formatter and handed over already in pixels.
|
|
16
|
+
*/
|
|
17
|
+
class MarkdownBlockIndentSpan(
|
|
18
|
+
@ColorInt private val borderColor: Int,
|
|
19
|
+
private val borderWidth: Float,
|
|
20
|
+
private val borderSpacing: Float
|
|
21
|
+
) : MarkdownSpan, LeadingMarginSpan {
|
|
22
|
+
|
|
23
|
+
/** Where the line's text starts, and where it resumes when it wraps. */
|
|
24
|
+
var firstLineIndent = 0f
|
|
25
|
+
var indent = 0f
|
|
26
|
+
|
|
27
|
+
/** Left edge of the blockquote's gutter, and how many ribbons fill it. */
|
|
28
|
+
var ribbonOffset = 0f
|
|
29
|
+
var depth = 0
|
|
30
|
+
|
|
31
|
+
override fun getLeadingMargin(first: Boolean): Int {
|
|
32
|
+
return (if (first) firstLineIndent else indent).toInt()
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
override fun drawLeadingMargin(
|
|
36
|
+
c: Canvas,
|
|
37
|
+
p: Paint,
|
|
38
|
+
x: Int,
|
|
39
|
+
dir: Int,
|
|
40
|
+
top: Int,
|
|
41
|
+
baseline: Int,
|
|
42
|
+
bottom: Int,
|
|
43
|
+
text: CharSequence?,
|
|
44
|
+
start: Int,
|
|
45
|
+
end: Int,
|
|
46
|
+
first: Boolean,
|
|
47
|
+
layout: Layout?
|
|
48
|
+
) {
|
|
49
|
+
if (depth == 0) {
|
|
50
|
+
return
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
val originalStyle = p.style
|
|
54
|
+
val originalColor = p.color
|
|
55
|
+
|
|
56
|
+
p.style = Paint.Style.FILL
|
|
57
|
+
p.color = borderColor
|
|
58
|
+
|
|
59
|
+
for (level in 0 until depth) {
|
|
60
|
+
val left = x + dir * (ribbonOffset + borderSpacing * level)
|
|
61
|
+
c.drawRect(left, top.toFloat(), left + dir * borderWidth, bottom.toFloat(), p)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
p.style = originalStyle
|
|
65
|
+
p.color = originalColor
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
package app.getbullet.marcus.spans
|
|
2
|
+
|
|
3
|
+
import android.content.res.AssetManager
|
|
4
|
+
import android.graphics.Paint
|
|
5
|
+
import android.text.TextPaint
|
|
6
|
+
import android.text.style.MetricAffectingSpan
|
|
7
|
+
import com.facebook.react.common.assets.ReactFontManager
|
|
8
|
+
|
|
9
|
+
class MarkdownFontFamilySpan(
|
|
10
|
+
private val fontFamily: String,
|
|
11
|
+
private val assetManager: AssetManager
|
|
12
|
+
) : MetricAffectingSpan(), MarkdownSpan {
|
|
13
|
+
|
|
14
|
+
override fun updateMeasureState(textPaint: TextPaint) {
|
|
15
|
+
apply(textPaint)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
override fun updateDrawState(tp: TextPaint) {
|
|
19
|
+
apply(tp)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
private fun apply(textPaint: TextPaint) {
|
|
23
|
+
val style = textPaint.typeface?.style ?: ReactFontManager.TypefaceStyle.NORMAL
|
|
24
|
+
val typeface = ReactFontManager.getInstance().getTypeface(fontFamily, style, assetManager)
|
|
25
|
+
textPaint.typeface = typeface
|
|
26
|
+
textPaint.flags = textPaint.flags or Paint.SUBPIXEL_TEXT_FLAG
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
package app.getbullet.marcus.spans
|
|
2
|
+
|
|
3
|
+
import android.graphics.Canvas
|
|
4
|
+
import android.graphics.Paint
|
|
5
|
+
import android.text.style.ReplacementSpan
|
|
6
|
+
import androidx.annotation.ColorInt
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Widens the character it covers by [gap] pixels, leaving the glyph where it is.
|
|
10
|
+
*
|
|
11
|
+
* Applied to the last character of a container's marker so that the container
|
|
12
|
+
* nested inside it can put its gutter between that marker and the next one.
|
|
13
|
+
*/
|
|
14
|
+
class MarkdownGapSpan(
|
|
15
|
+
private val gap: Float,
|
|
16
|
+
@ColorInt private val syntaxColor: Int
|
|
17
|
+
) : ReplacementSpan(), MarkdownSpan {
|
|
18
|
+
|
|
19
|
+
override fun getSize(
|
|
20
|
+
paint: Paint,
|
|
21
|
+
text: CharSequence,
|
|
22
|
+
start: Int,
|
|
23
|
+
end: Int,
|
|
24
|
+
fm: Paint.FontMetricsInt?
|
|
25
|
+
): Int {
|
|
26
|
+
if (fm != null) {
|
|
27
|
+
val metrics = paint.fontMetricsInt
|
|
28
|
+
fm.top = metrics.top
|
|
29
|
+
fm.ascent = metrics.ascent
|
|
30
|
+
fm.descent = metrics.descent
|
|
31
|
+
fm.bottom = metrics.bottom
|
|
32
|
+
fm.leading = metrics.leading
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return (paint.measureText(text, start, end) + gap).toInt()
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
override fun draw(
|
|
39
|
+
canvas: Canvas,
|
|
40
|
+
text: CharSequence,
|
|
41
|
+
start: Int,
|
|
42
|
+
end: Int,
|
|
43
|
+
x: Float,
|
|
44
|
+
top: Int,
|
|
45
|
+
y: Int,
|
|
46
|
+
bottom: Int,
|
|
47
|
+
paint: Paint
|
|
48
|
+
) {
|
|
49
|
+
// Spans inside a replacement are not applied, so the one colour a marker's
|
|
50
|
+
// last character can have is restored by hand. It is whitespace whenever the
|
|
51
|
+
// marker is followed by any, and a syntax character otherwise.
|
|
52
|
+
val originalColor = paint.color
|
|
53
|
+
paint.color = syntaxColor
|
|
54
|
+
canvas.drawText(text, start, end, x, y.toFloat(), paint)
|
|
55
|
+
paint.color = originalColor
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
package app.getbullet.marcus.spans
|
|
2
|
+
|
|
3
|
+
import android.graphics.Paint
|
|
4
|
+
import android.text.style.LineHeightSpan
|
|
5
|
+
|
|
6
|
+
class MarkdownLineHeightSpan(private val lineHeight: Float) : MarkdownSpan, LineHeightSpan {
|
|
7
|
+
override fun chooseHeight(
|
|
8
|
+
text: CharSequence?,
|
|
9
|
+
start: Int,
|
|
10
|
+
end: Int,
|
|
11
|
+
spanstartv: Int,
|
|
12
|
+
lineHeight: Int,
|
|
13
|
+
fm: Paint.FontMetricsInt
|
|
14
|
+
) {
|
|
15
|
+
// Java's `fm.top -= this.lineHeight / 4` performs the subtraction in float and
|
|
16
|
+
// narrows the result, so the truncation has to happen after the subtraction.
|
|
17
|
+
// Truncating the quotient first would shift the value by up to one pixel.
|
|
18
|
+
fm.top = (fm.top - this.lineHeight / 4).toInt()
|
|
19
|
+
fm.ascent = (fm.ascent - this.lineHeight / 4).toInt()
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.13)
|
|
2
|
+
set(CMAKE_VERBOSE_MAKEFILE ON)
|
|
3
|
+
set(CMAKE_CXX_STANDARD 20)
|
|
4
|
+
|
|
5
|
+
set(LIB_LITERAL RNMarcusSpec)
|
|
6
|
+
set(LIB_TARGET_NAME react_codegen_${LIB_LITERAL})
|
|
7
|
+
|
|
8
|
+
set(LIB_ANDROID_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
|
|
9
|
+
set(LIB_CPP_DIR ${LIB_ANDROID_DIR}/../cpp)
|
|
10
|
+
set(LIB_CUSTOM_SOURCES_DIR ${LIB_CPP_DIR}/react/renderer/components/${LIB_LITERAL})
|
|
11
|
+
set(LIB_ANDROID_GENERATED_JNI_DIR ${LIB_ANDROID_DIR}/build/generated/source/codegen/jni)
|
|
12
|
+
set(LIB_ANDROID_GENERATED_COMPONENTS_DIR ${LIB_ANDROID_GENERATED_JNI_DIR}/react/renderer/components/${LIB_LITERAL})
|
|
13
|
+
|
|
14
|
+
file(GLOB LIB_MODULE_SRCS CONFIGURE_DEPENDS *.cpp react/renderer/components/RNMarcusSpec/*.cpp)
|
|
15
|
+
file(GLOB LIB_CUSTOM_SRCS CONFIGURE_DEPENDS ${LIB_CUSTOM_SOURCES_DIR}/*.cpp)
|
|
16
|
+
file(GLOB LIB_CODEGEN_SRCS CONFIGURE_DEPENDS ${LIB_ANDROID_GENERATED_COMPONENTS_DIR}/*.cpp)
|
|
17
|
+
|
|
18
|
+
add_library(
|
|
19
|
+
${LIB_TARGET_NAME}
|
|
20
|
+
SHARED
|
|
21
|
+
${LIB_MODULE_SRCS}
|
|
22
|
+
${LIB_CUSTOM_SRCS}
|
|
23
|
+
${LIB_CODEGEN_SRCS}
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
target_include_directories(
|
|
27
|
+
${LIB_TARGET_NAME}
|
|
28
|
+
PUBLIC
|
|
29
|
+
.
|
|
30
|
+
./react/renderer/components/RNMarcusSpec
|
|
31
|
+
${LIB_ANDROID_GENERATED_JNI_DIR}
|
|
32
|
+
${LIB_ANDROID_GENERATED_COMPONENTS_DIR}
|
|
33
|
+
${LIB_CPP_DIR}
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
find_package(fbjni REQUIRED CONFIG)
|
|
37
|
+
find_package(ReactAndroid REQUIRED CONFIG)
|
|
38
|
+
|
|
39
|
+
target_link_libraries(
|
|
40
|
+
${LIB_TARGET_NAME}
|
|
41
|
+
fbjni::fbjni
|
|
42
|
+
ReactAndroid::jsi
|
|
43
|
+
ReactAndroid::reactnative
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
if (ReactAndroid_VERSION_MINOR LESS_EQUAL 80)
|
|
47
|
+
target_compile_options(
|
|
48
|
+
${LIB_TARGET_NAME}
|
|
49
|
+
PRIVATE
|
|
50
|
+
-DLOG_TAG=\"ReactNative\"
|
|
51
|
+
-fexceptions
|
|
52
|
+
-frtti
|
|
53
|
+
-Wall
|
|
54
|
+
-std=c++20
|
|
55
|
+
)
|
|
56
|
+
else()
|
|
57
|
+
target_compile_reactnative_options(${LIB_TARGET_NAME} PRIVATE)
|
|
58
|
+
endif()
|
|
59
|
+
|
|
60
|
+
target_compile_options(
|
|
61
|
+
${LIB_TARGET_NAME}
|
|
62
|
+
PRIVATE
|
|
63
|
+
-DREACT_NATIVE_MINOR_VERSION=${ReactAndroid_VERSION_MINOR}
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
target_include_directories(
|
|
67
|
+
${CMAKE_PROJECT_NAME}
|
|
68
|
+
PUBLIC
|
|
69
|
+
${CMAKE_CURRENT_SOURCE_DIR}
|
|
70
|
+
)
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* This code was generated by
|
|
4
|
+
* [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
5
|
+
*
|
|
6
|
+
* Do not edit this file as changes may cause incorrect behavior and will be
|
|
7
|
+
* lost once the code is regenerated.
|
|
8
|
+
*
|
|
9
|
+
* @generated by codegen project: GenerateModuleJniCpp.js
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
#include "RNMarcusSpec.h"
|
|
13
|
+
|
|
14
|
+
namespace facebook {
|
|
15
|
+
namespace react {
|
|
16
|
+
|
|
17
|
+
static facebook::jsi::Value
|
|
18
|
+
__hostFunction_NativeMarcusModuleSpecJSI_install(
|
|
19
|
+
facebook::jsi::Runtime &rt, TurboModule &turboModule, const facebook::jsi::Value *args, size_t count
|
|
20
|
+
) {
|
|
21
|
+
static jmethodID cachedMethodId = nullptr;
|
|
22
|
+
return static_cast<JavaTurboModule &>(turboModule)
|
|
23
|
+
.invokeJavaMethod(rt, BooleanKind, "install", "()Z", args, count, cachedMethodId);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
NativeMarcusModuleSpecJSI::NativeMarcusModuleSpecJSI(
|
|
27
|
+
const JavaTurboModule::InitParams ¶ms
|
|
28
|
+
)
|
|
29
|
+
: JavaTurboModule(params) {
|
|
30
|
+
methodMap_["install"] =
|
|
31
|
+
MethodMetadata{0, __hostFunction_NativeMarcusModuleSpecJSI_install};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
std::shared_ptr<TurboModule>
|
|
35
|
+
RNMarcusSpec_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams ¶ms) {
|
|
36
|
+
if (moduleName == "MarcusModule") {
|
|
37
|
+
return std::make_shared<NativeMarcusModuleSpecJSI>(params);
|
|
38
|
+
}
|
|
39
|
+
return nullptr;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
} // namespace react
|
|
43
|
+
} // namespace facebook
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* This code was generated by
|
|
4
|
+
* [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
5
|
+
*
|
|
6
|
+
* Do not edit this file as changes may cause incorrect behavior and will be
|
|
7
|
+
* lost once the code is regenerated.
|
|
8
|
+
*
|
|
9
|
+
* @generated by codegen project: GenerateModuleJniH.js
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
#pragma once
|
|
13
|
+
|
|
14
|
+
#include <ReactCommon/JavaTurboModule.h>
|
|
15
|
+
#include <ReactCommon/TurboModule.h>
|
|
16
|
+
#include <jsi/jsi.h>
|
|
17
|
+
|
|
18
|
+
#include <react/renderer/components/RNMarcusSpec/MarcusTextInputDecoratorViewComponentDescriptor.h>
|
|
19
|
+
|
|
20
|
+
namespace facebook {
|
|
21
|
+
namespace react {
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* JNI C++ class for module 'NativeMarcusModule'
|
|
25
|
+
*/
|
|
26
|
+
class JSI_EXPORT NativeMarcusModuleSpecJSI : public JavaTurboModule {
|
|
27
|
+
public:
|
|
28
|
+
NativeMarcusModuleSpecJSI(const JavaTurboModule::InitParams ¶ms);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
JSI_EXPORT
|
|
32
|
+
std::shared_ptr<TurboModule>
|
|
33
|
+
RNMarcusSpec_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams ¶ms);
|
|
34
|
+
|
|
35
|
+
} // namespace react
|
|
36
|
+
} // namespace facebook
|