Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ let OpenSwiftUI_SPITestTarget = Target.testTarget(
"OpenSwiftUI_SPI",
// For ProtocolDescriptor symbol linking
"OpenSwiftUI",
.product(name: "Numerics", package: "swift-numerics")
.product(name: "Numerics", package: "swift-numerics"),
],
exclude: ["README.md"],
swiftSettings: sharedSwiftSettings
Expand All @@ -119,6 +119,7 @@ let openSwiftUICoreTestTarget = Target.testTarget(
name: "OpenSwiftUICoreTests",
dependencies: [
"OpenSwiftUICore",
.product(name: "Numerics", package: "swift-numerics"),
],
exclude: ["README.md"],
swiftSettings: sharedSwiftSettings
Expand All @@ -133,6 +134,9 @@ let openSwiftUITestTarget = Target.testTarget(
)
let openSwiftUICompatibilityTestTarget = Target.testTarget(
name: "OpenSwiftUICompatibilityTests",
dependencies: [
.product(name: "Numerics", package: "swift-numerics"),
],
exclude: ["README.md"],
swiftSettings: sharedSwiftSettings
)
Expand Down
17 changes: 17 additions & 0 deletions Sources/OpenSwiftUICore/Data/Environment/EnvironmentalView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// EnvironmentalView.swift
// OpenSwiftUICore
//
// Audited for iOS 18.0
// Status: WIP

package protocol EnvironmentalView: PrimitiveView, UnaryView {
associatedtype EnvironmentBody: View
func body(environment: EnvironmentValues) -> EnvironmentBody
}

extension EnvironmentalView {
nonisolated public static func _makeView(view: _GraphValue<Self>, inputs: _ViewInputs) -> _ViewOutputs {
preconditionFailure("")

Check warning on line 15 in Sources/OpenSwiftUICore/Data/Environment/EnvironmentalView.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Data/Environment/EnvironmentalView.swift#L14-L15

Added lines #L14 - L15 were not covered by tests
}
}
87 changes: 0 additions & 87 deletions Sources/OpenSwiftUICore/Data/Other/AtomicBox.swift

This file was deleted.

107 changes: 107 additions & 0 deletions Sources/OpenSwiftUICore/Graphic/Color/Color+CGColor.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
//
// Color+CoreGraphics.swift
// OpenSwiftUICore
//
// Audited for iOS 18.0
// Status: Blocked by ResolvedGradient
// ID: A45C110C8134A7DB30776EFC6CE1E8A6 (SwiftUICore?)

#if canImport(Darwin)

public import CoreGraphics

// MARK: - CGColor + Color

extension Color {
/// Creates a color from a Core Graphics color.
///
/// - Parameter color: A
/// [CGColor](https://developer.apple.com/documentation/CoreGraphics/CGColor) instance
/// from which to create a color.
@available(*, deprecated, message: "Use Color(cgColor:) when converting a CGColor, or create a standard Color directly")
public init(_ cgColor: CGColor) {
self.init(cgColor: cgColor)

Check warning on line 23 in Sources/OpenSwiftUICore/Graphic/Color/Color+CGColor.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Graphic/Color/Color+CGColor.swift#L22-L23

Added lines #L22 - L23 were not covered by tests
}
}

extension Color {
/// Creates a color from a Core Graphics color.
///
/// - Parameter color: A
/// [CGColor](https://developer.apple.com/documentation/CoreGraphics/CGColor) instance
/// from which to create a color.
public init(cgColor: CGColor) {
self.init(provider: cgColor)

Check warning on line 34 in Sources/OpenSwiftUICore/Graphic/Color/Color+CGColor.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Graphic/Color/Color+CGColor.swift#L33-L34

Added lines #L33 - L34 were not covered by tests
}
}

extension CGColor: ColorProvider {
package func resolve(in environment: EnvironmentValues) -> Color.Resolved {
Color.Resolved(self)

Check warning on line 40 in Sources/OpenSwiftUICore/Graphic/Color/Color+CGColor.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Graphic/Color/Color+CGColor.swift#L39-L40

Added lines #L39 - L40 were not covered by tests
}

package var staticColor: CGColor? {
self

Check warning on line 44 in Sources/OpenSwiftUICore/Graphic/Color/Color+CGColor.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Graphic/Color/Color+CGColor.swift#L43-L44

Added lines #L43 - L44 were not covered by tests
}
}

extension Color.Resolved {
package static let srgb: CGColorSpace = CGColorSpace(name: CGColorSpace.sRGB)!
package static let srgbExtended: CGColorSpace = CGColorSpace(name: CGColorSpace.extendedSRGB)!
package static let srgbLinear: CGColorSpace = CGColorSpace(name: CGColorSpace.linearSRGB)!
package static let srgbExtendedLinear: CGColorSpace = CGColorSpace(name: CGColorSpace.extendedLinearSRGB)!
package static let displayP3: CGColorSpace = CGColorSpace(name: CGColorSpace.displayP3)!

package init(_ cgColor: CGColor) {
self = Color.Resolved(failableCGColor: cgColor) ?? .init(linearWhite: 0)

Check warning on line 56 in Sources/OpenSwiftUICore/Graphic/Color/Color+CGColor.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Graphic/Color/Color+CGColor.swift#L55-L56

Added lines #L55 - L56 were not covered by tests
}

package init?(failableCGColor cgColor: CGColor) {
let colorSpace: Color.RGBColorSpace
let convertedColor: CGColor
switch cgColor.colorSpace {
case Color.Resolved.srgb, Color.Resolved.srgbExtended:
colorSpace = .sRGB
convertedColor = cgColor
case Color.Resolved.srgbLinear, Color.Resolved.srgbExtendedLinear:
colorSpace = .sRGBLinear
convertedColor = cgColor
case Color.Resolved.displayP3:
colorSpace = .displayP3
convertedColor = cgColor
default:
guard let color = cgColor.converted(to: Color.Resolved.srgbExtended, intent: .defaultIntent, options: nil) else {
return nil

Check warning on line 74 in Sources/OpenSwiftUICore/Graphic/Color/Color+CGColor.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Graphic/Color/Color+CGColor.swift#L59-L74

Added lines #L59 - L74 were not covered by tests
}
colorSpace = .sRGB
convertedColor = color

Check warning on line 77 in Sources/OpenSwiftUICore/Graphic/Color/Color+CGColor.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Graphic/Color/Color+CGColor.swift#L76-L77

Added lines #L76 - L77 were not covered by tests
}
guard let components = convertedColor.components else {
return nil

Check warning on line 80 in Sources/OpenSwiftUICore/Graphic/Color/Color+CGColor.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Graphic/Color/Color+CGColor.swift#L79-L80

Added lines #L79 - L80 were not covered by tests
}
let red = Float(components[0])
let green = Float(components[1])
let blue = Float(components[2])
let alpha = Float(cgColor.alpha)
self.init(colorSpace: colorSpace, red: red, green: green, blue: blue, opacity: alpha)

Check warning on line 86 in Sources/OpenSwiftUICore/Graphic/Color/Color+CGColor.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Graphic/Color/Color+CGColor.swift#L82-L86

Added lines #L82 - L86 were not covered by tests
}
}

extension Color.Resolved {
private static let cache: ObjectCache<Color.Resolved, CGColor> = ObjectCache { resolved in
var components: [CGFloat] = [CGFloat(resolved.red), CGFloat(resolved.green), CGFloat(resolved.blue), CGFloat(resolved.opacity)]
return CGColor(colorSpace: Self.srgbExtended, components: &components)!

Check warning on line 93 in Sources/OpenSwiftUICore/Graphic/Color/Color+CGColor.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Graphic/Color/Color+CGColor.swift#L91-L93

Added lines #L91 - L93 were not covered by tests
}

public var cgColor: CGColor {
Self.cache[self]

Check warning on line 97 in Sources/OpenSwiftUICore/Graphic/Color/Color+CGColor.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Graphic/Color/Color+CGColor.swift#L96-L97

Added lines #L96 - L97 were not covered by tests
}
}

//extension ResolvedGradient {
// package var cgGradient: CGGradient? {
// get
// }
//}

#endif
72 changes: 72 additions & 0 deletions Sources/OpenSwiftUICore/Graphic/Color/Color+ShapeStyle.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
//
// Color+ShapeStyle.swift
// OpenSwiftUICore
//
// Audited for iOS 18.0
// Status: Complete

package import Foundation

extension Color: ShapeStyle {
package func fallbackColor(in env: EnvironmentValues) -> Color? { self }
package func resolvePaint(in environment: EnvironmentValues) -> Color.Resolved { resolve(in: environment) }

Check warning on line 12 in Sources/OpenSwiftUICore/Graphic/Color/Color+ShapeStyle.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Graphic/Color/Color+ShapeStyle.swift#L11-L12

Added lines #L11 - L12 were not covered by tests

@available(*, deprecated, message: "obsolete")
@_alwaysEmitIntoClient
nonisolated public static func _makeView<S>(view: _GraphValue<_ShapeView<S, Self>>, inputs: _ViewInputs) -> _ViewOutputs where S: Shape {
_ShapeView<S, Self>._makeView(view: view, inputs: inputs)

Check warning on line 17 in Sources/OpenSwiftUICore/Graphic/Color/Color+ShapeStyle.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Graphic/Color/Color+ShapeStyle.swift#L16-L17

Added lines #L16 - L17 were not covered by tests
}
}

extension ColorProvider {
package func apply(color: Color, to shape: inout _ShapeStyle_Shape) {
_apply(color: color, to: &shape)

Check warning on line 23 in Sources/OpenSwiftUICore/Graphic/Color/Color+ShapeStyle.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Graphic/Color/Color+ShapeStyle.swift#L22-L23

Added lines #L22 - L23 were not covered by tests
}

package func _apply(color: Color, to shape: inout _ShapeStyle_Shape) {
switch shape.operation {
case let .prepareText(level):
if level >= 1 {
let opacity = color.provider.opacity(at: level, environment: shape.environment)
shape.result = .preparedText(.foregroundColor(color.opacity(Double(opacity))))
} else {
shape.result = .preparedText(.foregroundColor(color))

Check warning on line 33 in Sources/OpenSwiftUICore/Graphic/Color/Color+ShapeStyle.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Graphic/Color/Color+ShapeStyle.swift#L26-L33

Added lines #L26 - L33 were not covered by tests
}
case let .resolveStyle(name, levels):
guard levels.lowerBound != levels.upperBound else {
return

Check warning on line 37 in Sources/OpenSwiftUICore/Graphic/Color/Color+ShapeStyle.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Graphic/Color/Color+ShapeStyle.swift#L35-L37

Added lines #L35 - L37 were not covered by tests
}
let resolved = resolve(in: shape.environment)
let opacity = color.provider.opacity(at: levels.lowerBound, environment: shape.environment)

var newPack: _ShapeStyle_Pack
switch shape.result {
case let .pack(pack): newPack = pack
default: newPack = .init()

Check warning on line 45 in Sources/OpenSwiftUICore/Graphic/Color/Color+ShapeStyle.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Graphic/Color/Color+ShapeStyle.swift#L39-L45

Added lines #L39 - L45 were not covered by tests
}
newPack[name, levels.lowerBound] = .init(.color(resolved.multiplyingOpacity(by: opacity)))
shape.result = .pack(newPack)
case let .fallbackColor(level):
if level >= 1 {
let opacity = color.provider.opacity(at: level, environment: shape.environment)
shape.result = .color(color.opacity(Double(opacity)))
} else {
shape.result = .color(color)

Check warning on line 54 in Sources/OpenSwiftUICore/Graphic/Color/Color+ShapeStyle.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Graphic/Color/Color+ShapeStyle.swift#L47-L54

Added lines #L47 - L54 were not covered by tests
}
default:
break

Check warning on line 57 in Sources/OpenSwiftUICore/Graphic/Color/Color+ShapeStyle.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Graphic/Color/Color+ShapeStyle.swift#L56-L57

Added lines #L56 - L57 were not covered by tests
}
}
}

// MARK: - Color.Resolved + ResolvedPaint

extension Color.Resolved: ResolvedPaint {
package func draw(path: Path, style: PathDrawingStyle, in context: GraphicsContext, bounds: CGRect?) {
context.draw(path, with: .color(self), style: style)

Check warning on line 66 in Sources/OpenSwiftUICore/Graphic/Color/Color+ShapeStyle.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Graphic/Color/Color+ShapeStyle.swift#L65-L66

Added lines #L65 - L66 were not covered by tests
}

package var isClear: Bool { opacity == 0 }
package var isOpaque: Bool { opacity == 1 }
package static var leafProtobufTag: CodableResolvedPaint.Tag? { .color }
}
Loading
Loading