@lattices/cli 0.4.14 → 0.5.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 (180) hide show
  1. package/README.md +5 -7
  2. package/apps/mac/Info.plist +2 -2
  3. package/apps/mac/Lattices.app/Contents/Info.plist +4 -12
  4. package/apps/mac/Lattices.app/Contents/MacOS/Lattices +0 -0
  5. package/bin/lattices-app.ts +110 -17
  6. package/bin/lattices-build +125 -0
  7. package/bin/lattices-dev +89 -16
  8. package/bin/lattices.ts +977 -16
  9. package/docs/agents.md +81 -4
  10. package/docs/ai-chat-ux-review.md +416 -0
  11. package/docs/api.md +135 -3
  12. package/docs/app.md +30 -8
  13. package/docs/config.md +4 -0
  14. package/docs/mouse-gestures.md +60 -1
  15. package/docs/proposals/LAT-004-interactive-overlay-actors.md +1 -1
  16. package/docs/proposals/LAT-005-action-runtime-product-spine.md +914 -0
  17. package/docs/proposals/LAT-006-mira-in-lattices.md +553 -0
  18. package/docs/reference/dewey.config.ts +2 -2
  19. package/docs/release.md +171 -0
  20. package/docs/repo-structure.md +4 -5
  21. package/docs/voice.md +11 -27
  22. package/package.json +9 -10
  23. package/apps/mac/Package.swift +0 -27
  24. package/apps/mac/Sources/AppShell/App.swift +0 -26
  25. package/apps/mac/Sources/AppShell/AppActivationCoordinator.swift +0 -27
  26. package/apps/mac/Sources/AppShell/AppDelegate.swift +0 -189
  27. package/apps/mac/Sources/AppShell/AppServicesBootstrap.swift +0 -25
  28. package/apps/mac/Sources/AppShell/AppShellView.swift +0 -171
  29. package/apps/mac/Sources/AppShell/AppUpdater.swift +0 -305
  30. package/apps/mac/Sources/AppShell/CliActionLauncher.swift +0 -50
  31. package/apps/mac/Sources/AppShell/HomeDashboardView.swift +0 -133
  32. package/apps/mac/Sources/AppShell/HotkeyBootstrap.swift +0 -87
  33. package/apps/mac/Sources/AppShell/KeyRecorderView.swift +0 -210
  34. package/apps/mac/Sources/AppShell/LatticesRuntime.swift +0 -104
  35. package/apps/mac/Sources/AppShell/MainView.swift +0 -847
  36. package/apps/mac/Sources/AppShell/MainWindow.swift +0 -83
  37. package/apps/mac/Sources/AppShell/MenuBarController.swift +0 -177
  38. package/apps/mac/Sources/AppShell/OnboardingView.swift +0 -483
  39. package/apps/mac/Sources/AppShell/PermissionsAssistantView.swift +0 -366
  40. package/apps/mac/Sources/AppShell/PermissionsAssistantWindow.swift +0 -70
  41. package/apps/mac/Sources/AppShell/Preferences.swift +0 -297
  42. package/apps/mac/Sources/AppShell/SettingsView.swift +0 -3163
  43. package/apps/mac/Sources/AppShell/SettingsWindow.swift +0 -34
  44. package/apps/mac/Sources/AppShell/WorkspaceInspectorPresenter.swift +0 -13
  45. package/apps/mac/Sources/Core/Actions/HotkeyManager.swift +0 -256
  46. package/apps/mac/Sources/Core/Actions/HotkeyStore.swift +0 -399
  47. package/apps/mac/Sources/Core/Actions/IntentEngine.swift +0 -988
  48. package/apps/mac/Sources/Core/Actions/IntentSchema.swift +0 -94
  49. package/apps/mac/Sources/Core/Actions/Intents/CreateLayerIntent.swift +0 -54
  50. package/apps/mac/Sources/Core/Actions/Intents/DistributeIntent.swift +0 -56
  51. package/apps/mac/Sources/Core/Actions/Intents/FocusIntent.swift +0 -69
  52. package/apps/mac/Sources/Core/Actions/Intents/HelpIntent.swift +0 -41
  53. package/apps/mac/Sources/Core/Actions/Intents/KillIntent.swift +0 -47
  54. package/apps/mac/Sources/Core/Actions/Intents/LatticeIntent.swift +0 -53
  55. package/apps/mac/Sources/Core/Actions/Intents/LaunchIntent.swift +0 -67
  56. package/apps/mac/Sources/Core/Actions/Intents/ListSessionsIntent.swift +0 -32
  57. package/apps/mac/Sources/Core/Actions/Intents/ListWindowsIntent.swift +0 -30
  58. package/apps/mac/Sources/Core/Actions/Intents/ScanIntent.swift +0 -52
  59. package/apps/mac/Sources/Core/Actions/Intents/SearchIntent.swift +0 -190
  60. package/apps/mac/Sources/Core/Actions/Intents/SwitchLayerIntent.swift +0 -50
  61. package/apps/mac/Sources/Core/Actions/Intents/TileIntent.swift +0 -61
  62. package/apps/mac/Sources/Core/Actions/PaletteCommand.swift +0 -439
  63. package/apps/mac/Sources/Core/Actions/VoiceIntentResolver.swift +0 -713
  64. package/apps/mac/Sources/Core/Companion/CompanionActivityLog.swift +0 -70
  65. package/apps/mac/Sources/Core/Companion/CompanionKeyboardController.swift +0 -141
  66. package/apps/mac/Sources/Core/Companion/LatticesCompanionBridgeServer.swift +0 -454
  67. package/apps/mac/Sources/Core/Companion/LatticesCompanionCockpit.swift +0 -555
  68. package/apps/mac/Sources/Core/Companion/LatticesCompanionSecurityCoordinator.swift +0 -629
  69. package/apps/mac/Sources/Core/Companion/LatticesCompanionTrackpadController.swift +0 -204
  70. package/apps/mac/Sources/Core/Companion/LatticesDeckHost.swift +0 -1463
  71. package/apps/mac/Sources/Core/Daemon/DaemonProtocol.swift +0 -114
  72. package/apps/mac/Sources/Core/Daemon/DaemonServer.swift +0 -427
  73. package/apps/mac/Sources/Core/Daemon/LatticesApi.swift +0 -2965
  74. package/apps/mac/Sources/Core/Desktop/AccessibilityTextExtractor.swift +0 -111
  75. package/apps/mac/Sources/Core/Desktop/AppTypeClassifier.swift +0 -106
  76. package/apps/mac/Sources/Core/Desktop/DesktopModel.swift +0 -331
  77. package/apps/mac/Sources/Core/Desktop/DesktopModelTypes.swift +0 -73
  78. package/apps/mac/Sources/Core/Desktop/InventoryManager.swift +0 -35
  79. package/apps/mac/Sources/Core/Desktop/InventoryPath.swift +0 -43
  80. package/apps/mac/Sources/Core/Desktop/MouseFinder.swift +0 -527
  81. package/apps/mac/Sources/Core/Desktop/OcrModel.swift +0 -467
  82. package/apps/mac/Sources/Core/Desktop/OcrStore.swift +0 -329
  83. package/apps/mac/Sources/Core/Desktop/PlacementSpec.swift +0 -195
  84. package/apps/mac/Sources/Core/Desktop/SessionWindowLocator.swift +0 -139
  85. package/apps/mac/Sources/Core/Desktop/TilePickerView.swift +0 -209
  86. package/apps/mac/Sources/Core/Desktop/WindowCapture.swift +0 -33
  87. package/apps/mac/Sources/Core/Desktop/WindowDragSnapController.swift +0 -429
  88. package/apps/mac/Sources/Core/Desktop/WindowPreviewCard.swift +0 -100
  89. package/apps/mac/Sources/Core/Desktop/WindowPreviewStore.swift +0 -112
  90. package/apps/mac/Sources/Core/Desktop/WindowSelectionStore.swift +0 -76
  91. package/apps/mac/Sources/Core/Desktop/WindowTiler.swift +0 -2222
  92. package/apps/mac/Sources/Core/Input/EventTapBreaker.swift +0 -124
  93. package/apps/mac/Sources/Core/Input/EventTapThread.swift +0 -54
  94. package/apps/mac/Sources/Core/Input/InputCaptureResetCenter.swift +0 -20
  95. package/apps/mac/Sources/Core/Input/KeyboardRemapConfig.swift +0 -69
  96. package/apps/mac/Sources/Core/Input/KeyboardRemapController.swift +0 -346
  97. package/apps/mac/Sources/Core/Input/KeyboardRemapStore.swift +0 -141
  98. package/apps/mac/Sources/Core/Input/MouseGestureConfig.swift +0 -499
  99. package/apps/mac/Sources/Core/Input/MouseGestureController.swift +0 -2583
  100. package/apps/mac/Sources/Core/Input/MouseInputDeviceStore.swift +0 -98
  101. package/apps/mac/Sources/Core/Input/MouseInputEventViewer.swift +0 -272
  102. package/apps/mac/Sources/Core/Input/MouseShortcutStore.swift +0 -170
  103. package/apps/mac/Sources/Core/Input/SecureEventInputMonitor.swift +0 -39
  104. package/apps/mac/Sources/Core/Input/ShapeRecognizer.swift +0 -624
  105. package/apps/mac/Sources/Core/Input/TapBudgetMeter.swift +0 -56
  106. package/apps/mac/Sources/Core/Overlays/AppWindowShell.swift +0 -63
  107. package/apps/mac/Sources/Core/Overlays/CommandMode/CommandModeState.swift +0 -1566
  108. package/apps/mac/Sources/Core/Overlays/CommandMode/CommandModeView.swift +0 -1927
  109. package/apps/mac/Sources/Core/Overlays/CommandMode/CommandModeWindow.swift +0 -196
  110. package/apps/mac/Sources/Core/Overlays/CommandPalette/CommandPaletteView.swift +0 -307
  111. package/apps/mac/Sources/Core/Overlays/CommandPalette/CommandPaletteWindow.swift +0 -67
  112. package/apps/mac/Sources/Core/Overlays/HUD/CheatSheetHUD.swift +0 -576
  113. package/apps/mac/Sources/Core/Overlays/HUD/HUDBottomBar.swift +0 -279
  114. package/apps/mac/Sources/Core/Overlays/HUD/HUDController.swift +0 -1158
  115. package/apps/mac/Sources/Core/Overlays/HUD/HUDLeftBar.swift +0 -849
  116. package/apps/mac/Sources/Core/Overlays/HUD/HUDMinimap.swift +0 -179
  117. package/apps/mac/Sources/Core/Overlays/HUD/HUDRightBar.swift +0 -596
  118. package/apps/mac/Sources/Core/Overlays/HUD/HUDState.swift +0 -367
  119. package/apps/mac/Sources/Core/Overlays/HUD/HUDTopBar.swift +0 -243
  120. package/apps/mac/Sources/Core/Overlays/HUD/LauncherHUD.swift +0 -334
  121. package/apps/mac/Sources/Core/Overlays/HUD/LayerBezel.swift +0 -203
  122. package/apps/mac/Sources/Core/Overlays/OmniSearch/OmniSearchState.swift +0 -280
  123. package/apps/mac/Sources/Core/Overlays/OmniSearch/OmniSearchView.swift +0 -422
  124. package/apps/mac/Sources/Core/Overlays/OmniSearch/OmniSearchWindow.swift +0 -94
  125. package/apps/mac/Sources/Core/Overlays/OverlayPanelShell.swift +0 -241
  126. package/apps/mac/Sources/Core/Overlays/ScreenMap/ScreenMapState.swift +0 -3135
  127. package/apps/mac/Sources/Core/Overlays/ScreenMap/ScreenMapView.swift +0 -3977
  128. package/apps/mac/Sources/Core/Overlays/ScreenMap/ScreenMapWindowController.swift +0 -119
  129. package/apps/mac/Sources/Core/Overlays/ScreenOverlayCanvasController.swift +0 -1217
  130. package/apps/mac/Sources/Core/Overlays/Voice/VoiceCommandWindow.swift +0 -1575
  131. package/apps/mac/Sources/Core/Pi/PiAuthNextStepCard.swift +0 -148
  132. package/apps/mac/Sources/Core/Pi/PiAuthPromptCard.swift +0 -90
  133. package/apps/mac/Sources/Core/Pi/PiChatDock.swift +0 -564
  134. package/apps/mac/Sources/Core/Pi/PiChatSession.swift +0 -1948
  135. package/apps/mac/Sources/Core/Pi/PiInstallCallout.swift +0 -86
  136. package/apps/mac/Sources/Core/Pi/PiProviderSetupCallout.swift +0 -99
  137. package/apps/mac/Sources/Core/Pi/PiWorkspaceView.swift +0 -510
  138. package/apps/mac/Sources/Core/System/Capability.swift +0 -79
  139. package/apps/mac/Sources/Core/System/DiagnosticLog.swift +0 -373
  140. package/apps/mac/Sources/Core/System/EventBus.swift +0 -31
  141. package/apps/mac/Sources/Core/System/PermissionChecker.swift +0 -224
  142. package/apps/mac/Sources/Core/System/ProcessModel.swift +0 -199
  143. package/apps/mac/Sources/Core/System/ProcessQuery.swift +0 -151
  144. package/apps/mac/Sources/Core/System/SystemTelemetryMonitor.swift +0 -273
  145. package/apps/mac/Sources/Core/Voice/AdvisorLearningStore.swift +0 -90
  146. package/apps/mac/Sources/Core/Voice/AgentSession.swift +0 -377
  147. package/apps/mac/Sources/Core/Voice/AudioProvider.swift +0 -555
  148. package/apps/mac/Sources/Core/Voice/HandsOffSession.swift +0 -839
  149. package/apps/mac/Sources/Core/Voice/VoiceChatView.swift +0 -192
  150. package/apps/mac/Sources/Core/Voice/VoxClient.swift +0 -454
  151. package/apps/mac/Sources/Core/Workspace/Project.swift +0 -28
  152. package/apps/mac/Sources/Core/Workspace/ProjectScanner.swift +0 -141
  153. package/apps/mac/Sources/Core/Workspace/SessionLayerStore.swift +0 -285
  154. package/apps/mac/Sources/Core/Workspace/SessionManager.swift +0 -75
  155. package/apps/mac/Sources/Core/Workspace/Terminal/Terminal.swift +0 -259
  156. package/apps/mac/Sources/Core/Workspace/Terminal/TerminalQuery.swift +0 -156
  157. package/apps/mac/Sources/Core/Workspace/Terminal/TerminalSynthesizer.swift +0 -200
  158. package/apps/mac/Sources/Core/Workspace/Tmux/TmuxModel.swift +0 -60
  159. package/apps/mac/Sources/Core/Workspace/Tmux/TmuxQuery.swift +0 -105
  160. package/apps/mac/Sources/Core/Workspace/WorkspaceManager.swift +0 -1027
  161. package/apps/mac/Sources/UI/ActionRow.swift +0 -78
  162. package/apps/mac/Sources/UI/OrphanRow.swift +0 -129
  163. package/apps/mac/Sources/UI/ProjectRow.swift +0 -368
  164. package/apps/mac/Sources/UI/TabGroupRow.swift +0 -178
  165. package/apps/mac/Sources/UI/Theme.swift +0 -164
  166. package/apps/mac/Tests/StageDragTests.swift +0 -333
  167. package/apps/mac/Tests/StageJoinTests.swift +0 -313
  168. package/apps/mac/Tests/StageManagerTests.swift +0 -280
  169. package/apps/mac/Tests/StageTileTests.swift +0 -353
  170. package/swift/Package.swift +0 -20
  171. package/swift/Sources/DeckKit/DeckAction.swift +0 -51
  172. package/swift/Sources/DeckKit/DeckBridgeSecurity.swift +0 -152
  173. package/swift/Sources/DeckKit/DeckCockpit.swift +0 -82
  174. package/swift/Sources/DeckKit/DeckHost.swift +0 -7
  175. package/swift/Sources/DeckKit/DeckManifest.swift +0 -145
  176. package/swift/Sources/DeckKit/DeckRuntimeSnapshot.swift +0 -533
  177. package/swift/Sources/DeckKit/DeckTrackpad.swift +0 -63
  178. package/swift/Sources/DeckKit/DeckValue.swift +0 -93
  179. package/swift/Sources/DeckKit/DeckVoiceError.swift +0 -88
  180. package/swift/Tests/DeckKitTests/DeckKitTests.swift +0 -286
