@mathers101/react-native-render-rich-text 0.0.0-stage → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/README.md +140 -3
- package/ReactNativeRenderRichText.podspec +23 -0
- package/android/build.gradle +86 -0
- package/android/consumer-rules.pro +3 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/cpp/jni-adapter.cpp +191 -0
- package/android/src/main/java/com/renderrichtext/EnrichedTiptapText.kt +673 -0
- package/android/src/main/java/com/renderrichtext/EnrichedTiptapTextLayoutManager.kt +24 -0
- package/android/src/main/java/com/renderrichtext/EnrichedTiptapTextManager.kt +405 -0
- package/android/src/main/java/com/renderrichtext/EnrichedTiptapTextPackage.kt +13 -0
- package/android/src/main/java/com/renderrichtext/MeasurementStore.kt +644 -0
- package/android/src/main/java/com/renderrichtext/accessibility/AccessibilityLabels.kt +17 -0
- package/android/src/main/java/com/renderrichtext/accessibility/AccessibleTiptapTextView.kt +112 -0
- package/android/src/main/java/com/renderrichtext/accessibility/TiptapAccessibilityHelper.kt +576 -0
- package/android/src/main/java/com/renderrichtext/events/CodeBlockPressEvent.kt +24 -0
- package/android/src/main/java/com/renderrichtext/events/ContextMenuItemPressEvent.kt +28 -0
- package/android/src/main/java/com/renderrichtext/events/CopyPressEvent.kt +24 -0
- package/android/src/main/java/com/renderrichtext/events/FactoidPressEvent.kt +23 -0
- package/android/src/main/java/com/renderrichtext/events/ImagePressEvent.kt +25 -0
- package/android/src/main/java/com/renderrichtext/events/LatexErrorEvent.kt +29 -0
- package/android/src/main/java/com/renderrichtext/events/LinkLongPressEvent.kt +23 -0
- package/android/src/main/java/com/renderrichtext/events/LinkPressEvent.kt +23 -0
- package/android/src/main/java/com/renderrichtext/events/MentionLongPressEvent.kt +25 -0
- package/android/src/main/java/com/renderrichtext/events/MentionPressEvent.kt +25 -0
- package/android/src/main/java/com/renderrichtext/events/TaskListItemPressEvent.kt +26 -0
- package/android/src/main/java/com/renderrichtext/math/LatexErrorReporter.kt +9 -0
- package/android/src/main/java/com/renderrichtext/parser/Parser.kt +59 -0
- package/android/src/main/java/com/renderrichtext/parser/TextLinkMatching.kt +35 -0
- package/android/src/main/java/com/renderrichtext/parser/TiptapASTNode.kt +69 -0
- package/android/src/main/java/com/renderrichtext/renderer/BaselineShiftRenderer.kt +45 -0
- package/android/src/main/java/com/renderrichtext/renderer/BlankLineRenderer.kt +39 -0
- package/android/src/main/java/com/renderrichtext/renderer/BlockStyleContext.kt +181 -0
- package/android/src/main/java/com/renderrichtext/renderer/BlockquoteRenderer.kt +243 -0
- package/android/src/main/java/com/renderrichtext/renderer/BlockquoteTextRenderer.kt +56 -0
- package/android/src/main/java/com/renderrichtext/renderer/CodeBlockRenderer.kt +135 -0
- package/android/src/main/java/com/renderrichtext/renderer/CodeRenderer.kt +37 -0
- package/android/src/main/java/com/renderrichtext/renderer/EmphasisRenderer.kt +28 -0
- package/android/src/main/java/com/renderrichtext/renderer/FactoidRenderer.kt +97 -0
- package/android/src/main/java/com/renderrichtext/renderer/HeadingRenderer.kt +81 -0
- package/android/src/main/java/com/renderrichtext/renderer/HighlightRenderer.kt +26 -0
- package/android/src/main/java/com/renderrichtext/renderer/LineBreakRenderer.kt +17 -0
- package/android/src/main/java/com/renderrichtext/renderer/LinkRenderer.kt +90 -0
- package/android/src/main/java/com/renderrichtext/renderer/ListContextManager.kt +109 -0
- package/android/src/main/java/com/renderrichtext/renderer/ListItemRenderer.kt +211 -0
- package/android/src/main/java/com/renderrichtext/renderer/ListRenderer.kt +133 -0
- package/android/src/main/java/com/renderrichtext/renderer/MentionRenderer.kt +85 -0
- package/android/src/main/java/com/renderrichtext/renderer/NodeRenderer.kt +207 -0
- package/android/src/main/java/com/renderrichtext/renderer/ParagraphRenderer.kt +91 -0
- package/android/src/main/java/com/renderrichtext/renderer/Renderer.kt +148 -0
- package/android/src/main/java/com/renderrichtext/renderer/SoftBreakRenderer.kt +17 -0
- package/android/src/main/java/com/renderrichtext/renderer/SpanStyleCache.kt +143 -0
- package/android/src/main/java/com/renderrichtext/renderer/StrikethroughRenderer.kt +28 -0
- package/android/src/main/java/com/renderrichtext/renderer/StrongRenderer.kt +28 -0
- package/android/src/main/java/com/renderrichtext/renderer/TextRenderer.kt +31 -0
- package/android/src/main/java/com/renderrichtext/renderer/ThematicBreakRenderer.kt +46 -0
- package/android/src/main/java/com/renderrichtext/renderer/UnderlineRenderer.kt +28 -0
- package/android/src/main/java/com/renderrichtext/spans/BaseListSpan.kt +164 -0
- package/android/src/main/java/com/renderrichtext/spans/BaselineShiftSpan.kt +27 -0
- package/android/src/main/java/com/renderrichtext/spans/BlockquoteSpan.kt +302 -0
- package/android/src/main/java/com/renderrichtext/spans/CodeBackgroundSpan.kt +205 -0
- package/android/src/main/java/com/renderrichtext/spans/CodeBlockSpan.kt +216 -0
- package/android/src/main/java/com/renderrichtext/spans/CodeSpan.kt +32 -0
- package/android/src/main/java/com/renderrichtext/spans/EmphasisSpan.kt +42 -0
- package/android/src/main/java/com/renderrichtext/spans/FactoidBackgroundSpan.kt +265 -0
- package/android/src/main/java/com/renderrichtext/spans/FactoidPaddingSpan.kt +258 -0
- package/android/src/main/java/com/renderrichtext/spans/FactoidSpan.kt +32 -0
- package/android/src/main/java/com/renderrichtext/spans/FadeInSpan.kt +29 -0
- package/android/src/main/java/com/renderrichtext/spans/HeadingSpan.kt +38 -0
- package/android/src/main/java/com/renderrichtext/spans/HighlightSpan.kt +80 -0
- package/android/src/main/java/com/renderrichtext/spans/ImageSpan.kt +481 -0
- package/android/src/main/java/com/renderrichtext/spans/InlineBackgroundGeometry.kt +42 -0
- package/android/src/main/java/com/renderrichtext/spans/LineHeightSpan.kt +39 -0
- package/android/src/main/java/com/renderrichtext/spans/LinkPillIconCache.kt +154 -0
- package/android/src/main/java/com/renderrichtext/spans/LinkPillSpan.kt +381 -0
- package/android/src/main/java/com/renderrichtext/spans/LinkSpan.kt +68 -0
- package/android/src/main/java/com/renderrichtext/spans/ListItemSpacingSpan.kt +33 -0
- package/android/src/main/java/com/renderrichtext/spans/ListMarkerAnchorSpan.kt +38 -0
- package/android/src/main/java/com/renderrichtext/spans/MarginBottomSpan.kt +76 -0
- package/android/src/main/java/com/renderrichtext/spans/MentionChipSpan.kt +132 -0
- package/android/src/main/java/com/renderrichtext/spans/MentionSpan.kt +46 -0
- package/android/src/main/java/com/renderrichtext/spans/OrderedListSpan.kt +127 -0
- package/android/src/main/java/com/renderrichtext/spans/SpoilerSpan.kt +33 -0
- package/android/src/main/java/com/renderrichtext/spans/StrikethroughSpan.kt +12 -0
- package/android/src/main/java/com/renderrichtext/spans/StrongSpan.kt +39 -0
- package/android/src/main/java/com/renderrichtext/spans/TaskListSpan.kt +143 -0
- package/android/src/main/java/com/renderrichtext/spans/TextSpan.kt +26 -0
- package/android/src/main/java/com/renderrichtext/spans/ThematicBreakSpan.kt +69 -0
- package/android/src/main/java/com/renderrichtext/spans/UnorderedListSpan.kt +96 -0
- package/android/src/main/java/com/renderrichtext/spoiler/SpoilerStubs.kt +46 -0
- package/android/src/main/java/com/renderrichtext/styles/BaseBlockStyle.kt +11 -0
- package/android/src/main/java/com/renderrichtext/styles/BlockquoteStyle.kt +83 -0
- package/android/src/main/java/com/renderrichtext/styles/CodeBlockStyle.kt +80 -0
- package/android/src/main/java/com/renderrichtext/styles/CodeStyle.kt +26 -0
- package/android/src/main/java/com/renderrichtext/styles/EmphasisStyle.kt +21 -0
- package/android/src/main/java/com/renderrichtext/styles/FactoidStyle.kt +21 -0
- package/android/src/main/java/com/renderrichtext/styles/HeadingStyle.kt +33 -0
- package/android/src/main/java/com/renderrichtext/styles/HighlightStyle.kt +19 -0
- package/android/src/main/java/com/renderrichtext/styles/ImageStyle.kt +29 -0
- package/android/src/main/java/com/renderrichtext/styles/InlineImageStyle.kt +17 -0
- package/android/src/main/java/com/renderrichtext/styles/InlineMathStyle.kt +17 -0
- package/android/src/main/java/com/renderrichtext/styles/LinkPillContent.kt +36 -0
- package/android/src/main/java/com/renderrichtext/styles/LinkPillStyle.kt +44 -0
- package/android/src/main/java/com/renderrichtext/styles/LinkStyle.kt +23 -0
- package/android/src/main/java/com/renderrichtext/styles/LinkVariantEntry.kt +34 -0
- package/android/src/main/java/com/renderrichtext/styles/ListStyle.kt +65 -0
- package/android/src/main/java/com/renderrichtext/styles/MathStyle.kt +29 -0
- package/android/src/main/java/com/renderrichtext/styles/MentionStyle.kt +19 -0
- package/android/src/main/java/com/renderrichtext/styles/ParagraphStyle.kt +33 -0
- package/android/src/main/java/com/renderrichtext/styles/SpoilerStyle.kt +27 -0
- package/android/src/main/java/com/renderrichtext/styles/StrikethroughStyle.kt +17 -0
- package/android/src/main/java/com/renderrichtext/styles/StrongStyle.kt +21 -0
- package/android/src/main/java/com/renderrichtext/styles/StyleConfig.kt +411 -0
- package/android/src/main/java/com/renderrichtext/styles/StyleParser.kt +92 -0
- package/android/src/main/java/com/renderrichtext/styles/SubscriptStyle.kt +16 -0
- package/android/src/main/java/com/renderrichtext/styles/SuperscriptStyle.kt +16 -0
- package/android/src/main/java/com/renderrichtext/styles/TableStyle.kt +75 -0
- package/android/src/main/java/com/renderrichtext/styles/TaskListStyle.kt +29 -0
- package/android/src/main/java/com/renderrichtext/styles/TextAlignment.kt +32 -0
- package/android/src/main/java/com/renderrichtext/styles/ThematicBreakStyle.kt +23 -0
- package/android/src/main/java/com/renderrichtext/styles/UnderlineStyle.kt +17 -0
- package/android/src/main/java/com/renderrichtext/styles/VideoStyle.kt +31 -0
- package/android/src/main/java/com/renderrichtext/utils/common/BorderStyleUtils.kt +86 -0
- package/android/src/main/java/com/renderrichtext/utils/common/BreakStrategyUtils.kt +32 -0
- package/android/src/main/java/com/renderrichtext/utils/common/CodeBlockHighlighter.kt +36 -0
- package/android/src/main/java/com/renderrichtext/utils/common/CodeBlockNode.kt +42 -0
- package/android/src/main/java/com/renderrichtext/utils/common/EllipsizeUtils.kt +27 -0
- package/android/src/main/java/com/renderrichtext/utils/common/EnrichedTiptapAncestorUtils.kt +10 -0
- package/android/src/main/java/com/renderrichtext/utils/common/FeatureFlags.kt +9 -0
- package/android/src/main/java/com/renderrichtext/utils/common/LinkRecognitionProps.kt +31 -0
- package/android/src/main/java/com/renderrichtext/utils/common/LinkRegexConfig.kt +56 -0
- package/android/src/main/java/com/renderrichtext/utils/common/MotionPreferences.kt +18 -0
- package/android/src/main/java/com/renderrichtext/utils/common/ReadableMapExtensions.kt +28 -0
- package/android/src/main/java/com/renderrichtext/utils/common/TiptapViewManagerUtils.kt +242 -0
- package/android/src/main/java/com/renderrichtext/utils/common/layout/RTLUtils.kt +6 -0
- package/android/src/main/java/com/renderrichtext/utils/common/serialization/TiptapASTSerializer.kt +368 -0
- package/android/src/main/java/com/renderrichtext/utils/text/ImageCache.kt +88 -0
- package/android/src/main/java/com/renderrichtext/utils/text/ImageDownloader.kt +203 -0
- package/android/src/main/java/com/renderrichtext/utils/text/LocalImageLoader.kt +167 -0
- package/android/src/main/java/com/renderrichtext/utils/text/TailFadeInAnimator.kt +84 -0
- package/android/src/main/java/com/renderrichtext/utils/text/conversion/HTMLGenerator.kt +1105 -0
- package/android/src/main/java/com/renderrichtext/utils/text/conversion/TiptapExtractor.kt +423 -0
- package/android/src/main/java/com/renderrichtext/utils/text/extensions/ParagraphUtils.kt +9 -0
- package/android/src/main/java/com/renderrichtext/utils/text/extensions/SpannableExtensions.kt +9 -0
- package/android/src/main/java/com/renderrichtext/utils/text/extensions/TextPaintExtensions.kt +76 -0
- package/android/src/main/java/com/renderrichtext/utils/text/interaction/CheckboxTouchHelper.kt +61 -0
- package/android/src/main/java/com/renderrichtext/utils/text/interaction/TaskListTapUtils.kt +286 -0
- package/android/src/main/java/com/renderrichtext/utils/text/span/ApplyLineHeight.kt +39 -0
- package/android/src/main/java/com/renderrichtext/utils/text/span/BlockSpacing.kt +142 -0
- package/android/src/main/java/com/renderrichtext/utils/text/span/SpanFlags.kt +43 -0
- package/android/src/main/java/com/renderrichtext/utils/text/span/WidthAwareSpans.kt +30 -0
- package/android/src/main/java/com/renderrichtext/utils/text/view/CodeBlockPressHost.kt +15 -0
- package/android/src/main/java/com/renderrichtext/utils/text/view/ImagePressHost.kt +19 -0
- package/android/src/main/java/com/renderrichtext/utils/text/view/LinkEvents.kt +88 -0
- package/android/src/main/java/com/renderrichtext/utils/text/view/LinkLongPressMovementMethod.kt +449 -0
- package/android/src/main/java/com/renderrichtext/utils/text/view/SelectionActionMode.kt +235 -0
- package/android/src/main/java/com/renderrichtext/utils/text/view/TextSelectionColors.kt +48 -0
- package/android/src/main/java/com/renderrichtext/utils/text/view/TextViewSetup.kt +119 -0
- package/android/src/main/java/com/renderrichtext/views/ContextMenuPopup.kt +217 -0
- package/android/src/main/java/com/renderrichtext/views/CopyGlyph.kt +101 -0
- package/android/src/main/java/com/renderrichtext/views/WrapGlyph.kt +40 -0
- package/android/src/main/jni/CMakeLists.txt +52 -0
- package/android/src/main/jni/react/renderer/components/RichTextSpec/ComponentDescriptors.h +30 -0
- package/android/src/main/jni/react/renderer/components/RichTextSpec/TiptapTextComponentDescriptor.h +29 -0
- package/android/src/main/jni/react/renderer/components/RichTextSpec/TiptapTextMeasurementManager.cpp +45 -0
- package/android/src/main/jni/react/renderer/components/RichTextSpec/TiptapTextMeasurementManager.h +21 -0
- package/android/src/main/jni/react/renderer/components/RichTextSpec/TiptapTextShadowNode.cpp +38 -0
- package/android/src/main/jni/react/renderer/components/RichTextSpec/TiptapTextShadowNode.h +53 -0
- package/android/src/main/jni/react/renderer/components/RichTextSpec/TiptapTextState.cpp +9 -0
- package/android/src/main/jni/react/renderer/components/RichTextSpec/TiptapTextState.h +24 -0
- package/android/src/main/jni/react/renderer/components/RichTextSpec/conversions.h +40 -0
- package/cpp/parser/TiptapASTNode.hpp +68 -0
- package/cpp/parser/TiptapParser.cpp +233 -0
- package/cpp/parser/TiptapParser.hpp +13 -0
- package/cpp/vendor/nlohmann/json.hpp +24765 -0
- package/ios/EnrichedTiptapText.h +27 -0
- package/ios/EnrichedTiptapText.mm +1222 -0
- package/ios/attachments/ENRMImageAttachment.h +51 -0
- package/ios/attachments/ENRMImageAttachment.m +398 -0
- package/ios/attachments/ENRMLinkPillAttachment.h +47 -0
- package/ios/attachments/ENRMLinkPillAttachment.m +324 -0
- package/ios/attachments/ENRMLinkPillIconCache.h +28 -0
- package/ios/attachments/ENRMLinkPillIconCache.m +181 -0
- package/ios/attachments/ENRMLinkPillText.h +27 -0
- package/ios/attachments/ENRMLinkPillText.m +118 -0
- package/ios/attachments/ENRMMathInlineAttachment.h +7 -0
- package/ios/attachments/ENRMMathInlineAttachment.m +4 -0
- package/ios/attachments/ThematicBreakAttachment.h +15 -0
- package/ios/attachments/ThematicBreakAttachment.m +33 -0
- package/ios/internals/ENRMViewFreeMeasurement.h +208 -0
- package/ios/internals/EnrichedTiptapTextComponentDescriptor.h +19 -0
- package/ios/internals/EnrichedTiptapTextShadowNode.h +43 -0
- package/ios/internals/EnrichedTiptapTextShadowNode.mm +69 -0
- package/ios/internals/EnrichedTiptapTextState.h +24 -0
- package/ios/internals/MeasurementCache.h +308 -0
- package/ios/internals/ShadowMeasurementUtils.h +145 -0
- package/ios/parser/ENRMTextLinkAttributes.h +7 -0
- package/ios/parser/ENRMTiptapParser.h +33 -0
- package/ios/parser/ENRMTiptapParser.mm +73 -0
- package/ios/parser/TiptapASTNode.h +57 -0
- package/ios/parser/TiptapASTNode.m +52 -0
- package/ios/parser/TiptapParserBridge.mm +179 -0
- package/ios/renderer/AttributedRenderer.h +23 -0
- package/ios/renderer/AttributedRenderer.m +229 -0
- package/ios/renderer/BaseRenderer.h +33 -0
- package/ios/renderer/BaseRenderer.m +46 -0
- package/ios/renderer/BaselineShiftTextAttributes.h +10 -0
- package/ios/renderer/BaselineShiftTextAttributes.m +26 -0
- package/ios/renderer/BlankLineRenderer.h +4 -0
- package/ios/renderer/BlankLineRenderer.m +51 -0
- package/ios/renderer/BlockquoteRenderer.h +6 -0
- package/ios/renderer/BlockquoteRenderer.m +258 -0
- package/ios/renderer/CodeBlockRenderer.h +9 -0
- package/ios/renderer/CodeBlockRenderer.m +99 -0
- package/ios/renderer/CodeRenderer.h +9 -0
- package/ios/renderer/CodeRenderer.m +69 -0
- package/ios/renderer/ENRMBlockquoteTextRenderer.h +25 -0
- package/ios/renderer/ENRMBlockquoteTextRenderer.m +48 -0
- package/ios/renderer/EmphasisRenderer.h +5 -0
- package/ios/renderer/EmphasisRenderer.m +100 -0
- package/ios/renderer/FactoidRenderer.h +9 -0
- package/ios/renderer/FactoidRenderer.m +130 -0
- package/ios/renderer/HeadingRenderer.h +6 -0
- package/ios/renderer/HeadingRenderer.m +103 -0
- package/ios/renderer/HighlightRenderer.h +7 -0
- package/ios/renderer/HighlightRenderer.m +33 -0
- package/ios/renderer/LinkRenderer.h +6 -0
- package/ios/renderer/LinkRenderer.m +158 -0
- package/ios/renderer/ListItemRenderer.h +24 -0
- package/ios/renderer/ListItemRenderer.m +283 -0
- package/ios/renderer/ListRenderer.h +13 -0
- package/ios/renderer/ListRenderer.m +126 -0
- package/ios/renderer/MentionRenderer.h +9 -0
- package/ios/renderer/MentionRenderer.m +96 -0
- package/ios/renderer/NodeRenderer.h +8 -0
- package/ios/renderer/ParagraphRenderer.h +6 -0
- package/ios/renderer/ParagraphRenderer.m +85 -0
- package/ios/renderer/RenderContext.h +145 -0
- package/ios/renderer/RenderContext.m +403 -0
- package/ios/renderer/RendererFactory.h +12 -0
- package/ios/renderer/RendererFactory.m +158 -0
- package/ios/renderer/StrikethroughRenderer.h +5 -0
- package/ios/renderer/StrikethroughRenderer.m +30 -0
- package/ios/renderer/StrongRenderer.h +5 -0
- package/ios/renderer/StrongRenderer.m +88 -0
- package/ios/renderer/TextRenderer.h +6 -0
- package/ios/renderer/TextRenderer.m +18 -0
- package/ios/renderer/ThematicBreakRenderer.h +4 -0
- package/ios/renderer/ThematicBreakRenderer.m +42 -0
- package/ios/renderer/UnderlineRenderer.h +4 -0
- package/ios/renderer/UnderlineRenderer.m +41 -0
- package/ios/styles/ENRMFontSlot.h +12 -0
- package/ios/styles/ENRMFontSlot.m +24 -0
- package/ios/styles/StyleConfig.h +488 -0
- package/ios/styles/StyleConfig.mm +2820 -0
- package/ios/utils/AccessibilityInfo.h +35 -0
- package/ios/utils/AccessibilityInfo.m +24 -0
- package/ios/utils/BlockquoteBorder.h +26 -0
- package/ios/utils/BlockquoteBorder.m +294 -0
- package/ios/utils/CodeBackground.h +19 -0
- package/ios/utils/CodeBackground.m +197 -0
- package/ios/utils/CodeBlockBackground.h +17 -0
- package/ios/utils/CodeBlockBackground.m +103 -0
- package/ios/utils/ContextMenuUtils.h +76 -0
- package/ios/utils/ContextMenuUtils.mm +75 -0
- package/ios/utils/ENRMAccessibilityLabels.h +40 -0
- package/ios/utils/ENRMAccessibilityLabels.m +5 -0
- package/ios/utils/ENRMAsyncRenderCoordinator.h +24 -0
- package/ios/utils/ENRMAsyncRenderCoordinator.m +37 -0
- package/ios/utils/ENRMAtomicSize.h +65 -0
- package/ios/utils/ENRMCodeBlockContent.h +37 -0
- package/ios/utils/ENRMCodeBlockContent.mm +89 -0
- package/ios/utils/ENRMFeatureFlags.h +25 -0
- package/ios/utils/ENRMImageDownloader.h +30 -0
- package/ios/utils/ENRMImageDownloader.m +168 -0
- package/ios/utils/ENRMLatexErrorCoordinator.h +27 -0
- package/ios/utils/ENRMLatexErrorCoordinator.mm +75 -0
- package/ios/utils/ENRMLatexErrorReporting.h +13 -0
- package/ios/utils/ENRMLinkContextMenus.h +93 -0
- package/ios/utils/ENRMLinkContextMenus.m +178 -0
- package/ios/utils/ENRMLinkRegexConfig.h +30 -0
- package/ios/utils/ENRMLinkRegexConfig.mm +104 -0
- package/ios/utils/ENRMLinkRegexProps.h +23 -0
- package/ios/utils/ENRMLocalImageLoader.h +35 -0
- package/ios/utils/ENRMLocalImageLoader.m +111 -0
- package/ios/utils/ENRMMenuAction.h +27 -0
- package/ios/utils/ENRMMenuAction.m +33 -0
- package/ios/utils/ENRMSpoilerOverlayManager.h +15 -0
- package/ios/utils/ENRMSpoilerOverlayManager.m +19 -0
- package/ios/utils/ENRMSpoilerTapUtils.h +6 -0
- package/ios/utils/ENRMSpoilerTapUtils.m +11 -0
- package/ios/utils/ENRMTailFadeInAnimator.h +16 -0
- package/ios/utils/ENRMTailFadeInAnimator.m +161 -0
- package/ios/utils/ENRMTextHitTest.h +23 -0
- package/ios/utils/ENRMTextHitTest.m +20 -0
- package/ios/utils/ENRMTextInteractionUtils.h +20 -0
- package/ios/utils/ENRMTextInteractionUtils.m +15 -0
- package/ios/utils/ENRMTextRenderer.h +38 -0
- package/ios/utils/ENRMTextRenderer.m +54 -0
- package/ios/utils/ENRMTextViewSetup.h +132 -0
- package/ios/utils/ENRMUIKit.h +429 -0
- package/ios/utils/EditMenuUtils.h +105 -0
- package/ios/utils/EditMenuUtils.m +143 -0
- package/ios/utils/FactoidBackground.h +20 -0
- package/ios/utils/FactoidBackground.m +161 -0
- package/ios/utils/FontScaleObserver.h +10 -0
- package/ios/utils/FontScaleObserver.m +55 -0
- package/ios/utils/FontUtils.h +31 -0
- package/ios/utils/FontUtils.m +63 -0
- package/ios/utils/HTMLGenerator.h +25 -0
- package/ios/utils/HTMLGenerator.m +1041 -0
- package/ios/utils/HeightUpdateUtils.h +25 -0
- package/ios/utils/ImageRequestHeaderUtils.h +35 -0
- package/ios/utils/LastElementUtils.h +97 -0
- package/ios/utils/LinkContextMenuUtils.h +55 -0
- package/ios/utils/LinkPillContentUtils.h +46 -0
- package/ios/utils/LinkTapUtils.h +56 -0
- package/ios/utils/LinkTapUtils.m +139 -0
- package/ios/utils/ListMarkerDrawer.h +15 -0
- package/ios/utils/ListMarkerDrawer.m +239 -0
- package/ios/utils/MentionBackground.h +26 -0
- package/ios/utils/MentionBackground.m +86 -0
- package/ios/utils/ParagraphStyleUtils.h +87 -0
- package/ios/utils/ParagraphStyleUtils.m +484 -0
- package/ios/utils/PasteboardUtils.h +48 -0
- package/ios/utils/PasteboardUtils.m +166 -0
- package/ios/utils/RTFExportUtils.h +24 -0
- package/ios/utils/RTFExportUtils.m +299 -0
- package/ios/utils/RuntimeKeys.h +44 -0
- package/ios/utils/RuntimeKeys.m +13 -0
- package/ios/utils/SelectionColorUtils.h +14 -0
- package/ios/utils/StylePropsUtils.h +1340 -0
- package/ios/utils/TaskListTapUtils.h +6 -0
- package/ios/utils/TaskListTapUtils.m +14 -0
- package/ios/utils/TextViewLayoutManager.h +14 -0
- package/ios/utils/TextViewLayoutManager.mm +198 -0
- package/ios/utils/TiptapAccessibilityElementBuilder.h +43 -0
- package/ios/utils/TiptapAccessibilityElementBuilder.m +432 -0
- package/ios/utils/TiptapExtractor.h +17 -0
- package/ios/utils/TiptapExtractor.m +367 -0
- package/ios/views/ENRMTiptapTextView.h +25 -0
- package/ios/views/ENRMTiptapTextView.m +247 -0
- package/package.json +70 -6
- package/react-native.config.js +10 -0
- package/src/EnrichedTiptapTextNativeComponent.ts +739 -0
- package/src/RichText.tsx +164 -0
- package/src/admonitionDefaults.ts +58 -0
- package/src/darkModeTextStyle.ts +99 -0
- package/src/headingDefaults.ts +21 -0
- package/src/index.tsx +4 -0
- package/src/linkVariantUtils.ts +120 -0
- package/src/normalizeTiptapStyle.ts +397 -0
- package/src/rn-globals.d.ts +1 -0
- package/src/styleUtils.ts +107 -0
- package/src/types/TiptapStyle.ts +532 -0
- package/src/types/TiptapStyleInternal.ts +299 -0
- package/src/types/linkPill.ts +9 -0
- package/src/utils/isDev.ts +4 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
#import "CodeBlockBackground.h"
|
|
2
|
+
#import "ENRMUIKit.h"
|
|
3
|
+
#import "LastElementUtils.h"
|
|
4
|
+
#import "StyleConfig.h"
|
|
5
|
+
|
|
6
|
+
// Draws the commonmark-flavor code block box behind the text view's glyph
|
|
7
|
+
// runs. The visual conventions (half-stroke border inset, corner radius
|
|
8
|
+
// handling) must stay in sync with the whole-rect box the github flavor
|
|
9
|
+
// draws in ENRMCodeBlockContainerView's drawRect:.
|
|
10
|
+
|
|
11
|
+
@implementation CodeBlockBackground {
|
|
12
|
+
StyleConfig *_config;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
- (instancetype)initWithConfig:(StyleConfig *)config
|
|
16
|
+
{
|
|
17
|
+
if (self = [super init]) {
|
|
18
|
+
_config = config;
|
|
19
|
+
}
|
|
20
|
+
return self;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
- (void)drawBackgroundsForGlyphRange:(NSRange)glyphsToShow
|
|
24
|
+
layoutManager:(NSLayoutManager *)layoutManager
|
|
25
|
+
textContainer:(NSTextContainer *)textContainer
|
|
26
|
+
atPoint:(CGPoint)origin
|
|
27
|
+
{
|
|
28
|
+
NSTextStorage *textStorage = layoutManager.textStorage;
|
|
29
|
+
NSRange charRange = [layoutManager characterRangeForGlyphRange:glyphsToShow actualGlyphRange:NULL];
|
|
30
|
+
|
|
31
|
+
// Enumerate over the full storage range so each code block's full rect is drawn.
|
|
32
|
+
// Restricting to charRange causes partial rects per draw pass, which produces
|
|
33
|
+
// multiple stacked oval shapes when border radius is large.
|
|
34
|
+
// The graphics context clip ensures only the visible portion is painted.
|
|
35
|
+
[textStorage enumerateAttribute:CodeBlockAttributeName
|
|
36
|
+
inRange:NSMakeRange(0, textStorage.length)
|
|
37
|
+
options:0
|
|
38
|
+
usingBlock:^(id value, NSRange range, BOOL *stop) {
|
|
39
|
+
if (!value)
|
|
40
|
+
return;
|
|
41
|
+
if (NSIntersectionRange(range, charRange).length == 0)
|
|
42
|
+
return;
|
|
43
|
+
[self drawCodeBlockBackgroundForRange:range
|
|
44
|
+
layoutManager:layoutManager
|
|
45
|
+
textContainer:textContainer
|
|
46
|
+
atPoint:origin];
|
|
47
|
+
}];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
- (void)drawCodeBlockBackgroundForRange:(NSRange)range
|
|
51
|
+
layoutManager:(NSLayoutManager *)layoutManager
|
|
52
|
+
textContainer:(NSTextContainer *)textContainer
|
|
53
|
+
atPoint:(CGPoint)origin
|
|
54
|
+
{
|
|
55
|
+
NSRange glyphRange = [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:NULL];
|
|
56
|
+
CGRect blockRect = [layoutManager boundingRectForGlyphRange:glyphRange inTextContainer:textContainer];
|
|
57
|
+
|
|
58
|
+
if (CGRectIsEmpty(blockRect))
|
|
59
|
+
return;
|
|
60
|
+
|
|
61
|
+
NSNumber *indentAttr = [layoutManager.textStorage attribute:CodeBlockIndentAttributeName
|
|
62
|
+
atIndex:range.location
|
|
63
|
+
effectiveRange:NULL];
|
|
64
|
+
CGFloat indent = [indentAttr doubleValue];
|
|
65
|
+
|
|
66
|
+
CGFloat availableWidth = textContainer.size.width - indent;
|
|
67
|
+
if (availableWidth <= 0)
|
|
68
|
+
return;
|
|
69
|
+
|
|
70
|
+
blockRect.origin.x = origin.x + indent;
|
|
71
|
+
blockRect.origin.y += origin.y;
|
|
72
|
+
blockRect.size.width = availableWidth;
|
|
73
|
+
|
|
74
|
+
// We extend the background specifically to cover the bottom padding spacer,
|
|
75
|
+
// excluding any additional marginBottom applied via measurement.
|
|
76
|
+
BOOL isLastCodeBlock = (NSMaxRange(range) == layoutManager.textStorage.length);
|
|
77
|
+
if (isLastCodeBlock) {
|
|
78
|
+
blockRect.size.height += [_config codeBlockPadding];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
CGFloat borderWidth = [_config codeBlockBorderWidth];
|
|
82
|
+
CGFloat borderRadius = [_config codeBlockBorderRadius];
|
|
83
|
+
CGFloat inset = borderWidth / 2.0;
|
|
84
|
+
|
|
85
|
+
CGRect insetRect = CGRectInset(blockRect, inset, inset);
|
|
86
|
+
UIBezierPath *path = UIBezierPathWithRoundedRect(insetRect, MAX(0, borderRadius - inset));
|
|
87
|
+
|
|
88
|
+
CGContextRef ctx = UIGraphicsGetCurrentContext();
|
|
89
|
+
CGContextSaveGState(ctx);
|
|
90
|
+
{
|
|
91
|
+
[[_config codeBlockBackgroundColor] setFill];
|
|
92
|
+
[path fill];
|
|
93
|
+
|
|
94
|
+
if (borderWidth > 0) {
|
|
95
|
+
[[_config codeBlockBorderColor] setStroke];
|
|
96
|
+
path.lineWidth = borderWidth;
|
|
97
|
+
BezierPathSetRoundStyle(path);
|
|
98
|
+
[path stroke];
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
CGContextRestoreGState(ctx);
|
|
102
|
+
}
|
|
103
|
+
@end
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#import "ENRMUIKit.h"
|
|
4
|
+
#import <Foundation/Foundation.h>
|
|
5
|
+
|
|
6
|
+
#ifdef __cplusplus
|
|
7
|
+
#include <string>
|
|
8
|
+
#include <vector>
|
|
9
|
+
|
|
10
|
+
template <typename T>
|
|
11
|
+
static bool ENRMContextMenuItemsChanged(const std::vector<T> &oldItems, const std::vector<T> &newItems)
|
|
12
|
+
{
|
|
13
|
+
if (newItems.size() != oldItems.size()) {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
for (size_t i = 0; i < newItems.size(); i++) {
|
|
17
|
+
if (newItems[i].text != oldItems[i].text || newItems[i].icon != oldItems[i].icon) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
template <typename T> static NSArray<NSString *> *ENRMContextMenuTextsFromItems(const std::vector<T> &items)
|
|
25
|
+
{
|
|
26
|
+
NSMutableArray<NSString *> *result = [NSMutableArray new];
|
|
27
|
+
for (const auto &item : items) {
|
|
28
|
+
[result addObject:[NSString stringWithUTF8String:item.text.c_str()]];
|
|
29
|
+
}
|
|
30
|
+
return [result copy];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
template <typename T> static NSArray<NSString *> *_Nullable ENRMContextMenuIconsFromItems(const std::vector<T> &items)
|
|
34
|
+
{
|
|
35
|
+
NSMutableArray<NSString *> *result = [NSMutableArray arrayWithCapacity:items.size()];
|
|
36
|
+
bool hasAnyIcon = false;
|
|
37
|
+
for (const auto &item : items) {
|
|
38
|
+
NSString *iconName = @(item.icon.c_str());
|
|
39
|
+
hasAnyIcon = hasAnyIcon || iconName.length > 0;
|
|
40
|
+
[result addObject:iconName];
|
|
41
|
+
}
|
|
42
|
+
return hasAnyIcon ? [result copy] : nil;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
#endif
|
|
46
|
+
|
|
47
|
+
typedef void (^ENRMContextMenuPressHandler)(NSString *_Nonnull itemText, NSString *_Nonnull selectedText,
|
|
48
|
+
NSUInteger selectionStart, NSUInteger selectionEnd);
|
|
49
|
+
|
|
50
|
+
#ifdef __cplusplus
|
|
51
|
+
extern "C" {
|
|
52
|
+
#endif
|
|
53
|
+
|
|
54
|
+
#if !TARGET_OS_OSX
|
|
55
|
+
|
|
56
|
+
// TODO: Remove API_AVAILABLE(ios(16.0)) guard when the minimum iOS deployment target in RN is bumped to 16.
|
|
57
|
+
NSMutableArray<UIAction *> *_Nullable ENRMBuildContextMenuActions(NSArray<NSString *> *_Nonnull itemTexts,
|
|
58
|
+
NSArray<NSString *> *_Nullable iconNames,
|
|
59
|
+
UITextView *_Nonnull textView, NSRange selectedRange,
|
|
60
|
+
ENRMContextMenuPressHandler _Nonnull handler)
|
|
61
|
+
API_AVAILABLE(ios(16.0));
|
|
62
|
+
|
|
63
|
+
#else
|
|
64
|
+
|
|
65
|
+
NSArray<NSMenuItem *> *_Nullable ENRMBuildContextMenuItems(NSArray<NSString *> *_Nonnull itemTexts,
|
|
66
|
+
NSArray<NSString *> *_Nullable iconNames,
|
|
67
|
+
NSTextView *_Nonnull textView,
|
|
68
|
+
ENRMContextMenuPressHandler _Nonnull handler);
|
|
69
|
+
|
|
70
|
+
void ENRMPrependMenuItems(NSMenu *_Nonnull menu, NSArray<NSMenuItem *> *_Nullable items);
|
|
71
|
+
|
|
72
|
+
#endif
|
|
73
|
+
|
|
74
|
+
#ifdef __cplusplus
|
|
75
|
+
}
|
|
76
|
+
#endif
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
#import "ContextMenuUtils.h"
|
|
2
|
+
#import "ENRMLinkPillText.h"
|
|
3
|
+
#import "ENRMMenuAction.h"
|
|
4
|
+
|
|
5
|
+
#if !TARGET_OS_OSX
|
|
6
|
+
|
|
7
|
+
// TODO: Remove API_AVAILABLE(ios(16.0)) guard when the minimum iOS deployment target in RN is bumped to 16.
|
|
8
|
+
NSMutableArray<UIAction *> *_Nullable ENRMBuildContextMenuActions(NSArray<NSString *> *itemTexts,
|
|
9
|
+
NSArray<NSString *> *_Nullable iconNames,
|
|
10
|
+
UITextView *textView, NSRange selectedRange,
|
|
11
|
+
ENRMContextMenuPressHandler handler)
|
|
12
|
+
API_AVAILABLE(ios(16.0))
|
|
13
|
+
{
|
|
14
|
+
if (itemTexts.count == 0) {
|
|
15
|
+
return nil;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
NSString *selectedText =
|
|
19
|
+
ENRMStringByExpandingLinkPills([textView.textStorage attributedSubstringFromRange:selectedRange]);
|
|
20
|
+
NSUInteger selectionStart = selectedRange.location;
|
|
21
|
+
NSUInteger selectionEnd = NSMaxRange(selectedRange);
|
|
22
|
+
|
|
23
|
+
NSMutableArray<UIAction *> *actions = [NSMutableArray arrayWithCapacity:itemTexts.count];
|
|
24
|
+
[itemTexts enumerateObjectsUsingBlock:^(NSString *itemText, NSUInteger index, BOOL *_) {
|
|
25
|
+
NSString *iconName = iconNames ? iconNames[index] : nil;
|
|
26
|
+
UIImage *image = iconName.length > 0 ? [UIImage systemImageNamed:iconName] : nil;
|
|
27
|
+
[actions addObject:[UIAction actionWithTitle:itemText
|
|
28
|
+
image:image
|
|
29
|
+
identifier:nil
|
|
30
|
+
handler:^(__kindof UIAction *_) {
|
|
31
|
+
handler(itemText, selectedText, selectionStart, selectionEnd);
|
|
32
|
+
}]];
|
|
33
|
+
}];
|
|
34
|
+
return actions;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
#else
|
|
38
|
+
|
|
39
|
+
NSArray<NSMenuItem *> *_Nullable ENRMBuildContextMenuItems(NSArray<NSString *> *itemTexts,
|
|
40
|
+
NSArray<NSString *> *_Nullable iconNames,
|
|
41
|
+
NSTextView *textView, ENRMContextMenuPressHandler handler)
|
|
42
|
+
{
|
|
43
|
+
if (itemTexts.count == 0) {
|
|
44
|
+
return nil;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
NSRange selectedRange = textView.selectedRange;
|
|
48
|
+
NSString *selectedText = [textView.string substringWithRange:selectedRange];
|
|
49
|
+
NSUInteger selectionStart = selectedRange.location;
|
|
50
|
+
NSUInteger selectionEnd = NSMaxRange(selectedRange);
|
|
51
|
+
|
|
52
|
+
NSMutableArray<NSMenuItem *> *items = [NSMutableArray arrayWithCapacity:itemTexts.count];
|
|
53
|
+
[itemTexts enumerateObjectsUsingBlock:^(NSString *itemText, NSUInteger index, BOOL *_) {
|
|
54
|
+
NSMenuItem *item =
|
|
55
|
+
ENRMCreateMenuItem(itemText, ^{ handler(itemText, selectedText, selectionStart, selectionEnd); });
|
|
56
|
+
NSString *iconName = iconNames ? iconNames[index] : nil;
|
|
57
|
+
if (iconName.length > 0) {
|
|
58
|
+
item.image = [NSImage imageWithSystemSymbolName:iconName accessibilityDescription:nil];
|
|
59
|
+
}
|
|
60
|
+
[items addObject:item];
|
|
61
|
+
}];
|
|
62
|
+
return items;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
void ENRMPrependMenuItems(NSMenu *menu, NSArray<NSMenuItem *> *items)
|
|
66
|
+
{
|
|
67
|
+
if (items.count == 0) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
[menu insertItem:[NSMenuItem separatorItem] atIndex:0];
|
|
71
|
+
[items enumerateObjectsWithOptions:NSEnumerationReverse
|
|
72
|
+
usingBlock:^(NSMenuItem *item, NSUInteger _, BOOL *__) { [menu insertItem:item atIndex:0]; }];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
#endif
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#import <Foundation/Foundation.h>
|
|
2
|
+
|
|
3
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
4
|
+
|
|
5
|
+
@interface ENRMAccessibilityLabels : NSObject
|
|
6
|
+
|
|
7
|
+
@property (nonatomic, copy) NSString *bulletPoint;
|
|
8
|
+
@property (nonatomic, copy) NSString *nestedBulletPoint;
|
|
9
|
+
@property (nonatomic, copy) NSString *orderedItem;
|
|
10
|
+
@property (nonatomic, copy) NSString *nestedOrderedItem;
|
|
11
|
+
@property (nonatomic, copy) NSString *blockquote;
|
|
12
|
+
@property (nonatomic, copy) NSString *nestedBlockquote;
|
|
13
|
+
@property (nonatomic, copy) NSString *tableRow;
|
|
14
|
+
@property (nonatomic, copy) NSString *mathEquation;
|
|
15
|
+
@property (nonatomic, copy) NSString *codeBlockWrap;
|
|
16
|
+
@property (nonatomic, copy) NSString *codeBlockUnwrap;
|
|
17
|
+
@property (nonatomic, copy) NSString *rotorHeadings;
|
|
18
|
+
@property (nonatomic, copy) NSString *rotorLinks;
|
|
19
|
+
@property (nonatomic, copy) NSString *rotorImages;
|
|
20
|
+
|
|
21
|
+
@end
|
|
22
|
+
|
|
23
|
+
NS_ASSUME_NONNULL_END
|
|
24
|
+
|
|
25
|
+
#ifdef __cplusplus
|
|
26
|
+
template <typename T> static bool ENRMAccessibilityLabelsChanged(const T &oldLabels, const T &newLabels)
|
|
27
|
+
{
|
|
28
|
+
return oldLabels.list.bulletPoint != newLabels.list.bulletPoint ||
|
|
29
|
+
oldLabels.list.nestedBulletPoint != newLabels.list.nestedBulletPoint ||
|
|
30
|
+
oldLabels.list.orderedItem != newLabels.list.orderedItem ||
|
|
31
|
+
oldLabels.list.nestedOrderedItem != newLabels.list.nestedOrderedItem ||
|
|
32
|
+
oldLabels.blockquote.quote != newLabels.blockquote.quote ||
|
|
33
|
+
oldLabels.blockquote.nestedQuote != newLabels.blockquote.nestedQuote ||
|
|
34
|
+
oldLabels.table.row != newLabels.table.row || oldLabels.math.equation != newLabels.math.equation ||
|
|
35
|
+
oldLabels.codeBlock.wrap != newLabels.codeBlock.wrap ||
|
|
36
|
+
oldLabels.codeBlock.unwrap != newLabels.codeBlock.unwrap ||
|
|
37
|
+
oldLabels.rotor.headings != newLabels.rotor.headings || oldLabels.rotor.links != newLabels.rotor.links ||
|
|
38
|
+
oldLabels.rotor.images != newLabels.rotor.images;
|
|
39
|
+
}
|
|
40
|
+
#endif
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
#import <Foundation/Foundation.h>
|
|
3
|
+
|
|
4
|
+
/// Owns the serial render queue and render-ID counter used by async render pipelines.
|
|
5
|
+
/// Handles stale-result cancellation and main-thread dispatch automatically.
|
|
6
|
+
/// Set blockAsyncRender = YES before synchronous rendering to suppress queued dispatches.
|
|
7
|
+
@interface ENRMAsyncRenderCoordinator : NSObject
|
|
8
|
+
|
|
9
|
+
@property (nonatomic) BOOL blockAsyncRender;
|
|
10
|
+
|
|
11
|
+
- (instancetype)initWithQueueLabel:(const char *)label NS_DESIGNATED_INITIALIZER;
|
|
12
|
+
- (instancetype)init NS_UNAVAILABLE;
|
|
13
|
+
|
|
14
|
+
/// Dispatches renderBlock on the serial queue.
|
|
15
|
+
/// If renderBlock returns YES, applyBlock is dispatched on the main queue,
|
|
16
|
+
/// provided the render ID has not been superseded by a newer call.
|
|
17
|
+
- (void)scheduleRender:(BOOL (^)(void))renderBlock apply:(dispatch_block_t)applyBlock;
|
|
18
|
+
|
|
19
|
+
/// Advances the render ID so any in-flight render's apply block is discarded
|
|
20
|
+
/// by the renderId == currentRenderId check when it lands on the main queue.
|
|
21
|
+
/// Use before recycling or otherwise resetting a host that owns this coordinator.
|
|
22
|
+
- (void)invalidate;
|
|
23
|
+
|
|
24
|
+
@end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#import "ENRMAsyncRenderCoordinator.h"
|
|
2
|
+
|
|
3
|
+
@implementation ENRMAsyncRenderCoordinator {
|
|
4
|
+
dispatch_queue_t _queue;
|
|
5
|
+
NSUInteger _currentRenderId;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
- (instancetype)initWithQueueLabel:(const char *)label
|
|
9
|
+
{
|
|
10
|
+
if (self = [super init]) {
|
|
11
|
+
_queue = dispatch_queue_create(label, DISPATCH_QUEUE_SERIAL);
|
|
12
|
+
}
|
|
13
|
+
return self;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
- (void)scheduleRender:(BOOL (^)(void))renderBlock apply:(dispatch_block_t)applyBlock
|
|
17
|
+
{
|
|
18
|
+
if (_blockAsyncRender)
|
|
19
|
+
return;
|
|
20
|
+
NSUInteger renderId = ++_currentRenderId;
|
|
21
|
+
dispatch_async(_queue, ^{
|
|
22
|
+
if (!renderBlock())
|
|
23
|
+
return;
|
|
24
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
25
|
+
if (renderId == self->_currentRenderId) {
|
|
26
|
+
applyBlock();
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
- (void)invalidate
|
|
33
|
+
{
|
|
34
|
+
++_currentRenderId;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@end
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <CoreGraphics/CGGeometry.h>
|
|
4
|
+
#include <atomic>
|
|
5
|
+
#include <cstdint>
|
|
6
|
+
#include <cstring>
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Lock-free size mailbox (issue #550).
|
|
10
|
+
*
|
|
11
|
+
* `measureContent` may run on the JS/layout thread while React Native holds
|
|
12
|
+
* the ShadowTree revision mutex (`preventShadowTreeCommitExhaustion` re-runs
|
|
13
|
+
* the entire commit — layout included — under `revisionMutexRecursive_` after
|
|
14
|
+
* three failed optimistic commits). A main-thread committer (e.g. Reanimated)
|
|
15
|
+
* can already be blocked on that same mutex, so any `dispatch_sync` to main
|
|
16
|
+
* from the measure path can deadlock: JS waits for main, main waits for the
|
|
17
|
+
* mutex JS holds. iOS kills the frozen app ~60s later (watchdog 0x8BADF00D).
|
|
18
|
+
*
|
|
19
|
+
* Reading `view.bounds` from a background thread is not safe either, so the
|
|
20
|
+
* component view *publishes* its last committed size here (from
|
|
21
|
+
* `updateLayoutMetrics:`, always on main) and the measure path *loads* it
|
|
22
|
+
* wait-free from any thread.
|
|
23
|
+
*
|
|
24
|
+
* Both dimensions are packed as IEEE-754 floats into one `uint64_t` so a
|
|
25
|
+
* single lock-free atomic covers the pair — a reader can never observe a new
|
|
26
|
+
* width with an old height (no torn reads). Relaxed memory ordering suffices:
|
|
27
|
+
* the value is self-contained and no other memory is published through it.
|
|
28
|
+
*/
|
|
29
|
+
class ENRMAtomicSize {
|
|
30
|
+
public:
|
|
31
|
+
void store(CGSize size)
|
|
32
|
+
{
|
|
33
|
+
bits_.store(pack(size), std::memory_order_relaxed);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
CGSize load() const
|
|
37
|
+
{
|
|
38
|
+
return unpack(bits_.load(std::memory_order_relaxed));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
private:
|
|
42
|
+
static uint64_t pack(CGSize size)
|
|
43
|
+
{
|
|
44
|
+
float width = (float)size.width;
|
|
45
|
+
float height = (float)size.height;
|
|
46
|
+
uint32_t widthBits;
|
|
47
|
+
uint32_t heightBits;
|
|
48
|
+
memcpy(&widthBits, &width, sizeof(widthBits));
|
|
49
|
+
memcpy(&heightBits, &height, sizeof(heightBits));
|
|
50
|
+
return ((uint64_t)widthBits << 32) | heightBits;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
static CGSize unpack(uint64_t bits)
|
|
54
|
+
{
|
|
55
|
+
uint32_t widthBits = (uint32_t)(bits >> 32);
|
|
56
|
+
uint32_t heightBits = (uint32_t)bits;
|
|
57
|
+
float width;
|
|
58
|
+
float height;
|
|
59
|
+
memcpy(&width, &widthBits, sizeof(width));
|
|
60
|
+
memcpy(&height, &heightBits, sizeof(height));
|
|
61
|
+
return CGSizeMake(width, height);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
std::atomic<uint64_t> bits_{0};
|
|
65
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#import <Foundation/Foundation.h>
|
|
4
|
+
|
|
5
|
+
@class TiptapASTNode;
|
|
6
|
+
@class StyleConfig;
|
|
7
|
+
|
|
8
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
9
|
+
|
|
10
|
+
#ifdef __cplusplus
|
|
11
|
+
extern "C" {
|
|
12
|
+
#endif
|
|
13
|
+
|
|
14
|
+
/// Shared code block node semantics, used by both tiptap flavors so the
|
|
15
|
+
/// meaning of a CodeBlock AST node (its text, language, fence) is defined in
|
|
16
|
+
/// one place. Language display names come from the shared C++ core
|
|
17
|
+
/// (cpp/highlight/CodeBlockLanguages.hpp) so all platforms label fences
|
|
18
|
+
/// identically.
|
|
19
|
+
|
|
20
|
+
NSString *ENRMCodeBlockExtractCode(TiptapASTNode *node);
|
|
21
|
+
NSString *_Nullable ENRMCodeBlockLanguage(TiptapASTNode *node);
|
|
22
|
+
NSString *ENRMCodeBlockFenceChar(TiptapASTNode *node);
|
|
23
|
+
NSString *ENRMCodeBlockFencedTiptap(NSString *code, NSString *_Nullable language, NSString *fenceChar);
|
|
24
|
+
NSString *ENRMCodeBlockDisplayLanguageName(NSString *_Nullable language);
|
|
25
|
+
|
|
26
|
+
/// Applies the flavor-independent code block text attributes (code font,
|
|
27
|
+
/// color, line height, forced-LTR left-aligned paragraph) to the range.
|
|
28
|
+
/// Callers layer their container-specific paragraph adjustments on top (the
|
|
29
|
+
/// commonmark span flavor adds padding indents; the github block view has
|
|
30
|
+
/// none).
|
|
31
|
+
void ENRMApplyCodeBlockTextAttributes(NSMutableAttributedString *string, NSRange range, StyleConfig *config);
|
|
32
|
+
|
|
33
|
+
#ifdef __cplusplus
|
|
34
|
+
}
|
|
35
|
+
#endif
|
|
36
|
+
|
|
37
|
+
NS_ASSUME_NONNULL_END
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
#import "ENRMCodeBlockContent.h"
|
|
2
|
+
#import "ENRMUIKit.h"
|
|
3
|
+
#import "TiptapASTNode.h"
|
|
4
|
+
#import "ParagraphStyleUtils.h"
|
|
5
|
+
#import "StyleConfig.h"
|
|
6
|
+
|
|
7
|
+
static void ENRMAppendNodeContent(TiptapASTNode *node, NSMutableString *output)
|
|
8
|
+
{
|
|
9
|
+
if (node.content.length > 0) {
|
|
10
|
+
[output appendString:node.content];
|
|
11
|
+
}
|
|
12
|
+
for (TiptapASTNode *child in node.children) {
|
|
13
|
+
ENRMAppendNodeContent(child, output);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
NSString *ENRMCodeBlockExtractCode(TiptapASTNode *node)
|
|
18
|
+
{
|
|
19
|
+
NSMutableString *code = [NSMutableString string];
|
|
20
|
+
ENRMAppendNodeContent(node, code);
|
|
21
|
+
NSUInteger end = code.length;
|
|
22
|
+
while (end > 0 && [code characterAtIndex:end - 1] == '\n') {
|
|
23
|
+
end--;
|
|
24
|
+
}
|
|
25
|
+
return [code substringToIndex:end];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
NSString *ENRMCodeBlockLanguage(TiptapASTNode *node)
|
|
29
|
+
{
|
|
30
|
+
NSString *language = node.attributes[@"language"];
|
|
31
|
+
return language.length > 0 ? language : nil;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
NSString *ENRMCodeBlockFenceChar(TiptapASTNode *node)
|
|
35
|
+
{
|
|
36
|
+
NSString *fenceChar = node.attributes[@"fenceChar"];
|
|
37
|
+
return fenceChar.length > 0 ? fenceChar : @"`";
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
NSString *ENRMCodeBlockFencedTiptap(NSString *code, NSString *language, NSString *fenceChar)
|
|
41
|
+
{
|
|
42
|
+
NSString *fence = [@"" stringByPaddingToLength:3 withString:fenceChar startingAtIndex:0];
|
|
43
|
+
return [NSString stringWithFormat:@"%@%@\n%@\n%@", fence, language ?: @"", code, fence];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
NSString *ENRMCodeBlockDisplayLanguageName(NSString *language)
|
|
47
|
+
{
|
|
48
|
+
if (language.length == 0) {
|
|
49
|
+
return @"";
|
|
50
|
+
}
|
|
51
|
+
return language;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
void ENRMApplyCodeBlockTextAttributes(NSMutableAttributedString *string, NSRange range, StyleConfig *config)
|
|
55
|
+
{
|
|
56
|
+
if (range.length == 0) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
UIFont *font = [config codeBlockFont];
|
|
61
|
+
RCTUIColor *color = [config codeBlockColor];
|
|
62
|
+
if (color) {
|
|
63
|
+
[string addAttributes:@{NSFontAttributeName : font, NSForegroundColorAttributeName : color} range:range];
|
|
64
|
+
} else {
|
|
65
|
+
[string addAttribute:NSFontAttributeName value:font range:range];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
CGFloat lineHeight = [config codeBlockLineHeight];
|
|
69
|
+
if (lineHeight > 0) {
|
|
70
|
+
applyLineHeight(string, range, lineHeight);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
NSMutableParagraphStyle *paragraphStyle = [getOrCreateParagraphStyle(string, range.location) mutableCopy];
|
|
74
|
+
paragraphStyle.baseWritingDirection = NSWritingDirectionLeftToRight;
|
|
75
|
+
paragraphStyle.alignment = NSTextAlignmentLeft;
|
|
76
|
+
// Re-clamp: unlike paragraphs, code blocks reserve their height analytically as
|
|
77
|
+
// lineCount * lineHeight (ENRMCodeBlockCodeHeight), so a line must not grow past the
|
|
78
|
+
// configured lineHeight or a tall run (emoji, wide glyph) would overflow and clip the block.
|
|
79
|
+
if (lineHeight > 0) {
|
|
80
|
+
paragraphStyle.maximumLineHeight = lineHeight;
|
|
81
|
+
}
|
|
82
|
+
[string addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:range];
|
|
83
|
+
|
|
84
|
+
if (lineHeight > 0) {
|
|
85
|
+
applyBaselineOffset(string, range);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
ENRMPinLineMetricsToStyledFonts(string, range);
|
|
89
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
// Auto-detect RaTeX availability as a fallback for the podspec flag.
|
|
4
|
+
#if __has_include(<RaTeXFFI/ratex.h>) || __has_include("ReactNativeRenderRichText-Swift.h")
|
|
5
|
+
#if !defined(ENRICHED_TIPTAP_MATH)
|
|
6
|
+
#define ENRICHED_TIPTAP_MATH 1
|
|
7
|
+
#endif
|
|
8
|
+
#endif
|
|
9
|
+
|
|
10
|
+
#if !defined(ENRICHED_TIPTAP_MATH)
|
|
11
|
+
#define ENRICHED_TIPTAP_MATH 0
|
|
12
|
+
#endif
|
|
13
|
+
|
|
14
|
+
// Code-block syntax highlighting is defined purely by the podspec (no external
|
|
15
|
+
// framework to auto-detect, unlike RaTeX). Default off when the podspec did not
|
|
16
|
+
// enable it; the C++ seam then degrades to no tokens.
|
|
17
|
+
#if !defined(ENRICHED_TIPTAP_CODE_HIGHLIGHT)
|
|
18
|
+
#define ENRICHED_TIPTAP_CODE_HIGHLIGHT 0
|
|
19
|
+
#endif
|
|
20
|
+
|
|
21
|
+
// Video playback support. Uses AVKit (built into both iOS and macOS — no
|
|
22
|
+
// external framework), so the flag gates only the container view code itself.
|
|
23
|
+
#if !defined(ENRICHED_TIPTAP_VIDEO)
|
|
24
|
+
#define ENRICHED_TIPTAP_VIDEO 0
|
|
25
|
+
#endif
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
#import "ENRMUIKit.h"
|
|
3
|
+
|
|
4
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
5
|
+
|
|
6
|
+
/// Decoded pixel cost, shared by native image caches.
|
|
7
|
+
FOUNDATION_EXPORT NSUInteger ENRMImageByteCost(RCTUIImage *image);
|
|
8
|
+
|
|
9
|
+
typedef void (^ENRMImageDownloadCompletion)(RCTUIImage *_Nullable image);
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Cache identity for a remote image request. Returns the URL itself when no
|
|
13
|
+
* headers are set; otherwise appends a SHA-256 digest of the sorted header
|
|
14
|
+
* pairs, so the same URL fetched with different headers is cached and
|
|
15
|
+
* deduplicated separately without embedding header values in the key.
|
|
16
|
+
* Header names are compared case-insensitively.
|
|
17
|
+
*/
|
|
18
|
+
NSString *ENRMImageCacheKey(NSString *url, NSDictionary<NSString *, NSString *> *_Nullable headers);
|
|
19
|
+
|
|
20
|
+
@interface ENRMImageDownloader : NSObject
|
|
21
|
+
|
|
22
|
+
+ (instancetype)shared;
|
|
23
|
+
|
|
24
|
+
- (void)downloadURL:(NSString *)url
|
|
25
|
+
headers:(nullable NSDictionary<NSString *, NSString *> *)headers
|
|
26
|
+
completion:(ENRMImageDownloadCompletion)completion;
|
|
27
|
+
|
|
28
|
+
@end
|
|
29
|
+
|
|
30
|
+
NS_ASSUME_NONNULL_END
|