nitro-ui-macos 0.0.0 → 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 +3 -3
  3. package/PARITY.md +373 -0
  4. package/README.md +144 -5
  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 +57 -8
  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,698 @@
1
+ #if DEBUG
2
+ import AppKit
3
+ import Foundation
4
+
5
+ /// Native AppKit error overlay manager for Debug runtime errors, build errors, and warnings.
6
+ @MainActor
7
+ final class ErrorSheet: NSObject {
8
+ static let shared = ErrorSheet()
9
+
10
+ var serverURL: URL?
11
+ var onReload: (() -> Void)?
12
+
13
+ private var reports: [ErrorReport] = []
14
+ private var buildError: ErrorReport?
15
+ private var selectedIndex = 0
16
+ private var sheetRequested = false
17
+ private var requests: [UUID: Task<Void, Never>] = [:]
18
+ private var windowController: ErrorOverlayWindowController?
19
+ private var warningBanner: WarningBannerController?
20
+
21
+ var isOverlayVisible: Bool { windowController?.window?.isVisible == true }
22
+ var shownReport: ErrorReport? {
23
+ if let buildError { return buildError }
24
+ guard reports.indices.contains(selectedIndex) else { return nil }
25
+ return reports[selectedIndex]
26
+ }
27
+
28
+ private override init() {
29
+ super.init()
30
+ }
31
+
32
+ func show(_ message: String, title: String) {
33
+ ReloadAnimation.shared.hide()
34
+ let id: UUID
35
+ if let existing = reports.firstIndex(where: { $0.message == message && $0.title == title }) {
36
+ reports[existing].occurrences += 1
37
+ selectedIndex = existing
38
+ id = reports[existing].id
39
+ } else {
40
+ let report = ErrorReport(message: message, title: title)
41
+ id = report.id
42
+ reports.append(report)
43
+ selectedIndex = reports.count - 1
44
+ }
45
+
46
+ let isWarning = title.hasSuffix("Warning")
47
+ if isWarning == false {
48
+ sheetRequested = true
49
+ }
50
+ refreshUI()
51
+ symbolicate(id, message)
52
+ }
53
+
54
+ func showLoadError(_ message: String, title: String) {
55
+ show(message, title: title)
56
+ sheetRequested = true
57
+ present()
58
+ }
59
+
60
+ func showBuildError(_ message: String, title: String) {
61
+ ReloadAnimation.shared.hide()
62
+ let report = ErrorReport(message: message, title: title)
63
+ buildError = report
64
+ refreshUI()
65
+ symbolicate(report.id, message) { [weak self] in
66
+ self?.present()
67
+ }
68
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) { [weak self] in
69
+ self?.present()
70
+ }
71
+ }
72
+
73
+ func hideBuildError() {
74
+ guard buildError != nil else { return }
75
+ buildError = nil
76
+ if sheetRequested, reports.isEmpty == false {
77
+ refreshUI()
78
+ present()
79
+ } else {
80
+ dismiss()
81
+ }
82
+ }
83
+
84
+ func hide() {
85
+ requests.values.forEach { $0.cancel() }
86
+ requests.removeAll()
87
+ reports.removeAll()
88
+ buildError = nil
89
+ selectedIndex = 0
90
+ dismiss()
91
+ }
92
+
93
+ func present() {
94
+ updateNotification()
95
+ guard (sheetRequested || buildError != nil), DevSession.shared.isReloading == false else { return }
96
+ guard shownReport != nil else { return }
97
+
98
+ if windowController == nil {
99
+ let controller = ErrorOverlayWindowController(
100
+ onReload: { [weak self] in
101
+ self?.triggerReload()
102
+ },
103
+ onDismiss: { [weak self] in
104
+ self?.dismiss()
105
+ },
106
+ onNavigate: { [weak self] delta in
107
+ self?.navigate(by: delta)
108
+ }
109
+ )
110
+ windowController = controller
111
+ }
112
+ refreshUI()
113
+ windowController?.present(relativeTo: DevTools.hostWindow)
114
+ warningBanner?.hide()
115
+ }
116
+
117
+ func updateNotification() {
118
+ let warningCount = reports.filter(\.isWarning).count
119
+ let errorCount = reports.count - warningCount
120
+ guard Launcher.shared.isVisible == false,
121
+ DevMenu.shared.isVisible == false,
122
+ sheetRequested == false,
123
+ windowController == nil,
124
+ buildError == nil,
125
+ errorCount + warningCount > 0 else {
126
+ warningBanner?.hide()
127
+ return
128
+ }
129
+ if warningBanner == nil {
130
+ warningBanner = WarningBannerController { [weak self] in
131
+ self?.sheetRequested = true
132
+ self?.present()
133
+ }
134
+ }
135
+ warningBanner?.show(errors: errorCount, warnings: warningCount, relativeTo: DevTools.hostWindow)
136
+ }
137
+
138
+ private func triggerReload() {
139
+ if let onReload {
140
+ onReload()
141
+ } else {
142
+ DevSession.shared.triggerReload()
143
+ }
144
+ }
145
+
146
+ private func navigate(by delta: Int) {
147
+ guard buildError == nil, reports.isEmpty == false else { return }
148
+ let next = selectedIndex + delta
149
+ if reports.indices.contains(next) {
150
+ selectedIndex = next
151
+ refreshUI()
152
+ }
153
+ }
154
+
155
+ private func dismiss() {
156
+ sheetRequested = false
157
+ windowController?.close()
158
+ windowController = nil
159
+ updateNotification()
160
+ }
161
+
162
+ private func refreshUI() {
163
+ if let report = shownReport {
164
+ windowController?.render(
165
+ report: report,
166
+ index: buildError != nil ? 0 : selectedIndex,
167
+ total: buildError != nil ? 1 : reports.count,
168
+ isBlockingBuildError: buildError != nil
169
+ )
170
+ }
171
+ if sheetRequested || buildError != nil {
172
+ if windowController == nil, DevSession.shared.isReloading == false {
173
+ present()
174
+ }
175
+ } else {
176
+ updateNotification()
177
+ }
178
+ }
179
+
180
+ private func symbolicate(_ id: UUID, _ message: String, then done: @escaping () -> Void = {}) {
181
+ guard let serverURL else { return done() }
182
+ guard requests[id] == nil else { return }
183
+ requests[id] = Task { [weak self] in
184
+ defer {
185
+ self?.requests[id] = nil
186
+ done()
187
+ }
188
+ do {
189
+ var request = URLRequest(url: serverURL.appendingPathComponent("symbolicate"))
190
+ request.httpMethod = "POST"
191
+ request.httpBody = Data(message.utf8)
192
+ request.setValue("text/plain; charset=utf-8", forHTTPHeaderField: "Content-Type")
193
+ let (data, response) = try await URLSession.shared.data(for: request)
194
+ guard (response as? HTTPURLResponse)?.statusCode == 200, Task.isCancelled == false else { return }
195
+ let result = try JSONDecoder().decode(ErrorSymbolication.self, from: data)
196
+ self?.applySymbolication(id, result: result)
197
+ } catch {
198
+ // Keep the unsymbolicated error visible when the server cannot symbolicate it.
199
+ }
200
+ }
201
+ }
202
+
203
+ private func applySymbolication(_ id: UUID, result: ErrorSymbolication) {
204
+ if buildError?.id == id {
205
+ buildError?.apply(result)
206
+ refreshUI()
207
+ return
208
+ }
209
+ if let idx = reports.firstIndex(where: { $0.id == id }) {
210
+ reports[idx].apply(result)
211
+ refreshUI()
212
+ }
213
+ }
214
+ }
215
+
216
+ /// Native AppKit window rendering an error report with syntax-highlighted source excerpt and clickable stack frames.
217
+ @MainActor
218
+ private final class ErrorOverlayWindowController: NSWindowController, NSWindowDelegate {
219
+ private let badgeLabel = NSTextField(labelWithString: "")
220
+ private let counterLabel = NSTextField(labelWithString: "")
221
+ private let prevButton = NSButton(title: "‹", target: nil, action: nil)
222
+ private let nextButton = NSButton(title: "›", target: nil, action: nil)
223
+ private let contentStack = NSStackView()
224
+ private let dismissButton = NSButton(title: "Dismiss", target: nil, action: nil)
225
+ private let showInternalCheckbox = NSButton(checkboxWithTitle: "Show internal frames", target: nil, action: nil)
226
+
227
+ private let onReload: () -> Void
228
+ private let onDismiss: () -> Void
229
+ private let onNavigate: (Int) -> Void
230
+ private var currentReport: ErrorReport?
231
+ private var currentIndex = 0
232
+ private var currentTotal = 1
233
+ private var isBlocking = false
234
+ private var frameLocations: [String] = []
235
+ private var sourceLocation: String?
236
+
237
+ init(
238
+ onReload: @escaping () -> Void,
239
+ onDismiss: @escaping () -> Void,
240
+ onNavigate: @escaping (Int) -> Void
241
+ ) {
242
+ self.onReload = onReload
243
+ self.onDismiss = onDismiss
244
+ self.onNavigate = onNavigate
245
+
246
+ let panel = NSPanel(
247
+ contentRect: NSRect(x: 0, y: 0, width: 680, height: 520),
248
+ styleMask: [.titled, .closable, .resizable],
249
+ backing: .buffered,
250
+ defer: false
251
+ )
252
+ panel.title = "\(DevTools.appName) — Runtime Error"
253
+ panel.minSize = NSSize(width: 480, height: 340)
254
+ panel.level = .floating
255
+ panel.isReleasedWhenClosed = false
256
+ super.init(window: panel)
257
+ panel.delegate = self
258
+
259
+ buildUI()
260
+ }
261
+
262
+ @available(*, unavailable)
263
+ required init?(coder: NSCoder) {
264
+ fatalError("init(coder:) is not supported")
265
+ }
266
+
267
+ func present(relativeTo hostWindow: NSWindow?) {
268
+ guard let panel = window else { return }
269
+ if panel.isVisible == false {
270
+ if let hostWindow {
271
+ let host = hostWindow.frame
272
+ let size = panel.frame.size
273
+ panel.setFrameOrigin(NSPoint(x: host.midX - size.width / 2, y: host.midY - size.height / 2))
274
+ } else {
275
+ panel.center()
276
+ }
277
+ }
278
+ panel.makeKeyAndOrderFront(nil)
279
+ }
280
+
281
+ func windowShouldClose(_ sender: NSWindow) -> Bool {
282
+ if isBlocking { return false }
283
+ onDismiss()
284
+ return true
285
+ }
286
+
287
+ func render(report: ErrorReport, index: Int, total: Int, isBlockingBuildError: Bool) {
288
+ currentReport = report
289
+ currentIndex = index
290
+ currentTotal = total
291
+ isBlocking = isBlockingBuildError
292
+
293
+ window?.title = "\(DevTools.appName) — \(report.title)"
294
+ let countSuffix = report.occurrences > 1 ? " (×\(report.occurrences))" : ""
295
+ badgeLabel.stringValue = "\(report.title)\(countSuffix)"
296
+ badgeLabel.textColor = report.accentColor
297
+
298
+ let showPager = total > 1
299
+ counterLabel.isHidden = !showPager
300
+ prevButton.isHidden = !showPager
301
+ nextButton.isHidden = !showPager
302
+ counterLabel.stringValue = "\(index + 1) of \(total)"
303
+ prevButton.isEnabled = index > 0
304
+ nextButton.isEnabled = index < total - 1
305
+
306
+ dismissButton.isHidden = isBlockingBuildError
307
+
308
+ rebuildDetails(report)
309
+ }
310
+
311
+ private func buildUI() {
312
+ guard let rootView = window?.contentView else { return }
313
+
314
+ let container = NSView()
315
+ container.translatesAutoresizingMaskIntoConstraints = false
316
+ rootView.addSubview(container)
317
+ NSLayoutConstraint.activate([
318
+ container.topAnchor.constraint(equalTo: rootView.topAnchor),
319
+ container.leadingAnchor.constraint(equalTo: rootView.leadingAnchor),
320
+ container.trailingAnchor.constraint(equalTo: rootView.trailingAnchor),
321
+ container.bottomAnchor.constraint(equalTo: rootView.bottomAnchor),
322
+ ])
323
+
324
+ // Header
325
+ let header = NSVisualEffectView()
326
+ header.material = .headerView
327
+ header.blendingMode = .withinWindow
328
+ header.translatesAutoresizingMaskIntoConstraints = false
329
+ container.addSubview(header)
330
+
331
+ badgeLabel.font = .systemFont(ofSize: 14, weight: .semibold)
332
+ counterLabel.font = .monospacedDigitSystemFont(ofSize: 12, weight: .regular)
333
+ counterLabel.textColor = .secondaryLabelColor
334
+
335
+ prevButton.bezelStyle = .rounded
336
+ prevButton.target = self
337
+ prevButton.action = #selector(prevClicked)
338
+ nextButton.bezelStyle = .rounded
339
+ nextButton.target = self
340
+ nextButton.action = #selector(nextClicked)
341
+
342
+ let headerRow = NSStackView(views: [badgeLabel, NSView(), prevButton, counterLabel, nextButton])
343
+ headerRow.orientation = .horizontal
344
+ headerRow.alignment = .centerY
345
+ headerRow.spacing = 8
346
+ headerRow.edgeInsets = NSEdgeInsets(top: 10, left: 16, bottom: 10, right: 16)
347
+ headerRow.translatesAutoresizingMaskIntoConstraints = false
348
+ header.addSubview(headerRow)
349
+ NSLayoutConstraint.activate([
350
+ headerRow.topAnchor.constraint(equalTo: header.topAnchor),
351
+ headerRow.leadingAnchor.constraint(equalTo: header.leadingAnchor),
352
+ headerRow.trailingAnchor.constraint(equalTo: header.trailingAnchor),
353
+ headerRow.bottomAnchor.constraint(equalTo: header.bottomAnchor),
354
+ ])
355
+
356
+ // Scrollable body
357
+ let scrollView = NSScrollView()
358
+ scrollView.hasVerticalScroller = true
359
+ scrollView.drawsBackground = true
360
+ scrollView.backgroundColor = .windowBackgroundColor
361
+ scrollView.translatesAutoresizingMaskIntoConstraints = false
362
+ container.addSubview(scrollView)
363
+
364
+ let docView = FlippedDevView()
365
+ docView.translatesAutoresizingMaskIntoConstraints = false
366
+ scrollView.documentView = docView
367
+
368
+ contentStack.orientation = .vertical
369
+ contentStack.alignment = .leading
370
+ contentStack.spacing = 12
371
+ contentStack.edgeInsets = NSEdgeInsets(top: 14, left: 16, bottom: 16, right: 16)
372
+ contentStack.translatesAutoresizingMaskIntoConstraints = false
373
+ docView.addSubview(contentStack)
374
+
375
+ NSLayoutConstraint.activate([
376
+ docView.leadingAnchor.constraint(equalTo: scrollView.contentView.leadingAnchor),
377
+ docView.trailingAnchor.constraint(equalTo: scrollView.contentView.trailingAnchor),
378
+ docView.topAnchor.constraint(equalTo: scrollView.contentView.topAnchor),
379
+ contentStack.topAnchor.constraint(equalTo: docView.topAnchor),
380
+ contentStack.leadingAnchor.constraint(equalTo: docView.leadingAnchor),
381
+ contentStack.trailingAnchor.constraint(equalTo: docView.trailingAnchor),
382
+ contentStack.bottomAnchor.constraint(equalTo: docView.bottomAnchor),
383
+ ])
384
+
385
+ showInternalCheckbox.target = self
386
+ showInternalCheckbox.action = #selector(toggleInternalFrames)
387
+ showInternalCheckbox.controlSize = .small
388
+ showInternalCheckbox.font = .systemFont(ofSize: 11.5)
389
+
390
+ // Footer
391
+ let footer = NSVisualEffectView()
392
+ footer.material = .headerView
393
+ footer.blendingMode = .withinWindow
394
+ footer.translatesAutoresizingMaskIntoConstraints = false
395
+ container.addSubview(footer)
396
+
397
+ let reloadButton = NSButton(title: "Reload (⌘R)", target: self, action: #selector(reloadClicked))
398
+ reloadButton.bezelStyle = .rounded
399
+ reloadButton.keyEquivalent = "r"
400
+ reloadButton.keyEquivalentModifierMask = [.command]
401
+
402
+ let copyButton = NSButton(title: "Copy Error", target: self, action: #selector(copyClicked))
403
+ copyButton.bezelStyle = .rounded
404
+
405
+ dismissButton.bezelStyle = .rounded
406
+ dismissButton.target = self
407
+ dismissButton.action = #selector(dismissClicked)
408
+ dismissButton.keyEquivalent = "\u{1b}"
409
+
410
+ let footerRow = NSStackView(views: [reloadButton, copyButton, NSView(), dismissButton])
411
+ footerRow.orientation = .horizontal
412
+ footerRow.alignment = .centerY
413
+ footerRow.spacing = 8
414
+ footerRow.edgeInsets = NSEdgeInsets(top: 10, left: 16, bottom: 10, right: 16)
415
+ footerRow.translatesAutoresizingMaskIntoConstraints = false
416
+ footer.addSubview(footerRow)
417
+ NSLayoutConstraint.activate([
418
+ footerRow.topAnchor.constraint(equalTo: footer.topAnchor),
419
+ footerRow.leadingAnchor.constraint(equalTo: footer.leadingAnchor),
420
+ footerRow.trailingAnchor.constraint(equalTo: footer.trailingAnchor),
421
+ footerRow.bottomAnchor.constraint(equalTo: footer.bottomAnchor),
422
+ ])
423
+
424
+ NSLayoutConstraint.activate([
425
+ header.topAnchor.constraint(equalTo: container.topAnchor),
426
+ header.leadingAnchor.constraint(equalTo: container.leadingAnchor),
427
+ header.trailingAnchor.constraint(equalTo: container.trailingAnchor),
428
+
429
+ scrollView.topAnchor.constraint(equalTo: header.bottomAnchor),
430
+ scrollView.leadingAnchor.constraint(equalTo: container.leadingAnchor),
431
+ scrollView.trailingAnchor.constraint(equalTo: container.trailingAnchor),
432
+ scrollView.bottomAnchor.constraint(equalTo: footer.topAnchor),
433
+
434
+ footer.leadingAnchor.constraint(equalTo: container.leadingAnchor),
435
+ footer.trailingAnchor.constraint(equalTo: container.trailingAnchor),
436
+ footer.bottomAnchor.constraint(equalTo: container.bottomAnchor),
437
+ ])
438
+ }
439
+
440
+ private func rebuildDetails(_ report: ErrorReport) {
441
+ for view in contentStack.arrangedSubviews {
442
+ contentStack.removeArrangedSubview(view)
443
+ view.removeFromSuperview()
444
+ }
445
+ frameLocations.removeAll()
446
+ sourceLocation = report.source?.editorLocation
447
+
448
+ let messageLabel = NSTextField(wrappingLabelWithString: report.summary.isEmpty ? report.displayMessage : report.summary)
449
+ messageLabel.font = .monospacedSystemFont(ofSize: 12.5, weight: .medium)
450
+ messageLabel.isSelectable = true
451
+ contentStack.addArrangedSubview(messageLabel)
452
+ messageLabel.widthAnchor.constraint(equalTo: contentStack.widthAnchor, constant: -32).isActive = true
453
+
454
+ if let source = report.source {
455
+ let card = makeSourceCard(source)
456
+ contentStack.addArrangedSubview(card)
457
+ card.widthAnchor.constraint(equalTo: contentStack.widthAnchor, constant: -32).isActive = true
458
+ }
459
+
460
+ if report.frames.isEmpty == false {
461
+ let headerRow = NSStackView()
462
+ headerRow.orientation = .horizontal
463
+ headerRow.alignment = .centerY
464
+ let stackTitle = NSTextField(labelWithString: "CALL STACK")
465
+ stackTitle.font = .systemFont(ofSize: 10.5, weight: .semibold)
466
+ stackTitle.textColor = .secondaryLabelColor
467
+ headerRow.addArrangedSubview(stackTitle)
468
+ headerRow.addArrangedSubview(NSView())
469
+ if report.frames.contains(where: { $0.internal }) {
470
+ headerRow.addArrangedSubview(showInternalCheckbox)
471
+ }
472
+ contentStack.addArrangedSubview(headerRow)
473
+ headerRow.widthAnchor.constraint(equalTo: contentStack.widthAnchor, constant: -32).isActive = true
474
+
475
+ let includeInternal = showInternalCheckbox.state == .on
476
+ let visibleFrames = report.frames.filter { includeInternal || !$0.internal }
477
+ let framesToShow = visibleFrames.isEmpty ? report.frames : visibleFrames
478
+ for frame in framesToShow {
479
+ let row = makeFrameRow(frame)
480
+ contentStack.addArrangedSubview(row)
481
+ row.widthAnchor.constraint(equalTo: contentStack.widthAnchor, constant: -32).isActive = true
482
+ }
483
+ }
484
+ }
485
+
486
+ private func makeSourceCard(_ source: ErrorSource) -> NSView {
487
+ let box = NSBox()
488
+ box.boxType = .custom
489
+ box.cornerRadius = 8
490
+ box.borderWidth = 1
491
+ box.borderColor = .separatorColor
492
+ box.fillColor = .textBackgroundColor
493
+ box.titlePosition = .noTitle
494
+
495
+ let cardStack = NSStackView()
496
+ cardStack.orientation = .vertical
497
+ cardStack.alignment = .leading
498
+ cardStack.spacing = 8
499
+ cardStack.edgeInsets = NSEdgeInsets(top: 10, left: 12, bottom: 10, right: 12)
500
+ cardStack.translatesAutoresizingMaskIntoConstraints = false
501
+ box.contentView?.addSubview(cardStack)
502
+ if let boxContent = box.contentView {
503
+ NSLayoutConstraint.activate([
504
+ cardStack.topAnchor.constraint(equalTo: boxContent.topAnchor),
505
+ cardStack.leadingAnchor.constraint(equalTo: boxContent.leadingAnchor),
506
+ cardStack.trailingAnchor.constraint(equalTo: boxContent.trailingAnchor),
507
+ cardStack.bottomAnchor.constraint(equalTo: boxContent.bottomAnchor),
508
+ ])
509
+ }
510
+
511
+ let topBar = NSStackView()
512
+ topBar.orientation = .horizontal
513
+ topBar.alignment = .centerY
514
+ let fileLabel = NSTextField(labelWithString: "\(source.fileName):\(source.line):\(source.column)")
515
+ fileLabel.font = .monospacedSystemFont(ofSize: 11.5, weight: .semibold)
516
+ fileLabel.textColor = .secondaryLabelColor
517
+ topBar.addArrangedSubview(fileLabel)
518
+ topBar.addArrangedSubview(NSView())
519
+ if source.editorLocation != nil {
520
+ let openButton = NSButton(title: "Open in Editor", target: self, action: #selector(openSourceInEditor))
521
+ openButton.bezelStyle = .rounded
522
+ openButton.controlSize = .small
523
+ topBar.addArrangedSubview(openButton)
524
+ }
525
+ cardStack.addArrangedSubview(topBar)
526
+ topBar.widthAnchor.constraint(equalTo: cardStack.widthAnchor, constant: -24).isActive = true
527
+
528
+ let codeAttr = NSMutableAttributedString()
529
+ let font = NSFont.monospacedSystemFont(ofSize: 12, weight: .regular)
530
+ let gutterFont = NSFont.monospacedDigitSystemFont(ofSize: 11, weight: .regular)
531
+ let rawLines = source.code.components(separatedBy: .newlines)
532
+ let lineCount = max(rawLines.count, source.tokens.count)
533
+ let maxNumberWidth = String(source.firstLine + max(0, lineCount - 1)).count
534
+
535
+ for idx in 0..<lineCount {
536
+ let lineNumber = source.firstLine + idx
537
+ let isErrorLine = lineNumber == source.line
538
+ let numberText = String(format: "%\(maxNumberWidth)d", lineNumber)
539
+ let prefix = isErrorLine ? "› \(numberText) | " : " \(numberText) | "
540
+ let lineBg: NSColor = isErrorLine ? NSColor.systemRed.withAlphaComponent(0.14) : .clear
541
+
542
+ codeAttr.append(NSAttributedString(string: prefix, attributes: [
543
+ .font: gutterFont,
544
+ .foregroundColor: isErrorLine ? NSColor.systemRed : NSColor.tertiaryLabelColor,
545
+ .backgroundColor: lineBg,
546
+ ]))
547
+
548
+ if idx < source.tokens.count, source.tokens[idx].isEmpty == false {
549
+ for token in source.tokens[idx] {
550
+ codeAttr.append(NSAttributedString(string: token.text, attributes: [
551
+ .font: font,
552
+ .foregroundColor: token.color,
553
+ .backgroundColor: lineBg,
554
+ ]))
555
+ }
556
+ } else if idx < rawLines.count {
557
+ codeAttr.append(NSAttributedString(string: rawLines[idx], attributes: [
558
+ .font: font,
559
+ .foregroundColor: NSColor.labelColor,
560
+ .backgroundColor: lineBg,
561
+ ]))
562
+ }
563
+ if idx + 1 < lineCount {
564
+ codeAttr.append(NSAttributedString(string: "\n", attributes: [.font: font]))
565
+ }
566
+ }
567
+
568
+ let codeLabel = NSTextField(labelWithAttributedString: codeAttr)
569
+ codeLabel.isSelectable = true
570
+ codeLabel.maximumNumberOfLines = 0
571
+ cardStack.addArrangedSubview(codeLabel)
572
+ return box
573
+ }
574
+
575
+ private func makeFrameRow(_ frame: ErrorStackFrame) -> NSView {
576
+ let row = NSStackView()
577
+ row.orientation = .horizontal
578
+ row.alignment = .centerY
579
+ row.spacing = 8
580
+
581
+ let textStack = NSStackView()
582
+ textStack.orientation = .vertical
583
+ textStack.alignment = .leading
584
+ textStack.spacing = 2
585
+
586
+ let nameLabel = NSTextField(labelWithString: frame.name.isEmpty ? "(anonymous)" : frame.name)
587
+ nameLabel.font = .monospacedSystemFont(ofSize: 12, weight: frame.internal ? .regular : .medium)
588
+ nameLabel.textColor = frame.internal ? .secondaryLabelColor : .labelColor
589
+ textStack.addArrangedSubview(nameLabel)
590
+
591
+ let locLabel = NSTextField(labelWithString: "\(frame.file):\(frame.line):\(frame.column)")
592
+ locLabel.font = .monospacedSystemFont(ofSize: 11, weight: .regular)
593
+ locLabel.textColor = frame.internal ? .tertiaryLabelColor : .secondaryLabelColor
594
+ textStack.addArrangedSubview(locLabel)
595
+
596
+ row.addArrangedSubview(textStack)
597
+ row.addArrangedSubview(NSView())
598
+
599
+ if let location = frame.editorLocation {
600
+ let tag = frameLocations.count
601
+ frameLocations.append(location)
602
+ let openButton = NSButton(title: "Open", target: self, action: #selector(openFrameInEditor(_:)))
603
+ openButton.bezelStyle = .rounded
604
+ openButton.controlSize = .small
605
+ openButton.tag = tag
606
+ row.addArrangedSubview(openButton)
607
+ }
608
+
609
+ return row
610
+ }
611
+
612
+ @objc private func reloadClicked() { onReload() }
613
+ @objc private func dismissClicked() { onDismiss() }
614
+ @objc private func prevClicked() { onNavigate(-1) }
615
+ @objc private func nextClicked() { onNavigate(1) }
616
+
617
+ @objc private func toggleInternalFrames() {
618
+ if let report = currentReport {
619
+ rebuildDetails(report)
620
+ }
621
+ }
622
+
623
+ @objc private func openSourceInEditor() {
624
+ if let location = sourceLocation {
625
+ ErrorEditor.open(location)
626
+ }
627
+ }
628
+
629
+ @objc private func openFrameInEditor(_ sender: NSButton) {
630
+ guard frameLocations.indices.contains(sender.tag) else { return }
631
+ ErrorEditor.open(frameLocations[sender.tag])
632
+ }
633
+
634
+ @objc private func copyClicked() {
635
+ guard let report = currentReport else { return }
636
+ NSPasteboard.general.clearContents()
637
+ NSPasteboard.general.setString("\(report.title)\n\(report.displayMessage)", forType: .string)
638
+ }
639
+ }
640
+
641
+ /// Compact floating banner for non-blocking warnings.
642
+ @MainActor
643
+ private final class WarningBannerController: NSObject {
644
+ private var panel: NSPanel?
645
+ private let onOpen: () -> Void
646
+
647
+ init(onOpen: @escaping () -> Void) {
648
+ self.onOpen = onOpen
649
+ super.init()
650
+ }
651
+
652
+ func show(errors: Int, warnings: Int, relativeTo hostWindow: NSWindow?) {
653
+ hide()
654
+ var parts: [String] = []
655
+ if errors > 0 { parts.append("\(errors) \(errors == 1 ? "Error" : "Errors")") }
656
+ if warnings > 0 { parts.append("\(warnings) \(warnings == 1 ? "Warning" : "Warnings")") }
657
+ let title = parts.joined(separator: " · ")
658
+
659
+ let panel = NSPanel(
660
+ contentRect: NSRect(x: 0, y: 0, width: 220, height: 34),
661
+ styleMask: [.borderless, .nonactivatingPanel],
662
+ backing: .buffered,
663
+ defer: false
664
+ )
665
+ panel.isOpaque = false
666
+ panel.backgroundColor = .clear
667
+ panel.level = .floating
668
+ panel.hasShadow = true
669
+
670
+ let button = NSButton(title: title, target: self, action: #selector(clicked))
671
+ button.bezelStyle = .rounded
672
+ button.frame = NSRect(x: 4, y: 3, width: 212, height: 28)
673
+ panel.contentView?.addSubview(button)
674
+
675
+ if let hostWindow {
676
+ let frame = hostWindow.frame
677
+ panel.setFrameOrigin(NSPoint(x: frame.midX - 110, y: frame.minY + 18))
678
+ } else {
679
+ panel.center()
680
+ }
681
+ panel.orderFront(nil)
682
+ self.panel = panel
683
+ }
684
+
685
+ func hide() {
686
+ panel?.orderOut(nil)
687
+ panel = nil
688
+ }
689
+
690
+ @objc private func clicked() {
691
+ onOpen()
692
+ }
693
+ }
694
+
695
+ private final class FlippedDevView: NSView {
696
+ override var isFlipped: Bool { true }
697
+ }
698
+ #endif