nitro-ui-macos 0.0.0-stage → 0.0.1

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 (128) hide show
  1. package/CONTRIBUTING.md +56 -0
  2. package/LICENSE +21 -0
  3. package/PARITY.md +373 -0
  4. package/README.md +147 -2
  5. package/native/nitro-core/Package.swift +78 -0
  6. package/native/nitro-ui-core/Package.swift +112 -0
  7. package/native/nitro-ui-core/Sources/NitroUICoreMac/AnimationFrameDisplayLink.swift +127 -0
  8. package/native/nitro-ui-core/Sources/NitroUICoreMac/HybridAnimationFrameScheduler.swift +91 -0
  9. package/native/nitro-ui-core/Sources/NitroUICoreMac/HybridLinking.swift +18 -0
  10. package/native/nitro-ui-dev/Package.swift +102 -0
  11. package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevBundleLoad.swift +14 -0
  12. package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevBundleLoader.swift +85 -0
  13. package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevLauncher.swift +192 -0
  14. package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevMenu.swift +172 -0
  15. package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevServerBrowser.swift +86 -0
  16. package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevSession.swift +151 -0
  17. package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevShortcuts.swift +85 -0
  18. package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevToast.swift +85 -0
  19. package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevTools.swift +141 -0
  20. package/native/nitro-ui-dev/Sources/NitroUIDevMac/ErrorModels.swift +97 -0
  21. package/native/nitro-ui-dev/Sources/NitroUIDevMac/ErrorOverlay.swift +698 -0
  22. package/native/nitro-ui-dev/Sources/NitroUIDevMac/HybridDevBundles.swift +64 -0
  23. package/native/nitro-ui-dev/Sources/NitroUIDevMac/HybridDevErrors.swift +56 -0
  24. package/native/nitro-ui-dev/Sources/NitroUIDevMac/HybridDevLoadingView.swift +27 -0
  25. package/native/nitro-ui-dev/Sources/NitroUIDevMac/HybridDevMenu.swift +40 -0
  26. package/native/nitro-ui-dev/Sources/NitroUIDevMac/HybridDevToast.swift +19 -0
  27. package/native/nitro-ui-dev/Sources/NitroUIDevMac/LauncherWindowController.swift +217 -0
  28. package/native/nitro-ui-dev/Sources/NitroUIDevMac/LoadingOverlay.swift +104 -0
  29. package/native/nitro-ui-dev/Sources/NitroUIDevMac/RegisterDevLoader.swift +22 -0
  30. package/native/nitro-ui-dev/Sources/NitroUIDevMac/SavedBundles.swift +70 -0
  31. package/native/nitro-ui-glass/Package.swift +103 -0
  32. package/native/nitro-ui-glass/macos/HybridLiquidGlass.swift +5 -0
  33. package/native/nitro-ui-glass/macos/HybridNativeLiquidGlassContainerView.swift +40 -0
  34. package/native/nitro-ui-glass/macos/HybridNativeLiquidGlassView.swift +80 -0
  35. package/native/nitro-ui-glass/macos/LiquidGlassEffectView.swift +181 -0
  36. package/native/nitro-ui-glass/macos/LiquidGlassSupport.swift +17 -0
  37. package/native/nitro-ui-navigation/Package.swift +105 -0
  38. package/native/nitro-ui-navigation/Sources/NitroUINavigationMac/HybridNavigationScreen.swift +199 -0
  39. package/native/nitro-ui-navigation/Sources/NitroUINavigationMac/HybridNavigationSharedElement.swift +17 -0
  40. package/native/nitro-ui-navigation/Sources/NitroUINavigationMac/HybridNavigationSplit.swift +889 -0
  41. package/native/nitro-ui-navigation/Sources/NitroUINavigationMac/HybridNavigationStack.swift +404 -0
  42. package/native/nitro-ui-navigation/Sources/NitroUINavigationMac/HybridNavigationTabs.swift +186 -0
  43. package/native/nitro-ui-navigation/Sources/NitroUINavigationMac/MacStackContainerController.swift +260 -0
  44. package/native/nitro-ui-navigation/Sources/NitroUINavigationMac/NavigationSharedElementView.swift +28 -0
  45. package/native/nitro-ui-renderer/Package.swift +105 -0
  46. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Animations/HybridAnimator.swift +502 -0
  47. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Animations/NitroAnimationContext.swift +54 -0
  48. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Animations/View+Animations.swift +35 -0
  49. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/AssetFonts.swift +36 -0
  50. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/FlippedView.swift +360 -0
  51. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/HybridContainerView.swift +28 -0
  52. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/HybridFonts.swift +7 -0
  53. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/HybridLabel.swift +127 -0
  54. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/HybridMaskedView.swift +185 -0
  55. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/HybridScrollView.swift +255 -0
  56. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/HybridScrollViewContent.swift +22 -0
  57. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/HybridView.swift +18 -0
  58. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/Image/HybridImage.swift +281 -0
  59. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/Image/HybridImageFactory.swift +132 -0
  60. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/Image/HybridImageLoader.swift +149 -0
  61. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/Image/HybridImageView.swift +601 -0
  62. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/Image/ImagePixelSupport.swift +418 -0
  63. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/LabelView.swift +198 -0
  64. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/HybridListView.swift +177 -0
  65. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/NativeListCell.swift +98 -0
  66. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/NativeListContentView.swift +12 -0
  67. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/NativeListFenwickTree.swift +94 -0
  68. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/NativeListScrollView.swift +1100 -0
  69. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/NativeListSnapshot.swift +24 -0
  70. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/NativeListUpdate.swift +11 -0
  71. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/NativeListView.swift +260 -0
  72. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/NativeContainerView.swift +443 -0
  73. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/NitroViewProtocols.swift +275 -0
  74. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/ShadowLayers.swift +338 -0
  75. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/TextInput/HybridTextInput.swift +252 -0
  76. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/TextInput/NitroTextInputView.swift +447 -0
  77. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/View.swift +660 -0
  78. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/CustomViewController.swift +254 -0
  79. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/DesktopHostDelegate.swift +14 -0
  80. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Extensions.swift +102 -0
  81. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Gestures/GestureRecognizerDelegate.swift +24 -0
  82. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Gestures/HybridGestureRecognizer.swift +41 -0
  83. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Gestures/HybridLongPressGestureRecognizer.swift +172 -0
  84. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Gestures/HybridPanGestureRecognizer.swift +193 -0
  85. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Gestures/HybridTapGestureRecognizer.swift +165 -0
  86. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/HybridAppearance.swift +75 -0
  87. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/HybridApplication.swift +29 -0
  88. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/HybridKeyboard.swift +26 -0
  89. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/HybridScreen.swift +29 -0
  90. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/HybridViewController.swift +232 -0
  91. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/HybridWindow.swift +61 -0
  92. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/HybridWindowScene.swift +17 -0
  93. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/LayoutNode.swift +73 -0
  94. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/NSColor+rgba.swift +29 -0
  95. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/RegisterRootCallback.swift +27 -0
  96. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/RuntimeReloadableAppDelegate.swift +7 -0
  97. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/SafeAreaInsetsListeners.swift +26 -0
  98. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/SizeListeners.swift +27 -0
  99. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/UIErrorHandler.swift +15 -0
  100. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/ViewController.swift +6 -0
  101. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Window.swift +156 -0
  102. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/WindowScene.swift +23 -0
  103. package/native/nitro-ui-runtime/Package.swift +67 -0
  104. package/native/nitro-ui-runtime/Sources/NitroUIRuntimeMac/DevLoader.swift +16 -0
  105. package/native/nitro-ui-runtime/Sources/NitroUIRuntimeMac/NitroUIAppDelegate.swift +253 -0
  106. package/package.json +59 -4
  107. package/src/Platform.ts +43 -0
  108. package/src/bin.js +18 -0
  109. package/src/build.ts +453 -0
  110. package/src/bundleWorker.ts +80 -0
  111. package/src/cli.ts +157 -0
  112. package/src/config.ts +233 -0
  113. package/src/create.ts +67 -0
  114. package/src/files.ts +70 -0
  115. package/src/index.ts +1 -0
  116. package/src/init.ts +301 -0
  117. package/src/inlinePlatform.ts +140 -0
  118. package/src/modules.ts +385 -0
  119. package/src/packageApp.ts +103 -0
  120. package/src/packageDirectory.ts +61 -0
  121. package/src/preload.ts +40 -0
  122. package/src/prepare.ts +433 -0
  123. package/src/run.ts +41 -0
  124. package/src/runApp.ts +81 -0
  125. package/src/start.ts +152 -0
  126. package/src/toolchain.ts +83 -0
  127. package/src/versions.ts +103 -0
  128. package/templates/AppIcon.icns +0 -0
