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
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
#import "ENRMAccessibilityLabels.h"
|
|
3
3
|
#import "ENRMFeatureFlags.h"
|
|
4
4
|
#import "ENRMMathFontWeight.h"
|
|
5
|
+
#import "RenderContext.h"
|
|
5
6
|
#include <TargetConditionals.h>
|
|
6
7
|
|
|
7
8
|
#if ENRICHED_MARKDOWN_MATH
|
|
@@ -61,7 +62,17 @@
|
|
|
61
62
|
@property (nonatomic, copy, readwrite) NSString *cachedLatex;
|
|
62
63
|
@end
|
|
63
64
|
|
|
64
|
-
@implementation ENRMMathContainerView
|
|
65
|
+
@implementation ENRMMathContainerView {
|
|
66
|
+
BOOL _parseFailed;
|
|
67
|
+
NSString *_parseMessage;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
- (void)reportLatexErrorIfNeeded
|
|
71
|
+
{
|
|
72
|
+
if (_parseFailed && self.onLatexError) {
|
|
73
|
+
self.onLatexError(_cachedLatex, _parseMessage ?: @"", YES);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
65
76
|
|
|
66
77
|
- (instancetype)initWithConfig:(StyleConfig *)config
|
|
67
78
|
{
|
|
@@ -69,6 +80,7 @@
|
|
|
69
80
|
if (self) {
|
|
70
81
|
_config = config;
|
|
71
82
|
_cachedLatex = @"";
|
|
83
|
+
_dynamicProps = [[ENRMDynamicBlockProps alloc] init];
|
|
72
84
|
|
|
73
85
|
_mathView = [[ENRMRaTeXCanvasView alloc] initWithFrame:CGRectZero];
|
|
74
86
|
_mathView.backgroundColor = [RCTUIColor clearColor];
|
|
@@ -94,20 +106,52 @@
|
|
|
94
106
|
return self;
|
|
95
107
|
}
|
|
96
108
|
|
|
109
|
+
- (void)setHighlighted:(BOOL)highlighted
|
|
110
|
+
{
|
|
111
|
+
BOOL changed = _highlighted != highlighted;
|
|
112
|
+
_highlighted = highlighted;
|
|
113
|
+
_mathView.backgroundColor = highlighted ? self.config.highlightBackgroundColor : [RCTUIColor clearColor];
|
|
114
|
+
if (changed && _cachedLatex.length > 0) {
|
|
115
|
+
[self applyLatex:_cachedLatex];
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
- (RCTUIColor *)formulaColor
|
|
120
|
+
{
|
|
121
|
+
StyleConfig *config = self.config;
|
|
122
|
+
if (!_highlighted) {
|
|
123
|
+
return config.mathColor;
|
|
124
|
+
}
|
|
125
|
+
return [RenderContext calculateHighlightColor:config.highlightColor
|
|
126
|
+
paragraphColor:config.paragraphColor
|
|
127
|
+
blockColor:config.mathColor]
|
|
128
|
+
?: config.mathColor;
|
|
129
|
+
}
|
|
130
|
+
|
|
97
131
|
- (void)applyLatex:(NSString *)latex
|
|
98
132
|
{
|
|
99
133
|
_cachedLatex = [latex copy];
|
|
134
|
+
_parseFailed = NO;
|
|
135
|
+
_parseMessage = nil;
|
|
100
136
|
|
|
101
137
|
StyleConfig *config = self.config;
|
|
138
|
+
RCTUIColor *color = [self formulaColor];
|
|
102
139
|
|
|
140
|
+
NSError *error = nil;
|
|
103
141
|
ENRMRaTeXRenderResult *result = [ENRMRaTeXBridge parse:latex
|
|
104
142
|
displayMode:YES
|
|
105
143
|
fontSize:config.mathFontSize
|
|
106
|
-
color:
|
|
144
|
+
color:color
|
|
107
145
|
bold:ENRMMathFontWeightIsBold(config.mathFontWeight)
|
|
108
|
-
glyphOverflow:config.mathGlyphOverflow
|
|
146
|
+
glyphOverflow:config.mathGlyphOverflow
|
|
147
|
+
error:&error];
|
|
148
|
+
if (!result) {
|
|
149
|
+
_parseFailed = YES;
|
|
150
|
+
_parseMessage = error.localizedDescription ?: @"";
|
|
151
|
+
[self reportLatexErrorIfNeeded];
|
|
152
|
+
}
|
|
109
153
|
_mathView.renderResult = result;
|
|
110
|
-
_mathView.fallbackSource = result ? nil : ENRMMathFallbackString(latex, @"$$", config.mathFontSize,
|
|
154
|
+
_mathView.fallbackSource = result ? nil : ENRMMathFallbackString(latex, @"$$", config.mathFontSize, color);
|
|
111
155
|
|
|
112
156
|
CGFloat padding = config.mathPadding;
|
|
113
157
|
_mathView.frame = CGRectMake(padding, padding, ceil(result.width), ceil(result.totalHeight));
|
|
@@ -128,16 +172,23 @@
|
|
|
128
172
|
configurationForMenuAtLocation:(CGPoint)location
|
|
129
173
|
{
|
|
130
174
|
// Returning nil is the UIKit-sanctioned way to suppress a context menu.
|
|
175
|
+
// `contextMenuHidden` (fork) wins over `enableBlockContextMenu` (upstream #708) and still
|
|
176
|
+
// reports the block through onMenuSuppressed (merge decision D1).
|
|
131
177
|
if (self.contextMenuHidden) {
|
|
132
178
|
if (self.onMenuSuppressed) {
|
|
133
179
|
self.onMenuSuppressed([NSString stringWithFormat:@"$$\n%@\n$$", _cachedLatex ?: @""], _cachedLatex ?: @"");
|
|
134
180
|
}
|
|
135
181
|
return nil;
|
|
136
182
|
}
|
|
183
|
+
if (!self.dynamicProps.enableBlockContextMenu) {
|
|
184
|
+
return nil;
|
|
185
|
+
}
|
|
186
|
+
// Labels are read live from the shared dynamic props (upstream); visibility/format/intercept
|
|
187
|
+
// come from the fork's per-view menuOptions.
|
|
137
188
|
__weak __typeof(self) weakSelf = self;
|
|
138
189
|
return ENRMBlockContextMenuConfiguration(
|
|
139
|
-
self.menuOptions, self.
|
|
140
|
-
^{ [weakSelf copyMarkdownToPasteboard]; }, ^{ [weakSelf requestCopy]; });
|
|
190
|
+
self.menuOptions, self.dynamicProps.menuCopyLabel, self.dynamicProps.menuCopyAsMarkdownLabel,
|
|
191
|
+
^{ [weakSelf copyLatexToPasteboard]; }, ^{ [weakSelf copyMarkdownToPasteboard]; }, ^{ [weakSelf requestCopy]; });
|
|
141
192
|
}
|
|
142
193
|
|
|
143
194
|
- (void)requestCopy
|
|
@@ -153,13 +204,13 @@
|
|
|
153
204
|
{
|
|
154
205
|
// This override never falls through to [super menuForEvent:], so nil fully
|
|
155
206
|
// suppresses the menu rather than restoring the AppKit default.
|
|
156
|
-
if (self.contextMenuHidden) {
|
|
207
|
+
if (self.contextMenuHidden || !self.dynamicProps.enableBlockContextMenu) {
|
|
157
208
|
return nil;
|
|
158
209
|
}
|
|
159
210
|
|
|
160
211
|
NSMenu *menu = [[NSMenu alloc] initWithTitle:@""];
|
|
161
|
-
[menu addItem:ENRMCreateMenuItem(self.
|
|
162
|
-
[menu addItem:ENRMCreateMenuItem(self.
|
|
212
|
+
[menu addItem:ENRMCreateMenuItem(self.dynamicProps.menuCopyLabel, ^{ [self copyLatexToPasteboard]; })];
|
|
213
|
+
[menu addItem:ENRMCreateMenuItem(self.dynamicProps.menuCopyAsMarkdownLabel, ^{ [self copyMarkdownToPasteboard]; })];
|
|
163
214
|
return menu;
|
|
164
215
|
}
|
|
165
216
|
#endif
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#import <CoreGraphics/CoreGraphics.h>
|
|
2
|
+
#import <Foundation/Foundation.h>
|
|
3
|
+
|
|
4
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
5
|
+
|
|
6
|
+
#ifdef __cplusplus
|
|
7
|
+
extern "C" {
|
|
8
|
+
#endif
|
|
9
|
+
|
|
10
|
+
// Parse an SVG path `d` string into a CGPath. Supports the M/L/H/V/C/S/Q/T/A/Z
|
|
11
|
+
// command set (absolute and relative), which covers the @primer/octicons glyphs
|
|
12
|
+
// used for admonition headers. Elliptical arcs are approximated with cubic
|
|
13
|
+
// beziers. Returns NULL on empty/invalid input. Caller owns the returned path
|
|
14
|
+
// (CGPathRelease). CoreGraphics is used so the same code renders on iOS and macOS.
|
|
15
|
+
CGPathRef _Nullable ENRMCreateCGPathFromSVGPath(NSString *pathData) CF_RETURNS_RETAINED;
|
|
16
|
+
|
|
17
|
+
#ifdef __cplusplus
|
|
18
|
+
}
|
|
19
|
+
#endif
|
|
20
|
+
|
|
21
|
+
NS_ASSUME_NONNULL_END
|
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
#import "ENRMSVGPath.h"
|
|
2
|
+
#import <math.h>
|
|
3
|
+
|
|
4
|
+
// Minimal SVG path `d` parser producing a CGPath. It is intentionally scoped to
|
|
5
|
+
// the command set the admonition octicons use (M m L l H h V v C c S s Q q T t
|
|
6
|
+
// A a Z z); it is not a general-purpose SVG engine. The parser walks the string
|
|
7
|
+
// with a scanner, tracking the current point, the current subpath start, and the
|
|
8
|
+
// previous control point (for the smooth S/T shorthands). Elliptical arcs are
|
|
9
|
+
// converted to cubic beziers via the endpoint -> center parameterization from
|
|
10
|
+
// the SVG implementation notes (appendix F.6).
|
|
11
|
+
|
|
12
|
+
typedef struct {
|
|
13
|
+
const char *chars;
|
|
14
|
+
NSUInteger length;
|
|
15
|
+
NSUInteger index;
|
|
16
|
+
} ENRMScanner;
|
|
17
|
+
|
|
18
|
+
static BOOL ENRMScanIsCommand(char c)
|
|
19
|
+
{
|
|
20
|
+
switch (c) {
|
|
21
|
+
case 'M':
|
|
22
|
+
case 'm':
|
|
23
|
+
case 'L':
|
|
24
|
+
case 'l':
|
|
25
|
+
case 'H':
|
|
26
|
+
case 'h':
|
|
27
|
+
case 'V':
|
|
28
|
+
case 'v':
|
|
29
|
+
case 'C':
|
|
30
|
+
case 'c':
|
|
31
|
+
case 'S':
|
|
32
|
+
case 's':
|
|
33
|
+
case 'Q':
|
|
34
|
+
case 'q':
|
|
35
|
+
case 'T':
|
|
36
|
+
case 't':
|
|
37
|
+
case 'A':
|
|
38
|
+
case 'a':
|
|
39
|
+
case 'Z':
|
|
40
|
+
case 'z':
|
|
41
|
+
return YES;
|
|
42
|
+
default:
|
|
43
|
+
return NO;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
static void ENRMScanSkipSeparators(ENRMScanner *s)
|
|
48
|
+
{
|
|
49
|
+
while (s->index < s->length) {
|
|
50
|
+
char c = s->chars[s->index];
|
|
51
|
+
if (c == ' ' || c == ',' || c == '\t' || c == '\n' || c == '\r') {
|
|
52
|
+
s->index++;
|
|
53
|
+
} else {
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Reads the next number. SVG allows numbers to run together without separators
|
|
60
|
+
// (e.g. "1 1 0 1 1"), and a leading '-' or '.' starts a new number even with no
|
|
61
|
+
// separator (e.g. "16 0Zm8-6.5"). Returns NO when no number is available.
|
|
62
|
+
static BOOL ENRMScanNumber(ENRMScanner *s, double *out)
|
|
63
|
+
{
|
|
64
|
+
ENRMScanSkipSeparators(s);
|
|
65
|
+
NSUInteger start = s->index;
|
|
66
|
+
BOOL seenDigit = NO;
|
|
67
|
+
BOOL seenDot = NO;
|
|
68
|
+
BOOL seenExp = NO;
|
|
69
|
+
|
|
70
|
+
if (s->index < s->length && (s->chars[s->index] == '+' || s->chars[s->index] == '-')) {
|
|
71
|
+
s->index++;
|
|
72
|
+
}
|
|
73
|
+
while (s->index < s->length) {
|
|
74
|
+
char c = s->chars[s->index];
|
|
75
|
+
if (c >= '0' && c <= '9') {
|
|
76
|
+
seenDigit = YES;
|
|
77
|
+
s->index++;
|
|
78
|
+
} else if (c == '.' && !seenDot && !seenExp) {
|
|
79
|
+
seenDot = YES;
|
|
80
|
+
s->index++;
|
|
81
|
+
} else if ((c == 'e' || c == 'E') && seenDigit && !seenExp) {
|
|
82
|
+
seenExp = YES;
|
|
83
|
+
s->index++;
|
|
84
|
+
if (s->index < s->length && (s->chars[s->index] == '+' || s->chars[s->index] == '-')) {
|
|
85
|
+
s->index++;
|
|
86
|
+
}
|
|
87
|
+
} else {
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (!seenDigit) {
|
|
93
|
+
s->index = start;
|
|
94
|
+
return NO;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
char buffer[64];
|
|
98
|
+
NSUInteger count = s->index - start;
|
|
99
|
+
if (count >= sizeof(buffer)) {
|
|
100
|
+
count = sizeof(buffer) - 1;
|
|
101
|
+
}
|
|
102
|
+
memcpy(buffer, s->chars + start, count);
|
|
103
|
+
buffer[count] = '\0';
|
|
104
|
+
*out = atof(buffer);
|
|
105
|
+
return YES;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// A single arc segment (<= 90 degrees) approximated as one cubic bezier.
|
|
109
|
+
static void ENRMArcSegment(CGMutablePathRef path, double cx, double cy, double rx, double ry, double phi, double t1,
|
|
110
|
+
double dt)
|
|
111
|
+
{
|
|
112
|
+
double cosPhi = cos(phi);
|
|
113
|
+
double sinPhi = sin(phi);
|
|
114
|
+
double alpha = (4.0 / 3.0) * tan(dt / 4.0);
|
|
115
|
+
|
|
116
|
+
double x1 = cos(t1);
|
|
117
|
+
double y1 = sin(t1);
|
|
118
|
+
double x2 = cos(t1 + dt);
|
|
119
|
+
double y2 = sin(t1 + dt);
|
|
120
|
+
|
|
121
|
+
double p1x = cx + rx * cosPhi * x1 - ry * sinPhi * y1;
|
|
122
|
+
double p1y = cy + rx * sinPhi * x1 + ry * cosPhi * y1;
|
|
123
|
+
double p2x = cx + rx * cosPhi * x2 - ry * sinPhi * y2;
|
|
124
|
+
double p2y = cy + rx * sinPhi * x2 + ry * cosPhi * y2;
|
|
125
|
+
|
|
126
|
+
double d1x = -rx * cosPhi * y1 - ry * sinPhi * x1;
|
|
127
|
+
double d1y = -rx * sinPhi * y1 + ry * cosPhi * x1;
|
|
128
|
+
double d2x = -rx * cosPhi * y2 - ry * sinPhi * x2;
|
|
129
|
+
double d2y = -rx * sinPhi * y2 + ry * cosPhi * x2;
|
|
130
|
+
|
|
131
|
+
CGPathAddCurveToPoint(path, NULL, (CGFloat)(p1x + alpha * d1x), (CGFloat)(p1y + alpha * d1y),
|
|
132
|
+
(CGFloat)(p2x - alpha * d2x), (CGFloat)(p2y - alpha * d2y), (CGFloat)p2x, (CGFloat)p2y);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Endpoint -> center parameterization, then split into <=90 degree bezier arcs.
|
|
136
|
+
static void ENRMAppendArc(CGMutablePathRef path, double x0, double y0, double rx, double ry, double xAxisRotationDeg,
|
|
137
|
+
BOOL largeArc, BOOL sweep, double x, double y)
|
|
138
|
+
{
|
|
139
|
+
if (rx == 0.0 || ry == 0.0) {
|
|
140
|
+
CGPathAddLineToPoint(path, NULL, (CGFloat)x, (CGFloat)y);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
rx = fabs(rx);
|
|
145
|
+
ry = fabs(ry);
|
|
146
|
+
double phi = xAxisRotationDeg * M_PI / 180.0;
|
|
147
|
+
double cosPhi = cos(phi);
|
|
148
|
+
double sinPhi = sin(phi);
|
|
149
|
+
|
|
150
|
+
double dx = (x0 - x) / 2.0;
|
|
151
|
+
double dy = (y0 - y) / 2.0;
|
|
152
|
+
double x1p = cosPhi * dx + sinPhi * dy;
|
|
153
|
+
double y1p = -sinPhi * dx + cosPhi * dy;
|
|
154
|
+
|
|
155
|
+
// Scale up the radii if they are too small to span the endpoints.
|
|
156
|
+
double lambda = (x1p * x1p) / (rx * rx) + (y1p * y1p) / (ry * ry);
|
|
157
|
+
if (lambda > 1.0) {
|
|
158
|
+
double scale = sqrt(lambda);
|
|
159
|
+
rx *= scale;
|
|
160
|
+
ry *= scale;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
double num = rx * rx * ry * ry - rx * rx * y1p * y1p - ry * ry * x1p * x1p;
|
|
164
|
+
double den = rx * rx * y1p * y1p + ry * ry * x1p * x1p;
|
|
165
|
+
double factor = den == 0.0 ? 0.0 : sqrt(fmax(0.0, num / den));
|
|
166
|
+
if (largeArc == sweep) {
|
|
167
|
+
factor = -factor;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
double cxp = factor * (rx * y1p / ry);
|
|
171
|
+
double cyp = factor * (-ry * x1p / rx);
|
|
172
|
+
double cx = cosPhi * cxp - sinPhi * cyp + (x0 + x) / 2.0;
|
|
173
|
+
double cy = sinPhi * cxp + cosPhi * cyp + (y0 + y) / 2.0;
|
|
174
|
+
|
|
175
|
+
double startAngle = atan2((y1p - cyp) / ry, (x1p - cxp) / rx);
|
|
176
|
+
double endAngle = atan2((-y1p - cyp) / ry, (-x1p - cxp) / rx);
|
|
177
|
+
double delta = endAngle - startAngle;
|
|
178
|
+
|
|
179
|
+
if (!sweep && delta > 0.0) {
|
|
180
|
+
delta -= 2.0 * M_PI;
|
|
181
|
+
} else if (sweep && delta < 0.0) {
|
|
182
|
+
delta += 2.0 * M_PI;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
int segments = (int)ceil(fabs(delta) / (M_PI / 2.0));
|
|
186
|
+
if (segments < 1) {
|
|
187
|
+
segments = 1;
|
|
188
|
+
}
|
|
189
|
+
double segDelta = delta / segments;
|
|
190
|
+
double angle = startAngle;
|
|
191
|
+
for (int i = 0; i < segments; i++) {
|
|
192
|
+
ENRMArcSegment(path, cx, cy, rx, ry, phi, angle, segDelta);
|
|
193
|
+
angle += segDelta;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
CGPathRef ENRMCreateCGPathFromSVGPath(NSString *pathData)
|
|
198
|
+
{
|
|
199
|
+
if (pathData.length == 0) {
|
|
200
|
+
return NULL;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
NSData *utf8 = [pathData dataUsingEncoding:NSUTF8StringEncoding];
|
|
204
|
+
ENRMScanner scanner = {.chars = (const char *)utf8.bytes, .length = utf8.length, .index = 0};
|
|
205
|
+
ENRMScanner *s = &scanner;
|
|
206
|
+
|
|
207
|
+
CGMutablePathRef path = CGPathCreateMutable();
|
|
208
|
+
double cx = 0, cy = 0; // current point
|
|
209
|
+
double sx = 0, sy = 0; // subpath start
|
|
210
|
+
double lastCx = 0, lastCy = 0; // last cubic control point (for S/s)
|
|
211
|
+
double lastQx = 0, lastQy = 0; // last quadratic control point (for T/t)
|
|
212
|
+
char lastCommand = 0;
|
|
213
|
+
char command = 0;
|
|
214
|
+
|
|
215
|
+
while (s->index < s->length) {
|
|
216
|
+
ENRMScanSkipSeparators(s);
|
|
217
|
+
if (s->index >= s->length) {
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
char c = s->chars[s->index];
|
|
222
|
+
if (ENRMScanIsCommand(c)) {
|
|
223
|
+
command = c;
|
|
224
|
+
s->index++;
|
|
225
|
+
} else if (command == 0) {
|
|
226
|
+
break; // malformed: data before any command
|
|
227
|
+
} else if (command == 'M') {
|
|
228
|
+
command = 'L'; // implicit lineto for repeated M coordinate pairs
|
|
229
|
+
} else if (command == 'm') {
|
|
230
|
+
command = 'l';
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
switch (command) {
|
|
234
|
+
case 'M':
|
|
235
|
+
case 'm': {
|
|
236
|
+
double nx, ny;
|
|
237
|
+
if (!ENRMScanNumber(s, &nx) || !ENRMScanNumber(s, &ny)) {
|
|
238
|
+
goto done;
|
|
239
|
+
}
|
|
240
|
+
if (command == 'm') {
|
|
241
|
+
nx += cx;
|
|
242
|
+
ny += cy;
|
|
243
|
+
}
|
|
244
|
+
cx = nx;
|
|
245
|
+
cy = ny;
|
|
246
|
+
sx = cx;
|
|
247
|
+
sy = cy;
|
|
248
|
+
CGPathMoveToPoint(path, NULL, (CGFloat)cx, (CGFloat)cy);
|
|
249
|
+
break;
|
|
250
|
+
}
|
|
251
|
+
case 'L':
|
|
252
|
+
case 'l': {
|
|
253
|
+
double nx, ny;
|
|
254
|
+
if (!ENRMScanNumber(s, &nx) || !ENRMScanNumber(s, &ny)) {
|
|
255
|
+
goto done;
|
|
256
|
+
}
|
|
257
|
+
if (command == 'l') {
|
|
258
|
+
nx += cx;
|
|
259
|
+
ny += cy;
|
|
260
|
+
}
|
|
261
|
+
cx = nx;
|
|
262
|
+
cy = ny;
|
|
263
|
+
CGPathAddLineToPoint(path, NULL, (CGFloat)cx, (CGFloat)cy);
|
|
264
|
+
break;
|
|
265
|
+
}
|
|
266
|
+
case 'H':
|
|
267
|
+
case 'h': {
|
|
268
|
+
double nx;
|
|
269
|
+
if (!ENRMScanNumber(s, &nx)) {
|
|
270
|
+
goto done;
|
|
271
|
+
}
|
|
272
|
+
cx = command == 'h' ? cx + nx : nx;
|
|
273
|
+
CGPathAddLineToPoint(path, NULL, (CGFloat)cx, (CGFloat)cy);
|
|
274
|
+
break;
|
|
275
|
+
}
|
|
276
|
+
case 'V':
|
|
277
|
+
case 'v': {
|
|
278
|
+
double ny;
|
|
279
|
+
if (!ENRMScanNumber(s, &ny)) {
|
|
280
|
+
goto done;
|
|
281
|
+
}
|
|
282
|
+
cy = command == 'v' ? cy + ny : ny;
|
|
283
|
+
CGPathAddLineToPoint(path, NULL, (CGFloat)cx, (CGFloat)cy);
|
|
284
|
+
break;
|
|
285
|
+
}
|
|
286
|
+
case 'C':
|
|
287
|
+
case 'c': {
|
|
288
|
+
double c1x, c1y, c2x, c2y, nx, ny;
|
|
289
|
+
if (!ENRMScanNumber(s, &c1x) || !ENRMScanNumber(s, &c1y) || !ENRMScanNumber(s, &c2x) ||
|
|
290
|
+
!ENRMScanNumber(s, &c2y) || !ENRMScanNumber(s, &nx) || !ENRMScanNumber(s, &ny)) {
|
|
291
|
+
goto done;
|
|
292
|
+
}
|
|
293
|
+
if (command == 'c') {
|
|
294
|
+
c1x += cx;
|
|
295
|
+
c1y += cy;
|
|
296
|
+
c2x += cx;
|
|
297
|
+
c2y += cy;
|
|
298
|
+
nx += cx;
|
|
299
|
+
ny += cy;
|
|
300
|
+
}
|
|
301
|
+
CGPathAddCurveToPoint(path, NULL, (CGFloat)c1x, (CGFloat)c1y, (CGFloat)c2x, (CGFloat)c2y, (CGFloat)nx,
|
|
302
|
+
(CGFloat)ny);
|
|
303
|
+
lastCx = c2x;
|
|
304
|
+
lastCy = c2y;
|
|
305
|
+
cx = nx;
|
|
306
|
+
cy = ny;
|
|
307
|
+
break;
|
|
308
|
+
}
|
|
309
|
+
case 'S':
|
|
310
|
+
case 's': {
|
|
311
|
+
double c2x, c2y, nx, ny;
|
|
312
|
+
if (!ENRMScanNumber(s, &c2x) || !ENRMScanNumber(s, &c2y) || !ENRMScanNumber(s, &nx) ||
|
|
313
|
+
!ENRMScanNumber(s, &ny)) {
|
|
314
|
+
goto done;
|
|
315
|
+
}
|
|
316
|
+
if (command == 's') {
|
|
317
|
+
c2x += cx;
|
|
318
|
+
c2y += cy;
|
|
319
|
+
nx += cx;
|
|
320
|
+
ny += cy;
|
|
321
|
+
}
|
|
322
|
+
double c1x = cx, c1y = cy;
|
|
323
|
+
if (lastCommand == 'C' || lastCommand == 'c' || lastCommand == 'S' || lastCommand == 's') {
|
|
324
|
+
c1x = 2 * cx - lastCx;
|
|
325
|
+
c1y = 2 * cy - lastCy;
|
|
326
|
+
}
|
|
327
|
+
CGPathAddCurveToPoint(path, NULL, (CGFloat)c1x, (CGFloat)c1y, (CGFloat)c2x, (CGFloat)c2y, (CGFloat)nx,
|
|
328
|
+
(CGFloat)ny);
|
|
329
|
+
lastCx = c2x;
|
|
330
|
+
lastCy = c2y;
|
|
331
|
+
cx = nx;
|
|
332
|
+
cy = ny;
|
|
333
|
+
break;
|
|
334
|
+
}
|
|
335
|
+
case 'Q':
|
|
336
|
+
case 'q': {
|
|
337
|
+
double c1x, c1y, nx, ny;
|
|
338
|
+
if (!ENRMScanNumber(s, &c1x) || !ENRMScanNumber(s, &c1y) || !ENRMScanNumber(s, &nx) ||
|
|
339
|
+
!ENRMScanNumber(s, &ny)) {
|
|
340
|
+
goto done;
|
|
341
|
+
}
|
|
342
|
+
if (command == 'q') {
|
|
343
|
+
c1x += cx;
|
|
344
|
+
c1y += cy;
|
|
345
|
+
nx += cx;
|
|
346
|
+
ny += cy;
|
|
347
|
+
}
|
|
348
|
+
CGPathAddQuadCurveToPoint(path, NULL, (CGFloat)c1x, (CGFloat)c1y, (CGFloat)nx, (CGFloat)ny);
|
|
349
|
+
lastQx = c1x;
|
|
350
|
+
lastQy = c1y;
|
|
351
|
+
cx = nx;
|
|
352
|
+
cy = ny;
|
|
353
|
+
break;
|
|
354
|
+
}
|
|
355
|
+
case 'T':
|
|
356
|
+
case 't': {
|
|
357
|
+
double nx, ny;
|
|
358
|
+
if (!ENRMScanNumber(s, &nx) || !ENRMScanNumber(s, &ny)) {
|
|
359
|
+
goto done;
|
|
360
|
+
}
|
|
361
|
+
if (command == 't') {
|
|
362
|
+
nx += cx;
|
|
363
|
+
ny += cy;
|
|
364
|
+
}
|
|
365
|
+
double c1x = cx, c1y = cy;
|
|
366
|
+
if (lastCommand == 'Q' || lastCommand == 'q' || lastCommand == 'T' || lastCommand == 't') {
|
|
367
|
+
c1x = 2 * cx - lastQx;
|
|
368
|
+
c1y = 2 * cy - lastQy;
|
|
369
|
+
}
|
|
370
|
+
CGPathAddQuadCurveToPoint(path, NULL, (CGFloat)c1x, (CGFloat)c1y, (CGFloat)nx, (CGFloat)ny);
|
|
371
|
+
lastQx = c1x;
|
|
372
|
+
lastQy = c1y;
|
|
373
|
+
cx = nx;
|
|
374
|
+
cy = ny;
|
|
375
|
+
break;
|
|
376
|
+
}
|
|
377
|
+
case 'A':
|
|
378
|
+
case 'a': {
|
|
379
|
+
double rx, ry, rot, laf, sf, nx, ny;
|
|
380
|
+
if (!ENRMScanNumber(s, &rx) || !ENRMScanNumber(s, &ry) || !ENRMScanNumber(s, &rot) ||
|
|
381
|
+
!ENRMScanNumber(s, &laf) || !ENRMScanNumber(s, &sf) || !ENRMScanNumber(s, &nx) || !ENRMScanNumber(s, &ny)) {
|
|
382
|
+
goto done;
|
|
383
|
+
}
|
|
384
|
+
if (command == 'a') {
|
|
385
|
+
nx += cx;
|
|
386
|
+
ny += cy;
|
|
387
|
+
}
|
|
388
|
+
ENRMAppendArc(path, cx, cy, rx, ry, rot, laf != 0.0, sf != 0.0, nx, ny);
|
|
389
|
+
cx = nx;
|
|
390
|
+
cy = ny;
|
|
391
|
+
break;
|
|
392
|
+
}
|
|
393
|
+
case 'Z':
|
|
394
|
+
case 'z': {
|
|
395
|
+
CGPathCloseSubpath(path);
|
|
396
|
+
cx = sx;
|
|
397
|
+
cy = sy;
|
|
398
|
+
break;
|
|
399
|
+
}
|
|
400
|
+
default:
|
|
401
|
+
goto done;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
lastCommand = command;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
done:
|
|
408
|
+
return path;
|
|
409
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#import "ENRMUIKit.h"
|
|
4
|
+
#import "ParagraphStyleUtils.h"
|
|
5
|
+
#import "RenderedMarkdownSegment.h"
|
|
6
|
+
#import "StyleConfig.h"
|
|
7
|
+
|
|
8
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* View-free height summation for a vertical stack of already-rendered
|
|
12
|
+
* segments at a fixed content width. This is the iOS counterpart of Android's
|
|
13
|
+
* SegmentHeightMeasurer: it single-sources the per-segment height arithmetic so
|
|
14
|
+
* the shadow-node measurement pass (ENRMViewFreeMeasurement) and the blockquote
|
|
15
|
+
* container's own laid-out/static heights cannot drift.
|
|
16
|
+
*
|
|
17
|
+
* Each kind is measured with the same helper the visible view uses: text via a
|
|
18
|
+
* fresh call-confined TextKit stack (ENRMMeasureAttributedTextViewFree), tables
|
|
19
|
+
* via +[TableContainerView measureHeightForTableNode:...], code blocks via
|
|
20
|
+
* +[ENRMCodeBlockContainerView measureHeightForCodeBlockNode:...], math via
|
|
21
|
+
* +[ENRMMathContainerView measureHeightForLatex:...], and nested blockquotes via
|
|
22
|
+
* +[ENRMBlockquoteContainerView measureHeightForBlockquoteNode:...] (recursion).
|
|
23
|
+
* Per-kind margins come from the config exactly as computeSegmentLayout applies
|
|
24
|
+
* them: marginTop before, marginBottom after unless it is the last segment and
|
|
25
|
+
* trailing margins are disabled.
|
|
26
|
+
*/
|
|
27
|
+
CGFloat ENRMMeasureSegmentsHeightViewFree(NSArray<ENRMRenderedSegment *> *segments, StyleConfig *config,
|
|
28
|
+
CGFloat contentWidth, BOOL allowTrailingMargin, CGFloat pointScaleFactor,
|
|
29
|
+
ENRMWritingDirectionMode writingDirectionMode,
|
|
30
|
+
NSWritingDirection resolvedLayoutDirection, BOOL allowFontScaling,
|
|
31
|
+
NSLineBreakStrategy lineBreakStrategy);
|
|
32
|
+
|
|
33
|
+
NS_ASSUME_NONNULL_END
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
#import "ENRMSegmentHeightMeasurer.h"
|
|
2
|
+
#import "ENRMBlockquoteContainerView.h"
|
|
3
|
+
#import "ENRMCodeBlockContainerView.h"
|
|
4
|
+
#import "ENRMFeatureFlags.h"
|
|
5
|
+
#import "ENRMTextRenderer.h"
|
|
6
|
+
#import "ENRMViewFreeMeasurement.h"
|
|
7
|
+
#import "TableContainerView.h"
|
|
8
|
+
#if ENRICHED_MARKDOWN_MATH
|
|
9
|
+
#import "ENRMMathContainerView.h"
|
|
10
|
+
#endif
|
|
11
|
+
#if ENRICHED_MARKDOWN_VIDEO
|
|
12
|
+
#import "ENRMVideoContainerView.h"
|
|
13
|
+
#endif
|
|
14
|
+
|
|
15
|
+
CGFloat ENRMMeasureSegmentsHeightViewFree(NSArray<ENRMRenderedSegment *> *segments, StyleConfig *config,
|
|
16
|
+
CGFloat contentWidth, BOOL allowTrailingMargin, CGFloat pointScaleFactor,
|
|
17
|
+
ENRMWritingDirectionMode writingDirectionMode,
|
|
18
|
+
NSWritingDirection resolvedLayoutDirection, BOOL allowFontScaling,
|
|
19
|
+
NSLineBreakStrategy lineBreakStrategy)
|
|
20
|
+
{
|
|
21
|
+
if (segments.count == 0) {
|
|
22
|
+
return 0;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
CGFloat totalHeight = 0;
|
|
26
|
+
const NSUInteger lastIndex = segments.count - 1;
|
|
27
|
+
|
|
28
|
+
for (NSUInteger i = 0; i < segments.count; i++) {
|
|
29
|
+
ENRMRenderedSegment *segment = segments[i];
|
|
30
|
+
const BOOL isLast = (i == lastIndex);
|
|
31
|
+
const BOOL shouldAddBottomMargin = (!isLast || allowTrailingMargin);
|
|
32
|
+
|
|
33
|
+
if (segment.kind == ENRMSegmentKindText && segment.textResult) {
|
|
34
|
+
// GFM segments are never line-clamped (numberOfLines is a no-op for GFM).
|
|
35
|
+
CGSize textSize = ENRMMeasureAttributedTextViewFree(
|
|
36
|
+
segment.textResult.attributedText, contentWidth, config, shouldAddBottomMargin,
|
|
37
|
+
segment.textResult.lastElementMarginBottom, pointScaleFactor, 0, NSLineBreakByWordWrapping);
|
|
38
|
+
totalHeight += textSize.height;
|
|
39
|
+
} else if (segment.kind == ENRMSegmentKindTable && segment.tableSegment) {
|
|
40
|
+
totalHeight += config.tableMarginTop;
|
|
41
|
+
totalHeight += [TableContainerView measureHeightForTableNode:segment.tableSegment.tableNode
|
|
42
|
+
config:config
|
|
43
|
+
allowFontScaling:allowFontScaling
|
|
44
|
+
maxFontSizeMultiplier:config.maxFontSizeMultiplier
|
|
45
|
+
writingDirectionMode:writingDirectionMode
|
|
46
|
+
resolvedLayoutDirection:resolvedLayoutDirection];
|
|
47
|
+
if (shouldAddBottomMargin) {
|
|
48
|
+
totalHeight += config.tableMarginBottom;
|
|
49
|
+
}
|
|
50
|
+
} else if (segment.kind == ENRMSegmentKindCodeBlock && segment.codeBlockSegment) {
|
|
51
|
+
totalHeight += config.codeBlockMarginTop;
|
|
52
|
+
totalHeight += [ENRMCodeBlockContainerView measureHeightForCodeBlockNode:segment.codeBlockSegment.codeBlockNode
|
|
53
|
+
config:config];
|
|
54
|
+
if (shouldAddBottomMargin) {
|
|
55
|
+
totalHeight += config.codeBlockMarginBottom;
|
|
56
|
+
}
|
|
57
|
+
} else if (segment.kind == ENRMSegmentKindBlockquote && segment.blockquoteSegment) {
|
|
58
|
+
// This helper only ever sums a quote's own children, so any quote here is
|
|
59
|
+
// nested and carries no vertical margin (only the outermost quote does,
|
|
60
|
+
// added by the root measurement pass); mirrors ENRMBlockquoteContainerView.nested.
|
|
61
|
+
totalHeight +=
|
|
62
|
+
[ENRMBlockquoteContainerView measureHeightForBlockquoteNode:segment.blockquoteSegment.blockquoteNode
|
|
63
|
+
config:config
|
|
64
|
+
maxWidth:contentWidth
|
|
65
|
+
pointScaleFactor:pointScaleFactor
|
|
66
|
+
allowFontScaling:allowFontScaling
|
|
67
|
+
lineBreakStrategy:lineBreakStrategy];
|
|
68
|
+
}
|
|
69
|
+
#if ENRICHED_MARKDOWN_MATH
|
|
70
|
+
else if (segment.kind == ENRMSegmentKindMath && segment.mathSegment) {
|
|
71
|
+
totalHeight += config.mathMarginTop;
|
|
72
|
+
totalHeight += [ENRMMathContainerView measureHeightForLatex:segment.mathSegment.latex
|
|
73
|
+
config:config
|
|
74
|
+
maxWidth:contentWidth];
|
|
75
|
+
if (shouldAddBottomMargin) {
|
|
76
|
+
totalHeight += config.mathMarginBottom;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
#endif
|
|
80
|
+
#if ENRICHED_MARKDOWN_VIDEO
|
|
81
|
+
else if (segment.kind == ENRMSegmentKindVideo && segment.videoSegment) {
|
|
82
|
+
totalHeight += config.videoMarginTop;
|
|
83
|
+
totalHeight += [ENRMVideoContainerView measureHeightForVideoNode:segment.videoSegment.videoNode
|
|
84
|
+
config:config
|
|
85
|
+
maxWidth:contentWidth];
|
|
86
|
+
if (shouldAddBottomMargin) {
|
|
87
|
+
totalHeight += config.videoMarginBottom;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
#endif
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return totalHeight;
|
|
94
|
+
}
|