├── .gitignore ├── Dependencies ├── Engine │ ├── Engine │ │ ├── Sources │ │ │ ├── AnyAnimatableData.swift │ │ │ ├── AnyShape.swift │ │ │ ├── AnyView.swift │ │ │ ├── AnyViewModifier.swift │ │ │ ├── ConditionalContent.swift │ │ │ ├── ConditionalLayout.swift │ │ │ ├── ConditionalShape.swift │ │ │ ├── ConditionalView.swift │ │ │ ├── EmptyShape.swift │ │ │ ├── EnvironmentKeyVisitor.swift │ │ │ ├── EnvironmentOrValue.swift │ │ │ ├── EnvironmentValuesVisitor.swift │ │ │ ├── ForEachSubview.swift │ │ │ ├── GraphInputs.swift │ │ │ ├── Group.swift │ │ │ ├── HostingController.swift │ │ │ ├── HostingView.swift │ │ │ ├── LayoutAdapter.swift │ │ │ ├── LayoutBuilder.swift │ │ │ ├── LayoutThatFits.swift │ │ │ ├── MultiViewAdapter.swift │ │ │ ├── MultiViewVisitor.swift │ │ │ ├── Never.swift │ │ │ ├── PreferenceKeyReader.swift │ │ │ ├── PrimitiveView.swift │ │ │ ├── PropertyList.swift │ │ │ ├── SectionView.swift │ │ │ ├── ShapeAdapter.swift │ │ │ ├── ShapeBuilder.swift │ │ │ ├── StateOrBinding.swift │ │ │ ├── StaticCondition.swift │ │ │ ├── StaticConditionalContent.swift │ │ │ ├── StaticConditionalModifier.swift │ │ │ ├── StaticContent.swift │ │ │ ├── StaticModifier.swift │ │ │ ├── StyleContext.swift │ │ │ ├── TraitValueKey.swift │ │ │ ├── UnaryViewAdaptor.swift │ │ │ ├── UpdatePhase.swift │ │ │ ├── UserInterfaceIdiomContent.swift │ │ │ ├── UserInterfaceIdiomModifier.swift │ │ │ ├── VariadicView.swift │ │ │ ├── VersionedDynamicProperty.swift │ │ │ ├── VersionedView.swift │ │ │ ├── VersionedViewInput.swift │ │ │ ├── VersionedViewModifier.swift │ │ │ ├── ViewAdapter.swift │ │ │ ├── ViewAlias.swift │ │ │ ├── ViewInputConditionalContent.swift │ │ │ ├── ViewInputConditionalModifier.swift │ │ │ ├── ViewInputKey.swift │ │ │ ├── ViewInputs.swift │ │ │ ├── ViewInputsVisitor.swift │ │ │ ├── ViewModifierBuilder.swift │ │ │ ├── ViewModifierContent.swift │ │ │ ├── ViewModifierVisitor.swift │ │ │ ├── ViewOutputAlias.swift │ │ │ ├── ViewOutputKey.swift │ │ │ ├── ViewStackAxisReader.swift │ │ │ ├── ViewStyle.swift │ │ │ ├── ViewTraitKey.swift │ │ │ ├── ViewTraitKeyVisitor.swift │ │ │ └── ViewVisitor.swift │ │ └── module.swift │ ├── EngineCore │ │ ├── AnyViewVisitor.swift │ │ ├── CustomViewVisitor.swift │ │ ├── EmptyViewVisitor.swift │ │ ├── EnvironmentKeyVisitor.swift │ │ ├── ForEachVisitor.swift │ │ ├── GroupVisitor.swift │ │ ├── ModifiedContentVisitor.swift │ │ ├── MultiViewVisitor.swift │ │ ├── OptionalVisitor.swift │ │ ├── ProtocolConformance.swift │ │ ├── Runtime.swift │ │ ├── SectionVisitor.swift │ │ ├── TupleViewVisitor.swift │ │ ├── TupleVisitor.swift │ │ ├── TypeDescriptor.swift │ │ ├── TypeIdentifier.swift │ │ ├── TypeMetadata.swift │ │ ├── UnsafePointer.swift │ │ ├── ViewModifierVisitor.swift │ │ ├── ViewTraitKeyVisitor.swift │ │ └── ViewVisitor.swift │ ├── EngineCoreC │ │ ├── include │ │ │ └── visitors.h │ │ └── visitors.c │ ├── EngineMacros │ │ └── StyledView.swift │ └── EngineMacrosCore │ │ ├── EngineMacrosCore.swift │ │ └── StyledViewMacro.swift ├── _SwiftUIZ_Nuke │ ├── AsyncImageTask.swift │ ├── Caching │ │ ├── Cache.swift │ │ ├── DataCache.swift │ │ ├── DataCaching.swift │ │ ├── ImageCache.swift │ │ └── ImageCaching.swift │ ├── Decoding │ │ ├── AssetType.swift │ │ ├── ImageDecoderRegistry.swift │ │ ├── ImageDecoders+Default.swift │ │ ├── ImageDecoders+Empty.swift │ │ └── ImageDecoding.swift │ ├── Encoding │ │ ├── ImageEncoders+Default.swift │ │ ├── ImageEncoders+ImageIO.swift │ │ ├── ImageEncoders.swift │ │ └── ImageEncoding.swift │ ├── ImageContainer.swift │ ├── ImageRequest.swift │ ├── ImageResponse.swift │ ├── ImageTask.swift │ ├── Internal │ │ ├── Atomic.swift │ │ ├── DataPublisher.swift │ │ ├── Extensions.swift │ │ ├── Graphics.swift │ │ ├── ImagePublisher.swift │ │ ├── ImageRequestKeys.swift │ │ ├── LinkedList.swift │ │ ├── Log.swift │ │ ├── Operation.swift │ │ ├── RateLimiter.swift │ │ └── ResumableData.swift │ ├── Loading │ │ ├── DataLoader.swift │ │ └── DataLoading.swift │ ├── Pipeline │ │ ├── ImagePipeline.swift │ │ ├── ImagePipelineCache.swift │ │ ├── ImagePipelineConfiguration.swift │ │ ├── ImagePipelineDelegate.swift │ │ └── ImagePipelineError.swift │ ├── Prefetching │ │ └── ImagePrefetcher.swift │ ├── Processing │ │ ├── ImageDecompression.swift │ │ ├── ImageProcessing.swift │ │ ├── ImageProcessingOptions.swift │ │ ├── ImageProcessors+Anonymous.swift │ │ ├── ImageProcessors+Circle.swift │ │ ├── ImageProcessors+Composition.swift │ │ ├── ImageProcessors+CoreImage.swift │ │ ├── ImageProcessors+GaussianBlur.swift │ │ ├── ImageProcessors+Resize.swift │ │ ├── ImageProcessors+RoundedCorners.swift │ │ └── ImageProcessors.swift │ └── Tasks │ │ ├── AsyncTask.swift │ │ ├── ImagePipelineTask.swift │ │ ├── OperationTask.swift │ │ ├── TaskFetchDecodedImage.swift │ │ ├── TaskFetchOriginalImageData.swift │ │ ├── TaskFetchWithPublisher.swift │ │ ├── TaskLoadData.swift │ │ └── TaskLoadImage.swift ├── _SwiftUIZ_NukeUI │ ├── FetchImage.swift │ ├── Internal.swift │ ├── LazyImage.swift │ ├── LazyImageState.swift │ └── LazyImageView.swift └── cmark-gfm │ ├── arena.c │ ├── autolink.c │ ├── blocks.c │ ├── buffer.c │ ├── case_fold_switch.inc │ ├── cmark.c │ ├── cmark_ctype.c │ ├── commonmark.c │ ├── core-extensions.c │ ├── entities.inc │ ├── ext_scanners.c │ ├── footnotes.c │ ├── houdini_href_e.c │ ├── houdini_html_e.c │ ├── houdini_html_u.c │ ├── html.c │ ├── include │ ├── autolink.h │ ├── buffer.h │ ├── chunk.h │ ├── cmark-gfm-core-extensions.h │ ├── cmark-gfm-extension_api.h │ ├── cmark-gfm-extensions_export.h │ ├── cmark-gfm.h │ ├── cmark-gfm_export.h │ ├── cmark-gfm_version.h │ ├── cmark_ctype.h │ ├── cmark_gfm.h │ ├── config.h │ ├── ext_scanners.h │ ├── footnotes.h │ ├── houdini.h │ ├── html.h │ ├── inlines.h │ ├── iterator.h │ ├── map.h │ ├── node.h │ ├── parser.h │ ├── plugin.h │ ├── references.h │ ├── registry.h │ ├── render.h │ ├── scanners.h │ ├── strikethrough.h │ ├── syntax_extension.h │ ├── table.h │ ├── tagfilter.h │ ├── tasklist.h │ └── utf8.h │ ├── inlines.c │ ├── iterator.c │ ├── latex.c │ ├── linked_list.c │ ├── man.c │ ├── map.c │ ├── node.c │ ├── plaintext.c │ ├── plugin.c │ ├── references.c │ ├── registry.c │ ├── render.c │ ├── scanners.c │ ├── strikethrough.c │ ├── syntax_extension.c │ ├── table.c │ ├── tagfilter.c │ ├── tasklist.c │ ├── utf8.c │ └── xml.c ├── LICENSE ├── Macros ├── Intramodular │ ├── EnvironmentValueMacro.swift │ ├── PreviewMacro.swift │ ├── ViewBodyMacro.swift │ ├── ViewMacro.swift │ ├── _ViewTraitKeyMacro.swift │ └── _ViewTraitValueMacro.swift └── module.swift ├── Miscellaneous ├── Emoji │ ├── Intramodular │ │ ├── Data │ │ │ ├── EmojiDataReader.swift │ │ │ └── GitHubEmojiDataReader.swift │ │ ├── Emoji.Category.swift │ │ ├── Emoji.Descriptor.swift │ │ ├── Emoji.SkinVariation.swift │ │ ├── Emoji.swift │ │ └── EmojiParser.swift │ ├── Resources │ │ ├── emoji-data.json │ │ └── gemoji.json │ └── module.swift └── MarkdownUI │ ├── Extensibility │ ├── AssetImageProvider.swift │ ├── AssetInlineImageProvider.swift │ ├── CodeSyntaxHighlighter.swift │ ├── DefaultImageProvider.swift │ ├── DefaultInlineImageProvider.swift │ ├── ImageProvider.swift │ └── InlineImageProvider.swift │ ├── MarkdownContent.swift │ ├── Parser │ ├── BlockNode+Rewrite.swift │ ├── BlockNode.swift │ ├── HTMLTag.swift │ ├── InlineNode+Collect.swift │ ├── InlineNode+Rewrite.swift │ ├── InlineNode.swift │ ├── MarkdownParser.swift │ └── UnsafeNode.swift │ ├── Renderer │ ├── AttributedStringInlineRenderer.swift │ ├── InlineTextStyles.swift │ └── TextInlineRenderer.swift │ ├── Theme │ ├── BlockStyle │ │ ├── BlockConfiguration.swift │ │ ├── BlockStyle.swift │ │ ├── CodeBlockConfiguration.swift │ │ ├── ListBullet.swift │ │ ├── ListMarkerConfiguration.swift │ │ ├── TableBackgroundStyle.swift │ │ ├── TableBorderStyle.swift │ │ ├── TableCellConfiguration.swift │ │ └── TaskListMarkerConfiguration.swift │ ├── TextStyle │ │ ├── Styles │ │ │ ├── BackgroundColor.swift │ │ │ ├── EmptyTextStyle.swift │ │ │ ├── Font+FontProperties.swift │ │ │ ├── FontCapsVariant.swift │ │ │ ├── FontDigitVariant.swift │ │ │ ├── FontFamily.swift │ │ │ ├── FontFamilyVariant.swift │ │ │ ├── FontProperties.swift │ │ │ ├── FontPropertiesAttribute.swift │ │ │ ├── FontSize.swift │ │ │ ├── FontStyle.swift │ │ │ ├── FontWeight.swift │ │ │ ├── ForegroundColor.swift │ │ │ ├── StrikethroughStyle.swift │ │ │ ├── TextKerning.swift │ │ │ ├── TextTracking.swift │ │ │ └── UnderlineStyle.swift │ │ ├── TextStyle.swift │ │ └── TextStyleBuilder.swift │ ├── Theme+Basic.swift │ ├── Theme+DocC.swift │ ├── Theme+GitHub.swift │ └── Theme.swift │ ├── Utility │ ├── BlockNode+ColorSchemeImage.swift │ ├── Color+RGBA.swift │ ├── FlowLayout.swift │ ├── InlineNode+PlainText.swift │ ├── InlineNode+RawImageData.swift │ ├── Int+Roman.swift │ ├── RelativeSize.swift │ ├── ResizeToFit.swift │ └── String+KebabCase.swift │ └── Views │ ├── Blocks │ ├── BlockMargin+SwiftUIZ.swift │ ├── BlockMargin.swift │ ├── BlockSequence.swift │ ├── BlockquoteView.swift │ ├── BulletedListView.swift │ ├── CodeBlockView.swift │ ├── ColumnWidthPreference.swift │ ├── HeadingView.swift │ ├── ImageFlow.swift │ ├── ListItemSequence.swift │ ├── ListItemView.swift │ ├── NumberedListView.swift │ ├── ParagraphView.swift │ ├── TableBackgroundView.swift │ ├── TableBorderSelector.swift │ ├── TableBorderView.swift │ ├── TableBounds.swift │ ├── TableCell.swift │ ├── TableView.swift │ ├── TaskListItemView.swift │ ├── TaskListView.swift │ ├── TextStyleAttributesReader.swift │ └── ThematicBreakView.swift │ ├── Environment │ ├── Environment+BaseURL.swift │ ├── Environment+CodeSyntaxHighlighter.swift │ ├── Environment+ImageProvider.swift │ ├── Environment+InlineImageProvider.swift │ ├── Environment+List.swift │ ├── Environment+Table.swift │ ├── Environment+TextStyle.swift │ └── Environment+Theme.swift │ ├── Inlines │ ├── ImageView.swift │ └── InlineText.swift │ └── Markdown.swift ├── Package.resolved ├── Package.swift ├── README.md └── Sources ├── SwiftUIZ ├── macros.swift └── module.swift ├── _SwiftUIZ_A ├── Intermodular │ ├── Extensions │ │ └── AppKit or UIKit │ │ │ └── AppKitOrUIKitImage++.swift │ └── Helpers │ │ └── Foundation │ │ └── _NSKeyValueObservedKeyPath.swift ├── Intramodular (WIP) │ ├── View Hypergraph │ │ ├── _AnyViewHypergraph.InterposeProtocol.swift │ │ ├── _AnyViewHypergraph.Symbol.swift │ │ ├── _AnyViewHypergraph.swift │ │ ├── _PGElementID.swift │ │ ├── _PropertyGraph.Consumable.swift │ │ ├── _ViewHypergraphElement.swift │ │ ├── _ViewHypergraphPass.swift │ │ └── _ViewPrototypeID.swift │ └── View Interposing │ │ ├── EnvironmentValues+_InterposeGraphContext.swift │ │ ├── _InterposeSceneContent.swift │ │ ├── _InterposedViewBodyBridge.swift │ │ ├── _InterposedViewBodyStorage.swift │ │ ├── _ViewInterposeError.swift │ │ └── _ViewInterposeScope.swift ├── Intramodular │ ├── Bindings │ │ └── _TypeCastBinding.swift │ ├── Containers │ │ ├── ContainerGroup.swift │ │ └── ControlBox.swift │ ├── Diagnostics │ │ └── _PrintMirrorView.swift │ ├── Dynamic Properties │ │ ├── _ConstantOrBinding.swift │ │ ├── _ConstantOrStateOrBinding.swift │ │ ├── _LazyState.swift │ │ ├── _PublishedConstantOrBinding.swift │ │ ├── _SwiftUIX_BindingType.swift │ │ ├── _SwiftUIZ_DynamicProperty.swift │ │ ├── _UpdatePhase.swift │ │ └── _WithBufferedBinding.swift │ ├── Dynamic Replacement │ │ └── _DynamicReplacementManager.swift │ ├── Event Management │ │ └── _EventModifiersMonitor.swift │ ├── Focus Management │ │ ├── View._focusRingVisibility.swift │ │ ├── _FocusOnAppear.swift │ │ ├── _FocusRingDrawing.swift │ │ ├── _FocusableViewConfiguration.swift │ │ ├── _FocusableViewReader.swift │ │ ├── _ListSelectionBindingController.swift │ │ ├── _SwiftUIX_FocusInteractions.swift │ │ └── _SwiftUIX_FocusableRepresentation.swift │ ├── Forms │ │ ├── _DisableFormStyling.swift │ │ └── _SubmitModelAction.swift │ ├── Layout │ │ ├── FrameRelativeValue.swift │ │ ├── Padding.swift │ │ └── _ContainerRelativeFrame.swift │ ├── Miscellaneous │ │ ├── Hierarchical View Bridge │ │ │ ├── _HierarchicalViewBridge.swift │ │ │ ├── _HostViewBridge.swift │ │ │ └── _ViewBridge.swift │ │ ├── InterfaceModel.swift │ │ └── _DynamicView.swift │ ├── Navigation │ │ └── _SelfSizingNavigationStack.swift │ ├── Pasteboard │ │ ├── Pasteboard.swift │ │ └── _SwiftUIX_AnyPasteCommandDelegate.swift │ ├── Preference Keys │ │ ├── _HasPreferenceKey.swift │ │ └── _PreferenceKeyValueReader.swift │ ├── Reflection │ │ ├── SwiftUIIntrospect+.swift │ │ ├── _ReadDetachedView.swift │ │ ├── _StaticViewTypeDescriptor.swift │ │ ├── _StaticViewTypeDescriptorKey.swift │ │ └── _VariadicViewChildren.SubviewTraitPair.swift │ ├── Scenes │ │ ├── DocumentEditor.swift │ │ ├── NavigationDetailGroup.swift │ │ ├── PresentationGroup.swift │ │ ├── _DonateDynamicSceneInitializer.swift │ │ ├── _DynamicScene.swift │ │ ├── _DynamicSceneInitializer.swift │ │ ├── _DynamicSceneManager.swift │ │ ├── _InitializeSceneContent.swift │ │ ├── _InterposedSceneContent.swift │ │ ├── _RuntimeDiscoveredScenes.swift │ │ ├── _SceneConfiguration.swift │ │ ├── _SceneContent.swift │ │ ├── _SceneRole.swift │ │ └── _SwiftUIZ_Scene.swift │ ├── Scroll View │ │ └── _ConditionalScrollView.swift │ ├── Split View │ │ └── _SidebarProxy.swift │ ├── Utilities │ │ ├── EitherView.swift │ │ ├── ModifiedContentProtocol.swift │ │ ├── TaskLocal++.swift │ │ ├── _AnyViewWrapper.swift │ │ ├── _AsymmetricInsertionRemoval.swift │ │ ├── _AsyncPhase.swift │ │ ├── _FlipFlopDisabled.swift │ │ ├── _InvisibleAppView.swift │ │ ├── _Suspense.swift │ │ ├── _UnimplementedView.swift │ │ ├── _UnsafelyAdaptingView.swift │ │ └── __static_SwiftUI_View_transformEnvironment.swift │ ├── View Proxies │ │ └── _ViewProxyType.swift │ ├── View Traits │ │ ├── _SwiftUIX_ViewTraitKey.swift │ │ ├── _SwiftUIX_ViewTraitValues.swift │ │ ├── _SwiftUIX_ViewTraitValuesReader.swift │ │ ├── _UnaryViewTraitReader.swift │ │ ├── _ViewTraitReader.swift │ │ └── _ViewTraitsRepresentingView.swift │ └── Window │ │ ├── _WindowConfigurator.swift │ │ └── _WindowDrawer.swift ├── macros.swift └── module.swift ├── _SwiftUIZ_B ├── Intramodular │ ├── AnyViewBuilder.swift │ ├── DynamicView.swift │ ├── Hypergraph │ │ ├── _LightweightViewHypergraph.Interpose.swift │ │ └── _LightweightViewHypergraph.swift │ ├── Previews │ │ ├── ViewPreview.swift │ │ └── _PreviewProviderDescriptor.swift │ ├── Scenes │ │ └── WindowGroup+_DynamicScene.swift │ ├── Shallow Environment │ │ ├── _HydrateShallowEnvironment.swift │ │ ├── _ShallowEnvironment.swift │ │ ├── _ShallowEnvironmentKeyDescriptor.swift │ │ ├── _ShallowEnvironmentProvider.swift │ │ └── _ShallowEnvironmentValues.swift │ ├── View Interposing │ │ ├── _InterposeViewBody.ViewGraphInsertion.swift │ │ ├── _InterposeViewBody.swift │ │ ├── _InterposedViewBody.swift │ │ ├── _InterposedViewProxy.HydrationSurface.swift │ │ └── _InterposedViewProxy.swift │ └── _InterposedApp.swift ├── macros.swift └── module.swift ├── _SwiftUI_Internals └── Intramodular │ ├── SwiftUI+_StaticSwift.swift │ ├── View Modifiers │ ├── _AnyForceModifiedView.swift │ ├── _ForceModifiedView.swift │ ├── _ThinForceModifiedView.swift │ └── _ThinViewModifier.swift │ ├── _SwiftUI_BloomFilter.swift │ └── _UnaryViewAdaptor.swift └── _UniversalDisplayLink ├── DisplayLink+SwiftUI.swift ├── DisplayLink.swift ├── DisplayLinkCallbackContext.swift ├── DisplayLinkDriver+CA.swift ├── DisplayLinkDriver+CV.swift ├── DisplayLinkDriver+Helper.swift └── DisplayLinkDriver.swift /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .swiftpm/ 3 | .swiftpm/* 4 | /*.xcodeproj 5 | /.build 6 | /Packages 7 | xcuserdata/ 8 | -------------------------------------------------------------------------------- /Dependencies/Engine/Engine/Sources/AnyView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nathan Tannar 3 | // 4 | 5 | import SwiftUI 6 | import EngineCore 7 | 8 | extension AnyView { 9 | 10 | /// Creates a type-erased view from a type-erased value if that value is also a `View` 11 | @_disfavoredOverload 12 | public init?(_ content: Any) { 13 | guard let view = AnyView(visiting: content) else { 14 | return nil 15 | } 16 | self = view 17 | } 18 | } 19 | 20 | // MARK: - Previews 21 | 22 | struct AnyView_Previews: PreviewProvider { 23 | static var previews: some View { 24 | VStack { 25 | AnyView(Optional.none as Any) 26 | 27 | let content: Any = Text("Hello, World") 28 | AnyView(content) 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Dependencies/Engine/Engine/Sources/EmptyShape.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nathan Tannar 3 | // 4 | 5 | import SwiftUI 6 | 7 | @frozen 8 | public struct EmptyShape: Shape { 9 | 10 | @inlinable 11 | public init() { } 12 | 13 | public func path(in rect: CGRect) -> Path { 14 | return Path() 15 | } 16 | 17 | @available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0, *) 18 | public func sizeThatFits(_ proposal: ProposedViewSize) -> CGSize { 19 | return .zero 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Dependencies/Engine/Engine/Sources/EnvironmentKeyVisitor.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nathan Tannar 3 | // 4 | 5 | import SwiftUI 6 | import EngineCore 7 | 8 | /// An ``EnvironmentKeyVisitor`` allows for `some EnvironmentKey` to be unwrapped 9 | /// to visit the concrete `EnvironmentKey` type. 10 | public typealias EnvironmentKeyVisitor = EngineCore.EnvironmentKeyVisitor 11 | 12 | /// The ``TypeDescriptor`` for the `EnvironmentKey` protocol 13 | public typealias EnvironmentKeyProtocolDescriptor = EngineCore.EnvironmentKeyProtocolDescriptor 14 | -------------------------------------------------------------------------------- /Dependencies/Engine/Engine/Sources/ForEachSubview.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nathan Tannar 3 | // 4 | 5 | import SwiftUI 6 | 7 | /// A view that transforms a each variadic view subview 8 | @frozen 9 | public struct ForEachSubview< 10 | Subview: View & Identifiable, 11 | Content: View 12 | >: View { 13 | 14 | @usableFromInline 15 | var source: Array 16 | 17 | @usableFromInline 18 | var subview: (Int, Subview) -> Content 19 | 20 | public init( 21 | _ source: VariadicView, 22 | @ViewBuilder subview: @escaping (Int, Subview) -> Content 23 | ) where Subview == AnyVariadicView.Subview { 24 | self.init(source.children.map { $0 }, subview: subview) 25 | } 26 | 27 | public init( 28 | _ source: [AnyVariadicView.Subview], 29 | @ViewBuilder subview: @escaping (Int, Subview) -> Content 30 | ) where Subview == AnyVariadicView.Subview { 31 | self.source = source 32 | self.subview = subview 33 | } 34 | 35 | public init( 36 | _ source: [MultiViewSubviewVisitor.Subview], 37 | @ViewBuilder subview: @escaping (Int, Subview) -> Content 38 | ) where Subview == MultiViewSubviewVisitor.Subview { 39 | self.source = source 40 | self.subview = subview 41 | } 42 | 43 | public var body: some View { 44 | let subviews = Array(zip(source.indices, source)) 45 | ForEach(subviews, id: \.1.id) { index, element in 46 | subview(index, element) 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Dependencies/Engine/Engine/Sources/LayoutBuilder.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nathan Tannar 3 | // 4 | 5 | import SwiftUI 6 | 7 | /// A custom parameter attribute that constructs a layout from closures. 8 | /// 9 | /// ``` 10 | /// var axis: Axis 11 | /// 12 | /// @LayoutBuilder 13 | /// var layout: some Layout { 14 | /// switch axis { 15 | /// case .vertical: 16 | /// VStackLayout() 17 | /// case .horizontal: 18 | /// HStackLayout() 19 | /// } 20 | /// } 21 | /// ``` 22 | @resultBuilder 23 | @available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0, *) 24 | public struct LayoutBuilder { 25 | public static func buildBlock() -> VStackLayout { 26 | VStackLayout() 27 | } 28 | 29 | public static func buildBlock( 30 | _ layout: L 31 | ) -> L { 32 | layout 33 | } 34 | 35 | public static func buildEither< 36 | TrueLayout: Layout, 37 | FalseLayout: Layout 38 | >( 39 | first: TrueLayout 40 | ) -> ConditionalLayout { 41 | ConditionalLayout(first) 42 | } 43 | 44 | public static func buildEither< 45 | TrueLayout: Layout, 46 | FalseLayout: Layout 47 | >( 48 | second: FalseLayout 49 | ) -> ConditionalLayout { 50 | ConditionalLayout(second) 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Dependencies/Engine/Engine/Sources/Never.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nathan Tannar 3 | // 4 | 5 | import SwiftUI 6 | 7 | extension View where Body == Never { 8 | @_transparent 9 | public func bodyError() -> Never { 10 | fatalError("body() should not be called on \(String(describing: Self.self))") 11 | } 12 | } 13 | 14 | extension ViewModifier where Body == Never { 15 | @_transparent 16 | public func bodyError() -> Never { 17 | fatalError("body(content:) should not be called on \(String(describing: Self.self))") 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Dependencies/Engine/Engine/Sources/StaticCondition.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nathan Tannar 3 | // 4 | 5 | import SwiftUI 6 | 7 | /// A statically defined condition 8 | /// 9 | /// > Important: The evaluation result should be static 10 | /// 11 | public protocol StaticCondition { 12 | static var value: Bool { get } 13 | } 14 | -------------------------------------------------------------------------------- /Dependencies/Engine/Engine/Sources/UpdatePhase.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nathan Tannar 3 | // 4 | 5 | import SwiftUI 6 | import Combine 7 | 8 | /// A property wrapper that automatically updates its value 9 | /// when the `View` it is attached to updates. 10 | /// 11 | /// > Tip: Useful for when you need to observe when a view updates 12 | /// 13 | @propertyWrapper 14 | @frozen 15 | @available(iOS 14.0, macOS 11.0, tvOS 14.0, watchOS 7.0, *) 16 | @MainActor @preconcurrency 17 | public struct UpdatePhase: DynamicProperty { 18 | @usableFromInline 19 | @MainActor @preconcurrency 20 | final class Storage: ObservableObject { 21 | var value: Value 22 | 23 | @usableFromInline 24 | init(value: Value) { 25 | self.value = value 26 | } 27 | } 28 | 29 | @usableFromInline 30 | var storage: StateObject 31 | 32 | @inlinable 33 | @MainActor @preconcurrency 34 | public init() { 35 | self.storage = StateObject(wrappedValue: Storage(value: Value())) 36 | } 37 | 38 | public nonisolated mutating func update() { 39 | MainActor.unsafe { 40 | storage.wrappedValue.value.update() 41 | } 42 | } 43 | 44 | @MainActor @preconcurrency 45 | public var wrappedValue: Value { 46 | storage.wrappedValue.value 47 | } 48 | 49 | @frozen 50 | public struct Value: Hashable, Sendable { 51 | @usableFromInline 52 | var phase: UInt32 53 | 54 | @inlinable 55 | public init() { 56 | self.phase = 0 57 | } 58 | 59 | mutating func update() { 60 | phase = phase &+ 1 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Dependencies/Engine/Engine/Sources/ViewAdapter.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nathan Tannar 3 | // 4 | 5 | import SwiftUI 6 | 7 | /// A wrapper for `@ViewBuilder` 8 | @frozen 9 | public struct ViewAdapter: View { 10 | 11 | @usableFromInline 12 | var content: Content 13 | 14 | @inlinable 15 | public init(@ViewBuilder content: () -> Content) { 16 | self.content = content() 17 | } 18 | 19 | public var body: Never { 20 | bodyError() 21 | } 22 | 23 | public static func _makeView( 24 | view: _GraphValue, 25 | inputs: _ViewInputs 26 | ) -> SwiftUI._ViewOutputs { 27 | Content._makeView(view: view[\.content], inputs: inputs) 28 | } 29 | 30 | public static func _makeViewList( 31 | view: _GraphValue, 32 | inputs: _ViewListInputs 33 | ) -> SwiftUI._ViewListOutputs { 34 | Content._makeViewList(view: view[\.content], inputs: inputs) 35 | } 36 | 37 | @available(iOS 14.0, macOS 11.0, tvOS 14.0, watchOS 7.0, *) 38 | public static func _viewListCount( 39 | inputs: SwiftUI._ViewListCountInputs 40 | ) -> Int? { 41 | Content._viewListCount(inputs: inputs) 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Dependencies/Engine/Engine/Sources/ViewModifierContent.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nathan Tannar 3 | // 4 | 5 | import SwiftUI 6 | 7 | extension _ViewModifier_Content { 8 | @_transparent 9 | public init() { 10 | precondition(MemoryLayout.size == 0) 11 | let content = unsafeBitCast(Void(), to: Self.self) 12 | self = content 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Dependencies/Engine/Engine/Sources/ViewModifierVisitor.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nathan Tannar 3 | // 4 | 5 | import SwiftUI 6 | import EngineCore 7 | 8 | /// A ``ViewModifierVisitor`` allows for `some ViewModifier` to be unwrapped 9 | /// to visit the concrete `ViewModifier` type. 10 | public typealias ViewModifierVisitor = EngineCore.ViewModifierVisitor 11 | 12 | /// The ``TypeDescriptor`` for the `ViewModifier` protocol 13 | public typealias ViewModifierProtocolDescriptor = EngineCore.ViewModifierProtocolDescriptor 14 | -------------------------------------------------------------------------------- /Dependencies/Engine/Engine/Sources/ViewTraitKeyVisitor.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nathan Tannar 3 | // 4 | 5 | import SwiftUI 6 | import EngineCore 7 | 8 | /// A ``ViewTraitKeyVisitor`` allows for `some _ViewTraitKey` to be unwrapped 9 | /// to visit the concrete `_ViewTraitKey` type. 10 | public typealias ViewTraitKeyVisitor = EngineCore.ViewTraitKeyVisitor 11 | 12 | /// The ``TypeDescriptor`` for the `_ViewTraitKey` protocol 13 | public typealias ViewTraitKeyProtocolDescriptor = EngineCore.ViewTraitKeyProtocolDescriptor 14 | -------------------------------------------------------------------------------- /Dependencies/Engine/Engine/module.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nathan Tannar 3 | // 4 | 5 | @_exported import EngineCore 6 | -------------------------------------------------------------------------------- /Dependencies/Engine/EngineCore/EmptyViewVisitor.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nathan Tannar 3 | // 4 | 5 | import SwiftUI 6 | 7 | extension EmptyView: MultiView { 8 | 9 | public func makeSubviewIterator() -> some MultiViewIterator { 10 | EmptySubviewIterator() 11 | } 12 | } 13 | 14 | private struct EmptySubviewIterator: MultiViewIterator { 15 | 16 | mutating func visit< 17 | Visitor: MultiViewVisitor 18 | >( 19 | visitor: UnsafeMutablePointer, 20 | context: Context, 21 | stop: inout Bool 22 | ) { 23 | // Do nothing 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Dependencies/Engine/EngineCore/GroupVisitor.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nathan Tannar 3 | // 4 | 5 | import SwiftUI 6 | 7 | extension Group: MultiView where Content: View { 8 | 9 | public var content: Content { 10 | try! swift_getFieldValue("content", Content.self, self) 11 | } 12 | 13 | public func makeSubviewIterator() -> some MultiViewIterator { 14 | content.makeSubviewIterator() 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Dependencies/Engine/EngineCore/ModifiedContentVisitor.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nathan Tannar 3 | // 4 | 5 | import SwiftUI 6 | 7 | extension ModifiedContent: MultiView where Content: View, Modifier: ViewModifier { 8 | 9 | public func makeSubviewIterator() -> some MultiViewIterator { 10 | ModifiedContentSubviewIterator( 11 | content: content, 12 | modifier: modifier 13 | ) 14 | } 15 | } 16 | 17 | private struct ModifiedContentSubviewIterator< 18 | Content: View, 19 | Modifier: ViewModifier 20 | >: MultiViewIterator { 21 | 22 | var content: Content 23 | var modifier: Modifier 24 | 25 | func visit< 26 | Visitor: MultiViewVisitor 27 | >( 28 | visitor: UnsafeMutablePointer, 29 | context: Context, 30 | stop: inout Bool 31 | ) { 32 | if let conformance = MultiViewProtocolDescriptor.conformance(of: Content.self) { 33 | conformance.visit( 34 | content: content, 35 | visitor: visitor, 36 | context: context.modifier(modifier), 37 | stop: &stop 38 | ) 39 | } else { 40 | visitor.value.visit( 41 | content: content.modifier(modifier), 42 | context: context, 43 | stop: &stop 44 | ) 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Dependencies/Engine/EngineCore/OptionalVisitor.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nathan Tannar 3 | // 4 | 5 | import SwiftUI 6 | 7 | extension Optional: MultiView where Wrapped: View { 8 | 9 | public func makeSubviewIterator() -> some MultiViewIterator { 10 | OptionalSubviewIterator(content: self) 11 | } 12 | } 13 | 14 | private struct OptionalSubviewIterator< 15 | Wrapped: View 16 | >: MultiViewIterator { 17 | 18 | var content: Optional 19 | 20 | func visit< 21 | Visitor: MultiViewVisitor 22 | >( 23 | visitor: UnsafeMutablePointer, 24 | context: Context, 25 | stop: inout Bool 26 | ) { 27 | switch content { 28 | case .none: 29 | // Do nothing 30 | break 31 | case .some(let element): 32 | element.visit(visitor: visitor, context: context, stop: &stop) 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Dependencies/Engine/EngineCore/ProtocolConformance.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nathan Tannar 3 | // 4 | 5 | import Swallow 6 | 7 | /// A type that wraps the conformance of protocol `P` for a given type. 8 | /// 9 | /// See also: 10 | /// - `https://forums.swift.org/t/calling-swift-runtime-methods/23325` 11 | /// - `https://github.com/apple/swift/blob/main/stdlib/toolchain/Compatibility50/ProtocolConformance.cpp` 12 | public struct ProtocolConformance { 13 | public var metadata: UnsafeRawPointer 14 | public var conformance: UnsafeRawPointer 15 | 16 | public init?(_ type: Any.Type) { 17 | let metadata = unsafeBitCast(type, to: UnsafeRawPointer.self) 18 | let desc = P.descriptor 19 | guard let conformance = _swift_conformsToProtocol(metadata, desc) else { 20 | return nil 21 | } 22 | self.metadata = metadata 23 | self.conformance = conformance 24 | } 25 | } 26 | 27 | extension TypeDescriptor { 28 | 29 | /// Returns the protocol conformance of the type, if it exists 30 | public static func conformance(of type: Any.Type) -> ProtocolConformance? { 31 | ProtocolConformance(type) 32 | } 33 | 34 | /// Returns the protocol conformance of the type, if it exists 35 | /// 36 | /// - Parameter typeName: The mangled name for a given type 37 | public static func conformance(of typeName: String) -> ProtocolConformance? { 38 | guard let type = _typeByName(typeName) else { 39 | return nil 40 | } 41 | return ProtocolConformance(type) 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Dependencies/Engine/EngineCore/TypeDescriptor.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nathan Tannar 3 | // 4 | 5 | /// A protocol to statically define a descriptor to a type's metadata 6 | /// 7 | /// See also: 8 | /// - `https://github.com/apple/swift/blob/main/docs/ABI/TypeMetadata.rst` 9 | public protocol TypeDescriptor { 10 | static var descriptor: UnsafeRawPointer { get } 11 | } 12 | 13 | extension TypeDescriptor { 14 | public static var descriptor: UnsafeRawPointer { 15 | TypeIdentifier(Self.self).metadata 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Dependencies/Engine/EngineCore/TypeIdentifier.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nathan Tannar 3 | // 4 | 5 | /// A unique identifier derived from a type 6 | @frozen 7 | public struct TypeIdentifier: Hashable, CustomDebugStringConvertible { 8 | public var metadata: UnsafeRawPointer 9 | 10 | public init(_: T.Type = T.self) { 11 | self.metadata = unsafeBitCast(T.self, to: UnsafeRawPointer.self) 12 | } 13 | 14 | public var debugDescription: String { 15 | _typeName(unsafeBitCast(metadata, to: Any.Type.self), qualified: true) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Dependencies/Engine/EngineCore/UnsafePointer.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nathan Tannar 3 | // 4 | 5 | import Foundation 6 | 7 | @_transparent 8 | public func withMemoryRebound(_ x: inout T, to _: U.Type, _ body: ((inout U) -> ReturnType)) -> ReturnType { 9 | withUnsafeMutablePointer(to: &x) { ptr in 10 | ptr.withMemoryRebound(to: U.self, capacity: 1) { ptr in 11 | body(&ptr.pointee) 12 | } 13 | } 14 | } 15 | 16 | extension UnsafeRawPointer { 17 | @_transparent 18 | func offset( 19 | of offset: Int 20 | ) -> UnsafeRawPointer { 21 | advanced(by: MemoryLayout.size * offset) 22 | } 23 | 24 | @_transparent 25 | func offset( 26 | of offset: Int, 27 | as type: T.Type 28 | ) -> UnsafeRawPointer { 29 | advanced(by: MemoryLayout.size * offset) 30 | } 31 | } 32 | 33 | extension UnsafeMutablePointer { 34 | var value: Pointee { 35 | @_transparent 36 | unsafeAddress { 37 | return UnsafePointer(self) 38 | } 39 | @_transparent 40 | nonmutating unsafeMutableAddress { 41 | return self 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Dependencies/Engine/EngineMacrosCore/EngineMacrosCore.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nathan Tannar 3 | // 4 | 5 | import SwiftCompilerPlugin 6 | import SwiftSyntaxMacros 7 | 8 | @main 9 | struct EngineMacrosCore: CompilerPlugin { 10 | let providingMacros: [Macro.Type] = [ 11 | StyledViewMacro.self 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /Dependencies/_SwiftUIZ_Nuke/Caching/DataCaching.swift: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015-2024 Alexander Grebenyuk (github.com/kean). 4 | 5 | import Foundation 6 | 7 | /// Data cache. 8 | /// 9 | /// - important: The implementation must be thread safe. 10 | public protocol DataCaching: Sendable { 11 | /// Retrieves data from cache for the given key. 12 | func cachedData(for key: String) -> Data? 13 | 14 | /// Returns `true` if the cache contains data for the given key. 15 | func containsData(for key: String) -> Bool 16 | 17 | /// Stores data for the given key. 18 | /// - note: The implementation must return immediately and store data 19 | /// asynchronously. 20 | func storeData(_ data: Data, for key: String) 21 | 22 | /// Removes data for the given key. 23 | func removeData(for key: String) 24 | 25 | /// Removes all items. 26 | func removeAll() 27 | } 28 | -------------------------------------------------------------------------------- /Dependencies/_SwiftUIZ_Nuke/Caching/ImageCaching.swift: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015-2024 Alexander Grebenyuk (github.com/kean). 4 | 5 | import Foundation 6 | 7 | /// In-memory image cache. 8 | /// 9 | /// The implementation must be thread safe. 10 | public protocol ImageCaching: AnyObject, Sendable { 11 | /// Access the image cached for the given request. 12 | subscript(key: ImageCacheKey) -> ImageContainer? { get set } 13 | 14 | /// Removes all caches items. 15 | func removeAll() 16 | } 17 | 18 | /// An opaque container that acts as a cache key. 19 | /// 20 | /// In general, you don't construct it directly, and use ``ImagePipeline`` or ``ImagePipeline/Cache-swift.struct`` APIs. 21 | public struct ImageCacheKey: Hashable, Sendable { 22 | let key: Inner 23 | 24 | // This is faster than using AnyHashable (and it shows in performance tests). 25 | enum Inner: Hashable, Sendable { 26 | case custom(String) 27 | case `default`(CacheKey) 28 | } 29 | 30 | public init(key: String) { 31 | self.key = .custom(key) 32 | } 33 | 34 | public init(request: ImageRequest) { 35 | self.key = .default(request.makeImageCacheKey()) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Dependencies/_SwiftUIZ_Nuke/Decoding/ImageDecoders+Empty.swift: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015-2024 Alexander Grebenyuk (github.com/kean). 4 | 5 | import Foundation 6 | 7 | extension ImageDecoders { 8 | /// A decoder that returns an empty placeholder image and attaches image 9 | /// data to the image container. 10 | public struct Empty: ImageDecoding, Sendable { 11 | public let isProgressive: Bool 12 | private let assetType: AssetType? 13 | 14 | public var isAsynchronous: Bool { false } 15 | 16 | /// Initializes the decoder. 17 | /// 18 | /// - Parameters: 19 | /// - type: Image type to be associated with an image container. 20 | /// `nil` by default. 21 | /// - isProgressive: If `false`, returns nil for every progressive 22 | /// scan. `false` by default. 23 | public init(assetType: AssetType? = nil, isProgressive: Bool = false) { 24 | self.assetType = assetType 25 | self.isProgressive = isProgressive 26 | } 27 | 28 | public func decode(_ data: Data) throws -> ImageContainer { 29 | ImageContainer(image: PlatformImage(), type: assetType, data: data, userInfo: [:]) 30 | } 31 | 32 | public func decodePartiallyDownloadedData(_ data: Data) -> ImageContainer? { 33 | isProgressive ? ImageContainer(image: PlatformImage(), type: assetType, data: data, userInfo: [:]) : nil 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Dependencies/_SwiftUIZ_Nuke/Encoding/ImageEncoders+Default.swift: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015-2024 Alexander Grebenyuk (github.com/kean). 4 | 5 | import Foundation 6 | 7 | #if !os(macOS) 8 | import UIKit 9 | #else 10 | import AppKit 11 | #endif 12 | 13 | extension ImageEncoders { 14 | /// A default adaptive encoder which uses best encoder available depending 15 | /// on the input image and its configuration. 16 | public struct Default: ImageEncoding { 17 | public var compressionQuality: Float 18 | 19 | /// Set to `true` to switch to HEIF when it is available on the current hardware. 20 | /// `false` by default. 21 | public var isHEIFPreferred = false 22 | 23 | public init(compressionQuality: Float = 0.8) { 24 | self.compressionQuality = compressionQuality 25 | } 26 | 27 | public func encode(_ image: PlatformImage) -> Data? { 28 | guard let cgImage = image.cgImage else { 29 | return nil 30 | } 31 | let type: AssetType 32 | if cgImage.isOpaque { 33 | if isHEIFPreferred && ImageEncoders.ImageIO.isSupported(type: .heic) { 34 | type = .heic 35 | } else { 36 | type = .jpeg 37 | } 38 | } else { 39 | type = .png 40 | } 41 | let encoder = ImageEncoders.ImageIO(type: type, compressionRatio: compressionQuality) 42 | return encoder.encode(image) 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Dependencies/_SwiftUIZ_Nuke/Encoding/ImageEncoders.swift: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015-2024 Alexander Grebenyuk (github.com/kean). 4 | 5 | import Foundation 6 | 7 | /// A namespace with all available encoders. 8 | public enum ImageEncoders {} 9 | 10 | extension ImageEncoding where Self == ImageEncoders.Default { 11 | public static func `default`(compressionQuality: Float = 0.8) -> ImageEncoders.Default { 12 | ImageEncoders.Default(compressionQuality: compressionQuality) 13 | } 14 | } 15 | 16 | extension ImageEncoding where Self == ImageEncoders.ImageIO { 17 | public static func imageIO(type: AssetType, compressionRatio: Float = 0.8) -> ImageEncoders.ImageIO { 18 | ImageEncoders.ImageIO(type: type, compressionRatio: compressionRatio) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Dependencies/_SwiftUIZ_Nuke/Encoding/ImageEncoding.swift: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015-2024 Alexander Grebenyuk (github.com/kean). 4 | 5 | #if canImport(UIKit) 6 | import UIKit 7 | #endif 8 | 9 | #if canImport(AppKit) 10 | import AppKit 11 | #endif 12 | 13 | import ImageIO 14 | 15 | // MARK: - ImageEncoding 16 | 17 | /// An image encoder. 18 | public protocol ImageEncoding: Sendable { 19 | /// Encodes the given image. 20 | func encode(_ image: PlatformImage) -> Data? 21 | 22 | /// An optional method which encodes the given image container. 23 | func encode(_ container: ImageContainer, context: ImageEncodingContext) -> Data? 24 | } 25 | 26 | extension ImageEncoding { 27 | public func encode(_ container: ImageContainer, context: ImageEncodingContext) -> Data? { 28 | if container.type == .gif { 29 | return container.data 30 | } 31 | return self.encode(container.image) 32 | } 33 | } 34 | 35 | /// Image encoding context used when selecting which encoder to use. 36 | public struct ImageEncodingContext: @unchecked Sendable { 37 | public let request: ImageRequest 38 | public let image: PlatformImage 39 | public let urlResponse: URLResponse? 40 | } 41 | -------------------------------------------------------------------------------- /Dependencies/_SwiftUIZ_Nuke/Internal/Atomic.swift: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015-2024 Alexander Grebenyuk (github.com/kean). 4 | 5 | import Foundation 6 | 7 | @propertyWrapper final class Atomic { 8 | private var value: T 9 | private let lock: os_unfair_lock_t 10 | 11 | init(wrappedValue value: T) { 12 | self.value = value 13 | self.lock = .allocate(capacity: 1) 14 | self.lock.initialize(to: os_unfair_lock()) 15 | } 16 | 17 | deinit { 18 | lock.deinitialize(count: 1) 19 | lock.deallocate() 20 | } 21 | 22 | var wrappedValue: T { 23 | get { getValue() } 24 | set { setValue(newValue) } 25 | } 26 | 27 | private func getValue() -> T { 28 | os_unfair_lock_lock(lock) 29 | defer { os_unfair_lock_unlock(lock) } 30 | return value 31 | } 32 | 33 | private func setValue(_ newValue: T) { 34 | os_unfair_lock_lock(lock) 35 | defer { os_unfair_lock_unlock(lock) } 36 | value = newValue 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Dependencies/_SwiftUIZ_Nuke/Internal/Extensions.swift: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015-2024 Alexander Grebenyuk (github.com/kean). 4 | 5 | import Foundation 6 | import CryptoKit 7 | 8 | extension String { 9 | /// Calculates SHA1 from the given string and returns its hex representation. 10 | /// 11 | /// ```swift 12 | /// print("http://test.com".sha1) 13 | /// // prints "50334ee0b51600df6397ce93ceed4728c37fee4e" 14 | /// ``` 15 | var sha1: String? { 16 | guard let input = self.data(using: .utf8) else { 17 | return nil // The conversion to .utf8 should never fail 18 | } 19 | let digest = Insecure.SHA1.hash(data: input) 20 | var output = "" 21 | for byte in digest { 22 | output.append(String(format: "%02x", byte)) 23 | } 24 | return output 25 | } 26 | } 27 | 28 | extension URL { 29 | var isLocalResource: Bool { 30 | scheme == "file" || scheme == "data" 31 | } 32 | } 33 | 34 | extension OperationQueue { 35 | convenience init(maxConcurrentCount: Int) { 36 | self.init() 37 | self.maxConcurrentOperationCount = maxConcurrentCount 38 | } 39 | } 40 | 41 | extension ImageRequest.Priority { 42 | var taskPriority: TaskPriority { 43 | switch self { 44 | case .veryLow: return .veryLow 45 | case .low: return .low 46 | case .normal: return .normal 47 | case .high: return .high 48 | case .veryHigh: return .veryHigh 49 | } 50 | } 51 | } 52 | 53 | final class AnonymousCancellable: Cancellable { 54 | let onCancel: @Sendable () -> Void 55 | 56 | init(_ onCancel: @Sendable @escaping () -> Void) { 57 | self.onCancel = onCancel 58 | } 59 | 60 | func cancel() { 61 | onCancel() 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Dependencies/_SwiftUIZ_Nuke/Loading/DataLoading.swift: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015-2024 Alexander Grebenyuk (github.com/kean). 4 | 5 | import Foundation 6 | 7 | /// Fetches original image data. 8 | public protocol DataLoading: Sendable { 9 | /// - parameter didReceiveData: Can be called multiple times if streaming 10 | /// is supported. 11 | /// - parameter completion: Must be called once after all (or none in case 12 | /// of an error) `didReceiveData` closures have been called. 13 | func loadData(with request: URLRequest, 14 | didReceiveData: @escaping (Data, URLResponse) -> Void, 15 | completion: @escaping (Error?) -> Void) -> any Cancellable 16 | } 17 | 18 | /// A unit of work that can be cancelled. 19 | public protocol Cancellable: AnyObject, Sendable { 20 | func cancel() 21 | } 22 | -------------------------------------------------------------------------------- /Dependencies/_SwiftUIZ_Nuke/Processing/ImageDecompression.swift: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015-2024 Alexander Grebenyuk (github.com/kean). 4 | 5 | import Foundation 6 | 7 | enum ImageDecompression { 8 | 9 | static func decompress(image: PlatformImage, isUsingPrepareForDisplay: Bool = false) -> PlatformImage { 10 | image.decompressed(isUsingPrepareForDisplay: isUsingPrepareForDisplay) ?? image 11 | } 12 | 13 | // MARK: Managing Decompression State 14 | 15 | static var isDecompressionNeededAK: UInt8 = 0 16 | 17 | static func setDecompressionNeeded(_ isDecompressionNeeded: Bool, for image: PlatformImage) { 18 | objc_setAssociatedObject(image, &isDecompressionNeededAK, isDecompressionNeeded, .OBJC_ASSOCIATION_RETAIN) 19 | } 20 | 21 | static func isDecompressionNeeded(for image: PlatformImage) -> Bool? { 22 | objc_getAssociatedObject(image, &isDecompressionNeededAK) as? Bool 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Dependencies/_SwiftUIZ_Nuke/Processing/ImageProcessors+Anonymous.swift: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015-2024 Alexander Grebenyuk (github.com/kean). 4 | 5 | import Foundation 6 | 7 | #if !os(macOS) 8 | import UIKit 9 | #else 10 | import AppKit 11 | #endif 12 | 13 | extension ImageProcessors { 14 | /// Processed an image using a specified closure. 15 | public struct Anonymous: ImageProcessing, CustomStringConvertible { 16 | public let identifier: String 17 | private let closure: @Sendable (PlatformImage) -> PlatformImage? 18 | 19 | public init(id: String, _ closure: @Sendable @escaping (PlatformImage) -> PlatformImage?) { 20 | self.identifier = id 21 | self.closure = closure 22 | } 23 | 24 | public func process(_ image: PlatformImage) -> PlatformImage? { 25 | closure(image) 26 | } 27 | 28 | public var description: String { 29 | "AnonymousProcessor(identifier: \(identifier)" 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Dependencies/_SwiftUIZ_Nuke/Processing/ImageProcessors+Circle.swift: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015-2024 Alexander Grebenyuk (github.com/kean). 4 | 5 | import Foundation 6 | 7 | #if !os(macOS) 8 | import UIKit 9 | #else 10 | import AppKit 11 | #endif 12 | 13 | extension ImageProcessors { 14 | 15 | /// Rounds the corners of an image into a circle. If the image is not a square, 16 | /// crops it to a square first. 17 | public struct Circle: ImageProcessing, Hashable, CustomStringConvertible { 18 | private let border: ImageProcessingOptions.Border? 19 | 20 | /// - parameter border: `nil` by default. 21 | public init(border: ImageProcessingOptions.Border? = nil) { 22 | self.border = border 23 | } 24 | 25 | public func process(_ image: PlatformImage) -> PlatformImage? { 26 | image.processed.byDrawingInCircle(border: border) 27 | } 28 | 29 | public var identifier: String { 30 | let suffix = border.map { "?border=\($0)" } 31 | return "com.github.kean/nuke/circle" + (suffix ?? "") 32 | } 33 | 34 | public var description: String { 35 | "Circle(border: \(border?.description ?? "nil"))" 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Dependencies/_SwiftUIZ_Nuke/Processing/ImageProcessors+GaussianBlur.swift: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015-2024 Alexander Grebenyuk (github.com/kean). 4 | 5 | #if os(iOS) || os(tvOS) || os(macOS) || os(visionOS) 6 | 7 | import Foundation 8 | import CoreImage 9 | 10 | #if !os(macOS) 11 | import UIKit 12 | #else 13 | import AppKit 14 | #endif 15 | 16 | extension ImageProcessors { 17 | /// Blurs an image using `CIGaussianBlur` filter. 18 | public struct GaussianBlur: ImageProcessing, Hashable, CustomStringConvertible { 19 | private let radius: Int 20 | 21 | /// Initializes the receiver with a blur radius. 22 | /// 23 | /// - parameter radius: `8` by default. 24 | public init(radius: Int = 8) { 25 | self.radius = radius 26 | } 27 | 28 | /// Applies `CIGaussianBlur` filter to the image. 29 | public func process(_ image: PlatformImage) -> PlatformImage? { 30 | try? _process(image) 31 | } 32 | 33 | /// Applies `CIGaussianBlur` filter to the image. 34 | public func process(_ container: ImageContainer, context: ImageProcessingContext) throws -> ImageContainer { 35 | try container.map(_process(_:)) 36 | } 37 | 38 | private func _process(_ image: PlatformImage) throws -> PlatformImage { 39 | try CoreImageFilter.applyFilter(named: "CIGaussianBlur", parameters: ["inputRadius": radius], to: image) 40 | } 41 | 42 | public var identifier: String { 43 | "com.github.kean/nuke/gaussian_blur?radius=\(radius)" 44 | } 45 | 46 | public var description: String { 47 | "GaussianBlur(radius: \(radius))" 48 | } 49 | } 50 | } 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /Dependencies/_SwiftUIZ_Nuke/Tasks/ImagePipelineTask.swift: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015-2024 Alexander Grebenyuk (github.com/kean). 4 | 5 | import Foundation 6 | 7 | // Each task holds a strong reference to the pipeline. This is by design. The 8 | // user does not need to hold a strong reference to the pipeline. 9 | class ImagePipelineTask: AsyncTask, @unchecked Sendable { 10 | let pipeline: ImagePipeline 11 | // A canonical request representing the unit work performed by the task. 12 | let request: ImageRequest 13 | 14 | init(_ pipeline: ImagePipeline, _ request: ImageRequest) { 15 | self.pipeline = pipeline 16 | self.request = request 17 | } 18 | } 19 | 20 | // Returns all image tasks subscribed to the current pipeline task. 21 | // A suboptimal approach just to make the new DiskCachPolicy.automatic work. 22 | protocol ImageTaskSubscribers { 23 | var imageTasks: [ImageTask] { get } 24 | } 25 | 26 | extension ImageTask: ImageTaskSubscribers { 27 | var imageTasks: [ImageTask] { 28 | [self] 29 | } 30 | } 31 | 32 | extension ImagePipelineTask: ImageTaskSubscribers { 33 | var imageTasks: [ImageTask] { 34 | subscribers.flatMap { subscribers -> [ImageTask] in 35 | (subscribers as? ImageTaskSubscribers)?.imageTasks ?? [] 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Dependencies/_SwiftUIZ_Nuke/Tasks/OperationTask.swift: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015-2024 Alexander Grebenyuk (github.com/kean). 4 | 5 | import Foundation 6 | 7 | /// A one-shot task for performing a single () -> T function. 8 | final class OperationTask: AsyncTask, @unchecked Sendable { 9 | private let pipeline: ImagePipeline 10 | private let queue: OperationQueue 11 | private let process: () throws -> T 12 | 13 | init(_ pipeline: ImagePipeline, _ queue: OperationQueue, _ process: @escaping () throws -> T) { 14 | self.pipeline = pipeline 15 | self.queue = queue 16 | self.process = process 17 | } 18 | 19 | override func start() { 20 | operation = queue.add { [weak self] in 21 | guard let self = self else { return } 22 | let result = Result(catching: { try self.process() }) 23 | self.pipeline.queue.async { 24 | switch result { 25 | case .success(let value): 26 | self.send(value: value, isCompleted: true) 27 | case .failure(let error): 28 | self.send(error: error) 29 | } 30 | } 31 | } 32 | } 33 | 34 | struct Error: Swift.Error {} 35 | } 36 | -------------------------------------------------------------------------------- /Dependencies/_SwiftUIZ_NukeUI/LazyImageState.swift: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015-2024 Alexander Grebenyuk (github.com/kean). 4 | 5 | import Foundation 6 | import _SwiftUIZ_Nuke 7 | import SwiftUI 8 | import Combine 9 | 10 | /// Describes current image state. 11 | @MainActor 12 | public protocol LazyImageState { 13 | /// Returns the current fetch result. 14 | var result: Result? { get } 15 | 16 | /// Returns the fetched image. 17 | /// 18 | /// - note: In case pipeline has `isProgressiveDecodingEnabled` option enabled 19 | /// and the image being downloaded supports progressive decoding, the `image` 20 | /// might be updated multiple times during the download. 21 | var imageContainer: ImageContainer? { get } 22 | 23 | /// Returns `true` if the image is being loaded. 24 | var isLoading: Bool { get } 25 | 26 | /// The progress of the image download. 27 | var progress: FetchImage.Progress { get } 28 | } 29 | 30 | extension LazyImageState { 31 | /// Returns the current error. 32 | public var error: Error? { 33 | if case .failure(let error) = result { 34 | return error 35 | } 36 | return nil 37 | } 38 | 39 | /// Returns an image view. 40 | public var image: Image? { 41 | #if os(macOS) 42 | imageContainer.map { Image(nsImage: $0.image) } 43 | #else 44 | imageContainer.map { Image(uiImage: $0.image) } 45 | #endif 46 | } 47 | } 48 | 49 | extension FetchImage: LazyImageState {} 50 | -------------------------------------------------------------------------------- /Dependencies/cmark-gfm/cmark.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "registry.h" 5 | #include "node.h" 6 | #include "houdini.h" 7 | #include "cmark-gfm.h" 8 | #include "buffer.h" 9 | 10 | cmark_node_type CMARK_NODE_LAST_BLOCK = CMARK_NODE_FOOTNOTE_DEFINITION; 11 | cmark_node_type CMARK_NODE_LAST_INLINE = CMARK_NODE_FOOTNOTE_REFERENCE; 12 | 13 | int cmark_version() { return CMARK_GFM_VERSION; } 14 | 15 | const char *cmark_version_string() { return CMARK_GFM_VERSION_STRING; } 16 | 17 | static void *xcalloc(size_t nmem, size_t size) { 18 | void *ptr = calloc(nmem, size); 19 | if (!ptr) { 20 | fprintf(stderr, "[cmark] calloc returned null pointer, aborting\n"); 21 | abort(); 22 | } 23 | return ptr; 24 | } 25 | 26 | static void *xrealloc(void *ptr, size_t size) { 27 | void *new_ptr = realloc(ptr, size); 28 | if (!new_ptr) { 29 | fprintf(stderr, "[cmark] realloc returned null pointer, aborting\n"); 30 | abort(); 31 | } 32 | return new_ptr; 33 | } 34 | 35 | static void xfree(void *ptr) { 36 | free(ptr); 37 | } 38 | 39 | cmark_mem CMARK_DEFAULT_MEM_ALLOCATOR = {xcalloc, xrealloc, xfree}; 40 | 41 | cmark_mem *cmark_get_default_mem_allocator() { 42 | return &CMARK_DEFAULT_MEM_ALLOCATOR; 43 | } 44 | 45 | char *cmark_markdown_to_html(const char *text, size_t len, int options) { 46 | cmark_node *doc; 47 | char *result; 48 | 49 | doc = cmark_parse_document(text, len, options); 50 | 51 | result = cmark_render_html(doc, options, NULL); 52 | cmark_node_free(doc); 53 | 54 | return result; 55 | } 56 | -------------------------------------------------------------------------------- /Dependencies/cmark-gfm/core-extensions.c: -------------------------------------------------------------------------------- 1 | #include "cmark-gfm-core-extensions.h" 2 | #include "autolink.h" 3 | #include "strikethrough.h" 4 | #include "table.h" 5 | #include "tagfilter.h" 6 | #include "tasklist.h" 7 | #include "registry.h" 8 | #include "plugin.h" 9 | 10 | static int core_extensions_registration(cmark_plugin *plugin) { 11 | cmark_plugin_register_syntax_extension(plugin, create_table_extension()); 12 | cmark_plugin_register_syntax_extension(plugin, 13 | create_strikethrough_extension()); 14 | cmark_plugin_register_syntax_extension(plugin, create_autolink_extension()); 15 | cmark_plugin_register_syntax_extension(plugin, create_tagfilter_extension()); 16 | cmark_plugin_register_syntax_extension(plugin, create_tasklist_extension()); 17 | return 1; 18 | } 19 | 20 | void cmark_gfm_core_extensions_ensure_registered(void) { 21 | static int registered = 0; 22 | 23 | if (!registered) { 24 | cmark_register_plugin(core_extensions_registration); 25 | registered = 1; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Dependencies/cmark-gfm/include/autolink.h: -------------------------------------------------------------------------------- 1 | #ifndef CMARK_GFM_AUTOLINK_H 2 | #define CMARK_GFM_AUTOLINK_H 3 | 4 | #include "cmark-gfm-core-extensions.h" 5 | 6 | cmark_syntax_extension *create_autolink_extension(void); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /Dependencies/cmark-gfm/include/cmark-gfm-extensions_export.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef CMARK_GFM_EXTENSIONS_EXPORT_H 3 | #define CMARK_GFM_EXTENSIONS_EXPORT_H 4 | 5 | #ifdef CMARK_GFM_EXTENSIONS_STATIC_DEFINE 6 | # define CMARK_GFM_EXTENSIONS_EXPORT 7 | # define CMARK_GFM_EXTENSIONS_NO_EXPORT 8 | #else 9 | # ifndef CMARK_GFM_EXTENSIONS_EXPORT 10 | # ifdef libcmark_gfm_extensions_EXPORTS 11 | /* We are building this library */ 12 | # define CMARK_GFM_EXTENSIONS_EXPORT __attribute__((visibility("default"))) 13 | # else 14 | /* We are using this library */ 15 | # define CMARK_GFM_EXTENSIONS_EXPORT __attribute__((visibility("default"))) 16 | # endif 17 | # endif 18 | 19 | # ifndef CMARK_GFM_EXTENSIONS_NO_EXPORT 20 | # define CMARK_GFM_EXTENSIONS_NO_EXPORT __attribute__((visibility("hidden"))) 21 | # endif 22 | #endif 23 | 24 | #ifndef CMARK_GFM_EXTENSIONS_DEPRECATED 25 | # define CMARK_GFM_EXTENSIONS_DEPRECATED __attribute__ ((__deprecated__)) 26 | #endif 27 | 28 | #ifndef CMARK_GFM_EXTENSIONS_DEPRECATED_EXPORT 29 | # define CMARK_GFM_EXTENSIONS_DEPRECATED_EXPORT CMARK_GFM_EXTENSIONS_EXPORT CMARK_GFM_EXTENSIONS_DEPRECATED 30 | #endif 31 | 32 | #ifndef CMARK_GFM_EXTENSIONS_DEPRECATED_NO_EXPORT 33 | # define CMARK_GFM_EXTENSIONS_DEPRECATED_NO_EXPORT CMARK_GFM_EXTENSIONS_NO_EXPORT CMARK_GFM_EXTENSIONS_DEPRECATED 34 | #endif 35 | 36 | #if 0 /* DEFINE_NO_DEPRECATED */ 37 | # ifndef CMARK_GFM_EXTENSIONS_NO_DEPRECATED 38 | # define CMARK_GFM_EXTENSIONS_NO_DEPRECATED 39 | # endif 40 | #endif 41 | 42 | #endif /* CMARK_GFM_EXTENSIONS_EXPORT_H */ 43 | -------------------------------------------------------------------------------- /Dependencies/cmark-gfm/include/cmark-gfm_export.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef CMARK_GFM_EXPORT_H 3 | #define CMARK_GFM_EXPORT_H 4 | 5 | #ifdef CMARK_GFM_STATIC_DEFINE 6 | # define CMARK_GFM_EXPORT 7 | # define CMARK_GFM_NO_EXPORT 8 | #else 9 | # ifndef CMARK_GFM_EXPORT 10 | # ifdef libcmark_gfm_EXPORTS 11 | /* We are building this library */ 12 | # define CMARK_GFM_EXPORT __attribute__((visibility("default"))) 13 | # else 14 | /* We are using this library */ 15 | # define CMARK_GFM_EXPORT __attribute__((visibility("default"))) 16 | # endif 17 | # endif 18 | 19 | # ifndef CMARK_GFM_NO_EXPORT 20 | # define CMARK_GFM_NO_EXPORT __attribute__((visibility("hidden"))) 21 | # endif 22 | #endif 23 | 24 | #ifndef CMARK_GFM_DEPRECATED 25 | # define CMARK_GFM_DEPRECATED __attribute__ ((__deprecated__)) 26 | #endif 27 | 28 | #ifndef CMARK_GFM_DEPRECATED_EXPORT 29 | # define CMARK_GFM_DEPRECATED_EXPORT CMARK_GFM_EXPORT CMARK_GFM_DEPRECATED 30 | #endif 31 | 32 | #ifndef CMARK_GFM_DEPRECATED_NO_EXPORT 33 | # define CMARK_GFM_DEPRECATED_NO_EXPORT CMARK_GFM_NO_EXPORT CMARK_GFM_DEPRECATED 34 | #endif 35 | 36 | #if 0 /* DEFINE_NO_DEPRECATED */ 37 | # ifndef CMARK_GFM_NO_DEPRECATED 38 | # define CMARK_GFM_NO_DEPRECATED 39 | # endif 40 | #endif 41 | 42 | #endif /* CMARK_GFM_EXPORT_H */ 43 | -------------------------------------------------------------------------------- /Dependencies/cmark-gfm/include/cmark-gfm_version.h: -------------------------------------------------------------------------------- 1 | #ifndef CMARK_GFM_VERSION_H 2 | #define CMARK_GFM_VERSION_H 3 | 4 | #define CMARK_GFM_VERSION ((0 << 24) | (29 << 16) | (0 << 8) | 4) 5 | #define CMARK_GFM_VERSION_STRING "0.29.0.gfm.4" 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /Dependencies/cmark-gfm/include/cmark_ctype.h: -------------------------------------------------------------------------------- 1 | #ifndef CMARK_CMARK_CTYPE_H 2 | #define CMARK_CMARK_CTYPE_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include "cmark-gfm_export.h" 9 | 10 | /** Locale-independent versions of functions from ctype.h. 11 | * We want cmark to behave the same no matter what the system locale. 12 | */ 13 | 14 | CMARK_GFM_EXPORT 15 | int cmark_isspace(char c); 16 | 17 | CMARK_GFM_EXPORT 18 | int cmark_ispunct(char c); 19 | 20 | CMARK_GFM_EXPORT 21 | int cmark_isalnum(char c); 22 | 23 | CMARK_GFM_EXPORT 24 | int cmark_isdigit(char c); 25 | 26 | CMARK_GFM_EXPORT 27 | int cmark_isalpha(char c); 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /Dependencies/cmark-gfm/include/cmark_gfm.h: -------------------------------------------------------------------------------- 1 | #ifndef CMARK_GFM_UMBRELLA_H 2 | #define CMARK_GFM_UMBRELLA_H 3 | 4 | #include "autolink.h" 5 | #include "cmark-gfm.h" 6 | #include "ext_scanners.h" 7 | #include "footnotes.h" 8 | #include "houdini.h" 9 | #include "html.h" 10 | #include "inlines.h" 11 | #include "iterator.h" 12 | #include "parser.h" 13 | #include "plugin.h" 14 | #include "references.h" 15 | #include "registry.h" 16 | #include "render.h" 17 | #include "scanners.h" 18 | #include "strikethrough.h" 19 | #include "syntax_extension.h" 20 | #include "table.h" 21 | #include "tagfilter.h" 22 | #include "tasklist.h" 23 | #include "utf8.h" 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /Dependencies/cmark-gfm/include/config.h: -------------------------------------------------------------------------------- 1 | #ifndef CMARK_CONFIG_H 2 | #define CMARK_CONFIG_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #define HAVE_STDBOOL_H 9 | 10 | #ifdef HAVE_STDBOOL_H 11 | #include 12 | #elif !defined(__cplusplus) 13 | typedef char bool; 14 | #endif 15 | 16 | #define HAVE___BUILTIN_EXPECT 17 | 18 | #define HAVE___ATTRIBUTE__ 19 | 20 | #ifdef HAVE___ATTRIBUTE__ 21 | #define CMARK_ATTRIBUTE(list) __attribute__ (list) 22 | #else 23 | #define CMARK_ATTRIBUTE(list) 24 | #endif 25 | 26 | #ifndef CMARK_INLINE 27 | #if defined(_MSC_VER) && !defined(__cplusplus) 28 | #define CMARK_INLINE __inline 29 | #else 30 | #define CMARK_INLINE inline 31 | #endif 32 | #endif 33 | 34 | /* snprintf and vsnprintf fallbacks for MSVC before 2015, 35 | due to Valentin Milea http://stackoverflow.com/questions/2915672/ 36 | */ 37 | 38 | #if defined(_MSC_VER) && _MSC_VER < 1900 39 | 40 | #include 41 | #include 42 | 43 | #define snprintf c99_snprintf 44 | #define vsnprintf c99_vsnprintf 45 | 46 | CMARK_INLINE int c99_vsnprintf(char *outBuf, size_t size, const char *format, va_list ap) 47 | { 48 | int count = -1; 49 | 50 | if (size != 0) 51 | count = _vsnprintf_s(outBuf, size, _TRUNCATE, format, ap); 52 | if (count == -1) 53 | count = _vscprintf(format, ap); 54 | 55 | return count; 56 | } 57 | 58 | CMARK_INLINE int c99_snprintf(char *outBuf, size_t size, const char *format, ...) 59 | { 60 | int count; 61 | va_list ap; 62 | 63 | va_start(ap, format); 64 | count = c99_vsnprintf(outBuf, size, format, ap); 65 | va_end(ap); 66 | 67 | return count; 68 | } 69 | 70 | #endif 71 | 72 | #ifdef __cplusplus 73 | } 74 | #endif 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /Dependencies/cmark-gfm/include/ext_scanners.h: -------------------------------------------------------------------------------- 1 | #include "chunk.h" 2 | #include "cmark-gfm.h" 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | bufsize_t _ext_scan_at(bufsize_t (*scanner)(const unsigned char *), 9 | unsigned char *ptr, int len, bufsize_t offset); 10 | bufsize_t _scan_table_start(const unsigned char *p); 11 | bufsize_t _scan_table_cell(const unsigned char *p); 12 | bufsize_t _scan_table_cell_end(const unsigned char *p); 13 | bufsize_t _scan_table_row_end(const unsigned char *p); 14 | bufsize_t _scan_tasklist(const unsigned char *p); 15 | 16 | #define scan_table_start(c, l, n) _ext_scan_at(&_scan_table_start, c, l, n) 17 | #define scan_table_cell(c, l, n) _ext_scan_at(&_scan_table_cell, c, l, n) 18 | #define scan_table_cell_end(c, l, n) _ext_scan_at(&_scan_table_cell_end, c, l, n) 19 | #define scan_table_row_end(c, l, n) _ext_scan_at(&_scan_table_row_end, c, l, n) 20 | #define scan_tasklist(c, l, n) _ext_scan_at(&_scan_tasklist, c, l, n) 21 | 22 | #ifdef __cplusplus 23 | } 24 | #endif 25 | -------------------------------------------------------------------------------- /Dependencies/cmark-gfm/include/footnotes.h: -------------------------------------------------------------------------------- 1 | #ifndef CMARK_FOOTNOTES_H 2 | #define CMARK_FOOTNOTES_H 3 | 4 | #include "map.h" 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | struct cmark_footnote { 11 | cmark_map_entry entry; 12 | cmark_node *node; 13 | unsigned int ix; 14 | }; 15 | 16 | typedef struct cmark_footnote cmark_footnote; 17 | 18 | void cmark_footnote_create(cmark_map *map, cmark_node *node); 19 | cmark_map *cmark_footnote_map_new(cmark_mem *mem); 20 | 21 | void cmark_unlink_footnotes_map(cmark_map *map); 22 | 23 | #ifdef __cplusplus 24 | } 25 | #endif 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /Dependencies/cmark-gfm/include/houdini.h: -------------------------------------------------------------------------------- 1 | #ifndef CMARK_HOUDINI_H 2 | #define CMARK_HOUDINI_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | #include "config.h" 10 | #include "buffer.h" 11 | 12 | #ifdef HAVE___BUILTIN_EXPECT 13 | #define likely(x) __builtin_expect((x), 1) 14 | #define unlikely(x) __builtin_expect((x), 0) 15 | #else 16 | #define likely(x) (x) 17 | #define unlikely(x) (x) 18 | #endif 19 | 20 | #ifdef HOUDINI_USE_LOCALE 21 | #define _isxdigit(c) isxdigit(c) 22 | #define _isdigit(c) isdigit(c) 23 | #else 24 | /* 25 | * Helper _isdigit methods -- do not trust the current locale 26 | * */ 27 | #define _isxdigit(c) (strchr("0123456789ABCDEFabcdef", (c)) != NULL) 28 | #define _isdigit(c) ((c) >= '0' && (c) <= '9') 29 | #endif 30 | 31 | #define HOUDINI_ESCAPED_SIZE(x) (((x)*12) / 10) 32 | #define HOUDINI_UNESCAPED_SIZE(x) (x) 33 | 34 | CMARK_GFM_EXPORT 35 | bufsize_t houdini_unescape_ent(cmark_strbuf *ob, const uint8_t *src, 36 | bufsize_t size); 37 | CMARK_GFM_EXPORT 38 | int houdini_escape_html(cmark_strbuf *ob, const uint8_t *src, 39 | bufsize_t size); 40 | CMARK_GFM_EXPORT 41 | int houdini_escape_html0(cmark_strbuf *ob, const uint8_t *src, 42 | bufsize_t size, int secure); 43 | CMARK_GFM_EXPORT 44 | int houdini_unescape_html(cmark_strbuf *ob, const uint8_t *src, 45 | bufsize_t size); 46 | CMARK_GFM_EXPORT 47 | void houdini_unescape_html_f(cmark_strbuf *ob, const uint8_t *src, 48 | bufsize_t size); 49 | CMARK_GFM_EXPORT 50 | int houdini_escape_href(cmark_strbuf *ob, const uint8_t *src, 51 | bufsize_t size); 52 | 53 | #ifdef __cplusplus 54 | } 55 | #endif 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /Dependencies/cmark-gfm/include/html.h: -------------------------------------------------------------------------------- 1 | #ifndef CMARK_HTML_H 2 | #define CMARK_HTML_H 3 | 4 | #include "buffer.h" 5 | #include "node.h" 6 | 7 | CMARK_INLINE 8 | static void cmark_html_render_cr(cmark_strbuf *html) { 9 | if (html->size && html->ptr[html->size - 1] != '\n') 10 | cmark_strbuf_putc(html, '\n'); 11 | } 12 | 13 | #define BUFFER_SIZE 100 14 | 15 | CMARK_INLINE 16 | static void cmark_html_render_sourcepos(cmark_node *node, cmark_strbuf *html, int options) { 17 | char buffer[BUFFER_SIZE]; 18 | if (CMARK_OPT_SOURCEPOS & options) { 19 | snprintf(buffer, BUFFER_SIZE, " data-sourcepos=\"%d:%d-%d:%d\"", 20 | cmark_node_get_start_line(node), cmark_node_get_start_column(node), 21 | cmark_node_get_end_line(node), cmark_node_get_end_column(node)); 22 | cmark_strbuf_puts(html, buffer); 23 | } 24 | } 25 | 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /Dependencies/cmark-gfm/include/inlines.h: -------------------------------------------------------------------------------- 1 | #ifndef CMARK_INLINES_H 2 | #define CMARK_INLINES_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include "references.h" 9 | 10 | cmark_chunk cmark_clean_url(cmark_mem *mem, cmark_chunk *url); 11 | cmark_chunk cmark_clean_title(cmark_mem *mem, cmark_chunk *title); 12 | 13 | CMARK_GFM_EXPORT 14 | void cmark_parse_inlines(cmark_parser *parser, 15 | cmark_node *parent, 16 | cmark_map *refmap, 17 | int options); 18 | 19 | bufsize_t cmark_parse_reference_inline(cmark_mem *mem, cmark_chunk *input, 20 | cmark_map *refmap); 21 | 22 | void cmark_inlines_add_special_character(unsigned char c, bool emphasis); 23 | void cmark_inlines_remove_special_character(unsigned char c, bool emphasis); 24 | 25 | #ifdef __cplusplus 26 | } 27 | #endif 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /Dependencies/cmark-gfm/include/iterator.h: -------------------------------------------------------------------------------- 1 | #ifndef CMARK_ITERATOR_H 2 | #define CMARK_ITERATOR_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include "cmark-gfm.h" 9 | 10 | typedef struct { 11 | cmark_event_type ev_type; 12 | cmark_node *node; 13 | } cmark_iter_state; 14 | 15 | struct cmark_iter { 16 | cmark_mem *mem; 17 | cmark_node *root; 18 | cmark_iter_state cur; 19 | cmark_iter_state next; 20 | }; 21 | 22 | #ifdef __cplusplus 23 | } 24 | #endif 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /Dependencies/cmark-gfm/include/map.h: -------------------------------------------------------------------------------- 1 | #ifndef CMARK_MAP_H 2 | #define CMARK_MAP_H 3 | 4 | #include "chunk.h" 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | struct cmark_map_entry { 11 | struct cmark_map_entry *next; 12 | unsigned char *label; 13 | unsigned int age; 14 | }; 15 | 16 | typedef struct cmark_map_entry cmark_map_entry; 17 | 18 | struct cmark_map; 19 | 20 | typedef void (*cmark_map_free_f)(struct cmark_map *, cmark_map_entry *); 21 | 22 | struct cmark_map { 23 | cmark_mem *mem; 24 | cmark_map_entry *refs; 25 | cmark_map_entry **sorted; 26 | unsigned int size; 27 | cmark_map_free_f free; 28 | }; 29 | 30 | typedef struct cmark_map cmark_map; 31 | 32 | unsigned char *normalize_map_label(cmark_mem *mem, cmark_chunk *ref); 33 | cmark_map *cmark_map_new(cmark_mem *mem, cmark_map_free_f free); 34 | void cmark_map_free(cmark_map *map); 35 | cmark_map_entry *cmark_map_lookup(cmark_map *map, cmark_chunk *label); 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /Dependencies/cmark-gfm/include/plugin.h: -------------------------------------------------------------------------------- 1 | #ifndef CMARK_PLUGIN_H 2 | #define CMARK_PLUGIN_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include "cmark-gfm.h" 9 | #include "cmark-gfm-extension_api.h" 10 | 11 | /** 12 | * cmark_plugin: 13 | * 14 | * A plugin structure, which should be filled by plugin's 15 | * init functions. 16 | */ 17 | struct cmark_plugin { 18 | cmark_llist *syntax_extensions; 19 | }; 20 | 21 | cmark_llist * 22 | cmark_plugin_steal_syntax_extensions(cmark_plugin *plugin); 23 | 24 | cmark_plugin * 25 | cmark_plugin_new(void); 26 | 27 | void 28 | cmark_plugin_free(cmark_plugin *plugin); 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /Dependencies/cmark-gfm/include/references.h: -------------------------------------------------------------------------------- 1 | #ifndef CMARK_REFERENCES_H 2 | #define CMARK_REFERENCES_H 3 | 4 | #include "map.h" 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | struct cmark_reference { 11 | cmark_map_entry entry; 12 | cmark_chunk url; 13 | cmark_chunk title; 14 | }; 15 | 16 | typedef struct cmark_reference cmark_reference; 17 | 18 | void cmark_reference_create(cmark_map *map, cmark_chunk *label, 19 | cmark_chunk *url, cmark_chunk *title); 20 | cmark_map *cmark_reference_map_new(cmark_mem *mem); 21 | 22 | #ifdef __cplusplus 23 | } 24 | #endif 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /Dependencies/cmark-gfm/include/registry.h: -------------------------------------------------------------------------------- 1 | #ifndef CMARK_REGISTRY_H 2 | #define CMARK_REGISTRY_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include "cmark-gfm.h" 9 | #include "plugin.h" 10 | 11 | CMARK_GFM_EXPORT 12 | void cmark_register_plugin(cmark_plugin_init_func reg_fn); 13 | 14 | CMARK_GFM_EXPORT 15 | void cmark_release_plugins(void); 16 | 17 | CMARK_GFM_EXPORT 18 | cmark_llist *cmark_list_syntax_extensions(cmark_mem *mem); 19 | 20 | #ifdef __cplusplus 21 | } 22 | #endif 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /Dependencies/cmark-gfm/include/strikethrough.h: -------------------------------------------------------------------------------- 1 | #ifndef CMARK_GFM_STRIKETHROUGH_H 2 | #define CMARK_GFM_STRIKETHROUGH_H 3 | 4 | #include "cmark-gfm-core-extensions.h" 5 | 6 | extern cmark_node_type CMARK_NODE_STRIKETHROUGH; 7 | cmark_syntax_extension *create_strikethrough_extension(void); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /Dependencies/cmark-gfm/include/syntax_extension.h: -------------------------------------------------------------------------------- 1 | #ifndef CMARK_SYNTAX_EXTENSION_H 2 | #define CMARK_SYNTAX_EXTENSION_H 3 | 4 | #include "cmark-gfm.h" 5 | #include "cmark-gfm-extension_api.h" 6 | #include "config.h" 7 | 8 | struct cmark_syntax_extension { 9 | cmark_match_block_func last_block_matches; 10 | cmark_open_block_func try_opening_block; 11 | cmark_match_inline_func match_inline; 12 | cmark_inline_from_delim_func insert_inline_from_delim; 13 | cmark_llist * special_inline_chars; 14 | char * name; 15 | void * priv; 16 | bool emphasis; 17 | cmark_free_func free_function; 18 | cmark_get_type_string_func get_type_string_func; 19 | cmark_can_contain_func can_contain_func; 20 | cmark_contains_inlines_func contains_inlines_func; 21 | cmark_common_render_func commonmark_render_func; 22 | cmark_common_render_func plaintext_render_func; 23 | cmark_common_render_func latex_render_func; 24 | cmark_xml_attr_func xml_attr_func; 25 | cmark_common_render_func man_render_func; 26 | cmark_html_render_func html_render_func; 27 | cmark_html_filter_func html_filter_func; 28 | cmark_postprocess_func postprocess_func; 29 | cmark_opaque_alloc_func opaque_alloc_func; 30 | cmark_opaque_free_func opaque_free_func; 31 | cmark_commonmark_escape_func commonmark_escape_func; 32 | }; 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /Dependencies/cmark-gfm/include/table.h: -------------------------------------------------------------------------------- 1 | #ifndef CMARK_GFM_TABLE_H 2 | #define CMARK_GFM_TABLE_H 3 | 4 | #include "cmark-gfm-core-extensions.h" 5 | 6 | 7 | extern cmark_node_type CMARK_NODE_TABLE, CMARK_NODE_TABLE_ROW, 8 | CMARK_NODE_TABLE_CELL; 9 | 10 | cmark_syntax_extension *create_table_extension(void); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /Dependencies/cmark-gfm/include/tagfilter.h: -------------------------------------------------------------------------------- 1 | #ifndef CMARK_GFM_TAGFILTER_H 2 | #define CMARK_GFM_TAGFILTER_H 3 | 4 | #include "cmark-gfm-core-extensions.h" 5 | 6 | cmark_syntax_extension *create_tagfilter_extension(void); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /Dependencies/cmark-gfm/include/tasklist.h: -------------------------------------------------------------------------------- 1 | #ifndef TASKLIST_H 2 | #define TASKLIST_H 3 | 4 | #include "cmark-gfm-core-extensions.h" 5 | 6 | cmark_syntax_extension *create_tasklist_extension(void); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /Dependencies/cmark-gfm/include/utf8.h: -------------------------------------------------------------------------------- 1 | #ifndef CMARK_UTF8_H 2 | #define CMARK_UTF8_H 3 | 4 | #include 5 | #include "buffer.h" 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | CMARK_GFM_EXPORT 12 | void cmark_utf8proc_case_fold(cmark_strbuf *dest, const uint8_t *str, 13 | bufsize_t len); 14 | 15 | CMARK_GFM_EXPORT 16 | void cmark_utf8proc_encode_char(int32_t uc, cmark_strbuf *buf); 17 | 18 | CMARK_GFM_EXPORT 19 | int cmark_utf8proc_iterate(const uint8_t *str, bufsize_t str_len, int32_t *dst); 20 | 21 | CMARK_GFM_EXPORT 22 | void cmark_utf8proc_check(cmark_strbuf *dest, const uint8_t *line, 23 | bufsize_t size); 24 | 25 | CMARK_GFM_EXPORT 26 | int cmark_utf8proc_is_space(int32_t uc); 27 | 28 | CMARK_GFM_EXPORT 29 | int cmark_utf8proc_is_punctuation(int32_t uc); 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /Dependencies/cmark-gfm/linked_list.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "cmark-gfm.h" 4 | 5 | cmark_llist *cmark_llist_append(cmark_mem *mem, cmark_llist *head, void *data) { 6 | cmark_llist *tmp; 7 | cmark_llist *new_node = (cmark_llist *) mem->calloc(1, sizeof(cmark_llist)); 8 | 9 | new_node->data = data; 10 | new_node->next = NULL; 11 | 12 | if (!head) 13 | return new_node; 14 | 15 | for (tmp = head; tmp->next; tmp=tmp->next); 16 | 17 | tmp->next = new_node; 18 | 19 | return head; 20 | } 21 | 22 | void cmark_llist_free_full(cmark_mem *mem, cmark_llist *head, cmark_free_func free_func) { 23 | cmark_llist *tmp, *prev; 24 | 25 | for (tmp = head; tmp;) { 26 | if (free_func) 27 | free_func(mem, tmp->data); 28 | 29 | prev = tmp; 30 | tmp = tmp->next; 31 | mem->free(prev); 32 | } 33 | } 34 | 35 | void cmark_llist_free(cmark_mem *mem, cmark_llist *head) { 36 | cmark_llist_free_full(mem, head, NULL); 37 | } 38 | -------------------------------------------------------------------------------- /Dependencies/cmark-gfm/plugin.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "plugin.h" 4 | 5 | extern cmark_mem CMARK_DEFAULT_MEM_ALLOCATOR; 6 | 7 | int cmark_plugin_register_syntax_extension(cmark_plugin * plugin, 8 | cmark_syntax_extension * extension) { 9 | plugin->syntax_extensions = cmark_llist_append(&CMARK_DEFAULT_MEM_ALLOCATOR, plugin->syntax_extensions, extension); 10 | return 1; 11 | } 12 | 13 | cmark_plugin * 14 | cmark_plugin_new(void) { 15 | cmark_plugin *res = (cmark_plugin *) CMARK_DEFAULT_MEM_ALLOCATOR.calloc(1, sizeof(cmark_plugin)); 16 | 17 | res->syntax_extensions = NULL; 18 | 19 | return res; 20 | } 21 | 22 | void 23 | cmark_plugin_free(cmark_plugin *plugin) { 24 | cmark_llist_free_full(&CMARK_DEFAULT_MEM_ALLOCATOR, 25 | plugin->syntax_extensions, 26 | (cmark_free_func) cmark_syntax_extension_free); 27 | CMARK_DEFAULT_MEM_ALLOCATOR.free(plugin); 28 | } 29 | 30 | cmark_llist * 31 | cmark_plugin_steal_syntax_extensions(cmark_plugin *plugin) { 32 | cmark_llist *res = plugin->syntax_extensions; 33 | 34 | plugin->syntax_extensions = NULL; 35 | return res; 36 | } 37 | -------------------------------------------------------------------------------- /Dependencies/cmark-gfm/references.c: -------------------------------------------------------------------------------- 1 | #include "cmark-gfm.h" 2 | #include "parser.h" 3 | #include "references.h" 4 | #include "inlines.h" 5 | #include "chunk.h" 6 | 7 | static void reference_free(cmark_map *map, cmark_map_entry *_ref) { 8 | cmark_reference *ref = (cmark_reference *)_ref; 9 | cmark_mem *mem = map->mem; 10 | if (ref != NULL) { 11 | mem->free(ref->entry.label); 12 | cmark_chunk_free(mem, &ref->url); 13 | cmark_chunk_free(mem, &ref->title); 14 | mem->free(ref); 15 | } 16 | } 17 | 18 | void cmark_reference_create(cmark_map *map, cmark_chunk *label, 19 | cmark_chunk *url, cmark_chunk *title) { 20 | cmark_reference *ref; 21 | unsigned char *reflabel = normalize_map_label(map->mem, label); 22 | 23 | /* empty reference name, or composed from only whitespace */ 24 | if (reflabel == NULL) 25 | return; 26 | 27 | assert(map->sorted == NULL); 28 | 29 | ref = (cmark_reference *)map->mem->calloc(1, sizeof(*ref)); 30 | ref->entry.label = reflabel; 31 | ref->url = cmark_clean_url(map->mem, url); 32 | ref->title = cmark_clean_title(map->mem, title); 33 | ref->entry.age = map->size; 34 | ref->entry.next = map->refs; 35 | 36 | map->refs = (cmark_map_entry *)ref; 37 | map->size++; 38 | } 39 | 40 | cmark_map *cmark_reference_map_new(cmark_mem *mem) { 41 | return cmark_map_new(mem, reference_free); 42 | } 43 | -------------------------------------------------------------------------------- /Dependencies/cmark-gfm/tagfilter.c: -------------------------------------------------------------------------------- 1 | #include "tagfilter.h" 2 | #include 3 | #include 4 | 5 | static const char *blacklist[] = { 6 | "title", "textarea", "style", "xmp", "iframe", 7 | "noembed", "noframes", "script", "plaintext", NULL, 8 | }; 9 | 10 | static int is_tag(const unsigned char *tag_data, size_t tag_size, 11 | const char *tagname) { 12 | size_t i; 13 | 14 | if (tag_size < 3 || tag_data[0] != '<') 15 | return 0; 16 | 17 | i = 1; 18 | 19 | if (tag_data[i] == '/') { 20 | i++; 21 | } 22 | 23 | for (; i < tag_size; ++i, ++tagname) { 24 | if (*tagname == 0) 25 | break; 26 | 27 | if (tolower(tag_data[i]) != *tagname) 28 | return 0; 29 | } 30 | 31 | if (i == tag_size) 32 | return 0; 33 | 34 | if (cmark_isspace(tag_data[i]) || tag_data[i] == '>') 35 | return 1; 36 | 37 | if (tag_data[i] == '/' && tag_size >= i + 2 && tag_data[i + 1] == '>') 38 | return 1; 39 | 40 | return 0; 41 | } 42 | 43 | static int filter(cmark_syntax_extension *ext, const unsigned char *tag, 44 | size_t tag_len) { 45 | const char **it; 46 | 47 | for (it = blacklist; *it; ++it) { 48 | if (is_tag(tag, tag_len, *it)) { 49 | return 0; 50 | } 51 | } 52 | 53 | return 1; 54 | } 55 | 56 | cmark_syntax_extension *create_tagfilter_extension(void) { 57 | cmark_syntax_extension *ext = cmark_syntax_extension_new("tagfilter"); 58 | cmark_syntax_extension_set_html_filter_func(ext, filter); 59 | return ext; 60 | } 61 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Vatsal Manot 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Macros/Intramodular/ViewBodyMacro.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import Swallow 6 | import SwiftSyntax 7 | import SwiftSyntaxMacros 8 | import SwiftSyntaxUtilities 9 | 10 | public struct ViewBodyMacro: DeclarationMacro { 11 | public static func expansion( 12 | of node: some FreestandingMacroExpansionSyntax, 13 | in context: some MacroExpansionContext 14 | ) throws -> [DeclSyntax] { 15 | guard node.arguments.isEmpty else { 16 | throw Never.Reason.illegal 17 | } 18 | 19 | guard let trailingClosure = node.trailingClosure else { 20 | throw Never.Reason.illegal 21 | } 22 | 23 | let result = DeclSyntax( 24 | """ 25 | public var body: AnyView { 26 | let `self` = self 27 | 28 | Group \(trailingClosure).eraseToAnyView() 29 | } 30 | """ 31 | ) 32 | 33 | return [result] 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Macros/module.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import SwiftCompilerPlugin 6 | import SwiftSyntaxMacros 7 | 8 | @main 9 | struct Plugin: CompilerPlugin { 10 | let providingMacros: [Macro.Type] = [ 11 | EnvironmentValuesMacro.self, 12 | EnvironmentValueMacro.self, 13 | PreviewMacro.self, 14 | ViewBodyMacro.self, 15 | ViewMacro.self, 16 | _ViewTraitKeyMacro.self, 17 | _ViewTraitValueMacro.self, 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /Miscellaneous/Emoji/Intramodular/Data/GitHubEmojiDataReader.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import Foundation 6 | import Swallow 7 | 8 | public struct GitHubEmojiEntry: Codable, Hashable, Identifiable { 9 | public let emoji: String 10 | public let description: String 11 | public let category: Emoji.Category 12 | public let aliases: [String] 13 | public let tags: [String] 14 | public let unicodeVersion: String 15 | public let iosVersion: String 16 | public var skinTones: Bool? 17 | 18 | public var id: some Hashable { 19 | emoji 20 | } 21 | 22 | public init?(from emoji: Emoji) { 23 | guard let entry = GitHubEmojiDataReader.data[emoji] else { 24 | return nil 25 | } 26 | 27 | self = entry 28 | } 29 | } 30 | 31 | struct GitHubEmojiDataReader { 32 | public static var data: [Emoji: GitHubEmojiEntry] = readData() 33 | 34 | static func readData() -> [Emoji: GitHubEmojiEntry] { 35 | do { 36 | let decoder = JSONDecoder() 37 | let path = Bundle.module.path(forResource: "gemoji", ofType: "json")! 38 | let entriesData = try FileManager.default.contents(atPath: path).unwrap() 39 | 40 | decoder.keyDecodingStrategy = .convertFromSnakeCase 41 | 42 | let entries = try decoder.decode([GitHubEmojiEntry].self, from: entriesData).map { 43 | (Emoji(rawValue: $0.emoji)!, $0) 44 | } 45 | 46 | return Dictionary( 47 | entries, 48 | uniquingKeysWith: { lhs, rhs in lhs } 49 | ) 50 | } catch { 51 | assertionFailure() 52 | 53 | return [:] 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Miscellaneous/Emoji/Intramodular/Emoji.Category.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import Swallow 6 | 7 | extension Emoji { 8 | public enum Category: String, CaseIterable, Codable, Hashable { 9 | case symbols = "Symbols" 10 | case objects = "Objects" 11 | case animalsAndNature = "Animals & Nature" 12 | case people = "People & Body" 13 | case foodAndDrink = "Food & Drink" 14 | case places = "Travel & Places" 15 | case activities = "Activities" 16 | case flags = "Flags" 17 | case smileysAndEmotion = "Smileys & Emotion" 18 | } 19 | } 20 | 21 | // MARK: - Conformances 22 | 23 | extension Emoji.Category: Identifiable { 24 | public var id: some Hashable { 25 | rawValue 26 | } 27 | } 28 | 29 | extension Emoji.Category: Named { 30 | public var name: String { 31 | rawValue 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Miscellaneous/Emoji/module.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import Swift 6 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Extensibility/AssetInlineImageProvider.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import Foundation 6 | import SwiftUI 7 | internal import SwiftUIX 8 | 9 | /// An inline image provider that loads images from resources located in an app or a module. 10 | public struct AssetInlineImageProvider: InlineImageProvider { 11 | private let name: (URL) -> String 12 | private let bundle: Bundle? 13 | 14 | /// Creates an asset inline image provider. 15 | /// - Parameters: 16 | /// - name: A closure that extracts the image resource name from the URL in the Markdown content. 17 | /// - bundle: The bundle where the image resources are located. Specify `nil` to search the app’s main bundle. 18 | public init( 19 | name: @escaping (URL) -> String = \.lastPathComponent, 20 | bundle: Bundle? = nil 21 | ) { 22 | self.name = name 23 | self.bundle = bundle 24 | } 25 | 26 | public func image(with url: URL, label: String) async throws -> Image { 27 | .init(self.name(url), bundle: self.bundle, label: Text(label)) 28 | } 29 | } 30 | 31 | extension InlineImageProvider where Self == AssetInlineImageProvider { 32 | /// An inline image provider that loads images from resources located in an app or a module. 33 | /// 34 | /// Use the `markdownInlineImageProvider(_:)` modifier to configure this image provider for a view hierarchy. 35 | public static var asset: Self { 36 | .init() 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Extensibility/CodeSyntaxHighlighter.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import SwiftUI 6 | internal import SwiftUIZ 7 | 8 | /// A type that provides syntax highlighting to code blocks in a Markdown view. 9 | /// 10 | /// To configure the current code syntax highlighter for a view hierarchy, use the 11 | /// `markdownCodeSyntaxHighlighter(_:)` modifier. 12 | public protocol CodeSyntaxHighlighter { 13 | /// Returns a text view configured with the syntax highlighted code. 14 | /// - Parameters: 15 | /// - code: The code block. 16 | /// - language: The language of the code block. 17 | func highlightCode(_ code: String, language: String?) -> Text 18 | } 19 | 20 | /// A code syntax highlighter that returns unstyled code blocks. 21 | public struct PlainTextCodeSyntaxHighlighter: CodeSyntaxHighlighter { 22 | /// Creates a plain text code syntax highlighter. 23 | public init() {} 24 | 25 | public func highlightCode(_ code: String, language: String?) -> Text { 26 | Text(code) 27 | } 28 | } 29 | 30 | extension CodeSyntaxHighlighter where Self == PlainTextCodeSyntaxHighlighter { 31 | /// A code syntax highlighter that returns unstyled code blocks. 32 | public static var plainText: Self { 33 | PlainTextCodeSyntaxHighlighter() 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Extensibility/DefaultImageProvider.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | internal import _SwiftUIZ_NukeUI 6 | import SwiftUI 7 | internal import SwiftUIX 8 | 9 | /// The default image provider, which loads images from the network. 10 | public struct DefaultImageProvider: ImageProvider { 11 | private let urlSession: URLSession 12 | 13 | /// Creates a default image provider. 14 | /// - Parameter urlSession: An `URLSession` instance to load images. 15 | public init(urlSession: URLSession = .shared) { 16 | self.urlSession = urlSession 17 | } 18 | 19 | public func makeImage(url: URL?) -> some View { 20 | DefaultImageView(url: url, urlSession: self.urlSession) 21 | } 22 | 23 | private struct DefaultImageView: View { 24 | let url: URL? 25 | let urlSession: URLSession 26 | 27 | var body: some View { 28 | LazyImage(url: url) { state in 29 | if let image = state.image { 30 | image 31 | .resizable() 32 | .aspectRatio(contentMode: .fit) 33 | } 34 | } 35 | } 36 | } 37 | } 38 | 39 | extension ImageProvider where Self == DefaultImageProvider { 40 | /// The default image provider, which loads images from the network. 41 | /// 42 | /// Use the `markdownImageProvider(_:)` modifier to configure this image provider for a view hierarchy. 43 | public static var `default`: Self { 44 | .init() 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Extensibility/DefaultInlineImageProvider.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | internal import _SwiftUIZ_Nuke 6 | import SwiftUI 7 | internal import SwiftUIX 8 | 9 | public struct DefaultInlineImageProvider: InlineImageProvider { 10 | private let urlSession: URLSession 11 | 12 | public init(urlSession: URLSession = .shared) { 13 | self.urlSession = urlSession 14 | } 15 | 16 | public func image(with url: URL, label: String) async throws -> Image { 17 | let request = ImageRequest( 18 | url: url, 19 | processors: [], 20 | priority: .high, 21 | options: [] 22 | ) 23 | 24 | let image = try await ImagePipeline.shared.image(for: request) 25 | 26 | return Image(image: image) 27 | } 28 | } 29 | 30 | extension InlineImageProvider where Self == DefaultInlineImageProvider { 31 | public static var `default`: Self { 32 | .init() 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Extensibility/ImageProvider.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import SwiftUI 6 | internal import SwiftUIZ 7 | 8 | /// A type that provides a view that asynchronously loads and displays an image in a Markdown view. 9 | /// 10 | /// To configure the current image provider for a view hierarchy, use the `markdownImageProvider(_:)` modifier. 11 | /// 12 | /// The following example shows how to configure the ``AssetImageProvider`` to load images from the main bundle. 13 | /// 14 | /// ```swift 15 | /// Markdown { 16 | /// "![A dog](dog)" 17 | /// "― Photo by André Spieker" 18 | /// } 19 | /// .markdownImageProvider(.asset) 20 | /// ``` 21 | public protocol ImageProvider { 22 | /// A view that loads and displays an image. 23 | associatedtype Body: View 24 | 25 | /// Creates a view that asynchronously loads and displays the image on a given URL. 26 | /// 27 | /// The ``Markdown`` views in a view hierarchy where this provider is the current image provider 28 | /// will call this method for each image in their contents. 29 | /// 30 | /// - Parameter url: The URL of the image to display. 31 | @ViewBuilder func makeImage(url: URL?) -> Body 32 | } 33 | 34 | struct AnyImageProvider: ImageProvider { 35 | private let _makeImage: (URL?) -> AnyView 36 | 37 | init(_ imageProvider: I) { 38 | self._makeImage = { 39 | AnyView(imageProvider.makeImage(url: $0)) 40 | } 41 | } 42 | 43 | func makeImage(url: URL?) -> some View { 44 | self._makeImage(url) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Extensibility/InlineImageProvider.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import SwiftUI 6 | internal import SwiftUIX 7 | 8 | /// A type that loads images that are displayed within a line of text. 9 | /// 10 | /// To configure the current inline image provider for a view hierarchy, 11 | /// use the `markdownInlineImageProvider(_:)` modifier. 12 | public protocol InlineImageProvider { 13 | /// Returns an image for the given URL. 14 | /// 15 | /// ``Markdown`` views call this method to load images within a line of text. 16 | /// 17 | /// - Parameters: 18 | /// - url: The URL of the image to display. 19 | /// - label: The accessibility label associated with the image. 20 | func image(with url: URL, label: String) async throws -> Image 21 | } 22 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Parser/HTMLTag.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import Foundation 6 | 7 | struct HTMLTag { 8 | let name: String 9 | } 10 | 11 | extension HTMLTag { 12 | private enum Constants { 13 | static let tagExpression = try! NSRegularExpression(pattern: "<\\/?([a-zA-Z0-9]+)[^>]*>") 14 | } 15 | 16 | init?(_ description: String) { 17 | guard 18 | let match = Constants.tagExpression.firstMatch( 19 | in: description, 20 | range: NSRange(description.startIndex..., in: description) 21 | ), 22 | let nameRange = Range(match.range(at: 1), in: description) 23 | else { 24 | return nil 25 | } 26 | 27 | self.name = String(description[nameRange]) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Parser/InlineNode+Rewrite.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import Foundation 6 | 7 | extension Sequence where Element == InlineNode { 8 | func rewrite( 9 | _ r: (InlineNode) throws -> [InlineNode] 10 | ) rethrows -> [InlineNode] { 11 | try self.flatMap { try $0.rewrite(r) } 12 | } 13 | } 14 | 15 | extension InlineNode { 16 | func rewrite( 17 | _ r: (InlineNode) throws -> [InlineNode] 18 | ) rethrows -> [InlineNode] { 19 | var inline = self 20 | inline.children = try self.children.rewrite(r) 21 | return try r(inline) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Parser/InlineNode.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import Foundation 6 | 7 | public enum InlineNode: Hashable { 8 | case text(String) 9 | case softBreak 10 | case lineBreak 11 | case code(String) 12 | case html(String) 13 | case emphasis(children: [InlineNode]) 14 | case strong(children: [InlineNode]) 15 | case strikethrough(children: [InlineNode]) 16 | case link(destination: String, children: [InlineNode]) 17 | case image(source: String, children: [InlineNode]) 18 | } 19 | 20 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Renderer/InlineTextStyles.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import Foundation 6 | 7 | @frozen 8 | @usableFromInline 9 | struct InlineTextStyles: Hashable { 10 | let code: AnyTextStyle 11 | let emphasis: AnyTextStyle 12 | let strong: AnyTextStyle 13 | let strikethrough: AnyTextStyle 14 | let link: AnyTextStyle 15 | 16 | init( 17 | code: any TextStyle, 18 | emphasis: any TextStyle, 19 | strong: any TextStyle, 20 | strikethrough: any TextStyle, 21 | link: any TextStyle 22 | ) { 23 | self.code = .init(erasing: code) 24 | self.emphasis = .init(erasing: emphasis) 25 | self.strong = .init(erasing: strong) 26 | self.strikethrough = .init(erasing: strikethrough) 27 | self.link = .init(erasing: link) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Theme/BlockStyle/BlockConfiguration.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | /// The properties of a Markdown block. 4 | /// 5 | /// Most theme ``BlockStyle`` instances receive a `BlockConfiguration` input in their 6 | /// `body` closure. The configuration ``BlockConfiguration/label-swift.property`` 7 | /// property reflects the block's content. 8 | public struct BlockConfiguration { 9 | /// A type-erased view of a Markdown block. 10 | public struct Label: View { 11 | init(_ label: L) { 12 | self.body = AnyView(label) 13 | } 14 | 15 | public let body: AnyView 16 | } 17 | 18 | /// The Markdown block view. 19 | public let label: Label 20 | 21 | /// The content of the Markdown block. 22 | /// 23 | /// This property provides access to different representations of the block content. 24 | /// For example, you can use ``MarkdownContent/renderMarkdown()`` 25 | /// to get the Markdown formatted text or ``MarkdownContent/renderPlainText()`` 26 | /// to get the plain text of the block content. 27 | public let content: MarkdownContent 28 | } 29 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Theme/BlockStyle/CodeBlockConfiguration.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | /// The properties of a Markdown code block. 4 | /// 5 | /// The theme ``Theme/codeBlock`` block style receives a `CodeBlockConfiguration` 6 | /// input in its `body` closure. 7 | public struct CodeBlockConfiguration { 8 | /// A type-erased view of a Markdown code block. 9 | public struct Label: View { 10 | public let body: AnyView 11 | 12 | init(_ label: L) { 13 | self.body = AnyView(label) 14 | } 15 | } 16 | 17 | /// The code block language, if present. 18 | public let language: String? 19 | 20 | /// The code block contents. 21 | public let content: String 22 | 23 | /// The code block view. 24 | public let label: Label 25 | } 26 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Theme/BlockStyle/ListBullet.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | struct ListBullet: View { 4 | private let image: Image 5 | 6 | var body: some View { 7 | TextStyleAttributesReader { attributes in 8 | let fontSize = attributes.fontProperties?.scaledSize ?? FontProperties.defaultSize 9 | 10 | self.image.font(.system(size: round(fontSize / 3))) 11 | } 12 | } 13 | } 14 | 15 | extension ListBullet { 16 | static var disc: Self { 17 | Self(image: .init(systemName: "circle.fill")) 18 | } 19 | 20 | static var circle: Self { 21 | Self(image: .init(systemName: "circle")) 22 | } 23 | 24 | static var square: Self { 25 | Self(image: .init(systemName: "square.fill")) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Theme/BlockStyle/TableCellConfiguration.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | /// The properties of a Markdown table cell. 4 | /// 5 | /// The theme ``Theme/tableCell`` block style receives a `TableCellConfiguration` 6 | /// input in its `body` closure. 7 | public struct TableCellConfiguration { 8 | /// A type-erased view of a Markdown table cell. 9 | public struct Label: View { 10 | init(_ label: L) { 11 | self.body = AnyView(label) 12 | } 13 | 14 | public let body: AnyView 15 | } 16 | 17 | /// The table cell row index. 18 | public let row: Int 19 | 20 | /// The table cell column index. 21 | public let column: Int 22 | 23 | /// The table cell view. 24 | public let label: Label 25 | 26 | /// The table cell content. 27 | public let content: MarkdownContent 28 | } 29 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Theme/BlockStyle/TaskListMarkerConfiguration.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | /// The properties of a task list marker in a Markdown list. 4 | /// 5 | /// The theme ``Theme/taskListMarker`` block style receives a `TaskListMarkerConfiguration` 6 | /// input in its `body` closure. 7 | public struct TaskListMarkerConfiguration { 8 | /// Determines whether the item to which the marker applies is completed or not. 9 | public let isCompleted: Bool 10 | } 11 | 12 | extension BlockStyle where Configuration == TaskListMarkerConfiguration { 13 | /// A task list marker style that displays a checkmark inside a square if the item is completed 14 | /// or a hollow square if the item is not completed. 15 | public static var checkmarkSquare: Self { 16 | BlockStyle { configuration in 17 | Image(systemName: configuration.isCompleted ? "checkmark.square.fill" : "square") 18 | .symbolRenderingMode(.hierarchical) 19 | .imageScale(.small) 20 | .relativeFrame(minWidth: .em(1.5), alignment: .trailing) 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Theme/TextStyle/Styles/BackgroundColor.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | /// A text style that sets the text background color. 4 | public struct BackgroundColor: Hashable, TextStyle { 5 | private let backgroundColor: Color? 6 | 7 | /// Creates a background color text style. 8 | /// - Parameter backgroundColor: The background color. 9 | public init(_ backgroundColor: Color?) { 10 | self.backgroundColor = backgroundColor 11 | } 12 | 13 | public func _collectAttributes(in attributes: inout AttributeContainer) { 14 | attributes.backgroundColor = self.backgroundColor 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Theme/TextStyle/Styles/EmptyTextStyle.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | /// A text style that doesn't apply any text style. 4 | public struct EmptyTextStyle: Hashable, TextStyle { 5 | /// Creates an empty text style. 6 | public init() {} 7 | 8 | public func _collectAttributes(in: inout AttributeContainer) { 9 | 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Theme/TextStyle/Styles/Font+FontProperties.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | extension Font { 4 | @_transparent 5 | static func withProperties(_ fontProperties: FontProperties) -> Font { 6 | var font: Font 7 | let size = round(fontProperties.size * fontProperties.scale) 8 | 9 | switch fontProperties.family { 10 | case .system(let design): 11 | font = .system(size: size, design: design) 12 | case .custom(let name): 13 | font = .custom(name, size: size) 14 | } 15 | 16 | switch fontProperties.familyVariant { 17 | case .normal: 18 | break // do nothing 19 | case .monospaced: 20 | font = font.monospaced() 21 | } 22 | 23 | switch fontProperties.capsVariant { 24 | case .normal: 25 | break // do nothing 26 | case .smallCaps: 27 | font = font.smallCaps() 28 | case .lowercaseSmallCaps: 29 | font = font.lowercaseSmallCaps() 30 | case .uppercaseSmallCaps: 31 | font = font.uppercaseSmallCaps() 32 | } 33 | 34 | switch fontProperties.digitVariant { 35 | case .normal: 36 | break // do nothing 37 | case .monospaced: 38 | font = font.monospacedDigit() 39 | } 40 | 41 | if fontProperties.weight != .regular { 42 | font = font.weight(fontProperties.weight) 43 | } 44 | 45 | switch fontProperties.style { 46 | case .normal: 47 | break // do nothing 48 | case .italic: 49 | font = font.italic() 50 | } 51 | 52 | return font 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Theme/TextStyle/Styles/FontCapsVariant.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | /// A text style that adjusts the font to use alternate glyphs for capital letters. 4 | public struct FontCapsVariant: Hashable, TextStyle { 5 | private let capsVariant: FontProperties.CapsVariant 6 | 7 | /// Creates a font caps variant text style. 8 | /// - Parameter capsVariant: The font caps variant. 9 | public init(_ capsVariant: FontProperties.CapsVariant) { 10 | self.capsVariant = capsVariant 11 | } 12 | 13 | public func _collectAttributes(in attributes: inout AttributeContainer) { 14 | attributes.fontProperties?.capsVariant = self.capsVariant 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Theme/TextStyle/Styles/FontDigitVariant.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | /// A text style that adjusts the font to use alternate glyphs for digits. 4 | public struct FontDigitVariant: Hashable, TextStyle { 5 | private let digitVariant: FontProperties.DigitVariant 6 | 7 | /// Creates a font digit variant text style. 8 | /// - Parameter digitVariant: The font digit variant. 9 | public init(_ digitVariant: FontProperties.DigitVariant) { 10 | self.digitVariant = digitVariant 11 | } 12 | 13 | public func _collectAttributes( 14 | in attributes: inout AttributeContainer 15 | ) { 16 | attributes.fontProperties?.digitVariant = self.digitVariant 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Theme/TextStyle/Styles/FontFamily.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | /// A text style that sets the text font family. 4 | public struct FontFamily: Hashable, TextStyle { 5 | private let family: FontProperties.Family 6 | 7 | /// Creates a font family text style. 8 | /// - Parameter family: The font family. 9 | public init(_ family: FontProperties.Family) { 10 | self.family = family 11 | } 12 | 13 | public func _collectAttributes(in attributes: inout AttributeContainer) { 14 | attributes.fontProperties?.family = self.family 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Theme/TextStyle/Styles/FontFamilyVariant.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | /// A text style that adjusts the font to use an alternate variant. 4 | public struct FontFamilyVariant: Hashable, TextStyle { 5 | private let familyVariant: FontProperties.FamilyVariant 6 | 7 | /// Creates a font family variant text style. 8 | /// - Parameter familyVariant: The font family variant. 9 | public init(_ familyVariant: FontProperties.FamilyVariant) { 10 | self.familyVariant = familyVariant 11 | } 12 | 13 | public func _collectAttributes(in attributes: inout AttributeContainer) { 14 | attributes.fontProperties?.familyVariant = self.familyVariant 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Theme/TextStyle/Styles/FontPropertiesAttribute.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import Swallow 6 | import SwiftUI 7 | 8 | @frozen 9 | @usableFromInline 10 | enum FontPropertiesAttribute: AttributedStringKey { 11 | @usableFromInline 12 | typealias Value = FontProperties 13 | 14 | @usableFromInline 15 | static let name = "fontProperties" 16 | } 17 | 18 | extension AttributeScopes { 19 | var markdownUI: MarkdownUIAttributes.Type { 20 | MarkdownUIAttributes.self 21 | } 22 | 23 | @frozen 24 | @usableFromInline 25 | struct MarkdownUIAttributes: AttributeScope { 26 | let swiftUI: SwiftUIAttributes 27 | let fontProperties: FontPropertiesAttribute 28 | } 29 | } 30 | 31 | extension AttributeDynamicLookup { 32 | subscript( 33 | dynamicMember keyPath: KeyPath 34 | ) -> T { 35 | @_transparent 36 | get { 37 | return self[T.self] 38 | } 39 | } 40 | } 41 | 42 | extension AttributedString { 43 | func resolvingFonts() -> AttributedString { 44 | _memoize(uniquingWith: self) { 45 | var output = self 46 | 47 | for run in output.runs { 48 | guard let fontProperties = run.fontProperties else { 49 | continue 50 | } 51 | output[run.range].font = .withProperties(fontProperties) 52 | output[run.range].fontProperties = nil 53 | } 54 | 55 | return output 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Theme/TextStyle/Styles/FontSize.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | /// A text style that sets the font size. 4 | public struct FontSize: Hashable, TextStyle { 5 | private enum Size: Hashable { 6 | case points(CGFloat) 7 | case relative(RelativeSize) 8 | } 9 | 10 | private let size: Size 11 | 12 | /// Creates a font size text style that sets the size to a relative value. 13 | /// - Parameter relativeSize: The relative size of the font. 14 | public init(_ relativeSize: RelativeSize) { 15 | self.size = .relative(relativeSize) 16 | } 17 | 18 | /// Creates a font size text style that sets the size to a given value. 19 | /// - Parameter size: The size of the font measured in points. 20 | public init(_ size: CGFloat) { 21 | self.size = .points(size) 22 | } 23 | 24 | public func _collectAttributes(in attributes: inout AttributeContainer) { 25 | switch self.size { 26 | case .points(let value): 27 | attributes.fontProperties?.size = value 28 | attributes.fontProperties?.scale = 1 29 | case .relative(let relativeSize): 30 | switch relativeSize.unit { 31 | case .em: 32 | attributes.fontProperties?.scale *= relativeSize.value 33 | case .rem: 34 | attributes.fontProperties?.scale = relativeSize.value 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Theme/TextStyle/Styles/FontStyle.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | /// A text style that sets whether the font should be styled with a normal or italic face from its font family. 4 | public struct FontStyle: Hashable, TextStyle { 5 | private let style: FontProperties.Style 6 | 7 | /// Creates a font style text style. 8 | /// - Parameter style: The font style. 9 | public init(_ style: FontProperties.Style) { 10 | self.style = style 11 | } 12 | 13 | public func _collectAttributes(in attributes: inout AttributeContainer) { 14 | attributes.fontProperties?.style = self.style 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Theme/TextStyle/Styles/FontWeight.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | /// A text style that adjusts the font weight. 4 | public struct FontWeight: Hashable, TextStyle { 5 | private let weight: Font.Weight 6 | 7 | /// Creates a font weight text style. 8 | /// - Parameter weight: The font weight. 9 | public init(_ weight: Font.Weight) { 10 | self.weight = weight 11 | } 12 | 13 | public func _collectAttributes(in attributes: inout AttributeContainer) { 14 | attributes.fontProperties?.weight = self.weight 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Theme/TextStyle/Styles/ForegroundColor.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | /// A text style that sets the foreground color of the text. 4 | public struct ForegroundColor: Hashable, TextStyle { 5 | private let foregroundColor: Color? 6 | 7 | /// Creates a foreground color text style. 8 | /// - Parameter foregroundColor: The foreground color. 9 | public init(_ foregroundColor: Color?) { 10 | self.foregroundColor = foregroundColor 11 | } 12 | 13 | public func _collectAttributes(in attributes: inout AttributeContainer) { 14 | attributes.foregroundColor = self.foregroundColor 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Theme/TextStyle/Styles/StrikethroughStyle.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import SwiftUI 6 | 7 | /// A text style that sets the strikethrough line style of the text. 8 | public struct StrikethroughStyle: Hashable, TextStyle { 9 | private let lineStyle: Text.LineStyle? 10 | 11 | /// Creates a strikethrough text style. 12 | /// - Parameter lineStyle: The line style. 13 | public init(_ lineStyle: Text.LineStyle?) { 14 | self.lineStyle = lineStyle 15 | } 16 | 17 | public func _collectAttributes( 18 | in attributes: inout AttributeContainer 19 | ) { 20 | attributes.strikethroughStyle = self.lineStyle 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Theme/TextStyle/Styles/TextKerning.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | /// A text style that sets the spacing, or kerning, between the characters of the text. 4 | public struct TextKerning: Hashable, TextStyle { 5 | private let kern: CGFloat? 6 | 7 | /// Creates a text kerning text style. 8 | /// - Parameter kern: The spacing to use between individual characters in the text. 9 | public init(_ kern: CGFloat?) { 10 | self.kern = kern 11 | } 12 | 13 | public func _collectAttributes(in attributes: inout AttributeContainer) { 14 | attributes.kern = self.kern 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Theme/TextStyle/Styles/TextTracking.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | /// A text style that sets the tracking of the text. 4 | public struct TextTracking: Hashable, TextStyle { 5 | private let tracking: CGFloat? 6 | 7 | /// Creates a text tracking text style. 8 | /// - Parameter tracking: The amount of additional space, in points, that is added to each character cluster. 9 | public init(_ tracking: CGFloat?) { 10 | self.tracking = tracking 11 | } 12 | 13 | public func _collectAttributes(in attributes: inout AttributeContainer) { 14 | attributes.tracking = self.tracking 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Theme/TextStyle/Styles/UnderlineStyle.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | /// A text style that sets the underline line style of the text. 4 | public struct UnderlineStyle: Hashable, TextStyle { 5 | private let lineStyle: Text.LineStyle? 6 | 7 | /// Creates an underline style text style. 8 | /// - Parameter lineStyle: The line style. 9 | public init(_ lineStyle: Text.LineStyle?) { 10 | self.lineStyle = lineStyle 11 | } 12 | 13 | public func _collectAttributes(in attributes: inout AttributeContainer) { 14 | attributes.underlineStyle = self.lineStyle 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Utility/BlockNode+ColorSchemeImage.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import SwiftUI 6 | 7 | extension Sequence where Element == BlockNode { 8 | func filterImagesMatching( 9 | colorScheme: ColorScheme 10 | ) -> [BlockNode] { 11 | self.rewrite { inline in 12 | switch inline { 13 | case .image(let source, _): 14 | guard let url = URL(string: source), url.matchesColorScheme(colorScheme) else { 15 | return [] 16 | } 17 | return [inline] 18 | default: 19 | return [inline] 20 | } 21 | } 22 | } 23 | } 24 | 25 | extension URL { 26 | fileprivate func matchesColorScheme( 27 | _ colorScheme: ColorScheme 28 | ) -> Bool { 29 | guard let fragment = self.fragment?.lowercased() else { 30 | return true 31 | } 32 | 33 | switch colorScheme { 34 | case .light: 35 | return fragment != "gh-dark-mode-only" 36 | case .dark: 37 | return fragment != "gh-light-mode-only" 38 | @unknown default: 39 | return true 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Utility/InlineNode+PlainText.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import Foundation 6 | 7 | extension Sequence where Element == InlineNode { 8 | @_transparent 9 | func renderPlainText() -> String { 10 | self.collect { inline in 11 | switch inline { 12 | case .text(let content): 13 | return [content] 14 | case .softBreak: 15 | return [" "] 16 | case .lineBreak: 17 | return ["\n"] 18 | case .code(let content): 19 | return [content] 20 | case .html(let content): 21 | return [content] 22 | default: 23 | return [] 24 | } 25 | } 26 | .joined() 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Utility/InlineNode+RawImageData.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import Foundation 6 | 7 | struct RawImageData: Hashable { 8 | var source: String 9 | var alt: String 10 | var destination: String? 11 | } 12 | 13 | extension InlineNode { 14 | var imageData: RawImageData? { 15 | switch self { 16 | case .image(let source, let children): 17 | return .init(source: source, alt: children.renderPlainText()) 18 | case .link(let destination, let children) where children.count == 1: 19 | guard var imageData = children.first?.imageData else { return nil } 20 | imageData.destination = destination 21 | return imageData 22 | default: 23 | return nil 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Utility/Int+Roman.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import Foundation 6 | 7 | extension Int { 8 | var roman: String { 9 | guard self > 0, self < 4000 else { 10 | return "\(self)" 11 | } 12 | 13 | let decimals = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1] 14 | let numerals = ["M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"] 15 | 16 | var number = self 17 | var result = "" 18 | 19 | for (decimal, numeral) in zip(decimals, numerals) { 20 | let repeats = number / decimal 21 | if repeats > 0 { 22 | result += String(repeating: numeral, count: repeats) 23 | } 24 | number = number % decimal 25 | } 26 | 27 | return result 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Utility/String+KebabCase.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import Foundation 6 | 7 | extension String { 8 | func kebabCased() -> String { 9 | self.components(separatedBy: .alphanumerics.inverted) 10 | .map({ $0.lowercased() }) 11 | .joined(separator: "-") 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Views/Blocks/BlockMargin+SwiftUIZ.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import CoreGraphics 6 | import SwiftUI 7 | internal import SwiftUIZ 8 | 9 | public struct _BlockMargin: Equatable { 10 | var top: CGFloat? 11 | var bottom: CGFloat? 12 | 13 | static let unspecified = _BlockMargin() 14 | } 15 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Views/Blocks/BlockquoteView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import SwiftUI 6 | 7 | struct BlockquoteView: View { 8 | @Environment(\.theme.blockquote) private var blockquote 9 | 10 | private let children: [BlockNode] 11 | 12 | init(children: [BlockNode]) { 13 | self.children = children 14 | } 15 | 16 | var body: some View { 17 | self.blockquote.makeBody( 18 | configuration: .init( 19 | label: .init(BlockSequence(self.children)), 20 | content: .init(block: .blockquote(children: self.children)) 21 | ) 22 | ) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Views/Blocks/BulletedListView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import SwiftUI 6 | 7 | struct BulletedListView: View { 8 | @Environment(\.theme.list) private var list 9 | @Environment(\.theme.bulletedListMarker) private var bulletedListMarker 10 | @Environment(\.listLevel) private var listLevel 11 | 12 | private let isTight: Bool 13 | private let items: [RawListItem] 14 | 15 | init(isTight: Bool, items: [RawListItem]) { 16 | self.isTight = isTight 17 | self.items = items 18 | } 19 | 20 | var body: some View { 21 | self.list.makeBody( 22 | configuration: .init( 23 | label: .init(self.label), 24 | content: .init(block: .bulletedList(isTight: self.isTight, items: self.items)) 25 | ) 26 | ) 27 | } 28 | 29 | private var label: some View { 30 | ListItemSequence(items: self.items, markerStyle: self.bulletedListMarker) 31 | .environment(\.listLevel, self.listLevel + 1) 32 | .environment(\.tightSpacingEnabled, self.isTight) 33 | } 34 | } 35 | 36 | extension BulletedListView: Equatable { 37 | static func == (lhs: Self, rhs: Self) -> Bool { 38 | lhs.isTight == rhs.isTight && lhs.items == rhs.items 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Views/Blocks/CodeBlockView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import SwiftUI 6 | 7 | struct CodeBlockView: View { 8 | @Environment(\.theme.codeBlock) private var codeBlock 9 | @Environment(\.codeSyntaxHighlighter) private var codeSyntaxHighlighter 10 | 11 | private let fenceInfo: String? 12 | private let content: String 13 | 14 | init(fenceInfo: String?, content: String) { 15 | self.fenceInfo = fenceInfo 16 | self.content = content.hasSuffix("\n") ? String(content.dropLast()) : content 17 | } 18 | 19 | var body: some View { 20 | self.codeBlock.makeBody( 21 | configuration: .init( 22 | language: self.fenceInfo, 23 | content: self.content, 24 | label: CodeBlockConfiguration.Label(self.label) 25 | ) 26 | ) 27 | } 28 | 29 | private var label: some View { 30 | self.codeSyntaxHighlighter 31 | .highlightCode(self.content, language: self.fenceInfo) 32 | ._useTextStyleAttributesReader() 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Views/Blocks/ColumnWidthPreference.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import SwiftUI 6 | 7 | extension View { 8 | func readWidth(column: Int) -> some View { 9 | self.background( 10 | GeometryReader { proxy in 11 | Color.clear.preference(key: ColumnWidthPreference.self, value: [column: proxy.size.width]) 12 | } 13 | ) 14 | } 15 | 16 | func onColumnWidthChange(perform action: @escaping ([Int: CGFloat]) -> Void) -> some View { 17 | self.onPreferenceChange(ColumnWidthPreference.self, perform: action) 18 | } 19 | } 20 | 21 | private struct ColumnWidthPreference: PreferenceKey { 22 | static let defaultValue: [Int: CGFloat] = [:] 23 | 24 | static func reduce(value: inout [Int: CGFloat], nextValue: () -> [Int: CGFloat]) { 25 | value.merge(nextValue(), uniquingKeysWith: max) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Views/Blocks/HeadingView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import SwiftUI 6 | 7 | struct HeadingView: View { 8 | @Environment(\.theme.headings) private var headings 9 | 10 | private let level: Int 11 | private let content: [InlineNode] 12 | 13 | init(level: Int, content: [InlineNode]) { 14 | self.level = level 15 | self.content = content 16 | } 17 | 18 | var body: some View { 19 | self.headings[self.level - 1].makeBody( 20 | configuration: .init( 21 | label: .init( 22 | InlineText( 23 | self.content 24 | ) 25 | .equatable() 26 | ), 27 | content: .init( 28 | block: .heading(level: self.level, content: self.content) 29 | ) 30 | ) 31 | ) 32 | .id(content.renderPlainText().kebabCased()) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Views/Blocks/ListItemSequence.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import SwiftUI 6 | 7 | struct ListItemSequence: View { 8 | @Environment(\.multilineTextAlignment) var textAlignment 9 | 10 | private let items: [RawListItem] 11 | private let start: Int 12 | private let markerStyle: BlockStyle 13 | private let markerWidth: CGFloat? 14 | 15 | init( 16 | items: [RawListItem], 17 | start: Int = 1, 18 | markerStyle: BlockStyle, 19 | markerWidth: CGFloat? = nil 20 | ) { 21 | self.items = items 22 | self.start = start 23 | self.markerStyle = markerStyle 24 | self.markerWidth = markerWidth 25 | } 26 | 27 | var body: some View { 28 | VStack(alignment: textAlignment.alignment.horizontal, spacing: 0) { 29 | BlockSequence(self.items) { index, item in 30 | ListItemView( 31 | item: item, 32 | number: self.start + index, 33 | markerStyle: self.markerStyle, 34 | markerWidth: self.markerWidth 35 | ) 36 | } 37 | .labelStyle(.titleAndIcon) 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Views/Blocks/ListItemView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import SwiftUI 6 | 7 | struct ListItemView: View { 8 | @Environment(\.theme.listItem) private var listItem 9 | @Environment(\.listLevel) private var listLevel 10 | 11 | private let item: RawListItem 12 | private let number: Int 13 | private let markerStyle: BlockStyle 14 | private let markerWidth: CGFloat? 15 | 16 | init( 17 | item: RawListItem, 18 | number: Int, 19 | markerStyle: BlockStyle, 20 | markerWidth: CGFloat? 21 | ) { 22 | self.item = item 23 | self.number = number 24 | self.markerStyle = markerStyle 25 | self.markerWidth = markerWidth 26 | } 27 | 28 | var body: some View { 29 | self.listItem.makeBody( 30 | configuration: .init( 31 | label: .init(self.label), 32 | content: .init(blocks: item.children) 33 | ) 34 | ) 35 | } 36 | 37 | private var label: some View { 38 | Label { 39 | BlockSequence(self.item.children) 40 | } icon: { 41 | self.markerStyle 42 | .makeBody(configuration: .init(listLevel: self.listLevel, itemNumber: self.number)) 43 | .textStyleFont() 44 | .readWidth(column: 0) 45 | .frame(width: self.markerWidth, alignment: .trailing) 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Views/Blocks/NumberedListView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import SwiftUI 6 | 7 | struct NumberedListView: View { 8 | @Environment(\.theme.list) private var list 9 | @Environment(\.theme.numberedListMarker) private var numberedListMarker 10 | @Environment(\.listLevel) private var listLevel 11 | 12 | @State private var markerWidth: CGFloat? 13 | 14 | private let isTight: Bool 15 | private let start: Int 16 | private let items: [RawListItem] 17 | 18 | init(isTight: Bool, start: Int, items: [RawListItem]) { 19 | self.isTight = isTight 20 | self.start = start 21 | self.items = items 22 | } 23 | 24 | var body: some View { 25 | self.list.makeBody( 26 | configuration: .init( 27 | label: .init(self.label), 28 | content: .init( 29 | block: .numberedList( 30 | isTight: self.isTight, 31 | start: self.start, 32 | items: self.items 33 | ) 34 | ) 35 | ) 36 | ) 37 | } 38 | 39 | private var label: some View { 40 | ListItemSequence( 41 | items: self.items, 42 | start: self.start, 43 | markerStyle: self.numberedListMarker, 44 | markerWidth: self.markerWidth 45 | ) 46 | .environment(\.listLevel, self.listLevel + 1) 47 | .environment(\.tightSpacingEnabled, self.isTight) 48 | .onColumnWidthChange { columnWidths in 49 | self.markerWidth = columnWidths[0] 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Views/Blocks/ParagraphView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import SwiftUI 6 | 7 | struct ParagraphView: View { 8 | @Environment(\.theme.paragraph) private var paragraph 9 | 10 | private let content: [InlineNode] 11 | 12 | init(content: String) { 13 | self.init( 14 | content: [ 15 | .text(content.hasSuffix("\n") ? String(content.dropLast()) : content) 16 | ] 17 | ) 18 | } 19 | 20 | init(content: [InlineNode]) { 21 | self.content = content 22 | } 23 | 24 | var body: some View { 25 | self.paragraph.makeBody( 26 | configuration: .init( 27 | label: .init(self.label), 28 | content: MarkdownContent(block: .paragraph(content: self.content)) 29 | ) 30 | ) 31 | } 32 | 33 | @ViewBuilder 34 | private var label: some View { 35 | if let imageView = ImageView(content) { 36 | imageView 37 | } else if #available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0, *), let imageFlow = ImageFlow(content) { 38 | imageFlow 39 | } else { 40 | InlineText(content) 41 | } 42 | } 43 | } 44 | 45 | extension ParagraphView: Equatable { 46 | static func == (lhs: Self, rhs: Self) -> Bool { 47 | lhs.content == rhs.content 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Views/Blocks/TableBackgroundView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import SwiftUI 6 | 7 | struct TableBackgroundView: View { 8 | @Environment(\.tableBackgroundStyle) private var tableBackgroundStyle 9 | 10 | private let tableBounds: TableBounds 11 | 12 | init(tableBounds: TableBounds) { 13 | self.tableBounds = tableBounds 14 | } 15 | 16 | var body: some View { 17 | ZStack(alignment: .topLeading) { 18 | ForEach(0..: View { 9 | @Environment(\.textStyle) private var textStyle 10 | 11 | private let content: (AttributeContainer) -> Content 12 | 13 | @ViewStorage 14 | private var _cachedAttributes: AttributeContainer? 15 | 16 | private var attributes: AttributeContainer { 17 | if let _cachedAttributes { 18 | return _cachedAttributes 19 | } 20 | 21 | var result = AttributeContainer() 22 | 23 | self.textStyle._collectAttributes(in: &result) 24 | 25 | self._cachedAttributes = result 26 | 27 | return result 28 | } 29 | 30 | init( 31 | @ViewBuilder content: @escaping (_ attributes: AttributeContainer) -> Content 32 | ) { 33 | self.content = content 34 | } 35 | 36 | var body: some View { 37 | self.content(self.attributes)._onChange(of: textStyle.eraseToAnyEquatable()) { _ in 38 | self._cachedAttributes = nil 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Views/Blocks/ThematicBreakView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import SwiftUI 6 | 7 | struct ThematicBreakView: View { 8 | @Environment(\.theme.thematicBreak) private var thematicBreak 9 | 10 | var body: some View { 11 | self.thematicBreak.makeBody(configuration: ()) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Views/Environment/Environment+BaseURL.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import SwiftUI 6 | 7 | extension EnvironmentValues { 8 | private struct BaseURLKey: EnvironmentKey { 9 | static var defaultValue: URL? = nil 10 | } 11 | 12 | var baseURL: URL? { 13 | get { self[BaseURLKey.self] } 14 | set { self[BaseURLKey.self] = newValue } 15 | } 16 | 17 | private struct ImageBaseURLKey: EnvironmentKey { 18 | static var defaultValue: URL? = nil 19 | } 20 | 21 | var imageBaseURL: URL? { 22 | get { 23 | self[ImageBaseURLKey.self] 24 | } set { 25 | self[ImageBaseURLKey.self] = newValue 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Views/Environment/Environment+CodeSyntaxHighlighter.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | extension View { 4 | /// Sets the code syntax highlighter for the Markdown code blocks in a view hierarchy. 5 | /// - Parameter codeSyntaxHighlighter: The code syntax highlighter to set. Use 6 | /// ``CodeSyntaxHighlighter/plainText`` or a custom syntax 7 | /// highlighter that you define by creating a type that conforms to the 8 | /// ``CodeSyntaxHighlighter`` protocol. 9 | /// - Returns: A view that uses the specified code syntax highlighter for itself and its 10 | /// child views. 11 | public func markdownCodeSyntaxHighlighter( 12 | _ codeSyntaxHighlighter: CodeSyntaxHighlighter 13 | ) -> some View { 14 | self.environment(\.codeSyntaxHighlighter, codeSyntaxHighlighter) 15 | } 16 | } 17 | 18 | extension EnvironmentValues { 19 | var codeSyntaxHighlighter: CodeSyntaxHighlighter { 20 | get { self[CodeSyntaxHighlighterKey.self] } 21 | set { self[CodeSyntaxHighlighterKey.self] = newValue } 22 | } 23 | } 24 | 25 | private struct CodeSyntaxHighlighterKey: EnvironmentKey { 26 | static let defaultValue: CodeSyntaxHighlighter = .plainText 27 | } 28 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Views/Environment/Environment+ImageProvider.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | extension View { 4 | /// Sets the image provider for the Markdown images in a view hierarchy. 5 | /// - Parameter imageProvider: The image provider to set. Use one of the built-in values, like 6 | /// ``ImageProvider/default`` or ``ImageProvider/asset``, 7 | /// or a custom image provider that you define by creating a type that 8 | /// conforms to the ``ImageProvider`` protocol. 9 | /// - Returns: A view that uses the specified image provider for itself and its child views. 10 | public func markdownImageProvider(_ imageProvider: I) -> some View { 11 | self.environment(\.imageProvider, .init(imageProvider)) 12 | } 13 | } 14 | 15 | extension EnvironmentValues { 16 | var imageProvider: AnyImageProvider { 17 | get { self[ImageProviderKey.self] } 18 | set { self[ImageProviderKey.self] = newValue } 19 | } 20 | } 21 | 22 | private struct ImageProviderKey: EnvironmentKey { 23 | static let defaultValue: AnyImageProvider = .init(.default) 24 | } 25 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Views/Environment/Environment+InlineImageProvider.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | extension View { 4 | /// Sets the inline image provider for the Markdown inline images in a view hierarchy. 5 | /// - Parameter inlineImageProvider: The inline image provider to set. Use one of the built-in values, like 6 | /// ``InlineImageProvider/default`` or ``InlineImageProvider/asset``, 7 | /// or a custom inline image provider that you define by creating a type that 8 | /// conforms to the ``InlineImageProvider`` protocol. 9 | /// - Returns: A view that uses the specified inline image provider for itself and its child views. 10 | public func markdownInlineImageProvider(_ inlineImageProvider: InlineImageProvider) -> some View { 11 | self.environment(\.inlineImageProvider, inlineImageProvider) 12 | } 13 | } 14 | 15 | extension EnvironmentValues { 16 | var inlineImageProvider: InlineImageProvider { 17 | get { self[InlineImageProviderKey.self] } 18 | set { self[InlineImageProviderKey.self] = newValue } 19 | } 20 | } 21 | 22 | private struct InlineImageProviderKey: EnvironmentKey { 23 | static let defaultValue: InlineImageProvider = .default 24 | } 25 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Views/Environment/Environment+List.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | extension EnvironmentValues { 4 | var listLevel: Int { 5 | get { self[ListLevelKey.self] } 6 | set { self[ListLevelKey.self] = newValue } 7 | } 8 | 9 | var tightSpacingEnabled: Bool { 10 | get { self[TightSpacingEnabledKey.self] } 11 | set { self[TightSpacingEnabledKey.self] = newValue } 12 | } 13 | } 14 | 15 | private struct ListLevelKey: EnvironmentKey { 16 | static var defaultValue = 0 17 | } 18 | 19 | private struct TightSpacingEnabledKey: EnvironmentKey { 20 | static var defaultValue = false 21 | } 22 | -------------------------------------------------------------------------------- /Miscellaneous/MarkdownUI/Views/Environment/Environment+Table.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | extension View { 4 | /// Sets the table border style for the Markdown tables in a view hierarchy. 5 | /// 6 | /// Use this modifier to customize the table border style inside the body of 7 | /// the ``Theme/table`` block style. 8 | /// 9 | /// - Parameter tableBorderStyle: The border style to set. 10 | public func markdownTableBorderStyle(_ tableBorderStyle: TableBorderStyle) -> some View { 11 | self.environment(\.tableBorderStyle, tableBorderStyle) 12 | } 13 | 14 | /// Sets the table background style for the Markdown tables in a view hierarchy. 15 | /// 16 | /// Use this modifier to customize the table background style inside the body of 17 | /// the ``Theme/table`` block style. 18 | /// 19 | /// - Parameter tableBackgroundStyle: The background style to set. 20 | public func markdownTableBackgroundStyle( 21 | _ tableBackgroundStyle: TableBackgroundStyle 22 | ) -> some View { 23 | self.environment(\.tableBackgroundStyle, tableBackgroundStyle) 24 | } 25 | } 26 | 27 | extension EnvironmentValues { 28 | var tableBorderStyle: TableBorderStyle { 29 | get { self[TableBorderStyleKey.self] } 30 | set { self[TableBorderStyleKey.self] = newValue } 31 | } 32 | 33 | var tableBackgroundStyle: TableBackgroundStyle { 34 | get { self[TableBackgroundStyleKey.self] } 35 | set { self[TableBackgroundStyleKey.self] = newValue } 36 | } 37 | } 38 | 39 | private struct TableBorderStyleKey: EnvironmentKey { 40 | static let defaultValue = TableBorderStyle(color: .secondary) 41 | } 42 | 43 | private struct TableBackgroundStyleKey: EnvironmentKey { 44 | static let defaultValue = TableBackgroundStyle.clear 45 | } 46 | -------------------------------------------------------------------------------- /Sources/SwiftUIZ/module.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | @_exported import SwiftUIX 6 | @_exported import _SwiftUIZ_A 7 | @_exported import _SwiftUIZ_B 8 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_A/Intermodular/Extensions/AppKit or UIKit/AppKitOrUIKitImage++.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import Merge 6 | import SwiftUIX 7 | 8 | #if os(macOS) 9 | extension AppKitOrUIKitImage { 10 | public func byPreparingThumbnail( 11 | ofSize thumbnailSize: NSSize 12 | ) async -> AppKitOrUIKitImage { 13 | let _self = _UncheckedSendable(self) 14 | 15 | return await Task(priority: .userInitiated) { () -> _UncheckedSendable in 16 | let thumbnail = NSImage(size: thumbnailSize) 17 | 18 | thumbnail.lockFocus() 19 | 20 | _self.wrappedValue.draw( 21 | in: NSRect(origin: .zero, size: thumbnailSize), 22 | from: NSRect(origin: .zero, size: _self.wrappedValue.size), 23 | operation: .sourceOver, 24 | fraction: 1.0 25 | ) 26 | 27 | thumbnail.unlockFocus() 28 | 29 | return _UncheckedSendable(thumbnail) 30 | } 31 | .value 32 | .wrappedValue 33 | } 34 | } 35 | #endif 36 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_A/Intramodular (WIP)/View Hypergraph/_PGElementID.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import Swallow 6 | import SwiftUI 7 | 8 | public struct _PGElementID: Hashable { 9 | private let localKey: AnyHashable 10 | private let swiftType: ObjectIdentifier 11 | private let interposeScope: _ViewInterposeScope? 12 | @HashIgnored 13 | private var name: () -> String 14 | 15 | public var isOverridden: Bool { 16 | interposeScope != nil 17 | } 18 | 19 | public init( 20 | localKey: AnyHashable, 21 | swiftType: ObjectIdentifier, 22 | interposeScope: _ViewInterposeScope?, 23 | name: @escaping () -> String 24 | ) { 25 | self.localKey = localKey 26 | self.swiftType = swiftType 27 | self.interposeScope = interposeScope 28 | self.name = name 29 | } 30 | } 31 | 32 | // MARK: - Conformances 33 | 34 | extension _PGElementID: CustomStringConvertible { 35 | public var description: String { 36 | if let interposeScope { 37 | return name() + "-override:\(interposeScope)" 38 | } else { 39 | return name() 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_A/Intramodular (WIP)/View Hypergraph/_PropertyGraph.Consumable.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import SwiftUI 6 | 7 | public enum _PropertyGraph { 8 | 9 | } 10 | 11 | extension _PropertyGraph { 12 | public protocol Consumable { 13 | static var _isHiddenConsumable: Bool { get } 14 | 15 | var _isConsumableResolved: Bool { get throws } 16 | 17 | dynamic func __conversion( 18 | context: EnvironmentValues._opaque_InterposeGraphContextProtocol 19 | ) throws -> any _PropertyGraph.Consumable 20 | 21 | func _resolveShallowIdentifier( 22 | in context: some EnvironmentValues._opaque_InterposeGraphContextProtocol 23 | ) throws -> _PGElementID 24 | 25 | func update( 26 | id: _PGElementID, 27 | context: inout Context 28 | ) throws 29 | } 30 | } 31 | 32 | extension _PropertyGraph.Consumable { 33 | public static var _isHiddenConsumable: Bool { 34 | false 35 | } 36 | 37 | public var _isConsumableResolved: Bool { 38 | true 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_A/Intramodular (WIP)/View Hypergraph/_ViewHypergraphPass.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import Swallow 6 | import SwiftUIX 7 | 8 | public protocol _HeavyweightViewHypergraphPass { 9 | associatedtype Target 10 | } 11 | 12 | public struct _HeavyweightViewHypergraphPassContext { 13 | public init() { 14 | 15 | } 16 | } 17 | 18 | public protocol _HeavyweightViewHypergraphPassTarget { 19 | 20 | } 21 | 22 | public protocol _HeavyweightViewHypergraphPassUpdating { 23 | associatedtype SymbolType 24 | 25 | static func update( 26 | _ target: inout Target, 27 | in pass: Pass, 28 | symbol: _AnyViewHypergraph.Symbol, 29 | context: _HeavyweightViewHypergraphPassContext 30 | ) throws 31 | } 32 | 33 | 34 | extension _HeavyweightViewHypergraphPassUpdating { 35 | public static func _typeUnchecked_update( 36 | _ target: inout Target, 37 | in pass: Pass, 38 | symbol: some _AnyViewHypergraph.SymbolType, 39 | context: _HeavyweightViewHypergraphPassContext 40 | ) throws { 41 | try self.update(&target, in: pass, symbol: unsafeBitCast(symbol), context: context) 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_A/Intramodular (WIP)/View Hypergraph/_ViewPrototypeID.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import CorePersistence 6 | import Swallow 7 | 8 | public struct _ViewPrototypeID: CustomStringConvertible, Sendable { 9 | private let base = _AutoIncrementingIdentifier() 10 | 11 | public var description: String { 12 | "#" + base.rawValue.description 13 | } 14 | 15 | public init() { 16 | 17 | } 18 | } 19 | 20 | extension _ViewPrototypeID: IdentifierProtocol { 21 | public var body: some IdentityRepresentation { 22 | base 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_A/Intramodular (WIP)/View Interposing/_InterposedViewBodyBridge.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import _SwiftUI_Internals 6 | import SwiftUI 7 | 8 | open class _InterposedViewBodyBridgeProtocol: _HierarchicalViewBridge<_InterposedViewBodyBridgeProtocol> { 9 | 10 | } 11 | 12 | public class _InterposedViewBodyBridge: _InterposedViewBodyBridgeProtocol { 13 | package var _swiftType: any _DynamicView.Type 14 | 15 | package weak var _bodyStorage: _InterposedViewBodyStorage? 16 | 17 | public var bodyStorage: _InterposedViewBodyStorage { 18 | _bodyStorage! 19 | } 20 | 21 | @usableFromInline 22 | package init(_swiftType: any _DynamicView.Type, _bodyStorage: _InterposedViewBodyStorage?) { 23 | self._swiftType = _swiftType 24 | self._bodyStorage = _bodyStorage 25 | 26 | super.init() 27 | } 28 | } 29 | 30 | // MARK: - Conformances 31 | 32 | extension _InterposedViewBodyBridge: CustomReflectable { 33 | public var customMirror: Mirror { 34 | Mirror(self) { 35 | [ 36 | "type": _swiftType 37 | ] 38 | } 39 | } 40 | } 41 | 42 | // MARK: - Debug 43 | 44 | public struct _DebugInterposedViewBody: View { 45 | @_ViewBridge(_InterposedViewBodyBridge.self) var bridge 46 | 47 | public var body: some View { 48 | _PrintMirrorView(reflecting: bridge) 49 | .border(Color.red) 50 | .frame(maxWidth: 512) 51 | } 52 | 53 | public init() { 54 | 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_A/Intramodular (WIP)/View Interposing/_InterposedViewBodyStorage.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import SwiftUIX 6 | 7 | public final class _InterposedViewBodyStorage: ObservableObject { 8 | public weak var view: _InterposedViewBodyBridge? 9 | 10 | public init() { 11 | 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_A/Intramodular (WIP)/View Interposing/_ViewInterposeError.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import Swallow 6 | 7 | public enum _ViewInterposeError: CustomStringConvertible, Swift.Error, LocalizedError { 8 | case viewGraphMissing 9 | 10 | public var description: String { 11 | switch self { 12 | case .viewGraphMissing: 13 | return "`WindowGroup` needs to be rewritten as `WindowGroup(.dynamic)`" 14 | } 15 | } 16 | 17 | public var errorDescription: String? { 18 | description 19 | } 20 | 21 | public var recoverySuggestion: String? { 22 | switch self { 23 | case .viewGraphMissing: 24 | return "In your SwiftUI app declaration, try changing WindowGroup { ... } to WindowGroup(.dynamic) { ... }" 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_A/Intramodular (WIP)/View Interposing/_ViewInterposeScope.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import SwiftUI 6 | 7 | public final class _ViewInterposeScope: Hashable, ObservableObject { 8 | init() { 9 | 10 | } 11 | } 12 | 13 | extension _ViewInterposeScope { 14 | @inlinable 15 | public func hash(into hasher: inout Hasher) { 16 | hasher.combine(ObjectIdentifier(self)) 17 | } 18 | 19 | @inlinable 20 | public static func == (lhs: _ViewInterposeScope, rhs: _ViewInterposeScope) -> Bool { 21 | lhs === rhs 22 | } 23 | } 24 | 25 | extension _ViewInterposeScope: CustomStringConvertible { 26 | public var description: String { 27 | String(hashValue, radix: 36, uppercase: false) 28 | } 29 | } 30 | 31 | @MainActor 32 | public struct _SetViewInterposeScope: _ThinViewModifier { 33 | @StateObject private var scope = _ViewInterposeScope() 34 | 35 | public init() { 36 | 37 | } 38 | 39 | public func body(content: C) -> some View { 40 | content.transformEnvironment(\._opaque_interposeContext) { context in 41 | if let _context = context { 42 | assert(!_context._isInvalidInstance) 43 | } 44 | 45 | context?.scope = scope 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_A/Intramodular/Bindings/_TypeCastBinding.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import SwiftUIX 6 | 7 | public struct _TypeCastBindingProxy { 8 | var binding: Binding 9 | 10 | public func `as`( 11 | _ type: U.Type, 12 | @ViewBuilder content: @escaping (Binding) -> Content 13 | ) -> _WithTypeCastBinding { 14 | _WithTypeCastBinding(base: self, content: content) 15 | } 16 | } 17 | 18 | public struct _TypeCastBinding: View { 19 | public let binding: Binding 20 | public let content: Content 21 | 22 | public init(_ binding: Binding, @ViewBuilder content: (_TypeCastBindingProxy) -> Content) { 23 | self.binding = binding 24 | self.content = content(.init(binding: binding)) 25 | } 26 | 27 | public var body: some View { 28 | _VariadicViewAdapter(content) { content in 29 | content.children.first(where: { $0[_WithTypeCastBindingTrait.self] != nil }) 30 | } 31 | } 32 | } 33 | 34 | public struct _WithTypeCastBinding: View { 35 | var base: _TypeCastBindingProxy 36 | let content: (Binding) -> Content 37 | 38 | public var body: some View { 39 | let binding = base.binding._conditionalCast(to: U.self) 40 | 41 | if binding.wrappedValue != nil { 42 | content(binding.forceUnwrap()) 43 | .trait(_WithTypeCastBindingTrait()) 44 | } 45 | } 46 | } 47 | 48 | // MARK: - Auxiliary 49 | 50 | fileprivate struct _WithTypeCastBindingTrait: Hashable { 51 | 52 | } 53 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_A/Intramodular/Containers/ContainerGroup.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import Diagnostics 6 | @_spi(Internal) import SwiftUIX 7 | 8 | public struct ContainerGroup: View { 9 | let content: Content 10 | 11 | public init(@ViewBuilder content: () -> Content) { 12 | self.content = content() 13 | } 14 | 15 | public var body: some View { 16 | Group { 17 | content 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_A/Intramodular/Containers/ControlBox.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import SwiftUIX 6 | 7 | public struct ControlBox: View { 8 | public let content: Content 9 | 10 | @FocusState var isFocused: Bool 11 | 12 | public init(@ViewBuilder content: () -> Content) { 13 | self.content = content() 14 | } 15 | 16 | public var body: some View { 17 | content 18 | .focused($isFocused) 19 | .padding(.small) 20 | .onTapGestureOnBackground { 21 | isFocused = true 22 | } 23 | .background(HierarchicalShapeStyle.quaternary) 24 | .cornerRadius(4) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_A/Intramodular/Dynamic Properties/_LazyState.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import Combine 6 | import SwiftUI 7 | 8 | @frozen 9 | @propertyWrapper 10 | public struct _LazyState: _SwiftUIZ_DynamicProperty { 11 | @usableFromInline 12 | class Storage: ObservableObject { 13 | var makeValue: (() -> Value)? 14 | var _value: Value? 15 | 16 | var value: Value { 17 | get { 18 | evaluate() 19 | } set { 20 | _value = newValue 21 | } 22 | } 23 | 24 | private func evaluate() -> Value { 25 | if let _value { 26 | return _value 27 | } 28 | 29 | self._value = makeValue!() 30 | 31 | self.makeValue = nil 32 | 33 | return self._value! 34 | } 35 | 36 | @usableFromInline 37 | init(value: @escaping () -> Value) { 38 | self.makeValue = value 39 | } 40 | } 41 | 42 | @usableFromInline 43 | var _storage: StateObject 44 | 45 | public var wrappedValue: Value { 46 | get { 47 | _storage.wrappedValue.value 48 | } 49 | } 50 | 51 | @inlinable 52 | public init(wrappedValue: @autoclosure @escaping () -> Value) { 53 | self._storage = .init(wrappedValue: Storage(value: wrappedValue)) 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_A/Intramodular/Dynamic Properties/_SwiftUIZ_DynamicProperty.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import Swallow 6 | import _SwiftUIX 7 | 8 | public protocol _SwiftUIZ_DynamicProperty: Swallow.PropertyWrapper, SwiftUI.DynamicProperty, _SwiftUIX._SwiftUIX_PropertyWrapper { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_A/Intramodular/Dynamic Properties/_UpdatePhase.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import Combine 6 | import SwiftUI 7 | 8 | /// A property wrapper that automatically updates its value when the `View` it is attached to updates. 9 | /// 10 | /// From [Engine](http://github.com/nathantannar4/Engine). 11 | @propertyWrapper 12 | @frozen 13 | public struct _UpdatePhase: _SwiftUIZ_DynamicProperty { 14 | @frozen 15 | public struct Value: Hashable { 16 | @usableFromInline 17 | var phase: UInt32 18 | 19 | @inlinable 20 | public init() { 21 | self.phase = 0 22 | } 23 | 24 | mutating func update() { 25 | phase = phase &+ 1 26 | } 27 | } 28 | 29 | @usableFromInline 30 | var storage: StateObject 31 | 32 | public var wrappedValue: Value { 33 | storage.wrappedValue.value 34 | } 35 | 36 | @inlinable 37 | public init() { 38 | self.storage = StateObject(wrappedValue: Storage(value: Value())) 39 | } 40 | 41 | public mutating func update() { 42 | storage.wrappedValue.value.update() 43 | } 44 | } 45 | 46 | // MARK: - Auxiliary 47 | 48 | extension _UpdatePhase { 49 | @usableFromInline 50 | final class Storage: ObservableObject { 51 | var value: Value 52 | 53 | @usableFromInline 54 | init(value: Value) { 55 | self.value = value 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_A/Intramodular/Event Management/_EventModifiersMonitor.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import Combine 6 | import SwiftUIX 7 | 8 | #if os(macOS) 9 | extension EventModifiers { 10 | public static var _currentlyActive: Self { 11 | EventModifiers(_appKitModifierFlags: NSEvent.modifierFlags) 12 | } 13 | } 14 | #else 15 | extension EventModifiers { 16 | public static var _currentlyActive: Self { 17 | fatalError("unimplemented") 18 | } 19 | } 20 | #endif 21 | 22 | /// Monitors changes to the current active `EventModifiers`. 23 | public class _EventModifiersMonitor: ObservableObject { 24 | public static let shared = _EventModifiersMonitor() 25 | 26 | @Published public private(set) var modifiers: EventModifiers = ._currentlyActive 27 | 28 | #if os(macOS) 29 | private var monitor: NSEventMonitor! 30 | #endif 31 | 32 | private init() { 33 | #if os(macOS) 34 | monitor = NSEventMonitor(context: .global, matching: .flagsChanged) { event -> NSEvent? in 35 | self.modifiers = ._currentlyActive 36 | 37 | return event 38 | } 39 | #endif 40 | } 41 | } 42 | 43 | // MARK: - Supplementary 44 | 45 | @MainActor 46 | extension View { 47 | public func disablesHitTesting( 48 | forModifiers modifiers: EventModifiers = [] 49 | ) -> some View { 50 | withInlineObservedObject(_EventModifiersMonitor.shared) { monitor in 51 | allowsHitTesting(monitor.modifiers.intersection(modifiers).isEmpty) 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_A/Intramodular/Focus Management/View._focusRingVisibility.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import SwiftUIIntrospect 6 | import SwiftUIX 7 | 8 | #if os(iOS) 9 | extension View { 10 | public func _focusRingVisibility(_ visibility: Visibility) -> some View { 11 | self 12 | } 13 | } 14 | #elseif os(macOS) 15 | extension View { 16 | public func _focusRingVisibility(_ visibility: Visibility) -> some View { 17 | self.introspect(.textField, on: .macOS(.v11, .v12, .v13)) { (textField: AppKitOrUIKitTextField) in 18 | if visibility == .visible { 19 | textField.focusRingType = .exterior 20 | } else if visibility == .hidden { 21 | textField.focusRingType = .none 22 | } else { 23 | textField.focusRingType = .default 24 | } 25 | } 26 | } 27 | } 28 | #endif 29 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_A/Intramodular/Focus Management/_FocusOnAppear.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import SwiftUI 6 | 7 | private struct _FocusOnAppear: ViewModifier { 8 | @FocusState private var isFocused: Bool 9 | 10 | func body(content: Content) -> some View { 11 | content.focused($isFocused).onAppear { 12 | isFocused = true 13 | 14 | withAnimation(after: .milliseconds(50)) { 15 | isFocused = true 16 | } 17 | } 18 | } 19 | } 20 | 21 | private struct _AddFocusActivatingBackground: ViewModifier { 22 | @FocusState private var isFocused: Bool 23 | 24 | let background: Background 25 | 26 | func body(content: Content) -> some View { 27 | content 28 | .focused($isFocused) 29 | .background { 30 | background.onTapGesture { 31 | isFocused = true 32 | } 33 | } 34 | } 35 | } 36 | 37 | // MARK: - API 38 | 39 | extension View { 40 | /// Set the focus state of this view when it appears. 41 | public func _focusOnAppear() -> some View { 42 | modifier(_FocusOnAppear()) 43 | } 44 | 45 | public func _focusActivatingBackground( 46 | @ViewBuilder content: () -> V 47 | ) -> some View { 48 | modifier(_AddFocusActivatingBackground(background: content())) 49 | } 50 | 51 | public func _focusActivatingBackground() -> some View { 52 | _focusActivatingBackground { 53 | Rectangle() 54 | .fill(Color.almostClear) 55 | .contentShape(Rectangle()) 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_A/Intramodular/Focus Management/_FocusRingDrawing.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import Swallow 6 | import SwiftUIX 7 | 8 | public struct _FocusRingDrawing: AppKitOrUIKitViewRepresentable { 9 | public let draw: Bool 10 | 11 | public init(draw: Bool) { 12 | self.draw = draw 13 | } 14 | 15 | public func makeAppKitOrUIKitView(context: Context) -> AppKitOrUIKitViewType { 16 | AppKitOrUIKitViewType() 17 | } 18 | 19 | public func updateAppKitOrUIKitView(_ view: AppKitOrUIKitViewType, context: Context) { 20 | view.drawFocusRing = draw 21 | } 22 | } 23 | 24 | #if os(iOS) || os(tvOS) || os(visionOS) || os(watchOS) 25 | extension _FocusRingDrawing { 26 | public class AppKitOrUIKitViewType: AppKitOrUIKitView { 27 | fileprivate var drawFocusRing: Bool = false 28 | } 29 | } 30 | #elseif os(macOS) 31 | extension _FocusRingDrawing { 32 | public class AppKitOrUIKitViewType: AppKitOrUIKitView { 33 | fileprivate var drawFocusRing: Bool = false { 34 | didSet { 35 | guard drawFocusRing != oldValue else { 36 | return 37 | } 38 | 39 | self.needsDisplay = true 40 | } 41 | } 42 | 43 | override public func draw(_ dirtyRect: NSRect) { 44 | super.draw(dirtyRect) 45 | 46 | if drawFocusRing { 47 | NSFocusRingPlacement.only.set() 48 | NSGraphicsContext.saveGraphicsState() 49 | NSFocusRingPlacement.only.set() 50 | 51 | self.bounds.fill() 52 | 53 | NSGraphicsContext.restoreGraphicsState() 54 | } 55 | } 56 | } 57 | } 58 | #endif 59 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_A/Intramodular/Focus Management/_FocusableViewConfiguration.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import SwiftUI 6 | import SwiftUIX 7 | import UniformTypeIdentifiers 8 | 9 | public struct _FocusableViewConfiguration: ExpressibleByNilLiteral { 10 | public enum Mode { 11 | case `default` 12 | case accessory 13 | } 14 | 15 | public var mode: Mode = .default 16 | public var _fixedSize: (horizontal: Bool, vertical: Bool)? = nil 17 | public var onMoveCommand: ((_SwiftUIX_MoveCommandDirection) -> Void)? 18 | public var onExitCommand: (() -> Void)? 19 | public var onDeleteCommand: (() -> Void)? 20 | 21 | public var pasteCommandHandler: _SwiftUIX_AnyPasteCommandDelegate? 22 | 23 | public init( 24 | mode: Mode, 25 | _fixedSize: (horizontal: Bool, vertical: Bool)? = nil, 26 | onMoveCommand: ((_SwiftUIX_MoveCommandDirection) -> Void)? = nil, 27 | onExitCommand: (() -> Void)? = nil, 28 | onDeleteCommand: (() -> Void)? = nil, 29 | pasteCommandHandler: _SwiftUIX_AnyPasteCommandDelegate? = nil 30 | ) { 31 | self.mode = mode 32 | self._fixedSize = _fixedSize 33 | self.onMoveCommand = onMoveCommand 34 | self.onExitCommand = onExitCommand 35 | self.onDeleteCommand = onDeleteCommand 36 | self.pasteCommandHandler = pasteCommandHandler 37 | } 38 | 39 | public init(nilLiteral: ()) { 40 | 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_A/Intramodular/Focus Management/_SwiftUIX_FocusInteractions.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import Swallow 6 | @_spi(Internal) import SwiftUIX 7 | 8 | public struct _SwiftUIX_FocusInteractions: Hashable, OptionSet { 9 | public let rawValue: UInt 10 | 11 | public init(rawValue: UInt) { 12 | self.rawValue = rawValue 13 | } 14 | 15 | public static let activate = Self(rawValue: 1 << 0) 16 | public static let edit = Self(rawValue: 1 << 1) 17 | } 18 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_A/Intramodular/Forms/_DisableFormStyling.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import Swift 6 | import SwiftUIIntrospect 7 | @_spi(Internal) import SwiftUIX 8 | 9 | struct _DisableFormStyling: ViewModifier { 10 | func body(content: Content) -> some View { 11 | Section { 12 | EmptyView() 13 | } header: { 14 | ZStack { 15 | HSpacer() 16 | 17 | content 18 | } 19 | } 20 | } 21 | } 22 | 23 | extension View { 24 | public func _disableFormStyling() -> some View { 25 | modifier(_DisableFormStyling()) 26 | } 27 | } 28 | 29 | @available(tvOS, unavailable) 30 | @available(watchOS, unavailable) 31 | extension View { 32 | public func _stripAllListOrListItemStyling() -> some View { 33 | self.modifier(_StipAllListItemStyling(insetsIncluded: false)) 34 | .listStyle(.plain) 35 | .scrollContentBackground(.hidden) 36 | } 37 | } 38 | 39 | public struct _StipAllListItemStyling: ViewModifier { 40 | public let insetsIncluded: Bool 41 | 42 | public init(insetsIncluded: Bool) { 43 | self.insetsIncluded = insetsIncluded 44 | } 45 | 46 | public func body(content: Content) -> some View { 47 | content 48 | .listRowSeparator(.hidden) 49 | .listSectionSeparator(.hidden) 50 | .listRowInsets(insetsIncluded ? .zero : nil) 51 | .listItemTint(Optional.none) 52 | .listRowBackground(Color.clear) 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_A/Intramodular/Layout/FrameRelativeValue.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import Swallow 6 | @_spi(Internal) import SwiftUIX 7 | 8 | @MainActor 9 | public struct FrameRelativeValue { 10 | public let value: @MainActor (CGSize) -> Value 11 | 12 | public init(_ value: @escaping @MainActor @Sendable (CGSize) -> Value) { 13 | self.value = value 14 | } 15 | 16 | public init() where Value == CGFloat { 17 | self.value = { _ in 0 } 18 | } 19 | } 20 | 21 | extension FrameRelativeValue where Value == CGFloat { 22 | public static var width: Self { 23 | Self({ $0.width }) 24 | } 25 | 26 | public static var height: Self { 27 | Self({ $0.height }) 28 | } 29 | } 30 | 31 | extension View { 32 | public func relativeOffset( 33 | x: FrameRelativeValue 34 | ) -> some View { 35 | self 36 | } 37 | } 38 | 39 | extension CGSize { 40 | @MainActor 41 | public func resolve( 42 | width: FrameRelativeValue, 43 | height: FrameRelativeValue 44 | ) -> CGSize { 45 | return CGSize( 46 | width: width.value(self), 47 | height: height.value(self) 48 | ) 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_A/Intramodular/Layout/Padding.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import SwiftUIX 6 | 7 | public struct Padding: View { 8 | public var body: some View { 9 | ZeroSizeView() 10 | .padding(.extraSmall) 11 | .modifier(_StipAllListItemStyling(insetsIncluded: false)) 12 | .accessibilityHidden(true) 13 | .opacity(0) 14 | } 15 | 16 | public init() { 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_A/Intramodular/Miscellaneous/Hierarchical View Bridge/_ViewBridge.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import Swallow 6 | import SwiftUI 7 | 8 | @propertyWrapper 9 | public struct _ViewBridge: DynamicProperty { 10 | @Environment(\.[_viewBridgeType: Metatype(T.InstanceType.self)]) var _bridge: Weak 11 | 12 | public var wrappedValue: T { 13 | _bridge.wrappedValue as! T 14 | } 15 | 16 | public init(_: T.Type) { 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_A/Intramodular/Miscellaneous/InterfaceModel.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import Swallow 6 | import SwiftUI 7 | 8 | public protocol InterfaceModel: Identifiable where ID: InterfaceModelIdentifier { 9 | 10 | } 11 | 12 | public protocol InterfaceModelIdentifier: InterfaceModel, Hashable, Sendable where ID == Self { 13 | associatedtype Model: InterfaceModel 14 | } 15 | 16 | // MARK: - Conformees 17 | 18 | extension _TypeAssociatedID: InterfaceModel where Parent: InterfaceModel { 19 | 20 | } 21 | 22 | extension _TypeAssociatedID: InterfaceModelIdentifier where Parent: InterfaceModel { 23 | public typealias Model = Parent 24 | } 25 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_A/Intramodular/Miscellaneous/_DynamicView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import Swallow 6 | import SwiftUI 7 | 8 | public protocol _DynamicView: CustomSourceDeclarationReflectable, View { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_A/Intramodular/Navigation/_SelfSizingNavigationStack.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import SwiftUIX 6 | 7 | public struct _SelfSizingNavigationStack: View { 8 | private enum _ViewElement { 9 | case content 10 | } 11 | 12 | public let content: Content 13 | 14 | public init(@ViewBuilder content: () -> Content) { 15 | self.content = content() 16 | } 17 | 18 | public var body: some View { 19 | FrameReader { proxy in 20 | NavigationStack { 21 | Group { 22 | content 23 | ._scrollBounceBehaviorBasedOnSizeIfAvailable() 24 | .frame(id: _ViewElement.content) 25 | .frame(minWidth: 44, minHeight: 44) 26 | } 27 | } 28 | .frame(width: proxy.size(for: _ViewElement.content)?.width) 29 | .frame( 30 | minHeight: proxy.size(for: _ViewElement.content).map({ $0.height + 44 }), 31 | idealHeight: proxy.size(for: _ViewElement.content).map({ $0.height + 44 }) 32 | ) 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_A/Intramodular/Pasteboard/_SwiftUIX_AnyPasteCommandDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import SwiftUI 6 | import UniformTypeIdentifiers 7 | 8 | public struct _SwiftUIX_AnyPasteCommandDelegate { 9 | public var supportedContentTypes: [UTType] 10 | public var action: ([NSItemProvider]) -> Void 11 | 12 | public init( 13 | supportedContentTypes: [UTType], 14 | action: @escaping ([NSItemProvider]) -> Void 15 | ) { 16 | self.supportedContentTypes = supportedContentTypes 17 | self.action = action 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_A/Intramodular/Reflection/_StaticViewTypeDescriptorKey.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import Swallow 6 | import SwiftUI 7 | 8 | public protocol _StaticViewTypeDescriptorKey: HeterogeneousDictionaryKey where Self.Domain == _StaticViewTypeDescriptor { 9 | static var defaultValue: Value { get } 10 | } 11 | 12 | extension _StaticViewTypeDescriptor { 13 | public protocol StaticUpdater { 14 | static func update( 15 | _ descriptor: inout _StaticViewTypeDescriptor, 16 | context: _StaticViewTypeDescriptor.UpdateContext 17 | ) throws 18 | } 19 | } 20 | 21 | // MARK: - Implementation 22 | 23 | extension _StaticViewTypeDescriptorKey where Value: Initiable { 24 | package static var defaultValue: Value { 25 | Value() 26 | } 27 | } 28 | 29 | extension _GenericHeterogeneousDictionaryKey: _StaticViewTypeDescriptorKey where Self.Domain == _StaticViewTypeDescriptor, Self.Value: Initiable { 30 | public static var defaultValue: Value { 31 | Value() 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_A/Intramodular/Scenes/NavigationDetailGroup.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import Swallow 6 | import SwiftUI 7 | 8 | /// A scene that represents a navigation detail. 9 | @MainActor 10 | public struct NavigationDetailGroup: _SwiftUIZ_Scene { 11 | public let initializer: _DynamicSceneInitializerGroup 12 | 13 | public init( 14 | for type: Value.Type, 15 | @ViewBuilder content: @escaping (Value) -> Content, 16 | validate: @escaping (Value) -> Bool 17 | ) { 18 | self.initializer = _DynamicSceneInitializerGroup( 19 | id: Metatype(Self.self), 20 | initializers: [ 21 | _AnyDynamicSceneInitializer( 22 | erasing: _DynamicSceneInitializers.ValueBased(value: { value -> _AnySceneContent? in 23 | if validate(value) { 24 | return _AnySceneContent { 25 | content(value) 26 | } 27 | } else { 28 | return nil 29 | } 30 | }) 31 | ) 32 | ] 33 | ) 34 | } 35 | 36 | public var body: some _SwiftUIZ_Scene { 37 | _DonateDynamicSceneInitializer { 38 | initializer 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_A/Intramodular/Scenes/PresentationGroup.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import Swallow 6 | import SwiftUIX 7 | 8 | /// A scene that represents a presentation. 9 | public struct PresentationGroup: _SwiftUIZ_Scene { 10 | public let initializer: _DynamicSceneInitializerGroup 11 | 12 | public init(@ViewBuilder content: () -> Content) { 13 | self.initializer = _DynamicSceneInitializerGroup( 14 | id: Metatype(Self.self), 15 | initializers: [ 16 | _AnyDynamicSceneInitializer( 17 | erasing: _DynamicSceneInitializers.ResolvedContent(content: content()) 18 | ) 19 | ] 20 | ) 21 | } 22 | 23 | public var body: some _SwiftUIZ_Scene { 24 | _DonateDynamicSceneInitializer { 25 | initializer 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_A/Intramodular/Scenes/_DonateDynamicSceneInitializer.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import SwiftUI 6 | 7 | @MainActor 8 | public struct _DonateDynamicSceneInitializer: _SwiftUIZ_PrimitiveScene, _SwiftUIZ_Scene { 9 | let content: () -> [_DynamicSceneInitializerGroup] 10 | 11 | public init(content: @escaping () -> [_DynamicSceneInitializerGroup]) { 12 | self.content = content 13 | } 14 | 15 | public init(content: @escaping () -> _DynamicSceneInitializerGroup) { 16 | self.init(content: { [content()] }) 17 | } 18 | 19 | public var body: some _SwiftUIZ_MaybePrimitiveScene { 20 | _ = { 21 | _DynamicSceneManager.shared._register(content()) 22 | }() 23 | 24 | return WindowGroup(id: UUID().uuidString) { 25 | ZeroSizeView() 26 | } 27 | } 28 | 29 | func _resolve() -> [_DynamicSceneInitializerGroup] { 30 | content() 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_A/Intramodular/Scenes/_DynamicScene.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import SwiftUI 6 | 7 | public protocol _DynamicScene: _SwiftUIZ_MaybePrimitiveScene { 8 | 9 | } 10 | 11 | extension Scene { 12 | public func hidden() -> some _DynamicScene { 13 | SwiftUI._EmptyScene() 14 | } 15 | } 16 | 17 | extension SwiftUI._EmptyScene: _DynamicScene { 18 | public var body: Never { 19 | fatalError() 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_A/Intramodular/Scenes/_DynamicSceneManager.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import Combine 6 | import CorePersistence 7 | import SwiftUIX 8 | 9 | @Singleton 10 | public final class _DynamicSceneManager: ObservableObject { 11 | @Published public var scenes: IdentifierIndexingArrayOf<_DynamicSceneInitializerGroup> = [] 12 | 13 | func _register(_ scenes: [_DynamicSceneInitializerGroup]) { 14 | self.scenes.append(contentsOf: scenes) 15 | } 16 | 17 | func initializer( 18 | for parameters: _SwiftUIZ_AnyDynamicSceneInitializerParameters 19 | ) throws -> (any _DynamicSceneInitializer)? { 20 | scenes.first(byUnwrapping: { group in 21 | group.initializers.first(where: { 22 | (try? $0.resolve(from: parameters)) != nil 23 | }) 24 | }) 25 | } 26 | 27 | public func resolveContent( 28 | for instance: T 29 | ) -> (some _SceneContent)? { 30 | #try(.optimistic) { 31 | try self._resolve_SceneContent(for: .init(value: instance)) 32 | } 33 | } 34 | 35 | package func _resolve_SceneContent( 36 | for parameters: _SwiftUIZ_AnyDynamicSceneInitializerParameters 37 | ) throws -> _AnySceneContent? { 38 | guard let initializer = try initializer(for: parameters) else { 39 | runtimeIssue("Failed to find a scene initializer.") 40 | 41 | return nil 42 | } 43 | 44 | guard let content = try initializer.resolve(from: parameters) else { 45 | runtimeIssue("Failed to initialize the scene content.") 46 | 47 | return nil 48 | } 49 | 50 | return content 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_A/Intramodular/Scenes/_InitializeSceneContent.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import Swallow 6 | 7 | package struct _InitializeSceneContent: View { 8 | @StateObject private var sceneManager: _DynamicSceneManager = .shared 9 | 10 | @_LazyState private var _resolvedContent: _AnySceneContent? 11 | 12 | init( 13 | _resolvedContent: _AnySceneContent 14 | ) { 15 | __resolvedContent = .init(wrappedValue: _resolvedContent) 16 | } 17 | 18 | public init( 19 | parameters: _SwiftUIZ_AnyDynamicSceneInitializerParameters 20 | ) { 21 | let sceneManager = _DynamicSceneManager.shared 22 | 23 | self.__resolvedContent = .init( 24 | wrappedValue: try! sceneManager._resolve_SceneContent(for: parameters) 25 | ) 26 | } 27 | 28 | public var body: some View { 29 | if let _resolvedContent { 30 | _resolvedContent 31 | } else { 32 | _UnimplementedView() 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_A/Intramodular/Scenes/_InterposedSceneContent.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import SwiftUIX 6 | 7 | /// A view that is the root of a `Scene` and has been interposed. 8 | public protocol _InterposedSceneContent: View { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_A/Intramodular/Scenes/_RuntimeDiscoveredScenes.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import CorePersistence 6 | import Merge 7 | import Runtime 8 | import Swallow 9 | import SwiftUIX 10 | 11 | /// Scenes discovered at runtime using `_RuntimeTypeDiscoveryIndex`. 12 | public struct _RuntimeDiscoveredScenes: _DynamicScene { 13 | @_StaticMirrorQuery(type: (any Scene).self, predicates: [.nonAppleFramework, .pureSwift]) 14 | private static var allSceneTypes: [any Scene.Type] 15 | 16 | public init() { 17 | 18 | } 19 | 20 | public var body: some Scene { 21 | _DonateDynamicSceneInitializer { 22 | try! Self.allSceneTypes.flatMap { sceneType -> [_DynamicSceneInitializerGroup] in 23 | guard !(sceneType is any _SwiftUIZ_PrimitiveScene.Type) else { 24 | return [] 25 | } 26 | 27 | typealias InitiableScene = Initiable & Scene 28 | 29 | switch sceneType { 30 | case Self.self: 31 | return [] 32 | case Never.self: 33 | return [] 34 | default: 35 | break 36 | } 37 | 38 | guard let sceneType = sceneType as? any InitiableScene.Type else { 39 | return [] 40 | } 41 | 42 | let scene = sceneType.init() 43 | 44 | guard let _scene = scene.body as? any _SwiftUIZ_Scene else { 45 | return [] 46 | } 47 | 48 | return try _scene._resolve() 49 | } 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_A/Intramodular/Scenes/_SceneConfiguration.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import SwiftUIX 6 | 7 | public struct _SceneConfiguration { 8 | public var role: _SceneRole = [] 9 | 10 | public init(role: _SceneRole) { 11 | self.role = role 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_A/Intramodular/Scenes/_SceneRole.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import SwallowMacrosClient 6 | import SwiftUI 7 | 8 | @OptionSet 9 | public struct _SceneRole { 10 | private enum Options: Int { 11 | case documentBrowser 12 | case documentEditor 13 | case documentViewer 14 | case form 15 | case inspector 16 | case preview 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_A/Intramodular/Scenes/_SwiftUIZ_Scene.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import Swallow 6 | import SwallowMacrosClient 7 | import SwiftUI 8 | 9 | @MainActor 10 | public protocol _SwiftUIZ_MaybePrimitiveScene: Scene { 11 | var body: Body { get } 12 | } 13 | 14 | @MainActor 15 | public protocol _SwiftUIZ_PrimitiveScene: _SwiftUIZ_MaybePrimitiveScene { 16 | 17 | } 18 | 19 | @MainActor 20 | public protocol _SwiftUIZ_Scene: _SwiftUIZ_MaybePrimitiveScene where Body: _SwiftUIZ_MaybePrimitiveScene { 21 | var body: Body { get } 22 | } 23 | 24 | // MARK: - Conformees 25 | 26 | @MainActor 27 | public struct SceneThatMakesSense: _SwiftUIZ_PrimitiveScene, _SwiftUIZ_Scene { 28 | private var content: [any Scene] 29 | 30 | public init( 31 | @ArrayBuilder content: () -> [any Scene] 32 | ) { 33 | self.content = content() 34 | } 35 | 36 | public var body: some _SwiftUIZ_Scene { 37 | _DonateDynamicSceneInitializer { 38 | try! content.flatMap { 39 | try cast($0, to: (any _SwiftUIZ_Scene).self)._resolve() 40 | } 41 | } 42 | } 43 | } 44 | 45 | @MainActor 46 | extension _SwiftUIZ_Scene { 47 | public func _resolve() throws -> [_DynamicSceneInitializerGroup] { 48 | if let _self = self as? _DonateDynamicSceneInitializer { 49 | return _self._resolve() 50 | } else if let body = body as? _DonateDynamicSceneInitializer { 51 | return body._resolve() 52 | } else { 53 | #throw 54 | } 55 | } 56 | } 57 | 58 | #if os(macOS) 59 | extension Window: _SwiftUIZ_MaybePrimitiveScene { 60 | 61 | } 62 | #endif 63 | 64 | extension WindowGroup: _SwiftUIZ_MaybePrimitiveScene { 65 | 66 | } 67 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_A/Intramodular/Scroll View/_ConditionalScrollView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import SwiftUIX 6 | 7 | public struct _ConditionalScrollView: View { 8 | public let scrollEnabled: Bool 9 | public let content: Content 10 | 11 | public init( 12 | scrollEnabled: Bool, 13 | @ViewBuilder content: () -> Content 14 | ) { 15 | self.scrollEnabled = scrollEnabled 16 | self.content = content() 17 | } 18 | 19 | public var body: some View { 20 | if !scrollEnabled { 21 | content 22 | } else { 23 | ScrollView(showsIndicators: true) { 24 | content 25 | } 26 | ._scrollBounceBehaviorBasedOnSizeIfAvailable() 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_A/Intramodular/Utilities/ModifiedContentProtocol.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import SwiftUI 6 | 7 | public protocol ModifiedContentProtocol { 8 | associatedtype ContentType 9 | 10 | var content: ContentType { get } 11 | } 12 | 13 | extension ModifiedContent: ModifiedContentProtocol { 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_A/Intramodular/Utilities/TaskLocal++.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import Swift 6 | import SwiftUI 7 | 8 | extension TaskLocal { 9 | @MainActor 10 | public func _makeViewWithValue( 11 | _ value: Value, 12 | @ViewBuilder content: @MainActor () -> Content, 13 | start: @MainActor () -> Void, 14 | end: @MainActor () -> Void 15 | ) -> Content { 16 | start() 17 | 18 | let result = self.withValue(value) { 19 | content() 20 | } 21 | 22 | end() 23 | 24 | return result 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_A/Intramodular/Utilities/_AnyViewWrapper.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import SwiftUI 6 | 7 | /// A marker protocol for views that essentially just wrap an `AnyView`. 8 | /// 9 | /// Potential bottleneck for performance and a potential refactoring task once I understand SwiftUI graph stuff better. 10 | public protocol _AnyViewWrapper { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_A/Intramodular/Utilities/_UnimplementedView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import Swallow 6 | import SwiftUIX 7 | 8 | @frozen 9 | public struct _RuntimeWarningView: View { 10 | @usableFromInline 11 | let raiseIssue: () -> Void 12 | 13 | public var body: some View { 14 | Image(systemName: .exclamationmarkTriangleFill) 15 | .foregroundColor(.yellow) 16 | .padding(.small) 17 | .border(Color.red) 18 | .onAppear(perform: raiseIssue) 19 | } 20 | 21 | public init( 22 | _ warning: StaticString, 23 | file: StaticString = #file, 24 | line: UInt = #line 25 | ) { 26 | raiseIssue = { 27 | runtimeIssue(warning, file: file, line: line) 28 | } 29 | } 30 | } 31 | 32 | @frozen 33 | public struct _UnimplementedView: View { 34 | @_transparent 35 | public var body: some View { 36 | Image(systemName: .exclamationmarkTriangleFill) 37 | .foregroundColor(.yellow) 38 | .padding(.small) 39 | .border(Color.red) 40 | } 41 | 42 | @_transparent 43 | public init( 44 | _ warning: StaticString? = nil, 45 | file: StaticString = #file, 46 | line: UInt = #line 47 | ) { 48 | runtimeIssue(warning ?? "This view is unimplemented.", file: file, line: line) 49 | } 50 | } 51 | 52 | extension Color { 53 | @_transparent 54 | public static var unimplemented: Self { 55 | runtimeIssue("This color is unimplemented.") 56 | 57 | return .cyan 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_A/Intramodular/Utilities/_UnsafelyAdaptingView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import SwiftUI 6 | 7 | public protocol _UnsafelyAdaptingView: View { 8 | associatedtype _UnsafeBody: View 9 | 10 | var _unsafeBody: _UnsafeBody { get } 11 | } 12 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_A/Intramodular/Utilities/__static_SwiftUI_View_transformEnvironment.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import SwiftUI 6 | 7 | public protocol _SwiftUI_View_transformEnvironment { 8 | associatedtype EnvironmentValueType 9 | 10 | var environmentKey: WritableKeyPath { get } 11 | 12 | func transformEnvironment( 13 | _ environment: inout EnvironmentValueType, 14 | for view: View 15 | ) 16 | } 17 | 18 | public protocol __static_SwiftUI_View_transformEnvironment { 19 | associatedtype EnvironmentValueType 20 | 21 | static var environmentKey: WritableKeyPath { get } 22 | 23 | static func transformEnvironment( 24 | _ view: View, 25 | transform: @escaping (inout EnvironmentValueType) -> Void 26 | ) 27 | } 28 | 29 | extension _SwiftUIX_ViewModifiers { 30 | public struct _SwiftUI_View_transformEnvironment: ViewModifier { 31 | let transformEnvironment: T 32 | 33 | public func body(content: Content) -> some View { 34 | content.transformEnvironment(transformEnvironment.environmentKey) { environment in 35 | transformEnvironment.transformEnvironment(&environment, for: content) 36 | } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_A/Intramodular/View Traits/_SwiftUIX_ViewTraitValuesReader.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import Diagnostics 6 | @_spi(Internal) import SwiftUIX 7 | 8 | public struct _SwiftUIX_ViewTraitsReader: View { 9 | let content: (_SwiftUIX_ViewTraitValues) -> Content 10 | 11 | public init(@ViewBuilder content: @escaping (_SwiftUIX_ViewTraitValues) -> Content) { 12 | self.content = content 13 | } 14 | 15 | @ViewStorage var traits: _SwiftUIX_ViewTraitValues = .init() 16 | 17 | public var body: some View { 18 | _VariadicViewAdapter(self.content(traits)) { content in 19 | let _: Void = _validate(content.children) 20 | 21 | if let view = content.children.first { 22 | let _: Void = { 23 | traits = view[_SwiftUIX_ViewTraitValues._ViewTraitKey.self] 24 | }() 25 | 26 | self.content(traits) 27 | } 28 | } 29 | } 30 | 31 | private func _validate(_ children: _VariadicViewChildren) { 32 | guard children.count == 1 else { 33 | runtimeIssue("_UnaryViewTraitReader expected to read a single view, but got: \(children.count)") 34 | 35 | return 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_A/Intramodular/View Traits/_ViewTraitsRepresentingView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import SwiftUIX 6 | 7 | /// A view trait expressed as a view. 8 | public protocol _ViewTraitsRepresentingView: View where Body == _ViewTraitsRepresentingView_Body { 9 | var body: _ViewTraitsRepresentingView_Body { get } 10 | 11 | func write(to _: inout TraitValues) 12 | } 13 | 14 | // MARK: - Implementation 15 | 16 | extension _ViewTraitsRepresentingView { 17 | public var body: _ViewTraitsRepresentingView_Body { 18 | _ViewTraitsRepresentingView_Body { 19 | var values = _ViewTraitsRepresentingView_Builder() 20 | 21 | self.write(to: &values) 22 | 23 | return values.view 24 | .eraseToAnyView() 25 | .accessibilityHidden(true) 26 | } 27 | } 28 | } 29 | 30 | // MARK: - Internal 31 | 32 | private struct _ViewTraitsRepresentingView_Builder: _ViewTraitValuesProtocol { 33 | var view: any View = ZeroSizeView() 34 | 35 | subscript( 36 | _ key: Key.Type 37 | ) -> Key.Value { 38 | get { 39 | assertionFailure() 40 | 41 | return Key.defaultValue 42 | } set { 43 | view = view._trait(key, newValue) 44 | } 45 | } 46 | } 47 | 48 | public struct _ViewTraitsRepresentingView_Body: View { 49 | let content: AnyView 50 | 51 | public var body: some View { 52 | content 53 | } 54 | 55 | fileprivate init(content: () -> Content) { 56 | self.content = content().eraseToAnyView() 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_A/Intramodular/Window/_WindowConfigurator.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import Swallow 6 | import SwiftUIX 7 | 8 | #if os(macOS) 9 | struct _SwiftUIX_WindowConfiguration { 10 | let backgroundColor: Color? 11 | } 12 | 13 | @available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *) 14 | struct _WindowConfigurator: ViewModifier { 15 | let configuration: _SwiftUIX_WindowConfiguration 16 | 17 | @State private var window = Weak() 18 | 19 | func body(content: Content) -> some View { 20 | fatalError() 21 | } 22 | } 23 | #endif 24 | 25 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_A/macros.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import Swift 6 | 7 | @attached(peer, names: suffixed(_ViewTraitKey)) 8 | @attached(extension, names: arbitrary) 9 | public macro _ViewTrait() = #externalMacro(module: "SwiftUIZ_Macros", type: "_ViewTraitValueMacro") 10 | 11 | @attached(member, names: arbitrary) 12 | public macro _ViewTraitKey(for: T.Type, named: String) = #externalMacro(module: "SwiftUIZ_Macros", type: "_ViewTraitKeyMacro") 13 | 14 | @attached(peer, names: suffixed(_ViewTraitKey)) 15 | @attached(extension, names: arbitrary) 16 | public macro _ViewTrait(_: String) = #externalMacro(module: "SwiftUIZ_Macros", type: "_ViewTraitValueMacro") 17 | 18 | /// Credits: 19 | /// - https://github.com/Wouter01/SwiftUI-Macros/tree/main 20 | @attached(peer, names: prefixed(EnvironmentKey_)) 21 | @attached(accessor, names: named(get), named(set)) 22 | public macro EnvironmentValue() = #externalMacro(module: "SwiftUIZ_Macros", type: "EnvironmentValueMacro") 23 | 24 | @attached(memberAttribute) 25 | public macro EnvironmentValuesMacro() = #externalMacro(module: "SwiftUIZ_Macros", type: "EnvironmentValuesMacro") 26 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_B/Intramodular/AnyViewBuilder.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import SwiftUI 6 | 7 | @resultBuilder 8 | public struct AnyViewBuilder { 9 | @_transparent 10 | public static func buildBlock( 11 | _ component: T 12 | ) -> AnyView { 13 | component.eraseToAnyView() 14 | } 15 | 16 | @_transparent 17 | public static func buildBlock( 18 | _ content: repeat each Content 19 | ) -> AnyView { 20 | TupleView((repeat each content)).eraseToAnyView() 21 | } 22 | 23 | @_transparent 24 | public static func buildPartialBlock( 25 | _ component: T 26 | ) -> AnyView { 27 | component.eraseToAnyView() 28 | } 29 | 30 | @_transparent 31 | public static func buildPartialBlock( 32 | _ content: repeat each Content 33 | ) -> AnyView where repeat each Content: View { 34 | buildBlock(repeat each content) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_B/Intramodular/DynamicView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import _SwiftUI_Internals 6 | import SwiftUIX 7 | 8 | /// This type is **WIP**. 9 | public protocol DynamicView: _DynamicView, _ThinForceModifiedView where ViewModifierType == _InterposeViewBody { 10 | var _unsafeDynamicViewFlags: Set<_UnsafeDynamicViewFlag> { get } 11 | } 12 | 13 | // MARK: - Implementation 14 | 15 | extension DynamicView { 16 | public var _unsafeDynamicViewFlags: Set<_UnsafeDynamicViewFlag> { 17 | [] 18 | } 19 | } 20 | 21 | // MARK: - Internal 22 | 23 | public enum _UnsafeDynamicViewFlag: Hashable { 24 | 25 | } 26 | 27 | extension _DynamicView where Self: DynamicView { 28 | public typealias ViewModifierType = _InterposeViewBody 29 | } 30 | 31 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_B/Intramodular/Hypergraph/_LightweightViewHypergraph.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import Compute 6 | import Merge 7 | import Swallow 8 | import SwiftUIX 9 | import _SwiftUIZ_A 10 | 11 | @objc(_SwiftUIZ_type_LightweightViewHypergraph) 12 | public final class _LightweightViewHypergraph: _AnyViewHypergraph, _AnyViewHypergraphType { 13 | package var initialStaticViewTypeDescriptors: IdentifierIndexingArrayOf<_StaticViewTypeDescriptor> = [] 14 | package var nodes: IdentifierIndexingArray = .init(id: \._opaque_id) 15 | 16 | public subscript(_ id: Interpose.ID) -> any _AnyViewHypergraph.InterposeProtocol { 17 | nodes[id: id]! 18 | } 19 | 20 | public func insert(_ object: any _AnyViewHypergraph.InterposeProtocol) { 21 | self.nodes.insert(object) 22 | } 23 | 24 | public func prepare(_ object: some _AnyViewHypergraph.InterposeProtocol) throws { 25 | 26 | } 27 | 28 | public func remove(_ object: any _AnyViewHypergraph.InterposeProtocol) { 29 | self.nodes.remove(object) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_B/Intramodular/Previews/_PreviewProviderDescriptor.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import _ModularDecodingEncoding 6 | import Runtime 7 | import Swallow 8 | 9 | public struct _PreviewProviderDescriptor: Identifiable { 10 | public let type: _CodableSwiftType 11 | public let title: String 12 | public let content: AnyView 13 | 14 | public var id: String { 15 | try! _getSanitizedTypeName(from: type.resolveType(), qualified: false) 16 | } 17 | 18 | public init( 19 | type: _CodableSwiftType, 20 | title: String, 21 | _ content: Content 22 | ) { 23 | self.type = type 24 | self.title = title 25 | self.content = content.eraseToAnyView() 26 | } 27 | } 28 | 29 | extension _PreviewProviderDescriptor { 30 | init(from view: any ViewPreview.Type) { 31 | self.init( 32 | type: _CodableSwiftType(from: view), 33 | title: view.title, 34 | view.init().eraseToAnyView() 35 | ) 36 | } 37 | } 38 | 39 | // MARK: - Conformances 40 | 41 | extension _PreviewProviderDescriptor: CaseIterable { 42 | public static let allCases: [_PreviewProviderDescriptor] = { 43 | _RuntimeTypeDiscoveryIndex 44 | .enumerate( 45 | typesConformingTo: (any ViewPreview).self 46 | ) 47 | .map { 48 | _PreviewProviderDescriptor(from: $0) 49 | } 50 | }() 51 | } 52 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_B/Intramodular/Shallow Environment/_HydrateShallowEnvironment.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import Diagnostics 6 | import Runtime 7 | import Swallow 8 | import SwiftUIX 9 | 10 | public protocol _ShallowEnvironmentHydrationSurface { 11 | var staticViewTypeDescriptor: _StaticViewTypeDescriptor { get } 12 | } 13 | 14 | struct _HydrateShallowEnvironment: _ThinViewModifier { 15 | let values: _ShallowEnvironmentValues 16 | 17 | @ViewStorage var provider = _ShallowEnvironmentProvider() 18 | 19 | @State var foo: Bool = false 20 | 21 | func body(content: Content) -> some View { 22 | _UnaryViewTraitReader(_ShallowEnvironmentHydrationSurface.self) { 23 | content 24 | .environment(\._shallowEnvironmentProvider, provider) 25 | .id(foo) 26 | } action: { (surface: _ShallowEnvironmentHydrationSurface?) in 27 | if let surface { 28 | provider.hydrate(from: values, forSurface: surface) 29 | 30 | refreshOnceIfNeeded() 31 | } 32 | } 33 | } 34 | 35 | private func refreshOnceIfNeeded() { 36 | if !foo { 37 | DispatchQueue.main.async { 38 | foo = true 39 | } 40 | } 41 | } 42 | } 43 | 44 | extension View { 45 | public func _transformShallowEnvironment( 46 | _ transform: (inout _ShallowEnvironmentValues) -> Void 47 | ) -> some View { 48 | var values = _ShallowEnvironmentValues() 49 | 50 | transform(&values) 51 | 52 | return _modifier(_HydrateShallowEnvironment(values: values)) 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_B/Intramodular/Shallow Environment/_ShallowEnvironment.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import Diagnostics 6 | import Swallow 7 | import SwiftUIX 8 | import _SwiftUIZ_A 9 | 10 | protocol _ShallowEnvironmentType: SwiftUI.DynamicProperty, PropertyWrapper, _SwiftUIX_PropertyWrapper { 11 | var id: AnyHashable? { get } 12 | var key: PartialKeyPath<_ShallowEnvironmentValues.Keys> { get } 13 | } 14 | 15 | @propertyWrapper 16 | public struct _ShallowEnvironment: _ShallowEnvironmentType { 17 | @Environment(\._shallowEnvironmentProvider) private var _shallowEnvironmentProvider 18 | 19 | @State internal var id: AnyHashable? = UUID() 20 | 21 | let key: PartialKeyPath<_ShallowEnvironmentValues.Keys> 22 | 23 | public var wrappedValue: Value { 24 | get { 25 | do { 26 | let key = _ShallowEnvironmentProvider.EnvironmentKey(id: id!, key: key) 27 | 28 | return try _shallowEnvironmentProvider[key, as: Value.self].unwrap() 29 | } catch { 30 | fatalError(error) 31 | } 32 | } 33 | } 34 | 35 | public init( 36 | _ key: KeyPath<_ShallowEnvironmentValues.Keys, Key> 37 | ) where Value == Key.Value { 38 | self.key = key 39 | } 40 | 41 | public init(_ type: T.Type) where Value == T? { 42 | self.key = \_ShallowEnvironmentValues.Keys.[Metatype(T.self)] 43 | } 44 | } 45 | 46 | // MARK: - Auxiliary 47 | 48 | @_spi(Internal) 49 | extension EnvironmentValues { 50 | @EnvironmentValue public var _shallowEnvironmentProvider = _ShallowEnvironmentProvider() 51 | } 52 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_B/Intramodular/Shallow Environment/_ShallowEnvironmentKeyDescriptor.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import Runtime 6 | import Swallow 7 | import SwallowMacrosClient 8 | import _SwiftUIZ_A 9 | 10 | public struct _ShallowEnvironmentKeyDescriptor { 11 | public let id: AnyHashable 12 | public let key: PartialKeyPath<_ShallowEnvironmentValues.Keys> 13 | } 14 | 15 | extension _ShallowEnvironmentKeyDescriptor { 16 | @RuntimeDiscoverable 17 | package struct _ViewTypeDescriptorStaticUpdater: _StaticViewTypeDescriptor.StaticUpdater, Hashable { 18 | package static func update( 19 | _ descriptor: inout _StaticViewTypeDescriptor, 20 | context: _StaticViewTypeDescriptor.UpdateContext 21 | ) throws { 22 | for field in context.view { 23 | if field.key.stringValue.hasSuffix("_dynamicReplacementObserver") { 24 | continue 25 | } 26 | 27 | if let value = field.value as? (any _ShallowEnvironmentType) { 28 | guard let id = value.id else { 29 | throw Never.Reason.unexpected 30 | } 31 | 32 | descriptor._shallowEnvironmentKeys.append( 33 | .init( 34 | id: id, 35 | key: value.key 36 | ) 37 | ) 38 | } 39 | } 40 | } 41 | } 42 | } 43 | 44 | extension _StaticViewTypeDescriptor { 45 | public var _shallowEnvironmentKeys: [_ShallowEnvironmentKeyDescriptor] { 46 | get { 47 | self[Array.self] 48 | } set { 49 | self[Array.self] = newValue 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_B/Intramodular/Shallow Environment/_ShallowEnvironmentProvider.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import Diagnostics 6 | import Swallow 7 | 8 | /// A type that vends shallow environment values for the immediate view that it is attached to. 9 | @_spi(Internal) 10 | public class _ShallowEnvironmentProvider { 11 | public struct EnvironmentKey: Hashable, Identifiable { 12 | public let id: AnyHashable 13 | public let key: PartialKeyPath<_ShallowEnvironmentValues.Keys> 14 | } 15 | 16 | public var storage: [EnvironmentKey: Any] = [:] 17 | 18 | public var isEmpty: Bool { 19 | storage.isEmpty 20 | } 21 | 22 | public subscript( 23 | _ key: EnvironmentKey, 24 | as type: T.Type 25 | ) -> T? { 26 | get { 27 | #try(.optimistic) { 28 | try cast(self.storage[key], to: T.self) 29 | } 30 | } 31 | } 32 | 33 | public init() { 34 | 35 | } 36 | 37 | public func hydrate( 38 | from values: _ShallowEnvironmentValues, 39 | forSurface surface: _ShallowEnvironmentHydrationSurface 40 | ) { 41 | for key in surface.staticViewTypeDescriptor._shallowEnvironmentKeys { 42 | self.storage[EnvironmentKey(id: key.id, key: key.key)] = values.storage[key.key]! 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_B/Intramodular/Shallow Environment/_ShallowEnvironmentValues.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import Swallow 6 | import SwiftUI 7 | 8 | public struct _ShallowEnvironmentValues: Initiable { 9 | package typealias Storage = [PartialKeyPath: Any] 10 | 11 | package var storage: [PartialKeyPath: Any] = [:] 12 | 13 | package var keys: Storage.Keys { 14 | storage.keys 15 | } 16 | 17 | public init() { 18 | 19 | } 20 | 21 | public subscript( 22 | _ keyPath: KeyPath 23 | ) -> Key.Value? { 24 | get { 25 | storage[keyPath].map({ $0 as! Key.Value }) 26 | } set { 27 | storage[keyPath] = newValue 28 | } 29 | } 30 | 31 | public subscript( 32 | _ type: T.Type 33 | ) -> T? { 34 | get { 35 | storage[\Keys.[Metatype(type)]].map({ $0 as! T }) 36 | } set { 37 | storage[\Keys.[Metatype(type)]] = newValue 38 | } 39 | } 40 | } 41 | 42 | extension _ShallowEnvironmentValues { 43 | public protocol Key: Hashable { 44 | associatedtype Value 45 | } 46 | 47 | public struct Keys { 48 | public struct _TypeToEnvironmentKeyAdaptor: Hashable { 49 | public typealias Value = T 50 | 51 | public let type: Metatype 52 | } 53 | 54 | public subscript(_ type: Metatype) -> _TypeToEnvironmentKeyAdaptor { 55 | .init(type: type) 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_B/Intramodular/View Interposing/_InterposeViewBody.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import Swallow 6 | import _SwiftUI_Internals 7 | import _SwiftUIZ_A 8 | @_spi(Internal) import SwiftUIX 9 | 10 | public struct _InterposeViewBody: Initiable, _ThinForceViewModifier { 11 | public init() { 12 | 13 | } 14 | 15 | @ViewBuilder 16 | public func body( 17 | root: Root, 18 | content: LazyView 19 | ) -> some View { 20 | _InterposedViewBody(root: root) { 21 | content 22 | } 23 | .environment(\._lazyViewResolver, _AnyLazyViewResolver(resolve: { resolve in 24 | let context: _TaskLocalValues._HeavyweightViewHypergraph = withMutableScope(_TaskLocalValues._dynamicViewGraph) { 25 | $0._managedDynamicViewBodyModifier = .init(root: type(of: root), content: Content.self) 26 | } 27 | 28 | return _TaskLocalValues.$_dynamicViewGraph.withValue(context) { 29 | resolve() 30 | } 31 | })) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_B/Intramodular/View Interposing/_InterposedViewProxy.HydrationSurface.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import SwiftUIX 6 | 7 | extension _InterposedViewBodyProxy { 8 | /// A context donated by a view to describe itself as a *receiver*. 9 | @_spi(Internal) 10 | public struct HydrationSurface: Equatable { 11 | public var bridge: _InterposedViewBodyBridge 12 | 13 | public init?(bridge: _InterposedViewBodyBridge) { 14 | self.bridge = bridge 15 | } 16 | } 17 | } 18 | 19 | extension _InterposedViewBodyProxy.HydrationSurface { 20 | struct _PreferenceKey: SwiftUI.PreferenceKey { 21 | typealias Value = _InterposedViewBodyProxy.HydrationSurface? 22 | 23 | static func reduce( 24 | value: inout Value, 25 | nextValue: () -> Value 26 | ) { 27 | value = nextValue() ?? value 28 | } 29 | } 30 | } 31 | 32 | extension _InterposedViewBodyBridge: _ShallowEnvironmentHydrationSurface { 33 | public var staticViewTypeDescriptor: _StaticViewTypeDescriptor { 34 | bodyStorage.graphInsertion.insertedObject.staticViewTypeDescriptor 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_B/Intramodular/View Interposing/_InterposedViewProxy.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import Diagnostics 6 | import Runtime 7 | @_spi(Internal) import SwiftUIX 8 | 9 | @MainActor 10 | public struct _InterposedViewBodyProxy: DynamicProperty { 11 | weak var _viewBridge: _InterposedViewBodyBridge? 12 | weak var _storage: _InterposedViewBodyStorage? 13 | 14 | var storage: _InterposedViewBodyStorage { 15 | get throws { 16 | try _storage.unwrap() 17 | } 18 | } 19 | 20 | package var root: any View 21 | package var content: any View 22 | 23 | let graphContext: EnvironmentValues._InterposeGraphContext 24 | 25 | init( 26 | _viewBridge: _InterposedViewBodyBridge, 27 | _storage: _InterposedViewBodyStorage?, 28 | root: any View, 29 | content: any View, 30 | graphContext: EnvironmentValues._InterposeGraphContext 31 | ) { 32 | self._viewBridge = _viewBridge 33 | self._storage = _storage 34 | self.root = root 35 | self.content = content 36 | self.graphContext = graphContext 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_B/Intramodular/_InterposedApp.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import SwiftUI 6 | 7 | public protocol _InterposedApp: App where Body: _DynamicScene { 8 | var body: Body { get } 9 | } 10 | 11 | // MARK: - Implementation 12 | 13 | @MainActor 14 | extension _InterposedApp where Body == _InterposedApp_DefaultBody { 15 | public var body: _InterposedApp_DefaultBody { 16 | _InterposedApp_DefaultBody() 17 | } 18 | } 19 | 20 | @MainActor 21 | public struct _InterposedApp_DefaultBody: _DynamicScene { 22 | public var body: some _DynamicScene { 23 | _RuntimeDiscoveredScenes() 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_B/macros.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import Swift 6 | -------------------------------------------------------------------------------- /Sources/_SwiftUIZ_B/module.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import Swallow 6 | @_exported import _SwiftUIZ_A 7 | 8 | extension _TaskLocalValues { 9 | public struct _HeavyweightViewHypergraph { 10 | struct _InterposeViewBody { 11 | let root: Any.Type 12 | let content: Any.Type 13 | } 14 | 15 | var _managedDynamicViewBodyModifier: _InterposeViewBody? 16 | } 17 | 18 | @TaskLocal package static var _dynamicViewGraph = _HeavyweightViewHypergraph() 19 | } 20 | -------------------------------------------------------------------------------- /Sources/_SwiftUI_Internals/Intramodular/View Modifiers/_AnyForceModifiedView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import SwiftUI 6 | 7 | public protocol _AnyForceModifiedView: DynamicProperty, View { 8 | static var _disableForceModifiedViewModification: Bool { get } 9 | } 10 | 11 | extension _AnyForceModifiedView { 12 | public static var _disableForceModifiedViewModification: Bool { 13 | false 14 | } 15 | 16 | fileprivate var _disableApplicationOfForceViewModifier: Bool { 17 | Self._disableForceModifiedViewModification 18 | } 19 | } 20 | 21 | extension _AnyForceModifiedView { 22 | var _umodifiedHosted: _AnyUnmodifiedView { 23 | _AnyUnmodifiedView(base: self) 24 | } 25 | } 26 | 27 | struct _AnyUnmodifiedView: View { 28 | var base: Base 29 | 30 | var body: some View { 31 | base.body 32 | } 33 | 34 | static func _makeView( 35 | view: _GraphValue, 36 | inputs: _ViewInputs 37 | ) -> SwiftUI._ViewOutputs { 38 | let body: _GraphValue = view[\Self.base.body] 39 | 40 | return Base.Body._makeView(view: body, inputs: inputs) 41 | } 42 | 43 | static func _makeViewList( 44 | view: _GraphValue, 45 | inputs: _ViewListInputs 46 | ) -> SwiftUI._ViewListOutputs { 47 | let body: _GraphValue = view[\Self.base.body] 48 | 49 | return Base.Body._makeViewList(view: body, inputs: inputs) 50 | } 51 | 52 | @available(iOS 14.0, macOS 11.0, tvOS 14.0, watchOS 7.0, *) 53 | static func _viewListCount( 54 | inputs: SwiftUI._ViewListCountInputs 55 | ) -> Int? { 56 | Base.Body._viewListCount(inputs: inputs) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Sources/_SwiftUI_Internals/Intramodular/_SwiftUI_BloomFilter.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import SwiftUI 6 | 7 | /// https://github.com/OpenSwiftUIProject/OpenSwiftUI 8 | public struct _SwiftUI_BloomFilter: Equatable { 9 | public var value: UInt 10 | 11 | public init(hashValue: Int) { 12 | // Make sure we do LSR instead of ASR 13 | let value = UInt(hashValue) 14 | 15 | let a0 = 1 &<< (value &>> 0x10) 16 | let a1 = 1 &<< (value &>> 0xa) 17 | let a2 = 1 &<< (value &>> 0x4) 18 | 19 | self.value = a0 | a1 | a2 20 | } 21 | 22 | public init(type: Any.Type) { 23 | let pointer = unsafeBitCast(type, to: OpaquePointer.self) 24 | 25 | self.init(hashValue: Int(bitPattern: pointer)) 26 | } 27 | 28 | @inline(__always) 29 | func match(_ filter: _SwiftUI_BloomFilter) -> Bool { 30 | (value & filter.value) == value 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Sources/_SwiftUI_Internals/Intramodular/_UnaryViewAdaptor.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Vatsal Manot 3 | // 4 | 5 | import SwiftUI 6 | 7 | @frozen 8 | public struct _SwiftUI_UnaryViewAdaptor: View { 9 | @usableFromInline 10 | var content: Content 11 | 12 | @inlinable 13 | public init(@ViewBuilder content: () -> Content) { 14 | self.content = content() 15 | } 16 | 17 | public var body: some View { 18 | _UnaryViewAdaptor(content) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Sources/_UniversalDisplayLink/DisplayLink.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DisplayLink.swift 3 | // MSDisplayLink 4 | // 5 | // Created by 秋星桥 on 2024/8/13. 6 | // 7 | 8 | import Combine 9 | import Foundation 10 | 11 | public protocol DisplayLinkDelegate: AnyObject { 12 | func synchronization(context: DisplayLinkCallbackContext) 13 | } 14 | 15 | public class DisplayLink { 16 | private weak var delegatingObject: DisplayLinkDelegate? 17 | 18 | private var driver: DisplayLinkDriver? 19 | private var driverSubscription: Set = .init() 20 | 21 | public init() { 22 | let driver = DisplayLinkDriver() 23 | driver.synchronizationPublisher 24 | .sink { [weak self] output in self?.delegatingObject?.synchronization(context: output) } 25 | .store(in: &driverSubscription) 26 | self.driver = driver 27 | } 28 | 29 | deinit { teardown() } 30 | 31 | func teardown() { 32 | driverSubscription.forEach { $0.cancel() } 33 | driverSubscription.removeAll() 34 | driver = nil 35 | } 36 | 37 | public func delegatingObject(_ object: DisplayLinkDelegate?) { 38 | delegatingObject = object 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Sources/_UniversalDisplayLink/DisplayLinkCallbackContext.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DisplayLinkCallbackContext.swift 3 | // MSDisplayLink 4 | // 5 | // Created by 秋星桥 on 2025/1/6. 6 | // 7 | 8 | import Foundation 9 | 10 | public struct DisplayLinkCallbackContext { 11 | /// The time interval between screen refresh updates. 12 | public let duration: TimeInterval 13 | /// The time interval that represents when the last frame displayed. 14 | public let timestamp: TimeInterval 15 | /// The time interval that represents when the next frame displays. 16 | public let targetTimestamp: TimeInterval 17 | 18 | public init(duration: TimeInterval, timestamp: TimeInterval, targetTimestamp: TimeInterval) { 19 | self.duration = duration 20 | self.timestamp = timestamp 21 | self.targetTimestamp = targetTimestamp 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Sources/_UniversalDisplayLink/DisplayLinkDriver.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DisplayLinkDriver.swift 3 | // MSDisplayLink 4 | // 5 | // Created by 秋星桥 on 2024/8/13. 6 | // 7 | 8 | import Combine 9 | import Foundation 10 | 11 | class DisplayLinkDriver: Identifiable { 12 | let id: UUID = .init() 13 | 14 | private static let sharedLink = DisplayLinkDriverHelper.shared 15 | 16 | typealias SynchornizationPublisher = PassthroughSubject< 17 | DisplayLinkCallbackContext, 18 | Never 19 | > 20 | let synchronizationPublisher: SynchornizationPublisher 21 | 22 | init() { 23 | synchronizationPublisher = .init() 24 | DisplayLinkDriverHelper.shared.delegate(self) 25 | } 26 | 27 | deinit { 28 | DisplayLinkDriverHelper.shared.remove(self) 29 | } 30 | 31 | func synchronize(context: DisplayLinkCallbackContext) { 32 | synchronizationPublisher.send(context) 33 | } 34 | } 35 | --------------------------------------------------------------------------------