@@ -0,0 +1,103 @@
1
+ // swift-tools-version: 6.4
2
+
3
+ import Foundation
4
+ import PackageDescription
5
+
6
+ let name = "NitroGlass"
7
+ let generated = "nitrogen/generated"
8
+ let nitroDependencies: [Target.Dependency] = [
9
+ .product(name: "NitroModules", package: "nitro-core"),
10
+ .product(name: "NitroUIRenderer", package: "nitro-ui-renderer"),
11
+ ]
12
+ let cxxSettings: [CXXSetting] = [
13
+ .define("DEBUG", .when(configuration: .debug)),
14
+ .define("NDEBUG", .when(configuration: .release)),
15
+ .disableWarning("nullability-extension"),
16
+ ]
17
+ let swiftSources = [
18
+ "macos",
19
+ "\(generated)/apple/swift",
20
+ ]
21
+ let bridgeSources = ["c++", "NitroGlass-Swift-Cxx-Bridge.cpp", "NitroGlassAutolinking.cpp"]
22
+
23
+ let package = Package(
24
+ name: name,
25
+ platforms: [.macOS(.v13)],
26
+ products: [
27
+ .library(name: name, targets: ["\(name)Cxx", name, "\(name)SwiftBridge"])
28
+ ],
29
+ dependencies: [
30
+ .package(path: "../nitro-core"),
31
+ .package(path: "../nitro-ui-renderer"),
32
+ ],
33
+ targets: [
34
+ .target(
35
+ name: "\(name)Cxx",
36
+ dependencies: nitroDependencies,
37
+ path: "\(generated)/shared/c++",
38
+ exclude: ["include"],
39
+ publicHeadersPath: "include",
40
+ cxxSettings: cxxSettings
41
+ ),
42
+ .target(
43
+ name: "\(name)AppleCxx",
44
+ dependencies: [.target(name: "\(name)Cxx")] + nitroDependencies,
45
+ path: "\(generated)/apple/\(name)AppleCxx",
46
+ cxxSettings: cxxSettings
47
+ ),
48
+ .target(
49
+ name: name,
50
+ dependencies: [.target(name: "\(name)AppleCxx")] + nitroDependencies,
51
+ path: ".",
52
+ exclude: excludes(in: ".", keeping: swiftSources),
53
+ sources: swiftSources,
54
+ cxxSettings: cxxSettings,
55
+ swiftSettings: [
56
+ .swiftLanguageMode(.v5),
57
+ .unsafeFlags(["-strict-concurrency=minimal"]),
58
+ .enableUpcomingFeature("InternalImportsByDefault"),
59
+ .enableUpcomingFeature("MemberImportVisibility"),
60
+ .interoperabilityMode(.Cxx),
61
+ .unsafeFlags(["-Xfrontend", "-clang-header-expose-decls=has-expose-attr-or-stdlib"]),
62
+ .unsafeFlags([
63
+ "-Xfrontend", "-clang-header-expose-module",
64
+ "-Xfrontend", "NitroModules=NitroModules-Swift.h",
65
+ ]),
66
+ ]
67
+ ),
68
+ .target(
69
+ name: "\(name)SwiftBridge",
70
+ dependencies: [.target(name: name), .target(name: "\(name)AppleCxx")] + nitroDependencies,
71
+ path: "\(generated)/apple",
72
+ exclude: excludes(in: "\(generated)/apple", keeping: bridgeSources) + ["c++/include"],
73
+ sources: bridgeSources,
74
+ publicHeadersPath: "c++/include",
75
+ cxxSettings: cxxSettings + [
76
+ .unsafeFlags(["-I${GENERATED_MODULEMAP_DIR}", "-fno-modules"])
77
+ ]
78
+ ),
79
+ ],
80
+ cxxLanguageStandard: .cxx20
81
+ )
82
+
83
+ func excludes(in path: String, keeping sources: [String]) -> [String] {
84
+ var parents: Set<String> = [""]
85
+ for source in sources {
86
+ var components = source.split(separator: "/").dropLast()
87
+ while !components.isEmpty {
88
+ parents.insert(components.joined(separator: "/"))
89
+ components = components.dropLast()
90
+ }
91
+ }
92
+ let root = URL(fileURLWithPath: Context.packageDirectory).appendingPathComponent(path)
93
+ return parents.sorted().flatMap { parent in
94
+ let entries =
95
+ (try? FileManager.default.contentsOfDirectory(
96
+ atPath: root.appendingPathComponent(parent).path)) ?? []
97
+ return entries.sorted().compactMap { entry in
98
+ let entryPath = parent.isEmpty ? entry : "\(parent)/\(entry)"
99
+ return entry.hasPrefix(".") || sources.contains(entryPath) || parents.contains(entryPath)
100
+ ? nil : entryPath
101
+ }
102
+ }
103
+ }
@@ -0,0 +1,5 @@
1
+ internal import NitroModules
2
+
3
+ final class HybridLiquidGlass: HybridLiquidGlassSpec {
4
+ static var isSupported: Bool { LiquidGlassSupport.isSupported }
5
+ }
@@ -0,0 +1,40 @@
1
+ internal import AppKit
2
+ internal import NitroModules
3
+ internal import NitroUIRenderer
4
+
5
+ final class HybridNativeLiquidGlassContainerView: HybridNativeLiquidGlassContainerViewSpec {
6
+ typealias AllowedChildrenType = any View
7
+
8
+ let view = LiquidGlassContainerHostView(frame: .zero)
9
+ let layoutNode = LayoutNode()
10
+ var parentReference: (any HybridViewSpec)?
11
+ var gestureRecognizers: [any HybridGestureRecognizerSpec] = []
12
+
13
+ var spacing: Double = 0 {
14
+ didSet { view.spacing = CGFloat(spacing) }
15
+ }
16
+
17
+ override init() throws {
18
+ try super.init()
19
+ view.updateEffect()
20
+ }
21
+
22
+ // Descendant NSGlassEffectViews merge when placed inside NSGlassEffectContainerView.contentView.
23
+ func appendChild(child: any HybridViewSpec) throws {
24
+ view.contentHost.addSubview(child.view)
25
+ child.parentReference = self
26
+ }
27
+
28
+ func insertBefore(child: any HybridViewSpec, beforeChild: any HybridViewSpec) throws {
29
+ if child === beforeChild {
30
+ return
31
+ }
32
+ view.contentHost.addSubview(child.view, positioned: .below, relativeTo: beforeChild.view)
33
+ child.parentReference = self
34
+ }
35
+
36
+ func removeChild(child: any HybridViewSpec) throws {
37
+ child.view.removeFromSuperview()
38
+ child.parentReference = nil
39
+ }
40
+ }
@@ -0,0 +1,80 @@
1
+ internal import AppKit
2
+ internal import NitroModules
3
+ internal import NitroUIRenderer
4
+
5
+ final class HybridNativeLiquidGlassView: HybridNativeLiquidGlassViewSpec {
6
+ typealias AllowedChildrenType = any View
7
+
8
+ let view = LiquidGlassHostView(frame: .zero)
9
+ let layoutNode = LayoutNode()
10
+ var parentReference: (any HybridViewSpec)?
11
+ var gestureRecognizers: [any HybridGestureRecognizerSpec] = []
12
+
13
+ override init() throws {
14
+ try super.init()
15
+ view.updateEffect()
16
+ }
17
+
18
+ var effect: LiquidGlassEffect = .regular {
19
+ didSet {
20
+ view.glassEffect = effect
21
+ view.updateEffect()
22
+ }
23
+ }
24
+
25
+ var interactive = false {
26
+ didSet {
27
+ view.isInteractive = interactive
28
+ view.updateEffect()
29
+ }
30
+ }
31
+
32
+ var tintColor: Double? {
33
+ didSet {
34
+ view.glassTintColor = tintColor.map { NSColor(rgba: UInt32($0)) }
35
+ view.updateEffect()
36
+ }
37
+ }
38
+
39
+ var colorScheme: LiquidGlassColorScheme = .system {
40
+ didSet {
41
+ view.applyColorScheme(colorScheme)
42
+ }
43
+ }
44
+
45
+ var animated = true {
46
+ didSet { view.animatesChanges = animated }
47
+ }
48
+
49
+ var animationDuration: Double? {
50
+ didSet { view.animationDuration = animationDuration }
51
+ }
52
+
53
+ var cornerRadius: Double {
54
+ get { Double(view.glassCornerRadius) }
55
+ set {
56
+ view.glassCornerRadius = CGFloat(newValue)
57
+ view.layer?.cornerRadius = CGFloat(newValue)
58
+ view.updateEffect()
59
+ }
60
+ }
61
+
62
+ // Embed children inside the flipped contentHost managed by NSGlassEffectView.contentView.
63
+ func appendChild(child: any HybridViewSpec) throws {
64
+ view.contentHost.addSubview(child.view)
65
+ child.parentReference = self
66
+ }
67
+
68
+ func insertBefore(child: any HybridViewSpec, beforeChild: any HybridViewSpec) throws {
69
+ if child === beforeChild {
70
+ return
71
+ }
72
+ view.contentHost.addSubview(child.view, positioned: .below, relativeTo: beforeChild.view)
73
+ child.parentReference = self
74
+ }
75
+
76
+ func removeChild(child: any HybridViewSpec) throws {
77
+ child.view.removeFromSuperview()
78
+ child.parentReference = nil
79
+ }
80
+ }
@@ -0,0 +1,181 @@
1
+ internal import AppKit
2
+ internal import NitroUIRenderer
3
+ internal import QuartzCore
4
+
5
+ final class LiquidGlassHostView: FlippedView {
6
+ let contentHost = FlippedView(frame: .zero)
7
+ private var glassViewStorage: NSView?
8
+
9
+ var glassEffect: LiquidGlassEffect = .regular
10
+ var isInteractive = false
11
+ var glassTintColor: NSColor?
12
+ var glassCornerRadius: CGFloat = 0
13
+ var animatesChanges = true
14
+ var animationDuration: TimeInterval?
15
+
16
+ override init(frame frameRect: NSRect) {
17
+ super.init(frame: frameRect)
18
+ contentHost.autoresizingMask = [.width, .height]
19
+ contentHost.frame = bounds
20
+ addSubview(contentHost)
21
+ }
22
+
23
+ override func setFrameSize(_ newSize: NSSize) {
24
+ super.setFrameSize(newSize)
25
+ syncChildFrames()
26
+ }
27
+
28
+ override func layout() {
29
+ super.layout()
30
+ syncChildFrames()
31
+ }
32
+
33
+ private func syncChildFrames() {
34
+ if let glassView = glassViewStorage {
35
+ if glassView.frame != bounds {
36
+ glassView.frame = bounds
37
+ }
38
+ if contentHost.frame != glassView.bounds {
39
+ contentHost.frame = glassView.bounds
40
+ }
41
+ } else if contentHost.frame != bounds {
42
+ contentHost.frame = bounds
43
+ }
44
+ }
45
+
46
+ func updateEffect() {
47
+ let reduceMotion = NSWorkspace.shared.accessibilityDisplayShouldReduceMotion
48
+ let shouldAnimate = animatesChanges && !reduceMotion
49
+
50
+ if LiquidGlassSupport.isSupported, glassEffect != .none, #available(macOS 26.0, *) {
51
+ let glassView: NSGlassEffectView
52
+ let newlyCreated: Bool
53
+ if let existing = glassViewStorage as? NSGlassEffectView {
54
+ glassView = existing
55
+ newlyCreated = false
56
+ } else {
57
+ let created = NSGlassEffectView(frame: bounds)
58
+ created.autoresizingMask = [.width, .height]
59
+ glassViewStorage = created
60
+ glassView = created
61
+ newlyCreated = true
62
+ }
63
+
64
+ if glassView.superview !== self {
65
+ addSubview(glassView)
66
+ }
67
+ glassView.frame = bounds
68
+
69
+ if glassView.contentView !== contentHost {
70
+ contentHost.removeFromSuperview()
71
+ contentHost.frame = glassView.bounds
72
+ glassView.contentView = contentHost
73
+ }
74
+
75
+ let style: NSGlassEffectView.Style = glassEffect == .clear ? .clear : .regular
76
+ let applyProperties = {
77
+ glassView.style = style
78
+ glassView.tintColor = self.glassTintColor
79
+ glassView.cornerRadius = self.glassCornerRadius
80
+ if #available(macOS 27.0, *) {
81
+ glassView.effectIsInteractive = self.isInteractive
82
+ }
83
+ }
84
+
85
+ if shouldAnimate && !newlyCreated {
86
+ NSAnimationContext.runAnimationGroup { context in
87
+ context.duration = animationDuration ?? 0.25
88
+ context.allowsImplicitAnimation = true
89
+ applyProperties()
90
+ }
91
+ } else {
92
+ applyProperties()
93
+ }
94
+ return
95
+ }
96
+
97
+ // Fallback plain view on macOS < 26, compatibility mode, or `effect === 'none'`.
98
+ if #available(macOS 26.0, *), let glassView = glassViewStorage as? NSGlassEffectView {
99
+ if glassView.contentView === contentHost {
100
+ glassView.contentView = nil
101
+ }
102
+ glassView.removeFromSuperview()
103
+ glassViewStorage = nil
104
+ }
105
+ if contentHost.superview !== self {
106
+ contentHost.removeFromSuperview()
107
+ contentHost.frame = bounds
108
+ addSubview(contentHost)
109
+ }
110
+ layer?.cornerRadius = glassCornerRadius
111
+ }
112
+
113
+ func applyColorScheme(_ scheme: LiquidGlassColorScheme) {
114
+ switch scheme {
115
+ case .light:
116
+ appearance = NSAppearance(named: .aqua)
117
+ case .dark:
118
+ appearance = NSAppearance(named: .darkAqua)
119
+ case .system:
120
+ appearance = nil
121
+ }
122
+ }
123
+ }
124
+
125
+ final class LiquidGlassContainerHostView: FlippedView {
126
+ let contentHost = FlippedView(frame: .zero)
127
+ private var containerStorage: NSView?
128
+
129
+ var spacing: CGFloat = 0 {
130
+ didSet {
131
+ updateEffect()
132
+ }
133
+ }
134
+
135
+ override init(frame frameRect: NSRect) {
136
+ super.init(frame: frameRect)
137
+ contentHost.autoresizingMask = [.width, .height]
138
+ contentHost.frame = bounds
139
+ if LiquidGlassSupport.isSupported, #available(macOS 26.0, *) {
140
+ let container = NSGlassEffectContainerView(frame: bounds)
141
+ container.autoresizingMask = [.width, .height]
142
+ container.contentView = contentHost
143
+ addSubview(container)
144
+ containerStorage = container
145
+ } else {
146
+ addSubview(contentHost)
147
+ }
148
+ }
149
+
150
+ override func setFrameSize(_ newSize: NSSize) {
151
+ super.setFrameSize(newSize)
152
+ syncChildFrames()
153
+ }
154
+
155
+ override func layout() {
156
+ super.layout()
157
+ syncChildFrames()
158
+ }
159
+
160
+ private func syncChildFrames() {
161
+ if let container = containerStorage {
162
+ if container.frame != bounds {
163
+ container.frame = bounds
164
+ }
165
+ if contentHost.frame != container.bounds {
166
+ contentHost.frame = container.bounds
167
+ }
168
+ } else if contentHost.frame != bounds {
169
+ contentHost.frame = bounds
170
+ }
171
+ }
172
+
173
+ func updateEffect() {
174
+ guard LiquidGlassSupport.isSupported, #available(macOS 26.0, *) else {
175
+ return
176
+ }
177
+ if let container = containerStorage as? NSGlassEffectContainerView {
178
+ container.spacing = spacing
179
+ }
180
+ }
181
+ }
@@ -0,0 +1,17 @@
1
+ internal import AppKit
2
+
3
+ enum LiquidGlassSupport {
4
+ static let isSupported: Bool = {
5
+ guard #available(macOS 26.0, *) else {
6
+ return false
7
+ }
8
+ // NitroUI apps build with the macOS 27 SDK, so macOS 27 ignores UIDesignRequiresCompatibility.
9
+ if #available(macOS 27.0, *) {
10
+ return true
11
+ }
12
+ // An absent key means the app uses the new design.
13
+ let requiresCompatibility =
14
+ Bundle.main.object(forInfoDictionaryKey: "UIDesignRequiresCompatibility") as? Bool ?? false
15
+ return !requiresCompatibility
16
+ }()
17
+ }
@@ -0,0 +1,105 @@
1
+ // swift-tools-version: 6.4
2
+
3
+ import Foundation
4
+ import PackageDescription
5
+
6
+ let name = "NitroUINavigation"
7
+ let generated = "nitrogen/generated"
8
+ let nitroDependencies: [Target.Dependency] = [
9
+ .product(name: "NitroModules", package: "nitro-core"),
10
+ .product(name: "NitroUIRenderer", package: "nitro-ui-renderer"),
11
+ ]
12
+ let cxxSettings: [CXXSetting] = [
13
+ .define("DEBUG", .when(configuration: .debug)),
14
+ .define("NDEBUG", .when(configuration: .release)),
15
+ .disableWarning("nullability-extension"),
16
+ ]
17
+ let swiftSources = [
18
+ "Sources/NitroUINavigationMac",
19
+ "\(generated)/apple/swift",
20
+ ]
21
+ let bridgeSources = [
22
+ "c++", "NitroUINavigation-Swift-Cxx-Bridge.cpp", "NitroUINavigationAutolinking.cpp",
23
+ ]
24
+
25
+ let package = Package(
26
+ name: name,
27
+ platforms: [.macOS(.v13)],
28
+ products: [
29
+ .library(name: name, targets: ["\(name)Cxx", name, "\(name)SwiftBridge"])
30
+ ],
31
+ dependencies: [
32
+ .package(path: "../nitro-core"),
33
+ .package(path: "../nitro-ui-renderer"),
34
+ ],
35
+ targets: [
36
+ .target(
37
+ name: "\(name)Cxx",
38
+ dependencies: nitroDependencies,
39
+ path: "\(generated)/shared/c++",
40
+ exclude: ["include"],
41
+ publicHeadersPath: "include",
42
+ cxxSettings: cxxSettings
43
+ ),
44
+ .target(
45
+ name: "\(name)AppleCxx",
46
+ dependencies: [.target(name: "\(name)Cxx")] + nitroDependencies,
47
+ path: "\(generated)/apple/\(name)AppleCxx",
48
+ cxxSettings: cxxSettings
49
+ ),
50
+ .target(
51
+ name: name,
52
+ dependencies: [.target(name: "\(name)AppleCxx")] + nitroDependencies,
53
+ path: ".",
54
+ exclude: excludes(in: ".", keeping: swiftSources),
55
+ sources: swiftSources,
56
+ cxxSettings: cxxSettings,
57
+ swiftSettings: [
58
+ .swiftLanguageMode(.v5),
59
+ .unsafeFlags(["-strict-concurrency=minimal"]),
60
+ .enableUpcomingFeature("InternalImportsByDefault"),
61
+ .enableUpcomingFeature("MemberImportVisibility"),
62
+ .interoperabilityMode(.Cxx),
63
+ .unsafeFlags(["-Xfrontend", "-clang-header-expose-decls=has-expose-attr-or-stdlib"]),
64
+ .unsafeFlags([
65
+ "-Xfrontend", "-clang-header-expose-module",
66
+ "-Xfrontend", "NitroModules=NitroModules-Swift.h",
67
+ ]),
68
+ ]
69
+ ),
70
+ .target(
71
+ name: "\(name)SwiftBridge",
72
+ dependencies: [.target(name: name), .target(name: "\(name)AppleCxx")] + nitroDependencies,
73
+ path: "\(generated)/apple",
74
+ exclude: excludes(in: "\(generated)/apple", keeping: bridgeSources) + ["c++/include"],
75
+ sources: bridgeSources,
76
+ publicHeadersPath: "c++/include",
77
+ cxxSettings: cxxSettings + [
78
+ .unsafeFlags(["-I${GENERATED_MODULEMAP_DIR}", "-fno-modules"])
79
+ ]
80
+ ),
81
+ ],
82
+ cxxLanguageStandard: .cxx20
83
+ )
84
+
85
+ func excludes(in path: String, keeping sources: [String]) -> [String] {
86
+ var parents: Set<String> = [""]
87
+ for source in sources {
88
+ var components = source.split(separator: "/").dropLast()
89
+ while !components.isEmpty {
90
+ parents.insert(components.joined(separator: "/"))
91
+ components = components.dropLast()
92
+ }
93
+ }
94
+ let root = URL(fileURLWithPath: Context.packageDirectory).appendingPathComponent(path)
95
+ return parents.sorted().flatMap { parent in
96
+ let entries =
97
+ (try? FileManager.default.contentsOfDirectory(
98
+ atPath: root.appendingPathComponent(parent).path)) ?? []
99
+ return entries.sorted().compactMap { entry in
100
+ let entryPath = parent.isEmpty ? entry : "\(parent)/\(entry)"
101
+ return entry.hasPrefix(".") || sources.contains(entryPath) || parents.contains(entryPath)
102
+ ? nil : entryPath
103
+ }
104
+ }
105
+ }