@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.
Files changed (400) hide show
  1. package/Package.swift +214 -0
  2. package/README.md +10 -2
  3. package/Sources/AVFoundation/AVFoundation.swift +131 -0
  4. package/Sources/AVFoundation/Asset.swift +487 -0
  5. package/Sources/AVFoundation/AudioSession.swift +144 -0
  6. package/Sources/AVFoundation/CMTime.swift +303 -0
  7. package/Sources/AVFoundation/Capture.swift +688 -0
  8. package/Sources/AVFoundation/Player.swift +749 -0
  9. package/Sources/AVFoundation/PlayerView.swift +117 -0
  10. package/Sources/AVKit/AVKit.swift +132 -0
  11. package/Sources/Accelerate/Accelerate.swift +122 -0
  12. package/Sources/AppIntents/AppIntents.swift +144 -0
  13. package/Sources/AppIntents/Parameters.swift +220 -0
  14. package/Sources/AppIntents/Shortcuts.swift +159 -0
  15. package/Sources/AudioToolbox/AudioToolbox.swift +55 -0
  16. package/Sources/AuthenticationServices/AuthenticationServices.swift +257 -0
  17. package/Sources/AuthenticationServices/Authorization.swift +251 -0
  18. package/Sources/Charts/Charts.swift +61 -0
  19. package/Sources/Combine/AnyCancellable.swift +65 -0
  20. package/Sources/Combine/AnyPublisher.swift +148 -0
  21. package/Sources/Combine/AnySubscriber.swift +230 -0
  22. package/Sources/Combine/Cancellable.swift +35 -0
  23. package/Sources/Combine/Codable.swift +29 -0
  24. package/Sources/Combine/CombineIdentifier.swift +45 -0
  25. package/Sources/Combine/Concurrency/ConcurrencyHelpers.swift +24 -0
  26. package/Sources/Combine/Concurrency/Future+Concurrency.swift +136 -0
  27. package/Sources/Combine/Concurrency/GENERATED-Publisher+Concurrency.swift +397 -0
  28. package/Sources/Combine/CurrentValueSubject.swift +252 -0
  29. package/Sources/Combine/CustomCombineIdentifierConvertible.swift +28 -0
  30. package/Sources/Combine/Future.swift +228 -0
  31. package/Sources/Combine/GENERATED-RootProtocols.swift +426 -0
  32. package/Sources/Combine/Helpers/ConduitBase.swift +40 -0
  33. package/Sources/Combine/Helpers/ConduitList.swift +59 -0
  34. package/Sources/Combine/Helpers/DebugHook.swift +177 -0
  35. package/Sources/Combine/Helpers/FilterProducer.swift +174 -0
  36. package/Sources/Combine/Helpers/Locking.swift +30 -0
  37. package/Sources/Combine/Helpers/PartialCompletion.swift +26 -0
  38. package/Sources/Combine/Helpers/ReduceProducer.swift +249 -0
  39. package/Sources/Combine/Helpers/SubjectSubscriber.swift +96 -0
  40. package/Sources/Combine/Helpers/SubscriberTap.swift +69 -0
  41. package/Sources/Combine/Helpers/SubscriptionStatus.swift +33 -0
  42. package/Sources/Combine/Helpers/SubscriptionTap.swift +33 -0
  43. package/Sources/Combine/Helpers/Utils.swift +30 -0
  44. package/Sources/Combine/Helpers/Violations.swift +33 -0
  45. package/Sources/Combine/ImmediateScheduler.swift +178 -0
  46. package/Sources/Combine/LICENSE +21 -0
  47. package/Sources/Combine/NotificationPublisher.swift +48 -0
  48. package/Sources/Combine/ObjectWillChange.swift +46 -0
  49. package/Sources/Combine/PassthroughSubject.swift +222 -0
  50. package/Sources/Combine/Publisher+Subscribe.swift +53 -0
  51. package/Sources/Combine/Publishers/Deferred.swift +48 -0
  52. package/Sources/Combine/Publishers/Empty.swift +54 -0
  53. package/Sources/Combine/Publishers/Fail.swift +42 -0
  54. package/Sources/Combine/Publishers/GENERATED-Publishers.Catch.swift +673 -0
  55. package/Sources/Combine/Publishers/GENERATED-Publishers.Encode.swift +388 -0
  56. package/Sources/Combine/Publishers/GENERATED-Publishers.MapKeyPath.swift +384 -0
  57. package/Sources/Combine/Publishers/Just.swift +313 -0
  58. package/Sources/Combine/Publishers/Optional.Publisher.swift +315 -0
  59. package/Sources/Combine/Publishers/Publishers.AllSatisfy.swift +217 -0
  60. package/Sources/Combine/Publishers/Publishers.AssertNoFailure.swift +158 -0
  61. package/Sources/Combine/Publishers/Publishers.Autoconnect.swift +193 -0
  62. package/Sources/Combine/Publishers/Publishers.Breakpoint.swift +231 -0
  63. package/Sources/Combine/Publishers/Publishers.Buffer.swift +356 -0
  64. package/Sources/Combine/Publishers/Publishers.Collect.swift +102 -0
  65. package/Sources/Combine/Publishers/Publishers.CollectByCount.swift +195 -0
  66. package/Sources/Combine/Publishers/Publishers.CompactMap.swift +241 -0
  67. package/Sources/Combine/Publishers/Publishers.Comparison.swift +371 -0
  68. package/Sources/Combine/Publishers/Publishers.Concatenate.swift +474 -0
  69. package/Sources/Combine/Publishers/Publishers.Contains.swift +293 -0
  70. package/Sources/Combine/Publishers/Publishers.Count.swift +87 -0
  71. package/Sources/Combine/Publishers/Publishers.Debounce.swift +332 -0
  72. package/Sources/Combine/Publishers/Publishers.Delay.swift +269 -0
  73. package/Sources/Combine/Publishers/Publishers.Drop.swift +155 -0
  74. package/Sources/Combine/Publishers/Publishers.DropUntilOutput.swift +283 -0
  75. package/Sources/Combine/Publishers/Publishers.DropWhile.swift +378 -0
  76. package/Sources/Combine/Publishers/Publishers.Filter.swift +248 -0
  77. package/Sources/Combine/Publishers/Publishers.First.swift +261 -0
  78. package/Sources/Combine/Publishers/Publishers.FlatMap.swift +533 -0
  79. package/Sources/Combine/Publishers/Publishers.HandleEvents.swift +260 -0
  80. package/Sources/Combine/Publishers/Publishers.IgnoreOutput.swift +109 -0
  81. package/Sources/Combine/Publishers/Publishers.Last.swift +252 -0
  82. package/Sources/Combine/Publishers/Publishers.MakeConnectable.swift +82 -0
  83. package/Sources/Combine/Publishers/Publishers.Map.swift +351 -0
  84. package/Sources/Combine/Publishers/Publishers.MapError.swift +140 -0
  85. package/Sources/Combine/Publishers/Publishers.MeasureInterval.swift +187 -0
  86. package/Sources/Combine/Publishers/Publishers.Multicast.swift +284 -0
  87. package/Sources/Combine/Publishers/Publishers.Output.swift +241 -0
  88. package/Sources/Combine/Publishers/Publishers.PrefixUntilOutput.swift +197 -0
  89. package/Sources/Combine/Publishers/Publishers.PrefixWhile.swift +176 -0
  90. package/Sources/Combine/Publishers/Publishers.Print.swift +206 -0
  91. package/Sources/Combine/Publishers/Publishers.ReceiveOn.swift +227 -0
  92. package/Sources/Combine/Publishers/Publishers.Reduce.swift +204 -0
  93. package/Sources/Combine/Publishers/Publishers.RemoveDuplicates.swift +264 -0
  94. package/Sources/Combine/Publishers/Publishers.ReplaceEmpty.swift +201 -0
  95. package/Sources/Combine/Publishers/Publishers.ReplaceError.swift +211 -0
  96. package/Sources/Combine/Publishers/Publishers.Retry.swift +274 -0
  97. package/Sources/Combine/Publishers/Publishers.Scan.swift +331 -0
  98. package/Sources/Combine/Publishers/Publishers.Sequence.swift +437 -0
  99. package/Sources/Combine/Publishers/Publishers.SetFailureType.swift +120 -0
  100. package/Sources/Combine/Publishers/Publishers.Share.swift +104 -0
  101. package/Sources/Combine/Publishers/Publishers.SubscribeOn.swift +197 -0
  102. package/Sources/Combine/Publishers/Publishers.SwitchToLatest.swift +444 -0
  103. package/Sources/Combine/Publishers/Publishers.Throttle.swift +359 -0
  104. package/Sources/Combine/Publishers/Publishers.Timeout.swift +301 -0
  105. package/Sources/Combine/Publishers/Publishers.Zip.swift +720 -0
  106. package/Sources/Combine/Publishers/Publishers.swift +13 -0
  107. package/Sources/Combine/Publishers/Record.swift +237 -0
  108. package/Sources/Combine/Publishers/Result.Publisher.swift +337 -0
  109. package/Sources/Combine/Result.swift +46 -0
  110. package/Sources/Combine/Scheduler.swift +89 -0
  111. package/Sources/Combine/Schedulers.swift +211 -0
  112. package/Sources/Combine/Subject+Void.swift +17 -0
  113. package/Sources/Combine/Subscriber+Void.swift +20 -0
  114. package/Sources/Combine/Subscribers/Subscribers.Assign.swift +175 -0
  115. package/Sources/Combine/Subscribers/Subscribers.Completion.swift +90 -0
  116. package/Sources/Combine/Subscribers/Subscribers.Demand.swift +476 -0
  117. package/Sources/Combine/Subscribers/Subscribers.Sink.swift +206 -0
  118. package/Sources/Combine/Subscribers/Subscribers.swift +9 -0
  119. package/Sources/Combine/Subscription.swift +22 -0
  120. package/Sources/Combine/Subscriptions.swift +42 -0
  121. package/Sources/Combine/SwiftUIObservation.swift +10 -0
  122. package/Sources/Combine/_Introspection.swift +107 -0
  123. package/Sources/CommonCrypto/CommonCrypto.swift +80 -0
  124. package/Sources/Compression/Compression.swift +365 -0
  125. package/Sources/Compression/Deflate.swift +407 -0
  126. package/Sources/Compression/Zlib.swift +179 -0
  127. package/Sources/CoreFoundationTypes/CoreFoundationTypes.swift +101 -0
  128. package/Sources/CoreGraphics/CoreGraphics.swift +411 -0
  129. package/Sources/CoreGraphics/ProjectionTransforms.swift +28 -0
  130. package/Sources/CoreHaptics/CoreHaptics.swift +399 -0
  131. package/Sources/CoreImage/CIColor.swift +41 -0
  132. package/Sources/CoreImage/CIContext.swift +31 -0
  133. package/Sources/CoreImage/CIDetector.swift +57 -0
  134. package/Sources/CoreImage/CIFilter.swift +243 -0
  135. package/Sources/CoreImage/CIFilterBuiltins.swift +136 -0
  136. package/Sources/CoreImage/CIImage.swift +162 -0
  137. package/Sources/CoreImage/QRCode.swift +393 -0
  138. package/Sources/CoreLocation/Coordinate.swift +30 -0
  139. package/Sources/CoreLocation/Location.swift +65 -0
  140. package/Sources/CoreML/Evaluation.swift +414 -0
  141. package/Sources/CoreML/FeatureValue.swift +266 -0
  142. package/Sources/CoreML/Model.swift +269 -0
  143. package/Sources/CoreML/MultiArray.swift +92 -0
  144. package/Sources/CoreML/Specification.swift +233 -0
  145. package/Sources/CoreText/CoreText.swift +64 -0
  146. package/Sources/CoreTransferable/CoreTransferable.swift +606 -0
  147. package/Sources/CryptoKit/ChaChaPoly.swift +258 -0
  148. package/Sources/CryptoKit/CryptoKit.swift +375 -0
  149. package/Sources/CryptoKit/Curve25519.swift +317 -0
  150. package/Sources/CryptoKit/P256.swift +321 -0
  151. package/Sources/FoundationBridge/AppStorage.swift +165 -0
  152. package/Sources/FoundationBridge/AssetResources.swift +90 -0
  153. package/Sources/FoundationBridge/AsyncBytes.swift +128 -0
  154. package/Sources/FoundationBridge/AsyncImage.swift +116 -0
  155. package/Sources/FoundationBridge/AttributedStrings.swift +16 -0
  156. package/Sources/FoundationBridge/Bundle.swift +119 -0
  157. package/Sources/FoundationBridge/CombineExports.swift +8 -0
  158. package/Sources/FoundationBridge/CoreFoundation.swift +77 -0
  159. package/Sources/FoundationBridge/Dispatch.swift +458 -0
  160. package/Sources/FoundationBridge/EnvironmentFoundation.swift +41 -0
  161. package/Sources/FoundationBridge/FileImporter.swift +128 -0
  162. package/Sources/FoundationBridge/FileSystem.swift +68 -0
  163. package/Sources/FoundationBridge/FoundationBridge.swift +29 -0
  164. package/Sources/FoundationBridge/HostResolution.swift +31 -0
  165. package/Sources/FoundationBridge/ItemProvider.swift +655 -0
  166. package/Sources/FoundationBridge/KeyValueObserving.swift +138 -0
  167. package/Sources/FoundationBridge/Links.swift +127 -0
  168. package/Sources/FoundationBridge/ListFormatter.swift +32 -0
  169. package/Sources/FoundationBridge/Locale.swift +86 -0
  170. package/Sources/FoundationBridge/Localization.swift +149 -0
  171. package/Sources/FoundationBridge/Locks.swift +50 -0
  172. package/Sources/FoundationBridge/Markdown.swift +527 -0
  173. package/Sources/FoundationBridge/MeasurementFormat.swift +95 -0
  174. package/Sources/FoundationBridge/NotificationCenter.swift +154 -0
  175. package/Sources/FoundationBridge/OpenURLHandlers.swift +60 -0
  176. package/Sources/FoundationBridge/Operation.swift +195 -0
  177. package/Sources/FoundationBridge/ProcessInfo.swift +32 -0
  178. package/Sources/FoundationBridge/RelativeDateTimeFormatter.swift +136 -0
  179. package/Sources/FoundationBridge/SceneStorage.swift +78 -0
  180. package/Sources/FoundationBridge/SecurityExports.swift +8 -0
  181. package/Sources/FoundationBridge/Selector.swift +226 -0
  182. package/Sources/FoundationBridge/StringComparators.swift +17 -0
  183. package/Sources/FoundationBridge/Table.swift +211 -0
  184. package/Sources/FoundationBridge/TextAttributes.swift +42 -0
  185. package/Sources/FoundationBridge/Timer.swift +53 -0
  186. package/Sources/FoundationBridge/UITextChecker.swift +30 -0
  187. package/Sources/FoundationBridge/URLSession.swift +718 -0
  188. package/Sources/FoundationBridge/UserDefaults.swift +183 -0
  189. package/Sources/FoundationBridge/WebAuthRedirects.swift +227 -0
  190. package/Sources/FoundationBridge/WebSocket.swift +187 -0
  191. package/Sources/FoundationModels/FoundationModels.swift +1098 -0
  192. package/Sources/ImageIO/GIF.swift +72 -0
  193. package/Sources/ImageIO/ImageIO.swift +248 -0
  194. package/Sources/ImageIO/ImageTypes.swift +28 -0
  195. package/Sources/LinkPresentation/LinkPresentation.swift +249 -0
  196. package/Sources/LocalAuthentication/LAContext.swift +86 -0
  197. package/Sources/MapKit/Geometry.swift +223 -0
  198. package/Sources/MapKit/Map.swift +638 -0
  199. package/Sources/MapKit/MapView.swift +229 -0
  200. package/Sources/MobileCoreServices/MobileCoreServices.swift +28 -0
  201. package/Sources/NaturalLanguage/LanguageIdentifier.swift +317 -0
  202. package/Sources/NaturalLanguage/NaturalLanguage.swift +135 -0
  203. package/Sources/OSLog/OSLog.swift +6 -0
  204. package/Sources/Photos/Photos.swift +572 -0
  205. package/Sources/PhotosUI/PhotosPicker.swift +248 -0
  206. package/Sources/PhotosUI/PhotosPickerItem.swift +261 -0
  207. package/Sources/QuickLook/QuickLook.swift +168 -0
  208. package/Sources/SafariServices/SafariServices.swift +106 -0
  209. package/Sources/Security/Security.swift +332 -0
  210. package/Sources/StoreKit/AppStore.swift +207 -0
  211. package/Sources/StoreKit/Products.swift +280 -0
  212. package/Sources/StoreKit/RequestReview.swift +28 -0
  213. package/Sources/StoreKit/StoreKit1.swift +486 -0
  214. package/Sources/StoreKit/StoreViews.swift +428 -0
  215. package/Sources/StoreKit/Transactions.swift +197 -0
  216. package/Sources/SwiftData/Macros.swift +58 -0
  217. package/Sources/SwiftData/ModelActor.swift +38 -0
  218. package/Sources/SwiftData/ModelContainer.swift +129 -0
  219. package/Sources/SwiftData/ModelContext.swift +451 -0
  220. package/Sources/SwiftData/PersistentModel.swift +238 -0
  221. package/Sources/SwiftData/Properties.swift +261 -0
  222. package/Sources/SwiftData/Query.swift +256 -0
  223. package/Sources/SwiftData/Schema.swift +192 -0
  224. package/Sources/SwiftData/Store.swift +146 -0
  225. package/Sources/SwiftData/StringPredicates.swift +125 -0
  226. package/Sources/SwiftDataMacros/EntryMacro.swift +82 -0
  227. package/Sources/SwiftDataMacros/GenerableMacro.swift +183 -0
  228. package/Sources/SwiftDataMacros/ModelActorMacro.swift +46 -0
  229. package/Sources/SwiftDataMacros/ModelMacro.swift +260 -0
  230. package/Sources/SwiftDataMacros/Plugin.swift +18 -0
  231. package/Sources/SwiftDataMacros/PredicateMacro.swift +1244 -0
  232. package/Sources/SwiftUI/API/Accessibility.swift +181 -0
  233. package/Sources/SwiftUI/API/AccessibilityExtras.swift +33 -0
  234. package/Sources/SwiftUI/API/AccessibilityFocus.swift +63 -0
  235. package/Sources/SwiftUI/API/Alert.swift +221 -0
  236. package/Sources/SwiftUI/API/AlignmentGuides.swift +65 -0
  237. package/Sources/SwiftUI/API/Animation.swift +285 -0
  238. package/Sources/SwiftUI/API/App.swift +87 -0
  239. package/Sources/SwiftUI/API/BindingCollections.swift +35 -0
  240. package/Sources/SwiftUI/API/BindingForEach.swift +27 -0
  241. package/Sources/SwiftUI/API/Bitmaps.swift +254 -0
  242. package/Sources/SwiftUI/API/ButtonStyles.swift +96 -0
  243. package/Sources/SwiftUI/API/Canvas.swift +337 -0
  244. package/Sources/SwiftUI/API/Color.swift +237 -0
  245. package/Sources/SwiftUI/API/ColorEffects.swift +52 -0
  246. package/Sources/SwiftUI/API/ColorPickerAndLabeledContent.swift +138 -0
  247. package/Sources/SwiftUI/API/ColorSpaces.swift +161 -0
  248. package/Sources/SwiftUI/API/Commands.swift +106 -0
  249. package/Sources/SwiftUI/API/ContainerBackground.swift +28 -0
  250. package/Sources/SwiftUI/API/ContentShape.swift +33 -0
  251. package/Sources/SwiftUI/API/ContentSizeCategory.swift +35 -0
  252. package/Sources/SwiftUI/API/ContentUnavailable.swift +101 -0
  253. package/Sources/SwiftUI/API/Controls.swift +300 -0
  254. package/Sources/SwiftUI/API/CustomLayout.swift +442 -0
  255. package/Sources/SwiftUI/API/CustomToolbarContent.swift +46 -0
  256. package/Sources/SwiftUI/API/Decorations.swift +92 -0
  257. package/Sources/SwiftUI/API/EditMode.swift +212 -0
  258. package/Sources/SwiftUI/API/Effects.swift +388 -0
  259. package/Sources/SwiftUI/API/Entry.swift +8 -0
  260. package/Sources/SwiftUI/API/Environment.swift +439 -0
  261. package/Sources/SwiftUI/API/EnvironmentSendable.swift +6 -0
  262. package/Sources/SwiftUI/API/Focus.swift +137 -0
  263. package/Sources/SwiftUI/API/Font.swift +131 -0
  264. package/Sources/SwiftUI/API/Gauge.swift +290 -0
  265. package/Sources/SwiftUI/API/Geometry.swift +89 -0
  266. package/Sources/SwiftUI/API/GeometryEffects.swift +232 -0
  267. package/Sources/SwiftUI/API/GeometryReader.swift +135 -0
  268. package/Sources/SwiftUI/API/GestureState.swift +65 -0
  269. package/Sources/SwiftUI/API/Gestures.swift +342 -0
  270. package/Sources/SwiftUI/API/Glass.swift +127 -0
  271. package/Sources/SwiftUI/API/Grid.swift +188 -0
  272. package/Sources/SwiftUI/API/GroupBoxAndControlGroup.swift +130 -0
  273. package/Sources/SwiftUI/API/KeyPress.swift +54 -0
  274. package/Sources/SwiftUI/API/LabelStyle.swift +124 -0
  275. package/Sources/SwiftUI/API/Layout.swift +220 -0
  276. package/Sources/SwiftUI/API/LazyStacks.swift +49 -0
  277. package/Sources/SwiftUI/API/LegacyAlert.swift +97 -0
  278. package/Sources/SwiftUI/API/Lists.swift +331 -0
  279. package/Sources/SwiftUI/API/Menu.swift +58 -0
  280. package/Sources/SwiftUI/API/Modifiers.swift +313 -0
  281. package/Sources/SwiftUI/API/MoreModifiers.swift +100 -0
  282. package/Sources/SwiftUI/API/Namespace.swift +44 -0
  283. package/Sources/SwiftUI/API/Navigation.swift +386 -0
  284. package/Sources/SwiftUI/API/NavigationDestinationBindings.swift +55 -0
  285. package/Sources/SwiftUI/API/ObservableObject.swift +293 -0
  286. package/Sources/SwiftUI/API/OnChange.swift +48 -0
  287. package/Sources/SwiftUI/API/Path.swift +543 -0
  288. package/Sources/SwiftUI/API/Phase8Controls.swift +411 -0
  289. package/Sources/SwiftUI/API/PhaseAnimator.swift +130 -0
  290. package/Sources/SwiftUI/API/Picker.swift +185 -0
  291. package/Sources/SwiftUI/API/PointerAndKeyboard.swift +77 -0
  292. package/Sources/SwiftUI/API/Popover.swift +41 -0
  293. package/Sources/SwiftUI/API/Preferences.swift +262 -0
  294. package/Sources/SwiftUI/API/Presentation.swift +122 -0
  295. package/Sources/SwiftUI/API/PresentationExtras.swift +60 -0
  296. package/Sources/SwiftUI/API/Primitives.swift +517 -0
  297. package/Sources/SwiftUI/API/Publishers.swift +107 -0
  298. package/Sources/SwiftUI/API/Redaction.swift +75 -0
  299. package/Sources/SwiftUI/API/RowActions.swift +84 -0
  300. package/Sources/SwiftUI/API/Scenes.swift +131 -0
  301. package/Sources/SwiftUI/API/ScrollModifiers.swift +132 -0
  302. package/Sources/SwiftUI/API/ScrollTargets.swift +104 -0
  303. package/Sources/SwiftUI/API/ScrollViewReader.swift +144 -0
  304. package/Sources/SwiftUI/API/SectionSupplements.swift +96 -0
  305. package/Sources/SwiftUI/API/Shape.swift +214 -0
  306. package/Sources/SwiftUI/API/ShapeStyle.swift +409 -0
  307. package/Sources/SwiftUI/API/ShapeTrim.swift +78 -0
  308. package/Sources/SwiftUI/API/Sharing.swift +193 -0
  309. package/Sources/SwiftUI/API/StackLayouts.swift +199 -0
  310. package/Sources/SwiftUI/API/State.swift +144 -0
  311. package/Sources/SwiftUI/API/StatusGaps.swift +121 -0
  312. package/Sources/SwiftUI/API/StrokeStyle.swift +30 -0
  313. package/Sources/SwiftUI/API/SymbolEffects.swift +203 -0
  314. package/Sources/SwiftUI/API/TabContent.swift +841 -0
  315. package/Sources/SwiftUI/API/Table.swift +382 -0
  316. package/Sources/SwiftUI/API/Tabs.swift +263 -0
  317. package/Sources/SwiftUI/API/Tasks.swift +35 -0
  318. package/Sources/SwiftUI/API/Text.swift +386 -0
  319. package/Sources/SwiftUI/API/TextDates.swift +61 -0
  320. package/Sources/SwiftUI/API/TextDecorations.swift +52 -0
  321. package/Sources/SwiftUI/API/TextFieldAxis.swift +103 -0
  322. package/Sources/SwiftUI/API/TextFieldCommit.swift +52 -0
  323. package/Sources/SwiftUI/API/Timeline.swift +212 -0
  324. package/Sources/SwiftUI/API/Toolbar.swift +251 -0
  325. package/Sources/SwiftUI/API/Transfer.swift +145 -0
  326. package/Sources/SwiftUI/API/UnevenRoundedRectangle.swift +66 -0
  327. package/Sources/SwiftUI/API/Video.swift +64 -0
  328. package/Sources/SwiftUI/API/View.swift +215 -0
  329. package/Sources/SwiftUI/API/ViewModifier.swift +43 -0
  330. package/Sources/SwiftUI/API/VisualEffect.swift +155 -0
  331. package/Sources/SwiftUI/API/Windows.swift +25 -0
  332. package/Sources/SwiftUI/Charts/Axis.swift +325 -0
  333. package/Sources/SwiftUI/Charts/AxisFormatsAndRanges.swift +68 -0
  334. package/Sources/SwiftUI/Charts/Chart.swift +660 -0
  335. package/Sources/SwiftUI/Charts/ChartContent.swift +376 -0
  336. package/Sources/SwiftUI/Charts/ChartProxy.swift +57 -0
  337. package/Sources/SwiftUI/Charts/Marks.swift +204 -0
  338. package/Sources/SwiftUI/Charts/Plottable.swift +99 -0
  339. package/Sources/SwiftUI/Charts/Scales.swift +326 -0
  340. package/Sources/SwiftUI/Localization/Localization.swift +498 -0
  341. package/Sources/SwiftUI/Localization/PluralRules.swift +127 -0
  342. package/Sources/SwiftUI/Runtime/Executor.swift +85 -0
  343. package/Sources/SwiftUI/Runtime/Exports.swift +101 -0
  344. package/Sources/SwiftUI/Runtime/ImageSource.swift +310 -0
  345. package/Sources/SwiftUI/Runtime/JSON.swift +143 -0
  346. package/Sources/SwiftUI/Runtime/JSONParser.swift +443 -0
  347. package/Sources/SwiftUI/Runtime/LazyRows.swift +99 -0
  348. package/Sources/SwiftUI/Runtime/Measurements.swift +140 -0
  349. package/Sources/SwiftUI/Runtime/Ops.swift +152 -0
  350. package/Sources/SwiftUI/Runtime/Reconciler.swift +219 -0
  351. package/Sources/SwiftUI/Runtime/Replay.swift +382 -0
  352. package/Sources/SwiftUI/Runtime/Runtime.swift +2146 -0
  353. package/Sources/SwiftUI/Runtime/Sameness.swift +152 -0
  354. package/Sources/SwiftUI/Runtime/ViewPath.swift +89 -0
  355. package/Sources/SwiftUI/Runtime/ViewTraits.swift +175 -0
  356. package/Sources/SwiftUI/Runtime/WebAuthHeadless.swift +49 -0
  357. package/Sources/Symbols/Symbols.swift +25 -0
  358. package/Sources/Translation/Translation.swift +423 -0
  359. package/Sources/UIKit/Activity.swift +213 -0
  360. package/Sources/UIKit/Alerts.swift +69 -0
  361. package/Sources/UIKit/AppDelegate.swift +222 -0
  362. package/Sources/UIKit/Appearance.swift +84 -0
  363. package/Sources/UIKit/ColorConversions.swift +70 -0
  364. package/Sources/UIKit/Controls.swift +225 -0
  365. package/Sources/UIKit/Device.swift +200 -0
  366. package/Sources/UIKit/Feedback.swift +65 -0
  367. package/Sources/UIKit/Font.swift +307 -0
  368. package/Sources/UIKit/Graphics.swift +204 -0
  369. package/Sources/UIKit/HostingController.swift +185 -0
  370. package/Sources/UIKit/Identity.swift +24 -0
  371. package/Sources/UIKit/Introspectable.swift +510 -0
  372. package/Sources/UIKit/Pasteboard.swift +363 -0
  373. package/Sources/UIKit/PhotoAlbum.swift +81 -0
  374. package/Sources/UIKit/RemoteNotifications.swift +15 -0
  375. package/Sources/UIKit/Representable.swift +288 -0
  376. package/Sources/UIKit/SafeArea.swift +12 -0
  377. package/Sources/UIKit/SceneDelegates.swift +132 -0
  378. package/Sources/UIKit/Scenes.swift +40 -0
  379. package/Sources/UIKit/ScrollView.swift +157 -0
  380. package/Sources/UIKit/ShortcutItems.swift +67 -0
  381. package/Sources/UIKit/SymbolConfiguration.swift +124 -0
  382. package/Sources/UIKit/TargetAction.swift +123 -0
  383. package/Sources/UIKit/TextPaste.swift +161 -0
  384. package/Sources/UIKit/TextView.swift +538 -0
  385. package/Sources/UIKit/UIKit.swift +292 -0
  386. package/Sources/UIKit/UIView.swift +855 -0
  387. package/Sources/UIKit/ViewTranslation.swift +311 -0
  388. package/Sources/UniformTypeIdentifiers/UTType.swift +196 -0
  389. package/Sources/UserNotifications/Content.swift +370 -0
  390. package/Sources/UserNotifications/NotificationCenter.swift +309 -0
  391. package/Sources/WeatherKit/WeatherKit.swift +228 -0
  392. package/Sources/WebKit/WebKit.swift +245 -0
  393. package/Sources/os/os.swift +376 -0
  394. package/Sources/zlib/zlib.swift +6 -0
  395. package/index.d.ts +2 -0
  396. package/index.mjs +16 -0
  397. package/manifest.d.mts +2 -0
  398. package/manifest.mjs +39 -0
  399. package/package.json +30 -4
  400. package/sync-sources.mjs +33 -0
