Ariver
2026-06-11 1bdf3fd8a05223aced3a7bf5b75a948d1afe32fc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import AppKit
import Foundation
 
public struct SkeletonThumbnailTemplate: Equatable, Sendable {
    public let category: AppCategory
    public let headerHeight: CGFloat
    public let contentRows: Int
    public let accentStripeCount: Int
 
    public init(category: AppCategory, headerHeight: CGFloat, contentRows: Int, accentStripeCount: Int) {
        self.category = category
        self.headerHeight = headerHeight
        self.contentRows = contentRows
        self.accentStripeCount = accentStripeCount
    }
 
    public static func template(for category: AppCategory) -> SkeletonThumbnailTemplate {
        switch category {
        case .finder:
            return SkeletonThumbnailTemplate(category: category, headerHeight: 18, contentRows: 4, accentStripeCount: 1)
        case .browser:
            return SkeletonThumbnailTemplate(category: category, headerHeight: 20, contentRows: 3, accentStripeCount: 3)
        case .terminal:
            return SkeletonThumbnailTemplate(category: category, headerHeight: 16, contentRows: 5, accentStripeCount: 0)
        case .editorIDE:
            return SkeletonThumbnailTemplate(category: category, headerHeight: 16, contentRows: 6, accentStripeCount: 2)
        case .chat:
            return SkeletonThumbnailTemplate(category: category, headerHeight: 16, contentRows: 4, accentStripeCount: 1)
        case .documentNotes:
            return SkeletonThumbnailTemplate(category: category, headerHeight: 14, contentRows: 5, accentStripeCount: 0)
        case .generic:
            return SkeletonThumbnailTemplate(category: category, headerHeight: 16, contentRows: 3, accentStripeCount: 1)
        }
    }
}
 
@MainActor
public final class NativeSkeletonThumbnailProvider: SkeletonThumbnailProviderProtocol {
    public static let defaultSize = NSSize(width: 120, height: 80)
 
    private let size: NSSize
 
    public init(size: NSSize = NativeSkeletonThumbnailProvider.defaultSize) {
        self.size = size
    }
 
    public func skeleton(for app: AlignerApp) -> NSImage {
        drawSkeleton(template: SkeletonThumbnailTemplate.template(for: app.category), title: nil)
    }
 
    public func withOverlayTitle(_ title: String, for app: AlignerApp) -> NSImage {
        drawSkeleton(template: SkeletonThumbnailTemplate.template(for: app.category), title: title)
    }
 
    private func drawSkeleton(template: SkeletonThumbnailTemplate, title: String?) -> NSImage {
        let image = NSImage(size: size)
        image.lockFocus()
 
        let bounds = NSRect(origin: .zero, size: size)
        NSColor.windowBackgroundColor.setFill()
        NSBezierPath(roundedRect: bounds, xRadius: 6, yRadius: 6).fill()
 
        drawHeader(template: template, in: bounds)
        drawContentRows(template: template, in: bounds, reservesTitleBand: title != nil)
        drawAccentStripes(template: template, in: bounds)
 
        if let title, !title.isEmpty {
            drawTitle(title, in: bounds)
        }
 
        image.unlockFocus()
        return image
    }
 
    private func drawHeader(template: SkeletonThumbnailTemplate, in bounds: NSRect) {
        let header = NSRect(
            x: 0,
            y: bounds.height - template.headerHeight,
            width: bounds.width,
            height: template.headerHeight
        )
        color(for: template.category).withAlphaComponent(0.22).setFill()
        NSBezierPath(roundedRect: header, xRadius: 6, yRadius: 6).fill()
    }
 
    private func drawContentRows(
        template: SkeletonThumbnailTemplate,
        in bounds: NSRect,
        reservesTitleBand: Bool
    ) {
        let rowHeight: CGFloat = 6
        let rowSpacing: CGFloat = 6
        let startY = bounds.height - template.headerHeight - 14
        let minimumY: CGFloat = reservesTitleBand ? 24 : 8
        let maxWidth = bounds.width - 24
        let maximumRows = max(0, Int(floor((startY - minimumY + rowSpacing) / (rowHeight + rowSpacing))))
        let rowsToDraw = min(template.contentRows, maximumRows)
 
        for row in 0..<rowsToDraw {
            let widthRatio = 1 - CGFloat(row % 3) * 0.18
            let rect = NSRect(
                x: 12,
                y: startY - CGFloat(row) * (rowHeight + rowSpacing),
                width: maxWidth * widthRatio,
                height: rowHeight
            )
            NSColor.secondaryLabelColor.withAlphaComponent(0.18).setFill()
            NSBezierPath(roundedRect: rect, xRadius: 3, yRadius: 3).fill()
        }
    }
 
    private func drawAccentStripes(template: SkeletonThumbnailTemplate, in bounds: NSRect) {
        guard template.accentStripeCount > 0 else { return }
 
        let stripeWidth: CGFloat = 8
        for stripe in 0..<template.accentStripeCount {
            let rect = NSRect(
                x: 12 + CGFloat(stripe) * (stripeWidth + 4),
                y: bounds.height - template.headerHeight + 5,
                width: stripeWidth,
                height: max(4, template.headerHeight - 10)
            )
            color(for: template.category).withAlphaComponent(0.55).setFill()
            NSBezierPath(roundedRect: rect, xRadius: 3, yRadius: 3).fill()
        }
    }
 
    private func drawTitle(_ title: String, in bounds: NSRect) {
        let titleBand = NSRect(x: 0, y: 0, width: bounds.width, height: 24)
        NSColor.windowBackgroundColor.withAlphaComponent(0.86).setFill()
        NSBezierPath(roundedRect: titleBand, xRadius: 6, yRadius: 6).fill()
 
        let paragraph = NSMutableParagraphStyle()
        paragraph.alignment = .center
        paragraph.lineBreakMode = .byTruncatingTail
 
        let attributes: [NSAttributedString.Key: Any] = [
            .font: NSFont.systemFont(ofSize: 10, weight: .semibold),
            .foregroundColor: NSColor.labelColor,
            .paragraphStyle: paragraph
        ]
        let rect = NSRect(x: 8, y: 6, width: bounds.width - 16, height: 14)
        title.draw(in: rect, withAttributes: attributes)
    }
 
    private func color(for category: AppCategory) -> NSColor {
        switch category {
        case .finder:
            return .systemBlue
        case .browser:
            return .systemTeal
        case .terminal:
            return .systemGreen
        case .editorIDE:
            return .systemPurple
        case .chat:
            return .systemMint
        case .documentNotes:
            return .systemYellow
        case .generic:
            return .tertiaryLabelColor
        }
    }
}