Draw Base's look natively: palette, sky, glass, type and marks
Palette mirrors every colour token in internal/look/static/app.css, dark from :root and light from :root[data-theme="light"] over it, under the web's names; PaletteTests parses the stylesheet and fails on any token that differs or isn't mirrored, so the web and the apps can't drift. The sky is the web's atmosphere in a Canvas under a 30 fps TimelineView: the gradient, the two swaying, breathing beams and the four banks of fog on their keyframe paths with their colours drifting, on the same periods, delays and easing. It pauses when the scene isn't active, and Reduce Motion (and snapshots) hold it at the stylesheet's reduced-motion pose. Glass, the conversation's sheet and the menus' solid surface are view modifiers with the web's fills, hairline edge, top shine and lift. Timeless Sans registers at launch from the bundle, Grotesk for headings and Sans for the rest, with DM Sans and then the system face as the fallbacks; the type scales with Dynamic Type. The marks are the web's state marks, working's turning arc included. snapshots.sh records the look in light and dark (base-look, base-type).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
34 files changed,
+1,487
−9
native/apple/Sources/BaseKit/Look/Appearance.swift+24 −0native/apple/Sources/BaseKit/Look/Glass.swift+107 −0native/apple/Sources/BaseKit/Look/Marks.swift+280 −0native/apple/Sources/BaseKit/Look/Palette.swift+348 −0native/apple/Sources/BaseKit/Look/Sky.swift+234 −0native/apple/Sources/BaseKit/Look/Type.swift+99 −0native/apple/Tests/BaseKitTests/LookTests.swift+63 −0native/apple/Tests/BaseKitTests/PaletteTests.swift+83 −0native/apple/Tests/BaseKitTests/TypeTests.swift+58 −0native/apple/Tests/BaseSnapshots/BaseSnapshots.swift+0 −9native/apple/Tests/BaseSnapshots/LookSnapshots.swift+108 −0native/apple/Tests/BaseSnapshots/__Snapshots__/base-look/iphone/ENVIRONMENT+10 −0native/apple/Tests/BaseSnapshots/__Snapshots__/base-look/iphone/marks-dark-default.pngbinarynative/apple/Tests/BaseSnapshots/__Snapshots__/base-look/iphone/marks-light-default.pngbinarynative/apple/Tests/BaseSnapshots/__Snapshots__/base-look/iphone/sky-dark-default.pngbinarynative/apple/Tests/BaseSnapshots/__Snapshots__/base-look/iphone/sky-light-default.pngbinarynative/apple/Tests/BaseSnapshots/__Snapshots__/base-look/iphone/surfaces-dark-default.pngbinarynative/apple/Tests/BaseSnapshots/__Snapshots__/base-look/iphone/surfaces-light-default.pngbinarynative/apple/Tests/BaseSnapshots/__Snapshots__/base-look/mac/ENVIRONMENT+9 −0native/apple/Tests/BaseSnapshots/__Snapshots__/base-look/mac/marks-dark-default.pngbinarynative/apple/Tests/BaseSnapshots/__Snapshots__/base-look/mac/marks-light-default.pngbinarynative/apple/Tests/BaseSnapshots/__Snapshots__/base-look/mac/sky-dark-default.pngbinarynative/apple/Tests/BaseSnapshots/__Snapshots__/base-look/mac/sky-light-default.pngbinarynative/apple/Tests/BaseSnapshots/__Snapshots__/base-look/mac/surfaces-dark-default.pngbinarynative/apple/Tests/BaseSnapshots/__Snapshots__/base-look/mac/surfaces-light-default.pngbinarynative/apple/Tests/BaseSnapshots/__Snapshots__/base-type/iphone/ENVIRONMENT+10 −0native/apple/Tests/BaseSnapshots/__Snapshots__/base-type/iphone/type-dark-ax3.pngbinarynative/apple/Tests/BaseSnapshots/__Snapshots__/base-type/iphone/type-dark-default.pngbinarynative/apple/Tests/BaseSnapshots/__Snapshots__/base-type/iphone/type-light-ax3.pngbinarynative/apple/Tests/BaseSnapshots/__Snapshots__/base-type/iphone/type-light-default.pngbinarynative/apple/Tests/BaseSnapshots/__Snapshots__/base-type/mac/ENVIRONMENT+9 −0native/apple/Tests/BaseSnapshots/__Snapshots__/base-type/mac/type-dark-default.pngbinarynative/apple/Tests/BaseSnapshots/__Snapshots__/base-type/mac/type-light-default.pngbinarynative/scripts/snapshots.sh+45 −0
diff --git a/native/apple/Sources/BaseKit/Look/Appearance.swift b/native/apple/Sources/BaseKit/Look/Appearance.swift| new file mode 100644 |
| index 0000000..b431127 |
| --- /dev/null |
| +++ b/native/apple/Sources/BaseKit/Look/Appearance.swift |
| @@ -0,0 +1,24 @@ |
| +import SwiftUI |
| + |
| +/// The member's Appearance, from `/api/v1/me` (Settings on the web): it |
| +/// overrides the system's, as `data-theme` on the web's `<html>` does. |
| +public enum BaseAppearance: String, Sendable, Codable, CaseIterable { |
| + case system, light, dark |
| + |
| + /// What to pass `preferredColorScheme`: nil follows the system. |
| + public var colorScheme: ColorScheme? { |
| + switch self { |
| + case .system: nil |
| + case .light: .light |
| + case .dark: .dark |
| + } |
| + } |
| + |
| + /// Anything else the server says (a value from a newer Base) is System. |
| + public init(server value: String?) { self = value.flatMap(BaseAppearance.init(rawValue:)) ?? .system } |
| +} |
| + |
| +public extension View { |
| + /// The member's Appearance over the system's. |
| + func baseAppearance(_ appearance: BaseAppearance) -> some View { preferredColorScheme(appearance.colorScheme) } |
| +} |
diff --git a/native/apple/Sources/BaseKit/Look/Glass.swift b/native/apple/Sources/BaseKit/Look/Glass.swift| new file mode 100644 |
| index 0000000..4416dd7 |
| --- /dev/null |
| +++ b/native/apple/Sources/BaseKit/Look/Glass.swift |
| @@ -0,0 +1,107 @@ |
| +import SwiftUI |
| + |
| +/// Base's surfaces (P10), each a rounded panel over the sky: |
| +/// |
| +/// - **glass**: the web's `.glass`, tinted dark in the dark and white frost |
| +/// in the light: `linear-gradient(--glass-1, --glass-2)` over |
| +/// `--glass-base`, over the system's thin material for the blur. |
| +/// - **sheet**: the panel that carries the conversation (the mockups' |
| +/// `.sheet`): the same, with `--sheet-*`, denser, so text keeps WCAG AA |
| +/// whatever the fog behind it does. |
| +/// - **solid**: menus and the job view (`.solid`, `.jobview`): near-solid |
| +/// `--menu-base`, as they open over other glass. |
| +/// |
| +/// Each has a 1 px bright top edge (`inset 0 1px 0 --glass-shine`), a |
| +/// hairline border (`--glass-edge`) and the web's soft lift. Text sits only |
| +/// on these, never straight on the sky (spec 6). |
| +public enum Surface: Sendable { case glass, sheet, solid } |
| + |
| +public extension View { |
| + func glass(cornerRadius: CGFloat = 18) -> some View { modifier(SurfaceModifier(kind: .glass, radius: cornerRadius)) } |
| + /// `.sheet` on the web; named so it can't be mistaken for SwiftUI's |
| + /// `.sheet(isPresented:)`. |
| + func glassSheet(cornerRadius: CGFloat = 18) -> some View { modifier(SurfaceModifier(kind: .sheet, radius: cornerRadius)) } |
| + func solid(cornerRadius: CGFloat = 16) -> some View { modifier(SurfaceModifier(kind: .solid, radius: cornerRadius)) } |
| +} |
| + |
| +struct SurfaceModifier: ViewModifier { |
| + let kind: Surface |
| + let radius: CGFloat |
| + @Environment(\.colorScheme) private var scheme |
| + |
| + func body(content: Content) -> some View { |
| + let p = Palette(scheme) |
| + let shape = RoundedRectangle(cornerRadius: radius, style: .continuous) |
| + content |
| + .background { |
| + switch kind { |
| + case .glass: |
| + ZStack { |
| + shape.fill(.ultraThinMaterial) |
| + shape.fill(p[.glassBase]) |
| + shape.fill(LinearGradient(colors: [p[.glass1], p[.glass2]], startPoint: .top, endPoint: .bottom)) |
| + } |
| + case .sheet: |
| + ZStack { |
| + shape.fill(.ultraThinMaterial) |
| + shape.fill(p[.sheetBase]) |
| + shape.fill(LinearGradient(colors: [p[.sheet1], p[.sheet2]], startPoint: .top, endPoint: .bottom)) |
| + } |
| + case .solid: |
| + shape.fill(p[.menuBase]) |
| + } |
| + } |
| + .overlay { |
| + ZStack { |
| + if kind != .solid { shape.strokeBorder(p[.glassEdge], lineWidth: 1) } |
| + TopShine(radius: radius, color: kind == .solid ? p[.menuShine] : p[.glassShine]) |
| + } |
| + .allowsHitTesting(false) |
| + } |
| + .clipShape(shape) |
| + // 0 18px 40px var(--glass-lift) var(--glass-shadow): a spread as |
| + // negative as half the blur leaves a soft, low shadow. SwiftUI has |
| + // no spread, so the radius and alpha are smaller; and the shadow |
| + // is drawn outside the panel only, as a box-shadow is, so the |
| + // glass doesn't darken itself. |
| + .background { |
| + OuterShadow(radius: radius, color: kind == .solid ? p[.menuShadow] : p[.glassShadow], |
| + blur: kind == .solid ? 24 : 14, y: kind == .solid ? 16 : 12) |
| + } |
| + } |
| +} |
| + |
| +/// A shadow cast outside a rounded panel, and nowhere under it. |
| +struct OuterShadow: View { |
| + let radius: CGFloat |
| + let color: Color |
| + let blur: CGFloat |
| + let y: CGFloat |
| + var body: some View { |
| + let shape = RoundedRectangle(cornerRadius: radius, style: .continuous) |
| + shape.fill(Color.black) |
| + .shadow(color: color.opacity(0.55), radius: blur, y: y) |
| + .mask { |
| + Rectangle().padding(-(blur * 3 + abs(y))) |
| + .overlay { shape.blendMode(.destinationOut) } |
| + .compositingGroup() |
| + } |
| + .allowsHitTesting(false) |
| + .accessibilityHidden(true) |
| + } |
| +} |
| + |
| +/// `inset 0 1px 0 <colour>`: a 1 px line inside the top edge that follows |
| +/// its corners and fades down them. |
| +struct TopShine: View { |
| + let radius: CGFloat |
| + let color: Color |
| + var body: some View { |
| + RoundedRectangle(cornerRadius: radius, style: .continuous) |
| + .stroke(color, lineWidth: 2) |
| + .offset(y: 1) |
| + .mask(LinearGradient(stops: [.init(color: .white, location: 0), .init(color: .clear, location: 0.5)], |
| + startPoint: .top, endPoint: UnitPoint(x: 0.5, y: min(1, radius / 40)))) |
| + .clipShape(RoundedRectangle(cornerRadius: radius, style: .continuous)) |
| + } |
| +} |
diff --git a/native/apple/Sources/BaseKit/Look/Marks.swift b/native/apple/Sources/BaseKit/Look/Marks.swift| new file mode 100644 |
| index 0000000..ee50c28 |
| --- /dev/null |
| +++ b/native/apple/Sources/BaseKit/Look/Marks.swift |
| @@ -0,0 +1,280 @@ |
| +import SwiftUI |
| + |
| +/// Base's mark: the wordmark's rounded square, `--mark-1` into `--mark-2` |
| +/// at 160°, with its edge (`.wordmark::before`, `.mark`). 14 pt in a |
| +/// heading, 16 pt in the sidebar, 18 pt in the Base button; its corners |
| +/// are 5/16 of its side, as the web's 16 px mark has 5 px. |
| +public struct BaseMark: View { |
| + let size: CGFloat |
| + @Environment(\.colorScheme) private var scheme |
| + public init(size: CGFloat = 16) { self.size = size } |
| + public var body: some View { |
| + let p = Palette(scheme) |
| + let shape = RoundedRectangle(cornerRadius: size * 5 / 16, style: .continuous) |
| + let (start, end) = SkyPainter.cssLine(degrees: 160, in: CGRect(x: 0, y: 0, width: 1, height: 1)) |
| + shape.fill(LinearGradient(colors: [p[.mark1], p[.mark2]], startPoint: UnitPoint(x: start.x, y: start.y), endPoint: UnitPoint(x: end.x, y: end.y))) |
| + .overlay { shape.strokeBorder(p[.markEdge], lineWidth: 1) } |
| + .frame(width: size, height: size) |
| + .accessibilityHidden(true) |
| + } |
| +} |
| + |
| +/// A job's state, as the web names them (ask.js `jobStates`). |
| +public enum JobState: String, Sendable, CaseIterable, Codable { |
| + case working, asking, ready, done, stopped |
| +} |
| + |
| +/// The 24-unit drawings Base's web uses (ask.js `marks`, the templates' |
| +/// `ask-mark`, and the job view's and composer's icons), as paths. |
| +public enum BaseIcon: Sendable { |
| + case asking, ready, done, stopped, arrowOut, close, send |
| + |
| + var svg: String { |
| + switch self { |
| + case .asking: "M9.2 9.2a2.9 2.9 0 0 1 5.6 1c0 2-2.8 2.4-2.8 4.3M12 18.2h.01" |
| + case .ready: "M8 16L16 8M9.5 8H16v6.5" |
| + case .done: "M6 12.5l4 4 8-9" |
| + case .stopped: "M9.5 7.5v9M14.5 7.5v9" |
| + case .arrowOut: "M9 6h9v9M18 6L7 17" |
| + case .close: "M6 6l12 12M18 6L6 18" |
| + case .send: "M12 19V5M6 11l6-6 6 6" |
| + } |
| + } |
| + |
| + /// The drawing scaled from its 24-unit box into `rect`. |
| + public func path(in rect: CGRect) -> Path { |
| + SVGPath.parse(svg).applying(CGAffineTransform(scaleX: rect.width / 24, y: rect.height / 24) |
| + .concatenating(CGAffineTransform(translationX: rect.minX, y: rect.minY))) |
| + } |
| +} |
| + |
| +/// An icon drawn as the web draws it: a round-capped stroke, `weight` in |
| +/// the drawing's 24 units (2.6 for a state's mark, 2.4 for Send, 1.8 for |
| +/// Close). |
| +public struct IconShape: Shape { |
| + let icon: BaseIcon |
| + public init(_ icon: BaseIcon) { self.icon = icon } |
| + public func path(in rect: CGRect) -> Path { icon.path(in: rect) } |
| +} |
| + |
| +public struct Icon: View { |
| + let icon: BaseIcon |
| + let weight: CGFloat |
| + public init(_ icon: BaseIcon, weight: CGFloat = 1.8) { self.icon = icon; self.weight = weight } |
| + public var body: some View { |
| + GeometryReader { geo in |
| + IconShape(icon).stroke(style: StrokeStyle(lineWidth: weight * geo.size.width / 24, lineCap: .round, lineJoin: .round)) |
| + } |
| + .aspectRatio(1, contentMode: .fit) |
| + .accessibilityHidden(true) |
| + } |
| +} |
| + |
| +/// A job state's mark (`.state-mark`): a disc. Working is a slow arc |
| +/// turning round a breathing dot, on the accent's tint; the rest are |
| +/// still icons on the state's colour (working, ready and done the accent, |
| +/// asking warm, stopped rose). With Reduce Motion, working holds still: a |
| +/// quarter arc and a steady dot. |
| +public struct StateMark: View { |
| + let state: JobState |
| + let size: CGFloat |
| + @Environment(\.colorScheme) private var scheme |
| + @Environment(\.accessibilityReduceMotion) private var reduceMotion |
| + @Environment(\.skyFrozen) private var frozen |
| + |
| + public init(_ state: JobState, size: CGFloat = 28) { self.state = state; self.size = size } |
| + |
| + public static func color(_ state: JobState, _ p: Palette) -> Color { |
| + switch state { |
| + case .working, .ready, .done: p[.signal] |
| + case .asking: p[.stAsk] |
| + case .stopped: p[.stStop] |
| + } |
| + } |
| + |
| + public var body: some View { |
| + let p = Palette(scheme) |
| + let st = Self.color(state, p) |
| + ZStack { |
| + if state == .working { |
| + Circle().fill(st.opacity(0.14)) |
| + Circle().strokeBorder(st.opacity(0.26), lineWidth: 2) |
| + if reduceMotion || frozen { |
| + WorkingArc(color: st).rotationEffect(.degrees(45)) |
| + Circle().fill(st).frame(width: 6, height: 6) |
| + } else { |
| + TimelineView(.animation) { timeline in |
| + let t = timeline.date.timeIntervalSinceReferenceDate |
| + // turn: 1.6s cubic-bezier(.5,.15,.5,.85) infinite |
| + let turn = SkyPainter.cubicBezier(t.truncatingRemainder(dividingBy: 1.6) / 1.6, 0.5, 0.15, 0.5, 0.85) |
| + // glow: 1.6s ease-in-out infinite alternate, .45 → 1 |
| + let glow = SkyPainter.mix(0.45, 1, SkyPainter.easeInOut(SkyPainter.progress(t, period: 1.6, delay: 0, reverse: false))) |
| + ZStack { |
| + WorkingArc(color: st).rotationEffect(.degrees(360 * turn)) |
| + Circle().fill(st).frame(width: 6, height: 6).opacity(glow) |
| + } |
| + } |
| + } |
| + } else { |
| + Circle().fill(st) |
| + Icon(icon, weight: 2.6) |
| + .foregroundStyle(p[.onSignal]) |
| + .frame(width: size * 15 / 28, height: size * 15 / 28) |
| + } |
| + } |
| + .frame(width: size, height: size) |
| + .accessibilityHidden(true) |
| + } |
| + |
| + var icon: BaseIcon { |
| + switch state { |
| + case .asking: .asking |
| + case .ready: .ready |
| + case .done: .done |
| + case .stopped, .working: .stopped |
| + } |
| + } |
| +} |
| + |
| +/// `border: 2px solid transparent; border-top-color: --st`: a quarter of |
| +/// the ring, centred on the top. |
| +struct WorkingArc: View { |
| + let color: Color |
| + var body: some View { |
| + Circle() |
| + .inset(by: 1) |
| + .trim(from: 0, to: 0.25) |
| + .stroke(color, style: StrokeStyle(lineWidth: 2, lineCap: .butt)) |
| + .rotationEffect(.degrees(-135)) |
| + } |
| +} |
| + |
| +/// Just enough SVG path syntax for the web's icons: M L H V C A Z, absolute |
| +/// and relative, with implicit repeats. |
| +enum SVGPath { |
| + static func parse(_ d: String) -> Path { |
| + var path = Path() |
| + var tokens = Tokens(d) |
| + var current = CGPoint.zero, start = CGPoint.zero |
| + var command: Character = "M" |
| + while let next = tokens.peekCommand() ?? (tokens.atEnd ? nil : command) { |
| + if tokens.peekCommand() != nil { tokens.skipCommand() } |
| + command = next |
| + let relative = command.isLowercase |
| + let base = relative ? current : .zero |
| + switch command.uppercased() { |
| + case "M": |
| + guard let x = tokens.number(), let y = tokens.number() else { return path } |
| + current = CGPoint(x: base.x + x, y: base.y + y); start = current |
| + path.move(to: current) |
| + command = relative ? "l" : "L" |
| + case "L": |
| + guard let x = tokens.number(), let y = tokens.number() else { return path } |
| + current = CGPoint(x: base.x + x, y: base.y + y); path.addLine(to: current) |
| + case "H": |
| + guard let x = tokens.number() else { return path } |
| + current = CGPoint(x: (relative ? current.x : 0) + x, y: current.y); path.addLine(to: current) |
| + case "V": |
| + guard let y = tokens.number() else { return path } |
| + current = CGPoint(x: current.x, y: (relative ? current.y : 0) + y); path.addLine(to: current) |
| + case "C": |
| + guard let x1 = tokens.number(), let y1 = tokens.number(), let x2 = tokens.number(), let y2 = tokens.number(), |
| + let x = tokens.number(), let y = tokens.number() else { return path } |
| + let end = CGPoint(x: base.x + x, y: base.y + y) |
| + path.addCurve(to: end, control1: CGPoint(x: base.x + x1, y: base.y + y1), control2: CGPoint(x: base.x + x2, y: base.y + y2)) |
| + current = end |
| + case "A": |
| + guard let rx = tokens.number(), let ry = tokens.number(), let rotation = tokens.number(), |
| + let large = tokens.flag(), let sweep = tokens.flag(), let x = tokens.number(), let y = tokens.number() else { return path } |
| + let end = CGPoint(x: base.x + x, y: base.y + y) |
| + addArc(&path, from: current, to: end, rx: rx, ry: ry, rotation: rotation, large: large, sweep: sweep) |
| + current = end |
| + case "Z": |
| + path.closeSubpath(); current = start |
| + default: |
| + return path |
| + } |
| + } |
| + return path |
| + } |
| + |
| + /// SVG's endpoint arc (implementation notes F.6.5), as cubic curves. |
| + static func addArc(_ path: inout Path, from p0: CGPoint, to p1: CGPoint, rx: Double, ry: Double, rotation: Double, large: Bool, sweep: Bool) { |
| + var rx = abs(rx), ry = abs(ry) |
| + guard rx > 0, ry > 0, p0 != p1 else { path.addLine(to: p1); return } |
| + let phi = rotation * .pi / 180, cosPhi = cos(phi), sinPhi = sin(phi) |
| + let dx = (p0.x - p1.x) / 2, dy = (p0.y - p1.y) / 2 |
| + let x1 = cosPhi * dx + sinPhi * dy, y1 = -sinPhi * dx + cosPhi * dy |
| + let lambda = (x1 * x1) / (rx * rx) + (y1 * y1) / (ry * ry) |
| + if lambda > 1 { rx *= sqrt(lambda); ry *= sqrt(lambda) } |
| + let num = rx * rx * ry * ry - rx * rx * y1 * y1 - ry * ry * x1 * x1 |
| + let den = rx * rx * y1 * y1 + ry * ry * x1 * x1 |
| + var coef = sqrt(max(0, num / den)) |
| + if large == sweep { coef = -coef } |
| + let cx1 = coef * rx * y1 / ry, cy1 = -coef * ry * x1 / rx |
| + let cx = cosPhi * cx1 - sinPhi * cy1 + (p0.x + p1.x) / 2 |
| + let cy = sinPhi * cx1 + cosPhi * cy1 + (p0.y + p1.y) / 2 |
| + func angle(_ ux: Double, _ uy: Double, _ vx: Double, _ vy: Double) -> Double { |
| + let a = atan2(ux * vy - uy * vx, ux * vx + uy * vy) |
| + return a |
| + } |
| + let theta1 = angle(1, 0, (x1 - cx1) / rx, (y1 - cy1) / ry) |
| + var delta = angle((x1 - cx1) / rx, (y1 - cy1) / ry, (-x1 - cx1) / rx, (-y1 - cy1) / ry) |
| + if !sweep && delta > 0 { delta -= 2 * .pi } |
| + if sweep && delta < 0 { delta += 2 * .pi } |
| + let segments = max(1, Int(ceil(abs(delta) / (.pi / 2)))) |
| + let step = delta / Double(segments) |
| + var theta = theta1 |
| + for _ in 0..<segments { |
| + let t = 4.0 / 3.0 * tan(step / 4) |
| + func point(_ a: Double) -> (CGPoint, CGPoint) { |
| + let ex = rx * cos(a), ey = ry * sin(a) |
| + let px = cx + cosPhi * ex - sinPhi * ey, py = cy + sinPhi * ex + cosPhi * ey |
| + let tx = -rx * sin(a), ty = ry * cos(a) |
| + return (CGPoint(x: px, y: py), CGPoint(x: cosPhi * tx - sinPhi * ty, y: sinPhi * tx + cosPhi * ty)) |
| + } |
| + let (a, da) = point(theta), (b, db) = point(theta + step) |
| + path.addCurve(to: b, control1: CGPoint(x: a.x + t * da.x, y: a.y + t * da.y), control2: CGPoint(x: b.x - t * db.x, y: b.y - t * db.y)) |
| + theta += step |
| + } |
| + } |
| + |
| + struct Tokens { |
| + let chars: [Character] |
| + var i = 0 |
| + init(_ s: String) { chars = Array(s) } |
| + var atEnd: Bool { mutating get { skipSeparators(); return i >= chars.count } } |
| + mutating func skipSeparators() { while i < chars.count, chars[i] == " " || chars[i] == "," || chars[i] == "\n" { i += 1 } } |
| + mutating func peekCommand() -> Character? { |
| + skipSeparators() |
| + guard i < chars.count, chars[i].isLetter, chars[i] != "e", chars[i] != "E" else { return nil } |
| + return chars[i] |
| + } |
| + mutating func skipCommand() { i += 1 } |
| + mutating func flag() -> Bool? { |
| + skipSeparators() |
| + guard i < chars.count, chars[i] == "0" || chars[i] == "1" else { return nil } |
| + defer { i += 1 } |
| + return chars[i] == "1" |
| + } |
| + mutating func number() -> Double? { |
| + skipSeparators() |
| + var s = "" |
| + var seenDot = false, seenExp = false |
| + while i < chars.count { |
| + let c = chars[i] |
| + if c == "-" || c == "+" { |
| + if !s.isEmpty && !(s.last == "e" || s.last == "E") { break } |
| + } else if c == "." { |
| + if seenDot || seenExp { break } |
| + seenDot = true |
| + } else if c == "e" || c == "E" { |
| + if seenExp { break } |
| + seenExp = true |
| + } else if !c.isNumber { break } |
| + s.append(c); i += 1 |
| + } |
| + return Double(s) |
| + } |
| + } |
| +} |
diff --git a/native/apple/Sources/BaseKit/Look/Palette.swift b/native/apple/Sources/BaseKit/Look/Palette.swift| new file mode 100644 |
| index 0000000..51f6bb3 |
| --- /dev/null |
| +++ b/native/apple/Sources/BaseKit/Look/Palette.swift |
| @@ -0,0 +1,348 @@ |
| +import SwiftUI |
| + |
| +/// One colour as the stylesheet writes it: 0–255 channels and an alpha. |
| +public struct RGBA: Hashable, Sendable, CustomStringConvertible { |
| + public let r: Int, g: Int, b: Int |
| + public let a: Double |
| + public init(_ r: Int, _ g: Int, _ b: Int, _ a: Double = 1) { self.r = r; self.g = g; self.b = b; self.a = a } |
| + public var color: Color { Color(.sRGB, red: Double(r) / 255, green: Double(g) / 255, blue: Double(b) / 255, opacity: a) } |
| + public var description: String { "rgba(\(r),\(g),\(b),\(a))" } |
| +} |
| + |
| +/// Base's colours, light and dark: the web's tokens (internal/look/static/ |
| +/// app.css, `:root` for dark and `:root[data-theme="light"]` over it for |
| +/// light), mirrored one for one under the same names (P7). PaletteTests |
| +/// parses the stylesheet and fails on any token that differs, so the web |
| +/// and the apps can't drift apart. Every colour the apps draw is one of |
| +/// these; nothing is tuned by eye here. |
| +/// |
| +/// @Environment(\.colorScheme) private var scheme |
| +/// ... .foregroundStyle(Palette(scheme)[.frost]) |
| +public struct Palette: Sendable { |
| + public let scheme: ColorScheme |
| + public init(_ scheme: ColorScheme) { self.scheme = scheme } |
| + |
| + public subscript(_ token: Token) -> Color { rgba(token).color } |
| + public func rgba(_ token: Token) -> RGBA { (scheme == .dark ? Self.dark : Self.light)[token]! } |
| + |
| + /// `--sky-stop`: where the sky's middle colour sits on its gradient. |
| + public var skyStop: Double { scheme == .dark ? 0.62 : 0.55 } |
| + /// `--fog-1-a` to `--fog-4-a`: each bank of fog's opacity. |
| + public var fogOpacity: [Double] { scheme == .dark ? [0.5, 0.55, 0.32, 0.14] : [0.28, 0.26, 0.2, 0.55] } |
| + /// `--st-wash`: how much of a job state's colour is washed into its pill. |
| + public var stateWash: Double { scheme == .dark ? 0.2 : 0.13 } |
| + /// `--glass-lift`: the glass's shadow spread (negative: tucked under it). |
| + public var glassLift: Double { scheme == .dark ? -20 : -22 } |
| + |
| + public enum Token: String, CaseIterable, Sendable { |
| + case lagoon |
| + case orchid |
| + case ember |
| + case rose |
| + case mist |
| + case frost |
| + case haze |
| + case signal |
| + case focus |
| + case onSignal = "on-signal" |
| + case ink |
| + case sky |
| + case sky1 = "sky-1" |
| + case sky2 = "sky-2" |
| + case sky3 = "sky-3" |
| + case beam1 = "beam-1" |
| + case beam2 = "beam-2" |
| + case beam3 = "beam-3" |
| + case shine1 = "shine-1" |
| + case shine2 = "shine-2" |
| + case fog4 = "fog-4" |
| + case glass1 = "glass-1" |
| + case glass2 = "glass-2" |
| + case glassBase = "glass-base" |
| + case glassEdge = "glass-edge" |
| + case glassShine = "glass-shine" |
| + case glassShadow = "glass-shadow" |
| + case mark1 = "mark-1" |
| + case mark2 = "mark-2" |
| + case markEdge = "mark-edge" |
| + case btn |
| + case btnInk = "btn-ink" |
| + case ghost |
| + case ghostEdge = "ghost-edge" |
| + case danger |
| + case dangerInk = "danger-ink" |
| + case field |
| + case fieldEdge = "field-edge" |
| + case placeholder |
| + case well |
| + case wellEdge = "well-edge" |
| + case wellRing = "well-ring" |
| + case wellHover = "well-hover" |
| + case accentEdge = "accent-edge" |
| + case ring |
| + case ringSoft = "ring-soft" |
| + case hover |
| + case chip |
| + case chipEdge = "chip-edge" |
| + case chipHover = "chip-hover" |
| + case track |
| + case trackEdge = "track-edge" |
| + case rule |
| + case ruleStrong = "rule-strong" |
| + case alarm |
| + case alarmEdge = "alarm-edge" |
| + case tileInk = "tile-ink" |
| + case amber1 = "amber-1" |
| + case amber2 = "amber-2" |
| + case teal1 = "teal-1" |
| + case teal2 = "teal-2" |
| + case violet1 = "violet-1" |
| + case violet2 = "violet-2" |
| + case mist1 = "mist-1" |
| + case mist2 = "mist-2" |
| + case rose1 = "rose-1" |
| + case rose2 = "rose-2" |
| + case menu1 = "menu-1" |
| + case menu2 = "menu-2" |
| + case menuBase = "menu-base" |
| + case menuShine = "menu-shine" |
| + case menuShadow = "menu-shadow" |
| + case sheet1 = "sheet-1" |
| + case sheet2 = "sheet-2" |
| + case sheetBase = "sheet-base" |
| + case scrim |
| + case mine |
| + case mineEdge = "mine-edge" |
| + case theirs |
| + case theirsEdge = "theirs-edge" |
| + case card |
| + case cardEdge = "card-edge" |
| + case pill |
| + case pillEdge = "pill-edge" |
| + case pillShine = "pill-shine" |
| + case pillLift = "pill-lift" |
| + case stAsk = "st-ask" |
| + case stStop = "st-stop" |
| + case edgeA = "edge-a" |
| + case edgeB = "edge-b" |
| + case edgeHi = "edge-hi" |
| + case edgeGlowA = "edge-glow-a" |
| + case edgeGlowB = "edge-glow-b" |
| + case spkRose = "spk-rose" |
| + case spkAmber = "spk-amber" |
| + case go1 = "go-1" |
| + case go2 = "go-2" |
| + case goInk = "go-ink" |
| + case goEdge = "go-edge" |
| + case goEdgeHover = "go-edge-hover" |
| + case goShine = "go-shine" |
| + } |
| + |
| + static let dark: [Token: RGBA] = [ |
| + .lagoon: RGBA(47, 198, 192, 1), |
| + .orchid: RGBA(139, 92, 246, 1), |
| + .ember: RGBA(255, 176, 102, 1), |
| + .rose: RGBA(244, 114, 182, 1), |
| + .mist: RGBA(201, 211, 227, 1), |
| + .frost: RGBA(238, 242, 248, 1), |
| + .haze: RGBA(221, 227, 240, 1), |
| + .signal: RGBA(110, 231, 220, 1), |
| + .focus: RGBA(110, 231, 220, 1), |
| + .onSignal: RGBA(30, 39, 56, 1), |
| + .ink: RGBA(30, 39, 56, 1), |
| + .sky: RGBA(26, 31, 69, 1), |
| + .sky1: RGBA(44, 52, 112, 1), |
| + .sky2: RGBA(26, 31, 69, 1), |
| + .sky3: RGBA(22, 25, 58, 1), |
| + .beam1: RGBA(255, 214, 170, 0.42), |
| + .beam2: RGBA(255, 176, 102, 0.12), |
| + .beam3: RGBA(255, 176, 102, 0), |
| + .shine1: RGBA(238, 242, 248, 0.26), |
| + .shine2: RGBA(238, 242, 248, 0), |
| + .fog4: RGBA(201, 211, 227, 1), |
| + .glass1: RGBA(238, 242, 248, 0.07), |
| + .glass2: RGBA(238, 242, 248, 0.03), |
| + .glassBase: RGBA(14, 17, 42, 0.4), |
| + .glassEdge: RGBA(238, 242, 248, 0.18), |
| + .glassShine: RGBA(255, 255, 255, 0.22), |
| + .glassShadow: RGBA(8, 12, 22, 0.6), |
| + .mark1: RGBA(255, 255, 255, 1), |
| + .mark2: RGBA(238, 242, 248, 0.35), |
| + .markEdge: RGBA(255, 255, 255, 0.5), |
| + .btn: RGBA(238, 242, 248, 1), |
| + .btnInk: RGBA(30, 39, 56, 1), |
| + .ghost: RGBA(238, 242, 248, 0.1), |
| + .ghostEdge: RGBA(238, 242, 248, 0.22), |
| + .danger: RGBA(243, 198, 201, 1), |
| + .dangerInk: RGBA(91, 24, 32, 1), |
| + .field: RGBA(10, 16, 28, 0.28), |
| + .fieldEdge: RGBA(238, 242, 248, 0.22), |
| + .placeholder: RGBA(221, 227, 240, 1), |
| + .well: RGBA(10, 16, 28, 0.25), |
| + .wellEdge: RGBA(238, 242, 248, 0.14), |
| + .wellRing: RGBA(238, 242, 248, 0.18), |
| + .wellHover: RGBA(10, 16, 28, 0.4), |
| + .accentEdge: RGBA(110, 231, 220, 0.45), |
| + .ring: RGBA(238, 242, 248, 0.5), |
| + .ringSoft: RGBA(238, 242, 248, 0.4), |
| + .hover: RGBA(238, 242, 248, 0.1), |
| + .chip: RGBA(238, 242, 248, 0.08), |
| + .chipEdge: RGBA(238, 242, 248, 0.2), |
| + .chipHover: RGBA(238, 242, 248, 0.16), |
| + .track: RGBA(238, 242, 248, 0.12), |
| + .trackEdge: RGBA(238, 242, 248, 0.35), |
| + .rule: RGBA(238, 242, 248, 0.12), |
| + .ruleStrong: RGBA(238, 242, 248, 0.14), |
| + .alarm: RGBA(243, 198, 201, 0.12), |
| + .alarmEdge: RGBA(243, 198, 201, 0.35), |
| + .tileInk: RGBA(238, 242, 248, 1), |
| + .amber1: RGBA(226, 128, 56, 0.82), |
| + .amber2: RGBA(244, 114, 182, 0.22), |
| + .teal1: RGBA(47, 198, 192, 0.55), |
| + .teal2: RGBA(47, 198, 192, 0.12), |
| + .violet1: RGBA(139, 92, 246, 0.6), |
| + .violet2: RGBA(139, 92, 246, 0.14), |
| + .mist1: RGBA(201, 211, 227, 0.4), |
| + .mist2: RGBA(201, 211, 227, 0.08), |
| + .rose1: RGBA(244, 114, 182, 0.55), |
| + .rose2: RGBA(244, 114, 182, 0.12), |
| + .menu1: RGBA(238, 242, 248, 0.08), |
| + .menu2: RGBA(238, 242, 248, 0.04), |
| + .menuBase: RGBA(24, 28, 62, 1), |
| + .menuShine: RGBA(255, 255, 255, 0.18), |
| + .menuShadow: RGBA(8, 12, 22, 0.8), |
| + .sheet1: RGBA(238, 242, 248, 0.07), |
| + .sheet2: RGBA(238, 242, 248, 0.03), |
| + .sheetBase: RGBA(14, 17, 42, 0.62), |
| + .scrim: RGBA(10, 12, 30, 0.38), |
| + .mine: RGBA(47, 198, 192, 0.24), |
| + .mineEdge: RGBA(110, 231, 220, 0.35), |
| + .theirs: RGBA(238, 242, 248, 0.08), |
| + .theirsEdge: RGBA(238, 242, 248, 0.16), |
| + .card: RGBA(139, 92, 246, 0.16), |
| + .cardEdge: RGBA(139, 92, 246, 0.45), |
| + .pill: RGBA(238, 242, 248, 0.11), |
| + .pillEdge: RGBA(238, 242, 248, 0.26), |
| + .pillShine: RGBA(255, 255, 255, 0.2), |
| + .pillLift: RGBA(6, 8, 22, 0.55), |
| + .stAsk: RGBA(255, 176, 102, 1), |
| + .stStop: RGBA(249, 168, 212, 1), |
| + .edgeA: RGBA(110, 231, 220, 1), |
| + .edgeB: RGBA(180, 156, 252, 1), |
| + .edgeHi: RGBA(230, 255, 251, 1), |
| + .edgeGlowA: RGBA(47, 198, 192, 0.5), |
| + .edgeGlowB: RGBA(139, 92, 246, 0.45), |
| + .spkRose: RGBA(249, 168, 212, 1), |
| + .spkAmber: RGBA(255, 196, 138, 1), |
| + .go1: RGBA(10, 122, 116, 0.94), |
| + .go2: RGBA(106, 63, 214, 0.94), |
| + .goInk: RGBA(255, 255, 255, 1), |
| + .goEdge: RGBA(255, 255, 255, 0.22), |
| + .goEdgeHover: RGBA(255, 255, 255, 0.4), |
| + .goShine: RGBA(255, 255, 255, 0.35), |
| + ] |
| + |
| + static let light: [Token: RGBA] = [ |
| + .lagoon: RGBA(47, 198, 192, 1), |
| + .orchid: RGBA(139, 92, 246, 1), |
| + .ember: RGBA(255, 176, 102, 1), |
| + .rose: RGBA(244, 114, 182, 1), |
| + .mist: RGBA(201, 211, 227, 1), |
| + .frost: RGBA(30, 36, 64, 1), |
| + .haze: RGBA(74, 82, 117, 1), |
| + .signal: RGBA(15, 168, 156, 1), |
| + .focus: RGBA(10, 110, 102, 1), |
| + .onSignal: RGBA(255, 255, 255, 1), |
| + .ink: RGBA(30, 39, 56, 1), |
| + .sky: RGBA(221, 225, 243, 1), |
| + .sky1: RGBA(244, 245, 252, 1), |
| + .sky2: RGBA(232, 234, 247, 1), |
| + .sky3: RGBA(221, 225, 243, 1), |
| + .beam1: RGBA(255, 214, 170, 0.55), |
| + .beam2: RGBA(255, 190, 140, 0.18), |
| + .beam3: RGBA(255, 190, 140, 0), |
| + .shine1: RGBA(238, 242, 248, 0.26), |
| + .shine2: RGBA(238, 242, 248, 0), |
| + .fog4: RGBA(255, 255, 255, 1), |
| + .glass1: RGBA(255, 255, 255, 0.62), |
| + .glass2: RGBA(255, 255, 255, 0.42), |
| + .glassBase: RGBA(255, 255, 255, 0), |
| + .glassEdge: RGBA(255, 255, 255, 0.75), |
| + .glassShine: RGBA(255, 255, 255, 0.95), |
| + .glassShadow: RGBA(40, 46, 90, 0.35), |
| + .mark1: RGBA(42, 49, 86, 1), |
| + .mark2: RGBA(107, 115, 168, 1), |
| + .markEdge: RGBA(255, 255, 255, 0), |
| + .btn: RGBA(30, 36, 64, 1), |
| + .btnInk: RGBA(255, 255, 255, 1), |
| + .ghost: RGBA(30, 36, 64, 0.06), |
| + .ghostEdge: RGBA(30, 36, 64, 0.18), |
| + .danger: RGBA(246, 211, 214, 1), |
| + .dangerInk: RGBA(91, 24, 32, 1), |
| + .field: RGBA(255, 255, 255, 0.75), |
| + .fieldEdge: RGBA(30, 36, 64, 0.16), |
| + .placeholder: RGBA(90, 98, 133, 1), |
| + .well: RGBA(255, 255, 255, 0.6), |
| + .wellEdge: RGBA(30, 36, 64, 0.12), |
| + .wellRing: RGBA(30, 36, 64, 0.14), |
| + .wellHover: RGBA(255, 255, 255, 0.85), |
| + .accentEdge: RGBA(15, 168, 156, 0.5), |
| + .ring: RGBA(30, 36, 64, 0.35), |
| + .ringSoft: RGBA(30, 36, 64, 0.35), |
| + .hover: RGBA(30, 36, 64, 0.07), |
| + .chip: RGBA(30, 36, 64, 0.05), |
| + .chipEdge: RGBA(30, 36, 64, 0.18), |
| + .chipHover: RGBA(30, 36, 64, 0.1), |
| + .track: RGBA(30, 36, 64, 0.08), |
| + .trackEdge: RGBA(30, 36, 64, 0.3), |
| + .rule: RGBA(30, 36, 64, 0.12), |
| + .ruleStrong: RGBA(30, 36, 64, 0.12), |
| + .alarm: RGBA(243, 198, 201, 0.35), |
| + .alarmEdge: RGBA(200, 90, 100, 0.35), |
| + .tileInk: RGBA(255, 255, 255, 1), |
| + .amber1: RGBA(192, 96, 24, 0.95), |
| + .amber2: RGBA(200, 70, 130, 0.8), |
| + .teal1: RGBA(12, 136, 129, 0.95), |
| + .teal2: RGBA(16, 150, 143, 0.85), |
| + .violet1: RGBA(110, 62, 220, 0.9), |
| + .violet2: RGBA(124, 77, 232, 0.72), |
| + .mist1: RGBA(84, 96, 138, 0.88), |
| + .mist2: RGBA(100, 112, 152, 0.7), |
| + .rose1: RGBA(205, 58, 128, 0.92), |
| + .rose2: RGBA(208, 62, 132, 0.82), |
| + .menu1: RGBA(255, 255, 255, 0), |
| + .menu2: RGBA(255, 255, 255, 0), |
| + .menuBase: RGBA(251, 251, 254, 1), |
| + .menuShine: RGBA(255, 255, 255, 0.95), |
| + .menuShadow: RGBA(40, 46, 90, 0.3), |
| + .sheet1: RGBA(255, 255, 255, 0.82), |
| + .sheet2: RGBA(255, 255, 255, 0.72), |
| + .sheetBase: RGBA(244, 245, 252, 0.6), |
| + .scrim: RGBA(30, 36, 64, 0.18), |
| + .mine: RGBA(15, 168, 156, 0.14), |
| + .mineEdge: RGBA(15, 168, 156, 0.38), |
| + .theirs: RGBA(255, 255, 255, 0.88), |
| + .theirsEdge: RGBA(30, 36, 64, 0.1), |
| + .card: RGBA(139, 92, 246, 0.1), |
| + .cardEdge: RGBA(124, 77, 232, 0.35), |
| + .pill: RGBA(255, 255, 255, 0.94), |
| + .pillEdge: RGBA(30, 36, 64, 0.16), |
| + .pillShine: RGBA(255, 255, 255, 1), |
| + .pillLift: RGBA(40, 46, 90, 0.28), |
| + .stAsk: RGBA(192, 101, 26, 1), |
| + .stStop: RGBA(194, 54, 111, 1), |
| + .edgeA: RGBA(11, 122, 114, 1), |
| + .edgeB: RGBA(106, 60, 214, 1), |
| + .edgeHi: RGBA(43, 88, 200, 1), |
| + .edgeGlowA: RGBA(15, 168, 156, 0.36), |
| + .edgeGlowB: RGBA(124, 77, 232, 0.32), |
| + .spkRose: RGBA(194, 54, 111, 1), |
| + .spkAmber: RGBA(184, 100, 28, 1), |
| + .go1: RGBA(10, 122, 116, 0.94), |
| + .go2: RGBA(106, 63, 214, 0.94), |
| + .goInk: RGBA(255, 255, 255, 1), |
| + .goEdge: RGBA(255, 255, 255, 0.22), |
| + .goEdgeHover: RGBA(255, 255, 255, 0.4), |
| + .goShine: RGBA(255, 255, 255, 0.35), |
| + ] |
| +} |
diff --git a/native/apple/Sources/BaseKit/Look/Sky.swift b/native/apple/Sources/BaseKit/Look/Sky.swift| new file mode 100644 |
| index 0000000..6fd14ca |
| --- /dev/null |
| +++ b/native/apple/Sources/BaseKit/Look/Sky.swift |
| @@ -0,0 +1,234 @@ |
| +import SwiftUI |
| + |
| +/// The sky behind everything (P9): the web's atmosphere, drawn as it is in |
| +/// internal/look/static/app.css. The sky's gradient (`body`), two beams of |
| +/// warm light that sway and breathe (`.light`, `.light::after`), and four |
| +/// banks of coloured fog on their own slow paths whose colours drift |
| +/// (`.fog`, `.fog i`), on the same keyframes, periods and delays. |
| +/// |
| +/// - Drawn by a `Canvas` under a `TimelineView` at 30 fps, paused while the |
| +/// scene isn't active (a hidden window, a backgrounded app). |
| +/// - Reduce Motion holds it at the stylesheet's reduced-motion pose: no |
| +/// animation, the beam at `skewX(-14deg)`. Snapshots draw that pose too |
| +/// (`.skyFrozen()`). |
| +public struct Sky: View { |
| + @Environment(\.colorScheme) private var scheme |
| + @Environment(\.accessibilityReduceMotion) private var reduceMotion |
| + @Environment(\.skyFrozen) private var frozen |
| + @Environment(\.scenePhase) private var phase |
| + |
| + public init() {} |
| + |
| + public var body: some View { |
| + let palette = Palette(scheme) |
| + Group { |
| + if reduceMotion || frozen { |
| + Canvas { context, size in SkyPainter(palette: palette, time: nil).paint(&context, size) } |
| + } else { |
| + TimelineView(.animation(minimumInterval: 1.0 / 30, paused: phase != .active)) { timeline in |
| + Canvas { context, size in |
| + SkyPainter(palette: palette, time: timeline.date.timeIntervalSinceReferenceDate).paint(&context, size) |
| + } |
| + } |
| + } |
| + } |
| + .ignoresSafeArea() |
| + .accessibilityHidden(true) |
| + .allowsHitTesting(false) |
| + } |
| +} |
| + |
| +public extension EnvironmentValues { |
| + /// Draws the sky still, at its reduced-motion pose (snapshots, and any |
| + /// screen that must not move). |
| + @Entry var skyFrozen: Bool = false |
| +} |
| + |
| +public extension View { |
| + func skyFrozen(_ frozen: Bool = true) -> some View { environment(\.skyFrozen, frozen) } |
| +} |
| + |
| +/// One frame of the sky. `time` nil is the reduced-motion pose. |
| +struct SkyPainter { |
| + let palette: Palette |
| + let time: TimeInterval? |
| + |
| + func paint(_ context: inout GraphicsContext, _ size: CGSize) { |
| + let rect = CGRect(origin: .zero, size: size) |
| + let p = palette |
| + // html { background: var(--sky) } under body's gradient, 165°: |
| + // --sky-1 0%, --sky-2 at --sky-stop, --sky-3 100%. |
| + context.fill(Path(rect), with: .color(p[.sky])) |
| + let (start, end) = Self.cssLine(degrees: 165, in: rect) |
| + context.fill(Path(rect), with: .linearGradient( |
| + Gradient(stops: [.init(color: p[.sky1], location: 0), .init(color: p[.sky2], location: p.skyStop), .init(color: p[.sky3], location: 1)]), |
| + startPoint: start, endPoint: end)) |
| + // .light sits before .fog in the page: the fog is drawn over it. |
| + drawLight(&context, size) |
| + drawFog(&context, size) |
| + } |
| + |
| + // MARK: The light |
| + |
| + /// `.light`: top -30%, left 18%, 46% × 120% of the page, a gradient from |
| + /// --beam-1 through --beam-2 (45%) to --beam-3 (78%), blurred 40px, |
| + /// swaying from its top centre (`sway` 9s) and breathing (`breathe` |
| + /// 6s). Its `::after` (left 95%, 45% × 85% of the beam, --shine-1 into |
| + /// --shine-2 at 80%) sways on its own (13s, -4s, alternate-reverse) |
| + /// inside it, under the same blur and breath. |
| + func drawLight(_ context: inout GraphicsContext, _ size: CGSize) { |
| + let p = palette |
| + let beam = CGRect(x: size.width * 0.18, y: -size.height * 0.30, width: size.width * 0.46, height: size.height * 1.2) |
| + let shine = CGRect(x: beam.minX + beam.width * 0.95, y: beam.minY, width: beam.width * 0.45, height: beam.height * 0.85) |
| + let parent: CGAffineTransform, child: CGAffineTransform, opacity: Double |
| + if let time { |
| + let sway = Self.easeInOut(Self.progress(time, period: 9, delay: 0, reverse: false)) |
| + parent = Self.skewTranslate(beam, skew: Self.mix(-24, -4, sway), translate: Self.mix(-0.18, 0.22, sway)) |
| + let swayAfter = Self.easeInOut(Self.progress(time, period: 13, delay: -4, reverse: true)) |
| + child = Self.skewTranslate(shine, skew: Self.mix(-24, -4, swayAfter), translate: Self.mix(-0.18, 0.22, swayAfter)) |
| + opacity = Self.mix(0.45, 1, Self.easeInOut(Self.progress(time, period: 6, delay: 0, reverse: false))) |
| + } else { |
| + // @media (prefers-reduced-motion): .light { transform: skewX(-14deg) } |
| + parent = Self.skewTranslate(beam, skew: -14, translate: 0) |
| + child = .identity |
| + opacity = 1 |
| + } |
| + context.drawLayer { layer in |
| + layer.addFilter(.blur(radius: 40)) |
| + layer.opacity = opacity |
| + var beamLayer = layer |
| + beamLayer.concatenate(parent) |
| + beamLayer.fill(Path(beam), with: .linearGradient( |
| + Gradient(stops: [.init(color: p[.beam1], location: 0), .init(color: p[.beam2], location: 0.45), .init(color: p[.beam3], location: 0.78)]), |
| + startPoint: CGPoint(x: beam.midX, y: beam.minY), endPoint: CGPoint(x: beam.midX, y: beam.maxY))) |
| + var shineLayer = layer |
| + shineLayer.concatenate(child.concatenating(parent)) |
| + shineLayer.fill(Path(shine), with: .linearGradient( |
| + Gradient(stops: [.init(color: p[.shine1], location: 0), .init(color: p[.shine2], location: 0.8)]), |
| + startPoint: CGPoint(x: shine.midX, y: shine.minY), endPoint: CGPoint(x: shine.midX, y: shine.maxY))) |
| + } |
| + } |
| + |
| + // MARK: The fog |
| + |
| + struct Bank { |
| + let token: Palette.Token |
| + let width: Double, height: Double |
| + /// left (or, with `fromRight`, right) and bottom, in % of the fog's box. |
| + let x: Double, bottom: Double |
| + let fromRight: Bool |
| + let path: [(tx: Double, ty: Double, scale: Double)] |
| + let period: Double, delay: Double |
| + let reverse: Bool |
| + } |
| + |
| + static let pathA: [(tx: Double, ty: Double, scale: Double)] = [(-0.18, 0.06, 0.9), (0.14, -0.28, 1.25), (0.36, 0.04, 1)] |
| + static let pathB: [(tx: Double, ty: Double, scale: Double)] = [(0.16, -0.04, 1.1), (-0.20, 0.22, 0.85), (-0.38, -0.14, 1.2)] |
| + static let pathC: [(tx: Double, ty: Double, scale: Double)] = [(0.10, 0.10, 0.8), (-0.32, -0.40, 1.3), (0.28, -0.18, 1)] |
| + |
| + /// `.fog i:nth-child(1…4)`. |
| + static let banks: [Bank] = [ |
| + Bank(token: .lagoon, width: 0.62, height: 0.34, x: -0.04, bottom: 0.10, fromRight: false, path: pathA, period: 12, delay: 0, reverse: false), |
| + Bank(token: .orchid, width: 0.58, height: 0.36, x: -0.06, bottom: 0.20, fromRight: true, path: pathB, period: 15, delay: -5, reverse: false), |
| + Bank(token: .rose, width: 0.36, height: 0.22, x: 0.40, bottom: 0.02, fromRight: false, path: pathC, period: 10, delay: -3, reverse: false), |
| + Bank(token: .fog4, width: 0.70, height: 0.18, x: 0.10, bottom: 0.30, fromRight: false, path: pathB, period: 17, delay: -9, reverse: true), |
| + ] |
| + |
| + /// `.fog`: inset -20% of the page, its colours turning (`tint`, 18s, |
| + /// hue-rotate -20° to 28°); each bank an ellipse blurred 56px. |
| + func drawFog(_ context: inout GraphicsContext, _ size: CGSize) { |
| + let box = CGRect(x: -size.width * 0.2, y: -size.height * 0.2, width: size.width * 1.4, height: size.height * 1.4) |
| + let opacities = palette.fogOpacity |
| + context.drawLayer { fog in |
| + if let time { |
| + let tint = Self.easeInOut(Self.progress(time, period: 18, delay: 0, reverse: false)) |
| + fog.addFilter(.hueRotation(.degrees(Self.mix(-20, 28, tint)))) |
| + } |
| + for (index, bank) in Self.banks.enumerated() { |
| + let w = box.width * bank.width, h = box.height * bank.height |
| + let x = bank.fromRight ? box.maxX - box.width * bank.x - w : box.minX + box.width * bank.x |
| + let y = box.maxY - box.height * bank.bottom - h |
| + var frame = CGRect(x: x, y: y, width: w, height: h) |
| + if let time { |
| + let t = Self.progress(time, period: bank.period, delay: bank.delay, reverse: bank.reverse) |
| + let pose = Self.keyframe(bank.path, t) |
| + // translate(tx%, ty%) of its own box, then scale about its centre. |
| + let centre = CGPoint(x: frame.midX + w * pose.tx, y: frame.midY + h * pose.ty) |
| + frame = CGRect(x: centre.x - w * pose.scale / 2, y: centre.y - h * pose.scale / 2, width: w * pose.scale, height: h * pose.scale) |
| + } |
| + fog.drawLayer { bankLayer in |
| + bankLayer.addFilter(.blur(radius: 56)) |
| + bankLayer.opacity = opacities[index] |
| + bankLayer.fill(Path(ellipseIn: frame), with: .color(palette[bank.token])) |
| + } |
| + } |
| + } |
| + } |
| + |
| + // MARK: CSS animation, as a browser runs it |
| + |
| + /// Where an `ease-in-out infinite` animation is within its keyframes at |
| + /// `time`: 0…1, running `alternate` (or `alternate-reverse`), `delay` |
| + /// seconds in (negative: started that long before). |
| + static func progress(_ time: TimeInterval, period: Double, delay: Double, reverse: Bool) -> Double { |
| + let elapsed = time - delay |
| + let cycles = elapsed / period |
| + let iteration = floor(cycles) |
| + var p = cycles - iteration |
| + let backwards = (Int(iteration) % 2 != 0) != reverse |
| + if backwards { p = 1 - p } |
| + return p |
| + } |
| + |
| + /// A three-keyframe path (0%, 50%, 100%) at progress `t`, each half |
| + /// eased (`ease-in-out`). |
| + static func keyframe(_ path: [(tx: Double, ty: Double, scale: Double)], _ t: Double) -> (tx: Double, ty: Double, scale: Double) { |
| + let (a, b, local) = t < 0.5 ? (path[0], path[1], t / 0.5) : (path[1], path[2], (t - 0.5) / 0.5) |
| + let e = easeInOut(local) |
| + return (mix(a.tx, b.tx, e), mix(a.ty, b.ty, e), mix(a.scale, b.scale, e)) |
| + } |
| + |
| + /// Between two keyframes' values (`from`, `to`) at eased progress t. |
| + static func mix(_ a: Double, _ b: Double, _ t: Double) -> Double { a + (b - a) * t } |
| + |
| + /// `skewX(deg) translateX(t × width)` about the box's top centre |
| + /// (`transform-origin: 50% 0`). |
| + static func skewTranslate(_ box: CGRect, skew degrees: Double, translate: Double) -> CGAffineTransform { |
| + let origin = CGPoint(x: box.midX, y: box.minY) |
| + let skew = CGAffineTransform(a: 1, b: 0, c: CGFloat(tan(degrees * .pi / 180)), d: 1, tx: 0, ty: 0) |
| + return CGAffineTransform(translationX: -origin.x + box.width * translate, y: -origin.y) |
| + .concatenating(skew) |
| + .concatenating(CGAffineTransform(translationX: origin.x, y: origin.y)) |
| + } |
| + |
| + /// `cubic-bezier(.42, 0, .58, 1)` at x. |
| + static func easeInOut(_ x: Double) -> Double { cubicBezier(x, 0.42, 0, 0.58, 1) } |
| + |
| + static func cubicBezier(_ x: Double, _ x1: Double, _ y1: Double, _ x2: Double, _ y2: Double) -> Double { |
| + if x <= 0 { return 0 } |
| + if x >= 1 { return 1 } |
| + func sample(_ t: Double, _ a1: Double, _ a2: Double) -> Double { |
| + let u = 1 - t |
| + return 3 * u * u * t * a1 + 3 * u * t * t * a2 + t * t * t |
| + } |
| + var lo = 0.0, hi = 1.0, t = x |
| + for _ in 0..<30 { |
| + let v = sample(t, x1, x2) |
| + if abs(v - x) < 1e-6 { break } |
| + if v < x { lo = t } else { hi = t } |
| + t = (lo + hi) / 2 |
| + } |
| + return sample(t, y1, y2) |
| + } |
| + |
| + /// A CSS linear-gradient's line for `degrees` (0° up, clockwise) over |
| + /// `rect`: through its centre, as long as the box's projection on it. |
| + static func cssLine(degrees: Double, in rect: CGRect) -> (CGPoint, CGPoint) { |
| + let a = degrees * .pi / 180 |
| + let dx = sin(a), dy = -cos(a) |
| + let half = (abs(rect.width * dx) + abs(rect.height * dy)) / 2 |
| + let c = CGPoint(x: rect.midX, y: rect.midY) |
| + // Screen y runs down, as CSS's does: (sin, -cos) is already the line. |
| + return (CGPoint(x: c.x - dx * half, y: c.y - dy * half), CGPoint(x: c.x + dx * half, y: c.y + dy * half)) |
| + } |
| +} |
diff --git a/native/apple/Sources/BaseKit/Look/Type.swift b/native/apple/Sources/BaseKit/Look/Type.swift| new file mode 100644 |
| index 0000000..c97d903 |
| --- /dev/null |
| +++ b/native/apple/Sources/BaseKit/Look/Type.swift |
| @@ -0,0 +1,99 @@ |
| +import CoreText |
| +import Foundation |
| +import Synchronization |
| +import SwiftUI |
| + |
| +/// Base's faces (P8). Timeless Sans is one variable file with two cuts on |
| +/// its STYL axis: Grotesk (STYL 0) for headings and the wordmark, Sans |
| +/// (STYL 100) for everything else, as the web sets it (`h1, h2, .wordmark` |
| +/// at STYL 0; the body at 100). The file is fetched, never committed |
| +/// (`make fonts`); without it the app is set in DM Sans, as the web is. |
| +/// |
| +/// `register()` runs at launch, before the first frame, so nothing ever |
| +/// paints in a fallback face while the file is there (no FOUT). |
| +public enum BaseFonts { |
| + public enum Face: Sendable, Equatable { case timeless, dmSans, system } |
| + |
| + /// The bundled faces: BaseKit's Resources/Fonts, filled by |
| + /// scripts/fonts-into-bundle.sh. |
| + public static var bundled: URL? { Bundle.module.url(forResource: "Fonts", withExtension: nil) } |
| + |
| + private static let state = Mutex<(face: Face, registered: Set<String>)>((.system, [])) |
| + |
| + /// The face in use: Timeless Sans once registered, DM Sans without it, |
| + /// the system's before anything is registered. |
| + public static var face: Face { state.withLock { $0.face } } |
| + |
| + /// Registers Timeless Sans from `directory`, or DM Sans when it is not |
| + /// there, for this process. Idempotent; never throws or traps: a |
| + /// missing or unreadable file falls back, and with neither file the app |
| + /// is set in the system face. |
| + @discardableResult |
| + public static func register(from directory: URL? = bundled) -> Face { |
| + let candidates: [(Face, String)] = [(.timeless, "TimelessSansVF.woff2"), (.dmSans, "DMSans-VF.woff2")] |
| + for (face, file) in candidates { |
| + guard let url = directory?.appendingPathComponent(file), FileManager.default.fileExists(atPath: url.path) else { continue } |
| + if registerFile(url) { |
| + state.withLock { $0.face = face } |
| + return face |
| + } |
| + } |
| + state.withLock { $0.face = .system } |
| + return .system |
| + } |
| + |
| + private static func registerFile(_ url: URL) -> Bool { |
| + if state.withLock({ $0.registered.contains(url.path) }) { return true } |
| + var error: Unmanaged<CFError>? |
| + let ok = CTFontManagerRegisterFontsForURL(url as CFURL, .process, &error) |
| + // Already registered by an earlier call in this process: usable. |
| + let already = (error?.takeRetainedValue()).map { CFErrorGetCode($0) == CTFontManagerError.alreadyRegistered.rawValue } ?? false |
| + guard ok || already else { return false } |
| + state.withLock { _ = $0.registered.insert(url.path) } |
| + return true |
| + } |
| + |
| + /// The PostScript name of a named instance: Timeless Sans's cuts and |
| + /// weights, or DM Sans's. |
| + static func postScriptName(grotesk: Bool, weight: BaseFont.Weight, face: Face) -> String? { |
| + switch face { |
| + case .timeless: return "TimelessSans-\(grotesk ? "Grotesk" : "Sans")\(weight.timeless)" |
| + case .dmSans: return "DMSans-9ptRegular_\(weight.dmSans)" |
| + case .system: return nil |
| + } |
| + } |
| +} |
| + |
| +/// The type scale. Sizes are the web's in points; each scales with Dynamic |
| +/// Type from its text style, as the system's own fonts do. |
| +public enum BaseFont { |
| + public enum Weight: Sendable, CaseIterable { |
| + case regular, medium, semibold, bold |
| + var timeless: String { |
| + switch self { case .regular: "Regular"; case .medium: "Medium"; case .semibold: "Semibold"; case .bold: "Bold" } |
| + } |
| + var dmSans: String { |
| + switch self { case .regular: "Regular"; case .medium: "Medium"; case .semibold: "SemiBold"; case .bold: "Bold" } |
| + } |
| + var system: Font.Weight { |
| + switch self { case .regular: .regular; case .medium: .medium; case .semibold: .semibold; case .bold: .bold } |
| + } |
| + } |
| + |
| + /// The Grotesk cut: headings and the wordmark. |
| + public static func heading(_ size: CGFloat, _ weight: Weight = .semibold, relativeTo style: Font.TextStyle = .title3) -> Font { |
| + font(size, weight, grotesk: true, style) |
| + } |
| + |
| + /// The Sans cut: everything else. |
| + public static func body(_ size: CGFloat, _ weight: Weight = .regular, relativeTo style: Font.TextStyle = .body) -> Font { |
| + font(size, weight, grotesk: false, style) |
| + } |
| + |
| + static func font(_ size: CGFloat, _ weight: Weight, grotesk: Bool, _ style: Font.TextStyle) -> Font { |
| + guard let name = BaseFonts.postScriptName(grotesk: grotesk, weight: weight, face: BaseFonts.face) else { |
| + return .system(size: size, weight: weight.system) |
| + } |
| + return .custom(name, size: size, relativeTo: style) |
| + } |
| +} |
diff --git a/native/apple/Tests/BaseKitTests/LookTests.swift b/native/apple/Tests/BaseKitTests/LookTests.swift| new file mode 100644 |
| index 0000000..10e0272 |
| --- /dev/null |
| +++ b/native/apple/Tests/BaseKitTests/LookTests.swift |
| @@ -0,0 +1,63 @@ |
| +@testable import BaseKit |
| +import SwiftUI |
| +import XCTest |
| + |
| +/// The sky's motion is the stylesheet's: its keyframes, eased, alternating. |
| +final class LookTests: XCTestCase { |
| + func testEaseInOutIsCSSs() { |
| + XCTAssertEqual(SkyPainter.easeInOut(0), 0) |
| + XCTAssertEqual(SkyPainter.easeInOut(1), 1) |
| + XCTAssertEqual(SkyPainter.easeInOut(0.5), 0.5, accuracy: 1e-4) |
| + // cubic-bezier(.42,0,.58,1) at 0.25 is about 0.129. |
| + XCTAssertEqual(SkyPainter.easeInOut(0.25), 0.129, accuracy: 0.002) |
| + } |
| + |
| + func testAlternatingProgress() { |
| + // sway 9s alternate: out on the first pass, back on the second. |
| + XCTAssertEqual(SkyPainter.progress(0, period: 9, delay: 0, reverse: false), 0, accuracy: 1e-9) |
| + XCTAssertEqual(SkyPainter.progress(4.5, period: 9, delay: 0, reverse: false), 0.5, accuracy: 1e-9) |
| + XCTAssertEqual(SkyPainter.progress(13.5, period: 9, delay: 0, reverse: false), 0.5, accuracy: 1e-9) |
| + XCTAssertEqual(SkyPainter.progress(12, period: 9, delay: 0, reverse: false), 2.0 / 3, accuracy: 1e-9) |
| + // A negative delay starts it part-way; alternate-reverse starts backwards. |
| + XCTAssertEqual(SkyPainter.progress(0, period: 15, delay: -5, reverse: false), 1.0 / 3, accuracy: 1e-9) |
| + XCTAssertEqual(SkyPainter.progress(0, period: 13, delay: -4, reverse: true), 1 - 4.0 / 13, accuracy: 1e-9) |
| + } |
| + |
| + func testKeyframesHitTheirStops() { |
| + let a = SkyPainter.pathA |
| + let start = SkyPainter.keyframe(a, 0), middle = SkyPainter.keyframe(a, 0.5), end = SkyPainter.keyframe(a, 1) |
| + XCTAssertEqual(start.tx, -0.18, accuracy: 1e-9); XCTAssertEqual(start.scale, 0.9, accuracy: 1e-9) |
| + XCTAssertEqual(middle.ty, -0.28, accuracy: 1e-9); XCTAssertEqual(middle.scale, 1.25, accuracy: 1e-9) |
| + XCTAssertEqual(end.tx, 0.36, accuracy: 1e-9); XCTAssertEqual(end.scale, 1, accuracy: 1e-9) |
| + } |
| + |
| + func testCSSGradientLine() { |
| + // 180deg runs top to bottom through the centre. |
| + let (s, e) = SkyPainter.cssLine(degrees: 180, in: CGRect(x: 0, y: 0, width: 100, height: 50)) |
| + XCTAssertEqual(s.x, 50, accuracy: 1e-9); XCTAssertEqual(s.y, 0, accuracy: 1e-9) |
| + XCTAssertEqual(e.x, 50, accuracy: 1e-9); XCTAssertEqual(e.y, 50, accuracy: 1e-9) |
| + // 165deg: down and a little right. |
| + let (_, e2) = SkyPainter.cssLine(degrees: 165, in: CGRect(x: 0, y: 0, width: 100, height: 100)) |
| + XCTAssertGreaterThan(e2.x, 50); XCTAssertGreaterThan(e2.y, 95) |
| + } |
| + |
| + func testIconsParse() { |
| + for icon in [BaseIcon.asking, .ready, .done, .stopped, .arrowOut, .close, .send] { |
| + let bounds = icon.path(in: CGRect(x: 0, y: 0, width: 24, height: 24)).boundingRect |
| + XCTAssertFalse(bounds.isEmpty && bounds.width == 0 && bounds.height == 0, "\(icon) drew nothing") |
| + XCTAssertTrue(CGRect(x: 0, y: 0, width: 24, height: 24).insetBy(dx: -1, dy: -1).contains(bounds), "\(icon) leaves its box: \(bounds)") |
| + } |
| + // The question mark's arc (a2.9 2.9 0 0 1 5.6 1) ends where the curve starts. |
| + let asking = BaseIcon.asking.path(in: CGRect(x: 0, y: 0, width: 24, height: 24)).boundingRect |
| + XCTAssertEqual(asking.minX, 9.2, accuracy: 0.05) |
| + XCTAssertEqual(asking.maxX, 14.8, accuracy: 0.6) |
| + } |
| + |
| + func testAppearanceFromTheServer() { |
| + XCTAssertEqual(BaseAppearance(server: "dark").colorScheme, .dark) |
| + XCTAssertEqual(BaseAppearance(server: "light").colorScheme, .light) |
| + XCTAssertNil(BaseAppearance(server: "system").colorScheme) |
| + XCTAssertEqual(BaseAppearance(server: "sepia"), .system) |
| + XCTAssertEqual(BaseAppearance(server: nil), .system) |
| + } |
| +} |
diff --git a/native/apple/Tests/BaseKitTests/PaletteTests.swift b/native/apple/Tests/BaseKitTests/PaletteTests.swift| new file mode 100644 |
| index 0000000..ffea31a |
| --- /dev/null |
| +++ b/native/apple/Tests/BaseKitTests/PaletteTests.swift |
| @@ -0,0 +1,83 @@ |
| +@testable import BaseKit |
| +import SwiftUI |
| +import XCTest |
| + |
| +/// P7: the apps' palette is the web's. Reads internal/look/static/app.css |
| +/// (`:root` holds every token's dark value; `:root[data-theme="light"]` |
| +/// the light values over it) and fails on any token Palette mirrors that |
| +/// differs, or any colour token it doesn't mirror. |
| +final class PaletteTests: XCTestCase { |
| + static let stylesheet = URL(fileURLWithPath: #filePath) |
| + .deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent() |
| + .deletingLastPathComponent().deletingLastPathComponent() |
| + .appendingPathComponent("internal/look/static/app.css") |
| + |
| + struct Sheet { |
| + var dark: [String: String] = [:] |
| + var light: [String: String] = [:] |
| + } |
| + |
| + static func read() throws -> Sheet { |
| + let css = try String(contentsOf: stylesheet, encoding: .utf8) |
| + func declarations(_ selector: String) throws -> [String: String] { |
| + guard let open = css.range(of: selector + " {"), let close = css[open.upperBound...].firstIndex(of: "}") else { |
| + throw XCTSkip("no \(selector) block in app.css") |
| + } |
| + var body = String(css[open.upperBound..<close]) |
| + body = body.replacingOccurrences(of: #"/\*[\s\S]*?\*/"#, with: "", options: .regularExpression) |
| + var out: [String: String] = [:] |
| + let regex = try NSRegularExpression(pattern: #"--([a-z0-9-]+)\s*:\s*([^;]+);"#) |
| + for match in regex.matches(in: body, range: NSRange(body.startIndex..., in: body)) { |
| + out[String(body[Range(match.range(at: 1), in: body)!])] = String(body[Range(match.range(at: 2), in: body)!]).trimmingCharacters(in: .whitespaces) |
| + } |
| + return out |
| + } |
| + var sheet = Sheet() |
| + sheet.dark = try declarations(":root") |
| + sheet.light = sheet.dark.merging(try declarations(#":root[data-theme="light"]"#)) { $1 } |
| + return sheet |
| + } |
| + |
| + static func parse(_ value: String) -> RGBA? { |
| + let v = value.trimmingCharacters(in: .whitespaces) |
| + if v.hasPrefix("#"), v.count == 7, let hex = Int(v.dropFirst(), radix: 16) { |
| + return RGBA(hex >> 16 & 0xFF, hex >> 8 & 0xFF, hex & 0xFF, 1) |
| + } |
| + if v.hasPrefix("rgb"), let open = v.firstIndex(of: "("), let close = v.lastIndex(of: ")") { |
| + let parts = v[v.index(after: open)..<close].split(separator: ",").map { $0.trimmingCharacters(in: .whitespaces) } |
| + guard parts.count >= 3, let r = Int(parts[0]), let g = Int(parts[1]), let b = Int(parts[2]) else { return nil } |
| + let a = parts.count == 4 ? Double(parts[3]) ?? -1 : 1 |
| + return RGBA(r, g, b, a) |
| + } |
| + return nil |
| + } |
| + |
| + func testEveryMirroredTokenMatchesTheStylesheet() throws { |
| + let sheet = try Self.read() |
| + XCTAssertGreaterThan(sheet.dark.count, 90, "app.css's :root looks too small to be the real one") |
| + for token in Palette.Token.allCases { |
| + for (scheme, values) in [(ColorScheme.dark, sheet.dark), (.light, sheet.light)] { |
| + guard let raw = values[token.rawValue] else { XCTFail("--\(token.rawValue) is not in app.css"); continue } |
| + XCTAssertEqual(Palette(scheme).rgba(token), Self.parse(raw), "--\(token.rawValue) (\(scheme)) is \(raw) on the web") |
| + } |
| + } |
| + } |
| + |
| + func testEveryColourTokenIsMirrored() throws { |
| + let sheet = try Self.read() |
| + let mirrored = Set(Palette.Token.allCases.map(\.rawValue)) |
| + let colours = sheet.dark.filter { Self.parse($0.value) != nil }.map(\.key) |
| + XCTAssertEqual(Set(colours).subtracting(mirrored), [], "colour tokens the apps don't mirror") |
| + } |
| + |
| + func testTheNumbersMatchTheStylesheet() throws { |
| + let sheet = try Self.read() |
| + for (scheme, values) in [(ColorScheme.dark, sheet.dark), (.light, sheet.light)] { |
| + let p = Palette(scheme) |
| + XCTAssertEqual(p.skyStop * 100, Double(values["sky-stop"]!.dropLast())!, accuracy: 0.001) |
| + XCTAssertEqual(p.fogOpacity, (1...4).map { Double(values["fog-\($0)-a"]!)! }) |
| + XCTAssertEqual(p.stateWash, Double(values["st-wash"]!)!) |
| + XCTAssertEqual(p.glassLift, Double(values["glass-lift"]!.dropLast(2))!) |
| + } |
| + } |
| +} |
diff --git a/native/apple/Tests/BaseKitTests/TypeTests.swift b/native/apple/Tests/BaseKitTests/TypeTests.swift| new file mode 100644 |
| index 0000000..3fdf35a |
| --- /dev/null |
| +++ b/native/apple/Tests/BaseKitTests/TypeTests.swift |
| @@ -0,0 +1,58 @@ |
| +@testable import BaseKit |
| +import CoreText |
| +import SwiftUI |
| +import XCTest |
| + |
| +/// P8: Timeless Sans registers before first use and both cuts resolve; |
| +/// without it, DM Sans, and with neither the system face, never a crash. |
| +final class TypeTests: XCTestCase { |
| + override func tearDown() { BaseFonts.register() } |
| + |
| + private func axis(_ name: String, _ tag: Int) -> Double? { |
| + let font = CTFontCreateWithName(name as CFString, 16, nil) |
| + let variation = CTFontCopyVariation(font) as? [NSNumber: NSNumber] |
| + return variation?[NSNumber(value: tag)]?.doubleValue |
| + } |
| + |
| + func testTimelessRegistersAndBothCutsResolve() throws { |
| + let bundled = try XCTUnwrap(BaseFonts.bundled) |
| + guard FileManager.default.fileExists(atPath: bundled.appendingPathComponent("TimelessSansVF.woff2").path) else { |
| + throw XCTSkip("no Timeless Sans in this build (make fonts fetches it): the fallback tests cover it") |
| + } |
| + XCTAssertEqual(BaseFonts.register(), .timeless) |
| + XCTAssertEqual(BaseFonts.register(), .timeless, "registering twice is harmless") |
| + let styl = 0x5354_594C // 'STYL' |
| + for weight in BaseFont.Weight.allCases { |
| + for grotesk in [true, false] { |
| + let name = try XCTUnwrap(BaseFonts.postScriptName(grotesk: grotesk, weight: weight, face: .timeless)) |
| + let font = CTFontCreateWithName(name as CFString, 16, nil) |
| + XCTAssertEqual(CTFontCopyPostScriptName(font) as String, name, "\(name) does not resolve") |
| + XCTAssertEqual(CTFontCopyFamilyName(font) as String, "Timeless Sans") |
| + // Grotesk is STYL 0, Sans STYL 100 (app.css's font-variation-settings). |
| + if let value = axis(name, styl) { XCTAssertEqual(value, grotesk ? 0 : 100, name) } |
| + } |
| + } |
| + } |
| + |
| + func testDMSansWhenTimelessIsAbsent() throws { |
| + let bundled = try XCTUnwrap(BaseFonts.bundled) |
| + let dir = FileManager.default.temporaryDirectory.appendingPathComponent("base-fonts-\(UUID().uuidString)") |
| + try FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true) |
| + defer { try? FileManager.default.removeItem(at: dir) } |
| + try FileManager.default.copyItem(at: bundled.appendingPathComponent("DMSans-VF.woff2"), to: dir.appendingPathComponent("DMSans-VF.woff2")) |
| + XCTAssertEqual(BaseFonts.register(from: dir), .dmSans) |
| + for weight in BaseFont.Weight.allCases { |
| + let name = try XCTUnwrap(BaseFonts.postScriptName(grotesk: true, weight: weight, face: .dmSans)) |
| + XCTAssertEqual(CTFontCopyPostScriptName(CTFontCreateWithName(name as CFString, 16, nil)) as String, name) |
| + } |
| + _ = BaseFont.heading(20) |
| + } |
| + |
| + func testNoFaceAtAllIsTheSystemsAndNoCrash() throws { |
| + let empty = FileManager.default.temporaryDirectory.appendingPathComponent("base-fonts-empty-\(UUID().uuidString)") |
| + XCTAssertEqual(BaseFonts.register(from: empty), .system) |
| + XCTAssertEqual(BaseFonts.register(from: nil), .system) |
| + _ = BaseFont.body(15) |
| + _ = BaseFont.heading(20, .medium) |
| + } |
| +} |
diff --git a/native/apple/Tests/BaseSnapshots/BaseSnapshots.swift b/native/apple/Tests/BaseSnapshots/BaseSnapshots.swift| deleted file mode 100644 |
| index c2fecf9..0000000 |
| --- a/native/apple/Tests/BaseSnapshots/BaseSnapshots.swift |
| +++ /dev/null |
| @@ -1,9 +0,0 @@ |
| -import XCTest |
| - |
| -/// The screenshot gate (Task 9 draws its screens). scripts/snapshots.sh runs |
| -/// it; plain `swift test` skips it. |
| -final class BaseSnapshots: XCTestCase { |
| - func testKeyScreens() throws { |
| - try XCTSkipUnless(ProcessInfo.processInfo.environment["RASTRILLO_SNAPSHOTS"] != nil, "Run with native/scripts/snapshots.sh") |
| - } |
| -} |
diff --git a/native/apple/Tests/BaseSnapshots/LookSnapshots.swift b/native/apple/Tests/BaseSnapshots/LookSnapshots.swift| new file mode 100644 |
| index 0000000..f4299a5 |
| --- /dev/null |
| +++ b/native/apple/Tests/BaseSnapshots/LookSnapshots.swift |
| @@ -0,0 +1,108 @@ |
| +import BaseKit |
| +import Foundation |
| +import RastrilloSnapshots |
| +import SwiftUI |
| +import XCTest |
| + |
| +/// Base's look for the screenshot gate (Task 9): the sky at its still pose, |
| +/// the three surfaces over it, the type scale and the marks, in light and |
| +/// dark (and on iPhone at AX3). `native/scripts/snapshots.sh` runs it; |
| +/// `swift test` alone skips it, because baselines match only the OS that |
| +/// drew them. The fonts are registered first, or the baselines would |
| +/// record the system face. |
| +final class LookSnapshots: XCTestCase { |
| + @MainActor func testLook() async throws { |
| + try XCTSkipUnless(ProcessInfo.processInfo.environment["RASTRILLO_SNAPSHOTS"] != nil, "Run with native/scripts/snapshots.sh") |
| + BaseFonts.register() |
| + await assertSnapshots(of: Self.catalog) |
| + await assertSnapshots(of: Self.typeCatalog) |
| + } |
| + |
| + static let tint = Color(red: 0x6E / 255, green: 0xE7 / 255, blue: 0xDC / 255) |
| + |
| + @MainActor static var catalog: SnapshotCatalog { |
| + // Nothing here holds text that grows: light and dark at the default |
| + // size only (each picture of the sky is a few hundred kilobytes). |
| + SnapshotCatalog(app: "base-look", variants: [.init(.light, .standard), .init(.dark, .standard)], |
| + settings: SnapshotSettings(tint: tint), screens: [ |
| + SnapshotScreen("sky", mac: .fixed(width: 640, height: 400), iphone: .fixed(width: 402, height: 874)) { |
| + Sky().skyFrozen() |
| + }, |
| + SnapshotScreen("surfaces", mac: .fixed(width: 720, height: 420), iphone: .fixed(width: 402, height: 760)) { |
| + ZStack { Sky(); SurfacesSample().padding(24) }.skyFrozen() |
| + }, |
| + SnapshotScreen("marks", mac: .fixed(width: 520, height: 160), iphone: .fixed(width: 402, height: 200)) { |
| + ZStack { Sky(); MarksSample().padding(20) }.skyFrozen() |
| + }, |
| + ]) |
| + } |
| + |
| + /// The type scale, at the accessibility size too. |
| + @MainActor static var typeCatalog: SnapshotCatalog { |
| + SnapshotCatalog(app: "base-type", settings: SnapshotSettings(tint: tint), screens: [ |
| + SnapshotScreen("type", mac: .fixed(width: 640, height: 560), iphone: .width(402, minHeight: 700)) { |
| + ZStack { Sky(); TypeSample().padding(20) }.skyFrozen() |
| + }, |
| + ]) |
| + } |
| +} |
| + |
| +/// Fixture words: what each surface carries in the mockups. |
| +struct SurfacesSample: View { |
| + @Environment(\.colorScheme) private var scheme |
| + var body: some View { |
| + let p = Palette(scheme) |
| + ViewThatFits(in: .horizontal) { |
| + HStack(alignment: .top, spacing: 18) { cards(p) } |
| + VStack(alignment: .leading, spacing: 18) { cards(p) } |
| + } |
| + .foregroundStyle(p[.frost]) |
| + } |
| + |
| + @ViewBuilder func cards(_ p: Palette) -> some View { |
| + card(title: "Glass", line: "The sidebar and the phone's buttons").glass(cornerRadius: 18) |
| + card(title: "Sheet", line: "The conversation, the Settings window").glassSheet(cornerRadius: 18) |
| + card(title: "Solid", line: "Menus and the job view").solid(cornerRadius: 16) |
| + } |
| + |
| + func card(title: String, line: String) -> some View { |
| + VStack(alignment: .leading, spacing: 6) { |
| + Text(verbatim: title).font(BaseFont.heading(17)) |
| + Text(verbatim: line).font(BaseFont.body(14)).foregroundStyle(Palette(scheme)[.haze]) |
| + } |
| + .padding(16) |
| + .frame(width: 200, alignment: .leading) |
| + } |
| +} |
| + |
| +struct TypeSample: View { |
| + @Environment(\.colorScheme) private var scheme |
| + var body: some View { |
| + let p = Palette(scheme) |
| + VStack(alignment: .leading, spacing: 10) { |
| + HStack(spacing: 9) { BaseMark(size: 18); Text(verbatim: "Base").font(BaseFont.heading(24)) } |
| + Text(verbatim: "Sign in to Base").font(BaseFont.heading(30, .medium, relativeTo: .largeTitle)) |
| + Text(verbatim: "Ask Base").font(BaseFont.heading(20, .medium, relativeTo: .title3)) |
| + Text(verbatim: "Christmas order form").font(BaseFont.heading(16, .semibold, relativeTo: .headline)) |
| + Text(verbatim: "Use your Oficina ID, the same one as Docs, Sheets and Calls.").font(BaseFont.body(17)) |
| + Text(verbatim: "On it. You'll see a first look in a couple of minutes, with the menu from your Sheets.").font(BaseFont.body(15)) |
| + Text(verbatim: "Bakery website · Building a first look").font(BaseFont.body(13.5, .semibold, relativeTo: .subheadline)) |
| + Text(verbatim: "Started 5 minutes ago").font(BaseFont.body(13, relativeTo: .footnote)).foregroundStyle(p[.haze]) |
| + } |
| + .foregroundStyle(p[.frost]) |
| + .padding(20) |
| + .frame(maxWidth: .infinity, alignment: .leading) |
| + .glassSheet(cornerRadius: 18) |
| + } |
| +} |
| + |
| +struct MarksSample: View { |
| + var body: some View { |
| + HStack(spacing: 14) { |
| + BaseMark(size: 18) |
| + ForEach(JobState.allCases, id: \.self) { StateMark($0) } |
| + } |
| + .padding(16) |
| + .glass(cornerRadius: 999) |
| + } |
| +} |
diff --git a/native/apple/Tests/BaseSnapshots/__Snapshots__/base-look/iphone/ENVIRONMENT b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-look/iphone/ENVIRONMENT| new file mode 100644 |
| index 0000000..a26fa8a |
| --- /dev/null |
| +++ b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-look/iphone/ENVIRONMENT |
| @@ -0,0 +1,10 @@ |
| +os: iOS 27.0.0 |
| +device: iPhone19,2 |
| +runtime: 27.0 (24A434) |
| +toolchain: Xcode 27.2 Build version 27B52 |
| +language: en |
| +locale: en_IE |
| +time zone: Europe/Dublin |
| +increase contrast: off |
| +reduce transparency: off |
| +differentiate without colour: off |
diff --git a/native/apple/Tests/BaseSnapshots/__Snapshots__/base-look/iphone/marks-dark-default.png b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-look/iphone/marks-dark-default.png| new file mode 100644 |
| index 0000000..1a2cba6 |
| Binary files /dev/null and b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-look/iphone/marks-dark-default.png differ |
diff --git a/native/apple/Tests/BaseSnapshots/__Snapshots__/base-look/iphone/marks-light-default.png b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-look/iphone/marks-light-default.png| new file mode 100644 |
| index 0000000..8a21610 |
| Binary files /dev/null and b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-look/iphone/marks-light-default.png differ |
diff --git a/native/apple/Tests/BaseSnapshots/__Snapshots__/base-look/iphone/sky-dark-default.png b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-look/iphone/sky-dark-default.png| new file mode 100644 |
| index 0000000..1459628 |
| Binary files /dev/null and b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-look/iphone/sky-dark-default.png differ |
diff --git a/native/apple/Tests/BaseSnapshots/__Snapshots__/base-look/iphone/sky-light-default.png b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-look/iphone/sky-light-default.png| new file mode 100644 |
| index 0000000..ce569ae |
| Binary files /dev/null and b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-look/iphone/sky-light-default.png differ |
diff --git a/native/apple/Tests/BaseSnapshots/__Snapshots__/base-look/iphone/surfaces-dark-default.png b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-look/iphone/surfaces-dark-default.png| new file mode 100644 |
| index 0000000..78dfe41 |
| Binary files /dev/null and b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-look/iphone/surfaces-dark-default.png differ |
diff --git a/native/apple/Tests/BaseSnapshots/__Snapshots__/base-look/iphone/surfaces-light-default.png b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-look/iphone/surfaces-light-default.png| new file mode 100644 |
| index 0000000..b34f9d8 |
| Binary files /dev/null and b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-look/iphone/surfaces-light-default.png differ |
diff --git a/native/apple/Tests/BaseSnapshots/__Snapshots__/base-look/mac/ENVIRONMENT b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-look/mac/ENVIRONMENT| new file mode 100644 |
| index 0000000..2a04923 |
| --- /dev/null |
| +++ b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-look/mac/ENVIRONMENT |
| @@ -0,0 +1,9 @@ |
| +os: macOS 27.0.0 |
| +toolchain: Xcode 27.2 Build version 27B52 |
| +language: en |
| +accent: #007AFF |
| +locale: en_IE |
| +time zone: Europe/Dublin |
| +increase contrast: off |
| +reduce transparency: off |
| +differentiate without colour: off |
diff --git a/native/apple/Tests/BaseSnapshots/__Snapshots__/base-look/mac/marks-dark-default.png b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-look/mac/marks-dark-default.png| new file mode 100644 |
| index 0000000..caad3da |
| Binary files /dev/null and b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-look/mac/marks-dark-default.png differ |
diff --git a/native/apple/Tests/BaseSnapshots/__Snapshots__/base-look/mac/marks-light-default.png b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-look/mac/marks-light-default.png| new file mode 100644 |
| index 0000000..0846e76 |
| Binary files /dev/null and b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-look/mac/marks-light-default.png differ |
diff --git a/native/apple/Tests/BaseSnapshots/__Snapshots__/base-look/mac/sky-dark-default.png b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-look/mac/sky-dark-default.png| new file mode 100644 |
| index 0000000..36b8114 |
| Binary files /dev/null and b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-look/mac/sky-dark-default.png differ |
diff --git a/native/apple/Tests/BaseSnapshots/__Snapshots__/base-look/mac/sky-light-default.png b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-look/mac/sky-light-default.png| new file mode 100644 |
| index 0000000..b25aeb3 |
| Binary files /dev/null and b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-look/mac/sky-light-default.png differ |
diff --git a/native/apple/Tests/BaseSnapshots/__Snapshots__/base-look/mac/surfaces-dark-default.png b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-look/mac/surfaces-dark-default.png| new file mode 100644 |
| index 0000000..c1cb20a |
| Binary files /dev/null and b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-look/mac/surfaces-dark-default.png differ |
diff --git a/native/apple/Tests/BaseSnapshots/__Snapshots__/base-look/mac/surfaces-light-default.png b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-look/mac/surfaces-light-default.png| new file mode 100644 |
| index 0000000..8b12bfb |
| Binary files /dev/null and b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-look/mac/surfaces-light-default.png differ |
diff --git a/native/apple/Tests/BaseSnapshots/__Snapshots__/base-type/iphone/ENVIRONMENT b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-type/iphone/ENVIRONMENT| new file mode 100644 |
| index 0000000..a26fa8a |
| --- /dev/null |
| +++ b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-type/iphone/ENVIRONMENT |
| @@ -0,0 +1,10 @@ |
| +os: iOS 27.0.0 |
| +device: iPhone19,2 |
| +runtime: 27.0 (24A434) |
| +toolchain: Xcode 27.2 Build version 27B52 |
| +language: en |
| +locale: en_IE |
| +time zone: Europe/Dublin |
| +increase contrast: off |
| +reduce transparency: off |
| +differentiate without colour: off |
diff --git a/native/apple/Tests/BaseSnapshots/__Snapshots__/base-type/iphone/type-dark-ax3.png b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-type/iphone/type-dark-ax3.png| new file mode 100644 |
| index 0000000..6e8d5a1 |
| Binary files /dev/null and b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-type/iphone/type-dark-ax3.png differ |
diff --git a/native/apple/Tests/BaseSnapshots/__Snapshots__/base-type/iphone/type-dark-default.png b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-type/iphone/type-dark-default.png| new file mode 100644 |
| index 0000000..1b22b59 |
| Binary files /dev/null and b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-type/iphone/type-dark-default.png differ |
diff --git a/native/apple/Tests/BaseSnapshots/__Snapshots__/base-type/iphone/type-light-ax3.png b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-type/iphone/type-light-ax3.png| new file mode 100644 |
| index 0000000..2847017 |
| Binary files /dev/null and b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-type/iphone/type-light-ax3.png differ |
diff --git a/native/apple/Tests/BaseSnapshots/__Snapshots__/base-type/iphone/type-light-default.png b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-type/iphone/type-light-default.png| new file mode 100644 |
| index 0000000..457e606 |
| Binary files /dev/null and b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-type/iphone/type-light-default.png differ |
diff --git a/native/apple/Tests/BaseSnapshots/__Snapshots__/base-type/mac/ENVIRONMENT b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-type/mac/ENVIRONMENT| new file mode 100644 |
| index 0000000..2a04923 |
| --- /dev/null |
| +++ b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-type/mac/ENVIRONMENT |
| @@ -0,0 +1,9 @@ |
| +os: macOS 27.0.0 |
| +toolchain: Xcode 27.2 Build version 27B52 |
| +language: en |
| +accent: #007AFF |
| +locale: en_IE |
| +time zone: Europe/Dublin |
| +increase contrast: off |
| +reduce transparency: off |
| +differentiate without colour: off |
diff --git a/native/apple/Tests/BaseSnapshots/__Snapshots__/base-type/mac/type-dark-default.png b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-type/mac/type-dark-default.png| new file mode 100644 |
| index 0000000..68a48ab |
| Binary files /dev/null and b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-type/mac/type-dark-default.png differ |
diff --git a/native/apple/Tests/BaseSnapshots/__Snapshots__/base-type/mac/type-light-default.png b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-type/mac/type-light-default.png| new file mode 100644 |
| index 0000000..c2052c1 |
| Binary files /dev/null and b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-type/mac/type-light-default.png differ |
diff --git a/native/scripts/snapshots.sh b/native/scripts/snapshots.sh| new file mode 100755 |
| index 0000000..7af0247 |
| --- /dev/null |
| +++ b/native/scripts/snapshots.sh |
| @@ -0,0 +1,45 @@ |
| +#!/bin/sh |
| +# Base's screenshot gate (rastrillo/native RastrilloSnapshots): the look |
| +# (the sky at its still pose, the surfaces, the type scale, the marks) and |
| +# Ask (the mockups' thread, its states and cards), light and dark, and on |
| +# iPhone at the default size and AX3. |
| +# |
| +# native/scripts/snapshots.sh [compare|record] [mac|iphone|all] |
| +# |
| +# compare (the default) fails on any changed, missing or stale picture; |
| +# record redraws the baselines in apple/Tests/BaseSnapshots/__Snapshots__/. |
| +# Review the contact sheets, apple/.build/snapshots/base-*/index.html, |
| +# before committing a recording, beside the approved mockups |
| +# (.superpowers/mockups/native/, git-ignored). |
| +# |
| +# Not in .amadan/ci.d: baselines are exact only on the OS and simulator |
| +# runtime that drew them (ENVIRONMENT beside them says which). The runner |
| +# scripts are rastrillo/native's own, from the pinned checkout; the iPhone |
| +# half runs on its "Rastrillo Snapshots" simulator under its lock. Drawn |
| +# with Timeless Sans when `make fonts` has fetched it; a run without it |
| +# draws DM Sans, and fails against baselines drawn in Timeless. |
| +set -eu |
| +cd "$(dirname "$0")/.." |
| +mode=${1:-compare} |
| +platforms=${2:-all} |
| +case "$mode" in compare|record) ;; *) echo "usage: $0 [compare|record] [mac|iphone|all]" >&2; exit 2 ;; esac |
| +case "$platforms" in mac|iphone|all) ;; *) echo "usage: $0 [compare|record] [mac|iphone|all]" >&2; exit 2 ;; esac |
| +scripts/fonts-into-bundle.sh |
| +swift package --package-path apple resolve |
| +shared=${OFICINA_NATIVE_PACKAGE_PATH:-apple/.build/checkouts/native} |
| +case "$shared" in /*) ;; *) shared="$(pwd)/$shared" ;; esac |
| +tools="$shared/tools" |
| + |
| +failed=0 |
| +case "$platforms" in mac|all) |
| + (cd apple && swift build --build-tests) |
| + if ! (cd apple && "$tools/snapshots-mac.sh" "$mode" BaseSnapshots); then failed=1; fi ;; |
| +esac |
| +case "$platforms" in iphone|all) |
| + xcodegen generate --spec ios/project.yml |
| + if ! (cd apple && SNAPSHOT_DERIVED_DATA=.build/xcode "$tools/snapshots-iphone.sh" "$mode" BasePhoneSnapshots BasePhoneSnapshots \ |
| + -project ../ios/BasePhone.xcodeproj -test-timeouts-enabled YES -default-test-execution-time-allowance 120); then |
| + failed=1 |
| + fi ;; |
| +esac |
| +exit "$failed" |