@swiftbrowser/swift 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Package.swift +214 -0
- package/README.md +10 -2
- package/Sources/AVFoundation/AVFoundation.swift +131 -0
- package/Sources/AVFoundation/Asset.swift +487 -0
- package/Sources/AVFoundation/AudioSession.swift +144 -0
- package/Sources/AVFoundation/CMTime.swift +303 -0
- package/Sources/AVFoundation/Capture.swift +688 -0
- package/Sources/AVFoundation/Player.swift +749 -0
- package/Sources/AVFoundation/PlayerView.swift +117 -0
- package/Sources/AVKit/AVKit.swift +132 -0
- package/Sources/Accelerate/Accelerate.swift +122 -0
- package/Sources/AppIntents/AppIntents.swift +144 -0
- package/Sources/AppIntents/Parameters.swift +220 -0
- package/Sources/AppIntents/Shortcuts.swift +159 -0
- package/Sources/AudioToolbox/AudioToolbox.swift +55 -0
- package/Sources/AuthenticationServices/AuthenticationServices.swift +257 -0
- package/Sources/AuthenticationServices/Authorization.swift +251 -0
- package/Sources/Charts/Charts.swift +61 -0
- package/Sources/Combine/AnyCancellable.swift +65 -0
- package/Sources/Combine/AnyPublisher.swift +148 -0
- package/Sources/Combine/AnySubscriber.swift +230 -0
- package/Sources/Combine/Cancellable.swift +35 -0
- package/Sources/Combine/Codable.swift +29 -0
- package/Sources/Combine/CombineIdentifier.swift +45 -0
- package/Sources/Combine/Concurrency/ConcurrencyHelpers.swift +24 -0
- package/Sources/Combine/Concurrency/Future+Concurrency.swift +136 -0
- package/Sources/Combine/Concurrency/GENERATED-Publisher+Concurrency.swift +397 -0
- package/Sources/Combine/CurrentValueSubject.swift +252 -0
- package/Sources/Combine/CustomCombineIdentifierConvertible.swift +28 -0
- package/Sources/Combine/Future.swift +228 -0
- package/Sources/Combine/GENERATED-RootProtocols.swift +426 -0
- package/Sources/Combine/Helpers/ConduitBase.swift +40 -0
- package/Sources/Combine/Helpers/ConduitList.swift +59 -0
- package/Sources/Combine/Helpers/DebugHook.swift +177 -0
- package/Sources/Combine/Helpers/FilterProducer.swift +174 -0
- package/Sources/Combine/Helpers/Locking.swift +30 -0
- package/Sources/Combine/Helpers/PartialCompletion.swift +26 -0
- package/Sources/Combine/Helpers/ReduceProducer.swift +249 -0
- package/Sources/Combine/Helpers/SubjectSubscriber.swift +96 -0
- package/Sources/Combine/Helpers/SubscriberTap.swift +69 -0
- package/Sources/Combine/Helpers/SubscriptionStatus.swift +33 -0
- package/Sources/Combine/Helpers/SubscriptionTap.swift +33 -0
- package/Sources/Combine/Helpers/Utils.swift +30 -0
- package/Sources/Combine/Helpers/Violations.swift +33 -0
- package/Sources/Combine/ImmediateScheduler.swift +178 -0
- package/Sources/Combine/LICENSE +21 -0
- package/Sources/Combine/NotificationPublisher.swift +48 -0
- package/Sources/Combine/ObjectWillChange.swift +46 -0
- package/Sources/Combine/PassthroughSubject.swift +222 -0
- package/Sources/Combine/Publisher+Subscribe.swift +53 -0
- package/Sources/Combine/Publishers/Deferred.swift +48 -0
- package/Sources/Combine/Publishers/Empty.swift +54 -0
- package/Sources/Combine/Publishers/Fail.swift +42 -0
- package/Sources/Combine/Publishers/GENERATED-Publishers.Catch.swift +673 -0
- package/Sources/Combine/Publishers/GENERATED-Publishers.Encode.swift +388 -0
- package/Sources/Combine/Publishers/GENERATED-Publishers.MapKeyPath.swift +384 -0
- package/Sources/Combine/Publishers/Just.swift +313 -0
- package/Sources/Combine/Publishers/Optional.Publisher.swift +315 -0
- package/Sources/Combine/Publishers/Publishers.AllSatisfy.swift +217 -0
- package/Sources/Combine/Publishers/Publishers.AssertNoFailure.swift +158 -0
- package/Sources/Combine/Publishers/Publishers.Autoconnect.swift +193 -0
- package/Sources/Combine/Publishers/Publishers.Breakpoint.swift +231 -0
- package/Sources/Combine/Publishers/Publishers.Buffer.swift +356 -0
- package/Sources/Combine/Publishers/Publishers.Collect.swift +102 -0
- package/Sources/Combine/Publishers/Publishers.CollectByCount.swift +195 -0
- package/Sources/Combine/Publishers/Publishers.CompactMap.swift +241 -0
- package/Sources/Combine/Publishers/Publishers.Comparison.swift +371 -0
- package/Sources/Combine/Publishers/Publishers.Concatenate.swift +474 -0
- package/Sources/Combine/Publishers/Publishers.Contains.swift +293 -0
- package/Sources/Combine/Publishers/Publishers.Count.swift +87 -0
- package/Sources/Combine/Publishers/Publishers.Debounce.swift +332 -0
- package/Sources/Combine/Publishers/Publishers.Delay.swift +269 -0
- package/Sources/Combine/Publishers/Publishers.Drop.swift +155 -0
- package/Sources/Combine/Publishers/Publishers.DropUntilOutput.swift +283 -0
- package/Sources/Combine/Publishers/Publishers.DropWhile.swift +378 -0
- package/Sources/Combine/Publishers/Publishers.Filter.swift +248 -0
- package/Sources/Combine/Publishers/Publishers.First.swift +261 -0
- package/Sources/Combine/Publishers/Publishers.FlatMap.swift +533 -0
- package/Sources/Combine/Publishers/Publishers.HandleEvents.swift +260 -0
- package/Sources/Combine/Publishers/Publishers.IgnoreOutput.swift +109 -0
- package/Sources/Combine/Publishers/Publishers.Last.swift +252 -0
- package/Sources/Combine/Publishers/Publishers.MakeConnectable.swift +82 -0
- package/Sources/Combine/Publishers/Publishers.Map.swift +351 -0
- package/Sources/Combine/Publishers/Publishers.MapError.swift +140 -0
- package/Sources/Combine/Publishers/Publishers.MeasureInterval.swift +187 -0
- package/Sources/Combine/Publishers/Publishers.Multicast.swift +284 -0
- package/Sources/Combine/Publishers/Publishers.Output.swift +241 -0
- package/Sources/Combine/Publishers/Publishers.PrefixUntilOutput.swift +197 -0
- package/Sources/Combine/Publishers/Publishers.PrefixWhile.swift +176 -0
- package/Sources/Combine/Publishers/Publishers.Print.swift +206 -0
- package/Sources/Combine/Publishers/Publishers.ReceiveOn.swift +227 -0
- package/Sources/Combine/Publishers/Publishers.Reduce.swift +204 -0
- package/Sources/Combine/Publishers/Publishers.RemoveDuplicates.swift +264 -0
- package/Sources/Combine/Publishers/Publishers.ReplaceEmpty.swift +201 -0
- package/Sources/Combine/Publishers/Publishers.ReplaceError.swift +211 -0
- package/Sources/Combine/Publishers/Publishers.Retry.swift +274 -0
- package/Sources/Combine/Publishers/Publishers.Scan.swift +331 -0
- package/Sources/Combine/Publishers/Publishers.Sequence.swift +437 -0
- package/Sources/Combine/Publishers/Publishers.SetFailureType.swift +120 -0
- package/Sources/Combine/Publishers/Publishers.Share.swift +104 -0
- package/Sources/Combine/Publishers/Publishers.SubscribeOn.swift +197 -0
- package/Sources/Combine/Publishers/Publishers.SwitchToLatest.swift +444 -0
- package/Sources/Combine/Publishers/Publishers.Throttle.swift +359 -0
- package/Sources/Combine/Publishers/Publishers.Timeout.swift +301 -0
- package/Sources/Combine/Publishers/Publishers.Zip.swift +720 -0
- package/Sources/Combine/Publishers/Publishers.swift +13 -0
- package/Sources/Combine/Publishers/Record.swift +237 -0
- package/Sources/Combine/Publishers/Result.Publisher.swift +337 -0
- package/Sources/Combine/Result.swift +46 -0
- package/Sources/Combine/Scheduler.swift +89 -0
- package/Sources/Combine/Schedulers.swift +211 -0
- package/Sources/Combine/Subject+Void.swift +17 -0
- package/Sources/Combine/Subscriber+Void.swift +20 -0
- package/Sources/Combine/Subscribers/Subscribers.Assign.swift +175 -0
- package/Sources/Combine/Subscribers/Subscribers.Completion.swift +90 -0
- package/Sources/Combine/Subscribers/Subscribers.Demand.swift +476 -0
- package/Sources/Combine/Subscribers/Subscribers.Sink.swift +206 -0
- package/Sources/Combine/Subscribers/Subscribers.swift +9 -0
- package/Sources/Combine/Subscription.swift +22 -0
- package/Sources/Combine/Subscriptions.swift +42 -0
- package/Sources/Combine/SwiftUIObservation.swift +10 -0
- package/Sources/Combine/_Introspection.swift +107 -0
- package/Sources/CommonCrypto/CommonCrypto.swift +80 -0
- package/Sources/Compression/Compression.swift +365 -0
- package/Sources/Compression/Deflate.swift +407 -0
- package/Sources/Compression/Zlib.swift +179 -0
- package/Sources/CoreFoundationTypes/CoreFoundationTypes.swift +101 -0
- package/Sources/CoreGraphics/CoreGraphics.swift +411 -0
- package/Sources/CoreGraphics/ProjectionTransforms.swift +28 -0
- package/Sources/CoreHaptics/CoreHaptics.swift +399 -0
- package/Sources/CoreImage/CIColor.swift +41 -0
- package/Sources/CoreImage/CIContext.swift +31 -0
- package/Sources/CoreImage/CIDetector.swift +57 -0
- package/Sources/CoreImage/CIFilter.swift +243 -0
- package/Sources/CoreImage/CIFilterBuiltins.swift +136 -0
- package/Sources/CoreImage/CIImage.swift +162 -0
- package/Sources/CoreImage/QRCode.swift +393 -0
- package/Sources/CoreLocation/Coordinate.swift +30 -0
- package/Sources/CoreLocation/Location.swift +65 -0
- package/Sources/CoreML/Evaluation.swift +414 -0
- package/Sources/CoreML/FeatureValue.swift +266 -0
- package/Sources/CoreML/Model.swift +269 -0
- package/Sources/CoreML/MultiArray.swift +92 -0
- package/Sources/CoreML/Specification.swift +233 -0
- package/Sources/CoreText/CoreText.swift +64 -0
- package/Sources/CoreTransferable/CoreTransferable.swift +606 -0
- package/Sources/CryptoKit/ChaChaPoly.swift +258 -0
- package/Sources/CryptoKit/CryptoKit.swift +375 -0
- package/Sources/CryptoKit/Curve25519.swift +317 -0
- package/Sources/CryptoKit/P256.swift +321 -0
- package/Sources/FoundationBridge/AppStorage.swift +165 -0
- package/Sources/FoundationBridge/AssetResources.swift +90 -0
- package/Sources/FoundationBridge/AsyncBytes.swift +128 -0
- package/Sources/FoundationBridge/AsyncImage.swift +116 -0
- package/Sources/FoundationBridge/AttributedStrings.swift +16 -0
- package/Sources/FoundationBridge/Bundle.swift +119 -0
- package/Sources/FoundationBridge/CombineExports.swift +8 -0
- package/Sources/FoundationBridge/CoreFoundation.swift +77 -0
- package/Sources/FoundationBridge/Dispatch.swift +458 -0
- package/Sources/FoundationBridge/EnvironmentFoundation.swift +41 -0
- package/Sources/FoundationBridge/FileImporter.swift +128 -0
- package/Sources/FoundationBridge/FileSystem.swift +68 -0
- package/Sources/FoundationBridge/FoundationBridge.swift +29 -0
- package/Sources/FoundationBridge/HostResolution.swift +31 -0
- package/Sources/FoundationBridge/ItemProvider.swift +655 -0
- package/Sources/FoundationBridge/KeyValueObserving.swift +138 -0
- package/Sources/FoundationBridge/Links.swift +127 -0
- package/Sources/FoundationBridge/ListFormatter.swift +32 -0
- package/Sources/FoundationBridge/Locale.swift +86 -0
- package/Sources/FoundationBridge/Localization.swift +149 -0
- package/Sources/FoundationBridge/Locks.swift +50 -0
- package/Sources/FoundationBridge/Markdown.swift +527 -0
- package/Sources/FoundationBridge/MeasurementFormat.swift +95 -0
- package/Sources/FoundationBridge/NotificationCenter.swift +154 -0
- package/Sources/FoundationBridge/OpenURLHandlers.swift +60 -0
- package/Sources/FoundationBridge/Operation.swift +195 -0
- package/Sources/FoundationBridge/ProcessInfo.swift +32 -0
- package/Sources/FoundationBridge/RelativeDateTimeFormatter.swift +136 -0
- package/Sources/FoundationBridge/SceneStorage.swift +78 -0
- package/Sources/FoundationBridge/SecurityExports.swift +8 -0
- package/Sources/FoundationBridge/Selector.swift +226 -0
- package/Sources/FoundationBridge/StringComparators.swift +17 -0
- package/Sources/FoundationBridge/Table.swift +211 -0
- package/Sources/FoundationBridge/TextAttributes.swift +42 -0
- package/Sources/FoundationBridge/Timer.swift +53 -0
- package/Sources/FoundationBridge/UITextChecker.swift +30 -0
- package/Sources/FoundationBridge/URLSession.swift +718 -0
- package/Sources/FoundationBridge/UserDefaults.swift +183 -0
- package/Sources/FoundationBridge/WebAuthRedirects.swift +227 -0
- package/Sources/FoundationBridge/WebSocket.swift +187 -0
- package/Sources/FoundationModels/FoundationModels.swift +1098 -0
- package/Sources/ImageIO/GIF.swift +72 -0
- package/Sources/ImageIO/ImageIO.swift +248 -0
- package/Sources/ImageIO/ImageTypes.swift +28 -0
- package/Sources/LinkPresentation/LinkPresentation.swift +249 -0
- package/Sources/LocalAuthentication/LAContext.swift +86 -0
- package/Sources/MapKit/Geometry.swift +223 -0
- package/Sources/MapKit/Map.swift +638 -0
- package/Sources/MapKit/MapView.swift +229 -0
- package/Sources/MobileCoreServices/MobileCoreServices.swift +28 -0
- package/Sources/NaturalLanguage/LanguageIdentifier.swift +317 -0
- package/Sources/NaturalLanguage/NaturalLanguage.swift +135 -0
- package/Sources/OSLog/OSLog.swift +6 -0
- package/Sources/Photos/Photos.swift +572 -0
- package/Sources/PhotosUI/PhotosPicker.swift +248 -0
- package/Sources/PhotosUI/PhotosPickerItem.swift +261 -0
- package/Sources/QuickLook/QuickLook.swift +168 -0
- package/Sources/SafariServices/SafariServices.swift +106 -0
- package/Sources/Security/Security.swift +332 -0
- package/Sources/StoreKit/AppStore.swift +207 -0
- package/Sources/StoreKit/Products.swift +280 -0
- package/Sources/StoreKit/RequestReview.swift +28 -0
- package/Sources/StoreKit/StoreKit1.swift +486 -0
- package/Sources/StoreKit/StoreViews.swift +428 -0
- package/Sources/StoreKit/Transactions.swift +197 -0
- package/Sources/SwiftData/Macros.swift +58 -0
- package/Sources/SwiftData/ModelActor.swift +38 -0
- package/Sources/SwiftData/ModelContainer.swift +129 -0
- package/Sources/SwiftData/ModelContext.swift +451 -0
- package/Sources/SwiftData/PersistentModel.swift +238 -0
- package/Sources/SwiftData/Properties.swift +261 -0
- package/Sources/SwiftData/Query.swift +256 -0
- package/Sources/SwiftData/Schema.swift +192 -0
- package/Sources/SwiftData/Store.swift +146 -0
- package/Sources/SwiftData/StringPredicates.swift +125 -0
- package/Sources/SwiftDataMacros/EntryMacro.swift +82 -0
- package/Sources/SwiftDataMacros/GenerableMacro.swift +183 -0
- package/Sources/SwiftDataMacros/ModelActorMacro.swift +46 -0
- package/Sources/SwiftDataMacros/ModelMacro.swift +260 -0
- package/Sources/SwiftDataMacros/Plugin.swift +18 -0
- package/Sources/SwiftDataMacros/PredicateMacro.swift +1244 -0
- package/Sources/SwiftUI/API/Accessibility.swift +181 -0
- package/Sources/SwiftUI/API/AccessibilityExtras.swift +33 -0
- package/Sources/SwiftUI/API/AccessibilityFocus.swift +63 -0
- package/Sources/SwiftUI/API/Alert.swift +221 -0
- package/Sources/SwiftUI/API/AlignmentGuides.swift +65 -0
- package/Sources/SwiftUI/API/Animation.swift +285 -0
- package/Sources/SwiftUI/API/App.swift +87 -0
- package/Sources/SwiftUI/API/BindingCollections.swift +35 -0
- package/Sources/SwiftUI/API/BindingForEach.swift +27 -0
- package/Sources/SwiftUI/API/Bitmaps.swift +254 -0
- package/Sources/SwiftUI/API/ButtonStyles.swift +96 -0
- package/Sources/SwiftUI/API/Canvas.swift +337 -0
- package/Sources/SwiftUI/API/Color.swift +237 -0
- package/Sources/SwiftUI/API/ColorEffects.swift +52 -0
- package/Sources/SwiftUI/API/ColorPickerAndLabeledContent.swift +138 -0
- package/Sources/SwiftUI/API/ColorSpaces.swift +161 -0
- package/Sources/SwiftUI/API/Commands.swift +106 -0
- package/Sources/SwiftUI/API/ContainerBackground.swift +28 -0
- package/Sources/SwiftUI/API/ContentShape.swift +33 -0
- package/Sources/SwiftUI/API/ContentSizeCategory.swift +35 -0
- package/Sources/SwiftUI/API/ContentUnavailable.swift +101 -0
- package/Sources/SwiftUI/API/Controls.swift +300 -0
- package/Sources/SwiftUI/API/CustomLayout.swift +442 -0
- package/Sources/SwiftUI/API/CustomToolbarContent.swift +46 -0
- package/Sources/SwiftUI/API/Decorations.swift +92 -0
- package/Sources/SwiftUI/API/EditMode.swift +212 -0
- package/Sources/SwiftUI/API/Effects.swift +388 -0
- package/Sources/SwiftUI/API/Entry.swift +8 -0
- package/Sources/SwiftUI/API/Environment.swift +439 -0
- package/Sources/SwiftUI/API/EnvironmentSendable.swift +6 -0
- package/Sources/SwiftUI/API/Focus.swift +137 -0
- package/Sources/SwiftUI/API/Font.swift +131 -0
- package/Sources/SwiftUI/API/Gauge.swift +290 -0
- package/Sources/SwiftUI/API/Geometry.swift +89 -0
- package/Sources/SwiftUI/API/GeometryEffects.swift +232 -0
- package/Sources/SwiftUI/API/GeometryReader.swift +135 -0
- package/Sources/SwiftUI/API/GestureState.swift +65 -0
- package/Sources/SwiftUI/API/Gestures.swift +342 -0
- package/Sources/SwiftUI/API/Glass.swift +127 -0
- package/Sources/SwiftUI/API/Grid.swift +188 -0
- package/Sources/SwiftUI/API/GroupBoxAndControlGroup.swift +130 -0
- package/Sources/SwiftUI/API/KeyPress.swift +54 -0
- package/Sources/SwiftUI/API/LabelStyle.swift +124 -0
- package/Sources/SwiftUI/API/Layout.swift +220 -0
- package/Sources/SwiftUI/API/LazyStacks.swift +49 -0
- package/Sources/SwiftUI/API/LegacyAlert.swift +97 -0
- package/Sources/SwiftUI/API/Lists.swift +331 -0
- package/Sources/SwiftUI/API/Menu.swift +58 -0
- package/Sources/SwiftUI/API/Modifiers.swift +313 -0
- package/Sources/SwiftUI/API/MoreModifiers.swift +100 -0
- package/Sources/SwiftUI/API/Namespace.swift +44 -0
- package/Sources/SwiftUI/API/Navigation.swift +386 -0
- package/Sources/SwiftUI/API/NavigationDestinationBindings.swift +55 -0
- package/Sources/SwiftUI/API/ObservableObject.swift +293 -0
- package/Sources/SwiftUI/API/OnChange.swift +48 -0
- package/Sources/SwiftUI/API/Path.swift +543 -0
- package/Sources/SwiftUI/API/Phase8Controls.swift +411 -0
- package/Sources/SwiftUI/API/PhaseAnimator.swift +130 -0
- package/Sources/SwiftUI/API/Picker.swift +185 -0
- package/Sources/SwiftUI/API/PointerAndKeyboard.swift +77 -0
- package/Sources/SwiftUI/API/Popover.swift +41 -0
- package/Sources/SwiftUI/API/Preferences.swift +262 -0
- package/Sources/SwiftUI/API/Presentation.swift +122 -0
- package/Sources/SwiftUI/API/PresentationExtras.swift +60 -0
- package/Sources/SwiftUI/API/Primitives.swift +517 -0
- package/Sources/SwiftUI/API/Publishers.swift +107 -0
- package/Sources/SwiftUI/API/Redaction.swift +75 -0
- package/Sources/SwiftUI/API/RowActions.swift +84 -0
- package/Sources/SwiftUI/API/Scenes.swift +131 -0
- package/Sources/SwiftUI/API/ScrollModifiers.swift +132 -0
- package/Sources/SwiftUI/API/ScrollTargets.swift +104 -0
- package/Sources/SwiftUI/API/ScrollViewReader.swift +144 -0
- package/Sources/SwiftUI/API/SectionSupplements.swift +96 -0
- package/Sources/SwiftUI/API/Shape.swift +214 -0
- package/Sources/SwiftUI/API/ShapeStyle.swift +409 -0
- package/Sources/SwiftUI/API/ShapeTrim.swift +78 -0
- package/Sources/SwiftUI/API/Sharing.swift +193 -0
- package/Sources/SwiftUI/API/StackLayouts.swift +199 -0
- package/Sources/SwiftUI/API/State.swift +144 -0
- package/Sources/SwiftUI/API/StatusGaps.swift +121 -0
- package/Sources/SwiftUI/API/StrokeStyle.swift +30 -0
- package/Sources/SwiftUI/API/SymbolEffects.swift +203 -0
- package/Sources/SwiftUI/API/TabContent.swift +841 -0
- package/Sources/SwiftUI/API/Table.swift +382 -0
- package/Sources/SwiftUI/API/Tabs.swift +263 -0
- package/Sources/SwiftUI/API/Tasks.swift +35 -0
- package/Sources/SwiftUI/API/Text.swift +386 -0
- package/Sources/SwiftUI/API/TextDates.swift +61 -0
- package/Sources/SwiftUI/API/TextDecorations.swift +52 -0
- package/Sources/SwiftUI/API/TextFieldAxis.swift +103 -0
- package/Sources/SwiftUI/API/TextFieldCommit.swift +52 -0
- package/Sources/SwiftUI/API/Timeline.swift +212 -0
- package/Sources/SwiftUI/API/Toolbar.swift +251 -0
- package/Sources/SwiftUI/API/Transfer.swift +145 -0
- package/Sources/SwiftUI/API/UnevenRoundedRectangle.swift +66 -0
- package/Sources/SwiftUI/API/Video.swift +64 -0
- package/Sources/SwiftUI/API/View.swift +215 -0
- package/Sources/SwiftUI/API/ViewModifier.swift +43 -0
- package/Sources/SwiftUI/API/VisualEffect.swift +155 -0
- package/Sources/SwiftUI/API/Windows.swift +25 -0
- package/Sources/SwiftUI/Charts/Axis.swift +325 -0
- package/Sources/SwiftUI/Charts/AxisFormatsAndRanges.swift +68 -0
- package/Sources/SwiftUI/Charts/Chart.swift +660 -0
- package/Sources/SwiftUI/Charts/ChartContent.swift +376 -0
- package/Sources/SwiftUI/Charts/ChartProxy.swift +57 -0
- package/Sources/SwiftUI/Charts/Marks.swift +204 -0
- package/Sources/SwiftUI/Charts/Plottable.swift +99 -0
- package/Sources/SwiftUI/Charts/Scales.swift +326 -0
- package/Sources/SwiftUI/Localization/Localization.swift +498 -0
- package/Sources/SwiftUI/Localization/PluralRules.swift +127 -0
- package/Sources/SwiftUI/Runtime/Executor.swift +85 -0
- package/Sources/SwiftUI/Runtime/Exports.swift +101 -0
- package/Sources/SwiftUI/Runtime/ImageSource.swift +310 -0
- package/Sources/SwiftUI/Runtime/JSON.swift +143 -0
- package/Sources/SwiftUI/Runtime/JSONParser.swift +443 -0
- package/Sources/SwiftUI/Runtime/LazyRows.swift +99 -0
- package/Sources/SwiftUI/Runtime/Measurements.swift +140 -0
- package/Sources/SwiftUI/Runtime/Ops.swift +152 -0
- package/Sources/SwiftUI/Runtime/Reconciler.swift +219 -0
- package/Sources/SwiftUI/Runtime/Replay.swift +382 -0
- package/Sources/SwiftUI/Runtime/Runtime.swift +2146 -0
- package/Sources/SwiftUI/Runtime/Sameness.swift +152 -0
- package/Sources/SwiftUI/Runtime/ViewPath.swift +89 -0
- package/Sources/SwiftUI/Runtime/ViewTraits.swift +175 -0
- package/Sources/SwiftUI/Runtime/WebAuthHeadless.swift +49 -0
- package/Sources/Symbols/Symbols.swift +25 -0
- package/Sources/Translation/Translation.swift +423 -0
- package/Sources/UIKit/Activity.swift +213 -0
- package/Sources/UIKit/Alerts.swift +69 -0
- package/Sources/UIKit/AppDelegate.swift +222 -0
- package/Sources/UIKit/Appearance.swift +84 -0
- package/Sources/UIKit/ColorConversions.swift +70 -0
- package/Sources/UIKit/Controls.swift +225 -0
- package/Sources/UIKit/Device.swift +200 -0
- package/Sources/UIKit/Feedback.swift +65 -0
- package/Sources/UIKit/Font.swift +307 -0
- package/Sources/UIKit/Graphics.swift +204 -0
- package/Sources/UIKit/HostingController.swift +185 -0
- package/Sources/UIKit/Identity.swift +24 -0
- package/Sources/UIKit/Introspectable.swift +510 -0
- package/Sources/UIKit/Pasteboard.swift +363 -0
- package/Sources/UIKit/PhotoAlbum.swift +81 -0
- package/Sources/UIKit/RemoteNotifications.swift +15 -0
- package/Sources/UIKit/Representable.swift +288 -0
- package/Sources/UIKit/SafeArea.swift +12 -0
- package/Sources/UIKit/SceneDelegates.swift +132 -0
- package/Sources/UIKit/Scenes.swift +40 -0
- package/Sources/UIKit/ScrollView.swift +157 -0
- package/Sources/UIKit/ShortcutItems.swift +67 -0
- package/Sources/UIKit/SymbolConfiguration.swift +124 -0
- package/Sources/UIKit/TargetAction.swift +123 -0
- package/Sources/UIKit/TextPaste.swift +161 -0
- package/Sources/UIKit/TextView.swift +538 -0
- package/Sources/UIKit/UIKit.swift +292 -0
- package/Sources/UIKit/UIView.swift +855 -0
- package/Sources/UIKit/ViewTranslation.swift +311 -0
- package/Sources/UniformTypeIdentifiers/UTType.swift +196 -0
- package/Sources/UserNotifications/Content.swift +370 -0
- package/Sources/UserNotifications/NotificationCenter.swift +309 -0
- package/Sources/WeatherKit/WeatherKit.swift +228 -0
- package/Sources/WebKit/WebKit.swift +245 -0
- package/Sources/os/os.swift +376 -0
- package/Sources/zlib/zlib.swift +6 -0
- package/index.d.ts +2 -0
- package/index.mjs +16 -0
- package/manifest.d.mts +2 -0
- package/manifest.mjs +39 -0
- package/package.json +30 -4
- package/sync-sources.mjs +33 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Subscription.swift
|
|
3
|
+
// OpenCombine
|
|
4
|
+
//
|
|
5
|
+
// Created by Sergej Jaskiewicz on 10.06.2019.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
/// A protocol representing the connection of a subscriber to a publisher.
|
|
9
|
+
///
|
|
10
|
+
/// Subscriptions are class constrained because a `Subscription` has identity -
|
|
11
|
+
/// defined by the moment in time a particular subscriber attached to a publisher.
|
|
12
|
+
/// Canceling a `Subscription` must be thread-safe.
|
|
13
|
+
///
|
|
14
|
+
/// You can only cancel a `Subscription` once.
|
|
15
|
+
///
|
|
16
|
+
/// Canceling a subscription frees up any resources previously allocated by attaching
|
|
17
|
+
/// the `Subscriber`.
|
|
18
|
+
public protocol Subscription: Cancellable, CustomCombineIdentifierConvertible {
|
|
19
|
+
|
|
20
|
+
/// Tells a publisher that it may send more values to the subscriber.
|
|
21
|
+
func request(_ demand: Subscribers.Demand)
|
|
22
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Subscriptions.swift
|
|
3
|
+
//
|
|
4
|
+
//
|
|
5
|
+
// Created by Sergej Jaskiewicz on 26.06.2019.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
/// A namespace for symbols related to subscriptions.
|
|
9
|
+
public enum Subscriptions {}
|
|
10
|
+
|
|
11
|
+
extension Subscriptions {
|
|
12
|
+
|
|
13
|
+
/// Returns the “empty” subscription.
|
|
14
|
+
///
|
|
15
|
+
/// Use the empty subscription when you need a `Subscription` that ignores requests
|
|
16
|
+
/// and cancellation.
|
|
17
|
+
public static let empty: Subscription = _EmptySubscription.singleton
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
extension Subscriptions {
|
|
21
|
+
private struct _EmptySubscription: Subscription,
|
|
22
|
+
CustomStringConvertible,
|
|
23
|
+
CustomReflectable,
|
|
24
|
+
CustomPlaygroundDisplayConvertible
|
|
25
|
+
{
|
|
26
|
+
let combineIdentifier = CombineIdentifier()
|
|
27
|
+
|
|
28
|
+
private init() {}
|
|
29
|
+
|
|
30
|
+
func request(_ demand: Subscribers.Demand) {}
|
|
31
|
+
|
|
32
|
+
func cancel() {}
|
|
33
|
+
|
|
34
|
+
fileprivate static let singleton = _EmptySubscription()
|
|
35
|
+
|
|
36
|
+
var description: String { return "Empty" }
|
|
37
|
+
|
|
38
|
+
var customMirror: Mirror { return Mirror(self, children: EmptyCollection()) }
|
|
39
|
+
|
|
40
|
+
var playgroundDescription: Any { return description }
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// The browser's Combine is OpenCombine (https://github.com/OpenCombine/OpenCombine,
|
|
2
|
+
// MIT; LICENSE), built as the module `Combine` without its `ObservableObject`
|
|
3
|
+
// and `@Published`: the SwiftUI shim has its own, which views observe, and
|
|
4
|
+
// they are re-exported here, so `import Combine` alone brings them as on
|
|
5
|
+
// Apple platforms. `#if WASI` selects OpenCombine's single-threaded locks on
|
|
6
|
+
// every platform (the browser has one thread). See docs/ops-protocol.md, "Combine".
|
|
7
|
+
|
|
8
|
+
@_exported import protocol SwiftUI.ObservableObject
|
|
9
|
+
@_exported import class SwiftUI.ObservableObjectPublisher
|
|
10
|
+
@_exported import struct SwiftUI.Published
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
//
|
|
2
|
+
// _Introspection.swift
|
|
3
|
+
//
|
|
4
|
+
//
|
|
5
|
+
// Created by Sergej Jaskiewicz on 27.09.2020.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
// swiftlint:disable:next type_name
|
|
9
|
+
public protocol _Introspection: AnyObject {
|
|
10
|
+
|
|
11
|
+
func willReceive<Upstream: Publisher, Downstream: Subscriber>(
|
|
12
|
+
publisher: Upstream,
|
|
13
|
+
subscriber: Downstream
|
|
14
|
+
) where Upstream.Failure == Downstream.Failure, Upstream.Output == Downstream.Input
|
|
15
|
+
|
|
16
|
+
func didReceive<Upstream: Publisher, Downstream: Subscriber>(
|
|
17
|
+
publisher: Upstream,
|
|
18
|
+
subscriber: Downstream
|
|
19
|
+
) where Upstream.Failure == Downstream.Failure, Upstream.Output == Downstream.Input
|
|
20
|
+
|
|
21
|
+
func willReceive<Downstream: Subscriber>(subscriber: Downstream,
|
|
22
|
+
subscription: Subscription)
|
|
23
|
+
|
|
24
|
+
func didReceive<Downstream: Subscriber>(subscriber: Downstream,
|
|
25
|
+
subscription: Subscription)
|
|
26
|
+
|
|
27
|
+
func willReceive<Downstream: Subscriber>(subscriber: Downstream,
|
|
28
|
+
input: Downstream.Input)
|
|
29
|
+
|
|
30
|
+
func didReceive<Downstream: Subscriber>(subscriber: Downstream,
|
|
31
|
+
input: Downstream.Input,
|
|
32
|
+
resultingDemand: Subscribers.Demand)
|
|
33
|
+
|
|
34
|
+
func willReceive<Downstream: Subscriber>(
|
|
35
|
+
subscriber: Downstream,
|
|
36
|
+
completion: Subscribers.Completion<Downstream.Failure>
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
func didReceive<Downstream: Subscriber>(
|
|
40
|
+
subscriber: Downstream,
|
|
41
|
+
completion: Subscribers.Completion<Downstream.Failure>
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
func willRequest(subscription: Subscription, _ demand: Subscribers.Demand)
|
|
45
|
+
|
|
46
|
+
func didRequest(subscription: Subscription, _ demand: Subscribers.Demand)
|
|
47
|
+
|
|
48
|
+
func willCancel(subscription: Subscription)
|
|
49
|
+
|
|
50
|
+
func didCancel(subscription: Subscription)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
extension _Introspection {
|
|
54
|
+
|
|
55
|
+
public func willReceive<Upstream: Publisher, Downstream: Subscriber>(
|
|
56
|
+
publisher: Upstream,
|
|
57
|
+
subscriber: Downstream
|
|
58
|
+
) where Upstream.Failure == Downstream.Failure, Upstream.Output == Downstream.Input {}
|
|
59
|
+
|
|
60
|
+
public func didReceive<Upstream: Publisher, Downstream: Subscriber>(
|
|
61
|
+
publisher: Upstream,
|
|
62
|
+
subscriber: Downstream
|
|
63
|
+
) where Upstream.Failure == Downstream.Failure, Upstream.Output == Downstream.Input {}
|
|
64
|
+
|
|
65
|
+
public func willReceive<Downstream: Subscriber>(subscriber: Downstream,
|
|
66
|
+
subscription: Subscription) {}
|
|
67
|
+
|
|
68
|
+
public func didReceive<Downstream: Subscriber>(subscriber: Downstream,
|
|
69
|
+
subscription: Subscription) {}
|
|
70
|
+
|
|
71
|
+
public func willReceive<Downstream: Subscriber>(subscriber: Downstream,
|
|
72
|
+
input: Downstream.Input) {}
|
|
73
|
+
|
|
74
|
+
public func didReceive<Downstream: Subscriber>(subscriber: Downstream,
|
|
75
|
+
input: Downstream.Input,
|
|
76
|
+
resultingDemand: Subscribers.Demand) {}
|
|
77
|
+
|
|
78
|
+
public func willReceive<Downstream: Subscriber>(
|
|
79
|
+
subscriber: Downstream,
|
|
80
|
+
completion: Subscribers.Completion<Downstream.Failure>
|
|
81
|
+
) {}
|
|
82
|
+
|
|
83
|
+
public func didReceive<Downstream: Subscriber>(
|
|
84
|
+
subscriber: Downstream,
|
|
85
|
+
completion: Subscribers.Completion<Downstream.Failure>
|
|
86
|
+
) {}
|
|
87
|
+
|
|
88
|
+
public func willRequest(subscription: Subscription, _ demand: Subscribers.Demand) {}
|
|
89
|
+
|
|
90
|
+
public func didRequest(subscription: Subscription, _ demand: Subscribers.Demand) {}
|
|
91
|
+
|
|
92
|
+
public func willCancel(subscription: Subscription) {}
|
|
93
|
+
|
|
94
|
+
public func didCancel(subscription: Subscription) {}
|
|
95
|
+
|
|
96
|
+
public func enable() {
|
|
97
|
+
DebugHook.enable(self)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
public func disable() {
|
|
101
|
+
DebugHook.disable(self)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
public var isEnabled: Bool {
|
|
105
|
+
return DebugHook.handlerIsEnabled(self)
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// `import CommonCrypto` for the browser: the digest functions of
|
|
2
|
+
// CommonDigest.h, as packages call them from Swift (TelemetryDeck hashes its
|
|
3
|
+
// user identifiers with `CC_SHA256`). The hashing is CryptoKit's.
|
|
4
|
+
|
|
5
|
+
import CryptoKit
|
|
6
|
+
|
|
7
|
+
public typealias CC_LONG = UInt32
|
|
8
|
+
|
|
9
|
+
public let CC_MD5_DIGEST_LENGTH: Int32 = 16
|
|
10
|
+
public let CC_SHA1_DIGEST_LENGTH: Int32 = 20
|
|
11
|
+
public let CC_SHA256_DIGEST_LENGTH: Int32 = 32
|
|
12
|
+
public let CC_SHA384_DIGEST_LENGTH: Int32 = 48
|
|
13
|
+
public let CC_SHA512_DIGEST_LENGTH: Int32 = 64
|
|
14
|
+
public let CC_MD5_BLOCK_BYTES: Int32 = 64
|
|
15
|
+
public let CC_SHA1_BLOCK_BYTES: Int32 = 64
|
|
16
|
+
public let CC_SHA256_BLOCK_BYTES: Int32 = 64
|
|
17
|
+
public let CC_SHA384_BLOCK_BYTES: Int32 = 128
|
|
18
|
+
public let CC_SHA512_BLOCK_BYTES: Int32 = 128
|
|
19
|
+
|
|
20
|
+
/// Hashes `len` bytes at `data` and writes the digest to `md`, which it returns.
|
|
21
|
+
func _digest<H: HashFunction>(_ hasher: H.Type, _ data: UnsafeRawPointer?, _ len: CC_LONG, _ md: UnsafeMutablePointer<UInt8>?) -> UnsafeMutablePointer<UInt8>? {
|
|
22
|
+
var hasher = H()
|
|
23
|
+
if let data { hasher.update(bufferPointer: UnsafeRawBufferPointer(start: data, count: Int(len))) }
|
|
24
|
+
return _write(hasher.finalize(), to: md)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
func _write<D: Digest>(_ digest: D, to md: UnsafeMutablePointer<UInt8>?) -> UnsafeMutablePointer<UInt8>? {
|
|
28
|
+
guard let md else { return nil }
|
|
29
|
+
for (i, byte) in digest.enumerated() { md[i] = byte }
|
|
30
|
+
return md
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@discardableResult public func CC_MD5(_ data: UnsafeRawPointer?, _ len: CC_LONG, _ md: UnsafeMutablePointer<UInt8>?) -> UnsafeMutablePointer<UInt8>? { _digest(Insecure.MD5.self, data, len, md) }
|
|
34
|
+
@discardableResult public func CC_SHA1(_ data: UnsafeRawPointer?, _ len: CC_LONG, _ md: UnsafeMutablePointer<UInt8>?) -> UnsafeMutablePointer<UInt8>? { _digest(Insecure.SHA1.self, data, len, md) }
|
|
35
|
+
@discardableResult public func CC_SHA256(_ data: UnsafeRawPointer?, _ len: CC_LONG, _ md: UnsafeMutablePointer<UInt8>?) -> UnsafeMutablePointer<UInt8>? { _digest(SHA256.self, data, len, md) }
|
|
36
|
+
@discardableResult public func CC_SHA384(_ data: UnsafeRawPointer?, _ len: CC_LONG, _ md: UnsafeMutablePointer<UInt8>?) -> UnsafeMutablePointer<UInt8>? { _digest(SHA384.self, data, len, md) }
|
|
37
|
+
@discardableResult public func CC_SHA512(_ data: UnsafeRawPointer?, _ len: CC_LONG, _ md: UnsafeMutablePointer<UInt8>?) -> UnsafeMutablePointer<UInt8>? { _digest(SHA512.self, data, len, md) }
|
|
38
|
+
|
|
39
|
+
// MARK: - Incremental hashing
|
|
40
|
+
|
|
41
|
+
/// A hash in progress, as `CC_SHA256_CTX` and its kin hold one.
|
|
42
|
+
public struct _CCContext<H: HashFunction>: Sendable {
|
|
43
|
+
var hasher = H()
|
|
44
|
+
public init() {}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public typealias CC_MD5_CTX = _CCContext<Insecure.MD5>
|
|
48
|
+
public typealias CC_SHA1_CTX = _CCContext<Insecure.SHA1>
|
|
49
|
+
public typealias CC_SHA256_CTX = _CCContext<SHA256>
|
|
50
|
+
public typealias CC_SHA512_CTX = _CCContext<SHA512>
|
|
51
|
+
|
|
52
|
+
func _init<H>(_ c: UnsafeMutablePointer<_CCContext<H>>?) -> Int32 {
|
|
53
|
+
c?.pointee = _CCContext()
|
|
54
|
+
return 1
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
func _update<H>(_ c: UnsafeMutablePointer<_CCContext<H>>?, _ data: UnsafeRawPointer?, _ len: CC_LONG) -> Int32 {
|
|
58
|
+
guard let c, let data else { return 1 }
|
|
59
|
+
c.pointee.hasher.update(bufferPointer: UnsafeRawBufferPointer(start: data, count: Int(len)))
|
|
60
|
+
return 1
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
func _final<H>(_ md: UnsafeMutablePointer<UInt8>?, _ c: UnsafeMutablePointer<_CCContext<H>>?) -> Int32 {
|
|
64
|
+
guard let c else { return 0 }
|
|
65
|
+
_ = _write(c.pointee.hasher.finalize(), to: md)
|
|
66
|
+
return 1
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
@discardableResult public func CC_MD5_Init(_ c: UnsafeMutablePointer<CC_MD5_CTX>?) -> Int32 { _init(c) }
|
|
70
|
+
@discardableResult public func CC_MD5_Update(_ c: UnsafeMutablePointer<CC_MD5_CTX>?, _ data: UnsafeRawPointer?, _ len: CC_LONG) -> Int32 { _update(c, data, len) }
|
|
71
|
+
@discardableResult public func CC_MD5_Final(_ md: UnsafeMutablePointer<UInt8>?, _ c: UnsafeMutablePointer<CC_MD5_CTX>?) -> Int32 { _final(md, c) }
|
|
72
|
+
@discardableResult public func CC_SHA1_Init(_ c: UnsafeMutablePointer<CC_SHA1_CTX>?) -> Int32 { _init(c) }
|
|
73
|
+
@discardableResult public func CC_SHA1_Update(_ c: UnsafeMutablePointer<CC_SHA1_CTX>?, _ data: UnsafeRawPointer?, _ len: CC_LONG) -> Int32 { _update(c, data, len) }
|
|
74
|
+
@discardableResult public func CC_SHA1_Final(_ md: UnsafeMutablePointer<UInt8>?, _ c: UnsafeMutablePointer<CC_SHA1_CTX>?) -> Int32 { _final(md, c) }
|
|
75
|
+
@discardableResult public func CC_SHA256_Init(_ c: UnsafeMutablePointer<CC_SHA256_CTX>?) -> Int32 { _init(c) }
|
|
76
|
+
@discardableResult public func CC_SHA256_Update(_ c: UnsafeMutablePointer<CC_SHA256_CTX>?, _ data: UnsafeRawPointer?, _ len: CC_LONG) -> Int32 { _update(c, data, len) }
|
|
77
|
+
@discardableResult public func CC_SHA256_Final(_ md: UnsafeMutablePointer<UInt8>?, _ c: UnsafeMutablePointer<CC_SHA256_CTX>?) -> Int32 { _final(md, c) }
|
|
78
|
+
@discardableResult public func CC_SHA512_Init(_ c: UnsafeMutablePointer<CC_SHA512_CTX>?) -> Int32 { _init(c) }
|
|
79
|
+
@discardableResult public func CC_SHA512_Update(_ c: UnsafeMutablePointer<CC_SHA512_CTX>?, _ data: UnsafeRawPointer?, _ len: CC_LONG) -> Int32 { _update(c, data, len) }
|
|
80
|
+
@discardableResult public func CC_SHA512_Final(_ md: UnsafeMutablePointer<UInt8>?, _ c: UnsafeMutablePointer<CC_SHA512_CTX>?) -> Int32 { _final(md, c) }
|
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
// `import Compression` for the browser: Apple's Compression framework as
|
|
2
|
+
// Swift code calls it, for its zlib algorithm (raw DEFLATE, as on Apple
|
|
3
|
+
// platforms), computed for real in Swift (Deflate.swift): the buffer
|
|
4
|
+
// functions (`compression_encode_buffer` / `compression_decode_buffer`), the
|
|
5
|
+
// `compression_stream` functions, and the Swift overlay's `InputFilter` and
|
|
6
|
+
// `OutputFilter`. The other algorithms (LZFSE, LZ4, LZMA, Brotli, LZBitmap)
|
|
7
|
+
// have no codec here: their constants exist, `Algorithm(rawValue:)` answers
|
|
8
|
+
// nil for them so code that probes for one falls back (RevenueCat then asks
|
|
9
|
+
// its server for gzip instead of Brotli), and using one fails the way a
|
|
10
|
+
// failed call fails on Apple platforms (0 bytes, an error status, a thrown
|
|
11
|
+
// `FilterError`). zlib's own `inflate` API is in Zlib.swift.
|
|
12
|
+
|
|
13
|
+
import Foundation
|
|
14
|
+
|
|
15
|
+
// MARK: - The C API (compression.h)
|
|
16
|
+
|
|
17
|
+
/// An algorithm, as compression.h's enum imports into Swift.
|
|
18
|
+
public struct compression_algorithm: RawRepresentable, Equatable, Hashable, Sendable {
|
|
19
|
+
public var rawValue: UInt32
|
|
20
|
+
public init(_ rawValue: UInt32) { self.rawValue = rawValue }
|
|
21
|
+
public init(rawValue: UInt32) { self.rawValue = rawValue }
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/// DEFLATE without the zlib header or trailer (RFC 1951). The one algorithm
|
|
25
|
+
/// the browser has a codec for.
|
|
26
|
+
public let COMPRESSION_ZLIB = compression_algorithm(0x205)
|
|
27
|
+
/// No codec in the browser: encoding and decoding fail.
|
|
28
|
+
public let COMPRESSION_LZ4 = compression_algorithm(0x100)
|
|
29
|
+
/// No codec in the browser: encoding and decoding fail.
|
|
30
|
+
public let COMPRESSION_LZ4_RAW = compression_algorithm(0x101)
|
|
31
|
+
/// No codec in the browser: encoding and decoding fail.
|
|
32
|
+
public let COMPRESSION_LZMA = compression_algorithm(0x306)
|
|
33
|
+
/// No codec in the browser: encoding and decoding fail.
|
|
34
|
+
public let COMPRESSION_LZFSE = compression_algorithm(0x801)
|
|
35
|
+
/// No codec in the browser: encoding and decoding fail.
|
|
36
|
+
public let COMPRESSION_LZBITMAP = compression_algorithm(0x702)
|
|
37
|
+
/// No codec in the browser: encoding and decoding fail.
|
|
38
|
+
public let COMPRESSION_BROTLI = compression_algorithm(0xb02)
|
|
39
|
+
|
|
40
|
+
public struct compression_status: RawRepresentable, Equatable, Hashable, Sendable {
|
|
41
|
+
public var rawValue: Int32
|
|
42
|
+
public init(_ rawValue: Int32) { self.rawValue = rawValue }
|
|
43
|
+
public init(rawValue: Int32) { self.rawValue = rawValue }
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public let COMPRESSION_STATUS_OK = compression_status(0)
|
|
47
|
+
public let COMPRESSION_STATUS_ERROR = compression_status(-1)
|
|
48
|
+
public let COMPRESSION_STATUS_END = compression_status(1)
|
|
49
|
+
|
|
50
|
+
public struct compression_stream_operation: RawRepresentable, Equatable, Hashable, Sendable {
|
|
51
|
+
public var rawValue: UInt32
|
|
52
|
+
public init(_ rawValue: UInt32) { self.rawValue = rawValue }
|
|
53
|
+
public init(rawValue: UInt32) { self.rawValue = rawValue }
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public let COMPRESSION_STREAM_ENCODE = compression_stream_operation(0)
|
|
57
|
+
public let COMPRESSION_STREAM_DECODE = compression_stream_operation(1)
|
|
58
|
+
|
|
59
|
+
public struct compression_stream_flags: RawRepresentable, Equatable, Hashable, Sendable {
|
|
60
|
+
public var rawValue: UInt32
|
|
61
|
+
public init(_ rawValue: UInt32) { self.rawValue = rawValue }
|
|
62
|
+
public init(rawValue: UInt32) { self.rawValue = rawValue }
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/// Passed to `compression_stream_process` when no more input follows.
|
|
66
|
+
public let COMPRESSION_STREAM_FINALIZE = compression_stream_flags(1)
|
|
67
|
+
|
|
68
|
+
/// The scratch space the buffer functions want: none in the browser.
|
|
69
|
+
public func compression_encode_scratch_buffer_size(_ algorithm: compression_algorithm) -> Int { 0 }
|
|
70
|
+
/// The scratch space the buffer functions want: none in the browser.
|
|
71
|
+
public func compression_decode_scratch_buffer_size(_ algorithm: compression_algorithm) -> Int { 0 }
|
|
72
|
+
|
|
73
|
+
/// Compresses `src_size` bytes into `dst_buffer`. Returns the compressed
|
|
74
|
+
/// size, or 0 if it does not fit in `dst_size` bytes or the algorithm has no
|
|
75
|
+
/// codec in the browser.
|
|
76
|
+
public func compression_encode_buffer(
|
|
77
|
+
_ dst_buffer: UnsafeMutablePointer<UInt8>, _ dst_size: Int,
|
|
78
|
+
_ src_buffer: UnsafePointer<UInt8>, _ src_size: Int,
|
|
79
|
+
_ scratch_buffer: UnsafeMutableRawPointer?, _ algorithm: compression_algorithm
|
|
80
|
+
) -> Int {
|
|
81
|
+
guard algorithm == COMPRESSION_ZLIB else { return 0 }
|
|
82
|
+
let encoded = _Deflate.deflate(Array(UnsafeBufferPointer(start: src_buffer, count: src_size)))
|
|
83
|
+
guard encoded.count <= dst_size else { return 0 }
|
|
84
|
+
encoded.withUnsafeBufferPointer { dst_buffer.update(from: $0.baseAddress!, count: encoded.count) }
|
|
85
|
+
return encoded.count
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/// Decompresses `src_size` bytes into `dst_buffer`. Returns the
|
|
89
|
+
/// decompressed size; when that exceeds `dst_size`, the first `dst_size`
|
|
90
|
+
/// bytes are written and `dst_size` is returned (as on Apple platforms).
|
|
91
|
+
/// Returns 0 for invalid or truncated input, or an algorithm with no codec in
|
|
92
|
+
/// the browser.
|
|
93
|
+
public func compression_decode_buffer(
|
|
94
|
+
_ dst_buffer: UnsafeMutablePointer<UInt8>, _ dst_size: Int,
|
|
95
|
+
_ src_buffer: UnsafePointer<UInt8>, _ src_size: Int,
|
|
96
|
+
_ scratch_buffer: UnsafeMutableRawPointer?, _ algorithm: compression_algorithm
|
|
97
|
+
) -> Int {
|
|
98
|
+
guard algorithm == COMPRESSION_ZLIB,
|
|
99
|
+
let decoded = try? _Deflate.inflate(Array(UnsafeBufferPointer(start: src_buffer, count: src_size))).output
|
|
100
|
+
else { return 0 }
|
|
101
|
+
let count = min(decoded.count, dst_size)
|
|
102
|
+
decoded.withUnsafeBufferPointer { if count > 0 { dst_buffer.update(from: $0.baseAddress!, count: count) } }
|
|
103
|
+
return count
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/// A stream in progress, as compression.h declares it: the caller points
|
|
107
|
+
/// `src_ptr` / `dst_ptr` at its buffers and `compression_stream_process`
|
|
108
|
+
/// advances them.
|
|
109
|
+
public struct compression_stream {
|
|
110
|
+
public var dst_ptr: UnsafeMutablePointer<UInt8>!
|
|
111
|
+
public var dst_size: Int
|
|
112
|
+
public var src_ptr: UnsafePointer<UInt8>!
|
|
113
|
+
public var src_size: Int
|
|
114
|
+
public var state: UnsafeMutableRawPointer!
|
|
115
|
+
|
|
116
|
+
public init() {
|
|
117
|
+
dst_ptr = nil
|
|
118
|
+
dst_size = 0
|
|
119
|
+
src_ptr = nil
|
|
120
|
+
src_size = 0
|
|
121
|
+
state = nil
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
public init(dst_ptr: UnsafeMutablePointer<UInt8>!, dst_size: Int, src_ptr: UnsafePointer<UInt8>!, src_size: Int, state: UnsafeMutableRawPointer!) {
|
|
125
|
+
self.dst_ptr = dst_ptr
|
|
126
|
+
self.dst_size = dst_size
|
|
127
|
+
self.src_ptr = src_ptr
|
|
128
|
+
self.src_size = src_size
|
|
129
|
+
self.state = state
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/// Starts a stream. `COMPRESSION_STATUS_ERROR` for an algorithm with no codec
|
|
134
|
+
/// in the browser.
|
|
135
|
+
public func compression_stream_init(
|
|
136
|
+
_ stream: UnsafeMutablePointer<compression_stream>,
|
|
137
|
+
_ operation: compression_stream_operation,
|
|
138
|
+
_ algorithm: compression_algorithm
|
|
139
|
+
) -> compression_status {
|
|
140
|
+
guard algorithm == COMPRESSION_ZLIB, operation == COMPRESSION_STREAM_ENCODE || operation == COMPRESSION_STREAM_DECODE else {
|
|
141
|
+
return COMPRESSION_STATUS_ERROR
|
|
142
|
+
}
|
|
143
|
+
let codec = _StreamCodec(encoding: operation == COMPRESSION_STREAM_ENCODE, format: .raw)
|
|
144
|
+
stream.pointee.state = Unmanaged.passRetained(codec).toOpaque()
|
|
145
|
+
return COMPRESSION_STATUS_OK
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/// Consumes input from `src_ptr` and writes output to `dst_ptr`, advancing
|
|
149
|
+
/// both. Returns `COMPRESSION_STATUS_END` once the whole stream has been
|
|
150
|
+
/// written out. The encoder writes its output once it is finalized; the
|
|
151
|
+
/// decoder writes it once the input holds the whole stream.
|
|
152
|
+
public func compression_stream_process(_ stream: UnsafeMutablePointer<compression_stream>, _ flags: Int32) -> compression_status {
|
|
153
|
+
guard let state = stream.pointee.state else { return COMPRESSION_STATUS_ERROR }
|
|
154
|
+
let codec = Unmanaged<_StreamCodec>.fromOpaque(state).takeUnretainedValue()
|
|
155
|
+
let input = stream.pointee.src_size > 0 ? UnsafeRawBufferPointer(start: stream.pointee.src_ptr, count: stream.pointee.src_size) : UnsafeRawBufferPointer(start: nil, count: 0)
|
|
156
|
+
let finalize = UInt32(bitPattern: flags) & COMPRESSION_STREAM_FINALIZE.rawValue != 0
|
|
157
|
+
let consumed: Int
|
|
158
|
+
do {
|
|
159
|
+
consumed = try codec.consume(input, finish: finalize)
|
|
160
|
+
} catch {
|
|
161
|
+
return COMPRESSION_STATUS_ERROR
|
|
162
|
+
}
|
|
163
|
+
stream.pointee.src_ptr = stream.pointee.src_ptr.map { $0 + consumed }
|
|
164
|
+
stream.pointee.src_size -= consumed
|
|
165
|
+
if finalize, !codec.finished { return COMPRESSION_STATUS_ERROR } // the input ended mid-stream
|
|
166
|
+
let written = codec.drain(into: stream.pointee.dst_ptr, capacity: stream.pointee.dst_size)
|
|
167
|
+
stream.pointee.dst_ptr = stream.pointee.dst_ptr.map { $0 + written }
|
|
168
|
+
stream.pointee.dst_size -= written
|
|
169
|
+
return codec.isDone ? COMPRESSION_STATUS_END : COMPRESSION_STATUS_OK
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/// Frees what `compression_stream_init` allocated.
|
|
173
|
+
public func compression_stream_destroy(_ stream: UnsafeMutablePointer<compression_stream>) -> compression_status {
|
|
174
|
+
guard let state = stream.pointee.state else { return COMPRESSION_STATUS_ERROR }
|
|
175
|
+
Unmanaged<_StreamCodec>.fromOpaque(state).release()
|
|
176
|
+
stream.pointee.state = nil
|
|
177
|
+
return COMPRESSION_STATUS_OK
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// MARK: - Streaming over whole-buffer codecs
|
|
181
|
+
|
|
182
|
+
/// A stream over the whole-buffer codecs: input accumulates until it holds
|
|
183
|
+
/// the whole stream (decoding) or until it is finalized (encoding); then the
|
|
184
|
+
/// output is handed out in as many pieces as the caller's buffers need. A
|
|
185
|
+
/// decoder retries only when the input has doubled since the last attempt,
|
|
186
|
+
/// when no new input came, or when finishing, so the work stays linear.
|
|
187
|
+
final class _StreamCodec {
|
|
188
|
+
let encoding: Bool
|
|
189
|
+
let format: _Deflate.Format
|
|
190
|
+
var input: [UInt8] = []
|
|
191
|
+
var output: [UInt8] = []
|
|
192
|
+
var outputPosition = 0
|
|
193
|
+
var finished = false
|
|
194
|
+
var attemptedAt = 0
|
|
195
|
+
/// zlib's running checksum (`z_stream.adler`) of the decoded output, once known.
|
|
196
|
+
var checksum: UInt32 = 0
|
|
197
|
+
|
|
198
|
+
init(encoding: Bool, format: _Deflate.Format) {
|
|
199
|
+
self.encoding = encoding
|
|
200
|
+
self.format = format
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
var isDone: Bool { finished && outputPosition == output.count }
|
|
204
|
+
|
|
205
|
+
/// Takes `bytes` and runs the codec if it is time to. Returns how many of
|
|
206
|
+
/// `bytes` were used: input after the end of a decoded stream is left over.
|
|
207
|
+
func consume(_ bytes: UnsafeRawBufferPointer, finish: Bool) throws(_Deflate.Failure) -> Int {
|
|
208
|
+
guard !finished else { return 0 }
|
|
209
|
+
input.append(contentsOf: bytes)
|
|
210
|
+
if encoding {
|
|
211
|
+
if finish {
|
|
212
|
+
output = _Deflate.deflate(input)
|
|
213
|
+
input = []
|
|
214
|
+
finished = true
|
|
215
|
+
}
|
|
216
|
+
return bytes.count
|
|
217
|
+
}
|
|
218
|
+
guard finish || bytes.isEmpty || input.count >= max(1, attemptedAt * 2) else { return bytes.count }
|
|
219
|
+
attemptedAt = input.count
|
|
220
|
+
do {
|
|
221
|
+
let (decoded, end) = try _Deflate.inflate(input, format: format)
|
|
222
|
+
output = decoded
|
|
223
|
+
finished = true
|
|
224
|
+
if format != .raw {
|
|
225
|
+
let gzip = format == .gzip || (format == .automatic && input.first == 0x1f)
|
|
226
|
+
checksum = gzip ? _Deflate.crc32(decoded) : _Deflate.adler32(decoded)
|
|
227
|
+
}
|
|
228
|
+
// Bytes after the stream: give back those that came in this call.
|
|
229
|
+
let unused = min(input.count - end, bytes.count)
|
|
230
|
+
input = []
|
|
231
|
+
return bytes.count - unused
|
|
232
|
+
} catch .truncated {
|
|
233
|
+
return bytes.count
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/// Copies the next output into `destination`; returns how many bytes.
|
|
238
|
+
func drain(into destination: UnsafeMutablePointer<UInt8>?, capacity: Int) -> Int {
|
|
239
|
+
let count = min(capacity, output.count - outputPosition)
|
|
240
|
+
guard count > 0, let destination else { return 0 }
|
|
241
|
+
output.withUnsafeBufferPointer { destination.update(from: $0.baseAddress! + outputPosition, count: count) }
|
|
242
|
+
outputPosition += count
|
|
243
|
+
if outputPosition == output.count, finished {
|
|
244
|
+
output = []
|
|
245
|
+
outputPosition = 0
|
|
246
|
+
}
|
|
247
|
+
return count
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// MARK: - The Swift overlay
|
|
252
|
+
|
|
253
|
+
/// The algorithms, as the Swift overlay names them. Only `.zlib` has a codec
|
|
254
|
+
/// in the browser, so `init(rawValue:)` answers nil for the others; a filter
|
|
255
|
+
/// made with one throws `FilterError.invalidState`.
|
|
256
|
+
public enum Algorithm: CaseIterable, RawRepresentable, Sendable {
|
|
257
|
+
case lzfse, zlib, lz4, lzma, brotli, lzbitmap
|
|
258
|
+
|
|
259
|
+
public init?(rawValue: compression_algorithm) {
|
|
260
|
+
guard rawValue == COMPRESSION_ZLIB else { return nil }
|
|
261
|
+
self = .zlib
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
public var rawValue: compression_algorithm {
|
|
265
|
+
switch self {
|
|
266
|
+
case .lzfse: COMPRESSION_LZFSE
|
|
267
|
+
case .zlib: COMPRESSION_ZLIB
|
|
268
|
+
case .lz4: COMPRESSION_LZ4
|
|
269
|
+
case .lzma: COMPRESSION_LZMA
|
|
270
|
+
case .brotli: COMPRESSION_BROTLI
|
|
271
|
+
case .lzbitmap: COMPRESSION_LZBITMAP
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
public enum FilterOperation: Sendable {
|
|
277
|
+
case compress, decompress
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
public enum FilterError: Error, Sendable {
|
|
281
|
+
case invalidState, invalidData, writingToFinalizedFilter, readingFromEndOfStream
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/// Compresses or decompresses data written to it, handing the result to
|
|
285
|
+
/// `writeFunc` in pieces of up to `bufferCapacity` bytes, then nil at the end.
|
|
286
|
+
public class OutputFilter {
|
|
287
|
+
let codec: _StreamCodec
|
|
288
|
+
let bufferCapacity: Int
|
|
289
|
+
let writeFunc: (Data?) throws -> Void
|
|
290
|
+
var finalized = false
|
|
291
|
+
|
|
292
|
+
public init(_ operation: FilterOperation, using algorithm: Algorithm, bufferCapacity: Int = 65536, writingTo writeFunc: @escaping (Data?) throws -> Void) throws {
|
|
293
|
+
guard algorithm == .zlib, bufferCapacity > 0 else { throw FilterError.invalidState }
|
|
294
|
+
codec = _StreamCodec(encoding: operation == .compress, format: .raw)
|
|
295
|
+
self.bufferCapacity = bufferCapacity
|
|
296
|
+
self.writeFunc = writeFunc
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/// Takes more input; nil or empty data finalizes the filter.
|
|
300
|
+
public func write<D: DataProtocol>(_ data: D?) throws {
|
|
301
|
+
guard let data, !data.isEmpty else { return try finalize() }
|
|
302
|
+
guard !finalized else { throw FilterError.writingToFinalizedFilter }
|
|
303
|
+
let bytes = [UInt8](data)
|
|
304
|
+
try bytes.withUnsafeBytes { buffer in try process(buffer, finish: false) }
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/// Ends the input and writes out the rest. Does nothing the second time.
|
|
308
|
+
public func finalize() throws {
|
|
309
|
+
guard !finalized else { return }
|
|
310
|
+
try process(UnsafeRawBufferPointer(start: nil, count: 0), finish: true)
|
|
311
|
+
guard codec.isDone else { throw FilterError.invalidData }
|
|
312
|
+
finalized = true
|
|
313
|
+
try writeFunc(nil)
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
func process(_ bytes: UnsafeRawBufferPointer, finish: Bool) throws {
|
|
317
|
+
do { _ = try codec.consume(bytes, finish: finish) } catch { throw FilterError.invalidData }
|
|
318
|
+
var chunk = [UInt8](repeating: 0, count: bufferCapacity)
|
|
319
|
+
while true {
|
|
320
|
+
let count = chunk.withUnsafeMutableBufferPointer { codec.drain(into: $0.baseAddress, capacity: bufferCapacity) }
|
|
321
|
+
if count == 0 { break }
|
|
322
|
+
try writeFunc(Data(chunk[0..<count]))
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/// Compresses or decompresses what `readFunc` supplies (it is asked for up
|
|
328
|
+
/// to `bufferCapacity` bytes at a time and answers nil or empty data at the
|
|
329
|
+
/// end), handing out the result through `readData(ofLength:)`.
|
|
330
|
+
public class InputFilter<D: DataProtocol> {
|
|
331
|
+
let codec: _StreamCodec
|
|
332
|
+
let bufferCapacity: Int
|
|
333
|
+
let readFunc: (Int) throws -> D?
|
|
334
|
+
var inputEnded = false
|
|
335
|
+
|
|
336
|
+
public init(_ operation: FilterOperation, using algorithm: Algorithm, bufferCapacity: Int = 65536, readingFrom readFunc: @escaping (Int) throws -> D?) throws {
|
|
337
|
+
guard algorithm == .zlib, bufferCapacity > 0 else { throw FilterError.invalidState }
|
|
338
|
+
codec = _StreamCodec(encoding: operation == .compress, format: .raw)
|
|
339
|
+
self.bufferCapacity = bufferCapacity
|
|
340
|
+
self.readFunc = readFunc
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/// Up to `count` bytes of output, or nil once all of it has been read.
|
|
344
|
+
public func readData(ofLength count: Int) throws -> Data? {
|
|
345
|
+
var result = Data()
|
|
346
|
+
while result.count < count {
|
|
347
|
+
var chunk = [UInt8](repeating: 0, count: count - result.count)
|
|
348
|
+
let written = chunk.withUnsafeMutableBufferPointer { codec.drain(into: $0.baseAddress, capacity: $0.count) }
|
|
349
|
+
if written > 0 {
|
|
350
|
+
result.append(contentsOf: chunk[0..<written])
|
|
351
|
+
continue
|
|
352
|
+
}
|
|
353
|
+
if codec.isDone { break }
|
|
354
|
+
guard !inputEnded else { throw FilterError.invalidData } // the input ended mid-stream
|
|
355
|
+
let next = try readFunc(bufferCapacity).map { [UInt8]($0) } ?? []
|
|
356
|
+
if next.isEmpty { inputEnded = true }
|
|
357
|
+
do {
|
|
358
|
+
_ = try next.withUnsafeBytes { buffer throws(_Deflate.Failure) in try codec.consume(buffer, finish: next.isEmpty) }
|
|
359
|
+
} catch {
|
|
360
|
+
throw FilterError.invalidData
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
return result.isEmpty && codec.isDone ? nil : result
|
|
364
|
+
}
|
|
365
|
+
}
|