react-native-enriched-markdown-scaffold 1.0.2-scaffold.9 → 1.2.0-scaffold.2
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/ReactNativeEnrichedMarkdown.podspec +31 -10
- package/android/build.gradle +49 -12
- package/android/consumer-rules.pro +3 -0
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownManagerDelegate.java +18 -0
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownManagerInterface.java +6 -0
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownTextInputManagerDelegate.java +3 -0
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownTextInputManagerInterface.java +1 -0
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownTextManagerDelegate.java +18 -0
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownTextManagerInterface.java +6 -0
- package/android/generated/jni/react/renderer/components/EnrichedMarkdownTextSpec/EventEmitters.cpp +62 -0
- package/android/generated/jni/react/renderer/components/EnrichedMarkdownTextSpec/EventEmitters.h +44 -0
- package/android/generated/jni/react/renderer/components/EnrichedMarkdownTextSpec/Props.cpp +67 -2
- package/android/generated/jni/react/renderer/components/EnrichedMarkdownTextSpec/Props.h +929 -178
- package/android/src/main/baseline-prof.txt +21 -22
- package/android/src/main/cpp/jni-adapter.cpp +17 -5
- package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdown.kt +729 -768
- package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownInternalText.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownManager.kt +72 -3
- package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownText.kt +222 -8
- package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownTextManager.kt +65 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/MeasurementStore.kt +191 -26
- package/android/src/main/java/com/swmansion/enriched/markdown/accessibility/AccessibleMarkdownTextView.kt +10 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/accessibility/MarkdownAccessibilityHelper.kt +54 -6
- package/android/src/main/java/com/swmansion/enriched/markdown/events/CodeBlockPressEvent.kt +24 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/events/ImagePressEvent.kt +25 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/events/LatexErrorEvent.kt +29 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/input/EnrichedMarkdownTextInputManager.kt +21 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/input/EnrichedMarkdownTextInputView.kt +101 -9
- package/android/src/main/java/com/swmansion/enriched/markdown/input/editing/EditPipeline.kt +48 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/input/editing/InputConnectionWrapper.kt +7 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/input/editing/MarkdownShortcutMatcher.kt +64 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/input/formatting/InputRemend.kt +44 -6
- package/android/src/main/java/com/swmansion/enriched/markdown/input/layout/InputEventEmitter.kt +9 -8
- package/android/src/main/java/com/swmansion/enriched/markdown/math/LatexErrorReporter.kt +9 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/parser/MarkdownASTNode.kt +6 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/parser/Parser.kt +5 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/BlankLineRenderer.kt +38 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/BlockStyleContext.kt +2 -2
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/BlockquoteRenderer.kt +3 -2
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/BlockquoteTextRenderer.kt +55 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/CodeBlockRenderer.kt +8 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/HighlightRenderer.kt +10 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/NodeRenderer.kt +31 -3
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/ParagraphRenderer.kt +17 -2
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/Renderer.kt +40 -21
- package/android/src/main/java/com/swmansion/enriched/markdown/segments/AdmonitionIcons.kt +62 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/{views → segments}/BlockSegmentView.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/segments/BlockquoteContainerView.kt +401 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/{views → segments}/CodeBlockContainerView.kt +55 -16
- package/android/src/main/java/com/swmansion/enriched/markdown/segments/ContainerNodeView.kt +164 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/{utils/common → segments}/MarkdownSegment.kt +21 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/segments/RenderedSegment.kt +137 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/segments/SegmentHeightMeasurer.kt +139 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/{utils/common → segments}/SegmentReconciler.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/{utils/common → segments}/SegmentSignature.kt +3 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/segments/SegmentViewCreators.kt +262 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/segments/SegmentViewFactory.kt +29 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/{views → segments}/TableContainerView.kt +100 -36
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/CodeBackgroundSpan.kt +18 -17
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/CodeBlockSpan.kt +3 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/HighlightSpan.kt +60 -6
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/ImageSpan.kt +15 -5
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/InlineBackgroundGeometry.kt +42 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/InlineChipPainter.kt +4 -27
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/LineHeightSpan.kt +10 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/LinkSpan.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/spoiler/SpoilerDrawUtils.kt +11 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/styles/BlockquoteStyle.kt +27 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/styles/LinkVariantEntry.kt +2 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/styles/StyleConfig.kt +10 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/styles/VideoStyle.kt +31 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/BorderStyleUtils.kt +86 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/EllipsizeUtils.kt +27 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/EnrichedMarkdownAncestorUtils.kt +10 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/FeatureFlags.kt +1 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/MarkdownViewManagerUtils.kt +36 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/ReadableMapExtensions.kt +5 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/serialization/MarkdownASTSerializer.kt +227 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/input/PasteTextUtils.kt +34 -2
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/conversion/HTMLGenerator.kt +50 -28
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/conversion/MarkdownExtractor.kt +16 -21
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/extensions/SpannableExtensions.kt +4 -3
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/span/BlockSpacing.kt +3 -2
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/span/SpanFlags.kt +13 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/view/CodeBlockPressHost.kt +15 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/view/ImagePressHost.kt +19 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/view/LinkEvents.kt +11 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/view/LinkLongPressMovementMethod.kt +87 -2
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/view/TextViewSetup.kt +79 -0
- package/android/src/main/jni/react/renderer/components/EnrichedMarkdownTextSpec/conversions.h +2 -0
- package/android/src/math/java/com/swmansion/enriched/markdown/renderer/MathInlineRenderer.kt +9 -3
- package/android/src/math/java/com/swmansion/enriched/markdown/{views → segments}/MathContainerView.kt +86 -29
- package/android/src/math/java/com/swmansion/enriched/markdown/spans/MathInlineSpan.kt +33 -7
- package/android/src/video/java/com/swmansion/enriched/markdown/segments/VideoContainerView.kt +115 -0
- package/cpp/md4c/md4c.c +343 -236
- package/cpp/md4c/md4c.h +28 -11
- package/cpp/parser/MD4CParser.cpp +266 -4
- package/cpp/parser/MD4CParser.hpp +6 -2
- package/cpp/parser/MarkdownASTNode.hpp +4 -1
- package/cpp/wasm/ASTSerializer.cpp +6 -0
- package/cpp/wasm/md4c_wasm.cpp +5 -1
- package/docs/API_REFERENCE.md +199 -12
- package/docs/BREAKING_CHANGES.md +75 -0
- package/docs/CODE_HIGHLIGHT.md +4 -0
- package/docs/COPY_OPTIONS.md +52 -9
- package/docs/ELEMENTS_STRUCTURE.md +48 -1
- package/docs/INPUT.md +60 -3
- package/docs/LATEX_MATH.md +30 -0
- package/docs/MACOS.md +1 -1
- package/docs/MENTIONS.md +2 -2
- package/docs/STYLES.md +27 -0
- package/docs/TEXT.md +8 -0
- package/docs/WEB.md +44 -10
- package/ios/EnrichedMarkdown.mm +285 -43
- package/ios/EnrichedMarkdownText.mm +185 -23
- package/ios/attachments/ENRMImageAttachment.h +17 -2
- package/ios/attachments/ENRMImageAttachment.m +26 -28
- package/ios/attachments/ENRMMathInlineAttachment+macOS.m +10 -2
- package/ios/attachments/ENRMMathInlineAttachment.h +3 -1
- package/ios/attachments/ENRMMathInlineAttachment.m +17 -1
- package/ios/attachments/ENRMMathInlineAttachmentShared.h +3 -0
- package/ios/generated/ReactCodegen/EnrichedMarkdownTextSpec/EventEmitters.cpp +62 -0
- package/ios/generated/ReactCodegen/EnrichedMarkdownTextSpec/EventEmitters.h +44 -0
- package/ios/generated/ReactCodegen/EnrichedMarkdownTextSpec/Props.cpp +67 -2
- package/ios/generated/ReactCodegen/EnrichedMarkdownTextSpec/Props.h +929 -178
- package/ios/input/ENRMInputFormatter.mm +68 -12
- package/ios/input/ENRMInputFormatterStyle.mm +9 -2
- package/ios/input/ENRMInputParser.mm +18 -0
- package/ios/input/ENRMInputRemend.mm +40 -3
- package/ios/input/ENRMMarkdownShortcutMatcher.h +39 -0
- package/ios/input/ENRMMarkdownShortcutMatcher.mm +66 -0
- package/ios/input/EnrichedMarkdownTextInput.mm +129 -1
- package/ios/internals/ENRMViewFreeMeasurement.h +45 -6
- package/ios/internals/MeasurementCache.h +20 -4
- package/ios/internals/ShadowMeasurementUtils.h +2 -0
- package/ios/math/ENRMLatexErrorCoordinator.h +27 -0
- package/ios/math/ENRMLatexErrorCoordinator.mm +75 -0
- package/ios/math/ENRMLatexErrorReporting.h +13 -0
- package/ios/math/ENRMRaTeXBridge.swift +46 -3
- package/ios/parser/ENRMMarkdownParser.h +3 -0
- package/ios/parser/ENRMMarkdownParser.mm +11 -2
- package/ios/parser/MarkdownASTNode.h +8 -1
- package/ios/parser/MarkdownASTNode.m +20 -0
- package/ios/parser/MarkdownParserBridge.mm +13 -2
- package/ios/renderer/AttributedRenderer.h +13 -1
- package/ios/renderer/AttributedRenderer.m +24 -13
- package/ios/renderer/BaselineShiftTextAttributes.h +4 -0
- package/ios/renderer/BaselineShiftTextAttributes.m +4 -0
- package/ios/renderer/BlankLineRenderer.h +4 -0
- package/ios/renderer/BlankLineRenderer.m +51 -0
- package/ios/renderer/BlockquoteRenderer.m +1 -0
- package/ios/renderer/CodeBlockRenderer.m +8 -0
- package/ios/renderer/CodeRenderer.m +5 -2
- package/ios/renderer/ENRMBlockquoteTextRenderer.h +25 -0
- package/ios/renderer/ENRMBlockquoteTextRenderer.m +48 -0
- package/ios/renderer/ENRMImageRenderer.m +1 -1
- package/ios/renderer/ENRMMathInlineRenderer.m +9 -1
- package/ios/renderer/HeadingRenderer.m +1 -0
- package/ios/renderer/HighlightRenderer.m +6 -0
- package/ios/renderer/LinkRenderer.m +1 -1
- package/ios/renderer/ListItemRenderer.m +51 -2
- package/ios/renderer/ParagraphRenderer.m +10 -3
- package/ios/renderer/RenderContext.h +16 -0
- package/ios/renderer/RenderContext.m +16 -0
- package/ios/renderer/RendererFactory.m +6 -0
- package/ios/renderer/SubscriptRenderer.m +1 -0
- package/ios/renderer/SuperscriptRenderer.m +1 -0
- package/ios/segments/ENRMAdmonitionIcons.h +31 -0
- package/ios/segments/ENRMAdmonitionIcons.m +93 -0
- package/ios/segments/ENRMBlockquoteContainerView.h +90 -0
- package/ios/segments/ENRMBlockquoteContainerView.mm +551 -0
- package/ios/{views → segments}/ENRMCodeBlockContainerView.h +9 -4
- package/ios/{views → segments}/ENRMCodeBlockContainerView.m +147 -36
- package/ios/segments/ENRMContainerNodeView.h +52 -0
- package/ios/segments/ENRMContainerNodeView.mm +201 -0
- package/ios/segments/ENRMDynamicBlockProps.h +32 -0
- package/ios/segments/ENRMDynamicBlockProps.m +15 -0
- package/ios/{views → segments}/ENRMMathContainerView.h +13 -5
- package/ios/{views → segments}/ENRMMathContainerView.m +60 -9
- package/ios/segments/ENRMSVGPath.h +21 -0
- package/ios/segments/ENRMSVGPath.m +409 -0
- package/ios/segments/ENRMSegmentHeightMeasurer.h +33 -0
- package/ios/segments/ENRMSegmentHeightMeasurer.mm +94 -0
- package/ios/segments/ENRMVideoContainerView.h +40 -0
- package/ios/segments/ENRMVideoContainerView.m +421 -0
- package/ios/{utils → segments}/RenderedMarkdownSegment.h +19 -2
- package/ios/{utils → segments}/RenderedMarkdownSegment.m +42 -1
- package/ios/segments/SegmentRenderer.h +26 -0
- package/ios/{utils → segments}/SegmentRenderer.m +46 -9
- package/ios/{views → segments}/TableContainerView.h +5 -4
- package/ios/{views → segments}/TableContainerView.m +96 -12
- package/ios/styles/StyleConfig.h +17 -0
- package/ios/styles/StyleConfig.mm +90 -0
- package/ios/utils/ENRMCodeBlockContent.mm +13 -0
- package/ios/utils/ENRMFeatureFlags.h +6 -0
- package/ios/utils/ENRMTextRenderer.h +8 -0
- package/ios/utils/ENRMTextRenderer.m +26 -10
- package/ios/utils/ENRMUIKit.h +1 -0
- package/ios/utils/FontUtils.h +2 -1
- package/ios/utils/FontUtils.m +22 -6
- package/ios/utils/LinkTapUtils.h +17 -2
- package/ios/utils/LinkTapUtils.m +44 -2
- package/ios/utils/ListMarkerDrawer.m +25 -1
- package/ios/utils/MarkdownASTSerializer.h +7 -0
- package/ios/utils/MarkdownASTSerializer.m +243 -0
- package/ios/utils/MarkdownAccessibilityElementBuilder.m +9 -67
- package/ios/utils/MarkdownExtractor.m +6 -3
- package/ios/utils/ParagraphStyleUtils.h +25 -1
- package/ios/utils/ParagraphStyleUtils.m +51 -7
- package/ios/utils/StylePropsUtils.h +60 -1
- package/ios/utils/TextViewLayoutManager.mm +57 -0
- package/lib/module/EnrichedMarkdownNativeComponent.ts +110 -4
- package/lib/module/EnrichedMarkdownTextInput.js +60 -2
- package/lib/module/EnrichedMarkdownTextInput.js.map +1 -1
- package/lib/module/EnrichedMarkdownTextInputNativeComponent.ts +12 -0
- package/lib/module/EnrichedMarkdownTextNativeComponent.ts +115 -4
- package/lib/module/admonitionDefaults.js +34 -0
- package/lib/module/admonitionDefaults.js.map +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/jest/index.js +84 -4
- package/lib/module/jest/index.js.map +1 -1
- package/lib/module/native/EnrichedMarkdownText.js +58 -5
- package/lib/module/native/EnrichedMarkdownText.js.map +1 -1
- package/lib/module/normalizeMarkdownShortcuts.js +31 -0
- package/lib/module/normalizeMarkdownShortcuts.js.map +1 -0
- package/lib/module/normalizeMarkdownStyle.js +15 -1
- package/lib/module/normalizeMarkdownStyle.js.map +1 -1
- package/lib/module/normalizeMarkdownStyle.web.js +15 -1
- package/lib/module/normalizeMarkdownStyle.web.js.map +1 -1
- package/lib/module/styleUtils.js +15 -3
- package/lib/module/styleUtils.js.map +1 -1
- package/lib/module/utils/textInputState.js +4 -3
- package/lib/module/utils/textInputState.js.map +1 -1
- package/lib/module/utils/usePressability.js +28 -0
- package/lib/module/utils/usePressability.js.map +1 -0
- package/lib/module/web/EnrichedMarkdownText.js +19 -6
- package/lib/module/web/EnrichedMarkdownText.js.map +1 -1
- package/lib/module/web/globalStyles.js +7 -1
- package/lib/module/web/globalStyles.js.map +1 -1
- package/lib/module/web/nativeProps.js +70 -0
- package/lib/module/web/nativeProps.js.map +1 -0
- package/lib/module/web/parseMarkdown.js +5 -3
- package/lib/module/web/parseMarkdown.js.map +1 -1
- package/lib/module/web/renderers/BlockRenderers.js +164 -8
- package/lib/module/web/renderers/BlockRenderers.js.map +1 -1
- package/lib/module/web/renderers/admonitionIcons.js +34 -0
- package/lib/module/web/renderers/admonitionIcons.js.map +1 -0
- package/lib/module/web/styles.js +30 -8
- package/lib/module/web/styles.js.map +1 -1
- package/lib/module/web/wasm/md4c.js +0 -0
- package/lib/module/web/wasm/md4c.js.map +1 -1
- package/lib/typescript/src/EnrichedMarkdownNativeComponent.d.ts +103 -3
- package/lib/typescript/src/EnrichedMarkdownNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/EnrichedMarkdownTextInput.d.ts +27 -3
- package/lib/typescript/src/EnrichedMarkdownTextInput.d.ts.map +1 -1
- package/lib/typescript/src/EnrichedMarkdownTextInputNativeComponent.d.ts +11 -0
- package/lib/typescript/src/EnrichedMarkdownTextInputNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/EnrichedMarkdownTextNativeComponent.d.ts +108 -3
- package/lib/typescript/src/EnrichedMarkdownTextNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/admonitionDefaults.d.ts +10 -0
- package/lib/typescript/src/admonitionDefaults.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +3 -2
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/index.web.d.ts +1 -1
- package/lib/typescript/src/index.web.d.ts.map +1 -1
- package/lib/typescript/src/jest/index.d.ts +2 -2
- package/lib/typescript/src/jest/index.d.ts.map +1 -1
- package/lib/typescript/src/native/EnrichedMarkdownText.d.ts +3 -3
- package/lib/typescript/src/native/EnrichedMarkdownText.d.ts.map +1 -1
- package/lib/typescript/src/normalizeMarkdownShortcuts.d.ts +7 -0
- package/lib/typescript/src/normalizeMarkdownShortcuts.d.ts.map +1 -0
- package/lib/typescript/src/normalizeMarkdownStyle.d.ts.map +1 -1
- package/lib/typescript/src/normalizeMarkdownStyle.web.d.ts.map +1 -1
- package/lib/typescript/src/styleUtils.d.ts.map +1 -1
- package/lib/typescript/src/types/MarkdownStyle.d.ts +59 -1
- package/lib/typescript/src/types/MarkdownStyle.d.ts.map +1 -1
- package/lib/typescript/src/types/MarkdownStyleInternal.d.ts +21 -0
- package/lib/typescript/src/types/MarkdownStyleInternal.d.ts.map +1 -1
- package/lib/typescript/src/types/MarkdownTextProps.d.ts +93 -8
- package/lib/typescript/src/types/MarkdownTextProps.d.ts.map +1 -1
- package/lib/typescript/src/types/MarkdownTextProps.web.d.ts +25 -1
- package/lib/typescript/src/types/MarkdownTextProps.web.d.ts.map +1 -1
- package/lib/typescript/src/types/events.d.ts +33 -5
- package/lib/typescript/src/types/events.d.ts.map +1 -1
- package/lib/typescript/src/utils/textInputState.d.ts +5 -3
- package/lib/typescript/src/utils/textInputState.d.ts.map +1 -1
- package/lib/typescript/src/utils/usePressability.d.ts +24 -0
- package/lib/typescript/src/utils/usePressability.d.ts.map +1 -0
- package/lib/typescript/src/web/EnrichedMarkdownText.d.ts +1 -1
- package/lib/typescript/src/web/EnrichedMarkdownText.d.ts.map +1 -1
- package/lib/typescript/src/web/globalStyles.d.ts +1 -0
- package/lib/typescript/src/web/globalStyles.d.ts.map +1 -1
- package/lib/typescript/src/web/nativeProps.d.ts +34 -0
- package/lib/typescript/src/web/nativeProps.d.ts.map +1 -0
- package/lib/typescript/src/web/parseMarkdown.d.ts +1 -1
- package/lib/typescript/src/web/parseMarkdown.d.ts.map +1 -1
- package/lib/typescript/src/web/renderers/BlockRenderers.d.ts.map +1 -1
- package/lib/typescript/src/web/renderers/admonitionIcons.d.ts +5 -0
- package/lib/typescript/src/web/renderers/admonitionIcons.d.ts.map +1 -0
- package/lib/typescript/src/web/styles.d.ts +1 -0
- package/lib/typescript/src/web/styles.d.ts.map +1 -1
- package/lib/typescript/src/web/types.d.ts +8 -2
- package/lib/typescript/src/web/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/postinstall.mjs +7 -0
- package/src/EnrichedMarkdownNativeComponent.ts +110 -4
- package/src/EnrichedMarkdownTextInput.tsx +101 -4
- package/src/EnrichedMarkdownTextInputNativeComponent.ts +12 -0
- package/src/EnrichedMarkdownTextNativeComponent.ts +115 -4
- package/src/admonitionDefaults.ts +58 -0
- package/src/index.tsx +5 -0
- package/src/index.web.tsx +3 -0
- package/src/jest/index.tsx +138 -5
- package/src/native/EnrichedMarkdownText.tsx +55 -3
- package/src/normalizeMarkdownShortcuts.ts +38 -0
- package/src/normalizeMarkdownStyle.ts +17 -0
- package/src/normalizeMarkdownStyle.web.ts +17 -0
- package/src/styleUtils.ts +17 -6
- package/src/types/MarkdownStyle.ts +62 -1
- package/src/types/MarkdownStyleInternal.ts +24 -0
- package/src/types/MarkdownTextProps.ts +95 -7
- package/src/types/MarkdownTextProps.web.ts +26 -0
- package/src/types/events.ts +36 -5
- package/src/utils/textInputState.ts +5 -3
- package/src/utils/usePressability.ts +34 -0
- package/src/web/EnrichedMarkdownText.tsx +36 -3
- package/src/web/globalStyles.ts +10 -0
- package/src/web/nativeProps.ts +78 -0
- package/src/web/parseMarkdown.ts +10 -2
- package/src/web/renderers/BlockRenderers.tsx +175 -6
- package/src/web/renderers/admonitionIcons.ts +37 -0
- package/src/web/styles.ts +28 -3
- package/src/web/types.ts +12 -1
- package/src/web/wasm/md4c.js +0 -0
- package/vendor-ratex.mjs +86 -17
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/DocumentRenderer.kt +0 -16
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/RenderedSegment.kt +0 -88
- package/ios/utils/SegmentRenderer.h +0 -24
- /package/ios/{views → segments}/ENRMTableGridView.h +0 -0
- /package/ios/{views → segments}/ENRMTableGridView.m +0 -0
- /package/ios/{views → segments}/ENRMTableIOSGridView.h +0 -0
- /package/ios/{views → segments}/ENRMTableIOSGridView.m +0 -0
- /package/ios/{utils → segments}/SegmentReconciler.h +0 -0
- /package/ios/{utils → segments}/SegmentReconciler.m +0 -0
- /package/ios/{utils → segments}/SegmentViewRegistry.h +0 -0
- /package/ios/{utils → segments}/SegmentViewRegistry.m +0 -0
|
@@ -1,26 +1,80 @@
|
|
|
1
1
|
package com.swmansion.enriched.markdown.spans
|
|
2
2
|
|
|
3
|
+
import android.graphics.Canvas
|
|
3
4
|
import android.graphics.Color
|
|
5
|
+
import android.graphics.Paint
|
|
6
|
+
import android.text.Spanned
|
|
4
7
|
import android.text.TextPaint
|
|
5
8
|
import android.text.style.CharacterStyle
|
|
9
|
+
import android.text.style.LineBackgroundSpan
|
|
6
10
|
import com.swmansion.enriched.markdown.renderer.BlockStyle
|
|
7
11
|
import com.swmansion.enriched.markdown.renderer.SpanStyleCache
|
|
12
|
+
import kotlin.math.max
|
|
13
|
+
import kotlin.math.min
|
|
8
14
|
|
|
9
15
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
16
|
+
* A plain [CharacterStyle], not a `MetricAffectingSpan`, so nested strong/emphasis spans inside
|
|
17
|
+
* ==highlight== keep their typeface and size. The background is a [LineBackgroundSpan] rather
|
|
18
|
+
* than [TextPaint.bgColor], which fills the whole line box and floats above the text once
|
|
19
|
+
* [LineHeightSpan] pads it out to the configured line height.
|
|
12
20
|
*/
|
|
13
21
|
class HighlightSpan(
|
|
14
22
|
private val styleCache: SpanStyleCache,
|
|
15
23
|
private val blockStyle: BlockStyle,
|
|
16
|
-
) : CharacterStyle()
|
|
24
|
+
) : CharacterStyle(),
|
|
25
|
+
LineBackgroundSpan {
|
|
17
26
|
private val foregroundColor = styleCache.getHighlightColorFor(blockStyle.color)
|
|
27
|
+
private val backgroundPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply { style = Paint.Style.FILL }
|
|
18
28
|
|
|
19
29
|
override fun updateDrawState(textPaint: TextPaint) {
|
|
20
30
|
textPaint.color = foregroundColor
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
override fun drawBackground(
|
|
34
|
+
canvas: Canvas,
|
|
35
|
+
p: Paint,
|
|
36
|
+
left: Int,
|
|
37
|
+
right: Int,
|
|
38
|
+
top: Int,
|
|
39
|
+
baseline: Int,
|
|
40
|
+
bottom: Int,
|
|
41
|
+
text: CharSequence,
|
|
42
|
+
start: Int,
|
|
43
|
+
end: Int,
|
|
44
|
+
lineNum: Int,
|
|
45
|
+
) {
|
|
21
46
|
val backgroundColor = styleCache.highlightBackgroundColor
|
|
22
|
-
if (Color.alpha(backgroundColor)
|
|
23
|
-
|
|
24
|
-
|
|
47
|
+
if (Color.alpha(backgroundColor) == 0) return
|
|
48
|
+
if (text !is Spanned) return
|
|
49
|
+
|
|
50
|
+
val spanStart = text.getSpanStart(this)
|
|
51
|
+
val spanEnd = text.getSpanEnd(this)
|
|
52
|
+
if (spanStart !in 0 until spanEnd) return
|
|
53
|
+
|
|
54
|
+
val isFirst = spanStart >= start
|
|
55
|
+
val isLast = spanEnd <= end
|
|
56
|
+
|
|
57
|
+
val leadingMargin = InlineBackgroundGeometry.leadingMarginAt(text, start)
|
|
58
|
+
val startX =
|
|
59
|
+
if (isFirst) {
|
|
60
|
+
InlineBackgroundGeometry.horizontalOffset(text, start, end, spanStart, p, leadingMargin) + left
|
|
61
|
+
} else {
|
|
62
|
+
left.toFloat() + leadingMargin
|
|
63
|
+
}
|
|
64
|
+
val endX =
|
|
65
|
+
if (isLast) {
|
|
66
|
+
InlineBackgroundGeometry.horizontalOffset(text, start, end, spanEnd, p, leadingMargin) + left
|
|
67
|
+
} else {
|
|
68
|
+
right.toFloat()
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Bound by the glyphs' ascent/descent, clamped to the line box so a tall line height never
|
|
72
|
+
// lets the band bleed into its neighbours.
|
|
73
|
+
val metrics = p.fontMetricsInt
|
|
74
|
+
val bandTop = max(top.toFloat(), (baseline + metrics.ascent).toFloat())
|
|
75
|
+
val bandBottom = min(bottom.toFloat(), (baseline + metrics.descent).toFloat())
|
|
76
|
+
|
|
77
|
+
backgroundPaint.color = backgroundColor
|
|
78
|
+
canvas.drawRect(min(startX, endX), bandTop, max(startX, endX), bandBottom, backgroundPaint)
|
|
25
79
|
}
|
|
26
80
|
}
|
|
@@ -18,9 +18,9 @@ import androidx.core.graphics.createBitmap
|
|
|
18
18
|
import androidx.core.graphics.drawable.toDrawable
|
|
19
19
|
import androidx.core.graphics.withClip
|
|
20
20
|
import androidx.core.graphics.withSave
|
|
21
|
-
import com.swmansion.enriched.markdown.EnrichedMarkdown
|
|
22
21
|
import com.swmansion.enriched.markdown.EnrichedMarkdownText
|
|
23
22
|
import com.swmansion.enriched.markdown.styles.StyleConfig
|
|
23
|
+
import com.swmansion.enriched.markdown.utils.common.findEnrichedMarkdownAncestor
|
|
24
24
|
import com.swmansion.enriched.markdown.utils.text.ImageCache
|
|
25
25
|
import com.swmansion.enriched.markdown.utils.text.ImageDownloader
|
|
26
26
|
import com.swmansion.enriched.markdown.utils.text.LocalImageLoader
|
|
@@ -67,6 +67,7 @@ class ImageSpan(
|
|
|
67
67
|
private var cachedWidth: Int = 0
|
|
68
68
|
private var viewRef: WeakReference<TextView>? = null
|
|
69
69
|
private var sourceDrawable: Drawable? = null
|
|
70
|
+
private var onBoxHeightChanged: (() -> Unit)? = null
|
|
70
71
|
|
|
71
72
|
private fun intrinsicImageSize(): Pair<Int, Int> {
|
|
72
73
|
sourceDrawable?.let { return it.intrinsicWidth to it.intrinsicHeight }
|
|
@@ -182,16 +183,25 @@ class ImageSpan(
|
|
|
182
183
|
// re-measure; it only propagates when the stored height actually changed.
|
|
183
184
|
private fun notifyBoxHeightMayHaveChanged(view: TextView) {
|
|
184
185
|
if (!dynamicBoxHeight) return
|
|
186
|
+
// A self-measuring host (e.g. a table cell) sizes the image box itself and drives
|
|
187
|
+
// its own re-layout, so bubbling up to the component would churn it and orphan this
|
|
188
|
+
// freshly registered view. Let the host re-measure locally instead.
|
|
189
|
+
onBoxHeightChanged?.let {
|
|
190
|
+
it()
|
|
191
|
+
return
|
|
192
|
+
}
|
|
185
193
|
if (view is EnrichedMarkdownText) {
|
|
186
194
|
view.layoutManager.invalidateLayout()
|
|
187
195
|
return
|
|
188
196
|
}
|
|
189
|
-
|
|
190
|
-
while (parent != null && parent !is EnrichedMarkdown) parent = parent.parent
|
|
191
|
-
parent?.onImageLayoutChanged()
|
|
197
|
+
view.findEnrichedMarkdownAncestor()?.onImageLayoutChanged()
|
|
192
198
|
}
|
|
193
199
|
|
|
194
|
-
fun registerTextView(
|
|
200
|
+
fun registerTextView(
|
|
201
|
+
view: TextView,
|
|
202
|
+
onBoxHeightChanged: (() -> Unit)? = null,
|
|
203
|
+
) {
|
|
204
|
+
this.onBoxHeightChanged = onBoxHeightChanged
|
|
195
205
|
viewRef = WeakReference(view)
|
|
196
206
|
if (!isInline) {
|
|
197
207
|
val availableWidth = getAvailableWidth(view)
|
package/android/src/main/java/com/swmansion/enriched/markdown/spans/InlineBackgroundGeometry.kt
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
package com.swmansion.enriched.markdown.spans
|
|
2
|
+
|
|
3
|
+
import android.graphics.Paint
|
|
4
|
+
import android.text.Spanned
|
|
5
|
+
import android.text.StaticLayout
|
|
6
|
+
import android.text.TextPaint
|
|
7
|
+
import android.text.style.LeadingMarginSpan
|
|
8
|
+
|
|
9
|
+
internal object InlineBackgroundGeometry {
|
|
10
|
+
/**
|
|
11
|
+
* Returns the x position of [index] relative to the line's left edge. The measuring layout keeps
|
|
12
|
+
* the line's spans, so a LeadingMarginSpan is already folded into getPrimaryHorizontal — only the
|
|
13
|
+
* early return, which builds no layout, adds [leadingMargin] itself.
|
|
14
|
+
*/
|
|
15
|
+
fun horizontalOffset(
|
|
16
|
+
text: CharSequence,
|
|
17
|
+
lineStart: Int,
|
|
18
|
+
lineEnd: Int,
|
|
19
|
+
index: Int,
|
|
20
|
+
paint: Paint,
|
|
21
|
+
leadingMargin: Int,
|
|
22
|
+
): Float {
|
|
23
|
+
if (index <= lineStart) return leadingMargin.toFloat()
|
|
24
|
+
val lineText = text.subSequence(lineStart, lineEnd)
|
|
25
|
+
val textPaint = paint as? TextPaint ?: TextPaint(paint)
|
|
26
|
+
val layout = StaticLayout.Builder.obtain(lineText, 0, lineText.length, textPaint, 10000).build()
|
|
27
|
+
return layout.getPrimaryHorizontal(index - lineStart)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
fun leadingMarginAt(
|
|
31
|
+
text: Spanned,
|
|
32
|
+
lineStart: Int,
|
|
33
|
+
): Int {
|
|
34
|
+
if (lineStart >= text.length) return 0
|
|
35
|
+
val spans = text.getSpans(lineStart, lineStart + 1, LeadingMarginSpan::class.java)
|
|
36
|
+
var margin = 0
|
|
37
|
+
for (span in spans) {
|
|
38
|
+
margin += span.getLeadingMargin(false)
|
|
39
|
+
}
|
|
40
|
+
return margin
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -5,9 +5,6 @@ import android.graphics.Paint
|
|
|
5
5
|
import android.graphics.Path
|
|
6
6
|
import android.graphics.RectF
|
|
7
7
|
import android.text.Spanned
|
|
8
|
-
import android.text.StaticLayout
|
|
9
|
-
import android.text.TextPaint
|
|
10
|
-
import android.text.style.LeadingMarginSpan
|
|
11
8
|
|
|
12
9
|
/**
|
|
13
10
|
* Shared geometry and drawing for inline "chips" painted from a [android.text.style.LineBackgroundSpan]
|
|
@@ -15,14 +12,8 @@ import android.text.style.LeadingMarginSpan
|
|
|
15
12
|
* stays open where a fragment is cut.
|
|
16
13
|
*/
|
|
17
14
|
internal object InlineChipPainter {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
* leading margin. The measuring StaticLayout is built from a subSequence that keeps
|
|
21
|
-
* all spans, so LeadingMarginSpans (lists, blockquotes) are already applied to
|
|
22
|
-
* getPrimaryHorizontal; adding the margin again on top would shift the background
|
|
23
|
-
* right by the indent. The margin is only added explicitly in the early-return case,
|
|
24
|
-
* where no layout is built.
|
|
25
|
-
*/
|
|
15
|
+
// Geometry delegates to upstream's InlineBackgroundGeometry (same algorithm the fork had
|
|
16
|
+
// here) so inline code and link chips can never drift apart.
|
|
26
17
|
fun horizontalOffset(
|
|
27
18
|
text: CharSequence,
|
|
28
19
|
lineStart: Int,
|
|
@@ -30,26 +21,12 @@ internal object InlineChipPainter {
|
|
|
30
21
|
index: Int,
|
|
31
22
|
paint: Paint,
|
|
32
23
|
leadingMargin: Int,
|
|
33
|
-
): Float
|
|
34
|
-
if (index <= lineStart) return leadingMargin.toFloat()
|
|
35
|
-
val lineText = text.subSequence(lineStart, lineEnd)
|
|
36
|
-
val textPaint = paint as? TextPaint ?: TextPaint(paint)
|
|
37
|
-
val layout = StaticLayout.Builder.obtain(lineText, 0, lineText.length, textPaint, 10000).build()
|
|
38
|
-
return layout.getPrimaryHorizontal(index - lineStart)
|
|
39
|
-
}
|
|
24
|
+
): Float = InlineBackgroundGeometry.horizontalOffset(text, lineStart, lineEnd, index, paint, leadingMargin)
|
|
40
25
|
|
|
41
26
|
fun leadingMarginAt(
|
|
42
27
|
text: Spanned,
|
|
43
28
|
lineStart: Int,
|
|
44
|
-
): Int
|
|
45
|
-
if (lineStart >= text.length) return 0
|
|
46
|
-
val spans = text.getSpans(lineStart, lineStart + 1, LeadingMarginSpan::class.java)
|
|
47
|
-
var margin = 0
|
|
48
|
-
for (span in spans) {
|
|
49
|
-
margin += span.getLeadingMargin(false)
|
|
50
|
-
}
|
|
51
|
-
return margin
|
|
52
|
-
}
|
|
29
|
+
): Int = InlineBackgroundGeometry.leadingMarginAt(text, lineStart)
|
|
53
30
|
|
|
54
31
|
/**
|
|
55
32
|
* Fills [rect] and strokes its border. [strokeInset] keeps a closed border inside [rect]
|
|
@@ -12,6 +12,16 @@ class LineHeightSpan(
|
|
|
12
12
|
) : AndroidLineHeightSpan {
|
|
13
13
|
private val lineHeight: Int = ceil(height.toDouble()).toInt()
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Distributes leading evenly above and below the line to reach lineHeight.
|
|
17
|
+
*
|
|
18
|
+
* Fork behaviour (merge decision D7(b), commit ea6c3fc1): text-only lines keep the exact
|
|
19
|
+
* clamp — a line whose natural content is taller than lineHeight is compressed back to it.
|
|
20
|
+
* Upstream #740 (issue #643) turned lineHeight into a floor for every line; the fork does
|
|
21
|
+
* NOT take that, because the app's fonts (natural height ~1.6em vs lineHeight 1.5em) would
|
|
22
|
+
* make every chat line taller and clip line-capped containers. Only lines carrying a
|
|
23
|
+
* self-measuring ReplacementSpan (inline math) are expanded-only, see below.
|
|
24
|
+
*/
|
|
15
25
|
override fun chooseHeight(
|
|
16
26
|
text: CharSequence?,
|
|
17
27
|
start: Int,
|
|
@@ -46,7 +46,7 @@ class LinkSpan(
|
|
|
46
46
|
|
|
47
47
|
val variant = styleCache.resolvedVariantForUrl(url)
|
|
48
48
|
|
|
49
|
-
val fontFamily = styleCache.linkFontFamily
|
|
49
|
+
val fontFamily = variant?.fontFamily?.takeIf { it.isNotEmpty() } ?: styleCache.linkFontFamily
|
|
50
50
|
if (fontFamily.isNotEmpty()) {
|
|
51
51
|
val overriddenBlockStyle = blockStyle.copy(fontFamily = fontFamily)
|
|
52
52
|
textPaint.applyBlockStyleFont(overriddenBlockStyle, context)
|
|
@@ -3,6 +3,8 @@ package com.swmansion.enriched.markdown.spoiler
|
|
|
3
3
|
import android.graphics.Color
|
|
4
4
|
import android.graphics.Paint
|
|
5
5
|
import android.text.Layout
|
|
6
|
+
import android.text.Spanned
|
|
7
|
+
import com.swmansion.enriched.markdown.spans.SpoilerSpan
|
|
6
8
|
|
|
7
9
|
internal fun computeSegmentRect(
|
|
8
10
|
layout: Layout,
|
|
@@ -38,3 +40,12 @@ internal fun colorWithAlpha(
|
|
|
38
40
|
val alphaComponent = (Color.alpha(color) * alpha).toInt().coerceIn(0, 255)
|
|
39
41
|
return Color.argb(alphaComponent, Color.red(color), Color.green(color), Color.blue(color))
|
|
40
42
|
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Whether a spoiler still hides `[start, end)`. Once a reveal starts, the fading overlay lets the text show
|
|
46
|
+
* through, so decorations drawn outside the text paint come back with it.
|
|
47
|
+
*/
|
|
48
|
+
internal fun Spanned.isConcealedBySpoiler(
|
|
49
|
+
start: Int,
|
|
50
|
+
end: Int,
|
|
51
|
+
): Boolean = getSpans(start, end, SpoilerSpan::class.java).any { !it.revealed && !it.revealing }
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
package com.swmansion.enriched.markdown.styles
|
|
2
2
|
|
|
3
3
|
import com.facebook.react.bridge.ReadableMap
|
|
4
|
+
import com.swmansion.enriched.markdown.segments.AdmonitionIcons
|
|
5
|
+
|
|
6
|
+
/** Per-admonition-type colors. [color] tints border/title/icon; [backgroundColor] null = transparent. */
|
|
7
|
+
data class AdmonitionColors(
|
|
8
|
+
val color: Int,
|
|
9
|
+
val backgroundColor: Int?,
|
|
10
|
+
)
|
|
4
11
|
|
|
5
12
|
data class BlockquoteStyle(
|
|
6
13
|
override val fontSize: Float,
|
|
@@ -16,8 +23,26 @@ data class BlockquoteStyle(
|
|
|
16
23
|
val backgroundColor: Int?,
|
|
17
24
|
val borderRadius: Float,
|
|
18
25
|
val padding: Float,
|
|
26
|
+
val admonitions: Map<String, AdmonitionColors>,
|
|
19
27
|
) : BaseBlockStyle {
|
|
20
28
|
companion object {
|
|
29
|
+
private fun parseAdmonitions(
|
|
30
|
+
map: ReadableMap,
|
|
31
|
+
parser: StyleParser,
|
|
32
|
+
): Map<String, AdmonitionColors> {
|
|
33
|
+
val admonitionsMap = map.getMap("admonitions") ?: return emptyMap()
|
|
34
|
+
val result = mutableMapOf<String, AdmonitionColors>()
|
|
35
|
+
for (type in AdmonitionIcons.TYPES) {
|
|
36
|
+
val typeMap = admonitionsMap.getMap(type) ?: continue
|
|
37
|
+
result[type] =
|
|
38
|
+
AdmonitionColors(
|
|
39
|
+
parser.parseColor(typeMap, "color"),
|
|
40
|
+
parser.parseOptionalColor(typeMap, "backgroundColor"),
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
return result
|
|
44
|
+
}
|
|
45
|
+
|
|
21
46
|
fun fromReadableMap(
|
|
22
47
|
map: ReadableMap,
|
|
23
48
|
parser: StyleParser,
|
|
@@ -36,6 +61,7 @@ data class BlockquoteStyle(
|
|
|
36
61
|
val backgroundColor = parser.parseOptionalColor(map, "backgroundColor")
|
|
37
62
|
val borderRadius = parser.toPixelFromDIP(map.getDouble("borderRadius").toFloat())
|
|
38
63
|
val padding = parser.toPixelFromDIP(map.getDouble("padding").toFloat())
|
|
64
|
+
val admonitions = parseAdmonitions(map, parser)
|
|
39
65
|
|
|
40
66
|
return BlockquoteStyle(
|
|
41
67
|
fontSize,
|
|
@@ -51,6 +77,7 @@ data class BlockquoteStyle(
|
|
|
51
77
|
backgroundColor,
|
|
52
78
|
borderRadius,
|
|
53
79
|
padding,
|
|
80
|
+
admonitions,
|
|
54
81
|
)
|
|
55
82
|
}
|
|
56
83
|
}
|
|
@@ -14,6 +14,7 @@ data class LinkVariantEntry(
|
|
|
14
14
|
val underline: Boolean,
|
|
15
15
|
val backgroundColor: Int,
|
|
16
16
|
val chip: LinkChipStyle,
|
|
17
|
+
val fontFamily: String = "",
|
|
17
18
|
) {
|
|
18
19
|
companion object {
|
|
19
20
|
fun fromReadableMap(
|
|
@@ -27,6 +28,7 @@ data class LinkVariantEntry(
|
|
|
27
28
|
underline = parser.parseBoolean(map, "underline"),
|
|
28
29
|
backgroundColor = backgroundColor,
|
|
29
30
|
chip = LinkChipStyle.fromReadableMap(map, parser, backgroundColor),
|
|
31
|
+
fontFamily = parser.parseString(map, "fontFamily"),
|
|
30
32
|
)
|
|
31
33
|
}
|
|
32
34
|
}
|
|
@@ -168,6 +168,14 @@ class StyleConfig(
|
|
|
168
168
|
|
|
169
169
|
var imageRequestHeaders: Map<String, String> = emptyMap()
|
|
170
170
|
|
|
171
|
+
val videoStyle: VideoStyle by lazy {
|
|
172
|
+
val map =
|
|
173
|
+
requireNotNull(style.getMap("video")) {
|
|
174
|
+
"Video style not found. JS should always provide defaults."
|
|
175
|
+
}
|
|
176
|
+
VideoStyle.fromReadableMap(map, styleParser)
|
|
177
|
+
}
|
|
178
|
+
|
|
171
179
|
val inlineImageStyle: InlineImageStyle by lazy {
|
|
172
180
|
val map =
|
|
173
181
|
requireNotNull(style.getMap("inlineImage")) {
|
|
@@ -327,6 +335,7 @@ class StyleConfig(
|
|
|
327
335
|
underlineStyle == other.underlineStyle &&
|
|
328
336
|
codeStyle == other.codeStyle &&
|
|
329
337
|
imageStyle == other.imageStyle &&
|
|
338
|
+
videoStyle == other.videoStyle &&
|
|
330
339
|
inlineImageStyle == other.inlineImageStyle &&
|
|
331
340
|
blockquoteStyle == other.blockquoteStyle &&
|
|
332
341
|
listStyle == other.listStyle &&
|
|
@@ -354,6 +363,7 @@ class StyleConfig(
|
|
|
354
363
|
result = 31 * result + underlineStyle.hashCode()
|
|
355
364
|
result = 31 * result + codeStyle.hashCode()
|
|
356
365
|
result = 31 * result + imageStyle.hashCode()
|
|
366
|
+
result = 31 * result + videoStyle.hashCode()
|
|
357
367
|
result = 31 * result + inlineImageStyle.hashCode()
|
|
358
368
|
result = 31 * result + blockquoteStyle.hashCode()
|
|
359
369
|
result = 31 * result + listStyle.hashCode()
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
package com.swmansion.enriched.markdown.styles
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.ReadableMap
|
|
4
|
+
|
|
5
|
+
data class VideoStyle(
|
|
6
|
+
val marginTop: Float,
|
|
7
|
+
val marginBottom: Float,
|
|
8
|
+
val borderRadius: Float,
|
|
9
|
+
val aspectRatio: Float,
|
|
10
|
+
val backgroundColor: Int,
|
|
11
|
+
) {
|
|
12
|
+
/** Aspect ratio guaranteed to be positive. Falls back to 16:9 if the raw value is ≤ 0. */
|
|
13
|
+
val resolvedAspectRatio: Float
|
|
14
|
+
get() = if (aspectRatio > 0f) aspectRatio else DEFAULT_ASPECT_RATIO
|
|
15
|
+
|
|
16
|
+
companion object {
|
|
17
|
+
private const val DEFAULT_ASPECT_RATIO = 16f / 9f
|
|
18
|
+
|
|
19
|
+
fun fromReadableMap(
|
|
20
|
+
map: ReadableMap,
|
|
21
|
+
parser: StyleParser,
|
|
22
|
+
): VideoStyle {
|
|
23
|
+
val marginTop = parser.toPixelFromDIP(map.getDouble("marginTop").toFloat())
|
|
24
|
+
val marginBottom = parser.toPixelFromDIP(map.getDouble("marginBottom").toFloat())
|
|
25
|
+
val borderRadius = parser.toPixelFromDIP(map.getDouble("borderRadius").toFloat())
|
|
26
|
+
val aspectRatio = map.getDouble("aspectRatio").toFloat()
|
|
27
|
+
val backgroundColor = parser.parseColor(map, "backgroundColor")
|
|
28
|
+
return VideoStyle(marginTop, marginBottom, borderRadius, aspectRatio, backgroundColor)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/BorderStyleUtils.kt
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
package com.swmansion.enriched.markdown.utils.common
|
|
2
|
+
|
|
3
|
+
import android.view.View
|
|
4
|
+
import com.facebook.react.bridge.ColorPropConverter
|
|
5
|
+
import com.facebook.react.uimanager.BackgroundStyleApplicator
|
|
6
|
+
import com.facebook.react.uimanager.LengthPercentage
|
|
7
|
+
import com.facebook.react.uimanager.ReactStylesDiffMap
|
|
8
|
+
import com.facebook.react.uimanager.style.BorderRadiusProp
|
|
9
|
+
import com.facebook.react.uimanager.style.BorderStyle
|
|
10
|
+
import com.facebook.react.uimanager.style.LogicalEdge
|
|
11
|
+
|
|
12
|
+
// BaseViewManagerDelegate (used by our SimpleViewManagers) ignores border
|
|
13
|
+
// width/color/style and no-ops borderRadius, so `containerStyle` borders vanish on
|
|
14
|
+
// Android. Replay them via BackgroundStyleApplicator like ReactViewManager does.
|
|
15
|
+
// Call after super.updateProperties so the composite background drawable exists.
|
|
16
|
+
fun applyReactBorderProps(
|
|
17
|
+
view: View,
|
|
18
|
+
props: ReactStylesDiffMap,
|
|
19
|
+
) {
|
|
20
|
+
for ((name, edge) in BORDER_WIDTH_EDGES) {
|
|
21
|
+
if (!props.hasKey(name)) continue
|
|
22
|
+
val width = if (props.isNull(name)) null else props.getFloat(name, Float.NaN).takeUnless { it.isNaN() }
|
|
23
|
+
BackgroundStyleApplicator.setBorderWidth(view, edge, width)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (BORDER_COLOR_EDGES.keys.any { props.hasKey(it) }) {
|
|
27
|
+
val rawProps = props.toMap()
|
|
28
|
+
for ((name, edge) in BORDER_COLOR_EDGES) {
|
|
29
|
+
if (!props.hasKey(name)) continue
|
|
30
|
+
val color = if (props.isNull(name)) null else ColorPropConverter.getColor(rawProps[name], view.context)
|
|
31
|
+
BackgroundStyleApplicator.setBorderColor(view, edge, color)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (props.hasKey("borderStyle")) {
|
|
36
|
+
val style = if (props.isNull("borderStyle")) null else BorderStyle.fromString(props.getString("borderStyle") ?: "")
|
|
37
|
+
BackgroundStyleApplicator.setBorderStyle(view, style)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Radius last, so the border drawable created above already exists and picks
|
|
41
|
+
// up the rounded corners.
|
|
42
|
+
for ((name, corner) in BORDER_RADIUS_PROPS) {
|
|
43
|
+
if (!props.hasKey(name)) continue
|
|
44
|
+
val radius = if (props.isNull(name)) null else LengthPercentage.setFromDynamic(props.getDynamic(name))
|
|
45
|
+
BackgroundStyleApplicator.setBorderRadius(view, corner, radius)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
private val BORDER_WIDTH_EDGES =
|
|
50
|
+
linkedMapOf(
|
|
51
|
+
"borderWidth" to LogicalEdge.ALL,
|
|
52
|
+
"borderLeftWidth" to LogicalEdge.LEFT,
|
|
53
|
+
"borderRightWidth" to LogicalEdge.RIGHT,
|
|
54
|
+
"borderTopWidth" to LogicalEdge.TOP,
|
|
55
|
+
"borderBottomWidth" to LogicalEdge.BOTTOM,
|
|
56
|
+
"borderStartWidth" to LogicalEdge.START,
|
|
57
|
+
"borderEndWidth" to LogicalEdge.END,
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
private val BORDER_COLOR_EDGES =
|
|
61
|
+
linkedMapOf(
|
|
62
|
+
"borderColor" to LogicalEdge.ALL,
|
|
63
|
+
"borderLeftColor" to LogicalEdge.LEFT,
|
|
64
|
+
"borderRightColor" to LogicalEdge.RIGHT,
|
|
65
|
+
"borderTopColor" to LogicalEdge.TOP,
|
|
66
|
+
"borderBottomColor" to LogicalEdge.BOTTOM,
|
|
67
|
+
"borderStartColor" to LogicalEdge.START,
|
|
68
|
+
"borderEndColor" to LogicalEdge.END,
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
private val BORDER_RADIUS_PROPS =
|
|
72
|
+
linkedMapOf(
|
|
73
|
+
"borderRadius" to BorderRadiusProp.BORDER_RADIUS,
|
|
74
|
+
"borderTopLeftRadius" to BorderRadiusProp.BORDER_TOP_LEFT_RADIUS,
|
|
75
|
+
"borderTopRightRadius" to BorderRadiusProp.BORDER_TOP_RIGHT_RADIUS,
|
|
76
|
+
"borderBottomRightRadius" to BorderRadiusProp.BORDER_BOTTOM_RIGHT_RADIUS,
|
|
77
|
+
"borderBottomLeftRadius" to BorderRadiusProp.BORDER_BOTTOM_LEFT_RADIUS,
|
|
78
|
+
"borderTopStartRadius" to BorderRadiusProp.BORDER_TOP_START_RADIUS,
|
|
79
|
+
"borderTopEndRadius" to BorderRadiusProp.BORDER_TOP_END_RADIUS,
|
|
80
|
+
"borderBottomStartRadius" to BorderRadiusProp.BORDER_BOTTOM_START_RADIUS,
|
|
81
|
+
"borderBottomEndRadius" to BorderRadiusProp.BORDER_BOTTOM_END_RADIUS,
|
|
82
|
+
"borderEndEndRadius" to BorderRadiusProp.BORDER_END_END_RADIUS,
|
|
83
|
+
"borderEndStartRadius" to BorderRadiusProp.BORDER_END_START_RADIUS,
|
|
84
|
+
"borderStartEndRadius" to BorderRadiusProp.BORDER_START_END_RADIUS,
|
|
85
|
+
"borderStartStartRadius" to BorderRadiusProp.BORDER_START_START_RADIUS,
|
|
86
|
+
)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
package com.swmansion.enriched.markdown.utils.common
|
|
2
|
+
|
|
3
|
+
import android.text.TextUtils.TruncateAt
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Resolves an ellipsizeMode prop value (string) to the TruncateAt used by
|
|
7
|
+
* StaticLayout.Builder.setEllipsize() and TextView.setEllipsize().
|
|
8
|
+
*
|
|
9
|
+
* "clip" maps to null: with maxLines set, the layout still truncates but draws
|
|
10
|
+
* no ellipsis glyph. Mirrors React Native's TextAttributeProps.getEllipsizeMode.
|
|
11
|
+
*
|
|
12
|
+
* Stateless like [BreakStrategyUtils]: the mode is a per-view prop stored per
|
|
13
|
+
* viewId in [com.swmansion.enriched.markdown.MeasurementStore]. Measurement and
|
|
14
|
+
* render paths must resolve the same value, or the measured line count diverges
|
|
15
|
+
* from the rendered one and the view is sized incorrectly.
|
|
16
|
+
*/
|
|
17
|
+
object EllipsizeUtils {
|
|
18
|
+
const val DEFAULT_MODE = "tail"
|
|
19
|
+
|
|
20
|
+
fun resolveTruncateAt(mode: String?): TruncateAt? =
|
|
21
|
+
when (mode) {
|
|
22
|
+
"head" -> TruncateAt.START
|
|
23
|
+
"middle" -> TruncateAt.MIDDLE
|
|
24
|
+
"clip" -> null
|
|
25
|
+
else -> TruncateAt.END
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
package com.swmansion.enriched.markdown.utils.common
|
|
2
|
+
|
|
3
|
+
import android.view.View
|
|
4
|
+
import com.swmansion.enriched.markdown.EnrichedMarkdown
|
|
5
|
+
|
|
6
|
+
fun View.findEnrichedMarkdownAncestor(): EnrichedMarkdown? {
|
|
7
|
+
var current = parent
|
|
8
|
+
while (current != null && current !is EnrichedMarkdown) current = current.parent
|
|
9
|
+
return current as? EnrichedMarkdown
|
|
10
|
+
}
|
|
@@ -4,5 +4,6 @@ import com.swmansion.enriched.markdown.BuildConfig
|
|
|
4
4
|
|
|
5
5
|
object FeatureFlags {
|
|
6
6
|
const val IS_MATH_ENABLED: Boolean = BuildConfig.ENABLE_MATH
|
|
7
|
+
const val IS_VIDEO_ENABLED: Boolean = BuildConfig.ENABLE_VIDEO
|
|
7
8
|
const val IS_CODE_HIGHLIGHT_ENABLED: Boolean = BuildConfig.ENABLE_CODE_HIGHLIGHT
|
|
8
9
|
}
|
|
@@ -5,9 +5,11 @@ import com.facebook.react.bridge.ReadableArray
|
|
|
5
5
|
import com.facebook.react.bridge.ReadableMap
|
|
6
6
|
import com.facebook.react.uimanager.UIManagerHelper
|
|
7
7
|
import com.swmansion.enriched.markdown.accessibility.AccessibilityLabels
|
|
8
|
+
import com.swmansion.enriched.markdown.events.CodeBlockPressEvent
|
|
8
9
|
import com.swmansion.enriched.markdown.events.ContextMenuItemPressEvent
|
|
9
10
|
import com.swmansion.enriched.markdown.events.CopyPressEvent
|
|
10
11
|
import com.swmansion.enriched.markdown.events.CopyRequestEvent
|
|
12
|
+
import com.swmansion.enriched.markdown.events.LatexErrorEvent
|
|
11
13
|
import com.swmansion.enriched.markdown.events.LinkLayoutEvent
|
|
12
14
|
import com.swmansion.enriched.markdown.events.LinkLongPressEvent
|
|
13
15
|
import com.swmansion.enriched.markdown.events.LinkPressEvent
|
|
@@ -27,10 +29,14 @@ fun markdownEventTypeConstants(): MutableMap<String, Any> {
|
|
|
27
29
|
mapOf("registrationName" to TaskListItemPressEvent.EVENT_NAME)
|
|
28
30
|
map[CopyPressEvent.EVENT_NAME] =
|
|
29
31
|
mapOf("registrationName" to CopyPressEvent.EVENT_NAME)
|
|
32
|
+
map[CodeBlockPressEvent.EVENT_NAME] =
|
|
33
|
+
mapOf("registrationName" to CodeBlockPressEvent.EVENT_NAME)
|
|
30
34
|
map[CopyRequestEvent.EVENT_NAME] =
|
|
31
35
|
mapOf("registrationName" to CopyRequestEvent.EVENT_NAME)
|
|
32
36
|
map[ContextMenuItemPressEvent.EVENT_NAME] =
|
|
33
37
|
mapOf("registrationName" to ContextMenuItemPressEvent.EVENT_NAME)
|
|
38
|
+
map[LatexErrorEvent.EVENT_NAME] =
|
|
39
|
+
mapOf("registrationName" to LatexErrorEvent.EVENT_NAME)
|
|
34
40
|
map[LinkLayoutEvent.EVENT_NAME] =
|
|
35
41
|
mapOf("registrationName" to LinkLayoutEvent.EVENT_NAME)
|
|
36
42
|
map[SelectionChangeEvent.EVENT_NAME] =
|
|
@@ -120,6 +126,33 @@ fun emitCopyRequest(
|
|
|
120
126
|
)
|
|
121
127
|
}
|
|
122
128
|
|
|
129
|
+
fun emitLatexError(
|
|
130
|
+
view: View,
|
|
131
|
+
source: String,
|
|
132
|
+
message: String?,
|
|
133
|
+
displayMode: Boolean,
|
|
134
|
+
) {
|
|
135
|
+
val context = view.context as com.facebook.react.bridge.ReactContext
|
|
136
|
+
val surfaceId = UIManagerHelper.getSurfaceId(context)
|
|
137
|
+
val eventDispatcher = UIManagerHelper.getEventDispatcherForReactTag(context, view.id)
|
|
138
|
+
eventDispatcher?.dispatchEvent(
|
|
139
|
+
LatexErrorEvent(surfaceId, view.id, source, message, displayMode),
|
|
140
|
+
)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
fun emitCodeBlockPress(
|
|
144
|
+
view: View,
|
|
145
|
+
code: String,
|
|
146
|
+
language: String,
|
|
147
|
+
) {
|
|
148
|
+
val context = view.context as com.facebook.react.bridge.ReactContext
|
|
149
|
+
val surfaceId = UIManagerHelper.getSurfaceId(context)
|
|
150
|
+
val eventDispatcher = UIManagerHelper.getEventDispatcherForReactTag(context, view.id)
|
|
151
|
+
eventDispatcher?.dispatchEvent(
|
|
152
|
+
CodeBlockPressEvent(surfaceId, view.id, code, language),
|
|
153
|
+
)
|
|
154
|
+
}
|
|
155
|
+
|
|
123
156
|
fun emitContextMenuItemPress(
|
|
124
157
|
view: View,
|
|
125
158
|
itemText: String,
|
|
@@ -144,12 +177,15 @@ fun emitContextMenuItemPress(
|
|
|
144
177
|
|
|
145
178
|
fun parseMd4cFlags(flags: ReadableMap?): Md4cFlags =
|
|
146
179
|
Md4cFlags(
|
|
180
|
+
// Guarded reads (fork convention): ReadableMap.getBoolean throws on a missing key.
|
|
147
181
|
underline = flags.getBooleanOrDefault("underline", false),
|
|
148
182
|
latexMath = FeatureFlags.IS_MATH_ENABLED && flags.getBooleanOrDefault("latexMath", true),
|
|
149
183
|
superscript = flags.getBooleanOrDefault("superscript", false),
|
|
150
184
|
subscript = flags.getBooleanOrDefault("subscript", false),
|
|
151
185
|
highlight = flags.getBooleanOrDefault("highlight", false),
|
|
152
186
|
hardSoftBreaks = flags.getBooleanOrDefault("hardSoftBreaks", false),
|
|
187
|
+
preserveBlankLines = flags.getBooleanOrDefault("preserveBlankLines", false),
|
|
188
|
+
admonitions = flags.getBooleanOrDefault("admonitions", true),
|
|
153
189
|
)
|
|
154
190
|
|
|
155
191
|
fun parseContextMenuItems(value: ReadableArray?): List<String> =
|
package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/ReadableMapExtensions.kt
CHANGED
|
@@ -13,6 +13,11 @@ fun ReadableMap?.getFloatOrDefault(
|
|
|
13
13
|
default: Float,
|
|
14
14
|
): Float = if (this?.hasKey(key) == true) getDouble(key).toFloat() else default
|
|
15
15
|
|
|
16
|
+
fun ReadableMap?.getIntOrDefault(
|
|
17
|
+
key: String,
|
|
18
|
+
default: Int,
|
|
19
|
+
): Int = if (this?.hasKey(key) == true) getDouble(key).toInt() else default
|
|
20
|
+
|
|
16
21
|
fun ReadableMap?.getStringOrDefault(
|
|
17
22
|
key: String,
|
|
18
23
|
default: String,
|