@@ -0,0 +1,285 @@
1
+ /// How a change is animated. Encoded for the renderer as documented in
2
+ /// docs/ops-protocol.md (Phase 3).
3
+ public struct Animation: Equatable, Sendable {
4
+ enum Kind: String, Sendable {
5
+ case `default`, linear, easeIn, easeOut, easeInOut, spring
6
+ }
7
+
8
+ var kind: Kind
9
+ var duration: Double
10
+ var bounce: Double
11
+ var delayBy: Double
12
+ /// `.repeatCount` / `.repeatForever`: `count` nil with `forever` false means once.
13
+ var repeatCount: Int?
14
+ var repeatForever = false
15
+ var autoreverses = true
16
+
17
+ init(kind: Kind, duration: Double = 0.35, bounce: Double = 0, delay: Double = 0) {
18
+ self.kind = kind
19
+ self.duration = duration
20
+ self.bounce = bounce
21
+ self.delayBy = delay
22
+ }
23
+
24
+ public static let `default` = Animation(kind: .default)
25
+ public static let linear = Animation(kind: .linear)
26
+ public static let easeIn = Animation(kind: .easeIn)
27
+ public static let easeOut = Animation(kind: .easeOut)
28
+ public static let easeInOut = Animation(kind: .easeInOut)
29
+ public static let spring = Animation(kind: .spring, duration: 0.5, bounce: 0)
30
+ public static let bouncy = Animation(kind: .spring, duration: 0.5, bounce: 0.3)
31
+ public static let smooth = Animation(kind: .spring, duration: 0.5, bounce: 0)
32
+ public static let snappy = Animation(kind: .spring, duration: 0.5, bounce: 0.15)
33
+
34
+ public static func linear(duration: Double) -> Animation { Animation(kind: .linear, duration: duration) }
35
+ public static func easeIn(duration: Double) -> Animation { Animation(kind: .easeIn, duration: duration) }
36
+ public static func easeOut(duration: Double) -> Animation { Animation(kind: .easeOut, duration: duration) }
37
+ public static func easeInOut(duration: Double) -> Animation { Animation(kind: .easeInOut, duration: duration) }
38
+ public static func spring(duration: Double = 0.5, bounce: Double = 0) -> Animation {
39
+ Animation(kind: .spring, duration: duration, bounce: bounce)
40
+ }
41
+ /// The pre-iOS 17 spring: `response` is the duration, the damping fraction
42
+ /// maps onto bounce (`1` is a smooth spring, lower values overshoot).
43
+ public static func spring(response: Double = 0.5, dampingFraction: Double = 0.825,
44
+ blendDuration: Double = 0) -> Animation {
45
+ Animation(kind: .spring, duration: response, bounce: max(0, min(1, 1 - dampingFraction)))
46
+ }
47
+ public static func interactiveSpring(response: Double = 0.15, dampingFraction: Double = 0.86,
48
+ blendDuration: Double = 0.25) -> Animation {
49
+ spring(response: response, dampingFraction: dampingFraction, blendDuration: blendDuration)
50
+ }
51
+ public static func bouncy(duration: Double = 0.5, extraBounce: Double = 0) -> Animation {
52
+ Animation(kind: .spring, duration: duration, bounce: 0.3 + extraBounce)
53
+ }
54
+ public static func smooth(duration: Double = 0.5, extraBounce: Double = 0) -> Animation {
55
+ Animation(kind: .spring, duration: duration, bounce: extraBounce)
56
+ }
57
+ public static func snappy(duration: Double = 0.5, extraBounce: Double = 0) -> Animation {
58
+ Animation(kind: .spring, duration: duration, bounce: 0.15 + extraBounce)
59
+ }
60
+
61
+ public func delay(_ delay: Double) -> Animation {
62
+ var copy = self
63
+ copy.delayBy = delay
64
+ return copy
65
+ }
66
+
67
+ public func speed(_ speed: Double) -> Animation {
68
+ var copy = self
69
+ copy.duration = speed > 0 ? duration / speed : duration
70
+ return copy
71
+ }
72
+
73
+ /// Repeats the animation `repeatCount` times, reversing on alternate runs
74
+ /// when `autoreverses`.
75
+ public func repeatCount(_ repeatCount: Int, autoreverses: Bool = true) -> Animation {
76
+ var copy = self
77
+ copy.repeatCount = repeatCount
78
+ copy.repeatForever = false
79
+ copy.autoreverses = autoreverses
80
+ return copy
81
+ }
82
+
83
+ public func repeatForever(autoreverses: Bool = true) -> Animation {
84
+ var copy = self
85
+ copy.repeatCount = nil
86
+ copy.repeatForever = true
87
+ copy.autoreverses = autoreverses
88
+ return copy
89
+ }
90
+
91
+ var _json: _JSON {
92
+ var object: [String: _JSON] = ["type": .string(kind.rawValue), "duration": .number(duration)]
93
+ if bounce != 0 { object["bounce"] = .number(bounce) }
94
+ if delayBy != 0 { object["delay"] = .number(delayBy) }
95
+ if repeatForever || repeatCount != nil {
96
+ object["repeat"] = .object([
97
+ "count": repeatForever ? .string("forever") : .number(Double(repeatCount ?? 1)),
98
+ "autoreverses": .bool(autoreverses),
99
+ ])
100
+ }
101
+ return .object(object)
102
+ }
103
+ }
104
+
105
+ extension Binding {
106
+ /// A binding whose writes animate the view changes they cause.
107
+ public func animation(_ animation: Animation? = .default) -> Binding<Value> {
108
+ let setter = self.setter
109
+ return Binding(get: getter) { value in
110
+ // Bindings are written from the main actor (event handlers, bodies).
111
+ let outer = MainActor.assumeIsolated { _Runtime.shared.beginTransaction(animation) }
112
+ setter(value)
113
+ MainActor.assumeIsolated { _Runtime.shared.endTransaction(outer) }
114
+ }
115
+ }
116
+ }
117
+
118
+ /// Runs `body` and animates the view changes it causes.
119
+ @MainActor
120
+ public func withAnimation<Result>(_ animation: Animation? = .default,
121
+ _ body: () throws -> Result) rethrows -> Result {
122
+ try _Runtime.shared.runInTransaction(animation, body)
123
+ }
124
+
125
+ /// Runs `body` in `transaction`: its animation (none when it disables
126
+ /// animations) animates the view changes `body` causes.
127
+ @MainActor
128
+ public func withTransaction<Result>(_ transaction: Transaction, _ body: () throws -> Result) rethrows -> Result {
129
+ try _Runtime.shared.runInTransaction(transaction.disablesAnimations ? nil : transaction.animation, body)
130
+ }
131
+
132
+ /// `withTransaction` with one property of a fresh transaction set.
133
+ @MainActor
134
+ public func withTransaction<Result, Value>(_ keyPath: WritableKeyPath<Transaction, Value>, _ value: Value,
135
+ _ body: () throws -> Result) rethrows -> Result {
136
+ var transaction = Transaction()
137
+ transaction[keyPath: keyPath] = value
138
+ return try withTransaction(transaction, body)
139
+ }
140
+
141
+ // MARK: - Transitions
142
+
143
+ /// How a view appears and disappears when inserted or removed with animation.
144
+ public struct AnyTransition: Sendable {
145
+ struct Part: Sendable {
146
+ var kind: String
147
+ var edge: Edge?
148
+ var scale: Double?
149
+ var offset: CGSize?
150
+ /// `asymmetric`: the transitions for insertion and removal.
151
+ var insertion: [Part]?
152
+ var removal: [Part]?
153
+
154
+ var _json: _JSON {
155
+ var object: [String: _JSON] = ["kind": .string(kind)]
156
+ if let edge { object["edge"] = .string(edge.name) }
157
+ if let scale { object["scale"] = .number(scale) }
158
+ if let offset {
159
+ object["x"] = .number(offset.width)
160
+ object["y"] = .number(offset.height)
161
+ }
162
+ if let insertion { object["insertion"] = AnyTransition(parts: insertion)._json }
163
+ if let removal { object["removal"] = AnyTransition(parts: removal)._json }
164
+ return .object(object)
165
+ }
166
+ }
167
+
168
+ public static func asymmetric(insertion: AnyTransition, removal: AnyTransition) -> AnyTransition {
169
+ AnyTransition(parts: [Part(kind: "asymmetric", insertion: insertion.parts, removal: removal.parts)])
170
+ }
171
+
172
+ var parts: [Part]
173
+
174
+ public static let identity = AnyTransition(parts: [Part(kind: "identity")])
175
+ public static let opacity = AnyTransition(parts: [Part(kind: "opacity")])
176
+ public static let slide = AnyTransition(parts: [Part(kind: "slide")])
177
+ public static let scale = AnyTransition(parts: [Part(kind: "scale", scale: 0.5)])
178
+
179
+ public static func scale(scale: Double) -> AnyTransition {
180
+ AnyTransition(parts: [Part(kind: "scale", scale: scale)])
181
+ }
182
+
183
+ /// The anchor is accepted for source compatibility; scaling is about the center.
184
+ public static func scale(scale: Double, anchor: UnitPoint) -> AnyTransition {
185
+ AnyTransition(parts: [Part(kind: "scale", scale: scale)])
186
+ }
187
+
188
+ /// iOS 17's spelling, `.scale(0.5)`.
189
+ public static func scale(_ scale: Double, anchor: UnitPoint = .center) -> AnyTransition {
190
+ AnyTransition(parts: [Part(kind: "scale", scale: scale)])
191
+ }
192
+
193
+ /// Slides in from / out to the given offset (points).
194
+ public static func offset(x: CGFloat = 0, y: CGFloat = 0) -> AnyTransition {
195
+ AnyTransition(parts: [Part(kind: "offset", offset: CGSize(width: x, height: y))])
196
+ }
197
+
198
+ public static func offset(_ offset: CGSize) -> AnyTransition {
199
+ AnyTransition(parts: [Part(kind: "offset", offset: offset)])
200
+ }
201
+
202
+ public static func move(edge: Edge) -> AnyTransition {
203
+ AnyTransition(parts: [Part(kind: "move", edge: edge)])
204
+ }
205
+
206
+ public func combined(with other: AnyTransition) -> AnyTransition {
207
+ AnyTransition(parts: parts + other.parts)
208
+ }
209
+
210
+ /// A transition between two states of a `ViewModifier`. The shim cannot
211
+ /// diff arbitrary modifiers, so it is accepted and rendered as `opacity`
212
+ /// (docs/ops-protocol.md, Phase 8).
213
+ public static func modifier<E: ViewModifier>(active: E, identity: E) -> AnyTransition {
214
+ .opacity
215
+ }
216
+
217
+ var _json: _JSON {
218
+ parts.count == 1 ? parts[0]._json : .array(parts.map(\._json))
219
+ }
220
+ }
221
+
222
+ extension Edge {
223
+ var name: String {
224
+ switch self {
225
+ case .top: "top"
226
+ case .leading: "leading"
227
+ case .bottom: "bottom"
228
+ case .trailing: "trailing"
229
+ }
230
+ }
231
+ }
232
+
233
+ // MARK: - Modifiers
234
+
235
+ /// Views whose subtree animates when `value` changes.
236
+ protocol _AnimatedView: _TraitBearing {
237
+ var _animation: Animation? { get }
238
+ /// Whether the tracked value differs from a previously stored one.
239
+ func _changed(since previous: Any?) -> Bool
240
+ var _value: Any { get }
241
+ var _content: [any View] { get }
242
+ }
243
+
244
+ struct _AnimationView<Content: View, Value: Equatable> {
245
+ let content: Content
246
+ let animation: Animation?
247
+ let value: Value
248
+ }
249
+ extension _AnimationView: _PrimitiveView {}
250
+ extension _AnimationView: _HostView {
251
+ var _kind: String { "styled" }
252
+ func _props(in environment: EnvironmentValues) -> _JSON { .object(["style": .object([:])]) }
253
+ var _content: [any View] { [content] }
254
+ }
255
+ extension _AnimationView: _AnimatedView {
256
+ var _animation: Animation? { animation }
257
+ var _value: Any { value }
258
+ func _changed(since previous: Any?) -> Bool {
259
+ guard let previous = previous as? Value else { return true }
260
+ return previous != value
261
+ }
262
+ }
263
+
264
+ nonisolated extension View {
265
+ /// Animates changes to this view whenever `value` changes.
266
+ public func animation<V: Equatable>(_ animation: Animation?, value: V) -> some View {
267
+ _AnimationView(content: self, animation: animation, value: value)
268
+ }
269
+
270
+ /// The transition to use when this view is inserted or removed with animation.
271
+ public func transition(_ transition: AnyTransition) -> some View {
272
+ _styled { $0.transition = transition }
273
+ }
274
+ }
275
+
276
+ // MARK: - Transaction
277
+
278
+ /// The context of a state change. Accepted where SwiftUI takes one
279
+ /// (`AsyncImage(url:transaction:content:)`); the renderer animates what
280
+ /// `withAnimation` asked for, so the value itself is not consulted.
281
+ public struct Transaction: Sendable {
282
+ public var animation: Animation?
283
+ public var disablesAnimations: Bool = false
284
+ public init(animation: Animation? = nil) { self.animation = animation }
285
+ }
@@ -0,0 +1,87 @@
1
+ /// A part of an app's user interface with a life cycle managed by the system.
2
+ @MainActor @preconcurrency
3
+ public protocol Scene {
4
+ associatedtype Body: Scene
5
+ @SceneBuilder var body: Self.Body { get }
6
+ }
7
+
8
+ extension Never: Scene {}
9
+
10
+ /// Scenes the runtime can mount directly.
11
+ protocol _RootScene {
12
+ @MainActor var _rootView: any View { get }
13
+ }
14
+
15
+ @resultBuilder
16
+ public enum SceneBuilder {
17
+ public static func buildBlock<Content: Scene>(_ content: Content) -> Content { content }
18
+ }
19
+
20
+ /// A scene that presents a view hierarchy in a window (on the web, the screen).
21
+ public struct WindowGroup<Content: View> {
22
+ let content: Content
23
+
24
+ public init(@ViewBuilder content: () -> Content) {
25
+ self.content = content()
26
+ }
27
+
28
+ public init(_ title: String, @ViewBuilder content: () -> Content) {
29
+ self.content = content()
30
+ }
31
+ }
32
+
33
+ extension WindowGroup: Scene {
34
+ public typealias Body = Never
35
+ public var body: Never { fatalError("WindowGroup is a primitive scene") }
36
+ }
37
+
38
+ extension WindowGroup: _RootScene {
39
+ var _rootView: any View { content }
40
+ }
41
+
42
+ /// A scene whose root view is wrapped in a view modifier: how another module
43
+ /// adds a scene modifier (SwiftData's `.modelContainer`) that applies to the
44
+ /// whole window's content.
45
+ public struct _RootModifiedScene<Content: Scene, Modifier: ViewModifier> {
46
+ let content: Content
47
+ let modifier: Modifier
48
+ }
49
+
50
+ extension _RootModifiedScene: Scene {
51
+ public typealias Body = Never
52
+ public var body: Never { fatalError("_RootModifiedScene is a primitive scene") }
53
+ }
54
+
55
+ extension _RootModifiedScene: _RootScene {
56
+ var _rootView: any View {
57
+ guard let root = content as? any _RootScene else {
58
+ fatalError("\(Content.self) is not a scene the runtime can present. Use WindowGroup.")
59
+ }
60
+ func wrap<V: View>(_ view: V) -> any View { view.modifier(modifier) }
61
+ return wrap(root._rootView)
62
+ }
63
+ }
64
+
65
+ extension Scene {
66
+ /// Applies `modifier` to the scene's root view.
67
+ public func _modifyingRootView<M: ViewModifier>(_ modifier: M) -> _RootModifiedScene<Self, M> {
68
+ _RootModifiedScene(content: self, modifier: modifier)
69
+ }
70
+ }
71
+
72
+ /// The structure and behavior of an app. Mark the conforming type `@main`.
73
+ @MainActor @preconcurrency
74
+ public protocol App {
75
+ associatedtype Body: Scene
76
+ @SceneBuilder var body: Self.Body { get }
77
+ init()
78
+ }
79
+
80
+ extension App {
81
+ /// Entry point used by `@main`. Mounts the app's root view and, in the
82
+ /// browser, returns while the module stays alive to receive events.
83
+ public static func main() {
84
+ _installHostExecutor()
85
+ _Runtime.shared.launch(Self())
86
+ }
87
+ }
@@ -0,0 +1,35 @@
1
+ // A binding to a mutable collection is a collection of bindings to its
2
+ // elements, as in SwiftUI (iOS 15): `$items.isEmpty`, `$items.count` and
3
+ // `$items[0]` read and write through the binding to the whole collection.
4
+
5
+ extension Binding: Sequence where Value: MutableCollection {
6
+ public typealias Element = Binding<Value.Element>
7
+ public typealias Iterator = IndexingIterator<Binding<Value>>
8
+ public typealias SubSequence = Slice<Binding<Value>>
9
+ }
10
+
11
+ extension Binding: Collection where Value: MutableCollection {
12
+ public typealias Index = Value.Index
13
+ public typealias Indices = Value.Indices
14
+
15
+ public var startIndex: Value.Index { wrappedValue.startIndex }
16
+ public var endIndex: Value.Index { wrappedValue.endIndex }
17
+ public var indices: Value.Indices { wrappedValue.indices }
18
+
19
+ public func index(after i: Value.Index) -> Value.Index { wrappedValue.index(after: i) }
20
+
21
+ public func formIndex(after i: inout Value.Index) { wrappedValue.formIndex(after: &i) }
22
+
23
+ public subscript(position: Value.Index) -> Binding<Value.Element> {
24
+ let whole = self
25
+ return Binding<Value.Element>(get: { whole.wrappedValue[position] }, set: { whole.wrappedValue[position] = $0 })
26
+ }
27
+ }
28
+
29
+ extension Binding: BidirectionalCollection where Value: BidirectionalCollection, Value: MutableCollection {
30
+ public func index(before i: Value.Index) -> Value.Index { wrappedValue.index(before: i) }
31
+
32
+ public func formIndex(before i: inout Value.Index) { wrappedValue.formIndex(before: &i) }
33
+ }
34
+
35
+ extension Binding: RandomAccessCollection where Value: RandomAccessCollection, Value: MutableCollection {}
@@ -0,0 +1,27 @@
1
+ /// `ForEach($items) { $item in … }` (iOS 15): a row per element, each with a
2
+ /// binding to its element (`Binding(projectedValue:)`, in State.swift, lets
3
+ /// the closure take its parameter as `$item`). Plus the older
4
+ /// `Picker(selection:label:content:)`.
5
+
6
+ extension ForEach where Content: View {
7
+ /// A row per element of the bound collection, identified by its `id`.
8
+ public init<C: MutableCollection & RandomAccessCollection>(
9
+ _ data: Binding<C>, @ViewBuilder content: @escaping (Binding<C.Element>) -> Content
10
+ ) where Data == [Binding<C.Element>], C.Element: Identifiable, ID == C.Element.ID {
11
+ self.init(_data: data.map { $0 }, id: { $0.wrappedValue.id }, content: content)
12
+ }
13
+
14
+ /// A row per element of the bound collection, identified by `id`.
15
+ public init<C: MutableCollection & RandomAccessCollection>(
16
+ _ data: Binding<C>, id: KeyPath<C.Element, ID>, @ViewBuilder content: @escaping (Binding<C.Element>) -> Content
17
+ ) where Data == [Binding<C.Element>] {
18
+ self.init(_data: data.map { $0 }, id: { $0.wrappedValue[keyPath: id] }, content: content)
19
+ }
20
+ }
21
+
22
+ extension Picker {
23
+ /// The pre-iOS 16 form, with the label first.
24
+ public init(selection: Binding<SelectionValue>, label: Label, @ViewBuilder content: () -> Content) {
25
+ self.init(selection: selection, content: content, label: { label })
26
+ }
27
+ }
@@ -0,0 +1,254 @@
1
+ import Foundation
2
+
3
+ // `UIImage` and `CGImage`, as far as SwiftUI apps use them: made from an
4
+ // image file's bytes, from Core Image (Sources/CoreImage), from an SF Symbol
5
+ // or a catalog name, and shown with `Image(uiImage:)`. On iOS SwiftUI
6
+ // re-exports UIKit's `UIImage` and Core Graphics' `CGImage`, so a file that
7
+ // imports SwiftUI alone uses both; here they live in the shim for the same
8
+ // reason. Neither holds pixels: each is a recipe the page draws
9
+ // (Runtime/ImageSource.swift, docs/ops-protocol.md, "Bitmaps and Core Image").
10
+
11
+ /// A bitmap: `width` × `height` pixels the page produces from a recipe.
12
+ public final class CGImage: @unchecked Sendable {
13
+ public let width: Int
14
+ public let height: Int
15
+ /// The recipe, ending at this image's pixel grid (extent `(0, 0, width, height)`).
16
+ public let _recipe: _ImageRecipe
17
+
18
+ /// Made by Core Image (`CIContext.createCGImage`) from a rendered recipe.
19
+ public init(_recipe recipe: _ImageRecipe) {
20
+ _recipe = recipe
21
+ let extent = recipe.extent.isNull || recipe.extent.isInfinite ? CGRect.zero : recipe.extent
22
+ width = Int(extent.width)
23
+ height = Int(extent.height)
24
+ }
25
+
26
+ public var bitsPerComponent: Int { 8 }
27
+ public var bitsPerPixel: Int { 32 }
28
+ public var bytesPerRow: Int { width * 4 }
29
+
30
+ /// The part of the image inside `rect` (pixels, origin at the top left),
31
+ /// clipped to the image; nil when they do not overlap.
32
+ public func cropping(to rect: CGRect) -> CGImage? {
33
+ let bounds = CGRect(x: 0, y: 0, width: Double(width), height: Double(height))
34
+ let box = rect.integral.intersection(bounds)
35
+ guard !box.isNull, box.width >= 1, box.height >= 1 else { return nil }
36
+ // Core Image's origin is at the bottom left.
37
+ let flipped = CGRect(x: box.minX, y: Double(height) - box.maxY, width: box.width, height: box.height)
38
+ return _recipe.rendered(in: flipped).map(CGImage.init(_recipe:))
39
+ }
40
+ }
41
+
42
+ /// UIKit's image: a bitmap with a scale (pixels per point), or an SF Symbol
43
+ /// or asset-catalog image the page draws by name.
44
+ public final class UIImage: Hashable, @unchecked Sendable {
45
+ public enum Orientation: Int, Sendable {
46
+ case up, down, left, right, upMirrored, downMirrored, leftMirrored, rightMirrored
47
+ }
48
+
49
+ enum Content {
50
+ case bitmap(_ImageRecipe)
51
+ case system(String)
52
+ case named(String)
53
+ }
54
+
55
+ let content: Content
56
+ /// The size in points: pixels ÷ `scale`.
57
+ public let size: CGSize
58
+ public let scale: CGFloat
59
+ /// Always `.up` for decoded files: the page draws them with their EXIF
60
+ /// rotation applied, and their size already accounts for it.
61
+ public let imageOrientation: Orientation
62
+ /// The `CIImage` a Core Image-backed image was made from (`UIImage(ciImage:)`).
63
+ public let _ciImage: AnyObject?
64
+ /// UIKit's `renderingMode`: 0 automatic, 1 always original, 2 always template.
65
+ public private(set) var _renderingMode = 0
66
+
67
+ private init(content: Content, size: CGSize, scale: CGFloat, orientation: Orientation, ciImage: AnyObject?) {
68
+ self.content = content
69
+ self.size = size
70
+ self.scale = scale
71
+ imageOrientation = orientation
72
+ _ciImage = ciImage
73
+ }
74
+
75
+ /// The same image with another rendering mode (UIKit's `withRenderingMode`),
76
+ /// or another bitmap of the same size (`withTintColor`).
77
+ public func _copy(recipe: _ImageRecipe? = nil, renderingMode: Int) -> UIImage {
78
+ let copy = UIImage(content: recipe.map(Content.bitmap) ?? content, size: size, scale: scale, orientation: imageOrientation,
79
+ ciImage: recipe == nil ? _ciImage : nil)
80
+ copy._renderingMode = renderingMode
81
+ return copy
82
+ }
83
+
84
+ /// Whether the image is an SF Symbol (drawn by the page by name).
85
+ public var _isSymbol: Bool {
86
+ if case .system = content { return true }
87
+ return false
88
+ }
89
+
90
+ /// An empty image, 0 × 0.
91
+ public init() {
92
+ content = .bitmap(.empty)
93
+ size = .zero
94
+ scale = 1
95
+ imageOrientation = .up
96
+ _ciImage = nil
97
+ }
98
+
99
+ /// The image in a PNG, JPEG, GIF, WebP, BMP, HEIC or AVIF file; nil when
100
+ /// the data is not one. Only the header is read here; the page decodes
101
+ /// the file when it draws it. (Chromium and Firefox draw no HEIC.)
102
+ public convenience init?(data: Data) {
103
+ self.init(data: data, scale: 1)
104
+ }
105
+
106
+ public init?(data: Data, scale: CGFloat) {
107
+ guard let source = _ImageSource(encoded: [UInt8](data)) else { return nil }
108
+ let factor = scale > 0 ? scale : 1
109
+ content = .bitmap(_ImageRecipe(source: source))
110
+ size = CGSize(width: Double(source.width) / factor, height: Double(source.height) / factor)
111
+ self.scale = factor
112
+ imageOrientation = .up
113
+ _ciImage = nil
114
+ }
115
+
116
+ public convenience init(cgImage: CGImage) {
117
+ self.init(cgImage: cgImage, scale: 1, orientation: .up)
118
+ }
119
+
120
+ /// `orientation` is recorded, not applied: the page draws the bitmap upright.
121
+ public init(cgImage: CGImage, scale: CGFloat, orientation: Orientation) {
122
+ let factor = scale > 0 ? scale : 1
123
+ content = .bitmap(cgImage._recipe)
124
+ size = CGSize(width: Double(cgImage.width) / factor, height: Double(cgImage.height) / factor)
125
+ self.scale = factor
126
+ imageOrientation = orientation
127
+ _ciImage = nil
128
+ }
129
+
130
+ /// A bitmap from a recipe whose extent is its pixel grid, `(0, 0, w, h)`
131
+ /// (Core Image's `UIImage(ciImage:)`).
132
+ public init(_recipe recipe: _ImageRecipe, scale: CGFloat, ciImage: AnyObject?) {
133
+ let factor = scale > 0 ? scale : 1
134
+ let extent = recipe.extent.isNull || recipe.extent.isInfinite ? CGRect.zero : recipe.extent
135
+ content = .bitmap(recipe)
136
+ size = CGSize(width: extent.width / factor, height: extent.height / factor)
137
+ self.scale = factor
138
+ imageOrientation = .up
139
+ _ciImage = ciImage
140
+ }
141
+
142
+ /// An SF Symbol. Never nil: the shim cannot tell which names exist, and
143
+ /// the page draws a placeholder for one it does not know. The size is
144
+ /// that of a symbol at the body text style.
145
+ public init?(systemName: String) {
146
+ content = .system(systemName)
147
+ size = CGSize(width: 20, height: 20)
148
+ scale = 1
149
+ imageOrientation = .up
150
+ _ciImage = nil
151
+ }
152
+
153
+ /// An asset-catalog image. Never nil, and its size is zero: the catalog
154
+ /// is the page's (docs/ops-protocol.md, "Phase 5"), so only the page knows it.
155
+ public init?(named name: String) {
156
+ content = .named(name)
157
+ size = .zero
158
+ scale = 1
159
+ imageOrientation = .up
160
+ _ciImage = nil
161
+ }
162
+
163
+ /// The bitmap, for an image made from data or a `CGImage`; nil for a
164
+ /// symbol, a catalog image, an empty image or one backed by a `CIImage`
165
+ /// (as on iOS).
166
+ public var cgImage: CGImage? {
167
+ guard _ciImage == nil, case .bitmap(let recipe) = content, recipe.source != nil else { return nil }
168
+ return CGImage(_recipe: recipe)
169
+ }
170
+
171
+ /// The recipe the page draws; nil for a symbol or a catalog image.
172
+ public var _recipe: _ImageRecipe? {
173
+ if case .bitmap(let recipe) = content { return recipe }
174
+ return nil
175
+ }
176
+
177
+ public static func == (lhs: UIImage, rhs: UIImage) -> Bool { lhs === rhs }
178
+ public func hash(into hasher: inout Hasher) { hasher.combine(ObjectIdentifier(self)) }
179
+ }
180
+
181
+ extension Image {
182
+ /// The way `Image(_:scale:orientation:label:)` takes a `CGImage`.
183
+ /// Recorded, not applied: the page draws the bitmap upright.
184
+ public enum Orientation: UInt8, CaseIterable, Hashable, Sendable {
185
+ case up, upMirrored, down, downMirrored, left, leftMirrored, right, rightMirrored
186
+ }
187
+
188
+ /// A `UIImage`: its bitmap (drawn by the page from its recipe), or the
189
+ /// symbol or catalog image it names. The intrinsic size is the image's
190
+ /// size in points.
191
+ public init(uiImage: UIImage) {
192
+ switch uiImage.content {
193
+ case .system(let name): self.init(source: .system(name), isResizable: false)
194
+ case .named(let name): self.init(source: .named(name), isResizable: false)
195
+ case .bitmap(let recipe):
196
+ self.init(source: .bitmap(recipe, width: uiImage.size.width, height: uiImage.size.height), isResizable: false)
197
+ }
198
+ }
199
+
200
+ public init(_ cgImage: CGImage, scale: CGFloat, orientation: Orientation = .up, label: Text) {
201
+ let factor = scale > 0 ? scale : 1
202
+ self.init(source: .bitmap(cgImage._recipe, width: Double(cgImage.width) / factor, height: Double(cgImage.height) / factor),
203
+ isResizable: false)
204
+ }
205
+
206
+ public init(decorative cgImage: CGImage, scale: CGFloat, orientation: Orientation = .up) {
207
+ self.init(cgImage, scale: scale, orientation: orientation, label: Text(""))
208
+ }
209
+
210
+ /// Sends the bitmap's source to the page once (an `imagedata` op), before
211
+ /// the element that draws it.
212
+ @MainActor func _sendBitmapSource(through runtime: _Runtime) {
213
+ if case .bitmap(let recipe, _, _) = source, let source = recipe.source { runtime._sendImageSource(source) }
214
+ }
215
+ }
216
+
217
+ // Core Graphics' rectangle helpers that Core Image's extents need.
218
+ extension CGRect {
219
+ /// A rectangle covering the whole plane (a `clampedToExtent()` image's extent).
220
+ public static let infinite = CGRect(x: -Double.greatestFiniteMagnitude / 2, y: -Double.greatestFiniteMagnitude / 2,
221
+ width: Double.greatestFiniteMagnitude, height: Double.greatestFiniteMagnitude)
222
+ /// No rectangle at all (the intersection of two that do not meet).
223
+ public static let null = CGRect(x: Double.infinity, y: Double.infinity, width: 0, height: 0)
224
+
225
+ public var isInfinite: Bool { size.width >= Double.greatestFiniteMagnitude || size.height >= Double.greatestFiniteMagnitude }
226
+ public var isNull: Bool { origin.x == .infinity || origin.y == .infinity }
227
+
228
+ /// The overlap of two rectangles; `.null` when they do not overlap.
229
+ public func intersection(_ other: CGRect) -> CGRect {
230
+ if isNull || other.isNull { return .null }
231
+ if isInfinite { return other }
232
+ if other.isInfinite { return self }
233
+ let x0 = max(minX, other.minX), y0 = max(minY, other.minY)
234
+ let x1 = min(maxX, other.maxX), y1 = min(maxY, other.maxY)
235
+ guard x1 > x0, y1 > y0 else { return .null }
236
+ return CGRect(x: x0, y: y0, width: x1 - x0, height: y1 - y0)
237
+ }
238
+
239
+ /// The smallest rectangle containing both.
240
+ public func union(_ other: CGRect) -> CGRect {
241
+ if isNull { return other }
242
+ if other.isNull { return self }
243
+ if isInfinite || other.isInfinite { return .infinite }
244
+ let x0 = min(minX, other.minX), y0 = min(minY, other.minY)
245
+ return CGRect(x: x0, y: y0, width: max(maxX, other.maxX) - x0, height: max(maxY, other.maxY) - y0)
246
+ }
247
+
248
+ /// The smallest rectangle with integer coordinates containing this one.
249
+ public var integral: CGRect {
250
+ if isNull || isInfinite { return self }
251
+ let x0 = minX.rounded(.down), y0 = minY.rounded(.down)
252
+ return CGRect(x: x0, y: y0, width: maxX.rounded(.up) - x0, height: maxY.rounded(.up) - y0)
253
+ }
254
+ }