#if os(macOS) import AppKit typealias KitColor = NSColor typealias KitWeight = NSFont.Weight #else import UIKit typealias KitColor = UIColor typealias KitWeight = UIImage.SymbolWeight #endif /// Internal: registers the views behind the kit's native controls, such as /// `Glass` and `Segmented`. `EffectUIHostComponentView` calls it on load. @objc(EffectUIKit) public final class _EffectUIKit: NSObject { @MainActor @objc public static func registerViews() { EffectUI.register("EffectUIGlass", props: ["cornerRadius", "tintColor", "material"]) { _ in EffectUIGlassView() } EffectUI.register("EffectUISymbol", props: ["name", "size", "weight", "tintColor", "accessibilityLabel"]) { _ in EffectUISymbolView() } EffectUI.register( "EffectUISegmented", props: ["segments", "selected", "momentary", "tintColor", "size", "disabled"] ) { EffectUISegmentedView($0) } EffectUI.register( "EffectUIButton", props: ["symbol", "label", "bezel", "tintColor", "size", "disabled", "accessibilityLabel"] ) { EffectUIButtonView($0) } EffectUI.register("EffectUIProgress", props: ["value", "shape", "tintColor"]) { _ in EffectUIProgressView() } #if os(macOS) EffectUI.register("EffectUIWindowDrag") { _ in EffectUIWindowDragView() } EffectUI.register("EffectUICheckbox", props: ["value", "disabled", "accessibilityLabel"]) { EffectUICheckboxView($0) } #endif } } // Removed props arrive as `NSNull`, which these casts read as `nil`. func kitNumber(_ value: Any?) -> CGFloat? { (value as? NSNumber).map { CGFloat($0.doubleValue) } } func kitBool(_ value: Any?) -> Bool { (value as? NSNumber)?.boolValue ?? false } /// A frame of `height` that fills the width of `bounds`, centred in its height. func kitCentered(_ height: CGFloat, in bounds: CGRect) -> CGRect { CGRect(x: 0, y: ((bounds.height - height) / 2).rounded(), width: bounds.width, height: height) } func kitSymbolWeight(_ value: Any?) -> KitWeight { switch value as? String { case "ultraLight": return .ultraLight case "thin": return .thin case "light": return .light case "medium": return .medium case "semibold": return .semibold case "bold": return .bold case "heavy": return .heavy case "black": return .black default: return .regular } } #if os(macOS) func kitControlSize(_ value: Any?) -> NSControl.ControlSize { switch value as? String { case "small": return .small case "large": return .large default: return .regular } } #endif