This commit is contained in:
Akshay Kolli
2026-06-30 01:12:19 -07:00
commit 4c1c6b2f37
55 changed files with 13180 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
import AppKit
extension NSImage {
func resized(to fitSize: CGSize) -> NSImage {
let target = NSSize(width: fitSize.width, height: fitSize.height)
let currentSize = size
let ratio = min(target.width / currentSize.width, target.height / currentSize.height, 1.0)
let newSize = NSSize(width: currentSize.width * ratio, height: currentSize.height * ratio)
let newImage = NSImage(size: newSize)
newImage.lockFocus()
draw(
in: NSRect(origin: .zero, size: newSize),
from: NSRect(origin: .zero, size: currentSize),
operation: .sourceOver,
fraction: 1.0
)
newImage.unlockFocus()
newImage.size = newSize
return newImage
}
func pngData() -> Data? {
guard let cgImage = cgImage(forProposedRect: nil, context: nil, hints: nil) else { return nil }
let rep = NSBitmapImageRep(cgImage: cgImage)
return rep.representation(using: .png, properties: [:])
}
}
extension NSView {
var isInAnyViewHierarchy: Bool {
return window != nil
}
}

View File

@@ -0,0 +1,19 @@
extension StringProtocol {
var clipboardTrimmed: String {
var start = startIndex
var end = endIndex
while start < end, self[start].isWhitespace {
formIndex(after: &start)
}
while end > start {
let previous = index(before: end)
if !self[previous].isWhitespace {
break
}
end = previous
}
return String(self[start..<end])
}
}