@@ -1,94 +0,0 @@
1
- import AppKit
2
- import SwiftUI
3
-
4
- final class OmniSearchWindow {
5
- static let shared = OmniSearchWindow()
6
-
7
- private var panel: NSPanel?
8
- private var keyMonitor: Any?
9
- private var state: OmniSearchState?
10
-
11
- var isVisible: Bool { panel?.isVisible ?? false }
12
-
13
- func toggle() {
14
- if isVisible {
15
- dismiss()
16
- } else {
17
- show()
18
- }
19
- }
20
-
21
- func show() {
22
- if let p = panel, p.isVisible {
23
- p.makeKeyAndOrderFront(nil)
24
- NSApp.activate(ignoringOtherApps: true)
25
- return
26
- }
27
-
28
- // Fresh state each time
29
- let searchState = OmniSearchState()
30
- state = searchState
31
-
32
- let view = OmniSearchView(state: searchState) { [weak self] in
33
- self?.dismiss()
34
- }
35
- .preferredColorScheme(.dark)
36
-
37
- let p = OverlayPanelShell.makePanel(
38
- config: .init(
39
- size: NSSize(width: 520, height: 480),
40
- styleMask: [.titled, .closable, .resizable, .utilityWindow, .nonactivatingPanel],
41
- title: "Search",
42
- titleVisible: .hidden,
43
- titlebarAppearsTransparent: true,
44
- background: .material(.popover),
45
- cornerRadius: 14,
46
- hidesOnDeactivate: false,
47
- isMovableByWindowBackground: true,
48
- minSize: NSSize(width: 400, height: 300),
49
- maxSize: NSSize(width: 700, height: 700),
50
- activatesOnMouseDown: true,
51
- appearance: NSAppearance(named: .darkAqua)
52
- ),
53
- rootView: view
54
- )
55
- p.hidesOnDeactivate = false
56
- p.becomesKeyOnlyIfNeeded = false
57
- OverlayPanelShell.position(p, placement: .centered(yOffsetRatio: 0.125))
58
- OverlayPanelShell.present(p)
59
- panel = p
60
-
61
- // Key monitor: Escape → dismiss, arrow keys → navigate, Enter → activate
62
- keyMonitor = NSEvent.addLocalMonitorForEvents(matching: .keyDown) { [weak self] event in
63
- guard self?.panel?.isKeyWindow == true else { return event }
64
-
65
- switch event.keyCode {
66
- case 53: // Escape
67
- self?.dismiss()
68
- return nil
69
- case 125: // ↓
70
- self?.state?.moveSelection(1)
71
- return nil
72
- case 126: // ↑
73
- self?.state?.moveSelection(-1)
74
- return nil
75
- case 36: // Enter
76
- self?.state?.activateSelected()
77
- self?.dismiss()
78
- return nil
79
- default:
80
- return event
81
- }
82
- }
83
- }
84
-
85
- func dismiss() {
86
- panel?.orderOut(nil)
87
- panel = nil
88
- state = nil
89
- if let monitor = keyMonitor {
90
- NSEvent.removeMonitor(monitor)
91
- keyMonitor = nil
92
- }
93
- }
94
- }
@@ -1,241 +0,0 @@
1
- import AppKit
2
- import SwiftUI
3
-
4
- final class OverlayPanel: NSPanel {
5
- var activatesOnMouseDown = false
6
- var onKeyDown: ((NSEvent) -> Void)?
7
- var onFlagsChanged: ((NSEvent) -> Void)?
8
-
9
- override var canBecomeKey: Bool { true }
10
- override var canBecomeMain: Bool { true }
11
-
12
- override func sendEvent(_ event: NSEvent) {
13
- if activatesOnMouseDown,
14
- event.type == .leftMouseDown || event.type == .rightMouseDown {
15
- if !NSApp.isActive {
16
- NSApp.activate(ignoringOtherApps: true)
17
- }
18
- if !isKeyWindow {
19
- makeKey()
20
- }
21
- }
22
- super.sendEvent(event)
23
- }
24
-
25
- override func keyDown(with event: NSEvent) {
26
- if let onKeyDown {
27
- onKeyDown(event)
28
- } else {
29
- super.keyDown(with: event)
30
- }
31
- }
32
-
33
- override func flagsChanged(with event: NSEvent) {
34
- if let onFlagsChanged {
35
- onFlagsChanged(event)
36
- } else {
37
- super.flagsChanged(with: event)
38
- }
39
- }
40
- }
41
-
42
- private final class OverlayHostingView<Content: View>: NSHostingView<Content> {
43
- override func acceptsFirstMouse(for event: NSEvent?) -> Bool { true }
44
- override var focusRingType: NSFocusRingType { get { .none } set {} }
45
- }
46
-
47
- struct OverlayPanelShell {
48
- enum Background {
49
- case clear
50
- case solid(NSColor)
51
- case material(NSVisualEffectView.Material)
52
- }
53
-
54
- enum Placement {
55
- case centered(yOffsetRatio: CGFloat = 0)
56
- case mouseScreenCentered(yOffsetRatio: CGFloat = 0)
57
- case topCenter(margin: CGFloat = 40)
58
- }
59
-
60
- struct Config {
61
- var size: NSSize
62
- var styleMask: NSWindow.StyleMask = [.nonactivatingPanel]
63
- var title: String = ""
64
- var titleVisible: NSWindow.TitleVisibility = .hidden
65
- var titlebarAppearsTransparent = false
66
- var background: Background = .clear
67
- var cornerRadius: CGFloat? = nil
68
- var level: NSWindow.Level = .floating
69
- var hasShadow = true
70
- var hidesOnDeactivate = false
71
- var isReleasedWhenClosed = false
72
- var isMovableByWindowBackground = false
73
- var collectionBehavior: NSWindow.CollectionBehavior = [.canJoinAllSpaces, .fullScreenAuxiliary]
74
- var minSize: NSSize? = nil
75
- var maxSize: NSSize? = nil
76
- var activatesOnMouseDown = false
77
- var onKeyDown: ((NSEvent) -> Void)? = nil
78
- var onFlagsChanged: ((NSEvent) -> Void)? = nil
79
- var appearance: NSAppearance? = NSAppearance(named: .darkAqua)
80
- }
81
-
82
- static func makePanel<Content: View>(config: Config, rootView: Content) -> OverlayPanel {
83
- let hosting = OverlayHostingView(rootView: rootView)
84
- hosting.translatesAutoresizingMaskIntoConstraints = false
85
-
86
- let panel = OverlayPanel(
87
- contentRect: NSRect(origin: .zero, size: config.size),
88
- styleMask: config.styleMask,
89
- backing: .buffered,
90
- defer: false
91
- )
92
- panel.title = config.title
93
- panel.titleVisibility = config.titleVisible
94
- panel.titlebarAppearsTransparent = config.titlebarAppearsTransparent
95
- panel.isOpaque = false
96
- panel.backgroundColor = backgroundColor(for: config.background)
97
- panel.level = config.level
98
- panel.hasShadow = config.hasShadow
99
- panel.hidesOnDeactivate = config.hidesOnDeactivate
100
- panel.isReleasedWhenClosed = config.isReleasedWhenClosed
101
- panel.isMovableByWindowBackground = config.isMovableByWindowBackground
102
- panel.collectionBehavior = config.collectionBehavior
103
- panel.activatesOnMouseDown = config.activatesOnMouseDown
104
- panel.onKeyDown = config.onKeyDown
105
- panel.onFlagsChanged = config.onFlagsChanged
106
- if let minSize = config.minSize {
107
- panel.minSize = minSize
108
- }
109
- if let maxSize = config.maxSize {
110
- panel.maxSize = maxSize
111
- }
112
- if let appearance = config.appearance {
113
- panel.appearance = appearance
114
- }
115
-
116
- install(hosting: hosting, on: panel, background: config.background, cornerRadius: config.cornerRadius)
117
- return panel
118
- }
119
-
120
- static func position(_ window: NSWindow, placement: Placement) {
121
- let screen: NSScreen
122
- switch placement {
123
- case .mouseScreenCentered, .topCenter:
124
- screen = mouseScreen()
125
- case .centered:
126
- screen = NSScreen.main ?? mouseScreen()
127
- }
128
-
129
- let visibleFrame = screen.visibleFrame
130
- let size = window.frame.size
131
- let origin: NSPoint
132
-
133
- switch placement {
134
- case .centered(let yOffsetRatio), .mouseScreenCentered(let yOffsetRatio):
135
- origin = NSPoint(
136
- x: visibleFrame.midX - size.width / 2,
137
- y: visibleFrame.midY - size.height / 2 + (visibleFrame.height * yOffsetRatio)
138
- )
139
- case .topCenter(let margin):
140
- origin = NSPoint(
141
- x: visibleFrame.midX - size.width / 2,
142
- y: visibleFrame.maxY - size.height - margin
143
- )
144
- }
145
-
146
- window.setFrameOrigin(origin)
147
- }
148
-
149
- static func present(
150
- _ panel: NSPanel,
151
- activate: Bool = true,
152
- makeKey: Bool = true,
153
- orderFrontRegardless: Bool = false
154
- ) {
155
- if orderFrontRegardless {
156
- panel.orderFrontRegardless()
157
- } else if makeKey {
158
- panel.makeKeyAndOrderFront(nil)
159
- } else {
160
- panel.orderFront(nil)
161
- }
162
-
163
- if makeKey {
164
- panel.makeKey()
165
- }
166
-
167
- if activate {
168
- NSApp.activate(ignoringOtherApps: true)
169
- }
170
- }
171
-
172
- private static func install(
173
- hosting: NSView,
174
- on panel: NSPanel,
175
- background: Background,
176
- cornerRadius: CGFloat?
177
- ) {
178
- switch background {
179
- case .material(let material):
180
- let effectView = NSVisualEffectView()
181
- effectView.blendingMode = .behindWindow
182
- effectView.material = material
183
- effectView.state = .active
184
- effectView.wantsLayer = true
185
- if let cornerRadius {
186
- effectView.maskImage = maskImage(cornerRadius: cornerRadius)
187
- }
188
- panel.contentView = effectView
189
- pin(hosting: hosting, to: effectView)
190
- case .clear, .solid:
191
- panel.contentView = hosting
192
- }
193
- }
194
-
195
- private static func pin(hosting: NSView, to container: NSView) {
196
- container.addSubview(hosting)
197
- NSLayoutConstraint.activate([
198
- hosting.leadingAnchor.constraint(equalTo: container.leadingAnchor),
199
- hosting.trailingAnchor.constraint(equalTo: container.trailingAnchor),
200
- hosting.topAnchor.constraint(equalTo: container.topAnchor),
201
- hosting.bottomAnchor.constraint(equalTo: container.bottomAnchor),
202
- ])
203
- }
204
-
205
- private static func mouseScreen() -> NSScreen {
206
- let mouseLocation = NSEvent.mouseLocation
207
- return NSScreen.screens.first(where: { $0.frame.contains(mouseLocation) })
208
- ?? NSScreen.main
209
- ?? NSScreen.screens.first!
210
- }
211
-
212
- private static func backgroundColor(for background: Background) -> NSColor {
213
- switch background {
214
- case .clear, .material:
215
- return .clear
216
- case .solid(let color):
217
- return color
218
- }
219
- }
220
-
221
- private static func maskImage(cornerRadius: CGFloat) -> NSImage {
222
- let edgeLength = 2.0 * cornerRadius + 1.0
223
- let maskImage = NSImage(
224
- size: NSSize(width: edgeLength, height: edgeLength),
225
- flipped: false
226
- ) { rect in
227
- let path = NSBezierPath(roundedRect: rect, xRadius: cornerRadius, yRadius: cornerRadius)
228
- NSColor.black.set()
229
- path.fill()
230
- return true
231
- }
232
- maskImage.capInsets = NSEdgeInsets(
233
- top: cornerRadius,
234
- left: cornerRadius,
235
- bottom: cornerRadius,
236
- right: cornerRadius
237
- )
238
- maskImage.resizingMode = .stretch
239
- return maskImage
240
- }
241
- }