Skip to content

armgit / cra

Public Imported from GitHub
0

The open-source Arc replacement for macOS. Spaces, pinned tabs, split view, Little Windows and Arc's shortcuts on Chromium, with your Arc sidebar imported in one go.

Peek grows out of the clicked link and closes back into it, as Arc's does (#204)

Victorfc14398ee92f
diff --git a/Packages/CraCore/Sources/CraCore/PeekLayout.swift b/Packages/CraCore/Sources/CraCore/PeekLayout.swift
index fc1b7bd..f485c38 100644
--- a/Packages/CraCore/Sources/CraCore/PeekLayout.swift
+++ b/Packages/CraCore/Sources/CraCore/PeekLayout.swift
@@ -1,4 +1,5 @@
import CoreGraphics
+import Foundation
/// Where Arc's Peek card and its buttons go in a browser window (y up, as in AppKit).
///
@@ -7,8 +8,13 @@ import CoreGraphics
/// card's), 80 % of its width (1105 of 1381 pt), 12 pt in from the window's top and bottom. Close,
/// Expand and Add To Split are 34 × 33 pt round buttons in a column 13 pt right of the card, the
/// first 7 pt below its top, 43.5 pt apart. The page behind fades to 28 %, the card has 8 pt corners
-/// and a 32 pt bar. It opens from the area's full size to its own and closes the same way back,
-/// fading as it goes (the timings below).
+/// and a 32 pt bar.
+///
+/// The motion (Arc 1.171, offline Arc, small links in two corners, 60 fps recordings, 6 Nov 2026,
+/// GitHub #204): the card grows out of the clicked link and closes back into it. A picture of the
+/// link fills the card's frame at first and fades out over it; closing, it fades back in as the card
+/// lands on the link. The 3 Nov run that read "from the whole area" used a page that was one big
+/// link, so the link was the area. Arc 1.172 only moved Chromium.
public enum PeekLayout {
public static let widthFraction: CGFloat = 0.8
public static let verticalInset: CGFloat = 12
@@ -21,27 +27,167 @@ public enum PeekLayout {
public static let buttonCount = 3
/// The page under a Peek (Arc: 233/240/254 → 178/172/151 over the window's background).
public static let pageAlpha: CGFloat = 0.28
- /// Arc's open, measured frame by frame at 60 fps (3 Nov 2026): the card's opacity reaches 1 in
- /// 0.075 s; its scale, from the whole area (1 / widthFraction) to 1 about its centre, follows an
- /// ease-out cubic over 0.205 s starting a frame in; the page fades to `pageAlpha` on an ease-out
- /// cubic over 0.18 s. The buttons ride the card's top-right corner and fade with it.
+ /// Arc's open, frame by frame at 60 fps, from the start of the link picture's fade: the picture
+ /// fades out on an ease-out over 0.075 s (0.40, 0.21, 0.065 a frame apart). The frame's centre
+ /// and width go from the link's to the card's on an ease-out cubic over 0.205 s from 0.016 s;
+ /// its height lags, on an ease-out cubic over 0.21 s from 0.028 s. The page fades to
+ /// `pageAlpha` on an ease-out cubic over 0.18 s. The buttons fade in once the picture is gone.
public static let openFadeDuration: Double = 0.075
public static let openScaleDelay: Double = 0.016
public static let openScaleDuration: Double = 0.205
+ public static let openHeightDelay: Double = 0.028
+ public static let openHeightDuration: Double = 0.21
+ public static let openButtonsDelay: Double = 0.075
+ public static let openButtonsDuration: Double = 0.06
public static let openVeilDuration: Double = 0.18
- /// Arc's close: back out to the whole area in 0.12 s (near linear), fading from 0.07 s for
- /// 0.09 s, while the page comes back over 0.2 s.
- public static let closeScaleDuration: Double = 0.12
+ /// Arc's close: the frame goes back to the link in 0.16 s (near linear, width and height
+ /// together; 0.12 s when the link was the whole area, a much shorter way), the link picture
+ /// fading back in from 0.07 s for 0.09 s, the buttons gone in 0.05 s, while the page comes
+ /// back over 0.2 s.
+ public static let closeScaleDuration: Double = 0.16
+ public static let closeToAreaDuration: Double = 0.12
public static let closeFadeDelay: Double = 0.07
public static let closeFadeDuration: Double = 0.09
+ public static let closeButtonsDuration: Double = 0.05
public static let closeVeilDuration: Double = 0.2
- /// The scale that makes the card cover the whole area's width.
- public static let areaScale: CGFloat = 1 / widthFraction
+ /// How long the whole open runs.
+ public static var openDuration: Double {
+ max(openScaleDelay + openScaleDuration, openHeightDelay + openHeightDuration, openButtonsDelay + openButtonsDuration)
+ }
+
+ /// A CSS-style cubic Bézier timing curve from (0, 0) to (1, 1).
+ public struct Curve: Sendable, Equatable {
+ public let x1, y1, x2, y2: Double
+ public init(_ x1: Double, _ y1: Double, _ x2: Double, _ y2: Double) { (self.x1, self.y1, self.x2, self.y2) = (x1, y1, x2, y2) }
+
+ public static let easeOut = Curve(0, 0, 0.58, 1)
+ public static let easeOutCubic = Curve(0.215, 0.61, 0.355, 1)
+ /// Arc's near-linear way back.
+ public static let close = Curve(0.25, 0.25, 0.5, 1)
+
+ /// Progress at `u` (time, 0…1, clamped).
+ public func callAsFunction(_ u: Double) -> Double {
+ let u = min(max(u, 0), 1)
+ if u == 0 || u == 1 { return u }
+ func bez(_ t: Double, _ a: Double, _ b: Double) -> Double { 3 * a * t * (1 - t) * (1 - t) + 3 * b * t * t * (1 - t) + t * t * t }
+ // Bisection: x(t) rises monotonically for control x's in 0…1.
+ var lo = 0.0, hi = 1.0, t = u
+ for _ in 0..<40 {
+ t = (lo + hi) / 2
+ if bez(t, x1, x2) < u { lo = t } else { hi = t }
+ }
+ return bez(t, y1, y2)
+ }
+ }
+
+ /// `curve` run over `duration` from `delay`, at time `t`.
+ static func progress(_ t: Double, delay: Double, duration: Double, _ curve: Curve) -> Double {
+ duration > 0 ? curve((t - delay) / duration) : (t >= delay ? 1 : 0)
+ }
+
+ /// Between `source` and `card`: the centre and width `p` of the way, the height `q`.
+ public static func frame(from source: CGRect, to card: CGRect, p: Double, q: Double) -> CGRect {
+ let p = CGFloat(p), q = CGFloat(q)
+ let cx = source.midX + (card.midX - source.midX) * p, cy = source.midY + (card.midY - source.midY) * p
+ let w = source.width + (card.width - source.width) * p, h = source.height + (card.height - source.height) * q
+ return CGRect(x: cx - w / 2, y: cy - h / 2, width: w, height: h)
+ }
+
+ /// One moment of a Peek's motion: the card's frame, the link picture's and the buttons' opacity.
+ public struct Moment: Equatable, Sendable {
+ public var frame: CGRect
+ public var sourceOpacity: Double
+ public var buttonsOpacity: Double
+ public init(frame: CGRect, sourceOpacity: Double, buttonsOpacity: Double) {
+ (self.frame, self.sourceOpacity, self.buttonsOpacity) = (frame, sourceOpacity, buttonsOpacity)
+ }
+ }
+
+ /// The open, `t` seconds in, growing from `source` (the link) to `card`.
+ public static func opening(from source: CGRect, to card: CGRect, at t: Double) -> Moment {
+ let p = progress(t, delay: openScaleDelay, duration: openScaleDuration, .easeOutCubic)
+ let q = progress(t, delay: openHeightDelay, duration: openHeightDuration, .easeOutCubic)
+ return Moment(frame: frame(from: source, to: card, p: p, q: q),
+ sourceOpacity: 1 - progress(t, delay: 0, duration: openFadeDuration, .easeOut),
+ buttonsOpacity: progress(t, delay: openButtonsDelay, duration: openButtonsDuration, .easeOut))
+ }
+
+ /// The close, `t` seconds in, from `card` back into `source`.
+ public static func closing(from card: CGRect, to source: CGRect, at t: Double, duration: Double = closeScaleDuration) -> Moment {
+ let p = progress(t, delay: 0, duration: duration, .close)
+ return Moment(frame: frame(from: card, to: source, p: p, q: p),
+ sourceOpacity: progress(t, delay: closeFadeDelay, duration: closeFadeDuration, .easeOut),
+ buttonsOpacity: 1 - progress(t, delay: 0, duration: closeButtonsDuration, .easeOut))
+ }
+
+ /// How long the whole close runs.
+ public static func closeDuration(scale: Double = closeScaleDuration) -> Double { max(scale, closeFadeDelay + closeFadeDuration) }
+
+ /// The page's picture inside `frame` (in the frame's own coordinates, y up): Arc scales it by the
+ /// frame's width against the card's and pins it to the frame's top-left; the frame clips the rest.
+ public static func content(in frame: CGRect, card: CGRect) -> CGRect {
+ let s = card.width > 0 ? frame.width / card.width : 1
+ return CGRect(x: 0, y: frame.height - card.height * s, width: card.width * s, height: card.height * s)
+ }
+
+ /// The button column beside `frame`: scaled like the page, its top `buttonTop` under the frame's
+ /// top and its left edge `buttonGap` (scaled) right of the frame, as in Arc.
+ public static func column(_ column: CGRect, card: CGRect, frame: CGRect) -> CGRect {
+ let s = card.width > 0 ? frame.width / card.width : 1
+ let w = column.width * s, h = column.height * s
+ let top = frame.maxY - (card.maxY - column.maxY)
+ return CGRect(x: frame.maxX + (column.minX - card.maxX) * s, y: top - h, width: w, height: h)
+ }
+
+ /// Where a link is (`fraction` of the page's view, y down, as a page script measures it) in
+ /// the view `page` (y up), kept on the page; nil when it isn't there.
+ public static func source(fraction: CGRect, in page: CGRect) -> CGRect? {
+ guard fraction.width > 0, fraction.height > 0, fraction.minX.isFinite, fraction.minY.isFinite,
+ fraction.width.isFinite, fraction.height.isFinite else { return nil }
+ let r = CGRect(x: page.minX + fraction.minX * page.width, y: page.maxY - fraction.maxY * page.height,
+ width: fraction.width * page.width, height: fraction.height * page.height).intersection(page)
+ return r.isNull || r.width < 1 || r.height < 1 ? nil : r
+ }
+
+ /// The page script that finds the link a Peek opens from: the link under `pointer` (fractions
+ /// of the view, y down; nil without one), else the focused one (Return on a link). Its answer
+ /// is the link's rect in fractions of the visual viewport, or null. It keeps the link for
+ /// `sourceAgainScript`. Runs in Cra's isolated world, where the page can't replace the DOM's
+ /// functions.
+ public static func sourceScript(pointer: CGPoint?) -> String {
+ let x = pointer.map { "\(Double($0.x))" } ?? "NaN", y = pointer.map { "\(Double($0.y))" } ?? "NaN"
+ return """
+ (() => {
+ const vv = visualViewport;
+ const link = e => e && e.closest && e.closest('a[href], area[href]');
+ let a = isFinite(\(x)) ? link(document.elementFromPoint(\(x) * vv.width + vv.offsetLeft, \(y) * vv.height + vv.offsetTop)) : null;
+ if (!a) a = link(document.activeElement);
+ window.__craPeekSource = a || null;
+ return a ? \(sourceRectJS) : null;
+ })()
+ """
+ }
+
+ /// The same link's rect again as the Peek closes (it may have moved), or null when it's gone.
+ public static let sourceAgainScript = """
+ (() => {
+ const a = window.__craPeekSource, vv = visualViewport;
+ return a && a.isConnected ? \(sourceRectJS) : null;
+ })()
+ """
+
+ static let sourceRectJS = """
+ (() => { const r = a.getBoundingClientRect(); \
+ return {x: (r.left - vv.offsetLeft) / vv.width, y: (r.top - vv.offsetTop) / vv.height, \
+ width: r.width / vv.width, height: r.height / vv.height}; })()
+ """
- /// How far the card's top-right corner (and the buttons with it) is from its place while the
- /// card is drawn at `scale` about its centre.
- public static func cornerShift(card: CGRect, scale: CGFloat) -> CGVector {
- CGVector(dx: (scale - 1) * card.width / 2, dy: (scale - 1) * card.height / 2)
+ /// The rect a source script answered with (fractions, y down), or nil.
+ public static func fraction(fromScript result: [String: Any]) -> CGRect? {
+ func number(_ v: Any?) -> CGFloat? { (v as? NSNumber).map { CGFloat($0.doubleValue) } }
+ guard let x = number(result["x"]), let y = number(result["y"]),
+ let w = number(result["width"]), let h = number(result["height"]) else { return nil }
+ return CGRect(x: x, y: y, width: w, height: h)
}
/// The area a Peek covers: right of the sidebar (`contentMinX`, window coordinates) to the
diff --git a/Packages/CraCore/Tests/CraCoreTests/PeekLayoutTests.swift b/Packages/CraCore/Tests/CraCoreTests/PeekLayoutTests.swift
index 9b7132c..0368348 100644
--- a/Packages/CraCore/Tests/CraCoreTests/PeekLayoutTests.swift
+++ b/Packages/CraCore/Tests/CraCoreTests/PeekLayoutTests.swift
@@ -29,12 +29,102 @@ struct PeekLayoutTests {
#expect(card.width == (Self.window.width * 0.8).rounded())
}
- @Test func openStartsAtTheAreasWidth() {
+ @Test func withoutALinkItGrowsFromTheArea() {
+ // Arc from a link that covers the page (3 Nov): the card starts as the whole area.
let area = PeekLayout.area(window: Self.window, contentMinX: 347)
let card = PeekLayout.card(in: area)
- #expect(abs(card.width * PeekLayout.areaScale - area.width) <= 1)
- // Arc's first measured frame (scale 1.1675): the corner 93 pt right and 89 pt up of its place.
- let shift = PeekLayout.cornerShift(card: card, scale: 1.1675)
- #expect(abs(shift.dx - 92.5) < 0.5 && abs(shift.dy - 88.8) < 0.5)
+ #expect(PeekLayout.opening(from: area, to: card, at: 0).frame == area)
+ #expect(PeekLayout.opening(from: area, to: card, at: PeekLayout.openDuration).frame == card)
+ #expect(PeekLayout.closing(from: card, to: area, at: PeekLayout.closeToAreaDuration, duration: PeekLayout.closeToAreaDuration).frame == area)
+ }
+
+ // MARK: Growing out of the link (Arc 1.171, small links, 60 fps, 6 Nov 2026, GitHub #204)
+
+ static let card = PeekLayout.card(in: PeekLayout.area(window: window, contentMinX: 347))
+ /// Link A of the run: x 407, 132 pt under the window's top, 68 × 31.
+ static let link = CGRect(x: 407, y: 1084 - 132 - 31, width: 68, height: 31)
+
+ @Test func curvesRunFromZeroToOne() {
+ for c in [PeekLayout.Curve.easeOut, .easeOutCubic, .close] {
+ #expect(c(0) == 0 && c(1) == 1 && c(-1) == 0 && c(2) == 1)
+ #expect(c(0.25) < c(0.5) && c(0.5) < c(0.75))
+ }
+ // The ease-out cubic's own value, 1 − (1 − u)³, within a hair.
+ #expect(abs(PeekLayout.Curve.easeOutCubic(0.5) - 0.875) < 0.02)
+ }
+
+ @Test func opensFromTheLinkAndLandsOnTheCard() {
+ let start = PeekLayout.opening(from: Self.link, to: Self.card, at: 0)
+ #expect(start.frame == Self.link)
+ #expect(start.sourceOpacity == 1 && start.buttonsOpacity == 0)
+ let end = PeekLayout.opening(from: Self.link, to: Self.card, at: PeekLayout.openDuration)
+ #expect(end.frame == Self.card)
+ #expect(end.sourceOpacity == 0 && end.buttonsOpacity == 1)
+ }
+
+ @Test func heightLagsWidthAsInArc() {
+ // Arc, run A: when the width was 60.3 % of the way, the height was 47.9 %.
+ var t = 0.0
+ while PeekLayout.opening(from: Self.link, to: Self.card, at: t).frame.width < Self.link.width + 0.603 * (Self.card.width - Self.link.width) { t += 0.0005 }
+ let f = PeekLayout.opening(from: Self.link, to: Self.card, at: t).frame
+ let q = (f.height - Self.link.height) / (Self.card.height - Self.link.height)
+ #expect(abs(q - 0.479) < 0.05)
+ // The centre goes with the width.
+ let p = (f.midX - Self.link.midX) / (Self.card.midX - Self.link.midX)
+ #expect(abs(p - 0.603) < 0.01)
+ // The link's picture was mostly gone by then (Arc: 0.065).
+ #expect(PeekLayout.opening(from: Self.link, to: Self.card, at: t).sourceOpacity < 0.12)
+ }
+
+ @Test func closesBackIntoTheLink() {
+ let start = PeekLayout.closing(from: Self.card, to: Self.link, at: 0)
+ #expect(start.frame == Self.card && start.sourceOpacity == 0 && start.buttonsOpacity == 1)
+ let end = PeekLayout.closing(from: Self.card, to: Self.link, at: PeekLayout.closeScaleDuration)
+ #expect(end.frame == Self.link && end.buttonsOpacity == 0)
+ // Arc, run B: the link picture at about a third when the frame was 80 % of the way.
+ var t = 0.0
+ while PeekLayout.closing(from: Self.card, to: Self.link, at: t).frame.width > Self.card.width - 0.8 * (Self.card.width - Self.link.width) { t += 0.0005 }
+ let a = PeekLayout.closing(from: Self.card, to: Self.link, at: t).sourceOpacity
+ #expect(a > 0.15 && a < 0.5)
+ }
+
+ @Test func pageScalesWithTheWidthFromTheTopLeft() {
+ let frame = PeekLayout.frame(from: Self.link, to: Self.card, p: 0.6, q: 0.48)
+ let c = PeekLayout.content(in: frame, card: Self.card)
+ #expect(abs(c.width - frame.width) < 0.001)
+ #expect(abs(c.maxY - frame.height) < 0.001 && c.minX == 0)
+ #expect(abs(c.height / Self.card.height - frame.width / Self.card.width) < 0.001)
+ #expect(PeekLayout.content(in: Self.card, card: Self.card) == CGRect(origin: .zero, size: Self.card.size))
+ }
+
+ @Test func columnRidesTheCorner() {
+ let column = PeekLayout.column(beside: Self.card)
+ #expect(PeekLayout.column(column, card: Self.card, frame: Self.card) == column)
+ let half = CGRect(x: 600, y: 300, width: Self.card.width / 2, height: 400)
+ let c = PeekLayout.column(column, card: Self.card, frame: half)
+ #expect(abs(c.width - column.width / 2) < 0.001)
+ #expect(abs(half.maxY - c.maxY - PeekLayout.buttonTop) < 0.5)
+ #expect(abs(c.minX - half.maxX - PeekLayout.buttonGap / 2) < 0.001)
+ }
+
+ @Test func linkFractionsMapOntoThePage() {
+ let page = CGRect(x: 347, y: 0, width: 1371, height: 1032)
+ // Run A's link: 60, 90, 68 × 31 CSS px in a 1371 × 1032 view.
+ let f = CGRect(x: 60.0 / 1371, y: 90.0 / 1032, width: 68.0 / 1371, height: 31.0 / 1032)
+ let r = PeekLayout.source(fraction: f, in: page)!
+ #expect(abs(r.minX - 407) < 0.001 && abs(r.maxY - (1032 - 90)) < 0.001 && abs(r.width - 68) < 0.001)
+ // Off the page, empty or not a number: no source.
+ #expect(PeekLayout.source(fraction: CGRect(x: 2, y: 0, width: 0.1, height: 0.1), in: page) == nil)
+ #expect(PeekLayout.source(fraction: CGRect(x: 0, y: 0, width: 0, height: 0.1), in: page) == nil)
+ #expect(PeekLayout.source(fraction: CGRect(x: .nan, y: 0, width: 0.1, height: 0.1), in: page) == nil)
+ // Partly scrolled out: the part on the page.
+ #expect(PeekLayout.source(fraction: CGRect(x: 0.5, y: -0.02, width: 0.1, height: 0.05), in: page)?.maxY == page.maxY)
+ }
+
+ @Test func scriptAnswersParse() {
+ #expect(PeekLayout.fraction(fromScript: ["x": 0.1, "y": 0.2, "width": 0.05, "height": 0.03]) == CGRect(x: 0.1, y: 0.2, width: 0.05, height: 0.03))
+ #expect(PeekLayout.fraction(fromScript: ["x": "0.1", "y": 0.2, "width": 0.05, "height": 0.03]) == nil)
+ #expect(!PeekLayout.sourceScript(pointer: nil).contains("nan"))
+ #expect(PeekLayout.sourceScript(pointer: CGPoint(x: 0.25, y: 0.5)).contains("0.25 * vv.width"))
}
}
diff --git a/Sources/Cra/App/AppDelegate.swift b/Sources/Cra/App/AppDelegate.swift
index 278b166..238118a 100644
--- a/Sources/Cra/App/AppDelegate.swift
+++ b/Sources/Cra/App/AppDelegate.swift
@@ -536,7 +536,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuItemValidation {
littleWindows.append(w)
// Arc badges the tab the Peek came from with the peeked page's favicon (modalIcon).
parent.sidebarUI.peekBadge = tabID.map { .init(tabID: $0, iconKey: FaviconKey.key(for: url)) }
- w.showAsPeek()
+ w.showAsPeek(fromTab: tabID)
}
func removeLittleWindow(_ w: LittleWindowController) {
diff --git a/Sources/Cra/UI/Windows/LittleWindowController.swift b/Sources/Cra/UI/Windows/LittleWindowController.swift
index adb33f5..ad6ea27 100644
--- a/Sources/Cra/UI/Windows/LittleWindowController.swift
+++ b/Sources/Cra/UI/Windows/LittleWindowController.swift
@@ -145,6 +145,8 @@ final class LittleWindowController: NSWindowController, NSWindowDelegate, @preco
private var openingPeek = false
/// The pictures moving while the Peek opens or closes.
private var transition: PeekTransition?
+ /// The link the Peek grew out of, which it closes back into (nil: the whole area).
+ private var peekSource: PeekSource?
private var commandPanel: CommandBarPanel!
private var commandHost: CommandBarView!
private var commandBarOpenedAt = Date.distantPast
@@ -415,11 +417,12 @@ final class LittleWindowController: NSWindowController, NSWindowDelegate, @preco
/// The click catcher, the Peek and its buttons, in their order above the parent's other children.
var peekWindows: [NSWindow] { [dim, window, controls].compactMap { $0 } }
- /// Arc's Peek: the card shrinks from the whole area right of the sidebar to its own frame as
- /// it fades in, its buttons riding its corner, while the page behind fades to 28 %. The motion
- /// is PeekTransition's pictures on Core Animation; the real card and buttons wait at their
- /// places, invisible, and take over when it lands.
- func showAsPeek() {
+ /// Arc's Peek: the card grows out of the link clicked in `tabID`'s page (without one, from the
+ /// whole area right of the sidebar) to its own frame, its buttons riding its corner, while the
+ /// page behind fades to 28 % (GitHub #204). The motion is PeekTransition's pictures on Core
+ /// Animation; the real card and buttons wait at their places, invisible, and take over when it
+ /// lands.
+ func showAsPeek(fromTab tabID: UUID?) {
guard let window, let parent = peekParent, let pw = parent.window else { return }
let dim = PeekDimPanel(covering: pw) { [weak self] in self?.closeWindow() }
self.dim = dim
@@ -444,17 +447,24 @@ final class LittleWindowController: NSWindowController, NSWindowDelegate, @preco
openingPeek = true
// Hidden, not transparent: Chromium sets its page window's alpha back to 1 as it shows it.
if let host = browser?.hostWindow, host.parent === window { host.contentView?.isHidden = true }
- let t = PeekTransition(over: pw, card: pw.convertFromScreen(window.frame), cardImage: PeekTransition.picture(of: shell),
- column: pw.convertFromScreen(controls.frame), columnImage: controls.contentView.flatMap { PeekTransition.picture(of: $0) })
- transition = t
if hasPage || isPopupHost { focusPage() } else { openCommandBar() }
- // Next turn, with the page focused and the panel on its way to the screen.
- DispatchQueue.main.async { [weak self, weak t] in
- guard let self, let t, self.transition === t, !self.closingPeek else { return }
- DispatchQueue.main.asyncAfter(deadline: .now() + PeekTransition.lead) {
- parent.setPeekVeil(true, duration: PeekLayout.openVeilDuration, timing: PeekTransition.easeOutCubic)
+ // The card waits, invisible at its place, for the link it grows out of (at most
+ // PeekSource.wait); a close meanwhile ends it unseen (closePeekAnimated).
+ parent.peekSource(fromTab: tabID) { [weak self] source in
+ guard let self, let window = self.window, let controls = self.controls, self.openingPeek, !self.closingPeek else { return }
+ self.peekSource = source
+ let t = PeekTransition(over: pw, card: pw.convertFromScreen(window.frame), cardImage: PeekTransition.picture(of: self.shell),
+ column: pw.convertFromScreen(controls.frame), columnImage: controls.contentView.flatMap { PeekTransition.picture(of: $0) },
+ source: source?.rect ?? pw.convertFromScreen(parent.peekArea()), sourceImage: source?.image)
+ self.transition = t
+ // Next turn, with the panel on its way to the screen.
+ DispatchQueue.main.async { [weak self, weak t] in
+ guard let self, let t, self.transition === t, !self.closingPeek else { return }
+ DispatchQueue.main.asyncAfter(deadline: .now() + PeekTransition.lead) {
+ parent.setPeekVeil(true, duration: PeekLayout.openVeilDuration, timing: PeekTransition.easeOutCubic)
+ }
+ self.landPeek(t)
}
- self.landPeek(t)
}
}
@@ -480,24 +490,40 @@ final class LittleWindowController: NSWindowController, NSWindowDelegate, @preco
controls?.place(parent.peekButtonFrames(), theme: parent.focusedSpace.theme)
}
- /// Arc closes a Peek the way it opened, backwards: out to the whole area, fading, as the page
- /// behind comes back. A picture of the card with its page (Chromium's own screenshot, waited
- /// for at most 80 ms) takes over from the real one. Expand and Add To Split don't animate.
+ /// Arc closes a Peek the way it opened, backwards: into the link it came from, where the page
+ /// has it now (out to the whole area, fading, without one), as the page behind comes back. A
+ /// picture of the card with its page (Chromium's own screenshot, waited for at most 80 ms)
+ /// takes over from the real one. Expand and Add To Split don't animate.
private func closePeekAnimated(then finish: @escaping () -> Void) {
guard let window, let parent = peekParent, let pw = parent.window else { finish(); return }
+ let neverShown = openingPeek && transition == nil
closingPeek = true
transition?.remove()
transition = nil
+ // Closed while it was still finding its link: it goes without having been seen.
+ if neverShown { finish(); return }
var started = false
+ // The card's screenshot and the link's place now, asked together.
+ var shot: CGImage??
+ var linkNow: NSRect?? = peekSource == nil ? .some(nil) : nil
let start: (CGImage?) -> Void = { [weak self] page in
guard let self, !started else { return }
started = true
let card = pw.convertFromScreen(window.frame)
let pageRect = self.shell.page.frame
+ // Into the link where the page has it now; where it was when Chromium is late; out to
+ // the whole area, fading, when it's gone.
+ let area = pw.convertFromScreen(parent.peekArea())
+ let back: (rect: NSRect, image: CGImage?) = switch linkNow {
+ case .none: (self.peekSource?.rect ?? area, self.peekSource?.image)
+ case .some(.some(let r)): (r, self.peekSource?.image)
+ case .some(.none): (area, nil)
+ }
let t = PeekTransition(over: pw, card: card,
cardImage: PeekTransition.picture(of: self.shell, page: page, pageRect: pageRect),
column: self.controls.map { pw.convertFromScreen($0.frame) } ?? .zero,
- columnImage: self.controls?.contentView.flatMap { PeekTransition.picture(of: $0) })
+ columnImage: self.controls?.contentView.flatMap { PeekTransition.picture(of: $0) },
+ source: back.rect, sourceImage: back.image)
self.transition = t
t.close {
finish()
@@ -511,14 +537,25 @@ final class LittleWindowController: NSWindowController, NSWindowDelegate, @preco
parent.setPeekVeil(false, duration: PeekLayout.closeVeilDuration, timing: PeekTransition.easeOutCubic)
}
}
- guard let b = browser, hasPage else { start(nil); return }
- b.sendDevToolsMethod("Page.captureScreenshot", params: #"{"format":"jpeg","quality":85,"optimizeForSpeed":true}"#) { shot, _ in
- let image = shot.flatMap { try? JSONSerialization.jsonObject(with: Data($0.utf8)) as? [String: Any] }
- .flatMap { $0["data"] as? String }.flatMap { Data(base64Encoded: $0) }
- .flatMap { CGImageSourceCreateWithData($0 as CFData, nil) }.flatMap { CGImageSourceCreateImageAtIndex($0, 0, nil) }
- DispatchQueue.main.async { start(image) }
+ let ready: (Bool) -> Void = { timedOut in
+ guard !started, timedOut || (shot != nil && linkNow != nil) else { return }
+ start(shot ?? nil)
+ }
+ if let source = peekSource {
+ parent.peekSourceAgain(source) { r in
+ if linkNow == nil { linkNow = .some(r) }
+ ready(false)
+ }
+ }
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.08) { ready(true) }
+ guard let b = browser, hasPage else { shot = .some(nil); ready(false); return }
+ b.sendDevToolsMethod("Page.captureScreenshot", params: #"{"format":"jpeg","quality":85,"optimizeForSpeed":true}"#) { result, _ in
+ let image = PeekSource.image(fromScreenshot: result)
+ DispatchQueue.main.async {
+ if shot == nil { shot = .some(image) }
+ ready(false)
+ }
}
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.08) { start(nil) }
}
private func endPeek() {
diff --git a/Sources/Cra/UI/Windows/MainWindowController.swift b/Sources/Cra/UI/Windows/MainWindowController.swift
index a23ab37..f45ab42 100644
--- a/Sources/Cra/UI/Windows/MainWindowController.swift
+++ b/Sources/Cra/UI/Windows/MainWindowController.swift
@@ -1489,6 +1489,80 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
return PeekLayout.buttons(beside: PeekLayout.card(in: peekAreaInWindow())).map { window.convertToScreen($0) }
}
+ /// The link a Peek opens from (GitHub #204): Arc grows the card out of it and closes it back in.
+ /// The link under the pointer in `tabID`'s page, else the page's focused link, found by
+ /// PeekLayout's script in Cra's isolated world, with a picture of it cut from Chromium's
+ /// screenshot. Answers within `PeekSource.wait` whatever Chromium does: nil without a link (the
+ /// Peek then grows from the whole area), no picture when the screenshot is late.
+ func peekSource(fromTab tabID: UUID?, completion: @escaping (PeekSource?) -> Void) {
+ guard let tabID, let window, let rt = browsers.runtimes[tabID], let host = rt.hostWindow, host.parent === window,
+ host.isVisible, rt.browser.isCreated, !rt.browser.isClosed else {
+ CraLog.note("peek: from the whole area (no page to find the link in)")
+ completion(nil)
+ return
+ }
+ let completion: (PeekSource?) -> Void = { source in
+ CraLog.note(source.map { "peek: from a link at \(Int($0.rect.minX)),\(Int($0.rect.minY)) \(Int($0.rect.width))×\(Int($0.rect.height))\($0.image == nil ? ", no picture" : "")" }
+ ?? "peek: from the whole area (no link under the pointer or focused)")
+ completion(source)
+ }
+ let pageFrame = host.frame
+ let m = NSEvent.mouseLocation
+ let pointer = pageFrame.contains(m)
+ ? CGPoint(x: (m.x - pageFrame.minX) / pageFrame.width, y: (pageFrame.maxY - m.y) / pageFrame.height) : nil
+ var fraction: CGRect??
+ var picture: CGImage??
+ var answered = false
+ let finish: (Bool) -> Void = { [weak window] timedOut in
+ guard !answered, let window else { return }
+ guard case .some(let found) = fraction else {
+ if timedOut { answered = true; completion(nil) }
+ return
+ }
+ if picture == nil, !timedOut { return }
+ answered = true
+ guard let found, let rect = PeekLayout.source(fraction: found, in: window.convertFromScreen(pageFrame)) else { completion(nil); return }
+ let image = (picture ?? nil).flatMap { PeekSource.crop($0, to: found) }
+ completion(PeekSource(tabID: tabID, rect: rect, image: image))
+ }
+ let script = PeekLayout.sourceScript(pointer: pointer)
+ let params = (try? JSONSerialization.data(withJSONObject: ["expression": script, "returnByValue": true]))
+ .flatMap { String(data: $0, encoding: .utf8) } ?? "{}"
+ rt.browser.evaluate(inIsolatedWorld: PageScript.world, params: params) { result, _ in
+ let found = PeekSource.value(result).flatMap(PeekLayout.fraction(fromScript:))
+ DispatchQueue.main.async { if fraction == nil { fraction = .some(found) }; finish(false) }
+ }
+ rt.browser.sendDevToolsMethod("Page.captureScreenshot", params: #"{"format":"png","optimizeForSpeed":true}"#) { shot, _ in
+ let image = PeekSource.image(fromScreenshot: shot)
+ DispatchQueue.main.async { if picture == nil { picture = .some(image) }; finish(false) }
+ }
+ DispatchQueue.main.asyncAfter(deadline: .now() + PeekSource.wait) { finish(true) }
+ }
+
+ /// Where the link a Peek came from is now (the page may have scrolled), in this window's
+ /// coordinates; nil when it's gone, off the page or Chromium doesn't answer in time.
+ func peekSourceAgain(_ source: PeekSource, completion: @escaping (NSRect?) -> Void) {
+ guard let window, let rt = browsers.runtimes[source.tabID], let host = rt.hostWindow, host.parent === window,
+ host.isVisible, rt.browser.isCreated, !rt.browser.isClosed else { completion(nil); return }
+ var answered = false
+ let params = (try? JSONSerialization.data(withJSONObject: ["expression": PeekLayout.sourceAgainScript, "returnByValue": true]))
+ .flatMap { String(data: $0, encoding: .utf8) } ?? "{}"
+ rt.browser.evaluate(inIsolatedWorld: PageScript.world, params: params) { [weak window, weak host] result, _ in
+ let found = PeekSource.value(result).flatMap(PeekLayout.fraction(fromScript:))
+ DispatchQueue.main.async {
+ guard !answered else { return }
+ answered = true
+ guard let window, let host, let found else { completion(nil); return }
+ completion(PeekLayout.source(fraction: found, in: window.convertFromScreen(host.frame)))
+ }
+ }
+ DispatchQueue.main.asyncAfter(deadline: .now() + PeekSource.wait) {
+ guard !answered else { return }
+ answered = true
+ completion(nil)
+ }
+ }
+
/// Arc fades the page under a Peek to 28 % over the window's background, its sidebar as it is.
func setPeekVeil(_ on: Bool, duration: TimeInterval, timing: CAMediaTimingFunction? = nil) {
let alpha: CGFloat = on ? PeekLayout.pageAlpha : 1
diff --git a/Sources/Cra/UI/Windows/PeekChrome.swift b/Sources/Cra/UI/Windows/PeekChrome.swift
index 2fc2c6e..76cb58f 100644
--- a/Sources/Cra/UI/Windows/PeekChrome.swift
+++ b/Sources/Cra/UI/Windows/PeekChrome.swift
@@ -183,23 +183,69 @@ final class PeekControlButton: NSView {
}
}
-/// Arc's Peek opening and closing, on Core Animation. A picture of the card and of its buttons
-/// rides in a panel over the browser window while the real ones wait, invisible, at their places:
-/// the window server draws every frame, nothing is resized or laid out while it runs, and the
-/// page window (which can't follow a frame animation) is never moved. Curves from PeekLayout.
+/// The link a Peek came from: where it is in the browser window (window coordinates) and a picture
+/// of it, at the window's scale (MainWindowController.peekSource).
+struct PeekSource {
+ let tabID: UUID
+ let rect: NSRect
+ let image: CGImage?
+ /// How long a Peek waits for Chromium's answers before it opens or closes without them.
+ static let wait: TimeInterval = 0.09
+
+ /// A Runtime.evaluate result's value (returnByValue), when it is an object.
+ static func value(_ result: String?) -> [String: Any]? {
+ result.flatMap { try? JSONSerialization.jsonObject(with: Data($0.utf8)) as? [String: Any] }
+ .flatMap { ($0["result"] as? [String: Any])?["value"] as? [String: Any] }
+ }
+
+ /// Page.captureScreenshot's picture.
+ static func image(fromScreenshot shot: String?) -> CGImage? {
+ shot.flatMap { try? JSONSerialization.jsonObject(with: Data($0.utf8)) as? [String: Any] }
+ .flatMap { $0["data"] as? String }.flatMap { Data(base64Encoded: $0) }
+ .flatMap { CGImageSourceCreateWithData($0 as CFData, nil) }.flatMap { CGImageSourceCreateImageAtIndex($0, 0, nil) }
+ }
+
+ /// The part of a viewport picture at `fraction` (y down, as the page measures).
+ static func crop(_ image: CGImage, to fraction: CGRect) -> CGImage? {
+ let w = CGFloat(image.width), h = CGFloat(image.height)
+ let r = CGRect(x: fraction.minX * w, y: fraction.minY * h, width: fraction.width * w, height: fraction.height * h)
+ .integral.intersection(CGRect(x: 0, y: 0, width: w, height: h))
+ return r.isEmpty ? nil : image.cropping(to: r)
+ }
+}
+
+/// Arc's Peek opening and closing, on Core Animation (GitHub #204). The card grows out of the
+/// link it came from and closes back into it: a picture of the card and of its buttons rides in a
+/// panel over the browser window while the real ones wait, invisible, at their places. A picture of
+/// the link fills the moving frame and fades out over the card as it opens, back in as it closes.
+/// Without a link (no pointer over one, a WebKit tab) the card grows from the whole area and fades
+/// itself, as Arc does from a link that covers the page. The window server draws every frame,
+/// nothing is resized or laid out while it runs, and the page window (which can't follow a frame
+/// animation) is never moved. Every frame comes from PeekLayout, sampled at 120 Hz.
@MainActor
final class PeekTransition {
private let panel: NSPanel
+ /// The card's shadow and its clipped picture, faded together when there is no link picture.
private let group = CALayer()
private let shadow = CALayer()
+ private let clip = CALayer()
private let card = CALayer()
+ private let link = CALayer()
private let buttons = CALayer()
- /// Arc's ease-out on the card's scale, and the near-linear way back out.
+ private let cardFrame: NSRect
+ private let columnFrame: NSRect
+ private let source: NSRect
+ private let hasLinkPicture: Bool
static let easeOutCubic = CAMediaTimingFunction(controlPoints: 0.215, 0.61, 0.355, 1)
- static let closeCurve = CAMediaTimingFunction(controlPoints: 0.25, 0.25, 0.5, 1)
- /// `card` and `column` in `window`'s coordinates; the pictures at the window's scale.
- init(over window: NSWindow, card frame: NSRect, cardImage: CGImage?, column: NSRect, columnImage: CGImage?) {
+ /// `card`, `column` and `source` (the link, or the whole area) in `window`'s coordinates; the
+ /// pictures at the window's scale.
+ init(over window: NSWindow, card frame: NSRect, cardImage: CGImage?, column: NSRect, columnImage: CGImage?,
+ source: NSRect, sourceImage: CGImage?) {
+ cardFrame = frame
+ columnFrame = column
+ self.source = source
+ hasLinkPicture = sourceImage != nil
panel = NSPanel(contentRect: window.frame, styleMask: [.borderless, .nonactivatingPanel], backing: .buffered, defer: false)
panel.isOpaque = false
panel.backgroundColor = .clear
@@ -214,28 +260,31 @@ final class PeekTransition {
let scale = window.backingScaleFactor
CATransaction.begin()
CATransaction.setDisableActions(true)
- group.frame = frame
- shadow.frame = group.bounds
- shadow.shadowPath = CGPath(roundedRect: group.bounds, cornerWidth: PeekLayout.cornerRadius, cornerHeight: PeekLayout.cornerRadius, transform: nil)
+ group.frame = view.bounds
shadow.shadowColor = NSColor.black.cgColor
shadow.shadowOpacity = 0.35
shadow.shadowRadius = 14
shadow.shadowOffset = CGSize(width: 0, height: -6)
- card.frame = group.bounds
- card.cornerRadius = PeekLayout.cornerRadius
- card.cornerCurve = .continuous
- card.masksToBounds = true
+ clip.cornerRadius = PeekLayout.cornerRadius
+ clip.cornerCurve = .continuous
+ clip.masksToBounds = true
card.contents = cardImage
card.contentsGravity = .resize
card.contentsScale = scale
- group.addSublayer(shadow)
- group.addSublayer(card)
- buttons.frame = column
+ link.contents = sourceImage
+ link.contentsGravity = .resize
+ link.contentsScale = scale
+ link.opacity = 0
buttons.contents = columnImage
buttons.contentsGravity = .resize
buttons.contentsScale = scale
+ clip.addSublayer(card)
+ clip.addSublayer(link)
+ group.addSublayer(shadow)
+ group.addSublayer(clip)
view.layer?.addSublayer(group)
view.layer?.addSublayer(buttons)
+ place(PeekLayout.Moment(frame: frame, sourceOpacity: 0, buttonsOpacity: 1))
// Nothing shows until open() or close() animates it: the panel reaches the screen before
// the animations do, and its first frame showed the card at its final size.
group.opacity = 0
@@ -245,78 +294,99 @@ final class PeekTransition {
panel.orderFront(nil)
}
- /// From the whole area to the card's frame, fading in; `done` once it has landed.
- /// A new panel reaches the screen a frame or two after it is ordered in, and the main thread
- /// still has the page to focus: animations clocked from now lost their first 60 ms. They start
- /// this far ahead instead, held at their first frame until then.
- static let lead: CFTimeInterval = 0.03
+ /// The layers' places at one moment, without animation.
+ private func place(_ m: PeekLayout.Moment) {
+ let v = values(m)
+ for (layer, frame) in [(shadow, v.frame), (clip, v.frame), (card, v.content), (link, v.linkFrame), (buttons, v.column)] {
+ layer.bounds = CGRect(origin: .zero, size: frame.size)
+ layer.position = CGPoint(x: frame.midX, y: frame.midY)
+ }
+ shadow.shadowPath = v.shadowPath
+ }
- func open(done: @escaping () -> Void) {
- let k = PeekLayout.areaScale
- let shift = PeekLayout.cornerShift(card: group.frame, scale: k)
- let now = CACurrentMediaTime() + Self.lead
+ private struct Values {
+ var frame: CGRect, content: CGRect, linkFrame: CGRect, column: CGRect, shadowPath: CGPath
+ }
+
+ private func values(_ m: PeekLayout.Moment) -> Values {
+ let f = m.frame
+ let r = min(PeekLayout.cornerRadius, f.width / 2, f.height / 2)
+ return Values(frame: f, content: PeekLayout.content(in: f, card: cardFrame),
+ linkFrame: CGRect(origin: .zero, size: f.size),
+ column: PeekLayout.column(columnFrame, card: cardFrame, frame: f),
+ shadowPath: CGPath(roundedRect: CGRect(origin: .zero, size: f.size), cornerWidth: r, cornerHeight: r, transform: nil))
+ }
+
+ /// Runs `moments` (sampled every 1/120 s over `duration`) on every layer, starting `lead` ahead.
+ private func run(_ moments: [PeekLayout.Moment], duration: Double, keepEnd: Bool, done: @escaping () -> Void) {
+ let begin = CACurrentMediaTime() + Self.lead
+ let times = moments.indices.map { NSNumber(value: Double($0) / Double(max(1, moments.count - 1))) }
+ let all = moments.map(values)
+ func animate(_ layer: CALayer, _ keyPath: String, _ vals: [Any]) {
+ let a = CAKeyframeAnimation(keyPath: keyPath)
+ a.values = vals
+ a.keyTimes = times
+ a.calculationMode = .linear
+ a.beginTime = begin
+ a.duration = duration
+ a.fillMode = keepEnd ? .both : .backwards
+ a.isRemovedOnCompletion = !keepEnd
+ layer.add(a, forKey: keyPath)
+ }
+ func frames(_ layer: CALayer, _ pick: (Values) -> CGRect) {
+ animate(layer, "bounds", all.map { NSValue(rect: CGRect(origin: .zero, size: pick($0).size)) })
+ animate(layer, "position", all.map { NSValue(point: CGPoint(x: pick($0).midX, y: pick($0).midY)) })
+ }
CATransaction.begin()
CATransaction.setDisableActions(true)
CATransaction.setCompletionBlock { MainActor.assumeIsolated { done() } }
- for layer in [group, buttons] {
- layer.opacity = 1
- let fade = CABasicAnimation(keyPath: "opacity")
- fade.fromValue = 0
- fade.toValue = 1
- fade.duration = PeekLayout.openFadeDuration
- fade.timingFunction = CAMediaTimingFunction(name: .easeOut)
- fade.beginTime = now
- fade.fillMode = .backwards
- layer.add(fade, forKey: "fade")
- }
- let grow = CABasicAnimation(keyPath: "transform.scale")
- grow.fromValue = k
- grow.toValue = 1
- let ride = CABasicAnimation(keyPath: "position")
- ride.fromValue = NSValue(point: NSPoint(x: buttons.position.x + shift.dx, y: buttons.position.y + shift.dy))
- ride.toValue = NSValue(point: buttons.position)
- for (layer, a) in [(group, grow), (buttons, ride)] as [(CALayer, CABasicAnimation)] {
- a.beginTime = now + PeekLayout.openScaleDelay
- a.duration = PeekLayout.openScaleDuration
- a.timingFunction = Self.easeOutCubic
- a.fillMode = .backwards
- layer.add(a, forKey: "move")
+ frames(shadow) { $0.frame }
+ frames(clip) { $0.frame }
+ frames(card) { $0.content }
+ frames(link) { $0.linkFrame }
+ frames(buttons) { $0.column }
+ animate(shadow, "shadowPath", all.map(\.shadowPath))
+ let linkOpacity = moments.map { Float($0.sourceOpacity) }
+ if hasLinkPicture {
+ animate(link, "opacity", linkOpacity)
+ animate(group, "opacity", moments.map { _ in Float(1) })
+ } else {
+ // No picture of the link: the card fades in its place.
+ animate(group, "opacity", linkOpacity.map { 1 - $0 })
}
+ animate(buttons, "opacity", moments.map { Float($0.buttonsOpacity) })
+ let end = moments.last!
+ place(end)
+ link.opacity = hasLinkPicture ? Float(end.sourceOpacity) : 0
+ group.opacity = hasLinkPicture ? 1 : Float(1 - end.sourceOpacity)
+ buttons.opacity = Float(end.buttonsOpacity)
CATransaction.commit()
}
- /// Back out to the whole area, fading partway; `done` once it is gone.
+ private static func samples(_ duration: Double, _ moment: (Double) -> PeekLayout.Moment) -> [PeekLayout.Moment] {
+ let n = max(2, Int((duration * 120).rounded(.up)) + 1)
+ return (0..<n).map { moment(duration * Double($0) / Double(n - 1)) }
+ }
+
+ /// A new panel reaches the screen a frame or two after it is ordered in, and the main thread
+ /// still has the page to focus: animations clocked from now lost their first 60 ms. They start
+ /// this far ahead instead, held at their first frame until then.
+ static let lead: CFTimeInterval = 0.03
+
+ /// Out of the link (or the area) to the card's frame; `done` once it has landed.
+ func open(done: @escaping () -> Void) {
+ let d = PeekLayout.openDuration
+ run(Self.samples(d) { PeekLayout.opening(from: self.source, to: self.cardFrame, at: $0) }, duration: d, keepEnd: false, done: done)
+ }
+
+ /// Back into the link (or out to the area, fading); `done` once it is gone.
func close(done: @escaping () -> Void) {
- let k = PeekLayout.areaScale
- let shift = PeekLayout.cornerShift(card: group.frame, scale: k)
- let now = CACurrentMediaTime() + Self.lead
- CATransaction.begin()
- CATransaction.setDisableActions(true)
- CATransaction.setCompletionBlock { MainActor.assumeIsolated { done() } }
- let grow = CABasicAnimation(keyPath: "transform.scale")
- grow.fromValue = 1
- grow.toValue = k
- let ride = CABasicAnimation(keyPath: "position")
- ride.fromValue = NSValue(point: buttons.position)
- ride.toValue = NSValue(point: NSPoint(x: buttons.position.x + shift.dx, y: buttons.position.y + shift.dy))
- for (layer, a) in [(group, grow), (buttons, ride)] as [(CALayer, CABasicAnimation)] {
- a.beginTime = now
- a.duration = PeekLayout.closeScaleDuration
- a.timingFunction = Self.closeCurve
- a.fillMode = .both
- a.isRemovedOnCompletion = false
- layer.add(a, forKey: "move")
- let fade = CABasicAnimation(keyPath: "opacity")
- fade.fromValue = 1
- fade.toValue = 0
- fade.beginTime = now + PeekLayout.closeFadeDelay
- fade.duration = PeekLayout.closeFadeDuration
- fade.timingFunction = CAMediaTimingFunction(name: .easeOut)
- fade.fillMode = .backwards
- layer.add(fade, forKey: "fade")
- layer.opacity = 0
- }
- CATransaction.commit()
+ let target = source
+ let scale = hasLinkPicture ? PeekLayout.closeScaleDuration : PeekLayout.closeToAreaDuration
+ let d = PeekLayout.closeDuration(scale: scale)
+ // The panel goes at the end, and the real link is under the picture.
+ run(Self.samples(d) { PeekLayout.closing(from: self.cardFrame, to: target, at: $0, duration: scale) },
+ duration: d, keepEnd: true, done: done)
}
func remove() {
diff --git a/docs/arc-reverse-engineering.md b/docs/arc-reverse-engineering.md
index 4e0aab2..5b85a1e 100644
--- a/docs/arc-reverse-engineering.md
+++ b/docs/arc-reverse-engineering.md
@@ -2930,19 +2930,18 @@ event with `shiftClickModalEntryPointEnabled` set for the run, AX frames and 60
250/238/194 on the fake home's yellow space: the space's tooltip fill (shadedDark at 30 %) and its light
foreground. Their tips are the space's ArcTooltip.
- [O] The page behind fades to about 28 % over the window's background (233/240/254 → 178/172/151); the sidebar
- stays. Opening, the card starts at the area's full size and shrinks to its frame as it fades in (~0.12 s), the
- buttons appearing at the end. Escape closes it backwards: out to the full area, fading, as the page comes back
- (~0.22 s).
+ stays. Opening and closing: see "Peek grows out of the link" below. This run's page was one big link, so the
+ card seemed to start at the area's full size and to go back out to it.
- [O] "Copied Current URL" carries a Share glyph button in browser windows too (AX `square.and.arrow.up`, "Share",
31 × 27). The toast is 195 × 47 pt: text 13 pt in, 14.5 pt to a 29 × 27 pt button 13 pt from the end, 10 pt from
top and bottom. The button is a white wash over the pill (≈ 60 % on the light toast, 15 % on Little Arc's dark
one) with an outline. A click opens the macOS share menu (AirDrop, Notes…) from the button; the toast stays.
-- [O] The motion, frame by frame at 60 fps (card edges on one row, the card's and the page's luminance): opening,
- the card's opacity reaches 1 in ~0.075 s, and its scale goes from the whole area (1.25, centred) to 1 on an
- ease-out cubic over ~0.205 s (scale − 1 per frame: .168, .127, .092, .063, .041, .025, .015, .008, .002). The
- buttons appear with it and ride its top-right corner. The page fades on an ease-out cubic over ~0.18 s.
- Closing: the card grows to ~1.19 in ~0.09 s (near linear), fading from ~0.07 s, gone by ~0.16 s; the page is
- back after ~0.2 s.
+- [O] The motion from that page-sized link, frame by frame at 60 fps (card edges on one row, the card's and the
+ page's luminance): opening, what read as the card's opacity reaching 1 in ~0.075 s was the link's picture (the
+ whole page) fading out over it; its scale went from the whole area (1.25, centred) to 1 on an ease-out cubic
+ over ~0.205 s (scale − 1 per frame: .168, .127, .092, .063, .041, .025, .015, .008, .002). The page fades on an
+ ease-out cubic over ~0.18 s. Closing: the card grew to ~1.19 in ~0.09 s (near linear), "fading" from ~0.07 s
+ (the link's picture coming back), gone by ~0.16 s; the page is back after ~0.2 s.
- Cra draws the motion on Core Animation (PeekTransition): pictures of the card (with Chromium's screenshot of
the page when closing) and of the buttons in a panel over the window, the real card and buttons invisible at
their places until it lands. Animating the windows' frames (the first version) resized and laid out the card
@@ -2965,6 +2964,36 @@ event with `shiftClickModalEntryPointEnabled` set for the run, AX frames and 60
- [?] Not measured: the card at other window widths (Cra keeps 80 % of the area), and the Peek with Arc's
toolbar turned off.
+### Peek grows out of the link (Arc 1.171, 6 Nov 2026, GitHub #204, offline Arc)
+The reporter recorded Arc 1.172.1 growing the card out of the clicked link. 1.172.0/1.172.1 only moved Chromium
+(appcast notes: "no other changes"), so this was measured on 1.171 with a lab page on 127.0.0.1: two 68 × 31 pt
+links, A near the top left and B near the bottom right, real HID Shift-clicks (`modalEnabled` and
+`shiftClickModalEntryPointEnabled` set for the run), Escape to close, an app-only ScreenCaptureKit recording at
+60 fps, the card's frame and a black box inside the peeked page measured per frame.
+- [O] Opening: a picture of the link fills the moving frame (stretched, opaque) and fades out over the card on an
+ ease-out over ~0.075 s (red over blue reads 0.40, 0.21, 0.065, 0.02 a frame apart). The frame goes from the
+ link's rect to the card's: its centre (x and y) and width on an ease-out cubic over ~0.205 s, the height
+ lagging on an ease-out cubic over ~0.21 s about 12 ms later (when the width was 60 % of the way the height
+ was 48 %; frames from link B gave the same pairs). The page inside is a picture scaled by the frame's width
+ against the card's, pinned to the frame's top-left; the frame (8 pt corners) clips the rest.
+- [O] The buttons ride the frame's top-right corner, scaled like the page, 7 pt below its top, and fade in once
+ the link's picture is gone (none at ~0.055 s after the motion starts, faint at ~0.08, full by ~0.13).
+- [O] Closing from link B: the frame goes back to the link's rect on the same near-linear curve as before, over
+ ~0.16 s (fit on 6 frames: .13, .31, .49, .64, .80, .88), the card opaque, the link's picture fading back in
+ over it from ~0.07 s (≈ 0.3 at 80 % of the way, 0.55 at 88 %); then only the real link. The buttons go in
+ ~0.05 s.
+- [O] Closing from link A went back into link A the same way (.09, .26, .44, .66, .78, .86, .92 a frame apart,
+ the link's red fading in over the blue). Only the very first Peek after launch (Arc's toolbar grew 8 pt during
+ that run) shrank about its own centre instead and faded out in ~0.07 s; taken as a first-run glitch.
+- Cra: PeekLayout.opening / closing / content / column (CraCore) sample the motion; PeekTransition plays it as
+ Core Animation keyframes at 120 Hz. MainWindowController.peekSource finds the link under the pointer (else
+ the focused link) with a script in Cra's isolated world and cuts its picture out of Chromium's screenshot,
+ within 90 ms; without one (or in a WebKit tab) the card grows from the whole area and fades itself, as from
+ Arc's page-sized link. Closing asks where the link is now (the page may have scrolled) and goes back there;
+ out to the whole area when it's gone. Recorded the same way in a test copy: the card's left edge went .65,
+ .77, .84, .91, .93, .98 of the way a frame apart (Arc .60, .77, .85, .91, .95, .97), its bottom edge .34,
+ .59, .71, .80, .87, .91 (Arc .31, .54, .73, .82, .89, .94), and it closed back into the link.
+
## Capture (Arc 1.171, 4 Nov 2026, X request, Swift metadata + strings + offline Arc at 2x, 120 fps recordings)
- [O metadata] Module `Capture`: ContentCaptureViewController holds ContentCaptureView (grayscale and darkened layers with
shape masks, a lens ShadowView, a camera cursor view, single/double click and pan recognizers, an Esc monitor,