Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : Lou-Ka iOS9// File : LouKa/Design/Door/DoorTransition.swift10// Description : signature « Ouvrir la porte » (v2) — une vraie porte11// émerge de la photo touchée, vient au centre de l'écran, la12// béquille s'abaisse, le battant pivote vers l'intérieur13// dans son embrasure, la lumière sort, puis l'embrasure14// devient la photo principale de la fiche. Interruptible.15// Module : LouKa16// Repository : https://git.spboucher.ai/lou-ka-ios-v317// Project Website : https://www.lou-ka.com18// Created : 2026-11-2519// Last Modified : 2026-11-2820//21// =============================================================================22// AUTHOR & PROFESSIONAL AFFILIATION23// =============================================================================24//25// Author : Simon-Pierre Boucher26// Position : Professor of Finance27// Institution : Université du Québec en Outaouais (UQO)28// Department : Département des sciences administratives29// Organization : SP Boucher30//31// Website : https://spboucher.ai32// Git : https://git.spboucher.ai33//34// =============================================================================35// OFFICIAL CONTACT DIRECTORY36// =============================================================================37//38// General : info@spboucher.ai39// Professional : contact@spboucher.ai40// Direct : simon@spboucher.ai41// Research : research@spboucher.ai42// Development : dev@spboucher.ai43// Support : support@spboucher.ai44// Security/Admin : admin@spboucher.ai45// Notifications : notifications@spboucher.ai46//47// Preferred Contact: support@spboucher.ai48//49// =============================================================================50// COPYRIGHT & INTELLECTUAL PROPERTY51// =============================================================================52//53// Copyright (c) 202654// Simon-Pierre Boucher55//56// All rights reserved where applicable.57//58// This file is governed by the applicable project license,59// copyright notices, institutional agreements and relevant law.60//61// Unless expressly authorized by the applicable license or62// rights holder, copying, redistribution, sublicensing,63// publication and commercial exploitation are not permitted.64//65// Existing third-party rights and notices remain unaffected.66//67// =============================================================================68// CONFIDENTIALITY & SECURITY69// =============================================================================70//71// Classification : Public72// Distribution : Public repository; use is governed by the project license73// Security Contact : admin@spboucher.ai74//75// Access to this source does not independently grant permission76// to redistribute or disclose confidential materials.77//78// Do not embed credentials, private keys, access tokens,79// certificates or confidential personal information.80//81// =============================================================================82// LICENSE & MAINTENANCE83// =============================================================================84//85// License : None specified (no license file in this repository)86// Maintainer : Simon-Pierre Boucher87// Technical Contact: dev@spboucher.ai88//89// =============================================================================90// END OF SP BOUCHER SOURCE HEADER91// =============================================================================9293import Observation94import SwiftUI95import UIKit9697@MainActor98@Observable99final class DoorCenter {100 struct Run: Identifiable, Equatable {101 let id = UUID()102 let uid: String103 let image: String?104 let source: CGRect105 let level: DoorLevel106 let start: Date107 }108109 private(set) var machine = DoorStateMachine()110 private(set) var run: Run?111 /// photo du logement, prête à être dessinée (même cache que la carte touchée)112 private(set) var photo: UIImage?113 /// ouvertures jouées depuis le lancement : les premières sont complètes, les suivantes plus courtes114 private(set) var opensThisSession = 0115 /// cadre global de la photo principale de la fiche (publié par la galerie) : cible du passage du seuil116 var heroRect: CGRect?117 /// temps figé pour les captures de vérification (Debug) ; nil = temps réel118 private(set) var frozenTime: Double?119120 var preference: DoorPreference {121 didSet { defaults.set(preference.rawValue, forKey: "door.preference") }122 }123 /// réglages persistants ; les tests injectent un domaine jetable pour ne pas toucher à ceux de l'app124 private let defaults: UserDefaults125126 private var task: Task<Void, Never>?127 /// instant de la première image réellement dessinée : l'horloge de la scène part de là, pour qu'un128 /// accroc du fil principal au toucher ne mange pas l'émergence de la porte129 @ObservationIgnored private var anchor: Date?130131 /// Temps de scène (secondes) pour une image du calque.132 func elapsed(at date: Date) -> Double {133 if anchor == nil { anchor = date }134 return max(0, date.timeIntervalSince(anchor ?? date)) / slow135 }136137 /// Retard entre le toucher et la première image dessinée (borné), rattrapé par la séquence.138 private func lag(since start: Date) -> Double {139 guard let anchor else { return 0 }140 return min(0.35, max(0, anchor.timeIntervalSince(start)))141 }142 private var navigate: (() -> Void)?143144 /// Ralenti de laboratoire (analyse image par image) : argument de lancement `-LKDoorSlow <1…40>`.145 let slow: Double = {146 let v = UserDefaults.standard.double(forKey: "LKDoorSlow")147 return v >= 1 && v <= 40 ? v : 1148 }()149150 init(defaults: UserDefaults = .standard) {151 self.defaults = defaults152 preference = DoorPreference(rawValue: defaults.string(forKey: "door.preference") ?? "") ?? .automatic153 }154155 var state: DoorState { machine.state }156157 /// Ouvre un logement depuis `source` (cadre global de la photo ou de la pastille touchée).158 /// `navigate` pousse la fiche ; il est toujours appelé, quoi qu'il arrive à l'animation.159 func open(uid: String, image: String?, from source: CGRect, origin: DoorOrigin = .card, reduceMotion: Bool, navigate: @escaping () -> Void) {160 let level = DoorLevelPolicy.level(opensThisSession: opensThisSession, origin: origin, reduceMotion: reduceMotion, preference: preference)161 if run != nil { interrupt() }162 guard level != .none, source.width > 8, source.height > 8 else {163 navigate()164 return165 }166 opensThisSession += 1167 machine.send(.reset)168 machine.send(.trigger)169 photo = nil170 frozenTime = nil171 anchor = nil172 let r = Run(uid: uid, image: image, source: source, level: level, start: Date())173 run = r174 self.navigate = navigate175 loadPhoto(for: r)176 // Door Engine 3.0 : rien n'attend l'animation. Les données de la fiche partent au geste, en parallèle177 // de la chorégraphie ; la fiche les trouve déjà en cache quand elle se monte.178 Task.detached(priority: .userInitiated) {179 async let a = try? APIClient.shared.listingV3(uid)180 async let b = try? APIClient.shared.listing(uid)181 _ = await (a, b)182 }183184 task = Task { [weak self] in185 guard let self else { return }186 // 1 à 3. émergence, béquille, pivotement : dessinés par le calque à partir du temps écoulé187 if level.showsDoor {188 try? await Task.sleep(for: .seconds((level.swingDelay + level.swing * 0.9) * self.slow))189 if Task.isCancelled { return }190 let late = self.lag(since: r.start)191 if late > 0.01 { try? await Task.sleep(for: .seconds(late)) }192 if Task.isCancelled { return }193 self.machine.send(.panelOpened)194 self.machine.send(image == nil ? .fail : .reveal)195 try? await Task.sleep(for: .seconds(max(0, level.revealStart - level.swingDelay - level.swing * 0.9) * self.slow))196 } else {197 try? await Task.sleep(for: .seconds(level.revealStart * self.slow))198 }199 if Task.isCancelled { return }200 // 4. passage du seuil : la navigation part, la fiche se monte sous la scène201 self.machine.send(.expand)202 self.push()203 try? await Task.sleep(for: .seconds((level.reveal + level.settle) * self.slow))204 if Task.isCancelled { return }205 // 5. effacement terminé206 self.machine.send(.finish)207 guard self.run?.id == r.id else { return }208 self.run = nil209 self.photo = nil210 self.machine.send(.reset)211 }212 }213214 private func loadPhoto(for r: Run) {215 guard let src = r.image else { return }216 Task { [weak self] in217 // la miniature de la carte est déjà en cache : disponible tout de suite218 let small = await ImageLoader.shared.image(for: src, width: .small)219 guard let self, self.run?.id == r.id else { return }220 if self.photo == nil { self.photo = small }221 // la même définition que la photo principale de la fiche, pour un raccord net222 if let medium = await ImageLoader.shared.image(for: src, width: .medium), self.run?.id == r.id { self.photo = medium }223 }224 }225226 /// Pousse la fiche sans animation : elle apparaît sous la scène, qui se charge du raccord.227 private func push() {228 let go = navigate229 navigate = nil230 var t = Transaction()231 t.disablesAnimations = true232 withTransaction(t) { go?() }233 }234235 /// Interruption (toucher pendant l'animation, autre navigation) : la fiche s'ouvre tout de suite.236 func interrupt() {237 guard run != nil else { return }238 task?.cancel()239 task = nil240 machine.send(.interrupt)241 let go = navigate242 navigate = nil243 run = nil244 photo = nil245 frozenTime = nil246 go?()247 machine.send(.finish)248 machine.send(.reset)249 }250251 #if DEBUG252 /// Fige la scène à un instant donné, en secondes après le toucher (captures d'écran de vérification).253 func debugFreeze(uid: String, image: String?, source: CGRect, at time: Double, level: DoorLevel = .signature) {254 task?.cancel()255 machine.send(.reset); machine.send(.trigger)256 let r = Run(uid: uid, image: image, source: source, level: level, start: Date())257 run = r258 photo = nil259 frozenTime = time260 loadPhoto(for: r)261 }262 #endif263}264265// MARK: - Scène266267/// Valeurs de la scène à un instant donné : toute la chorégraphie est une fonction pure du temps écoulé.268struct DoorSceneState: Equatable {269 var veil: Double // opacité du voile couleur de fond270 var rigOpacity: Double271 var rig: CGRect // boîte de la porte à l'écran272 var rigScale: CGFloat // émergence : échelle autour du centre de la boîte273 var rigOffset: CGSize // émergence : décalage depuis la photo touchée274 var push: CGFloat // travelling avant (1 → 1,07)275 var angle: Double // battant, en degrés276 var lever: Double // béquille, en degrés (négatif : abaissée)277 var hardware: Double // opacité de l'encadrement, du seuil, du battant et de la lumière278 var inset: CGFloat // 1 : l'embrasure est en retrait de l'encadrement ; 0 : elle occupe toute la boîte279 var rootOpacity: Double280281 /// Boîte de la porte au centre de l'écran : proportions d'une vraie porte.282 static func doorRect(in size: CGSize) -> CGRect {283 let h = (max(280, min(560, size.height * 0.62))).rounded()284 let w = (h * 0.54).rounded()285 return CGRect(x: ((size.width - w) / 2).rounded(), y: ((size.height - h) / 2 - size.height * 0.015).rounded(), width: w, height: h)286 }287288 static func at(_ t: Double, level: DoorLevel, source: CGRect, hero: CGRect, screen: CGSize) -> DoorSceneState {289 let door = doorRect(in: screen)290 let rs = level.revealStart291 func lerp(_ a: CGRect, _ b: CGRect, _ p: Double) -> CGRect {292 CGRect(x: a.minX + (b.minX - a.minX) * p, y: a.minY + (b.minY - a.minY) * p,293 width: a.width + (b.width - a.width) * p, height: a.height + (b.height - a.height) * p)294 }295 let fadeOut = t <= rs + level.reveal ? 1.0 : max(0, 1 - (t - rs - level.reveal) / max(level.settle, 0.001))296297 switch level {298 case .signature, .standard:299 // 1. émergence : la porte fermée part de la photo touchée et vient au centre en grandissant300 let e = BezierEase.emerge(min(1, t / level.emerge))301 let s0 = min(1, source.height * 0.94 / door.height)302 let dx = source.midX - door.midX, dy = source.midY - door.midY303 // 2. béquille : elle s'abaisse de 26° puis remonte, juste avant le pivotement304 let lu = (t - max(0, level.swingDelay - 0.07)) / 0.19305 let lever = (lu > 0 && lu < 1) ? -26 * sin(.pi * lu) : 0306 // 3. pivotement selon la trajectoire, et travelling avant307 let angle = level.angle * SwingPath.value(at: (t - level.swingDelay) / level.swing)308 let pushDur = rs - level.swingDelay + level.reveal * 0.2309 var push = 1 + 0.07 * BezierEase.push(max(0, min(1, (t - level.swingDelay) / pushDur)))310 var rig = door311 var hardware = 1.0, inset: CGFloat = 1, veil = 0.94 * BezierEase.out(min(1, t / (level.emerge * 1.2)))312 if t >= rs {313 // 4. passage du seuil : l'embrasure s'élargit jusqu'à la photo de la fiche314 let q = t - rs315 rig = lerp(door, hero, BezierEase.morph(min(1, q / level.reveal)))316 hardware = 1 - BezierEase.out(min(1, q / (level.reveal * 0.55)))317 inset = CGFloat(1 - BezierEase.door(min(1, q / (level.reveal * 0.7))))318 push = 1 + (push - 1) * CGFloat(1 - BezierEase.door(min(1, q / (level.reveal * 0.8))))319 veil = 0.94 + 0.06 * min(1, q / (level.reveal * 0.5))320 }321 return DoorSceneState(veil: veil, rigOpacity: min(1, t / (level.emerge * 0.3)), rig: rig,322 rigScale: CGFloat(s0 + (1 - s0) * e), rigOffset: CGSize(width: dx * (1 - e), height: dy * (1 - e)),323 push: push, angle: angle, lever: lever, hardware: hardware, inset: inset, rootOpacity: fadeOut)324 case .compact:325 // sans porte : la photo touchée s'étend jusqu'à la photo de la fiche326 let q = max(0, t - rs)327 return DoorSceneState(veil: min(1, t / 0.07), rigOpacity: 1, rig: lerp(source, hero, BezierEase.morph(min(1, q / level.reveal))),328 rigScale: 1, rigOffset: .zero, push: 1, angle: 0, lever: 0, hardware: 0, inset: 0, rootOpacity: fadeOut)329 case .reduced, .none:330 // Réduire les animations : la fiche est déjà là, un simple fondu l'accompagne331 return DoorSceneState(veil: 1, rigOpacity: 0, rig: hero, rigScale: 1, rigOffset: .zero, push: 1, angle: 0, lever: 0,332 hardware: 0, inset: 0, rootOpacity: max(0, 1 - t / max(level.settle, 0.001)))333 }334 }335}336337/// Calque plein écran de la transition (posé à la racine, coordonnées globales).338struct DoorOverlay: View {339 @Environment(DoorCenter.self) private var door340 @Environment(\.colorScheme) private var scheme341 @Environment(\.horizontalSizeClass) private var hSize342343 var body: some View {344 GeometryReader { geo in345 if let run = door.run {346 let photo = door.photo347 let hero = door.heroRect ?? fallbackHero(geo.size, safeTop: geo.safeAreaInsets.top)348 TimelineView(.animation(paused: door.frozenTime != nil)) { timeline in349 let t = door.frozenTime ?? door.elapsed(at: timeline.date)350 let s = DoorSceneState.at(t, level: run.level, source: run.source, hero: hero, screen: geo.size)351 Canvas(opaque: false, rendersAsynchronously: false) { ctx, size in352 DoorPainter(state: s, dark: scheme == .dark, photo: photo, showsDoor: run.level.showsDoor).draw(&ctx, size: size)353 }354 .opacity(s.rootOpacity)355 }356 .contentShape(Rectangle())357 .onTapGesture { door.interrupt() }358 .accessibilityHidden(true)359 }360 }361 .ignoresSafeArea()362 .allowsHitTesting(door.run != nil)363 }364365 /// Cadre estimé de la photo principale tant que la fiche ne l'a pas publié.366 private func fallbackHero(_ size: CGSize, safeTop: CGFloat) -> CGRect {367 CGRect(x: 0, y: safeTop + 54, width: size.width, height: hSize == .regular ? 460 : 320)368 }369}370371/// Dessin de la porte : encadrement, seuil, embrasure (photo), battant en perspective, lumière.372struct DoorPainter {373 let state: DoorSceneState374 let dark: Bool375 let photo: UIImage?376 let showsDoor: Bool377378 private var orange: Color { Theme.heritageOrange }379 private var panelBase: Color { dark ? Color(hex: 0xE9EBE5) : Color(hex: 0x1B201D) }380381 func draw(_ ctx: inout GraphicsContext, size: CGSize) {382 let s = state383 // voile couleur de fond : la page d'origine s'efface384 ctx.fill(Path(CGRect(origin: .zero, size: size)), with: .color((dark ? Color(hex: 0x111815) : Color(hex: 0xF7F6F0)).opacity(s.veil)))385 guard s.rigOpacity > 0.001 else { return }386387 var c = ctx388 c.opacity = s.rigOpacity389 // émergence : translation et échelle autour du centre de la boîte390 c.translateBy(x: s.rig.midX + s.rigOffset.width, y: s.rig.midY + s.rigOffset.height)391 c.scaleBy(x: s.rigScale, y: s.rigScale)392 c.translateBy(x: -s.rig.midX, y: -s.rig.midY)393 // travelling avant : échelle autour de 50 % / 58 % de la boîte394 let ox = s.rig.minX + s.rig.width * 0.5, oy = s.rig.minY + s.rig.height * 0.58395 c.translateBy(x: ox, y: oy)396 c.scaleBy(x: s.push, y: s.push)397 c.translateBy(x: -ox, y: -oy)398399 let r = s.rig400 let ft = showsDoor ? max(8, (DoorSceneState.doorRectWidth(for: r) * 0.042).rounded()) : 0401 let fi = ft * s.inset402 let opening = CGRect(x: r.minX + fi, y: r.minY + fi, width: max(1, r.width - 2 * fi), height: max(1, r.height - fi))403 let a = min(1, max(0, s.angle / 86))404405 // Door Engine 3.0 : ni nappe de lumière au sol ni halo ; la lumière vient de la photographie réelle406407 // embrasure : la vraie photo du logement, qui recule et dont la lumière se pose408 c.drawLayer { layer in409 layer.clip(to: Path(opening))410 layer.fill(Path(opening), with: .color(photo == nil ? Theme.doorInterior : Color(hex: 0x1A1F1C)))411 if let photo {412 let img = layer.resolve(Image(uiImage: photo))413 let scale = max(opening.width / photo.size.width, opening.height / photo.size.height) * (showsDoor ? CGFloat(1.14 - 0.14 * a) : 1)414 let w = photo.size.width * scale, h = photo.size.height * scale415 let p = layer416 p.draw(img, in: CGRect(x: opening.midX - w / 2, y: opening.midY - h / 2, width: w, height: h))417 }418 guard showsDoor, s.hardware > 0.01 else { return }419 var fx = layer420 fx.opacity = s.hardware421 // ombre portée du battant sur l'intérieur, côté charnières, qui se retire422 let depth = max(0, 1 - s.angle / 88)423 fx.fill(Path(opening), with: .linearGradient(424 Gradient(stops: [.init(color: .black.opacity(0.62 * depth), location: 0), .init(color: .black.opacity(0.28 * depth), location: 0.45),425 .init(color: .black.opacity(0), location: 0.82)]),426 startPoint: CGPoint(x: opening.minX, y: 0), endPoint: CGPoint(x: opening.maxX, y: 0)))427 // profondeur du tableau : l'encadrement fait de l'ombre sur l'intérieur428 fx.fill(Path(CGRect(x: opening.minX, y: opening.minY, width: 12, height: opening.height)),429 with: .linearGradient(Gradient(colors: [.black.opacity(0.4), .black.opacity(0)]), startPoint: CGPoint(x: opening.minX, y: 0), endPoint: CGPoint(x: opening.minX + 12, y: 0)))430 fx.fill(Path(CGRect(x: opening.minX, y: opening.minY, width: opening.width, height: 12)),431 with: .linearGradient(Gradient(colors: [.black.opacity(0.36), .black.opacity(0)]), startPoint: CGPoint(x: 0, y: opening.minY), endPoint: CGPoint(x: 0, y: opening.minY + 12)))432 // battant : il pivote DANS l'embrasure (rogné), le bord libre s'éloigne433 drawPanel(&fx, opening: opening, doorWidth: r.width)434 }435436 guard showsDoor, s.hardware > 0.01 else { return }437 var hw = c438 hw.opacity = s.rigOpacity * s.hardware439 // encadrement : deux montants et un linteau, coins hauts de 3 pt, ombre portée douce440 let frameRect = CGRect(x: r.minX + ft / 2, y: r.minY + ft / 2, width: r.width - ft, height: r.height - ft / 2)441 var shadowed = hw442 shadowed.addFilter(.shadow(color: .black.opacity(0.28), radius: 16, x: 0, y: 12))443 shadowed.stroke(DoorFrameShape(radius: 3).path(in: frameRect), with: .color(orange), style: StrokeStyle(lineWidth: ft, lineCap: .butt, lineJoin: .round))444 // seuil : barre de 5 pt couleur du battant, qui dépasse de 9 % de chaque côté445 let sill = CGRect(x: r.minX - r.width * 0.09, y: r.maxY, width: r.width * 1.18, height: 5)446 hw.fill(Path(roundedRect: sill, cornerRadius: 2.5), with: .color(panelBase))447 }448449 /// Battant en perspective : distance focale 2,1 fois la largeur de la porte, point de fuite à 72 % / 46 %.450 private func drawPanel(_ ctx: inout GraphicsContext, opening o: CGRect, doorWidth: CGFloat) {451 let theta = state.angle * .pi / 180452 guard state.angle < 89.5 else { return }453 let pw = o.width, ph = o.height454 let f = Double(doorWidth) * 2.1455 let vx = Double(pw) * 0.72, vy = Double(ph) * 0.46456 let cosT = cos(theta), sinT = sin(theta)457 func proj(_ x: Double, _ y: Double) -> CGPoint {458 let X = x * cosT, Z = x * sinT459 let k = f / (f + Z)460 return CGPoint(x: o.minX + CGFloat(vx + (X - vx) * k), y: o.minY + CGFloat(vy + (y - vy) * k))461 }462 func quad(_ x0: Double, _ y0: Double, _ x1: Double, _ y1: Double) -> Path {463 var p = Path()464 p.move(to: proj(x0, y0)); p.addLine(to: proj(x1, y0)); p.addLine(to: proj(x1, y1)); p.addLine(to: proj(x0, y1)); p.closeSubpath()465 return p466 }467 let W = Double(pw), H = Double(ph)468 let a = min(1, max(0, state.angle / 86))469 let face = quad(0, 0, W, H)470471 // face : éclairage très léger de gauche à droite, assombrie en tournant472 let colors: [Color] = dark ? [Color(hex: 0xF4F5F0), Color(hex: 0xE9EBE5), Color(hex: 0xD9DCD5)] : [Color(hex: 0x262C28), Color(hex: 0x1B201D), Color(hex: 0x151917)]473 ctx.fill(face, with: .linearGradient(Gradient(stops: [.init(color: colors[0], location: 0), .init(color: colors[1], location: 0.46), .init(color: colors[2], location: 1)]),474 startPoint: proj(0, H / 2), endPoint: proj(W, H / 2)))475 ctx.fill(face, with: .color(.black.opacity(0.42 * a)))476 ctx.stroke(face, with: .color((dark ? Color.black : Color.white).opacity(0.06)), lineWidth: 1)477478 // deux moulures en creux : arête sombre en haut et à gauche, arête claire en bas et à droite479 for (top, bottom) in [(0.08, 0.48), (0.54, 0.92)] {480 let x0 = W * 0.13, x1 = W * 0.87, y0 = H * top, y1 = H * bottom481 var darkEdge = Path()482 darkEdge.move(to: proj(x0, y1)); darkEdge.addLine(to: proj(x0, y0)); darkEdge.addLine(to: proj(x1, y0))483 var lightEdge = Path()484 lightEdge.move(to: proj(x1, y0)); lightEdge.addLine(to: proj(x1, y1)); lightEdge.addLine(to: proj(x0, y1))485 ctx.stroke(darkEdge, with: .color(.black.opacity(dark ? 0.16 : 0.5)), lineWidth: 1.5)486 ctx.stroke(lightEdge, with: .color(.white.opacity(dark ? 0.8 : 0.09)), lineWidth: 1.5)487 }488489 // chant du battant : son épaisseur (10 pt), visible dès qu'il pivote490 let edgeW = 10 * sinT491 if edgeW > 0.4 {492 let k = f / (f + W * sinT)493 let p0 = proj(W, 0), p1 = proj(W, H)494 var edge = Path()495 edge.move(to: p0); edge.addLine(to: CGPoint(x: p0.x + CGFloat(edgeW * k), y: p0.y))496 edge.addLine(to: CGPoint(x: p1.x + CGFloat(edgeW * k), y: p1.y)); edge.addLine(to: p1); edge.closeSubpath()497 let e: [Color] = dark ? [Color(hex: 0xB9BDB5), Color(hex: 0xF1F3EE)] : [Color(hex: 0x0C0F0D), Color(hex: 0x2B322D)]498 ctx.fill(edge, with: .linearGradient(Gradient(colors: e), startPoint: p0, endPoint: CGPoint(x: p0.x + CGFloat(edgeW * k), y: p0.y)))499 }500501 // rosace et béquille orange, à 8,5 % du bord libre, à mi-hauteur502 let roseR = W * 0.0325503 let roseCX = W * (1 - 0.085) - roseR, roseCY = H * 0.5 + roseR504 let k = f / (f + roseCX * sinT)505 let rc = proj(roseCX, roseCY)506 let rx = CGFloat(roseR * cosT * k), ry = CGFloat(roseR * k)507 var hardware = ctx508 hardware.addFilter(.shadow(color: .black.opacity(0.45), radius: 1.5, x: 0, y: 1))509 // béquille : barre partant de la rosace vers les charnières ; elle s'abaisse en pivotant autour de la rosace510 let len = W * 0.17, th = max(3, H * 0.013)511 let la = -state.lever * .pi / 180 // angle positif : l'extrémité libre descend512 let end = proj(roseCX - len * cos(la), roseCY + len * sin(la))513 var lever = Path()514 lever.move(to: rc); lever.addLine(to: end)515 hardware.stroke(lever, with: .color(orange), style: StrokeStyle(lineWidth: CGFloat(th * k), lineCap: .round))516 hardware.fill(Path(ellipseIn: CGRect(x: rc.x - rx, y: rc.y - ry, width: rx * 2, height: ry * 2)), with: .color(orange))517 }518}519520extension DoorSceneState {521 /// Largeur de référence pour l'épaisseur de l'encadrement : celle de la porte au centre, même pendant le raccord.522 static func doorRectWidth(for rig: CGRect) -> CGFloat {523 // l'encadrement garde son épaisseur d'origine pendant que la boîte s'élargit vers la photo de la fiche524 let h = rig.height525 return min(rig.width, (max(280, min(560, h)) * 0.54))526 }527}528529/// Carte d'annonce qui ouvre la fiche par la porte.530struct ListingLink: View {531 let listing: Listing532 var layout: ListingCard.Layout = .grid533 @Environment(AppModel.self) private var app534 @Environment(DoorCenter.self) private var door535 @Environment(\.accessibilityReduceMotion) private var reduceMotion536 @State private var frame: CGRect = .zero537538 var body: some View {539 Button {540 Haptics.tap()541 let uid = listing.uid542 door.open(uid: uid, image: listing.images.first, from: photoRect, reduceMotion: reduceMotion) { app.open(.listing(uid)) }543 } label: {544 ListingCard(listing: listing, layout: layout)545 }546 .buttonStyle(PressScaleStyle())547 .accessibilityIdentifier("listing.card")548 .onGeometryChange(for: CGRect.self) { $0.frame(in: .global) } action: { frame = $0 }549 }550551 /// Cadre de la photo dans la carte : la porte en émerge.552 private var photoRect: CGRect {553 switch layout {554 case .grid: CGRect(x: frame.minX, y: frame.minY, width: frame.width, height: min(frame.height, frame.width * 3 / 4))555 case .row: CGRect(x: frame.minX, y: frame.minY, width: min(132, frame.width), height: frame.height)556 }557 }558}559560/// Retour tactile immédiat : la carte se resserre légèrement sous le doigt.561struct PressScaleStyle: ButtonStyle {562 func makeBody(configuration: Configuration) -> some View {563 configuration.label564 .scaleEffect(configuration.isPressed ? 0.975 : 1)565 .animation(.easeOut(duration: 0.12), value: configuration.isPressed)566 }567}568