Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151public enum WhimsyLevel: String, Sendable, CaseIterable { case calm case playful case extra}
public struct MotionSettings: Sendable, Equatable { public static let supportedSpeeds = 0.1...4.0 public var level: WhimsyLevel public var speedMultiplier: Double { didSet { precondition(Self.supportedSpeeds.contains(speedMultiplier)) } }
public init(level: WhimsyLevel = .playful, speedMultiplier: Double = 1) { precondition(Self.supportedSpeeds.contains(speedMultiplier)) self.level = level self.speedMultiplier = speedMultiplier }}
public enum MotionAccent: Sendable, Equatable { case none case scale(from: Double) case offset(horizontal: Double, vertical: Double)}
public enum MotionCurve: Sendable, Equatable { case spring case glide case fade}
public struct MotionSpec: Sendable, Equatable { public let duration: Double public let bounce: Double public let stagger: Double public let maximumStagger: Double public let overshootLimit: Double public let accent: MotionAccent public let curve: MotionCurve public let maximumRedraws: Int?
public var spring: SpringParameters { SpringParameters(duration: duration, bounce: bounce) }
public func delay(for index: Int) -> Double { precondition(index >= 0) return min(Double(index) * stagger, maximumStagger) }}
public enum MotionToken: String, Sendable, CaseIterable { case settle case pop case nudge case shuffle case stack case fade case glance case drop
public func spec(settings: MotionSettings = MotionSettings()) -> MotionSpec { if settings.level == .calm && self != .fade { return MotionToken.settle.makeSpec(speed: settings.speedMultiplier, calm: true) } return makeSpec(speed: settings.speedMultiplier, extra: settings.level == .extra) }
private func makeSpec(speed: Double, calm: Bool = false, extra: Bool = false) -> MotionSpec { let duration: Double var bounce: Double var stagger = 0.0 var cap = 0.0 var accent = MotionAccent.none var curve = MotionCurve.spring var redraws: Int? switch self { case .settle: duration = 0.20 bounce = 0 curve = calm ? .spring : .glide case .pop: duration = 0.25 bounce = 0.15 accent = .scale(from: 0.98) case .nudge: duration = 0.18 bounce = 0.5 accent = .offset(horizontal: 4, vertical: 0) case .shuffle: duration = 0.24 bounce = 0.1 stagger = 0.012 cap = 0.048 case .stack: duration = 0.28 bounce = 0.12 accent = .offset(horizontal: 2, vertical: 0) case .fade: duration = 0.12 bounce = 0 curve = .fade case .glance: duration = 0.15 bounce = 0 redraws = 10 case .drop: duration = 0.30 bounce = 0.25 } if extra { if self == .pop || self == .drop || self == .shuffle { bounce = min(bounce + 0.1, 0.4) } stagger *= 1.5 cap *= 1.5 } return MotionSpec( duration: duration / speed, bounce: bounce, stagger: stagger / speed, maximumStagger: cap / speed, overshootLimit: bounce == 0 ? 0 : min(bounce, 0.25), accent: accent, curve: curve, maximumRedraws: redraws ) }}
public enum MotionSurface: Sendable, Equatable { case window case overlay case miniMap}
public enum MotionBehavior: Sendable, Equatable { case instant case animate case fade(duration: Double)}
public struct MotionPolicy: Sendable, Equatable { public var enabled: Bool public var reduceMotion: Bool
public init(enabled: Bool = true, reduceMotion: Bool = false) { self.enabled = enabled self.reduceMotion = reduceMotion }
public func behavior(for surface: MotionSurface, level: WhimsyLevel = .playful) -> MotionBehavior { guard enabled else { return .instant } if reduceMotion { return surface == .overlay ? .fade(duration: 0.12) : .instant } if level == .calm && surface == .window { return .instant } return .animate }}