Open source CapCut alternative.
TypeScript
feat(ios): the camera's guide is the editor's red short-form keep-out behind one button
David Le0a2a2385c349
diff --git a/apps/ios/DonkeyKit/Sources/DonkeyKitModels/CameraModel.swift b/apps/ios/DonkeyKit/Sources/DonkeyKitModels/CameraModel.swiftindex 461cc203..86db2148 100644--- a/apps/ios/DonkeyKit/Sources/DonkeyKitModels/CameraModel.swift+++ b/apps/ios/DonkeyKit/Sources/DonkeyKitModels/CameraModel.swift@@ -41,13 +41,12 @@ public final class CameraModel {}}- /// The short-form platforms whose covered areas shade the picture. Kept- /// across sessions: a person who posts to one place frames for it every- /// time.- public private(set) var safeZones: Set<SafeZonePlatform> = [] {+ /// Whether the short-form guide shades the picture. Kept across+ /// sessions: a person who posts vertical video frames for it every time.+ public private(set) var showsSafeZones = false {didSet {- if safeZones != oldValue {- defaults.set(safeZones.map(\.rawValue).sorted(), forKey: Self.safeZonesKey)+ if showsSafeZones != oldValue {+ defaults.set(showsSafeZones, forKey: Self.safeZonesKey)}}}@@ -58,7 +57,7 @@ public final class CameraModel {private let defaults: UserDefaultsprivate static let teleprompterKey = "teleprompterSettings"- private static let safeZonesKey = "safeZonePlatforms"+ private static let safeZonesKey = "showsSafeZones"public init(defaults: UserDefaults = .standard) {self.defaults = defaults@@ -66,17 +65,11 @@ public final class CameraModel {let settings = try? JSONDecoder().decode(TeleprompterSettings.self, from: data) {teleprompter.settings = settings}- if let stored = defaults.stringArray(forKey: Self.safeZonesKey) {- safeZones = Set(stored.compactMap(SafeZonePlatform.init(rawValue:)))- }+ showsSafeZones = defaults.bool(forKey: Self.safeZonesKey)}- public func toggleSafeZone(_ platform: SafeZonePlatform) {- if safeZones.contains(platform) {- safeZones.remove(platform)- } else {- safeZones.insert(platform)- }+ public func toggleSafeZones() {+ showsSafeZones.toggle()}private func persistTeleprompterSettings() {diff --git a/apps/ios/DonkeyKit/Sources/DonkeyKitModels/SafeZones.swift b/apps/ios/DonkeyKit/Sources/DonkeyKitModels/SafeZones.swiftindex 3f3bc106..17b1f6de 100644--- a/apps/ios/DonkeyKit/Sources/DonkeyKitModels/SafeZones.swift+++ b/apps/ios/DonkeyKit/Sources/DonkeyKitModels/SafeZones.swift@@ -1,44 +1,23 @@import Foundation-/// A short-form platform whose own chrome covers part of a vertical frame:-/// the bar across the top, the caption block along the bottom, the action-/// column down the right edge. Whatever a shot needs stays out of them.-nonisolated public enum SafeZonePlatform: String, CaseIterable, Codable, Sendable, Identifiable {- case tiktok, reels, shorts+/// The short-form guide: the parts of a vertical frame that TikTok, Reels+/// and Shorts cover with their own UI or crop away, merged into one keep-out+/// so each region is the widest of the three. It is the same guide the+/// editor's preview draws, measured September 2026 on a 1170×2532 phone and+/// mapped onto a 1080×1920 frame: the top band is the status bar and the+/// search row under it, the rail the actions from the avatar down, the+/// bottom band the username, caption and music line, and the side strips+/// what Reels and Shorts crop when they fill a taller phone screen.+nonisolated public enum ShortFormGuide {+ private static func phone(_ px: Double, of total: Double) -> Double { px / total }- public var id: String { rawValue }-- public var title: String {- switch self {- case .tiktok: "TikTok"- case .reels: "Reels"- case .shorts: "Shorts"- }- }-- /// The covered parts of a 9:16 frame, as fractions of its width and- /// height. The numbers approximate each platform's layout on a phone;- /// the platforms move their chrome now and then, so these are tuned by- /// eye against a current phone.- public var covered: [SafeZoneRegion] {- switch self {- case .tiktok: [- SafeZoneRegion(x: 0, y: 0, width: 1, height: 0.11),- SafeZoneRegion(x: 0, y: 0.76, width: 1, height: 0.24),- SafeZoneRegion(x: 0.87, y: 0.36, width: 0.13, height: 0.40),- ]- case .reels: [- SafeZoneRegion(x: 0, y: 0, width: 1, height: 0.12),- SafeZoneRegion(x: 0, y: 0.74, width: 1, height: 0.26),- SafeZoneRegion(x: 0.86, y: 0.40, width: 0.14, height: 0.34),- ]- case .shorts: [- SafeZoneRegion(x: 0, y: 0, width: 1, height: 0.09),- SafeZoneRegion(x: 0, y: 0.78, width: 1, height: 0.22),- SafeZoneRegion(x: 0.87, y: 0.44, width: 0.13, height: 0.34),- ]- }- }+ public static let boxes: [SafeZoneRegion] = [+ SafeZoneRegion(x: 0, y: 0, width: 1, height: phone(215, of: 1920), label: "Top bar"),+ SafeZoneRegion(x: 0, y: 0, width: phone(50, of: 1080), height: 1, label: "Cropped"),+ SafeZoneRegion(x: 1 - phone(50, of: 1080), y: 0, width: phone(50, of: 1080), height: 1, label: "Cropped"),+ SafeZoneRegion(x: phone(895, of: 1080), y: phone(730, of: 1920), width: phone(185, of: 1080), height: phone(730, of: 1920), label: "Actions"),+ SafeZoneRegion(x: 0, y: phone(1460, of: 1920), width: 1, height: phone(460, of: 1920), label: "Caption · music · nav"),+ ]}/// A rectangle in a frame's own units: every value is a fraction of the@@ -48,12 +27,14 @@ nonisolated public struct SafeZoneRegion: Equatable, Sendable {public var y: Doublepublic var width: Doublepublic var height: Double+ public var label: String- public init(x: Double, y: Double, width: Double, height: Double) {+ public init(x: Double, y: Double, width: Double, height: Double, label: String) {self.x = xself.y = yself.width = widthself.height = height+ self.label = label}}diff --git a/apps/ios/DonkeyKit/Sources/DonkeyKitUI/CameraScreen.swift b/apps/ios/DonkeyKit/Sources/DonkeyKitUI/CameraScreen.swiftindex 5cb602b7..e2120c92 100644--- a/apps/ios/DonkeyKit/Sources/DonkeyKitUI/CameraScreen.swift+++ b/apps/ios/DonkeyKit/Sources/DonkeyKitUI/CameraScreen.swift@@ -22,7 +22,6 @@ struct CameraScreen<CameraPreview: View>: View {@State private var showsZoomPicker = false@State private var showsQualityPopover = false@State private var showsTeleSettings = false- @State private var showsSafeZones = false@State private var showsNotePicker = false@State private var playingRecording: Recording?/// The take that just finished, docked in the corner until it is watched@@ -62,8 +61,8 @@ struct CameraScreen<CameraPreview: View>: View {stage// Short-form chrome is shaded on the picture itself, under the// script and the controls, so a take is framed against it too.- if !camera.safeZones.isEmpty, !isSideways, camera.availability == .running {- SafeZoneOverlay(platforms: camera.safeZones)+ if camera.showsSafeZones, !isSideways, camera.availability == .running {+ SafeZoneOverlay()}if camera.isFillLightOn, camera.availability == .running {FillLightOverlay()@@ -298,20 +297,13 @@ struct CameraScreen<CameraPreview: View>: View {.glassEffect(camera.teleprompter.isCardShown || camera.teleprompter.isRunning ? .regular.tint(.white.opacity(0.25)).interactive() : .regular.interactive())Button {- showsSafeZones.toggle()- showsZoomPicker = false- showsQualityPopover = false+ camera.toggleSafeZones()} label: {Image(systemName: "rectangle.dashed").frame(width: 40, height: 40)}- .glassEffect(camera.safeZones.isEmpty ? .regular.interactive() : .regular.tint(.white.opacity(0.25)).interactive())- .popover(isPresented: $showsSafeZones, arrowEdge: .leading) {- safeZonePopover- .presentationCompactAdaptation(.popover)- .preferredColorScheme(.dark)- .presentationBackground(Color.black.opacity(0.78))- }+ .glassEffect(camera.showsSafeZones ? .regular.tint(.white.opacity(0.25)).interactive() : .regular.interactive())+ .accessibilityLabel(camera.showsSafeZones ? "Hide short-form guide" : "Show short-form guide")Spacer().frame(height: 10)@@ -411,22 +403,6 @@ struct CameraScreen<CameraPreview: View>: View {.frame(minWidth: 280)}- private var safeZonePopover: some View {- VStack(alignment: .leading, spacing: 12) {- Text("Safe Zones")- .font(.footnote)- .foregroundStyle(.secondary)- ForEach(SafeZonePlatform.allCases) { platform in- Toggle(platform.title, isOn: Binding(- get: { camera.safeZones.contains(platform) },- set: { _ in camera.toggleSafeZone(platform) }- ))- }- }- .padding(16)- .frame(minWidth: 220)- }-private var resolutionBinding: Binding<CaptureResolution> {Binding(get: { camera.settings.resolution },@@ -504,48 +480,73 @@ private struct CaptureFlight: View {/// A bright frame around the preview: the screen fill light for cameras/// without a torch.-/// Shades the parts of the recorded frame a platform's chrome will cover.-/// The picture fills the screen, so the frame is wider than the screen in-/// portrait and the regions are placed against the frame, not the screen.+/// The short-form guide over the picture, drawn the way the editor's+/// preview draws it: each keep-out box a red wash under a diagonal hatch,+/// a dashed red edge, and its name in white. The picture fills the screen,+/// so the 9:16 frame is wider than the screen in portrait and every box is+/// placed against the frame, not the screen.struct SafeZoneOverlay: View {- let platforms: Set<SafeZonePlatform>-private static let verticalAspect = 9.0 / 16.0+ private static let red = Color(red: 239 / 255, green: 68 / 255, blue: 68 / 255)var body: some View {- GeometryReader { geometry in+ Canvas { context, size inlet frame = FrameRect.aspectFill(contentAspect: Self.verticalAspect,- containerWidth: geometry.size.width,- containerHeight: geometry.size.height+ containerWidth: size.width,+ containerHeight: size.height)- let shown = SafeZonePlatform.allCases.filter(platforms.contains)- ZStack(alignment: .topLeading) {- ForEach(Array(shown.enumerated()), id: \.element) { index, platform in- ForEach(Array(platform.covered.enumerated()), id: \.offset) { _, region in- Rectangle()- .fill(.black.opacity(0.22))- .overlay(Rectangle().strokeBorder(.white.opacity(0.4), lineWidth: 1))- .frame(width: region.width * frame.width, height: region.height * frame.height)- .offset(x: frame.x + region.x * frame.width, y: frame.y + region.y * frame.height)+ let labelSize = max(9, min(12, frame.width / 36))+ for box in ShortFormGuide.boxes {+ let rect = CGRect(+ x: frame.x + box.x * frame.width,+ y: frame.y + box.y * frame.height,+ width: box.width * frame.width,+ height: box.height * frame.height+ )+ context.fill(Path(rect), with: .color(Self.red.opacity(0.12)))+ context.drawLayer { hatch in+ hatch.clip(to: Path(rect))+ var lines = Path()+ // Diagonals eight points apart, running up and to the+ // right across the whole box.+ let span = rect.width + rect.height+ var start = -rect.height+ while start < span {+ lines.move(to: CGPoint(x: rect.minX + start, y: rect.maxY))+ lines.addLine(to: CGPoint(x: rect.minX + start + rect.height, y: rect.minY))+ start += 8 * 2.squareRoot()}- // The name sits at the top of the caption block, one row- // per platform, so overlapping shades still read.- if let bottom = platform.covered.dropFirst().first {- Text(platform.title)- .font(.caption2.weight(.semibold))- .foregroundStyle(.white.opacity(0.8))- .padding(.horizontal, 6)- .padding(.vertical, 2)- .background(.black.opacity(0.4), in: Capsule())- .offset(- x: max(frame.x, 0) + 8,- y: frame.y + bottom.y * frame.height + 6 + CGFloat(index) * 22- )+ hatch.stroke(lines, with: .color(Self.red.opacity(0.45)), lineWidth: 1.5)+ }+ context.stroke(+ Path(rect.insetBy(dx: 0.5, dy: 0.5)),+ with: .color(Self.red.opacity(0.8)),+ style: StrokeStyle(lineWidth: 1, dash: [4, 3])+ )+ // A full-width band names itself at its inner edge; a rail at+ // its top, where the keep-out meets the picture. A strip too+ // narrow for its label runs the label down its length.+ let fullWidth = box.width >= 0.99+ let narrow = rect.width <= 40 && rect.height > 120+ guard narrow || (rect.width > 40 && rect.height > labelSize * 2) else { continue }+ let text = Text(box.label)+ .font(.system(size: labelSize, weight: .semibold))+ .foregroundStyle(.white)+ var label = context.resolve(text)+ label.shading = .color(.white)+ let measured = label.measure(in: CGSize(width: 400, height: 40))+ if narrow {+ context.drawLayer { turned in+ turned.translateBy(x: rect.midX, y: rect.minY + 8)+ turned.rotate(by: .degrees(90))+ turned.draw(label, at: CGPoint(x: 0, y: 0), anchor: .topLeading)}+ } else {+ let y = fullWidth && box.y <= 0.01 ? rect.maxY - 5 - measured.height : rect.minY + 4+ context.draw(label, at: CGPoint(x: max(rect.minX, 0) + 6, y: y), anchor: .topLeading)}}- .frame(width: geometry.size.width, height: geometry.size.height, alignment: .topLeading)}.ignoresSafeArea().allowsHitTesting(false)diff --git a/apps/ios/DonkeyKit/Tests/DonkeyKitModelsTests/DonkeyKitModelsTests.swift b/apps/ios/DonkeyKit/Tests/DonkeyKitModelsTests/DonkeyKitModelsTests.swiftindex 8e971165..62c6f00a 100644--- a/apps/ios/DonkeyKit/Tests/DonkeyKitModelsTests/DonkeyKitModelsTests.swift+++ b/apps/ios/DonkeyKit/Tests/DonkeyKitModelsTests/DonkeyKitModelsTests.swift@@ -75,14 +75,22 @@ import Testing#expect(frame.y < 0)}- @Test func everyPlatformKeepsRegionsInsideTheFrame() {- for platform in SafeZonePlatform.allCases {- for region in platform.covered {- #expect(region.x >= 0 && region.x + region.width <= 1)- #expect(region.y >= 0 && region.y + region.height <= 1)- }+ @Test func theGuideKeepsEveryBoxInsideTheFrame() {+ for region in ShortFormGuide.boxes {+ #expect(region.x >= 0 && region.x + region.width <= 1 + 1e-9)+ #expect(region.y >= 0 && region.y + region.height <= 1 + 1e-9)+ #expect(!region.label.isEmpty)}}++ @Test func theGuideTogglesAndIsRemembered() {+ let defaults = UserDefaults(suiteName: "guide-\(UUID())")!+ let camera = CameraModel(defaults: defaults)+ #expect(!camera.showsSafeZones)+ camera.toggleSafeZones()+ #expect(camera.showsSafeZones)+ #expect(CameraModel(defaults: defaults).showsSafeZones)+ }}@Suite struct ZoomTests {diff --git a/docs/guides/ios-app.md b/docs/guides/ios-app.mdindex 6e17bb1d..575d5484 100644--- a/docs/guides/ios-app.md+++ b/docs/guides/ios-app.md@@ -131,10 +131,10 @@ viewfinder.The camera shoots whichever way the phone is held: turn it sideways and thetake is a landscape file, with the shutter across on the trailing edge.-A rail button shades the parts of a vertical frame that TikTok, Reels or-Shorts cover with their own chrome, placed against the recorded frame rather-than the screen, kept across sessions, and drawn under the script so a take-is framed against them too.+A rail button under the teleprompter toggles the short-form guide: the same+red keep-out the editor's preview draws for TikTok, Reels and Shorts, placed+against the recorded frame rather than the screen, kept across sessions, and+drawn under the script so a take is framed against it too.## The Watch